@pisell/pisellos 2.3.17 → 2.3.19

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 (37) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  2. package/dist/modules/Order/index.d.ts +4 -1
  3. package/dist/modules/Order/index.js +56 -29
  4. package/dist/modules/Order/types.d.ts +13 -0
  5. package/dist/modules/Product/index.d.ts +1 -1
  6. package/dist/modules/Rules/index.d.ts +2 -8
  7. package/dist/modules/Rules/index.js +55 -9
  8. package/dist/modules/Rules/types.d.ts +10 -1
  9. package/dist/modules/SalesSummary/index.d.ts +7 -3
  10. package/dist/modules/SalesSummary/index.js +67 -39
  11. package/dist/modules/SalesSummary/types.d.ts +1 -0
  12. package/dist/modules/SurchargeList/index.d.ts +6 -4
  13. package/dist/modules/SurchargeList/index.js +62 -39
  14. package/dist/modules/SurchargeList/types.d.ts +6 -2
  15. package/dist/server/modules/order/index.js +1 -2
  16. package/dist/solution/BaseSales/index.d.ts +6 -0
  17. package/dist/solution/BaseSales/index.js +782 -658
  18. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +2 -1
  19. package/lib/model/strategy/adapter/promotion/index.js +0 -49
  20. package/lib/modules/Order/index.d.ts +4 -1
  21. package/lib/modules/Order/index.js +39 -16
  22. package/lib/modules/Order/types.d.ts +13 -0
  23. package/lib/modules/Product/index.d.ts +1 -1
  24. package/lib/modules/Rules/index.d.ts +2 -8
  25. package/lib/modules/Rules/index.js +57 -6
  26. package/lib/modules/Rules/types.d.ts +10 -1
  27. package/lib/modules/SalesSummary/index.d.ts +7 -3
  28. package/lib/modules/SalesSummary/index.js +28 -11
  29. package/lib/modules/SalesSummary/types.d.ts +1 -0
  30. package/lib/modules/SurchargeList/index.d.ts +6 -4
  31. package/lib/modules/SurchargeList/index.js +41 -21
  32. package/lib/modules/SurchargeList/types.d.ts +6 -2
  33. package/lib/server/modules/order/index.js +1 -2
  34. package/lib/solution/BaseSales/index.d.ts +6 -0
  35. package/lib/solution/BaseSales/index.js +103 -29
  36. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +2 -1
  37. package/package.json +1 -1
@@ -66,7 +66,8 @@ function normalizeBundleItems(bundleItems) {
66
66
  price: (_bundleItem$price3 = bundleItem.price) !== null && _bundleItem$price3 !== void 0 ? _bundleItem$price3 : unitStr,
67
67
  bundle_selling_price: unitStr,
68
68
  original_price: (_ref8 = (_ref9 = (_bundleItem$original_ = bundleItem.original_price) !== null && _bundleItem$original_ !== void 0 ? _bundleItem$original_ : bundleItem.product_price) !== null && _ref9 !== void 0 ? _ref9 : bundleItem.price) !== null && _ref8 !== void 0 ? _ref8 : unitStr,
69
- option: normalizeOptionItems(bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.option)
69
+ option: normalizeOptionItems(bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.option),
70
+ discount_list: preferPriceField ? [] : bundleItem.discount_list
70
71
  });
71
72
  // bundle_selling_price 落「正净额」:markdown = |price| − Σoptions;markup/原价维持原值。
72
73
  normalizedItem.bundle_selling_price = getBundleSellingMagnitude(magnitudeSource).toFixed(2);
@@ -1,49 +0,0 @@
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/model/strategy/adapter/promotion/index.ts
30
- var promotion_exports = {};
31
- __export(promotion_exports, {
32
- BUY_X_GET_Y_FREE_STRATEGY: () => import_examples.BUY_X_GET_Y_FREE_STRATEGY,
33
- PromotionAdapter: () => import_adapter.PromotionAdapter,
34
- PromotionEvaluator: () => import_evaluator.PromotionEvaluator,
35
- X_ITEMS_FOR_Y_PRICE_STRATEGY: () => import_examples.X_ITEMS_FOR_Y_PRICE_STRATEGY,
36
- default: () => import_adapter2.default
37
- });
38
- module.exports = __toCommonJS(promotion_exports);
39
- var import_evaluator = require("./evaluator");
40
- var import_adapter = require("./adapter");
41
- var import_adapter2 = __toESM(require("./adapter"));
42
- var import_examples = require("./examples");
43
- // Annotate the CommonJS export names for ESM import in node:
44
- 0 && (module.exports = {
45
- BUY_X_GET_Y_FREE_STRATEGY,
46
- PromotionAdapter,
47
- PromotionEvaluator,
48
- X_ITEMS_FOR_Y_PRICE_STRATEGY
49
- });
@@ -84,7 +84,9 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
84
84
  unavailableReasonKey?: string | null;
