29 lines
947 B
Python
29 lines
947 B
Python
"""加车结果。HTTP 客户端把商城回包收成这三种。"""
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
|
|
KIND_OK = "ok"
|
|
KIND_BUSINESS = "business"
|
|
KIND_SYSTEM = "system"
|
|
|
|
|
|
@dataclass
|
|
class AddOutcome:
|
|
kind: str
|
|
reason: str = ""
|
|
|
|
|
|
def classify_mall_message(text: str) -> AddOutcome:
|
|
msg = (text or "").strip()
|
|
if not msg:
|
|
return AddOutcome(kind=KIND_SYSTEM, reason="加购失败")
|
|
if any(token in msg for token in ("成功", "已加入")):
|
|
return AddOutcome(kind=KIND_OK)
|
|
if any(token in msg for token in ("中包装", "倍数", "起订")):
|
|
reason = msg if "中包装" in msg else f"中包装加不进:{msg}"
|
|
return AddOutcome(kind=KIND_BUSINESS, reason=reason)
|
|
if any(token in msg for token in ("库存", "无货", "缺货")):
|
|
return AddOutcome(kind=KIND_BUSINESS, reason="库存不足")
|
|
return AddOutcome(kind=KIND_BUSINESS, reason=msg)
|