model = new \app\admin\model\ResignInfo(); } /** 创建 * @param id 主键 * @param resign_uid|离职人id * @param hand_uid|交接人id * @param resign_date|离职日期 * @param expire_date|生效时间 * @param is_hand|是否交接 * @param remark|备注 * @return \think\Response|\think\response\Json|void */ public function create(){ $post = $this->request->only(['resign_uid', 'hand_uid', 'resign_date', 'expire_date', 'is_hand' => 0,'is_del' => 0, 'remark' => ''], 'post', 'trim'); $valid=Validate::rule([ "resign_uid|离职人id"=>"require|number|gt:0|unique:\app\admin\model\ResignInfo,resign_uid^is_del", "hand_uid|交接人id"=>"require|number|gt:0", "resign_date|离职日期"=>"require|date", "expire_date|生效时间"=>"require|date", "is_hand|是否交接"=>"require|number|in:0,1", "remark|备注"=>"require|max:255", ]); if(!$valid->check($post))return error($valid->getError()); $resingInfo=\app\user\model\User::where('account_id',$post['resign_uid'])->findOrEmpty(); if($resingInfo->isEmpty())return error('离职人信息不存在'); $handInfo=\app\user\model\User::where('account_id',$post['hand_uid'])->findOrEmpty(); if($handInfo->isEmpty())return error('交接人信息不存在'); $this->model->startTrans(); try{ $data=[ 'resign_uid' => $post['resign_uid'], 'hand_uid' => $post['hand_uid'], 'resign_name' => $resingInfo->nickname, 'hand_name' => $handInfo->nickname, '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'], ]; $create=$this->model->create($data); if($create->isEmpty())throw new \Exception('创建失败'); $this->model->commit(); }catch (\Exception $e){ $this->model->rollback(); return error($e->getMessage()); } return success("创建成功"); } /** 修改 * @param id 主键 * @param resign_uid|离职人id * @param hand_uid|交接人id * @param resign_date|离职日期 * @param expire_date|生效时间 * @param is_hand|是否交接 * @param remark|备注 * @return \think\Response|\think\response\Json|void */ public function save(){ $post = $this->request->only(['id', 'resign_uid', 'hand_uid', 'resign_date', 'expire_date','is_del' => 0, 'is_hand' => 0, 'remark' => ''], 'post', 'trim'); $valid=Validate::rule([ "id|id"=>"require|number|gt:0", "resign_uid|离职人id"=>"require|number|gt:0|unique:\app\admin\model\ResignInfo,resign_uid^is_del", "hand_uid|交接人id"=>"require|number|gt:0", "resign_date|离职日期"=>"require|date", "expire_date|生效时间"=>"require|date", "is_hand|是否交接"=>"require|number|in:0,1", ]); if(!$valid->check($post))return error($valid->getError()); $resingInfo=$this->model->where('id',$post['id'])->findOrEmpty(); if($resingInfo->isEmpty())return error('离职信息不存在'); if($resingInfo->resign_uid!=$post['resign_uid']){ $resingInfo->resign_uid=$post['resign_uid']; $resingInfo=\app\user\model\User::where('account_id',$post['resign_uid'])->findOrEmpty(); if($resingInfo->isEmpty())return error('离职人信息不存在'); $resingInfo->resign_name=$resingInfo->nickname; } if($resingInfo->hand_uid!=$post['hand_uid']){ $resingInfo->hand_uid=$post['hand_uid']; $handInfo=\app\user\model\User::where('account_id',$post['hand_uid'])->findOrEmpty(); if($handInfo->isEmpty())return error('交接人信息不存在'); $resingInfo->hand_name=$handInfo->nickname; } $resingInfo->resign_date=$post['resign_date']; $resingInfo->expire_date=$post['expire_date']; $resingInfo->is_hand=$post['is_hand']; $resingInfo->remark=$post['remark']; if(!$resingInfo->save())return error('修改失败'); return success("修改成功"); } /** 删除 * @param id 主键 * @return \think\Response|\think\response\Json|void */ public function delete(){ $id=$this->request->post('id/d'); if(empty($id))return error('参数错误'); $resingInfo=$this->model->where('id',$id)->findOrEmpty(); if($resingInfo->isEmpty())return error('离职信息不存在'); $resingInfo->is_del=1; if(!$resingInfo->save())return error('删除失败'); return success("删除成功"); } public function list(){ $post = $this->request->only(['resign_uid'=>"", 'hand_uid'=>"", 'start'=>"", 'end'=>"", 'status'=>"", 'page'=>1, 'size'=>20], 'post', 'trim'); $where=[["is_del","=",0]]; if($post['resign_uid']!="")$where[]=["resign_uid","=",$post['resign_uid']]; if($post['hand_uid']!="")$where[]=["hand_uid","=",$post['hand_uid']]; if($post['start']!="")$where[]=["addtime",'>=',$post['start']]; if($post['end']!="")$where[]=["addtime",'<=',$post['end']]; if($post['status']!="")$where[]=["status","=",$post['status']]; $list=$this->model->where($where)->order('id desc')->paginate(['page'=>$post['page'],'list_rows'=>$post['size']]); return success("获取成功",["list"=>$list->items(),"count"=>$list->total()]); } }