Resigninfo.php 12 KB

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