Resigninfo.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. //交接
  12. class Resigninfo extends Base
  13. {
  14. public function __construct(App $app)
  15. {
  16. parent::__construct($app);
  17. }
  18. public function list(){
  19. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  20. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  21. $where =[['is_del',"=",0]];
  22. // $resign_depart_id = isset($this->post['resign_depart_id']) && $this->post['resign_depart_id'] !== "" ? intval($this->post['resign_depart_id']) : "";
  23. // if ($resign_depart_id !== "") {
  24. // $where = ["resign_depart_id"=>$resign_depart_id];
  25. // }
  26. // $hand_depart_id = isset($this->post['hand_depart_id']) && $this->post['hand_depart_id'] !== "" ? intval($this->post['hand_depart_id']) : "";
  27. // if ($hand_depart_id !== "") {
  28. // $where = ["hand_depart_id"=>$hand_depart_id];
  29. // }
  30. $status =isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  31. if ($status !== "") {
  32. $where[]= ["status",'=',$status];
  33. }
  34. $resign_uid = isset($this->post['resign_uid']) && $this->post['resign_uid'] !== "" ? intval($this->post['resign_uid']) : "";
  35. if ($resign_uid !== "") {
  36. //$where = ["resign_uid"=>$resign_uid];
  37. $where[]= ["resign_uid",'=',$resign_uid];
  38. }
  39. $hand_uid = isset($this->post['hand_uid']) && $this->post['hand_uid'] !== "" ? intval($this->post['hand_uid']) : "";
  40. if ($hand_uid !== "") {
  41. // $where = ["hand_uid"=>$hand_uid];
  42. $where[]= ["hand_uid",'=',$hand_uid];
  43. }
  44. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  45. if ($start !="") {
  46. // $where = ["addtime"=>Db::raw(">= '{$start}'")];
  47. $where[]= ["addtime",'>=',$start];
  48. }
  49. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  50. if($end !=""){
  51. // $where = ["addtime"=>Db::raw("<= '{$end}'")];
  52. $where[]= ["addtime",'<=',$end];
  53. }
  54. $role = $this->checkDataShare();
  55. if (!empty($role[DataGroupModel::$type_全部])) $where[] = ["hand_uid", "in", $role[DataGroupModel::$type_全部]];
  56. $count = Db::name('resign_info')->where($where)->count();
  57. $total = ceil($count/$size);
  58. $page = $page >= $total ? $total : $page;
  59. $list = Db::name('resign_info')
  60. ->where($where)
  61. ->order("addtime desc")
  62. ->page($page,$size)
  63. ->append(['is_allow_update'])
  64. ->withAttr('is_allow_update', function ($val, $data) use ($role) {
  65. return (in_array($this->roleid, [1, 33]) || in_array($data['hand_uid'], $role[DataGroupModel::$type_可编辑])) ? 1 : 0; //是否具有编辑权限
  66. })
  67. ->select()
  68. ->toArray();
  69. return app_show(0,"获取成功",['list'=>$list,'count'=>$count]);
  70. }
  71. public function create(){
  72. $token =isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
  73. $condition=[];
  74. $resign_id = isset($this->post['resign_uid']) && $this->post['resign_uid'] !==""? trim($this->post['resign_uid']) :"";
  75. if($resign_id==""){
  76. return error_show(1002,"离职人id不能为空");
  77. }
  78. $condition['id']=$resign_id;
  79. $resign_uid=GetInfoById($token,$condition);
  80. if(empty($resign_uid)||$resign_uid['code']!=0){
  81. return error_show(1002,"离职人员信息不存在");
  82. }
  83. $ri= isset($resign_uid["data"]['nickname']) ? $resign_uid["data"]['nickname'] : "";
  84. $hand_id = isset($this->post['hand_uid']) && $this->post['hand_uid'] !==""? trim($this->post['hand_uid']) :"";
  85. if($hand_id==""){
  86. return error_show(1002,"交接人名称不能为空");
  87. }
  88. $condition['id']=$hand_id;
  89. $hand_uid = GetInfoById($token,$condition);
  90. if(empty($hand_uid)||$hand_uid['code']!=0){
  91. return error_show(1002,"交接人员信息不存在");
  92. }
  93. $rp= isset($hand_uid["data"]['nickname']) ? $hand_uid["data"]['nickname'] : "";
  94. $resign_date = isset($this->post['resign_date']) && $this->post['resign_date']!== "" ? $this->post['resign_date']:date("Y-m-d H:i:s");
  95. if($resign_date==""){
  96. return error_show(1005,'离职日期不能为空');
  97. }
  98. $expire_date = isset($this->post['expire_date']) && $this->post['expire_date']!== "" ?
  99. $this->post['expire_date']:date("Y-m-d H:i:s");
  100. if($expire_date==""){
  101. return error_show(1005,'生效时间不能为空');
  102. }
  103. $is_hand = isset($this->post['is_hand']) && $this->post['is_hand'] !=="" ? trim($this->post['is_hand']):"0";
  104. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "0";
  105. $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? intval($this->post['remark']) : "";
  106. $data=[
  107. "resign_uid"=>$resign_id,
  108. "hand_uid"=>$hand_id,
  109. // "resign_depart_id"=>$resign_depart_id,
  110. // "hand_depart_id"=>$hand_depart_id,
  111. "resign_name"=>$ri,
  112. "hand_name"=>$rp,
  113. "resign_date"=> $resign_date,
  114. "expire_date"=>$expire_date,
  115. "is_hand"=>$is_hand,
  116. "status"=>$status,
  117. "remark"=>$remark,
  118. "is_del"=>0,
  119. "addtime"=>date("Y-m-d H:i:s"),
  120. "updatetime"=>date("Y-m-d H:i:s"),
  121. ];
  122. $in = Db::name('resign_info')->insertGetId($data);
  123. $stn = ["order_code"=>'',"status"=>$status,"action_remark"=>'',"action_type"=>"create"];
  124. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$stn,"LZJJ",$status,$stn);
  125. $process=["order_code"=>'',"order_id"=>$in,"order_status"=>$status,"order_type"=>'LZJJ',"before_status"=>0, 'holder_id' => $this->uid];
  126. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process);
  127. return $in ? error_show(0,"添加成功") : error_show(1002,"添加失败");
  128. }
  129. public function selec(){
  130. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  131. if($id==""){
  132. return error_show(1002,"离职人员信息不存在");
  133. }
  134. $rid = Db::name('resign_info')->where(['is_del'=>0,'id'=>$id])->find();
  135. return app_show(0,"获取成功",$rid);
  136. }
  137. public function edit(){
  138. $condition=[];
  139. $token =isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
  140. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  141. $eid = Db::name('resign_info')->where(['is_del'=>0,'id'=>$id])->find();
  142. if($eid==""){
  143. return error_show(1002,"离职信息不存在");
  144. }
  145. $resign_id = isset($this->post['resign_uid']) && $this->post['resign_uid'] !=="" ? trim($this->post['resign_uid']):"";
  146. if($resign_id==""){
  147. return error_show(1002,"离职人员ID不能为空");
  148. }
  149. $condition['id']=$resign_id;
  150. $resign_uid=GetInfoById($token,$condition);
  151. if(empty($resign_uid)||$resign_uid['code']!=0){
  152. return error_show(1002,"离职人员信息不存在");
  153. }
  154. $rr= isset($resign_uid["data"]['nickname']) ? $resign_uid["data"]['nickname'] : "";
  155. $resign_date = isset($this->post['resign_date']) && $this->post['resign_date']!== "" ? $this->post['resign_date']:date("Y-m-d H:i:s");
  156. if($resign_date==""){
  157. return error_show(1005,'离职日期不能为空');
  158. }
  159. $hand_id = isset($this->post['hand_uid']) && $this->post['hand_uid'] !=="" ? trim($this->post['hand_uid']) :"";
  160. if($hand_id=="") {
  161. return error_show(1002, "交接人员id不能为空");
  162. }
  163. $condition['id']=$hand_id;
  164. $hand_uid = GetInfoById($token,$condition);
  165. if(empty($hand_uid)||$hand_uid['code']!=0){
  166. return error_show(1002,"交接人员信息不存在");
  167. }
  168. $r= isset($hand_uid["data"]['nickname']) ? $hand_uid["data"]['nickname'] : "";
  169. $is_hand = isset($this->post['is_hand']) && $this->post['is_hand'] !=="" ? trim($this->post['is_hand']):"0";
  170. $str=[
  171. "hand_name"=>$r,
  172. "resign_name"=>$rr,
  173. "id"=>$id,
  174. "resign_uid"=>$resign_id,
  175. "hand_uid"=>$hand_id,
  176. "is_hand"=>$is_hand,
  177. "resign_date"=>date('Y-m-d H:i:s'),
  178. "is_del"=>0,
  179. "updatetime"=>date('Y-m-d H:i:s'),
  180. ];
  181. $it = Db::name('resign_info')->where(['is_del'=>0,'id'=>$id])->save($str);
  182. if($it){
  183. $stn = ["order_code"=>$id,"status"=>0,"action_remark"=>'',"action_type"=>"edit"];
  184. ActionLog::logAdd($this->post['token'],$stn,"LZJJ",0,$stn);
  185. $process=["order_code"=>'',"order_id"=>$id,"order_status"=>$eid['status'],"order_type"=>'LZJJ',"before_status"=>0, 'holder_id' => $this->uid];
  186. ProcessOrder::AddProcess(['id'=>$hand_id,'nickname'=>$r],$process);
  187. return error_show(0,"编辑成功");
  188. }else{
  189. return error_show(1002,"编辑失败");
  190. }
  191. }
  192. public function del(){
  193. $id = isset($this->post['id']) && $this->post['id'] !== "" ? $this->post['id'] : "";
  194. $fid = Db::name('resign_info')->where(['is_del' => 0, 'id' => $id])->find();
  195. if ($fid == false) return error_show(1002, "离职人员不存在");
  196. Db::startTrans();
  197. try {
  198. $num = Db::name('resign_info')
  199. ->where(['is_del' => 0, 'id' => $id])
  200. ->update(['is_del' => 1, 'id' => $id, "updatetime" => date("Y-m-d H:i:s")]);
  201. if ($num) {
  202. $stn = ["order_code" => "BH", "status" => 0, "action_remark" => '', "action_type" => "delete"];
  203. ActionLog::logAdd($this->post['token'], $stn, "LZJJ", 0, $stn);
  204. //将对应的离职交接单流程的数据都删掉(没有相关的中断节点,所以这里直接操作process_wait表)
  205. Db::name('process_wait')
  206. ->where([
  207. 'order_type' => 'LZJJ',
  208. 'order_id' => $id,
  209. 'status' => ProcessWait::$status_wait,
  210. ])->update(['status' => ProcessWait::$status_interrupt]);
  211. Db::commit();
  212. return app_show(0, "删除成功");
  213. } else throw new Exception("删除失败");
  214. } catch (Exception $exception) {
  215. Db::rollback();
  216. return error_show(1004, $exception->getMessage());
  217. }
  218. // $id = isset($this->post['id']) && $this->post['id'] !=="" ? $this->post['id']:"";
  219. // $fid = Db::name('resign_info')->where(['is_del'=>0,'id'=>$id])->find();
  220. // if($fid==false){
  221. // return error_show(1002,"离职人员不存在");
  222. // }
  223. // $num = Db::name('resign_info')->update(['is_del'=>1,'id'=>$id,"updatetime"=>date("Y-m-d H:i:s")]);
  224. // if($num){
  225. // $stn = ["order_code"=>"BH","status"=>0,"action_remark"=>'',"action_type"=>"delete"];
  226. // ActionLog::logAdd($this->post['token'],$stn,"LZJJ",0,$stn);
  227. // return error_show(0,"删除成功");
  228. // }else{
  229. // return error_show(1002,"删除失败");
  230. // }
  231. }
  232. public function statu(){
  233. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  234. if($id==""){
  235. return error_show(1002,"离职人id不能为空");
  236. }
  237. $remark = isset($this->post['remark']) && $this->post['remark'] !=="" ? trim($this->post['remark']) :"";
  238. $stauts = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
  239. if($stauts===""){
  240. return error_show(1002,"状态不能为空");
  241. }
  242. $st = Db::name('resign_info')->where(['id'=>$id,"is_del"=>0])->find();
  243. if(empty($st)){
  244. return error_show(1002,"离职人员信息未找到");
  245. }
  246. $tn =$st['status'];
  247. $st['remark']=$remark;
  248. $st['status']=$stauts==3 && strtotime($st['expire_date'])>=time() ? 4 :$stauts;
  249. $st['updatetime']= date('Y-m-d H:i:s');
  250. $sv = Db::name('resign_info')->save($st);
  251. if($sv){
  252. $stn = ["order_code"=>$id,"status"=>$tn,"action_remark"=>'',"action_type"=>"edit"];
  253. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$stn,"LZJJ",$stauts,$st);
  254. $process = ["order_code" => '', "order_id" => $id, "order_status" => $st['status'], "order_type" => 'LZJJ', "before_status" => $tn, 'holder_id' => $this->uid];
  255. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process);
  256. return error_show(0,"状态更新成功");
  257. }else{
  258. return error_show(1002,"状态更新失败");
  259. }
  260. }
  261. }