@pisell/pisellos 0.0.291 → 0.0.292
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.
- package/dist/modules/Payment/index.js +18 -7
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/Checkout/index.js +42 -33
- package/lib/modules/Payment/index.js +9 -1
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/Checkout/index.js +8 -6
- package/package.json +1 -1
|
@@ -2037,7 +2037,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2037
2037
|
key: "roundAmountAsync",
|
|
2038
2038
|
value: function () {
|
|
2039
2039
|
var _roundAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(originalAmount, interval, rule) {
|
|
2040
|
-
var amount, roundingInterval, supportedIntervals, intervalValue, baseValue, roundedValue, finalAmount,
|
|
2040
|
+
var amount, roundingInterval, supportedIntervals, intervalValue, baseValue, roundedValue, finalAmount, originalAmountStr, roundedAmountStr, roundingDifference, roundingDifferenceStr;
|
|
2041
2041
|
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
2042
2042
|
while (1) switch (_context26.prev = _context26.next) {
|
|
2043
2043
|
case 0:
|
|
@@ -2085,8 +2085,19 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2085
2085
|
case 22:
|
|
2086
2086
|
// 计算最终金额:roundedValue * interval
|
|
2087
2087
|
finalAmount = roundedValue.mul(roundingInterval);
|
|
2088
|
-
|
|
2089
|
-
|
|
2088
|
+
originalAmountStr = amount.toFixed(2); // 如果最终金额是 0 元,则不采用舍入金额,返回原始金额
|
|
2089
|
+
if (!finalAmount.eq(0)) {
|
|
2090
|
+
_context26.next = 27;
|
|
2091
|
+
break;
|
|
2092
|
+
}
|
|
2093
|
+
console.log("[PaymentModule] \u6700\u7EC8\u91D1\u989D\u4E3A0\uFF0C\u8FD4\u56DE\u539F\u59CB\u91D1\u989D: ".concat(originalAmountStr));
|
|
2094
|
+
return _context26.abrupt("return", {
|
|
2095
|
+
originalAmount: originalAmountStr,
|
|
2096
|
+
roundedAmount: originalAmountStr,
|
|
2097
|
+
roundingDifference: '0.00'
|
|
2098
|
+
});
|
|
2099
|
+
case 27:
|
|
2100
|
+
roundedAmountStr = finalAmount.toFixed(2); // 计算舍入差额
|
|
2090
2101
|
roundingDifference = finalAmount.sub(amount);
|
|
2091
2102
|
roundingDifferenceStr = roundingDifference.toFixed(2);
|
|
2092
2103
|
console.log("[PaymentModule] \u820D\u5165\u7ED3\u679C - \u539F\u59CB\u91D1\u989D: ".concat(originalAmountStr, ", \u820D\u5165\u540E\u91D1\u989D: ").concat(roundedAmountStr, ", \u820D\u5165\u5DEE\u989D: ").concat(roundingDifferenceStr));
|
|
@@ -2095,16 +2106,16 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2095
2106
|
roundedAmount: roundedAmountStr,
|
|
2096
2107
|
roundingDifference: roundingDifferenceStr
|
|
2097
2108
|
});
|
|
2098
|
-
case
|
|
2099
|
-
_context26.prev =
|
|
2109
|
+
case 34:
|
|
2110
|
+
_context26.prev = 34;
|
|
2100
2111
|
_context26.t1 = _context26["catch"](0);
|
|
2101
2112
|
console.error('[PaymentModule] 金额舍入失败:', _context26.t1);
|
|
2102
2113
|
throw new Error("\u91D1\u989D\u820D\u5165\u5931\u8D25: ".concat(_context26.t1 instanceof Error ? _context26.t1.message : String(_context26.t1)));
|
|
2103
|
-
case
|
|
2114
|
+
case 38:
|
|
2104
2115
|
case "end":
|
|
2105
2116
|
return _context26.stop();
|
|
2106
2117
|
}
|
|
2107
|
-
}, _callee26, this, [[0,
|
|
2118
|
+
}, _callee26, this, [[0, 34]]);
|
|
2108
2119
|
}));
|
|
2109
2120
|
function roundAmountAsync(_x28, _x29, _x30) {
|
|
2110
2121
|
return _roundAmountAsync.apply(this, arguments);
|
|
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
|
|
|
49
49
|
getCategories(): ProductCategory[];
|
|
50
50
|
setOtherParams(key: string, value: any): void;
|
|
51
51
|
getOtherParams(): any;
|
|
52
|
-
getProductType(): "
|
|
52
|
+
getProductType(): "normal" | "duration" | "session";
|
|
53
53
|
}
|
|
@@ -326,7 +326,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
326
326
|
};
|
|
327
327
|
setOtherData(key: string, value: any): void;
|
|
328
328
|
getOtherData(key: string): any;
|
|
329
|
-
getProductTypeById(id: number): Promise<"
|
|
329
|
+
getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
|
|
330
330
|
/**
|
|
331
331
|
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
332
332
|
*
|
|
@@ -573,7 +573,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
573
573
|
|
|
574
574
|
// 自动设置 stateAmount 为剩余未支付金额
|
|
575
575
|
_context9.next = 27;
|
|
576
|
-
return this.updateStateAmountToRemaining();
|
|
576
|
+
return this.updateStateAmountToRemaining(false);
|
|
577
577
|
case 27:
|
|
578
578
|
this.logInfo('本地订单创建成功:', {
|
|
579
579
|
localOrderId: localOrderId,
|
|
@@ -717,7 +717,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
717
717
|
case 31:
|
|
718
718
|
this.store.currentOrder = updated;
|
|
719
719
|
_context10.next = 34;
|
|
720
|
-
return this.updateStateAmountToRemaining();
|
|
720
|
+
return this.updateStateAmountToRemaining(false);
|
|
721
721
|
case 34:
|
|
722
722
|
this.logInfo('本地订单更新成功(保留支付项):', {
|
|
723
723
|
orderId: params.orderId,
|
|
@@ -1455,7 +1455,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1455
1455
|
value: (function () {
|
|
1456
1456
|
var _updateVoucherPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(voucherPaymentItems) {
|
|
1457
1457
|
var _this3 = this;
|
|
1458
|
-
var remainingAmount, remainingValue, isOrderSynced, orderPaymentType, voucherPaymentItemsWithType, currentOrderId, isCurrentOrderReal, updatedOrder;
|
|
1458
|
+
var paymentItems, allPaymentItemsSynced, remainingAmount, remainingValue, isOrderSynced, orderPaymentType, voucherPaymentItemsWithType, currentOrderId, isCurrentOrderReal, updatedOrder;
|
|
1459
1459
|
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
1460
1460
|
while (1) switch (_context18.prev = _context18.next) {
|
|
1461
1461
|
case 0:
|
|
@@ -1467,13 +1467,20 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1467
1467
|
throw createCheckoutError(CheckoutErrorType.ValidationFailed, '当前没有活跃订单,无法更新代金券支付项');
|
|
1468
1468
|
case 3:
|
|
1469
1469
|
_context18.next = 5;
|
|
1470
|
-
return this.
|
|
1470
|
+
return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
|
|
1471
1471
|
case 5:
|
|
1472
|
+
paymentItems = _context18.sent;
|
|
1473
|
+
allPaymentItemsSynced = paymentItems.every(function (item) {
|
|
1474
|
+
return item.isSynced;
|
|
1475
|
+
});
|
|
1476
|
+
_context18.next = 9;
|
|
1477
|
+
return this.calculateRemainingAmountAsync();
|
|
1478
|
+
case 9:
|
|
1472
1479
|
remainingAmount = _context18.sent;
|
|
1473
1480
|
remainingValue = new Decimal(remainingAmount);
|
|
1474
1481
|
isOrderSynced = this.store.isOrderSynced;
|
|
1475
|
-
if (!(remainingValue.lte(0) && isOrderSynced && voucherPaymentItems.length === 0)) {
|
|
1476
|
-
_context18.next =
|
|
1482
|
+
if (!(remainingValue.lte(0) && isOrderSynced && voucherPaymentItems.length === 0 && allPaymentItemsSynced)) {
|
|
1483
|
+
_context18.next = 15;
|
|
1477
1484
|
break;
|
|
1478
1485
|
}
|
|
1479
1486
|
this.logInfo('订单已同步且支付完成,跳过清空代金券操作避免重复同步:', {
|
|
@@ -1485,7 +1492,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1485
1492
|
reason: 'Order synced and payment completed, skip clear vouchers to avoid duplicate sync'
|
|
1486
1493
|
});
|
|
1487
1494
|
return _context18.abrupt("return");
|
|
1488
|
-
case
|
|
1495
|
+
case 15:
|
|
1489
1496
|
this.logInfo('开始批量更新代金券支付项:', {
|
|
1490
1497
|
voucherPaymentItems: voucherPaymentItems
|
|
1491
1498
|
});
|
|
@@ -1507,15 +1514,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1507
1514
|
metadata: metadata
|
|
1508
1515
|
});
|
|
1509
1516
|
}); // 调用 Payment 模块的批量更新方法
|
|
1510
|
-
_context18.next =
|
|
1517
|
+
_context18.next = 20;
|
|
1511
1518
|
return this.payment.updateVoucherPaymentItemsAsync(this.store.currentOrder.uuid, voucherPaymentItemsWithType);
|
|
1512
|
-
case
|
|
1519
|
+
case 20:
|
|
1513
1520
|
// 重新从Payment模块获取最新的订单数据,确保支付项同步
|
|
1514
1521
|
currentOrderId = this.store.currentOrder.order_id; // 保存当前的订单ID
|
|
1515
1522
|
isCurrentOrderReal = currentOrderId && !isVirtualOrderId(currentOrderId);
|
|
1516
|
-
_context18.next =
|
|
1523
|
+
_context18.next = 24;
|
|
1517
1524
|
return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
|
|
1518
|
-
case
|
|
1525
|
+
case 24:
|
|
1519
1526
|
updatedOrder = _context18.sent;
|
|
1520
1527
|
if (updatedOrder) {
|
|
1521
1528
|
// 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
|
|
@@ -1530,10 +1537,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1530
1537
|
}
|
|
1531
1538
|
|
|
1532
1539
|
// 更新 stateAmount 为剩余未支付金额
|
|
1533
|
-
_context18.next =
|
|
1540
|
+
_context18.next = 28;
|
|
1534
1541
|
return this.updateStateAmountToRemaining(false);
|
|
1535
|
-
case
|
|
1536
|
-
_context18.next =
|
|
1542
|
+
case 28:
|
|
1543
|
+
_context18.next = 30;
|
|
1537
1544
|
return this.core.effects.emit(CheckoutHooks.OnPaymentStarted, {
|
|
1538
1545
|
orderUuid: this.store.currentOrder.uuid,
|
|
1539
1546
|
paymentMethodCode: 'VOUCHER_BATCH',
|
|
@@ -1542,23 +1549,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1542
1549
|
}, 0).toFixed(2),
|
|
1543
1550
|
timestamp: Date.now()
|
|
1544
1551
|
});
|
|
1545
|
-
case
|
|
1552
|
+
case 30:
|
|
1546
1553
|
this.logInfo('代金券支付项批量更新成功');
|
|
1547
|
-
_context18.next =
|
|
1554
|
+
_context18.next = 39;
|
|
1548
1555
|
break;
|
|
1549
|
-
case
|
|
1550
|
-
_context18.prev =
|
|
1556
|
+
case 33:
|
|
1557
|
+
_context18.prev = 33;
|
|
1551
1558
|
_context18.t0 = _context18["catch"](0);
|
|
1552
1559
|
this.logError('[Checkout] 批量更新代金券支付项失败:', _context18.t0);
|
|
1553
|
-
_context18.next =
|
|
1560
|
+
_context18.next = 38;
|
|
1554
1561
|
return this.handleError(_context18.t0, CheckoutErrorType.PaymentFailed);
|
|
1555
|
-
case
|
|
1562
|
+
case 38:
|
|
1556
1563
|
throw _context18.t0;
|
|
1557
|
-
case
|
|
1564
|
+
case 39:
|
|
1558
1565
|
case "end":
|
|
1559
1566
|
return _context18.stop();
|
|
1560
1567
|
}
|
|
1561
|
-
}, _callee18, this, [[0,
|
|
1568
|
+
}, _callee18, this, [[0, 33]]);
|
|
1562
1569
|
}));
|
|
1563
1570
|
function updateVoucherPaymentItemsAsync(_x17) {
|
|
1564
1571
|
return _updateVoucherPaymentItemsAsync.apply(this, arguments);
|
|
@@ -2876,27 +2883,29 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2876
2883
|
_context34.next = 9;
|
|
2877
2884
|
return this.updateBalanceDueAmount();
|
|
2878
2885
|
case 9:
|
|
2879
|
-
if (checkOrder) {
|
|
2880
|
-
_context34.next =
|
|
2886
|
+
if (!checkOrder) {
|
|
2887
|
+
_context34.next = 14;
|
|
2881
2888
|
break;
|
|
2882
2889
|
}
|
|
2883
|
-
|
|
2884
|
-
return _context34.abrupt("return");
|
|
2885
|
-
case 12:
|
|
2886
|
-
_context34.next = 14;
|
|
2890
|
+
_context34.next = 12;
|
|
2887
2891
|
return this.checkOrderPaymentCompletion();
|
|
2892
|
+
case 12:
|
|
2893
|
+
_context34.next = 15;
|
|
2894
|
+
break;
|
|
2888
2895
|
case 14:
|
|
2889
|
-
|
|
2896
|
+
this.logInfo('外部传入无需 checkOrder,不执行订单支付完成检测和同步');
|
|
2897
|
+
case 15:
|
|
2898
|
+
_context34.next = 20;
|
|
2890
2899
|
break;
|
|
2891
|
-
case
|
|
2892
|
-
_context34.prev =
|
|
2900
|
+
case 17:
|
|
2901
|
+
_context34.prev = 17;
|
|
2893
2902
|
_context34.t0 = _context34["catch"](1);
|
|
2894
2903
|
this.logError('更新 stateAmount 为剩余金额失败:', _context34.t0);
|
|
2895
|
-
case
|
|
2904
|
+
case 20:
|
|
2896
2905
|
case "end":
|
|
2897
2906
|
return _context34.stop();
|
|
2898
2907
|
}
|
|
2899
|
-
}, _callee34, this, [[1,
|
|
2908
|
+
}, _callee34, this, [[1, 17]]);
|
|
2900
2909
|
}));
|
|
2901
2910
|
function updateStateAmountToRemaining() {
|
|
2902
2911
|
return _updateStateAmountToRemaining.apply(this, arguments);
|
|
@@ -1056,8 +1056,16 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
1056
1056
|
throw new Error(`不支持的舍入规则: ${rule}`);
|
|
1057
1057
|
}
|
|
1058
1058
|
const finalAmount = roundedValue.mul(roundingInterval);
|
|
1059
|
-
const roundedAmountStr = finalAmount.toFixed(2);
|
|
1060
1059
|
const originalAmountStr = amount.toFixed(2);
|
|
1060
|
+
if (finalAmount.eq(0)) {
|
|
1061
|
+
console.log(`[PaymentModule] 最终金额为0,返回原始金额: ${originalAmountStr}`);
|
|
1062
|
+
return {
|
|
1063
|
+
originalAmount: originalAmountStr,
|
|
1064
|
+
roundedAmount: originalAmountStr,
|
|
1065
|
+
roundingDifference: "0.00"
|
|
1066
|
+
};
|
|
1067
|
+
}
|
|
1068
|
+
const roundedAmountStr = finalAmount.toFixed(2);
|
|
1061
1069
|
const roundingDifference = finalAmount.sub(amount);
|
|
1062
1070
|
const roundingDifferenceStr = roundingDifference.toFixed(2);
|
|
1063
1071
|
console.log(`[PaymentModule] 舍入结果 - 原始金额: ${originalAmountStr}, 舍入后金额: ${roundedAmountStr}, 舍入差额: ${roundingDifferenceStr}`);
|
|
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
|
|
|
49
49
|
getCategories(): ProductCategory[];
|
|
50
50
|
setOtherParams(key: string, value: any): void;
|
|
51
51
|
getOtherParams(): any;
|
|
52
|
-
getProductType(): "
|
|
52
|
+
getProductType(): "normal" | "duration" | "session";
|
|
53
53
|
}
|
|
@@ -326,7 +326,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
326
326
|
};
|
|
327
327
|
setOtherData(key: string, value: any): void;
|
|
328
328
|
getOtherData(key: string): any;
|
|
329
|
-
getProductTypeById(id: number): Promise<"
|
|
329
|
+
getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
|
|
330
330
|
/**
|
|
331
331
|
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
332
332
|
*
|
|
@@ -342,7 +342,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
342
342
|
order: paymentOrder,
|
|
343
343
|
timestamp: Date.now()
|
|
344
344
|
});
|
|
345
|
-
await this.updateStateAmountToRemaining();
|
|
345
|
+
await this.updateStateAmountToRemaining(false);
|
|
346
346
|
this.logInfo("本地订单创建成功:", {
|
|
347
347
|
localOrderId,
|
|
348
348
|
uuid: paymentOrder.uuid,
|
|
@@ -439,7 +439,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
439
439
|
if (!updated)
|
|
440
440
|
throw (0, import_utils.createCheckoutError)(import_types.CheckoutErrorType.UnknownError, "订单更新失败");
|
|
441
441
|
this.store.currentOrder = updated;
|
|
442
|
-
await this.updateStateAmountToRemaining();
|
|
442
|
+
await this.updateStateAmountToRemaining(false);
|
|
443
443
|
this.logInfo("本地订单更新成功(保留支付项):", {
|
|
444
444
|
orderId: params.orderId,
|
|
445
445
|
uuid: updated.uuid,
|
|
@@ -908,10 +908,12 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
908
908
|
"当前没有活跃订单,无法更新代金券支付项"
|
|
909
909
|
);
|
|
910
910
|
}
|
|
911
|
+
const paymentItems = await this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
|
|
912
|
+
const allPaymentItemsSynced = paymentItems.every((item) => item.isSynced);
|
|
911
913
|
const remainingAmount = await this.calculateRemainingAmountAsync();
|
|
912
914
|
const remainingValue = new import_decimal.default(remainingAmount);
|
|
913
915
|
const isOrderSynced = this.store.isOrderSynced;
|
|
914
|
-
if (remainingValue.lte(0) && isOrderSynced && voucherPaymentItems.length === 0) {
|
|
916
|
+
if (remainingValue.lte(0) && isOrderSynced && voucherPaymentItems.length === 0 && allPaymentItemsSynced) {
|
|
915
917
|
this.logInfo("订单已同步且支付完成,跳过清空代金券操作避免重复同步:", {
|
|
916
918
|
orderUuid: this.store.currentOrder.uuid,
|
|
917
919
|
orderId: this.store.currentOrder.order_id,
|
|
@@ -1776,11 +1778,11 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1776
1778
|
});
|
|
1777
1779
|
}
|
|
1778
1780
|
await this.updateBalanceDueAmount();
|
|
1779
|
-
if (
|
|
1781
|
+
if (checkOrder) {
|
|
1782
|
+
await this.checkOrderPaymentCompletion();
|
|
1783
|
+
} else {
|
|
1780
1784
|
this.logInfo("外部传入无需 checkOrder,不执行订单支付完成检测和同步");
|
|
1781
|
-
return;
|
|
1782
1785
|
}
|
|
1783
|
-
await this.checkOrderPaymentCompletion();
|
|
1784
1786
|
} catch (error) {
|
|
1785
1787
|
this.logError("更新 stateAmount 为剩余金额失败:", error);
|
|
1786
1788
|
}
|