model = new \app\admin\model\ResignInfo(); } public function create(){ $post = $this->request->only(['resign_uid', 'hand_uid', 'resign_date', 'expire_date', 'is_hand' => 0, 'remark' => ''], 'post', 'trim'); $valid=Validate::rule([ "resign_uid|离职人id"=>"require|number|gt:0", "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("创建成功"); } }