@pisell/pisellos 0.10.7 → 0.10.8
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.
- package/dist/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +12 -10
- package/dist/modules/Order/index.d.ts +12 -5
- package/dist/modules/Order/index.js +310 -210
- package/dist/modules/Order/types.d.ts +26 -3
- package/dist/modules/Order/types.js +11 -0
- package/dist/modules/Order/utils/discountProductLineIdentity.d.ts +45 -0
- package/dist/modules/Order/utils/discountProductLineIdentity.js +227 -0
- package/dist/modules/Rules/index.js +125 -52
- package/dist/modules/SalesSummary/utils.js +7 -1
- package/dist/server/index.d.ts +6 -0
- package/dist/server/index.js +810 -729
- package/dist/server/modules/order/index.d.ts +1 -0
- package/dist/server/modules/order/index.js +9 -2
- package/dist/server/modules/order/types.d.ts +1 -1
- package/dist/solution/BaseSales/index.d.ts +15 -5
- package/dist/solution/BaseSales/index.js +211 -159
- package/dist/solution/BaseSales/utils/cartPromotion.js +26 -3
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +1 -1
- package/dist/solution/BaseSales/utils.js +31 -20
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.js +1 -4
- package/dist/solution/BookingTicket/types.d.ts +3 -0
- package/dist/solution/BookingTicket/utils/cartView.js +44 -32
- package/dist/solution/Sales/index.d.ts +1 -0
- package/dist/solution/Sales/index.js +16 -2
- package/dist/solution/ScanOrder/utils.js +31 -20
- package/dist/solution/UnifiedBookingSales/index.d.ts +5 -4
- package/dist/solution/UnifiedBookingSales/index.js +51 -39
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +3 -1
- package/lib/modules/Order/index.d.ts +12 -5
- package/lib/modules/Order/index.js +148 -43
- package/lib/modules/Order/types.d.ts +26 -3
- package/lib/modules/Order/utils/discountProductLineIdentity.d.ts +45 -0
- package/lib/modules/Order/utils/discountProductLineIdentity.js +170 -0
- package/lib/modules/Rules/index.js +100 -20
- package/lib/modules/SalesSummary/utils.js +5 -1
- package/lib/server/index.d.ts +6 -0
- package/lib/server/index.js +51 -0
- package/lib/server/modules/order/index.d.ts +1 -0
- package/lib/server/modules/order/index.js +9 -3
- package/lib/server/modules/order/types.d.ts +1 -1
- package/lib/solution/BaseSales/index.d.ts +15 -5
- package/lib/solution/BaseSales/index.js +64 -16
- package/lib/solution/BaseSales/utils/cartPromotion.js +26 -2
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +1 -1
- package/lib/solution/BaseSales/utils.js +29 -18
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.js +1 -4
- package/lib/solution/BookingTicket/types.d.ts +3 -0
- package/lib/solution/BookingTicket/utils/cartView.js +43 -30
- package/lib/solution/Sales/index.d.ts +1 -0
- package/lib/solution/Sales/index.js +15 -3
- package/lib/solution/ScanOrder/utils.js +29 -18
- package/lib/solution/UnifiedBookingSales/index.d.ts +5 -4
- package/lib/solution/UnifiedBookingSales/index.js +35 -26
- package/package.json +1 -1
|
@@ -321,6 +321,24 @@ export interface ReplaceTempOrderOptions {
|
|
|
321
321
|
saveDraft?: boolean;
|
|
322
322
|
}
|
|
323
323
|
export type AddProductBookingInput = Record<string, any>;
|
|
324
|
+
/**
|
|
325
|
+
* 添加商品行时的顺序控制。
|
|
326
|
+
* 默认追加到 products 尾部;预约数量同步可插入到既有预约组的最新行之后,
|
|
327
|
+
* 避免步进器修改数量改变该组展示位置。
|
|
328
|
+
*/
|
|
329
|
+
export interface AddProductToOrderOptions {
|
|
330
|
+
insertAfterProductUid?: string;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* 删除商品后的可选位置保持策略。
|
|
334
|
+
* 预约合并行减量时仍删除最新真实行,再把剩余代表行移动到被删除代表行原位置。
|
|
335
|
+
*/
|
|
336
|
+
export interface RemoveProductsFromOrderOptions {
|
|
337
|
+
preserveDisplayPosition?: {
|
|
338
|
+
remainingProductUid: string;
|
|
339
|
+
anchorProductUid: string;
|
|
340
|
+
};
|
|
341
|
+
}
|
|
324
342
|
/** 更新购物车行:仅传 SKU 时命中同 SKU 第一行;多行同 SKU 须传 unique_identification_number / 选项指纹等 */
|
|
325
343
|
export interface UpdateOrderProductParams {
|
|
326
344
|
product_id: number | null;
|
|
@@ -726,17 +744,22 @@ export interface OrderModuleAPI {
|
|
|
726
744
|
updateTempOrderCustomer: (customer: UpdateTempOrderCustomerInput) => OrderSnapshot['customer'];
|
|
727
745
|
updateTempOrderBuzzer: (buzzer: string) => string;
|
|
728
746
|
updateTempOrderContactsInfo: (contactsInfo: Record<string, any> | null) => Record<string, any> | null;
|
|
729
|
-
addProductToOrder: (product: Partial<OrderProduct> & OrderProductIdentity, booking?: AddProductBookingInput) => Promise<OrderProduct[]>;
|
|
747
|
+
addProductToOrder: (product: Partial<OrderProduct> & OrderProductIdentity, booking?: AddProductBookingInput, options?: AddProductToOrderOptions) => Promise<OrderProduct[]>;
|
|
730
748
|
updateOrderProduct: (params: UpdateOrderProductParams) => Promise<OrderProduct[]>;
|
|
731
749
|
/** 批量更新购物车行,末尾仅触发一次促销重算与 summary 刷新 */
|
|
732
750
|
updateOrderProducts: (paramsList: UpdateOrderProductParams[]) => Promise<OrderProduct[]>;
|
|
733
751
|
updateOrderProductQuantity: (params: UpdateOrderProductQuantityParams) => Promise<OrderProduct[]>;
|
|
734
752
|
updateOrderBooking: (params: UpdateOrderBookingParams) => any[];
|
|
735
|
-
removeProductFromOrder: (identity: OrderProductIdentity) => Promise<OrderProduct[]>;
|
|
753
|
+
removeProductFromOrder: (identity: OrderProductIdentity, options?: RemoveProductsFromOrderOptions) => Promise<OrderProduct[]>;
|
|
736
754
|
/** 批量删除购物车行,末尾仅触发一次促销重算与 summary 刷新 */
|
|
737
|
-
removeProductsFromOrder: (identities: OrderProductIdentity[]) => Promise<OrderProduct[]>;
|
|
755
|
+
removeProductsFromOrder: (identities: OrderProductIdentity[], options?: RemoveProductsFromOrderOptions) => Promise<OrderProduct[]>;
|
|
738
756
|
/** 在显式开启时保存当前 tempOrder 的 sessionStorage 会话快照。 */
|
|
739
757
|
persistTempOrder: () => void;
|
|
758
|
+
/**
|
|
759
|
+
* 删除当前 cacheId 的 tempOrder 会话快照,并阻止当前模块实例再次写入。
|
|
760
|
+
* 新模块实例初始化时会按 otherParams 重新启用持久化。
|
|
761
|
+
*/
|
|
762
|
+
clearSessionStoragePersistedTempOrder: () => void;
|
|
740
763
|
/** 取出一次待恢复的 sessionStorage tempOrder 快照。 */
|
|
741
764
|
consumeSessionStorageRestore: () => Record<string, any> | null;
|
|
742
765
|
/**
|
|
@@ -63,6 +63,17 @@ export var OrderHooks = /*#__PURE__*/function (OrderHooks) {
|
|
|
63
63
|
* 清空时整个 payload 为 null。
|
|
64
64
|
*/
|
|
65
65
|
|
|
66
|
+
/**
|
|
67
|
+
* 添加商品行时的顺序控制。
|
|
68
|
+
* 默认追加到 products 尾部;预约数量同步可插入到既有预约组的最新行之后,
|
|
69
|
+
* 避免步进器修改数量改变该组展示位置。
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 删除商品后的可选位置保持策略。
|
|
74
|
+
* 预约合并行减量时仍删除最新真实行,再把剩余代表行移动到被删除代表行原位置。
|
|
75
|
+
*/
|
|
76
|
+
|
|
66
77
|
/** 更新购物车行:仅传 SKU 时命中同 SKU 第一行;多行同 SKU 须传 unique_identification_number / 选项指纹等 */
|
|
67
78
|
|
|
68
79
|
/** 仅更新购物车行数量;行定位语义与 updateOrderProduct / removeProductFromOrder 保持一致 */
|
|
@@ -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
|
+
}
|