diff --git a/docs/斗鱼/DOUYU_PROTOCOL_OVERVIEW.md b/docs/斗鱼/DOUYU_PROTOCOL_OVERVIEW.md index 0b936b0..d519cf5 100644 --- a/docs/斗鱼/DOUYU_PROTOCOL_OVERVIEW.md +++ b/docs/斗鱼/DOUYU_PROTOCOL_OVERVIEW.md @@ -413,3 +413,23 @@ alias 上的旧角色,不能把 `cjm` 的新角色写入账号库。 | 2026-11-21 | 补充同名重绑、轮询退避、直接绑定识别和角色接口原始响应留档 | | 2026-11-21 | 按最新 HAR 更新鱼翅余额/充值二维码/支付状态、积分 multipart、到期批次和积分流水协议 | | 2026-11-22 | 按成功/失败 HAR 重构绑定判定:已有 `bindAct=0` 可确认,`bindAct=1` 不误报,`-200001` 归为斗鱼账号冷却并保留旧角色 | + +## 精英宝典工作台:兑换图片与供应商直充上限 + +### 兑换图片默认隐藏 + +账号表“兑换图片”列不再默认展示历史兑换任务图片。只有**本页面本次发起过 +交换任务**的账号才显示图片;刷新页面后历史图片继续保持隐藏。 + +前端用 `exchangeImageAccountIds` 记录本页发起的 `exchange_goods` / +`exchange_esports_goods` / `exchange_xpd_goods` 账号;列只在这些账号且最新 +兑换成功时渲染图片。 + +### 供应商 API 直充单笔上限 + +`douyu_config.gold_api_max_amount`,默认 **800 鱼翅**。 + +- `精英宝典配置` 可修改; +- 充值金额输入框自动 clamp 到该值; +- 后端执行器在创建供应商订单前再次校验,超过上限直接失败,不会下单; +- 迁移 `20261124_0130_douyu_api_max_amount` 新增列并默认 800。 diff --git a/tests/test_douyu_gold_recharge_channel.py b/tests/test_douyu_gold_recharge_channel.py index fb86220..8648afe 100644 --- a/tests/test_douyu_gold_recharge_channel.py +++ b/tests/test_douyu_gold_recharge_channel.py @@ -242,6 +242,30 @@ class TestDouyuGoldRechargeChannel: assert "pay_url" not in task_result assert "sign" not in task_result["supplier_order"] + @patch("web.backend.services.douyu_runner_gold.FishFinRechargeClient") + def test_supplier_channel_rejects_amount_over_configured_max(self, client_class): + config = { + "gold_recharge_channel": "supplier_api", + "gold_api_product_id": "gold-product", + "gold_api_account_template_name": "斗鱼昵称", + "gold_api_max_amount": 800, + } + self.task.result = {"payload": {"amount": 801}} + self.session.commit() + + self.runner._execute_create_gold_qr( + self.session, + self.task, + self.account, + "acf_uid=10001", + config, + ) + + client_class.assert_not_called() + self.session.refresh(self.task) + assert self.task.status == "failed" + assert "800" in self.task.message + @patch("web.backend.services.douyu_runner_gold.FishFinRechargeClient") def test_supplier_channel_rejects_account_without_nickname(self, client_class): self.account.nickname = "" @@ -355,6 +379,11 @@ class TestDouyuGoldRechargeChannel: dumped = res.model_dump() assert dumped["gold_recharge_channel"] == "supplier_api" assert dumped["peace_enabled"] is True + assert dumped["gold_api_max_amount"] == 800 + + req_max = DouyuConfigUpdate(gold_api_max_amount=500) + res_max = update_config(req_max, db=self.session, current=admin_user) + assert res_max.model_dump()["gold_api_max_amount"] == 500 # 2. 切换回 wechat_qr req2 = DouyuConfigUpdate( diff --git a/tests/test_migrations.py b/tests/test_migrations.py index 43106e9..e46bc6a 100644 --- a/tests/test_migrations.py +++ b/tests/test_migrations.py @@ -45,7 +45,7 @@ TESTS_DIR = Path(__file__).resolve().parent PROJECT_ROOT = TESTS_DIR.parent VERSIONS_DIR = PROJECT_ROOT / "web" / "backend" / "migrations" / "versions" -HEAD_REVISION = "20261124_0129" +HEAD_REVISION = "20261124_0130" # 迁移新增、但不声明在模型里的复合查询索引。 EXTRA_INDEXES = ( diff --git a/web/backend/migrations/migration_manifest.json b/web/backend/migrations/migration_manifest.json index f8149ab..1a323ba 100644 --- a/web/backend/migrations/migration_manifest.json +++ b/web/backend/migrations/migration_manifest.json @@ -517,6 +517,10 @@ "20261124_0129_account_role_change_lock.py": { "revision": "20261124_0129", "sha256": "75b97c990e0c870add48073da26a9d2ac9ffd75ba1ffe477ae97268155cab42c" + }, + "20261124_0130_douyu_api_max_amount.py": { + "revision": "20261124_0130", + "sha256": "fcaa64dfa069084fd6636b459b53f670376c79adf765f41646f05b6829ee9885" } } } diff --git a/web/backend/migrations/versions/20261124_0130_douyu_api_max_amount.py b/web/backend/migrations/versions/20261124_0130_douyu_api_max_amount.py new file mode 100644 index 0000000..9806da1 --- /dev/null +++ b/web/backend/migrations/versions/20261124_0130_douyu_api_max_amount.py @@ -0,0 +1,48 @@ +"""供应商 API 直充单笔上限(默认 800 鱼翅)。 + +配置项 `douyu_config.gold_api_max_amount`,任务执行前和前端输入框都使用它。 +""" + +from __future__ import annotations + +import sqlalchemy as sa +from alembic import op + +revision: str = "20261124_0130" +down_revision: str | None = "20261124_0129" +branch_labels: str | None = None +depends_on: str | None = None + +TABLE = "douyu_config" +COLUMN = "gold_api_max_amount" + + +def _column_exists() -> bool: + conn = op.get_bind() + count = conn.execute( + sa.text( + "SELECT COUNT(*) FROM information_schema.columns " + "WHERE table_schema = DATABASE() AND table_name = :table " + "AND column_name = :name" + ), + {"table": TABLE, "name": COLUMN}, + ).scalar() + return bool(count) + + +def upgrade() -> None: + if not _column_exists(): + op.add_column( + TABLE, + sa.Column( + COLUMN, + sa.Integer(), + nullable=False, + server_default="800", + ), + ) + + +def downgrade() -> None: + if _column_exists(): + op.drop_column(TABLE, COLUMN) diff --git a/web/backend/models.py b/web/backend/models.py index e15ae93..0bcbb5e 100644 --- a/web/backend/models.py +++ b/web/backend/models.py @@ -644,6 +644,10 @@ class DouyuConfig(Base): recharge_duplicate_confirm_minutes: Mapped[int] = mapped_column( Integer, nullable=False, default=10, server_default="10" ) + # 供应商 API 直充的单笔上限(鱼翅)。默认 800,防止误填过大金额。 + gold_api_max_amount: Mapped[int] = mapped_column( + Integer, nullable=False, default=800, server_default="800" + ) gift_id: Mapped[str] = mapped_column(String(64), default="23643") skin_id: Mapped[str] = mapped_column(String(64), default="2942") updated_at: Mapped[datetime] = mapped_column( diff --git a/web/backend/routers/douyu.py b/web/backend/routers/douyu.py index 80eb4e9..d4b0f18 100644 --- a/web/backend/routers/douyu.py +++ b/web/backend/routers/douyu.py @@ -737,6 +737,7 @@ def _config_out(config: DouyuConfig) -> DouyuConfigOut: recharge_duplicate_confirm_minutes=number( "recharge_duplicate_confirm_minutes" ), + gold_api_max_amount=number("gold_api_max_amount"), gift_id=text("gift_id"), skin_id=text("skin_id"), updated_at=config.updated_at, diff --git a/web/backend/schemas.py b/web/backend/schemas.py index 2fc29fc..0867c35 100644 --- a/web/backend/schemas.py +++ b/web/backend/schemas.py @@ -1537,6 +1537,7 @@ class DouyuConfigOut(BaseModel): gold_api_product_id: str = "111570" gold_api_account_template_name: str = "斗鱼昵称" recharge_duplicate_confirm_minutes: int = 10 + gold_api_max_amount: int = 800 gift_id: str = "23643" skin_id: str = "2942" updated_at: datetime | None = None @@ -1569,6 +1570,7 @@ class DouyuConfigOut(BaseModel): "recharge_duplicate_confirm_minutes": ( self.recharge_duplicate_confirm_minutes ), + "gold_api_max_amount": self.gold_api_max_amount, "gift_id": self.gift_id, "skin_id": self.skin_id, "updated_at": _isoformat(self.updated_at), @@ -1601,6 +1603,7 @@ class DouyuConfigUpdate(BaseModel): gold_api_product_id: str | None = Field(None, max_length=128) gold_api_account_template_name: str | None = Field(None, max_length=64) recharge_duplicate_confirm_minutes: int | None = Field(None, ge=0, le=1440) + gold_api_max_amount: int | None = Field(None, ge=1, le=1_000_000) gift_id: str | None = None skin_id: str | None = None diff --git a/web/backend/services/douyu_runner_gold.py b/web/backend/services/douyu_runner_gold.py index 3b20f0d..6fc2eec 100644 --- a/web/backend/services/douyu_runner_gold.py +++ b/web/backend/services/douyu_runner_gold.py @@ -575,6 +575,11 @@ class GoldMixin: amount: int, ) -> None: """创建供应商鱼翅直充订单并轮询订单状态。""" + max_amount = int(config.get("gold_api_max_amount") or 800) + if amount > max_amount: + raise FishFinRechargeError( + f"单笔供应商直充不能超过 {max_amount} 鱼翅(当前 {amount})" + ) product_id = str(config.get("gold_api_product_id") or "").strip() template_name = str( config.get("gold_api_account_template_name") or "斗鱼昵称" diff --git a/web/backend/services/douyu_service.py b/web/backend/services/douyu_service.py index f22c24b..e69ee0c 100644 --- a/web/backend/services/douyu_service.py +++ b/web/backend/services/douyu_service.py @@ -134,6 +134,7 @@ DOUYU_CONFIG_DEFAULTS = { "gold_api_product_id": "111570", "gold_api_account_template_name": "斗鱼昵称", "recharge_duplicate_confirm_minutes": 10, + "gold_api_max_amount": 800, "gift_id": "23643", "skin_id": "2942", # 和平小店总开关,默认关(小店当前关闭;关着时一键查询完全跳过它的请求) diff --git a/web/frontend/src/api/types.ts b/web/frontend/src/api/types.ts index 2d1bb5b..0f0a531 100644 --- a/web/frontend/src/api/types.ts +++ b/web/frontend/src/api/types.ts @@ -950,6 +950,7 @@ export interface DouyuConfig { gold_api_product_id: string; gold_api_account_template_name: string; recharge_duplicate_confirm_minutes: number; + gold_api_max_amount: number; gift_id: string; skin_id: string; updated_at: string | null; diff --git a/web/frontend/src/pages/douyu-tasks/DouyuTasksPage.tsx b/web/frontend/src/pages/douyu-tasks/DouyuTasksPage.tsx index 152b6ec..ae1aa38 100644 --- a/web/frontend/src/pages/douyu-tasks/DouyuTasksPage.tsx +++ b/web/frontend/src/pages/douyu-tasks/DouyuTasksPage.tsx @@ -220,6 +220,8 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind }) const [configOpen, setConfigOpen] = useState(false); const [concurrency, setConcurrency] = useState(3); const [goldAmount, setGoldAmount] = useState(() => savedPositiveInteger(DOUYU_GOLD_AMOUNT_STORAGE_KEY)); + // 历史兑换截图默认不展示;只有本页面本次实际发起过兑换的账号才显示。 + const [exchangeImageAccountIds, setExchangeImageAccountIds] = useState>(() => new Set()); const [giftCount, setGiftCount] = useState(() => savedPositiveInteger(DOUYU_GIFT_COUNT_STORAGE_KEY)); const [selectedGoodsId, setSelectedGoodsId] = useState(''); const [xpdPayType, setXpdPayType] = useState<'1' | '5'>('1'); @@ -453,11 +455,12 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind }) const map = new Map(); for (const task of visibleTasks) { if (!exchangeTaskSucceeded(task)) continue; + if (!exchangeImageAccountIds.has(task.account_id)) continue; const previous = map.get(task.account_id); if (!previous || task.id > previous.id) map.set(task.account_id, task); } return map; - }, [visibleTasks]); + }, [visibleTasks, exchangeImageAccountIds]); const latestLockedTaskByAccount = useMemo(() => { const paidOrders = new Set( @@ -1113,6 +1116,13 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind }) } // 只有本页面创建的批次才允许主动弹二维码,防止其他工作台/浏览器的任务打扰当前操作。 locallyStartedBatchIds.current.add(result.batch_id); + if (['exchange_goods', 'exchange_esports_goods', 'exchange_xpd_goods'].includes(taskType)) { + setExchangeImageAccountIds((prev) => { + const next = new Set(prev); + for (const id of ids) next.add(id); + return next; + }); + } if ( DOUYU_PAYMENT_TASK_TYPE_SET.has(taskType) && !(taskType === 'create_gold_qr' && goldRechargeChannel === 'supplier_api') @@ -2423,6 +2433,10 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind }) } }; const goldAmountLabel = '充值金额'; + const supplierMaxGoldAmount = Math.max( + 1, + Number(config?.gold_api_max_amount) || 800, + ); const isRechargeChannelLoading = goldRechargeChannel === null; const isSupplierGoldRecharge = goldRechargeChannel === 'supplier_api'; const goldRechargeChannelLabel = isRechargeChannelLoading @@ -2592,8 +2606,13 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind }) setGoldAmount(v || 1)} + onChange={(v) => setGoldAmount( + isSupplierGoldRecharge + ? Math.min(Number(v) || 1, supplierMaxGoldAmount) + : (Number(v) || 1), + )} addonBefore={goldAmountLabel} style={{ width: '100%' }} /> @@ -2661,8 +2680,13 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind }) setGoldAmount(v || 1)} + onChange={(v) => setGoldAmount( + isSupplierGoldRecharge + ? Math.min(Number(v) || 1, supplierMaxGoldAmount) + : (Number(v) || 1), + )} addonBefore={goldAmountLabel} style={{ width: '100%' }} /> @@ -3125,6 +3149,20 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind }) } : prev)} /> + + 最大单笔充值额度(鱼翅) + setConfigFormValues((prev) => prev ? { + ...prev, + gold_api_max_amount: Number(value) || 800, + } : prev)} + /> + {[ { label: '供应商商品 ID', key: 'gold_api_product_id' }, { label: '充值账号模板名(值为斗鱼昵称)', key: 'gold_api_account_template_name' },