@pisell/pisellos 2.1.173 → 2.1.174

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 (93) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  2. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  3. package/dist/model/strategy/adapter/walletPass/evaluator.js +4 -2
  4. package/dist/modules/Discount/availability.d.ts +7 -0
  5. package/dist/modules/Discount/availability.js +52 -0
  6. package/dist/modules/Discount/entitlementPass.d.ts +34 -0
  7. package/dist/modules/Discount/entitlementPass.js +147 -0
  8. package/dist/modules/Discount/entitlementState.d.ts +8 -0
  9. package/dist/modules/Discount/entitlementState.js +205 -0
  10. package/dist/modules/Discount/index.d.ts +6 -3
  11. package/dist/modules/Discount/index.js +125 -23
  12. package/dist/modules/Discount/types.d.ts +34 -5
  13. package/dist/modules/Holder/index.d.ts +48 -0
  14. package/dist/modules/Holder/index.js +640 -0
  15. package/dist/modules/Holder/types.d.ts +123 -0
  16. package/dist/modules/Holder/types.js +1 -0
  17. package/dist/modules/Holder/utils.d.ts +13 -0
  18. package/dist/modules/Holder/utils.js +34 -0
  19. package/dist/modules/Order/index.d.ts +1 -0
  20. package/dist/modules/Order/index.js +18 -1
  21. package/dist/modules/Order/types.d.ts +2 -0
  22. package/dist/modules/Order/utils.d.ts +10 -0
  23. package/dist/modules/Order/utils.js +35 -3
  24. package/dist/modules/Product/types.d.ts +7 -0
  25. package/dist/modules/Rules/entitlementLines.d.ts +8 -0
  26. package/dist/modules/Rules/entitlementLines.js +157 -0
  27. package/dist/modules/Rules/index.d.ts +12 -2
  28. package/dist/modules/Rules/index.js +377 -112
  29. package/dist/modules/Rules/types.d.ts +2 -2
  30. package/dist/modules/index.d.ts +1 -0
  31. package/dist/modules/index.js +2 -1
  32. package/dist/plugins/window.d.ts +3 -0
  33. package/dist/solution/BookingByStep/index.d.ts +17 -2
  34. package/dist/solution/BookingByStep/index.js +276 -204
  35. package/dist/solution/BookingByStep/types.d.ts +2 -1
  36. package/dist/solution/BookingByStep/types.js +3 -1
  37. package/dist/solution/ScanOrder/index.js +1 -1
  38. package/dist/solution/ScanOrder/types.d.ts +1 -0
  39. package/dist/solution/ShopDiscount/index.d.ts +3 -0
  40. package/dist/solution/ShopDiscount/index.js +161 -78
  41. package/dist/solution/ShopDiscount/utils.d.ts +1 -0
  42. package/dist/solution/ShopDiscount/utils.js +40 -1
  43. package/dist/solution/VenueBooking/index.d.ts +19 -0
  44. package/dist/solution/VenueBooking/index.js +978 -748
  45. package/dist/solution/VenueBooking/types.d.ts +2 -0
  46. package/dist/types/index.d.ts +1 -0
  47. package/lib/model/strategy/adapter/promotion/index.js +49 -0
  48. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  49. package/lib/model/strategy/adapter/walletPass/evaluator.js +4 -2
  50. package/lib/modules/Discount/availability.d.ts +7 -0
  51. package/lib/modules/Discount/availability.js +91 -0
  52. package/lib/modules/Discount/entitlementPass.d.ts +34 -0
  53. package/lib/modules/Discount/entitlementPass.js +184 -0
  54. package/lib/modules/Discount/entitlementState.d.ts +8 -0
  55. package/lib/modules/Discount/entitlementState.js +206 -0
  56. package/lib/modules/Discount/index.d.ts +6 -3
  57. package/lib/modules/Discount/index.js +66 -16
  58. package/lib/modules/Discount/types.d.ts +34 -5
  59. package/lib/modules/Holder/index.d.ts +48 -0
  60. package/lib/modules/Holder/index.js +402 -0
  61. package/lib/modules/Holder/types.d.ts +123 -0
  62. package/lib/modules/Holder/types.js +17 -0
  63. package/lib/modules/Holder/utils.d.ts +13 -0
  64. package/lib/modules/Holder/utils.js +71 -0
  65. package/lib/modules/Order/index.d.ts +1 -0
  66. package/lib/modules/Order/index.js +14 -0
  67. package/lib/modules/Order/types.d.ts +2 -0
  68. package/lib/modules/Order/utils.d.ts +10 -0
  69. package/lib/modules/Order/utils.js +36 -5
  70. package/lib/modules/Product/types.d.ts +7 -0
  71. package/lib/modules/Rules/entitlementLines.d.ts +8 -0
  72. package/lib/modules/Rules/entitlementLines.js +158 -0
  73. package/lib/modules/Rules/index.d.ts +12 -2
  74. package/lib/modules/Rules/index.js +304 -70
  75. package/lib/modules/Rules/types.d.ts +2 -2
  76. package/lib/modules/index.d.ts +1 -0
  77. package/lib/modules/index.js +3 -1
  78. package/lib/plugins/window.d.ts +3 -0
  79. package/lib/solution/BookingByStep/index.d.ts +17 -2
  80. package/lib/solution/BookingByStep/index.js +39 -0
  81. package/lib/solution/BookingByStep/types.d.ts +2 -1
  82. package/lib/solution/BookingByStep/types.js +5 -0
  83. package/lib/solution/ScanOrder/index.js +1 -1
  84. package/lib/solution/ScanOrder/types.d.ts +1 -0
  85. package/lib/solution/ShopDiscount/index.d.ts +3 -0
  86. package/lib/solution/ShopDiscount/index.js +78 -28
  87. package/lib/solution/ShopDiscount/utils.d.ts +1 -0
  88. package/lib/solution/ShopDiscount/utils.js +42 -1
  89. package/lib/solution/VenueBooking/index.d.ts +19 -0
  90. package/lib/solution/VenueBooking/index.js +134 -16
  91. package/lib/solution/VenueBooking/types.d.ts +2 -0
  92. package/lib/types/index.d.ts +1 -0
  93. package/package.json +1 -1
