UserInfo.php 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Exception;
  6. use think\Model;
  7. class UserInfo extends Model
  8. {
  9. // 获取普通用户列表
  10. public function lists($orgId){
  11. $page = input('page/d',1);
  12. $size = input('size/d',10);
  13. $name = input('name','','trim');
  14. $code = input('code','','trim');
  15. $phone = input('phone','','trim');
  16. $isWorking = input('isWorking','','trim');
  17. $startTime = input('startTime','','trim');
  18. $endTime = input('endTime','','trim');
  19. $gender = input('gender/d',0);
  20. $companyId = input('companyId/d',-1);
  21. $job = input('job','','trim');
  22. $education = input('education','','trim');
  23. $profession = input('profession','','trim');
  24. $uids = model('User')->getAdminUsers();
  25. if($uids){
  26. $map[] = ['u.id','not in',$uids];
  27. }
  28. if($name){
  29. $map[] = ['ui.name','like','%'.$name.'%'];
  30. }
  31. if($code){
  32. $map[] = ['u.code','like','%'.$code.'%'];
  33. }
  34. if($phone){
  35. $map[] = ['u.phone','like','%'.$phone.'%'];
  36. }
  37. if($isWorking){
  38. $map[] = ['ui.is_working','=',$isWorking];
  39. }
  40. // if($joinTime){
  41. // $map[] = ['ui.join_time','=',$joinTime];
  42. // }
  43. if($startTime){
  44. $map[] = ['ui.join_time','>=',$startTime];
  45. }
  46. if($endTime){
  47. $map[] = ['ui.join_time','<=',$endTime];
  48. }
  49. if($gender > 0){
  50. $map[] = ['ui.gender','=',$gender];
  51. }
  52. if($companyId >= 0){
  53. $map[] = ['ui.company_id','=',$companyId];
  54. }
  55. if($job){
  56. $map[] = ['ui.job','like','%'.$job.'%'];
  57. }
  58. if($education){
  59. $map[] = ['ui.education','like','%'.$education.'%'];
  60. }
  61. if($profession){
  62. $map[] = ['ui.profession','like','%'.$profession.'%'];
  63. }
  64. $sort = input('sort','','trim');
  65. $order = input('order','','trim');
  66. $orderby = '';
  67. if($sort == 'age' && in_array($order,['ascending','descending'])){
  68. $orderby = 'ui.birthday '.($order == 'ascending'?'desc':'asc').',';
  69. }
  70. $map[] = ['u.del','=',0];
  71. $map[] = ['r.type','=',3];
  72. $map[] = ['r.org_id','=',$orgId];
  73. $lists = Db::name('user_info')
  74. ->alias('ui')
  75. ->join('user u','ui.user_id = u.id')
  76. ->join('user_roles ur','ur.user_id = u.id')
  77. ->join('roles r','ur.roles_id = r.id')
  78. ->where($map)
  79. ->field('u.code,u.phone,u.enable,ui.*')
  80. ->page($page,$size)
  81. ->order($orderby.'u.sorts asc,ui.is_working asc,u.id desc')
  82. ->select();
  83. $lists = $lists?$lists:[];
  84. foreach ($lists as $k=>$v){
  85. // 获取用户岗位
  86. $jlist = Db::name('user_job')
  87. ->alias('uj')
  88. ->join('job j','j.id = uj.job_id')
  89. ->join('dep d','d.id = j.dep_id')
  90. ->where('uj.user_id',$v['user_id'])
  91. ->where('j.del',0)
  92. ->where('j.enable',1)
  93. ->where('d.del',0)
  94. ->where('d.enable',1)
  95. ->field("d.name as dep,j.name as job")
  96. ->select();
  97. $jlist = $jlist?$jlist:[];
  98. $deps = $jobs = [];
  99. foreach ($jlist as $kk=>$vv){
  100. $deps[] = $vv['dep'];
  101. // $jobs[] = $vv['job'];
  102. }
  103. $lists[$k]['dep'] = $deps?implode(',',$deps):'';
  104. // $lists[$k]['job'] = $jobs?implode(',',$jobs):'';
  105. $lists[$k]['company'] = '';
  106. if($lists[$k]['company_id'] > 0){
  107. $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title');
  108. }
  109. $lists[$k]['psname'] = '';
  110. if($lists[$k]['psid'] > 0){
  111. $lists[$k]['psname'] = Db::name('post_salary')->where('id',$v['psid'])->value('job');
  112. }
  113. $lists[$k]['age'] = $v['birthday']?calculate_age($v['birthday']):'';
  114. }
  115. $total = Db::name('user_info')
  116. ->alias('ui')
  117. ->join('user u','ui.user_id = u.id')
  118. ->join('user_roles ur','ur.user_id = u.id')
  119. ->join('roles r','ur.roles_id = r.id')
  120. ->where($map)
  121. ->count();
  122. $data = [
  123. 'total' => $total,
  124. 'list' => $lists?$lists:[]
  125. ];
  126. return $data;
  127. }
  128. // 获取普通用户假期统计列表
  129. public function listsholiday($orgId){
  130. $page = input('page/d',1);
  131. $size = input('size/d',10);
  132. $name = input('name','','trim');
  133. $code = input('code','','trim');
  134. $phone = input('phone','','trim');
  135. $isWorking = input('isWorking','','trim');
  136. $startTime = input('startTime','','trim');
  137. $endTime = input('endTime','','trim');
  138. $gender = input('gender/d',0);
  139. $companyId = input('companyId/d',-1);
  140. $job = input('job','','trim');
  141. $education = input('education','','trim');
  142. $profession = input('profession','','trim');
  143. $uids = model('User')->getAdminUsers();
  144. if($uids){
  145. $map[] = ['u.id','not in',$uids];
  146. }
  147. if($name){
  148. $map[] = ['ui.name','like','%'.$name.'%'];
  149. }
  150. if($code){
  151. $map[] = ['u.code','like','%'.$code.'%'];
  152. }
  153. if($phone){
  154. $map[] = ['u.phone','like','%'.$phone.'%'];
  155. }
  156. if($isWorking){
  157. $map[] = ['ui.is_working','=',$isWorking];
  158. }
  159. // if($joinTime){
  160. // $map[] = ['ui.join_time','=',$joinTime];
  161. // }
  162. // if($startTime){
  163. // $map[] = ['ui.join_time','>=',$startTime];
  164. // }
  165. // if($endTime){
  166. // $map[] = ['ui.join_time','<=',$endTime];
  167. // }
  168. if($gender > 0){
  169. $map[] = ['ui.gender','=',$gender];
  170. }
  171. if($companyId >= 0){
  172. $map[] = ['ui.company_id','=',$companyId];
  173. }
  174. // if($job){
  175. // $map[] = ['ui.job','like','%'.$job.'%'];
  176. // }
  177. if($job){
  178. $map[] = ['d.name','like','%'.$job.'%'];
  179. }
  180. if($education){
  181. $map[] = ['ui.education','like','%'.$education.'%'];
  182. }
  183. if($profession){
  184. $map[] = ['ui.profession','like','%'.$profession.'%'];
  185. }
  186. $sort = input('sort','','trim');
  187. $order = input('order','','trim');
  188. $orderby = '';
  189. if($sort == 'age' && in_array($order,['ascending','descending'])){
  190. $orderby = 'ui.birthday '.($order == 'ascending'?'desc':'asc').',';
  191. }
  192. $map[] = ['u.del','=',0];
  193. $map[] = ['r.type','=',3];
  194. $map[] = ['r.org_id','=',$orgId];
  195. $types = Db::name('attendance_leave_type')->where('enable',1)->where('del',0)->select();
  196. $types = $types?$types:[];
  197. $lists = Db::name('user_info')
  198. ->alias('ui')
  199. ->join('user u','ui.user_id = u.id')
  200. ->join('user_roles ur','ur.user_id = u.id')
  201. ->join('roles r','ur.roles_id = r.id')
  202. ->join('user_job uj','uj.user_id = u.id','left')
  203. ->join('job j','uj.job_id = j.id','left')
  204. ->join('dep d','j.dep_id = d.id','left')
  205. ->where($map)
  206. ->field('u.code,u.phone,u.enable,ui.*')
  207. ->page($page,$size)
  208. ->group('u.id')
  209. ->order($orderby.'u.sorts asc,ui.is_working asc,u.id desc')
  210. ->select();
  211. $lists = $lists?$lists:[];
  212. foreach ($lists as $k=>$v){
  213. // 获取用户岗位
  214. $jlist = Db::name('user_job')
  215. ->alias('uj')
  216. ->join('job j','j.id = uj.job_id')
  217. ->join('dep d','d.id = j.dep_id')
  218. ->where('uj.user_id',$v['user_id'])
  219. ->where('j.del',0)
  220. ->where('j.enable',1)
  221. ->where('d.del',0)
  222. ->where('d.enable',1)
  223. ->field("d.name as dep,j.name as job")
  224. ->select();
  225. $jlist = $jlist?$jlist:[];
  226. $deps = $jobs = [];
  227. foreach ($jlist as $kk=>$vv){
  228. $deps[] = $vv['dep'];
  229. }
  230. $lists[$k]['dep'] = $deps?implode(',',$deps):'';
  231. $tday = 0;
  232. foreach ($types as $kk=>$vv){
  233. $jmap = [];
  234. $jmap[] = ['status','=',1];
  235. $jmap[] = ['user_id','=',$v['user_id']];
  236. $jmap[] = ['leave_type','=',$vv['id']];
  237. $startTime = $startTime?date('Y-m-d',strtotime($startTime)):'';
  238. $endTime = $endTime?date('Y-m-d',strtotime($endTime)):'';
  239. if(!$startTime && !$endTime){
  240. $day = Db::name('attendance_leave')->where($jmap)->sum('cur_days');
  241. }else{
  242. $jjmap = $jmap;
  243. if($startTime){
  244. $jjmap[] = ['start_time','>=',$startTime.' 00:00:00'];
  245. }
  246. if($endTime){
  247. $jjmap[] = ['end_time','<=',$endTime.' 23:59:59'];
  248. }
  249. $day1 = 0; // 先计算完全在时间范围内的假期
  250. $day2 = 0; // 不再时间内的假期平均分配
  251. if($startTime || $endTime){ // 1先计算完全在时间范围内的假期
  252. $day1 = Db::name('attendance_leave')->where($jjmap)->sum('cur_days');
  253. // 计算有效假期,最后按比例分配
  254. $type = $vv['id'] == 6?0:1; // 产假,不减节假日
  255. // 2再计算不完全在时间范围内的假期
  256. if($startTime){
  257. $jjmap2 = $jmap;
  258. $jjmap2[] = ['start_time','<',$startTime.' 00:00:00'];
  259. $jjmap2[] = ['end_time','>',$startTime.' 23:59:59'];
  260. $dlist = Db::name('attendance_leave')->where($jjmap2)->select();
  261. foreach ($dlist as $dk=>$dv){
  262. $d = calculate_leave($startTime.' 00:00:00',$dv['end_time'],$type); // 有效天数
  263. $cd = round($dv['cur_days']*$d/$dv['days'],2); // 实际有效天数
  264. $day2 += $cd;
  265. }
  266. }
  267. if($endTime){
  268. $jjmap2 = $jmap;
  269. $jjmap2[] = ['start_time','<',$endTime.' 00:00:00'];
  270. $jjmap2[] = ['end_time','>',$endTime.' 23:59:59'];
  271. $dlist = Db::name('attendance_leave')->where($jjmap2)->select();
  272. foreach ($dlist as $dk=>$dv){
  273. $d = calculate_leave($dv['start_time'],$endTime.' 23:59:59',$type); // 有效天数
  274. $cd = round($dv['cur_days']*$d/$dv['days'],2); // 实际有效天数
  275. $day2 += $cd;
  276. }
  277. }
  278. }
  279. $day = $day1 + $day2;
  280. }
  281. $lists[$k]['type'.$vv['id']] = $day;
  282. $tday += $day;
  283. }
  284. $lists[$k]['tday'] = $tday;
  285. }
  286. $total = Db::name('user_info')
  287. ->alias('ui')
  288. ->join('user u','ui.user_id = u.id')
  289. ->join('user_roles ur','ur.user_id = u.id')
  290. ->join('roles r','ur.roles_id = r.id')
  291. ->join('user_job uj','uj.user_id = u.id','left')
  292. ->join('job j','uj.job_id = j.id','left')
  293. ->join('dep d','j.dep_id = d.id','left')
  294. ->where($map)
  295. ->group('u.id')
  296. ->count();
  297. $data = [
  298. 'total' => $total,
  299. 'list' => $lists?$lists:[],
  300. 'types' => $types
  301. ];
  302. return $data;
  303. }
  304. // 花用户列表
  305. public function rosterLists($orgId){
  306. $page = input('page/d',1);
  307. $size = input('size/d',10);
  308. $name = input('name','','trim');
  309. $code = input('code','','trim');
  310. $phone = input('phone','','trim');
  311. $isWorking = input('isWorking','','trim');
  312. $startTime = input('startTime','','trim');
  313. $endTime = input('endTime','','trim');
  314. $gender = input('gender/d',0);
  315. $companyType = input('companyType/d',-1);
  316. if($companyType == 1){
  317. $map[] = ['ui.company_id','=',1];
  318. $map[] = ['ui.is_working','in',[1,2]];
  319. }else if($companyType == 2){
  320. $map[] = ['ui.company_id','=',1];
  321. $map[] = ['ui.is_working','=',4];
  322. }else if($companyType == 3){
  323. $map[] = ['ui.company_id','=',2];
  324. $map[] = ['ui.is_working','in',[1,2]];
  325. }else if($companyType == 4){
  326. $map[] = ['ui.company_id','=',0];
  327. $map[] = ['ui.is_working','in',[1,2]];
  328. }
  329. $job = input('job','','trim');
  330. $education = input('education','','trim');
  331. $profession = input('profession','','trim');
  332. $uids = model('User')->getAdminUsers();
  333. if($uids){
  334. $map[] = ['u.id','not in',$uids];
  335. }
  336. if($name){
  337. $map[] = ['ui.name','like','%'.$name.'%'];
  338. }
  339. if($code){
  340. $map[] = ['u.code','like','%'.$code.'%'];
  341. }
  342. if($phone){
  343. $map[] = ['u.phone','like','%'.$phone.'%'];
  344. }
  345. // if($isWorking){
  346. // $map[] = ['ui.is_working','=',$isWorking];
  347. // }
  348. // if($joinTime){
  349. // $map[] = ['ui.join_time','=',$joinTime];
  350. // }
  351. if($startTime){
  352. $map[] = ['ui.join_time','>=',$startTime];
  353. }
  354. if($endTime){
  355. $map[] = ['ui.join_time','<=',$endTime];
  356. }
  357. if($gender > 0){
  358. $map[] = ['ui.gender','=',$gender];
  359. }
  360. // if($companyId >= 0){
  361. // $map[] = ['ui.company_id','=',$companyId];
  362. // }
  363. if($job){
  364. $map[] = ['ui.job','like','%'.$job.'%'];
  365. }
  366. if($education){
  367. $map[] = ['ui.education','like','%'.$education.'%'];
  368. }
  369. if($profession){
  370. $map[] = ['ui.profession','like','%'.$profession.'%'];
  371. }
  372. $prop = input('prop','','trim');
  373. $order = input('order','','trim');
  374. if($prop == 'birthday'){
  375. $prop = 'ui.birthday';
  376. }else if($prop == 'age'){
  377. $prop = 'ui.birthday';
  378. }else if($prop == 'workDate'){
  379. $prop = 'ui.work_date';
  380. }else if($prop == 'dangDate'){
  381. $prop = 'ui.dang_date';
  382. }
  383. if($prop && $order == 'ascending'){
  384. $orderby = $prop.' asc,ui.sorts2 asc, u.id desc';
  385. }else if($prop && $order == 'descending'){
  386. $orderby = $prop.' desc,ui.sorts2 asc, u.id desc';
  387. }else{
  388. $orderby = 'ui.sorts2 asc,u.id desc';
  389. }
  390. $map[] = ['u.del','=',0];
  391. $map[] = ['r.type','=',3];
  392. $map[] = ['r.org_id','=',$orgId];
  393. $lists = Db::name('user_info')
  394. ->alias('ui')
  395. ->join('user u','ui.user_id = u.id')
  396. ->join('user_roles ur','ur.user_id = u.id')
  397. ->join('roles r','ur.roles_id = r.id')
  398. ->where($map)
  399. ->field('u.code,u.phone,u.enable,ui.*')
  400. ->page($page,$size)
  401. ->order($orderby)
  402. ->select();
  403. $lists = $lists?$lists:[];
  404. foreach ($lists as $k=>$v){
  405. // 获取用户岗位
  406. $jlist = Db::name('user_job')
  407. ->alias('uj')
  408. ->join('job j','j.id = uj.job_id')
  409. ->join('dep d','d.id = j.dep_id')
  410. ->where('j.del',0)
  411. ->where('j.enable',1)
  412. ->where('d.del',0)
  413. ->where('d.enable',1)
  414. ->where('uj.user_id',$v['user_id'])
  415. ->field("d.name as dep,j.name as job")
  416. ->select();
  417. $jlist = $jlist?$jlist:[];
  418. $deps = $jobs = [];
  419. foreach ($jlist as $kk=>$vv){
  420. $deps[] = $vv['dep'];
  421. // $jobs[] = $vv['job'];
  422. }
  423. $lists[$k]['dep'] = $deps?implode(',',$deps):'';
  424. // $lists[$k]['job'] = $jobs?implode(',',$jobs):'';
  425. $lists[$k]['company'] = '';
  426. if($lists[$k]['company_id'] > 0){
  427. $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title');
  428. }
  429. $lists[$k]['psname'] = '';
  430. if($lists[$k]['psid'] > 0){
  431. $lists[$k]['psname'] = Db::name('post_salary')->where('id',$v['psid'])->value('job');
  432. }
  433. $lists[$k]['age'] = $v['birthday']?calculate_age($v['birthday']):'';
  434. }
  435. $total = Db::name('user_info')
  436. ->alias('ui')
  437. ->join('user u','ui.user_id = u.id')
  438. ->join('user_roles ur','ur.user_id = u.id')
  439. ->join('roles r','ur.roles_id = r.id')
  440. ->where($map)
  441. ->count();
  442. $data = [
  443. 'total' => $total,
  444. 'list' => $lists?$lists:[]
  445. ];
  446. return $data;
  447. }
  448. // 获取普通用户薪资岗位列表
  449. public function lists2($orgId){
  450. $page = input('page/d',1);
  451. $size = input('size/d',10);
  452. $name = input('name','','trim');
  453. $payType = input('payType/d',-1);
  454. $type = input('type/d',0);
  455. $companyId = input('companyId/d',-1);
  456. $uids = model('User')->getAdminUsers();
  457. if($uids){
  458. $map[] = ['u.id','not in',$uids];
  459. }
  460. if($name){
  461. $map[] = ['ui.name','like','%'.$name.'%'];
  462. }
  463. if($payType >= 0){
  464. $map[] = ['ui.pay_type','=',$payType];
  465. }
  466. if($companyId >= 0){
  467. $map[] = ['ui.company_id','=',$companyId];
  468. }
  469. if($type){
  470. $map[] = ['ui.type','=',$type];
  471. }
  472. $map[] = ['u.del','=',0];
  473. $map[] = ['r.type','=',3];
  474. $map[] = ['r.org_id','=',$orgId];
  475. $lists = Db::name('user_info')
  476. ->alias('ui')
  477. ->join('user u','ui.user_id = u.id')
  478. ->join('user_roles ur','ur.user_id = u.id')
  479. ->join('roles r','ur.roles_id = r.id')
  480. ->where($map)
  481. ->field('u.code,u.phone,u.enable,ui.*')
  482. ->page($page,$size)
  483. ->order('ui.sorts3 asc,u.id desc')
  484. ->select();
  485. $lists = $lists?$lists:[];
  486. foreach ($lists as $k=>$v){
  487. $lists[$k]['company'] = '';
  488. if($lists[$k]['company_id'] > 0){
  489. $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title');
  490. }
  491. $lists[$k]['work_age'] = $v['work_date']?calculate_age($v['work_date']):0; // 工龄
  492. $lists[$k]['psname'] = '';
  493. $lists[$k]['psmonth'] = '';
  494. $lists[$k]['psmoney'] = 0;
  495. if($lists[$k]['psid'] > 0){
  496. $psinfo = Db::name('post_salary')->where('id',$v['psid'])->find();
  497. if($psinfo){
  498. $lists[$k]['psname'] = $psinfo['job'];
  499. $lists[$k]['psmoney'] = $psinfo['money'];
  500. $lists[$k]['psmonth'] = $psinfo['month_performance'];
  501. if($lists[$k]['work_age'] > 25 && $psinfo['month_performance2'] > 0){
  502. $lists[$k]['psmonth'] = $psinfo['month_performance2'];
  503. }
  504. }
  505. }
  506. $lists[$k]['pay_wages'] = [];
  507. $lists[$k]['pwmoney'] = 0;
  508. if($v['type'] > 0 && $v['company_id'] > 0){
  509. $pay_wages = Db::name('pay_wages')
  510. ->where('company_id',$v['company_id'])
  511. ->where('type',$v['type'])
  512. ->value('content');
  513. $pay_wages = $pay_wages?json_decode($pay_wages,true):[];
  514. $lists[$k]['pay_wages'] = $pay_wages;
  515. foreach ($pay_wages as $kk=>$vv){
  516. if($v['pwlevel'] == $vv['level']){
  517. $lists[$k]['pwmoney'] = $vv['money'];
  518. break;
  519. }
  520. }
  521. }
  522. }
  523. $total = Db::name('user_info')
  524. ->alias('ui')
  525. ->join('user u','ui.user_id = u.id')
  526. ->join('user_roles ur','ur.user_id = u.id')
  527. ->join('roles r','ur.roles_id = r.id')
  528. ->where($map)
  529. ->count();
  530. $data = [
  531. 'total' => $total,
  532. 'list' => $lists?$lists:[]
  533. ];
  534. return $data;
  535. }
  536. public function all($orgId,$companyId){
  537. $uids = model('User')->getAdminUsers();
  538. if($uids){
  539. $map[] = ['u.id','not in',$uids];
  540. }
  541. if($companyId >= 0){
  542. $map[] = ['ui.company_id','=',$companyId];
  543. }
  544. $map[] = ['u.del','=',0];
  545. $map[] = ['r.type','=',3];
  546. $map[] = ['r.org_id','=',$orgId];
  547. $lists = Db::name('user_info')
  548. ->alias('ui')
  549. ->join('user u','ui.user_id = u.id')
  550. ->join('user_roles ur','ur.user_id = u.id')
  551. ->join('roles r','ur.roles_id = r.id')
  552. ->where($map)
  553. ->field('u.code,u.phone,ui.*')
  554. ->order('u.id desc')
  555. ->select();
  556. $lists = $lists?$lists:[];
  557. foreach ($lists as $k=>$v){
  558. // 获取用户岗位
  559. $jlist = Db::name('user_job')
  560. ->alias('uj')
  561. ->join('job j','j.id = uj.job_id')
  562. ->join('dep d','d.id = j.dep_id')
  563. ->where('j.del',0)
  564. ->where('j.enable',1)
  565. ->where('d.del',0)
  566. ->where('d.enable',1)
  567. ->where('uj.user_id',$v['user_id'])
  568. ->field("d.name as dep,j.name as job")
  569. ->select();
  570. $jlist = $jlist?$jlist:[];
  571. $deps = $jobs = [];
  572. foreach ($jlist as $kk=>$vv){
  573. $deps[] = $vv['dep'];
  574. }
  575. $lists[$k]['dep'] = $deps?implode(',',$deps):'';
  576. $lists[$k]['company'] = '';
  577. if($lists[$k]['company_id'] > 0){
  578. $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title');
  579. }
  580. $lists[$k]['age'] = $v['birthday']?calculate_age($v['birthday']):'';
  581. }
  582. return $lists;
  583. }
  584. // 获取普通用户导出列表
  585. public function exportLists($orgId){
  586. $name = input('name','','trim');
  587. $code = input('code','','trim');
  588. $phone = input('phone','','trim');
  589. $isWorking = input('isWorking','','trim');
  590. $startTime = input('startTime','','trim');
  591. $endTime = input('endTime','','trim');
  592. $gender = input('gender/d',0);
  593. $companyId = input('companyId/d',-1);
  594. $job = input('job','','trim');
  595. $education = input('education','','trim');
  596. $profession = input('profession','','trim');
  597. $uids = model('User')->getAdminUsers();
  598. if($uids){
  599. $map[] = ['u.id','not in',$uids];
  600. }
  601. if($name){
  602. $map[] = ['ui.name','like','%'.$name.'%'];
  603. }
  604. if($code){
  605. $map[] = ['u.code','like','%'.$code.'%'];
  606. }
  607. if($phone){
  608. $map[] = ['u.phone','like','%'.$phone.'%'];
  609. }
  610. if($isWorking){
  611. $map[] = ['ui.is_working','=',$isWorking];
  612. }
  613. // if($joinTime){
  614. // $map[] = ['ui.join_time','=',$joinTime];
  615. // }
  616. if($startTime){
  617. $map[] = ['ui.join_time','>=',$startTime];
  618. }
  619. if($endTime){
  620. $map[] = ['ui.join_time','<=',$endTime];
  621. }
  622. if($gender > 0){
  623. $map[] = ['ui.gender','=',$gender];
  624. }
  625. if($companyId >= 0){
  626. $map[] = ['ui.company_id','=',$companyId];
  627. }
  628. if($job){
  629. $map[] = ['ui.job','like','%'.$job.'%'];
  630. }
  631. if($education){
  632. $map[] = ['ui.education','like','%'.$education.'%'];
  633. }
  634. if($profession){
  635. $map[] = ['ui.profession','like','%'.$profession.'%'];
  636. }
  637. $map[] = ['u.del','=',0];
  638. $map[] = ['r.type','=',3];
  639. $map[] = ['r.org_id','=',$orgId];
  640. $lists = Db::name('user_info')
  641. ->alias('ui')
  642. ->join('user u','ui.user_id = u.id')
  643. ->join('user_roles ur','ur.user_id = u.id')
  644. ->join('roles r','ur.roles_id = r.id')
  645. ->where($map)
  646. ->field('u.code,u.phone,ui.*')
  647. ->order('ui.is_working asc,u.id desc')
  648. ->select();
  649. $lists = $lists?$lists:[];
  650. foreach ($lists as $k=>$v){
  651. // 获取用户岗位
  652. $jlist = Db::name('user_job')
  653. ->alias('uj')
  654. ->join('job j','j.id = uj.job_id')
  655. ->join('dep d','d.id = j.dep_id')
  656. ->where('j.del',0)
  657. ->where('j.enable',1)
  658. ->where('d.del',0)
  659. ->where('d.enable',1)
  660. ->where('uj.user_id',$v['user_id'])
  661. ->field("d.name as dep,j.name as job")
  662. ->select();
  663. $jlist = $jlist?$jlist:[];
  664. $deps = $jobs = [];
  665. foreach ($jlist as $kk=>$vv){
  666. $deps[] = $vv['dep'];
  667. $jobs[] = $vv['job'];
  668. }
  669. $lists[$k]['dep'] = $deps?implode(',',$deps):'';
  670. // $lists[$k]['job'] = $jobs?implode(',',$jobs):'';
  671. $lists[$k]['company'] = '';
  672. if($lists[$k]['company_id'] > 0){
  673. $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title');
  674. }
  675. if($v['is_working'] == 1){
  676. $lists[$k]['isWorkingText'] = '试用期';
  677. }else if($v['is_working'] == 2){
  678. $lists[$k]['isWorkingText'] = '正式';
  679. }else if($v['is_working'] == 3){
  680. $lists[$k]['isWorkingText'] = '离职';
  681. }else if($v['is_working'] == 4){
  682. $lists[$k]['isWorkingText'] = '退休';
  683. }else{
  684. $lists[$k]['isWorkingText'] = '';
  685. }
  686. if($v['gender'] == 1){
  687. $lists[$k]['genderText'] = '男';
  688. }else if($v['gender'] == 2){
  689. $lists[$k]['genderText'] = '女';
  690. }else{
  691. $lists[$k]['genderText'] = '';
  692. }
  693. //1=管理人员 2=专业技术人员 3=工勤技能人员
  694. if($v['type'] == 1){
  695. $lists[$k]['typeText'] = '管理人员';
  696. }else if($v['type'] == 2){
  697. $lists[$k]['typeText'] = '专业技术人员';
  698. }else if($v['type'] == 3){
  699. $lists[$k]['typeText'] = '工勤技能人员';
  700. }else{
  701. $lists[$k]['typeText'] = '';
  702. }
  703. $lists[$k]['psName'] = '';
  704. if($lists[$k]['psid'] > 0){
  705. $lists[$k]['psName'] = Db::name('post_salary')->where('id',$v['psid'])->value('title');
  706. }
  707. $lists[$k]['jobDateText'] = '';
  708. if($v['job'] || $v['job_date']){
  709. $arr[$k]['jobDateText'] = $v['job'].'/'.$v['job_date'];
  710. }
  711. }
  712. $columns = [
  713. ["title" => "部门","key" => "dep"],
  714. ["title" => "行政职务","key" => "position"],
  715. ["title" => "姓名","key" => "name"],
  716. ["title" => "岗位及时间","key" => "jobDateText"],
  717. ["title" => "性别","key" => "genderText"],
  718. ["title" => "民族","key" => "nation"],
  719. ["title" => "籍贯","key" => "nativePlace"],
  720. ["title" => "出生日期","key" => "birthday"],
  721. ["title" => "身份证号码","key" => "idCard"],
  722. ["title" => "年龄","key" => "age"],
  723. ["title" => "学历","key" => "education"],
  724. ["title" => "专业","key" => "profession"],
  725. ["title" => "入党时间","key" => "dangDate"],
  726. ["title" => "工作时间","key" => "workDate"],
  727. ["title" => "任现职时间","key" => "curJobDate"],
  728. ["title" => "专业技术职务","key" => "professionPosition"],
  729. ["title" => "评定时间","key" => "assessDate"],
  730. ["title" => "职业资格","key" => "qualification"],
  731. ["title" => "来办时间","key" => "joinTime"],
  732. ["title" => "进入形式","key" => "inShape"],
  733. ["title" => "同级职务时间","key" => "levelJobDate"],
  734. ];
  735. $data = [
  736. 'columns' => $columns,
  737. 'list' => $lists
  738. ];
  739. return $data;
  740. }
  741. public function exportHolidayLists($orgId){
  742. // $page = input('page/d',1);
  743. // $size = input('size/d',10);
  744. $name = input('name','','trim');
  745. $code = input('code','','trim');
  746. $phone = input('phone','','trim');
  747. $isWorking = input('isWorking','','trim');
  748. $startTime = input('startTime','','trim');
  749. $endTime = input('endTime','','trim');
  750. $gender = input('gender/d',0);
  751. $companyId = input('companyId/d',-1);
  752. $job = input('job','','trim');
  753. $education = input('education','','trim');
  754. $profession = input('profession','','trim');
  755. $uids = model('User')->getAdminUsers();
  756. if($uids){
  757. $map[] = ['u.id','not in',$uids];
  758. }
  759. if($name){
  760. $map[] = ['ui.name','like','%'.$name.'%'];
  761. }
  762. if($code){
  763. $map[] = ['u.code','like','%'.$code.'%'];
  764. }
  765. if($phone){
  766. $map[] = ['u.phone','like','%'.$phone.'%'];
  767. }
  768. if($isWorking){
  769. $map[] = ['ui.is_working','=',$isWorking];
  770. }
  771. // if($joinTime){
  772. // $map[] = ['ui.join_time','=',$joinTime];
  773. // }
  774. // if($startTime){
  775. // $map[] = ['ui.join_time','>=',$startTime];
  776. // }
  777. // if($endTime){
  778. // $map[] = ['ui.join_time','<=',$endTime];
  779. // }
  780. if($gender > 0){
  781. $map[] = ['ui.gender','=',$gender];
  782. }
  783. if($companyId >= 0){
  784. $map[] = ['ui.company_id','=',$companyId];
  785. }
  786. // if($job){
  787. // $map[] = ['ui.job','like','%'.$job.'%'];
  788. // }
  789. if($job){
  790. $map[] = ['d.name','like','%'.$job.'%'];
  791. }
  792. if($education){
  793. $map[] = ['ui.education','like','%'.$education.'%'];
  794. }
  795. if($profession){
  796. $map[] = ['ui.profession','like','%'.$profession.'%'];
  797. }
  798. $sort = input('sort','','trim');
  799. $order = input('order','','trim');
  800. $orderby = '';
  801. if($sort == 'age' && in_array($order,['ascending','descending'])){
  802. $orderby = 'ui.birthday '.($order == 'ascending'?'desc':'asc').',';
  803. }
  804. $map[] = ['u.del','=',0];
  805. $map[] = ['r.type','=',3];
  806. $map[] = ['r.org_id','=',$orgId];
  807. $types = Db::name('attendance_leave_type')->where('enable',1)->where('del',0)->select();
  808. $types = $types?$types:[];
  809. $lists = Db::name('user_info')
  810. ->alias('ui')
  811. ->join('user u','ui.user_id = u.id')
  812. ->join('user_roles ur','ur.user_id = u.id')
  813. ->join('roles r','ur.roles_id = r.id')
  814. ->join('user_job uj','uj.user_id = u.id','left')
  815. ->join('job j','uj.job_id = j.id','left')
  816. ->join('dep d','j.dep_id = d.id','left')
  817. ->where($map)
  818. ->field('u.code,u.phone,u.enable,ui.*')
  819. ->group('u.id')
  820. // ->page($page,$size)
  821. ->order($orderby.'u.sorts asc,ui.is_working asc,u.id desc')
  822. ->select();
  823. $lists = $lists?$lists:[];
  824. foreach ($lists as $k=>$v){
  825. // 获取用户岗位
  826. $jlist = Db::name('user_job')
  827. ->alias('uj')
  828. ->join('job j','j.id = uj.job_id')
  829. ->join('dep d','d.id = j.dep_id')
  830. ->where('uj.user_id',$v['user_id'])
  831. ->where('j.del',0)
  832. ->where('j.enable',1)
  833. ->where('d.del',0)
  834. ->where('d.enable',1)
  835. ->field("d.name as dep,j.name as job")
  836. ->select();
  837. $jlist = $jlist?$jlist:[];
  838. $deps = $jobs = [];
  839. foreach ($jlist as $kk=>$vv){
  840. $deps[] = $vv['dep'];
  841. }
  842. $lists[$k]['dep'] = $deps?implode(',',$deps):'';
  843. $tday = 0;
  844. foreach ($types as $kk=>$vv){
  845. $jmap = [];
  846. $jmap[] = ['status','=',1];
  847. $jmap[] = ['user_id','=',$v['user_id']];
  848. $jmap[] = ['leave_type','=',$vv['id']];
  849. $startTime = $startTime?date('Y-m-d',strtotime($startTime)):'';
  850. $endTime = $endTime?date('Y-m-d',strtotime($endTime)):'';
  851. if(!$startTime && !$endTime){
  852. $day = Db::name('attendance_leave')->where($jmap)->sum('cur_days');
  853. }else{
  854. $jjmap = $jmap;
  855. if($startTime){
  856. $jjmap[] = ['start_time','>=',$startTime.' 00:00:00'];
  857. }
  858. if($endTime){
  859. $jjmap[] = ['end_time','<=',$endTime.' 23:59:59'];
  860. }
  861. $day1 = 0; // 先计算完全在时间范围内的假期
  862. $day2 = 0; // 不再时间内的假期平均分配
  863. if($startTime || $endTime){ // 1先计算完全在时间范围内的假期
  864. $day1 = Db::name('attendance_leave')->where($jjmap)->sum('cur_days');
  865. // 计算有效假期,最后按比例分配
  866. $type = $vv['id'] == 6?0:1; // 产假,不减节假日
  867. // 2再计算不完全在时间范围内的假期
  868. if($startTime){
  869. $jjmap2 = $jmap;
  870. $jjmap2[] = ['start_time','<',$startTime.' 00:00:00'];
  871. $jjmap2[] = ['end_time','>',$startTime.' 23:59:59'];
  872. $dlist = Db::name('attendance_leave')->where($jjmap2)->select();
  873. foreach ($dlist as $dk=>$dv){
  874. $d = calculate_leave($startTime.' 00:00:00',$dv['end_time'],$type); // 有效天数
  875. $cd = round($dv['cur_days']*$d/$dv['days'],2); // 实际有效天数
  876. $day2 += $cd;
  877. }
  878. }
  879. if($endTime){
  880. $jjmap2 = $jmap;
  881. $jjmap2[] = ['start_time','<',$endTime.' 00:00:00'];
  882. $jjmap2[] = ['end_time','>',$endTime.' 23:59:59'];
  883. $dlist = Db::name('attendance_leave')->where($jjmap2)->select();
  884. foreach ($dlist as $dk=>$dv){
  885. $d = calculate_leave($dv['start_time'],$endTime.' 23:59:59',$type); // 有效天数
  886. $cd = round($dv['cur_days']*$d/$dv['days'],2); // 实际有效天数
  887. $day2 += $cd;
  888. }
  889. }
  890. }
  891. $day = $day1 + $day2;
  892. }
  893. $lists[$k]['type'.$vv['id']] = $day;
  894. $tday += $day;
  895. }
  896. $lists[$k]['tday'] = $tday;
  897. }
  898. $columns = [
  899. ["title" => "姓名","key" => "name"],
  900. ["title" => "部门","key" => "dep"],
  901. ["title" => "当前剩余年假","key" => "annualLeave"],
  902. ["title" => "请假总天数","key" => "tday"],
  903. ];
  904. foreach ($types as $k=>$v){
  905. $columns[] = ["title" => $v['name'],"key" => "type".$v['id']];
  906. }
  907. $data = [
  908. 'columns' => $columns,
  909. 'list' => $lists
  910. ];
  911. return $data;
  912. }
  913. // 获取花名册导出列表
  914. public function exportRosterLists($orgId){
  915. $name = input('name','','trim');
  916. $code = input('code','','trim');
  917. $phone = input('phone','','trim');
  918. // $isWorking = input('isWorking','','trim');
  919. $startTime = input('startTime','','trim');
  920. $endTime = input('endTime','','trim');
  921. $gender = input('gender/d',0);
  922. $companyType = input('companyType/d',-1);
  923. if($companyType == 1){
  924. $map[] = ['ui.is_working','in',[1,2]];
  925. $map[] = ['ui.company_id','=',1];
  926. } else if($companyType == 2){
  927. $map[] = ['ui.is_working','=',4];
  928. $map[] = ['ui.company_id','=',1];
  929. } else if($companyType == 3){
  930. $map[] = ['ui.is_working','in',[1,2]];
  931. $map[] = ['ui.company_id','=',2];
  932. } else if($companyType == 4){
  933. $map[] = ['ui.is_working','in',[1,2]];
  934. $map[] = ['ui.company_id','=',0];
  935. }
  936. $job = input('job','','trim');
  937. $education = input('education','','trim');
  938. $profession = input('profession','','trim');
  939. $uids = model('User')->getAdminUsers();
  940. if($uids){
  941. $map[] = ['u.id','not in',$uids];
  942. }
  943. if($name){
  944. $map[] = ['ui.name','like','%'.$name.'%'];
  945. }
  946. if($code){
  947. $map[] = ['u.code','like','%'.$code.'%'];
  948. }
  949. if($phone){
  950. $map[] = ['u.phone','like','%'.$phone.'%'];
  951. }
  952. // if($isWorking){
  953. // $map[] = ['ui.is_working','=',$isWorking];
  954. // }
  955. // if($joinTime){
  956. // $map[] = ['ui.join_time','=',$joinTime];
  957. // }
  958. if($startTime){
  959. $map[] = ['ui.join_time','>=',$startTime];
  960. }
  961. if($endTime){
  962. $map[] = ['ui.join_time','<=',$endTime];
  963. }
  964. if($gender > 0){
  965. $map[] = ['ui.gender','=',$gender];
  966. }
  967. // if($companyId >= 0){
  968. // $map[] = ['ui.company_id','=',$companyId];
  969. // }
  970. if($job){
  971. $map[] = ['ui.job','like','%'.$job.'%'];
  972. }
  973. if($education){
  974. $map[] = ['ui.education','like','%'.$education.'%'];
  975. }
  976. if($profession){
  977. $map[] = ['ui.profession','like','%'.$profession.'%'];
  978. }
  979. $map[] = ['u.del','=',0];
  980. $map[] = ['r.type','=',3];
  981. $map[] = ['r.org_id','=',$orgId];
  982. $lists = Db::name('user_info')
  983. ->alias('ui')
  984. ->join('user u','ui.user_id = u.id')
  985. ->join('user_roles ur','ur.user_id = u.id')
  986. ->join('roles r','ur.roles_id = r.id')
  987. ->where($map)
  988. ->field('u.code,u.phone,ui.*')
  989. ->order('ui.sorts2 asc,u.id desc')
  990. ->select();
  991. $lists = $lists?$lists:[];
  992. foreach ($lists as $k=>$v){
  993. // 获取用户岗位
  994. $jlist = Db::name('user_job')
  995. ->alias('uj')
  996. ->join('job j','j.id = uj.job_id')
  997. ->join('dep d','d.id = j.dep_id')
  998. ->where('j.del',0)
  999. ->where('j.enable',1)
  1000. ->where('d.del',0)
  1001. ->where('d.enable',1)
  1002. ->where('uj.user_id',$v['user_id'])
  1003. ->field("d.name as dep,j.name as job")
  1004. ->select();
  1005. $jlist = $jlist?$jlist:[];
  1006. $deps = $jobs = [];
  1007. foreach ($jlist as $kk=>$vv){
  1008. $deps[] = $vv['dep'];
  1009. $jobs[] = $vv['job'];
  1010. }
  1011. $lists[$k]['dep'] = $deps?implode(',',$deps):'';
  1012. // $lists[$k]['job'] = $jobs?implode(',',$jobs):'';
  1013. $lists[$k]['company'] = '';
  1014. if($lists[$k]['company_id'] > 0){
  1015. $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title');
  1016. }
  1017. if($v['is_working'] == 1){
  1018. $lists[$k]['isWorkingText'] = '试用期';
  1019. }else if($v['is_working'] == 2){
  1020. $lists[$k]['isWorkingText'] = '正式';
  1021. }else if($v['is_working'] == 3){
  1022. $lists[$k]['isWorkingText'] = '离职';
  1023. }else if($v['is_working'] == 4){
  1024. $lists[$k]['isWorkingText'] = '退休';
  1025. }else{
  1026. $lists[$k]['isWorkingText'] = '';
  1027. }
  1028. if($v['gender'] == 1){
  1029. $lists[$k]['genderText'] = '男';
  1030. }else if($v['gender'] == 2){
  1031. $lists[$k]['genderText'] = '女';
  1032. }else{
  1033. $lists[$k]['genderText'] = '';
  1034. }
  1035. //1=管理人员 2=专业技术人员 3=工勤技能人员
  1036. if($v['type'] == 1){
  1037. $lists[$k]['typeText'] = '管理人员';
  1038. }else if($v['type'] == 2){
  1039. $lists[$k]['typeText'] = '专业技术人员';
  1040. }else if($v['type'] == 3){
  1041. $lists[$k]['typeText'] = '工勤技能人员';
  1042. }else{
  1043. $lists[$k]['typeText'] = '';
  1044. }
  1045. $lists[$k]['psName'] = '';
  1046. if($lists[$k]['psid'] > 0){
  1047. $lists[$k]['psName'] = Db::name('post_salary')->where('id',$v['psid'])->value('title');
  1048. }
  1049. $lists[$k]['jobDateText'] = '';
  1050. if($v['job'] || $v['job_date']){
  1051. $arr[$k]['jobDateText'] = $v['job'].'/'.$v['job_date'];
  1052. }
  1053. }
  1054. // $columns = [
  1055. // ["title" => "姓名","key" => "name"],
  1056. // ["title" => "工号","key" => "code"],
  1057. // ["title" => "手机号","key" => "phone"],
  1058. // ["title" => "状态","key" => "isWorkingText"],
  1059. // ["title" => "部门","key" => "dep"],
  1060. // ["title" => "岗位","key" => "job"],
  1061. // ["title" => "电子邮箱","key" => "email"],
  1062. // ["title" => "身份证号","key" => "idCard"],
  1063. // ["title" => "性别","key" => "genderText"],
  1064. // ["title" => "民族","key" => "nation"],
  1065. // ["title" => "籍贯","key" => "nativePlace"],
  1066. // ["title" => "生日","key" => "birthday"],
  1067. // ["title" => "最高学历","key" => "education"],
  1068. // ["title" => "最高学位","key" => "degree"],
  1069. // ["title" => "专业","key" => "profession"],
  1070. // ["title" => "入职日期","key" => "joinTime"],
  1071. // ["title" => "政治面貌","key" => "political"],
  1072. // ["title" => "入党时间","key" => "dangDate"],
  1073. // ["title" => "工作时间","key" => "workDate"],
  1074. // ["title" => "任现职时间","key" => "curJobDate"],
  1075. // ["title" => "专业技术职务","key" => "professionPosition"],
  1076. // ["title" => "评定时间","key" => "assessDate"],
  1077. // ["title" => "职业资格","key" => "qualification"],
  1078. // ["title" => "来办时间","key" => "lbDate"],
  1079. // ["title" => "进入形式","key" => "inShape"],
  1080. // ["title" => "同级职务时间","key" => "levelJobDate"],
  1081. // ["title" => "离职/退休日期","key" => "outTime"],
  1082. // ["title" => "离职原因","key" => "outReason"],
  1083. // ["title" => "婚姻状况","key" => "marital"],
  1084. // ["title" => "所属公司","key" => "company"],
  1085. // ["title" => "剩余年假","key" => "annualLeave"],
  1086. // ["title" => "岗位等级","key" => "psName"],
  1087. // ["title" => "薪级","key" => "pwlevel"],
  1088. // ["title" => "类型","key" => "typeText"],
  1089. // ["title" => "备注1","key" => "remark1"],
  1090. // ["title" => "备注2","key" => "remark2"],
  1091. // ["title" => "备注3","key" => "remark3"],
  1092. // ["title" => "备注4","key" => "remark4"],
  1093. // ["title" => "备注5","key" => "remark5"],
  1094. // ];
  1095. $columns = [
  1096. ["title" => "部门","key" => "dep"],
  1097. ["title" => "行政职务","key" => "position"],
  1098. ["title" => "姓名","key" => "name"],
  1099. ["title" => "岗位及时间","key" => "jobDateText"],
  1100. ["title" => "性别","key" => "genderText"],
  1101. ["title" => "民族","key" => "nation"],
  1102. ["title" => "籍贯","key" => "nativePlace"],
  1103. ["title" => "出生日期","key" => "birthday"],
  1104. ["title" => "身份证号码","key" => "idCard"],
  1105. ["title" => "年龄","key" => "age"],
  1106. ["title" => "学历","key" => "education"],
  1107. ["title" => "专业","key" => "profession"],
  1108. ["title" => "入党时间","key" => "dangDate"],
  1109. ["title" => "工作时间","key" => "workDate"],
  1110. ["title" => "任现职时间","key" => "curJobDate"],
  1111. ["title" => "专业技术职务","key" => "professionPosition"],
  1112. ["title" => "评定时间","key" => "assessDate"],
  1113. ["title" => "职业资格","key" => "qualification"],
  1114. ["title" => "来办时间","key" => "joinTime"],
  1115. ["title" => "进入形式","key" => "inShape"],
  1116. ["title" => "同级职务时间","key" => "levelJobDate"],
  1117. ];
  1118. $data = [
  1119. 'columns' => $columns,
  1120. 'list' => $lists
  1121. ];
  1122. return $data;
  1123. }
  1124. public function info($id){
  1125. $info = Db::name('user')
  1126. ->alias('u')
  1127. ->join('user_info ui','ui.user_id = u.id')
  1128. ->where('ui.id', $id)
  1129. ->where('u.del', 0)
  1130. ->field('u.sorts,u.code,u.phone,ui.*')
  1131. ->find();
  1132. if(!$info){
  1133. HelpHander::error('数据不存在');
  1134. }
  1135. $jobs = Db::name('user_job')
  1136. ->alias('uj')
  1137. ->join('job j','j.id = uj.job_id')
  1138. ->join('dep d','d.id = j.dep_id')
  1139. ->where('j.del',0)
  1140. ->where('j.enable',1)
  1141. ->where('d.del',0)
  1142. ->where('d.enable',1)
  1143. ->where('uj.user_id',$info['user_id'])
  1144. ->field('j.id as job_id,j.dep_id,j.name as jobName,d.name as depName')
  1145. ->select();
  1146. $info['jobs'] = $jobs?$jobs:[];
  1147. $info['company'] = '';
  1148. if($info['company_id'] > 0){
  1149. $info['company'] = Db::name('company')->where('id',$info['company_id'])->value('title');
  1150. }
  1151. $info['company2'] = '';
  1152. if($info['company_id2'] > 0){
  1153. $info['company2'] = Db::name('company')->where('id',$info['company_id2'])->value('title');
  1154. }
  1155. $info['pstitle'] = '';
  1156. $info['psjob'] = '';
  1157. if($info['company_id'] > 0){
  1158. $info['company'] = Db::name('company')->where('id',$info['company_id'])->value('title');
  1159. }
  1160. if($info['psid'] > 0){
  1161. $psinfo = Db::name('post_salary')->where('id',$info['psid'])->find();
  1162. $info['pstitle'] = $psinfo?$psinfo['title']:'';
  1163. $info['psjob'] = $psinfo?$psinfo['job']:'';
  1164. }
  1165. $info['age'] = $info['birthday']?calculate_age($info['birthday']):'';
  1166. $info['workAge'] = $info['work_date']?calculate_age($info['work_date']):'';
  1167. return $info;
  1168. }
  1169. public function edit($data,$id){
  1170. $result = validate('UserInfo')->check($data,[],'edit');
  1171. if(true !== $result){
  1172. HelpHander::error(validate('UserInfo')->getError());
  1173. }
  1174. if($data['id_card']){
  1175. $bd = get_birthday_sex_by_idcard($data['id_card']);
  1176. $data['birthday'] = $bd['birthday'];
  1177. $data['gender'] = $bd['gender'];
  1178. }
  1179. $sorts = $data['sorts'];
  1180. unset($data['sorts']);
  1181. $data['update_time'] = date('Y-m-d H:i:s');
  1182. $ret = $this->save($data,['id'=>$id]);
  1183. if(!$ret){
  1184. HelpHander::error('修改失败');
  1185. }
  1186. $userId = Db::name('user_info')->where('id',$id)->value('user_id');
  1187. Db::name('user')->where('id',$userId)->setField('sorts',$sorts);
  1188. $logdata = json_encode($data);
  1189. model('ActionLog')->add(5,'修改人员档案',0,$logdata);
  1190. return true;
  1191. }
  1192. public function changeSalary($data,$id,$userId,$orgId){
  1193. $info = Db::name('user_info')->where('id',$id)->find();
  1194. if(!$info){
  1195. HelpHander::error('记录不存在');
  1196. }
  1197. if($info['company_id'] == $data['company_id'] && $info['type'] == $data['type'] && $info['pwlevel'] == $data['pwlevel'] && $info['psid'] == $data['psid']){
  1198. HelpHander::error('岗位未作出任何变动');
  1199. }
  1200. Db::startTrans();
  1201. try{
  1202. $ssdata = [
  1203. 'company_id' => $data['company_id'],
  1204. 'type' => $data['type'],
  1205. 'pwlevel' => $data['pwlevel'],
  1206. 'psid' => $data['psid'],
  1207. 'update_time' => date('Y-m-d H:i:s')
  1208. ];
  1209. $ret = $this->save($ssdata,['id'=>$id]);
  1210. if(!$ret){
  1211. \exception('操作失败2');
  1212. }
  1213. $sdata = [
  1214. 'org_id' => $orgId,
  1215. 'user_id' => $info['user_id'],
  1216. 'psid' => $data['psid'],
  1217. 'create_user_id' => $userId,
  1218. 'pwlevel' => $data['pwlevel'],
  1219. 'imgs' => $data['imgs'],
  1220. 'remark' => $data['remark'],
  1221. 'create_time' => date('Y-m-d H:i:s'),
  1222. 'type' => $data['type']
  1223. ];
  1224. $res = Db::name('user_post_log')->insert($sdata);
  1225. if(!$res){
  1226. \exception('操作失败1');
  1227. }
  1228. Db::commit();
  1229. }catch (Exception $e){
  1230. Db::rollback();
  1231. HelpHander::error('操作失败'.$e);
  1232. }
  1233. return true;
  1234. }
  1235. public function salaryLogList($page,$size,$orgId,$userId=0){
  1236. $map[] = ['org_id','=',$orgId];
  1237. if($userId > 0){
  1238. $map[] = ['user_id','=',$userId];
  1239. }
  1240. $lists = Db::name('user_post_log')
  1241. ->where($map)
  1242. ->page($page,$size)
  1243. ->order('id desc')
  1244. ->select();
  1245. $lists = $lists?$lists:[];
  1246. foreach ($lists as $k=>$v){
  1247. $post = Db::name('post_salary')
  1248. ->alias('ps')
  1249. ->join('company c','c.id = ps.company_id')
  1250. ->field('ps.*,c.title as company')
  1251. ->where('ps.id',$v['psid'])
  1252. ->find();
  1253. $lists[$k]['title'] = $post['title'];
  1254. $lists[$k]['job'] = $post['job'];
  1255. $lists[$k]['company'] = $post['company'];
  1256. $lists[$k]['userName'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name');
  1257. $lists[$k]['createUserName'] = Db::name('user_info')->where('user_id',$v['create_user_id'])->value('name');
  1258. }
  1259. $total = Db::name('user_post_log')
  1260. ->where($map)->count();
  1261. $data = [
  1262. 'total' => $total,
  1263. 'list' => $lists?$lists:[]
  1264. ];
  1265. return $data;
  1266. }
  1267. public function advancedEndUserInfo($id,$orgId,$userId,$formJson){
  1268. $formJson = json_decode($formJson,true);
  1269. $type = '';
  1270. $outTime = '';
  1271. $outReason = '';
  1272. foreach ($formJson as $k=>$v){
  1273. if($v['componentName'] == 'dddeparturefield'){
  1274. foreach ($v['components'] as $key=>$val){
  1275. $val['values2'] = isset($val['values2'])?$val['values2']:[];
  1276. $val['values'] = isset($val['values'])?$val['values']:'';
  1277. switch ($val['idx']){
  1278. case '0':
  1279. $type = isset($val['values'])?$val['values']:'';
  1280. break;
  1281. case '1':
  1282. $outTime = isset($val['values'])?$val['values']:'';
  1283. break;
  1284. case '2':
  1285. $outReason = isset($val['values'])?$val['values']:'';
  1286. break;
  1287. }
  1288. }
  1289. break;
  1290. }
  1291. }
  1292. $data = [
  1293. 'out_time' => $outTime,
  1294. 'out_reason' => $outReason,
  1295. 'is_working' => 3 // 离职
  1296. ];
  1297. if($type == '退休'){
  1298. $data['is_working'] = 4;
  1299. }
  1300. $ret = Db::name('user_info')->where('user_id',$userId)->update($data);
  1301. if(!$ret){
  1302. return false;
  1303. }
  1304. $ret2 = Db::name('user')->where('id',$userId)->setField('enable',0);
  1305. return $ret2?true:false;
  1306. }
  1307. public function departure($data,$userId,$orgId){
  1308. $result = validate('UserInfo')->check($data,[],'departure');
  1309. if(true !== $result){
  1310. HelpHander::error(validate('UserInfo')->getError());
  1311. }
  1312. $user = Db::name('user')
  1313. ->alias('u')
  1314. ->join('user_info ui','u.id = ui.user_id')
  1315. ->where('u.id',$data['user_id'])
  1316. ->where('u.del',0)
  1317. ->field('u.id,u.enable,ui.is_working')
  1318. ->find();
  1319. if(!$user){
  1320. HelpHander::error('用户不存在');
  1321. }
  1322. if(!in_array($user['is_working'],[1,2])){
  1323. HelpHander::error('该状态无法办理离职');
  1324. }
  1325. Db::startTrans();
  1326. try{
  1327. $ret = Db::name('user')->where('id',$data['user_id'])->update(['enable'=>0,'update_time'=>date('Y-m-d H:i:s')]);
  1328. if(!$ret){
  1329. \exception('操作失败');
  1330. }
  1331. if($data['is_work'] == 0){
  1332. $isWorking = 3; // 离职
  1333. }else{
  1334. $isWorking = 4; // 退休
  1335. }
  1336. $res = Db::name('user_info')->where('user_id',$data['user_id'])->update([
  1337. 'is_working' => $isWorking,
  1338. 'out_time' => $data['out_time'],
  1339. 'out_reason' => $data['out_reason'],
  1340. ]);
  1341. if(!$res){
  1342. \exception('操作失败');
  1343. }
  1344. Db::commit();
  1345. }catch (Exception $e){
  1346. Db::rollback();
  1347. HelpHander::error($e->getMessage());
  1348. }
  1349. return true;
  1350. }
  1351. public function back($data,$userId,$orgId){
  1352. $result = validate('UserInfo')->check($data,[],'back');
  1353. if(true !== $result){
  1354. HelpHander::error(validate('UserInfo')->getError());
  1355. }
  1356. $user = Db::name('user')
  1357. ->alias('u')
  1358. ->join('user_info ui','u.id = ui.user_id')
  1359. ->where('u.id',$data['user_id'])
  1360. ->where('u.del',0)
  1361. ->field('u.id,u.enable,ui.is_working')
  1362. ->find();
  1363. if(!$user){
  1364. HelpHander::error('用户不存在');
  1365. }
  1366. if(!in_array($user['is_working'],[3,4])){
  1367. HelpHander::error('该状态无法重新入职');
  1368. }
  1369. Db::startTrans();
  1370. try{
  1371. $ret = Db::name('user')->where('id',$data['user_id'])->update(['enable'=>1,'update_time'=>date('Y-m-d H:i:s')]);
  1372. if(!$ret){
  1373. \exception('操作失败');
  1374. }
  1375. if($data['is_work'] == 0){
  1376. $isWorking = 1; // 试用期
  1377. }else{
  1378. $isWorking = 2; // 正式
  1379. }
  1380. $res = Db::name('user_info')->where('user_id',$data['user_id'])->update([
  1381. 'is_working' => $isWorking,
  1382. 'join_time' => $data['join_time']
  1383. ]);
  1384. if(!$res){
  1385. \exception('操作失败');
  1386. }
  1387. Db::commit();
  1388. }catch (Exception $e){
  1389. Db::rollback();
  1390. HelpHander::error($e->getMessage());
  1391. }
  1392. $logdata = json_encode($data);
  1393. model('ActionLog')->add(5,'人员重新入职',0,$logdata);
  1394. return true;
  1395. }
  1396. /**
  1397. * 根据所属公司获取在职人数
  1398. * @param $comapnyId
  1399. * @return float|string
  1400. */
  1401. public function getCountByCompany($comapnyId){
  1402. $map[] = ['u.del','=',0];
  1403. $map[] = ['u.enable','=',1];
  1404. $map[] = ['ui.is_working','in',[1,2]];
  1405. $map[] = ['ui.company_id','=',$comapnyId];
  1406. $count = Db::name('user')
  1407. ->alias('u')
  1408. ->join('user_info ui','ui.user_id = u.id')
  1409. ->where($map)
  1410. ->count();
  1411. return $count;
  1412. }
  1413. /**
  1414. * 根据性别获取在职人数
  1415. * @param $gender
  1416. * @return float|string
  1417. */
  1418. public function getCountByGender($gender){
  1419. $map[] = ['u.del','=',0];
  1420. $map[] = ['u.enable','=',1];
  1421. $map[] = ['ui.is_working','in',[1,2]];
  1422. $map[] = ['ui.gender','=',$gender];
  1423. $count = Db::name('user')
  1424. ->alias('u')
  1425. ->join('user_info ui','ui.user_id = u.id')
  1426. ->where($map)
  1427. ->count();
  1428. return $count;
  1429. }
  1430. public function getCountByGender2($company){
  1431. $map[] = ['u.del','=',0];
  1432. $map[] = ['u.enable','=',1];
  1433. $map[] = ['ui.is_working','in',[1,2]];
  1434. if($company > 0){
  1435. $map[] = ['ui.company_id','=',$company];
  1436. }
  1437. $count = Db::name('user')
  1438. ->alias('u')
  1439. ->join('user_info ui','ui.user_id = u.id')
  1440. ->where($map)
  1441. ->count();
  1442. $map[] = ['ui.gender','=',1];
  1443. $count1 = Db::name('user')
  1444. ->alias('u')
  1445. ->join('user_info ui','ui.user_id = u.id')
  1446. ->where($map)
  1447. ->count();
  1448. $count2 = $count - $count1;
  1449. return ['c1' => $count1,'c2' => $count2];
  1450. }
  1451. public function getDangStructure($company){
  1452. $map[] = ['u.del','=',0];
  1453. $map[] = ['u.enable','=',1];
  1454. $map[] = ['ui.is_working','in',[1,2]];
  1455. if($company > 0){
  1456. $map[] = ['ui.company_id','=',$company];
  1457. }
  1458. $count = Db::name('user')
  1459. ->alias('u')
  1460. ->join('user_info ui','ui.user_id = u.id')
  1461. ->where($map)
  1462. ->count();
  1463. $map[] = ['ui.dang_date','>',0];
  1464. $count1 = Db::name('user')
  1465. ->alias('u')
  1466. ->join('user_info ui','ui.user_id = u.id')
  1467. ->where($map)
  1468. ->count();
  1469. $count2 = $count - $count1;
  1470. return ['c1' => $count1,'c2' => $count2];
  1471. }
  1472. /**
  1473. * 根据在职状态获取在职人数
  1474. * @param $work
  1475. * @return float|string
  1476. */
  1477. public function getCountByWork($work){
  1478. $map[] = ['u.del','=',0];
  1479. if($work == 1||$work == 2){
  1480. $map[] = ['u.enable','=',1];
  1481. }
  1482. $map[] = ['ui.is_working','=',$work];
  1483. $count = Db::name('user')
  1484. ->alias('u')
  1485. ->join('user_info ui','ui.user_id = u.id')
  1486. ->where($map)
  1487. ->count();
  1488. return $count;
  1489. }
  1490. public function getCountByType($type){
  1491. $map[] = ['u.del','=',0];
  1492. $map[] = ['u.enable','=',1];
  1493. $map[] = ['ui.is_working','in',[1,2]];
  1494. $map[] = ['ui.type','=',$type];
  1495. $count = Db::name('user')
  1496. ->alias('u')
  1497. ->join('user_info ui','ui.user_id = u.id')
  1498. ->where($map)
  1499. ->count();
  1500. return $count;
  1501. }
  1502. public function changePayBatch($companyId, $userId, $orgId){
  1503. $uids = model('User')->getAdminUsers();
  1504. if($uids){
  1505. $map[] = ['u.id','not in',$uids];
  1506. }
  1507. $map[] = ['u.enable','=',1];
  1508. $map[] = ['u.del','=',0];
  1509. $map[] = ['r.type','=',3];
  1510. $map[] = ['r.org_id','=',$orgId];
  1511. $map[] = ['ui.company_id','=',$companyId];
  1512. $lists = Db::name('user_info')
  1513. ->alias('ui')
  1514. ->join('user u','ui.user_id = u.id')
  1515. ->join('user_roles ur','ur.user_id = u.id')
  1516. ->join('roles r','ur.roles_id = r.id')
  1517. ->where($map)
  1518. ->field('ui.id,ui.user_id,ui.type,ui.company_id,ui.pwlevel,ui.psid')
  1519. ->select();
  1520. $lists = $lists?$lists:[];
  1521. Db::startTrans();
  1522. try{
  1523. foreach ($lists as $k=>$v){
  1524. if(($v['type'] == 1||$v['type'] == 2) && $v['pwlevel'] >= 65){
  1525. continue;
  1526. }
  1527. if($v['company_id'] == 1 && $v['type'] == 3 && $v['pwlevel'] >= 40){
  1528. continue;
  1529. }
  1530. if($v['company_id'] == 2 && $v['type'] == 3 && $v['pwlevel'] >= 50){
  1531. continue;
  1532. }
  1533. $res = Db::name('user_info')->where('id',$v['id'])->update(['pwlevel'=>$v['pwlevel'] + 1]);
  1534. if(!$res){
  1535. \exception('操作失败');
  1536. }
  1537. $sdata = [
  1538. 'org_id' => $orgId,
  1539. 'user_id' => $v['user_id'],
  1540. 'psid' => $v['psid'],
  1541. 'create_user_id' => $userId,
  1542. 'pwlevel' => $v['pwlevel'],
  1543. 'remark' => '薪级普调',
  1544. 'create_time' => date('Y-m-d H:i:s'),
  1545. 'type' => $v['type']
  1546. ];
  1547. $res = Db::name('user_post_log')->insert($sdata);
  1548. if(!$res){
  1549. \exception('操作失败');
  1550. }
  1551. }
  1552. Db::commit();
  1553. }catch (Exception $e){
  1554. Db::rollback();
  1555. HelpHander::error($e->getMessage());
  1556. }
  1557. return true;
  1558. }
  1559. // 修改基础绩效或工资排序
  1560. public function changeFixed($id, $money, $type){
  1561. $info = Db::name('user_info')->where('id',$id)->find();
  1562. if(!$info){
  1563. HelpHander::error('参数错误');
  1564. }
  1565. if($type == 0){
  1566. $res = Db::name('user_info')->where('id',$id)->setField('fixed_performance',$money);
  1567. }else{
  1568. $res = Db::name('user_info')->where('id',$id)->setField('sorts3',$money);
  1569. }
  1570. if(!$res){
  1571. HelpHander::error('操作失败');
  1572. }
  1573. return true;
  1574. }
  1575. public function changeSortsFixed($id, $sorts2){
  1576. $info = Db::name('user_info')->where('id',$id)->find();
  1577. if(!$info){
  1578. HelpHander::error('参数错误');
  1579. }
  1580. if($info['sorts2'] === $sorts2){
  1581. return true;
  1582. }
  1583. $res = Db::name('user_info')->where('id',$id)->setField('sorts2',$sorts2);
  1584. if(!$res){
  1585. HelpHander::error('操作失败');
  1586. }
  1587. return true;
  1588. }
  1589. }