日期:2026-10-31 状态:待评审 范围:cfc-backend(Spring Boot 2.7.18 / MyBatis-Plus / MySQL 8.0.34)、cfc-web(管理端 Vue2 + Element UI)、cfc-frontend(消费端 uni-app)
代码库目前存在两套并行的「套餐/组合」机制,均与业务目标不符:
| 机制 | 归属 | 现状 | 问题 |
|---|---|---|---|
combo(product_sku_combo_items) |
SKU 级:SKU 可作为「组合」变体 | 迁移434 建表;SKU 编辑器「商品组合」模式;下单时扣子商品库存(deductComboStock/restockComboOrder 及 3 处回补) | 组合被当作 SKU 变体处理,违反「组合≠SKU」 |
bundle(product_bundle_items) |
product 级:product_type='bundle' 独立商品 + bundle_sku_id 锚点 |
迁移435;ProductEdit 套餐编辑;BundlePricingCalculator 购物车自动计价(saving>0 才触发);消费端 cart.vue 自动展示已享套餐价 |
自动合并计价,用户要的是「提示 + 一键替换」 |
用户确认的新设计(2026-10-31):
决策:重写全新套餐模型,整体替换上述两套机制。
product_type='bundle'),用户直接加购、下单、支付、售后。DatabaseInitializer.runMigrations() 幂等模式,并同步 schema.sql。product_type='bundle' 表示套餐商品(现有枚举值)。| 列 | 类型 | 说明 |
|---|---|---|
| id | BIGINT PK AUTO | |
| combo_sku_id | BIGINT NOT NULL | 套餐 SKU id(内容归属;套餐单规格时即套餐唯一 SKU) |
| child_product_id | BIGINT NOT NULL | 子商品 |
| child_sku_id | BIGINT NOT NULL | 子商品 SKU(必填,精确到规格) |
| quantity | INT NOT NULL DEFAULT 1 | 数量(>0) |
| created_at | DATETIME |
uk_combo_sku_child (combo_sku_id, child_sku_id)。product_sku_combo_items/product_bundle_items),避免与旧机制混淆。product_sku_combo_items、product_bundle_items(0 数据,幂等 drop)。entity/ProductComboItem.java + mapper/ProductComboItemMapper.java。saveComboItems(comboProductId, items[]):先删后插;校验 combo 商品 product_type='bundle'、child_sku 存在且属于 child_product、quantity>0。listComboItems(comboProductId):返回带子商品名称/图/规格描述的清单。(child_product_id, child_sku_id): qty,遍历所有套餐商品内容:
groups = min over children(floor(have/need));replaceCartWithCombo(userId, checkedCartItemIds, comboProductId, groups):
groups 份,返回新购物车。entity/ProductSkuComboItem.java、mapper/ProductSkuComboItemMapper.java、ProductSku.comboItems 字段。entity/ProductBundleItem.java、mapper/ProductBundleItemMapper.java。pricing/ 包:BundlePricingCalculator、BundleDef、BundleChild、BundleHit、BundleDiscountResult、BundlePricingService、LineItem。ProductSkuService:combo 相关(fillComboItems/validateComboItems/saveComboItems/buildComboSummary/hasComboItems)。CartService:SKU 组合摘要(specDesc)、attachBundleMatches、computeBundlePromo、toBundlePromo、bundle 相关 import。ProductOrderService:combo 子商品库存扣减/回补(deductComboStock、restockComboOrder、3 处回补调用、combo 行特殊处理)、checkBundleStock 调用(3 处)、bundleDiscount 应用(结算价)。InventoryService:checkBundleStock、saveBundleItems、listBundleItems 及 bundle 出库联动逻辑。ProductController.detail:SKU comboItems 组装。AdminProductPickerController:bundle 相关(视情况)。CREATE TABLE IF NOT EXISTS product_combo_items ... + DROP TABLE IF EXISTS product_sku_combo_items, product_bundle_items(0 数据安全)。schema.sql 同步新表。ProductEdit.vue:productType='bundle' 时展示「套餐内容编辑」:跨分类搜索子商品 → 选子商品 SKU 规格 + 数量(复用 ProductPicker 的多选+SKU 选择能力);保存调 saveComboItems,加载调 listComboItems。替换现有 bundleItems 编辑。ProductSkuEditor.vue:移除「商品组合」模式(radio 只留「规格变体」),删除 comboItems/ProductPicker 组合调用与相关样式;保留单选/多选公共组件 ProductPicker 无需改动或按需精简。pages/shop/cart/cart.vue:
pages/shop/checkout/checkout.vue:适配(移除自动优惠展示;若有未处理 offer 时不自动保留)。utils/bundle-pricing.js:改为套餐 offer 展示辅助(安全读取后端 offer 字段,纯展示,杜绝前端算金额)。用户在购物车勾选 A×2 + B×1 准备结算
│
├─ 后端 offer 检测:A、B 恰为套餐X内容,套餐X价 < A+B 单买总和?
│ 是 → 购物车顶部提示「这 3 件组成套餐「XX」,套餐价 ¥Y(省 ¥Z)」[一键替换为套餐]
│ 否 → 不提示,按原商品价结算
│
└─ 用户点「一键替换为套餐」
→ 后端重算:购物车删除 A×2、B×1,加入「套餐X」SKU ×1
→ 刷新购物车 → 用户继续按套餐商品结算
边界:
saveComboItems/listComboItems 校验(非 bundle 商品拒绝、child_sku 不存在拒绝、quantity≤0 拒绝)。replaceCartWithCombo:购物车行扣减/新增/余量保留/防篡改(组数后端重算)。ProductSkuComboServiceTest、ProductOrderComboStockTest(组合语义已删除)。product_combo_items、归属列 combo_sku_id(命名决策,避开旧表名)。