@pisell/pisellos 2.2.246 → 2.2.248

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.
@@ -76,6 +76,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
76
76
  this.giftSelectResolver = null;
77
77
  /** applyPromotion 递归保护 flag(写路径同步调 applyPromotion,禁止重入) */
78
78
  this.isApplyingPromotion = false;
79
+ /** 商品曾应用过客户券卡,客户变更剥离后需强制跑一次 calcDiscount 复位价格 */
80
+ this.hasActiveCustomerBoundDiscount = false;
79
81
  /** 最近一次 applyPromotion 的未满足促销提示 */
80
82
  this.lastUnfulfilledPromotions = [];
81
83
  /** 最近一次 applyPromotion 的赠品操作 diff(debug / SDK 读取使用) */
@@ -166,33 +168,53 @@ var OrderModule = class extends import_BaseModule.BaseModule {
166
168
  */
167
169
  static populateSavedAmounts(productList, discountList) {
168
170
  const savedMap = /* @__PURE__ */ new Map();
169
- const addDiscountAmount = (discount, quantity) => {
171
+ const editModeSavedMap = /* @__PURE__ */ new Map();
172
+ const runtimeSavedMap = /* @__PURE__ */ new Map();
173
+ const editModeDiscountKeys = new Set(
174
+ (discountList || []).filter((discount) => discount == null ? void 0 : discount.isEditMode).map((discount) => discount == null ? void 0 : discount.id).filter((id) => id !== void 0 && id !== null)
175
+ );
176
+ const addDiscountAmount = (targetMap, discountKey, amount) => {
177
+ targetMap.set(
178
+ discountKey,
179
+ (targetMap.get(discountKey) || new import_decimal.default(0)).plus(amount)
180
+ );
181
+ };
182
+ const addProductDiscountAmount = (discount, quantity, isPersistedProduct) => {
170
183
  var _a, _b;
171
184
  const discountKey = ((_a = discount.discount) == null ? void 0 : _a.resource_id) || discount.id;
172
185
  if (discountKey == null)
173
186
  return;
174
187
  const qty = Number(quantity) || 1;
175
188
  const amount = new import_decimal.default(discount.amount || 0).times(qty).plus(((_b = discount.metadata) == null ? void 0 : _b.product_discount_difference) || 0);
176
- savedMap.set(
189
+ addDiscountAmount(savedMap, discountKey, amount);
190
+ addDiscountAmount(
191
+ isPersistedProduct || discount.order_discount_id != null ? editModeSavedMap : runtimeSavedMap,
177
192
  discountKey,
178
- (savedMap.get(discountKey) || new import_decimal.default(0)).plus(amount)
193
+ amount
179
194
  );
180
195
  };
181
196
  for (const product of productList) {
182
197
  const qty = product.num || 1;
198
+ const isPersistedProduct = Boolean(
199
+ product.order_detail_id || product.orderDetailId || product.booking_id
200
+ );
183
201
  for (const pd of product.discount_list || []) {
184
- addDiscountAmount(pd, qty);
202
+ addProductDiscountAmount(pd, qty, isPersistedProduct);
185
203
  }
186
204
  for (const bundle of product.product_bundle || []) {
205
+ const isPersistedBundleProduct = isPersistedProduct || Boolean(
206
+ (bundle == null ? void 0 : bundle.order_detail_id) || (bundle == null ? void 0 : bundle.orderDetailId) || (bundle == null ? void 0 : bundle.booking_id)
207
+ );
187
208
  const bundleQty = new import_decimal.default(Number(qty) || 1).times(Number((bundle == null ? void 0 : bundle.num) ?? (bundle == null ? void 0 : bundle.quantity) ?? 1) || 1).toNumber();
188
209
  for (const pd of (bundle == null ? void 0 : bundle.discount_list) || []) {
189
- addDiscountAmount(pd, bundleQty);
210
+ addProductDiscountAmount(pd, bundleQty, isPersistedBundleProduct);
190
211
  }
191
212
  }
192
213
  }
193
214
  for (const d of discountList) {
194
215
  const key = d.id;
195
- d.savedAmount = d.isSelected && key != null && savedMap.has(key) ? savedMap.get(key).toNumber() : 0;
216
+ const sourceMap = d.isEditMode ? editModeSavedMap : editModeDiscountKeys.has(key) ? runtimeSavedMap : savedMap;
217
+ d.savedAmount = d.isSelected && key != null && sourceMap.has(key) ? sourceMap.get(key).toNumber() : 0;
196
218
  }
197
219
  }
198
220
  applyProductDiscountPrices(products) {
@@ -369,12 +391,16 @@ var OrderModule = class extends import_BaseModule.BaseModule {
369
391
  }));
370
392
  if (discountList) {
371
393
  const currentEditDiscounts = (((_c = this.store.discount) == null ? void 0 : _c.getDiscountList()) || []).filter((discount) => discount == null ? void 0 : discount.isEditMode);
372
- const currentEditDiscountIds = new Set(
373
- currentEditDiscounts.map((discount) => discount == null ? void 0 : discount.id)
374
- );
394
+ const runtimeDiscountIds = /* @__PURE__ */ new Set();
395
+ const runtimeDiscounts = discountList.filter((discount) => {
396
+ if (runtimeDiscountIds.has(discount == null ? void 0 : discount.id))
397
+ return false;
398
+ runtimeDiscountIds.add(discount == null ? void 0 : discount.id);
399
+ return true;
400
+ });
375
401
  const mergedDiscountList = [
376
402
  ...currentEditDiscounts,
377
- ...discountList.filter((discount) => !currentEditDiscountIds.has(discount == null ? void 0 : discount.id))
403
+ ...runtimeDiscounts
378
404
  ];
379
405
  await ((_d = this.store.discount) == null ? void 0 : _d.setOriginalDiscountList(mergedDiscountList));
380
406
  await ((_e = this.store.discount) == null ? void 0 : _e.setDiscountList(mergedDiscountList));
@@ -471,6 +497,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
471
497
  if (!tempOrder)
472
498
  return;
473
499
  delete tempOrder.discount_list;
500
+ if (this.shouldSkipDiscountCalculation(tempOrder))
501
+ return;
474
502
  const rulesModule = this.store.rules;
475
503
  if (!rulesModule)
476
504
  return;
@@ -512,6 +540,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
512
540
  );
513
541
  (_e = this.store.discount) == null ? void 0 : _e.setDiscountList(result.discountList);
514
542
  }
543
+ this.hasActiveCustomerBoundDiscount = (tempOrder.products || []).some(
544
+ (product) => this.productHasCustomerBoundDiscount(product)
545
+ );
515
546
  }