85
85
  scannedDiscountList?: Discount[];
86
86
  }>;
87
- applyDiscount(): void;
87
+ applyDiscount(options?: {
88
+ reapplyBookingDiscountProductUids?: string[];
89
+ }): void;
88
90
  /**
89
91
  * 注入促销评估器。
90
92
  *
@@ -197,6 +199,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
197
199
  private clearManualDepositOverride;
198
200
  private getOriginalSalesSnapshot;
199
201
  private isSnapshotPayableAmountUnchanged;
202
+ private hasShopDiscountChangedFromSnapshot;
200
203
  private restoreOriginalSnapshotIfProductsUnchanged;
201
204
  private clearPersistedAmountFieldsForFullRecalc;
202
205
  private getPaymentTargetAmount;
@@ -107,7 +107,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
107
107
  this.draftPersistEnabled = true;
108
108
  }
109
109
  collectHydratedEditDiscounts(products) {
110
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
110
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
111
111
  const discountMap = /* @__PURE__ */ new Map();
112
112
  for (const product of (0, import_bundleDiscountHydration.expandHydratedProductsForDiscountCollection)(products)) {
113
113
  for (const item of (product == null ? void 0 : product.discount_list) || []) {
@@ -137,6 +137,13 @@ var OrderModule = class extends import_BaseModule.BaseModule {
137
137
  existed.amount = Number(existed.amount || 0) + amount;
138
138
  existed.used_par_value = String(Number(existed.used_par_value || 0) + amount);
139
139
  existed.balance = String(Number(existed.balance || 0) + amount);
140
+ const productIds = Array.isArray((_f = existed.limited_relation_product_data) == null ? void 0 : _f.product_ids) ? existed.limited_relation_product_data.product_ids : [];
141
+ if ((product == null ? void 0 : product.product_id) !== void 0 && (product == null ? void 0 : product.product_id) !== null && !productIds.includes(product.product_id)) {
142
+ existed.limited_relation_product_data = {
143
+ ...existed.limited_relation_product_data || {},
144
+ product_ids: [...productIds, product.product_id]
145
+ };
146
+ }
140
147
  existed.applicableProductDetails = [
141
148
  ...existed.applicableProductDetails || [],
142
149
  detail
@@ -153,9 +160,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
153
160
  encoded: "",
154
161
  code: "",
155
162
  tag: type,
156
- product_id: ((_f = item == null ? void 0 : item.discount) == null ? void 0 : _f.discount_product_id) ?? (product == null ? void 0 : product.product_id) ?? 0,
163
+ product_id: ((_g = item == null ? void 0 : item.discount) == null ? void 0 : _g.discount_product_id) ?? (product == null ? void 0 : product.product_id) ?? 0,
157
164
  relation_type: "",
158
- par_value: String(((_g = item == null ? void 0 : item.discount) == null ? void 0 : _g.original_amount) ?? (item == null ? void 0 : item.amount) ?? "0"),
165
+ par_value: String(((_h = item == null ? void 0 : item.discount) == null ? void 0 : _h.original_amount) ?? (item == null ? void 0 : item.amount) ?? "0"),
159
166
  used_par_value: String((item == null ? void 0 : item.amount) ?? "0"),
160
167
  limit_status: "enable",
161
168
  limited_relation_product_data: {
@@ -185,8 +192,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
185
192
  discount: {
186
193
  ...(item == null ? void 0 : item.discount) || {},
187
194
  resource_id: key,
188
- discount_product_id: ((_h = item == null ? void 0 : item.discount) == null ? void 0 : _h.discount_product_id) ?? (product == null ? void 0 : product.product_id) ?? 0,
189
- discount_calculation_mode: ((_i = item == null ? void 0 : item.discount) == null ? void 0 : _i.discount_calculation_mode) ?? "item_level"
195
+ discount_product_id: ((_i = item == null ? void 0 : item.discount) == null ? void 0 : _i.discount_product_id) ?? (product == null ? void 0 : product.product_id) ?? 0,
196
+ discount_calculation_mode: ((_j = item == null ? void 0 : item.discount) == null ? void 0 : _j.discount_calculation_mode) ?? "item_level"
190
197
  },
191
198
  applicableProductDetails: [detail],
192
199
  appliedProductDetails: [detail]
@@ -539,7 +546,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
539
546
  unavailableReason
540
547
  };
541
548
  }
542
- applyDiscount() {
549
+ applyDiscount(options) {
543
550
  var _a, _b, _c, _d;
544
551
  const tempOrder = this.store.tempOrder;
545
552
  if (!tempOrder)
@@ -560,6 +567,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
560
567
  holders,
561
568
  isFormSubject: (product) => (0, import_utils.resolveIsFormSubject)(tempOrder, product),
562
569
  orderTotalAmount: Number(((_c = this.store.summary) == null ? void 0 : _c.total_amount) || 0)
570
+ }, {
571
+ reapplyBookingDiscountProductUids: options == null ? void 0 : options.reapplyBookingDiscountProductUids
563
572
  });
564
573
  if (result == null ? void 0 : result.productList) {
565
574
  const previousProductsByUid = (0, import_utils.indexOrderProductsByUid)(tempOrder.products);
@@ -1470,10 +1479,15 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1470
1479
  });
1471
1480
  return currentAmountGap === snapshotAmountGap;
1472
1481
  }
1473
- restoreOriginalSnapshotIfProductsUnchanged(tempOrder) {
1474
- const snapshot = this.getOriginalSalesSnapshot(tempOrder);
1475
- if (!snapshot)
1476
- return null;
1482
+ hasShopDiscountChangedFromSnapshot(tempOrder, snapshot) {
1483
+ const snapshotSummary = snapshot.summary && typeof snapshot.summary === "object" ? snapshot.summary : {};
1484
+ const snapshotShopDiscount = snapshot.shop_discount ?? snapshotSummary.shop_discount;
1485
+ if (snapshotShopDiscount === void 0 || snapshotShopDiscount === null || snapshotShopDiscount === "") {
1486
+ return !new import_decimal.default(tempOrder.shop_discount || 0).equals(0);
1487
+ }
1488
+ return !new import_decimal.default(tempOrder.shop_discount || 0).equals(snapshotShopDiscount || 0);
1489
+ }
1490
+ restoreOriginalSnapshotIfProductsUnchanged(tempOrder, snapshot) {
1477
1491
  const currentFingerprint = this.buildOrderProductsFingerprint(tempOrder.products);
1478
1492
  if (currentFingerprint !== snapshot.productFingerprint) {
1479
1493
  const currentStructuralFingerprint = this.buildOrderProductsStructuralFingerprint(tempOrder.products);
@@ -1974,14 +1988,18 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1974
1988
  return this.applyLastOrderDepositSnapshot(tempOrder, nextSummary);
1975
1989
  }
1976
1990
  async recalculateSummary(options) {
1991
+ var _a;
1977
1992
  const tempOrder = (options == null ? void 0 : options.createIfMissing) ? this.ensureTempOrder() : this.store.tempOrder;
1978
1993
  if (!tempOrder)
1979
1994
  return null;
1980
1995
  this.sanitizeTempOrderProducts(tempOrder);
1981
- const snapshotSummary = this.restoreOriginalSnapshotIfProductsUnchanged(tempOrder);
1996
+ const originalSnapshot = this.getOriginalSalesSnapshot(tempOrder);
1997
+ const hasShopDiscountChanged = originalSnapshot ? this.hasShopDiscountChangedFromSnapshot(tempOrder, originalSnapshot) : false;
1998
+ const shouldReuseOriginalSnapshot = originalSnapshot && !hasShopDiscountChanged;
1999
+ const snapshotSummary = shouldReuseOriginalSnapshot ? this.restoreOriginalSnapshotIfProductsUnchanged(tempOrder, originalSnapshot) : null;
1982
2000
  if (snapshotSummary)
1983
2001
  return snapshotSummary;
1984
- const shouldFullRecalculateFromSnapshot = Boolean(this.getOriginalSalesSnapshot(tempOrder));
2002
+ const shouldFullRecalculateFromSnapshot = Boolean(originalSnapshot);
1985
2003
  const summaryProducts = shouldFullRecalculateFromSnapshot ? (0, import_lodash_es.cloneDeep)(tempOrder.products || []) : tempOrder.products;
1986
2004
  if (shouldFullRecalculateFromSnapshot) {
1987
2005
  this.clearPersistedAmountFieldsForFullRecalc(summaryProducts || []);
@@ -2028,7 +2046,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2028
2046
  const salesSummaryResult = await salesSummary.getSummary({
2029
2047
  products: summaryProducts,
2030
2048
  isPriceIncludeTax: tempOrder.is_price_include_tax,
2031
- shopDiscount: tempOrder.shop_discount
2049
+ shopDiscount: tempOrder.shop_discount,
2050
+ ...((_a = this.otherParams) == null ? void 0 : _a.channel) ? { channel: this.otherParams.channel } : {}
2032
2051
  });
2033
2052
  if (shouldFullRecalculateFromSnapshot) {
2034
2053
  tempOrder.products = summaryProducts;
@@ -2964,7 +2983,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2964
2983
  });
2965
2984
  }
2966
2985
  applyOrderProductUpdateToTempOrder(tempOrder, params) {
2967
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
2986
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
2968
2987
  const {
2969
2988
  product_id,
2970
2989
  product_variant_id,
@@ -3118,12 +3137,15 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3118
3137
  tempOrder.products[productIndex],
3119
3138
  (_q = tempOrder.products[productIndex].metadata) == null ? void 0 : _q.unique_identification_number
3120
3139
  );
3140
+ return (_r = tempOrder.products[productIndex].metadata) == null ? void 0 : _r.unique_identification_number;
3121
3141
  }
3122
3142
  async updateOrderProduct(params) {
3123
3143
  const tempOrder = this.ensureTempOrder();
3124
- this.applyOrderProductUpdateToTempOrder(tempOrder, params);
3144
+ const updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params);
3125
3145
  await this.applyPromotion();
3126
- this.applyDiscount();
3146
+ this.applyDiscount({
3147
+ reapplyBookingDiscountProductUids: params.allow_booking_discount_reapply && updatedProductUid ? [String(updatedProductUid)] : void 0
3148
+ });
3127
3149
  this.sanitizeTempOrderProducts(tempOrder);
3128
3150
  await this.recalculateSummary({ createIfMissing: true });
3129
3151
  this.persistTempOrder();
@@ -3947,6 +3969,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3947
3969
  products: (0, import_lodash_es.cloneDeep)(nextTempOrder.products || []),
3948
3970
  payments: (0, import_lodash_es.cloneDeep)(nextTempOrder.payments || []),
3949
3971
  surcharges: (0, import_lodash_es.cloneDeep)(nextTempOrder.surcharges || []),
3972
+ shop_discount: nextTempOrder.shop_discount || "0.00",
3950
3973
  productFingerprint: this.buildOrderProductsFingerprint(nextTempOrder.products || [])
3951
3974
  }
3952
3975
  };
@@ -340,6 +340,19 @@ export interface UpdateOrderProductParams {
340
340
  * });
