@pisell/pisellos 2.1.46 → 2.1.47

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.
@@ -51,8 +51,10 @@ export interface RulesParamsHooks {
51
51
  origin_total?: number;
52
52
  price?: string | number;
53
53
  variant?: any[];
54
- original_price?: number;
54
+ original_price?: number | string;
55
55
  quantity?: number;
56
+ bundle?: any[];
57
+ main_product_selling_price?: string | number;
56
58
  }) => Record<string, any>;
57
59
  }
58
60
  export {};
@@ -48,6 +48,7 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
48
48
  * 初始化结账流程
49
49
  */
50
50
  initializeCheckoutAsync(params: CheckoutInitParams): Promise<void>;
51
+ getHolderIdFromBooking(obj: any): number | undefined;
51
52
  getProductListByOrder(): {
52
53
  product_id: number;
53
54
  product_variant_id: string;
@@ -371,10 +371,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
371
371
  }
372
372
  return initializeCheckoutAsync;
373
373
  }())
374
+ }, {
375
+ key: "getHolderIdFromBooking",
376
+ value: function getHolderIdFromBooking(obj) {
377
+ var _obj$holder;
378
+ if (!obj) return undefined;
379
+ var ret = obj.holder_id || ((_obj$holder = obj.holder) === null || _obj$holder === void 0 ? void 0 : _obj$holder.form_record);
380
+ if (Array.isArray(ret)) {
381
+ return ret.length > 0 ? Number(ret[0]) : undefined;
382
+ }
383
+ return Number(ret) || undefined;
384
+ }
374
385
  }, {
375
386
  key: "getProductListByOrder",
376
387
  value: function getProductListByOrder() {
377
- var _this$store$currentOr, _this$store$currentOr2;
388
+ var _this$store$currentOr,
389
+ _this3 = this,
390
+ _this$store$currentOr2;
378
391
  if (!this.store.currentOrder) {
379
392
  return [];
380
393
  }
@@ -383,22 +396,50 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
383
396
  return pre + (item.amount || 0);
384
397
  }, 0);
385
398
  };