516
547
  // ─── 促销/赠品 ──────────────────────────────────────
517
548
  /**
@@ -556,7 +587,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
556
587
  * - 不主动调用 applyDiscount / recalculateSummary,调用方负责跟进。
557
588
  */
558
589
  async applyPromotion() {
559
- var _a;
590
+ var _a, _b, _c;
560
591
  if (this.isApplyingPromotion) {
561
592
  return;
562
593
  }
@@ -567,6 +598,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
567
598
  if (!tempOrder) {
568
599
  return;
569
600
  }
601
+ const strategyConfigs = (_b = (_a = this.promotionEvaluator).getStrategyConfigs) == null ? void 0 : _b.call(_a);
602
+ if (Array.isArray(strategyConfigs) && strategyConfigs.length === 0) {
603
+ return;
604
+ }
570
605
  this.isApplyingPromotion = true;
571
606
  try {
572
607
  const result = (0, import_cartPromotion.processCartPromotion)(
@@ -608,11 +643,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
608
643
  if (addAction.giftOptions.length === 1) {
609
644
  const sameStrategy = result.products.find(
610
645
  (p) => {
611
- var _a2, _b;
612
- return ((_b = (_a2 = p.metadata) == null ? void 0 : _a2._giftInfo) == null ? void 0 : _b.strategyId) === addAction.strategyId;
646
+ var _a2, _b2;
647
+ return ((_b2 = (_a2 = p.metadata) == null ? void 0 : _a2._giftInfo) == null ? void 0 : _b2.strategyId) === addAction.strategyId;
613
648
  }
614
649
  );
615
- if (sameStrategy && !sameStrategy.booking_uid && !((_a = sameStrategy.metadata) == null ? void 0 : _a.booking_uid)) {
650
+ if (sameStrategy && !sameStrategy.booking_uid && !((_c = sameStrategy.metadata) == null ? void 0 : _c.booking_uid)) {
616
651
  sameStrategy.num = (Number(sameStrategy.num) || 0) + (addAction.giftCount || 1);
617
652
  continue;
618
653
  }
@@ -1977,12 +2012,37 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1977
2012
  const type = (discount == null ? void 0 : discount.type) ?? (discount == null ? void 0 : discount.tag);
1978
2013
  return type === "good_pass" || type === "discount_card" || type === "product_discount_card";
1979
2014
  }
2015
+ productHasCustomerBoundDiscount(product) {
2016
+ if (((product == null ? void 0 : product.discount_list) || []).some((discount) => this.isCustomerBoundDiscount(discount))) {
2017
+ return true;
2018
+ }
2019
+ return ((product == null ? void 0 : product.product_bundle) || []).some(
2020
+ (bundle) => ((bundle == null ? void 0 : bundle.discount_list) || []).some((discount) => this.isCustomerBoundDiscount(discount))
2021
+ );
2022
+ }
2023
+ shouldSkipDiscountCalculation(tempOrder) {
2024
+ var _a, _b;
2025
+ if (this.hasActiveCustomerBoundDiscount)
2026
+ return false;
2027
+ const discountList = ((_b = (_a = this.store.discount) == null ? void 0 : _a.getDiscountList) == null ? void 0 : _b.call(_a)) || [];
2028
+ if (discountList.length > 0)
2029
+ return false;
2030
+ return !(tempOrder.products || []).some(
2031
+ (product) => this.productHasCustomerBoundDiscount(product)
2032
+ );
2033
+ }
1980
2034
  clearCustomerBoundDiscounts(tempOrder) {
1981
2035
  var _a, _b, _c, _d;
2036
+ let didRemoveCustomerBoundDiscount = false;
1982
2037
  const filterDiscountList = (discountList) => {
1983
2038
  if (!Array.isArray(discountList))
1984
2039
  return [];
1985
- return discountList.filter((discount) => !this.isCustomerBoundDiscount(discount));
2040
+ return discountList.filter((discount) => {
2041
+ const shouldRemove = this.isCustomerBoundDiscount(discount);
2042
+ if (shouldRemove)
2043
+ didRemoveCustomerBoundDiscount = true;
2044
+ return !shouldRemove;
2045
+ });
1986
2046
  };
1987
2047
  tempOrder.products = (tempOrder.products || []).map((product) => {
1988
2048
  const nextProduct = {
@@ -1998,6 +2058,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1998
2058
  return nextProduct;
1999
2059
  });
2000
2060
  delete tempOrder.discount_list;
2061
+ if (didRemoveCustomerBoundDiscount) {
2062
+ this.hasActiveCustomerBoundDiscount = true;
2063
+ }
2001
2064
  const discountModule = this.store.discount;
2002
2065
  if (!discountModule)
2003
2066
  return;
@@ -3631,12 +3694,59 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3631
3694
  };
3632
3695
  }
3633
3696
  tempOrderExtend.productsByUid = productsByUid;
3697
+ this.hydrateLinkedBookingIdentity(nextTempOrder);
3634
3698
  if ((options == null ? void 0 : options.ensureIdentity) !== false) {
3635
3699
  this.ensureExternalSaleNumber(nextTempOrder);
3636
3700
  }
3637
3701
  nextTempOrder.vouchers = raw.vouchers || [];
3638
3702
  return nextTempOrder;
3639
3703
  }
3704
+ hydrateLinkedBookingIdentity(tempOrder) {
3705
+ const bookingUidByProductUid = /* @__PURE__ */ new Map();
3706
+ const productByUid = /* @__PURE__ */ new Map();
3707
+ (tempOrder.products || []).forEach((product) => {
3708
+ var _a;
3709
+ const productUid = ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.unique_identification_number) || (product == null ? void 0 : product.unique_identification_number);
3710
+ if (productUid !== void 0 && productUid !== null && String(productUid) !== "") {
3711
+ productByUid.set(String(productUid), product);
3712
+ }
3713
+ });
3714
+ (tempOrder.bookings || []).forEach((booking) => {
3715
+ var _a;
3716
+ if (!booking || typeof booking !== "object")
3717
+ return;
3718
+ if (!booking.metadata || typeof booking.metadata !== "object") {
3719
+ booking.metadata = {};
3720
+ }
3721
+ const productUid = booking.product_uid || booking.metadata.product_uid;
3722
+ if (productUid === void 0 || productUid === null || String(productUid) === "")
3723
+ return;
3724
+ const matchedProduct = productByUid.get(String(productUid));
3725
+ const existedProductBookingUid = (matchedProduct == null ? void 0 : matchedProduct.booking_uid) || ((_a = matchedProduct == null ? void 0 : matchedProduct.metadata) == null ? void 0 : _a.booking_uid);
3726
+ const bookingUid = String(
3727
+ booking.metadata.unique_identification_number || existedProductBookingUid || (0, import_utils.createUuidV4)()
3728
+ );
3729
+ booking.metadata.unique_identification_number = bookingUid;
3730
+ bookingUidByProductUid.set(String(productUid), bookingUid);
3731
+ });
3732
+ (tempOrder.products || []).forEach((product) => {
3733
+ var _a;
3734
+ const productUid = ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.unique_identification_number) || (product == null ? void 0 : product.unique_identification_number);
3735
+ if (productUid === void 0 || productUid === null || String(productUid) === "")
3736
+ return;
3737
+ const bookingUid = bookingUidByProductUid.get(String(productUid));
3738
+ if (!bookingUid)
3739
+ return;
3740
+ if (!product.metadata || typeof product.metadata !== "object") {
3741
+ product.metadata = {};
3742
+ }
3743
+ const linkedBookingUid = String(
3744
+ product.booking_uid || product.metadata.booking_uid || bookingUid
3745
+ );
3746
+ product.booking_uid = linkedBookingUid;
3747
+ product.metadata.booking_uid = linkedBookingUid;
3748
+ });
3749
+ }
3640
3750
  pickHydratedDisplayText(value) {
3641
3751
  if (value === void 0 || value === null)
3642
3752
  return "";
@@ -34,6 +34,7 @@ export interface OrderPromotionEvaluator {
34
34
  products: any[];
35
35
  channel?: string;
36
36
  }, matchVariant?: boolean): any[];
37
+ getStrategyConfigs?: () => unknown[];
37
38
  }
