@pisell/pisellos 0.0.478 → 0.0.479
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.
|
@@ -125,13 +125,14 @@ export function processVouchers(applicableVouchers, orderTotalAmount, products)
|
|
|
125
125
|
return ((_usageMap$get = usageMap.get(walletPassProductId)) === null || _usageMap$get === void 0 ? void 0 : _usageMap$get.get(orderItemProductId)) || 0;
|
|
126
126
|
};
|
|
127
127
|
|
|
128
|
-
// 更新指定 Wallet Pass 商品对指定订单商品行的已用卡券次数
|
|
128
|
+
// 更新指定 Wallet Pass 商品对指定订单商品行的已用卡券次数
|
|
129
129
|
var incrementItemPassUsage = function incrementItemPassUsage(usageMap, walletPassProductId, orderItemProductId) {
|
|
130
|
+
var count = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
|
|
130
131
|
if (!usageMap.has(walletPassProductId)) {
|
|
131
132
|
usageMap.set(walletPassProductId, new Map());
|
|
132
133
|
}
|
|
133
134
|
var innerMap = usageMap.get(walletPassProductId);
|
|
134
|
-
innerMap.set(orderItemProductId, (innerMap.get(orderItemProductId) || 0) +
|
|
135
|
+
innerMap.set(orderItemProductId, (innerMap.get(orderItemProductId) || 0) + count);
|
|
135
136
|
};
|
|
136
137
|
|
|
137
138
|
// 按 maxPassesPerItem 过滤商品:排除已达到单商品可用卡券上限的商品
|
|
@@ -222,8 +223,12 @@ export function processVouchers(applicableVouchers, orderTotalAmount, products)
|
|
|
222
223
|
var maxProduct = applicableProducts.reduce(function (max, p) {
|
|
223
224
|
return p[amountField].greaterThan(max[amountField]) ? p : max;
|
|
224
225
|
});
|
|
225
|
-
//
|
|
226
|
-
|
|
226
|
+
// maxPassesPerItem 限制每张券最多抵扣的单位数
|
|
227
|
+
if (maxPassesPerItem > 0) {
|
|
228
|
+
finalApplicableAmount = Decimal.min(maxProduct[unitPriceField].times(maxPassesPerItem), maxProduct[amountField]);
|
|
229
|
+
} else {
|
|
230
|
+
finalApplicableAmount = maxProduct[amountField];
|
|
231
|
+
}
|
|
227
232
|
}
|
|
228
233
|
|
|
229
234
|
// 返回最小值
|
|
@@ -427,8 +432,12 @@ export function processVouchers(applicableVouchers, orderTotalAmount, products)
|
|
|
427
432
|
var maxProduct = applicableProducts.reduce(function (max, p) {
|
|
428
433
|
return p[amountField].greaterThan(max[amountField]) ? p : max;
|
|
429
434
|
});
|
|
430
|
-
//
|
|
431
|
-
|
|
435
|
+
// maxPassesPerItem 限制每张券最多抵扣的单位数
|
|
436
|
+
if (maxPassesPerItem > 0) {
|
|
437
|
+
calculatedAvailableMaxAmount = Decimal.min(maxProduct[unitPriceField].times(maxPassesPerItem), maxProduct[amountField]);
|
|
438
|
+
} else {
|
|
439
|
+
calculatedAvailableMaxAmount = maxProduct[amountField];
|
|
440
|
+
}
|
|
432
441
|
}
|
|
433
442
|
|
|
434
443
|
// 取最小值:min(recommended_usage_amount, maxDeductionAmount, 适用商品金额, 订单剩余金额)
|
|
@@ -483,11 +492,16 @@ export function processVouchers(applicableVouchers, orderTotalAmount, products)
|
|
|
483
492
|
}
|
|
484
493
|
} else {
|
|
485
494
|
// 非跨商品券:只抵扣一个商品(剩余金额最高的)
|
|
486
|
-
// allowCrossProduct=false 时,applicableProductLimit 不生效
|
|
487
495
|
var targetProduct = applicableProducts.reduce(function (max, p) {
|
|
488
496
|
return p[amountField].greaterThan(max[amountField]) ? p : max;
|
|
489
497
|
});
|
|
490
|
-
|
|
498
|
+
|
|
499
|
+
// maxPassesPerItem 限制每张券最多抵扣的单位数
|
|
500
|
+
var _maxDeductForProduct = targetProduct[amountField];
|
|
501
|
+
if (maxPassesPerItem > 0) {
|
|
502
|
+
_maxDeductForProduct = Decimal.min(targetProduct[unitPriceField].times(maxPassesPerItem), targetProduct[amountField]);
|
|
503
|
+
}
|
|
504
|
+
var _actualDeductAmount = Decimal.min(deductionLeft, _maxDeductForProduct);
|
|
491
505
|
|
|
492
506
|
// 计算实际抵扣的数量
|
|
493
507
|
var _actualDeductQty = Math.ceil(_actualDeductAmount.dividedBy(targetProduct[unitPriceField]).toNumber());
|
|
@@ -511,9 +525,9 @@ export function processVouchers(applicableVouchers, orderTotalAmount, products)
|
|
|
511
525
|
// 更新券使用次数(按 product_id 统计)
|
|
512
526
|
usedVoucherCounts.set(product_id, (usedVoucherCounts.get(product_id) || 0) + 1);
|
|
513
527
|
|
|
514
|
-
// 更新 maxPassesPerItem
|
|
528
|
+
// 更新 maxPassesPerItem 追踪:按实际抵扣数量递增
|
|
515
529
|
deductionDetails.forEach(function (detail) {
|
|
516
|
-
incrementItemPassUsage(itemPassUsageMap, product_id, detail.product_id);
|
|
530
|
+
incrementItemPassUsage(itemPassUsageMap, product_id, detail.product_id, detail.deductQuantity);
|
|
517
531
|
});
|
|
518
532
|
|
|
519
533
|
// 添加到推荐列表(包含基于当前剩余金额计算的 available_max_amount)
|
|
@@ -605,11 +619,12 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
|
|
|
605
619
|
return ((_itemPassUsageMap$get = itemPassUsageMap.get(walletPassProductId)) === null || _itemPassUsageMap$get === void 0 ? void 0 : _itemPassUsageMap$get.get(orderItemProductId)) || 0;
|
|
606
620
|
};
|
|
607
621
|
var incrementItemPassUsage = function incrementItemPassUsage(walletPassProductId, orderItemProductId) {
|
|
622
|
+
var count = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
608
623
|
if (!itemPassUsageMap.has(walletPassProductId)) {
|
|
609
624
|
itemPassUsageMap.set(walletPassProductId, new Map());
|
|
610
625
|
}
|
|
611
626
|
var innerMap = itemPassUsageMap.get(walletPassProductId);
|
|
612
|
-
innerMap.set(orderItemProductId, (innerMap.get(orderItemProductId) || 0) +
|
|
627
|
+
innerMap.set(orderItemProductId, (innerMap.get(orderItemProductId) || 0) + count);
|
|
613
628
|
};
|
|
614
629
|
var filterByMaxPassesPerItem = function filterByMaxPassesPerItem(products, walletPassProductId, maxPassesPerItem) {
|
|
615
630
|
if (maxPassesPerItem <= 0) return products; // 0 = 不限制
|
|
@@ -703,11 +718,16 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
|
|
|
703
718
|
}
|
|
704
719
|
} else {
|
|
705
720
|
// 非跨商品券:只抵扣一个商品(剩余金额最高的)
|
|
706
|
-
// allowCrossProduct=false 时,applicableProductLimit 不生效
|
|
707
721
|
var targetProduct = applicableProducts.reduce(function (max, p) {
|
|
708
722
|
return p[amountField].greaterThan(max[amountField]) ? p : max;
|
|
709
723
|
});
|
|
710
|
-
|
|
724
|
+
|
|
725
|
+
// maxPassesPerItem 限制每张券最多抵扣的单位数
|
|
726
|
+
var _maxDeductForProduct2 = targetProduct[amountField];
|
|
727
|
+
if (maxPassesPerItem > 0) {
|
|
728
|
+
_maxDeductForProduct2 = Decimal.min(targetProduct[unitPriceField].times(maxPassesPerItem), targetProduct[amountField]);
|
|
729
|
+
}
|
|
730
|
+
var _actualDeductAmount2 = Decimal.min(deductionLeft, _maxDeductForProduct2);
|
|
711
731
|
|
|
712
732
|
// 计算实际抵扣的数量
|
|
713
733
|
var _actualDeductQty2 = Math.ceil(_actualDeductAmount2.dividedBy(targetProduct[unitPriceField]).toNumber());
|
|
@@ -728,9 +748,9 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
|
|
|
728
748
|
// 更新订单剩余金额
|
|
729
749
|
remainingOrderAmount = remainingOrderAmount.minus(totalDeducted);
|
|
730
750
|
|
|
731
|
-
// 更新 maxPassesPerItem
|
|
751
|
+
// 更新 maxPassesPerItem 追踪:按实际抵扣数量递增
|
|
732
752
|
deductionDetails.forEach(function (detail) {
|
|
733
|
-
incrementItemPassUsage(selectedVoucher.product_id, detail.product_id);
|
|
753
|
+
incrementItemPassUsage(selectedVoucher.product_id, detail.product_id, detail.deductQuantity);
|
|
734
754
|
});
|
|
735
755
|
selectedWithDetails.push(_objectSpread(_objectSpread({}, selectedVoucher), {}, {
|
|
736
756
|
actualDeduction: totalDeducted.toNumber(),
|
|
@@ -845,11 +865,15 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
|
|
|
845
865
|
}
|
|
846
866
|
} else {
|
|
847
867
|
// 非跨商品券:单个剩余金额最高的商品
|
|
848
|
-
// allowCrossProduct=false 时,applicableProductLimit 不生效
|
|
849
868
|
var maxProduct = applicableProducts.reduce(function (max, p) {
|
|
850
869
|
return p[amountField].greaterThan(max[amountField]) ? p : max;
|
|
851
870
|
});
|
|
852
|
-
|
|
871
|
+
// maxPassesPerItem 限制每张券最多抵扣的单位数
|
|
872
|
+
if (maxPassesPerItem > 0) {
|
|
873
|
+
calculatedMaxAmount = Decimal.min(maxProduct[unitPriceField].times(maxPassesPerItem), maxProduct[amountField]);
|
|
874
|
+
} else {
|
|
875
|
+
calculatedMaxAmount = maxProduct[amountField];
|
|
876
|
+
}
|
|
853
877
|
}
|
|
854
878
|
calculatedMaxAmount = Decimal.min(baseAmount, calculatedMaxAmount, remainingOrderAmount);
|
|
855
879
|
if (calculatedMaxAmount.lessThanOrEqualTo(0)) {
|
|
@@ -94,12 +94,12 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
|
|
|
94
94
|
var _a;
|
|
95
95
|
return ((_a = usageMap.get(walletPassProductId)) == null ? void 0 : _a.get(orderItemProductId)) || 0;
|
|
96
96
|
};
|
|
97
|
-
const incrementItemPassUsage = (usageMap, walletPassProductId, orderItemProductId) => {
|
|
97
|
+
const incrementItemPassUsage = (usageMap, walletPassProductId, orderItemProductId, count = 1) => {
|
|
98
98
|
if (!usageMap.has(walletPassProductId)) {
|
|
99
99
|
usageMap.set(walletPassProductId, /* @__PURE__ */ new Map());
|
|
100
100
|
}
|
|
101
101
|
const innerMap = usageMap.get(walletPassProductId);
|
|
102
|
-
innerMap.set(orderItemProductId, (innerMap.get(orderItemProductId) || 0) +
|
|
102
|
+
innerMap.set(orderItemProductId, (innerMap.get(orderItemProductId) || 0) + count);
|
|
103
103
|
};
|
|
104
104
|
const filterByMaxPassesPerItem = (products2, usageMap, walletPassProductId, maxPassesPerItem) => {
|
|
105
105
|
if (maxPassesPerItem <= 0)
|
|
@@ -152,7 +152,14 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
|
|
|
152
152
|
const maxProduct = applicableProducts.reduce(
|
|
153
153
|
(max, p) => p[amountField].greaterThan(max[amountField]) ? p : max
|
|
154
154
|
);
|
|
155
|
-
|
|
155
|
+
if (maxPassesPerItem > 0) {
|
|
156
|
+
finalApplicableAmount = import_decimal.default.min(
|
|
157
|
+
maxProduct[unitPriceField].times(maxPassesPerItem),
|
|
158
|
+
maxProduct[amountField]
|
|
159
|
+
);
|
|
160
|
+
} else {
|
|
161
|
+
finalApplicableAmount = maxProduct[amountField];
|
|
162
|
+
}
|
|
156
163
|
}
|
|
157
164
|
return import_decimal.default.min(baseAmount, finalApplicableAmount, remainingOrderAmount);
|
|
158
165
|
};
|
|
@@ -264,7 +271,14 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
|
|
|
264
271
|
const maxProduct = applicableProducts.reduce(
|
|
265
272
|
(max, p) => p[amountField].greaterThan(max[amountField]) ? p : max
|
|
266
273
|
);
|
|
267
|
-
|
|
274
|
+
if (maxPassesPerItem > 0) {
|
|
275
|
+
calculatedAvailableMaxAmount = import_decimal.default.min(
|
|
276
|
+
maxProduct[unitPriceField].times(maxPassesPerItem),
|
|
277
|
+
maxProduct[amountField]
|
|
278
|
+
);
|
|
279
|
+
} else {
|
|
280
|
+
calculatedAvailableMaxAmount = maxProduct[amountField];
|
|
281
|
+
}
|
|
268
282
|
}
|
|
269
283
|
const availableMaxAmount = import_decimal.default.min(
|
|
270
284
|
baseAmount,
|
|
@@ -310,7 +324,14 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
|
|
|
310
324
|
const targetProduct = applicableProducts.reduce(
|
|
311
325
|
(max, p) => p[amountField].greaterThan(max[amountField]) ? p : max
|
|
312
326
|
);
|
|
313
|
-
|
|
327
|
+
let maxDeductForProduct = targetProduct[amountField];
|
|
328
|
+
if (maxPassesPerItem > 0) {
|
|
329
|
+
maxDeductForProduct = import_decimal.default.min(
|
|
330
|
+
targetProduct[unitPriceField].times(maxPassesPerItem),
|
|
331
|
+
targetProduct[amountField]
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
const actualDeductAmount = import_decimal.default.min(deductionLeft, maxDeductForProduct);
|
|
314
335
|
const actualDeductQty = Math.ceil(actualDeductAmount.dividedBy(targetProduct[unitPriceField]).toNumber());
|
|
315
336
|
targetProduct[amountField] = targetProduct[amountField].minus(actualDeductAmount);
|
|
316
337
|
deductionLeft = deductionLeft.minus(actualDeductAmount);
|
|
@@ -327,7 +348,7 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
|
|
|
327
348
|
remainingOrderAmount = remainingOrderAmount.minus(totalDeducted);
|
|
328
349
|
usedVoucherCounts.set(product_id, (usedVoucherCounts.get(product_id) || 0) + 1);
|
|
329
350
|
deductionDetails.forEach((detail) => {
|
|
330
|
-
incrementItemPassUsage(itemPassUsageMap, product_id, detail.product_id);
|
|
351
|
+
incrementItemPassUsage(itemPassUsageMap, product_id, detail.product_id, detail.deductQuantity);
|
|
331
352
|
});
|
|
332
353
|
recommendedVouchers.push({
|
|
333
354
|
...voucher,
|
|
@@ -375,12 +396,12 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
|
|
|
375
396
|
var _a;
|
|
376
397
|
return ((_a = itemPassUsageMap.get(walletPassProductId)) == null ? void 0 : _a.get(orderItemProductId)) || 0;
|
|
377
398
|
};
|
|
378
|
-
const incrementItemPassUsage = (walletPassProductId, orderItemProductId) => {
|
|
399
|
+
const incrementItemPassUsage = (walletPassProductId, orderItemProductId, count = 1) => {
|
|
379
400
|
if (!itemPassUsageMap.has(walletPassProductId)) {
|
|
380
401
|
itemPassUsageMap.set(walletPassProductId, /* @__PURE__ */ new Map());
|
|
381
402
|
}
|
|
382
403
|
const innerMap = itemPassUsageMap.get(walletPassProductId);
|
|
383
|
-
innerMap.set(orderItemProductId, (innerMap.get(orderItemProductId) || 0) +
|
|
404
|
+
innerMap.set(orderItemProductId, (innerMap.get(orderItemProductId) || 0) + count);
|
|
384
405
|
};
|
|
385
406
|
const filterByMaxPassesPerItem = (products2, walletPassProductId, maxPassesPerItem) => {
|
|
386
407
|
if (maxPassesPerItem <= 0)
|
|
@@ -451,7 +472,14 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
|
|
|
451
472
|
const targetProduct = applicableProducts.reduce(
|
|
452
473
|
(max, p) => p[amountField].greaterThan(max[amountField]) ? p : max
|
|
453
474
|
);
|
|
454
|
-
|
|
475
|
+
let maxDeductForProduct = targetProduct[amountField];
|
|
476
|
+
if (maxPassesPerItem > 0) {
|
|
477
|
+
maxDeductForProduct = import_decimal.default.min(
|
|
478
|
+
targetProduct[unitPriceField].times(maxPassesPerItem),
|
|
479
|
+
targetProduct[amountField]
|
|
480
|
+
);
|
|
481
|
+
}
|
|
482
|
+
const actualDeductAmount = import_decimal.default.min(deductionLeft, maxDeductForProduct);
|
|
455
483
|
const actualDeductQty = Math.ceil(actualDeductAmount.dividedBy(targetProduct[unitPriceField]).toNumber());
|
|
456
484
|
targetProduct[amountField] = targetProduct[amountField].minus(actualDeductAmount);
|
|
457
485
|
deductionLeft = deductionLeft.minus(actualDeductAmount);
|
|
@@ -466,7 +494,7 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
|
|
|
466
494
|
const totalDeducted = maxDeduction.minus(deductionLeft);
|
|
467
495
|
remainingOrderAmount = remainingOrderAmount.minus(totalDeducted);
|
|
468
496
|
deductionDetails.forEach((detail) => {
|
|
469
|
-
incrementItemPassUsage(selectedVoucher.product_id, detail.product_id);
|
|
497
|
+
incrementItemPassUsage(selectedVoucher.product_id, detail.product_id, detail.deductQuantity);
|
|
470
498
|
});
|
|
471
499
|
selectedWithDetails.push({
|
|
472
500
|
...selectedVoucher,
|
|
@@ -552,7 +580,14 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
|
|
|
552
580
|
const maxProduct = applicableProducts.reduce(
|
|
553
581
|
(max, p) => p[amountField].greaterThan(max[amountField]) ? p : max
|
|
554
582
|
);
|
|
555
|
-
|
|
583
|
+
if (maxPassesPerItem > 0) {
|
|
584
|
+
calculatedMaxAmount = import_decimal.default.min(
|
|
585
|
+
maxProduct[unitPriceField].times(maxPassesPerItem),
|
|
586
|
+
maxProduct[amountField]
|
|
587
|
+
);
|
|
588
|
+
} else {
|
|
589
|
+
calculatedMaxAmount = maxProduct[amountField];
|
|
590
|
+
}
|
|
556
591
|
}
|
|
557
592
|
calculatedMaxAmount = import_decimal.default.min(
|
|
558
593
|
baseAmount,
|