feat(huya): 协作台账店铺字典·新建强校验·同买家多单 + uid 放开(迁移 0057/0058)
- 店铺字典(迁移 0057):大按钮点选 + 「新店」自定义自动登记;重命名可级联、 停用/备注;列表行内改、详情、筛选条共用同一个 picker - 新建强校验:订单编号/店铺/CK/礼包名/主页截图必填;贴 CK 即探针预览, 读不到绑定角色禁止提交;礼包用工作台配置的活动 SID 现拉(浏览器缓存 + 强制刷新) - 图片:绑定图停用、「绑定斗鱼号」下线(绑定关系改由探针读 bind_game_*), 主页截图改为新建必填(弹窗内先传 OSS 再随表单落库) - 同买家多单软识别:按「绑定账号 + 绑定角色」整批一次查询,列表「同买家」列 + 详情分组,点单号直接切单 - uid 放开唯一性(迁移 0058):同一份 CK 可服务多单,原 409 冲突改为提示 + 审计 - 列表体验:序号列、搜索扩到 11 个字段、CK 状态列截断、新建弹窗放大并去滚动条 - 验证:pytest 932 passed / 6 skipped;接口冒烟 56 项全绿;tsc+eslint+build 通过
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
"""协作台账的店铺字典表 `huya_collab_shops`。
|
||||
|
||||
为什么要有它:新建协作单时"店铺"原来是手打的自由文本,同一个店铺各种写法(错别字、
|
||||
多空格)会把筛选打散。改成一张可维护的字典:新建时**点一下选中**,
|
||||
下拉里也能直接输一个新名字(自定义,会自动登记进字典)。
|
||||
|
||||
**不回填历史订单里的店铺名**(2026-10-16 用户明确"不用看之前的"):字典从空开始,
|
||||
需要哪些店铺就在「店铺管理」里加、或在新建时自定义输入。
|
||||
|
||||
注意:订单里存的仍是店铺**名字**(`huya_external_orders.shop`),不是 id —— 历史 Excel
|
||||
就是文本,本轮不改语义;改名走 `update_shop(..., rename_orders=True)` 级联。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "20261016_0057"
|
||||
down_revision: str | None = "20261016_0056"
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
TABLE = "huya_collab_shops"
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
bind = op.get_bind()
|
||||
if TABLE in set(sa.inspect(bind).get_table_names()):
|
||||
return
|
||||
op.create_table(
|
||||
TABLE,
|
||||
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
|
||||
sa.Column("name", sa.String(length=64), nullable=False),
|
||||
sa.Column("sort_order", sa.Integer(), nullable=False, server_default="0"),
|
||||
sa.Column("is_active", sa.Boolean(), nullable=False, server_default="1"),
|
||||
sa.Column("remark", sa.String(length=255), nullable=False, server_default=""),
|
||||
sa.Column("created_by", sa.Integer(), nullable=True),
|
||||
sa.Column("updated_by", sa.Integer(), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(), nullable=False),
|
||||
)
|
||||
op.create_index(f"ix_{TABLE}_name", TABLE, ["name"], unique=True)
|
||||
op.create_index(f"ix_{TABLE}_is_active", TABLE, ["is_active"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
bind = op.get_bind()
|
||||
if TABLE in set(sa.inspect(bind).get_table_names()):
|
||||
# MySQL 删表会连索引一起删。
|
||||
op.drop_table(TABLE)
|
||||
@@ -0,0 +1,78 @@
|
||||
"""放开 `huya_external_orders.uid` 的唯一性:一个虎牙号可以挂多单。
|
||||
|
||||
背景(2026-10-16 用户拍板):真机上"同一个买家买两件"往往**继续用同一份外部 CK**,
|
||||
而 0055 建的 `ix_huya_external_orders_uid` 是**唯一索引** —— 第二单会被数据库顶掉
|
||||
(`Duplicate entry ... for key ...uid`)。原来"一个虎牙号只能挂一单"的规则随之作废:
|
||||
服务层不再抛 `uid_conflict`,「这个号还挂在哪些单上」只作为提示/审计信息(见 §5.6)。
|
||||
|
||||
做法:把该索引改成**普通索引**(保留查询性能,不再约束唯一)。
|
||||
uid 仍然可空 —— 「先建单、后贴 CK」不受影响(MySQL 索引对多个 NULL 宽松,普通索引更是)。
|
||||
|
||||
可重复执行:按当前索引的实际唯一性判断,已经是非唯一就直接返回。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "20261016_0058"
|
||||
down_revision: str | None = "20261016_0057"
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
TABLE = "huya_external_orders"
|
||||
INDEX = "ix_huya_external_orders_uid"
|
||||
COLUMNS = ["uid"]
|
||||
|
||||
|
||||
def _has_table(bind) -> bool:
|
||||
return TABLE in set(sa.inspect(bind).get_table_names())
|
||||
|
||||
|
||||
def _index(bind) -> dict | None:
|
||||
for index in sa.inspect(bind).get_indexes(TABLE):
|
||||
if index.get("name") == INDEX:
|
||||
return index
|
||||
return None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
bind = op.get_bind()
|
||||
if not _has_table(bind):
|
||||
return
|
||||
index = _index(bind)
|
||||
if index is None:
|
||||
# 索引丢了(手工库):补一个普通索引就行
|
||||
op.create_index(INDEX, TABLE, COLUMNS, unique=False)
|
||||
return
|
||||
if not index.get("unique"):
|
||||
return
|
||||
op.drop_index(INDEX, table_name=TABLE)
|
||||
op.create_index(INDEX, TABLE, COLUMNS, unique=False)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
bind = op.get_bind()
|
||||
if not _has_table(bind):
|
||||
return
|
||||
index = _index(bind)
|
||||
if index is None:
|
||||
op.create_index(INDEX, TABLE, COLUMNS, unique=True)
|
||||
return
|
||||
if index.get("unique"):
|
||||
return
|
||||
# 回退前先确认没有重复 uid,否则唯一索引建不起来(宁可报错也不要静默丢数据)
|
||||
duplicates = bind.execute(
|
||||
sa.text(
|
||||
f"SELECT uid FROM {TABLE} WHERE uid IS NOT NULL AND uid <> '' "
|
||||
"GROUP BY uid HAVING COUNT(*) > 1 LIMIT 5"
|
||||
)
|
||||
).fetchall()
|
||||
if duplicates:
|
||||
names = ", ".join(str(row[0]) for row in duplicates)
|
||||
raise RuntimeError(f"存在重复 uid({names}),先合并/清理这些订单再降级")
|
||||
op.drop_index(INDEX, table_name=TABLE)
|
||||
op.create_index(INDEX, TABLE, COLUMNS, unique=True)
|
||||
Reference in New Issue
Block a user