fix: cart_item_id不是itemID,修复商品链接错误导致抢购失败

- cart_service: 拦截购物车API提取真实itemID映射
- cart_service: 从Vue组件/data属性/window全局变量多路提取itemID
- tasks: 区分item_id和cart_item_id,只有真实itemID才拼URL
- snatcher: 增加商品不存在/已下架检测,增加空URL检测
This commit is contained in:
2026-04-01 13:40:42 +08:00
parent def06c6360
commit 2ebdaec965
4 changed files with 136 additions and 8 deletions

View File

@@ -128,10 +128,10 @@ def sync_cart(account_id):
if not snatch_time:
continue
cart_item_id = item.get('cart_item_id', '')
item_id = item.get('item_id', '') or cart_item_id
item_id = item.get('item_id', '')
title = item.get('title', '')
# 用 cart_item_id 去重(因为可能没有 item_id
dedup_key = item_id or title
# 去重:优先用 item_id其次 cart_item_id最后 title
dedup_key = item_id or cart_item_id or title
if dedup_key:
existing = db2.execute(
'SELECT id FROM tasks WHERE account_id = ? AND (item_id = ? OR item_name = ?) AND status = "pending"',
@@ -140,8 +140,11 @@ def sync_cart(account_id):
if existing:
continue
url = item.get('url', '')
# 只有真正的 itemID 才拼 URLcart_item_id 不是 itemID
if not url and item_id and item_id.isdigit():
url = f'https://weidian.com/item.html?itemID={item_id}'
if not item_id:
item_id = cart_item_id
db2.execute(
'INSERT INTO tasks (account_id, target_url, item_name, item_id, sku_id, price, snatch_time) VALUES (?, ?, ?, ?, ?, ?, ?)',
(account_id, url, title, item_id,
@@ -217,9 +220,9 @@ def sync_all_carts():
if not snatch_time:
continue
cart_item_id = item.get('cart_item_id', '')
item_id = item.get('item_id', '') or cart_item_id
item_id = item.get('item_id', '')
title = item.get('title', '')
dedup_key = item_id or title
dedup_key = item_id or cart_item_id or title
if dedup_key:
existing = db2.execute(
'SELECT id FROM tasks WHERE account_id = ? AND (item_id = ? OR item_name = ?) AND status = "pending"',
@@ -230,6 +233,8 @@ def sync_all_carts():
url = item.get('url', '')
if not url and item_id and item_id.isdigit():
url = f'https://weidian.com/item.html?itemID={item_id}'
if not item_id:
item_id = cart_item_id
db2.execute(
'INSERT INTO tasks (account_id, target_url, item_name, item_id, sku_id, price, snatch_time) VALUES (?, ?, ?, ?, ?, ?, ?)',
(aid, url, title, item_id,