1.8 KiB
1.8 KiB
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表示无折扣
查询优先级:
- 精确匹配:产品类型 + 产品id
- 类型级别匹配:产品类型 (productid为NULL)
- 默认匹配:所有产品 (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 - 生成促销二维码