@@ -0,0 +1,123 @@
1
+ import { ProductData } from '../Product/types';
2
+ /**
3
+ * 商品 holder 配置
4
+ */
5
+ export interface IHolderConfig {
6
+ required?: number;
7
+ resource_id: number;
8
+ status?: string;
9
+ [key: string]: any;
10
+ }
11
+ /**
12
+ * 表单记录
13
+ */
14
+ export interface IFormRecord {
15
+ form_id: number;
16
+ form_record_id: number;
17
+ main_field: string;
18
+ customer_cover?: string;
19
+ created_at?: string;
20
+ customer_id?: number;
21
+ [key: string]: any;
22
+ }
23
+ /**
24
+ * 表单配置/定义
25
+ */
26
+ export interface IFormInfo {
27
+ form_id: number;
28
+ name: string;
29
+ fields?: Record<string, any>[];
30
+ [key: string]: any;
31
+ }
32
+ /**
33
+ * 单个 form_id 下的数据结构
34
+ */
35
+ export interface IFormItemData {
36
+ records: IFormRecord[];
37
+ form: IFormInfo | Record<string, any>;
38
+ }
39
+ /**
40
+ * form_id 为 key 的 map 结构,如 948: { records: [], form: {} }
41
+ */
42
+ export type HolderFormMap = Record<string, IFormItemData>;
43
+ /**
44
+ * Holder 模块 reactive store,仅 holderMap 会触发 changed 事件
45
+ */
46
+ export interface HolderState {
47
+ holderMap: HolderFormMap;
48
+ }
49
+ export interface IFetchFormInfoParams {
50
+ url?: string;
51
+ query: {
52
+ form_id: string | number;
53
+ };
54
+ useCache?: boolean;
55
+ }
56
+ export interface IFetchFormRecordsParams {
57
+ url?: string;
58
+ query: {
59
+ customer_id?: number;
60
+ form_id: string | number;
61
+ shop_id: string | number;
62
+ num?: number;
63
+ skip?: number;
64
+ [key: string]: any;
65
+ };
66
+ useCache?: boolean;
67
+ }
68
+ export interface IAddFormRecordParams {
69
+ url?: string;
70
+ body: {
71
+ form_id: number;
72
+ shop_id: number | string;
73
+ customer_id?: number;
74
+ [key: string]: any;
75
+ };
76
+ }
77
+ /**
78
+ * UI 层自行调用添加接口后,将返回记录写入 holderMap
79
+ */
80
+ export interface IAppendFormRecordParams {
81
+ /** 接口返回的 data,或完整响应 { data: {...} } */
82
+ record: IFormRecord | Record<string, any>;
83
+ /** 可选,未传则从 record.form_id 读取 */
84
+ form_id?: number | string;
85
+ }
86
+ export interface IEnsureFormDataParams {
87
+ form_id: number | string;
88
+ shop_id: number | string;
89
+ customer_id?: number;
90
+ useCache?: boolean;
91
+ forceRefresh?: boolean;
92
+ formInfoUrl?: string;
93
+ recordsUrl?: string;
94
+ skip?: number;
95
+ num?: number;
96
+ }
97
+ export interface IEnsureFormByProductParams {
98
+ product: ProductData | Record<string, any>;
99
+ customer_id?: number;
100
+ shop_id?: number | string;
101
+ useCache?: boolean;
102
+ }
103
+ export interface IRefreshAllFormRecordsParams {
104
+ customer_id?: number;
105
+ useCache?: boolean;
106
+ recordsUrl?: string;
107
+ num?: number;
108
+ skip?: number;
109
+ }
110
+ export interface HolderModuleAPI {
111
+ getHolderFormMap: () => HolderFormMap;
112
+ getHolderFormData: (formId: number | string) => IFormItemData | undefined;
113
+ setFormData: (formId: number | string, data: Partial<IFormItemData>) => void;
114
+ fetchFormInfo: (params: IFetchFormInfoParams) => Promise<IFormInfo | IFormInfo[]>;
115
+ fetchRecords: (params: IFetchFormRecordsParams) => Promise<IFormRecord[]>;
116
+ ensureFormData: (params: IEnsureFormDataParams) => Promise<IFormItemData>;
117
+ ensureFormByProduct: (params: IEnsureFormByProductParams) => Promise<IFormItemData | null>;
118
+ addFormRecord: (params: IAddFormRecordParams) => Promise<IFormRecord>;
119
+ appendFormRecord: (params: IAppendFormRecordParams) => IFormRecord;
120
+ removeFormRecord: (formId: number | string, formRecordId: number) => void;
121
+ clearFormData: (formId?: number | string) => void;
122
+ refreshAllFormRecords: (params?: IRefreshAllFormRecordsParams) => Promise<HolderFormMap>;
123
+ }
@@ -0,0 +1,17 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+
15
+ // src/modules/Holder/types.ts
16
+ var types_exports = {};
17
+ module.exports = __toCommonJS(types_exports);
@@ -0,0 +1,13 @@
1
+ import { ProductData } from '../Product/types';
2
+ import { IFormItemData, IHolderConfig } from './types';
3
+ export declare function getProductHolderConfig(product?: ProductData | Record<string, any> | null): IHolderConfig | null;
4
+ export declare function getFormIdFromHolderConfig(config: IHolderConfig): number;
5
+ export declare function normalizeFormId(formId: number | string): number;
6
+ export declare function createEmptyFormItemData(): {
7
+ records: any[];
8
+ form: Record<string, any>;
9
+ };
10
+ export declare function resolveFormMetaFromHolderItem(mapKey: string, item: IFormItemData): {
11
+ form_id: number | string;
12
+ shop_id: number | string;
13
+ } | null;
@@ -0,0 +1,71 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/modules/Holder/utils.ts
20
+ var utils_exports = {};
21
+ __export(utils_exports, {
22
+ createEmptyFormItemData: () => createEmptyFormItemData,
23
+ getFormIdFromHolderConfig: () => getFormIdFromHolderConfig,
24
+ getProductHolderConfig: () => getProductHolderConfig,
25
+ normalizeFormId: () => normalizeFormId,
26
+ resolveFormMetaFromHolderItem: () => resolveFormMetaFromHolderItem
27
+ });
28
+ module.exports = __toCommonJS(utils_exports);
29
+ function getProductHolderConfig(product) {
30
+ var _a;
31
+ if (!product)
32
+ return null;
33
+ const config = (product == null ? void 0 : product.holder_config) ?? ((_a = product == null ? void 0 : product.origin) == null ? void 0 : _a.holder_config);
34
+ if ((config == null ? void 0 : config.status) && (config == null ? void 0 : config.status) !== "enable")
35
+ return null;
36
+ if (!(config == null ? void 0 : config.resource_id))
37
+ return null;
38
+ return config;
39
+ }
40
+ function getFormIdFromHolderConfig(config) {
41
+ return Number(config == null ? void 0 : config.resource_id);
42
+ }
43
+ function normalizeFormId(formId) {
44
+ return Number(formId);
45
+ }
46
+ function createEmptyFormItemData() {
47
+ return {
48
+ records: [],
49
+ form: {}
50
+ };
51
+ }
52
+ function resolveFormMetaFromHolderItem(mapKey, item) {
53
+ const formInfo = item.form || {};
54
+ const nestedForm = formInfo.form || {};
55
+ const form_id = normalizeFormId(
56
+ nestedForm.id ?? formInfo.form_id ?? formInfo.id ?? mapKey
57
+ );
58
+ const shop_id = nestedForm.shop_id ?? formInfo.shop_id;
59
+ if (shop_id === void 0 || shop_id === null || shop_id === "") {
60
+ return null;
61
+ }
62
+ return { form_id, shop_id };
63
+ }
64
+ // Annotate the CommonJS export names for ESM import in node:
65
+ 0 && (module.exports = {
66
+ createEmptyFormItemData,
67
+ getFormIdFromHolderConfig,
68
+ getProductHolderConfig,
69
+ normalizeFormId,
70
+ resolveFormMetaFromHolderItem
71
+ });
@@ -57,6 +57,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
57
57
  private getTempOrderStorageKey;
