|
@@ -3,13 +3,14 @@ declare (strict_types = 1);
|
|
|
|
|
|
namespace app\bug\listener;
|
|
|
|
|
|
-use app\bug\model\Work;use app\bug\model\WorkUser;use think\facade\Log;class UserEvent
|
|
|
+use app\bug\model\Work;use app\bug\model\WorkUser;
|
|
|
+use app\user\model\Headquarters;
|
|
|
+use think\facade\Log;class UserEvent
|
|
|
{
|
|
|
private $model;
|
|
|
private $type=['on'=>'启用','off'=>'禁用','delete'=>'删除'];
|
|
|
/**
|
|
|
* 事件监听处理
|
|
|
- *
|
|
|
* @return mixed
|
|
|
*/
|
|
|
public function handle($event)
|
|
@@ -42,14 +43,14 @@ use app\bug\model\Work;use app\bug\model\WorkUser;use think\facade\Log;class Use
|
|
|
$this->model->startTrans();
|
|
|
try {
|
|
|
|
|
|
- $method = "user".ucfirst($type);
|
|
|
+ $method = 'user'.ucfirst($type);
|
|
|
$data=[
|
|
|
- "uid"=>$info->account_id,
|
|
|
- "nickname"=>$info->Account->nickname,
|
|
|
- "roleid"=>$info->belong_role_id,
|
|
|
- "companyNo"=>$info->companyNo,
|
|
|
- "status"=>$info->WorkRole->status,
|
|
|
- "id"=>$info->id,
|
|
|
+ 'uid'=>$info->account_id,
|
|
|
+ 'nickname'=>$info->Account->nickname,
|
|
|
+ 'roleid'=>$info->belong_role_id,
|
|
|
+ 'companyNo'=>$info->companyNo,
|
|
|
+ 'status'=>$info->WorkRole->status,
|
|
|
+ 'id'=>$info->id,
|
|
|
];
|
|
|
$result = $this->$method($data);
|
|
|
if ($result === false) {
|
|
@@ -69,16 +70,19 @@ use app\bug\model\Work;use app\bug\model\WorkUser;use think\facade\Log;class Use
|
|
|
}
|
|
|
|
|
|
private function userOn($event){
|
|
|
- $info=$this->model->where([['uid',"=",$event['uid']],["companyNo","=",$event['companyNo']],['is_del','=',0]])
|
|
|
+ $info=$this->model->where([['uid','=',$event['uid']],['companyNo','=',$event['companyNo']],['is_del','=',0]])
|
|
|
->findOrEmpty();
|
|
|
+ $company = Headquarters::where('code',$event['companyNo'])->value('type',0);
|
|
|
$info->uid = $event['uid'];
|
|
|
$info->nickname = $event['nickname'];
|
|
|
$info->roleid = $event['roleid'];
|
|
|
+ $info->company_type =$company==1?2:1;
|
|
|
+// $info->is_main =$ismain->isEmpty()?1:0;
|
|
|
$info->companyNo = $event['companyNo'];
|
|
|
$save=$info->save();
|
|
|
if($save){
|
|
|
- $work=WorkUser::where('id',$event['id'])->update(["status"=>2]);//系统同步成功
|
|
|
- if($work)throw new \Exception("系统同步失败");
|
|
|
+ $work=WorkUser::where('id',$event['id'])->update(['status'=>2]);//系统同步成功
|
|
|
+ if($work==false)throw new \Exception('系统同步失败');
|
|
|
}
|
|
|
return $save;
|
|
|
}
|
|
@@ -92,8 +96,7 @@ use app\bug\model\Work;use app\bug\model\WorkUser;use think\facade\Log;class Use
|
|
|
}
|
|
|
|
|
|
private function userDelete($event){
|
|
|
- $info=$this->model->where([['uid','=',$event['uid']],['companyNo','=',$event['companyNo']],['roleid','=',
|
|
|
- $event['roleid']],['is_del','=',0]])->findOrEmpty();
|
|
|
+ $info=$this->model->where([['uid','=',$event['uid']],['companyNo','=',$event['companyNo']],['roleid','=',$event['roleid']],['is_del','=',0]])->findOrEmpty();
|
|
|
if($info->isEmpty())return false;
|
|
|
$info->is_del = 1;
|
|
|
$save=$info->save();
|