341
341
  */
342
342
  allow_booking_reprice?: boolean;
343
+ /**
344
+ * Change time 重报价后,允许当前预约商品行重新应用已选编辑态折扣卡。
345
+ *
346
+ * @example
347
+ * await order.updateOrderProduct({
348
+ * product_id: 1,
349
+ * product_variant_id: 0,
350
+ * updates: { discount_list: [] },
351
+ * booking: { duration: 2 },
352
+ * allow_booking_discount_reapply: true,
353
+ * });
354
+ */
355
+ allow_booking_discount_reapply?: boolean;
343
356
  }
344
357
  /** 仅更新购物车行数量;行定位语义与 updateOrderProduct / removeProductFromOrder 保持一致 */
345
358
  export interface UpdateOrderProductQuantityParams extends OrderProductIdentity {
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "duration" | "session" | "normal";
52
+ getProductType(): "normal" | "duration" | "session";
53
53
  }
@@ -1,8 +1,7 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
- import { Rules, RulesModuleAPI, DiscountResult, RulesFormSubject, UnavailableReason } from './types';
3
+ import { Rules, RulesModuleAPI, DiscountResult, RulesFormSubject, RulesCalcDiscountOptions, UnavailableReason } from './types';
4
4
  import { Discount } from '../Discount/types';
