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. 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. // $resign_depart_id = isset($this->post['resign_depart_uid']) && $this->post['resign_depart_uid'] !=="" ?$this->post['resign_depart_uid'] :"";
  93. // if($resign_depart_id==""){
  94. // return error_show(1005,"离职人部门id不能为空");
  95. // }
  96. // $hand_depart_id = isset($this->post['hand_depart_uid']) && $this->post['hand_depart_uid'] !=="" ? $this->post['hand_depart_uid']:"";
  97. // if($hand_depart_id==""){
  98. // return error_show(1005,"交接人部门id不能为空");
  99. // }
  100. $is_hand = isset($this->post['is_hand']) && $this->post['is_hand'] !=="" ? trim($this->post['is_hand']):"0";
  101. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "0";
  102. $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? intval($this->post['remark']) : "";
  103. $data=[
  104. "resign_uid"=>$resign_id,
  105. "hand_uid"=>$hand_id,
  106. // "resign_depart_id"=>$resign_depart_id,
  107. // "hand_depart_id"=>$hand_depart_id,
  108. "resign_name"=>$ri,
  109. "hand_name"=>$rp,
  110. "resign_date"=>date("Y-m-d H:i:s"),
  111. "is_hand"=>$is_hand,
  112. "status"=>$status,
  113. "remark"=>$remark,
  114. "is_del"=>0,
  115. "addtime"=>date("Y-m-d H:i:s"),
  116. "updatetime"=>date("Y-m-d H:i:s"),
  117. ];
  118. $in = Db::name('resign_info')->insert($data);
  119. $stn = ["order_code"=>$resign_id,"status"=>$status,"action_remark"=>'',"action_type"=>"create"];
  120. ActionLog::logAdd($this->post['token'],$stn,"resign_info",$status,$stn);
  121. return $in ? error_show(0,"添加成功") : error_show(1002,"添加失败");
  122. }
  123. public function selec(){
  124. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  125. if($id==""){
  126. return error_show(1002,"离职人员信息不存在");
  127. }
  128. $rid = Db::name('resign_info')->where(['is_del'=>0,'id'=>$id])->find();
  129. return app_show(0,"获取成功",$rid);
  130. }
  131. public function edit(){
  132. $condition=[];
  133. $token =isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
  134. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  135. $eid = Db::name('resign_info')->where(['is_del'=>0,'id'=>$id])->find();
  136. if($eid==""){
  137. return error_show(1002,"离职信息不存在");
  138. }
  139. $resign_id = isset($this->post['resign_uid']) && $this->post['resign_uid'] !=="" ? trim($this->post['resign_uid']):"";
  140. if($resign_id==""){
  141. return error_show(1002,"离职人员ID不能为空");
  142. }
  143. $condition['id']=$resign_id;
  144. $resign_uid=GetInfoById($token,$condition);
  145. if(empty($resign_uid)||$resign_uid['code']!=0){
  146. return error_show(1002,"离职人员信息不存在");
  147. }
  148. $rr= isset($resign_uid["data"]['nickname']) ? $resign_uid["data"]['nickname'] : "";
  149. $resign_date = isset($this->post['resign_date']) && $this->post['resign_date']!== "" ? $this->post['resign_date']:date("Y-m-d H:i:s");
  150. if($resign_date==""){
  151. return error_show(1005,'离职日期不能为空');
  152. }
  153. $hand_id = isset($this->post['hand_uid']) && $this->post['hand_uid'] !=="" ? trim($this->post['hand_uid']) :"";
  154. if($hand_id=="") {
  155. return error_show(1002, "交接人员id不能为空");
  156. }
  157. $condition['id']=$hand_id;
  158. $hand_uid = GetInfoById($token,$condition);
  159. if(empty($hand_uid)||$hand_uid['code']!=0){
  160. return error_show(1002,"交接人员信息不存在");
  161. }
  162. $r= isset($hand_uid["data"]['nickname']) ? $hand_uid["data"]['nickname'] : "";
  163. $is_hand = isset($this->post['is_hand']) && $this->post['is_hand'] !=="" ? trim($this->post['is_hand']):"0";
  164. $str=[
  165. "hand_name"=>$r,
  166. "resign_name"=>$rr,
  167. "id"=>$id,
  168. "resign_uid"=>$resign_id,
  169. "hand_uid"=>$hand_id,
  170. "is_hand"=>$is_hand,
  171. "resign_date"=>date('Y-m-d H:i:s'),
  172. "is_del"=>0,
  173. "updatetime"=>date('Y-m-d H:i:s'),
  174. ];
  175. $it = Db::name('resign_info')->where(['is_del'=>0,'id'=>$id])->save($str);
  176. if($it){
  177. $stn = ["order_code"=>$id,"status"=>0,"action_remark"=>'',"action_type"=>"edit"];
  178. ActionLog::logAdd($this->post['token'],$stn,"resign_info",0,$stn);
  179. return error_show(0,"编辑成功");
  180. }else{
  181. return error_show(1002,"编辑失败");
  182. }
  183. }
  184. public function del(){
  185. $id = isset($this->post['id']) && $this->post['id'] !=="" ? $this->post['id']:"";
  186. $fid = Db::name('resign_info')->where(['is_del'=>0,'id'=>$id])->find();
  187. if($fid==false){
  188. return error_show(1002,"离职人员不存在");
  189. }
  190. $num = Db::name('resign_info')->update(['is_del'=>1,'id'=>$id,"updatetime"=>date("Y-m-d H:i:s")]);
  191. if($num){
  192. $stn = ["order_code"=>$id,"status"=>0,"action_remark"=>'',"action_type"=>"delete"];
  193. ActionLog::logAdd($this->post['token'],$stn,"resign_info",0,$stn);
  194. return error_show(0,"删除成功");
  195. }else{
  196. return error_show(1002,"删除失败");
  197. }
  198. }
  199. public function statu(){
  200. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  201. if($id==""){
  202. return error_show(1002,"离职人id不能为空");
  203. }
  204. $remark = isset($this->post['remark']) && $this->post['remark'] !=="" ? trim($this->post['remark']) :"";
  205. $stauts = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
  206. if($stauts===""){
  207. return error_show(1002,"状态不能为空");
  208. }
  209. $st = Db::name('resign_info')->where(['id'=>$id,"is_del"=>0])->find();
  210. if(empty($st)){
  211. return error_show(1002,"离职人员信息未找到");
  212. }
  213. $tn =$st['status'];
  214. $st['remark']=$remark;
  215. $st['status']=$stauts;
  216. $st['updatetime']= date('Y-m-d H:i:s');
  217. $sv = Db::name('resign_info')->save($st);
  218. if($sv){
  219. $stn = ["order_code"=>$id,"status"=>$tn,"action_remark"=>'',"action_type"=>"edit"];
  220. ActionLog::logAdd($this->post['token'],$stn,"resign_info",$stauts,$stn);
  221. return error_show(0,"状态更新成功");
  222. }else{
  223. return error_show(1002,"状态更新失败");
  224. }
  225. }
  226. }