post['page']) && $this->post['page'] != "" ? intval($this->post['page']) : 1; $size = isset($this->post['size']) && $this->post['size'] != "" ? intval($this->post['size']) : 10; $us=[]; $count = Db::name("depart_user")->where($us)->count(); $page>=ceil($count/$size) ? $page=ceil($count/$size) :""; $list = Db::name("depart_user")->alias('b')->join('company_item a','a.id=b.itemid','left') ->field('a.name,b.itemid,b.uid,b.nickname')->where($us)->page($page,$size)->select(); $i=[]; foreach ($list as $p){ $tips = Db::name('depart_tips')->where(['is_del'=>0,'depart_uid'=>$p['uid']])->select(); $p['total_tips']=$tips; $i[]=$p; } return app_show(0, '信息获取成功', ['list' => $i, 'count' => $count]); } /*添加*/ public function attend(){ $uid = isset($this->post['uid']) && $this->post['uid'] !==""? trim($this->post['uid']):""; if($uid==""){ return error_show(1004,"员工id不能为空"); } $token = isset($this->post['token']) ? trim($this->post['token']) : ""; $to= GetInfoById($token,['id'=>$uid]); if(empty($to)||$to['code']!=0){ return app_show(1002,"员工信息不存在"); } $nickname = isset($to['data']['nickname']) &&$to['data']['nickname']!="" ? $to['data']['nickname'] :"" ; $itemid = isset($this->post['itemid']) && $this->post['itemid'] !==""? trim($this->post['itemid']):""; if($itemid==""){ return error_show(1004,"部门不能为空"); } $repeat_itemid = Db::name("depart_user")->where(["is_del"=>0,"itemid"=>$itemid,"uid"=>$uid])->find(); if(!empty($repeat_itemid)){ return error_show(1004,"部门用户已存在"); } $tid = Db::name('company_item')->where(['id'=>$itemid,'is_del'=>0])->find(); //var_dump( Db::name('company_item')->getLastSql()); if(empty($tid)){ return error_show(1004,"部门不存在"); } $status = isset($this->post['status']) && $this->post['status'] !==""? trim($this->post['status']) : "1"; if($status==""){ return error_show(0,"状态不能为空"); } Db::startTrans(); try{ $data = [ 'uid'=>$uid,'nickname'=>$nickname,'itemid'=>$itemid, 'is_del'=>0,'status'=>$status, 'addtime'=>date("Y-m-d H:i:s"), 'updatetime'=>date("Y-m-d H:i:s") ]; $str=Db::name('depart_user')->insert($data); if($str){ $orde = ["order_code"=>$uid,"status"=>$status,"action_remark"=>'',"action_type"=>"create"]; ActionLog::logAdd($this->post['token'],$orde,'depart_user',$status,$orde); Db::commit(); return error_show(0,"添加成功"); }else{ Db::rollback(); return error_show(1002,"添加失败"); } }catch (\Exception $e){ return error_show(1003,$e->getMessage()); } } /*编辑*/ public function useredit(){ $token = isset($this->post['token']) ? trim($this->post['token']) : ""; $id = isset($this->post['id']) &&$this->post['id'] !==""? trim($this->post['id']):""; if($id ==""){ return error_show(1004,"id不能为空"); } $nid = Db::name('depart_user')->where(['id'=>$id,'is_del'=>0])->find(); if(empty($nid)){ return error_show(1004,"id不能为空"); } $uid = isset($this->post['uid']) && $this->post['uid'] !==""? trim($this->post['uid']):""; if($uid ==""){ return error_show(1004,"员工id不能为空"); } $to= GetInfoById($token,['id'=>$uid]); if(empty($to)||$to['code']!=0){ return app_show(1002,"员工信息不存在"); } $nickname = isset($to['data']['nickname']) &&$to['data']['nickname']!="" ? $to['data']['nickname'] :"" ; $itemid = isset($this->post['itemid']) && $this->post['itemid'] !==""?($this->post)['itemid']: ""; if($itemid==""){ return error_show(1004,"部门id不能为空"); } $repeat_itemid = Db::name("depart_user")->where(["is_del"=>0,"itemid"=>$itemid,"uid"=>$uid])->where('id','<>',$id)->find(); if(!empty($repeat_itemid)){ return error_show(1004,"部门用户已存在"); } try{ $d=[ 'uid'=>$uid,'itemid'=>$itemid,'nickname'=>$nickname, 'is_del'=>0,'addtime'=>date("Y-m-d H:i:s"), 'updatetime'=>date("Y-m-d H:i:s"), ]; $r = Db::name("depart_user")->where(["is_del"=>0,"id"=>$id])->save($d); // var_dump( Db::name("depart_user")->getLastSql()); $orde = ["order_code"=>$id,"status"=>0,"action_remark"=>'',"action_type"=>"edit"]; ActionLog::logAdd($this->post['token'],$orde,'depart_user',0,$orde); return $r ? app_show(0,"信息更新成功"): error_show(1003,"信息更新失败"); }catch (\Exception $e){ return error_show(1003,$e->getMessage()); } } /*查询*/ public function found(){ $id = isset($this->post['id'])&& $this->post['id'] !==""? trim($this->post['id']) : ""; if($id==""){ return error_show(1004,'员工不能为空'); } $fo = Db::name('depart_user')->alias('a')->join('company_item b',"b.id=a.id",'left') ->field('a.uid,a.itemid,a.nickname,b.name')->where(['uid'=>$id,'a.is_del'=>0,'b.is_del'=>0])->find(); // var_dump( Db::name('depart_user')->getLastSql()); if(empty($fo)){ return error_show(1004,"信息获取失败"); } $fi = Db::name('depart_tips')->field('year,month,total_tips')->where(['depart_uid'=>$id,'is_del'=>0])->select(); $fo['depart_user']=$fi; return app_show(0,"获取成功",$fo); } /*删除*/ public function userdel(){ $id = isset($this->post['id']) && $this->post['id'] !==""? trim($this->post['id']) :""; $de = Db::name('depart_user')->where(['is_del'=>0,'id'=>$id])->find(); if($de==false){ return error_show(1004,"员工信息不存在"); } $de['is_del']=1; $de['updatetime']= date("Y-m-d H:i:s"); $back = Db::name('depart_user')->save($de); // var_dump(Db::name('depart_user')->getLastSql()); return $back ? app_show(0,"删除成功") :error_show(1004,"删除失败"); } }