Resigninfo.php 11 KB

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