Resignation.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use app\admin\model\DataGroup;
  5. use think\facade\Validate;
  6. //离职交接
  7. class Resignation extends Base{
  8. public function __construct(App $app) {
  9. parent::__construct($app);
  10. $this->model = new \app\admin\model\ResignInfo();
  11. }
  12. public function list(){
  13. $param = $this->request->only(['page' => 1, 'size' => 10, 'status' => '', 'resign_uid' => '', 'hand_uid' => '', 'start' => '', 'end' => '', 'companyNo' => ''], 'post', 'trim');
  14. $where = [['is_del', '=', 0]];
  15. if ($param['status'] !== '') $where[] = ['status', '=', $param['status']];
  16. if ($param['resign_uid'] !== '') $where[] = ['resign_uid', '=', $param['resign_uid']];
  17. if ($param['hand_uid'] !== '') $where[] = ['hand_uid', '=', $param['hand_uid']];
  18. if ($param['start'] != '') $where[] = ['addtime', '>=', $param['start']];
  19. if ($param['end'] != '') $where[] = ['addtime', '<=', $param['end']];
  20. if ($param['companyNo'] != '') $where[] = ['companyNo', 'like', '%' . $param['companyNo'] . '%'];
  21. $share=[];
  22. if(!in_array($this->roleid,[1,33])){
  23. $share = DataGroup::checkDataShare($this->uid,$this->level);
  24. $hand = resign_hand_user($this->uid, 0);
  25. if (!empty($share[DataGroup::$type_all])) {
  26. $arr = array_unique(array_merge($hand, $share[DataGroup::$type_all]));
  27. $where[] = ['hand_uid|resign_uid', 'in', $arr];
  28. }
  29. }
  30. $list = $this->model->where($where)->order('id desc')->paginate(["list_rows"=>$param['size'],"page"=>$param['page']])
  31. ->each(function (&$iten)use($share){
  32. $iten['is_allow_update'] = (in_array($this->roleid, [1, 33]) || in_array($iten['hand_uid'], $share[DataGroup::$type_write])) ? 1 : 0;
  33. });
  34. return success('获取成功',['list'=>$list->items(),'count'=>$list->total()]);
  35. }
  36. public function create(){
  37. $post = $this->request->only(['resign_uid', 'hand_uid', 'resign_date', 'expire_date', 'is_hand' => 0, 'remark' => ''], 'post', 'trim');
  38. $val = Validate::rule([
  39. 'resign_uid|离职人' => 'require|number|gt:0',
  40. 'hand_uid|交接人' => 'require|number|gt:0',
  41. 'resign_date|离职日期' => 'require|date',
  42. 'expire_date|生效时间' => 'require|date',
  43. 'is_hand|是否交接' => 'require|number|in:0,1',
  44. 'remark|备注' => 'max:255',
  45. ]);
  46. if (!$val->check($post)) return error($val->getError());
  47. $uname = \app\user\model\User::where(["account_id"=>[$post['resign_uid'],$post['hand_uid']]])->column("nickname","account_id");
  48. if ($post['resign_uid'] == $post['hand_uid']) return error("离职人与交接人不能相同");
  49. $resign_info = $this->model->where(['resign_uid' => $post['resign_uid'], 'status' => 0])->find();
  50. if ($resign_info) return error("该用户已添加离职交接记录,请勿重复操作");
  51. $data = [
  52. 'resign_uid' => $post['resign_uid'],
  53. 'hand_uid' => $post['hand_uid'],
  54. 'resign_name' => $uname[$post['resign_uid']]??"",
  55. 'hand_name' => $uname[$post['hand_uid']]??"",
  56. 'resign_date' => $post['resign_date'],
  57. 'expire_date' => $post['expire_date'],
  58. 'is_hand' => $post['is_hand'],
  59. 'apply_id' => $this->uid,
  60. 'apply_name' => $this->uname,
  61. 'status' => 0,
  62. 'remark' => $post['remark'],
  63. 'is_del' => 0,
  64. 'addtime' => date('Y-m-d H:i:s'),
  65. 'updatetime' => date('Y-m-d H:i:s'),
  66. ];
  67. $create = $this->model->create($data);
  68. if ($create) return success("添加成功");
  69. else return error("添加失败");
  70. }
  71. public function update(){
  72. $post = $this->request->only(['id', 'resign_uid', 'hand_uid', 'resign_date', 'expire_date', 'is_hand' => 0, 'remark' => ''], 'post', 'trim');
  73. $val = Validate::rule([
  74. 'id' => 'require|number|gt:0',
  75. 'resign_uid|离职人' => 'require|number|gt:0',
  76. 'hand_uid|交接人' => 'require|number|gt:0',
  77. 'resign_date|离职日期' => 'require|date',
  78. 'expire_date|生效时间' => 'require|date',
  79. 'is_hand|是否交接' => 'require|number|in:0,1',
  80. 'remark|备注' => 'max:255',
  81. ]);
  82. if (!$val->check($post)) return error($val->getError());
  83. $uname = \app\user\model\User::where(["account_id"=>[$post['resign_uid'],$post['hand_uid']]])->column("nickname","account_id");
  84. if ($post['resign_uid'] == $post['hand_uid']) return error("离职人与交接人不能相同");
  85. $info = $this->model->where(['id' => $post['id'], 'is_del' => 0])->findOrEmpty();
  86. if ($info->isEmpty()) return error("离职交接记录不存在");
  87. if ($info->status==1) return error("离职交接记录已生效,无法修改");
  88. $data = [
  89. 'resign_uid' => $post['resign_uid'],
  90. 'hand_uid' => $post['hand_uid'],
  91. 'resign_name' => $uname[$post['resign_uid']]??"",
  92. 'hand_name' => $uname[$post['hand_uid']]??"",
  93. 'resign_date' => $post['resign_date'],
  94. 'expire_date' => $post['expire_date'],
  95. 'is_hand' => $post['is_hand'],
  96. ];
  97. $update = $info->save($data);
  98. if ($update) return success("修改成功");
  99. else return error("修改失败");
  100. }
  101. public function delete(){
  102. $post = $this->request->only(['id'], 'post', 'trim');
  103. $val = Validate::rule([
  104. 'id' => 'require|number|gt:0',
  105. ]);
  106. if (!$val->check($post)) return error($val->getError());
  107. $info = $this->model->where(['id' => $post['id'], 'is_del' => 0])->findOrEmpty();
  108. if ($info->isEmpty()) return error("离职交接记录不存在");
  109. if ($info->status==1) return error("离职交接记录已生效,无法删除");
  110. $info->is_del = 1;
  111. $update = $info->save();
  112. if ($update) return success("删除成功");
  113. else return error("删除失败");
  114. }
  115. public function detail(){
  116. $post = $this->request->only(['id'], 'post', 'trim');
  117. $val = Validate::rule([
  118. 'id' => 'require|number|gt:0',
  119. ]);
  120. if (!$val->check($post)) return error($val->getError());
  121. $info = $this->model->where(['id' => $post['id'], 'is_del' => 0])->findOrEmpty();
  122. if ($info->isEmpty()) return error('离职交接记录不存在');
  123. return success('获取成功', $info);
  124. }
  125. public function status(){
  126. $post = $this->request->only(['id','status',"remark"], 'post', 'trim');
  127. $val = Validate::rule([
  128. 'id|主键id' => 'require|number|gt:0',
  129. 'status|状态' => 'require|number|in:1,2,3,4',
  130. "remark"=>"max:255"
  131. ]);
  132. if (!$val->check($post)) return error($val->getError());
  133. $info = $this->model->where(['id' => $post['id'], 'is_del' => 0])->findOrEmpty();
  134. if ($info->isEmpty()) return error('离职交接记录不存在');
  135. $info->remark = $post['remark'];
  136. if ($post['status'] == 3 && strtotime($info->expire_date)<=time()) {
  137. $info->status=4;
  138. }else{
  139. $info->status=$post['status'];
  140. }
  141. $update = $info->save();
  142. if ($update) return success("修改成功");
  143. else return error("修改失败");
  144. }
  145. }