5
- import { SetDiscountSelectedParams } from '../../solution/ShopDiscount/types';
6
5
  import { WindowPlugin } from '../../plugins';
7
6
  export declare class RulesModule extends BaseModule implements Module, RulesModuleAPI {
8
7
  protected defaultName: string;
@@ -45,12 +44,7 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
45
44
  }[];
46
45
  isFormSubject: RulesFormSubject;
47
46
  orderTotalAmount: number;
48
- }, options?: {
49
- isSelected?: boolean;
50
- discountId?: number;
51
- selectedList?: SetDiscountSelectedParams[];
52
- scan?: boolean;
53
- }): DiscountResult;
47
+ }, options?: RulesCalcDiscountOptions): DiscountResult;
54
48
  /**
55
49
  * 检查优惠是否符合 PackageSubItemUsageRules 配置
56
50
  * @param discount 优惠券
@@ -209,6 +209,36 @@ var RulesModule = class extends import_BaseModule.BaseModule {
209
209
  var _a;
210
210
  const resolveIsFormSubject = (product) => typeof isFormSubject === "function" ? Boolean(isFormSubject(product)) : Boolean(isFormSubject);
211
211
  const isEditModeAddNewProduct = productList.find((n) => n.booking_id) && productList.find((n) => !n.booking_id);
212
+ const reapplyBookingDiscountProductUids = new Set(
213
+ ((options == null ? void 0 : options.reapplyBookingDiscountProductUids) || []).filter((uid) => uid !== void 0 && uid !== null && uid !== "").map(String)
214
+ );
215
+ const getOriginProductUid = (originProduct) => {
216
+ var _a2;
217
+ const uid = ((_a2 = originProduct == null ? void 0 : originProduct.metadata) == null ? void 0 : _a2.unique_identification_number) ?? (originProduct == null ? void 0 : originProduct.unique_identification_number);
218
+ if (uid === void 0 || uid === null || uid === "")
219
+ return void 0;
220
+ return String(uid);
221
+ };
222
+ const shouldReapplyBookingDiscount = (originProduct, selectedDiscount) => {
223
+ if (!selectedDiscount)
224
+ return false;
225
+ const uid = getOriginProductUid(originProduct);
226
+ if (!uid || !reapplyBookingDiscountProductUids.has(uid))
227
+ return false;
228
+ const discountType = selectedDiscount.tag || selectedDiscount.type;
229
+ return selectedDiscount.isEditMode === true && selectedDiscount.isSelected === true && ["good_pass", "discount_card", "product_discount_card"].includes(discountType);
230
+ };
231
+ const resolveReapplyEditModeDiscountPercent = (originProduct, selectedDiscount) => {
232
+ var _a2;
233
+ if (!shouldReapplyBookingDiscount(originProduct, selectedDiscount))
234
+ return void 0;
235
+ const discountType = (selectedDiscount == null ? void 0 : selectedDiscount.tag) || (selectedDiscount == null ? void 0 : selectedDiscount.type);
236
+ if (discountType !== "discount_card" && discountType !== "product_discount_card") {
237
+ return void 0;
238
+ }
239
+ const percent = Number((_a2 = selectedDiscount.discount) == null ? void 0 : _a2.percent);
240
+ return Number.isFinite(percent) ? percent : void 0;
241
+ };
212
242
  const editModeDiscount = [];
213
243
  const addModeDiscount = [];
214
244
  discountList.forEach((discount) => {
@@ -232,9 +262,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
232
262
  }
233
263
  });
234
264
  }
235
- const filteredDiscountList = addModeDiscount.filter((discount) => {
236
- return !discount.isManualSelect;
237
- });
238
265
  const hasDiscountInput = editModeDiscount.length > 0 || addModeDiscount.length > 0 || Boolean(options == null ? void 0 : options.discountId) || Boolean((_a = options == null ? void 0 : options.selectedList) == null ? void 0 : _a.length) || Boolean(options == null ? void 0 : options.scan);
239
266
  if (!hasDiscountInput) {
240
267
  return {
@@ -242,6 +269,14 @@ var RulesModule = class extends import_BaseModule.BaseModule {
242
269
  productList
243
270
  };
244
271
  }
272
+ const canUseEditModeDiscountForReapply = (discount) => {
273
+ const discountType = discount.tag || discount.type;
274
+ return reapplyBookingDiscountProductUids.size > 0 && discount.isEditMode === true && discount.isSelected === true && ["good_pass", "discount_card", "product_discount_card"].includes(discountType);
275
+ };
276
+ const filteredDiscountList = [
277
+ ...addModeDiscount.filter((discount) => !discount.isManualSelect),
278
+ ...editModeDiscount.filter(canUseEditModeDiscountForReapply)
279
+ ];
245
280
  const flattenProductsWithBundle = (productList2) => {
246
281
  const flattened = [];
247
282
  productList2.forEach((originProduct) => {
@@ -737,9 +772,18 @@ var RulesModule = class extends import_BaseModule.BaseModule {
737
772
  const applicableDiscounts = sortedDiscountList.filter((discount) => {
738
773
  var _a3, _b2, _c2, _d2;
739
774
  const discountType = discount.tag || discount.type;
775
+ const currentOriginUid = getOriginProductUid(originProduct);
776
+ const isReapplyEditModeDiscountForProduct = discount.isEditMode && reapplyBookingDiscountProductUids.size > 0 && currentOriginUid && reapplyBookingDiscountProductUids.has(String(currentOriginUid)) && discount.isSelected === true;
777
+ if (discount.isEditMode && reapplyBookingDiscountProductUids.size > 0) {
778
+ const uid = currentOriginUid;
779
+ if (!uid || !reapplyBookingDiscountProductUids.has(uid))
780
+ return false;
781
+ if (!discount.isSelected)
782
+ return false;
783
+ }
740
784
  if (["good_pass", "discount_card", "product_discount_card"].includes(
741
785
  discountType
742
- )) {
786
+ ) && !isReapplyEditModeDiscountForProduct) {
743
787
  if (discount.config === void 0 || !((_a3 = discount == null ? void 0 : discount.config) == null ? void 0 : _a3.isAvailable)) {
744
788
  return false;
745
789
  }
@@ -955,7 +999,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
955
999
  }
956
1000
  return;
957
1001
  }
958
- if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === "undefined" && !(options == null ? void 0 : options.scan) && !isEditModeAddNewProduct) {
1002
+ const shouldReapplyBookingDiscountForProduct = shouldReapplyBookingDiscount(originProduct, selectedDiscount);
1003
+ if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === "undefined" && !(options == null ? void 0 : options.scan) && !isEditModeAddNewProduct && !shouldReapplyBookingDiscountForProduct) {
959
1004
  return;
960
1005
  }
961
1006
  const isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === "good_pass";
@@ -1011,10 +1056,16 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1011
1056
  let productDiscountDifference;
1012
1057
  let discountedOptions = product.options;
1013
1058
  let optionDiscountAmount = 0;
1059
+ let reapplyDiscountPercent;
1014
1060
  if (isOrderLevel && productAllocation) {
1015
1061
  amount = productAllocation.discountAmount;
1016
1062
  productDiscountDifference = productAllocation.difference;
1017
1063
  mainProductSellingPrice = Math.max(new import_decimal.default(product.price).minus(amount).toNumber(), 0);
1064
+ } else if (resolveReapplyEditModeDiscountPercent(originProduct, selectedDiscount2) !== void 0) {
1065
+ const percent = resolveReapplyEditModeDiscountPercent(originProduct, selectedDiscount2);
1066
+ reapplyDiscountPercent = new import_decimal.default(percent).toFixed(2);
1067
+ mainProductSellingPrice = new import_decimal.default(product.price || 0).mul(new import_decimal.default(100).minus(percent)).div(100).toDecimalPlaces(2).toNumber();
1068
+ amount = new import_decimal.default(product.price).minus(mainProductSellingPrice).toNumber();
1018
1069
  } else {
1019
1070
  mainProductSellingPrice = (0, import_utils.getDiscountAmount)(
1020
1071
  selectedDiscount2,
@@ -1049,7 +1100,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1049
1100
  title: selectedDiscount2.format_title,
1050
1101
  original_amount: product.price,
1051
1102
  product_id: originProduct.id || originProduct.product_id,
1052
- percent: selectedDiscount2.par_value,
1103
+ percent: reapplyDiscountPercent ?? selectedDiscount2.par_value,
1053
1104
  discount_product_id: selectedDiscount2.product_id
1054
1105
  },
1055
1106
  // 前端使用的num数量,为了计算优惠金额
@@ -1,4 +1,5 @@
1
1
  import { Discount } from '../Discount/types';
2
+ import { SetDiscountSelectedParams } from '../../solution/ShopDiscount/types';
2
3
  export declare enum UnavailableReason {
3
4
  TimeLimit = "time_limit",
4
5
  ProductNotApplicable = "product_not_applicable",
@@ -23,6 +24,14 @@ export interface DiscountResult {
23
24
  discountList: any[];
24
25
  }
25
26
  export type RulesFormSubject = boolean | ((product: any) => boolean);
27
+ export interface RulesCalcDiscountOptions {
28
+ isSelected?: boolean;
29
+ discountId?: number;
30
+ selectedList?: SetDiscountSelectedParams[];
31
+ scan?: boolean;
32
+ /** Change time 重报价目标行:允许已选编辑态折扣卡重新应用到这些 booking 商品。 */
33
+ reapplyBookingDiscountProductUids?: string[];
34
+ }
26
35
  export interface RulesModuleAPI {
27
36
  setRulesList: (rulesList: Rules[]) => Promise<void>;
28
37
  clear: () => Promise<void>;
@@ -34,7 +43,7 @@ export interface RulesModuleAPI {
34
43
  }[];
35
44
  isFormSubject: RulesFormSubject;
36
45
  orderTotalAmount: number;
37
- }) => DiscountResult;
46
+ }, options?: RulesCalcDiscountOptions) => DiscountResult;
38
47
  }
