@pisell/pisellos 2.3.55 → 2.3.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/dist/core/index.js +0 -1
  2. package/dist/modules/BookingContext/utils/productExtend.js +5 -9
  3. package/dist/modules/BookingContext/utils/timeSlices.js +24 -3
  4. package/dist/modules/Order/index.d.ts +8 -2
  5. package/dist/modules/Order/index.js +636 -645
  6. package/dist/modules/Order/utils/discountProductLineIdentity.d.ts +45 -0
  7. package/dist/modules/Order/utils/discountProductLineIdentity.js +227 -0
  8. package/dist/modules/Rules/index.js +46 -5
  9. package/dist/solution/BaseSales/index.js +53 -34
  10. package/dist/solution/BaseSales/utils/cartPromotion.js +19 -1
  11. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +1 -1
  12. package/dist/solution/BookingByStep/index.d.ts +1 -1
  13. package/dist/solution/BookingTicket/index.js +1 -4
  14. package/lib/core/index.js +0 -1
  15. package/lib/model/strategy/adapter/promotion/index.js +0 -51
  16. package/lib/modules/BookingContext/utils/productExtend.js +4 -3
  17. package/lib/modules/BookingContext/utils/timeSlices.js +18 -3
  18. package/lib/modules/Order/index.d.ts +8 -2
  19. package/lib/modules/Order/index.js +161 -118
  20. package/lib/modules/Order/utils/discountProductLineIdentity.d.ts +45 -0
  21. package/lib/modules/Order/utils/discountProductLineIdentity.js +170 -0
  22. package/lib/modules/Rules/index.js +47 -3
  23. package/lib/solution/BaseSales/index.js +26 -6
  24. package/lib/solution/BaseSales/utils/cartPromotion.js +18 -0
  25. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +1 -1
  26. package/lib/solution/BookingByStep/index.d.ts +1 -1
  27. package/lib/solution/BookingTicket/index.js +1 -4
  28. package/package.json +1 -1
