@pisell/pisellos 1.0.94 → 1.0.95

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.
@@ -64,7 +64,9 @@ export interface Product {
64
64
  surcharge_rounding_remainder?: number;
65
65
  main_product_selling_price: number;
66
66
  };
67
+ is_price_include_tax: 0 | 1;
67
68
  product_bundle: {
69
+ is_price_include_tax: 0 | 1;
68
70
  bundle_id: number;
69
71
  bundle_product_id: number;
70
72
  bundle_variant_id: number;
@@ -154,9 +154,9 @@ export function processVouchers(applicableVouchers, orderTotalAmount, products)
154
154
  if (allowCrossProduct) {
155
155
  // 跨商品券:可以抵扣多个商品
156
156
  if (applicableProductLimit > 0) {
157
- // 有数量限制:按单价从高到低排序,按动态计算的可抵扣数量累计直到达到 limit
157
+ // 有数量限制:按剩余金额从高到低排序,按动态计算的可抵扣数量累计直到达到 limit
158
158
  var sortedProducts = _toConsumableArray(applicableProducts).sort(function (a, b) {
159
- return a[unitPriceField].comparedTo(b[unitPriceField]) > 0 ? -1 : 1;
159
+ return a[amountField].comparedTo(b[amountField]) > 0 ? -1 : 1;
160
160
  });
161
161
  var remainingLimit = applicableProductLimit;
162
162
  var _iterator = _createForOfIteratorHelper(sortedProducts),
@@ -185,9 +185,9 @@ export function processVouchers(applicableVouchers, orderTotalAmount, products)
185
185
  }, new Decimal(0));
186
186
  }
187
187
  } else {
188
- // 非跨商品券:只能抵扣单个商品(单价最高的)
188
+ // 非跨商品券:只能抵扣单个商品(剩余金额最高的)
189
189
  var maxProduct = applicableProducts.reduce(function (max, p) {
190
- return p[unitPriceField].greaterThan(max[unitPriceField]) ? p : max;
190
+ return p[amountField].greaterThan(max[amountField]) ? p : max;
191
191
  });
192
192
  // 动态计算当前可抵扣数量
193
193
  var _currentAvailableQty = Math.ceil(maxProduct[amountField].dividedBy(maxProduct[unitPriceField]).toNumber());
@@ -337,8 +337,9 @@ export function processVouchers(applicableVouchers, orderTotalAmount, products)
337
337
  if (allowCrossProduct) {
338
338
  // 跨商品券:按 quantity 限制计算可抵扣金额
339
339
  if (applicableProductLimit > 0) {
340
+ // 按剩余金额从高到低排序
340
341
  var sortedProducts = _toConsumableArray(applicableProducts).sort(function (a, b) {
341
- return a[unitPriceField].comparedTo(b[unitPriceField]) > 0 ? -1 : 1;
342
+ return a[amountField].comparedTo(b[amountField]) > 0 ? -1 : 1;
342
343
  });
343
344
  var remainingLimit = applicableProductLimit;
344
345
  var _iterator2 = _createForOfIteratorHelper(sortedProducts),
@@ -367,9 +368,9 @@ export function processVouchers(applicableVouchers, orderTotalAmount, products)
367
368
  }, new Decimal(0));
368
369
  }