39
48
  type ProductDetail = {
40
49
  isClient?: boolean;
@@ -9,16 +9,19 @@ export declare class SalesSummaryModule extends BaseModule implements Module, Sa
9
9
  private store;
10
10
  private request;
11
11
  private surchargeListModuleName;
12
+ private otherParams;
13
+ private surchargeListChannel;
12
14
  constructor(name?: string, version?: string);
13
15
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
14
16
  /**
15
- * 更新父级解决方案透传的运行态参数,并在 surcharge 模块名变化时刷新附加费列表。
17
+ * 更新父级解决方案透传的运行态参数,并在 surcharge 模块名或渠道变化时刷新附加费列表。
16
18
  *
17
19
  * @example
18
- * await salesSummaryModule.updateOtherParams({ surchargeListModuleName: 'custom_surchargeList' });
20
+ * await salesSummaryModule.updateOtherParams({ channel: 'pos', surchargeListModuleName: 'custom_surchargeList' });
19
21
  */
20
22
  updateOtherParams(params: Record<string, any>): Promise<void>;
21
- getSurchargeList(): Promise<void>;
23
+ private resolveChannel;
24
+ getSurchargeList(channel?: string): Promise<void>;
22
25
  private getAppData;
23
26
  private getTaxConfig;
24
27
  getSummary(params: {
@@ -26,6 +29,7 @@ export declare class SalesSummaryModule extends BaseModule implements Module, Sa
26
29
  isPriceIncludeTax?: number;
27
30
  taxRate?: number;
28
31
  shopDiscount?: string | number;
32
+ channel?: string;
29
33
  }): Promise<{
30
34
  tax_title: string;
31
35
  tax_rate: number | undefined;
@@ -33,12 +33,15 @@ var salesSummaryDataKeys = {
33
33
  taxTitle: "tax_title",
34
34
  taxCountryCode: "tax_country_code"
35
35
  };
36
+ var DEFAULT_SURCHARGE_CHANNEL = "online-store";
36
37
  var SalesSummaryModule = class extends import_BaseModule.BaseModule {
37
38
  constructor(name, version) {
38
39
  super(name, version);
39
40
  this.defaultName = "salesSummary";
40
41
  this.defaultVersion = "1.0.0";
41
42
  this.surchargeListModuleName = "surchargeList";
43
+ this.otherParams = {};
44
+ this.surchargeListChannel = DEFAULT_SURCHARGE_CHANNEL;
42
45
  }
43
46
  async initialize(core, options) {
44
47
  var _a, _b, _c;
@@ -46,9 +49,10 @@ var SalesSummaryModule = class extends import_BaseModule.BaseModule {
46
49
  this.store = options.store;
47
50
  this.appPlugin = this.core.getPlugin("app");
48
51
  this.request = this.core.getPlugin("request");
52
+ this.otherParams = options.otherParams || {};
49
53
  this.store.surchargeList = ((_a = options.initialState) == null ? void 0 : _a.surchargeList) || [];
50
54
  this.store.summary = ((_b = options.initialState) == null ? void 0 : _b.summary) || (0, import_utils.createEmptySalesSummary)();
51
- this.surchargeListModuleName = ((_c = options.otherParams) == null ? void 0 : _c.surchargeListModuleName) || "surchargeList";
55
+ this.surchargeListModuleName = ((_c = this.otherParams) == null ? void 0 : _c.surchargeListModuleName) || "surchargeList";
52
56
  if (!this.appPlugin) {
53
57
  throw new Error("SalesSummaryModule 需要 app 插件支持");
54
58
  }
@@ -58,41 +62,50 @@ var SalesSummaryModule = class extends import_BaseModule.BaseModule {
58
62
  await this.getSurchargeList();
59
63
  }
60
64
  /**
61
- * 更新父级解决方案透传的运行态参数,并在 surcharge 模块名变化时刷新附加费列表。
65
+ * 更新父级解决方案透传的运行态参数,并在 surcharge 模块名或渠道变化时刷新附加费列表。
62
66
  *
63
67
  * @example
64
- * await salesSummaryModule.updateOtherParams({ surchargeListModuleName: 'custom_surchargeList' });
68
+ * await salesSummaryModule.updateOtherParams({ channel: 'pos', surchargeListModuleName: 'custom_surchargeList' });
65
69
  */
66
70
  async updateOtherParams(params) {
71
+ const previousChannel = this.resolveChannel();
67
72
  const nextSurchargeListModuleName = (params == null ? void 0 : params.surchargeListModuleName) || "surchargeList";
68
- if (nextSurchargeListModuleName === this.surchargeListModuleName)
69
- return;
73
+ const nextChannel = this.resolveChannel(params);
74
+ const shouldReload = nextSurchargeListModuleName !== this.surchargeListModuleName || nextChannel !== previousChannel;
75
+ this.otherParams = params || {};
70
76
  this.surchargeListModuleName = nextSurchargeListModuleName;
71
- await this.getSurchargeList();
77
+ if (shouldReload) {
78
+ await this.getSurchargeList(nextChannel);
79
+ }
72
80
  }
73
- async getSurchargeList() {
81
+ resolveChannel(params = this.otherParams) {
82
+ return (params == null ? void 0 : params.channel) || DEFAULT_SURCHARGE_CHANNEL;
83
+ }
84
+ async getSurchargeList(channel = this.resolveChannel()) {
74
85
  try {
75
86
  const surchargeListModule = this.core.getModule(
76
87
  this.surchargeListModuleName
77
88
  );
78
89
  if (surchargeListModule == null ? void 0 : surchargeListModule.getSurchargeList) {
79
- this.store.surchargeList = await surchargeListModule.getSurchargeList();
90
+ this.store.surchargeList = await surchargeListModule.getSurchargeList({ channel });
91
+ this.surchargeListChannel = channel;
80
92
  return;
81
93
  }
82
94
  const surchargeList = await this.request.get(
83
95
  "/order/custom-surcharge/available/v2",
84
96
  {
85
- // TODO 真实的渠道
86
- channel: "online-store",
97
+ channel,
87
98
  is_assemble_product_data: 1,
88
99
  is_assemble_schedule_data: 1,
89
100
  with: ["relationSchedule"]
90
101
  }
91
102
  );
92
103
  this.store.surchargeList = (surchargeList == null ? void 0 : surchargeList.data) || [];
104
+ this.surchargeListChannel = channel;
93
105
  } catch (error) {
94
106
  console.warn("[SalesSummaryModule] 加载附加费配置失败", error);
95
107
  this.store.surchargeList = [];
108
+ this.surchargeListChannel = channel;
96
109
  }
97
110
  }
98
111
  getAppData(key) {
@@ -114,7 +127,11 @@ var SalesSummaryModule = class extends import_BaseModule.BaseModule {
114
127
  }
115
128
  async getSummary(params) {
116
129
  var _a, _b;
117
- const { products = [], isPriceIncludeTax, taxRate, shopDiscount } = params;
130
+ const { products = [], isPriceIncludeTax, taxRate, shopDiscount, channel } = params;
131
+ const summaryChannel = channel || this.resolveChannel();
132
+ if (summaryChannel !== this.surchargeListChannel) {
133
+ await this.getSurchargeList(summaryChannel);
134
+ }
118
135
  const taxConfig = this.getTaxConfig();
119
136
  const summarySchedule = this.core.getModule(
120
137
  `${this.name.split("_")[0]}_schedule`
@@ -63,5 +63,6 @@ export interface SalesSummaryModuleAPI {
63
63
  isPriceIncludeTax?: number;
64
64
  taxRate?: number;
65
65
  shopDiscount?: string | number;
66
+ channel?: string;
66
67
  }): Promise<SalesSummaryData>;
67
68
  }
@@ -1,16 +1,18 @@
1
1
  import { Module, ModuleOptions, PisellCore } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
- import { SurchargeListItem, SurchargeListModuleAPI } from './types';
3
+ import { SurchargeListItem, SurchargeListModuleAPI, SurchargeListQuery } from './types';
4
4
  export * from './types';
5
5
  export declare class SurchargeListModule extends BaseModule implements Module, SurchargeListModuleAPI {
6
6
  protected defaultName: string;
7
7
  protected defaultVersion: string;
8
8
  private request;
9
9
  private store;
10
- private loadingPromise;
10
+ private loadingPromises;
11
+ private requestVersion;
11
12
  constructor(name?: string, version?: string);
12
13
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
13
- getSurchargeList(): Promise<SurchargeListItem[]>;
14
- refreshSurchargeList(): Promise<SurchargeListItem[]>;
14
+ private resolveChannel;
15
+ getSurchargeList(query?: SurchargeListQuery): Promise<SurchargeListItem[]>;
16
+ refreshSurchargeList(query?: SurchargeListQuery): Promise<SurchargeListItem[]>;
15
17
  private loadSurchargeList;
16
18
  }