@pisell/pisellos 2.2.172 → 2.2.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 (34) hide show
  1. package/dist/modules/Order/index.d.ts +6 -21
  2. package/dist/modules/Order/index.js +56 -103
  3. package/dist/modules/Order/types.d.ts +3 -2
  4. package/dist/modules/Order/utils.d.ts +16 -0
  5. package/dist/modules/Order/utils.js +82 -2
  6. package/dist/modules/Quotation/index.d.ts +0 -1
  7. package/dist/modules/Quotation/index.js +8 -17
  8. package/dist/server/modules/products/index.d.ts +1 -1
  9. package/dist/server/modules/products/index.js +128 -112
  10. package/dist/solution/BaseSales/index.d.ts +4 -16
  11. package/dist/solution/BaseSales/index.js +178 -104
  12. package/dist/solution/BaseSales/types.d.ts +14 -0
  13. package/dist/solution/BaseSales/utils/quotationPrice.js +95 -17
  14. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +4 -2
  15. package/dist/solution/BookingByStep/index.d.ts +1 -1
  16. package/dist/solution/BookingTicket/index.js +10 -2
  17. package/lib/model/strategy/adapter/promotion/index.js +49 -0
  18. package/lib/modules/Order/index.d.ts +6 -21
  19. package/lib/modules/Order/index.js +55 -100
  20. package/lib/modules/Order/types.d.ts +3 -2
  21. package/lib/modules/Order/utils.d.ts +16 -0
  22. package/lib/modules/Order/utils.js +54 -2
  23. package/lib/modules/Quotation/index.d.ts +0 -1
  24. package/lib/modules/Quotation/index.js +1 -9
  25. package/lib/server/modules/products/index.d.ts +1 -1
  26. package/lib/server/modules/products/index.js +26 -15
  27. package/lib/solution/BaseSales/index.d.ts +4 -16
  28. package/lib/solution/BaseSales/index.js +71 -35
  29. package/lib/solution/BaseSales/types.d.ts +14 -0
  30. package/lib/solution/BaseSales/utils/quotationPrice.js +90 -14
  31. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +1 -1
  32. package/lib/solution/BookingByStep/index.d.ts +1 -1
  33. package/lib/solution/BookingTicket/index.js +8 -0
  34. package/package.json +1 -1
@@ -1,3 +1,9 @@
1
+ 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); }
2
+ 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; }
3
+ 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; }
4
+ 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; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ 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); }
1
7
  import dayjs from 'dayjs';
2
8
  import Decimal from 'decimal.js';