58
58
  private restoreTempOrderFromStorage;
59
59
  persistTempOrder(): void;
60
+ notifyTempOrderChanged(): void;
60
61
  private createDefaultTempOrderInstance;
61
62
  ensureTempOrder(): ScanOrderTempOrder;
62
63
  restoreOrder(): ScanOrderTempOrder;
@@ -325,6 +325,16 @@ var OrderModule = class extends import_BaseModule.BaseModule {
325
325
  return;
326
326
  this.window.localStorage.setItem(key, JSON.stringify(this.store.tempOrder));
327
327
  }
328
+ notifyTempOrderChanged() {
329
+ if (!this.store.tempOrder)
330
+ return;
331
+ this.store.tempOrder = {
332
+ ...this.store.tempOrder,
333
+ products: [...this.store.tempOrder.products],
334
+ bookings: this.store.tempOrder.bookings ? [...this.store.tempOrder.bookings] : []
335
+ };
336
+ this.persistTempOrder();
337
+ }
328
338
  // ─── TempOrder: 创建 & 获取 ───
329
339
  createDefaultTempOrderInstance() {
330
340
  return (0, import_utils.createDefaultTempOrder)({
@@ -595,6 +605,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
595
605
  let is_deposit = 0;
596
606
  if (params.cartItems.length > 0) {
597
607
  params.cartItems.forEach((item) => {
608
+ var _a2;
598
609
  if (!item._origin.duration) {
599
610
  const { duration, durationType } = (0, import_utils.generateDuration)(item);
600
611
  item._origin.duration = duration;
@@ -602,6 +613,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
602
613
  }
603
614
  const discountList = (0, import_utils.getAllDiscountList)(item);
604
615
  item._origin.product.discount_list = discountList;
616
+ if ((_a2 = params == null ? void 0 : params.extraData) == null ? void 0 : _a2.is_add_holder_info) {
617
+ (0, import_utils.ensureCartItemOriginHolder)(item, this.window);
618
+ }
605
619
  if ((0, import_utils2.isNormalProduct)(item._origin)) {
606
620
  order.relation_products.push(item._origin.product);
607
621
  const relationForms = item._origin.relation_forms || [];
@@ -235,6 +235,8 @@ export interface OrderModuleAPI {
235
235
  updateProductInOrder: (params: UpdateProductInOrderParams) => Promise<ScanOrderOrderProduct[]>;
236
236
  removeProductFromOrder: (identity: ScanOrderOrderProductIdentity) => Promise<ScanOrderOrderProduct[]>;
237
237
  persistTempOrder: () => void;
238
+ /** 提交 tempOrder 变更并触发 `{moduleName}:changed` 事件 */
239
+ notifyTempOrderChanged: () => void;
238
240
  submitTempOrder: <T = any>(params?: {
239
241
  cacheId?: string;
240
242
  platform?: string;
@@ -2,6 +2,7 @@ import Decimal from 'decimal.js';
2
2
  import { CartItem } from "../Cart";
3
3
  import type { ScanOrderSubmitPayload, ScanOrderSubmitProduct, ScanOrderSummary, ScanOrderTempOrder } from '../../solution/ScanOrder/types';
4
4
  import type { RulesParamsHooks } from '../Rules/types';
5
+ import type { WindowPlugin } from '../../plugins';
5
6
  /**
6
7
  * 把"含 option 的主商品单价"与 bundle 合成"单行 composite 单价"。
7
8
  *
@@ -86,6 +87,15 @@ export declare const mergeRelationForms: (relationForms: {
86
87
  form_id: number;
87
88
  form_record_ids: number[];
88
89
  }[];
90
+ export interface CartOrderHolder {
91
+ customer_id?: number;
92
+ form_id: number | string;
93
+ form_record: (number | string)[] | null;
94
+ }
95
+ /**
96
+ * 为购物车行补齐订单所需的 holder 信息(与 cartAccount 结构保持一致)
97
+ */
98
+ export declare function ensureCartItemOriginHolder(cartItem: CartItem, window?: WindowPlugin): void;
89
99
  export declare const getAllDiscountList: (cartItem: CartItem) => any;
90
100
  export declare function createUuidV4(): string;
91
101
  export declare function isTempOrder(data: any): data is ScanOrderTempOrder;
@@ -33,8 +33,9 @@ __export(utils_exports, {
33
33
  composeLinePrice: () => composeLinePrice,
34
34
  createDefaultOrderRulesHooks: () => createDefaultOrderRulesHooks,
35
35
  createDefaultTempOrder: () => createDefaultTempOrder,
36
- createEmptySummary: () => import_utils2.createEmptySummary,
36
+ createEmptySummary: () => import_utils3.createEmptySummary,
37
37
  createUuidV4: () => createUuidV4,
38
+ ensureCartItemOriginHolder: () => ensureCartItemOriginHolder,
38
39
  filterProductsForScanOrderMore: () => filterProductsForScanOrderMore,
39
40
  formatDateTime: () => formatDateTime,
40
41
  formatV1Product: () => formatV1Product,
@@ -50,8 +51,9 @@ __export(utils_exports, {
50
51
  module.exports = __toCommonJS(utils_exports);
51
52
  var import_dayjs = __toESM(require("dayjs"));
52
53
  var import_decimal = __toESM(require("decimal.js"));
53
- var import_utils = require("../../solution/ScanOrder/utils");
54
+ var import_utils = require("../Holder/utils");
54
55
  var import_utils2 = require("../../solution/ScanOrder/utils");
56
+ var import_utils3 = require("../../solution/ScanOrder/utils");
55
57
  function composeLinePrice(params) {
56
58
  const { mainPrice, bundle, useOriginalBundle } = params;
57
59
  let total = new import_decimal.default(Number(mainPrice) || 0);
@@ -113,7 +115,7 @@ function createDefaultOrderRulesHooks() {
113
115
  // 否则同 SKU 不同小料会在 calcDiscount 重组时互相覆盖。
114
116
  // 不透明 identity 契约下,normalizeOrderProduct / restoreTempOrderFromStorage 已保证 identity_key 必存在;
115
117
  // 留 fingerprint 分支仅作 Rules 单测里直接传裸 product 时的兜底。
116
- _id: product.identity_key ? `${product.product_id}_${product.product_variant_id}_${product.identity_key}` : `${product.product_id}_${product.product_variant_id}_${(0, import_utils.buildProductLineFingerprint)(
118
+ _id: product.identity_key ? `${product.product_id}_${product.product_variant_id}_${product.identity_key}` : `${product.product_id}_${product.product_variant_id}_${(0, import_utils2.buildProductLineFingerprint)(
117
119
  product.product_option_item,
118
120
  product.product_bundle
119
121
  )}`,
@@ -196,6 +198,34 @@ var mergeRelationForms = (relationForms) => {
196
198
  }, {})
197
199
  ).filter((item) => item.form_record_ids.length > 0);
198
200
  };
201
+ function getCustomerIdFromStorage(window) {
202
+ var _a;
203
+ try {
204
+ const customer = JSON.parse(((_a = window == null ? void 0 : window.getLocalStorage) == null ? void 0 : _a.call(window, "customer")) || "{}");
205
+ const customerId = Number(customer == null ? void 0 : customer.id);
206
+ return Number.isFinite(customerId) && customerId > 0 ? customerId : void 0;
207
+ } catch {
208
+ return void 0;
209
+ }
210
+ }
211
+ function ensureCartItemOriginHolder(cartItem, window) {
212
+ var _a;
213
+ if ((_a = cartItem == null ? void 0 : cartItem._origin) == null ? void 0 : _a.holder) {
214
+ return;
215
+ }
216
+ const holderConfig = (0, import_utils.getProductHolderConfig)(
217
+ (cartItem == null ? void 0 : cartItem._productInit) ?? (cartItem == null ? void 0 : cartItem._productOrigin)
218
+ );
219
+ const formRecordId = cartItem == null ? void 0 : cartItem.holder_id;
220
+ if (!(holderConfig == null ? void 0 : holderConfig.resource_id) || formRecordId == null) {
221
+ return;
222
+ }
223
+ cartItem._origin.holder = {
224
+ customer_id: getCustomerIdFromStorage(window),
225
+ form_id: holderConfig.resource_id,
226
+ form_record: [formRecordId]
227
+ };
228
+ }
199
229
  var getAllDiscountList = (cartItem) => {
200
230
  var _a, _b, _c, _d;
201
231
  let discountList = ((_b = (_a = cartItem == null ? void 0 : cartItem._origin) == null ? void 0 : _a.product) == null ? void 0 : _b.discount_list) || [];
@@ -378,7 +408,7 @@ function resolveSubmitCollectPax(tempOrder) {
378
408
  return normalizeSubmitCollectPaxValue((_a = tempOrder.metadata) == null ? void 0 : _a.collect_pax);
379
409
  }
380
410
  function createDefaultTempOrder(params) {
381
- const summary = params.summary || (0, import_utils.createEmptySummary)();
411
+ const summary = params.summary || (0, import_utils2.createEmptySummary)();
382
412
  return {
383
413
  order_id: null,
384
414
  relation_id: void 0,
@@ -437,7 +467,7 @@ function buildSubmitPayload(params) {
437
467
  enhance
438
468
  } = params;
439
469
  const scheduleDate = tempOrder.schedule_date || tempOrder.created_at || formatDateTime(now);
440
- const summary = tempOrder.summary || (0, import_utils.createEmptySummary)();
470
+ const summary = tempOrder.summary || (0, import_utils2.createEmptySummary)();
441
471
  const relationId = tempOrder.relation_id;
442
472
  const tableFormId = tempOrder.table_form_id;
443
473
  const bookingUuid = createUuidV4();
@@ -540,6 +570,7 @@ function formatV1Product(products) {
540
570
  createDefaultTempOrder,
541
571
  createEmptySummary,
542
572
  createUuidV4,
573
+ ensureCartItemOriginHolder,
543
574
  filterProductsForScanOrderMore,
544
575
  formatDateTime,
545
576
  formatV1Product,
@@ -189,6 +189,13 @@ export interface ProductData {
189
189
  };
190
190
  /** 购物车行键,用于唯一标识购物车中的商品,用于相同 SKU商品合并 */
191
191
  rowKey?: string;
192
+ /** holder 表单配置 */
193
+ holder_config?: {
194
+ required?: number;
195
+ resource_id?: number;
196
+ status?: string;
197
+ [key: string]: any;
198
+ };
192
199
  }
193
200
  /**
194
201
  * 商品媒体信息接口
@@ -0,0 +1,8 @@
1
+ import type { RulesParamsHooks } from './types';
2
+ export declare function isEntitlementRuntimeLine(product: any, mappedProduct?: any): boolean;
3
+ /** 仅同步本次多次卡行的数量与价格,沿用 Rules 的主商品、套餐计算结果。 */
4
+ export declare function rebuildEntitlementLine(origin: any, bundle: any[], hooks: RulesParamsHooks, count?: number): any;
5
+ /** 重算只还原本次多次卡;套餐和多 Holder 按父商品份数计算,不再合并商品行。 */
6
+ export declare function prepareEntitlementLines(products: any[], hooks: RulesParamsHooks, canUseEntitlement: (product: any) => boolean): any[];
7
+ /** 客户端钩子可能保留原 _id,只给新增的重复行补标识,保留拆分结果。 */
8
+ export declare function finalizeEntitlementLines(products: any[], hooks: RulesParamsHooks): any[];
@@ -0,0 +1,158 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/modules/Rules/entitlementLines.ts
30
+ var entitlementLines_exports = {};
31
+ __export(entitlementLines_exports, {
32
+ finalizeEntitlementLines: () => finalizeEntitlementLines,
33
+ isEntitlementRuntimeLine: () => isEntitlementRuntimeLine,
34
+ prepareEntitlementLines: () => prepareEntitlementLines,
35
+ rebuildEntitlementLine: () => rebuildEntitlementLine
36
+ });
37
+ module.exports = __toCommonJS(entitlementLines_exports);
38
+ var import_lodash_es = require("lodash-es");
39
+ var import_decimal = __toESM(require("decimal.js"));
40
+ var import_entitlementPass = require("../Discount/entitlementPass");
41
+ var import_entitlementState = require("../Discount/entitlementState");
42
+ var SOURCE = "entitlement_source_identity";
43
+ function isManualDiscount(data) {
44
+ var _a;
45
+ return data.isManualDiscount ?? (data.total != data.origin_total && (data.bundle || []).every((item) => {
46
+ var _a2;
47
+ return !((_a2 = item.discount_list) == null ? void 0 : _a2.length);
48
+ }) && (!((_a = data.discount_list) == null ? void 0 : _a.length) || data.discount_list.every((item) => item.type === "product")));
49
+ }
50
+ function isEntitlementRuntimeLine(product, mappedProduct) {
51
+ var _a;
52
+ return ((_a = product.metadata) == null ? void 0 : _a[SOURCE]) != null && !(0, import_entitlementState.isPersistedEntitlementLine)(product, mappedProduct) && !isManualDiscount(mappedProduct ?? product);
53
+ }
54
+ function rebuildEntitlementLine(origin, bundle, hooks, count) {
55
+ const data = hooks.getProduct(origin);
56
+ const quantity = count ?? data.quantity ?? data.num ?? 1;
57
+ const discounts = (data.discount_list || []).map(
58
+ (item) => {
59
+ var _a;
60
+ return (0, import_entitlementPass.isEntitlementPass)(item) && !((_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) ? { ...item, _num: quantity, metadata: { ...item.metadata, num: quantity } } : item;
61
+ }
62
+ );
63
+ const mainDiscount = discounts.filter((item) => {
64
+ var _a;
65
+ return !((_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
66
+ }).reduce((sum, item) => sum.plus(item.amount || 0), new import_decimal.default(0));
67
+ const originalPrice = new import_decimal.default(data.original_price ?? data.price ?? 0);
68
+ const sourceSellingPrice = originalPrice.minus(mainDiscount).toNumber();
69
+ const optionPrice = (data.options || []).reduce((sum, item) => sum.plus(new import_decimal.default(item.price || 0).times(item.num || 0)), new import_decimal.default(0));
70
+ const bundleTotal = bundle.reduce((sum, item) => sum.plus(new import_decimal.default(item.price || 0).times(item.num || 1)), new import_decimal.default(0));
71
+ const bundleOriginalTotal = bundle.reduce((sum, item) => sum.plus(new import_decimal.default(item.original_price ?? item.price ?? 0).times(item.num || 1)), new import_decimal.default(0));
72
+ return hooks.setProduct(origin, {
73
+ quantity,
74
+ discount_list: discounts,
75
+ bundle,
76
+ price: sourceSellingPrice,
77
+ main_product_selling_price: sourceSellingPrice,
78
+ total: new import_decimal.default(sourceSellingPrice).plus(optionPrice).plus(bundleTotal).toNumber(),
79
+ origin_total: originalPrice.plus(optionPrice).plus(bundleOriginalTotal).toNumber()
80
+ });
81
+ }
82
+ function setLineIdentity(row, id) {
83
+ row._id = id;
84
+ row.metadata = { ...row.metadata, unique_identification_number: id };
85
+ if (row._extend)
86
+ row._extend.unique_identification_number = id;
87
+ return row;
88
+ }
89
+ function prepareEntitlementLines(products, hooks, canUseEntitlement) {
90
+ return products.flatMap((original) => {
91
+ var _a, _b, _c, _d;
92
+ const data = hooks.getProduct(original);
93
+ if ((0, import_entitlementState.isPersistedEntitlementLine)(original, data) || isManualDiscount(data))
94
+ return [original];
95
+ const applicable = canUseEntitlement(original);
96
+ if (!((_a = original.metadata) == null ? void 0 : _a[SOURCE]) && !(0, import_entitlementState.hasEntitlementDiscount)(data) && !applicable)
97
+ return [original];
98
+ const origin = (0, import_lodash_es.cloneDeep)(original);
99
+ origin.metadata = { ...origin.metadata, [SOURCE]: ((_b = origin.metadata) == null ? void 0 : _b[SOURCE]) ?? data._id };
100
+ const bundle = (data.bundle || []).map((item) => {
101
+ var _a2;
102
+ const entitlement = (item.discount_list || []).find(import_entitlementPass.isEntitlementPass);
103
+ if (!entitlement)
104
+ return item;
105
+ const discounts = (item.discount_list || []).filter((discount) => !(0, import_entitlementPass.isEntitlementPass)(discount));
106
+ const originalPrice = item.original_price ?? ((_a2 = entitlement.discount) == null ? void 0 : _a2.original_amount) ?? item.product_price ?? item.price ?? 0;
107
+ const amount = discounts.reduce((sum, discount) => sum.plus(discount.amount || 0), new import_decimal.default(0));
108
+ const price = new import_decimal.default(originalPrice).minus(amount.div(item.num || 1)).toNumber();
109
+ return { ...item, original_price: originalPrice, price, bundle_selling_price: price, discount_list: discounts };
110
+ });
111
+ const mainEntitlement = (_c = data.discount_list) == null ? void 0 : _c.find(import_entitlementPass.isEntitlementPass);
112
+ const restored = hooks.setProduct(origin, {
113
+ original_price: data.original_price ?? ((_d = mainEntitlement == null ? void 0 : mainEntitlement.discount) == null ? void 0 : _d.original_amount) ?? data.price,
114
+ discount_list: (data.discount_list || []).filter((item) => !(0, import_entitlementPass.isEntitlementPass)(item)),
115
+ bundle
116
+ });
117
+ const row = rebuildEntitlementLine(restored, bundle, hooks);
118
+ const count = Math.max(1, Math.floor(Number(data.quantity || data.num || 1)));
119
+ if (!applicable || count <= 1 || !bundle.length && !Array.isArray(data.holder_id))
120
+ return [row];
121
+ return Array.from({ length: count }, (_, index) => {
122
+ var _a2, _b2;
123
+ const unit = (0, import_lodash_es.cloneDeep)(row);
124
+ for (const source of [unit, unit._extend]) {
125
+ if (Array.isArray(source == null ? void 0 : source.holder_id))
126
+ source.holder_id = source.holder_id.slice(index, index + 1);
127
+ }
128
+ if (Array.isArray((_b2 = (_a2 = unit._origin) == null ? void 0 : _a2.holder) == null ? void 0 : _b2.form_record)) {
129
+ const records = unit._origin.holder.form_record;
130
+ if (records.length > 1)
131
+ unit._origin.holder.form_record = records.slice(index, index + 1);
132
+ }
133
+ return setLineIdentity(rebuildEntitlementLine(unit, hooks.getProduct(unit).bundle || [], hooks, 1), `${data._id}:entitlement-unit:${index}`);
134
+ });
135
+ });
136
+ }
137
+ function finalizeEntitlementLines(products, hooks) {
138
+ const runtime = (item) => isEntitlementRuntimeLine(item, hooks.getProduct(item));
139
+ const seen = new Set(products.filter((item) => !runtime(item)).map((item) => String(item._id)));
140
+ return products.map((origin, index) => {
141
+ if (!runtime(origin))
142
+ return origin;
143
+ const base = String(origin._id ?? hooks.getProduct(origin)._id);
144
+ let id = base;
145
+ let ordinal = index;
146
+ while (seen.has(id))
147
+ id = `${base}:entitlement-split:${ordinal++}`;
148
+ seen.add(id);
149
+ return id === String(origin._id) ? origin : setLineIdentity((0, import_lodash_es.cloneDeep)(origin), id);
150
+ });
151
+ }
152
+ // Annotate the CommonJS export names for ESM import in node:
153
+ 0 && (module.exports = {
154
+ finalizeEntitlementLines,
155
+ isEntitlementRuntimeLine,
156
+ prepareEntitlementLines,
157
+ rebuildEntitlementLine
158
+ });
@@ -8,17 +8,26 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
8
8
  protected defaultVersion: string;
9
9
  private store;
10
10
  private hooks;
11
+ private entitlementPassEnabled;
12
+ private defaultWalletPassEvaluator?;
13
+ setEntitlementPassEnabled(enabled: boolean): void;
14
+ private getWalletPassEvaluator;
11
15
  constructor(name?: string, version?: string);
12
16
  initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
13
17
  setRulesList(rulesList: Rules[]): Promise<void>;
14
18
  getRulesList(): Rules[];
19
+ private normalizeHolderRecordIds;
20
+ /**
21
+ * 商品未开启 Holder 选择时跳过匹配;已开启时,特定 form Holder 卡
22
+ * 只适用于同一 Holder Record,是否必填不影响匹配规则。
23
+ */
15
24
  private checkHolderMatch;
16
25
  isDiscountListAvailable({ oldDiscountList, newDiscountList, productList, holders, isFormSubject, }: {
17
26
  oldDiscountList: Discount[];
18
27
  newDiscountList: Discount[];
19
28
  productList: any[];
20
29
  holders: {
21
- form_record_id: number;
30
+ form_record_id: number | string;
22
31
  }[];
23
32
  isFormSubject: boolean;
24
33
  }): {
@@ -26,6 +35,7 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
26
35
  discountList: Discount[];
27
36
  productList: any[];
28
37
  unavailableReason?: UnavailableReason;
38
+ evaluatedDiscountList?: Discount[];
29
39
  };
30
40
  filterDiscountListByType(discountList: Discount[], type: string): Discount[];
31
41
  private getUnavailableReason;
@@ -33,7 +43,7 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
33
43
  discountList: Discount[];
34
44
  productList: any[];
35
45
  holders: {
36
- form_record_id: number;
46
+ form_record_id: number | string;
37
47
  }[];
38
48
  isFormSubject: boolean;
39
49
  }, options?: {