123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Exception;
- use think\Model;
- class UserInfo extends Model
- {
- // 获取普通用户列表
- public function lists($orgId){
- $page = input('page/d',1);
- $size = input('size/d',10);
- $name = input('name','','trim');
- $code = input('code','','trim');
- $phone = input('phone','','trim');
- $isWorking = input('isWorking','','trim');
- $startTime = input('startTime','','trim');
- $endTime = input('endTime','','trim');
- $gender = input('gender/d',0);
- $companyId = input('companyId/d',-1);
- $job = input('job','','trim');
- $education = input('education','','trim');
- $profession = input('profession','','trim');
- $uids = model('User')->getAdminUsers();
- if($uids){
- $map[] = ['u.id','not in',$uids];
- }
- if($name){
- $map[] = ['ui.name','like','%'.$name.'%'];
- }
- if($code){
- $map[] = ['u.code','like','%'.$code.'%'];
- }
- if($phone){
- $map[] = ['u.phone','like','%'.$phone.'%'];
- }
- if($isWorking){
- $map[] = ['ui.is_working','=',$isWorking];
- }
- // if($joinTime){
- // $map[] = ['ui.join_time','=',$joinTime];
- // }
- if($startTime){
- $map[] = ['ui.join_time','>=',$startTime];
- }
- if($endTime){
- $map[] = ['ui.join_time','<=',$endTime];
- }
- if($gender > 0){
- $map[] = ['ui.gender','=',$gender];
- }
- if($companyId >= 0){
- $map[] = ['ui.company_id','=',$companyId];
- }
- if($job){
- $map[] = ['ui.job','like','%'.$job.'%'];
- }
- if($education){
- $map[] = ['ui.education','like','%'.$education.'%'];
- }
- if($profession){
- $map[] = ['ui.profession','like','%'.$profession.'%'];
- }
- $sort = input('sort','','trim');
- $order = input('order','','trim');
- $orderby = '';
- if($sort == 'age' && in_array($order,['ascending','descending'])){
- $orderby = 'ui.birthday '.($order == 'ascending'?'desc':'asc').',';
- }
- $map[] = ['u.del','=',0];
- $map[] = ['r.type','=',3];
- $map[] = ['r.org_id','=',$orgId];
- $lists = Db::name('user_info')
- ->alias('ui')
- ->join('user u','ui.user_id = u.id')
- ->join('user_roles ur','ur.user_id = u.id')
- ->join('roles r','ur.roles_id = r.id')
- ->where($map)
- ->field('u.code,u.phone,u.enable,ui.*')
- ->page($page,$size)
- ->order($orderby.'u.sorts asc,ui.is_working asc,u.id desc')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- // 获取用户岗位
- $jlist = Db::name('user_job')
- ->alias('uj')
- ->join('job j','j.id = uj.job_id')
- ->join('dep d','d.id = j.dep_id')
- ->where('uj.user_id',$v['user_id'])
- ->where('j.del',0)
- ->where('j.enable',1)
- ->where('d.del',0)
- ->where('d.enable',1)
- ->field("d.name as dep,j.name as job")
- ->select();
- $jlist = $jlist?$jlist:[];
- $deps = $jobs = [];
- foreach ($jlist as $kk=>$vv){
- $deps[] = $vv['dep'];
- // $jobs[] = $vv['job'];
- }
- $lists[$k]['dep'] = $deps?implode(',',$deps):'';
- // $lists[$k]['job'] = $jobs?implode(',',$jobs):'';
- $lists[$k]['company'] = '';
- if($lists[$k]['company_id'] > 0){
- $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title');
- }
- $lists[$k]['psname'] = '';
- if($lists[$k]['psid'] > 0){
- $lists[$k]['psname'] = Db::name('post_salary')->where('id',$v['psid'])->value('job');
- }
- $lists[$k]['age'] = $v['birthday']?calculate_age($v['birthday']):'';
- }
- $total = Db::name('user_info')
- ->alias('ui')
- ->join('user u','ui.user_id = u.id')
- ->join('user_roles ur','ur.user_id = u.id')
- ->join('roles r','ur.roles_id = r.id')
- ->where($map)
- ->count();
- $data = [
- 'total' => $total,
- 'list' => $lists?$lists:[]
- ];
- return $data;
- }
- // 获取普通用户假期统计列表
- public function listsholiday($orgId){
- $page = input('page/d',1);
- $size = input('size/d',10);
- $name = input('name','','trim');
- $code = input('code','','trim');
- $phone = input('phone','','trim');
- $isWorking = input('isWorking','','trim');
- $startTime = input('startTime','','trim');
- $endTime = input('endTime','','trim');
- $gender = input('gender/d',0);
- $companyId = input('companyId/d',-1);
- $job = input('job','','trim');
- $education = input('education','','trim');
- $profession = input('profession','','trim');
- $uids = model('User')->getAdminUsers();
- if($uids){
- $map[] = ['u.id','not in',$uids];
- }
- if($name){
- $map[] = ['ui.name','like','%'.$name.'%'];
- }
- if($code){
- $map[] = ['u.code','like','%'.$code.'%'];
- }
- if($phone){
- $map[] = ['u.phone','like','%'.$phone.'%'];
- }
- if($isWorking){
- $map[] = ['ui.is_working','=',$isWorking];
- }
- // if($joinTime){
- // $map[] = ['ui.join_time','=',$joinTime];
- // }
- // if($startTime){
- // $map[] = ['ui.join_time','>=',$startTime];
- // }
- // if($endTime){
- // $map[] = ['ui.join_time','<=',$endTime];
- // }
- if($gender > 0){
- $map[] = ['ui.gender','=',$gender];
- }
- if($companyId >= 0){
- $map[] = ['ui.company_id','=',$companyId];
- }
- // if($job){
- // $map[] = ['ui.job','like','%'.$job.'%'];
- // }
- if($job){
- $map[] = ['d.name','like','%'.$job.'%'];
- }
- if($education){
- $map[] = ['ui.education','like','%'.$education.'%'];
- }
- if($profession){
- $map[] = ['ui.profession','like','%'.$profession.'%'];
- }
- $sort = input('sort','','trim');
- $order = input('order','','trim');
- $orderby = '';
- if($sort == 'age' && in_array($order,['ascending','descending'])){
- $orderby = 'ui.birthday '.($order == 'ascending'?'desc':'asc').',';
- }
- $map[] = ['u.del','=',0];
- $map[] = ['r.type','=',3];
- $map[] = ['r.org_id','=',$orgId];
- $types = Db::name('attendance_leave_type')->where('enable',1)->where('del',0)->select();
- $types = $types?$types:[];
- $lists = Db::name('user_info')
- ->alias('ui')
- ->join('user u','ui.user_id = u.id')
- ->join('user_roles ur','ur.user_id = u.id')
- ->join('roles r','ur.roles_id = r.id')
- ->join('user_job uj','uj.user_id = u.id','left')
- ->join('job j','uj.job_id = j.id','left')
- ->join('dep d','j.dep_id = d.id','left')
- ->where($map)
- ->field('u.code,u.phone,u.enable,ui.*')
- ->page($page,$size)
- ->group('u.id')
- ->order($orderby.'u.sorts asc,ui.is_working asc,u.id desc')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- // 获取用户岗位
- $jlist = Db::name('user_job')
- ->alias('uj')
- ->join('job j','j.id = uj.job_id')
- ->join('dep d','d.id = j.dep_id')
- ->where('uj.user_id',$v['user_id'])
- ->where('j.del',0)
- ->where('j.enable',1)
- ->where('d.del',0)
- ->where('d.enable',1)
- ->field("d.name as dep,j.name as job")
- ->select();
- $jlist = $jlist?$jlist:[];
- $deps = $jobs = [];
- foreach ($jlist as $kk=>$vv){
- $deps[] = $vv['dep'];
- }
- $lists[$k]['dep'] = $deps?implode(',',$deps):'';
- $tday = 0;
- foreach ($types as $kk=>$vv){
- $jmap = [];
- $jmap[] = ['status','=',1];
- $jmap[] = ['user_id','=',$v['user_id']];
- $jmap[] = ['leave_type','=',$vv['id']];
- $startTime = $startTime?date('Y-m-d',strtotime($startTime)):'';
- $endTime = $endTime?date('Y-m-d',strtotime($endTime)):'';
- if(!$startTime && !$endTime){
- $day = Db::name('attendance_leave')->where($jmap)->sum('cur_days');
- }else{
- $jjmap = $jmap;
- if($startTime){
- $jjmap[] = ['start_time','>=',$startTime.' 00:00:00'];
- }
- if($endTime){
- $jjmap[] = ['end_time','<=',$endTime.' 23:59:59'];
- }
- $day1 = 0; // 先计算完全在时间范围内的假期
- $day2 = 0; // 不再时间内的假期平均分配
- if($startTime || $endTime){ // 1先计算完全在时间范围内的假期
- $day1 = Db::name('attendance_leave')->where($jjmap)->sum('cur_days');
- // 计算有效假期,最后按比例分配
- $type = $vv['id'] == 6?0:1; // 产假,不减节假日
- // 2再计算不完全在时间范围内的假期
- if($startTime){
- $jjmap2 = $jmap;
- $jjmap2[] = ['start_time','<',$startTime.' 00:00:00'];
- $jjmap2[] = ['end_time','>',$startTime.' 23:59:59'];
- $dlist = Db::name('attendance_leave')->where($jjmap2)->select();
- foreach ($dlist as $dk=>$dv){
- $d = calculate_leave($startTime.' 00:00:00',$dv['end_time'],$type); // 有效天数
- $cd = round($dv['cur_days']*$d/$dv['days'],2); // 实际有效天数
- $day2 += $cd;
- }
- }
- if($endTime){
- $jjmap2 = $jmap;
- $jjmap2[] = ['start_time','<',$endTime.' 00:00:00'];
- $jjmap2[] = ['end_time','>',$endTime.' 23:59:59'];
- $dlist = Db::name('attendance_leave')->where($jjmap2)->select();
- foreach ($dlist as $dk=>$dv){
- $d = calculate_leave($dv['start_time'],$endTime.' 23:59:59',$type); // 有效天数
- $cd = round($dv['cur_days']*$d/$dv['days'],2); // 实际有效天数
- $day2 += $cd;
- }
- }
- }
- $day = $day1 + $day2;
- }
- $lists[$k]['type'.$vv['id']] = $day;
- $tday += $day;
- }
- $lists[$k]['tday'] = $tday;
- }
- $total = Db::name('user_info')
- ->alias('ui')
- ->join('user u','ui.user_id = u.id')
- ->join('user_roles ur','ur.user_id = u.id')
- ->join('roles r','ur.roles_id = r.id')
- ->join('user_job uj','uj.user_id = u.id','left')
- ->join('job j','uj.job_id = j.id','left')
- ->join('dep d','j.dep_id = d.id','left')
- ->where($map)
- ->group('u.id')
- ->count();
- $data = [
- 'total' => $total,
- 'list' => $lists?$lists:[],
- 'types' => $types
- ];
- return $data;
- }
- // 花用户列表
- public function rosterLists($orgId){
- $page = input('page/d',1);
- $size = input('size/d',10);
- $name = input('name','','trim');
- $code = input('code','','trim');
- $phone = input('phone','','trim');
- $isWorking = input('isWorking','','trim');
- $startTime = input('startTime','','trim');
- $endTime = input('endTime','','trim');
- $gender = input('gender/d',0);
- $companyType = input('companyType/d',-1);
- if($companyType == 1){
- $map[] = ['ui.company_id','=',1];
- $map[] = ['ui.is_working','in',[1,2]];
- }else if($companyType == 2){
- $map[] = ['ui.company_id','=',1];
- $map[] = ['ui.is_working','=',4];
- }else if($companyType == 3){
- $map[] = ['ui.company_id','=',2];
- $map[] = ['ui.is_working','in',[1,2]];
- }else if($companyType == 4){
- $map[] = ['ui.company_id','=',0];
- $map[] = ['ui.is_working','in',[1,2]];
- }
- $job = input('job','','trim');
- $education = input('education','','trim');
- $profession = input('profession','','trim');
- $uids = model('User')->getAdminUsers();
- if($uids){
- $map[] = ['u.id','not in',$uids];
- }
- if($name){
- $map[] = ['ui.name','like','%'.$name.'%'];
- }
- if($code){
- $map[] = ['u.code','like','%'.$code.'%'];
- }
- if($phone){
- $map[] = ['u.phone','like','%'.$phone.'%'];
- }
- // if($isWorking){
- // $map[] = ['ui.is_working','=',$isWorking];
- // }
- // if($joinTime){
- // $map[] = ['ui.join_time','=',$joinTime];
- // }
- if($startTime){
- $map[] = ['ui.join_time','>=',$startTime];
- }
- if($endTime){
- $map[] = ['ui.join_time','<=',$endTime];
- }
- if($gender > 0){
- $map[] = ['ui.gender','=',$gender];
- }
- // if($companyId >= 0){
- // $map[] = ['ui.company_id','=',$companyId];
- // }
- if($job){
- $map[] = ['ui.job','like','%'.$job.'%'];
- }
- if($education){
- $map[] = ['ui.education','like','%'.$education.'%'];
- }
- if($profession){
- $map[] = ['ui.profession','like','%'.$profession.'%'];
- }
- $prop = input('prop','','trim');
- $order = input('order','','trim');
- if($prop == 'birthday'){
- $prop = 'ui.birthday';
- }else if($prop == 'age'){
- $prop = 'ui.birthday';
- }else if($prop == 'workDate'){
- $prop = 'ui.work_date';
- }else if($prop == 'dangDate'){
- $prop = 'ui.dang_date';
- }
- if($prop && $order == 'ascending'){
- $orderby = $prop.' asc,ui.sorts2 asc, u.id desc';
- }else if($prop && $order == 'descending'){
- $orderby = $prop.' desc,ui.sorts2 asc, u.id desc';
- }else{
- $orderby = 'ui.sorts2 asc,u.id desc';
- }
- $map[] = ['u.del','=',0];
- $map[] = ['r.type','=',3];
- $map[] = ['r.org_id','=',$orgId];
- $lists = Db::name('user_info')
- ->alias('ui')
- ->join('user u','ui.user_id = u.id')
- ->join('user_roles ur','ur.user_id = u.id')
- ->join('roles r','ur.roles_id = r.id')
- ->where($map)
- ->field('u.code,u.phone,u.enable,ui.*')
- ->page($page,$size)
- ->order($orderby)
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- // 获取用户岗位
- $jlist = Db::name('user_job')
- ->alias('uj')
- ->join('job j','j.id = uj.job_id')
- ->join('dep d','d.id = j.dep_id')
- ->where('j.del',0)
- ->where('j.enable',1)
- ->where('d.del',0)
- ->where('d.enable',1)
- ->where('uj.user_id',$v['user_id'])
- ->field("d.name as dep,j.name as job")
- ->select();
- $jlist = $jlist?$jlist:[];
- $deps = $jobs = [];
- foreach ($jlist as $kk=>$vv){
- $deps[] = $vv['dep'];
- // $jobs[] = $vv['job'];
- }
- $lists[$k]['dep'] = $deps?implode(',',$deps):'';
- // $lists[$k]['job'] = $jobs?implode(',',$jobs):'';
- $lists[$k]['company'] = '';
- if($lists[$k]['company_id'] > 0){
- $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title');
- }
- $lists[$k]['psname'] = '';
- if($lists[$k]['psid'] > 0){
- $lists[$k]['psname'] = Db::name('post_salary')->where('id',$v['psid'])->value('job');
- }
- $lists[$k]['age'] = $v['birthday']?calculate_age($v['birthday']):'';
- }
- $total = Db::name('user_info')
- ->alias('ui')
- ->join('user u','ui.user_id = u.id')
- ->join('user_roles ur','ur.user_id = u.id')
- ->join('roles r','ur.roles_id = r.id')
- ->where($map)
- ->count();
- $data = [
- 'total' => $total,
- 'list' => $lists?$lists:[]
- ];
- return $data;
- }
- // 获取普通用户薪资岗位列表
- public function lists2($orgId){
- $page = input('page/d',1);
- $size = input('size/d',10);
- $name = input('name','','trim');
- $payType = input('payType/d',-1);
- $type = input('type/d',0);
- $companyId = input('companyId/d',-1);
- $uids = model('User')->getAdminUsers();
- if($uids){
- $map[] = ['u.id','not in',$uids];
- }
- if($name){
- $map[] = ['ui.name','like','%'.$name.'%'];
- }
- if($payType >= 0){
- $map[] = ['ui.pay_type','=',$payType];
- }
- if($companyId >= 0){
- $map[] = ['ui.company_id','=',$companyId];
- }
- if($type){
- $map[] = ['ui.type','=',$type];
- }
- $map[] = ['u.del','=',0];
- $map[] = ['r.type','=',3];
- $map[] = ['r.org_id','=',$orgId];
- $lists = Db::name('user_info')
- ->alias('ui')
- ->join('user u','ui.user_id = u.id')
- ->join('user_roles ur','ur.user_id = u.id')
- ->join('roles r','ur.roles_id = r.id')
- ->where($map)
- ->field('u.code,u.phone,u.enable,ui.*')
- ->page($page,$size)
- ->order('ui.sorts3 asc,u.id desc')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- $lists[$k]['company'] = '';
- if($lists[$k]['company_id'] > 0){
- $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title');
- }
- $lists[$k]['work_age'] = $v['work_date']?calculate_age($v['work_date']):0; // 工龄
- $lists[$k]['psname'] = '';
- $lists[$k]['psmonth'] = '';
- $lists[$k]['psmoney'] = 0;
- if($lists[$k]['psid'] > 0){
- $psinfo = Db::name('post_salary')->where('id',$v['psid'])->find();
- if($psinfo){
- $lists[$k]['psname'] = $psinfo['job'];
- $lists[$k]['psmoney'] = $psinfo['money'];
- $lists[$k]['psmonth'] = $psinfo['month_performance'];
- if($lists[$k]['work_age'] > 25 && $psinfo['month_performance2'] > 0){
- $lists[$k]['psmonth'] = $psinfo['month_performance2'];
- }
- }
- }
- $lists[$k]['pay_wages'] = [];
- $lists[$k]['pwmoney'] = 0;
- if($v['type'] > 0 && $v['company_id'] > 0){
- $pay_wages = Db::name('pay_wages')
- ->where('company_id',$v['company_id'])
- ->where('type',$v['type'])
- ->value('content');
- $pay_wages = $pay_wages?json_decode($pay_wages,true):[];
- $lists[$k]['pay_wages'] = $pay_wages;
- foreach ($pay_wages as $kk=>$vv){
- if($v['pwlevel'] == $vv['level']){
- $lists[$k]['pwmoney'] = $vv['money'];
- break;
- }
- }
- }
- }
- $total = Db::name('user_info')
- ->alias('ui')
- ->join('user u','ui.user_id = u.id')
- ->join('user_roles ur','ur.user_id = u.id')
- ->join('roles r','ur.roles_id = r.id')
- ->where($map)
- ->count();
- $data = [
- 'total' => $total,
- 'list' => $lists?$lists:[]
- ];
- return $data;
- }
- public function all($orgId,$companyId){
- $uids = model('User')->getAdminUsers();
- if($uids){
- $map[] = ['u.id','not in',$uids];
- }
- if($companyId >= 0){
- $map[] = ['ui.company_id','=',$companyId];
- }
- $map[] = ['u.del','=',0];
- $map[] = ['r.type','=',3];
- $map[] = ['r.org_id','=',$orgId];
- $lists = Db::name('user_info')
- ->alias('ui')
- ->join('user u','ui.user_id = u.id')
- ->join('user_roles ur','ur.user_id = u.id')
- ->join('roles r','ur.roles_id = r.id')
- ->where($map)
- ->field('u.code,u.phone,ui.*')
- ->order('u.id desc')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- // 获取用户岗位
- $jlist = Db::name('user_job')
- ->alias('uj')
- ->join('job j','j.id = uj.job_id')
- ->join('dep d','d.id = j.dep_id')
- ->where('j.del',0)
- ->where('j.enable',1)
- ->where('d.del',0)
- ->where('d.enable',1)
- ->where('uj.user_id',$v['user_id'])
- ->field("d.name as dep,j.name as job")
- ->select();
- $jlist = $jlist?$jlist:[];
- $deps = $jobs = [];
- foreach ($jlist as $kk=>$vv){
- $deps[] = $vv['dep'];
- }
- $lists[$k]['dep'] = $deps?implode(',',$deps):'';
- $lists[$k]['company'] = '';
- if($lists[$k]['company_id'] > 0){
- $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title');
- }
- $lists[$k]['age'] = $v['birthday']?calculate_age($v['birthday']):'';
- }
- return $lists;
- }
- // 获取普通用户导出列表
- public function exportLists($orgId){
- $name = input('name','','trim');
- $code = input('code','','trim');
- $phone = input('phone','','trim');
- $isWorking = input('isWorking','','trim');
- $startTime = input('startTime','','trim');
- $endTime = input('endTime','','trim');
- $gender = input('gender/d',0);
- $companyId = input('companyId/d',-1);
- $job = input('job','','trim');
- $education = input('education','','trim');
- $profession = input('profession','','trim');
- $uids = model('User')->getAdminUsers();
- if($uids){
- $map[] = ['u.id','not in',$uids];
- }
- if($name){
- $map[] = ['ui.name','like','%'.$name.'%'];
- }
- if($code){
- $map[] = ['u.code','like','%'.$code.'%'];
- }
- if($phone){
- $map[] = ['u.phone','like','%'.$phone.'%'];
- }
- if($isWorking){
- $map[] = ['ui.is_working','=',$isWorking];
- }
- // if($joinTime){
- // $map[] = ['ui.join_time','=',$joinTime];
- // }
- if($startTime){
- $map[] = ['ui.join_time','>=',$startTime];
- }
- if($endTime){
- $map[] = ['ui.join_time','<=',$endTime];
- }
- if($gender > 0){
- $map[] = ['ui.gender','=',$gender];
- }
- if($companyId >= 0){
- $map[] = ['ui.company_id','=',$companyId];
- }
- if($job){
- $map[] = ['ui.job','like','%'.$job.'%'];
- }
- if($education){
- $map[] = ['ui.education','like','%'.$education.'%'];
- }
- if($profession){
- $map[] = ['ui.profession','like','%'.$profession.'%'];
- }
- $map[] = ['u.del','=',0];
- $map[] = ['r.type','=',3];
- $map[] = ['r.org_id','=',$orgId];
- $lists = Db::name('user_info')
- ->alias('ui')
- ->join('user u','ui.user_id = u.id')
- ->join('user_roles ur','ur.user_id = u.id')
- ->join('roles r','ur.roles_id = r.id')
- ->where($map)
- ->field('u.code,u.phone,ui.*')
- ->order('ui.is_working asc,u.id desc')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- // 获取用户岗位
- $jlist = Db::name('user_job')
- ->alias('uj')
- ->join('job j','j.id = uj.job_id')
- ->join('dep d','d.id = j.dep_id')
- ->where('j.del',0)
- ->where('j.enable',1)
- ->where('d.del',0)
- ->where('d.enable',1)
- ->where('uj.user_id',$v['user_id'])
- ->field("d.name as dep,j.name as job")
- ->select();
- $jlist = $jlist?$jlist:[];
- $deps = $jobs = [];
- foreach ($jlist as $kk=>$vv){
- $deps[] = $vv['dep'];
- $jobs[] = $vv['job'];
- }
- $lists[$k]['dep'] = $deps?implode(',',$deps):'';
- // $lists[$k]['job'] = $jobs?implode(',',$jobs):'';
- $lists[$k]['company'] = '';
- if($lists[$k]['company_id'] > 0){
- $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title');
- }
- if($v['is_working'] == 1){
- $lists[$k]['isWorkingText'] = '试用期';
- }else if($v['is_working'] == 2){
- $lists[$k]['isWorkingText'] = '正式';
- }else if($v['is_working'] == 3){
- $lists[$k]['isWorkingText'] = '离职';
- }else if($v['is_working'] == 4){
- $lists[$k]['isWorkingText'] = '退休';
- }else{
- $lists[$k]['isWorkingText'] = '';
- }
- if($v['gender'] == 1){
- $lists[$k]['genderText'] = '男';
- }else if($v['gender'] == 2){
- $lists[$k]['genderText'] = '女';
- }else{
- $lists[$k]['genderText'] = '';
- }
- //1=管理人员 2=专业技术人员 3=工勤技能人员
- if($v['type'] == 1){
- $lists[$k]['typeText'] = '管理人员';
- }else if($v['type'] == 2){
- $lists[$k]['typeText'] = '专业技术人员';
- }else if($v['type'] == 3){
- $lists[$k]['typeText'] = '工勤技能人员';
- }else{
- $lists[$k]['typeText'] = '';
- }
- $lists[$k]['psName'] = '';
- if($lists[$k]['psid'] > 0){
- $lists[$k]['psName'] = Db::name('post_salary')->where('id',$v['psid'])->value('title');
- }
- $lists[$k]['jobDateText'] = '';
- if($v['job'] || $v['job_date']){
- $arr[$k]['jobDateText'] = $v['job'].'/'.$v['job_date'];
- }
- }
- $columns = [
- ["title" => "部门","key" => "dep"],
- ["title" => "行政职务","key" => "position"],
- ["title" => "姓名","key" => "name"],
- ["title" => "岗位及时间","key" => "jobDateText"],
- ["title" => "性别","key" => "genderText"],
- ["title" => "民族","key" => "nation"],
- ["title" => "籍贯","key" => "nativePlace"],
- ["title" => "出生日期","key" => "birthday"],
- ["title" => "身份证号码","key" => "idCard"],
- ["title" => "年龄","key" => "age"],
- ["title" => "学历","key" => "education"],
- ["title" => "专业","key" => "profession"],
- ["title" => "入党时间","key" => "dangDate"],
- ["title" => "工作时间","key" => "workDate"],
- ["title" => "任现职时间","key" => "curJobDate"],
- ["title" => "专业技术职务","key" => "professionPosition"],
- ["title" => "评定时间","key" => "assessDate"],
- ["title" => "职业资格","key" => "qualification"],
- ["title" => "来办时间","key" => "joinTime"],
- ["title" => "进入形式","key" => "inShape"],
- ["title" => "同级职务时间","key" => "levelJobDate"],
- ];
- $data = [
- 'columns' => $columns,
- 'list' => $lists
- ];
- return $data;
- }
- public function exportHolidayLists($orgId){
- // $page = input('page/d',1);
- // $size = input('size/d',10);
- $name = input('name','','trim');
- $code = input('code','','trim');
- $phone = input('phone','','trim');
- $isWorking = input('isWorking','','trim');
- $startTime = input('startTime','','trim');
- $endTime = input('endTime','','trim');
- $gender = input('gender/d',0);
- $companyId = input('companyId/d',-1);
- $job = input('job','','trim');
- $education = input('education','','trim');
- $profession = input('profession','','trim');
- $uids = model('User')->getAdminUsers();
- if($uids){
- $map[] = ['u.id','not in',$uids];
- }
- if($name){
- $map[] = ['ui.name','like','%'.$name.'%'];
- }
- if($code){
- $map[] = ['u.code','like','%'.$code.'%'];
- }
- if($phone){
- $map[] = ['u.phone','like','%'.$phone.'%'];
- }
- if($isWorking){
- $map[] = ['ui.is_working','=',$isWorking];
- }
- // if($joinTime){
- // $map[] = ['ui.join_time','=',$joinTime];
- // }
- // if($startTime){
- // $map[] = ['ui.join_time','>=',$startTime];
- // }
- // if($endTime){
- // $map[] = ['ui.join_time','<=',$endTime];
- // }
- if($gender > 0){
- $map[] = ['ui.gender','=',$gender];
- }
- if($companyId >= 0){
- $map[] = ['ui.company_id','=',$companyId];
- }
- // if($job){
- // $map[] = ['ui.job','like','%'.$job.'%'];
- // }
- if($job){
- $map[] = ['d.name','like','%'.$job.'%'];
- }
- if($education){
- $map[] = ['ui.education','like','%'.$education.'%'];
- }
- if($profession){
- $map[] = ['ui.profession','like','%'.$profession.'%'];
- }
- $sort = input('sort','','trim');
- $order = input('order','','trim');
- $orderby = '';
- if($sort == 'age' && in_array($order,['ascending','descending'])){
- $orderby = 'ui.birthday '.($order == 'ascending'?'desc':'asc').',';
- }
- $map[] = ['u.del','=',0];
- $map[] = ['r.type','=',3];
- $map[] = ['r.org_id','=',$orgId];
- $types = Db::name('attendance_leave_type')->where('enable',1)->where('del',0)->select();
- $types = $types?$types:[];
- $lists = Db::name('user_info')
- ->alias('ui')
- ->join('user u','ui.user_id = u.id')
- ->join('user_roles ur','ur.user_id = u.id')
- ->join('roles r','ur.roles_id = r.id')
- ->join('user_job uj','uj.user_id = u.id','left')
- ->join('job j','uj.job_id = j.id','left')
- ->join('dep d','j.dep_id = d.id','left')
- ->where($map)
- ->field('u.code,u.phone,u.enable,ui.*')
- ->group('u.id')
- // ->page($page,$size)
- ->order($orderby.'u.sorts asc,ui.is_working asc,u.id desc')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- // 获取用户岗位
- $jlist = Db::name('user_job')
- ->alias('uj')
- ->join('job j','j.id = uj.job_id')
- ->join('dep d','d.id = j.dep_id')
- ->where('uj.user_id',$v['user_id'])
- ->where('j.del',0)
- ->where('j.enable',1)
- ->where('d.del',0)
- ->where('d.enable',1)
- ->field("d.name as dep,j.name as job")
- ->select();
- $jlist = $jlist?$jlist:[];
- $deps = $jobs = [];
- foreach ($jlist as $kk=>$vv){
- $deps[] = $vv['dep'];
- }
- $lists[$k]['dep'] = $deps?implode(',',$deps):'';
- $tday = 0;
- foreach ($types as $kk=>$vv){
- $jmap = [];
- $jmap[] = ['status','=',1];
- $jmap[] = ['user_id','=',$v['user_id']];
- $jmap[] = ['leave_type','=',$vv['id']];
- $startTime = $startTime?date('Y-m-d',strtotime($startTime)):'';
- $endTime = $endTime?date('Y-m-d',strtotime($endTime)):'';
- if(!$startTime && !$endTime){
- $day = Db::name('attendance_leave')->where($jmap)->sum('cur_days');
- }else{
- $jjmap = $jmap;
- if($startTime){
- $jjmap[] = ['start_time','>=',$startTime.' 00:00:00'];
- }
- if($endTime){
- $jjmap[] = ['end_time','<=',$endTime.' 23:59:59'];
- }
- $day1 = 0; // 先计算完全在时间范围内的假期
- $day2 = 0; // 不再时间内的假期平均分配
- if($startTime || $endTime){ // 1先计算完全在时间范围内的假期
- $day1 = Db::name('attendance_leave')->where($jjmap)->sum('cur_days');
- // 计算有效假期,最后按比例分配
- $type = $vv['id'] == 6?0:1; // 产假,不减节假日
- // 2再计算不完全在时间范围内的假期
- if($startTime){
- $jjmap2 = $jmap;
- $jjmap2[] = ['start_time','<',$startTime.' 00:00:00'];
- $jjmap2[] = ['end_time','>',$startTime.' 23:59:59'];
- $dlist = Db::name('attendance_leave')->where($jjmap2)->select();
- foreach ($dlist as $dk=>$dv){
- $d = calculate_leave($startTime.' 00:00:00',$dv['end_time'],$type); // 有效天数
- $cd = round($dv['cur_days']*$d/$dv['days'],2); // 实际有效天数
- $day2 += $cd;
- }
- }
- if($endTime){
- $jjmap2 = $jmap;
- $jjmap2[] = ['start_time','<',$endTime.' 00:00:00'];
- $jjmap2[] = ['end_time','>',$endTime.' 23:59:59'];
- $dlist = Db::name('attendance_leave')->where($jjmap2)->select();
- foreach ($dlist as $dk=>$dv){
- $d = calculate_leave($dv['start_time'],$endTime.' 23:59:59',$type); // 有效天数
- $cd = round($dv['cur_days']*$d/$dv['days'],2); // 实际有效天数
- $day2 += $cd;
- }
- }
- }
- $day = $day1 + $day2;
- }
- $lists[$k]['type'.$vv['id']] = $day;
- $tday += $day;
- }
- $lists[$k]['tday'] = $tday;
- }
- $columns = [
- ["title" => "姓名","key" => "name"],
- ["title" => "部门","key" => "dep"],
- ["title" => "当前剩余年假","key" => "annualLeave"],
- ["title" => "请假总天数","key" => "tday"],
- ];
- foreach ($types as $k=>$v){
- $columns[] = ["title" => $v['name'],"key" => "type".$v['id']];
- }
- $data = [
- 'columns' => $columns,
- 'list' => $lists
- ];
- return $data;
- }
- // 获取花名册导出列表
- public function exportRosterLists($orgId){
- $name = input('name','','trim');
- $code = input('code','','trim');
- $phone = input('phone','','trim');
- // $isWorking = input('isWorking','','trim');
- $startTime = input('startTime','','trim');
- $endTime = input('endTime','','trim');
- $gender = input('gender/d',0);
- $companyType = input('companyType/d',-1);
- if($companyType == 1){
- $map[] = ['ui.is_working','in',[1,2]];
- $map[] = ['ui.company_id','=',1];
- } else if($companyType == 2){
- $map[] = ['ui.is_working','=',4];
- $map[] = ['ui.company_id','=',1];
- } else if($companyType == 3){
- $map[] = ['ui.is_working','in',[1,2]];
- $map[] = ['ui.company_id','=',2];
- } else if($companyType == 4){
- $map[] = ['ui.is_working','in',[1,2]];
- $map[] = ['ui.company_id','=',0];
- }
- $job = input('job','','trim');
- $education = input('education','','trim');
- $profession = input('profession','','trim');
- $uids = model('User')->getAdminUsers();
- if($uids){
- $map[] = ['u.id','not in',$uids];
- }
- if($name){
- $map[] = ['ui.name','like','%'.$name.'%'];
- }
- if($code){
- $map[] = ['u.code','like','%'.$code.'%'];
- }
- if($phone){
- $map[] = ['u.phone','like','%'.$phone.'%'];
- }
- // if($isWorking){
- // $map[] = ['ui.is_working','=',$isWorking];
- // }
- // if($joinTime){
- // $map[] = ['ui.join_time','=',$joinTime];
- // }
- if($startTime){
- $map[] = ['ui.join_time','>=',$startTime];
- }
- if($endTime){
- $map[] = ['ui.join_time','<=',$endTime];
- }
- if($gender > 0){
- $map[] = ['ui.gender','=',$gender];
- }
- // if($companyId >= 0){
- // $map[] = ['ui.company_id','=',$companyId];
- // }
- if($job){
- $map[] = ['ui.job','like','%'.$job.'%'];
- }
- if($education){
- $map[] = ['ui.education','like','%'.$education.'%'];
- }
- if($profession){
- $map[] = ['ui.profession','like','%'.$profession.'%'];
- }
- $map[] = ['u.del','=',0];
- $map[] = ['r.type','=',3];
- $map[] = ['r.org_id','=',$orgId];
- $lists = Db::name('user_info')
- ->alias('ui')
- ->join('user u','ui.user_id = u.id')
- ->join('user_roles ur','ur.user_id = u.id')
- ->join('roles r','ur.roles_id = r.id')
- ->where($map)
- ->field('u.code,u.phone,ui.*')
- ->order('ui.sorts2 asc,u.id desc')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- // 获取用户岗位
- $jlist = Db::name('user_job')
- ->alias('uj')
- ->join('job j','j.id = uj.job_id')
- ->join('dep d','d.id = j.dep_id')
- ->where('j.del',0)
- ->where('j.enable',1)
- ->where('d.del',0)
- ->where('d.enable',1)
- ->where('uj.user_id',$v['user_id'])
- ->field("d.name as dep,j.name as job")
- ->select();
- $jlist = $jlist?$jlist:[];
- $deps = $jobs = [];
- foreach ($jlist as $kk=>$vv){
- $deps[] = $vv['dep'];
- $jobs[] = $vv['job'];
- }
- $lists[$k]['dep'] = $deps?implode(',',$deps):'';
- // $lists[$k]['job'] = $jobs?implode(',',$jobs):'';
- $lists[$k]['company'] = '';
- if($lists[$k]['company_id'] > 0){
- $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title');
- }
- if($v['is_working'] == 1){
- $lists[$k]['isWorkingText'] = '试用期';
- }else if($v['is_working'] == 2){
- $lists[$k]['isWorkingText'] = '正式';
- }else if($v['is_working'] == 3){
- $lists[$k]['isWorkingText'] = '离职';
- }else if($v['is_working'] == 4){
- $lists[$k]['isWorkingText'] = '退休';
- }else{
- $lists[$k]['isWorkingText'] = '';
- }
- if($v['gender'] == 1){
- $lists[$k]['genderText'] = '男';
- }else if($v['gender'] == 2){
- $lists[$k]['genderText'] = '女';
- }else{
- $lists[$k]['genderText'] = '';
- }
- //1=管理人员 2=专业技术人员 3=工勤技能人员
- if($v['type'] == 1){
- $lists[$k]['typeText'] = '管理人员';
- }else if($v['type'] == 2){
- $lists[$k]['typeText'] = '专业技术人员';
- }else if($v['type'] == 3){
- $lists[$k]['typeText'] = '工勤技能人员';
- }else{
- $lists[$k]['typeText'] = '';
- }
- $lists[$k]['psName'] = '';
- if($lists[$k]['psid'] > 0){
- $lists[$k]['psName'] = Db::name('post_salary')->where('id',$v['psid'])->value('title');
- }
- $lists[$k]['jobDateText'] = '';
- if($v['job'] || $v['job_date']){
- $arr[$k]['jobDateText'] = $v['job'].'/'.$v['job_date'];
- }
- }
- // $columns = [
- // ["title" => "姓名","key" => "name"],
- // ["title" => "工号","key" => "code"],
- // ["title" => "手机号","key" => "phone"],
- // ["title" => "状态","key" => "isWorkingText"],
- // ["title" => "部门","key" => "dep"],
- // ["title" => "岗位","key" => "job"],
- // ["title" => "电子邮箱","key" => "email"],
- // ["title" => "身份证号","key" => "idCard"],
- // ["title" => "性别","key" => "genderText"],
- // ["title" => "民族","key" => "nation"],
- // ["title" => "籍贯","key" => "nativePlace"],
- // ["title" => "生日","key" => "birthday"],
- // ["title" => "最高学历","key" => "education"],
- // ["title" => "最高学位","key" => "degree"],
- // ["title" => "专业","key" => "profession"],
- // ["title" => "入职日期","key" => "joinTime"],
- // ["title" => "政治面貌","key" => "political"],
- // ["title" => "入党时间","key" => "dangDate"],
- // ["title" => "工作时间","key" => "workDate"],
- // ["title" => "任现职时间","key" => "curJobDate"],
- // ["title" => "专业技术职务","key" => "professionPosition"],
- // ["title" => "评定时间","key" => "assessDate"],
- // ["title" => "职业资格","key" => "qualification"],
- // ["title" => "来办时间","key" => "lbDate"],
- // ["title" => "进入形式","key" => "inShape"],
- // ["title" => "同级职务时间","key" => "levelJobDate"],
- // ["title" => "离职/退休日期","key" => "outTime"],
- // ["title" => "离职原因","key" => "outReason"],
- // ["title" => "婚姻状况","key" => "marital"],
- // ["title" => "所属公司","key" => "company"],
- // ["title" => "剩余年假","key" => "annualLeave"],
- // ["title" => "岗位等级","key" => "psName"],
- // ["title" => "薪级","key" => "pwlevel"],
- // ["title" => "类型","key" => "typeText"],
- // ["title" => "备注1","key" => "remark1"],
- // ["title" => "备注2","key" => "remark2"],
- // ["title" => "备注3","key" => "remark3"],
- // ["title" => "备注4","key" => "remark4"],
- // ["title" => "备注5","key" => "remark5"],
- // ];
- $columns = [
- ["title" => "部门","key" => "dep"],
- ["title" => "行政职务","key" => "position"],
- ["title" => "姓名","key" => "name"],
- ["title" => "岗位及时间","key" => "jobDateText"],
- ["title" => "性别","key" => "genderText"],
- ["title" => "民族","key" => "nation"],
- ["title" => "籍贯","key" => "nativePlace"],
- ["title" => "出生日期","key" => "birthday"],
- ["title" => "身份证号码","key" => "idCard"],
- ["title" => "年龄","key" => "age"],
- ["title" => "学历","key" => "education"],
- ["title" => "专业","key" => "profession"],
- ["title" => "入党时间","key" => "dangDate"],
- ["title" => "工作时间","key" => "workDate"],
- ["title" => "任现职时间","key" => "curJobDate"],
- ["title" => "专业技术职务","key" => "professionPosition"],
- ["title" => "评定时间","key" => "assessDate"],
- ["title" => "职业资格","key" => "qualification"],
- ["title" => "来办时间","key" => "joinTime"],
- ["title" => "进入形式","key" => "inShape"],
- ["title" => "同级职务时间","key" => "levelJobDate"],
- ];
- $data = [
- 'columns' => $columns,
- 'list' => $lists
- ];
- return $data;
- }
- public function info($id){
- $info = Db::name('user')
- ->alias('u')
- ->join('user_info ui','ui.user_id = u.id')
- ->where('ui.id', $id)
- ->where('u.del', 0)
- ->field('u.sorts,u.code,u.phone,ui.*')
- ->find();
- if(!$info){
- HelpHander::error('数据不存在');
- }
- $jobs = Db::name('user_job')
- ->alias('uj')
- ->join('job j','j.id = uj.job_id')
- ->join('dep d','d.id = j.dep_id')
- ->where('j.del',0)
- ->where('j.enable',1)
- ->where('d.del',0)
- ->where('d.enable',1)
- ->where('uj.user_id',$info['user_id'])
- ->field('j.id as job_id,j.dep_id,j.name as jobName,d.name as depName')
- ->select();
- $info['jobs'] = $jobs?$jobs:[];
- $info['company'] = '';
- if($info['company_id'] > 0){
- $info['company'] = Db::name('company')->where('id',$info['company_id'])->value('title');
- }
- $info['company2'] = '';
- if($info['company_id2'] > 0){
- $info['company2'] = Db::name('company')->where('id',$info['company_id2'])->value('title');
- }
- $info['pstitle'] = '';
- $info['psjob'] = '';
- if($info['company_id'] > 0){
- $info['company'] = Db::name('company')->where('id',$info['company_id'])->value('title');
- }
- if($info['psid'] > 0){
- $psinfo = Db::name('post_salary')->where('id',$info['psid'])->find();
- $info['pstitle'] = $psinfo?$psinfo['title']:'';
- $info['psjob'] = $psinfo?$psinfo['job']:'';
- }
- $info['age'] = $info['birthday']?calculate_age($info['birthday']):'';
- $info['workAge'] = $info['work_date']?calculate_age($info['work_date']):'';
- return $info;
- }
- public function edit($data,$id){
- $result = validate('UserInfo')->check($data,[],'edit');
- if(true !== $result){
- HelpHander::error(validate('UserInfo')->getError());
- }
- if($data['id_card']){
- $bd = get_birthday_sex_by_idcard($data['id_card']);
- $data['birthday'] = $bd['birthday'];
- $data['gender'] = $bd['gender'];
- }
- $sorts = $data['sorts'];
- unset($data['sorts']);
- $data['update_time'] = date('Y-m-d H:i:s');
- $ret = $this->save($data,['id'=>$id]);
- if(!$ret){
- HelpHander::error('修改失败');
- }
- $userId = Db::name('user_info')->where('id',$id)->value('user_id');
- Db::name('user')->where('id',$userId)->setField('sorts',$sorts);
- $logdata = json_encode($data);
- model('ActionLog')->add(5,'修改人员档案',0,$logdata);
- return true;
- }
- public function changeSalary($data,$id,$userId,$orgId){
- $info = Db::name('user_info')->where('id',$id)->find();
- if(!$info){
- HelpHander::error('记录不存在');
- }
- if($info['company_id'] == $data['company_id'] && $info['type'] == $data['type'] && $info['pwlevel'] == $data['pwlevel'] && $info['psid'] == $data['psid']){
- HelpHander::error('岗位未作出任何变动');
- }
- Db::startTrans();
- try{
- $ssdata = [
- 'company_id' => $data['company_id'],
- 'type' => $data['type'],
- 'pwlevel' => $data['pwlevel'],
- 'psid' => $data['psid'],
- 'update_time' => date('Y-m-d H:i:s')
- ];
- $ret = $this->save($ssdata,['id'=>$id]);
- if(!$ret){
- \exception('操作失败2');
- }
- $sdata = [
- 'org_id' => $orgId,
- 'user_id' => $info['user_id'],
- 'psid' => $data['psid'],
- 'create_user_id' => $userId,
- 'pwlevel' => $data['pwlevel'],
- 'imgs' => $data['imgs'],
- 'remark' => $data['remark'],
- 'create_time' => date('Y-m-d H:i:s'),
- 'type' => $data['type']
- ];
- $res = Db::name('user_post_log')->insert($sdata);
- if(!$res){
- \exception('操作失败1');
- }
- Db::commit();
- }catch (Exception $e){
- Db::rollback();
- HelpHander::error('操作失败'.$e);
- }
- return true;
- }
- public function salaryLogList($page,$size,$orgId,$userId=0){
- $map[] = ['org_id','=',$orgId];
- if($userId > 0){
- $map[] = ['user_id','=',$userId];
- }
- $lists = Db::name('user_post_log')
- ->where($map)
- ->page($page,$size)
- ->order('id desc')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- $post = Db::name('post_salary')
- ->alias('ps')
- ->join('company c','c.id = ps.company_id')
- ->field('ps.*,c.title as company')
- ->where('ps.id',$v['psid'])
- ->find();
- $lists[$k]['title'] = $post['title'];
- $lists[$k]['job'] = $post['job'];
- $lists[$k]['company'] = $post['company'];
- $lists[$k]['userName'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name');
- $lists[$k]['createUserName'] = Db::name('user_info')->where('user_id',$v['create_user_id'])->value('name');
- }
- $total = Db::name('user_post_log')
- ->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists?$lists:[]
- ];
- return $data;
- }
- public function advancedEndUserInfo($id,$orgId,$userId,$formJson){
- $formJson = json_decode($formJson,true);
- $type = '';
- $outTime = '';
- $outReason = '';
- foreach ($formJson as $k=>$v){
- if($v['componentName'] == 'dddeparturefield'){
- foreach ($v['components'] as $key=>$val){
- $val['values2'] = isset($val['values2'])?$val['values2']:[];
- $val['values'] = isset($val['values'])?$val['values']:'';
- switch ($val['idx']){
- case '0':
- $type = isset($val['values'])?$val['values']:'';
- break;
- case '1':
- $outTime = isset($val['values'])?$val['values']:'';
- break;
- case '2':
- $outReason = isset($val['values'])?$val['values']:'';
- break;
- }
- }
- break;
- }
- }
- $data = [
- 'out_time' => $outTime,
- 'out_reason' => $outReason,
- 'is_working' => 3 // 离职
- ];
- if($type == '退休'){
- $data['is_working'] = 4;
- }
- $ret = Db::name('user_info')->where('user_id',$userId)->update($data);
- if(!$ret){
- return false;
- }
- $ret2 = Db::name('user')->where('id',$userId)->setField('enable',0);
- return $ret2?true:false;
- }
- public function departure($data,$userId,$orgId){
- $result = validate('UserInfo')->check($data,[],'departure');
- if(true !== $result){
- HelpHander::error(validate('UserInfo')->getError());
- }
- $user = Db::name('user')
- ->alias('u')
- ->join('user_info ui','u.id = ui.user_id')
- ->where('u.id',$data['user_id'])
- ->where('u.del',0)
- ->field('u.id,u.enable,ui.is_working')
- ->find();
- if(!$user){
- HelpHander::error('用户不存在');
- }
- if(!in_array($user['is_working'],[1,2])){
- HelpHander::error('该状态无法办理离职');
- }
- Db::startTrans();
- try{
- $ret = Db::name('user')->where('id',$data['user_id'])->update(['enable'=>0,'update_time'=>date('Y-m-d H:i:s')]);
- if(!$ret){
- \exception('操作失败');
- }
- if($data['is_work'] == 0){
- $isWorking = 3; // 离职
- }else{
- $isWorking = 4; // 退休
- }
- $res = Db::name('user_info')->where('user_id',$data['user_id'])->update([
- 'is_working' => $isWorking,
- 'out_time' => $data['out_time'],
- 'out_reason' => $data['out_reason'],
- ]);
- if(!$res){
- \exception('操作失败');
- }
- Db::commit();
- }catch (Exception $e){
- Db::rollback();
- HelpHander::error($e->getMessage());
- }
- return true;
- }
- public function back($data,$userId,$orgId){
- $result = validate('UserInfo')->check($data,[],'back');
- if(true !== $result){
- HelpHander::error(validate('UserInfo')->getError());
- }
- $user = Db::name('user')
- ->alias('u')
- ->join('user_info ui','u.id = ui.user_id')
- ->where('u.id',$data['user_id'])
- ->where('u.del',0)
- ->field('u.id,u.enable,ui.is_working')
- ->find();
- if(!$user){
- HelpHander::error('用户不存在');
- }
- if(!in_array($user['is_working'],[3,4])){
- HelpHander::error('该状态无法重新入职');
- }
- Db::startTrans();
- try{
- $ret = Db::name('user')->where('id',$data['user_id'])->update(['enable'=>1,'update_time'=>date('Y-m-d H:i:s')]);
- if(!$ret){
- \exception('操作失败');
- }
- if($data['is_work'] == 0){
- $isWorking = 1; // 试用期
- }else{
- $isWorking = 2; // 正式
- }
- $res = Db::name('user_info')->where('user_id',$data['user_id'])->update([
- 'is_working' => $isWorking,
- 'join_time' => $data['join_time']
- ]);
- if(!$res){
- \exception('操作失败');
- }
- Db::commit();
- }catch (Exception $e){
- Db::rollback();
- HelpHander::error($e->getMessage());
- }
- $logdata = json_encode($data);
- model('ActionLog')->add(5,'人员重新入职',0,$logdata);
- return true;
- }
- /**
- * 根据所属公司获取在职人数
- * @param $comapnyId
- * @return float|string
- */
- public function getCountByCompany($comapnyId){
- $map[] = ['u.del','=',0];
- $map[] = ['u.enable','=',1];
- $map[] = ['ui.is_working','in',[1,2]];
- $map[] = ['ui.company_id','=',$comapnyId];
- $count = Db::name('user')
- ->alias('u')
- ->join('user_info ui','ui.user_id = u.id')
- ->where($map)
- ->count();
- return $count;
- }
- /**
- * 根据性别获取在职人数
- * @param $gender
- * @return float|string
- */
- public function getCountByGender($gender){
- $map[] = ['u.del','=',0];
- $map[] = ['u.enable','=',1];
- $map[] = ['ui.is_working','in',[1,2]];
- $map[] = ['ui.gender','=',$gender];
- $count = Db::name('user')
- ->alias('u')
- ->join('user_info ui','ui.user_id = u.id')
- ->where($map)
- ->count();
- return $count;
- }
- public function getCountByGender2($company){
- $map[] = ['u.del','=',0];
- $map[] = ['u.enable','=',1];
- $map[] = ['ui.is_working','in',[1,2]];
- if($company > 0){
- $map[] = ['ui.company_id','=',$company];
- }
- $count = Db::name('user')
- ->alias('u')
- ->join('user_info ui','ui.user_id = u.id')
- ->where($map)
- ->count();
- $map[] = ['ui.gender','=',1];
- $count1 = Db::name('user')
- ->alias('u')
- ->join('user_info ui','ui.user_id = u.id')
- ->where($map)
- ->count();
- $count2 = $count - $count1;
- return ['c1' => $count1,'c2' => $count2];
- }
- public function getDangStructure($company){
- $map[] = ['u.del','=',0];
- $map[] = ['u.enable','=',1];
- $map[] = ['ui.is_working','in',[1,2]];
- if($company > 0){
- $map[] = ['ui.company_id','=',$company];
- }
- $count = Db::name('user')
- ->alias('u')
- ->join('user_info ui','ui.user_id = u.id')
- ->where($map)
- ->count();
- $map[] = ['ui.dang_date','>',0];
- $count1 = Db::name('user')
- ->alias('u')
- ->join('user_info ui','ui.user_id = u.id')
- ->where($map)
- ->count();
- $count2 = $count - $count1;
- return ['c1' => $count1,'c2' => $count2];
- }
- /**
- * 根据在职状态获取在职人数
- * @param $work
- * @return float|string
- */
- public function getCountByWork($work){
- $map[] = ['u.del','=',0];
- if($work == 1||$work == 2){
- $map[] = ['u.enable','=',1];
- }
- $map[] = ['ui.is_working','=',$work];
- $count = Db::name('user')
- ->alias('u')
- ->join('user_info ui','ui.user_id = u.id')
- ->where($map)
- ->count();
- return $count;
- }
- public function getCountByType($type){
- $map[] = ['u.del','=',0];
- $map[] = ['u.enable','=',1];
- $map[] = ['ui.is_working','in',[1,2]];
- $map[] = ['ui.type','=',$type];
- $count = Db::name('user')
- ->alias('u')
- ->join('user_info ui','ui.user_id = u.id')
- ->where($map)
- ->count();
- return $count;
- }
- public function changePayBatch($companyId, $userId, $orgId){
- $uids = model('User')->getAdminUsers();
- if($uids){
- $map[] = ['u.id','not in',$uids];
- }
- $map[] = ['u.enable','=',1];
- $map[] = ['u.del','=',0];
- $map[] = ['r.type','=',3];
- $map[] = ['r.org_id','=',$orgId];
- $map[] = ['ui.company_id','=',$companyId];
- $lists = Db::name('user_info')
- ->alias('ui')
- ->join('user u','ui.user_id = u.id')
- ->join('user_roles ur','ur.user_id = u.id')
- ->join('roles r','ur.roles_id = r.id')
- ->where($map)
- ->field('ui.id,ui.user_id,ui.type,ui.company_id,ui.pwlevel,ui.psid')
- ->select();
- $lists = $lists?$lists:[];
- Db::startTrans();
- try{
- foreach ($lists as $k=>$v){
- if(($v['type'] == 1||$v['type'] == 2) && $v['pwlevel'] >= 65){
- continue;
- }
- if($v['company_id'] == 1 && $v['type'] == 3 && $v['pwlevel'] >= 40){
- continue;
- }
- if($v['company_id'] == 2 && $v['type'] == 3 && $v['pwlevel'] >= 50){
- continue;
- }
- $res = Db::name('user_info')->where('id',$v['id'])->update(['pwlevel'=>$v['pwlevel'] + 1]);
- if(!$res){
- \exception('操作失败');
- }
- $sdata = [
- 'org_id' => $orgId,
- 'user_id' => $v['user_id'],
- 'psid' => $v['psid'],
- 'create_user_id' => $userId,
- 'pwlevel' => $v['pwlevel'],
- 'remark' => '薪级普调',
- 'create_time' => date('Y-m-d H:i:s'),
- 'type' => $v['type']
- ];
- $res = Db::name('user_post_log')->insert($sdata);
- if(!$res){
- \exception('操作失败');
- }
- }
- Db::commit();
- }catch (Exception $e){
- Db::rollback();
- HelpHander::error($e->getMessage());
- }
- return true;
- }
- // 修改基础绩效或工资排序
- public function changeFixed($id, $money, $type){
- $info = Db::name('user_info')->where('id',$id)->find();
- if(!$info){
- HelpHander::error('参数错误');
- }
- if($type == 0){
- $res = Db::name('user_info')->where('id',$id)->setField('fixed_performance',$money);
- }else{
- $res = Db::name('user_info')->where('id',$id)->setField('sorts3',$money);
- }
- if(!$res){
- HelpHander::error('操作失败');
- }
- return true;
- }
- public function changeSortsFixed($id, $sorts2){
- $info = Db::name('user_info')->where('id',$id)->find();
- if(!$info){
- HelpHander::error('参数错误');
- }
- if($info['sorts2'] === $sorts2){
- return true;
- }
- $res = Db::name('user_info')->where('id',$id)->setField('sorts2',$sorts2);
- if(!$res){
- HelpHander::error('操作失败');
- }
- return true;
- }
- }
|