@@ -0,0 +1,45 @@
1
+ import type { OrderTempOrder } from '../types';
2
+ /**
3
+ * 商品券拆行的身份与回并工具。
4
+ *
5
+ * 背景:
6
+ * Rules.calcDiscount 应用 good_pass 时,会把一个数量行拆成若干「用券行」和
7
+ * 「普通余量行」。Rules 返回的拆分行可能复制同一份
8
+ * metadata.unique_identification_number,进而造成:
9
+ * - 按 UID 删除时同时命中多行;
10
+ * - UI 把不同券行视为同一个商品;
11
+ * - 后续商品更新无法准确定位目标行。
12
+ *
13
+ * 处理原则:
14
+ * 1. 拆分后每一行必须拥有独立 UID;
15
+ * 2. 原始拆分来源仅记录在 tempOrder._extend.productsByUid 的运行态索引中,
16
+ * 不写入商品 metadata,不污染提交协议;
17
+ * 3. 券被移除后,只回并被本工具确认来自同一折扣拆分源的行;
18
+ * 4. 预约、赠品、促销、手动折扣、备注、称重、holder 和已落库行均为硬边界。
19
+ *
20
+ * 两个导出函数都会原地更新 tempOrder。调用顺序必须是:
21
+ * ensureUniqueProductLineUids -> consolidateDiscountFreeProductLines。
22
+ */
23
+ /** productsByUid 运行态记录中用于关联同一次折扣拆分的字段。 */
24
+ export declare const DISCOUNT_SPLIT_ORIGIN_UID_KEY = "discountSplitOriginUid";
25
+ /**
26
+ * 修复 Rules 折扣拆行复制 UID 的问题,并为拆分行记录共同来源。
27
+ *
28
+ * 第一条商品保留原 UID,后续重复行生成新 UUID;对应的 productsByUid.runtime
29
+ * 会复制原行 runtime(包括 origin),以保证删除、编辑及展示字段回读仍可工作。
30
+ *
31
+ * 没有 UID 的裸商品不会被补写 UID。这是为了兼容 Rules/mock 的历史协议形状;
32
+ * 正常 Order 写路径会在 normalize 阶段提前创建 UID。
33
+ */
34
+ export declare function ensureUniqueProductLineUids(tempOrder: OrderTempOrder): void;
35
+ /**
36
+ * 把券移除后已经恢复原价的同源折扣拆分行重新合并。
37
+ *
38
+ * 此函数刻意不执行通用的「同 SKU 合并」:没有 discountSplitOriginUid 的普通行
39
+ * 可能是业务 hook、导入订单或其它流程主动拆开的,不能在折扣重算时擅自合并。
40
+ *
41
+ * payment_price、tax_fee、surcharge_fee 属于 summary 计算层的派生值。券行与普通行
42
+ * 在回并前可能暂时不同,因此它们不参与 mergeKey;原始价格、SKU/option/bundle
43
+ * 结构以及税务/商品类型配置仍参与比较,防止不同商品语义被误合并。
44
+ */
45
+ export declare function consolidateDiscountFreeProductLines(tempOrder: OrderTempOrder): void;
@@ -0,0 +1,227 @@
1
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
3
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
4
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
5
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
7
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
8
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
9
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
10
+ import { cloneDeep } from 'lodash-es';
11
+ import { buildProductLineFingerprint, getSafeProductNum } from "../../../solution/ScanOrder/utils";
12
+ import { createUuidV4 } from "./orderCollectionIdentity";
13
+
14
+ /**
15
+ * 商品券拆行的身份与回并工具。
16
+ *
17
+ * 背景:
18
+ * Rules.calcDiscount 应用 good_pass 时,会把一个数量行拆成若干「用券行」和
19
+ * 「普通余量行」。Rules 返回的拆分行可能复制同一份
20
+ * metadata.unique_identification_number,进而造成:
21
+ * - 按 UID 删除时同时命中多行;
22
+ * - UI 把不同券行视为同一个商品;
23
+ * - 后续商品更新无法准确定位目标行。
24
+ *
25
+ * 处理原则:
26
+ * 1. 拆分后每一行必须拥有独立 UID;
27
+ * 2. 原始拆分来源仅记录在 tempOrder._extend.productsByUid 的运行态索引中,
28
+ * 不写入商品 metadata,不污染提交协议;
29
+ * 3. 券被移除后,只回并被本工具确认来自同一折扣拆分源的行;
30
+ * 4. 预约、赠品、促销、手动折扣、备注、称重、holder 和已落库行均为硬边界。
31
+ *
32
+ * 两个导出函数都会原地更新 tempOrder。调用顺序必须是:
33
+ * ensureUniqueProductLineUids -> consolidateDiscountFreeProductLines。
34
+ */
35
+
36
+ /** productsByUid 运行态记录中用于关联同一次折扣拆分的字段。 */
37
+ export var DISCOUNT_SPLIT_ORIGIN_UID_KEY = 'discountSplitOriginUid';
38
+
39
+ // 这里只保留本模块所需的最小读取逻辑,避免反向依赖体量较大的 Order/utils.ts
40
+ // 并形成 utils.ts -> 本文件 -> utils.ts 的循环引用。
41
+ function getProductLineUid(product) {
42
+ var _product$metadata$uni, _product$metadata;
43
+ if (!product || _typeof(product) !== 'object') return null;
44
+ var uid = (_product$metadata$uni = (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.unique_identification_number) !== null && _product$metadata$uni !== void 0 ? _product$metadata$uni : product.unique_identification_number;
45
+ if (uid === undefined || uid === null || uid === '') return null;
46
+ return String(uid);
47
+ }
48
+ function getProductSkuOptions(product) {
49
+ var _product$product_sku;
50
+ return Array.isArray((_product$product_sku = product.product_sku) === null || _product$product_sku === void 0 ? void 0 : _product$product_sku.option) ? product.product_sku.option : [];
51
+ }
52
+ function hasProductLineNote(product) {
53
+ return typeof product.note === 'string' && product.note.trim().length > 0;
54
+ }
55
+ function isManualProductDiscountLine(product) {
56
+ var _product$metadata2, _product$metadata3;
57
+ return ((_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2.is_manual_discount) === true || ((_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.is_manual_discount) === 1 || (product.discount_list || []).some(function (item) {
58
+ return (item === null || item === void 0 ? void 0 : item.type) === 'product';
59
+ });
60
+ }
61
+ function ensureProductsByUid(tempOrder) {
62
+ if (!tempOrder._extend || _typeof(tempOrder._extend) !== 'object') {
63
+ tempOrder._extend = {
64
+ productsByUid: {}
65
+ };
66
+ }
67
+ if (!tempOrder._extend.productsByUid) {
68
+ tempOrder._extend.productsByUid = {};
69
+ }
70
+ return tempOrder._extend.productsByUid;
71
+ }
72
+
73
+ /**
74
+ * 修复 Rules 折扣拆行复制 UID 的问题,并为拆分行记录共同来源。
75
+ *
76
+ * 第一条商品保留原 UID,后续重复行生成新 UUID;对应的 productsByUid.runtime
77
+ * 会复制原行 runtime(包括 origin),以保证删除、编辑及展示字段回读仍可工作。
78
+ *
79
+ * 没有 UID 的裸商品不会被补写 UID。这是为了兼容 Rules/mock 的历史协议形状;
80
+ * 正常 Order 写路径会在 normalize 阶段提前创建 UID。
81
+ */
82
+ export function ensureUniqueProductLineUids(tempOrder) {
83
+ // usedUids 只描述本次 Rules 返回的商品集合,不能直接依赖 productsByUid:
84
+ // productsByUid 可能还保留已删除行的历史 runtime,历史 UID 不应导致当前行被改号。
85
+ var usedUids = new Set();
86
+ var productsByUid = ensureProductsByUid(tempOrder);
87
+ tempOrder.products = (tempOrder.products || []).map(function (product) {
88
+ var sourceUid = getProductLineUid(product);
89
+ // 单测 mock 或兼容旧 Rules 时可能返回没有 UID 的裸商品。
90
+ // 这里不主动补 UID,避免一个“校验重复”的工具意外改变旧协议对象形状。
91
+ if (!sourceUid) return product;
92
+
93
+ // 实际场景:可乐 ×5 首次进入 Rules 时只有一行。
94
+ // 使用三张券后 Rules 可能返回「可乐 ×2 + 三条可乐 ×1」,但四条都复制原 UID。
95
+ // 第一条继续使用原 UID,可保留购物车已有引用、runtime origin 和删除定位的稳定性。
96
+ if (!usedUids.has(sourceUid)) {
97
+ usedUids.add(sourceUid);
98
+ return product;
99
+ }
100
+
101
+ // 从第二条重复 UID 开始生成真正的行级身份。
102
+ // 这样点击任意一条“可乐 ×1”时,只会删除该行,不会把所有同 UID 行一起删除。
103
+ var splitUid = createUuidV4();
104
+ while (usedUids.has(splitUid)) {
105
+ splitUid = createUuidV4();
106
+ }
107
+ product.metadata = _objectSpread(_objectSpread({}, product.metadata || {}), {}, {
108
+ unique_identification_number: splitUid
109
+ });
110
+ var sourceRuntime = productsByUid[sourceUid] || {};
111
+ // 如果当前行已经是上一轮拆分出来的子行,继续沿用最初的拆分来源。
112
+ // 例如删除一条券行后,空出的券再次把「可乐 ×2」拆成两条 ×1,
113
+ // 新行仍应归属于最初那条可乐,而不是形成一个无法回并的新分组。
114
+ var discountSplitOriginUid = String(sourceRuntime[DISCOUNT_SPLIT_ORIGIN_UID_KEY] || sourceUid);
115
+
116
+ // 来源只写入 _extend.productsByUid:
117
+ // - metadata.unique_identification_number 是对外的行身份,必须各不相同;
118
+ // - discountSplitOriginUid 是内部回并依据,不能进入提交给后端的商品 metadata。
119
+ productsByUid[sourceUid] = _objectSpread(_objectSpread({}, sourceRuntime), {}, _defineProperty({}, DISCOUNT_SPLIT_ORIGIN_UID_KEY, discountSplitOriginUid));
120
+ // 克隆 origin 等 runtime 数据,保证新拆分行仍能正确展示标题、封面等商品信息。
121
+ productsByUid[splitUid] = _objectSpread(_objectSpread({}, cloneDeep(sourceRuntime)), {}, _defineProperty({}, DISCOUNT_SPLIT_ORIGIN_UID_KEY, discountSplitOriginUid));
122
+ usedUids.add(splitUid);
123
+ return product;
124
+ });
125
+ }
126
+
127
+ /**
128
+ * 把券移除后已经恢复原价的同源折扣拆分行重新合并。
129
+ *
130
+ * 此函数刻意不执行通用的「同 SKU 合并」:没有 discountSplitOriginUid 的普通行
131
+ * 可能是业务 hook、导入订单或其它流程主动拆开的,不能在折扣重算时擅自合并。
132
+ *
133
+ * payment_price、tax_fee、surcharge_fee 属于 summary 计算层的派生值。券行与普通行
134
+ * 在回并前可能暂时不同,因此它们不参与 mergeKey;原始价格、SKU/option/bundle
135
+ * 结构以及税务/商品类型配置仍参与比较,防止不同商品语义被误合并。
136
+ */
137
+ export function consolidateDiscountFreeProductLines(tempOrder) {
138
+ // 实际目标场景:
139
+ // 选择客户后「可乐 ×5」被三张商品券拆成「×2、×1、×1、×1」;
140
+ // 清除客户/商品券后,四行都恢复为无折扣状态,应在本轮重算中立即回并为「可乐 ×5」。
141
+ var consolidatedProducts = [];
142
+ var productIndexByKey = new Map();
143
+ var _iterator = _createForOfIteratorHelper(tempOrder.products || []),
144
+ _step;
145
+ try {
146
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
147
+ var _product$booking_uid, _product$metadata4, _booking_id, _product$metadata5, _product$order_detail, _holder_id, _product$metadata6, _product$metadata7, _product$metadata8, _product$product_sku2, _product$metadata9, _tempOrder$_extend, _product$selling_pric, _product$original_pri, _custom_price, _product$is_charge_ta, _product$gift_card, _product$bundle_edit, _product$metadata$pri, _product$metadata10, _product$metadata$sou, _product$metadata11, _product$metadata$mai, _product$metadata12, _product$metadata$mai2, _product$metadata13, _product$product_vari;
148
+ var product = _step.value;
149
+ var productBundle = Array.isArray(product.product_bundle) ? product.product_bundle : [];
150
+ var hasDiscount = (product.discount_list || []).length > 0 || productBundle.some(function (bundle) {
151
+ return ((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []).length > 0;
152
+ });
153
+ var bookingUid = (_product$booking_uid = product.booking_uid) !== null && _product$booking_uid !== void 0 ? _product$booking_uid : (_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.booking_uid;
154
+ var bookingId = (_booking_id = product.booking_id) !== null && _booking_id !== void 0 ? _booking_id : (_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.booking_id;
155
+ var orderDetailId = (_product$order_detail = product.order_detail_id) !== null && _product$order_detail !== void 0 ? _product$order_detail : product.orderDetailId;
156
+ var holderId = (_holder_id = product.holder_id) !== null && _holder_id !== void 0 ? _holder_id : (_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.holder_id;
157
+
158
+ // 以下情况即使“看起来是同一个 SKU”也必须保持独立:
159
+ // - 仍有商品券/折扣:每条券行分别承担券归属和 savedAmount;
160
+ // - 赠品/促销:独立行承载策略来源,合并会破坏促销撤销和展示;
161
+ // - 手动改价/备注:用户显式表达了不同价格或不同制作要求;
162
+ // - 称重商品:每次称重的净重和金额属于独立交易事实;
163
+ // - 预约/holder/历史订单行:分别关联预约、持有人或后端 order_detail。
164
+ var hasMergeBoundary = hasDiscount || Boolean(((_product$metadata7 = product.metadata) === null || _product$metadata7 === void 0 ? void 0 : _product$metadata7._giftInfo) || product._giftInfo) || Boolean((_product$metadata8 = product.metadata) === null || _product$metadata8 === void 0 ? void 0 : _product$metadata8._promotion) || isManualProductDiscountLine(product) || hasProductLineNote(product) || Number(((_product$product_sku2 = product.product_sku) === null || _product$product_sku2 === void 0 ? void 0 : _product$product_sku2.open_sold_weight) || 0) === 1 || ((_product$metadata9 = product.metadata) === null || _product$metadata9 === void 0 ? void 0 : _product$metadata9.is_edit_for_runtime) === true || bookingId !== undefined && bookingId !== null && bookingId !== 0 && bookingId !== '0' || bookingUid !== undefined && bookingUid !== null && String(bookingUid) !== '' || holderId !== undefined && holderId !== null && String(holderId) !== '' || orderDetailId !== undefined && orderDetailId !== null && orderDetailId !== '';
165
+ if (hasMergeBoundary) {
166
+ consolidatedProducts.push(product);
167
+ continue;
168
+ }
169
+ var productUid = getProductLineUid(product);
170
+ var discountSplitOriginUid = productUid ? (_tempOrder$_extend = tempOrder._extend) === null || _tempOrder$_extend === void 0 || (_tempOrder$_extend = _tempOrder$_extend.productsByUid) === null || _tempOrder$_extend === void 0 || (_tempOrder$_extend = _tempOrder$_extend[productUid]) === null || _tempOrder$_extend === void 0 ? void 0 : _tempOrder$_extend[DISCOUNT_SPLIT_ORIGIN_UID_KEY] : undefined;
171
+
172
+ // 没有同源标记的两条可乐,可能是 onBeforeMergeProductToOrder 返回 false 后
173
+ // 由业务主动保留的独立行,也可能来自导入订单;不能仅凭 SKU 相同就擅自合并。
174
+ if (!discountSplitOriginUid) {
175
+ consolidatedProducts.push(product);
176
+ continue;
177
+ }
178
+
179
+ // 同属一次券拆分仍不代表一定可以合并。
180
+ // 例如两行后来选择了不同 option、套餐子商品或自定义价格,需要继续保持独立。
181
+ var fingerprint = buildProductLineFingerprint(getProductSkuOptions(product), productBundle);
182
+ var priceSignature = JSON.stringify({
183
+ selling_price: String((_product$selling_pric = product.selling_price) !== null && _product$selling_pric !== void 0 ? _product$selling_pric : ''),
184
+ original_price: String((_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : ''),
185
+ custom_price: String((_custom_price = product.custom_price) !== null && _custom_price !== void 0 ? _custom_price : ''),
186
+ is_charge_tax: Number((_product$is_charge_ta = product.is_charge_tax) !== null && _product$is_charge_ta !== void 0 ? _product$is_charge_ta : 0),
187
+ gift_card: Number((_product$gift_card = product.gift_card) !== null && _product$gift_card !== void 0 ? _product$gift_card : 0),
188
+ bundle_edit: Number((_product$bundle_edit = product.bundle_edit) !== null && _product$bundle_edit !== void 0 ? _product$bundle_edit : 0),
189
+ price_schema_version: (_product$metadata$pri = (_product$metadata10 = product.metadata) === null || _product$metadata10 === void 0 ? void 0 : _product$metadata10.price_schema_version) !== null && _product$metadata$pri !== void 0 ? _product$metadata$pri : '',
190
+ source_product_price: String((_product$metadata$sou = (_product$metadata11 = product.metadata) === null || _product$metadata11 === void 0 ? void 0 : _product$metadata11.source_product_price) !== null && _product$metadata$sou !== void 0 ? _product$metadata$sou : ''),
191
+ main_product_selling_price: String((_product$metadata$mai = (_product$metadata12 = product.metadata) === null || _product$metadata12 === void 0 ? void 0 : _product$metadata12.main_product_selling_price) !== null && _product$metadata$mai !== void 0 ? _product$metadata$mai : ''),
192
+ main_product_original_price: String((_product$metadata$mai2 = (_product$metadata13 = product.metadata) === null || _product$metadata13 === void 0 ? void 0 : _product$metadata13.main_product_original_price) !== null && _product$metadata$mai2 !== void 0 ? _product$metadata$mai2 : ''),
193
+ bundle: productBundle.map(function (bundle) {
194
+ var _ref, _bundle$bundle_id, _ref2, _ref3, _bundle$bundle_produc, _ref4, _ref5, _bundle$bundle_varian, _bundle$price, _bundle$original_pric, _bundle$bundle_sellin;
195
+ return {
196
+ bundle_id: (_ref = (_bundle$bundle_id = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_id) !== null && _bundle$bundle_id !== void 0 ? _bundle$bundle_id : bundle === null || bundle === void 0 ? void 0 : bundle.id) !== null && _ref !== void 0 ? _ref : '',
197
+ product_id: (_ref2 = (_ref3 = (_bundle$bundle_produc = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle === null || bundle === void 0 ? void 0 : bundle._bundle_product_id) !== null && _ref3 !== void 0 ? _ref3 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id) !== null && _ref2 !== void 0 ? _ref2 : '',
198
+ product_variant_id: (_ref4 = (_ref5 = (_bundle$bundle_varian = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle === null || bundle === void 0 ? void 0 : bundle.variant_id) !== null && _ref5 !== void 0 ? _ref5 : bundle === null || bundle === void 0 ? void 0 : bundle.product_variant_id) !== null && _ref4 !== void 0 ? _ref4 : 0,
199
+ price: String((_bundle$price = bundle === null || bundle === void 0 ? void 0 : bundle.price) !== null && _bundle$price !== void 0 ? _bundle$price : ''),
200
+ original_price: String((_bundle$original_pric = bundle === null || bundle === void 0 ? void 0 : bundle.original_price) !== null && _bundle$original_pric !== void 0 ? _bundle$original_pric : ''),
201
+ bundle_selling_price: String((_bundle$bundle_sellin = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price) !== null && _bundle$bundle_sellin !== void 0 ? _bundle$bundle_sellin : '')
202
+ };
203
+ })
204
+ });
205
+ var mergeKey = [discountSplitOriginUid, product.product_id, (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : 0, fingerprint, priceSignature].join('#');
206
+ var matchedIndex = productIndexByKey.get(mergeKey);
207
+
208
+ // 当前拆分来源 + 商品结构组合第一次出现时,保留该行作为回并目标。
209
+ // 后续相同行只累加数量,从而稳定保留首行 UID,避免 UI key 再次变化。
210
+ if (matchedIndex === undefined) {
211
+ productIndexByKey.set(mergeKey, consolidatedProducts.length);
212
+ consolidatedProducts.push(product);
213
+ continue;
214
+ }
215
+ var matchedProduct = consolidatedProducts[matchedIndex];
216
+ matchedProduct.num = getSafeProductNum(Number(matchedProduct.num || 0) + Number(product.num || 0));
217
+ // 示例:目标行 ×2,依次吸收三条 ×1,最终得到 ×5。
218
+ // 被吸收行的 productsByUid runtime 暂不删除:异步 UI/日志可能仍持有旧 UID,
219
+ // 保留历史索引比立即清理更安全;当前购物车身份始终以 tempOrder.products 为准。
220
+ }
221
+ } catch (err) {
222
+ _iterator.e(err);
223
+ } finally {
224
+ _iterator.f();
225
+ }
226
+ tempOrder.products = consolidatedProducts;
227
+ }
@@ -1382,7 +1382,44 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1382
1382
  if (flatItem.type === 'main') {
1383
1383
  // 主商品:保持原有逻辑
1384
1384
  if (splitCount < totalQuantity && isNeedSplit) {
1385
- var _product$origin_total2;
1385
+ var _product$origin_total2, _product$main_product2;
1386
+ var remainingQuantity = totalQuantity - splitCount;
1387
+ var applicableNonGoodPassById = new Map(applicableDiscounts.filter(function (discount) {
1388
+ return (discount.tag || discount.type) !== 'good_pass';
1389
+ }).map(function (discount) {
1390
+ return [String(discount.id), discount];
1391
+ }));
1392
+ var remainderDiscountList = (product.discount_list || []).filter(function (discount) {
1393
+ var _discount$discount$re, _discount$discount5;
1394
+ var discountType = discount.tag || discount.type;
1395
+ if (discountType === 'promotion') return true;
1396
+ if (discountType === 'good_pass') return false;
1397
+ var resourceId = (_discount$discount$re = (_discount$discount5 = discount.discount) === null || _discount$discount5 === void 0 ? void 0 : _discount$discount5.resource_id) !== null && _discount$discount$re !== void 0 ? _discount$discount$re : discount.id;
1398
+ return resourceId !== undefined && resourceId !== null && applicableNonGoodPassById.has(String(resourceId));
1399
+ }).map(function (discount) {
1400
+ var _discount$discount$re2, _discount$discount6;
1401
+ if ((discount.tag || discount.type) === 'promotion') return discount;
1402
+ var resourceId = (_discount$discount$re2 = (_discount$discount6 = discount.discount) === null || _discount$discount6 === void 0 ? void 0 : _discount$discount6.resource_id) !== null && _discount$discount$re2 !== void 0 ? _discount$discount$re2 : discount.id;
1403
+ var matchedDiscount = applicableNonGoodPassById.get(String(resourceId));
1404
+ if (matchedDiscount) {
1405
+ // 实际场景:3 件折扣卡商品中拆出 1 件改用商品券后,
1406
+ // 剩余 2 件仍在使用原折扣卡;必须同步登记折扣卡的使用状态,
1407
+ // 否则 updatedDiscountList 会把它改成未选中并清空 savedAmount。
1408
+ usedDiscounts.set(matchedDiscount.id, true);
1409
+ var appliedProducts = appliedDiscountProducts.get(matchedDiscount.id) || [];
1410
+ appliedProducts.push(_objectSpread(_objectSpread({}, discount), {}, {
1411
+ _num: remainingQuantity
1412
+ }));
1413
+ appliedDiscountProducts.set(matchedDiscount.id, appliedProducts);
1414
+ }
1415
+ return _objectSpread(_objectSpread({}, discount), {}, {
1416
+ // _num 是 Rules 运行态的行数量;Order 写回 tempOrder 时会裁剪该字段。
1417
+ _num: remainingQuantity
1418
+ });
1419
+ });
1420
+ var hasRetainedWalletDiscount = remainderDiscountList.some(function (discount) {
1421
+ return !['promotion', 'good_pass'].includes(discount.tag || discount.type);
1422
+ });
1386
1423
  var _total = (_product$origin_total2 = product.origin_total) !== null && _product$origin_total2 !== void 0 ? _product$origin_total2 : product.total;
1387
1424
  if ((product.discount_list || []).some(function (item) {
1388
1425
  return item.type === 'promotion';
@@ -1390,12 +1427,16 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1390
1427
  var _product$total2;
1391
1428
  _total = (_product$total2 = product.total) !== null && _product$total2 !== void 0 ? _product$total2 : product.origin_total;
1392
1429
  }
1393
- arr.push(_this4.hooks.setProduct(originProduct, {
1394
- discount_list: _this4.filterDiscountListByType(product.discount_list, 'promotion'),
1395
- quantity: totalQuantity - splitCount,
1430
+ arr.push(_this4.hooks.setProduct(originProduct, _objectSpread({
1431
+ // 商品券只替换被拆出的 splitCount 件。余量行原本仍有效的折扣卡
1432
+ // 不能随 good_pass 拆分一起清除;已取消或已失效的折扣不会进入此列表。
1433
+ discount_list: remainderDiscountList,
1434
+ quantity: remainingQuantity,
1396
1435
  _id: product._id.split('___')[0],
1397
1436
  total: _total
1398
- }));
1437
+ }, hasRetainedWalletDiscount ? {
1438
+ main_product_selling_price: (_product$main_product2 = product.main_product_selling_price) !== null && _product$main_product2 !== void 0 ? _product$main_product2 : product.price
1439
+ } : {})));
1399
1440
  }
1400
1441
  for (var i = 0; i < splitCount; i++) {
1401
1442
  var _originProduct4, _selectedDiscount$con, _product$options, _product$options2, _selectedDiscount$met, _selectedDiscount$met2, _reapplyDiscountPerce;
@@ -65,19 +65,21 @@ function isRejectedSalesSubmitResult(result) {
65
65
  var _result$response, _result$response2;
66
66
  var candidates = [result, result === null || result === void 0 ? void 0 : result.data, result === null || result === void 0 || (_result$response = result.response) === null || _result$response === void 0 ? void 0 : _result$response.data, result === null || result === void 0 || (_result$response2 = result.response) === null || _result$response2 === void 0 ? void 0 : _result$response2.body];
67
67
  return candidates.some(function (candidate) {
68
- var _candidate$code;
69
68
  if (!candidate || _typeof(candidate) !== 'object') return false;
70
- var responseCode = Number((_candidate$code = candidate.code) !== null && _candidate$code !== void 0 ? _candidate$code : candidate.statusCode);
71
- if (Number.isFinite(responseCode) && responseCode >= 400) return true;
69
+ if (candidate.code !== undefined && candidate.code !== 200 && candidate.code !== '200') {
70
+ return true;
71
+ }
72
+ var statusCode = Number(candidate.statusCode);
73
+ if (Number.isFinite(statusCode) && statusCode >= 400) return true;
72
74
  if (candidate.status === false || candidate.success === false || candidate.result === false) {
73
75
  return true;
74
76
  }
75
77
  return ['failed', 'error'].includes(String(candidate.status || '').toLowerCase());
76
78
  });
77
79
  }
78
- function getSalesSubmitErrorMessage(result) {
80
+ function getSalesSubmitErrorMessage(result, fallbackMessage) {
79
81
  var _result$data, _result$data2;
80
- return (result === null || result === void 0 ? void 0 : result.message) || (result === null || result === void 0 ? void 0 : result.msg) || (result === null || result === void 0 || (_result$data = result.data) === null || _result$data === void 0 ? void 0 : _result$data.message) || (result === null || result === void 0 || (_result$data2 = result.data) === null || _result$data2 === void 0 ? void 0 : _result$data2.msg) || 'Wallet 支付确认失败';
82
+ return (result === null || result === void 0 ? void 0 : result.message) || (result === null || result === void 0 ? void 0 : result.msg) || (result === null || result === void 0 || (_result$data = result.data) === null || _result$data === void 0 ? void 0 : _result$data.message) || (result === null || result === void 0 || (_result$data2 = result.data) === null || _result$data2 === void 0 ? void 0 : _result$data2.msg) || fallbackMessage;
81
83
  }
82
84
  function toWalletFundValue(value) {
83
85
  try {
@@ -4047,7 +4049,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
4047
4049
  key: "scanWalletAsset",
4048
4050
  value: (function () {
4049
4051
  var _scanWalletAsset = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(code) {
4050
- var result;
4052
+ var wallet, businessData, result;
4051
4053
  return _regeneratorRuntime().wrap(function _callee42$(_context42) {
4052
4054
  while (1) switch (_context42.prev = _context42.next) {
4053
4055
  case 0:
@@ -4057,22 +4059,27 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
4057
4059
  }
4058
4060
  throw new Error('payment 模块未初始化');
4059
4061
  case 2:
4060
- _context42.next = 4;
4061
- return this.store.payment.wallet.scanWalletAssetAsync(code);
4062
- case 4:
4062
+ wallet = this.store.payment.wallet; // 扫码可能早于后台 Wallet 刷新,搜索参数必须以当前订单为准。
4063
+ businessData = this.buildWalletInitBusinessData();
4064
+ if (businessData) {
4065
+ wallet.generateWalletParams(businessData);
4066
+ }
4067
+ _context42.next = 7;
4068
+ return wallet.scanWalletAssetAsync(code);
4069
+ case 7:
4063
4070
  result = _context42.sent;
4064
4071
  if (!(result.type === 'normalCode')) {
4065
- _context42.next = 10;
4072
+ _context42.next = 13;
4066
4073
  break;
4067
4074
  }
4068
- _context42.next = 8;
4075
+ _context42.next = 11;
4069
4076
  return this.syncSelectedWalletAssets(result.state);
4070
- case 8:
4071
- _context42.next = 10;
4077
+ case 11:
4078
+ _context42.next = 13;
4072
4079
  return this.publishWalletAssetsState(result.state);
4073
- case 10:
4080
+ case 13:
4074
4081
  return _context42.abrupt("return", result);
4075
- case 11:
4082
+ case 14:
4076
4083
  case "end":
4077
4084
  return _context42.stop();
4078
4085
  }
@@ -4304,7 +4311,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
4304
4311
  _context46.next = 17;
4305
4312
  break;
4306
4313
  }
4307
- throw new Error(getSalesSubmitErrorMessage(submitResult));
4314
+ throw new Error(getSalesSubmitErrorMessage(submitResult, 'Wallet 支付确认失败'));
4308
4315
  case 17:
4309
4316
  _context46.next = 27;
4310
4317
  break;
@@ -4465,23 +4472,29 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
4465
4472
  });
4466
4473
  case 32:
4467
4474
  syncResult = _context47.sent;
4475
+ if (!isRejectedSalesSubmitResult(syncResult.submitResult)) {
4476
+ _context47.next = 35;
4477
+ break;
4478
+ }
4479
+ throw new Error(getSalesSubmitErrorMessage(syncResult.submitResult, '订单提交失败'));
4480
+ case 35:
4468
4481
  if (!this.store.payment) {
4469
- _context47.next = 38;
4482
+ _context47.next = 40;
4470
4483
  break;
4471
4484
  }
4472
4485
  committed = this.getCommittedWalletAssets();
4473
4486
  walletState = this.store.payment.wallet.setCommittedWalletAssets(committed.ids, committed.assets);
4474
- _context47.next = 38;
4487
+ _context47.next = 40;
4475
4488
  return this.publishWalletAssetsState(walletState);
4476
- case 38:
4489
+ case 40:
4477
4490
  return _context47.abrupt("return", {
4478
4491
  payment: payment || {},
4479
4492
  payments: this.store.order.getOrderPayments(),
4480
4493
  syncResult: syncResult,
4481
4494
  isOrderFullyPaid: syncResult.isOrderFullyPaid
4482
4495
  });
4483
- case 41:
4484
- _context47.prev = 41;
4496
+ case 43:
4497
+ _context47.prev = 43;
4485
4498
  _context47.t0 = _context47["catch"](29);
4486
4499
  this.store.order.setOrderPayments(beforePayments);
4487
4500
  restoredTempOrder = this.store.order.getTempOrder();
@@ -4489,17 +4502,17 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
4489
4502
  restoredTempOrder.payment_status = beforePaymentStatus;
4490
4503
  this.store.order.persistTempOrder();
4491
4504
  }
4492
- _context47.next = 48;
4505
+ _context47.next = 50;
4493
4506
  return this.store.order.recalculateSummary({
4494
4507
  createIfMissing: true
4495
4508
  });
4496
- case 48:
4509
+ case 50:
4497
4510
  throw _context47.t0;
4498
- case 49:
4511
+ case 51:
4499
4512
  case "end":
4500
4513
  return _context47.stop();
4501
4514
  }
4502
- }, _callee47, this, [[29, 41]]);
4515
+ }, _callee47, this, [[29, 43]]);
4503
4516
  }));
4504
4517
  function payCash(_x39) {
4505
4518
  return _payCash.apply(this, arguments);
@@ -4621,23 +4634,29 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
4621
4634
  });
4622
4635
  case 33:
4623
4636
  syncResult = _context48.sent;
4637
+ if (!isRejectedSalesSubmitResult(syncResult.submitResult)) {
4638
+ _context48.next = 36;
4639
+ break;
4640
+ }
4641
+ throw new Error(getSalesSubmitErrorMessage(syncResult.submitResult, '订单提交失败'));
4642
+ case 36:
4624
4643
  if (!this.store.payment) {
4625
- _context48.next = 39;
4644
+ _context48.next = 41;
4626
4645
  break;
4627
4646
  }
4628
4647
  committed = this.getCommittedWalletAssets();
4629
4648
  walletState = this.store.payment.wallet.setCommittedWalletAssets(committed.ids, committed.assets);
4630
- _context48.next = 39;
4649
+ _context48.next = 41;
4631
4650
  return this.publishWalletAssetsState(walletState);
4632
- case 39:
4651
+ case 41:
4633
4652
  return _context48.abrupt("return", {
4634
4653
  payment: payment || {},
4635
4654
  payments: this.store.order.getOrderPayments(),
4636
4655
  syncResult: syncResult,
4637
4656
  isOrderFullyPaid: syncResult.isOrderFullyPaid
4638
4657
  });
4639
- case 42:
4640
- _context48.prev = 42;
4658
+ case 44:
4659
+ _context48.prev = 44;
4641
4660
  _context48.t0 = _context48["catch"](30);
4642
4661
  this.store.order.setOrderPayments(beforePayments);
4643
4662
  restoredTempOrder = this.store.order.getTempOrder();
@@ -4645,17 +4664,17 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
4645
4664
  restoredTempOrder.payment_status = beforePaymentStatus;
4646
4665
  this.store.order.persistTempOrder();
4647
4666
  }
4648
- _context48.next = 49;
4667
+ _context48.next = 51;
4649
4668
  return this.store.order.recalculateSummary({
4650
4669
  createIfMissing: true
4651
4670
  });
4652
- case 49:
4671
+ case 51:
4653
4672
  throw _context48.t0;
4654
- case 50:
4673
+ case 52:
4655
4674
  case "end":
4656
4675
  return _context48.stop();
4657
4676
  }
4658
- }, _callee48, this, [[30, 42]]);
4677
+ }, _callee48, this, [[30, 44]]);
4659
4678
  }));