386
- var productList = ((_this$store$currentOr = this.store.currentOrder.order_info) === null || _this$store$currentOr === void 0 || (_this$store$currentOr = _this$store$currentOr.original_order_data.bookings) === null || _this$store$currentOr === void 0 ? void 0 : _this$store$currentOr.map(function (item) {
387
- return {
388
- product_id: item.product.product_id,
389
- product_variant_id: item.product.product_variant_id,
390
- quantity: item.product.num,
391
- selling_price: item.product.calculated_selling_price
392
- };
393
- })) || [];
394
- var relationProducts = ((_this$store$currentOr2 = this.store.currentOrder.order_info) === null || _this$store$currentOr2 === void 0 || (_this$store$currentOr2 = _this$store$currentOr2.original_order_data) === null || _this$store$currentOr2 === void 0 || (_this$store$currentOr2 = _this$store$currentOr2.relation_products) === null || _this$store$currentOr2 === void 0 ? void 0 : _this$store$currentOr2.map(function (item) {
395
- return {
396
- product_id: item.product_id,
397
- product_variant_id: item.product_variant_id,
398
- quantity: item.num,
399
- selling_price: item.source_product_price
400
- };
401
- })) || [];
399
+ var formatProduct = function formatProduct(items) {
400
+ return items.map(function (item) {
401
+ var _item$is_charge_tax;
402
+ return {
403
+ product_id: item.product_id,
404
+ product_variant_id: item.product_variant_id,
405
+ quantity: item.num,
406
+ // 商品是否含税:1;0
407
+ is_charge_tax: (_item$is_charge_tax = item.is_charge_tax) !== null && _item$is_charge_tax !== void 0 ? _item$is_charge_tax : 0,
408
+ // 若商品不含税,计算得到的税费,单位(元)
409
+ tax_fee: item.tax_fee,
410
+ // 整个商品折扣后的总金额
411
+ selling_price: item.calculated_selling_price,
412
+ // 使用者id
413
+ holder_id: item.holder_id,
414
+ // 整个商品折扣前的总金额
415
+ original_price: item.calculated_original_price,
416
+ // 主商品折扣前金额,不包含套餐子商品
417
+ main_product_original_price: item.price,
418
+ // 主商品折扣后金额,不包含套餐子商品
419
+ main_product_selling_price: item.main_product_selling_price,
420
+ product_bundle: item.product_bundle.map(function (bundle) {
421
+ return {
422
+ bundle_id: bundle.bundle_id,
423
+ bundle_product_id: bundle.bundle_product_id,
424
+ bundle_variant_id: bundle.bundle_variant_id,
425
+ price_type: bundle.price_type,
426
+ price_type_ext: bundle.price_type_ext,
427
+ // 套餐子商品总价,不包含折扣金额
428
+ bundle_sum_price: bundle.bundle_sum_price,
429
+ // 套餐子商品折扣后金额
430
+ bundle_selling_price: bundle.bundle_selling_price,
431
+ num: bundle.num
432
+ };
433
+ })
434
+ };
435
+ }) || [];
436
+ };
437
+ var productList = formatProduct(((_this$store$currentOr = this.store.currentOrder.order_info) === null || _this$store$currentOr === void 0 || (_this$store$currentOr = _this$store$currentOr.original_order_data) === null || _this$store$currentOr === void 0 || (_this$store$currentOr = _this$store$currentOr.bookings) === null || _this$store$currentOr === void 0 ? void 0 : _this$store$currentOr.map(function (item) {
438
+ return _objectSpread(_objectSpread({}, item.product), {}, {
439
+ holder_id: _this3.getHolderIdFromBooking(item)
440
+ });
441
+ })) || []);
442
+ var relationProducts = formatProduct(((_this$store$currentOr2 = this.store.currentOrder.order_info) === null || _this$store$currentOr2 === void 0 || (_this$store$currentOr2 = _this$store$currentOr2.original_order_data) === null || _this$store$currentOr2 === void 0 ? void 0 : _this$store$currentOr2.relation_products) || []);
402
443
  return [].concat(_toConsumableArray(productList), _toConsumableArray(relationProducts));
403
444
  }
