column('user_id'); if(empty($firstUserIds)){ return []; } // 查询父级下面的用户 $userIds = UserModel::where('origin_user_id','in',$firstUserIds)->column('user_id'); return array_merge($firstUserIds, $userIds); // return UserModel::where('origin_user_id','in',$firstUserIds)->column('user_id'); } // 判断操作用户是否是代理商 public static function checkUserIsAgent($adminId) { // 代理角色 $admin = self::where('id', $adminId)->find(); if($admin && $admin['role_id'] == self::ROLE_ID_AGENT){ return true; } return false; // $agentGroupId = env('AGENT.AGENT_GROUP_ID'); // $authGroupAccess = AuthGroupAccessModel::where('uid', $adminId)->find(); // if($authGroupAccess && $authGroupAccess['group_id'] == $agentGroupId){ // return true; // } // return false; } /** * @desc 根据用户id 查询指定字段 * @param $fields * @param $userId * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public static function getFieldsByUserId($fields, $userId): array { $self = self::where('id', $userId)->field($fields)->find(); if(empty($self)){ return []; } return $self->toArray(); } /** * @desc 获取邀请码用户 * @param $inviteCode * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public static function getIdByInviteCode($inviteCode): int { $self = self::where('invite_code', $inviteCode)->value('id'); if(empty($self)){ return 0; } return $self; } // 获取默认的代理ID public static function getDefaultAgentId(): int { $role = AuthRoleModel::where(['name'=>'代理'])->find(); if (empty($role)) { return 0; } return $role->id; } // 根据代理ID获取其下属的所有客服ID (账号关系:代理 - 总监 - 组长 - 客服) public static function getCustomerIdsByAgentId($agentId): array { // 获取代理下的所有总监ID $directors = self::where(['parent_id' => $agentId])->column('id'); if (empty($directors)) { return []; } // 获取总监下所有组长ID $teamHeaders = self::where('parent_id', 'in', $directors)->column('id'); if (empty($teamHeaders)) { return []; } // 获取组长下的客服ID $customers = self::where('parent_id', 'in', $teamHeaders)->column('id'); if (empty($customers)) { return []; } return $customers; } }