3
9
  function toFiniteNumber(value) {
@@ -56,6 +62,22 @@ function getProductQuantity(product) {
56
62
  var _product$num;
57
63
  return toPositiveInt((_product$num = product.num) !== null && _product$num !== void 0 ? _product$num : product.quantity, 1);
58
64
  }
65
+ function getBundleProductId(bundle) {
66
+ var _bundle$bundle_produc;
67
+ var productId = toFiniteNumber((_bundle$bundle_produc = bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle._bundle_product_id, NaN);
68
+ if (!Number.isFinite(productId)) return null;
69
+ return productId;
70
+ }
71
+ function getBundleVariantId(bundle) {
72
+ var _bundle$bundle_varian;
73
+ var variantId = toFiniteNumber((_bundle$bundle_varian = bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle.variant_id, 0);
74
+ if (!Number.isFinite(variantId) || variantId <= 0) return undefined;
75
+ return variantId;
76
+ }
77
+ function getBundleFallbackPrice(bundle) {
78
+ var _ref4, _ref5, _ref6, _bundle$bundle_sellin;
79
+ return toPriceString((_ref4 = (_ref5 = (_ref6 = (_bundle$bundle_sellin = bundle.bundle_selling_price) !== null && _bundle$bundle_sellin !== void 0 ? _bundle$bundle_sellin : bundle.price) !== null && _ref6 !== void 0 ? _ref6 : bundle.original_price) !== null && _ref5 !== void 0 ? _ref5 : bundle.base_price) !== null && _ref4 !== void 0 ? _ref4 : 0);
80
+ }
59
81
  function shouldSplitByDuration(duration, start, end) {
60
82
  if (!duration) return false;
61
83
  if (!start || !end || !end.isAfter(start)) return false;
@@ -121,39 +143,95 @@ function buildPriceSegment(params) {
121
143
  source: quotedPrice !== null ? 'quotation' : 'fallback'
122
144
  };
123
145
  }
124
- export function calculateBaseSalesProductBookingPrice(params) {
146
+ function calculatePriceForProduct(params) {
125
147
  var _segments$find;
126
- var product = params.product || {};
127
- var productId = getProductId(product);
128
- var variantId = getProductVariantId(product);
129
- var productQuantity = getProductQuantity(product);
130
- var fallbackPrice = getFallbackPrice(params);
131
- var segments = buildTimeSegments(params).map(function (segment) {
148
+ var segments = params.segments.map(function (segment) {
132
149
  return buildPriceSegment({
133
150
  quotation: params.quotation,
134
- productId: productId,
135
- variantId: variantId,
136
- customerId: params.customer_id,
137
- fallbackPrice: fallbackPrice,
151
+ productId: params.productId,
152
+ variantId: params.variantId,
153
+ customerId: params.customerId,
154
+ fallbackPrice: params.fallbackPrice,
138
155
  segment: segment
139
156
  });
140
157
  });
141
158
  var unitPrice = segments.reduce(function (total, segment) {
142
159
  return total.plus(segment.total_price);
143
160
  }, new Decimal(0));
144
- var totalPrice = unitPrice.times(productQuantity);
161
+ var totalPrice = unitPrice.times(params.quantity);
145
162
  var quotationShelfId = ((_segments$find = segments.find(function (segment) {
146
163
  return segment.quotation_shelf_id;
147
164
  })) === null || _segments$find === void 0 ? void 0 : _segments$find.quotation_shelf_id) || 0;
148
165
  return {
166
+ unitPrice: unitPrice,
167
+ totalPrice: totalPrice,
168
+ quotationShelfId: quotationShelfId,
169
+ segments: segments
170
+ };
171
+ }
172
+ function calculateBundlePrices(params, segments) {
173
+ var _params$product;
174
+ var bundleList = ((_params$product = params.product) === null || _params$product === void 0 ? void 0 : _params$product.product_bundle) || [];
175
+ if (!bundleList.length) return undefined;
176
+ return bundleList.map(function (bundle) {
177
+ var _bundle$bundle_id;
178
+ var productId = getBundleProductId(bundle);
179
+ var variantId = getBundleVariantId(bundle);
180
+ var quantity = getProductQuantity(bundle);
181
+ var price = calculatePriceForProduct({
182
+ quotation: params.quotation,
183
+ productId: productId,
184
+ variantId: variantId,
185
+ customerId: params.customer_id,
186
+ quantity: quantity,
187
+ fallbackPrice: getBundleFallbackPrice(bundle),
188
+ segments: segments
189
+ });
190
+ return {
191
+ bundle_id: (_bundle$bundle_id = bundle.bundle_id) !== null && _bundle$bundle_id !== void 0 ? _bundle$bundle_id : bundle.id,
192
+ group_id: bundle.group_id,
193
+ bundle_group_id: bundle.bundle_group_id,
194
+ bundle_product_id: productId,
195
+ bundle_variant_id: variantId !== null && variantId !== void 0 ? variantId : 0,
196
+ unit_price: price.unitPrice.toDecimalPlaces(2).toFixed(2),
197
+ total_price: price.totalPrice.toDecimalPlaces(2).toFixed(2),
198
+ quantity: quantity,
199
+ quotation_shelf_id: price.quotationShelfId,
200
+ source: price.segments.some(function (segment) {
201
+ return segment.source === 'quotation';
202
+ }) ? 'quotation' : 'fallback',
203
+ segments: price.segments
204
+ };
205
+ });
206
+ }
207
+ export function calculateBaseSalesProductBookingPrice(params) {
208
+ var product = params.product || {};
209
+ var productId = getProductId(product);
210
+ var variantId = getProductVariantId(product);
211
+ var productQuantity = getProductQuantity(product);
212
+ var fallbackPrice = getFallbackPrice(params);
213
+ var timeSegments = buildTimeSegments(params);
214
+ var price = calculatePriceForProduct({
215
+ quotation: params.quotation,
216
+ productId: productId,
217
+ variantId: variantId,
218
+ customerId: params.customer_id,
219
+ quantity: productQuantity,
220
+ fallbackPrice: fallbackPrice,
221
+ segments: timeSegments
222
+ });
223
+ var bundlePrices = calculateBundlePrices(params, timeSegments);
224
+ return _objectSpread({
149
225
  product_id: productId,
150
226
  product_variant_id: variantId !== null && variantId !== void 0 ? variantId : 0,
151
227
  customer_id: params.customer_id,
152
- unit_price: unitPrice.toDecimalPlaces(2).toFixed(2),
153
- total_price: totalPrice.toDecimalPlaces(2).toFixed(2),
228
+ unit_price: price.unitPrice.toDecimalPlaces(2).toFixed(2),
229
+ total_price: price.totalPrice.toDecimalPlaces(2).toFixed(2),
154
230
  quantity: productQuantity,
155
231
  duration: params.duration,
156
- quotation_shelf_id: quotationShelfId,
157
- segments: segments
158
- };
232
+ quotation_shelf_id: price.quotationShelfId,
233
+ segments: price.segments
234
+ }, bundlePrices ? {
235
+ product_bundle: bundlePrices
236
+ } : {});
159
237
  }
@@ -75,7 +75,7 @@ function findVariantById(origin, variantId) {
75
75
  * 注意:这里不生成 identity,缺省时由 OrderModule 自动补齐。
76
76
  */
77
77
  export function transformBaseProductToOrderProduct(params) {
78
- var _ref10, _ref11, _ref12, _payload$product_id, _ref13, _ref14, _payload$product_vari, _payload$_origin, _payload$_origin2, _ref15, _findVariantById, _ref16, _ref17, _ref18, _ref19, _ref20, _ref21, _ref22, _payload$price, _ref23, _payload$line_total, _payload$_extend, _ref24, _payload$option, _payload$bundle, _payload$unique_ident, _payload$quantity, _payload$_extend2, _extend, _extend2, _ref25, _ref26, _origin$base_price, _ref27, _ref28, _payload$line_total2, _payload$_extend3, _payload$_extend4, _extend3, _payload$_extend5, _payload$_extend6, _ref29, _ref30, _payload$tax_fee, _ref31, _ref32, _payload$is_charge_ta;
78
+ var _ref10, _ref11, _ref12, _payload$product_id, _ref13, _ref14, _payload$product_vari, _payload$_origin, _payload$_origin2, _ref15, _findVariantById, _ref16, _ref17, _ref18, _ref19, _ref20, _ref21, _ref22, _payload$price, _ref23, _payload$line_total, _payload$_extend, _ref24, _payload$option, _payload$bundle, _payload$quantity, _payload$_extend2, _extend, _extend2, _ref25, _ref26, _origin$base_price, _ref27, _ref28, _payload$line_total2, _payload$_extend3, _payload$_extend4, _extend3, _payload$_extend5, _payload$_extend6, _ref29, _ref30, _payload$tax_fee, _ref31, _ref32, _payload$is_charge_ta;
79
79
  var payload = params.payload,
80
80
  _params$fallbackProdu = params.fallbackProductId,
81
81
  fallbackProductId = _params$fallbackProdu === void 0 ? null : _params$fallbackProdu;
@@ -92,7 +92,9 @@ export function transformBaseProductToOrderProduct(params) {
92
92
  var hasPriceOverride = payload.price_override !== undefined && payload.price_override !== null && payload.price_override !== '';
93
93
  var productOptionItem = normalizeOptionItems((_ref24 = (_payload$option = payload.option) !== null && _payload$option !== void 0 ? _payload$option : payload.options) !== null && _ref24 !== void 0 ? _ref24 : payload.product_option_item);
94
94
  var productBundle = normalizeBundleItems((_payload$bundle = payload.bundle) !== null && _payload$bundle !== void 0 ? _payload$bundle : payload.product_bundle, hasPriceOverride);
95
- var uniqueIdentificationNumber = (_payload$unique_ident = payload.unique_identification_number) !== null && _payload$unique_ident !== void 0 ? _payload$unique_ident : payload.unique;
95
+ // `payload.unique` 是业务侧商品/票务标识,可能在连续加同一商品时重复;
96
+ // 行级唯一值只接受显式协议字段,缺省交给 OrderModule 生成。
97
+ var uniqueIdentificationNumber = payload.unique_identification_number;
96
98
  var resolvedQuantity = toSafePositiveInt((_payload$quantity = payload.quantity) !== null && _payload$quantity !== void 0 ? _payload$quantity : payload.num, 1);
97
99
  var originTotal = resolveManualDiscountOriginTotal({
98
100
  originTotal: payload.origin_total,
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
311
311
  date: string;
312
312
  status: string;
313
313
  week: string;
314
- weekNum: 0 | 2 | 1 | 5 | 3 | 4 | 6;
314
+ weekNum: 0 | 1 | 2 | 6 | 3 | 5 | 4;
315
315
  }[]>;
316
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
317
317
  private getScheduleDataByIds;
@@ -868,11 +868,17 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
868
868
  }, {
869
869
  key: "setOrderCustomer",
870
870
  value: function setOrderCustomer(customer) {
871
+ var _this$store$order$get3;
871
872
  if (!customer) {
872
873
  this.clearOrderCustomer();
873
874
  return;
874
875
  }
876
+ var previousCustomerId = (_this$store$order$get3 = this.store.order.getOrderCustomer()) === null || _this$store$order$get3 === void 0 ? void 0 : _this$store$order$get3.customer_id;
875
877
  var patch = formatOrderCustomerPatch(customer);
878
+ if (Number(previousCustomerId || 0) !== Number(patch.customer_id || 0)) {
879
+ this.discountConfigCacheKey = null;
880
+ this.hasManualDiscountSelection = false;
881
+ }
876
882
  this.store.order.setOrderCustomer(patch, customer);
877
883
  var next = this.buildOrderCustomerPayload();
878
884
  this.core.effects.emit("".concat(this.name, ":onOrderCustomerChange"), next);
@@ -907,6 +913,8 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
907
913
  _discountModule$setDi,
908
914
  _this3 = this;
909
915
  this.store.order.clearOrderCustomer();
916
+ this.discountConfigCacheKey = null;
917
+ this.hasManualDiscountSelection = false;
910
918
  var orderStore = this.store.order.store || {};
911
919
  var discountModule = orderStore.discount;
912
920
  void (discountModule === null || discountModule === void 0 || (_discountModule$setOr = discountModule.setOriginalDiscountList) === null || _discountModule$setOr === void 0 ? void 0 : _discountModule$setOr.call(discountModule, []));
@@ -1525,10 +1533,10 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
1525
1533
  }, {
1526
1534
  key: "buildAddProductCtx",
1527
1535
  value: function buildAddProductCtx(extra) {
1528
- var _extra$date2, _ref11, _this$getOrderCustome, _this$getOrderCustome2, _this$store$order$get3, _extra$presetStartTim2;
1536
+ var _extra$date2, _ref11, _this$getOrderCustome, _this$getOrderCustome2, _this$store$order$get4, _extra$presetStartTim2;
1529
1537
  var bookingContextState = this.store.bookingContext.getState();
1530
1538
  var date = (_extra$date2 = extra === null || extra === void 0 ? void 0 : extra.date) !== null && _extra$date2 !== void 0 ? _extra$date2 : bookingContextState.date;
1531
- var orderCustomerId = (_ref11 = (_this$getOrderCustome = (_this$getOrderCustome2 = this.getOrderCustomerSnapshot()) === null || _this$getOrderCustome2 === void 0 ? void 0 : _this$getOrderCustome2.id) !== null && _this$getOrderCustome !== void 0 ? _this$getOrderCustome : (_this$store$order$get3 = this.store.order.getTempOrder()) === null || _this$store$order$get3 === void 0 ? void 0 : _this$store$order$get3.customer_id) !== null && _ref11 !== void 0 ? _ref11 : undefined;
1539
+ var orderCustomerId = (_ref11 = (_this$getOrderCustome = (_this$getOrderCustome2 = this.getOrderCustomerSnapshot()) === null || _this$getOrderCustome2 === void 0 ? void 0 : _this$getOrderCustome2.id) !== null && _this$getOrderCustome !== void 0 ? _this$getOrderCustome : (_this$store$order$get4 = this.store.order.getTempOrder()) === null || _this$store$order$get4 === void 0 ? void 0 : _this$store$order$get4.customer_id) !== null && _ref11 !== void 0 ? _ref11 : undefined;
1532
1540
  return _objectSpread({
1533
1541
  bookingConfig: bookingContextState.bookingConfig,
1534
1542
  resourcesOrigin: bookingContextState.resourcesOrigin,
@@ -0,0 +1,49 @@
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
+ });
@@ -19,13 +19,12 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
19
19
  private rulesHooksOverride?;
20
20
  private orderHooks?;
21
21
  private otherParams?;
22
- /** 是否将 tempOrder 写入 localStorage;默认 true,SalesSdk 等内存态场景可关闭。 */
23
- private enableTempOrderPersist;
24
22
  /**
25
23
  * Populate `savedAmount` on each discount based on product-level discount details.
26
24
  * Only selected discounts get a non-zero value.
27
25
  */
28
26
  static populateSavedAmounts(productList: Array<Record<string, any>>, discountList: Array<Record<string, any>>): void;
27
+ private applyProductDiscountPrices;
29
28
  constructor(name?: string, version?: string);
30
29
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
31
30
  /**
@@ -55,25 +54,11 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
55
54
  cacheId?: string;
56
55
  salesSummaryModuleName?: string;
57
56
  }): void;
58
- private getTempOrderStorageKey;
59
- private restoreTempOrderFromStorage;
60
- /**
61
- * 运行时切换 tempOrder localStorage 持久化。
62
- *
63
- * @example
64
- * orderModule.setEnableTempOrderPersist(false);
65
- * orderModule.addProductToOrder(product); // 不会写入 localStorage
66
- */
67
- setEnableTempOrderPersist(enabled: boolean): void;
68
- /**
69
- * 读取当前是否启用 tempOrder localStorage 持久化。
70
- *
71
- * @example
72
- * if (orderModule.isTempOrderPersistEnabled()) {
73
- * orderModule.persistTempOrder();
74
- * }
75
- */
57
+ /** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化。 */
58
+ setEnableTempOrderPersist(_enabled: boolean): void;
59
+ /** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化。 */
76
60
  isTempOrderPersistEnabled(): boolean;
61
+ /** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化;草稿保存请使用 IndexedDB saveDraft。 */
77
62
  persistTempOrder(): void;
78
63
  private createDefaultTempOrderInstance;
79
64
  private createExternalSaleNumber;
@@ -204,7 +189,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
204
189
  private logSubmitBackendRejected;
205
190
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
206
191
  createOrder(params: CommitOrderParams['query']): {
207
- type: "appointment_booking" | "virtual";
192
+ type: "virtual" | "appointment_booking";
208
193
  platform: string;
209
194
  sales_channel: string;
210
195
  order_sales_channel: string;
@@ -50,8 +50,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
50
50
  super(name || "order", version);
51
51
  this.defaultName = "order";
52
52
  this.defaultVersion = "1.0.0";
53
- /** 是否将 tempOrder 写入 localStorage;默认 true,SalesSdk 等内存态场景可关闭。 */
54
- this.enableTempOrderPersist = true;
55
53
  }
56
54
  /**
57
55
  * Populate `savedAmount` on each discount based on product-level discount details.
@@ -78,6 +76,30 @@ var OrderModule = class extends import_BaseModule.BaseModule {
78
76
  d.savedAmount = d.isSelected && key != null && savedMap.has(key) ? savedMap.get(key).toNumber() : 0;
79
77
  }
80
78
  }
79
+ applyProductDiscountPrices(products) {
80
+ return (products || []).map((product) => {
81
+ var _a, _b, _c;
82
+ if ((_a = product.metadata) == null ? void 0 : _a.is_manual_discount)
83
+ return product;
84
+ const totalPerUnitDiscount = (product.discount_list || []).reduce(
85
+ (sum, discount) => sum + Number(discount.amount || 0),
86
+ 0
87
+ );
88
+ const optionSum = (0, import_utils.sumOptionUnitPrice)(product.product_option_item);
89
+ const sourcePrice = ((_b = product.metadata) == null ? void 0 : _b.source_product_price) ?? (((_c = product.metadata) == null ? void 0 : _c.main_product_original_price) != null ? new import_decimal.default(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : product.original_price ?? "0");
90
+ const newSourceSellingPrice = new import_decimal.default(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
91
+ const newMainSellingPrice = new import_decimal.default(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
92
+ if (product.metadata) {
93
+ product.metadata.main_product_selling_price = newMainSellingPrice;
94
+ product.metadata.price_schema_version = 2;
95
+ }
96
+ product.selling_price = (0, import_utils.composeLinePrice)({
97
+ mainPrice: newMainSellingPrice,
98
+ bundle: product.product_bundle
99
+ });
100
+ return product;
101
+ });
102
+ }
81
103
  async initialize(core, options) {
82
104
  var _a, _b, _c;
83
105
  this.core = core;
@@ -103,11 +125,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
103
125
  this.rulesHooksOverride = (_a = otherParams.rules) == null ? void 0 : _a.hooks;
104
126
  this.orderHooks = options.hooks || ((_b = otherParams.order) == null ? void 0 : _b.hooks) || ((_c = otherParams.hooks) == null ? void 0 : _c.order);
105
127
  this.otherParams = otherParams;
106
- this.enableTempOrderPersist = otherParams.enableTempOrderPersist !== false;
107
128
  this.registerDiscountModules(options);
108
- if (this.enableTempOrderPersist) {
109
- this.restoreTempOrderFromStorage();
110
- }
111
129
  this.logInfo("OrderModule initialized successfully");
112
130
  }
113
131
  /**
@@ -279,15 +297,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
279
297
  orderTotalAmount: Number(((_d = this.store.summary) == null ? void 0 : _d.total_amount) || 0)
280
298
  });
281
299
  if (result == null ? void 0 : result.productList) {
282
- tempOrder.products = (result.productList || []).map((product) => ({
283
- ...product,
284
- discount_list: (0, import_utils.normalizeOrderProductDiscountList)(
285
- (0, import_manualProductDiscount.syncManualProductDiscountProductNum)(
286
- product.discount_list,
287
- product.num
300
+ tempOrder.products = this.applyProductDiscountPrices(
301
+ (result.productList || []).map((product) => ({
302
+ ...product,
303
+ discount_list: (0, import_utils.normalizeOrderProductDiscountList)(
304
+ (0, import_manualProductDiscount.syncManualProductDiscountProductNum)(
305
+ product.discount_list,
306
+ product.num
307
+ )
288
308
  )
289
- )
290
- }));
309
+ }))
310
+ );
291
311
  }
292
312
  if (result == null ? void 0 : result.discountList) {
293
313
  OrderModule.populateSavedAmounts(
@@ -303,97 +323,16 @@ var OrderModule = class extends import_BaseModule.BaseModule {
303
323
  this.cacheId = params.cacheId;
304
324
  if (params.salesSummaryModuleName !== void 0)
305
325
  this.salesSummaryModuleName = params.salesSummaryModuleName;
306
- this.restoreTempOrderFromStorage();
307
- }
308
- // ─── TempOrder: localStorage 持久化 ───
309
- getTempOrderStorageKey() {
310
- if (!this.cacheId)
311
- return null;
312
- return `scanOrder:tempOrder:${this.cacheId}`;
313
- }
314
- restoreTempOrderFromStorage() {
315
- var _a, _b;
316
- const key = this.getTempOrderStorageKey();
317
- if (!key)
318
- return;
319
- if (!this.window)
320
- return;
321
- const cachedData = this.window.localStorage.getItem(key);
322
- if (!cachedData)
323
- return;
324
- try {
325
- const parsedData = JSON.parse(cachedData);
326
- if (!(0, import_utils.isTempOrder)(parsedData)) {
327
- this.window.localStorage.removeItem(key);
328
- return;
329
- }
330
- if (Array.isArray(parsedData.products)) {
331
- for (let i = 0; i < parsedData.products.length; i++) {
332
- const p = parsedData.products[i];
333
- if (!p || typeof p !== "object")
334
- continue;
335
- if (!Array.isArray(p.product_option_item)) {
336
- p.product_option_item = [];
337
- }
338
- if (!Array.isArray(p.product_bundle)) {
339
- p.product_bundle = [];
340
- }
341
- const row = p;
342
- const normalized = (0, import_utils3.normalizeOrderProduct)(row);
343
- normalized.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
344
- normalized.discount_list
345
- );
346
- parsedData.products[i] = normalized;
347
- }
348
- }
349
- delete parsedData.discount_list;
350
- const parsedRecord = parsedData;
351
- this.store.summary = parsedRecord.summary || (0, import_utils.createEmptySummary)();
352
- delete parsedData.summary;
353
- if (parsedRecord.lastOrderInfo) {
354
- this.store.lastOrderInfo = parsedRecord.lastOrderInfo;
355
- delete parsedData.lastOrderInfo;
356
- }
357
- if (!parsedData._extend || typeof parsedData._extend !== "object") {
358
- parsedData._extend = { productsByUid: {} };
359
- } else if (!parsedData._extend.productsByUid) {
360
- parsedData._extend.productsByUid = {};
361
- }
362
- this.store.tempOrder = parsedData;
363
- } catch {
364
- (_b = (_a = this.window) == null ? void 0 : _a.localStorage) == null ? void 0 : _b.removeItem(key);
365
- }
366
326
  }
367
- /**
368
- * 运行时切换 tempOrder localStorage 持久化。
369
- *
370
- * @example
371
- * orderModule.setEnableTempOrderPersist(false);
372
- * orderModule.addProductToOrder(product); // 不会写入 localStorage
373
- */
374
- setEnableTempOrderPersist(enabled) {
375
- this.enableTempOrderPersist = enabled;
327
+ /** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化。 */
328
+ setEnableTempOrderPersist(_enabled) {
376
329
  }
377
- /**
378
- * 读取当前是否启用 tempOrder localStorage 持久化。
379
- *
380
- * @example
381
- * if (orderModule.isTempOrderPersistEnabled()) {
382
- * orderModule.persistTempOrder();
383
- * }
384
- */
330
+ /** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化。 */
385
331
  isTempOrderPersistEnabled() {
386
- return this.enableTempOrderPersist;
332
+ return false;
387
333
  }
334
+ /** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化;草稿保存请使用 IndexedDB saveDraft。 */
388
335
  persistTempOrder() {
389
- if (!this.enableTempOrderPersist)
390
- return;
391
- const key = this.getTempOrderStorageKey();
392
- if (!key || !this.store.tempOrder)
393
- return;
394
- if (!this.window)
395
- return;
396
- this.window.localStorage.setItem(key, JSON.stringify(this.store.tempOrder));
397
336
  }
398
337
  // ─── TempOrder: 创建 & 获取 ───
399
338
  createDefaultTempOrderInstance() {
@@ -976,6 +915,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
976
915
  return;
977
916
  }
978
917
  const tempOrder = this.ensureTempOrder();
918
+ const previousCustomerId = tempOrder.customer_id ?? null;
979
919
  tempOrder.customer_id = patch.customer_id || patch.id || null;
980
920
  tempOrder.customer_name = String(patch.customer_name || "");
981
921
  tempOrder.country_calling_code = String(patch.country_calling_code || "");
@@ -996,6 +936,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
996
936
  else
997
937
  extend.customerSnapshot = (0, import_lodash_es.cloneDeep)(snapshot);
998
938
  }
939
+ const nextCustomerId = tempOrder.customer_id ?? null;
940
+ if (String(previousCustomerId ?? "") !== String(nextCustomerId ?? "")) {
941
+ (0, import_utils.clearTempOrderHolderAssignments)(tempOrder);
942
+ }
999
943
  this.persistTempOrder();
1000
944
  this.saveDraftInBackground();
1001
945
  this.emitOrderCustomerChange();
@@ -1020,6 +964,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1020
964
  }
1021
965
  clearOrderCustomer() {
1022
966
  const tempOrder = this.ensureTempOrder();
967
+ (0, import_utils.clearTempOrderHolderAssignments)(tempOrder);
1023
968
  tempOrder.customer_id = null;
1024
969
  tempOrder.customer_name = "";
1025
970
  tempOrder.country_calling_code = "";
@@ -1990,6 +1935,16 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1990
1935
  delete nextTempOrder.summary;
1991
1936
  delete nextTempOrder.lastOrderInfo;
1992
1937
  delete nextTempOrder.discount_list;
1938
+ delete nextTempOrder.shop_id;
1939
+ delete nextTempOrder.create_date;
1940
+ delete nextTempOrder.total_amount;
1941
+ delete nextTempOrder.expect_amount;
1942
+ delete nextTempOrder.paid_amount;
1943
+ delete nextTempOrder.shop_note;
1944
+ delete nextTempOrder.start_time;
1945
+ delete nextTempOrder.tax_fee;
1946
+ delete nextTempOrder.total_refund_amount;
1947
+ delete nextTempOrder.holder_id;
1993
1948
  nextTempOrder.metadata = raw.metadata && typeof raw.metadata === "object" ? { ...raw.metadata } : {};
1994
1949
  nextTempOrder.holder = raw.holder && typeof raw.holder === "object" ? { ...raw.holder } : null;
1995
1950
  nextTempOrder.products = Array.isArray(raw.products) ? raw.products.map((p) => this.normalizeHydratedOrderProduct(p)) : [];
@@ -500,10 +500,11 @@ export interface OrderModuleAPI {
500
500
  updateOrderProductQuantity: (params: UpdateOrderProductQuantityParams) => Promise<OrderProduct[]>;
501
501
  updateOrderBooking: (params: UpdateOrderBookingParams) => any[];
502
502
  removeProductFromOrder: (identity: OrderProductIdentity) => Promise<OrderProduct[]>;
503
+ /** @deprecated no-op;OrderModule 不再负责 tempOrder localStorage 持久化。 */
503
504
  persistTempOrder: () => void;
504
- /** 运行时切换 tempOrder localStorage 持久化开关。 */
505
+ /** @deprecated no-op;OrderModule 不再负责 tempOrder localStorage 持久化。 */
505
506
  setEnableTempOrderPersist: (enabled: boolean) => void;
506
- /** 当前是否启用 tempOrder localStorage 持久化。 */
507
+ /** @deprecated 固定返回 false;OrderModule 不再负责 tempOrder localStorage 持久化。 */
507
508
  isTempOrderPersistEnabled: () => boolean;
508
509
  submitTempOrder: <T = any>(params?: {
509
510
  cacheId?: string;
@@ -160,6 +160,22 @@ export declare function formatV1Product(products: OrderSubmitProduct[]): {
160
160
  session: null;
161
161
  unique: string;
162
162
  }[];
163
+ /**
164
+ * 判断 holder_id 是否已分配(非空)。
165
+ *
166
+ * @example
167
+ * hasAssignedHolderId(12); // true
168
+ * hasAssignedHolderId([]); // false
169
+ */
170
+ export declare function hasAssignedHolderId(value: unknown): boolean;
171
+ /**
172
+ * 清空 tempOrder 购物车行上的 holder 分配(products / bookings / runtime origin)。
173
+ * 移除或更换下单客户时调用,与 booking 页换客户清 holder 行为对齐。
174
+ *
175
+ * @example
176
+ * clearTempOrderHolderAssignments(tempOrder);
177
+ */
178
+ export declare function clearTempOrderHolderAssignments(tempOrder: OrderTempOrder): boolean;
163
179
  export { createEmptySummary } from '../../solution/ScanOrder/utils';
164
180
  export { buildManualProductDiscountItem, ensureManualProductDiscountList, findManualProductDiscountItem, mergeManualProductDiscountIntoList, resolveManualDiscountMessage, resolveManualDiscountOriginTotal, resolveManualDiscountReasonFromSources, resolveSafeProductNum, shouldBuildManualProductDiscount, syncManualProductDiscountProductNum, stripManualProductDiscountItems, } from './utils/manualProductDiscount';
165
181
  export type { ManualProductDiscountItem } from './utils/manualProductDiscount';