添加授权列表
This commit is contained in:
@@ -10,20 +10,6 @@ from app.models.user_oauth import UserOAuth
|
||||
from app.models.user_oauth_app import UserOAuthApp
|
||||
from app.utils.id_gen import generate_id
|
||||
|
||||
|
||||
OAUTH_TYPE_CONFIG = {
|
||||
1: {"port_type": 1, "name": "千川", "app_type": "juliang_qianchuan"},
|
||||
2: {"port_type": 1, "name": "广告", "app_type": "juliang_ad"},
|
||||
3: {"port_type": 1, "name": "本地推", "app_type": "juliang_ad"},
|
||||
4: {"port_type": 1, "name": "星图", "app_type": "juliang_ad"},
|
||||
5: {"port_type": 2, "name": "快手代理商", "app_type": "kuaishou"},
|
||||
6: {"port_type": 3, "name": "巨量星图", "app_type": "juliang_ad"},
|
||||
7: {"port_type": 4, "name": "巨量服务单", "app_type": "juliang_ad"},
|
||||
8: {"port_type": 4, "name": "腾讯服务单", "app_type": "tencent"},
|
||||
9: {"port_type": 5, "name": "腾讯营销K2", "app_type": "tencent"},
|
||||
10: {"port_type": 5, "name": "腾讯营销K3", "app_type": "tencent"},
|
||||
}
|
||||
|
||||
#随机获取一个可用的应用配置
|
||||
async def get_available_app(open_type: int, db: AsyncSession) -> dict:
|
||||
# 从 user_oauth_app 表查询可用应用
|
||||
@@ -54,7 +40,7 @@ async def get_available_app(open_type: int, db: AsyncSession) -> dict:
|
||||
count = count_result.scalar() or 0
|
||||
|
||||
# 检查是否达到最大授权数
|
||||
max_users = app.count
|
||||
max_users = app.max_count
|
||||
if count < max_users:
|
||||
available_apps.append({
|
||||
"app_id": app.app_id,
|
||||
@@ -266,5 +252,52 @@ async def get_juliang_token(app_id: str, secret: str, code: str, open_type: int,
|
||||
|
||||
async def get_kuaishou_token(app_id: str, secret: str, code: str, oauth_type: int, user_id: str, db: AsyncSession) -> dict:
|
||||
return "未配置"
|
||||
|
||||
|
||||
async def get_tencent_token(app_id: str, secret: str, code: str, oauth_type: int, user_id: str, db: AsyncSession) -> str:
|
||||
return "未配置"
|
||||
return "未配置"
|
||||
|
||||
|
||||
async def get_oauth_list(
|
||||
user_id: str,
|
||||
db: AsyncSession,
|
||||
account_userid: str | None = None,
|
||||
open_type: int | None = None,
|
||||
account_id: str | None = None,
|
||||
page: int = 1,
|
||||
page_size: int = 10,
|
||||
) -> dict:
|
||||
if page < 1:
|
||||
page = 1
|
||||
if page_size < 1:
|
||||
page_size = 10
|
||||
|
||||
query = select(UserOAuth).where(
|
||||
UserOAuth.user_id == user_id,
|
||||
UserOAuth.deleted_at.is_(None),
|
||||
)
|
||||
|
||||
if account_userid:
|
||||
query = query.where(UserOAuth.account_userid == account_userid)
|
||||
if open_type:
|
||||
query = query.where(UserOAuth.open_type == open_type)
|
||||
if account_id:
|
||||
query = query.where(UserOAuth.account_id == account_id)
|
||||
|
||||
query = query.order_by(UserOAuth.created_at.desc())
|
||||
|
||||
total_result = await db.execute(query.with_only_columns(UserOAuth.id))
|
||||
total = len(total_result.scalars().all())
|
||||
|
||||
offset = (page - 1) * page_size
|
||||
query = query.offset(offset).limit(page_size)
|
||||
|
||||
result = await db.execute(query)
|
||||
oauth_list = result.scalars().all()
|
||||
|
||||
return {
|
||||
"data": oauth_list,
|
||||
"total": total,
|
||||
"page": page,
|
||||
"page_size": page_size,
|
||||
}
|
||||
Reference in New Issue
Block a user