@pisell/pisellos 2.1.60 → 2.1.62

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 (99) hide show
  1. package/dist/index.d.ts +0 -1
  2. package/dist/index.js +0 -1
  3. package/dist/modules/Cart/types.d.ts +0 -2
  4. package/dist/modules/Cart/utils/cartProduct.js +0 -11
  5. package/dist/modules/Customer/index.js +1 -1
  6. package/dist/modules/Discount/types.d.ts +0 -15
  7. package/dist/modules/Payment/index.d.ts +1 -2
  8. package/dist/modules/Payment/index.js +7 -10
  9. package/dist/modules/Payment/utils.js +0 -3
  10. package/dist/modules/Payment/walletpass.d.ts +0 -23
  11. package/dist/modules/Payment/walletpass.js +95 -191
  12. package/dist/modules/Rules/index.d.ts +3 -8
  13. package/dist/modules/Rules/index.js +36 -164
  14. package/dist/modules/Rules/types.d.ts +0 -1
  15. package/dist/modules/Summary/types.d.ts +0 -2
  16. package/dist/modules/Summary/utils.d.ts +0 -6
  17. package/dist/modules/Summary/utils.js +0 -21
  18. package/dist/plugins/window.d.ts +0 -2
  19. package/dist/solution/BookingByStep/index.d.ts +0 -1
  20. package/dist/solution/BookingTicket/index.d.ts +1 -1
  21. package/dist/solution/Checkout/index.js +0 -2
  22. package/dist/solution/ShopDiscount/index.d.ts +0 -1
  23. package/dist/solution/ShopDiscount/index.js +1 -11
  24. package/dist/solution/ShopDiscount/types.d.ts +0 -1
  25. package/dist/solution/ShopDiscount/utils.js +11 -26
  26. package/lib/index.d.ts +0 -1
  27. package/lib/index.js +1 -3
  28. package/lib/modules/Cart/types.d.ts +0 -2
  29. package/lib/modules/Cart/utils/cartProduct.js +0 -9
  30. package/lib/modules/Customer/index.js +1 -1
  31. package/lib/modules/Discount/types.d.ts +0 -15
  32. package/lib/modules/Payment/index.d.ts +1 -2
  33. package/lib/modules/Payment/index.js +0 -1
  34. package/lib/modules/Payment/utils.js +0 -3
  35. package/lib/modules/Payment/walletpass.d.ts +0 -23
  36. package/lib/modules/Payment/walletpass.js +17 -94
  37. package/lib/modules/Rules/index.d.ts +3 -8
  38. package/lib/modules/Rules/index.js +197 -375
  39. package/lib/modules/Rules/types.d.ts +0 -1
  40. package/lib/modules/Summary/types.d.ts +0 -2
  41. package/lib/modules/Summary/utils.d.ts +0 -6
  42. package/lib/modules/Summary/utils.js +0 -15
  43. package/lib/plugins/window.d.ts +0 -2
  44. package/lib/solution/BookingByStep/index.d.ts +0 -1
  45. package/lib/solution/BookingTicket/index.d.ts +1 -1
  46. package/lib/solution/Checkout/index.js +0 -2
  47. package/lib/solution/ShopDiscount/index.d.ts +0 -1
  48. package/lib/solution/ShopDiscount/index.js +0 -6
  49. package/lib/solution/ShopDiscount/types.d.ts +0 -1
  50. package/lib/solution/ShopDiscount/utils.js +6 -10
  51. package/package.json +1 -1
  52. package/dist/model/index.d.ts +0 -1
  53. package/dist/model/index.js +0 -1
  54. package/dist/model/strategy/adapter/index.d.ts +0 -3
  55. package/dist/model/strategy/adapter/index.js +0 -4
  56. package/dist/model/strategy/adapter/type.d.ts +0 -28
  57. package/dist/model/strategy/adapter/type.js +0 -1
  58. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +0 -84
  59. package/dist/model/strategy/adapter/walletPass/evaluator.js +0 -496
  60. package/dist/model/strategy/adapter/walletPass/example.d.ts +0 -4
  61. package/dist/model/strategy/adapter/walletPass/example.js +0 -258
  62. package/dist/model/strategy/adapter/walletPass/index.d.ts +0 -32
  63. package/dist/model/strategy/adapter/walletPass/index.js +0 -182
  64. package/dist/model/strategy/adapter/walletPass/locales.d.ts +0 -1
  65. package/dist/model/strategy/adapter/walletPass/locales.js +0 -23
  66. package/dist/model/strategy/adapter/walletPass/type.d.ts +0 -163
  67. package/dist/model/strategy/adapter/walletPass/type.js +0 -1
  68. package/dist/model/strategy/adapter/walletPass/utils.d.ts +0 -50
  69. package/dist/model/strategy/adapter/walletPass/utils.js +0 -965
  70. package/dist/model/strategy/index.d.ts +0 -94
  71. package/dist/model/strategy/index.js +0 -551
  72. package/dist/model/strategy/strategy-example.d.ts +0 -5
  73. package/dist/model/strategy/strategy-example.js +0 -331
  74. package/dist/model/strategy/type.d.ts +0 -228
  75. package/dist/model/strategy/type.js +0 -94
  76. package/lib/model/index.d.ts +0 -1
  77. package/lib/model/index.js +0 -23
  78. package/lib/model/strategy/adapter/index.d.ts +0 -3
  79. package/lib/model/strategy/adapter/index.js +0 -45
  80. package/lib/model/strategy/adapter/type.d.ts +0 -28
  81. package/lib/model/strategy/adapter/type.js +0 -17
  82. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +0 -84
  83. package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -420
  84. package/lib/model/strategy/adapter/walletPass/example.d.ts +0 -4
  85. package/lib/model/strategy/adapter/walletPass/example.js +0 -207
  86. package/lib/model/strategy/adapter/walletPass/index.d.ts +0 -32
  87. package/lib/model/strategy/adapter/walletPass/index.js +0 -142
  88. package/lib/model/strategy/adapter/walletPass/locales.d.ts +0 -1
  89. package/lib/model/strategy/adapter/walletPass/locales.js +0 -51
  90. package/lib/model/strategy/adapter/walletPass/type.d.ts +0 -163
  91. package/lib/model/strategy/adapter/walletPass/type.js +0 -17
  92. package/lib/model/strategy/adapter/walletPass/utils.d.ts +0 -50
  93. package/lib/model/strategy/adapter/walletPass/utils.js +0 -660
  94. package/lib/model/strategy/index.d.ts +0 -94
  95. package/lib/model/strategy/index.js +0 -413
  96. package/lib/model/strategy/strategy-example.d.ts +0 -5
  97. package/lib/model/strategy/strategy-example.js +0 -318
  98. package/lib/model/strategy/type.d.ts +0 -228
  99. package/lib/model/strategy/type.js +0 -44
