Deaprture.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;use think\facade\Validate;
  4. class Deaprture extends Base{
  5. public function __construct(App $app) {
  6. parent::__construct($app);
  7. $this->model = new \app\admin\model\ResignInfo();
  8. }
  9. public function create(){
  10. $post = $this->request->only(['resign_uid', 'hand_uid', 'resign_date', 'expire_date', 'is_hand' => 0, 'remark' => ''], 'post', 'trim');
  11. $valid=Validate::rule([
  12. "resign_uid|离职人id"=>"require|number|gt:0",
  13. "hand_uid|交接人id"=>"require|number|gt:0",
  14. "resign_date|离职日期"=>"require|date",
  15. "expire_date|生效时间"=>"require|date",
  16. "is_hand|是否交接"=>"require|number|in:0,1",
  17. "remark|备注"=>"require|max:255",
  18. ]);
  19. if(!$valid->check($post))return error($valid->getError());
  20. $resingInfo=\app\user\model\User::where('account_id',$post['resign_uid'])->findOrEmpty();
  21. if($resingInfo->isEmpty())return error('离职人信息不存在');
  22. $handInfo=\app\user\model\User::where('account_id',$post['hand_uid'])->findOrEmpty();
  23. if($handInfo->isEmpty())return error('交接人信息不存在');
  24. $this->model->startTrans();
  25. try{
  26. $data=[
  27. 'resign_uid' => $post['resign_uid'],
  28. 'hand_uid' => $post['hand_uid'],
  29. 'resign_name' => $resingInfo->nickname,
  30. 'hand_name' => $handInfo->nickname,
  31. 'resign_date' => $post['resign_date'],
  32. 'expire_date' => $post['expire_date'],
  33. 'is_hand' => $post['is_hand'],
  34. 'apply_id' => $this->uid,
  35. 'apply_name' => $this->uname,
  36. 'status' => 0,
  37. 'remark' => $post['remark'],
  38. ];
  39. $create=$this->model->create($data);
  40. if($create->isEmpty())throw new \Exception('创建失败');
  41. $this->model->commit();
  42. }catch (\Exception $e){
  43. $this->model->rollback();
  44. return error($e->getMessage());
  45. }
  46. return success("创建成功");
  47. }
  48. }