@pisell/pisellos 2.3.7 → 2.3.9
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/Order/index.d.ts +17 -1
- package/dist/modules/Order/index.js +282 -121
- package/dist/modules/Order/types.d.ts +15 -2
- package/dist/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
- package/dist/modules/Order/utils/bundleDiscountHydration.js +144 -0
- package/dist/modules/Order/utils.js +83 -28
- package/dist/solution/BaseSales/index.d.ts +15 -1
- package/dist/solution/BaseSales/index.js +405 -260
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/lib/model/strategy/adapter/promotion/index.js +49 -0
- package/lib/modules/Order/index.d.ts +17 -1
- package/lib/modules/Order/index.js +205 -36
- package/lib/modules/Order/types.d.ts +15 -2
- package/lib/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
- package/lib/modules/Order/utils/bundleDiscountHydration.js +139 -0
- package/lib/modules/Order/utils.js +45 -2
- package/lib/solution/BaseSales/index.d.ts +15 -1
- package/lib/solution/BaseSales/index.js +105 -14
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
311
311
|
date: string;
|
|
312
312
|
status: string;
|
|
313
313
|
week: string;
|
|
314
|
-
weekNum: 0 |
|
|
314
|
+
weekNum: 0 | 2 | 1 | 6 | 3 | 4 | 5;
|
|
315
315
|
}[]>;
|
|
316
316
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
317
317
|
private getScheduleDataByIds;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
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
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/model/strategy/adapter/promotion/index.ts
|
|
30
|
+
var promotion_exports = {};
|
|
31
|
+
__export(promotion_exports, {
|
|
32
|
+
BUY_X_GET_Y_FREE_STRATEGY: () => import_examples.BUY_X_GET_Y_FREE_STRATEGY,
|
|
33
|
+
PromotionAdapter: () => import_adapter.PromotionAdapter,
|
|
34
|
+
PromotionEvaluator: () => import_evaluator.PromotionEvaluator,
|
|
35
|
+
X_ITEMS_FOR_Y_PRICE_STRATEGY: () => import_examples.X_ITEMS_FOR_Y_PRICE_STRATEGY,
|
|
36
|
+
default: () => import_adapter2.default
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(promotion_exports);
|
|
39
|
+
var import_evaluator = require("./evaluator");
|
|
40
|
+
var import_adapter = require("./adapter");
|
|
41
|
+
var import_adapter2 = __toESM(require("./adapter"));
|
|
42
|
+
var import_examples = require("./examples");
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
BUY_X_GET_Y_FREE_STRATEGY,
|
|
46
|
+
PromotionAdapter,
|
|
47
|
+
PromotionEvaluator,
|
|
48
|
+
X_ITEMS_FOR_Y_PRICE_STRATEGY
|
|
49
|
+
});
|
|
@@ -312,13 +312,27 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
312
312
|
updateOrderPayment(paymentIdentity: string | number, updates: Partial<OrderPaymentData> & Record<string, any>): OrderPaymentData[];
|
|
313
313
|
/** 从当前订单支付项中移除指定支付项。 */
|
|
314
314
|
deleteOrderPayment(paymentIdentity: string | number): OrderPaymentData[];
|
|
315
|
+
private confirmPendingVoucherPaymentsInList;
|
|
316
|
+
private discardPendingVoucherPaymentsFromList;
|
|
317
|
+
private prepareVoucherPaymentsForSubmit;
|
|
318
|
+
private applyPaymentLifecycleChange;
|
|
319
|
+
confirmPendingVoucherPayments(options?: {
|
|
320
|
+
persist?: boolean;
|
|
321
|
+
recalculateSummary?: boolean;
|
|
322
|
+
}): OrderPaymentData[];
|
|
323
|
+
discardPendingVoucherPayments(options?: {
|
|
324
|
+
persist?: boolean;
|
|
325
|
+
recalculateSummary?: boolean;
|
|
326
|
+
}): OrderPaymentData[];
|
|
315
327
|
/**
|
|
316
328
|
* 覆盖当前订单中的 wallet pass 支付项。
|
|
317
329
|
*
|
|
318
330
|
* 判断口径与 PaymentModal 保持一致:voucher_id 存在且不为 0 的支付项
|
|
319
331
|
* 视为 wallet pass;其它支付项保持不变。
|
|
320
332
|
*/
|
|
321
|
-
updateVoucherOrderPayments(payments: OrderPaymentSource[]
|
|
333
|
+
updateVoucherOrderPayments(payments: OrderPaymentSource[], options?: {
|
|
334
|
+
status?: 'paid' | 'payment_pending';
|
|
335
|
+
}): OrderPaymentData[];
|
|
322
336
|
private shouldMergeProductToOrder;
|
|
323
337
|
private hasOrderProductLineNote;
|
|
324
338
|
/**
|
|
@@ -418,6 +432,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
418
432
|
payments?: OrderPaymentSource[];
|
|
419
433
|
paymentStatus?: SubmitSalesOrderParams['query']['payment_status'];
|
|
420
434
|
smallTicketDataFlag?: number;
|
|
435
|
+
confirmPendingVoucherPayments?: boolean;
|
|
421
436
|
enhancePayload?: SubmitPayloadEnhancer;
|
|
422
437
|
}): Promise<T>;
|
|
423
438
|
submitTempOrderAsync<T = any>(params?: {
|
|
@@ -429,6 +444,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
429
444
|
payments?: OrderPaymentSource[];
|
|
430
445
|
paymentStatus?: SubmitSalesOrderParams['query']['payment_status'];
|
|
431
446
|
smallTicketDataFlag?: number;
|
|
447
|
+
confirmPendingVoucherPayments?: boolean;
|
|
432
448
|
enhancePayload?: SubmitPayloadEnhancer;
|
|
433
449
|
}): Promise<T>;
|
|
434
450
|
private runSubmitTempOrder;
|
|
@@ -40,6 +40,7 @@ var import_dayjs = __toESM(require("dayjs"));
|
|
|
40
40
|
var import_cartPromotion = require("../../solution/BaseSales/utils/cartPromotion");
|
|
41
41
|
var import_utils3 = require("../../solution/ScanOrder/utils");
|
|
42
42
|
var import_manualProductDiscount = require("./utils/manualProductDiscount");
|
|
43
|
+
var import_bundleDiscountHydration = require("./utils/bundleDiscountHydration");
|
|
43
44
|
var import_Discount = require("../Discount");
|
|
44
45
|
var import_Rules = require("../Rules");
|
|
45
46
|
var import_types2 = require("../Rules/types");
|
|
@@ -64,6 +65,23 @@ function isManualProductDiscountProduct(product) {
|
|
|
64
65
|
var _a, _b;
|
|
65
66
|
return ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.is_manual_discount) === true || ((_b = product == null ? void 0 : product.metadata) == null ? void 0 : _b.is_manual_discount) === 1 || ((product == null ? void 0 : product.discount_list) || []).some((item) => (item == null ? void 0 : item.type) === "product");
|
|
66
67
|
}
|
|
68
|
+
var ORDER_PAYMENT_STATUS_PAID = "paid";
|
|
69
|
+
var ORDER_PAYMENT_STATUS_PENDING = "payment_pending";
|
|
70
|
+
function isVoucherPaymentRecord(payment) {
|
|
71
|
+
return (payment == null ? void 0 : payment.voucher_id) !== void 0 && Number(payment.voucher_id) !== 0;
|
|
72
|
+
}
|
|
73
|
+
function hasSyncedOrderPaymentRecord(payment) {
|
|
74
|
+
return (payment == null ? void 0 : payment.order_payment_id) !== void 0 && payment.order_payment_id !== null;
|
|
75
|
+
}
|
|
76
|
+
function isPendingVoucherPaymentRecord(payment) {
|
|
77
|
+
return isVoucherPaymentRecord(payment) && (payment == null ? void 0 : payment.status) === ORDER_PAYMENT_STATUS_PENDING;
|
|
78
|
+
}
|
|
79
|
+
function isPaidPaymentRecord(payment) {
|
|
80
|
+
return (payment == null ? void 0 : payment.status) === ORDER_PAYMENT_STATUS_PAID;
|
|
81
|
+
}
|
|
82
|
+
function isCommittedVoucherPaymentRecord(payment) {
|
|
83
|
+
return isVoucherPaymentRecord(payment) && (payment == null ? void 0 : payment.status) !== "voided" && (hasSyncedOrderPaymentRecord(payment) || isPaidPaymentRecord(payment));
|
|
84
|
+
}
|
|
67
85
|
var OrderModule = class extends import_BaseModule.BaseModule {
|
|
68
86
|
constructor(name, version) {
|
|
69
87
|
super(name || "order", version);
|
|
@@ -91,7 +109,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
91
109
|
collectHydratedEditDiscounts(products) {
|
|
92
110
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
93
111
|
const discountMap = /* @__PURE__ */ new Map();
|
|
94
|
-
for (const product of
|
|
112
|
+
for (const product of (0, import_bundleDiscountHydration.expandHydratedProductsForDiscountCollection)(products)) {
|
|
95
113
|
for (const item of (product == null ? void 0 : product.discount_list) || []) {
|
|
96
114
|
const type = (item == null ? void 0 : item.type) ?? (item == null ? void 0 : item.tag);
|
|
97
115
|
if (!type || type === "product")
|
|
@@ -114,6 +132,21 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
114
132
|
discount: item == null ? void 0 : item.discount,
|
|
115
133
|
_num: Number(((_e = item == null ? void 0 : item.metadata) == null ? void 0 : _e.num) ?? (product == null ? void 0 : product.num) ?? (product == null ? void 0 : product.product_quantity) ?? 1) || 1
|
|
116
134
|
};
|
|
135
|
+
const existed = discountMap.get(key);
|
|
136
|
+
if (existed) {
|
|
137
|
+
existed.amount = Number(existed.amount || 0) + amount;
|
|
138
|
+
existed.used_par_value = String(Number(existed.used_par_value || 0) + amount);
|
|
139
|
+
existed.balance = String(Number(existed.balance || 0) + amount);
|
|
140
|
+
existed.applicableProductDetails = [
|
|
141
|
+
...existed.applicableProductDetails || [],
|
|
142
|
+
detail
|
|
143
|
+
];
|
|
144
|
+
existed.appliedProductDetails = [
|
|
145
|
+
...existed.appliedProductDetails || [],
|
|
146
|
+
detail
|
|
147
|
+
];
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
117
150
|
discountMap.set(key, {
|
|
118
151
|
id: key,
|
|
119
152
|
product_name: "",
|
|
@@ -832,6 +865,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
832
865
|
return (0, import_utils.mapPaymentItemsToOrderPayments)(payments, {
|
|
833
866
|
includeVoided: false
|
|
834
867
|
}).reduce((sum, payment) => {
|
|
868
|
+
if (!isPaidPaymentRecord(payment))
|
|
869
|
+
return sum;
|
|
835
870
|
return sum.plus(this.calculatePaymentEffectiveAmount(payment));
|
|
836
871
|
}, new import_decimal.default(0));
|
|
837
872
|
}
|
|
@@ -949,7 +984,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
949
984
|
calculateDepositPaidAmount(payments) {
|
|
950
985
|
return (payments || []).reduce((sum, payment) => {
|
|
951
986
|
const paymentRecord = payment;
|
|
952
|
-
if ((paymentRecord
|
|
987
|
+
if (!isPaidPaymentRecord(paymentRecord))
|
|
953
988
|
return sum;
|
|
954
989
|
const isDepositPayment = paymentRecord.type === "deposit" || paymentRecord.order_payment_type === "deposit";
|
|
955
990
|
if (!isDepositPayment)
|
|
@@ -1100,7 +1135,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1100
1135
|
return (payments || []).reduce(
|
|
1101
1136
|
(summary, payment) => {
|
|
1102
1137
|
const paymentRecord = payment;
|
|
1103
|
-
if ((paymentRecord
|
|
1138
|
+
if (!isPaidPaymentRecord(paymentRecord))
|
|
1104
1139
|
return summary;
|
|
1105
1140
|
return {
|
|
1106
1141
|
customerPaidAmount: summary.customerPaidAmount.plus(paymentRecord.amount || 0),
|
|
@@ -1526,6 +1561,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1526
1561
|
}
|
|
1527
1562
|
restoreOrder() {
|
|
1528
1563
|
var _a, _b;
|
|
1564
|
+
this.logInfo("restoreOrder start", {});
|
|
1529
1565
|
const freshTempOrder = this.createDefaultTempOrderInstance();
|
|
1530
1566
|
this.ensureExternalSaleNumber(freshTempOrder);
|
|
1531
1567
|
this.store.tempOrder = freshTempOrder;
|
|
@@ -2394,27 +2430,78 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2394
2430
|
this.persistTempOrder();
|
|
2395
2431
|
return tempOrder.payments;
|
|
2396
2432
|
}
|
|
2433
|
+
confirmPendingVoucherPaymentsInList(payments) {
|
|
2434
|
+
return (payments || []).map((payment) => {
|
|
2435
|
+
if (!isPendingVoucherPaymentRecord(payment))
|
|
2436
|
+
return payment;
|
|
2437
|
+
return {
|
|
2438
|
+
...payment,
|
|
2439
|
+
status: ORDER_PAYMENT_STATUS_PAID
|
|
2440
|
+
};
|
|
2441
|
+
});
|
|
2442
|
+
}
|
|
2443
|
+
discardPendingVoucherPaymentsFromList(payments) {
|
|
2444
|
+
return (payments || []).filter((payment) => !isPendingVoucherPaymentRecord(payment));
|
|
2445
|
+
}
|
|
2446
|
+
prepareVoucherPaymentsForSubmit(payments, confirmPendingVoucherPayments = true) {
|
|
2447
|
+
const mappedPayments = (0, import_utils.mapPaymentItemsToOrderPayments)(payments || []);
|
|
2448
|
+
return confirmPendingVoucherPayments ? this.confirmPendingVoucherPaymentsInList(mappedPayments) : this.discardPendingVoucherPaymentsFromList(mappedPayments);
|
|
2449
|
+
}
|
|
2450
|
+
applyPaymentLifecycleChange(tempOrder, options) {
|
|
2451
|
+
this.updateTempOrderPaymentStatus(tempOrder);
|
|
2452
|
+
if ((options == null ? void 0 : options.persist) !== false) {
|
|
2453
|
+
this.persistTempOrder();
|
|
2454
|
+
}
|
|
2455
|
+
if ((options == null ? void 0 : options.recalculateSummary) === false)
|
|
2456
|
+
return;
|
|
2457
|
+
const logContext = (options == null ? void 0 : options.logContext) || "payment lifecycle change";
|
|
2458
|
+
void this.recalculateSummary({ createIfMissing: true }).catch((error) => {
|
|
2459
|
+
this.logError(`recalculate summary after ${logContext} failed`, {
|
|
2460
|
+
error: error instanceof Error ? error.message : String(error)
|
|
2461
|
+
});
|
|
2462
|
+
});
|
|
2463
|
+
}
|
|
2464
|
+
confirmPendingVoucherPayments(options) {
|
|
2465
|
+
const tempOrder = this.ensureTempOrder();
|
|
2466
|
+
const payments = tempOrder.payments || [];
|
|
2467
|
+
const hasPendingVoucher = payments.some((payment) => isPendingVoucherPaymentRecord(payment));
|
|
2468
|
+
if (!hasPendingVoucher)
|
|
2469
|
+
return payments;
|
|
2470
|
+
tempOrder.payments = this.confirmPendingVoucherPaymentsInList(payments);
|
|
2471
|
+
this.applyPaymentLifecycleChange(tempOrder, {
|
|
2472
|
+
...options,
|
|
2473
|
+
logContext: "confirmPendingVoucherPayments"
|
|
2474
|
+
});
|
|
2475
|
+
return tempOrder.payments;
|
|
2476
|
+
}
|
|
2477
|
+
discardPendingVoucherPayments(options) {
|
|
2478
|
+
const tempOrder = this.ensureTempOrder();
|
|
2479
|
+
const payments = tempOrder.payments || [];
|
|
2480
|
+
const nextPayments = this.discardPendingVoucherPaymentsFromList(payments);
|
|
2481
|
+
if (nextPayments.length === payments.length)
|
|
2482
|
+
return payments;
|
|
2483
|
+
tempOrder.payments = nextPayments;
|
|
2484
|
+
this.applyPaymentLifecycleChange(tempOrder, {
|
|
2485
|
+
...options,
|
|
2486
|
+
logContext: "discardPendingVoucherPayments"
|
|
2487
|
+
});
|
|
2488
|
+
return tempOrder.payments;
|
|
2489
|
+
}
|
|
2397
2490
|
/**
|
|
2398
2491
|
* 覆盖当前订单中的 wallet pass 支付项。
|
|
2399
2492
|
*
|
|
2400
2493
|
* 判断口径与 PaymentModal 保持一致:voucher_id 存在且不为 0 的支付项
|
|
2401
2494
|
* 视为 wallet pass;其它支付项保持不变。
|
|
2402
2495
|
*/
|
|
2403
|
-
updateVoucherOrderPayments(payments) {
|
|
2496
|
+
updateVoucherOrderPayments(payments, options) {
|
|
2404
2497
|
const tempOrder = this.ensureTempOrder();
|
|
2405
|
-
const isVoucherPayment = (payment) => {
|
|
2406
|
-
return payment.voucher_id !== void 0 && Number(payment.voucher_id) !== 0;
|
|
2407
|
-
};
|
|
2408
|
-
const hasSyncedOrderPayment = (payment) => {
|
|
2409
|
-
return payment.order_payment_id !== void 0 && payment.order_payment_id !== null;
|
|
2410
|
-
};
|
|
2411
2498
|
const isOrderPaymentType = (value) => {
|
|
2412
2499
|
return value === "normal" || value === "deposit";
|
|
2413
2500
|
};
|
|
2414
2501
|
const voucherOrderPaymentType = this.resolveNextOrderPaymentType(tempOrder);
|
|
2415
2502
|
const withVoucherPaymentType = (payment) => {
|
|
2416
2503
|
const paymentRecord = payment;
|
|
2417
|
-
if (!
|
|
2504
|
+
if (!isVoucherPaymentRecord(paymentRecord))
|
|
2418
2505
|
return payment;
|
|
2419
2506
|
const explicitPaymentType = isOrderPaymentType(paymentRecord.order_payment_type) ? paymentRecord.order_payment_type : isOrderPaymentType(paymentRecord.type) ? paymentRecord.type : void 0;
|
|
2420
2507
|
const nextPaymentType = explicitPaymentType || voucherOrderPaymentType;
|
|
@@ -2426,35 +2513,70 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2426
2513
|
order_payment_type: nextPaymentType
|
|
2427
2514
|
};
|
|
2428
2515
|
};
|
|
2516
|
+
const normalizeVoucherPaymentStatus = (payment) => {
|
|
2517
|
+
const paymentRecord = payment;
|
|
2518
|
+
if (!isVoucherPaymentRecord(paymentRecord))
|
|
2519
|
+
return payment;
|
|
2520
|
+
if (hasSyncedOrderPaymentRecord(paymentRecord) && (paymentRecord.status === void 0 || paymentRecord.status === "active")) {
|
|
2521
|
+
return {
|
|
2522
|
+
...paymentRecord,
|
|
2523
|
+
status: ORDER_PAYMENT_STATUS_PAID
|
|
2524
|
+
};
|
|
2525
|
+
}
|
|
2526
|
+
if (paymentRecord.status !== void 0 && paymentRecord.status !== "active") {
|
|
2527
|
+
return payment;
|
|
2528
|
+
}
|
|
2529
|
+
return {
|
|
2530
|
+
...paymentRecord,
|
|
2531
|
+
status: (options == null ? void 0 : options.status) || ORDER_PAYMENT_STATUS_PENDING
|
|
2532
|
+
};
|
|
2533
|
+
};
|
|
2429
2534
|
const mappedVouchers = (0, import_utils.mapPaymentItemsToOrderPayments)(
|
|
2430
2535
|
payments.map(
|
|
2431
|
-
(payment) => this.normalizePaymentSource(
|
|
2536
|
+
(payment) => this.normalizePaymentSource(
|
|
2537
|
+
normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)),
|
|
2538
|
+
{ defaultPaid: false }
|
|
2539
|
+
)
|
|
2432
2540
|
)
|
|
2433
2541
|
).filter((payment) => {
|
|
2434
|
-
return
|
|
2542
|
+
return isVoucherPaymentRecord(payment);
|
|
2435
2543
|
});
|
|
2436
2544
|
const nonVoucherPayments = (tempOrder.payments || []).filter((payment) => {
|
|
2437
|
-
return !
|
|
2438
|
-
});
|
|
2439
|
-
const syncedVoucherPayments = (tempOrder.payments || []).filter((payment) => {
|
|
2440
|
-
return isVoucherPayment(payment) && hasSyncedOrderPayment(payment);
|
|
2545
|
+
return !isVoucherPaymentRecord(payment);
|
|
2441
2546
|
});
|
|
2442
|
-
const
|
|
2443
|
-
|
|
2547
|
+
const normalizeCommittedVoucherPayment = (payment) => {
|
|
2548
|
+
if (hasSyncedOrderPaymentRecord(payment) && (payment.status === void 0 || payment.status === "active")) {
|
|
2549
|
+
return {
|
|
2550
|
+
...payment,
|
|
2551
|
+
status: ORDER_PAYMENT_STATUS_PAID
|
|
2552
|
+
};
|
|
2553
|
+
}
|
|
2554
|
+
return payment;
|
|
2555
|
+
};
|
|
2556
|
+
const committedVoucherPayments = (tempOrder.payments || []).filter((payment) => isCommittedVoucherPaymentRecord(payment)).map((payment) => normalizeCommittedVoucherPayment(payment));
|
|
2557
|
+
const committedVoucherPaymentIds = new Set(
|
|
2558
|
+
committedVoucherPayments.filter((payment) => hasSyncedOrderPaymentRecord(payment)).map((payment) => String(payment.order_payment_id))
|
|
2559
|
+
);
|
|
2560
|
+
const committedVoucherIds = new Set(
|
|
2561
|
+
committedVoucherPayments.map((payment) => String(payment.voucher_id))
|
|
2444
2562
|
);
|
|
2445
2563
|
const replaceableVouchers = mappedVouchers.filter((payment) => {
|
|
2446
|
-
if (
|
|
2447
|
-
return
|
|
2448
|
-
|
|
2564
|
+
if (hasSyncedOrderPaymentRecord(payment) && committedVoucherPaymentIds.has(String(payment.order_payment_id))) {
|
|
2565
|
+
return false;
|
|
2566
|
+
}
|
|
2567
|
+
if (payment.voucher_id !== void 0 && committedVoucherIds.has(String(payment.voucher_id))) {
|
|
2568
|
+
return false;
|
|
2569
|
+
}
|
|
2570
|
+
return true;
|
|
2449
2571
|
});
|
|
2450
2572
|
const cappedVouchers = this.capVoucherPaymentsByRemainingAmount({
|
|
2451
2573
|
vouchers: replaceableVouchers,
|
|
2452
2574
|
nonVoucherPayments: [
|
|
2453
2575
|
...nonVoucherPayments,
|
|
2454
|
-
...
|
|
2576
|
+
...committedVoucherPayments
|
|
2455
2577
|
]
|
|
2456
2578
|
});
|
|
2457
|
-
tempOrder.payments = [...nonVoucherPayments, ...
|
|
2579
|
+
tempOrder.payments = [...nonVoucherPayments, ...committedVoucherPayments, ...cappedVouchers];
|
|
2458
2580
|
this.updateTempOrderPaymentStatus(tempOrder);
|
|
2459
2581
|
this.persistTempOrder();
|
|
2460
2582
|
void this.recalculateSummary({ createIfMissing: true }).catch((error) => {
|
|
@@ -2692,6 +2814,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2692
2814
|
}
|
|
2693
2815
|
await this.appendProductLineToTempOrder(tempOrder, product, booking);
|
|
2694
2816
|
await this.finalizeProductOrderMutation(tempOrder);
|
|
2817
|
+
this.logInfo("addProductToOrder success", {
|
|
2818
|
+
product_id: product.product_id,
|
|
2819
|
+
with_booking: !!booking
|
|
2820
|
+
});
|
|
2695
2821
|
return tempOrder.products;
|
|
2696
2822
|
}
|
|
2697
2823
|
/**
|
|
@@ -2733,6 +2859,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2733
2859
|
await this.appendProductLineToTempOrder(tempOrder, product, booking);
|
|
2734
2860
|
}
|
|
2735
2861
|
await this.finalizeProductOrderMutation(tempOrder, options);
|
|
2862
|
+
this.logInfo("addProductsToOrder success", {
|
|
2863
|
+
itemsCount: items.length
|
|
2864
|
+
});
|
|
2736
2865
|
return tempOrder.products;
|
|
2737
2866
|
}
|
|
2738
2867
|
hasGoodPassDiscount(product) {
|
|
@@ -2955,6 +3084,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2955
3084
|
this.sanitizeTempOrderProducts(tempOrder);
|
|
2956
3085
|
await this.recalculateSummary({ createIfMissing: true });
|
|
2957
3086
|
this.persistTempOrder();
|
|
3087
|
+
this.logInfo("updateOrderProduct success", {
|
|
3088
|
+
params
|
|
3089
|
+
});
|
|
2958
3090
|
return tempOrder.products;
|
|
2959
3091
|
}
|
|
2960
3092
|
async updateOrderProducts(paramsList) {
|
|
@@ -2966,6 +3098,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2966
3098
|
this.applyOrderProductUpdateToTempOrder(tempOrder, params);
|
|
2967
3099
|
});
|
|
2968
3100
|
await this.finalizeAfterProductsMutation(tempOrder);
|
|
3101
|
+
this.logInfo("updateOrderProduct success", {
|
|
3102
|
+
paramsList
|
|
3103
|
+
});
|
|
2969
3104
|
return tempOrder.products;
|
|
2970
3105
|
}
|
|
2971
3106
|
async updateOrderProductQuantity(params) {
|
|
@@ -3030,6 +3165,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3030
3165
|
this.sanitizeTempOrderProducts(tempOrder);
|
|
3031
3166
|
await this.recalculateSummary({ createIfMissing: true });
|
|
3032
3167
|
this.persistTempOrder();
|
|
3168
|
+
this.logInfo("updateOrderProductQuantity success", {
|
|
3169
|
+
params
|
|
3170
|
+
});
|
|
3033
3171
|
return tempOrder.products;
|
|
3034
3172
|
}
|
|
3035
3173
|
updateOrderBooking(params) {
|
|
@@ -3131,6 +3269,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3131
3269
|
});
|
|
3132
3270
|
}
|
|
3133
3271
|
await this.finalizeAfterProductsMutation(tempOrder);
|
|
3272
|
+
this.logInfo("removeProductsFromOrder success", {
|
|
3273
|
+
identities
|
|
3274
|
+
});
|
|
3134
3275
|
return tempOrder.products;
|
|
3135
3276
|
}
|
|
3136
3277
|
async removeProductFromOrder(identity) {
|
|
@@ -3156,6 +3297,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3156
3297
|
this.sanitizeTempOrderProducts(tempOrder);
|
|
3157
3298
|
await this.recalculateSummary({ createIfMissing: true });
|
|
3158
3299
|
this.persistTempOrder();
|
|
3300
|
+
this.logInfo("clearOrderCartLines success", {});
|
|
3159
3301
|
return tempOrder;
|
|
3160
3302
|
}
|
|
3161
3303
|
// ─── TempOrder: 提交 ───
|
|
@@ -3216,21 +3358,37 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3216
3358
|
async runSubmitTempOrder(params) {
|
|
3217
3359
|
var _a, _b, _c, _d, _e;
|
|
3218
3360
|
const tempOrder = this.ensureTempOrder();
|
|
3361
|
+
const shouldConfirmPendingVoucherPayments = (params == null ? void 0 : params.confirmPendingVoucherPayments) !== false;
|
|
3362
|
+
const hasPaymentOverride = (params == null ? void 0 : params.payments) !== void 0;
|
|
3363
|
+
const preparedPaymentOverride = hasPaymentOverride ? this.prepareVoucherPaymentsForSubmit(
|
|
3364
|
+
(params == null ? void 0 : params.payments) || [],
|
|
3365
|
+
shouldConfirmPendingVoucherPayments
|
|
3366
|
+
) : void 0;
|
|
3367
|
+
if (!hasPaymentOverride) {
|
|
3368
|
+
if (shouldConfirmPendingVoucherPayments) {
|
|
3369
|
+
this.confirmPendingVoucherPayments({
|
|
3370
|
+
persist: false,
|
|
3371
|
+
recalculateSummary: false
|
|
3372
|
+
});
|
|
3373
|
+
} else {
|
|
3374
|
+
this.discardPendingVoucherPayments({
|
|
3375
|
+
persist: false,
|
|
3376
|
+
recalculateSummary: false
|
|
3377
|
+
});
|
|
3378
|
+
}
|
|
3379
|
+
}
|
|
3219
3380
|
this.persistTempOrder();
|
|
3220
3381
|
const latestSummary = await this.recalculateSummary({ createIfMissing: true }) || this.store.summary || (0, import_utils.createEmptySummary)();
|
|
3221
3382
|
const effectiveCacheId = (params == null ? void 0 : params.cacheId) ?? this.cacheId;
|
|
3222
|
-
const hasPaymentOverride = (params == null ? void 0 : params.payments) !== void 0;
|
|
3223
3383
|
const hasPaymentStatusOverride = (params == null ? void 0 : params.paymentStatus) !== void 0;
|
|
3224
3384
|
const hasSmallTicketDataFlagOverride = (params == null ? void 0 : params.smallTicketDataFlag) !== void 0;
|
|
3225
3385
|
const enhancePayload = hasPaymentOverride || hasPaymentStatusOverride || hasSmallTicketDataFlagOverride || (params == null ? void 0 : params.enhancePayload) ? (payload2, ctx) => {
|
|
3226
3386
|
const nextPayload = {
|
|
3227
3387
|
...payload2,
|
|
3228
3388
|
...hasPaymentOverride ? {
|
|
3229
|
-
payments:
|
|
3230
|
-
(params == null ? void 0 : params.payments) || []
|
|
3231
|
-
)
|
|
3389
|
+
payments: preparedPaymentOverride || []
|
|
3232
3390
|
} : {},
|
|
3233
|
-
...hasPaymentStatusOverride ? { payment_status: params == null ? void 0 : params.paymentStatus } : {},
|
|
3391
|
+
...hasPaymentStatusOverride && !shouldConfirmPendingVoucherPayments ? { payment_status: params == null ? void 0 : params.paymentStatus } : {},
|
|
3234
3392
|
...hasSmallTicketDataFlagOverride ? { small_ticket_data_flag: params == null ? void 0 : params.smallTicketDataFlag } : {}
|
|
3235
3393
|
};
|
|
3236
3394
|
const enhancedPayload = (params == null ? void 0 : params.enhancePayload) ? params.enhancePayload(nextPayload, ctx) : nextPayload;
|
|
@@ -3248,6 +3406,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3248
3406
|
request_unique_idempotency_token: params == null ? void 0 : params.request_unique_idempotency_token,
|
|
3249
3407
|
enhance: enhancePayload
|
|
3250
3408
|
});
|
|
3409
|
+
console.log("[Order.runSubmitTempOrder.payload]", payload);
|
|
3251
3410
|
if (params == null ? void 0 : params.syncMode) {
|
|
3252
3411
|
payload.sync_mode = true;
|
|
3253
3412
|
}
|
|
@@ -3381,9 +3540,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3381
3540
|
const mappedPayments = (0, import_utils.mapPaymentItemsToOrderPayments)(
|
|
3382
3541
|
params.payments || []
|
|
3383
3542
|
);
|
|
3384
|
-
const
|
|
3385
|
-
const
|
|
3386
|
-
|
|
3543
|
+
const shouldConfirmPendingVoucherPayments = params.confirmPendingVoucherPayments ?? params.submitWhenPaid === true;
|
|
3544
|
+
const effectivePayments = shouldConfirmPendingVoucherPayments ? this.confirmPendingVoucherPaymentsInList(mappedPayments) : params.confirmPendingVoucherPayments === false ? this.discardPendingVoucherPaymentsFromList(mappedPayments) : mappedPayments;
|
|
3545
|
+
const completion = this.getPaymentCompletion(effectivePayments);
|
|
3546
|
+
const paidPaymentTotal = this.calculatePaymentTotal(effectivePayments);
|
|
3547
|
+
const paymentStatus = completion.isOrderFullyPaid ? params.paymentStatus || "paid" : paidPaymentTotal.gt(0) ? "partially_paid" : "payment_processing";
|
|
3548
|
+
tempOrder.payments = effectivePayments;
|
|
3387
3549
|
tempOrder.payment_status = paymentStatus;
|
|
3388
3550
|
this.persistTempOrder();
|
|
3389
3551
|
await this.saveDraft();
|
|
@@ -3396,14 +3558,15 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3396
3558
|
this.store.syncState = "submitting";
|
|
3397
3559
|
const paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(
|
|
3398
3560
|
tempOrder,
|
|
3399
|
-
|
|
3561
|
+
effectivePayments
|
|
3400
3562
|
);
|
|
3401
3563
|
const submitResult = await this.submitTempOrder({
|
|
3402
|
-
payments:
|
|
3564
|
+
payments: effectivePayments,
|
|
3403
3565
|
paymentStatus,
|
|
3404
3566
|
smallTicketDataFlag: params.smallTicketDataFlag,
|
|
3405
3567
|
businessCode: params.businessCode,
|
|
3406
3568
|
channel: params.channel,
|
|
3569
|
+
confirmPendingVoucherPayments: true,
|
|
3407
3570
|
enhancePayload: (payload) => {
|
|
3408
3571
|
const nextPayload = {
|
|
3409
3572
|
...payload,
|
|
@@ -3746,6 +3909,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3746
3909
|
const currentDiscounts = typeof ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList) === "function" ? this.store.discount.getDiscountList() || [] : [];
|
|
3747
3910
|
const shouldSkipEmptyDiscountSync = hydratedEditDiscounts.length === 0 && currentDiscounts.length === 0;
|
|
3748
3911
|
if (!shouldSkipEmptyDiscountSync) {
|
|
3912
|
+
OrderModule.populateSavedAmounts(
|
|
3913
|
+
nextTempOrder.products,
|
|
3914
|
+
hydratedEditDiscounts
|
|
3915
|
+
);
|
|
3749
3916
|
await ((_b = this.store.discount) == null ? void 0 : _b.setOriginalDiscountList(hydratedEditDiscounts));
|
|
3750
3917
|
await ((_c = this.store.discount) == null ? void 0 : _c.setDiscountList(hydratedEditDiscounts));
|
|
3751
3918
|
}
|
|
@@ -3950,7 +4117,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3950
4117
|
return normalized;
|
|
3951
4118
|
}
|
|
3952
4119
|
normalizeHydratedOrderProduct(product) {
|
|
3953
|
-
|
|
4120
|
+
let row = { ...product || {} };
|
|
3954
4121
|
if (row.num === void 0 && row.product_quantity !== void 0) {
|
|
3955
4122
|
row.num = row.product_quantity;
|
|
3956
4123
|
}
|
|
@@ -3971,6 +4138,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3971
4138
|
if (row.booking_uid && !row.metadata.booking_uid) {
|
|
3972
4139
|
row.metadata.booking_uid = row.booking_uid;
|
|
3973
4140
|
}
|
|
4141
|
+
row = (0, import_bundleDiscountHydration.restoreHydratedBundleDiscounts)(row, import_utils.normalizeOrderProductDiscountList);
|
|
3974
4142
|
const existingIdentity = row.metadata.unique_identification_number || row.unique_identification_number;
|
|
3975
4143
|
if (!existingIdentity) {
|
|
3976
4144
|
row.metadata.unique_identification_number = (0, import_utils.createUuidV4)();
|
|
@@ -3990,7 +4158,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3990
4158
|
};
|
|
3991
4159
|
if (result.metadata)
|
|
3992
4160
|
delete result.metadata.price_schema_version;
|
|
3993
|
-
|
|
4161
|
+
const restored = (0, import_bundleDiscountHydration.restoreHydratedBundleDiscounts)(result, import_utils.normalizeOrderProductDiscountList);
|
|
4162
|
+
return this.sanitizeOrderProductForTempOrder(restored);
|
|
3994
4163
|
}
|
|
3995
4164
|
getLastOrderInfo() {
|
|
3996
4165
|
var _a;
|
|
@@ -491,7 +491,7 @@ export interface OrderPaymentData {
|
|
|
491
491
|
voucher_id?: string | number;
|
|
492
492
|
origin_amount?: string;
|
|
493
493
|
service_fee?: string;
|
|
494
|
-
status?: 'active' | 'voided' | string;
|
|
494
|
+
status?: 'active' | 'paid' | 'voided' | 'payment_pending' | string;
|
|
495
495
|
/** 支付时间 (格式: YYYY-MM-DD HH:mm:ss) */
|
|
496
496
|
payment_time?: string;
|
|
497
497
|
wallet_pass_usage_unit?: unknown;
|
|
@@ -537,6 +537,7 @@ export interface SyncPaymentsToOrderParams {
|
|
|
537
537
|
smallTicketDataFlag?: number;
|
|
538
538
|
businessCode?: string;
|
|
539
539
|
channel?: string;
|
|
540
|
+
confirmPendingVoucherPayments?: boolean;
|
|
540
541
|
}
|
|
541
542
|
export interface SyncPaymentsToOrderResult<T = any> {
|
|
542
543
|
isFullyPaid: boolean;
|
|
@@ -696,6 +697,7 @@ export interface OrderModuleAPI {
|
|
|
696
697
|
payments?: OrderPaymentSource[];
|
|
697
698
|
paymentStatus?: SubmitSalesOrderParams['query']['payment_status'];
|
|
698
699
|
smallTicketDataFlag?: number;
|
|
700
|
+
confirmPendingVoucherPayments?: boolean;
|
|
699
701
|
enhancePayload?: SubmitPayloadEnhancer;
|
|
700
702
|
}) => Promise<T>;
|
|
701
703
|
submitTempOrderAsync: <T = any>(params?: {
|
|
@@ -707,6 +709,7 @@ export interface OrderModuleAPI {
|
|
|
707
709
|
payments?: OrderPaymentSource[];
|
|
708
710
|
paymentStatus?: SubmitSalesOrderParams['query']['payment_status'];
|
|
709
711
|
smallTicketDataFlag?: number;
|
|
712
|
+
confirmPendingVoucherPayments?: boolean;
|
|
710
713
|
enhancePayload?: SubmitPayloadEnhancer;
|
|
711
714
|
}) => Promise<T>;
|
|
712
715
|
getOrderPayments: () => OrderPaymentData[];
|
|
@@ -714,7 +717,17 @@ export interface OrderModuleAPI {
|
|
|
714
717
|
addOrderPayment: (payment: OrderPaymentSource) => OrderPaymentData[];
|
|
715
718
|
updateOrderPayment: (paymentIdentity: string | number, updates: Partial<OrderPaymentData> & Record<string, any>) => OrderPaymentData[];
|
|
716
719
|
deleteOrderPayment: (paymentIdentity: string | number) => OrderPaymentData[];
|
|
717
|
-
updateVoucherOrderPayments: (payments: OrderPaymentSource[]
|
|
720
|
+
updateVoucherOrderPayments: (payments: OrderPaymentSource[], options?: {
|
|
721
|
+
status?: 'paid' | 'payment_pending';
|
|
722
|
+
}) => OrderPaymentData[];
|
|
723
|
+
confirmPendingVoucherPayments: (options?: {
|
|
724
|
+
persist?: boolean;
|
|
725
|
+
recalculateSummary?: boolean;
|
|
726
|
+
}) => OrderPaymentData[];
|
|
727
|
+
discardPendingVoucherPayments: (options?: {
|
|
728
|
+
persist?: boolean;
|
|
729
|
+
recalculateSummary?: boolean;
|
|
730
|
+
}) => OrderPaymentData[];
|
|
718
731
|
sendCustomerPayLink: <T = any>(params: SendCustomerPayLinkParams) => Promise<T>;
|
|
719
732
|
saveDraft: () => Promise<void>;
|
|
720
733
|
hydrateTempOrderFromRecord: (record: Record<string, any>, options?: {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { OrderProductDiscountItem } from '../types';
|
|
2
|
+
type NormalizeDiscountList = (discountList?: unknown[] | null) => OrderProductDiscountItem[];
|
|
3
|
+
export declare function restoreHydratedBundleDiscounts<T extends Record<string, any>>(product: T, normalizeDiscountList: NormalizeDiscountList): T;
|
|
4
|
+
export declare function expandHydratedProductsForDiscountCollection(products: any[] | undefined | null): any[];
|
|
5
|
+
export {};
|