yumoqing 55b4943170 feat(discount): 折扣率语义扩展——允许>1加价卖给客户+解析改专属优先/*兜底
用户决策(2026-09-06):
1. 折扣率允许大于1:平台可加价卖产品给客户(如存储缺省1.5);
   也可小于1让利(如百炼模型0.9,供应商有折扣传导给客户)
2. 解析规则:确定客户→查客户专属折扣;查不到→'*'通配兜底;再无→1.0
   旧实现bug:专属与通配OR混查取全局min——专属0.95+通配0.8返回0.8,
   专属记录形同虚设

改动:
- init.py sor_get_min_product_discount: 两步查询(专属层min→通配层min)
- init.py add/update_discount_detail: 上限1→9.9999(DB double(5,4)约束)
- discount_setting/save_discount.dspy: 兜底记录识别'*'+NULL两种形态;
  「客户折扣率不得高于通用折扣率」校验保留(加价语义下=单客户价不贵于通用价)
- marketing_discount_setting/save_discount.dspy: >1上限放开,保留<基准约束
- generate_qr.dspy: 同上放开
- index.ui: placeholder 0~1→'>1加价 <1折扣',dec_len 2→4

本地mock测试5场景全过:专属优先/通配兜底/无记录1.0/exact_match不兜底/层内min
2026-09-06 15:43:01 +08:00
2026-06-24 01:33:46 +08:00
2026-05-11 11:30:57 +08:00
2026-05-11 11:30:57 +08:00

discount

功能

支持商户为客户设置折扣,可以为不同产品设置不同的折扣值。

数据模型

discount (折扣表)

主折扣记录表,定义商户-客户关系的折扣。

  • id: 折扣id
  • name: 折扣名称
  • resellerid: 商户id
  • customerid: 客户id (可为NULL表示商户级默认折扣)
  • enabled_date: 启用日期
  • expired_date: 失效日期

discount_detail (折扣产品明细表)

存储每个产品的具体折扣值。

  • id: 明细id
  • discountid: 关联折扣id
  • resellerid: 商户id
  • prodtypeid: 产品类型id (可为NULL表示所有类型)
  • productid: 产品id (可为NULL表示该类型下所有产品)
  • discount: 折扣值 (0 < discount < 1)

discount_qr (折扣二维码表)

促销二维码记录。

  • id: 二维码id
  • resellerid: 商户id
  • discount: 折扣值
  • valid_term: 有效期 (如 30D, 3M, 1Y)
  • expired_date: 促销失效日期
  • qr_webpath: 二维码路径

折扣查询

获取产品折扣

from discount.init import get_product_discount

discount = await get_product_discount(resellerid, customerid, prodtypeid, productid)
# 返回折扣值 (float)1.0表示无折扣

查询优先级:

  1. 精确匹配:产品类型 + 产品id
  2. 类型级别匹配:产品类型 (productid为NULL)
  3. 默认匹配:所有产品 (prodtypeid和productid均为NULL)

获取客户默认折扣 (兼容旧接口)

from discount.init import get_customer_discount

discount = await get_customer_discount(resellerid, customerid)
# 返回客户默认折扣值

维护界面

  • 折扣管理: discount_list.ui - 创建/编辑/删除折扣记录
  • 折扣产品明细: discount_detail_list.ui?discountid=xxx - 为指定折扣添加产品明细,设置各产品折扣值
  • 生成促销码: promote.ui - 生成促销二维码
Description
No description provided
Readme 812 KiB
Languages
Python 99.9%
Shell 0.1%