@pisell/pisellos 0.0.293 → 0.0.295
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 +16 -14
- package/dist/modules/Payment/types.d.ts +4 -0
- package/dist/modules/Payment/walletpass.js +1 -1
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingByStep/index.js +15 -11
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/Checkout/index.d.ts +8 -0
- package/dist/solution/Checkout/index.js +278 -187
- package/lib/modules/Payment/index.js +2 -1
- package/lib/modules/Payment/types.d.ts +4 -0
- package/lib/modules/Payment/walletpass.js +1 -1
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingByStep/index.js +9 -7
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/Checkout/index.d.ts +8 -0
- package/lib/solution/Checkout/index.js +142 -52
- package/package.json +1 -1
|
@@ -397,6 +397,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
397
397
|
const order = await this.dbManager.get("order", orderUuid);
|
|
398
398
|
if (order) {
|
|
399
399
|
const updatedOrder = { ...order, ...params };
|
|
400
|
+
this.recalculateOrderAmount(updatedOrder);
|
|
400
401
|
await this.dbManager.update("order", updatedOrder);
|
|
401
402
|
await this.core.effects.emit(import_types.PaymentHooks.OnOrderUpdated, updatedOrder);
|
|
402
403
|
await this.core.effects.emit(import_types.PaymentHooks.OnOrderChanged, {
|
|
@@ -914,7 +915,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
914
915
|
},
|
|
915
916
|
new import_decimal.Decimal(0)
|
|
916
917
|
);
|
|
917
|
-
const remainingAmount = totalAmount.minus(paidAmount);
|
|
918
|
+
const remainingAmount = order.is_deposit === 1 ? new import_decimal.Decimal(order.deposit_amount).minus(paidAmount) : totalAmount.minus(paidAmount);
|
|
918
919
|
order.expect_amount = import_decimal.Decimal.max(0, remainingAmount).toFixed(2);
|
|
919
920
|
console.log(`[PaymentModule] 重新计算订单金额:`, {
|
|
920
921
|
orderUuid: order.uuid,
|
|
@@ -60,7 +60,7 @@ var WalletPassPaymentImpl = class {
|
|
|
60
60
|
// 订单小计金额
|
|
61
61
|
order_product_amount: subTotal,
|
|
62
62
|
// 订单待支付金额
|
|
63
|
-
order_wait_pay_amount: order_wait_pay_amount || totalAmount,
|
|
63
|
+
order_wait_pay_amount: order_wait_pay_amount || ((amountInfo == null ? void 0 : amountInfo.isDeposit) ? Number(amountInfo == null ? void 0 : amountInfo.depositAmount) : totalAmount),
|
|
64
64
|
// order_behavior_count_customer_id: 1,
|
|
65
65
|
products,
|
|
66
66
|
prepare_payments: [],
|
|
@@ -326,7 +326,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
326
326
|
};
|
|
327
327
|
setOtherData(key: string, value: any): void;
|
|
328
328
|
getOtherData(key: string): any;
|
|
329
|
-
getProductTypeById(id: number): Promise<"
|
|
329
|
+
getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
|
|
330
330
|
/**
|
|
331
331
|
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
332
332
|
*
|
|
@@ -1829,13 +1829,15 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1829
1829
|
return !(0, import_dayjs.default)(n2.start_at).isAfter((0, import_dayjs.default)(item.start), "minute") && !(0, import_dayjs.default)(n2.end_at).isBefore((0, import_dayjs.default)(item.end), "minute") || (0, import_dayjs.default)(n2.start_at).isBefore((0, import_dayjs.default)(item.end), "minute") && (0, import_dayjs.default)(n2.end_at).isAfter((0, import_dayjs.default)(item.start), "minute");
|
|
1830
1830
|
});
|
|
1831
1831
|
const mSet = /* @__PURE__ */ new Map();
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1832
|
+
mTimes.forEach((n2) => {
|
|
1833
|
+
n2.event_list.forEach((m) => {
|
|
1834
|
+
if ((0, import_resources.isConflict)(
|
|
1835
|
+
{ start_at: m.start_at, end_at: m.end_at },
|
|
1836
|
+
{ start_at: (0, import_dayjs.default)(item.start), end_at: (0, import_dayjs.default)(item.end) }
|
|
1837
|
+
)) {
|
|
1838
|
+
mSet.set(m.id, m.pax || 1);
|
|
1839
|
+
}
|
|
1840
|
+
});
|
|
1839
1841
|
});
|
|
1840
1842
|
acc += Array.from(mSet.values()).reduce((acc2, curr2) => acc2 + curr2, 0);
|
|
1841
1843
|
return acc;
|
|
@@ -111,7 +111,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
|
|
|
111
111
|
* 获取当前的客户搜索条件
|
|
112
112
|
* @returns 当前搜索条件
|
|
113
113
|
*/
|
|
114
|
-
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "
|
|
114
|
+
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
|
|
115
115
|
/**
|
|
116
116
|
* 获取客户列表状态(包含滚动加载相关状态)
|
|
117
117
|
* @returns 客户状态
|
|
@@ -56,6 +56,14 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
|
|
|
56
56
|
initWalletData(params?: {
|
|
57
57
|
order_wait_pay_amount: number;
|
|
58
58
|
}): Promise<void>;
|
|
59
|
+
checkIsNeedDepositAsync(bookings: any[], relationProducts: any[]): {
|
|
60
|
+
total: number;
|
|
61
|
+
protocols: {
|
|
62
|
+
id: number;
|
|
63
|
+
title: string;
|
|
64
|
+
}[];
|
|
65
|
+
hasDeposit: boolean;
|
|
66
|
+
};
|
|
59
67
|
/**
|
|
60
68
|
* 创建本地订单 (前端模拟下单流程)
|
|
61
69
|
*
|
|
@@ -40,6 +40,7 @@ var import_Payment = require("../../modules/Payment");
|
|
|
40
40
|
var import_types = require("./types");
|
|
41
41
|
var import_types2 = require("../../modules/Payment/types");
|
|
42
42
|
var import_utils = require("./utils");
|
|
43
|
+
var import_utils2 = require("../../modules/Cart/utils");
|
|
43
44
|
__reExport(Checkout_exports, require("./types"), module.exports);
|
|
44
45
|
var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
45
46
|
constructor(name, version) {
|
|
@@ -221,7 +222,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
221
222
|
return [...productList, ...relationProducts];
|
|
222
223
|
}
|
|
223
224
|
async initWalletData(params) {
|
|
224
|
-
var _a, _b, _c, _d, _e;
|
|
225
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
225
226
|
this.logInfo("initWalletData called", {
|
|
226
227
|
params
|
|
227
228
|
});
|
|
@@ -236,13 +237,15 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
236
237
|
customer_id: ((_c = this.store.currentCustomer) == null ? void 0 : _c.customer_id) ? Number(this.store.currentCustomer.customer_id) : void 0,
|
|
237
238
|
amountInfo: {
|
|
238
239
|
totalAmount: amountInfo.totalAmount,
|
|
239
|
-
subTotal: amountInfo.subTotal
|
|
240
|
+
subTotal: amountInfo.subTotal,
|
|
241
|
+
depositAmount: (_d = this.store.currentOrder) == null ? void 0 : _d.deposit_amount,
|
|
242
|
+
isDeposit: (_e = this.store.currentOrder) == null ? void 0 : _e.is_deposit
|
|
240
243
|
},
|
|
241
244
|
products: this.getProductListByOrder(),
|
|
242
245
|
...params
|
|
243
246
|
};
|
|
244
247
|
if (this.store.isOrderSynced) {
|
|
245
|
-
walletBusinessData.payment_order_id = (
|
|
248
|
+
walletBusinessData.payment_order_id = (_f = this.store.currentOrder) == null ? void 0 : _f.order_id;
|
|
246
249
|
}
|
|
247
250
|
this.logInfo("开始拉取:initializeWalletDataFromBusinessAsync", {
|
|
248
251
|
walletBusinessData
|
|
@@ -260,7 +263,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
260
263
|
currentOrder: this.store.currentOrder
|
|
261
264
|
});
|
|
262
265
|
await this.core.effects.emit(import_types.CheckoutHooks.OnWalletDataInitialized, {
|
|
263
|
-
orderUuid: (
|
|
266
|
+
orderUuid: (_g = this.store.currentOrder) == null ? void 0 : _g.uuid,
|
|
264
267
|
customerId: walletBusinessData.customer_id,
|
|
265
268
|
walletBusinessData: {
|
|
266
269
|
customer_id: walletBusinessData.customer_id,
|
|
@@ -270,6 +273,58 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
270
273
|
timestamp: Date.now()
|
|
271
274
|
});
|
|
272
275
|
}
|
|
276
|
+
checkIsNeedDepositAsync(bookings, relationProducts) {
|
|
277
|
+
const summaryDeposit = {
|
|
278
|
+
total: 0,
|
|
279
|
+
protocols: [],
|
|
280
|
+
hasDeposit: false
|
|
281
|
+
};
|
|
282
|
+
bookings == null ? void 0 : bookings.forEach((item) => {
|
|
283
|
+
const deposit = (0, import_utils2.getProductDeposit)({
|
|
284
|
+
cartItem: {
|
|
285
|
+
total: item.product.price * item.num
|
|
286
|
+
},
|
|
287
|
+
product: item.product,
|
|
288
|
+
bundle: item.bundle,
|
|
289
|
+
options: item.options,
|
|
290
|
+
num: item.num
|
|
291
|
+
});
|
|
292
|
+
item.deposit = deposit;
|
|
293
|
+
if ((deposit == null ? void 0 : deposit.total) && Number(deposit.total) > 0) {
|
|
294
|
+
summaryDeposit.total = new import_decimal.default(summaryDeposit.total).plus(deposit.total).toNumber();
|
|
295
|
+
item.product.discount_list.forEach((discount) => {
|
|
296
|
+
summaryDeposit.total = new import_decimal.default(summaryDeposit.total).minus(discount.amount || 0).toNumber();
|
|
297
|
+
});
|
|
298
|
+
summaryDeposit.protocols = summaryDeposit.protocols.concat(
|
|
299
|
+
deposit.protocols
|
|
300
|
+
);
|
|
301
|
+
summaryDeposit.hasDeposit = true;
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
relationProducts == null ? void 0 : relationProducts.forEach((item) => {
|
|
305
|
+
const deposit = (0, import_utils2.getProductDeposit)({
|
|
306
|
+
cartItem: {
|
|
307
|
+
total: item.price * item.num
|
|
308
|
+
},
|
|
309
|
+
product: item,
|
|
310
|
+
bundle: item.product_bundle,
|
|
311
|
+
options: item.product_option_item,
|
|
312
|
+
num: item.num
|
|
313
|
+
});
|
|
314
|
+
item.deposit = deposit;
|
|
315
|
+
if ((deposit == null ? void 0 : deposit.total) && Number(deposit.total) > 0) {
|
|
316
|
+
summaryDeposit.total = new import_decimal.default(summaryDeposit.total).plus(deposit.total).toNumber();
|
|
317
|
+
item.discount_list.forEach((discount) => {
|
|
318
|
+
summaryDeposit.total = new import_decimal.default(summaryDeposit.total).minus(discount.amount || 0).toNumber();
|
|
319
|
+
});
|
|
320
|
+
summaryDeposit.protocols = summaryDeposit.protocols.concat(
|
|
321
|
+
deposit.protocols
|
|
322
|
+
);
|
|
323
|
+
summaryDeposit.hasDeposit = true;
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
return summaryDeposit;
|
|
327
|
+
}
|
|
273
328
|
/**
|
|
274
329
|
* 创建本地订单 (前端模拟下单流程)
|
|
275
330
|
*
|
|
@@ -319,11 +374,15 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
319
374
|
this.store.currentCustomer = void 0;
|
|
320
375
|
console.log("[Checkout] 未提供客户信息");
|
|
321
376
|
}
|
|
377
|
+
const isNeedDeposit = this.checkIsNeedDepositAsync(
|
|
378
|
+
params.orderData.bookings,
|
|
379
|
+
params.orderData.relation_products
|
|
380
|
+
);
|
|
322
381
|
const paymentOrder = await this.payment.createPaymentOrderAsync({
|
|
323
382
|
order_id: localOrderId,
|
|
324
383
|
total_amount: amountInfo.totalAmount,
|
|
325
|
-
is_deposit:
|
|
326
|
-
deposit_amount:
|
|
384
|
+
is_deposit: isNeedDeposit.hasDeposit ? 1 : 0,
|
|
385
|
+
deposit_amount: isNeedDeposit.total ? isNeedDeposit.total.toString() : "0.00",
|
|
327
386
|
order_info: {
|
|
328
387
|
original_order_data: params.orderData,
|
|
329
388
|
cart_summary: params.cartSummary,
|
|
@@ -412,13 +471,17 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
412
471
|
);
|
|
413
472
|
if (existingOrder) {
|
|
414
473
|
const totalAmount = new import_decimal.default(amountInfo.totalAmount || "0");
|
|
415
|
-
const activePayments = (existingOrder.payment || []).filter(
|
|
474
|
+
const activePayments = (existingOrder.payment || []).filter(
|
|
475
|
+
(p) => p.status !== "voided"
|
|
476
|
+
);
|
|
416
477
|
const paidAmount = activePayments.reduce((sum, p) => {
|
|
417
478
|
const amt = new import_decimal.default(p.amount || "0");
|
|
418
479
|
const rounding = new import_decimal.default(p.rounding_amount || "0").abs();
|
|
419
480
|
return sum.plus(amt).plus(rounding);
|
|
420
481
|
}, new import_decimal.default(0));
|
|
421
|
-
const remaining = import_decimal.default.max(0, totalAmount.minus(paidAmount)).toFixed(
|
|
482
|
+
const remaining = import_decimal.default.max(0, totalAmount.minus(paidAmount)).toFixed(
|
|
483
|
+
2
|
|
484
|
+
);
|
|
422
485
|
await this.payment.updateOrderAsync(existingOrder.uuid, {
|
|
423
486
|
total_amount: amountInfo.totalAmount,
|
|
424
487
|
is_deposit: params.orderData.is_deposit || 0,
|
|
@@ -435,9 +498,14 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
435
498
|
amount_breakdown: amountInfo
|
|
436
499
|
}
|
|
437
500
|
});
|
|
438
|
-
const updated = await this.payment.getPaymentOrderByUuidAsync(
|
|
501
|
+
const updated = await this.payment.getPaymentOrderByUuidAsync(
|
|
502
|
+
existingOrder.uuid
|
|
503
|
+
);
|
|
439
504
|
if (!updated)
|
|
440
|
-
throw (0, import_utils.createCheckoutError)(
|
|
505
|
+
throw (0, import_utils.createCheckoutError)(
|
|
506
|
+
import_types.CheckoutErrorType.UnknownError,
|
|
507
|
+
"订单更新失败"
|
|
508
|
+
);
|
|
441
509
|
this.store.currentOrder = updated;
|
|
442
510
|
await this.updateStateAmountToRemaining(false);
|
|
443
511
|
this.logInfo("本地订单更新成功(保留支付项):", {
|
|
@@ -908,7 +976,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
908
976
|
"当前没有活跃订单,无法更新代金券支付项"
|
|
909
977
|
);
|
|
910
978
|
}
|
|
911
|
-
const paymentItems = await this.payment.getPaymentItemsAsync(
|
|
979
|
+
const paymentItems = await this.payment.getPaymentItemsAsync(
|
|
980
|
+
this.store.currentOrder.uuid
|
|
981
|
+
);
|
|
912
982
|
const allPaymentItemsSynced = paymentItems.every((item) => item.isSynced);
|
|
913
983
|
const remainingAmount = await this.calculateRemainingAmountAsync();
|
|
914
984
|
const remainingValue = new import_decimal.default(remainingAmount);
|
|
@@ -1028,6 +1098,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1028
1098
|
if (this.store.localOrderData) {
|
|
1029
1099
|
this.store.localOrderData.is_deposit = newDepositValue;
|
|
1030
1100
|
}
|
|
1101
|
+
this.updateStateAmountToRemaining();
|
|
1031
1102
|
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
|
|
1032
1103
|
order: this.store.currentOrder,
|
|
1033
1104
|
timestamp: Date.now()
|
|
@@ -1076,13 +1147,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1076
1147
|
"未找到当前订单,无法设置定金金额"
|
|
1077
1148
|
);
|
|
1078
1149
|
}
|
|
1079
|
-
const totalAmount = new import_decimal.default(this.store.currentOrder.total_amount || "0");
|
|
1080
|
-
if (depositValue.gt(totalAmount)) {
|
|
1081
|
-
throw (0, import_utils.createCheckoutError)(
|
|
1082
|
-
import_types.CheckoutErrorType.ValidationFailed,
|
|
1083
|
-
`定金金额 ${depositAmount} 不能超过订单总额 ${totalAmount.toFixed(2)}`
|
|
1084
|
-
);
|
|
1085
|
-
}
|
|
1086
1150
|
const formattedDepositAmount = depositValue.toFixed(2);
|
|
1087
1151
|
const oldDepositAmount = this.store.currentOrder.deposit_amount || "0.00";
|
|
1088
1152
|
if (formattedDepositAmount === oldDepositAmount) {
|
|
@@ -1097,7 +1161,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1097
1161
|
orderId: this.store.currentOrder.order_id,
|
|
1098
1162
|
oldDepositAmount,
|
|
1099
1163
|
newDepositAmount: formattedDepositAmount,
|
|
1100
|
-
totalAmount:
|
|
1164
|
+
totalAmount: this.store.currentOrder.total_amount
|
|
1101
1165
|
});
|
|
1102
1166
|
const updateParams = {
|
|
1103
1167
|
deposit_amount: formattedDepositAmount
|
|
@@ -1125,6 +1189,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1125
1189
|
this.store.localOrderData.is_deposit = updateParams.is_deposit;
|
|
1126
1190
|
}
|
|
1127
1191
|
}
|
|
1192
|
+
this.updateStateAmountToRemaining(false);
|
|
1128
1193
|
await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
|
|
1129
1194
|
order: this.store.currentOrder,
|
|
1130
1195
|
timestamp: Date.now()
|
|
@@ -1152,7 +1217,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1152
1217
|
* 用于强制同步订单到后端,特别适用于纯代金券支付完成的订单
|
|
1153
1218
|
*/
|
|
1154
1219
|
async manualSyncOrderAsync() {
|
|
1155
|
-
var _a, _b, _c, _d;
|
|
1220
|
+
var _a, _b, _c, _d, _e;
|
|
1156
1221
|
this.logInfo("manualSyncOrderAsync called", {
|
|
1157
1222
|
hasCurrentOrder: !!this.store.currentOrder,
|
|
1158
1223
|
currentOrderId: (_a = this.store.currentOrder) == null ? void 0 : _a.order_id,
|
|
@@ -1197,14 +1262,19 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1197
1262
|
"[Checkout] 严重警告:返回的订单ID与存储的订单ID不一致!"
|
|
1198
1263
|
);
|
|
1199
1264
|
}
|
|
1200
|
-
|
|
1265
|
+
let newRes = {
|
|
1266
|
+
...syncResult,
|
|
1267
|
+
is_deposit: ((_d = this.store.currentOrder) == null ? void 0 : _d.is_deposit) || 0
|
|
1268
|
+
};
|
|
1269
|
+
await this.updateStateAmountToRemaining(false);
|
|
1270
|
+
return newRes;
|
|
1201
1271
|
} catch (error) {
|
|
1202
1272
|
this.logError("手动同步订单失败:", error);
|
|
1203
1273
|
const errorMessage = error instanceof Error ? error.message : "同步失败";
|
|
1204
1274
|
return {
|
|
1205
1275
|
success: false,
|
|
1206
1276
|
message: `订单同步失败: ${errorMessage}`,
|
|
1207
|
-
orderUuid: (
|
|
1277
|
+
orderUuid: (_e = this.store.currentOrder) == null ? void 0 : _e.uuid
|
|
1208
1278
|
};
|
|
1209
1279
|
}
|
|
1210
1280
|
}
|
|
@@ -1715,9 +1785,11 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1715
1785
|
this.logWarning("calculateRemainingAmountAsync: 没有当前订单");
|
|
1716
1786
|
return "0.00";
|
|
1717
1787
|
}
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
)
|
|
1788
|
+
let totalAmount = new import_decimal.default(this.store.currentOrder.total_amount || "0");
|
|
1789
|
+
const currentOrder = await this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
|
|
1790
|
+
if ((currentOrder == null ? void 0 : currentOrder.is_deposit) && (currentOrder == null ? void 0 : currentOrder.deposit_amount) && Number(currentOrder == null ? void 0 : currentOrder.deposit_amount) > 0) {
|
|
1791
|
+
totalAmount = new import_decimal.default(currentOrder == null ? void 0 : currentOrder.deposit_amount);
|
|
1792
|
+
}
|
|
1721
1793
|
const paidAmountStr = await this.calculatePaidAmountAsync();
|
|
1722
1794
|
const paidAmount = new import_decimal.default(paidAmountStr);
|
|
1723
1795
|
const remainingAmount = totalAmount.sub(paidAmount);
|
|
@@ -1757,7 +1829,28 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1757
1829
|
* 更新 stateAmount 为当前剩余未支付金额
|
|
1758
1830
|
*/
|
|
1759
1831
|
async updateStateAmountToRemaining(checkOrder = true) {
|
|
1832
|
+
var _a, _b, _c, _d;
|
|
1760
1833
|
try {
|
|
1834
|
+
if (((_a = this.store.currentOrder) == null ? void 0 : _a.is_deposit) === 1) {
|
|
1835
|
+
const paymentItems = await this.payment.getPaymentItemsAsync((_b = this.store.currentOrder) == null ? void 0 : _b.uuid);
|
|
1836
|
+
const depositPaidAmount = paymentItems.filter((item) => item.order_payment_type === "deposit" && item.status !== "voided").reduce((sum, item) => {
|
|
1837
|
+
if (item.voucher_id && !item.isSynced) {
|
|
1838
|
+
return sum;
|
|
1839
|
+
}
|
|
1840
|
+
const amount = new import_decimal.default(item.amount || "0");
|
|
1841
|
+
const roundingAmount = new import_decimal.default(item.rounding_amount || "0");
|
|
1842
|
+
return sum.add(amount.add(roundingAmount.abs()));
|
|
1843
|
+
}, new import_decimal.default(0));
|
|
1844
|
+
if (depositPaidAmount.gte((_c = this.store.currentOrder) == null ? void 0 : _c.deposit_amount)) {
|
|
1845
|
+
this.store.currentOrder = {
|
|
1846
|
+
...this.store.currentOrder,
|
|
1847
|
+
is_deposit: 0
|
|
1848
|
+
};
|
|
1849
|
+
await this.payment.updateOrderAsync((_d = this.store.currentOrder) == null ? void 0 : _d.uuid, {
|
|
1850
|
+
is_deposit: 0
|
|
1851
|
+
});
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1761
1854
|
const remainingAmount = await this.calculateRemainingAmountAsync();
|
|
1762
1855
|
const currentStateAmount = this.store.stateAmount;
|
|
1763
1856
|
if (remainingAmount !== currentStateAmount) {
|
|
@@ -1868,7 +1961,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1868
1961
|
* @returns 包含订单ID、UUID和完整后端响应的对象
|
|
1869
1962
|
*/
|
|
1870
1963
|
async syncOrderToBackendWithReturn(isManual = false, customPaymentItems) {
|
|
1871
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1964
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1872
1965
|
if (!this.store.localOrderData || !this.store.currentOrder) {
|
|
1873
1966
|
throw new Error("缺少必要的订单数据,无法同步到后端");
|
|
1874
1967
|
}
|
|
@@ -1896,42 +1989,23 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1896
1989
|
});
|
|
1897
1990
|
let finalDepositAmount;
|
|
1898
1991
|
const manualDepositAmount = ((_a = this.store.currentOrder) == null ? void 0 : _a.deposit_amount) || "0.00";
|
|
1899
|
-
const depositPaymentItems = processedPaymentItems.filter(
|
|
1900
|
-
(item) => item.order_payment_type === "deposit" && item.status !== "voided"
|
|
1901
|
-
);
|
|
1902
|
-
const calculatedDepositAmount = depositPaymentItems.reduce((sum, item) => {
|
|
1903
|
-
const amount = new import_decimal.default(item.amount || "0");
|
|
1904
|
-
const roundingAmount = new import_decimal.default(item.rounding_amount || "0");
|
|
1905
|
-
const effectiveAmount = amount.add(roundingAmount.abs());
|
|
1906
|
-
return sum.add(effectiveAmount);
|
|
1907
|
-
}, new import_decimal.default(0)).toFixed(2);
|
|
1908
1992
|
const manualDepositValue = new import_decimal.default(manualDepositAmount);
|
|
1909
|
-
const calculatedDepositValue = new import_decimal.default(calculatedDepositAmount);
|
|
1910
1993
|
if (manualDepositValue.gt(0)) {
|
|
1911
1994
|
finalDepositAmount = manualDepositAmount;
|
|
1912
1995
|
this.logInfo("使用手动设置的定金金额", {
|
|
1913
1996
|
manualDepositAmount,
|
|
1914
|
-
calculatedDepositAmount,
|
|
1915
1997
|
reason: "用户通过setDepositAmountAsync手动设置了定金金额"
|
|
1916
1998
|
});
|
|
1917
|
-
} else if (calculatedDepositValue.gt(0)) {
|
|
1918
|
-
finalDepositAmount = calculatedDepositAmount;
|
|
1919
|
-
this.logInfo("使用从支付项计算的定金金额", {
|
|
1920
|
-
manualDepositAmount,
|
|
1921
|
-
calculatedDepositAmount,
|
|
1922
|
-
reason: "未手动设置定金金额,从定金类型支付项计算得出"
|
|
1923
|
-
});
|
|
1924
1999
|
} else {
|
|
1925
2000
|
finalDepositAmount = "0.00";
|
|
1926
2001
|
this.logInfo("定金金额为0", {
|
|
1927
2002
|
manualDepositAmount,
|
|
1928
|
-
calculatedDepositAmount,
|
|
1929
2003
|
reason: "手动设置和计算值均为0"
|
|
1930
2004
|
});
|
|
1931
2005
|
}
|
|
1932
2006
|
this.logInfo("定金金额确定结果", {
|
|
1933
|
-
depositPaymentItemsCount:
|
|
1934
|
-
depositPaymentItems:
|
|
2007
|
+
depositPaymentItemsCount: processedPaymentItems.length,
|
|
2008
|
+
depositPaymentItems: processedPaymentItems.map((item) => ({
|
|
1935
2009
|
uuid: item.uuid,
|
|
1936
2010
|
code: item.code,
|
|
1937
2011
|
amount: item.amount,
|
|
@@ -1940,7 +2014,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1940
2014
|
status: item.status
|
|
1941
2015
|
})),
|
|
1942
2016
|
manualDepositAmount,
|
|
1943
|
-
calculatedDepositAmount,
|
|
1944
2017
|
finalDepositAmount,
|
|
1945
2018
|
isDeposit: ((_b = this.store.currentOrder) == null ? void 0 : _b.is_deposit) || 0
|
|
1946
2019
|
});
|
|
@@ -1963,11 +2036,28 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
1963
2036
|
currency_code: this.otherParams.currency_code,
|
|
1964
2037
|
currency_symbol: this.otherParams.currency_symbol,
|
|
1965
2038
|
currency_format: this.otherParams.currency_format,
|
|
1966
|
-
is_deposit: ((_d = this.store.currentOrder) == null ? void 0 : _d.is_deposit) || 0,
|
|
2039
|
+
is_deposit: (((_d = this.store.currentOrder) == null ? void 0 : _d.is_deposit) || Number(finalDepositAmount) > 0 ? 1 : 0) || 0,
|
|
1967
2040
|
deposit_amount: finalDepositAmount,
|
|
1968
2041
|
// 使用最终确定的定金金额(手动设置优先)
|
|
1969
2042
|
product_tax_fee: this.store.localOrderData.tax_fee,
|
|
1970
|
-
note: this.store.localOrderData.shop_note
|
|
2043
|
+
note: this.store.localOrderData.shop_note,
|
|
2044
|
+
bookings: (_e = this.store.localOrderData.bookings) == null ? void 0 : _e.map((item) => {
|
|
2045
|
+
return {
|
|
2046
|
+
...item,
|
|
2047
|
+
product: {
|
|
2048
|
+
...item.product,
|
|
2049
|
+
custom_deposit_data: void 0
|
|
2050
|
+
},
|
|
2051
|
+
deposit: void 0
|
|
2052
|
+
};
|
|
2053
|
+
}),
|
|
2054
|
+
relation_products: (_f = this.store.localOrderData.relation_products) == null ? void 0 : _f.map((item) => {
|
|
2055
|
+
return {
|
|
2056
|
+
...item,
|
|
2057
|
+
custom_deposit_data: void 0,
|
|
2058
|
+
deposit: void 0
|
|
2059
|
+
};
|
|
2060
|
+
})
|
|
1971
2061
|
};
|
|
1972
2062
|
if (isUpdateOperation) {
|
|
1973
2063
|
if ((0, import_utils.isVirtualOrderId)(currentOrderId)) {
|
|
@@ -2018,7 +2108,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2018
2108
|
orderUuid: this.store.currentOrder.uuid,
|
|
2019
2109
|
operation: isUpdateOperation ? "update" : "create",
|
|
2020
2110
|
isManual,
|
|
2021
|
-
orderId: submitSuccess ? ((
|
|
2111
|
+
orderId: submitSuccess ? ((_g = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _g.order_id) || (checkoutResponse == null ? void 0 : checkoutResponse.order_id) : void 0,
|
|
2022
2112
|
error: submitError,
|
|
2023
2113
|
duration: Date.now() - startTime,
|
|
2024
2114
|
timestamp: Date.now()
|
|
@@ -2044,7 +2134,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
2044
2134
|
if (isUpdateOperation) {
|
|
2045
2135
|
realOrderId = currentOrderId;
|
|
2046
2136
|
} else {
|
|
2047
|
-
let extractedOrderId = (
|
|
2137
|
+
let extractedOrderId = (_h = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _h.order_id;
|
|
2048
2138
|
if (!extractedOrderId) {
|
|
2049
2139
|
extractedOrderId = checkoutResponse == null ? void 0 : checkoutResponse.order_id;
|
|
2050
2140
|
}
|