@@ -49,7 +49,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
49
49
  this.core = core;
50
50
  this.hooks = options == null ? void 0 : options.hooks;
51
51
  this.store = options == null ? void 0 : options.store;
52
- this.window = core.getPlugin("window");
53
52
  }
54
53
  async setRulesList(rulesList) {
55
54
  this.store.rulesList = rulesList;
@@ -58,10 +57,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
58
57
  getRulesList() {
59
58
  return this.store.rulesList;
60
59
  }
61
- getWalletPassEvaluator() {
62
- var _a, _b;
63
- return (_b = (_a = this.window).getWalletPassEvaluator) == null ? void 0 : _b.call(_a);
64
- }
65
60
  // 商品不需要holder,则不需要判断,直接返回true,商品需要holder但是还没填写,那么暂时不使用带有holder的券,直到填写才去匹配
66
61
  checkHolderMatch(discount, product, holders) {
67
62
  var _a;
@@ -81,7 +76,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
81
76
  newDiscountList,
82
77
  productList,
83
78
  holders,
84
- orderTotalAmount,
85
79
  isFormSubject
86
80
  }) {
87
81
  if (!newDiscountList || newDiscountList.length === 0) {
@@ -102,18 +96,15 @@ var RulesModule = class extends import_BaseModule.BaseModule {
102
96
  productList
103
97
  };
104
98
  }
105
- const filteredOldDiscountList = oldDiscountList.filter(
106
- (discount) => !discount.isEditMode && discount.tag !== "good_pass"
107
- );
108
- const mergedDiscountList = (0, import_utils.uniqueById)(
109
- (0, import_utils.uniqueById)([...filteredOldDiscountList, ...newDiscountList]),
110
- "product_id"
111
- );
99
+ const filteredOldDiscountList = oldDiscountList.filter((discount) => !discount.isEditMode && discount.tag !== "good_pass");
100
+ const mergedDiscountList = (0, import_utils.uniqueById)((0, import_utils.uniqueById)([
101
+ ...filteredOldDiscountList,
102
+ ...newDiscountList
103
+ ]), "product_id");
112
104
  const result = this.calcDiscount({
113
105
  discountList: mergedDiscountList,
114
106
  productList: [...productList],
115
107
  holders,
116
- orderTotalAmount,
117
108
  isFormSubject
118
109
  }, {
119
110
  scan: true
@@ -148,7 +139,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
148
139
  discountList,
149
140
  productList,
150
141
  holders,
151
- orderTotalAmount,
152
142
  isFormSubject
153
143
  }, options) {
154
144
  const isEditModeAddNewProduct = productList.find((n) => n.booking_id) && productList.find((n) => !n.booking_id);
@@ -251,8 +241,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
251
241
  const flattenedList = flattenProductsWithBundle(productList);
252
242
  const sortedFlattenedList = flattenedList.sort((a, b) => {
253
243
  var _a, _b;
254
- const priceA = new import_decimal.default(a.price || "0");
255
- const priceB = new import_decimal.default(b.price || "0");
244
+ const priceA = new import_decimal.default(
245
+ a.type === "bundle" ? a.original_price ?? a.price ?? "0" : a.price || "0"
246
+ );
247
+ const priceB = new import_decimal.default(
248
+ b.type === "bundle" ? b.original_price ?? b.price ?? "0" : b.price || "0"
249
+ );
256
250
  if (priceA.equals(priceB)) {
257
251
  if (a.type !== b.type) {
258
252
  return a.type === "main" ? -1 : 1;
@@ -269,50 +263,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
269
263
  }
270
264
  return priceB.minus(priceA).toNumber();
271
265
  });
272
- const evaluator = this.getWalletPassEvaluator();
273
- if (evaluator) {
274
- addModeDiscount.forEach((discount) => {
275
- var _a, _b;
276
- const discountType = discount.tag || discount.type;
277
- if (["good_pass", "discount_card", "product_discount_card"].includes(
278
- discountType
279
- )) {
280
- const voucher = {
281
- id: discount.id,
282
- amount: Number(discount.par_value || 0),
283
- balance: Number(discount.balance || 0),
284
- type: discountType,
285
- product_id: discount.product_id,
286
- unified_available_status: 1,
287
- available_product_type: (_a = discount.limited_relation_product_data) == null ? void 0 : _a.type,
288
- available_product_ids: (_b = discount.limited_relation_product_data) == null ? void 0 : _b.product_ids
289
- };
290
- const productsForEvaluate = sortedFlattenedList.map((item) => ({
291
- product_id: item.id,
292
- price: item.price || 0,
293
- quantity: item.quantity || item.num || 1,
294
- selling_price: item.price || 0
295
- }));
296
- const result = evaluator.checkVoucherAvailability({
297
- orderTotalAmount,
298
- products: productsForEvaluate,
299
- vouchers: [voucher]
300
- });
301
- if (result.isAvailable) {
302
- discount.config = {
303
- ...result.config,
304
- isAvailable: true
305
- };
306
- } else {
307
- discount.config = {
308
- isAvailable: false
309
- };
310
- }
311
- }
312
- });
313
- }
314
266
  const usedDiscounts = /* @__PURE__ */ new Map();
315
- const usedProductIdCounts = /* @__PURE__ */ new Map();
316
267
  const discountApplicability = /* @__PURE__ */ new Map();
317
268
  const discountApplicableProducts = /* @__PURE__ */ new Map();
318
269
  addModeDiscount.forEach((discount) => {
@@ -341,7 +292,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
341
292
  originProduct = flatItem.originProduct;
342
293
  }
343
294
  addModeDiscount.forEach((discount) => {
344
- var _a, _b, _c, _d, _e, _f, _g;
295
+ var _a, _b, _c, _d, _e, _f;
345
296
  const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
346
297
  const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
347
298
  const isHolderMatch = this.checkHolderMatch(
@@ -354,17 +305,11 @@ var RulesModule = class extends import_BaseModule.BaseModule {
354
305
  );
355
306
  let timeLimit = true;
356
307
  timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], ((product == null ? void 0 : product.startDate) || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
357
- const isLimitedProduct = (limitedData.type === "product_all" && limitedData.filter !== 1 || limitedData.type === "product_all" && limitedData.filter === 1 && !limitedData.exclude_product_ids.includes(product.id) || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
358
- const isAvailableProduct = flatItem.type === "main" ? !((product == null ? void 0 : product.booking_id) && ((_a = product == null ? void 0 : product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every(
359
- (discount2) => discount2.id && [
360
- "good_pass",
361
- "discount_card",
362
- "product_discount_card"
363
- ].includes(discount2.tag || discount2.type)
364
- ))) : !((flatItem == null ? void 0 : flatItem.booking_id) && ((_d = (_c = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _c.metadata) == null ? void 0 : _d.custom_product_bundle_map_id));
308
+ const isLimitedProduct = (limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
309
+ const isAvailableProduct = flatItem.type === "main" ? !((product == null ? void 0 : product.booking_id) && ((_a = product == null ? void 0 : product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount2) => discount2.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount2.tag || discount2.type)))) : !((flatItem == null ? void 0 : flatItem.booking_id) && ((_d = (_c = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _c.metadata) == null ? void 0 : _d.custom_product_bundle_map_id));
365
310
  const isBundleAvailable = this.checkPackageSubItemUsageRules(discount, flatItem);
366
- if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable && ((_e = discount.config) == null ? void 0 : _e.isAvailable)) {
367
- (_f = discountApplicability.get(discount.id)) == null ? void 0 : _f.push(product.id);
311
+ if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable) {
312
+ (_e = discountApplicability.get(discount.id)) == null ? void 0 : _e.push(product.id);
368
313
  const applicableProducts = discountApplicableProducts.get(discount.id) || [];
369
314
  const discountType = discount.tag || discount.type;
370
315
  const isGoodPass = discountType === "good_pass";
@@ -374,14 +319,13 @@ var RulesModule = class extends import_BaseModule.BaseModule {
374
319
  type: discountType,
375
320
  tag: discountType,
376
321
  discount: {
377
- discount_card_type: (_g = discount == null ? void 0 : discount.metadata) == null ? void 0 : _g.discount_card_type,
322
+ discount_card_type: (_f = discount == null ? void 0 : discount.metadata) == null ? void 0 : _f.discount_card_type,
378
323
  fixed_amount: product.price,
379
324
  resource_id: discount.id,
380
325
  title: discount.format_title,
381
326
  original_amount: product.price || product.origin_total,
382
327
  pre_value: discount.par_value,
383
- product_id: originProduct.id,
384
- discount_product_id: discount.product_id
328
+ product_id: originProduct.id
385
329
  },
386
330
  metadata: {
387
331
  num
@@ -414,39 +358,22 @@ var RulesModule = class extends import_BaseModule.BaseModule {
414
358
  };
415
359
  originProduct = flatItem.originProduct;
416
360
  }
417
- if ((product == null ? void 0 : product.booking_id) && ((_d = product.discount_list) == null ? void 0 : _d.length) && ((_e = product == null ? void 0 : product.discount_list) == null ? void 0 : _e.every(
418
- (discount) => discount.id && ["good_pass", "discount_card", "product_discount_card"].includes(
419
- discount.tag || discount.type
420
- )
421
- ))) {
361
+ if ((product == null ? void 0 : product.booking_id) && ((_d = product.discount_list) == null ? void 0 : _d.length) && ((_e = product == null ? void 0 : product.discount_list) == null ? void 0 : _e.every((discount) => discount.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount.tag || discount.type)))) {
422
362
  if (flatItem.type === "main") {
423
363
  processedProductsMap.set(product._id, [originProduct]);
424
364
  } else {
425
- processedFlatItemsMap.set(flatItem._id, [
426
- {
427
- ...flatItem,
428
- processed: true
429
- }
430
- ]);
365
+ processedFlatItemsMap.set(flatItem._id, [{
366
+ ...flatItem,
367
+ processed: true
368
+ }]);
431
369
  }
432
370
  return;
433
371
  }
434
372
  const applicableDiscounts = sortedDiscountList.filter((discount) => {
435
- var _a2, _b2, _c2, _d2;
436
- const discountType = discount.tag || discount.type;
437
- if (["good_pass", "discount_card", "product_discount_card"].includes(
438
- discountType
439
- )) {
440
- if (discount.config === void 0 || !((_a2 = discount == null ? void 0 : discount.config) == null ? void 0 : _a2.isAvailable)) {
441
- return false;
442
- }
443
- }
444
- if ((Number(product.price) <= 0 || !product.price) && !((_b2 = product.discount_list) == null ? void 0 : _b2.find((n) => {
445
- var _a3;
446
- return ((_a3 = n.discount) == null ? void 0 : _a3.resource_id) === discount.id;
447
- })) && (discount.tag || discount.type) === "good_pass")
373
+ var _a2, _b2;
374
+ if ((Number(product.price) <= 0 || !product.price) && !((_a2 = product.discount_list) == null ? void 0 : _a2.length) && (discount.tag || discount.type) === "good_pass")
448
375
  return false;
449
- if ((Number(product.price) <= 0 || !product.price) && !((_c2 = product.discount_list) == null ? void 0 : _c2.find((n) => {
376
+ if ((Number(product.price) <= 0 || !product.price) && !((_b2 = product.discount_list) == null ? void 0 : _b2.find((n) => {
450
377
  var _a3;
451
378
  return ((_a3 = n.discount) == null ? void 0 : _a3.resource_id) === discount.id;
452
379
  })) && (discount.tag || discount.type) !== "good_pass")
@@ -454,15 +381,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
454
381
  const targetUsedDiscounts = usedDiscounts.get(discount.id);
455
382
  if (targetUsedDiscounts && (discount.tag || discount.type) === "good_pass")
456
383
  return false;
457
- if ((discount.tag || discount.type) === "good_pass") {
458
- const maxUsagePerOrder = (_d2 = discount.config) == null ? void 0 : _d2.maxUsagePerOrder;
459
- if (maxUsagePerOrder && maxUsagePerOrder > 0) {
460
- const currentUsedCount = usedProductIdCounts.get(discount.product_id) || 0;
461
- if (currentUsedCount >= maxUsagePerOrder) {
462
- return false;
463
- }
464
- }
465
- }
466
384
  const limitedData = discount.limited_relation_product_data;
467
385
  const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
468
386
  const isHolderMatch = this.checkHolderMatch(
@@ -481,9 +399,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
481
399
  return false;
482
400
  }
483
401
  if (limitedData.type === "product_all") {
484
- if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
485
- return false;
486
- }
487
402
  if (!this.checkPackageSubItemUsageRules(discount, flatItem)) {
488
403
  return false;
489
404
  }
@@ -496,96 +411,66 @@ var RulesModule = class extends import_BaseModule.BaseModule {
496
411
  }
497
412
  return false;
498
413
  });
499
- const selectedDiscountCard = applicableDiscounts.find(
500
- (n) => n.isScan && n.isSelected && (n.tag || n.type) !== "good_pass"
501
- );
414
+ const selectedDiscountCard = applicableDiscounts.find((n) => n.isScan && n.isSelected && (n.tag || n.type) !== "good_pass");
502
415
  const selectedDiscount = selectedDiscountCard || applicableDiscounts[0];
503
416
  let isManualDiscount = false;
504
417
  if (flatItem.type === "main") {
505
- isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(
506
- (item) => {
507
- var _a2;
508
- return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
509
- }
510
- ) && (!((_f = product.discount_list) == null ? void 0 : _f.length) || ((_h = (_g = product == null ? void 0 : product.discount_list) == null ? void 0 : _g.every) == null ? void 0 : _h.call(
511
- _g,
512
- (item) => item.type === "product"
513
- )));
418
+ isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every((item) => {
419
+ var _a2;
420
+ return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
421
+ }) && (!((_f = product.discount_list) == null ? void 0 : _f.length) || ((_h = (_g = product == null ? void 0 : product.discount_list) == null ? void 0 : _g.every) == null ? void 0 : _h.call(_g, (item) => item.type === "product")));
514
422
  } else {
515
423
  const parentProduct = flatItem.parentProduct;
516
424
  if (parentProduct) {
517
- isManualDiscount = typeof parentProduct.isManualDiscount === "boolean" ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(
518
- (item) => {
519
- var _a2;
520
- return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
521
- }
522
- ) && (!((_i = parentProduct.discount_list) == null ? void 0 : _i.length) || ((_k = (_j = parentProduct == null ? void 0 : parentProduct.discount_list) == null ? void 0 : _j.every) == null ? void 0 : _k.call(
523
- _j,
524
- (item) => item.type === "product"
525
- )));
425
+ isManualDiscount = typeof parentProduct.isManualDiscount === "boolean" ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every((item) => {
426
+ var _a2;
427
+ return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
428
+ }) && (!((_i = parentProduct.discount_list) == null ? void 0 : _i.length) || ((_k = (_j = parentProduct == null ? void 0 : parentProduct.discount_list) == null ? void 0 : _j.every) == null ? void 0 : _k.call(_j, (item) => item.type === "product")));
526
429
  }
527
430
  }
528
431
  if (options == null ? void 0 : options.discountId) {
529
- if (flatItem.type === "main" && ((_l = product.discount_list) == null ? void 0 : _l.some(
530
- (item) => {
531
- var _a2;
532
- return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
533
- }
534
- ))) {
432
+ if (flatItem.type === "main" && ((_l = product.discount_list) == null ? void 0 : _l.some((item) => {
433
+ var _a2;
434
+ return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
435
+ }))) {
535
436
  isManualDiscount = false;
536
437
  }
537
438
  if (flatItem.type === "bundle") {
538
- if (((_m = product.discount_list) == null ? void 0 : _m.some(
539
- (item) => {
540
- var _a2;
541
- return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
542
- }
543
- )) || ((_o = (_n = flatItem.parentProduct) == null ? void 0 : _n.discount_list) == null ? void 0 : _o.some(
544
- (item) => {
545
- var _a2;
546
- return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
547
- }
548
- ))) {
439
+ if (((_m = product.discount_list) == null ? void 0 : _m.some((item) => {
440
+ var _a2;
441
+ return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
442
+ })) || ((_o = (_n = flatItem.parentProduct) == null ? void 0 : _n.discount_list) == null ? void 0 : _o.some((item) => {
443
+ var _a2;
444
+ return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
445
+ }))) {
549
446
  isManualDiscount = false;
550
447
  }
551
448
  }
552
449
  }
553
450
  if (options == null ? void 0 : options.selectedList) {
554
- if (flatItem.type === "main" && ((_p = product.discount_list) == null ? void 0 : _p.some(
555
- (item) => {
556
- var _a2;
557
- return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some(
558
- (n) => {
559
- var _a3;
560
- return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
561
- }
562
- );
563
- }
564
- ))) {
451
+ if (flatItem.type === "main" && ((_p = product.discount_list) == null ? void 0 : _p.some((item) => {
452
+ var _a2;
453
+ return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some((n) => {
454
+ var _a3;
455
+ return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
456
+ });
457
+ }))) {
565
458
  isManualDiscount = false;
566
459
  }
567
460
  if (flatItem.type === "bundle") {
568
- if (((_q = product.discount_list) == null ? void 0 : _q.some(
569
- (item) => {
570
- var _a2;
571
- return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some(
572
- (n) => {
573
- var _a3;
574
- return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
575
- }
576
- );
577
- }
578
- )) || ((_s = (_r = flatItem.parentProduct) == null ? void 0 : _r.discount_list) == null ? void 0 : _s.some(
579
- (item) => {
580
- var _a2;
581
- return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some(
582
- (n) => {
583
- var _a3;
584
- return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
585
- }
586
- );
587
- }
588
- ))) {
461
+ if (((_q = product.discount_list) == null ? void 0 : _q.some((item) => {
462
+ var _a2;
463
+ return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some((n) => {
464
+ var _a3;
465
+ return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
466
+ });
467
+ })) || ((_s = (_r = flatItem.parentProduct) == null ? void 0 : _r.discount_list) == null ? void 0 : _s.some((item) => {
468
+ var _a2;
469
+ return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some((n) => {
470
+ var _a3;
471
+ return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
472
+ });
473
+ }))) {
589
474
  isManualDiscount = false;
590
475
  }
591
476
  }
@@ -593,8 +478,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
593
478
  if (applicableDiscounts.length === 0 || isManualDiscount || (0, import_lodash_es.isBoolean)(product.vouchersApplicable) && !product.vouchersApplicable) {
594
479
  if (flatItem.type === "main") {
595
480
  if (product.isClient) {
596
- processedProductsMap.set(product._id, [
597
- this.hooks.setProduct(originProduct, {
481
+ processedProductsMap.set(
482
+ product._id,
483
+ [this.hooks.setProduct(originProduct, {
598
484
  ...isManualDiscount ? {} : {
599
485
  origin_total: (0, import_utils2.getProductOriginTotalPrice)({
600
486
  product: {
@@ -615,11 +501,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
615
501
  price: product.price
616
502
  },
617
503
  discount_list: []
618
- })
619
- ]);
504
+ })]
505
+ );
620
506
  } else {
621
- processedProductsMap.set(product._id, [
622
- this.hooks.setProduct(originProduct, {
507
+ processedProductsMap.set(
508
+ product._id,
509
+ [this.hooks.setProduct(originProduct, {
623
510
  ...isManualDiscount ? {
624
511
  price: product.price,
625
512
  main_product_selling_price: product.price
@@ -630,8 +517,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
630
517
  main_product_selling_price: product.price
631
518
  },
632
519
  discount_list: []
633
- })
634
- ]);
520
+ })]
521
+ );
635
522
  }
636
523
  } else {
637
524
  processedFlatItemsMap.set(flatItem._id, [{
@@ -648,36 +535,20 @@ var RulesModule = class extends import_BaseModule.BaseModule {
648
535
  }
649
536
  const isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === "good_pass";
650
537
  const totalQuantity = product.quantity || product.num || 1;
651
- const availableGoodPassCount = applicableDiscounts.filter(
652
- (item) => (item.tag || item.type) === "good_pass"
653
- ).length;
654
- let maxUsageLimit = availableGoodPassCount;
655
- if (selectedDiscount.config && selectedDiscount.config.maxUsagePerOrder) {
656
- maxUsageLimit = Math.min(
657
- availableGoodPassCount,
658
- selectedDiscount.config.maxUsagePerOrder
659
- );
660
- }
661
- const splitCount = isNeedSplit ? Math.min(product.quantity || product.num || 1, maxUsageLimit) : 1;
538
+ const availableGoodPassCount = applicableDiscounts.filter((item) => (item.tag || item.type) === "good_pass").length;
539
+ const splitCount = isNeedSplit ? Math.min(totalQuantity, availableGoodPassCount) : 1;
662
540
  const arr = [];
663
541
  if (flatItem.type === "main") {
664
542
  if (splitCount < totalQuantity && isNeedSplit) {
665
- arr.push(
666
- this.hooks.setProduct(originProduct, {
667
- discount_list: [],
668
- quantity: totalQuantity - splitCount,
669
- _id: product._id.split("___")[0],
670
- total: product.origin_total || product.total
671
- })
672
- );
543
+ arr.push(this.hooks.setProduct(originProduct, {
544
+ discount_list: [],
545
+ quantity: totalQuantity - splitCount,
546
+ _id: product._id.split("___")[0]
547
+ }));
673
548
  }
674
549
  for (let i = 0; i < splitCount; i++) {
675
550
  const selectedDiscount2 = selectedDiscountCard || applicableDiscounts[i];
676
551
  usedDiscounts.set(selectedDiscount2.id, true);
677
- if ((selectedDiscount2.tag || selectedDiscount2.type) === "good_pass") {
678
- const currentCount = usedProductIdCounts.get(selectedDiscount2.product_id) || 0;
679
- usedProductIdCounts.set(selectedDiscount2.product_id, currentCount + 1);
680
- }
681
552
  const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
682
553
  let productOriginTotal = product.origin_total || product.total || 0;
683
554
  if (((_t = product.discount_list) == null ? void 0 : _t.length) && product.origin_total) {
@@ -686,30 +557,24 @@ var RulesModule = class extends import_BaseModule.BaseModule {
686
557
  if (Number(((_u = originProduct == null ? void 0 : originProduct._productInit) == null ? void 0 : _u.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
687
558
  productOriginTotal = product.total;
688
559
  }
689
- const targetProductTotal = (0, import_utils.getDiscountAmount)(
690
- selectedDiscount2,
691
- product.price,
692
- product.price
693
- );
694
- const discountType = selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag;
695
- const actualDiscountAmount = new import_decimal.default(product.price).minus(new import_decimal.default(targetProductTotal)).toNumber();
560
+ const targetProductTotal = (0, import_utils.getDiscountAmount)(selectedDiscount2, product.price, product.price);
561
+ const discountType = selectedDiscount2.tag || selectedDiscount2.type;
696
562
  const isGoodPass = discountType === "good_pass";
563
+ const amount = new import_decimal.default(product.price).minus(new import_decimal.default(targetProductTotal)).toNumber();
697
564
  const discountDetail = {
698
- amount: actualDiscountAmount,
699
- type: discountType,
565
+ amount,
566
+ type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : discountType,
700
567
  discount: {
701
568
  discount_card_type: (_v = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _v.discount_card_type,
702
- fixed_amount: actualDiscountAmount,
569
+ fixed_amount: amount,
703
570
  resource_id: selectedDiscount2.id,
704
571
  title: selectedDiscount2.format_title,
705
572
  original_amount: product.price,
706
573
  product_id: originProduct.id,
707
- percent: selectedDiscount2.par_value,
708
- discount_product_id: selectedDiscount2.product_id
574
+ percent: selectedDiscount2.par_value
709
575
  },
710
576
  // 前端使用的num数量,为了计算优惠金额
711
577
  _num: isGoodPass ? 1 : product.num,
712
- config: selectedDiscount2 == null ? void 0 : selectedDiscount2.config,
713
578
  metadata: {
714
579
  num: 1
715
580
  }
@@ -725,6 +590,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
725
590
  }, new import_decimal.default(total)).toNumber();
726
591
  }
727
592
  if (product.isClient) {
593
+ debugger;
728
594
  arr.push(this.hooks.setProduct(originProduct, {
729
595
  discount_list: [discountDetail],
730
596
  price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
@@ -761,35 +627,23 @@ var RulesModule = class extends import_BaseModule.BaseModule {
761
627
  for (let i = 0; i < discountNum; i++) {
762
628
  const selectedDiscount2 = applicableDiscounts[i];
763
629
  usedDiscounts.set(selectedDiscount2.id, true);
764
- if ((selectedDiscount2.tag || selectedDiscount2.type) === "good_pass") {
765
- const currentCount = usedProductIdCounts.get(selectedDiscount2.product_id) || 0;
766
- usedProductIdCounts.set(selectedDiscount2.product_id, currentCount + 1);
767
- }
768
630
  const uniqueId = `${flatItem._id}_split_${i}`;
769
- const discountedPrice = (0, import_utils.getDiscountAmount)(
770
- selectedDiscount2,
771
- product.origin_total,
772
- product.origin_total
773
- );
774
- const bundleDiscountAmount = new import_decimal.default(product.origin_total || 0).minus(discountedPrice).toNumber();
775
631
  const discountDetail = {
776
- amount: bundleDiscountAmount,
632
+ amount: product.origin_total,
777
633
  type: "good_pass",
778
634
  discount: {
779
635
  fixed_amount: product.origin_total,
780
636
  resource_id: selectedDiscount2.id,
781
637
  title: selectedDiscount2.format_title,
782
638
  original_amount: product.origin_total,
783
- product_id: product.id,
784
- discount_product_id: selectedDiscount2.product_id
639
+ product_id: product.id
785
640
  },
786
641
  metadata: {
787
642
  // 🔥 使用拆分后的唯一 _id
788
643
  custom_product_bundle_map_id: uniqueId,
789
644
  num: 1
790
645
  },
791
- _num: 1,
792
- config: selectedDiscount2 == null ? void 0 : selectedDiscount2.config
646
+ _num: 1
793
647
  };
794
648
  const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
795
649
  appliedProducts.push(discountDetail);
@@ -800,9 +654,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
800
654
  _id: uniqueId,
801
655
  num: 1,
802
656
  quantity: 1,
803
- price: discountedPrice,
804
- // 折扣后的价格
805
- total: discountedPrice,
657
+ price: 0,
658
+ // 商品券价格为0
659
+ total: 0,
806
660
  discount_list: [discountDetail],
807
661
  processed: true,
808
662
  _discountId: selectedDiscount2.id
@@ -822,37 +676,30 @@ var RulesModule = class extends import_BaseModule.BaseModule {
822
676
  } else {
823
677
  const selectedDiscount2 = selectedDiscountCard || applicableDiscounts[0];
824
678
  usedDiscounts.set(selectedDiscount2.id, true);
825
- if ((selectedDiscount2.tag || selectedDiscount2.type) === "good_pass") {
826
- const currentCount = usedProductIdCounts.get(selectedDiscount2.product_id) || 0;
827
- usedProductIdCounts.set(selectedDiscount2.product_id, currentCount + 1);
828
- }
829
679
  const productOriginTotal = product.original_price || product.price || 0;
830
680
  const targetProductTotal = (0, import_utils.getDiscountAmount)(
831
681
  selectedDiscount2,
832
682
  productOriginTotal,
833
683
  productOriginTotal
834
684
  );
835
- const bundleActualDiscountAmount = new import_decimal.default(productOriginTotal).minus(targetProductTotal).toNumber();
836
685
  const uniqueId = flatItem._id;
837
686
  const discountDetail = {
838
- amount: bundleActualDiscountAmount * (product.num || 1),
687
+ amount: new import_decimal.default(productOriginTotal).minus(targetProductTotal).toNumber() * (product.num || 1),
839
688
  type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag,
840
689
  discount: {
841
690
  discount_card_type: (_w = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _w.discount_card_type,
842
- fixed_amount: bundleActualDiscountAmount,
691
+ fixed_amount: new import_decimal.default(productOriginTotal).minus(targetProductTotal).toNumber(),
843
692
  resource_id: selectedDiscount2.id,
844
693
  title: selectedDiscount2.format_title,
845
694
  original_amount: product.original_price,
846
695
  product_id: product.id,
847
- percent: selectedDiscount2.par_value,
848
- discount_product_id: selectedDiscount2.product_id
696
+ percent: selectedDiscount2.par_value
849
697
  },
850
698
  metadata: {
851
699
  // 🔥 使用唯一的 _id
852
700
  custom_product_bundle_map_id: uniqueId,
853
701
  num: product.num || 1
854
702
  },
855
- config: selectedDiscount2 == null ? void 0 : selectedDiscount2.config,
856
703
  _num: (product.num || 1) * (((_x = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _x.num) || 1)
857
704
  };
858
705
  const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
@@ -942,65 +789,59 @@ var RulesModule = class extends import_BaseModule.BaseModule {
942
789
  const mainProduct = mainProductArr[0];
943
790
  const mainProductData = this.hooks.getProduct(mainProduct);
944
791
  const newBundleWithDiscount = [];
945
- (product.bundle || []).forEach(
946
- (bundleItem, bundleIndex) => {
947
- const processedItems = bundleProcessingInfo.get(
948
- bundleIndex
949
- ) || [bundleItem];
950
- if (processedItems.length > 1) {
951
- processedItems.forEach((item) => {
952
- const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
953
- var _a;
954
- return {
955
- ...discount,
956
- metadata: {
957
- num: item.num,
958
- custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
959
- }
960
- // num: item.num, // 使用拆分后的 num
961
- };
962
- });
963
- newBundleWithDiscount.push({
964
- ...bundleItem,
965
- _id: item._id,
966
- product_id: bundleItem.product_id,
967
- price: item.price,
968
- num: item.num,
969
- discount_list: updatedDiscountList2
970
- });
792
+ (product.bundle || []).forEach((bundleItem, bundleIndex) => {
793
+ const processedItems = bundleProcessingInfo.get(bundleIndex) || [bundleItem];
794
+ if (processedItems.length > 1) {
795
+ processedItems.forEach((item) => {
796
+ const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
797
+ var _a;
798
+ return {
799
+ ...discount,
800
+ metadata: {
801
+ num: item.num,
802
+ custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
803
+ }
804
+ // num: item.num, // 使用拆分后的 num
805
+ };
806
+ });
807
+ newBundleWithDiscount.push({
808
+ ...bundleItem,
809
+ _id: item._id,
810
+ product_id: bundleItem.product_id,
811
+ price: item.price,
812
+ num: item.num,
813
+ discount_list: updatedDiscountList2
814
+ });
815
+ });
816
+ } else {
817
+ const item = processedItems[0];
818
+ if (item.processed) {
819
+ const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
820
+ var _a;
821
+ return {
822
+ ...discount,
823
+ metadata: {
824
+ num: item.num,
825
+ custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
826
+ }
827
+ // num: item.num, // 使用当前的 num
828
+ };
829
+ });
830
+ newBundleWithDiscount.push({
831
+ ...bundleItem,
832
+ _id: item._id,
833
+ product_id: bundleItem.product_id,
834
+ price: item.price,
835
+ num: item.num,
836
+ discount_list: updatedDiscountList2
971
837
  });
972
838
  } else {
973
- const item = processedItems[0];
974
- if (item.processed) {
975
- const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
976
- var _a;
977
- return {
978
- ...discount,
979
- metadata: {
980
- num: item.num,
981
- custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
982
- }
983
- // num: item.num, // 使用当前的 num
984
- };
985
- });
986
- newBundleWithDiscount.push({
987
- ...bundleItem,
988
- _id: item._id,
989
- product_id: bundleItem.product_id,
990
- price: item.price,
991
- num: item.num,
992
- discount_list: updatedDiscountList2
993
- });
994
- } else {
995
- newBundleWithDiscount.push(item);
996
- }
839
+ newBundleWithDiscount.push(item);
997
840
  }
998
841
  }
999
- );
842
+ });
1000
843
  let newTotalWithDiscount = Number(mainProductData.price || 0);
1001
- let newOriginTotalWithDiscount = Number(
1002
- mainProductData.original_price || mainProductData.price || 0
1003
- );
844
+ let newOriginTotalWithDiscount = Number(mainProductData.original_price || mainProductData.price || 0);
1004
845
  const updatedMainDiscountList = mainProductData.discount_list.map((discount) => {
1005
846
  var _a, _b;
1006
847
  if ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) {
@@ -1015,12 +856,10 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1015
856
  }
1016
857
  };
1017
858
  });
1018
- const mainDiscountList = updatedMainDiscountList.filter(
1019
- (item) => {
1020
- var _a;
1021
- return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
1022
- }
1023
- );
859
+ const mainDiscountList = updatedMainDiscountList.filter((item) => {
860
+ var _a;
861
+ return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
862
+ });
1024
863
  if (mainDiscountList && mainDiscountList.length > 0) {
1025
864
  const allDiscountAmount = (0, import_utils.getDiscountListAmountTotal)(mainDiscountList);
1026
865
  newTotalWithDiscount = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotalWithDiscount;
@@ -1056,18 +895,14 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1056
895
  );
1057
896
  if (mainProductQuantity > 1) {
1058
897
  const newBundleOriginal = [];
1059
- (product.bundle || []).forEach(
1060
- (bundleItem, bundleIndex) => {
1061
- newBundleOriginal.push({
1062
- ...bundleItem,
1063
- discount_list: []
1064
- });
1065
- }
1066
- );
898
+ (product.bundle || []).forEach((bundleItem, bundleIndex) => {
899
+ newBundleOriginal.push({
900
+ ...bundleItem,
901
+ discount_list: []
902
+ });
903
+ });
1067
904
  let newTotalOriginal = Number(mainProductData.price || 0);
1068
- let newOriginTotalOriginal = Number(
1069
- mainProductData.original_price || mainProductData.price || 0
1070
- );
905
+ let newOriginTotalOriginal = Number(mainProductData.original_price || mainProductData.price || 0);
1071
906
  const updatedMainDiscountListOriginal = mainProductData.discount_list.map((discount) => {
1072
907
  var _a, _b;
1073
908
  if ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) {
@@ -1082,16 +917,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1082
917
  // num: mainProductQuantity - 1,
1083
918
  };
1084
919
  });
1085
- const mainDiscountListOriginal = updatedMainDiscountListOriginal.filter(
1086
- (item) => {
1087
- var _a;
1088
- return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
1089
- }
1090
- );
920
+ const mainDiscountListOriginal = updatedMainDiscountListOriginal.filter((item) => {
921
+ var _a;
922
+ return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
923
+ });
1091
924
  if (mainDiscountListOriginal && mainDiscountListOriginal.length > 0) {
1092
- const allDiscountAmount = (0, import_utils.getDiscountListAmount)(
1093
- mainDiscountListOriginal
1094
- );
925
+ const allDiscountAmount = (0, import_utils.getDiscountListAmount)(mainDiscountListOriginal);
1095
926
  newTotalOriginal = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotalOriginal;
1096
927
  newOriginTotalOriginal = mainProductData.origin_total ?? newOriginTotalOriginal;
1097
928
  }
@@ -1126,56 +957,47 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1126
957
  const mainProductData = this.hooks.getProduct(mainProduct);
1127
958
  const newBundle = [];
1128
959
  if (product.bundle && Array.isArray(product.bundle)) {
1129
- product.bundle.forEach(
1130
- (bundleItem, bundleIndex) => {
1131
- const bundleItemId = `${product._id}_bundle_${bundleIndex}`;
1132
- const processedBundleItems = processedFlatItemsMap2.get(bundleItemId);
1133
- if (!processedBundleItems || processedBundleItems.length === 0) {
1134
- newBundle.push(bundleItem);
1135
- } else {
1136
- processedBundleItems.forEach((item) => {
1137
- const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
1138
- var _a2;
1139
- return {
1140
- ...discount,
1141
- metadata: {
1142
- num: item.num,
1143
- custom_product_bundle_map_id: (_a2 = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id
1144
- }
1145
- // num: item.num, // 使用拆分后的 num
1146
- };
1147
- });
1148
- newBundle.push({
1149
- ...bundleItem,
1150
- _id: item._id,
1151
- product_id: bundleItem.product_id,
1152
- price: item.price,
1153
- num: item.num,
1154
- discount_list: updatedDiscountList2
1155
- });
960
+ product.bundle.forEach((bundleItem, bundleIndex) => {
961
+ const bundleItemId = `${product._id}_bundle_${bundleIndex}`;
962
+ const processedBundleItems = processedFlatItemsMap2.get(bundleItemId);
963
+ if (!processedBundleItems || processedBundleItems.length === 0) {
964
+ newBundle.push(bundleItem);
965
+ } else {
966
+ processedBundleItems.forEach((item) => {
967
+ const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
968
+ var _a2;
969
+ return {
970
+ ...discount,
971
+ metadata: {
972
+ num: item.num,
973
+ custom_product_bundle_map_id: (_a2 = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id
974
+ }
975
+ // num: item.num, // 使用拆分后的 num
976
+ };
977
+ });
978
+ newBundle.push({
979
+ ...bundleItem,
980
+ _id: item._id,
981
+ product_id: bundleItem.product_id,
982
+ price: item.price,
983
+ num: item.num,
984
+ discount_list: updatedDiscountList2
1156
985
  });
1157
- }
986
+ });
1158
987
  }
1159
- );
988
+ });
1160
989
  }
1161
990
  let newTotal = Number(mainProductData.price || 0);
1162
- let newOriginTotal = Number(
1163
- mainProductData.original_price || mainProductData.price || 0
1164
- );
1165
- const isManualDiscount = typeof mainProductData.isManualDiscount === "boolean" ? mainProductData.isManualDiscount : mainProductData.total != mainProductData.origin_total && (!((_a = mainProductData.discount_list) == null ? void 0 : _a.length) || ((_c = (_b = mainProductData == null ? void 0 : mainProductData.discount_list) == null ? void 0 : _b.every) == null ? void 0 : _c.call(
1166
- _b,
1167
- (item) => item.type === "product"
1168
- )));
991
+ let newOriginTotal = Number(mainProductData.original_price || mainProductData.price || 0);
992
+ const isManualDiscount = typeof mainProductData.isManualDiscount === "boolean" ? mainProductData.isManualDiscount : mainProductData.total != mainProductData.origin_total && (!((_a = mainProductData.discount_list) == null ? void 0 : _a.length) || ((_c = (_b = mainProductData == null ? void 0 : mainProductData.discount_list) == null ? void 0 : _b.every) == null ? void 0 : _c.call(_b, (item) => item.type === "product")));
1169
993
  if (isManualDiscount) {
1170
994
  newTotal = mainProductData.total ?? newTotal;
1171
995
  newOriginTotal = mainProductData.origin_total ?? newOriginTotal;
1172
996
  } else {
1173
- const mainDiscountList = mainProductData.discount_list.filter(
1174
- (item) => {
1175
- var _a2;
1176
- return !((_a2 = item == null ? void 0 : item.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id);
1177
- }
1178
- );
997
+ const mainDiscountList = mainProductData.discount_list.filter((item) => {
998
+ var _a2;
999
+ return !((_a2 = item == null ? void 0 : item.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id);
1000
+ });
1179
1001
  if (mainDiscountList && mainDiscountList.length > 0) {
1180
1002
  const allDiscountAmount = (0, import_utils.getDiscountListAmount)(mainDiscountList);
1181
1003
  newTotal = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotal;