@pisell/pisellos 0.0.262 → 0.0.264
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/Cart/utils/cartProduct.js +9 -2
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/Checkout/index.d.ts +10 -0
- package/dist/solution/Checkout/index.js +616 -444
- package/dist/solution/Checkout/types.d.ts +6 -0
- package/lib/modules/Cart/utils/cartProduct.js +9 -2
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/Checkout/index.d.ts +10 -0
- package/lib/solution/Checkout/index.js +138 -9
- package/lib/solution/Checkout/types.d.ts +6 -0
- package/package.json +1 -1
|
@@ -438,6 +438,12 @@ export interface CheckoutModuleAPI extends Module {
|
|
|
438
438
|
* 修改当前订单的定金状态
|
|
439
439
|
*/
|
|
440
440
|
updateOrderDepositStatusAsync(isDeposit: number): Promise<void>;
|
|
441
|
+
/**
|
|
442
|
+
* 手动设置当前订单的定金金额
|
|
443
|
+
*
|
|
444
|
+
* @param depositAmount 定金金额,必须是有效的数字字符串,且不能超过订单总额
|
|
445
|
+
*/
|
|
446
|
+
setDepositAmountAsync(depositAmount: string): Promise<void>;
|
|
441
447
|
/**
|
|
442
448
|
* 手动同步订单到后端
|
|
443
449
|
*
|
|
@@ -44,6 +44,7 @@ __export(cartProduct_exports, {
|
|
|
44
44
|
module.exports = __toCommonJS(cartProduct_exports);
|
|
45
45
|
var import_decimal = __toESM(require("decimal.js"));
|
|
46
46
|
var import_utils = require("../../Product/utils");
|
|
47
|
+
var import_utils2 = require("../../../solution/ShopDiscount/utils");
|
|
47
48
|
var handleVariantProduct = (product) => {
|
|
48
49
|
var _a;
|
|
49
50
|
if (product == null ? void 0 : product.product_variant_id) {
|
|
@@ -183,9 +184,15 @@ var getProductTotalPrice = (params) => {
|
|
|
183
184
|
}
|
|
184
185
|
if (discounts == null ? void 0 : discounts.length) {
|
|
185
186
|
discounts.forEach((currentValue) => {
|
|
187
|
+
var _a;
|
|
186
188
|
if (currentValue.type !== "good_pass") {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
+
price = (0, import_utils2.getDiscountAmount)({
|
|
190
|
+
tag: currentValue.type,
|
|
191
|
+
par_value: currentValue.discount.percent,
|
|
192
|
+
metadata: {
|
|
193
|
+
discount_card_type: (_a = currentValue == null ? void 0 : currentValue.discount) == null ? void 0 : _a.discount_card_type
|
|
194
|
+
}
|
|
195
|
+
}, price, price);
|
|
189
196
|
}
|
|
190
197
|
});
|
|
191
198
|
}
|
|
@@ -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
|
}
|
|
@@ -314,7 +314,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
314
314
|
}[];
|
|
315
315
|
setOtherData(key: string, value: any): void;
|
|
316
316
|
getOtherData(key: string): any;
|
|
317
|
-
getProductTypeById(id: number): Promise<"
|
|
317
|
+
getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
|
|
318
318
|
/**
|
|
319
319
|
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
320
320
|
*
|
|
@@ -182,6 +182,16 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
|
|
|
182
182
|
* @throws 当前没有活跃订单时抛出错误
|
|
183
183
|
*/
|
|
184
184
|
updateOrderDepositStatusAsync(isDeposit: number): Promise<void>;
|
|
185
|
+
/**
|
|
186
|
+
* 手动设置当前订单的定金金额
|
|
187
|
+
*
|
|
188
|
+
* 允许手动设置订单的定金金额,通常用于用户自定义定金支付场景
|
|
189
|
+
*
|
|
190
|
+
* @param depositAmount 定金金额,必须是有效的数字字符串,且不能超过订单总额
|
|
191
|
+
* @throws 当前没有活跃订单时抛出错误
|
|
192
|
+
* @throws 定金金额格式无效或超过订单总额时抛出错误
|
|
193
|
+
*/
|
|
194
|
+
setDepositAmountAsync(depositAmount: string): Promise<void>;
|
|
185
195
|
/**
|
|
186
196
|
* 手动同步订单到后端
|
|
187
197
|
*
|
|
@@ -913,6 +913,107 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
913
913
|
throw error;
|
|
914
914
|
}
|
|
915
915
|
}
|
|
916
|
+
/**
|
|
917
|
+
* 手动设置当前订单的定金金额
|
|
918
|
+
*
|
|
919
|
+
* 允许手动设置订单的定金金额,通常用于用户自定义定金支付场景
|
|
920
|
+
*
|
|
921
|
+
* @param depositAmount 定金金额,必须是有效的数字字符串,且不能超过订单总额
|
|
922
|
+
* @throws 当前没有活跃订单时抛出错误
|
|
923
|
+
* @throws 定金金额格式无效或超过订单总额时抛出错误
|
|
924
|
+
*/
|
|
925
|
+
async setDepositAmountAsync(depositAmount) {
|
|
926
|
+
var _a, _b;
|
|
927
|
+
this.logInfo("setDepositAmountAsync called", {
|
|
928
|
+
depositAmount,
|
|
929
|
+
hasCurrentOrder: !!this.store.currentOrder,
|
|
930
|
+
currentOrderId: (_a = this.store.currentOrder) == null ? void 0 : _a.order_id,
|
|
931
|
+
currentTotalAmount: (_b = this.store.currentOrder) == null ? void 0 : _b.total_amount
|
|
932
|
+
});
|
|
933
|
+
try {
|
|
934
|
+
const depositValue = new import_decimal.default(depositAmount);
|
|
935
|
+
if (depositValue.isNaN() || depositValue.lt(0)) {
|
|
936
|
+
throw (0, import_utils.createCheckoutError)(
|
|
937
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
938
|
+
`无效的定金金额格式: ${depositAmount}`
|
|
939
|
+
);
|
|
940
|
+
}
|
|
941
|
+
if (!this.store.currentOrder) {
|
|
942
|
+
throw (0, import_utils.createCheckoutError)(
|
|
943
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
944
|
+
"未找到当前订单,无法设置定金金额"
|
|
945
|
+
);
|
|
946
|
+
}
|
|
947
|
+
const totalAmount = new import_decimal.default(this.store.currentOrder.total_amount || "0");
|
|
948
|
+
if (depositValue.gt(totalAmount)) {
|
|
949
|
+
throw (0, import_utils.createCheckoutError)(
|
|
950
|
+
import_types.CheckoutErrorType.ValidationFailed,
|
|
951
|
+
`定金金额 ${depositAmount} 不能超过订单总额 ${totalAmount.toFixed(2)}`
|
|
952
|
+
);
|
|
953
|
+
}
|
|
954
|
+
const formattedDepositAmount = depositValue.toFixed(2);
|
|
955
|
+
const oldDepositAmount = this.store.currentOrder.deposit_amount || "0.00";
|
|
956
|
+
if (formattedDepositAmount === oldDepositAmount) {
|
|
957
|
+
this.logInfo("定金金额无变化,跳过更新:", {
|
|
958
|
+
currentAmount: oldDepositAmount,
|
|
959
|
+
newAmount: formattedDepositAmount
|
|
960
|
+
});
|
|
961
|
+
return;
|
|
962
|
+
}
|
|
963
|
+
this.logInfo("开始设置订单定金金额:", {
|
|
964
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
965
|
+
orderId: this.store.currentOrder.order_id,
|
|
966
|
+
oldDepositAmount,
|
|
967
|
+
newDepositAmount: formattedDepositAmount,
|
|
968
|
+
totalAmount: totalAmount.toFixed(2)
|
|
969
|
+
});
|
|
970
|
+
const updateParams = {
|
|
971
|
+
deposit_amount: formattedDepositAmount
|
|
972
|
+
};
|
|
973
|
+
if (depositValue.gt(0) && this.store.currentOrder.is_deposit !== 1) {
|
|
974
|
+
updateParams.is_deposit = 1;
|
|
975
|
+
this.logInfo("定金金额大于0,自动设置为定金订单");
|
|
976
|
+
} else if (depositValue.eq(0) && this.store.currentOrder.is_deposit === 1) {
|
|
977
|
+
updateParams.is_deposit = 0;
|
|
978
|
+
this.logInfo("定金金额为0,自动设置为全款订单");
|
|
979
|
+
}
|
|
980
|
+
await this.payment.updateOrderAsync(
|
|
981
|
+
this.store.currentOrder.uuid,
|
|
982
|
+
updateParams
|
|
983
|
+
);
|
|
984
|
+
this.store.currentOrder = {
|
|
985
|
+
...this.store.currentOrder,
|
|
986
|
+
...updateParams
|
|
987
|
+
};
|
|
988
|
+
if (this.store.localOrderData) {
|
|
989
|
+
if ("deposit_amount" in this.store.localOrderData) {
|
|
990
|
+
this.store.localOrderData.deposit_amount = formattedDepositAmount;
|
|
991
|
+
}
|
|
992
|
+
if (updateParams.is_deposit !== void 0) {
|
|
993
|
+
this.store.localOrderData.is_deposit = updateParams.is_deposit;
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
|
|
997
|
+
order: this.store.currentOrder,
|
|
998
|
+
timestamp: Date.now()
|
|
999
|
+
});
|
|
1000
|
+
this.logInfo("订单定金金额设置成功:", {
|
|
1001
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
1002
|
+
orderId: this.store.currentOrder.order_id,
|
|
1003
|
+
oldDepositAmount,
|
|
1004
|
+
newDepositAmount: formattedDepositAmount,
|
|
1005
|
+
isDeposit: this.store.currentOrder.is_deposit,
|
|
1006
|
+
totalAmount: this.store.currentOrder.total_amount
|
|
1007
|
+
});
|
|
1008
|
+
} catch (error) {
|
|
1009
|
+
this.logError("设置订单定金金额失败:", error);
|
|
1010
|
+
await this.handleError(
|
|
1011
|
+
error,
|
|
1012
|
+
import_types.CheckoutErrorType.ValidationFailed
|
|
1013
|
+
);
|
|
1014
|
+
throw error;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
916
1017
|
/**
|
|
917
1018
|
* 手动同步订单到后端
|
|
918
1019
|
*
|
|
@@ -1631,7 +1732,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1631
1732
|
* @returns 包含订单ID、UUID和完整后端响应的对象
|
|
1632
1733
|
*/
|
|
1633
1734
|
async syncOrderToBackendWithReturn(isManual = false, customPaymentItems) {
|
|
1634
|
-
var _a, _b, _c, _d, _e;
|
|
1735
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1635
1736
|
if (!this.store.localOrderData || !this.store.currentOrder) {
|
|
1636
1737
|
throw new Error("缺少必要的订单数据,无法同步到后端");
|
|
1637
1738
|
}
|
|
@@ -1657,6 +1758,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1657
1758
|
}
|
|
1658
1759
|
};
|
|
1659
1760
|
});
|
|
1761
|
+
let finalDepositAmount;
|
|
1762
|
+
const manualDepositAmount = ((_a = this.store.currentOrder) == null ? void 0 : _a.deposit_amount) || "0.00";
|
|
1660
1763
|
const depositPaymentItems = processedPaymentItems.filter(
|
|
1661
1764
|
(item) => item.order_payment_type === "deposit" && item.status !== "voided"
|
|
1662
1765
|
);
|
|
@@ -1666,7 +1769,31 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1666
1769
|
const effectiveAmount = amount.add(roundingAmount.abs());
|
|
1667
1770
|
return sum.add(effectiveAmount);
|
|
1668
1771
|
}, new import_decimal.default(0)).toFixed(2);
|
|
1669
|
-
|
|
1772
|
+
const manualDepositValue = new import_decimal.default(manualDepositAmount);
|
|
1773
|
+
const calculatedDepositValue = new import_decimal.default(calculatedDepositAmount);
|
|
1774
|
+
if (manualDepositValue.gt(0)) {
|
|
1775
|
+
finalDepositAmount = manualDepositAmount;
|
|
1776
|
+
this.logInfo("使用手动设置的定金金额", {
|
|
1777
|
+
manualDepositAmount,
|
|
1778
|
+
calculatedDepositAmount,
|
|
1779
|
+
reason: "用户通过setDepositAmountAsync手动设置了定金金额"
|
|
1780
|
+
});
|
|
1781
|
+
} else if (calculatedDepositValue.gt(0)) {
|
|
1782
|
+
finalDepositAmount = calculatedDepositAmount;
|
|
1783
|
+
this.logInfo("使用从支付项计算的定金金额", {
|
|
1784
|
+
manualDepositAmount,
|
|
1785
|
+
calculatedDepositAmount,
|
|
1786
|
+
reason: "未手动设置定金金额,从定金类型支付项计算得出"
|
|
1787
|
+
});
|
|
1788
|
+
} else {
|
|
1789
|
+
finalDepositAmount = "0.00";
|
|
1790
|
+
this.logInfo("定金金额为0", {
|
|
1791
|
+
manualDepositAmount,
|
|
1792
|
+
calculatedDepositAmount,
|
|
1793
|
+
reason: "手动设置和计算值均为0"
|
|
1794
|
+
});
|
|
1795
|
+
}
|
|
1796
|
+
this.logInfo("定金金额确定结果", {
|
|
1670
1797
|
depositPaymentItemsCount: depositPaymentItems.length,
|
|
1671
1798
|
depositPaymentItems: depositPaymentItems.map((item) => ({
|
|
1672
1799
|
uuid: item.uuid,
|
|
@@ -1676,8 +1803,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1676
1803
|
order_payment_type: item.order_payment_type,
|
|
1677
1804
|
status: item.status
|
|
1678
1805
|
})),
|
|
1806
|
+
manualDepositAmount,
|
|
1679
1807
|
calculatedDepositAmount,
|
|
1680
|
-
|
|
1808
|
+
finalDepositAmount,
|
|
1809
|
+
isDeposit: ((_b = this.store.currentOrder) == null ? void 0 : _b.is_deposit) || 0
|
|
1681
1810
|
});
|
|
1682
1811
|
const orderParams = {
|
|
1683
1812
|
...this.store.localOrderData,
|
|
@@ -1685,7 +1814,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1685
1814
|
platform: this.store.localOrderData.platform,
|
|
1686
1815
|
payments: processedPaymentItems,
|
|
1687
1816
|
// 使用处理过的支付项数据
|
|
1688
|
-
customer_id: (
|
|
1817
|
+
customer_id: (_c = this.store.currentCustomer) == null ? void 0 : _c.customer_id,
|
|
1689
1818
|
// 添加客户ID
|
|
1690
1819
|
is_price_include_tax: this.otherParams.is_price_include_tax,
|
|
1691
1820
|
// core 有
|
|
@@ -1698,9 +1827,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1698
1827
|
currency_code: this.otherParams.currency_code,
|
|
1699
1828
|
currency_symbol: this.otherParams.currency_symbol,
|
|
1700
1829
|
currency_format: this.otherParams.currency_format,
|
|
1701
|
-
is_deposit: ((
|
|
1702
|
-
deposit_amount:
|
|
1703
|
-
//
|
|
1830
|
+
is_deposit: ((_d = this.store.currentOrder) == null ? void 0 : _d.is_deposit) || 0,
|
|
1831
|
+
deposit_amount: finalDepositAmount,
|
|
1832
|
+
// 使用最终确定的定金金额(手动设置优先)
|
|
1704
1833
|
product_tax_fee: this.store.localOrderData.tax_fee,
|
|
1705
1834
|
note: this.store.localOrderData.shop_note
|
|
1706
1835
|
};
|
|
@@ -1753,7 +1882,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1753
1882
|
orderUuid: this.store.currentOrder.uuid,
|
|
1754
1883
|
operation: isUpdateOperation ? "update" : "create",
|
|
1755
1884
|
isManual,
|
|
1756
|
-
orderId: submitSuccess ? ((
|
|
1885
|
+
orderId: submitSuccess ? ((_e = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _e.order_id) || (checkoutResponse == null ? void 0 : checkoutResponse.order_id) : void 0,
|
|
1757
1886
|
error: submitError,
|
|
1758
1887
|
duration: Date.now() - startTime,
|
|
1759
1888
|
timestamp: Date.now()
|
|
@@ -1779,7 +1908,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1779
1908
|
if (isUpdateOperation) {
|
|
1780
1909
|
realOrderId = currentOrderId;
|
|
1781
1910
|
} else {
|
|
1782
|
-
let extractedOrderId = (
|
|
1911
|
+
let extractedOrderId = (_f = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _f.order_id;
|
|
1783
1912
|
if (!extractedOrderId) {
|
|
1784
1913
|
extractedOrderId = checkoutResponse == null ? void 0 : checkoutResponse.order_id;
|
|
1785
1914
|
}
|
|
@@ -438,6 +438,12 @@ export interface CheckoutModuleAPI extends Module {
|
|
|
438
438
|
* 修改当前订单的定金状态
|
|
439
439
|
*/
|
|
440
440
|
updateOrderDepositStatusAsync(isDeposit: number): Promise<void>;
|
|
441
|
+
/**
|
|
442
|
+
* 手动设置当前订单的定金金额
|
|
443
|
+
*
|
|
444
|
+
* @param depositAmount 定金金额,必须是有效的数字字符串,且不能超过订单总额
|
|
445
|
+
*/
|
|
446
|
+
setDepositAmountAsync(depositAmount: string): Promise<void>;
|
|
441
447
|
/**
|
|
442
448
|
* 手动同步订单到后端
|
|
443
449
|
*
|