Resigninfo.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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', '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. "status"=>$status,
  123. "remark"=>$remark,
  124. "is_del"=>0,
  125. "addtime"=>date("Y-m-d H:i:s"),
  126. "updatetime"=>date("Y-m-d H:i:s"),
  127. ];
  128. $in = Db::name('resign_info')->insertGetId($data);
  129. $stn = ["order_code"=>'',"status"=>$status,"action_remark"=>'',"action_type"=>"create"];
  130. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$stn,"LZJJ",$status,$stn);
  131. $process=["order_code"=>'',"order_id"=>$in,"order_status"=>$status,"order_type"=>'LZJJ',"before_status"=>0, 'holder_id' => $this->uid];
  132. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process);
  133. return $in ? error_show(0,"添加成功") : error_show(1002,"添加失败");
  134. }
  135. public function selec(){
  136. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  137. if($id==""){
  138. return error_show(1002,"离职人员信息不存在");
  139. }
  140. $rid = Db::name('resign_info')->where(['is_del'=>0,'id'=>$id])->find();
  141. return app_show(0,"获取成功",$rid);
  142. }
  143. public function edit(){
  144. $condition=[];
  145. $token =isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
  146. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  147. $eid = Db::name('resign_info')->where(['is_del'=>0,'id'=>$id])->find();
  148. if($eid==""){
  149. return error_show(1002,"离职信息不存在");
  150. }
  151. $resign_id = isset($this->post['resign_uid']) && $this->post['resign_uid'] !=="" ? trim($this->post['resign_uid']):"";
  152. if($resign_id==""){
  153. return error_show(1002,"离职人员ID不能为空");
  154. }
  155. $condition['id']=$resign_id;
  156. $resign_uid=GetInfoById($token,$condition);
  157. if(empty($resign_uid)||$resign_uid['code']!=0){
  158. return error_show(1002,"离职人员信息不存在");
  159. }
  160. $rr= isset($resign_uid["data"]['nickname']) ? $resign_uid["data"]['nickname'] : "";
  161. $resign_date = isset($this->post['resign_date']) && $this->post['resign_date']!== "" ? $this->post['resign_date']:date("Y-m-d H:i:s");
  162. if($resign_date==""){
  163. return error_show(1005,'离职日期不能为空');
  164. }
  165. $hand_id = isset($this->post['hand_uid']) && $this->post['hand_uid'] !=="" ? trim($this->post['hand_uid']) :"";
  166. if($hand_id=="") {
  167. return error_show(1002, "交接人员id不能为空");
  168. }
  169. $condition['id']=$hand_id;
  170. $hand_uid = GetInfoById($token,$condition);
  171. if(empty($hand_uid)||$hand_uid['code']!=0){
  172. return error_show(1002,"交接人员信息不存在");
  173. }
  174. $r= isset($hand_uid["data"]['nickname']) ? $hand_uid["data"]['nickname'] : "";
  175. $is_hand = isset($this->post['is_hand']) && $this->post['is_hand'] !=="" ? trim($this->post['is_hand']):"0";
  176. $str=[
  177. "hand_name"=>$r,
  178. "resign_name"=>$rr,
  179. "id"=>$id,
  180. "resign_uid"=>$resign_id,
  181. "hand_uid"=>$hand_id,
  182. "is_hand"=>$is_hand,
  183. "resign_date"=>date('Y-m-d H:i:s'),
  184. "is_del"=>0,
  185. "updatetime"=>date('Y-m-d H:i:s'),
  186. ];
  187. $it = Db::name('resign_info')->where(['is_del'=>0,'id'=>$id])->save($str);
  188. if($it){
  189. $stn = ["order_code"=>$id,"status"=>0,"action_remark"=>'',"action_type"=>"edit"];
  190. ActionLog::logAdd($this->post['token'],$stn,"LZJJ",0,$stn);
  191. $process=["order_code"=>'',"order_id"=>$id,"order_status"=>$eid['status'],"order_type"=>'LZJJ',"before_status"=>0, 'holder_id' => $this->uid];
  192. ProcessOrder::AddProcess(['id'=>$hand_id,'nickname'=>$r],$process);
  193. return error_show(0,"编辑成功");
  194. }else{
  195. return error_show(1002,"编辑失败");
  196. }
  197. }
  198. public function del(){
  199. $id = isset($this->post['id']) && $this->post['id'] !== "" ? $this->post['id'] : "";
  200. $fid = Db::name('resign_info')->where(['is_del' => 0, 'id' => $id])->find();
  201. if ($fid == false) return error_show(1002, "离职人员不存在");
  202. Db::startTrans();
  203. try {
  204. $num = Db::name('resign_info')
  205. ->where(['is_del' => 0, 'id' => $id])
  206. ->update(['is_del' => 1, 'id' => $id, "updatetime" => date("Y-m-d H:i:s")]);
  207. if ($num) {
  208. $stn = ["order_code" => "BH", "status" => 0, "action_remark" => '', "action_type" => "delete"];
  209. ActionLog::logAdd($this->post['token'], $stn, "LZJJ", 0, $stn);
  210. //将对应的离职交接单流程的数据都删掉(没有相关的中断节点,所以这里直接操作process_wait表)
  211. Db::name('process_wait')
  212. ->where([
  213. 'order_type' => 'LZJJ',
  214. 'order_id' => $id,
  215. 'status' => ProcessWait::$status_wait,
  216. ])->update(['status' => ProcessWait::$status_interrupt]);
  217. Db::commit();
  218. return app_show(0, "删除成功");
  219. } else throw new Exception("删除失败");
  220. } catch (Exception $exception) {
  221. Db::rollback();
  222. return error_show(1004, $exception->getMessage());
  223. }
  224. // $id = isset($this->post['id']) && $this->post['id'] !=="" ? $this->post['id']:"";
  225. // $fid = Db::name('resign_info')->where(['is_del'=>0,'id'=>$id])->find();
  226. // if($fid==false){
  227. // return error_show(1002,"离职人员不存在");
  228. // }
  229. // $num = Db::name('resign_info')->update(['is_del'=>1,'id'=>$id,"updatetime"=>date("Y-m-d H:i:s")]);
  230. // if($num){
  231. // $stn = ["order_code"=>"BH","status"=>0,"action_remark"=>'',"action_type"=>"delete"];
  232. // ActionLog::logAdd($this->post['token'],$stn,"LZJJ",0,$stn);
  233. // return error_show(0,"删除成功");
  234. // }else{
  235. // return error_show(1002,"删除失败");
  236. // }
  237. }
  238. public function statu(){
  239. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  240. if($id==""){
  241. return error_show(1002,"离职人id不能为空");
  242. }
  243. $remark = isset($this->post['remark']) && $this->post['remark'] !=="" ? trim($this->post['remark']) :"";
  244. $stauts = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
  245. if($stauts===""){
  246. return error_show(1002,"状态不能为空");
  247. }
  248. $st = Db::name('resign_info')->where(['id'=>$id,"is_del"=>0])->find();
  249. if(empty($st)){
  250. return error_show(1002,"离职人员信息未找到");
  251. }
  252. $tn =$st['status'];
  253. $st['remark']=$remark;
  254. $st['status']=$stauts==3 && strtotime($st['expire_date'])>=time() ? 4 :$stauts;
  255. $st['updatetime']= date('Y-m-d H:i:s');
  256. $sv = Db::name('resign_info')->save($st);
  257. if($sv){
  258. $stn = ["order_code"=>$id,"status"=>$tn,"action_remark"=>'',"action_type"=>"edit"];
  259. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$stn,"LZJJ",$stauts,$st);
  260. $process = ["order_code" => '', "order_id" => $id, "order_status" => $st['status'], "order_type" => 'LZJJ', "before_status" => $tn, 'holder_id' => $this->uid];
  261. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process);
  262. return error_show(0,"状态更新成功");
  263. }else{
  264. return error_show(1002,"状态更新失败");
  265. }
  266. }
  267. }