Resigninfo.php 10 KB

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