38
39
  /** 赠品解析回调 context(OS → SDK 的请求体) */
39
40
  export interface OrderGiftSelectContext {
@@ -214,7 +214,7 @@ var WalletPassPaymentImpl = class {
214
214
  };
215
215
  const [allList, orderBasicDetail] = await Promise.all([
216
216
  this.getUserIdentificationCodeListAsync(identificationParams),
217
- baseParams.payment_order_id ? this.getOrderBasicDetailAsync(baseParams.payment_order_id) : Promise.resolve(null)
217
+ baseParams.payment_order_id && typeof baseParams.payment_order_id === "string" && !baseParams.payment_order_id.startsWith("LOCAL_") ? this.getOrderBasicDetailAsync(baseParams.payment_order_id) : Promise.resolve(null)
218
218
  ]);
219
219
  const walletPassEvaluator = (_b = (_a = this.paymentModule.window) == null ? void 0 : _a.getWalletPassEvaluator) == null ? void 0 : _b.call(_a);
220
220
  if (!walletPassEvaluator) {
@@ -35,6 +35,7 @@ export interface SmallTicketProduct {
35
35
  original_price: string;
36
36
  total_original_price: string;
37
37
  extension_list: any[];
38
+ discount_list?: any[];
38
39
  options?: Array<{
39
40
  name: string;
40
41
  num?: number;
@@ -57,8 +57,11 @@ var LABELS = {
57
57
  remainingPoints: "Remaining points",
58
58
  table: "Table",
59
59
  orderDiscount: "Order discount",
60
+ manualDiscount: "Manual discount",
60
61
  payProcessingFee: "Pay processing fee",
61
- rounding: "Rounding"
62
+ rounding: "Rounding",
63
+ gross: "Gross",
64
+ tare: "Tare"
62
65
  },
63
66
  zh_CN: {
64
67
  contactName: "联系人姓名",
@@ -80,8 +83,11 @@ var LABELS = {
80
83
  remainingPoints: "剩余积分",
81
84
  table: "桌台",
82
85
  orderDiscount: "整单折扣",
86
+ manualDiscount: "手动折扣",
83
87
  payProcessingFee: "支付手续费",
84
- rounding: "抹零"
88
+ rounding: "抹零",
89
+ gross: "重量",
90
+ tare: "去皮"
85
91
  },
86
92
  zh_HK: {
87
93
  contactName: "聯絡人姓名",
@@ -103,8 +109,11 @@ var LABELS = {
103
109
  remainingPoints: "剩餘積分",
104
110
  table: "桌台",
105
111
  orderDiscount: "整單折扣",
112
+ manualDiscount: "手動折扣",
106
113
  payProcessingFee: "支付手續費",
107
- rounding: "抹零"
114
+ rounding: "抹零",
115
+ gross: "重量",
116
+ tare: "去皮"
108
117
  }
109
118
  };
110
119
  function buildSmallTicketData(params) {
@@ -184,19 +193,112 @@ function buildProducts(order, locale, productMap) {
184
193
  parentProduct
185
194
  });
186
195
  const resolvedVariant = resolveProductVariantText({ product, parentProduct, locale });
196
+ const extensionList = buildProductExtensionList({
197
+ product,
198
+ locale,
199
+ currencySymbol,
200
+ quantity,
201
+ originalPrice
202
+ });
203
+ const discountList = normalizeProductDiscounts({ product, locale, currencySymbol, quantity });
187
204
  return {
188
205
  product_title: productTitle,
189
206
  product_quantity: quantity,
190
207
  selling_price: formatMoney(sellingPrice, currencySymbol),
191
208
  original_price: formatMoney(originalPrice, currencySymbol),
192
209
  total_original_price: formatMoney(new import_decimal.default(toMoneyNumber(originalPrice)).mul(quantity), currencySymbol),
193
- extension_list: Array.isArray(product.extension_list) ? product.extension_list : [],
210
+ extension_list: extensionList,
211
+ ...discountList.length ? { discount_list: discountList } : {},
194
212
  ...options.length ? { options } : {},
195
213
  ...resolvedVariant ? { variant: resolvedVariant } : {},
196
214
  ...Array.isArray(product.combinations) ? { combinations: product.combinations } : combinations.length ? { combinations } : {}
197
215
  };
198
216
  });
199
217
  }
218
+ function normalizeProductDiscounts(params) {
219
+ const { product, locale, currencySymbol, quantity } = params;
220
+ return normalizeArray(product.discount_list).map((discount) => {
221
+ const title = resolveDiscountTitleWithPercent(discount, locale);
222
+ const amount = discount.amount ?? discount.value ?? discount.discount_amount;
223
+ const formattedAmount = formatNegativeMoney(new import_decimal.default(toMoneyNumber(amount)).mul(quantity), currencySymbol);
224
+ return {
225
+ ...discount,
226
+ item: title,
227
+ name: title,
228
+ title,
229
+ value: formattedAmount
230
+ };
231
+ });
232
+ }
233
+ function buildProductExtensionList(params) {
234
+ const { product, locale, currencySymbol, quantity, originalPrice } = params;
235
+ const extensionList = [
236
+ ...buildProductOpenWeightRows({ product, locale, currencySymbol }),
237
+ ...quantity > 1 ? [{
238
+ item: buildProductQuantityPriceText({ quantity, currencySymbol, price: originalPrice }),
239
+ value: ""
240
+ }] : []
241
+ ];
242
+ return extensionList.length ? extensionList : normalizeArray(product.extension_list);
243
+ }
244
+ function buildProductOpenWeightRows(params) {
245
+ const { product, locale, currencySymbol } = params;
246
+ const productSku = product.product_sku || {};
247
+ if (productSku.open_sold_weight != 1)
248
+ return [];
249
+ const unit = productSku.unit ?? "";
250
+ const manualFlag = productSku.weight_source === "manual" ? "(M) " : "";
251
+ const hasTare = toNumber(productSku.tare_weight, 0) > 0;
252
+ const rows = [];
253
+ if (hasTare) {
254
+ rows.push({
255
+ item: `${manualFlag}${label(locale, "gross")}: ${productSku.weight ?? 0}${unit}`,
256
+ value: ""
257
+ });
258
+ rows.push({
259
+ item: `${label(locale, "tare")}: ${productSku.tare_weight}${unit}`,
260
+ value: ""
261
+ });
262
+ }
263
+ const netWeight = productSku.net_weight ?? 0;
264
+ const unitPrice = productSku.unit_price ?? 0;
265
+ const netItem = `${netWeight} ${unit} NET @ ${currencySymbol}${unitPrice}/${unit}`;
266
+ rows.push({
267
+ item: hasTare ? netItem : `${manualFlag}${netItem}`,
268
+ value: ""
269
+ });
270
+ return rows;
271
+ }
272
+ function buildProductQuantityPriceText(params) {
273
+ const { quantity, currencySymbol, price } = params;
274
+ return `${quantity} @ ${currencySymbol}${stringify(price)} EACH`;
275
+ }
276
+ function resolveDiscountTitleWithPercent(discount, locale) {
277
+ var _a, _b;
278
+ const title = resolveDiscountTitle(discount, locale);
279
+ const percentRaw = (_a = discount.discount) == null ? void 0 : _a.percent;
280
+ const cardType = ((_b = discount.discount) == null ? void 0 : _b.discount_card_type) ?? "percent";
281
+ const percent = percentRaw !== void 0 && percentRaw !== null ? Math.trunc(Number(percentRaw)) : NaN;
282
+ if (percentRaw === void 0 || percentRaw === null)
283
+ return title;
284
+ if (cardType !== "percent")
285
+ return title;
286
+ if (Number.isNaN(percent))
287
+ return title;
288
+ return `${title} (${percent}%)`;
289
+ }
290
+ function resolveDiscountTitle(discount, locale) {
291
+ var _a, _b, _c;
292
+ const title = getLocalizedValue(
293
+ ((_a = discount.discount) == null ? void 0 : _a.name) ?? ((_b = discount.discount) == null ? void 0 : _b.title) ?? ((_c = discount.discount) == null ? void 0 : _c.message) ?? discount.name ?? discount.title ?? discount.message,
294
+ locale
295
+ );
296
+ if (title)
297
+ return title;
298
+ if (discount.type === "product")
299
+ return label(locale, "manualDiscount");
300
+ return "";
301
+ }
200
302
  function resolveProductTitle(params) {
201
303
  const { product, productMap, locale } = params;
202
304
  const ownTitle = getProductTitleSource(product, locale);
@@ -480,11 +582,11 @@ function buildFees(params) {
480
582
  value: formatMoney(value, currencySymbol)
481
583
  });
482
584
  }
483
- const discountAmount = summary.discount_amount || order.discount_amount || order.shop_discount;
585
+ const discountAmount = order.shop_discount ?? summary.discount_amount ?? order.discount_amount;
484
586
  if (isNonZero(discountAmount)) {
485
587
  fees.push({
486
588
  item: label(locale, "orderDiscount"),
487
- value: formatMoney(new import_decimal.default(toMoneyNumber(discountAmount)).neg(), currencySymbol)
589
+ value: formatNegativeMoney(discountAmount, currencySymbol)
488
590
  });
489
591
  }
490
592
  const taxFee = summary.tax_fee || order.tax_fee;
@@ -508,14 +610,14 @@ function buildFees(params) {
508
610
  value: formatMoney(payProcessingFee, currencySymbol)
509
611
  });
