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; } }