和平小店可以返回所有商品
This commit is contained in:
@@ -437,8 +437,20 @@ class DouyuBatchRunner:
|
||||
db.commit()
|
||||
|
||||
def _upsert_xpd_goods(self, db: Session, goods: list[dict]) -> None:
|
||||
"""写入和平小店商品快照。"""
|
||||
"""同步和平小店商品快照,移除上一次热门抢购等遗留商品。"""
|
||||
now = datetime.now(timezone.utc)
|
||||
commodity_ids = {
|
||||
str(raw.get("commodity_id") or raw.get("iGoodsId") or "")
|
||||
for raw in goods
|
||||
}
|
||||
commodity_ids.discard("")
|
||||
query = db.query(DouyuXpdGoodsSnapshot)
|
||||
if commodity_ids:
|
||||
query.filter(~DouyuXpdGoodsSnapshot.commodity_id.in_(commodity_ids)).delete(
|
||||
synchronize_session=False,
|
||||
)
|
||||
else:
|
||||
query.delete(synchronize_session=False)
|
||||
for raw in goods:
|
||||
commodity_id = str(raw.get("commodity_id") or raw.get("iGoodsId") or "")
|
||||
if not commodity_id:
|
||||
@@ -1458,7 +1470,8 @@ class DouyuBatchRunner:
|
||||
currency = "点券" if pay_type == 1 else "扭蛋碎片"
|
||||
self._mark_task(db, task, "failed", f"该商品不支持使用{currency}兑换")
|
||||
return
|
||||
if goods.goods_left is not None and goods.goods_left <= 0:
|
||||
# iGoodsLeft=-1 表示活动未公开库存,不是售罄;只有 0 才阻止兑换。
|
||||
if goods.goods_left == 0:
|
||||
self._mark_task(db, task, "failed", "该商品库存不足,请刷新商品列表后重试")
|
||||
return
|
||||
|
||||
|
||||
@@ -242,7 +242,7 @@ function xpdGoodsLabel(item: DouyuGoodsItem): string {
|
||||
].filter(Boolean);
|
||||
const stock = xpd.goods_left;
|
||||
const stockText = stock != null && Number.isFinite(Number(stock))
|
||||
? `库存${stock}`
|
||||
? (Number(stock) < 0 ? '库存未公开' : `库存${stock}`)
|
||||
: '库存未知';
|
||||
return `${item.name || item.commodity_id}${prices.length ? ` / ${prices.join(' 或 ')}` : ' / 暂不可兑换'} / ${stockText}`;
|
||||
}
|
||||
@@ -885,7 +885,7 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
|
||||
);
|
||||
const selectedXpdGoodsSoldOut = (() => {
|
||||
const stock = (selectedXpdGoods as (DouyuGoodsItem & { goods_left?: number | null }) | undefined)?.goods_left;
|
||||
return stock != null && Number.isFinite(Number(stock)) && Number(stock) <= 0;
|
||||
return stock != null && Number.isFinite(Number(stock)) && Number(stock) === 0;
|
||||
})();
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user