Resigninfo.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\DataGroup as DataGroupModel;
  4. use app\admin\model\ProcessOrder;
  5. use app\admin\model\ProcessWait;
  6. use app\BaseController;
  7. use think\App;
  8. use think\Exception;
  9. use think\facade\Db;
  10. use app\admin\model\ActionLog;
  11. use think\facade\Validate;
  12. //交接
  13. class Resigninfo extends Base
  14. {
  15. public function __construct(App $app)
  16. {
  17. parent::__construct($app);
  18. }
  19. //列表
  20. public function list()
  21. {
  22. $param = $this->request->only(['page' => 1, 'size' => 10, 'status' => '', 'resign_uid' => '', 'hand_uid' => '', 'start' => '', 'end' => '', 'companyNo' => ''], 'post', 'trim');
  23. $where = [['is_del', "=", 0]];
  24. if ($param['status'] !== '') $where[] = ['status', '=', $param['status']];
  25. if ($param['resign_uid'] !== '') $where[] = ['resign_uid', '=', $param['resign_uid']];
  26. if ($param['hand_uid'] !== '') $where[] = ['hand_uid', '=', $param['hand_uid']];
  27. if ($param['start'] != '') $where[] = ['addtime', '>=', $param['start']];
  28. if ($param['end'] != '') $where[] = ['addtime', '<=', $param['end']];
  29. if ($param['companyNo'] != '') $where[] = ['companyNo', 'like', '%' . $param['companyNo'] . '%'];
  30. // $role = $this->checkDataShare();
  31. // if (!empty($role[DataGroupModel::$type_全部])) $where[] = ["hand_uid", "in", $role[DataGroupModel::$type_全部]];
  32. $role = $this->checkDataShare();
  33. $hand = resign_hand_user($this->uid, 0);
  34. if (!empty($role[DataGroupModel::$type_全部])) {
  35. $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  36. $where[] = ['hand_uid|resign_uid', 'in', $arr];
  37. }
  38. $count = Db::name('resign_info')
  39. ->where($where)
  40. ->count('id');
  41. $list = Db::name('resign_info')
  42. ->where($where)
  43. ->order("addtime desc")
  44. ->page($param['page'], $param['size'])
  45. ->append(['is_allow_update'])
  46. ->withAttr('is_allow_update', function ($val, $data) use ($role) {
  47. return (in_array($this->roleid, [1, 33]) || in_array($data['hand_uid'], $role[DataGroupModel::$type_可编辑])) ? 1 : 0; //是否具有编辑权限
  48. })
  49. ->select()
  50. ->toArray();
  51. return app_show(0, "获取成功", ['list' => $list, 'count' => $count]);
  52. }
  53. //创建
  54. public function create()
  55. {
  56. $post = $this->request->only(['resign_uid', 'hand_uid', 'resign_date', 'expire_date', 'is_hand' => 0, 'remark' => ''], 'post', 'trim');
  57. $val = Validate::rule([
  58. 'resign_uid|离职人' => 'require|number|gt:0',
  59. 'hand_uid|交接人' => 'require|number|gt:0',
  60. 'resign_date|离职日期' => 'require|date',
  61. 'expire_date|生效时间' => 'require|date',
  62. // 'companyNo|所属公司' => 'require|max:255',
  63. 'is_hand|是否交接' => 'require|number|in:0,1',
  64. 'remark|备注' => 'max:255',
  65. ]);
  66. if ($val->check($post) == false) return json_show(1004, $val->getError());
  67. $userCommon = \app\admin\common\User::getIns();
  68. $rs = $userCommon->handle('userlist', ['uid' => [$post['resign_uid'], $post['hand_uid']]]);
  69. $uid_nickname = array_column($rs['data']['list'], 'nickname', 'id');
  70. if (!isset($uid_nickname[$post['resign_uid']])) return json_show(1004, '离职人不存在或不属于该公司');
  71. if (!isset($uid_nickname[$post['hand_uid']])) return json_show(1004, '交接人不存在或不属于该公司');
  72. Db::startTrans();
  73. try {
  74. $status = 0;
  75. $data = [
  76. // 'companyNo' => $post['companyNo'],
  77. "resign_uid" => $post['resign_uid'],
  78. "hand_uid" => $post['hand_uid'],
  79. "resign_name" => $uid_nickname[$post['resign_uid']],
  80. "hand_name" => $uid_nickname[$post['hand_uid']],
  81. "resign_date" => $post['resign_date'],
  82. "expire_date" => $post['expire_date'],
  83. "is_hand" => $post['is_hand'],
  84. "apply_id" => $this->uid,
  85. "apply_name" => $this->uname,
  86. "status" => $status,
  87. "remark" => $post['remark'],
  88. "is_del" => 0,
  89. "addtime" => date("Y-m-d H:i:s"),
  90. "updatetime" => date("Y-m-d H:i:s"),
  91. ];
  92. $in = Db::name('resign_info')->insertGetId($data);
  93. $stn = ["order_code" => '', "status" => $status, "action_remark" => '', "action_type" => "create"];
  94. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $stn, "LZJJ", $status, $stn);
  95. $process = ["order_code" => '', "order_id" => $in, "order_status" => $status, "order_type" => 'LZJJ', "before_status" => 0, 'holder_id' => $this->uid];
  96. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $process);
  97. Db::commit();
  98. return json_show(0, "添加成功");
  99. } catch (Exception $exception) {
  100. Db::rollback();
  101. return json_show(1002, '添加失败,' . $exception->getMessage());
  102. }
  103. }
  104. //详情
  105. public function selec()
  106. {
  107. $id = $this->request->post('id/d', 0, 'trim');
  108. if ($id == 0) return error_show(1002, "离职人员信息不存在");
  109. $rid = Db::name('resign_info')
  110. ->where(['is_del' => 0, 'id' => $id])
  111. ->findOrEmpty();
  112. return app_show(0, "获取成功", $rid);
  113. }
  114. //编辑
  115. public function edit()
  116. {
  117. $post = $this->request->only(['id', 'resign_uid', 'hand_uid', 'resign_date', 'expire_date', 'is_hand' => 0, 'remark' => ''], 'post', 'trim');
  118. $val = Validate::rule([
  119. 'id' => 'require|number|gt:0',
  120. 'resign_uid|离职人' => 'require|number|gt:0',
  121. 'hand_uid|交接人' => 'require|number|gt:0',
  122. 'resign_date|离职日期' => 'require|date',
  123. 'expire_date|生效时间' => 'require|date',
  124. // 'companyNo|所属公司' => 'require|max:255',
  125. 'is_hand|是否交接' => 'require|number|in:0,1',
  126. 'remark|备注' => 'max:255',
  127. ]);
  128. if ($val->check($post) == false) return json_show(1004, $val->getError());
  129. $userCommon = \app\admin\common\User::getIns();
  130. $rs = $userCommon->handle('userlist', ['uid' => [$post['resign_uid'], $post['hand_uid']]]);
  131. $uid_nickname = array_column($rs['data']['list'], 'nickname', 'id');
  132. if (!isset($uid_nickname[$post['resign_uid']])) return json_show(1004, '离职人不存在或不属于该公司');
  133. if (!isset($uid_nickname[$post['hand_uid']])) return json_show(1004, '交接人不存在或不属于该公司');
  134. Db::startTrans();
  135. try {
  136. $rs = Db::name('resign_info')
  137. ->field('id,status')
  138. ->where(['is_del' => 0, 'id' => $post['id']])
  139. ->findOrEmpty();
  140. if (empty($rs)) throw new Exception('离职信息不存在');
  141. $str = [
  142. "hand_name" => $uid_nickname[$post['hand_uid']],
  143. "id" => $post['id'],
  144. "resign_name" => $uid_nickname[$post['resign_uid']],
  145. "resign_uid" => $post['resign_uid'],
  146. "hand_uid" => $post['hand_uid'],
  147. "is_hand" => $post['is_hand'],
  148. "resign_date" => date('Y-m-d H:i:s'),
  149. "is_del" => 0,
  150. // 'companyNo' => $post['companyNo'],
  151. "updatetime" => date('Y-m-d H:i:s'),
  152. ];
  153. $it = Db::name('resign_info')->where(['is_del' => 0, 'id' => $post['id']])->save($str);
  154. $stn = ["order_code" => $post['id'], "status" => 0, "action_remark" => '', "action_type" => "edit"];
  155. ActionLog::logAdd($this->post['token'], $stn, "LZJJ", 0, $stn);
  156. $process = ["order_code" => '', "order_id" => $post['id'], "order_status" => $rs['status'], "order_type" => 'LZJJ', "before_status" => 0, 'holder_id' => $this->uid];
  157. ProcessOrder::AddProcess(['id' => $post['hand_uid'], 'nickname' => $uid_nickname[$post['hand_uid']]], $process);
  158. return error_show(0, "编辑成功");
  159. Db::commit();
  160. return json_show(0, "编辑成功");
  161. } catch (Exception $exception) {
  162. Db::rollback();
  163. return json_show(1002, '编辑失败,' . $exception->getMessage());
  164. }
  165. }
  166. //删除
  167. public function del()
  168. {
  169. $id = isset($this->post['id']) && $this->post['id'] !== "" ? $this->post['id'] : "";
  170. $fid = Db::name('resign_info')->where(['is_del' => 0, 'id' => $id])->findOrEmpty();
  171. if (empty($fid)) return error_show(1002, "离职人员不存在");
  172. Db::startTrans();
  173. try {
  174. $num = Db::name('resign_info')
  175. ->where(['is_del' => 0, 'id' => $id])
  176. ->update(['is_del' => 1, 'id' => $id, "updatetime" => date("Y-m-d H:i:s")]);
  177. if ($num) {
  178. $stn = ["order_code" => "BH", "status" => 0, "action_remark" => '', "action_type" => "delete"];
  179. ActionLog::logAdd($this->post['token'], $stn, "LZJJ", 0, $stn);
  180. //将对应的离职交接单流程的数据都删掉(没有相关的中断节点,所以这里直接操作process_wait表)
  181. Db::name('process_wait')
  182. ->where([
  183. 'order_type' => 'LZJJ',
  184. 'order_id' => $id,
  185. 'status' => ProcessWait::$status_wait,
  186. ])->update(['status' => ProcessWait::$status_interrupt]);
  187. Db::commit();
  188. return app_show(0, "删除成功");
  189. } else throw new Exception();
  190. } catch (Exception $exception) {
  191. Db::rollback();
  192. return error_show(1004, '删除失败,', $exception->getMessage());
  193. }
  194. }
  195. //启禁用
  196. public function statu()
  197. {
  198. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  199. if ($id == "") {
  200. return error_show(1002, "离职人id不能为空");
  201. }
  202. $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
  203. $stauts = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  204. if ($stauts === "") {
  205. return error_show(1002, "状态不能为空");
  206. }
  207. $st = Db::name('resign_info')->where(['id' => $id, "is_del" => 0])->find();
  208. if (empty($st)) {
  209. return error_show(1002, "离职人员信息未找到");
  210. }
  211. $tn = $st['status'];
  212. $st['remark'] = $remark;
  213. $st['status'] = $stauts == 3 && strtotime($st['expire_date']) <= time() ? 4 : $stauts;
  214. $st['updatetime'] = date('Y-m-d H:i:s');
  215. $sv = Db::name('resign_info')->save($st);
  216. if ($sv) {
  217. $stn = ["order_code" => $id, "status" => $tn, "action_remark" => '', "action_type" => "edit"];
  218. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $stn, "LZJJ", $stauts, $st);
  219. $process = ["order_code" => '', "order_id" => $id, "order_status" => $st['status'], "order_type" => 'LZJJ', "before_status" => $tn, 'holder_id' => $this->uid];
  220. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $process);
  221. return error_show(0, "状态更新成功");
  222. } else {
  223. return error_show(1002, "状态更新失败");
  224. }
  225. }
  226. }