model = new \app\admin\model\ResignInfo(); } public function list(){ $param = $this->request->only(['page' => 1, 'size' => 10, 'status' => '', 'resign_uid' => '', 'hand_uid' => '', 'start' => '', 'end' => '', 'companyNo' => ''], 'post', 'trim'); $where = [['is_del', '=', 0]]; if ($param['status'] !== '') $where[] = ['status', '=', $param['status']]; if ($param['resign_uid'] !== '') $where[] = ['resign_uid', '=', $param['resign_uid']]; if ($param['hand_uid'] !== '') $where[] = ['hand_uid', '=', $param['hand_uid']]; if ($param['start'] != '') $where[] = ['addtime', '>=', $param['start']]; if ($param['end'] != '') $where[] = ['addtime', '<=', $param['end']]; if ($param['companyNo'] != '') $where[] = ['companyNo', 'like', '%' . $param['companyNo'] . '%']; $share=[]; if(!in_array($this->roleid,[1,33])){ $share = DataGroup::checkDataShare($this->uid,$this->level); $hand = resign_hand_user($this->uid, 0); if (!empty($share[DataGroup::$type_all])) { $arr = array_unique(array_merge($hand, $share[DataGroup::$type_all])); $where[] = ['hand_uid|resign_uid', 'in', $arr]; } } $list = $this->model->where($where)->order('id desc')->paginate(["list_rows"=>$param['size'],"page"=>$param['page']]) ->each(function (&$iten)use($share){ $iten['is_allow_update'] = (in_array($this->roleid, [1, 33]) || in_array($iten['hand_uid'], $share[DataGroup::$type_write])) ? 1 : 0; }); return success('获取成功',['list'=>$list->items(),'count'=>$list->total()]); } public function create(){ $post = $this->request->only(['resign_uid', 'hand_uid', 'resign_date', 'expire_date', 'is_hand' => 0, 'remark' => ''], 'post', 'trim'); $val = Validate::rule([ 'resign_uid|离职人' => 'require|number|gt:0', 'hand_uid|交接人' => 'require|number|gt:0', 'resign_date|离职日期' => 'require|date', 'expire_date|生效时间' => 'require|date', 'is_hand|是否交接' => 'require|number|in:0,1', 'remark|备注' => 'max:255', ]); if (!$val->check($post)) return error($val->getError()); $uname = \app\user\model\User::where(["account_id"=>[$post['resign_uid'],$post['hand_uid']]])->column("nickname","account_id"); if ($post['resign_uid'] == $post['hand_uid']) return error("离职人与交接人不能相同"); $resign_info = $this->model->where(['resign_uid' => $post['resign_uid'], 'status' => 0])->find(); if ($resign_info) return error("该用户已添加离职交接记录,请勿重复操作"); $data = [ 'resign_uid' => $post['resign_uid'], 'hand_uid' => $post['hand_uid'], 'resign_name' => $uname[$post['resign_uid']]??"", 'hand_name' => $uname[$post['hand_uid']]??"", 'resign_date' => $post['resign_date'], 'expire_date' => $post['expire_date'], 'is_hand' => $post['is_hand'], 'apply_id' => $this->uid, 'apply_name' => $this->uname, 'status' => 0, 'remark' => $post['remark'], 'is_del' => 0, 'addtime' => date('Y-m-d H:i:s'), 'updatetime' => date('Y-m-d H:i:s'), ]; $create = $this->model->create($data); if ($create) return success("添加成功"); else return error("添加失败"); } public function update(){ $post = $this->request->only(['id', 'resign_uid', 'hand_uid', 'resign_date', 'expire_date', 'is_hand' => 0, 'remark' => ''], 'post', 'trim'); $val = Validate::rule([ 'id' => 'require|number|gt:0', 'resign_uid|离职人' => 'require|number|gt:0', 'hand_uid|交接人' => 'require|number|gt:0', 'resign_date|离职日期' => 'require|date', 'expire_date|生效时间' => 'require|date', 'is_hand|是否交接' => 'require|number|in:0,1', 'remark|备注' => 'max:255', ]); if (!$val->check($post)) return error($val->getError()); $uname = \app\user\model\User::where(["account_id"=>[$post['resign_uid'],$post['hand_uid']]])->column("nickname","account_id"); if ($post['resign_uid'] == $post['hand_uid']) return error("离职人与交接人不能相同"); $info = $this->model->where(['id' => $post['id'], 'is_del' => 0])->findOrEmpty(); if ($info->isEmpty()) return error("离职交接记录不存在"); if ($info->status==1) return error("离职交接记录已生效,无法修改"); $data = [ 'resign_uid' => $post['resign_uid'], 'hand_uid' => $post['hand_uid'], 'resign_name' => $uname[$post['resign_uid']]??"", 'hand_name' => $uname[$post['hand_uid']]??"", 'resign_date' => $post['resign_date'], 'expire_date' => $post['expire_date'], 'is_hand' => $post['is_hand'], ]; $update = $info->save($data); if ($update) return success("修改成功"); else return error("修改失败"); } public function delete(){ $post = $this->request->only(['id'], 'post', 'trim'); $val = Validate::rule([ 'id' => 'require|number|gt:0', ]); if (!$val->check($post)) return error($val->getError()); $info = $this->model->where(['id' => $post['id'], 'is_del' => 0])->findOrEmpty(); if ($info->isEmpty()) return error("离职交接记录不存在"); if ($info->status==1) return error("离职交接记录已生效,无法删除"); $info->is_del = 1; $update = $info->save(); if ($update) return success("删除成功"); else return error("删除失败"); } public function detail(){ $post = $this->request->only(['id'], 'post', 'trim'); $val = Validate::rule([ 'id' => 'require|number|gt:0', ]); if (!$val->check($post)) return error($val->getError()); $info = $this->model->where(['id' => $post['id'], 'is_del' => 0])->findOrEmpty(); if ($info->isEmpty()) return error('离职交接记录不存在'); return success('获取成功', $info); } public function status(){ $post = $this->request->only(['id','status',"remark"], 'post', 'trim'); $val = Validate::rule([ 'id|主键id' => 'require|number|gt:0', 'status|状态' => 'require|number|in:1,2,3,4', "remark"=>"max:255" ]); if (!$val->check($post)) return error($val->getError()); $info = $this->model->where(['id' => $post['id'], 'is_del' => 0])->findOrEmpty(); if ($info->isEmpty()) return error('离职交接记录不存在'); $info->remark = $post['remark']; if ($post['status'] == 3 && strtotime($info->expire_date)<=time()) { $info->status=4; }else{ $info->status=$post['status']; } $update = $info->save(); if ($update) return success("修改成功"); else return error("修改失败"); } }