加 /api/cart/* 接口;加购链路完全归 trading
trading 新增 4 条购物车接口(POST /api/cart/{add,status,clear,remove}),
全部 Bearer 鉴权、走 SiteInteractor(Playwright + storage_state)。同步把
SiteInteractor 从 gateway URL 解耦——lifespan 总是构造与启停,container
字段 worker_site → site,加 asyncio.Lock 让 HTTP 与 worker 共用同一把锁
(同账号串行硬约束)。clear/remove 用 UI 点击 button[aria-label="削除"],
探针回报这是稳定 selector;真账号实测前先用此路径。
抽 ichiba 加购字段解析到 app/shared/purchase_contract.py(常量 +
inventory_flag_for + basket_domain_of + base_form_fields),原本 scraping
与 trading 重复实现同一段 __INITIAL_STATE__.purchase 解析。进一步发现
README 写的「purchase 块是两服务契约」实际未落地——trading 必须 Playwright
开页(httpx 被 TLS 指纹拦死),本地抽比再调 /api/item_detail 更快更新鲜。
删除 scraping 端 PurchaseInfo/PurchaseOption/PurchaseOptionValue 模型、
各站 _purchase_info 函数、tests/test_purchase.py。ItemDetailData 保留
purchase_condition / is_sold_out / purchase_unit / sku 等商品状态字段。
README「加购与下单」段重写。
328 测试全绿(含架构测试守住三方互不 import)。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -68,3 +68,65 @@ class TradingHealthData(BaseModel):
|
||||
|
||||
status: str
|
||||
auth: dict[str, Any] = Field(default_factory=dict)
|
||||
|
||||
|
||||
# ---- 购物车接口(/api/cart/*)----
|
||||
|
||||
|
||||
class CartAddRequest(BaseModel):
|
||||
"""加购请求
|
||||
|
||||
item_url 必填;variant_id / choice 不传时由 SiteInteractor 按商品页
|
||||
__INITIAL_STATE__.purchase 自动选(多规格选第一个非售罄,必填选项选第一个候选值)。
|
||||
choice 接受字符串("颜色:赤")或字符串列表(["颜色:赤", "サイズ:M"])。
|
||||
"""
|
||||
|
||||
item_url: str
|
||||
quantity: int = 1
|
||||
variant_id: str | None = None
|
||||
choice: str | list[str] | None = None
|
||||
|
||||
|
||||
class CartStatusRequest(BaseModel):
|
||||
"""购物车状态查询请求(无入参,保留结构对称)"""
|
||||
|
||||
|
||||
class CartClearRequest(BaseModel):
|
||||
"""清空购物车请求(无入参)"""
|
||||
|
||||
|
||||
class CartRemoveRequest(BaseModel):
|
||||
"""删除指定商品请求"""
|
||||
|
||||
item_id: str
|
||||
|
||||
|
||||
class CartAddData(BaseModel):
|
||||
"""加购响应数据"""
|
||||
|
||||
added: bool = True
|
||||
item_id: str
|
||||
shop_bid: str
|
||||
cart_count: int # -1 表示加购成功但末尾 count 查询失败
|
||||
|
||||
|
||||
class CartStatusData(BaseModel):
|
||||
"""购物车状态响应数据"""
|
||||
|
||||
logged_in: bool
|
||||
count: int
|
||||
raw_status: str # 站点状态码字符串,"100" 表示正常
|
||||
|
||||
|
||||
class CartClearData(BaseModel):
|
||||
"""清空购物车响应数据"""
|
||||
|
||||
removed_count: int # 实际点击「削除」按钮的次数
|
||||
cart_count: int # -1 表示末尾 count 查询失败
|
||||
|
||||
|
||||
class CartRemoveData(BaseModel):
|
||||
"""删除指定商品响应数据"""
|
||||
|
||||
removed: bool # 末尾 cart HTML 已不含 item_id 时为 true
|
||||
item_id: str
|
||||
|
||||
Reference in New Issue
Block a user