Resigninfo.php 11 KB

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