From b8207504c8ca7bdbb42af585207d32b9a96f3f92 Mon Sep 17 00:00:00 2001 From: chuan <2154243450@qq.com> Date: Thu, 10 Apr 2025 20:50:55 +0800 Subject: [PATCH] admin --- app/admin/service/UserService.php | 27 +++++++++++++++++---------- app/model/AdminModel.php | 21 ++++++++++----------- app/model/UserModel.php | 3 ++- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/app/admin/service/UserService.php b/app/admin/service/UserService.php index e83a59b8..442b0292 100644 --- a/app/admin/service/UserService.php +++ b/app/admin/service/UserService.php @@ -2,6 +2,7 @@ namespace app\admin\service; +use app\admin\controller\Admin; use app\admin\validate\UserValidate; use app\home\service\BaseHomeService; use app\model\AccountFrozenModel; @@ -827,20 +828,27 @@ class UserService extends AdminBaseService if ($isAgent) { $agentId = $adminId; } else { // 指定一个默认代理 - $getAgent = AdminModel::where(['role_id'=>AdminModel::ROLE_ID_AGENT])->find(); - if (empty($getAgent)) { + $agentId = AdminModel::getDefaultAgentId(); + if (empty($agentId)) { return $this->toData('500', '系统缺少代理账号'); } - $agentId = $getAgent->id; } - // 查询代理下的一个客服 - $getCustomer = AdminModel::where(['parent_id'=>$agentId])->find(); - if (empty($getCustomer)) { - return $this->toData('500', '代理下缺少客服账号', ['agent_id'=>$agentId]); + // 查询代理下的一个客服 (等级关系: 代理-总监-组长-客服) + $director = AdminModel::where('parent_id', $agentId)->find(); + if (empty($director)) { + return $this->toData('500', '系统缺少总监账号'); } - $customerId = $getCustomer->id; + $teamHeader = AdminModel::where('parent_id', $director->id)->find(); + if (empty($teamHeader)) { + return $this->toData('500', '系统缺少组长账号'); + } + $customer = AdminModel::where('parent_id', $teamHeader->id)->find(); + if (empty($customer)) { + return $this->toData('500', '系统缺少客服账号'); + } + $customerId = $customer->id; // 查询客服的chat信息 - $customerChatInfo = UserChatLinkModel::where(['user_id'=>$customerId, 'user_type'=>UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_ADMIN])->find(); //查询客服的聊天账号uuid + $customerChatInfo = UserChatLinkModel::where(['user_id'=>$customerId, 'user_type'=>UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_ADMIN])->find(); if (empty($customerChatInfo)) { return $this->toData('500', '客服账号缺少chat信息'); } @@ -850,7 +858,6 @@ class UserService extends AdminBaseService return $this->toData('500', '当前代理还未创建chat群聊'); } - // 生成userNo $userNo = (new BaseHomeService())->getUniqUserNo(); diff --git a/app/model/AdminModel.php b/app/model/AdminModel.php index 3c01f612..660f10a6 100644 --- a/app/model/AdminModel.php +++ b/app/model/AdminModel.php @@ -30,19 +30,18 @@ class AdminModel extends BaseModel // 判断操作用户是否是代理商 public static function checkUserIsAgent($adminId) { - // 代理角色 $admin = self::where('id', $adminId)->find(); - if($admin && $admin['role_id'] == self::ROLE_ID_AGENT){ - return true; + if (empty($admin)) { + return false; } - - return false; -// $agentGroupId = env('AGENT.AGENT_GROUP_ID'); -// $authGroupAccess = AuthGroupAccessModel::where('uid', $adminId)->find(); -// if($authGroupAccess && $authGroupAccess['group_id'] == $agentGroupId){ -// return true; -// } -// return false; + $agentRole = AuthRoleModel::where(['id'=>$admin->role_id])->find(); + if (empty($agentRole)) { + return false; + } + if ($agentRole->name != '代理') { + return false; + } + return true; } /** diff --git a/app/model/UserModel.php b/app/model/UserModel.php index da9f6fbd..e606dbfa 100644 --- a/app/model/UserModel.php +++ b/app/model/UserModel.php @@ -190,7 +190,7 @@ class UserModel extends BaseModel * @param $ip * @return int */ - public static function emailRegister($email, $userNo, $inviteCode, $parentId, $password, $ip, $salt, $isTestUser, $agentId): int + public static function emailRegister($email, $userNo, $inviteCode, $parentId, $password, $ip, $salt, $isTestUser, $agentId, $customerId=0): int { $self = new self; $self->email = $email; @@ -198,6 +198,7 @@ class UserModel extends BaseModel $self->invite_code = $inviteCode; $self->parent_id = $parentId; $self->agent_id = $agentId; + $self->customer_id = $customerId; $self->login_password = $password; $self->salt = $salt; $self->reg_ip = $ip;