|
@@ -13,6 +13,14 @@ class Departuser extends BaseController
|
|
|
{
|
|
|
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(){
|
|
@@ -33,18 +41,25 @@ class Departuser extends BaseController
|
|
|
}
|
|
|
/*添加*/
|
|
|
public function attend(){
|
|
|
+
|
|
|
$uid = isset($this->post['uid']) && $this->post['uid'] !==""? trim($this->post['uid']):"";
|
|
|
if($uid==""){
|
|
|
return error_show(1004,"员工id不能为空");
|
|
|
}
|
|
|
- $nickname = isset($this->post['nickname']) && $this->post['nickname'] !==""? trim($this->post['nickname']):"";
|
|
|
- if($nickname==""){
|
|
|
- return error_show(1004,"员工名称不能为空");
|
|
|
+ $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)){
|
|
@@ -71,32 +86,42 @@ class Departuser extends BaseController
|
|
|
}
|
|
|
/*编辑*/
|
|
|
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不能为空");
|
|
|
}
|
|
|
- $nickname = isset($this->post['nickname']) && $this->post['nickname'] !==""?($this->post)['nickname']: "";
|
|
|
+ $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])->where('id','<>',$id)->find();
|
|
|
+ $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,"部门id已存在");
|
|
|
+ return error_show(1004,"部门用户已存在");
|
|
|
}
|
|
|
try{
|
|
|
$d=[
|
|
|
- 'uid'=>$uid,'nickname'=>$nickname,'itemid'=>$itemid,
|
|
|
+ '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"=>$itemid])->save($d);
|
|
|
+ $r = Db::name("depart_user")->where(["is_del"=>0,"id"=>$id])->save($d);
|
|
|
// var_dump( Db::name("depart_user")->getLastSql());
|
|
|
- return $r ? app_show(0,"信息更新成功"): error_show(1003,"信息更新失败");
|
|
|
+ return $r ? app_show(0,"信息更新成功",$to): error_show(1003,"信息更新失败");
|
|
|
}catch (\Exception $e){
|
|
|
return error_show(1003,$e->getMessage());
|
|
|
}
|