Resigninfo.php 13 KB

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