Deaprture.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. /** 创建
  10. * @param id 主键
  11. * @param resign_uid|离职人id
  12. * @param hand_uid|交接人id
  13. * @param resign_date|离职日期
  14. * @param expire_date|生效时间
  15. * @param is_hand|是否交接
  16. * @param remark|备注
  17. * @return \think\Response|\think\response\Json|void
  18. */
  19. public function create(){
  20. $post = $this->request->only(['resign_uid', 'hand_uid', 'resign_date', 'expire_date', 'is_hand' => 0,'is_del' => 0, 'remark' => ''], 'post', 'trim');
  21. $valid=Validate::rule([
  22. "resign_uid|离职人id"=>"require|number|gt:0|unique:\app\admin\model\ResignInfo,resign_uid^is_del",
  23. "hand_uid|交接人id"=>"require|number|gt:0",
  24. "resign_date|离职日期"=>"require|date",
  25. "expire_date|生效时间"=>"require|date",
  26. "is_hand|是否交接"=>"require|number|in:0,1",
  27. "remark|备注"=>"require|max:255",
  28. ]);
  29. if(!$valid->check($post))return error($valid->getError());
  30. $resingInfo=\app\user\model\User::where('account_id',$post['resign_uid'])->findOrEmpty();
  31. if($resingInfo->isEmpty())return error('离职人信息不存在');
  32. $handInfo=\app\user\model\User::where('account_id',$post['hand_uid'])->findOrEmpty();
  33. if($handInfo->isEmpty())return error('交接人信息不存在');
  34. $this->model->startTrans();
  35. try{
  36. $data=[
  37. 'resign_uid' => $post['resign_uid'],
  38. 'hand_uid' => $post['hand_uid'],
  39. 'resign_name' => $resingInfo->nickname,
  40. 'hand_name' => $handInfo->nickname,
  41. 'resign_date' => $post['resign_date'],
  42. 'expire_date' => $post['expire_date'],
  43. 'is_hand' => $post['is_hand'],
  44. 'apply_id' => $this->uid,
  45. 'apply_name' => $this->uname,
  46. 'status' => 0,
  47. 'remark' => $post['remark'],
  48. ];
  49. $create=$this->model->create($data);
  50. if($create->isEmpty())throw new \Exception('创建失败');
  51. $this->model->commit();
  52. }catch (\Exception $e){
  53. $this->model->rollback();
  54. return error($e->getMessage());
  55. }
  56. return success("创建成功");
  57. }
  58. /** 修改
  59. * @param id 主键
  60. * @param resign_uid|离职人id
  61. * @param hand_uid|交接人id
  62. * @param resign_date|离职日期
  63. * @param expire_date|生效时间
  64. * @param is_hand|是否交接
  65. * @param remark|备注
  66. * @return \think\Response|\think\response\Json|void
  67. */
  68. public function save(){
  69. $post = $this->request->only(['id', 'resign_uid', 'hand_uid', 'resign_date', 'expire_date','is_del' => 0, 'is_hand' => 0, 'remark' => ''], 'post', 'trim');
  70. $valid=Validate::rule([
  71. "id|id"=>"require|number|gt:0",
  72. "resign_uid|离职人id"=>"require|number|gt:0|unique:\app\admin\model\ResignInfo,resign_uid^is_del",
  73. "hand_uid|交接人id"=>"require|number|gt:0",
  74. "resign_date|离职日期"=>"require|date",
  75. "expire_date|生效时间"=>"require|date",
  76. "is_hand|是否交接"=>"require|number|in:0,1",
  77. ]);
  78. if(!$valid->check($post))return error($valid->getError());
  79. $resingInfo=$this->model->where('id',$post['id'])->findOrEmpty();
  80. if($resingInfo->isEmpty())return error('离职信息不存在');
  81. if($resingInfo->resign_uid!=$post['resign_uid']){
  82. $resingInfo->resign_uid=$post['resign_uid'];
  83. $resingInfo=\app\user\model\User::where('account_id',$post['resign_uid'])->findOrEmpty();
  84. if($resingInfo->isEmpty())return error('离职人信息不存在');
  85. $resingInfo->resign_name=$resingInfo->nickname;
  86. }
  87. if($resingInfo->hand_uid!=$post['hand_uid']){
  88. $resingInfo->hand_uid=$post['hand_uid'];
  89. $handInfo=\app\user\model\User::where('account_id',$post['hand_uid'])->findOrEmpty();
  90. if($handInfo->isEmpty())return error('交接人信息不存在');
  91. $resingInfo->hand_name=$handInfo->nickname;
  92. }
  93. $resingInfo->resign_date=$post['resign_date'];
  94. $resingInfo->expire_date=$post['expire_date'];
  95. $resingInfo->is_hand=$post['is_hand'];
  96. $resingInfo->remark=$post['remark'];
  97. if(!$resingInfo->save())return error('修改失败');
  98. return success("修改成功");
  99. }
  100. /** 删除
  101. * @param id 主键
  102. * @return \think\Response|\think\response\Json|void
  103. */
  104. public function delete(){
  105. $id=$this->request->post('id/d');
  106. if(empty($id))return error('参数错误');
  107. $resingInfo=$this->model->where('id',$id)->findOrEmpty();
  108. if($resingInfo->isEmpty())return error('离职信息不存在');
  109. $resingInfo->is_del=1;
  110. if(!$resingInfo->save())return error('删除失败');
  111. return success("删除成功");
  112. }
  113. public function list(){
  114. $post = $this->request->only(['resign_uid'=>"", 'hand_uid'=>"", 'start'=>"", 'end'=>"", 'status'=>"", 'page'=>1, 'size'=>20], 'post', 'trim');
  115. $where=[["is_del","=",0]];
  116. if($post['resign_uid']!="")$where[]=["resign_uid","=",$post['resign_uid']];
  117. if($post['hand_uid']!="")$where[]=["hand_uid","=",$post['hand_uid']];
  118. if($post['start']!="")$where[]=["addtime",'>=',$post['start']];
  119. if($post['end']!="")$where[]=["addtime",'<=',$post['end']];
  120. if($post['status']!="")$where[]=["status","=",$post['status']];
  121. $list=$this->model->where($where)->order('id desc')->paginate(['page'=>$post['page'],'list_rows'=>$post['size']]);
  122. return success("获取成功",["list"=>$list->items(),"count"=>$list->total()]);
  123. }
  124. }