4660
4679
  function commitPaymentMethodPayment(_x40) {
4661
4680
  return _commitPaymentMethodPayment.apply(this, arguments);
@@ -466,15 +466,33 @@ function getProductLineNoteSignature(product) {
466
466
  var uid = getOrderProductUid(product);
467
467
  return uid ? "note:".concat(uid) : "note:".concat(normalizedNote);
468
468
  }
469
+ function hasGoodPassDiscount(product) {
470
+ var _product$_extend;
471
+ var productBundle = Array.isArray(product === null || product === void 0 ? void 0 : product.product_bundle) ? product.product_bundle : [];
472
+ var extendedBundle = Array.isArray(product === null || product === void 0 || (_product$_extend = product._extend) === null || _product$_extend === void 0 || (_product$_extend = _product$_extend.other) === null || _product$_extend === void 0 ? void 0 : _product$_extend.bundle) ? product._extend.other.bundle : [];
473
+ var discountLists = [product === null || product === void 0 ? void 0 : product.discount_list].concat(_toConsumableArray(productBundle.map(function (item) {
474
+ return item === null || item === void 0 ? void 0 : item.discount_list;
475
+ })), _toConsumableArray(extendedBundle.map(function (item) {
476
+ return item === null || item === void 0 ? void 0 : item.discount_list;
477
+ })));
478
+ return discountLists.some(function (discountList) {
479
+ return Array.isArray(discountList) && discountList.some(function (item) {
480
+ return (item === null || item === void 0 ? void 0 : item.type) === 'good_pass' || (item === null || item === void 0 ? void 0 : item.tag) === 'good_pass';
481
+ });
482
+ });
483
+ }
469
484
 
470
485
  /**
471
- * 自定义商品、称重行以及编辑订单历史行都有各自的促销合并边界。
486
+ * 商品券、自定义商品、称重行以及编辑订单历史行都有各自的促销合并边界。
472
487
  */
473
488
  function getPromotionLineMergeBoundary(product) {
474
489
  var _product$product_sku, _product$metadata3;
475
490
  if ((product === null || product === void 0 ? void 0 : product.product_id) === undefined || (product === null || product === void 0 ? void 0 : product.product_id) === null) {
476
491
  return "custom:".concat(getOrderProductUid(product));
477
492
  }
493
+ if (hasGoodPassDiscount(product)) {
494
+ return "good-pass:".concat(getOrderProductUid(product));
495
+ }
478
496
  if (Number((product === null || product === void 0 || (_product$product_sku = product.product_sku) === null || _product$product_sku === void 0 ? void 0 : _product$product_sku.open_sold_weight) || 0) === 1) {
479
497
  return "weighing:".concat(getOrderProductUid(product));
480
498
  }
@@ -193,7 +193,7 @@ export function transformBaseProductToOrderProduct(params) {
193
193
  }
194
194
  // 从源头补充商品多语言标题
195
195
  var productTitle = _objectSpread(_objectSpread({}, (sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.title_i18n) || {}), {}, {
196
- original: (sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.title) || ''
196
+ original: (sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.original_title) || (sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.title) || ''
197
197
  });
198
198
  return {
199
199
  product_id: productId,
@@ -326,7 +326,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
326
326
  date: string;
327
327
  status: string;
328
328
  week: string;
329
- weekNum: 0 | 2 | 1 | 6 | 4 | 5 | 3;
329
+ weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
330
330
  }[]>;
331
331
  submitTimeSlot(timeSlots: TimeSliceItem): void;
332
332
  private getScheduleDataByIds;
@@ -2620,10 +2620,7 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
2620
2620
  _context30.next = 11;
2621
2621
  break;
2622
2622
  }
2623
- return _context30.abrupt("return", this.store.order.addProductsToOrder(orderLines, {
2624
- skipEditDiscountConfigRefresh: true,
2625
- skipDiscountRecalculation: true
2626
- }));
2623
+ return _context30.abrupt("return", this.store.order.addProductsToOrder(orderLines));
2627
2624
  case 11:
2628
2625
  result = [];
2629
2626
  _iterator2 = _createForOfIteratorHelper(orderLines);
package/lib/core/index.js CHANGED
@@ -50,7 +50,6 @@ var PisellOSCore = class {
50
50
  this.serverOptions = options.server;
51
51
  }
52
52
  this.initialize(options);
53
- console.log("constructor1234");
54
53
  }
55
54
  initialize(options) {
56
55
  if (options == null ? void 0 : options.plugins) {