@pisell/pisellos 0.0.247 → 0.0.249
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 +22 -4
- package/dist/modules/Payment/types.d.ts +9 -0
- package/dist/solution/Checkout/index.js +148 -113
- package/lib/modules/Payment/index.js +14 -4
- package/lib/modules/Payment/types.d.ts +9 -0
- package/lib/solution/Checkout/index.js +64 -40
- package/package.json +1 -1
|
@@ -1750,9 +1750,16 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1750
1750
|
if (payment.status === 'voided') {
|
|
1751
1751
|
return sum;
|
|
1752
1752
|
}
|
|
1753
|
-
|
|
1753
|
+
|
|
1754
|
+
// 计算有效支付金额:支付金额 + 抹零金额的绝对值
|
|
1755
|
+
// 当 rounding_amount 为负数时,表示抹掉的金额,按绝对值计算有效支付
|
|
1756
|
+
// 例如:amount=15, rounding_amount=-0.2,有效支付=15.2(抹掉0.2元零头)
|
|
1757
|
+
var paymentAmount = new Decimal(payment.amount || 0);
|
|
1758
|
+
var roundingAmount = new Decimal(payment.rounding_amount || 0);
|
|
1759
|
+
var effectiveAmount = paymentAmount.plus(roundingAmount.abs());
|
|
1760
|
+
return sum.plus(effectiveAmount);
|
|
1754
1761
|
} catch (error) {
|
|
1755
|
-
console.warn("[PaymentModule] \u65E0\u6548\u7684\u652F\u4ED8\u91D1\u989D: ".concat(payment.amount, "\uFF0C\u8DF3\u8FC7\u8BA1\u7B97"));
|
|
1762
|
+
console.warn("[PaymentModule] \u65E0\u6548\u7684\u652F\u4ED8\u91D1\u989D: amount=".concat(payment.amount, ", rounding_amount=").concat(payment.rounding_amount, "\uFF0C\u8DF3\u8FC7\u8BA1\u7B97"));
|
|
1756
1763
|
return sum;
|
|
1757
1764
|
}
|
|
1758
1765
|
}, new Decimal(0));
|
|
@@ -1761,14 +1768,25 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1761
1768
|
console.log("[PaymentModule] \u91CD\u65B0\u8BA1\u7B97\u8BA2\u5355\u91D1\u989D:", {
|
|
1762
1769
|
orderUuid: order.uuid,
|
|
1763
1770
|
totalAmount: order.total_amount,
|
|
1764
|
-
|
|
1771
|
+
effectivePaidAmount: paidAmount.toFixed(2),
|
|
1765
1772
|
remainingAmount: order.expect_amount,
|
|
1766
1773
|
activePayments: order.payment.filter(function (p) {
|
|
1767
1774
|
return p.status !== 'voided';
|
|
1768
1775
|
}).length,
|
|
1769
1776
|
voidedPayments: order.payment.filter(function (p) {
|
|
1770
1777
|
return p.status === 'voided';
|
|
1771
|
-
}).length
|
|
1778
|
+
}).length,
|
|
1779
|
+
paymentDetails: order.payment.filter(function (p) {
|
|
1780
|
+
return p.status !== 'voided';
|
|
1781
|
+
}).map(function (p) {
|
|
1782
|
+
return {
|
|
1783
|
+
code: p.code,
|
|
1784
|
+
amount: p.amount,
|
|
1785
|
+
rounding_amount: p.rounding_amount || '0.00',
|
|
1786
|
+
effective_amount: new Decimal(p.amount || 0).plus(new Decimal(p.rounding_amount || 0).abs()).toFixed(2)
|
|
1787
|
+
};
|
|
1788
|
+
}),
|
|
1789
|
+
说明: '有效支付金额包含抹零计算(amount + |rounding_amount|)'
|
|
1772
1790
|
});
|
|
1773
1791
|
}
|
|
1774
1792
|
|
|
@@ -222,6 +222,15 @@ export interface PaymentItemInput {
|
|
|
222
222
|
rounding_amount?: string;
|
|
223
223
|
/** 订单支付类型 */
|
|
224
224
|
order_payment_type?: 'normal' | 'deposit';
|
|
225
|
+
/** 扩展参数字段 */
|
|
226
|
+
metadata?: {
|
|
227
|
+
/** 钱箱 ID */
|
|
228
|
+
shop_wallet_pass_id?: string;
|
|
229
|
+
/** 唯一支付号 */
|
|
230
|
+
unique_payment_number?: string;
|
|
231
|
+
/** rounding规则 */
|
|
232
|
+
rounding_rule?: any;
|
|
233
|
+
};
|
|
225
234
|
}
|
|
226
235
|
/**
|
|
227
236
|
* 推送支付项参数
|
|
@@ -1660,7 +1660,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1660
1660
|
key: "addPaymentItemAsync",
|
|
1661
1661
|
value: (function () {
|
|
1662
1662
|
var _addPaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(paymentItem) {
|
|
1663
|
-
var _paymentItem$type, _paymentItem$code, orderPaymentType, paymentItemWithType, isEftposPayment;
|
|
1663
|
+
var _paymentItem$type, _paymentItem$code, orderPaymentType, metadata, paymentItemWithType, isEftposPayment;
|
|
1664
1664
|
return _regeneratorRuntime().wrap(function _callee25$(_context25) {
|
|
1665
1665
|
while (1) switch (_context25.prev = _context25.next) {
|
|
1666
1666
|
case 0:
|
|
@@ -1672,9 +1672,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1672
1672
|
throw createCheckoutError(CheckoutErrorType.ValidationFailed, '未找到当前订单,无法添加支付项');
|
|
1673
1673
|
case 3:
|
|
1674
1674
|
// 根据当前订单的定金状态设置订单支付类型
|
|
1675
|
-
orderPaymentType = this.store.currentOrder.is_deposit === 1 ? 'deposit' : 'normal'; //
|
|
1675
|
+
orderPaymentType = this.store.currentOrder.is_deposit === 1 ? 'deposit' : 'normal'; // 从 otherParams 获取 metadata 字段
|
|
1676
|
+
metadata = _objectSpread(_objectSpread({}, paymentItem.metadata), {}, {
|
|
1677
|
+
rounding_rule: this.otherParams.order_rounding_setting,
|
|
1678
|
+
shop_wallet_pass_id: this.otherParams.shop_wallet_pass_id
|
|
1679
|
+
}); // 设置支付项的订单支付类型和 metadata
|
|
1676
1680
|
paymentItemWithType = _objectSpread(_objectSpread({}, paymentItem), {}, {
|
|
1677
|
-
order_payment_type: orderPaymentType
|
|
1681
|
+
order_payment_type: orderPaymentType,
|
|
1682
|
+
metadata: metadata
|
|
1678
1683
|
});
|
|
1679
1684
|
console.log('[Checkout] 为当前订单添加支付项:', {
|
|
1680
1685
|
orderUuid: this.store.currentOrder.uuid,
|
|
@@ -1686,16 +1691,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1686
1691
|
service_charge: paymentItemWithType.service_charge,
|
|
1687
1692
|
rounding_amount: paymentItemWithType.rounding_amount,
|
|
1688
1693
|
voucher_id: paymentItemWithType.voucher_id,
|
|
1689
|
-
order_payment_type: paymentItemWithType.order_payment_type
|
|
1694
|
+
order_payment_type: paymentItemWithType.order_payment_type,
|
|
1695
|
+
metadata: paymentItemWithType.metadata
|
|
1690
1696
|
},
|
|
1691
1697
|
orderDepositStatus: this.store.currentOrder.is_deposit,
|
|
1692
1698
|
calculatedOrderPaymentType: orderPaymentType
|
|
1693
1699
|
});
|
|
1694
1700
|
|
|
1695
1701
|
// 添加支付项到订单
|
|
1696
|
-
_context25.next =
|
|
1702
|
+
_context25.next = 9;
|
|
1697
1703
|
return this.payment.addPaymentItemAsync(this.store.currentOrder.uuid, paymentItemWithType);
|
|
1698
|
-
case
|
|
1704
|
+
case 9:
|
|
1699
1705
|
console.log('[Checkout] 支付项添加成功');
|
|
1700
1706
|
|
|
1701
1707
|
// 检查是否是 EFTPOS 支付,如果是则立即同步订单
|
|
@@ -1707,54 +1713,54 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1707
1713
|
currentOrderSynced: this.store.isOrderSynced
|
|
1708
1714
|
});
|
|
1709
1715
|
if (!isEftposPayment) {
|
|
1710
|
-
_context25.next =
|
|
1716
|
+
_context25.next = 25;
|
|
1711
1717
|
break;
|
|
1712
1718
|
}
|
|
1713
1719
|
console.log('[Checkout] 检测到 EFTPOS 支付,立即同步订单到后端...');
|
|
1714
|
-
_context25.prev =
|
|
1715
|
-
_context25.next =
|
|
1720
|
+
_context25.prev = 14;
|
|
1721
|
+
_context25.next = 17;
|
|
1716
1722
|
return this.syncOrderToBackendWithReturn(true);
|
|
1717
|
-
case
|
|
1723
|
+
case 17:
|
|
1718
1724
|
console.log('[Checkout] EFTPOS 支付后订单同步完成 (已标记为手动同步):', {
|
|
1719
1725
|
订单ID: this.store.currentOrder.order_id,
|
|
1720
1726
|
是否已同步: this.store.isOrderSynced
|
|
1721
1727
|
});
|
|
1722
|
-
_context25.next =
|
|
1728
|
+
_context25.next = 25;
|
|
1723
1729
|
break;
|
|
1724
|
-
case
|
|
1725
|
-
_context25.prev =
|
|
1726
|
-
_context25.t0 = _context25["catch"](
|
|
1730
|
+
case 20:
|
|
1731
|
+
_context25.prev = 20;
|
|
1732
|
+
_context25.t0 = _context25["catch"](14);
|
|
1727
1733
|
console.error('[Checkout] EFTPOS 支付后订单同步失败:', _context25.t0);
|
|
1728
1734
|
// 不抛出错误,避免影响支付流程,但记录错误
|
|
1729
|
-
_context25.next =
|
|
1735
|
+
_context25.next = 25;
|
|
1730
1736
|
return this.handleError(new Error("EFTPOS \u652F\u4ED8\u540E\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(_context25.t0 instanceof Error ? _context25.t0.message : String(_context25.t0))), CheckoutErrorType.OrderCreationFailed);
|
|
1731
|
-
case
|
|
1732
|
-
_context25.next =
|
|
1737
|
+
case 25:
|
|
1738
|
+
_context25.next = 27;
|
|
1733
1739
|
return this.updateStateAmountToRemaining();
|
|
1734
|
-
case
|
|
1735
|
-
_context25.next =
|
|
1740
|
+
case 27:
|
|
1741
|
+
_context25.next = 29;
|
|
1736
1742
|
return this.core.effects.emit(CheckoutHooks.OnPaymentStarted, {
|
|
1737
1743
|
orderUuid: this.store.currentOrder.uuid,
|
|
1738
1744
|
paymentMethodCode: paymentItem.code,
|
|
1739
1745
|
amount: String(paymentItem.amount),
|
|
1740
1746
|
timestamp: Date.now()
|
|
1741
1747
|
});
|
|
1742
|
-
case
|
|
1743
|
-
_context25.next =
|
|
1748
|
+
case 29:
|
|
1749
|
+
_context25.next = 37;
|
|
1744
1750
|
break;
|
|
1745
|
-
case
|
|
1746
|
-
_context25.prev =
|
|
1751
|
+
case 31:
|
|
1752
|
+
_context25.prev = 31;
|
|
1747
1753
|
_context25.t1 = _context25["catch"](0);
|
|
1748
1754
|
console.error('[Checkout] 添加支付项失败:', _context25.t1);
|
|
1749
|
-
_context25.next =
|
|
1755
|
+
_context25.next = 36;
|
|
1750
1756
|
return this.handleError(_context25.t1, CheckoutErrorType.PaymentFailed);
|
|
1751
|
-
case 35:
|
|
1752
|
-
throw _context25.t1;
|
|
1753
1757
|
case 36:
|
|
1758
|
+
throw _context25.t1;
|
|
1759
|
+
case 37:
|
|
1754
1760
|
case "end":
|
|
1755
1761
|
return _context25.stop();
|
|
1756
1762
|
}
|
|
1757
|
-
}, _callee25, this, [[0,
|
|
1763
|
+
}, _callee25, this, [[0, 31], [14, 20]]);
|
|
1758
1764
|
}));
|
|
1759
1765
|
function addPaymentItemAsync(_x16) {
|
|
1760
1766
|
return _addPaymentItemAsync.apply(this, arguments);
|
|
@@ -1889,6 +1895,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1889
1895
|
key: "updateVoucherPaymentItemsAsync",
|
|
1890
1896
|
value: (function () {
|
|
1891
1897
|
var _updateVoucherPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(voucherPaymentItems) {
|
|
1898
|
+
var _this3 = this;
|
|
1892
1899
|
var orderPaymentType, voucherPaymentItemsWithType, currentOrderId, isCurrentOrderReal, updatedOrder, voucherItems;
|
|
1893
1900
|
return _regeneratorRuntime().wrap(function _callee27$(_context27) {
|
|
1894
1901
|
while (1) switch (_context27.prev = _context27.next) {
|
|
@@ -1907,13 +1914,20 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1907
1914
|
});
|
|
1908
1915
|
|
|
1909
1916
|
// 根据当前订单的定金状态设置订单支付类型
|
|
1910
|
-
orderPaymentType = this.store.currentOrder.is_deposit === 1 ? 'deposit' : 'normal'; // 验证所有支付项都包含 voucher_id,并设置 order_payment_type
|
|
1917
|
+
orderPaymentType = this.store.currentOrder.is_deposit === 1 ? 'deposit' : 'normal'; // 验证所有支付项都包含 voucher_id,并设置 order_payment_type 和 metadata
|
|
1911
1918
|
voucherPaymentItemsWithType = voucherPaymentItems.map(function (item) {
|
|
1912
1919
|
if (!item.voucher_id) {
|
|
1913
1920
|
throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u4EE3\u91D1\u5238\u652F\u4ED8\u9879\u7F3A\u5C11 voucher_id: ".concat(JSON.stringify(item)));
|
|
1914
1921
|
}
|
|
1922
|
+
|
|
1923
|
+
// 从 otherParams 获取 metadata 字段
|
|
1924
|
+
var metadata = _objectSpread(_objectSpread({}, item.metadata), {}, {
|
|
1925
|
+
rounding_rule: _this3.otherParams.order_rounding_setting,
|
|
1926
|
+
shop_wallet_pass_id: _this3.otherParams.shop_wallet_pass_id
|
|
1927
|
+
});
|
|
1915
1928
|
return _objectSpread(_objectSpread({}, item), {}, {
|
|
1916
|
-
order_payment_type: orderPaymentType
|
|
1929
|
+
order_payment_type: orderPaymentType,
|
|
1930
|
+
metadata: metadata
|
|
1917
1931
|
});
|
|
1918
1932
|
});
|
|
1919
1933
|
console.log('[Checkout] 代金券支付项订单支付类型设置:', {
|
|
@@ -2531,7 +2545,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2531
2545
|
key: "saveForLaterPaymentAsync",
|
|
2532
2546
|
value: (function () {
|
|
2533
2547
|
var _saveForLaterPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
|
|
2534
|
-
var orderUuid, currentOrderId, allPaymentItems,
|
|
2548
|
+
var orderUuid, currentOrderId, allPaymentItems, realOrderId, finalOrderId, _this$store$currentOr11, errorMessage;
|
|
2535
2549
|
return _regeneratorRuntime().wrap(function _callee33$(_context33) {
|
|
2536
2550
|
while (1) switch (_context33.prev = _context33.next) {
|
|
2537
2551
|
case 0:
|
|
@@ -2558,45 +2572,16 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2558
2572
|
return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
|
|
2559
2573
|
case 8:
|
|
2560
2574
|
allPaymentItems = _context33.sent;
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
}); // 记录过滤结果
|
|
2565
|
-
voucherItems = allPaymentItems.filter(function (payment) {
|
|
2566
|
-
return payment.voucher_id;
|
|
2567
|
-
});
|
|
2568
|
-
console.log('[Checkout] 支付项过滤结果:', {
|
|
2569
|
-
总支付项: allPaymentItems.length,
|
|
2570
|
-
过滤后支付项: filteredPaymentItems.length,
|
|
2571
|
-
被过滤的代金券项: voucherItems.length,
|
|
2572
|
-
代金券详情: voucherItems.map(function (item) {
|
|
2573
|
-
return {
|
|
2574
|
-
uuid: item.uuid,
|
|
2575
|
-
code: item.code,
|
|
2576
|
-
amount: item.amount,
|
|
2577
|
-
voucherId: item.voucher_id
|
|
2578
|
-
};
|
|
2579
|
-
}),
|
|
2580
|
-
保留的支付项: filteredPaymentItems.map(function (item) {
|
|
2581
|
-
return {
|
|
2582
|
-
uuid: item.uuid,
|
|
2583
|
-
code: item.code,
|
|
2584
|
-
amount: item.amount
|
|
2585
|
-
};
|
|
2586
|
-
})
|
|
2587
|
-
});
|
|
2588
|
-
|
|
2589
|
-
// 调用同步方法,传入过滤后的支付项
|
|
2590
|
-
_context33.next = 14;
|
|
2591
|
-
return this.syncOrderToBackendWithReturn(false, filteredPaymentItems);
|
|
2592
|
-
case 14:
|
|
2575
|
+
_context33.next = 11;
|
|
2576
|
+
return this.syncOrderToBackendWithReturn(false, allPaymentItems);
|
|
2577
|
+
case 11:
|
|
2593
2578
|
realOrderId = _context33.sent;
|
|
2594
2579
|
console.log('[Checkout] 保存订单完成:', {
|
|
2595
2580
|
orderUuid: orderUuid,
|
|
2596
2581
|
oldOrderId: currentOrderId,
|
|
2597
2582
|
realOrderId: realOrderId,
|
|
2598
2583
|
isOrderSynced: this.store.isOrderSynced,
|
|
2599
|
-
filteredPaymentsCount:
|
|
2584
|
+
filteredPaymentsCount: allPaymentItems.length
|
|
2600
2585
|
});
|
|
2601
2586
|
|
|
2602
2587
|
// 验证最终状态
|
|
@@ -2613,8 +2598,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2613
2598
|
orderId: realOrderId,
|
|
2614
2599
|
orderUuid: orderUuid
|
|
2615
2600
|
});
|
|
2616
|
-
case
|
|
2617
|
-
_context33.prev =
|
|
2601
|
+
case 18:
|
|
2602
|
+
_context33.prev = 18;
|
|
2618
2603
|
_context33.t0 = _context33["catch"](0);
|
|
2619
2604
|
console.error('[Checkout] 保存订单失败:', _context33.t0);
|
|
2620
2605
|
errorMessage = _context33.t0 instanceof Error ? _context33.t0.message : '保存失败';
|
|
@@ -2623,11 +2608,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2623
2608
|
message: "\u8BA2\u5355\u4FDD\u5B58\u5931\u8D25: ".concat(errorMessage),
|
|
2624
2609
|
orderUuid: (_this$store$currentOr11 = this.store.currentOrder) === null || _this$store$currentOr11 === void 0 ? void 0 : _this$store$currentOr11.uuid
|
|
2625
2610
|
});
|
|
2626
|
-
case
|
|
2611
|
+
case 23:
|
|
2627
2612
|
case "end":
|
|
2628
2613
|
return _context33.stop();
|
|
2629
2614
|
}
|
|
2630
|
-
}, _callee33, this, [[0,
|
|
2615
|
+
}, _callee33, this, [[0, 18]]);
|
|
2631
2616
|
}));
|
|
2632
2617
|
function saveForLaterPaymentAsync() {
|
|
2633
2618
|
return _saveForLaterPaymentAsync.apply(this, arguments);
|
|
@@ -3240,7 +3225,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3240
3225
|
uuid: p.uuid,
|
|
3241
3226
|
amount: p.amount,
|
|
3242
3227
|
code: p.code,
|
|
3243
|
-
status: p.status
|
|
3228
|
+
status: p.status,
|
|
3229
|
+
rounding_amount: p.rounding_amount
|
|
3244
3230
|
};
|
|
3245
3231
|
})
|
|
3246
3232
|
});
|
|
@@ -3249,8 +3235,19 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3249
3235
|
}) // 只计算未撤销的支付项
|
|
3250
3236
|
.reduce(function (sum, payment) {
|
|
3251
3237
|
var amount = parseFloat(payment.amount || '0');
|
|
3252
|
-
|
|
3253
|
-
|
|
3238
|
+
var roundingAmount = parseFloat(payment.rounding_amount || '0');
|
|
3239
|
+
|
|
3240
|
+
// 计算实际支付有效金额:
|
|
3241
|
+
// 当 rounding_amount 为负数时,表示抹掉的金额,应该按绝对值加到实际支付中
|
|
3242
|
+
// 例如:amount=15, rounding_amount=-0.2,实际相当于支付了15.2(抹掉了0.2元的零头)
|
|
3243
|
+
var effectiveAmount = amount + Math.abs(roundingAmount);
|
|
3244
|
+
console.log("[Checkout] \u8BA1\u7B97\u652F\u4ED8\u9879: ".concat(payment.code), {
|
|
3245
|
+
原始金额: amount,
|
|
3246
|
+
抹零金额: roundingAmount,
|
|
3247
|
+
有效金额: effectiveAmount,
|
|
3248
|
+
说明: roundingAmount !== 0 ? "\u62B9\u96F6\u91D1\u989D ".concat(roundingAmount, " \u5143\uFF0C\u6709\u6548\u652F\u4ED8\u589E\u52A0 ").concat(Math.abs(roundingAmount), " \u5143") : '无抹零'
|
|
3249
|
+
});
|
|
3250
|
+
return sum + effectiveAmount;
|
|
3254
3251
|
}, 0);
|
|
3255
3252
|
result = paidAmount.toFixed(2);
|
|
3256
3253
|
console.log('[Checkout] calculatePaidAmountAsync: 计算结果 =', result);
|
|
@@ -3304,7 +3301,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3304
3301
|
totalAmount: totalAmount.toFixed(2),
|
|
3305
3302
|
paidAmount: paidAmount.toFixed(2),
|
|
3306
3303
|
calculatedRemaining: remainingAmount.toFixed(2),
|
|
3307
|
-
finalResult: result
|
|
3304
|
+
finalResult: result,
|
|
3305
|
+
说明: '已支付金额包含抹零计算(amount + |rounding_amount|)'
|
|
3308
3306
|
});
|
|
3309
3307
|
return _context43.abrupt("return", result);
|
|
3310
3308
|
case 13:
|
|
@@ -3537,6 +3535,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3537
3535
|
uuid: p.uuid,
|
|
3538
3536
|
code: p.code,
|
|
3539
3537
|
amount: p.amount,
|
|
3538
|
+
rounding_amount: p.rounding_amount,
|
|
3539
|
+
effective_amount: (parseFloat(p.amount || '0') + Math.abs(parseFloat(p.rounding_amount || '0'))).toFixed(2),
|
|
3540
3540
|
voucher_id: p.voucher_id,
|
|
3541
3541
|
status: p.status
|
|
3542
3542
|
};
|
|
@@ -3652,7 +3652,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3652
3652
|
key: "syncOrderToBackendWithReturn",
|
|
3653
3653
|
value: (function () {
|
|
3654
3654
|
var _syncOrderToBackendWithReturn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee47() {
|
|
3655
|
-
var
|
|
3655
|
+
var _this4 = this,
|
|
3656
|
+
_processedPaymentItem,
|
|
3657
|
+
_this$store$currentCu2,
|
|
3658
|
+
_this$store$currentOr20,
|
|
3659
|
+
_this$store$currentOr21,
|
|
3660
|
+
_checkoutResponse3,
|
|
3661
|
+
_checkoutResponse4,
|
|
3662
|
+
_checkoutResponse5,
|
|
3663
|
+
_checkoutResponse6,
|
|
3664
|
+
_checkoutResponse7,
|
|
3665
|
+
_checkoutResponse8;
|
|
3656
3666
|
var isManual,
|
|
3657
3667
|
customPaymentItems,
|
|
3658
3668
|
syncType,
|
|
@@ -3662,6 +3672,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3662
3672
|
reason,
|
|
3663
3673
|
operation,
|
|
3664
3674
|
paymentItems,
|
|
3675
|
+
processedPaymentItems,
|
|
3665
3676
|
orderParams,
|
|
3666
3677
|
startTime,
|
|
3667
3678
|
checkoutResponse,
|
|
@@ -3759,7 +3770,31 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3759
3770
|
amount: p.amount,
|
|
3760
3771
|
uniquePaymentNumber: (_p$metadata = p.metadata) === null || _p$metadata === void 0 ? void 0 : _p$metadata.unique_payment_number,
|
|
3761
3772
|
voucherId: p.voucher_id,
|
|
3762
|
-
orderPaymentType: p.order_payment_type
|
|
3773
|
+
orderPaymentType: p.order_payment_type,
|
|
3774
|
+
metadata: p.metadata
|
|
3775
|
+
};
|
|
3776
|
+
})
|
|
3777
|
+
});
|
|
3778
|
+
|
|
3779
|
+
// 处理支付项数据,确保包含完整的 metadata
|
|
3780
|
+
processedPaymentItems = paymentItems.map(function (item) {
|
|
3781
|
+
var _item$metadata, _item$metadata2;
|
|
3782
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
3783
|
+
metadata: _objectSpread(_objectSpread({}, item.metadata), {}, {
|
|
3784
|
+
rounding_rule: ((_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.rounding_rule) || _this4.otherParams.order_rounding_setting,
|
|
3785
|
+
shop_wallet_pass_id: ((_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.shop_wallet_pass_id) || _this4.otherParams.shop_wallet_pass_id
|
|
3786
|
+
})
|
|
3787
|
+
});
|
|
3788
|
+
});
|
|
3789
|
+
console.log('[Checkout] 处理后的支付项数据(包含完整metadata):', {
|
|
3790
|
+
originalCount: paymentItems.length,
|
|
3791
|
+
processedCount: processedPaymentItems.length,
|
|
3792
|
+
sampleMetadata: (_processedPaymentItem = processedPaymentItems[0]) === null || _processedPaymentItem === void 0 ? void 0 : _processedPaymentItem.metadata,
|
|
3793
|
+
allPaymentItems: processedPaymentItems.map(function (p) {
|
|
3794
|
+
return {
|
|
3795
|
+
code: p.code,
|
|
3796
|
+
amount: p.amount,
|
|
3797
|
+
metadata: p.metadata
|
|
3763
3798
|
};
|
|
3764
3799
|
})
|
|
3765
3800
|
});
|
|
@@ -3768,8 +3803,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3768
3803
|
orderParams = _objectSpread(_objectSpread({}, this.store.localOrderData), {}, {
|
|
3769
3804
|
type: this.store.localOrderData.type,
|
|
3770
3805
|
platform: this.store.localOrderData.platform,
|
|
3771
|
-
payments:
|
|
3772
|
-
//
|
|
3806
|
+
payments: processedPaymentItems,
|
|
3807
|
+
// 使用处理过的支付项数据
|
|
3773
3808
|
customer_id: (_this$store$currentCu2 = this.store.currentCustomer) === null || _this$store$currentCu2 === void 0 ? void 0 : _this$store$currentCu2.customer_id,
|
|
3774
3809
|
// 添加客户ID
|
|
3775
3810
|
is_price_include_tax: this.otherParams.is_price_include_tax,
|
|
@@ -3815,7 +3850,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3815
3850
|
|
|
3816
3851
|
// 发送下单接口请求开始事件
|
|
3817
3852
|
startTime = Date.now();
|
|
3818
|
-
_context47.next =
|
|
3853
|
+
_context47.next = 27;
|
|
3819
3854
|
return this.core.effects.emit(CheckoutHooks.OnOrderSubmitStart, {
|
|
3820
3855
|
orderUuid: this.store.currentOrder.uuid,
|
|
3821
3856
|
operation: isUpdateOperation ? 'update' : 'create',
|
|
@@ -3823,26 +3858,26 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3823
3858
|
paymentItemCount: paymentItems.length,
|
|
3824
3859
|
timestamp: startTime
|
|
3825
3860
|
});
|
|
3826
|
-
case
|
|
3861
|
+
case 27:
|
|
3827
3862
|
submitSuccess = false;
|
|
3828
|
-
_context47.prev =
|
|
3829
|
-
_context47.next =
|
|
3863
|
+
_context47.prev = 28;
|
|
3864
|
+
_context47.next = 31;
|
|
3830
3865
|
return this.order.createOrderByCheckout(orderParams);
|
|
3831
|
-
case
|
|
3866
|
+
case 31:
|
|
3832
3867
|
checkoutResponse = _context47.sent;
|
|
3833
3868
|
submitSuccess = true;
|
|
3834
3869
|
console.log('[Checkout] 下单接口调用成功');
|
|
3835
|
-
_context47.next =
|
|
3870
|
+
_context47.next = 43;
|
|
3836
3871
|
break;
|
|
3837
|
-
case
|
|
3838
|
-
_context47.prev =
|
|
3839
|
-
_context47.t1 = _context47["catch"](
|
|
3872
|
+
case 36:
|
|
3873
|
+
_context47.prev = 36;
|
|
3874
|
+
_context47.t1 = _context47["catch"](28);
|
|
3840
3875
|
submitSuccess = false;
|
|
3841
3876
|
submitError = _context47.t1 instanceof Error ? _context47.t1.message : String(_context47.t1);
|
|
3842
3877
|
// console.error('[Checkout] 下单接口调用失败:', submitError);
|
|
3843
3878
|
|
|
3844
3879
|
// 发送订单同步失败事件(网络错误或请求失败)
|
|
3845
|
-
_context47.next =
|
|
3880
|
+
_context47.next = 42;
|
|
3846
3881
|
return this.core.effects.emit(CheckoutHooks.OnOrderSyncFailed, {
|
|
3847
3882
|
orderUuid: this.store.currentOrder.uuid,
|
|
3848
3883
|
operation: isUpdateOperation ? 'update' : 'create',
|
|
@@ -3852,11 +3887,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3852
3887
|
duration: Date.now() - startTime,
|
|
3853
3888
|
timestamp: Date.now()
|
|
3854
3889
|
});
|
|
3855
|
-
case
|
|
3890
|
+
case 42:
|
|
3856
3891
|
throw _context47.t1;
|
|
3857
|
-
case
|
|
3858
|
-
_context47.prev =
|
|
3859
|
-
_context47.next =
|
|
3892
|
+
case 43:
|
|
3893
|
+
_context47.prev = 43;
|
|
3894
|
+
_context47.next = 46;
|
|
3860
3895
|
return this.core.effects.emit(CheckoutHooks.OnOrderSubmitEnd, {
|
|
3861
3896
|
success: submitSuccess,
|
|
3862
3897
|
orderUuid: this.store.currentOrder.uuid,
|
|
@@ -3867,9 +3902,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3867
3902
|
duration: Date.now() - startTime,
|
|
3868
3903
|
timestamp: Date.now()
|
|
3869
3904
|
});
|
|
3870
|
-
case
|
|
3871
|
-
return _context47.finish(
|
|
3872
|
-
case
|
|
3905
|
+
case 46:
|
|
3906
|
+
return _context47.finish(43);
|
|
3907
|
+
case 47:
|
|
3873
3908
|
console.log('[Checkout] 后端返回的响应数据:', {
|
|
3874
3909
|
status: (_checkoutResponse3 = checkoutResponse) === null || _checkoutResponse3 === void 0 ? void 0 : _checkoutResponse3.status,
|
|
3875
3910
|
code: (_checkoutResponse4 = checkoutResponse) === null || _checkoutResponse4 === void 0 ? void 0 : _checkoutResponse4.code,
|
|
@@ -3881,7 +3916,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3881
3916
|
responseStatus = (_checkoutResponse7 = checkoutResponse) === null || _checkoutResponse7 === void 0 ? void 0 : _checkoutResponse7.status;
|
|
3882
3917
|
isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus === 'success' || responseStatus === 1 && ((_checkoutResponse8 = checkoutResponse) === null || _checkoutResponse8 === void 0 ? void 0 : _checkoutResponse8.code) === 200;
|
|
3883
3918
|
if (isSuccessResponse) {
|
|
3884
|
-
_context47.next =
|
|
3919
|
+
_context47.next = 56;
|
|
3885
3920
|
break;
|
|
3886
3921
|
}
|
|
3887
3922
|
errorMessage = ((_checkoutResponse9 = checkoutResponse) === null || _checkoutResponse9 === void 0 ? void 0 : _checkoutResponse9.message) || '订单同步失败,后端返回非成功状态';
|
|
@@ -3894,7 +3929,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3894
3929
|
});
|
|
3895
3930
|
|
|
3896
3931
|
// 发送订单同步失败事件
|
|
3897
|
-
_context47.next =
|
|
3932
|
+
_context47.next = 55;
|
|
3898
3933
|
return this.core.effects.emit(CheckoutHooks.OnOrderSyncFailed, {
|
|
3899
3934
|
orderUuid: this.store.currentOrder.uuid,
|
|
3900
3935
|
operation: isUpdateOperation ? 'update' : 'create',
|
|
@@ -3905,20 +3940,20 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3905
3940
|
duration: Date.now() - startTime,
|
|
3906
3941
|
timestamp: Date.now()
|
|
3907
3942
|
});
|
|
3908
|
-
case
|
|
3943
|
+
case 55:
|
|
3909
3944
|
throw new Error(errorMessage);
|
|
3910
|
-
case
|
|
3945
|
+
case 56:
|
|
3911
3946
|
console.log('[Checkout] 响应状态检查通过,开始处理订单数据');
|
|
3912
3947
|
if (!isUpdateOperation) {
|
|
3913
|
-
_context47.next =
|
|
3948
|
+
_context47.next = 62;
|
|
3914
3949
|
break;
|
|
3915
3950
|
}
|
|
3916
3951
|
// 更新操作:使用现有的订单ID
|
|
3917
3952
|
realOrderId = currentOrderId;
|
|
3918
3953
|
console.log("[Checkout] \u8BA2\u5355\u66F4\u65B0\u6210\u529F\uFF0C\u8BA2\u5355ID: ".concat(realOrderId));
|
|
3919
|
-
_context47.next =
|
|
3954
|
+
_context47.next = 83;
|
|
3920
3955
|
break;
|
|
3921
|
-
case
|
|
3956
|
+
case 62:
|
|
3922
3957
|
// 创建操作:从响应中提取新的订单ID
|
|
3923
3958
|
extractedOrderId = (_checkoutResponse12 = checkoutResponse) === null || _checkoutResponse12 === void 0 || (_checkoutResponse12 = _checkoutResponse12.data) === null || _checkoutResponse12 === void 0 ? void 0 : _checkoutResponse12.order_id; // 如果data.order_id不存在,尝试直接从根级获取
|
|
3924
3959
|
if (!extractedOrderId) {
|
|
@@ -3930,11 +3965,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3930
3965
|
extractedOrderId = String(extractedOrderId);
|
|
3931
3966
|
}
|
|
3932
3967
|
if (extractedOrderId) {
|
|
3933
|
-
_context47.next =
|
|
3968
|
+
_context47.next = 67;
|
|
3934
3969
|
break;
|
|
3935
3970
|
}
|
|
3936
3971
|
throw new Error('后端返回的订单信息中未包含订单ID');
|
|
3937
|
-
case
|
|
3972
|
+
case 67:
|
|
3938
3973
|
realOrderId = extractedOrderId;
|
|
3939
3974
|
console.log('[Checkout] 订单创建成功,真实订单ID:', realOrderId);
|
|
3940
3975
|
|
|
@@ -3944,10 +3979,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3944
3979
|
oldOrderId: this.store.currentOrder.order_id,
|
|
3945
3980
|
newOrderId: realOrderId
|
|
3946
3981
|
});
|
|
3947
|
-
_context47.prev =
|
|
3948
|
-
_context47.next =
|
|
3982
|
+
_context47.prev = 70;
|
|
3983
|
+
_context47.next = 73;
|
|
3949
3984
|
return this.payment.replaceOrderIdByUuidAsync(this.store.currentOrder.uuid, realOrderId);
|
|
3950
|
-
case
|
|
3985
|
+
case 73:
|
|
3951
3986
|
updatedOrder = _context47.sent;
|
|
3952
3987
|
console.log('[Checkout] Payment模块替换订单ID结果:', {
|
|
3953
3988
|
wasSuccessful: !!updatedOrder,
|
|
@@ -3974,22 +4009,22 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3974
4009
|
目标ID: realOrderId
|
|
3975
4010
|
});
|
|
3976
4011
|
}
|
|
3977
|
-
_context47.next =
|
|
4012
|
+
_context47.next = 83;
|
|
3978
4013
|
break;
|
|
3979
|
-
case
|
|
3980
|
-
_context47.prev =
|
|
3981
|
-
_context47.t2 = _context47["catch"](
|
|
4014
|
+
case 78:
|
|
4015
|
+
_context47.prev = 78;
|
|
4016
|
+
_context47.t2 = _context47["catch"](70);
|
|
3982
4017
|
console.error('[Checkout] 调用Payment模块替换订单ID时发生错误:', _context47.t2);
|
|
3983
4018
|
|
|
3984
4019
|
// 发生错误时也进行手动替换
|
|
3985
4020
|
this.store.currentOrder.order_id = realOrderId;
|
|
3986
4021
|
console.log('[Checkout] 错误恢复:手动设置订单ID:', realOrderId);
|
|
3987
|
-
case
|
|
4022
|
+
case 83:
|
|
3988
4023
|
// 标记订单已同步
|
|
3989
4024
|
this.store.isOrderSynced = true;
|
|
3990
4025
|
|
|
3991
4026
|
// 触发订单同步完成事件
|
|
3992
|
-
_context47.next =
|
|
4027
|
+
_context47.next = 86;
|
|
3993
4028
|
return this.core.effects.emit(CheckoutHooks.OnOrderSynced, {
|
|
3994
4029
|
orderUuid: this.store.currentOrder.uuid,
|
|
3995
4030
|
realOrderId: realOrderId,
|
|
@@ -3998,7 +4033,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3998
4033
|
isManual: isManual,
|
|
3999
4034
|
response: checkoutResponse
|
|
4000
4035
|
});
|
|
4001
|
-
case
|
|
4036
|
+
case 86:
|
|
4002
4037
|
// 验证最终状态
|
|
4003
4038
|
finalOrderId = this.store.currentOrder.order_id;
|
|
4004
4039
|
finalIsVirtual = this.isVirtualOrderId(finalOrderId || '');
|
|
@@ -4016,11 +4051,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
4016
4051
|
|
|
4017
4052
|
// 返回真实订单ID
|
|
4018
4053
|
return _context47.abrupt("return", realOrderId);
|
|
4019
|
-
case
|
|
4054
|
+
case 91:
|
|
4020
4055
|
case "end":
|
|
4021
4056
|
return _context47.stop();
|
|
4022
4057
|
}
|
|
4023
|
-
}, _callee47, this, [[
|
|
4058
|
+
}, _callee47, this, [[28, 36, 43, 47], [70, 78]]);
|
|
4024
4059
|
}));
|
|
4025
4060
|
function syncOrderToBackendWithReturn() {
|
|
4026
4061
|
return _syncOrderToBackendWithReturn.apply(this, arguments);
|
|
@@ -866,9 +866,12 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
866
866
|
if (payment.status === "voided") {
|
|
867
867
|
return sum;
|
|
868
868
|
}
|
|
869
|
-
|
|
869
|
+
const paymentAmount = new import_decimal.Decimal(payment.amount || 0);
|
|
870
|
+
const roundingAmount = new import_decimal.Decimal(payment.rounding_amount || 0);
|
|
871
|
+
const effectiveAmount = paymentAmount.plus(roundingAmount.abs());
|
|
872
|
+
return sum.plus(effectiveAmount);
|
|
870
873
|
} catch (error) {
|
|
871
|
-
console.warn(`[PaymentModule] 无效的支付金额:
|
|
874
|
+
console.warn(`[PaymentModule] 无效的支付金额: amount=${payment.amount}, rounding_amount=${payment.rounding_amount},跳过计算`);
|
|
872
875
|
return sum;
|
|
873
876
|
}
|
|
874
877
|
},
|
|
@@ -879,10 +882,17 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
879
882
|
console.log(`[PaymentModule] 重新计算订单金额:`, {
|
|
880
883
|
orderUuid: order.uuid,
|
|
881
884
|
totalAmount: order.total_amount,
|
|
882
|
-
|
|
885
|
+
effectivePaidAmount: paidAmount.toFixed(2),
|
|
883
886
|
remainingAmount: order.expect_amount,
|
|
884
887
|
activePayments: order.payment.filter((p) => p.status !== "voided").length,
|
|
885
|
-
voidedPayments: order.payment.filter((p) => p.status === "voided").length
|
|
888
|
+
voidedPayments: order.payment.filter((p) => p.status === "voided").length,
|
|
889
|
+
paymentDetails: order.payment.filter((p) => p.status !== "voided").map((p) => ({
|
|
890
|
+
code: p.code,
|
|
891
|
+
amount: p.amount,
|
|
892
|
+
rounding_amount: p.rounding_amount || "0.00",
|
|
893
|
+
effective_amount: new import_decimal.Decimal(p.amount || 0).plus(new import_decimal.Decimal(p.rounding_amount || 0).abs()).toFixed(2)
|
|
894
|
+
})),
|
|
895
|
+
说明: "有效支付金额包含抹零计算(amount + |rounding_amount|)"
|
|
886
896
|
});
|
|
887
897
|
}
|
|
888
898
|
/**
|
|
@@ -222,6 +222,15 @@ export interface PaymentItemInput {
|
|
|
222
222
|
rounding_amount?: string;
|
|
223
223
|
/** 订单支付类型 */
|
|
224
224
|
order_payment_type?: 'normal' | 'deposit';
|
|
225
|
+
/** 扩展参数字段 */
|
|
226
|
+
metadata?: {
|
|
227
|
+
/** 钱箱 ID */
|
|
228
|
+
shop_wallet_pass_id?: string;
|
|
229
|
+
/** 唯一支付号 */
|
|
230
|
+
unique_payment_number?: string;
|
|
231
|
+
/** rounding规则 */
|
|
232
|
+
rounding_rule?: any;
|
|
233
|
+
};
|
|
225
234
|
}
|
|
226
235
|
/**
|
|
227
236
|
* 推送支付项参数
|
|
@@ -940,9 +940,15 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
940
940
|
);
|
|
941
941
|
}
|
|
942
942
|
const orderPaymentType = this.store.currentOrder.is_deposit === 1 ? "deposit" : "normal";
|
|
943
|
+
const metadata = {
|
|
944
|
+
...paymentItem.metadata,
|
|
945
|
+
rounding_rule: this.otherParams.order_rounding_setting,
|
|
946
|
+
shop_wallet_pass_id: this.otherParams.shop_wallet_pass_id
|
|
947
|
+
};
|
|
943
948
|
const paymentItemWithType = {
|
|
944
949
|
...paymentItem,
|
|
945
|
-
order_payment_type: orderPaymentType
|
|
950
|
+
order_payment_type: orderPaymentType,
|
|
951
|
+
metadata
|
|
946
952
|
};
|
|
947
953
|
console.log("[Checkout] 为当前订单添加支付项:", {
|
|
948
954
|
orderUuid: this.store.currentOrder.uuid,
|
|
@@ -954,7 +960,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
954
960
|
service_charge: paymentItemWithType.service_charge,
|
|
955
961
|
rounding_amount: paymentItemWithType.rounding_amount,
|
|
956
962
|
voucher_id: paymentItemWithType.voucher_id,
|
|
957
|
-
order_payment_type: paymentItemWithType.order_payment_type
|
|
963
|
+
order_payment_type: paymentItemWithType.order_payment_type,
|
|
964
|
+
metadata: paymentItemWithType.metadata
|
|
958
965
|
},
|
|
959
966
|
orderDepositStatus: this.store.currentOrder.is_deposit,
|
|
960
967
|
calculatedOrderPaymentType: orderPaymentType
|
|
@@ -1112,9 +1119,15 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1112
1119
|
`代金券支付项缺少 voucher_id: ${JSON.stringify(item)}`
|
|
1113
1120
|
);
|
|
1114
1121
|
}
|
|
1122
|
+
const metadata = {
|
|
1123
|
+
...item.metadata,
|
|
1124
|
+
rounding_rule: this.otherParams.order_rounding_setting,
|
|
1125
|
+
shop_wallet_pass_id: this.otherParams.shop_wallet_pass_id
|
|
1126
|
+
};
|
|
1115
1127
|
return {
|
|
1116
1128
|
...item,
|
|
1117
|
-
order_payment_type: orderPaymentType
|
|
1129
|
+
order_payment_type: orderPaymentType,
|
|
1130
|
+
metadata
|
|
1118
1131
|
};
|
|
1119
1132
|
});
|
|
1120
1133
|
console.log("[Checkout] 代金券支付项订单支付类型设置:", {
|
|
@@ -1553,38 +1566,16 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1553
1566
|
const allPaymentItems = await this.payment.getPaymentItemsAsync(
|
|
1554
1567
|
this.store.currentOrder.uuid
|
|
1555
1568
|
);
|
|
1556
|
-
const filteredPaymentItems = allPaymentItems.filter(
|
|
1557
|
-
(payment) => !payment.voucher_id
|
|
1558
|
-
);
|
|
1559
|
-
const voucherItems = allPaymentItems.filter(
|
|
1560
|
-
(payment) => payment.voucher_id
|
|
1561
|
-
);
|
|
1562
|
-
console.log("[Checkout] 支付项过滤结果:", {
|
|
1563
|
-
总支付项: allPaymentItems.length,
|
|
1564
|
-
过滤后支付项: filteredPaymentItems.length,
|
|
1565
|
-
被过滤的代金券项: voucherItems.length,
|
|
1566
|
-
代金券详情: voucherItems.map((item) => ({
|
|
1567
|
-
uuid: item.uuid,
|
|
1568
|
-
code: item.code,
|
|
1569
|
-
amount: item.amount,
|
|
1570
|
-
voucherId: item.voucher_id
|
|
1571
|
-
})),
|
|
1572
|
-
保留的支付项: filteredPaymentItems.map((item) => ({
|
|
1573
|
-
uuid: item.uuid,
|
|
1574
|
-
code: item.code,
|
|
1575
|
-
amount: item.amount
|
|
1576
|
-
}))
|
|
1577
|
-
});
|
|
1578
1569
|
const realOrderId = await this.syncOrderToBackendWithReturn(
|
|
1579
1570
|
false,
|
|
1580
|
-
|
|
1571
|
+
allPaymentItems
|
|
1581
1572
|
);
|
|
1582
1573
|
console.log("[Checkout] 保存订单完成:", {
|
|
1583
1574
|
orderUuid,
|
|
1584
1575
|
oldOrderId: currentOrderId,
|
|
1585
1576
|
realOrderId,
|
|
1586
1577
|
isOrderSynced: this.store.isOrderSynced,
|
|
1587
|
-
filteredPaymentsCount:
|
|
1578
|
+
filteredPaymentsCount: allPaymentItems.length
|
|
1588
1579
|
});
|
|
1589
1580
|
const finalOrderId = this.store.currentOrder.order_id;
|
|
1590
1581
|
console.log("[Checkout] saveForLaterPaymentAsync 最终状态验证:", {
|
|
@@ -1984,13 +1975,21 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1984
1975
|
uuid: p.uuid,
|
|
1985
1976
|
amount: p.amount,
|
|
1986
1977
|
code: p.code,
|
|
1987
|
-
status: p.status
|
|
1978
|
+
status: p.status,
|
|
1979
|
+
rounding_amount: p.rounding_amount
|
|
1988
1980
|
}))
|
|
1989
1981
|
});
|
|
1990
1982
|
const paidAmount = payments.filter((payment) => payment.status !== "voided").reduce((sum, payment) => {
|
|
1991
1983
|
const amount = parseFloat(payment.amount || "0");
|
|
1992
|
-
|
|
1993
|
-
|
|
1984
|
+
const roundingAmount = parseFloat(payment.rounding_amount || "0");
|
|
1985
|
+
const effectiveAmount = amount + Math.abs(roundingAmount);
|
|
1986
|
+
console.log(`[Checkout] 计算支付项: ${payment.code}`, {
|
|
1987
|
+
原始金额: amount,
|
|
1988
|
+
抹零金额: roundingAmount,
|
|
1989
|
+
有效金额: effectiveAmount,
|
|
1990
|
+
说明: roundingAmount !== 0 ? `抹零金额 ${roundingAmount} 元,有效支付增加 ${Math.abs(roundingAmount)} 元` : "无抹零"
|
|
1991
|
+
});
|
|
1992
|
+
return sum + effectiveAmount;
|
|
1994
1993
|
}, 0);
|
|
1995
1994
|
const result = paidAmount.toFixed(2);
|
|
1996
1995
|
console.log("[Checkout] calculatePaidAmountAsync: 计算结果 =", result);
|
|
@@ -2017,7 +2016,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2017
2016
|
totalAmount: totalAmount.toFixed(2),
|
|
2018
2017
|
paidAmount: paidAmount.toFixed(2),
|
|
2019
2018
|
calculatedRemaining: remainingAmount.toFixed(2),
|
|
2020
|
-
finalResult: result
|
|
2019
|
+
finalResult: result,
|
|
2020
|
+
说明: "已支付金额包含抹零计算(amount + |rounding_amount|)"
|
|
2021
2021
|
});
|
|
2022
2022
|
return result;
|
|
2023
2023
|
}
|
|
@@ -2137,6 +2137,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2137
2137
|
uuid: p.uuid,
|
|
2138
2138
|
code: p.code,
|
|
2139
2139
|
amount: p.amount,
|
|
2140
|
+
rounding_amount: p.rounding_amount,
|
|
2141
|
+
effective_amount: (parseFloat(p.amount || "0") + Math.abs(parseFloat(p.rounding_amount || "0"))).toFixed(2),
|
|
2140
2142
|
voucher_id: p.voucher_id,
|
|
2141
2143
|
status: p.status
|
|
2142
2144
|
}))
|
|
@@ -2212,7 +2214,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2212
2214
|
* @returns 后端返回的真实订单ID
|
|
2213
2215
|
*/
|
|
2214
2216
|
async syncOrderToBackendWithReturn(isManual = false, customPaymentItems) {
|
|
2215
|
-
var _a, _b, _c, _d, _e;
|
|
2217
|
+
var _a, _b, _c, _d, _e, _f;
|
|
2216
2218
|
if (!this.store.localOrderData || !this.store.currentOrder) {
|
|
2217
2219
|
throw new Error("缺少必要的订单数据,无法同步到后端");
|
|
2218
2220
|
}
|
|
@@ -2261,17 +2263,39 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2261
2263
|
amount: p.amount,
|
|
2262
2264
|
uniquePaymentNumber: (_a2 = p.metadata) == null ? void 0 : _a2.unique_payment_number,
|
|
2263
2265
|
voucherId: p.voucher_id,
|
|
2264
|
-
orderPaymentType: p.order_payment_type
|
|
2266
|
+
orderPaymentType: p.order_payment_type,
|
|
2267
|
+
metadata: p.metadata
|
|
2265
2268
|
};
|
|
2266
2269
|
})
|
|
2267
2270
|
});
|
|
2271
|
+
const processedPaymentItems = paymentItems.map((item) => {
|
|
2272
|
+
var _a2, _b2;
|
|
2273
|
+
return {
|
|
2274
|
+
...item,
|
|
2275
|
+
metadata: {
|
|
2276
|
+
...item.metadata,
|
|
2277
|
+
rounding_rule: ((_a2 = item.metadata) == null ? void 0 : _a2.rounding_rule) || this.otherParams.order_rounding_setting,
|
|
2278
|
+
shop_wallet_pass_id: ((_b2 = item.metadata) == null ? void 0 : _b2.shop_wallet_pass_id) || this.otherParams.shop_wallet_pass_id
|
|
2279
|
+
}
|
|
2280
|
+
};
|
|
2281
|
+
});
|
|
2282
|
+
console.log("[Checkout] 处理后的支付项数据(包含完整metadata):", {
|
|
2283
|
+
originalCount: paymentItems.length,
|
|
2284
|
+
processedCount: processedPaymentItems.length,
|
|
2285
|
+
sampleMetadata: (_a = processedPaymentItems[0]) == null ? void 0 : _a.metadata,
|
|
2286
|
+
allPaymentItems: processedPaymentItems.map((p) => ({
|
|
2287
|
+
code: p.code,
|
|
2288
|
+
amount: p.amount,
|
|
2289
|
+
metadata: p.metadata
|
|
2290
|
+
}))
|
|
2291
|
+
});
|
|
2268
2292
|
const orderParams = {
|
|
2269
2293
|
...this.store.localOrderData,
|
|
2270
2294
|
type: this.store.localOrderData.type,
|
|
2271
2295
|
platform: this.store.localOrderData.platform,
|
|
2272
|
-
payments:
|
|
2273
|
-
//
|
|
2274
|
-
customer_id: (
|
|
2296
|
+
payments: processedPaymentItems,
|
|
2297
|
+
// 使用处理过的支付项数据
|
|
2298
|
+
customer_id: (_b = this.store.currentCustomer) == null ? void 0 : _b.customer_id,
|
|
2275
2299
|
// 添加客户ID
|
|
2276
2300
|
is_price_include_tax: this.otherParams.is_price_include_tax,
|
|
2277
2301
|
// core 有
|
|
@@ -2284,8 +2308,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2284
2308
|
currency_code: this.otherParams.currency_code,
|
|
2285
2309
|
currency_symbol: this.otherParams.currency_symbol,
|
|
2286
2310
|
currency_format: this.otherParams.currency_format,
|
|
2287
|
-
is_deposit: ((
|
|
2288
|
-
deposit_amount: ((
|
|
2311
|
+
is_deposit: ((_c = this.store.currentOrder) == null ? void 0 : _c.is_deposit) || 0,
|
|
2312
|
+
deposit_amount: ((_d = this.store.currentOrder) == null ? void 0 : _d.deposit_amount) || "0.00",
|
|
2289
2313
|
// surcharge_fee: this.otherParams.surcharge_fee,
|
|
2290
2314
|
// surcharges: ,
|
|
2291
2315
|
note: this.store.localOrderData.shop_note
|
|
@@ -2347,7 +2371,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2347
2371
|
orderUuid: this.store.currentOrder.uuid,
|
|
2348
2372
|
operation: isUpdateOperation ? "update" : "create",
|
|
2349
2373
|
isManual,
|
|
2350
|
-
orderId: submitSuccess ? ((
|
|
2374
|
+
orderId: submitSuccess ? ((_e = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _e.order_id) || (checkoutResponse == null ? void 0 : checkoutResponse.order_id) : void 0,
|
|
2351
2375
|
error: submitError,
|
|
2352
2376
|
duration: Date.now() - startTime,
|
|
2353
2377
|
timestamp: Date.now()
|
|
@@ -2388,7 +2412,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2388
2412
|
realOrderId = currentOrderId;
|
|
2389
2413
|
console.log(`[Checkout] 订单更新成功,订单ID: ${realOrderId}`);
|
|
2390
2414
|
} else {
|
|
2391
|
-
let extractedOrderId = (
|
|
2415
|
+
let extractedOrderId = (_f = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _f.order_id;
|
|
2392
2416
|
if (!extractedOrderId) {
|
|
2393
2417
|
extractedOrderId = checkoutResponse == null ? void 0 : checkoutResponse.order_id;
|
|
2394
2418
|
}
|