123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- <?php
- namespace app\admin\controller;
- use app\BaseController;
- use think\App;
- use think\facade\Db;
- use app\admin\model\ActionLog;
- //交接
- class Resigninfo extends BaseController
- {
- public $post="";
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->post = $this->request->post();
- $token = isset($this->post['token']) ? trim($this->post['token']) : "";
- if($token==""){
- return error_show(101,'token不能为空');
- }
- $effetc = VerifyTokens($token);
- if(!empty($effetc) && $effetc['code']!=0) {
- return error_show($effetc['code'], $effetc['message']);
- }
- }
- public function list(){
- $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
- $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
- $where =[['is_del',"=",0]];
- // $resign_depart_id = isset($this->post['resign_depart_id']) && $this->post['resign_depart_id'] !== "" ? intval($this->post['resign_depart_id']) : "";
- // if ($resign_depart_id !== "") {
- // $where = ["resign_depart_id"=>$resign_depart_id];
- // }
- // $hand_depart_id = isset($this->post['hand_depart_id']) && $this->post['hand_depart_id'] !== "" ? intval($this->post['hand_depart_id']) : "";
- // if ($hand_depart_id !== "") {
- // $where = ["hand_depart_id"=>$hand_depart_id];
- // }
- $status =isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
- if ($status !== "") {
- $where[]= ["status",'=',$status];
- }
- $resign_uid = isset($this->post['resign_uid']) && $this->post['resign_uid'] !== "" ? intval($this->post['resign_uid']) : "";
- if ($resign_uid !== "") {
- //$where = ["resign_uid"=>$resign_uid];
- $where[]= ["resign_uid",'=',$resign_uid];
- }
- $hand_uid = isset($this->post['hand_uid']) && $this->post['hand_uid'] !== "" ? intval($this->post['hand_uid']) : "";
- if ($hand_uid !== "") {
- // $where = ["hand_uid"=>$hand_uid];
- $where[]= ["hand_uid",'=',$hand_uid];
- }
- $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
- if ($start !="") {
- // $where = ["addtime"=>Db::raw(">= '{$start}'")];
- $where[]= ["addtime",'>=',$start];
- }
- $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
- if($end !=""){
- // $where = ["addtime"=>Db::raw("<= '{$end}'")];
- $where[]= ["addtime",'<=',$end];
- }
- $count = Db::name('resign_info')->where($where)->count();
- $total = ceil($count/$size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name('resign_info')->where($where)->order("addtime desc")->page($page,$size)->select();
- return app_show(0,"获取成功",['list'=>$list,'count'=>$count]);
- }
- public function create(){
- $token =isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
- $condition=[];
- $resign_id = isset($this->post['resign_uid']) && $this->post['resign_uid'] !==""? trim($this->post['resign_uid']) :"";
- if($resign_id==""){
- return error_show(1002,"离职人id不能为空");
- }
- $condition['id']=$resign_id;
- $resign_uid=GetInfoById($token,$condition);
- if(empty($resign_uid)||$resign_uid['code']!=0){
- return error_show(1002,"离职人员信息不存在");
- }
- $ri= isset($resign_uid["data"]['nickname']) ? $resign_uid["data"]['nickname'] : "";
- $hand_id = isset($this->post['hand_uid']) && $this->post['hand_uid'] !==""? trim($this->post['hand_uid']) :"";
- if($hand_id==""){
- return error_show(1002,"交接人名称不能为空");
- }
- $condition['id']=$hand_id;
- $hand_uid = GetInfoById($token,$condition);
- if(empty($hand_uid)||$hand_uid['code']!=0){
- return error_show(1002,"交接人员信息不存在");
- }
- $rp= isset($hand_uid["data"]['nickname']) ? $hand_uid["data"]['nickname'] : "";
- $resign_date = isset($this->post['resign_date']) && $this->post['resign_date']!== "" ? $this->post['resign_date']:date("Y-m-d H:i:s");
- if($resign_date==""){
- return error_show(1005,'离职日期不能为空');
- }
- $expire_date = isset($this->post['expire_date']) && $this->post['expire_date']!== "" ?
- $this->post['expire_date']:date("Y-m-d H:i:s");
- if($expire_date==""){
- return error_show(1005,'生效时间不能为空');
- }
- $is_hand = isset($this->post['is_hand']) && $this->post['is_hand'] !=="" ? trim($this->post['is_hand']):"0";
- $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "0";
- $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? intval($this->post['remark']) : "";
- $data=[
- "resign_uid"=>$resign_id,
- "hand_uid"=>$hand_id,
- // "resign_depart_id"=>$resign_depart_id,
- // "hand_depart_id"=>$hand_depart_id,
- "resign_name"=>$ri,
- "hand_name"=>$rp,
- "resign_date"=> $resign_date,
- "expire_date"=>$expire_date,
- "is_hand"=>$is_hand,
- "status"=>$status,
- "remark"=>$remark,
- "is_del"=>0,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s"),
- ];
- $in = Db::name('resign_info')->insert($data);
- $stn = ["order_code"=>"BH","status"=>$status,"action_remark"=>'',"action_type"=>"create"];
- ActionLog::logAdd($this->post['token'],$stn,"离职交接",$status,$stn);
- return $in ? error_show(0,"添加成功") : error_show(1002,"添加失败");
- }
- public function selec(){
- $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
- if($id==""){
- return error_show(1002,"离职人员信息不存在");
- }
- $rid = Db::name('resign_info')->where(['is_del'=>0,'id'=>$id])->find();
- return app_show(0,"获取成功",$rid);
- }
- public function edit(){
- $condition=[];
- $token =isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
- $eid = Db::name('resign_info')->where(['is_del'=>0,'id'=>$id])->find();
- if($eid==""){
- return error_show(1002,"离职信息不存在");
- }
- $resign_id = isset($this->post['resign_uid']) && $this->post['resign_uid'] !=="" ? trim($this->post['resign_uid']):"";
- if($resign_id==""){
- return error_show(1002,"离职人员ID不能为空");
- }
- $condition['id']=$resign_id;
- $resign_uid=GetInfoById($token,$condition);
- if(empty($resign_uid)||$resign_uid['code']!=0){
- return error_show(1002,"离职人员信息不存在");
- }
- $rr= isset($resign_uid["data"]['nickname']) ? $resign_uid["data"]['nickname'] : "";
- $resign_date = isset($this->post['resign_date']) && $this->post['resign_date']!== "" ? $this->post['resign_date']:date("Y-m-d H:i:s");
- if($resign_date==""){
- return error_show(1005,'离职日期不能为空');
- }
- $hand_id = isset($this->post['hand_uid']) && $this->post['hand_uid'] !=="" ? trim($this->post['hand_uid']) :"";
- if($hand_id=="") {
- return error_show(1002, "交接人员id不能为空");
- }
- $condition['id']=$hand_id;
- $hand_uid = GetInfoById($token,$condition);
- if(empty($hand_uid)||$hand_uid['code']!=0){
- return error_show(1002,"交接人员信息不存在");
- }
- $r= isset($hand_uid["data"]['nickname']) ? $hand_uid["data"]['nickname'] : "";
- $is_hand = isset($this->post['is_hand']) && $this->post['is_hand'] !=="" ? trim($this->post['is_hand']):"0";
- $str=[
- "hand_name"=>$r,
- "resign_name"=>$rr,
- "id"=>$id,
- "resign_uid"=>$resign_id,
- "hand_uid"=>$hand_id,
- "is_hand"=>$is_hand,
- "resign_date"=>date('Y-m-d H:i:s'),
- "is_del"=>0,
- "updatetime"=>date('Y-m-d H:i:s'),
- ];
- $it = Db::name('resign_info')->where(['is_del'=>0,'id'=>$id])->save($str);
- if($it){
- $stn = ["order_code"=>"BH","status"=>0,"action_remark"=>'',"action_type"=>"edit"];
- ActionLog::logAdd($this->post['token'],$stn,"resign_info",0,$stn);
- return error_show(0,"编辑成功");
- }else{
- return error_show(1002,"编辑失败");
- }
- }
- public function del(){
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? $this->post['id']:"";
- $fid = Db::name('resign_info')->where(['is_del'=>0,'id'=>$id])->find();
- if($fid==false){
- return error_show(1002,"离职人员不存在");
- }
- $num = Db::name('resign_info')->update(['is_del'=>1,'id'=>$id,"updatetime"=>date("Y-m-d H:i:s")]);
- if($num){
- $stn = ["order_code"=>"BH","status"=>0,"action_remark"=>'',"action_type"=>"delete"];
- ActionLog::logAdd($this->post['token'],$stn,"resign_info",0,$stn);
- return error_show(0,"删除成功");
- }else{
- return error_show(1002,"删除失败");
- }
- }
- public function statu(){
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
- if($id==""){
- return error_show(1002,"离职人id不能为空");
- }
- $remark = isset($this->post['remark']) && $this->post['remark'] !=="" ? trim($this->post['remark']) :"";
- $stauts = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
- if($stauts===""){
- return error_show(1002,"状态不能为空");
- }
- $st = Db::name('resign_info')->where(['id'=>$id,"is_del"=>0])->find();
- if(empty($st)){
- return error_show(1002,"离职人员信息未找到");
- }
- $tn =$st['status'];
- $st['remark']=$remark;
- $st['status']=$stauts==3 && strtotime($st['expire_date'])>=time() ? 4 :$stauts;
- $st['updatetime']= date('Y-m-d H:i:s');
- $sv = Db::name('resign_info')->save($st);
- if($sv){
- $stn = ["order_code"=>$id,"status"=>$tn,"action_remark"=>'',"action_type"=>"edit"];
- ActionLog::logAdd($this->post['token'],$stn,"resign_info",$stauts,$st);
- return error_show(0,"状态更新成功");
- }else{
- return error_show(1002,"状态更新失败");
- }
- }
- }
|