123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\DataGroup as DataGroupModel;
- use app\admin\model\ProcessOrder;
- use app\admin\model\ProcessWait;
- use app\BaseController;
- use think\App;
- use think\Exception;
- use think\facade\Db;
- use app\admin\model\ActionLog;
- //交接
- class Resigninfo extends Base
- {
- public function __construct(App $app)
- {
- parent::__construct($app);
- }
- 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];
- }
- $role = $this->checkDataShare();
- if (!empty($role[DataGroupModel::$type_全部])) $where[] = ["hand_uid", "in", $role[DataGroupModel::$type_全部]];
- $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)
- ->append(['is_allow_update'])
- ->withAttr('is_allow_update', function ($val, $data) use ($role) {
- return (in_array($this->roleid, [1, 33]) || in_array($data['hand_uid'], $role[DataGroupModel::$type_可编辑])) ? 1 : 0; //是否具有编辑权限
- })
- ->select()
- ->toArray();
- 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')->insertGetId($data);
- $stn = ["order_code"=>'',"status"=>$status,"action_remark"=>'',"action_type"=>"create"];
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$stn,"LZJJ",$status,$stn);
- $process=["order_code"=>'',"order_id"=>$in,"order_status"=>$status,"order_type"=>'LZJJ',"before_status"=>0, 'holder_id' => $this->uid];
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process);
- 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"=>$id,"status"=>0,"action_remark"=>'',"action_type"=>"edit"];
- ActionLog::logAdd($this->post['token'],$stn,"LZJJ",0,$stn);
- $process=["order_code"=>'',"order_id"=>$id,"order_status"=>$eid['status'],"order_type"=>'LZJJ',"before_status"=>0, 'holder_id' => $this->uid];
- ProcessOrder::AddProcess(['id'=>$hand_id,'nickname'=>$r],$process);
- 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, "离职人员不存在");
- Db::startTrans();
- try {
- $num = Db::name('resign_info')
- ->where(['is_del' => 0, 'id' => $id])
- ->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, "LZJJ", 0, $stn);
- //将对应的离职交接单流程的数据都删掉(没有相关的中断节点,所以这里直接操作process_wait表)
- Db::name('process_wait')
- ->where([
- 'order_type' => 'LZJJ',
- 'order_id' => $id,
- 'status' => ProcessWait::$status_wait,
- ])->update(['status' => ProcessWait::$status_interrupt]);
- Db::commit();
- return app_show(0, "删除成功");
- } else throw new Exception("删除失败");
- } catch (Exception $exception) {
- Db::rollback();
- return error_show(1004, $exception->getMessage());
- }
- // $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,"LZJJ",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(['id'=>$this->uid,'nickname'=>$this->uname],$stn,"LZJJ",$stauts,$st);
- $process = ["order_code" => '', "order_id" => $id, "order_status" => $st['status'], "order_type" => 'LZJJ', "before_status" => $tn, 'holder_id' => $this->uid];
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process);
- return error_show(0,"状态更新成功");
- }else{
- return error_show(1002,"状态更新失败");
- }
- }
- }
|