column('uid'); $roleId = 10; $agentAdminUser = AdminModel::where('role_id', 'in', $roleId)->field('id,user_name,nick_name,email,mobile,status,invite_code')->select(); $rows = []; if (!$agentAdminUser->isEmpty()) { foreach ($agentAdminUser as $item) { $rows[] = [ 'id' => $item['id'], 'username' => $item['user_name'], 'nickname' => $item['nick_name'], 'email' => $item['email'] ?? '-', 'mobile' => $item['mobile'] ?? '-', 'status' => $item['status'], 'invite_code' => $item['invite_code'], ]; } } return $this->toData('0', 'SUCCESS', ['list' => $rows, 'total' => count($rows)]); } catch (\Exception $exception) { return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); } } // 代理用户 public function user($param) { try { if (empty($param['agent_id'])) { return $this->toData('0', 'SUCCESS', ['list' => []]); } $userList = UserModel::where('agent_id', 'in', [0, $param['agent_id']])->where('parent_id', 0) ->order('user_id', 'desc') ->select(); $rows = []; if (!$userList->isEmpty()) { foreach ($userList as $item) { $rows[] = [ 'id' => $item['user_id'], 'email' => $item['email'], 'user_no' => $item['user_no'], 'status' => $item['agent_id'] == $param['agent_id'], 'agent_id' => $param['agent_id'], ]; } } return $this->toData('0', 'SUCCESS', ['list' => $rows, 'total' => count($rows)]); } catch (\Exception $exception) { return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); } } public function manager($param) { try { if (empty($param['id']) || !is_numeric($param['id'])) { return $this->toData('1', '参错错误', ['list' => []]); } if (empty($param['agent_id']) || !is_numeric($param['agent_id'])) { return $this->toData('1', '参错错误', ['list' => []]); } $user = UserModel::where('user_id', $param['id'])->find(); if (empty($user)) { return $this->toData('1', '用户不存在', ['list' => []]); } if ($user['parent_id'] != 0) { return $this->toData('1', '只能绑定顶层用户', ['list' => []]); } // 判断代理是否有效 $admin = AdminModel::where('id', $param['agent_id'])->find(); $roleId = 10; if (empty($admin) || $admin['role_id'] != $roleId) { return $this->toData('1', '代理不存在', ['list' => []]); } // $agentUserId = env('AGENT.AGENT_GROUP_ID'); // $agentAdminUserIds = AuthGroupAccessModel::where('group_id', $agentUserId)->column('uid'); // if(!in_array($param['agent_id'], $agentAdminUserIds)){ // return $this->toData('1', '代理不存在', ['list' => []]); // } // 未绑定 直接绑定 if ($user->agent_id == 0) { UserModel::update(['agent_id' => $param['agent_id']], ['user_id' => $param['id']]); return $this->toData('0', 'SUCCESS', []); } // 取消绑定 if ($user->agent_id == $param['agent_id']) { UserModel::update(['agent_id' => 0], ['user_id' => $param['id']]); return $this->toData('0', 'SUCCESS', []); } return $this->toData('1', '该用户已被其他代理绑定, 请先取消绑定', []); } catch (\Exception $exception) { return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); } } public function addUser($param) { try { if (empty($param['agent_id']) || !is_numeric($param['agent_id'])) { return $this->toData('1', '参错错误'); } if (empty($param['user_id']) || !is_numeric($param['user_id'])) { return $this->toData('1', '参错错误'); } $user = UserModel::where('user_id', $param['user_id'])->find(); if (empty($user)) { return $this->toData('1', '用户不存在'); } if ($user['parent_id'] != 0) { return $this->toData('1', '只能绑定顶层用户'); } // 判断代理是否有效 $admin = AdminModel::where('id', $param['agent_id'])->find(); $roleId = 10; if (empty($admin) || $admin['role_id'] != $roleId) { return $this->toData('1', '代理不存在'); } UserModel::update(['agent_id' => $param['agent_id']], ['user_id' => $param['user_id']]); return $this->toData('0', 'SUCCESS', []); } catch (\Exception $exception) { return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); } } }