@pisell/pisellos 2.1.27 → 2.1.29
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 +2 -2
- package/dist/solution/Checkout/index.d.ts +4 -0
- package/dist/solution/Checkout/index.js +347 -247
- package/lib/modules/Payment/index.js +2 -2
- package/lib/solution/Checkout/index.d.ts +4 -0
- package/lib/solution/Checkout/index.js +62 -12
- package/package.json +1 -1
|
@@ -913,7 +913,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
913
913
|
}
|
|
914
914
|
const paymentAmount = new import_decimal.Decimal(payment.amount || 0);
|
|
915
915
|
const roundingAmount = new import_decimal.Decimal(payment.rounding_amount || 0);
|
|
916
|
-
const effectiveAmount = paymentAmount.plus(roundingAmount.abs());
|
|
916
|
+
const effectiveAmount = paymentAmount.plus(roundingAmount.isNegative() ? roundingAmount.abs() : 0);
|
|
917
917
|
return sum.plus(effectiveAmount);
|
|
918
918
|
} catch (error) {
|
|
919
919
|
console.warn(`[PaymentModule] 无效的支付金额: amount=${payment.amount}, rounding_amount=${payment.rounding_amount},跳过计算`);
|
|
@@ -935,7 +935,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
935
935
|
code: p.code,
|
|
936
936
|
amount: p.amount,
|
|
937
937
|
rounding_amount: p.rounding_amount || "0.00",
|
|
938
|
-
effective_amount: new import_decimal.Decimal(p.amount || 0).plus(new import_decimal.Decimal(p.rounding_amount || 0).abs()).toFixed(2)
|
|
938
|
+
effective_amount: new import_decimal.Decimal(p.amount || 0).plus(new import_decimal.Decimal(Number(p.rounding_amount) > 0 ? 0 : p.rounding_amount || 0).abs()).toFixed(2)
|
|
939
939
|
})),
|
|
940
940
|
说明: "有效支付金额包含抹零计算(amount + |rounding_amount|)"
|
|
941
941
|
});
|
|
@@ -310,6 +310,10 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
|
|
|
310
310
|
* 计算剩余未支付金额(从 Payment 模块获取最新数据)
|
|
311
311
|
*/
|
|
312
312
|
private calculateRemainingAmountAsync;
|
|
313
|
+
/**
|
|
314
|
+
* 计算剩余未支付金额(排除定金计算,始终使用订单总金额)
|
|
315
|
+
*/
|
|
316
|
+
private calculateRemainingTotalAmountAsync;
|
|
313
317
|
/**
|
|
314
318
|
* 更新 balanceDueAmount 为当前剩余未支付金额(系统内部计算)
|
|
315
319
|
*/
|
|
@@ -475,7 +475,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
475
475
|
);
|
|
476
476
|
const paidAmount = activePayments.reduce((sum, p) => {
|
|
477
477
|
const amt = new import_decimal.default(p.amount || "0");
|
|
478
|
-
const rounding = new import_decimal.default(p.rounding_amount || "0").abs();
|
|
478
|
+
const rounding = new import_decimal.default(Number(p.rounding_amount) > 0 ? 0 : p.rounding_amount || "0").abs();
|
|
479
479
|
return sum.plus(amt).plus(rounding);
|
|
480
480
|
}, new import_decimal.default(0));
|
|
481
481
|
const remaining = import_decimal.default.max(0, totalAmount.minus(paidAmount)).toFixed(
|
|
@@ -524,14 +524,18 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
524
524
|
});
|
|
525
525
|
const syncedAmount = activePayments.reduce((sum, p) => {
|
|
526
526
|
const amt = new import_decimal.default(p.amount || "0");
|
|
527
|
-
const rounding = new import_decimal.default(p.rounding_amount || "0").abs();
|
|
527
|
+
const rounding = new import_decimal.default(Number(p.rounding_amount) > 0 ? 0 : p.rounding_amount || "0").abs();
|
|
528
528
|
return sum.plus(amt).plus(rounding);
|
|
529
529
|
}, new import_decimal.default(0));
|
|
530
530
|
const remainingExpectAmount = import_decimal.default.max(0, totalAmount.minus(syncedAmount)).toFixed(
|
|
531
531
|
2
|
|
532
532
|
);
|
|
533
|
+
let depositDiffAmount = new import_decimal.default(0).toFixed(2);
|
|
534
|
+
if (updated.is_deposit === 1) {
|
|
535
|
+
depositDiffAmount = new import_decimal.default(updated.deposit_amount).minus(syncedAmount).toFixed(2);
|
|
536
|
+
}
|
|
533
537
|
this.initWalletData({
|
|
534
|
-
order_wait_pay_amount: Number(remainingExpectAmount)
|
|
538
|
+
order_wait_pay_amount: Number(depositDiffAmount) > 0 ? Number(depositDiffAmount) : Number(remainingExpectAmount)
|
|
535
539
|
});
|
|
536
540
|
return updated;
|
|
537
541
|
}
|
|
@@ -1094,7 +1098,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1094
1098
|
console.log("[Checkout] 定金状态无变化,跳过更新");
|
|
1095
1099
|
return;
|
|
1096
1100
|
}
|
|
1097
|
-
let deposit_amount =
|
|
1101
|
+
let deposit_amount = this.store.currentOrder.deposit_amount || "0.00";
|
|
1098
1102
|
if (!deposit_amount || Number(deposit_amount) === 0) {
|
|
1099
1103
|
deposit_amount = this.store.currentOrder.expect_amount;
|
|
1100
1104
|
}
|
|
@@ -1769,7 +1773,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1769
1773
|
const paidAmount = payments.filter((payment) => payment.status !== "voided").reduce((sum, payment) => {
|
|
1770
1774
|
const amount = new import_decimal.default(payment.amount || "0");
|
|
1771
1775
|
const roundingAmount = new import_decimal.default(payment.rounding_amount || "0");
|
|
1772
|
-
const effectiveAmount = amount.add(roundingAmount.abs());
|
|
1776
|
+
const effectiveAmount = amount.add(roundingAmount.isNegative() ? roundingAmount.abs() : 0);
|
|
1773
1777
|
console.log(`[Checkout] 计算支付项: ${payment.code}`, {
|
|
1774
1778
|
originalAmount: amount.toFixed(2),
|
|
1775
1779
|
roundingAmount: roundingAmount.toFixed(2),
|
|
@@ -1814,19 +1818,37 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1814
1818
|
this.logInfo("calculateRemainingAmountAsync: 计算=", result);
|
|
1815
1819
|
return result;
|
|
1816
1820
|
}
|
|
1821
|
+
/**
|
|
1822
|
+
* 计算剩余未支付金额(排除定金计算,始终使用订单总金额)
|
|
1823
|
+
*/
|
|
1824
|
+
async calculateRemainingTotalAmountAsync() {
|
|
1825
|
+
if (!this.store.currentOrder) {
|
|
1826
|
+
this.logWarning("calculateRemainingTotalAmountAsync: 没有当前订单");
|
|
1827
|
+
return "0.00";
|
|
1828
|
+
}
|
|
1829
|
+
const totalAmount = new import_decimal.default(this.store.currentOrder.total_amount || "0");
|
|
1830
|
+
const paidAmountStr = await this.calculatePaidAmountAsync();
|
|
1831
|
+
const paidAmount = new import_decimal.default(paidAmountStr);
|
|
1832
|
+
const remainingAmount = totalAmount.sub(paidAmount);
|
|
1833
|
+
const result = import_decimal.default.max(0, remainingAmount).toFixed(2);
|
|
1834
|
+
this.logInfo("calculateRemainingTotalAmountAsync: 计算=", result);
|
|
1835
|
+
return result;
|
|
1836
|
+
}
|
|
1817
1837
|
/**
|
|
1818
1838
|
* 更新 balanceDueAmount 为当前剩余未支付金额(系统内部计算)
|
|
1819
1839
|
*/
|
|
1820
1840
|
async updateBalanceDueAmount() {
|
|
1821
1841
|
try {
|
|
1822
1842
|
const remainingAmount = await this.calculateRemainingAmountAsync();
|
|
1843
|
+
const remainingTotalAmount = await this.calculateRemainingTotalAmountAsync();
|
|
1823
1844
|
const currentBalanceDueAmount = this.store.balanceDueAmount;
|
|
1824
1845
|
if (remainingAmount !== currentBalanceDueAmount) {
|
|
1825
1846
|
this.store.balanceDueAmount = remainingAmount;
|
|
1826
1847
|
await this.core.effects.emit(import_types.CheckoutHooks.OnBalanceDueAmountChanged, {
|
|
1827
1848
|
oldAmount: currentBalanceDueAmount,
|
|
1828
1849
|
newAmount: remainingAmount,
|
|
1829
|
-
timestamp: Date.now()
|
|
1850
|
+
timestamp: Date.now(),
|
|
1851
|
+
totalAmount: remainingTotalAmount
|
|
1830
1852
|
});
|
|
1831
1853
|
this.logInfo("balanceDueAmount 已自动更新:", {
|
|
1832
1854
|
oldAmount: currentBalanceDueAmount,
|
|
@@ -1860,7 +1882,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1860
1882
|
}
|
|
1861
1883
|
const amount = new import_decimal.default(item.amount || "0");
|
|
1862
1884
|
const roundingAmount = new import_decimal.default(item.rounding_amount || "0");
|
|
1863
|
-
return sum.add(amount.add(roundingAmount.abs()));
|
|
1885
|
+
return sum.add(amount.add(roundingAmount.isNegative() ? roundingAmount.abs() : 0));
|
|
1864
1886
|
}, new import_decimal.default(0));
|
|
1865
1887
|
if (depositPaidAmount.gte((_c = this.store.currentOrder) == null ? void 0 : _c.deposit_amount)) {
|
|
1866
1888
|
this.store.currentOrder = {
|
|
@@ -1873,13 +1895,15 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1873
1895
|
}
|
|
1874
1896
|
}
|
|
1875
1897
|
const remainingAmount = await this.calculateRemainingAmountAsync();
|
|
1898
|
+
const remainingTotalAmount = await this.calculateRemainingTotalAmountAsync();
|
|
1876
1899
|
const currentStateAmount = this.store.stateAmount;
|
|
1877
1900
|
if (remainingAmount !== currentStateAmount) {
|
|
1878
1901
|
this.store.stateAmount = remainingAmount;
|
|
1879
1902
|
this.core.effects.emit(import_types.CheckoutHooks.OnStateAmountChanged, {
|
|
1880
1903
|
oldAmount: currentStateAmount,
|
|
1881
1904
|
newAmount: remainingAmount,
|
|
1882
|
-
timestamp: Date.now()
|
|
1905
|
+
timestamp: Date.now(),
|
|
1906
|
+
totalAmount: remainingTotalAmount
|
|
1883
1907
|
});
|
|
1884
1908
|
this.logInfo("stateAmount 已自动更新为剩余金额:", {
|
|
1885
1909
|
oldAmount: currentStateAmount,
|
|
@@ -1946,7 +1970,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1946
1970
|
code: p.code,
|
|
1947
1971
|
amount: p.amount,
|
|
1948
1972
|
rounding_amount: p.rounding_amount,
|
|
1949
|
-
effective_amount: (parseFloat(p.amount || "0") + Math.abs(parseFloat(p.rounding_amount || "0"))).toFixed(2),
|
|
1973
|
+
effective_amount: (parseFloat(p.amount || "0") + Math.abs(parseFloat(Number(p.rounding_amount) > 0 ? "0" : p.rounding_amount || "0"))).toFixed(2),
|
|
1950
1974
|
voucher_id: p.voucher_id,
|
|
1951
1975
|
status: p.status
|
|
1952
1976
|
}))
|
|
@@ -2024,6 +2048,24 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2024
2048
|
reason: "手动设置和计算值均为0"
|
|
2025
2049
|
});
|
|
2026
2050
|
}
|
|
2051
|
+
if (this.store.currentOrder.is_deposit === 0 && processedPaymentItems.every((item) => item.order_payment_type !== "deposit")) {
|
|
2052
|
+
finalDepositAmount = "0.00";
|
|
2053
|
+
this.store.currentOrder.is_deposit = 0;
|
|
2054
|
+
}
|
|
2055
|
+
if (this.store.currentOrder.is_deposit === 0 && processedPaymentItems.some((item) => item.order_payment_type === "deposit")) {
|
|
2056
|
+
finalDepositAmount = processedPaymentItems.filter((item) => item.status !== "voided" && item.order_payment_type === "deposit").reduce((sum, item) => {
|
|
2057
|
+
const amt = new import_decimal.default(item.amount || "0");
|
|
2058
|
+
const rounding = new import_decimal.default(item.rounding_amount || "0");
|
|
2059
|
+
return sum.plus(amt).sub(rounding);
|
|
2060
|
+
}, new import_decimal.default(0)).toFixed(2);
|
|
2061
|
+
}
|
|
2062
|
+
if (this.store.currentOrder.is_deposit === 1 && new import_decimal.default(finalDepositAmount).gte(new import_decimal.default(this.store.currentOrder.total_amount))) {
|
|
2063
|
+
finalDepositAmount = processedPaymentItems.filter((item) => item.status !== "voided" && item.order_payment_type === "deposit").reduce((sum, item) => {
|
|
2064
|
+
const amt = new import_decimal.default(item.amount || "0");
|
|
2065
|
+
const rounding = new import_decimal.default(item.rounding_amount || "0");
|
|
2066
|
+
return sum.plus(amt).sub(rounding);
|
|
2067
|
+
}, new import_decimal.default(0)).toFixed(2);
|
|
2068
|
+
}
|
|
2027
2069
|
this.logInfo("定金金额确定结果", {
|
|
2028
2070
|
depositPaymentItemsCount: processedPaymentItems.length,
|
|
2029
2071
|
depositPaymentItems: processedPaymentItems.map((item) => ({
|
|
@@ -2411,11 +2453,19 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2411
2453
|
* @returns 舍入结果详情,包含原始金额、舍入后金额和舍入差额
|
|
2412
2454
|
*/
|
|
2413
2455
|
async roundAmountAsync(amount) {
|
|
2414
|
-
var _a, _b;
|
|
2456
|
+
var _a, _b, _c;
|
|
2457
|
+
const cashManualPayment = this.store.paymentMethods.find((p) => p.code === "CASHMANUAL");
|
|
2458
|
+
if (!((_a = cashManualPayment == null ? void 0 : cashManualPayment.metadata) == null ? void 0 : _a.order_rounding_switch)) {
|
|
2459
|
+
return {
|
|
2460
|
+
originalAmount: amount.toString(),
|
|
2461
|
+
roundedAmount: amount.toString(),
|
|
2462
|
+
roundingDifference: "0.00"
|
|
2463
|
+
};
|
|
2464
|
+
}
|
|
2415
2465
|
const result = await this.payment.roundAmountAsync(
|
|
2416
2466
|
amount,
|
|
2417
|
-
(
|
|
2418
|
-
(
|
|
2467
|
+
(_b = this.otherParams.order_rounding_setting) == null ? void 0 : _b.interval,
|
|
2468
|
+
(_c = this.otherParams.order_rounding_setting) == null ? void 0 : _c.type
|
|
2419
2469
|
);
|
|
2420
2470
|
return result;
|
|
2421
2471
|
}
|