369
370
  } else {
370
- // 非跨商品券:单个最高单价商品,也受 applicableProductLimit 限制
371
+ // 非跨商品券:单个剩余金额最高的商品,也受 applicableProductLimit 限制
371
372
  var maxProduct = applicableProducts.reduce(function (max, p) {
372
- return p[unitPriceField].greaterThan(max[unitPriceField]) ? p : max;
373
+ return p[amountField].greaterThan(max[amountField]) ? p : max;
373
374
  });
374
375
  // 动态计算当前可抵扣数量
375
376
  var _currentAvailableQty2 = Math.ceil(maxProduct[amountField].dividedBy(maxProduct[unitPriceField]).toNumber());
@@ -387,9 +388,9 @@ export function processVouchers(applicableVouchers, orderTotalAmount, products)
387
388
  var deductionLeft = maxDeduction;
388
389
  var deductionDetails = [];
389
390
  if (allowCrossProduct) {
390
- // 跨商品券:按单价从高到低抵扣,受 applicableProductLimit 限制
391
+ // 跨商品券:按剩余金额从高到低抵扣,受 applicableProductLimit 限制
391
392
  var _sortedProducts = _toConsumableArray(applicableProducts).sort(function (a, b) {
392
- return a[unitPriceField].comparedTo(b[unitPriceField]) > 0 ? -1 : 1;
393
+ return a[amountField].comparedTo(b[amountField]) > 0 ? -1 : 1;
393
394
  });
394
395
  var _remainingLimit = applicableProductLimit > 0 ? applicableProductLimit : Infinity;
395
396
  var _iterator3 = _createForOfIteratorHelper(_sortedProducts),
@@ -429,9 +430,9 @@ export function processVouchers(applicableVouchers, orderTotalAmount, products)
429
430
  _iterator3.f();
430
431
  }
431
432
  } else {
432
- // 非跨商品券:只抵扣一个商品(单价最高的),也受 applicableProductLimit 限制
433
+ // 非跨商品券:只抵扣一个商品(剩余金额最高的),也受 applicableProductLimit 限制
433
434
  var targetProduct = applicableProducts.reduce(function (max, p) {
434
- return p[unitPriceField].greaterThan(max[unitPriceField]) ? p : max;
435
+ return p[amountField].greaterThan(max[amountField]) ? p : max;
435
436
  });
436
437
 
437
438
  // 动态计算当前可抵扣数量
@@ -583,9 +584,9 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
583
584
  var deductionLeft = maxDeduction;
584
585
  var deductionDetails = [];
585
586
  if (allowCrossProduct) {
586
- // 跨商品券:按单价从高到低抵扣,受 applicableProductLimit 限制
587
+ // 跨商品券:按剩余金额从高到低抵扣,受 applicableProductLimit 限制
587
588
  var sortedProducts = _toConsumableArray(applicableProducts).sort(function (a, b) {
588
- return a[unitPriceField].comparedTo(b[unitPriceField]) > 0 ? -1 : 1;
589
+ return a[amountField].comparedTo(b[amountField]) > 0 ? -1 : 1;
589
590
  });
590
591
  var remainingLimit = applicableProductLimit > 0 ? applicableProductLimit : Infinity;
591
592
  var _iterator4 = _createForOfIteratorHelper(sortedProducts),
@@ -625,9 +626,9 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
625
626
  _iterator4.f();
626
627
  }
627
628
  } else {
628
- // 非跨商品券:只抵扣一个商品(单价最高的),也受 applicableProductLimit 限制
629
+ // 非跨商品券:只抵扣一个商品(剩余金额最高的),也受 applicableProductLimit 限制
629
630
  var targetProduct = applicableProducts.reduce(function (max, p) {
630
- return p[unitPriceField].greaterThan(max[unitPriceField]) ? p : max;
631
+ return p[amountField].greaterThan(max[amountField]) ? p : max;
631
632
  });
632
633
 
633
634
  // 动态计算当前可抵扣数量
@@ -733,9 +734,9 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
733
734
  var baseAmount = Decimal.min(new Decimal(recommendedAmount), new Decimal(maxDeductionAmount));
734
735
  if (allowCrossProduct) {
735
736
  if (applicableProductLimit > 0) {
736
- // 按单价从高到低排序,按动态计算的可抵扣数量累计直到达到 limit
737
+ // 按剩余金额从高到低排序,按动态计算的可抵扣数量累计直到达到 limit
737
738
  var sortedProducts = _toConsumableArray(applicableProducts).sort(function (a, b) {
738
- return a[unitPriceField].comparedTo(b[unitPriceField]) > 0 ? -1 : 1;
739
+ return a[amountField].comparedTo(b[amountField]) > 0 ? -1 : 1;
739
740
  });
740
741
  var remainingLimit = applicableProductLimit;
741
742
  var _iterator5 = _createForOfIteratorHelper(sortedProducts),
@@ -764,9 +765,9 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
764
765
  }, new Decimal(0));
765
766
  }
766
767
  } else {
767
- // 非跨商品券:单个最高单价商品,也受 applicableProductLimit 限制
768
+ // 非跨商品券:单个剩余金额最高的商品,也受 applicableProductLimit 限制
768
769
  var maxProduct = applicableProducts.reduce(function (max, p) {
769
- return p[unitPriceField].greaterThan(max[unitPriceField]) ? p : max;
770
+ return p[amountField].greaterThan(max[amountField]) ? p : max;
770
771
  });
771
772
  // 动态计算当前可抵扣数量
772
773
  var _currentAvailableQty6 = Math.ceil(maxProduct[amountField].dividedBy(maxProduct[unitPriceField]).toNumber());
@@ -818,14 +819,17 @@ export var getMainProductPrice = function getMainProductPrice(product, isDeductT
818
819
  mainProductPrice = mainProductPrice.add(bundleItemPrice.times(bundleItem.num));
819
820
  }
820
821
  }
821
-
822
- // 税费
823
822
  } catch (err) {
824
823
  _iterator6.e(err);
825
824
  } finally {
826
825
  _iterator6.f();
827
826
  }
