@pisell/pisellos 2.1.11 → 2.1.13
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/Discount/types.d.ts +3 -0
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/Rules/index.js +39 -12
- 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/dist/solution/ShopDiscount/utils.d.ts +11 -0
- package/dist/solution/ShopDiscount/utils.js +29 -0
- package/lib/modules/Cart/utils/cartProduct.js +9 -2
- package/lib/modules/Discount/types.d.ts +3 -0
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Rules/index.js +25 -7
- 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/lib/solution/ShopDiscount/utils.d.ts +11 -0
- package/lib/solution/ShopDiscount/utils.js +24 -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
|
*
|
|
@@ -1 +1,12 @@
|
|
|
1
|
+
import { Discount } from "../../modules/Discount/types";
|
|
1
2
|
export declare const uniqueById: <T>(arr: T[], key?: string) => T[];
|
|
3
|
+
/**
|
|
4
|
+
* 获取折扣金额 基于折扣卡类型计算
|
|
5
|
+
* 商品券:直接返回商品价格
|
|
6
|
+
* 折扣卡:根据折扣卡类型计算 固定金额:直接返回折扣卡金额 百分比:根据折扣卡金额计算
|
|
7
|
+
* @param discount
|
|
8
|
+
* @param total
|
|
9
|
+
* @param price
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare const getDiscountAmount: (discount: Discount, total: number, price: number) => number;
|
|
@@ -1,7 +1,36 @@
|
|
|
1
|
+
import Decimal from "decimal.js";
|
|
1
2
|
export var uniqueById = function uniqueById(arr) {
|
|
2
3
|
var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'id';
|
|
3
4
|
var seen = new Set();
|
|
4
5
|
return arr.filter(function (item) {
|
|
5
6
|
return !seen.has(item[key]) && seen.add(item[key]);
|
|
6
7
|
});
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 获取折扣金额 基于折扣卡类型计算
|
|
12
|
+
* 商品券:直接返回商品价格
|
|
13
|
+
* 折扣卡:根据折扣卡类型计算 固定金额:直接返回折扣卡金额 百分比:根据折扣卡金额计算
|
|
14
|
+
* @param discount
|
|
15
|
+
* @param total
|
|
16
|
+
* @param price
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
export var getDiscountAmount = function getDiscountAmount(discount, total, price) {
|
|
20
|
+
var _discount$metadata;
|
|
21
|
+
// 商品券
|
|
22
|
+
if (discount.tag === 'good_pass') {
|
|
23
|
+
return new Decimal(total).minus(new Decimal(price || 0)).toNumber();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 判断是否是固定金额
|
|
27
|
+
var isFixedAmount = (discount === null || discount === void 0 || (_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.discount_card_type) === 'fixed_amount';
|
|
28
|
+
|
|
29
|
+
// 固定金额 小于0时返回0
|
|
30
|
+
if (isFixedAmount) {
|
|
31
|
+
return Math.max(new Decimal(total).minus(new Decimal(discount.par_value || 0)).toNumber(), 0);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// 百分比:根据折扣卡金额计算
|
|
35
|
+
return new Decimal(100).minus(discount.par_value || 0).div(100).mul(new Decimal(total)).toNumber();
|
|
7
36
|
};
|
|
@@ -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
|
}
|
|
@@ -70,6 +70,9 @@ export interface Discount {
|
|
|
70
70
|
limited_relation_product_data: Limitedrelationproductdata;
|
|
71
71
|
balance: string;
|
|
72
72
|
format_title: Formattitle;
|
|
73
|
+
metadata?: {
|
|
74
|
+
discount_card_type?: 'fixed_amount' | 'percent';
|
|
75
|
+
};
|
|
73
76
|
product: Product;
|
|
74
77
|
type: "product" | 'good_pass';
|
|
75
78
|
resource_id?: number;
|
|
@@ -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
|
}
|
|
@@ -132,6 +132,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
132
132
|
return !discount.isManualSelect;
|
|
133
133
|
});
|
|
134
134
|
const sortedDiscountList = [...filteredDiscountList].sort((a, b) => {
|
|
135
|
+
var _a, _b;
|
|
135
136
|
if (a.tag === "good_pass" && b.tag !== "good_pass")
|
|
136
137
|
return -1;
|
|
137
138
|
if (b.tag === "good_pass" && a.tag !== "good_pass")
|
|
@@ -139,10 +140,25 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
139
140
|
if (a.tag === "good_pass" && b.tag === "good_pass") {
|
|
140
141
|
return compareByExpireTime(a, b);
|
|
141
142
|
} else if (a.tag === "product_discount_card" && b.tag === "product_discount_card") {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
return
|
|
143
|
+
const typeA = ((_a = a.metadata) == null ? void 0 : _a.discount_card_type) || "percent";
|
|
144
|
+
const typeB = ((_b = b.metadata) == null ? void 0 : _b.discount_card_type) || "percent";
|
|
145
|
+
if (typeA === "fixed_amount" && typeB === "percent")
|
|
146
|
+
return -1;
|
|
147
|
+
if (typeA === "percent" && typeB === "fixed_amount")
|
|
148
|
+
return 1;
|
|
149
|
+
if (typeA === "fixed_amount" && typeB === "fixed_amount") {
|
|
150
|
+
if (a.par_value !== b.par_value) {
|
|
151
|
+
const valueA = new import_decimal.default(a.par_value || 0);
|
|
152
|
+
const valueB = new import_decimal.default(b.par_value || 0);
|
|
153
|
+
return valueB.minus(valueA).toNumber();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (typeA === "percent" && typeB === "percent") {
|
|
157
|
+
if (a.par_value !== b.par_value) {
|
|
158
|
+
const valueA = new import_decimal.default(100).minus(a.par_value || 0);
|
|
159
|
+
const valueB = new import_decimal.default(100).minus(b.par_value || 0);
|
|
160
|
+
return valueB.minus(valueA).toNumber();
|
|
161
|
+
}
|
|
146
162
|
}
|
|
147
163
|
return compareByExpireTime(a, b);
|
|
148
164
|
}
|
|
@@ -182,7 +198,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
182
198
|
sortedProductList.forEach((originProduct) => {
|
|
183
199
|
const product = this.hooks.getProduct(originProduct);
|
|
184
200
|
addModeDiscount.forEach((discount) => {
|
|
185
|
-
var _a, _b, _c;
|
|
201
|
+
var _a, _b, _c, _d;
|
|
186
202
|
const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
|
|
187
203
|
const isLimitedProduct = limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id);
|
|
188
204
|
const isAvailableProduct = !((product == null ? void 0 : product.booking_id) && ((_a = product == null ? void 0 : product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount2) => discount2.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount2.tag || discount2.type))));
|
|
@@ -195,6 +211,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
195
211
|
type: discountType,
|
|
196
212
|
tag: discountType,
|
|
197
213
|
discount: {
|
|
214
|
+
discount_card_type: (_d = discount == null ? void 0 : discount.metadata) == null ? void 0 : _d.discount_card_type,
|
|
198
215
|
resource_id: discount.id,
|
|
199
216
|
title: discount.format_title,
|
|
200
217
|
original_amount: product.origin_total,
|
|
@@ -212,7 +229,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
212
229
|
});
|
|
213
230
|
console.log(sortedProductList, "sortedProductListsortedProductList");
|
|
214
231
|
sortedProductList.forEach((originProduct, i) => {
|
|
215
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
232
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
216
233
|
const product = this.hooks.getProduct(originProduct);
|
|
217
234
|
if ((product == null ? void 0 : product.booking_id) && ((_a = product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount) => discount.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount.tag || discount.type)))) {
|
|
218
235
|
processedProductsMap.set(product._id, [originProduct]);
|
|
@@ -322,12 +339,13 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
322
339
|
if (Number(((_i = originProduct == null ? void 0 : originProduct._productInit) == null ? void 0 : _i.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
|
|
323
340
|
productOriginTotal = product.total;
|
|
324
341
|
}
|
|
325
|
-
const targetProductTotal =
|
|
342
|
+
const targetProductTotal = (0, import_utils.getDiscountAmount)(selectedDiscount2, productOriginTotal, product.price);
|
|
326
343
|
const discountType = selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag;
|
|
327
344
|
const discountDetail = {
|
|
328
345
|
amount: new import_decimal.default(productOriginTotal).minus(new import_decimal.default(targetProductTotal)).toNumber(),
|
|
329
346
|
type: discountType,
|
|
330
347
|
discount: {
|
|
348
|
+
discount_card_type: (_j = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _j.discount_card_type,
|
|
331
349
|
resource_id: selectedDiscount2.id,
|
|
332
350
|
title: selectedDiscount2.format_title,
|
|
333
351
|
original_amount: productOriginTotal,
|
|
@@ -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<"duration" | "session" | "normal">;
|
|
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
|
*
|
|
@@ -1 +1,12 @@
|
|
|
1
|
+
import { Discount } from "../../modules/Discount/types";
|
|
1
2
|
export declare const uniqueById: <T>(arr: T[], key?: string) => T[];
|
|
3
|
+
/**
|
|
4
|
+
* 获取折扣金额 基于折扣卡类型计算
|
|
5
|
+
* 商品券:直接返回商品价格
|
|
6
|
+
* 折扣卡:根据折扣卡类型计算 固定金额:直接返回折扣卡金额 百分比:根据折扣卡金额计算
|
|
7
|
+
* @param discount
|
|
8
|
+
* @param total
|
|
9
|
+
* @param price
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare const getDiscountAmount: (discount: Discount, total: number, price: number) => number;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __export = (target, all) => {
|
|
6
8
|
for (var name in all)
|
|
@@ -14,19 +16,41 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
16
|
}
|
|
15
17
|
return to;
|
|
16
18
|
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
17
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
28
|
|
|
19
29
|
// src/solution/ShopDiscount/utils.ts
|
|
20
30
|
var utils_exports = {};
|
|
21
31
|
__export(utils_exports, {
|
|
32
|
+
getDiscountAmount: () => getDiscountAmount,
|
|
22
33
|
uniqueById: () => uniqueById
|
|
23
34
|
});
|
|
24
35
|
module.exports = __toCommonJS(utils_exports);
|
|
36
|
+
var import_decimal = __toESM(require("decimal.js"));
|
|
25
37
|
var uniqueById = (arr, key = "id") => {
|
|
26
38
|
const seen = /* @__PURE__ */ new Set();
|
|
27
39
|
return arr.filter((item) => !seen.has(item[key]) && seen.add(item[key]));
|
|
28
40
|
};
|
|
41
|
+
var getDiscountAmount = (discount, total, price) => {
|
|
42
|
+
var _a;
|
|
43
|
+
if (discount.tag === "good_pass") {
|
|
44
|
+
return new import_decimal.default(total).minus(new import_decimal.default(price || 0)).toNumber();
|
|
45
|
+
}
|
|
46
|
+
const isFixedAmount = ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.discount_card_type) === "fixed_amount";
|
|
47
|
+
if (isFixedAmount) {
|
|
48
|
+
return Math.max(new import_decimal.default(total).minus(new import_decimal.default(discount.par_value || 0)).toNumber(), 0);
|
|
49
|
+
}
|
|
50
|
+
return new import_decimal.default(100).minus(discount.par_value || 0).div(100).mul(new import_decimal.default(total)).toNumber();
|
|
51
|
+
};
|
|
29
52
|
// Annotate the CommonJS export names for ESM import in node:
|
|
30
53
|
0 && (module.exports = {
|
|
54
|
+
getDiscountAmount,
|
|
31
55
|
uniqueById
|
|
32
56
|
});
|