input('id/d',0), 'name' => input('name','','trim'), 'level' => input('level','','trim'), 'content' => input('content','','trim'), 'org_id' => input('orgId/d',0), 'dep_id' => input('depId/d',0), 'type' => input('type/d',0), 'leader' => input('leader/d',0), ]; $result = validate('Job')->check($data,[],''); if(true !== $result){ HelpHander::error(validate('Job')->getError()); } $id = $data['id']; unset($data['id']); if($id > 0){ unset($data['org_id']); unset($data['dep_id']); $ret = $this->allowField(true)->save($data,['id'=>$id]); }else{ $maxcode = Db::name('job')->order('id desc')->value('code'); if($maxcode){ $data['code'] = $maxcode + 1; }else{ $data['code'] = '001'; } $ret = $this->allowField(true)->save($data); } if(!$ret){ HelpHander::error('操作失败'); } return true; } public function info($id){ $info = $this->where('id',$id)->where('del',0)->find(); if(!$info){ HelpHander::error('数据不存在'); } return $info->toArray(); } public function lists($page,$size){ $lists = $this ->where('del',0) ->page($page,$size) ->order('id asc') ->select(); return $lists?$lists->toArray():[]; } public function changeStatus($id,$enable){ $ret = $this->where('id',$id)->setField('enable',$enable); if(!$ret){ HelpHander::error('操作失败'); } return true; } /** * 根据部门id集合获取所有岗位id集合 * @param $depids * @return array */ public function getJobByDeps($depids){ $children = Db::name('job') ->where('del',0) ->where('enable',1) ->where('dep_id','in',$depids) ->column('id'); return $children ? $children : []; } // 部门下的岗位 public function queryJobByDep($depId){ $lists = $this ->where('dep_id',$depId) ->where('del',0) ->order('id asc') ->select(); return $lists ? $lists->toArray() : []; } // 部门下的岗位 public function queryJobByOrg($orgId){ $lists = $this ->where('org_id',$orgId) ->where('del',0) ->order('id asc') ->select(); return $lists ? $lists->toArray() : []; } //查询当前岗位下未分配的人员 public function screenUserByJob($page,$size,$jobId,$param){ // 去除管理员 $uids = model('User')->getAdminUsers(); // 去除已分配人员 $userids = Db::name('user_job')->where('job_id',$jobId)->column('user_id'); $userids = $userids?$userids:[]; $userids = array_merge($uids,$userids); if($userids){ $map[] = ['u.id','not in',$userids]; } if($param){ $map[] = ['ui.name|u.code','like','%'.$param.'%']; } $map[] = ['u.del','=',0]; $lists = Db::name('user') ->alias('u') ->join('user_info ui','ui.user_id = u.id') ->where($map) ->page($page,$size) ->field('u.id,u.code,u.del,ui.device_sn,u.enable,u.phone,ui.join_time,ui.name as userName') ->order('u.id desc') ->select(); $total = Db::name('user') ->alias('u') ->join('user_info ui','ui.user_id = u.id') ->where($map)->count(); $data = [ 'total' => $total, 'list' => $lists?$lists:[] ]; return $data; } //查询当前岗位分配的人员 public function queryUserByJob($page,$size,$jobId,$param){ if($param){ $map[] = ['ui.name|u.code','like','%'.$param.'%']; } $map[] = ['u.del','=',0]; $map[] = ['uj.job_id','=',$jobId]; $lists = Db::name('user_job') ->alias('uj') ->join('user_info ui','ui.user_id = uj.user_id') ->join('user u','uj.user_id = u.id') ->where($map) ->page($page,$size) ->field('u.id,u.code,u.del,ui.device_sn,u.enable,u.phone,ui.join_time,ui.name as userName') ->order('u.id asc') ->select(); $total = Db::name('user_job') ->alias('uj') ->join('user_info ui','ui.user_id = uj.user_id') ->join('user u','uj.user_id = u.id') ->where($map)->count(); $data = [ 'total' => $total, 'list' => $lists?$lists:[] ]; return $data; } }