828
827
  var taxFee = new Decimal((product === null || product === void 0 ? void 0 : product.tax_fee) || (product === null || product === void 0 || (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2.main_product_attached_bundle_tax_fee) || 0);
828
+ if (product.is_price_include_tax === 1) {
829
+ taxFee = new Decimal(0);
830
+ }
831
+
832
+ // 税费
829
833
  // 附加费
830
834
  var surchargeFee = new Decimal((product === null || product === void 0 || (_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.main_product_attached_bundle_surcharge_fee) || 0).add((product === null || product === void 0 || (_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.surcharge_rounding_remainder) || 0);
831
835
 
@@ -857,6 +861,9 @@ export var getBundleItemPrice = function getBundleItemPrice(bundleItem, parentQu
857
861
  var _bundleItem$tax_fee, _bundleItem$metadata$, _bundleItem$metadata;
858
862
  // 税费
859
863
  var taxFee = new Decimal((_bundleItem$tax_fee = bundleItem.tax_fee) !== null && _bundleItem$tax_fee !== void 0 ? _bundleItem$tax_fee : 0).times(totalQuantity);
864
+ if (bundleItem.is_price_include_tax === 1) {
865
+ taxFee = new Decimal(0);
866
+ }
860
867
  // 附加费
861
868
  var surchargeFee = new Decimal((_bundleItem$metadata$ = (_bundleItem$metadata = bundleItem.metadata) === null || _bundleItem$metadata === void 0 ? void 0 : _bundleItem$metadata.surcharge_fee) !== null && _bundleItem$metadata$ !== void 0 ? _bundleItem$metadata$ : 0).times(totalQuantity);
862
869
  bundleItemPrice = bundleItemPrice.add(taxFee).add(surchargeFee);
@@ -16,7 +16,7 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
16
16
  getRulesList(): Rules[];
17
17
  private checkHolderMatch;
18
18
  getWalletPassEvaluator(): import("../..").WalletPassEvaluator | undefined;
19
- isDiscountListAvailable({ oldDiscountList, newDiscountList, productList, holders, orderTotalAmount, }: {
19
+ isDiscountListAvailable({ oldDiscountList, newDiscountList, productList, holders, orderTotalAmount, isFormSubject, }: {
20
20
  oldDiscountList: Discount[];
21
21
  newDiscountList: Discount[];
22
22
  productList: any[];
@@ -24,18 +24,20 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
24
24
  form_record_id: number;
25
25
  }[];
26
26
  orderTotalAmount: number;
27
+ isFormSubject: boolean;
27
28
  }): {
28
29
  isAvailable: boolean;
29
30
  discountList: Discount[];
30
31
  productList: any[];
31
32
  };
32
- calcDiscount({ discountList, productList, holders, orderTotalAmount }: {
33
+ calcDiscount({ discountList, productList, holders, orderTotalAmount, isFormSubject, }: {
33
34
  discountList: Discount[];
34
35
  productList: any[];
35
36
  holders: {
36
37
  form_record_id: number;
37
38
  }[];
38
39
  orderTotalAmount: number;
40
+ isFormSubject: boolean;
39
41
  }, options?: {
40
42
  isSelected?: boolean;
41
43
  discountId?: number;
@@ -130,7 +130,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
130
130
  newDiscountList = _ref.newDiscountList,
131
131
  productList = _ref.productList,
132
132
  holders = _ref.holders,
133
- orderTotalAmount = _ref.orderTotalAmount;
133
+ orderTotalAmount = _ref.orderTotalAmount,
134
+ isFormSubject = _ref.isFormSubject;
134
135
  // 首先检查是否有新的优惠券可应用
135
136
  if (!newDiscountList || newDiscountList.length === 0) {
136
137
  return {
@@ -162,7 +163,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
162
163
  discountList: mergedDiscountList,
163
164
  productList: _toConsumableArray(productList),
164
165
  holders: holders,
165
- orderTotalAmount: orderTotalAmount
166
+ orderTotalAmount: orderTotalAmount,
167
+ isFormSubject: isFormSubject
166
168
  }, {
167
169
  scan: true
168
170
  });
@@ -206,7 +208,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
206
208
  var discountList = _ref2.discountList,
207
209
  productList = _ref2.productList,
208
210
  holders = _ref2.holders,
209
- orderTotalAmount = _ref2.orderTotalAmount;
211
+ orderTotalAmount = _ref2.orderTotalAmount,
212
+ isFormSubject = _ref2.isFormSubject;
210
213
  // 识别出来是不是在编辑的界面里又新增了商品
211
214
  // 这种情况下,如果有可用的优惠券,也会自动勾选上
212
215
  var isEditModeAddNewProduct = productList.find(function (n) {
@@ -501,7 +504,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
501
504
  // 拿到discount配置的holder信息 product信息 product.holder 加在 isLimitedProduct
502
505
  var _tempVar = (flatItem === null || flatItem === void 0 ? void 0 : flatItem.type) === 'bundle' ? flatItem === null || flatItem === void 0 ? void 0 : flatItem.parentProduct : flatItem === null || flatItem === void 0 ? void 0 : flatItem.product;
503
506
  var isHolderMatch = _this3.checkHolderMatch(discount, {
504
- isNeedHolder: _tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.isNeedHolder,
507
+ isNeedHolder: isFormSubject && !(_tempVar !== null && _tempVar !== void 0 && _tempVar.isNormalProduct),
505
508
  holder_id: (_tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.holder_id) || product.holder_id
506
509
  }, holders);
507
510
  var timeLimit = true;
@@ -643,7 +646,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
643
646
  // 拿到discount配置的holder信息 product信息 product.holder 不可用return false
644
647
  var _tempVar = (flatItem === null || flatItem === void 0 ? void 0 : flatItem.type) === 'bundle' ? flatItem === null || flatItem === void 0 ? void 0 : flatItem.parentProduct : flatItem === null || flatItem === void 0 ? void 0 : flatItem.product;
645
648
  var isHolderMatch = _this3.checkHolderMatch(discount, {
646
- isNeedHolder: _tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.isNeedHolder,
649
+ isNeedHolder: isFormSubject && !(_tempVar !== null && _tempVar !== void 0 && _tempVar.isNormalProduct),
647
650
  holder_id: (_tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.holder_id) || product.holder_id
648
651
  }, holders);
649
652
  // 如果 holder 不匹配,则不适用
@@ -26,6 +26,7 @@ export interface RulesModuleAPI {
26
26
  form_record_id: number;
27
27
  }[];
28
28
  orderTotalAmount: number;
29
+ isFormSubject: boolean;
29
30
  }) => DiscountResult;
30
31
  }
31
32
  type ProductDetail = {
@@ -403,6 +403,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
403
403
  product_id: item.product_id,
404
404
  product_variant_id: item.product_variant_id,
405
405
  quantity: item.num,
406
+ is_price_include_tax: item.is_price_include_tax,
406
407
  // 商品是否含税:1;0
407
408
  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
  // 若商品不含税,计算得到的税费,单位(元)
@@ -427,6 +428,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
427
428
  },
428
429
  product_bundle: item.product_bundle.map(function (bundle) {
429
430
  return {
431
+ is_price_include_tax: item.is_price_include_tax,
430
432
  bundle_id: bundle.bundle_id,
431
433
  bundle_product_id: bundle.bundle_product_id,
432
434
  bundle_variant_id: bundle.bundle_variant_id,
@@ -25,6 +25,10 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
25
25
  setHolders(holders: {
26
26
  form_record_id: number;
27
27
  }[]): void;
28
+ setBookingSubject(bookingSubject: {
29
+ type?: 'form' | 'customer';
30
+ [key: string]: any;
31
+ }): void;
28
32
  calcDiscount(productList: Record<string, any>[], options?: SetDiscountSelectedParams): {
29
33
  productList: Record<string, any>[];
30
34
  discountList: Discount[];
@@ -55,7 +55,8 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
55
55
  originalDiscountList: [],
56
56
  currentBookingTime: "",
57
57
  filteredDiscountList: [],
58
- orderTotalAmount: 0
58
+ orderTotalAmount: 0,
59
+ bookingSubject: undefined
59
60
  };
60
61
  return _this;
61
62
  }
@@ -300,11 +301,17 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
300
301
  value: function setHolders(holders) {
301
302
  this.store.holders = holders;
302
303
  }
304
+ }, {
305
+ key: "setBookingSubject",
306
+ value: function setBookingSubject(bookingSubject) {
307
+ this.store.bookingSubject = bookingSubject;
308
+ }
303
309
 
304
310
  // 计算优惠券
305
311
  }, {
306
312
  key: "calcDiscount",
307
313
  value: function calcDiscount(productList, options) {
314
+ var _this$store$bookingSu;
308
315
  this.store.productList = productList;
309
316
  var rulesModule = this.core.getModule("".concat(this.name, "_rules"));
310
317
  if (!rulesModule) {
@@ -317,7 +324,8 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
317
324
  productList: productList,
318
325
  discountList: this.getDiscountList(),
319
326
  holders: this.store.holders || [],
320
- orderTotalAmount: this.store.orderTotalAmount || 0
327
+ orderTotalAmount: this.store.orderTotalAmount || 0,
328
+ isFormSubject: ((_this$store$bookingSu = this.store.bookingSubject) === null || _this$store$bookingSu === void 0 ? void 0 : _this$store$bookingSu.type) === 'form'
321
329
  }, options) || {
322
330
  productList: productList,
323
331
  discountList: this.getDiscountList()
@@ -390,7 +398,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
390
398
  key: "scanCode",
391
399
  value: function () {
392
400
  var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(code, customerId) {
393
- var _this$store$discount3, resultDiscountList, rulesModule, withScanList, currentSelectedDiscountList, _ref2, newProductList, newDiscountList, isAvailable, _this$options$otherPa6;
401
+ var _this$store$discount3, _this$store$bookingSu2, resultDiscountList, rulesModule, withScanList, currentSelectedDiscountList, _ref2, newProductList, newDiscountList, isAvailable, _this$options$otherPa6;
394
402
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
395
403
  while (1) switch (_context5.prev = _context5.next) {
396
404
  case 0:
@@ -457,7 +465,8 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
457
465
  oldDiscountList: this.getDiscountList(),
458
466
  newDiscountList: withScanList,
459
467
  holders: this.store.holders || [],
460
- orderTotalAmount: this.store.orderTotalAmount || 0
468
+ orderTotalAmount: this.store.orderTotalAmount || 0,
469
+ isFormSubject: ((_this$store$bookingSu2 = this.store.bookingSubject) === null || _this$store$bookingSu2 === void 0 ? void 0 : _this$store$bookingSu2.type) === 'form'
461
470
  }) || {
462
471
  isAvailable: false,
463
472
  productList: this.store.productList || [],
@@ -32,6 +32,10 @@ export interface ShopDiscountState {
32
32
  currentBookingTime: string | null;
33
33
  filteredDiscountList: Discount[];
34
34
  orderTotalAmount?: number;
35
+ bookingSubject?: {
36
+ type?: 'form' | 'customer';
37
+ [key: string]: any;
38
+ };
35
39
  }
36
40
  export interface SetDiscountSelectedParams {
37
41
  discountId: number;
@@ -64,7 +64,9 @@ export interface Product {
64
64
  surcharge_rounding_remainder?: number;
65
65
  main_product_selling_price: number;
66
66
  };
67
+ is_price_include_tax: 0 | 1;
67
68
  product_bundle: {
69
+ is_price_include_tax: 0 | 1;
68
70
  bundle_id: number;
69
71
  bundle_product_id: number;
70
72
  bundle_variant_id: number;
@@ -103,7 +103,7 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
103
103
  let finalApplicableAmount = new import_decimal.default(0);
104
104
  if (allowCrossProduct) {
105
105
  if (applicableProductLimit > 0) {
106
- const sortedProducts = [...applicableProducts].sort((a, b) => a[unitPriceField].comparedTo(b[unitPriceField]) > 0 ? -1 : 1);
106
+ const sortedProducts = [...applicableProducts].sort((a, b) => a[amountField].comparedTo(b[amountField]) > 0 ? -1 : 1);
107
107
  let remainingLimit = applicableProductLimit;
108
108
  for (const product of sortedProducts) {
109
109
  if (remainingLimit <= 0)
@@ -125,7 +125,7 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
125
125
  }
126
126
  } else {
127
127
  const maxProduct = applicableProducts.reduce(
128
- (max, p) => p[unitPriceField].greaterThan(max[unitPriceField]) ? p : max
128
+ (max, p) => p[amountField].greaterThan(max[amountField]) ? p : max
129
129
  );
130
130
  const currentAvailableQty = Math.ceil(maxProduct[amountField].dividedBy(maxProduct[unitPriceField]).toNumber());
131
131
  const deductQty = applicableProductLimit > 0 ? Math.min(currentAvailableQty, applicableProductLimit) : currentAvailableQty;
@@ -208,7 +208,7 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
208
208
  let calculatedAvailableMaxAmount = new import_decimal.default(0);
209
209
  if (allowCrossProduct) {
210
210
  if (applicableProductLimit > 0) {
211
- const sortedProducts = [...applicableProducts].sort((a, b) => a[unitPriceField].comparedTo(b[unitPriceField]) > 0 ? -1 : 1);
211
+ const sortedProducts = [...applicableProducts].sort((a, b) => a[amountField].comparedTo(b[amountField]) > 0 ? -1 : 1);
212
212
  let remainingLimit = applicableProductLimit;
213
213
  for (const product of sortedProducts) {
214
214
  if (remainingLimit <= 0)
@@ -230,7 +230,7 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
230
230
  }
231
231
  } else {
232
232
  const maxProduct = applicableProducts.reduce(
233
- (max, p) => p[unitPriceField].greaterThan(max[unitPriceField]) ? p : max
233
+ (max, p) => p[amountField].greaterThan(max[amountField]) ? p : max
234
234
  );
235
235
  const currentAvailableQty = Math.ceil(maxProduct[amountField].dividedBy(maxProduct[unitPriceField]).toNumber());
236
236
  const deductQty = applicableProductLimit > 0 ? Math.min(currentAvailableQty, applicableProductLimit) : currentAvailableQty;
@@ -252,7 +252,7 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
252
252
  const deductionDetails = [];
253
253
  if (allowCrossProduct) {
254
254
  const sortedProducts = [...applicableProducts].sort(
255
- (a, b) => a[unitPriceField].comparedTo(b[unitPriceField]) > 0 ? -1 : 1
255
+ (a, b) => a[amountField].comparedTo(b[amountField]) > 0 ? -1 : 1
256
256
  );
257
257
  let remainingLimit = applicableProductLimit > 0 ? applicableProductLimit : Infinity;
258
258
  for (const product of sortedProducts) {
@@ -281,7 +281,7 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
281
281
  }
282
282
  } else {
283
283
  const targetProduct = applicableProducts.reduce(
284
- (max, p) => p[unitPriceField].greaterThan(max[unitPriceField]) ? p : max
284
+ (max, p) => p[amountField].greaterThan(max[amountField]) ? p : max
285
285
  );
286
286
  const currentAvailableQty = Math.ceil(targetProduct[amountField].dividedBy(targetProduct[unitPriceField]).toNumber());
287
287
  const availableQty = applicableProductLimit > 0 ? Math.min(currentAvailableQty, applicableProductLimit) : currentAvailableQty;
@@ -378,7 +378,7 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
378
378
  const deductionDetails = [];
379
379
  if (allowCrossProduct) {
380
380
  const sortedProducts = [...applicableProducts].sort(
381
- (a, b) => a[unitPriceField].comparedTo(b[unitPriceField]) > 0 ? -1 : 1
381
+ (a, b) => a[amountField].comparedTo(b[amountField]) > 0 ? -1 : 1
382
382
  );
383
383
  let remainingLimit = applicableProductLimit > 0 ? applicableProductLimit : Infinity;
384
384
  for (const product of sortedProducts) {
@@ -407,7 +407,7 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
407
407
  }
408
408
  } else {
409
409
  const targetProduct = applicableProducts.reduce(
410
- (max, p) => p[unitPriceField].greaterThan(max[unitPriceField]) ? p : max
410
+ (max, p) => p[amountField].greaterThan(max[amountField]) ? p : max
411
411
  );
412
412
  const currentAvailableQty = Math.ceil(targetProduct[amountField].dividedBy(targetProduct[unitPriceField]).toNumber());
413
413
  const availableQty = applicableProductLimit > 0 ? Math.min(currentAvailableQty, applicableProductLimit) : currentAvailableQty;
@@ -490,7 +490,7 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
490
490
  );
491
491
  if (allowCrossProduct) {
492
492
  if (applicableProductLimit > 0) {
493
- const sortedProducts = [...applicableProducts].sort((a, b) => a[unitPriceField].comparedTo(b[unitPriceField]) > 0 ? -1 : 1);
493
+ const sortedProducts = [...applicableProducts].sort((a, b) => a[amountField].comparedTo(b[amountField]) > 0 ? -1 : 1);
494
494
  let remainingLimit = applicableProductLimit;
495
495
  for (const product of sortedProducts) {
496
496
  if (remainingLimit <= 0)
@@ -512,7 +512,7 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
512
512
  }
513
513
  } else {
514
514
  const maxProduct = applicableProducts.reduce(
515
- (max, p) => p[unitPriceField].greaterThan(max[unitPriceField]) ? p : max
515
+ (max, p) => p[amountField].greaterThan(max[amountField]) ? p : max
516
516
  );
517
517
  const currentAvailableQty = Math.ceil(maxProduct[amountField].dividedBy(maxProduct[unitPriceField]).toNumber());
518
518
  const deductQty = applicableProductLimit > 0 ? Math.min(currentAvailableQty, applicableProductLimit) : currentAvailableQty;
@@ -555,7 +555,10 @@ var getMainProductPrice = (product, isDeductTaxAndFee) => {
555
555
  mainProductPrice = mainProductPrice.add(bundleItemPrice.times(bundleItem.num));
556
556
  }
557
557
  }
558
- const taxFee = new import_decimal.default((product == null ? void 0 : product.tax_fee) || ((_b = product == null ? void 0 : product.metadata) == null ? void 0 : _b.main_product_attached_bundle_tax_fee) || 0);
558
+ let taxFee = new import_decimal.default((product == null ? void 0 : product.tax_fee) || ((_b = product == null ? void 0 : product.metadata) == null ? void 0 : _b.main_product_attached_bundle_tax_fee) || 0);
559
+ if (product.is_price_include_tax === 1) {
560
+ taxFee = new import_decimal.default(0);
561
+ }
559
562
  const surchargeFee = new import_decimal.default(((_c = product == null ? void 0 : product.metadata) == null ? void 0 : _c.main_product_attached_bundle_surcharge_fee) || 0).add(((_d = product == null ? void 0 : product.metadata) == null ? void 0 : _d.surcharge_rounding_remainder) || 0);
560
563
  const taxAndFeeTotal = taxFee.add(surchargeFee);
561
564
  if (isDeductTaxAndFee) {
@@ -568,7 +571,10 @@ var getBundleItemPrice = (bundleItem, parentQuantity, isDeductTaxAndFee) => {
568
571
  const totalQuantity = bundleItem.num * parentQuantity;
569
572
  let bundleItemPrice = new import_decimal.default(bundleItem.bundle_selling_price ?? 0).times(totalQuantity);
570
573
  if (isDeductTaxAndFee) {
571
- const taxFee = new import_decimal.default(bundleItem.tax_fee ?? 0).times(totalQuantity);
574
+ let taxFee = new import_decimal.default(bundleItem.tax_fee ?? 0).times(totalQuantity);
575
+ if (bundleItem.is_price_include_tax === 1) {
576
+ taxFee = new import_decimal.default(0);
577
+ }
572
578
  const surchargeFee = new import_decimal.default(((_a = bundleItem.metadata) == null ? void 0 : _a.surcharge_fee) ?? 0).times(totalQuantity);
573
579
  bundleItemPrice = bundleItemPrice.add(taxFee).add(surchargeFee);
574
580
  }
@@ -16,7 +16,7 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
16
16
  getRulesList(): Rules[];
17
17
  private checkHolderMatch;
18
18
  getWalletPassEvaluator(): import("../..").WalletPassEvaluator | undefined;
19
- isDiscountListAvailable({ oldDiscountList, newDiscountList, productList, holders, orderTotalAmount, }: {
19
+ isDiscountListAvailable({ oldDiscountList, newDiscountList, productList, holders, orderTotalAmount, isFormSubject, }: {
20
20
  oldDiscountList: Discount[];
21
21
  newDiscountList: Discount[];
22
22
  productList: any[];
@@ -24,18 +24,20 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
24
24
  form_record_id: number;
25
25
  }[];
26
26
  orderTotalAmount: number;
27
+ isFormSubject: boolean;
27
28
  }): {
28
29
  isAvailable: boolean;
29
30
  discountList: Discount[];
30
31
  productList: any[];
31
32
  };
32
- calcDiscount({ discountList, productList, holders, orderTotalAmount }: {
33
+ calcDiscount({ discountList, productList, holders, orderTotalAmount, isFormSubject, }: {
33
34
  discountList: Discount[];
34
35
  productList: any[];
35
36
  holders: {
36
37
  form_record_id: number;
37
38
  }[];
38
39
  orderTotalAmount: number;
40
+ isFormSubject: boolean;
39
41
  }, options?: {
40
42
  isSelected?: boolean;
41
43
  discountId?: number;
@@ -81,7 +81,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
81
81
  newDiscountList,
82
82
  productList,
83
83
  holders,
84
- orderTotalAmount
84
+ orderTotalAmount,
85
+ isFormSubject
85
86
  }) {
86
87
  if (!newDiscountList || newDiscountList.length === 0) {
87
88
  return {
@@ -112,7 +113,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
112
113
  discountList: mergedDiscountList,
113
114
  productList: [...productList],
114
115
  holders,
115
- orderTotalAmount
116
+ orderTotalAmount,
117
+ isFormSubject
116
118
  }, {
117
119
  scan: true
118
120
  });
@@ -146,7 +148,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
146
148
  discountList,
147
149
  productList,
148
150
  holders,
149
- orderTotalAmount
151
+ orderTotalAmount,
152
+ isFormSubject
150
153
  }, options) {
151
154
  const isEditModeAddNewProduct = productList.find((n) => n.booking_id) && productList.find((n) => !n.booking_id);
152
155
  const editModeDiscount = [];
@@ -344,7 +347,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
344
347
  const isHolderMatch = this.checkHolderMatch(
345
348
  discount,
346
349
  {
347
- isNeedHolder: _tempVar == null ? void 0 : _tempVar.isNeedHolder,
350
+ isNeedHolder: isFormSubject && !(_tempVar == null ? void 0 : _tempVar.isNormalProduct),
348
351
  holder_id: (_tempVar == null ? void 0 : _tempVar.holder_id) || product.holder_id
349
352
  },
350
353
  holders
@@ -465,7 +468,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
465
468
  const isHolderMatch = this.checkHolderMatch(
466
469
  discount,
467
470
  {
468
- isNeedHolder: _tempVar == null ? void 0 : _tempVar.isNeedHolder,
471
+ isNeedHolder: isFormSubject && !(_tempVar == null ? void 0 : _tempVar.isNormalProduct),
469
472
  holder_id: (_tempVar == null ? void 0 : _tempVar.holder_id) || product.holder_id
470
473
  },
471
474
  holders
@@ -26,6 +26,7 @@ export interface RulesModuleAPI {
26
26
  form_record_id: number;
27
27
  }[];
28
28
  orderTotalAmount: number;
29
+ isFormSubject: boolean;
29
30
  }) => DiscountResult;
30
31
  }
31
32
  type ProductDetail = {
@@ -122,6 +122,12 @@ var BookingTicketImpl = class extends import_BaseModule.BaseModule {
122
122
  throw error;
123
123
  }
124
124
  }
125
+ /**
126
+ * 初始化外设扫码结果监听
127
+ */
128
+ initPeripheralsListener() {
129
+ this.scan.initPeripheralsListener();
130
+ }
125
131
  /**
126
132
  * 获取商品列表(不加载到模块中)
127
133
  * @returns 商品列表
@@ -222,6 +222,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
222
222
  product_id: item.product_id,
223
223
  product_variant_id: item.product_variant_id,
224
224
  quantity: item.num,
225
+ is_price_include_tax: item.is_price_include_tax,
225
226
  // 商品是否含税:1;0
226
227
  is_charge_tax: item.is_charge_tax ?? 0,
227
228
  // 若商品不含税,计算得到的税费,单位(元)
@@ -246,6 +247,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
246
247
  },
247
248
  product_bundle: item.product_bundle.map((bundle) => {
248
249
  return {
250
+ is_price_include_tax: item.is_price_include_tax,
249
251
  bundle_id: bundle.bundle_id,
250
252
  bundle_product_id: bundle.bundle_product_id,
251
253
  bundle_variant_id: bundle.bundle_variant_id,
@@ -25,6 +25,10 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
25
25
  setHolders(holders: {
26
26
  form_record_id: number;
27
27
  }[]): void;
28
+ setBookingSubject(bookingSubject: {
29
+ type?: 'form' | 'customer';
30
+ [key: string]: any;
31
+ }): void;
28
32
  calcDiscount(productList: Record<string, any>[], options?: SetDiscountSelectedParams): {
29
33
  productList: Record<string, any>[];
30
34
  discountList: Discount[];
@@ -55,7 +55,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
55
55
  originalDiscountList: [],
56
56
  currentBookingTime: "",
57
57
  filteredDiscountList: [],
58
- orderTotalAmount: 0
58
+ orderTotalAmount: 0,
59
+ bookingSubject: void 0
59
60
  };
60
61
  }
61
62
  // =========== 生命周期方法 ===========
@@ -200,8 +201,12 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
200
201
  setHolders(holders) {
201
202
  this.store.holders = holders;
202
203
  }
204
+ setBookingSubject(bookingSubject) {
205
+ this.store.bookingSubject = bookingSubject;
206
+ }
203
207
  // 计算优惠券
204
208
  calcDiscount(productList, options) {
209
+ var _a;
205
210
  this.store.productList = productList;
206
211
  const rulesModule = this.core.getModule(`${this.name}_rules`);
207
212
  if (!rulesModule) {
@@ -212,7 +217,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
212
217
  productList,
213
218
  discountList: this.getDiscountList(),
214
219
  holders: this.store.holders || [],
215
- orderTotalAmount: this.store.orderTotalAmount || 0
220
+ orderTotalAmount: this.store.orderTotalAmount || 0,
221
+ isFormSubject: ((_a = this.store.bookingSubject) == null ? void 0 : _a.type) === "form"
216
222
  },
217
223
  options
218
224
  ) || { productList, discountList: this.getDiscountList() };
@@ -259,7 +265,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
259
265
  }
260
266
  // 扫码输入code
261
267
  async scanCode(code, customerId) {
262
- var _a, _b;
268
+ var _a, _b, _c;
263
269
  try {
264
270
  const resultDiscountList = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, customerId)) || [];
265
271
  const rulesModule = this.store.rules;
@@ -303,7 +309,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
303
309
  oldDiscountList: this.getDiscountList(),
304
310
  newDiscountList: withScanList,
305
311
  holders: this.store.holders || [],
306
- orderTotalAmount: this.store.orderTotalAmount || 0
312
+ orderTotalAmount: this.store.orderTotalAmount || 0,
313
+ isFormSubject: ((_b = this.store.bookingSubject) == null ? void 0 : _b.type) === "form"
307
314
  }) || {
308
315
  isAvailable: false,
309
316
  productList: this.store.productList || [],
@@ -313,7 +320,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
313
320
  this.setDiscountList(newDiscountList || []);
314
321
  this.store.originalDiscountList = newDiscountList || [];
315
322
  this.setProductList(newProductList || []);
316
- if (this.isWalkIn() && resultDiscountList.length && ((_b = this.options.otherParams) == null ? void 0 : _b.platform) === "shop") {
323
+ if (this.isWalkIn() && resultDiscountList.length && ((_c = this.options.otherParams) == null ? void 0 : _c.platform) === "shop") {
317
324
  await this.getCustomerWallet(
318
325
  resultDiscountList[0].customer_id
319
326
  );
@@ -32,6 +32,10 @@ export interface ShopDiscountState {
32
32
  currentBookingTime: string | null;
33
33
  filteredDiscountList: Discount[];
34
34
  orderTotalAmount?: number;
35
+ bookingSubject?: {
36
+ type?: 'form' | 'customer';
37
+ [key: string]: any;
38
+ };
35
39
  }
36
40
  export interface SetDiscountSelectedParams {
37
41
  discountId: number;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "1.0.94",
4
+ "version": "1.0.95",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",