404
445
  }, {
@@ -1542,7 +1583,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1542
1583
  key: "updateVoucherPaymentItemsAsync",
1543
1584
  value: (function () {
1544
1585
  var _updateVoucherPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(voucherPaymentItems) {
1545
- var _this3 = this;
1586
+ var _this4 = this;
1546
1587
  var paymentItems, allPaymentItemsSynced, remainingAmount, remainingValue, isOrderSynced, orderPaymentType, voucherPaymentItemsWithType, currentOrderId, isCurrentOrderReal, updatedOrder;
1547
1588
  return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1548
1589
  while (1) switch (_context18.prev = _context18.next) {
@@ -1594,8 +1635,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1594
1635
 
1595
1636
  // 从 otherParams 获取 metadata 字段
1596
1637
  var metadata = _objectSpread(_objectSpread({}, item.metadata), {}, {
1597
- rounding_rule: _this3.otherParams.order_rounding_setting,
1598
- shop_wallet_pass_id: _this3.otherParams.shop_wallet_pass_id
1638
+ rounding_rule: _this4.otherParams.order_rounding_setting,
1639
+ shop_wallet_pass_id: _this4.otherParams.shop_wallet_pass_id
1599
1640
  });
1600
1641
  return _objectSpread(_objectSpread({}, item), {}, {
1601
1642
  order_payment_type: orderPaymentType,
@@ -3140,7 +3181,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3140
3181
  key: "updateStateAmountToRemaining",
3141
3182
  value: (function () {
3142
3183
  var _updateStateAmountToRemaining = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36() {
3143
- var _this4 = this;
3184
+ var _this5 = this;
3144
3185
  var checkOrder,
3145
3186
  _yield$this$fetchOrde3,
3146
3187
  paymentItems,
@@ -3236,7 +3277,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3236
3277
  hasStateChanged = true;
3237
3278
  setTimeout(function () {
3238
3279
  // 发出 stateAmount 变更事件
3239
- _this4.core.effects.emit("".concat(_this4.name, ":onStateAmountChanged"), {
3280
+ _this5.core.effects.emit("".concat(_this5.name, ":onStateAmountChanged"), {
3240
3281
  oldAmount: currentStateAmount,
3241
3282
  newAmount: remainingAmount,
3242
3283
  timestamp: Date.now(),
@@ -3257,7 +3298,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3257
3298
 
3258
3299
  // 发出 balanceDueAmount 变更事件
3259
3300
  setTimeout(function () {
3260
- _this4.core.effects.emit("".concat(_this4.name, ":onBalanceDueAmountChanged"), {
3301
+ _this5.core.effects.emit("".concat(_this5.name, ":onBalanceDueAmountChanged"), {
3261
3302
  oldAmount: currentBalanceDueAmount,
3262
3303
  newAmount: remainingAmount,
3263
3304
  timestamp: Date.now(),
@@ -3555,7 +3596,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3555
3596
  key: "syncOrderToBackendWithReturn",
3556
3597
  value: (function () {
3557
3598
  var _syncOrderToBackendWithReturn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39() {
3558
- var _this5 = this,
3599
+ var _this6 = this,
3559
3600
  _this$store$currentOr23,
3560
3601
  _this$store$currentOr24,
3561
3602
  _this$store$currentCu2,
@@ -3636,8 +3677,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3636
3677
  var _item$metadata, _item$metadata2;
3637
3678
  return _objectSpread(_objectSpread({}, item), {}, {
3638
3679
  metadata: _objectSpread(_objectSpread({}, item.metadata), {}, {
3639
- rounding_rule: ((_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.rounding_rule) || _this5.otherParams.order_rounding_setting,
3640
- shop_wallet_pass_id: ((_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.shop_wallet_pass_id) || _this5.otherParams.shop_wallet_pass_id
3680
+ rounding_rule: ((_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.rounding_rule) || _this6.otherParams.order_rounding_setting,
3681
+ shop_wallet_pass_id: ((_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.shop_wallet_pass_id) || _this6.otherParams.shop_wallet_pass_id
3641
3682
  })
3642
3683
  });
3643
3684
  }); // 确定最终的定金金额:优先使用手动设置的值,否则从支付项中计算
@@ -4344,7 +4385,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4344
4385
  }, {
4345
4386
  key: "resetStoreState",
4346
4387
  value: function resetStoreState() {
4347
- var _this6 = this;
4388
+ var _this7 = this;
4348
4389
  try {
4349
4390
  var prevOrderInfo = this.store.currentOrder ? {
4350
4391
  uuid: this.store.currentOrder.uuid,
@@ -4379,7 +4420,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4379
4420
  // 使用 setTimeout 确保事件处理不会阻塞状态重置
4380
4421
  if (prevOrderInfo) {
4381
4422
  setTimeout(function () {
4382
- _this6.core.effects.emit("".concat(_this6.name, ":onOrderCleared"), {
4423
+ _this7.core.effects.emit("".concat(_this7.name, ":onOrderCleared"), {
4383
4424
  previousOrder: prevOrderInfo,
4384
4425
  timestamp: Date.now()
4385
4426
  });
@@ -549,7 +549,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
549
549
  if (index !== -1) {
550
550
  editModeDiscountList[index] = _objectSpread(_objectSpread({}, editModeDiscountList[index]), {}, {
551
551
  amount: new Decimal(discount.amount || 0).plus(new Decimal(editModeDiscountList[index].amount || 0)).toNumber(),
552
- savedAmount: new Decimal(discount.amount || 0).times((product === null || product === void 0 ? void 0 : product.num) || 1).plus(new Decimal(editModeDiscountList[index].savedAmount || 0)).toNumber()
552
+ savedAmount: new Decimal(discount.amount || 0).times((product === null || product === void 0 ? void 0 : product.quantity) || (product === null || product === void 0 ? void 0 : product.num) || 1).plus(new Decimal(editModeDiscountList[index].savedAmount || 0)).toNumber()
553
553
  });
554
554
  } else {
555
555
  var _discount$discount2, _discount$discount3, _discount$discount4;
@@ -560,7 +560,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
560
560
  name: discount.name || discount.discount.title.auto,
561
561
  isEditMode: true,
562
562
  limited_relation_product_data: {},
563
- savedAmount: discount.amount * ((product === null || product === void 0 ? void 0 : product.num) || 1),
563
+ savedAmount: discount.amount * ((product === null || product === void 0 ? void 0 : product.quantity) || (product === null || product === void 0 ? void 0 : product.num) || 1),
564
564
  isAvailable: true,
565
565
  id: ((_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.resource_id) || discount.id,
566
566
  format_title: ((_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.title) || discount.format_title,
@@ -581,17 +581,20 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
581
581
  var targetProduct = productList.find(function (n) {
582
582
  return n.id === id;
583
583
  });
584
+ if (!targetProduct) return false;
584
585
  var product = (_this3$hooks2 = _this3.hooks) === null || _this3$hooks2 === void 0 ? void 0 : _this3$hooks2.getProduct(targetProduct);
585
586
  // 如果 product.total 是小于等于0有可能是她已经用过商品券或者折扣卡导致的,或者本身就是负数价格,所以此时还需要判断 origin_total 是否小于等于0
586
587
  // 如果 product.vouchersApplicable是布尔值,并且是 false,也当做免费商品处理,此商品不可用优惠券或折扣卡
587
588
  return Number(product === null || product === void 0 ? void 0 : product.total) <= 0 && (Number(product === null || product === void 0 ? void 0 : product.origin_total) <= 0 || !(product !== null && product !== void 0 && product.origin_total)) || isBoolean(product === null || product === void 0 ? void 0 : product.vouchersApplicable) && !(product !== null && product !== void 0 && product.vouchersApplicable);
588
589
  };
589
- var allUsedProductIds = newDiscountList.map(function (n) {
590
+ var allUsedProductIds = newDiscountList.filter(function (item) {
591
+ return !(item !== null && item !== void 0 && item.isEditMode);
592
+ }).map(function (n) {
590
593
  var _n$appliedProductDeta;
591
- return n.isSelected ? (_n$appliedProductDeta = n.appliedProductDetails) === null || _n$appliedProductDeta === void 0 ? void 0 : _n$appliedProductDeta.map(function (n) {
594
+ return n.isSelected ? ((_n$appliedProductDeta = n.appliedProductDetails) === null || _n$appliedProductDeta === void 0 ? void 0 : _n$appliedProductDeta.map(function (n) {
592
595
  var _n$discount;
593
596
  return (_n$discount = n.discount) === null || _n$discount === void 0 ? void 0 : _n$discount.product_id;
594
- }) : [];
597
+ })) || n.product_id : [];
595
598
  }).flat();
596
599
  newDiscountList.forEach(function (item) {
597
600
  var _item$applicableProdu;
@@ -12,6 +12,13 @@ export declare const isAllNormalProduct: (items: any[]) => boolean;
12
12
  * @returns
13
13
  */
14
14
  export declare const getDiscountAmount: (discount: Discount, total: number, price: number) => number;
15
+ export declare const getDiscountListAmountTotal: (discount: Discount[]) => any;
16
+ /**
17
+ * 获取折扣金额 计算每个折扣的金额
18
+ * @param discount
19
+ * @returns
20
+ */
21
+ export declare const getDiscountListAmount: (discount: Discount[]) => any;
15
22
  export interface ScheduleItem {
16
23
  id: number;
17
24
  name: string | {
@@ -37,7 +37,7 @@ export var getDiscountAmount = function getDiscountAmount(discount, total, price
37
37
  var _discount$metadata;
38
38
  // 商品券
39
39
  if (discount.tag === 'good_pass') {
40
- return new Decimal(total).minus(new Decimal(price || 0)).toNumber();
40
+ return new Decimal(price).minus(new Decimal(price || 0)).toNumber();
41
41
  }
42
42
 
43
43
  // 判断是否是固定金额
@@ -45,11 +45,27 @@ export var getDiscountAmount = function getDiscountAmount(discount, total, price
45
45
 
46
46
  // 固定金额 小于0时返回0
47
47
  if (isFixedAmount) {
48
- return Math.max(new Decimal(total).minus(new Decimal(discount.par_value || 0)).toNumber(), 0);
48
+ return Math.max(new Decimal(price).minus(new Decimal(discount.par_value || 0)).toNumber(), 0);
49
49
  }
50
50
 
51
51
  // 百分比:根据折扣卡金额计算
52
- return new Decimal(100).minus(discount.par_value || 0).div(100).mul(new Decimal(total)).toNumber();
52
+ return new Decimal(100).minus(discount.par_value || 0).div(100).mul(new Decimal(price)).toNumber();
53
+ };
54
+ export var getDiscountListAmountTotal = function getDiscountListAmountTotal(discount) {
55
+ return discount.reduce(function (acc, cur) {
56
+ return new Decimal(acc).plus(new Decimal(cur.num || 1).mul(new Decimal(cur.amount || 0))).toNumber();
57
+ }, new Decimal(0));
58
+ };
59
+
60
+ /**
61
+ * 获取折扣金额 计算每个折扣的金额
62
+ * @param discount
63
+ * @returns
64
+ */
65
+ export var getDiscountListAmount = function getDiscountListAmount(discount) {
66
+ return discount.reduce(function (acc, cur) {
67
+ return new Decimal(acc).plus(new Decimal(cur.amount || 0)).toNumber();
68
+ }, new Decimal(0));
53
69
  };
54
70
 
55
71
  // 日程项接口定义
@@ -172,6 +172,18 @@ var formatProductToCartItemOrigin = (params) => {
172
172
  var getProductTotalPrice = (params) => {
173
173
  const { product, bundle, options, discounts } = params;
174
174
  let price = Number(product.price);
175
+ if (discounts == null ? void 0 : discounts.length) {
176
+ discounts.forEach((currentValue) => {
177
+ var _a;
178
+ price = (0, import_utils2.getDiscountAmount)({
179
+ tag: currentValue.type,
180
+ par_value: currentValue.discount.percent,
181
+ metadata: {
182
+ discount_card_type: (_a = currentValue == null ? void 0 : currentValue.discount) == null ? void 0 : _a.discount_card_type
183
+ }
184
+ }, price, price);
185
+ });
186
+ }
175
187
  if (bundle == null ? void 0 : bundle.length) {
176
188
  price = bundle.reduce((accumulator, currentValue) => {
177
189
  return accumulator + Number(currentValue.price) * Number(currentValue.num);
@@ -182,21 +194,7 @@ var getProductTotalPrice = (params) => {
182
194
  return accumulator + Number(currentValue.price) * Number(currentValue.num);
183
195
  }, price);
184
196
  }
185
- if (discounts == null ? void 0 : discounts.length) {
186
- discounts.forEach((currentValue) => {
187
- var _a;
188
- if (currentValue.type !== "good_pass") {
189
- price = (0, import_utils2.getDiscountAmount)({
190
- tag: currentValue.type,
191
- par_value: currentValue.discount.percent,
192
- metadata: {
193
- discount_card_type: (_a = currentValue == null ? void 0 : currentValue.discount) == null ? void 0 : _a.discount_card_type
194
- }
195
- }, price, price);
196
- }
197
- });
198
- }
199
- return price;
197
+ return Math.max(0, price);
200
198
  };
201
199
  var getProductOriginTotalPrice = (params) => {
202
200
  const { product, bundle, options, discounts } = params;
@@ -254,9 +252,15 @@ var formatBundle = (bundle) => {
254
252
  price: item == null ? void 0 : item.price,
255
253
  total: item == null ? void 0 : item.price,
256
254
  price_type: item == null ? void 0 : item.price_type,
255
+ original_price: item == null ? void 0 : item.original_price,
256
+ original_total: item == null ? void 0 : item.original_total,
257
+ price_type_ext: item == null ? void 0 : item.price_type_ext,
257
258
  bundle_sum_price: item == null ? void 0 : item.bundle_sum_price,
258
259
  bundle_sum_type: item == null ? void 0 : item.bundle_sum_type,
259
- options: formatOptions(item == null ? void 0 : item.option)
260
+ options: formatOptions(item == null ? void 0 : item.option),
261
+ _bundle_product_id: item._bundle_product_id,
262
+ discount_list: item.discount_list,
263
+ originBundleItem: item.originBundleItem || item
260
264
  };
261
265
  });
262
266
  };
@@ -264,15 +268,24 @@ var formatBundleToOrigin = (bundle) => {
264
268
  if (!(bundle == null ? void 0 : bundle.length))
265
269
  return [];
266
270
  return bundle.map((d) => {
271
+ const getBundleValueByKey = (key) => {
272
+ var _a;
273
+ return (d == null ? void 0 : d[key]) || ((_a = d == null ? void 0 : d.originBundleItem) == null ? void 0 : _a[key]);
274
+ };
267
275
  return {
268
- bundle_group_id: d.group_id,
276
+ bundle_group_id: getBundleValueByKey("group_id"),
269
277
  bundle_id: d.id,
270
- bundle_product_id: (d == null ? void 0 : d._bundle_product_id) || (d == null ? void 0 : d.product_id),
271
- bundle_variant_id: d.bundle_variant_id,
278
+ bundle_product_id: getBundleValueByKey("_bundle_product_id") || getBundleValueByKey("product_id"),
279
+ bundle_variant_id: getBundleValueByKey("bundle_variant_id"),
272
280
  num: d.num,
273
- extension_id: d.extension_id,
274
- extension_type: d.extension_type,
275
- option: formatOptionsToOrigin(d.option)
281
+ extension_id: getBundleValueByKey("extension_id"),
282
+ extension_type: getBundleValueByKey("extension_type"),
283
+ option: formatOptionsToOrigin(getBundleValueByKey("option")),
284
+ discount_list: d.discount_list,
285
+ "bundle_selling_price": d == null ? void 0 : d.price,
286
+ metadata: {
287
+ custom_product_bundle_map_id: d._id
288
+ }
276
289
  };
277
290
  });
278
291
  };
@@ -176,7 +176,8 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
176
176
  }
177
177
  if (discount.appliedProductDetails) {
178
178
  return discount.appliedProductDetails.reduce((total, product) => {
179
- const price = new import_decimal.default((product == null ? void 0 : product.amount) || 0).mul((product == null ? void 0 : product.num) || 1);
179
+ var _a;
180
+ const price = new import_decimal.default(((_a = product == null ? void 0 : product.discount) == null ? void 0 : _a.fixed_amount) || 0).mul((product == null ? void 0 : product._num) || 1);
180
181
  return new import_decimal.default(total).plus(price).toNumber();
181
182
  }, 0);
182
183
  }
@@ -15,11 +15,16 @@ interface Formattitle {
15
15
  'zh-CN'?: any;
16
16
  'zh-HK'?: any;
17
17
  }
18
+ interface PackageSubItemUsageRules {
19
+ type: 'universal_discount' | 'package_exclusive' | 'single_item_promo' | 'custom_usage_rules';
20
+ rules: ("original_price" | "markup_price")[];
21
+ }
18
22
  interface Limitedrelationproductdata {
19
23
  id: number;
20
24
  type: 'product_all' | 'products' | 'product_collection';
21
25
  product_ids: number[];
22
26
  product_collection_id: number[];
27
+ package_sub_item_usage_rules?: PackageSubItemUsageRules;
23
28
  }
24
29
  interface ApplicableProductDetails {
25
30
  amount: string;
@@ -29,12 +34,14 @@ interface ApplicableProductDetails {
29
34
  original_amount: string;
30
35
  num: number;
31
36
  discount?: {
37
+ fixed_amount?: number;
32
38
  product_id?: number;
33
39
  original_amount?: string;
34
40
  percent?: string;
35
41
  resource_id?: number;
36
42
  title?: string;
37
43
  };
44
+ _num: number;
38
45
  }
39
46
  interface UsageCreditsValue {
40
47
  total_credits: number;
@@ -72,6 +79,7 @@ export interface Discount {
72
79
  format_title: Formattitle;
73
80
  metadata?: {
74
81
  discount_card_type?: 'fixed_amount' | 'percent';
82
+ custom_product_bundle_map_id?: string;
75
83
  validity_type?: "custom_schedule_validity" | "fixed_validity";
76
84
  };
77
85
  product: Product;
@@ -102,6 +110,7 @@ export interface Discount {
102
110
  custom_schedule_snapshot?: {
103
111
  data: any[];
104
112
  };
113
+ num?: number;
105
114
  }
106
115
  export interface DiscountState {
107
116
  discountList: Discount[];
@@ -115,6 +115,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
115
115
  item._origin.duration = duration;
116
116
  item._origin.sub_type = durationType;
117
117
  }
118
+ const discountList = (0, import_utils.getAllDiscountList)(item);
119
+ item._origin.product.discount_list = discountList;
118
120
  if ((0, import_utils2.isNormalProduct)(item._origin)) {
119
121
  order.relation_products.push(item._origin.product);
120
122
  const relationForms = item._origin.relation_forms || [];
@@ -20,3 +20,4 @@ export declare const mergeRelationForms: (relationForms: {
20
20
  form_id: number;
21
21
  form_record_ids: number[];
22
22
  }[];
23
+ export declare const getAllDiscountList: (cartItem: CartItem) => any;
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  var utils_exports = {};
31
31
  __export(utils_exports, {
32
32
  generateDuration: () => generateDuration,
33
+ getAllDiscountList: () => getAllDiscountList,
33
34
  mergeRelationForms: () => mergeRelationForms
34
35
  });
35
36
  module.exports = __toCommonJS(utils_exports);
@@ -55,8 +56,18 @@ var mergeRelationForms = (relationForms) => {
55
56
  }, {})
56
57
  ).filter((item) => item.form_record_ids.length > 0);
57
58
  };
59
+ var getAllDiscountList = (cartItem) => {
60
+ var _a, _b, _c, _d;
61
+ let discountList = ((_b = (_a = cartItem == null ? void 0 : cartItem._origin) == null ? void 0 : _a.product) == null ? void 0 : _b.discount_list) || [];
62
+ (((_d = (_c = cartItem == null ? void 0 : cartItem._origin) == null ? void 0 : _c.product) == null ? void 0 : _d.product_bundle) || []).forEach((item) => {
63
+ discountList = [...discountList, ...item.discount_list];
64
+ item.discount_list = void 0;
65
+ });
66
+ return discountList;
67
+ };
58
68
  // Annotate the CommonJS export names for ESM import in node:
59
69
  0 && (module.exports = {
60
70
  generateDuration,
71
+ getAllDiscountList,
61
72
  mergeRelationForms
62
73
  });
@@ -30,6 +30,13 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
30
30
  selectedList?: SetDiscountSelectedParams[];
31
31
  scan?: boolean;
32
32
  }): DiscountResult;
33
+ /**
34
+ * 检查优惠是否符合 PackageSubItemUsageRules 配置
35
+ * @param discount 优惠券
36
+ * @param flatItem 扁平化后的商品项(可能是主商品或bundle子商品)
37
+ * @returns 是否可用
38
+ */
39
+ private checkPackageSubItemUsageRules;
33
40
  destroy(): Promise<void>;
34
41
  clear(): Promise<void>;
35
42
  }