510
612
  }
613
+ const productExpectAmount = summary.product_expect_amount || summary.product_amount || order.product_expect_amount;
614
+ const productOriginalAmount = summary.product_original_amount ?? order.product_original_amount ?? productExpectAmount;
615
+ const totalSavingsAmount = new import_decimal.default(toMoneyNumber(productOriginalAmount)).minus(toMoneyNumber(productExpectAmount)).plus(toMoneyNumber(discountAmount));
511
616
  return {
512
617
  fees,
513
618
  countFee: {
514
619
  total_amount: formatMoney(summary.total_amount || order.total_amount, currencySymbol),
515
- product_expect_amount: formatMoney(
516
- summary.product_expect_amount || summary.product_amount || order.product_expect_amount,
517
- currencySymbol
518
- ),
620
+ product_expect_amount: formatMoney(productExpectAmount, currencySymbol),
519
621
  expect_amount: formatMoney(summary.expect_amount || order.expect_amount || summary.total_amount || order.total_amount, currencySymbol),
520
622
  product_quantity: toNumber(
521
623
  summary.product_quantity || products.reduce((sum, product) => sum + product.product_quantity, 0),
@@ -526,7 +628,7 @@ function buildFees(params) {
526
628
  tax_title: stringify(summary.tax_title || order.tax_title || shopInfo.tax_title),
527
629
  total_refund_amount: formatMoney(summary.total_refund_amount || order.total_refund_amount, currencySymbol),
528
630
  ...isNonZero(roundingAmount) ? { rounding_amount: formatMoney(roundingAmount, currencySymbol) } : {},
529
- ...isNonZero(discountAmount) ? { order_total_discount: formatMoney(discountAmount, currencySymbol) } : {},
631
+ ...isNonZero(totalSavingsAmount) ? { order_total_discount: formatMoney(totalSavingsAmount, currencySymbol) } : {},
530
632
  ...isNonZero(payProcessingFee) ? { pay_processing_fee: formatMoney(payProcessingFee, currencySymbol) } : {},
531
633
  ...isNonZero(taxFee) ? { tax_fee: formatMoney(taxFee, currencySymbol) } : {}
532
634
  }
@@ -712,8 +814,9 @@ function getLocalizedValue(value, locale) {
712
814
  if (typeof value !== "object")
713
815
  return stringify(value);
714
816
  const dashedLocale = locale.replace("_", "-");
817
+ const underscoredLocale = locale.replace("-", "_");
715
818
  return stringify(
716
- value[locale] ?? value[dashedLocale] ?? value.default ?? value.en ?? ""
819
+ value[locale] ?? value[dashedLocale] ?? value[underscoredLocale] ?? value.original ?? value.auto ?? value.default ?? value.en ?? ""
717
820
  );
718
821
  }
719
822
  function buildShopAddress(shopInfo) {
@@ -742,6 +845,10 @@ function formatMoney(value, currencySymbol) {
742
845
  const amount = new import_decimal.default(toMoneyNumber(value));
743
846
  return `${currencySymbol}${amount.toFixed(2)}`;
744
847
  }
848
+ function formatNegativeMoney(value, currencySymbol) {
849
+ const amount = new import_decimal.default(toMoneyNumber(value)).abs();
850
+ return `-${currencySymbol}${amount.toFixed(2)}`;
851
+ }
745
852
  function calculateReceiptPaidAmount(order, summary) {
746
853
  const paidAmount = sumPayments(order.payments);
747
854
  const payProcessingFee = new import_decimal.default(
@@ -70,6 +70,11 @@ function preserveManualProductDiscountProducts(previousProducts, nextProducts) {
70
70
  return previous && isBaseSalesManualProductDiscountProduct(previous) ? previous : product;
71
71
  });
72
72
  }
73
+ function isBaseSalesHistoricalDiscountEntry(discount) {
74
+ return Boolean(
75
+ (discount == null ? void 0 : discount.isEditMode) || (discount == null ? void 0 : discount.isDisabled) || (discount == null ? void 0 : discount.order_discount_id) != null
76
+ );
77
+ }
73
78
  function getBaseSalesUniqueArrayMetadataKey(key) {
74
79
  if (key === "products" || key === "bookings")
75
80
  return "unique_identification_number";
@@ -883,7 +888,11 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
883
888
  const historyIds = new Set(historyDiscountList.map((discount) => discount.id));
884
889
  return [
885
890
  ...historyDiscountList,
886
- ...(discountList || []).filter((discount) => !historyIds.has(discount.id))
891
+ ...(discountList || []).filter((discount) => {
892
+ if (!historyIds.has(discount.id))
893
+ return true;
894
+ return !isBaseSalesHistoricalDiscountEntry(discount);
895
+ })
887
896
  ];
888
897
  }
889
898
  shouldSkipAutoApplyFetchedDiscountsInEditMode(params) {
@@ -906,11 +915,17 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
906
915
  mergeCurrentDiscountSelectionState(discountList, currentDiscountList) {
907
916
  if (!currentDiscountList.length)
908
917
  return discountList;
909
- const currentDiscountMap = new Map(
910
- currentDiscountList.map((discount) => [discount.id, discount])
911
- );
918
+ const currentDiscountMap = /* @__PURE__ */ new Map();
919
+ currentDiscountList.forEach((discount) => {
920
+ currentDiscountMap.set(
921
+ `${discount.id}:${isBaseSalesHistoricalDiscountEntry(discount) ? "historical" : "runtime"}`,
922
+ discount
923
+ );
924
+ });
912
925
  return discountList.map((discount) => {
913
- const currentDiscount = currentDiscountMap.get(discount.id);
926
+ const currentDiscount = currentDiscountMap.get(
927
+ `${discount.id}:${isBaseSalesHistoricalDiscountEntry(discount) ? "historical" : "runtime"}`
928
+ );
914
929
  if (!currentDiscount)
915
930
  return discount;
916
931
  if (currentDiscount.isManualSelect) {
@@ -1145,7 +1160,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1145
1160
  throw new Error("order 模块未初始化");
1146
1161
  const list = this.store.order.getDiscountList();
1147
1162
  const updated = list.map(
1148
- (d) => d.id === params.discountId ? {
1163
+ (d) => d.id === params.discountId && !isBaseSalesHistoricalDiscountEntry(d) ? {
1149
1164
  ...d,
1150
1165
  isSelected: params.isSelected,
1151
1166
  isManualSelect: !params.isSelected
@@ -322,7 +322,7 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
322
322
  * 获取当前的客户搜索条件
323
323
  * @returns 当前搜索条件
324
324
  */
325
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
325
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
326
326
  /**
327
327
  * 获取客户列表状态(包含滚动加载相关状态)
328
328
  * @returns 客户状态
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.2.246",
4
+ "version": "2.2.248",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",