@pisell/pisellos 2.2.260 → 2.2.261
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/model/strategy/adapter/index.d.ts +0 -4
- package/dist/model/strategy/adapter/index.js +1 -5
- package/dist/model/strategy/adapter/promotion/adapter.d.ts +4 -0
- package/dist/model/strategy/adapter/promotion/adapter.js +23 -0
- package/dist/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
- package/dist/model/strategy/adapter/promotion/evaluator.js +279 -6
- package/dist/model/strategy/adapter/promotion/examples.d.ts +86 -0
- package/dist/model/strategy/adapter/promotion/examples.js +99 -0
- package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
- package/dist/model/strategy/adapter/promotion/index.js +1 -1
- package/dist/model/strategy/adapter/promotion/type.d.ts +90 -2
- package/dist/model/strategy/adapter/promotion/type.js +45 -0
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +17 -13
- package/dist/modules/Order/index.d.ts +33 -2
- package/dist/modules/Order/index.js +615 -288
- package/dist/modules/Order/types.d.ts +20 -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.d.ts +4 -0
- package/dist/modules/Order/utils.js +116 -29
- package/dist/modules/Product/types.d.ts +0 -22
- package/dist/modules/ProductList/index.d.ts +1 -1
- package/dist/modules/ProductList/index.js +2 -4
- package/dist/modules/ProductList/types.d.ts +0 -2
- package/dist/modules/Rules/index.d.ts +4 -3
- package/dist/modules/Rules/index.js +42 -17
- package/dist/modules/Rules/types.d.ts +2 -1
- package/dist/modules/SalesSummary/index.d.ts +7 -3
- package/dist/modules/SalesSummary/index.js +67 -39
- package/dist/modules/SalesSummary/types.d.ts +1 -0
- package/dist/modules/SalesSummary/utils.js +2 -1
- package/dist/modules/SurchargeList/index.d.ts +6 -4
- package/dist/modules/SurchargeList/index.js +62 -39
- package/dist/modules/SurchargeList/types.d.ts +6 -2
- package/dist/server/index.d.ts +3 -50
- package/dist/server/index.js +1075 -1040
- package/dist/server/modules/order/index.d.ts +22 -3
- package/dist/server/modules/order/index.js +398 -316
- package/dist/server/modules/products/index.d.ts +7 -26
- package/dist/server/modules/products/index.js +76 -166
- package/dist/server/modules/products/types.d.ts +0 -14
- package/dist/solution/BaseSales/index.d.ts +22 -2
- package/dist/solution/BaseSales/index.js +995 -701
- package/dist/solution/BaseSales/types.d.ts +1 -0
- package/dist/solution/BaseSales/types.js +2 -1
- package/dist/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
- package/dist/solution/BaseSales/utils/cartPromotion.js +74 -29
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +6 -3
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +9 -1
- package/dist/solution/BookingTicket/index.js +153 -6
- package/dist/solution/BookingTicket/types.d.ts +0 -2
- package/dist/solution/ScanOrder/index.js +31 -20
- package/dist/solution/VenueBooking/index.js +30 -19
- package/lib/model/strategy/adapter/index.d.ts +0 -4
- package/lib/model/strategy/adapter/index.js +2 -13
- package/lib/model/strategy/adapter/promotion/adapter.d.ts +4 -0
- package/lib/model/strategy/adapter/promotion/adapter.js +20 -0
- package/lib/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
- package/lib/model/strategy/adapter/promotion/evaluator.js +235 -0
- package/lib/model/strategy/adapter/promotion/examples.d.ts +86 -0
- package/lib/model/strategy/adapter/promotion/examples.js +91 -0
- package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
- package/lib/model/strategy/adapter/promotion/index.js +2 -0
- package/lib/model/strategy/adapter/promotion/type.d.ts +90 -2
- package/lib/model/strategy/adapter/promotion/type.js +2 -0
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +11 -1
- package/lib/modules/Order/index.d.ts +33 -2
- package/lib/modules/Order/index.js +402 -64
- package/lib/modules/Order/types.d.ts +20 -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.d.ts +4 -0
- package/lib/modules/Order/utils.js +90 -3
- package/lib/modules/Product/types.d.ts +0 -22
- package/lib/modules/ProductList/index.d.ts +1 -1
- package/lib/modules/ProductList/index.js +2 -4
- package/lib/modules/ProductList/types.d.ts +0 -2
- package/lib/modules/Rules/index.d.ts +4 -3
- package/lib/modules/Rules/index.js +27 -7
- package/lib/modules/Rules/types.d.ts +2 -1
- package/lib/modules/SalesSummary/index.d.ts +7 -3
- package/lib/modules/SalesSummary/index.js +28 -11
- package/lib/modules/SalesSummary/types.d.ts +1 -0
- package/lib/modules/SalesSummary/utils.js +2 -0
- package/lib/modules/SurchargeList/index.d.ts +6 -4
- package/lib/modules/SurchargeList/index.js +41 -21
- package/lib/modules/SurchargeList/types.d.ts +6 -2
- package/lib/server/index.d.ts +3 -50
- package/lib/server/index.js +244 -215
- package/lib/server/modules/order/index.d.ts +22 -3
- package/lib/server/modules/order/index.js +103 -53
- package/lib/server/modules/products/index.d.ts +7 -26
- package/lib/server/modules/products/index.js +35 -113
- package/lib/server/modules/products/types.d.ts +0 -14
- package/lib/solution/BaseSales/index.d.ts +22 -2
- package/lib/solution/BaseSales/index.js +246 -60
- package/lib/solution/BaseSales/types.d.ts +1 -0
- package/lib/solution/BaseSales/types.js +2 -1
- package/lib/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
- package/lib/solution/BaseSales/utils/cartPromotion.js +59 -16
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +6 -6
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +9 -1
- package/lib/solution/BookingTicket/index.js +101 -0
- package/lib/solution/BookingTicket/types.d.ts +0 -2
- package/lib/solution/ScanOrder/index.js +8 -0
- package/lib/solution/VenueBooking/index.js +8 -0
- package/package.json +1 -1
- package/dist/model/strategy/adapter/dataVariant/adapter.d.ts +0 -49
- package/dist/model/strategy/adapter/dataVariant/adapter.js +0 -152
- package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +0 -87
- package/dist/model/strategy/adapter/dataVariant/evaluator.js +0 -755
- package/dist/model/strategy/adapter/dataVariant/examples.d.ts +0 -39
- package/dist/model/strategy/adapter/dataVariant/examples.js +0 -282
- package/dist/model/strategy/adapter/dataVariant/index.d.ts +0 -4
- package/dist/model/strategy/adapter/dataVariant/index.js +0 -4
- package/dist/model/strategy/adapter/dataVariant/type.d.ts +0 -146
- package/dist/model/strategy/adapter/dataVariant/type.js +0 -54
- package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +0 -49
- package/lib/model/strategy/adapter/dataVariant/adapter.js +0 -139
- package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +0 -87
- package/lib/model/strategy/adapter/dataVariant/evaluator.js +0 -564
- package/lib/model/strategy/adapter/dataVariant/examples.d.ts +0 -39
- package/lib/model/strategy/adapter/dataVariant/examples.js +0 -295
- package/lib/model/strategy/adapter/dataVariant/index.d.ts +0 -4
- package/lib/model/strategy/adapter/dataVariant/index.js +0 -38
- package/lib/model/strategy/adapter/dataVariant/type.d.ts +0 -146
- package/lib/model/strategy/adapter/dataVariant/type.js +0 -31
|
@@ -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: "",
|
|
@@ -236,6 +269,21 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
236
269
|
product.metadata.main_product_selling_price = newMainSellingPrice;
|
|
237
270
|
product.metadata.price_schema_version = 2;
|
|
238
271
|
}
|
|
272
|
+
if (Array.isArray(product.product_bundle)) {
|
|
273
|
+
product.product_bundle = product.product_bundle.map((bundle) => {
|
|
274
|
+
const hasBundleDiscount = Array.isArray(bundle == null ? void 0 : bundle.discount_list) && bundle.discount_list.length > 0;
|
|
275
|
+
if (hasBundleDiscount)
|
|
276
|
+
return bundle;
|
|
277
|
+
const restoredPrice = (bundle == null ? void 0 : bundle.original_price) ?? (bundle == null ? void 0 : bundle.product_price) ?? (bundle == null ? void 0 : bundle.price);
|
|
278
|
+
if (restoredPrice === void 0 || restoredPrice === null || restoredPrice === "")
|
|
279
|
+
return bundle;
|
|
280
|
+
return {
|
|
281
|
+
...bundle,
|
|
282
|
+
price: restoredPrice,
|
|
283
|
+
bundle_selling_price: restoredPrice
|
|
284
|
+
};
|
|
285
|
+
});
|
|
286
|
+
}
|
|
239
287
|
product.selling_price = (0, import_utils.composeLinePrice)({
|
|
240
288
|
mainPrice: newMainSellingPrice,
|
|
241
289
|
bundle: product.product_bundle
|
|
@@ -434,7 +482,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
434
482
|
});
|
|
435
483
|
}
|
|
436
484
|
async scanCode(code, customerId) {
|
|
437
|
-
var _a, _b, _c, _d
|
|
485
|
+
var _a, _b, _c, _d;
|
|
438
486
|
const resultDiscountWithReason = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, { customerId })) || { discountList: [], unavailableReasonKey: null };
|
|
439
487
|
const { discountList: resultDiscountList, unavailableReasonKey } = resultDiscountWithReason;
|
|
440
488
|
const rulesModule = this.store.rules;
|
|
@@ -470,17 +518,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
470
518
|
};
|
|
471
519
|
}
|
|
472
520
|
const tempOrder = this.store.tempOrder;
|
|
473
|
-
const holders = ((_b = tempOrder == null ? void 0 : tempOrder.holder) == null ? void 0 : _b.
|
|
521
|
+
const holders = ((_b = tempOrder == null ? void 0 : tempOrder.holder) == null ? void 0 : _b.form_record) || [];
|
|
474
522
|
const { isAvailable, discountList: newDiscountList, unavailableReason } = rulesModule.isDiscountListAvailable({
|
|
475
523
|
productList: (tempOrder == null ? void 0 : tempOrder.products) || [],
|
|
476
524
|
oldDiscountList: this.getDiscountList(),
|
|
477
525
|
newDiscountList: withScanList,
|
|
478
526
|
orderTotalAmount: Number(((_c = this.store.summary) == null ? void 0 : _c.total_amount) || 0),
|
|
479
527
|
holders,
|
|
480
|
-
isFormSubject:
|
|
528
|
+
isFormSubject: (product) => (0, import_utils.resolveIsFormSubject)(tempOrder, product)
|
|
481
529
|
}) || { isAvailable: false, discountList: this.getDiscountList() };
|
|
482
530
|
if (isAvailable && newDiscountList) {
|
|
483
|
-
(
|
|
531
|
+
(_d = this.store.discount) == null ? void 0 : _d.setDiscountList(newDiscountList);
|
|
484
532
|
this.applyDiscount();
|
|
485
533
|
}
|
|
486
534
|
return {
|
|
@@ -492,24 +540,26 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
492
540
|
};
|
|
493
541
|
}
|
|
494
542
|
applyDiscount() {
|
|
495
|
-
var _a, _b, _c, _d
|
|
543
|
+
var _a, _b, _c, _d;
|
|
496
544
|
const tempOrder = this.store.tempOrder;
|
|
497
545
|
if (!tempOrder)
|
|
498
546
|
return;
|
|
547
|
+
this.syncLinkedBookingHoldersToProducts(tempOrder);
|
|
499
548
|
delete tempOrder.discount_list;
|
|
500
|
-
|
|
549
|
+
const discountList = ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList()) || [];
|
|
550
|
+
const shouldSkipDiscountCalculation = this.shouldSkipDiscountCalculation(tempOrder);
|
|
551
|
+
if (shouldSkipDiscountCalculation)
|
|
501
552
|
return;
|
|
502
553
|
const rulesModule = this.store.rules;
|
|
503
554
|
if (!rulesModule)
|
|
504
555
|
return;
|
|
505
|
-
const
|
|
506
|
-
const holders = ((_b = tempOrder.holder) == null ? void 0 : _b.form_record_id) ? [{ form_record_id: tempOrder.holder.form_record_id }] : [];
|
|
556
|
+
const holders = ((_b = tempOrder.holder) == null ? void 0 : _b.form_record) || [];
|
|
507
557
|
const result = rulesModule.calcDiscount({
|
|
508
558
|
productList: tempOrder.products,
|
|
509
559
|
discountList,
|
|
510
560
|
holders,
|
|
511
|
-
isFormSubject:
|
|
512
|
-
orderTotalAmount: Number(((
|
|
561
|
+
isFormSubject: (product) => (0, import_utils.resolveIsFormSubject)(tempOrder, product),
|
|
562
|
+
orderTotalAmount: Number(((_c = this.store.summary) == null ? void 0 : _c.total_amount) || 0)
|
|
513
563
|
});
|
|
514
564
|
if (result == null ? void 0 : result.productList) {
|
|
515
565
|
const previousProductsByUid = (0, import_utils.indexOrderProductsByUid)(tempOrder.products);
|
|
@@ -538,7 +588,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
538
588
|
result.productList || tempOrder.products,
|
|
539
589
|
result.discountList
|
|
540
590
|
);
|
|
541
|
-
(
|
|
591
|
+
(_d = this.store.discount) == null ? void 0 : _d.setDiscountList(result.discountList);
|
|
542
592
|
}
|
|
543
593
|
this.hasActiveCustomerBoundDiscount = (tempOrder.products || []).some(
|
|
544
594
|
(product) => this.productHasCustomerBoundDiscount(product)
|
|
@@ -816,6 +866,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
816
866
|
return (0, import_utils.mapPaymentItemsToOrderPayments)(payments, {
|
|
817
867
|
includeVoided: false
|
|
818
868
|
}).reduce((sum, payment) => {
|
|
869
|
+
if (!isPaidPaymentRecord(payment))
|
|
870
|
+
return sum;
|
|
819
871
|
return sum.plus(this.calculatePaymentEffectiveAmount(payment));
|
|
820
872
|
}, new import_decimal.default(0));
|
|
821
873
|
}
|
|
@@ -825,6 +877,33 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
825
877
|
normalizeDepositAmount(amount) {
|
|
826
878
|
return import_decimal.default.max(new import_decimal.default(Number(amount) || 0), 0).toDecimalPlaces(2).toFixed(2);
|
|
827
879
|
}
|
|
880
|
+
getLastOrderDepositSnapshot() {
|
|
881
|
+
var _a;
|
|
882
|
+
const lastOrderInfo = this.store.lastOrderInfo;
|
|
883
|
+
if (!lastOrderInfo || typeof lastOrderInfo !== "object")
|
|
884
|
+
return null;
|
|
885
|
+
const rawDepositAmount = lastOrderInfo.deposit_amount ?? ((_a = lastOrderInfo.summary) == null ? void 0 : _a.deposit_amount);
|
|
886
|
+
const depositAmount = this.normalizeDepositAmount(rawDepositAmount ?? 0);
|
|
887
|
+
const hasDepositAmount = new import_decimal.default(depositAmount).gt(0);
|
|
888
|
+
const isDeposit = Number(lastOrderInfo.is_deposit) === 1 || hasDepositAmount;
|
|
889
|
+
if (!isDeposit || !hasDepositAmount)
|
|
890
|
+
return null;
|
|
891
|
+
return {
|
|
892
|
+
isDeposit: 1,
|
|
893
|
+
depositAmount
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
getLastOrderSubmitSnapshot() {
|
|
897
|
+
const lastOrderInfo = this.store.lastOrderInfo;
|
|
898
|
+
if (!lastOrderInfo || typeof lastOrderInfo !== "object")
|
|
899
|
+
return {};
|
|
900
|
+
const businessCode = lastOrderInfo.business_code;
|
|
901
|
+
const type = lastOrderInfo.type;
|
|
902
|
+
return {
|
|
903
|
+
...typeof businessCode === "string" && businessCode ? { businessCode } : {},
|
|
904
|
+
...typeof type === "string" && type ? { type } : {}
|
|
905
|
+
};
|
|
906
|
+
}
|
|
828
907
|
applyDepositAmountToSummary(tempOrder, summary, amount) {
|
|
829
908
|
const depositAmount = this.normalizeDepositAmount(amount);
|
|
830
909
|
const hasDepositAmount = new import_decimal.default(depositAmount).gt(0);
|
|
@@ -843,8 +922,27 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
843
922
|
tempOrder.is_deposit = hasDepositAmount ? 1 : 0;
|
|
844
923
|
return nextSummary;
|
|
845
924
|
}
|
|
925
|
+
applyLastOrderDepositSnapshot(tempOrder, summary) {
|
|
926
|
+
const snapshot = this.getLastOrderDepositSnapshot();
|
|
927
|
+
if (!snapshot)
|
|
928
|
+
return summary;
|
|
929
|
+
const existedDeposit = summary.deposit && typeof summary.deposit === "object" ? summary.deposit : void 0;
|
|
930
|
+
const nextSummary = {
|
|
931
|
+
...summary,
|
|
932
|
+
deposit_amount: snapshot.depositAmount,
|
|
933
|
+
deposit: {
|
|
934
|
+
...existedDeposit || {},
|
|
935
|
+
total: snapshot.depositAmount,
|
|
936
|
+
deposit_policy_ids: (existedDeposit == null ? void 0 : existedDeposit.deposit_policy_ids) || [],
|
|
937
|
+
hasDeposit: true
|
|
938
|
+
}
|
|
939
|
+
};
|
|
940
|
+
tempOrder.deposit_amount = snapshot.depositAmount;
|
|
941
|
+
tempOrder.is_deposit = tempOrder.is_deposit === 0 && new import_decimal.default(tempOrder.deposit_amount || 0).gt(0) ? 0 : snapshot.isDeposit;
|
|
942
|
+
return nextSummary;
|
|
943
|
+
}
|
|
846
944
|
isDepositOrder(tempOrder, depositAmount) {
|
|
847
|
-
return tempOrder.is_deposit === 1
|
|
945
|
+
return tempOrder.is_deposit === 1 && depositAmount.gt(0);
|
|
848
946
|
}
|
|
849
947
|
getOrderExpectedAmount(summary) {
|
|
850
948
|
return new import_decimal.default(summary.expect_amount || summary.total_amount || 0);
|
|
@@ -857,10 +955,37 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
857
955
|
return false;
|
|
858
956
|
return params.paidAmount.gte(depositAmount);
|
|
859
957
|
}
|
|
958
|
+
getPaymentCompletion(payments) {
|
|
959
|
+
const tempOrder = this.ensureTempOrder();
|
|
960
|
+
const summary = this.store.summary || (0, import_utils.createEmptySummary)();
|
|
961
|
+
const paymentList = payments || tempOrder.payments || [];
|
|
962
|
+
const refundAmount = this.getSummaryRefundAmount(summary);
|
|
963
|
+
const netPaidAmount = import_decimal.default.max(
|
|
964
|
+
this.calculatePaymentTotal(paymentList).minus(refundAmount),
|
|
965
|
+
0
|
|
966
|
+
);
|
|
967
|
+
const depositAmount = this.getDepositAmount(tempOrder, summary);
|
|
968
|
+
const orderExpectedAmount = this.getOrderExpectedAmount(summary);
|
|
969
|
+
const isDepositFullyPaid = this.isDepositCovered({
|
|
970
|
+
tempOrder,
|
|
971
|
+
summary,
|
|
972
|
+
paidAmount: netPaidAmount
|
|
973
|
+
});
|
|
974
|
+
const isOrderFullyPaid = orderExpectedAmount.lte(0) ? true : netPaidAmount.gte(orderExpectedAmount);
|
|
975
|
+
const paymentStage = this.isDepositOrder(tempOrder, depositAmount) && !isDepositFullyPaid ? "deposit" : "normal";
|
|
976
|
+
return {
|
|
977
|
+
isFullyPaid: isOrderFullyPaid,
|
|
978
|
+
isOrderFullyPaid,
|
|
979
|
+
isDepositFullyPaid,
|
|
980
|
+
paymentStage,
|
|
981
|
+
depositAmount: depositAmount.toFixed(2),
|
|
982
|
+
orderExpectedAmount: orderExpectedAmount.toFixed(2)
|
|
983
|
+
};
|
|
984
|
+
}
|
|
860
985
|
calculateDepositPaidAmount(payments) {
|
|
861
986
|
return (payments || []).reduce((sum, payment) => {
|
|
862
987
|
const paymentRecord = payment;
|
|
863
|
-
if ((paymentRecord
|
|
988
|
+
if (!isPaidPaymentRecord(paymentRecord))
|
|
864
989
|
return sum;
|
|
865
990
|
const isDepositPayment = paymentRecord.type === "deposit" || paymentRecord.order_payment_type === "deposit";
|
|
866
991
|
if (!isDepositPayment)
|
|
@@ -1011,7 +1136,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1011
1136
|
return (payments || []).reduce(
|
|
1012
1137
|
(summary, payment) => {
|
|
1013
1138
|
const paymentRecord = payment;
|
|
1014
|
-
if ((paymentRecord
|
|
1139
|
+
if (!isPaidPaymentRecord(paymentRecord))
|
|
1015
1140
|
return summary;
|
|
1016
1141
|
return {
|
|
1017
1142
|
customerPaidAmount: summary.customerPaidAmount.plus(paymentRecord.amount || 0),
|
|
@@ -1345,10 +1470,15 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1345
1470
|
});
|
|
1346
1471
|
return currentAmountGap === snapshotAmountGap;
|
|
1347
1472
|
}
|
|
1348
|
-
|
|
1349
|
-
const
|
|
1350
|
-
|
|
1351
|
-
|
|
1473
|
+
hasShopDiscountChangedFromSnapshot(tempOrder, snapshot) {
|
|
1474
|
+
const snapshotSummary = snapshot.summary && typeof snapshot.summary === "object" ? snapshot.summary : {};
|
|
1475
|
+
const snapshotShopDiscount = snapshot.shop_discount ?? snapshotSummary.shop_discount;
|
|
1476
|
+
if (snapshotShopDiscount === void 0 || snapshotShopDiscount === null || snapshotShopDiscount === "") {
|
|
1477
|
+
return !new import_decimal.default(tempOrder.shop_discount || 0).equals(0);
|
|
1478
|
+
}
|
|
1479
|
+
return !new import_decimal.default(tempOrder.shop_discount || 0).equals(snapshotShopDiscount || 0);
|
|
1480
|
+
}
|
|
1481
|
+
restoreOriginalSnapshotIfProductsUnchanged(tempOrder, snapshot) {
|
|
1352
1482
|
const currentFingerprint = this.buildOrderProductsFingerprint(tempOrder.products);
|
|
1353
1483
|
if (currentFingerprint !== snapshot.productFingerprint) {
|
|
1354
1484
|
const currentStructuralFingerprint = this.buildOrderProductsStructuralFingerprint(tempOrder.products);
|
|
@@ -1437,6 +1567,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1437
1567
|
}
|
|
1438
1568
|
restoreOrder() {
|
|
1439
1569
|
var _a, _b;
|
|
1570
|
+
this.logInfo("restoreOrder start", {});
|
|
1440
1571
|
const freshTempOrder = this.createDefaultTempOrderInstance();
|
|
1441
1572
|
this.ensureExternalSaleNumber(freshTempOrder);
|
|
1442
1573
|
this.store.tempOrder = freshTempOrder;
|
|
@@ -1515,7 +1646,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1515
1646
|
orderPaidAmount: paidPaymentSummary.gapPaidAmount
|
|
1516
1647
|
});
|
|
1517
1648
|
return {
|
|
1518
|
-
isDeposit: tempOrder.is_deposit === 1
|
|
1649
|
+
isDeposit: tempOrder.is_deposit === 1,
|
|
1519
1650
|
depositAmount,
|
|
1520
1651
|
expectAmount: summary.expect_amount || "0.00",
|
|
1521
1652
|
totalAmount: summary.total_amount || "0.00",
|
|
@@ -1662,6 +1793,47 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1662
1793
|
const records = Array.isArray(source) ? source : [source];
|
|
1663
1794
|
return records.filter((record) => record !== void 0 && record !== null && record !== "");
|
|
1664
1795
|
}
|
|
1796
|
+
setProductHolderFromBooking(product, booking) {
|
|
1797
|
+
if (!product || !booking)
|
|
1798
|
+
return;
|
|
1799
|
+
const holderRecords = this.collectBookingHolderRecords(booking);
|
|
1800
|
+
if (!product.metadata || typeof product.metadata !== "object") {
|
|
1801
|
+
product.metadata = {};
|
|
1802
|
+
}
|
|
1803
|
+
product.metadata.holder_id = holderRecords.length > 0 ? holderRecords : null;
|
|
1804
|
+
}
|
|
1805
|
+
syncLinkedBookingHoldersToProducts(tempOrder) {
|
|
1806
|
+
const bookings = tempOrder.bookings || [];
|
|
1807
|
+
const products = tempOrder.products || [];
|
|
1808
|
+
if (!bookings.length || !products.length)
|
|
1809
|
+
return;
|
|
1810
|
+
const bookingByProductUid = /* @__PURE__ */ new Map();
|
|
1811
|
+
const bookingByBookingUid = /* @__PURE__ */ new Map();
|
|
1812
|
+
bookings.forEach((booking) => {
|
|
1813
|
+
var _a, _b;
|
|
1814
|
+
if (!booking || typeof booking !== "object")
|
|
1815
|
+
return;
|
|
1816
|
+
const productUid = booking.product_uid || ((_a = booking.metadata) == null ? void 0 : _a.product_uid);
|
|
1817
|
+
if (productUid !== void 0 && productUid !== null && String(productUid) !== "") {
|
|
1818
|
+
bookingByProductUid.set(String(productUid), booking);
|
|
1819
|
+
}
|
|
1820
|
+
const bookingUid = ((_b = booking.metadata) == null ? void 0 : _b.unique_identification_number) || booking.booking_uid;
|
|
1821
|
+
if (bookingUid !== void 0 && bookingUid !== null && String(bookingUid) !== "") {
|
|
1822
|
+
bookingByBookingUid.set(String(bookingUid), booking);
|
|
1823
|
+
}
|
|
1824
|
+
});
|
|
1825
|
+
products.forEach((product) => {
|
|
1826
|
+
var _a, _b;
|
|
1827
|
+
if (!product || typeof product !== "object")
|
|
1828
|
+
return;
|
|
1829
|
+
const productUid = ((_a = product.metadata) == null ? void 0 : _a.unique_identification_number) || product.unique_identification_number;
|
|
1830
|
+
const bookingUid = product.booking_uid || ((_b = product.metadata) == null ? void 0 : _b.booking_uid);
|
|
1831
|
+
const linkedBooking = (productUid !== void 0 && productUid !== null && String(productUid) !== "" ? bookingByProductUid.get(String(productUid)) : void 0) || (bookingUid !== void 0 && bookingUid !== null && String(bookingUid) !== "" ? bookingByBookingUid.get(String(bookingUid)) : void 0);
|
|
1832
|
+
if (linkedBooking) {
|
|
1833
|
+
this.setProductHolderFromBooking(product, linkedBooking);
|
|
1834
|
+
}
|
|
1835
|
+
});
|
|
1836
|
+
}
|
|
1665
1837
|
/**
|
|
1666
1838
|
* 按 form_record 顺序读取 booking holder 的主字段名称。
|
|
1667
1839
|
*
|
|
@@ -1741,6 +1913,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1741
1913
|
if (nextHolder || hasHolderSource || bookings.length === 0) {
|
|
1742
1914
|
tempOrder.holder = nextHolder;
|
|
1743
1915
|
}
|
|
1916
|
+
this.syncLinkedBookingHoldersToProducts(tempOrder);
|
|
1744
1917
|
}
|
|
1745
1918
|
getBookingUniqueIdentificationNumber(booking) {
|
|
1746
1919
|
var _a;
|
|
@@ -1800,19 +1973,24 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1800
1973
|
hasDeposit: true
|
|
1801
1974
|
} : void 0
|
|
1802
1975
|
};
|
|
1976
|
+
const isExistingDepositDisabled = tempOrder.is_deposit === 0 && new import_decimal.default(tempOrder.deposit_amount || 0).gt(0);
|
|
1803
1977
|
tempOrder.deposit_amount = depositAmount;
|
|
1804
|
-
tempOrder.is_deposit = hasDepositAmount ? 1 : 0;
|
|
1805
|
-
return nextSummary;
|
|
1978
|
+
tempOrder.is_deposit = hasDepositAmount && !isExistingDepositDisabled ? 1 : 0;
|
|
1979
|
+
return this.applyLastOrderDepositSnapshot(tempOrder, nextSummary);
|
|
1806
1980
|
}
|
|
1807
1981
|
async recalculateSummary(options) {
|
|
1982
|
+
var _a;
|
|
1808
1983
|
const tempOrder = (options == null ? void 0 : options.createIfMissing) ? this.ensureTempOrder() : this.store.tempOrder;
|
|
1809
1984
|
if (!tempOrder)
|
|
1810
1985
|
return null;
|
|
1811
1986
|
this.sanitizeTempOrderProducts(tempOrder);
|
|
1812
|
-
const
|
|
1987
|
+
const originalSnapshot = this.getOriginalSalesSnapshot(tempOrder);
|
|
1988
|
+
const hasShopDiscountChanged = originalSnapshot ? this.hasShopDiscountChangedFromSnapshot(tempOrder, originalSnapshot) : false;
|
|
1989
|
+
const shouldReuseOriginalSnapshot = originalSnapshot && !hasShopDiscountChanged;
|
|
1990
|
+
const snapshotSummary = shouldReuseOriginalSnapshot ? this.restoreOriginalSnapshotIfProductsUnchanged(tempOrder, originalSnapshot) : null;
|
|
1813
1991
|
if (snapshotSummary)
|
|
1814
1992
|
return snapshotSummary;
|
|
1815
|
-
const shouldFullRecalculateFromSnapshot = Boolean(
|
|
1993
|
+
const shouldFullRecalculateFromSnapshot = Boolean(originalSnapshot);
|
|
1816
1994
|
const summaryProducts = shouldFullRecalculateFromSnapshot ? (0, import_lodash_es.cloneDeep)(tempOrder.products || []) : tempOrder.products;
|
|
1817
1995
|
if (shouldFullRecalculateFromSnapshot) {
|
|
1818
1996
|
this.clearPersistedAmountFieldsForFullRecalc(summaryProducts || []);
|
|
@@ -1859,7 +2037,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1859
2037
|
const salesSummaryResult = await salesSummary.getSummary({
|
|
1860
2038
|
products: summaryProducts,
|
|
1861
2039
|
isPriceIncludeTax: tempOrder.is_price_include_tax,
|
|
1862
|
-
shopDiscount: tempOrder.shop_discount
|
|
2040
|
+
shopDiscount: tempOrder.shop_discount,
|
|
2041
|
+
...((_a = this.otherParams) == null ? void 0 : _a.channel) ? { channel: this.otherParams.channel } : {}
|
|
1863
2042
|
});
|
|
1864
2043
|
if (shouldFullRecalculateFromSnapshot) {
|
|
1865
2044
|
tempOrder.products = summaryProducts;
|
|
@@ -2146,6 +2325,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2146
2325
|
if (String(previousCustomerId ?? "") !== String(nextCustomerId ?? "")) {
|
|
2147
2326
|
(0, import_utils.clearTempOrderHolderAssignments)(tempOrder);
|
|
2148
2327
|
this.clearCustomerBoundDiscounts(tempOrder);
|
|
2328
|
+
this.applyDiscount();
|
|
2149
2329
|
}
|
|
2150
2330
|
this.persistTempOrder();
|
|
2151
2331
|
this.saveDraftInBackground();
|
|
@@ -2303,49 +2483,153 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2303
2483
|
this.persistTempOrder();
|
|
2304
2484
|
return tempOrder.payments;
|
|
2305
2485
|
}
|
|
2486
|
+
confirmPendingVoucherPaymentsInList(payments) {
|
|
2487
|
+
return (payments || []).map((payment) => {
|
|
2488
|
+
if (!isPendingVoucherPaymentRecord(payment))
|
|
2489
|
+
return payment;
|
|
2490
|
+
return {
|
|
2491
|
+
...payment,
|
|
2492
|
+
status: ORDER_PAYMENT_STATUS_PAID
|
|
2493
|
+
};
|
|
2494
|
+
});
|
|
2495
|
+
}
|
|
2496
|
+
discardPendingVoucherPaymentsFromList(payments) {
|
|
2497
|
+
return (payments || []).filter((payment) => !isPendingVoucherPaymentRecord(payment));
|
|
2498
|
+
}
|
|
2499
|
+
prepareVoucherPaymentsForSubmit(payments, confirmPendingVoucherPayments = true) {
|
|
2500
|
+
const mappedPayments = (0, import_utils.mapPaymentItemsToOrderPayments)(payments || []);
|
|
2501
|
+
return confirmPendingVoucherPayments ? this.confirmPendingVoucherPaymentsInList(mappedPayments) : this.discardPendingVoucherPaymentsFromList(mappedPayments);
|
|
2502
|
+
}
|
|
2503
|
+
applyPaymentLifecycleChange(tempOrder, options) {
|
|
2504
|
+
this.updateTempOrderPaymentStatus(tempOrder);
|
|
2505
|
+
if ((options == null ? void 0 : options.persist) !== false) {
|
|
2506
|
+
this.persistTempOrder();
|
|
2507
|
+
}
|
|
2508
|
+
if ((options == null ? void 0 : options.recalculateSummary) === false)
|
|
2509
|
+
return;
|
|
2510
|
+
const logContext = (options == null ? void 0 : options.logContext) || "payment lifecycle change";
|
|
2511
|
+
void this.recalculateSummary({ createIfMissing: true }).catch((error) => {
|
|
2512
|
+
this.logError(`recalculate summary after ${logContext} failed`, {
|
|
2513
|
+
error: error instanceof Error ? error.message : String(error)
|
|
2514
|
+
});
|
|
2515
|
+
});
|
|
2516
|
+
}
|
|
2517
|
+
confirmPendingVoucherPayments(options) {
|
|
2518
|
+
const tempOrder = this.ensureTempOrder();
|
|
2519
|
+
const payments = tempOrder.payments || [];
|
|
2520
|
+
const hasPendingVoucher = payments.some((payment) => isPendingVoucherPaymentRecord(payment));
|
|
2521
|
+
if (!hasPendingVoucher)
|
|
2522
|
+
return payments;
|
|
2523
|
+
tempOrder.payments = this.confirmPendingVoucherPaymentsInList(payments);
|
|
2524
|
+
this.applyPaymentLifecycleChange(tempOrder, {
|
|
2525
|
+
...options,
|
|
2526
|
+
logContext: "confirmPendingVoucherPayments"
|
|
2527
|
+
});
|
|
2528
|
+
return tempOrder.payments;
|
|
2529
|
+
}
|
|
2530
|
+
discardPendingVoucherPayments(options) {
|
|
2531
|
+
const tempOrder = this.ensureTempOrder();
|
|
2532
|
+
const payments = tempOrder.payments || [];
|
|
2533
|
+
const nextPayments = this.discardPendingVoucherPaymentsFromList(payments);
|
|
2534
|
+
if (nextPayments.length === payments.length)
|
|
2535
|
+
return payments;
|
|
2536
|
+
tempOrder.payments = nextPayments;
|
|
2537
|
+
this.applyPaymentLifecycleChange(tempOrder, {
|
|
2538
|
+
...options,
|
|
2539
|
+
logContext: "discardPendingVoucherPayments"
|
|
2540
|
+
});
|
|
2541
|
+
return tempOrder.payments;
|
|
2542
|
+
}
|
|
2306
2543
|
/**
|
|
2307
2544
|
* 覆盖当前订单中的 wallet pass 支付项。
|
|
2308
2545
|
*
|
|
2309
2546
|
* 判断口径与 PaymentModal 保持一致:voucher_id 存在且不为 0 的支付项
|
|
2310
2547
|
* 视为 wallet pass;其它支付项保持不变。
|
|
2311
2548
|
*/
|
|
2312
|
-
updateVoucherOrderPayments(payments) {
|
|
2549
|
+
updateVoucherOrderPayments(payments, options) {
|
|
2313
2550
|
const tempOrder = this.ensureTempOrder();
|
|
2314
|
-
const
|
|
2315
|
-
return
|
|
2551
|
+
const isOrderPaymentType = (value) => {
|
|
2552
|
+
return value === "normal" || value === "deposit";
|
|
2316
2553
|
};
|
|
2317
|
-
const
|
|
2318
|
-
|
|
2554
|
+
const voucherOrderPaymentType = this.resolveNextOrderPaymentType(tempOrder);
|
|
2555
|
+
const withVoucherPaymentType = (payment) => {
|
|
2556
|
+
const paymentRecord = payment;
|
|
2557
|
+
if (!isVoucherPaymentRecord(paymentRecord))
|
|
2558
|
+
return payment;
|
|
2559
|
+
const explicitPaymentType = isOrderPaymentType(paymentRecord.order_payment_type) ? paymentRecord.order_payment_type : isOrderPaymentType(paymentRecord.type) ? paymentRecord.type : void 0;
|
|
2560
|
+
const nextPaymentType = explicitPaymentType || voucherOrderPaymentType;
|
|
2561
|
+
const shouldPreserveCustomPaymentType = paymentRecord.custom_payment_type === void 0 && paymentRecord.type !== void 0 && !isOrderPaymentType(paymentRecord.type);
|
|
2562
|
+
return {
|
|
2563
|
+
...paymentRecord,
|
|
2564
|
+
...shouldPreserveCustomPaymentType ? { custom_payment_type: paymentRecord.type } : {},
|
|
2565
|
+
type: nextPaymentType,
|
|
2566
|
+
order_payment_type: nextPaymentType
|
|
2567
|
+
};
|
|
2568
|
+
};
|
|
2569
|
+
const normalizeVoucherPaymentStatus = (payment) => {
|
|
2570
|
+
const paymentRecord = payment;
|
|
2571
|
+
if (!isVoucherPaymentRecord(paymentRecord))
|
|
2572
|
+
return payment;
|
|
2573
|
+
if (hasSyncedOrderPaymentRecord(paymentRecord) && (paymentRecord.status === void 0 || paymentRecord.status === "active")) {
|
|
2574
|
+
return {
|
|
2575
|
+
...paymentRecord,
|
|
2576
|
+
status: ORDER_PAYMENT_STATUS_PAID
|
|
2577
|
+
};
|
|
2578
|
+
}
|
|
2579
|
+
if (paymentRecord.status !== void 0 && paymentRecord.status !== "active") {
|
|
2580
|
+
return payment;
|
|
2581
|
+
}
|
|
2582
|
+
return {
|
|
2583
|
+
...paymentRecord,
|
|
2584
|
+
status: (options == null ? void 0 : options.status) || ORDER_PAYMENT_STATUS_PENDING
|
|
2585
|
+
};
|
|
2319
2586
|
};
|
|
2320
2587
|
const mappedVouchers = (0, import_utils.mapPaymentItemsToOrderPayments)(
|
|
2321
2588
|
payments.map(
|
|
2322
|
-
(payment) => this.normalizePaymentSource(
|
|
2589
|
+
(payment) => this.normalizePaymentSource(
|
|
2590
|
+
normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)),
|
|
2591
|
+
{ defaultPaid: false }
|
|
2592
|
+
)
|
|
2323
2593
|
)
|
|
2324
2594
|
).filter((payment) => {
|
|
2325
|
-
return
|
|
2595
|
+
return isVoucherPaymentRecord(payment);
|
|
2326
2596
|
});
|
|
2327
2597
|
const nonVoucherPayments = (tempOrder.payments || []).filter((payment) => {
|
|
2328
|
-
return !
|
|
2329
|
-
});
|
|
2330
|
-
const syncedVoucherPayments = (tempOrder.payments || []).filter((payment) => {
|
|
2331
|
-
return isVoucherPayment(payment) && hasSyncedOrderPayment(payment);
|
|
2598
|
+
return !isVoucherPaymentRecord(payment);
|
|
2332
2599
|
});
|
|
2333
|
-
const
|
|
2334
|
-
|
|
2600
|
+
const normalizeCommittedVoucherPayment = (payment) => {
|
|
2601
|
+
if (hasSyncedOrderPaymentRecord(payment) && (payment.status === void 0 || payment.status === "active")) {
|
|
2602
|
+
return {
|
|
2603
|
+
...payment,
|
|
2604
|
+
status: ORDER_PAYMENT_STATUS_PAID
|
|
2605
|
+
};
|
|
2606
|
+
}
|
|
2607
|
+
return payment;
|
|
2608
|
+
};
|
|
2609
|
+
const committedVoucherPayments = (tempOrder.payments || []).filter((payment) => isCommittedVoucherPaymentRecord(payment)).map((payment) => normalizeCommittedVoucherPayment(payment));
|
|
2610
|
+
const committedVoucherPaymentIds = new Set(
|
|
2611
|
+
committedVoucherPayments.filter((payment) => hasSyncedOrderPaymentRecord(payment)).map((payment) => String(payment.order_payment_id))
|
|
2612
|
+
);
|
|
2613
|
+
const committedVoucherIds = new Set(
|
|
2614
|
+
committedVoucherPayments.map((payment) => String(payment.voucher_id))
|
|
2335
2615
|
);
|
|
2336
2616
|
const replaceableVouchers = mappedVouchers.filter((payment) => {
|
|
2337
|
-
if (
|
|
2338
|
-
return
|
|
2339
|
-
|
|
2617
|
+
if (hasSyncedOrderPaymentRecord(payment) && committedVoucherPaymentIds.has(String(payment.order_payment_id))) {
|
|
2618
|
+
return false;
|
|
2619
|
+
}
|
|
2620
|
+
if (payment.voucher_id !== void 0 && committedVoucherIds.has(String(payment.voucher_id))) {
|
|
2621
|
+
return false;
|
|
2622
|
+
}
|
|
2623
|
+
return true;
|
|
2340
2624
|
});
|
|
2341
2625
|
const cappedVouchers = this.capVoucherPaymentsByRemainingAmount({
|
|
2342
2626
|
vouchers: replaceableVouchers,
|
|
2343
2627
|
nonVoucherPayments: [
|
|
2344
2628
|
...nonVoucherPayments,
|
|
2345
|
-
...
|
|
2629
|
+
...committedVoucherPayments
|
|
2346
2630
|
]
|
|
2347
2631
|
});
|
|
2348
|
-
tempOrder.payments = [...nonVoucherPayments, ...
|
|
2632
|
+
tempOrder.payments = [...nonVoucherPayments, ...committedVoucherPayments, ...cappedVouchers];
|
|
2349
2633
|
this.updateTempOrderPaymentStatus(tempOrder);
|
|
2350
2634
|
this.persistTempOrder();
|
|
2351
2635
|
void this.recalculateSummary({ createIfMissing: true }).catch((error) => {
|
|
@@ -2561,7 +2845,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2561
2845
|
*/
|
|
2562
2846
|
async addProductToOrder(product, booking) {
|
|
2563
2847
|
const tempOrder = this.ensureTempOrder();
|
|
2564
|
-
debugger;
|
|
2565
2848
|
if (booking) {
|
|
2566
2849
|
const productRecord = product;
|
|
2567
2850
|
const splitCount = (0, import_utils3.getSafeProductNum)(
|
|
@@ -2584,6 +2867,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2584
2867
|
}
|
|
2585
2868
|
await this.appendProductLineToTempOrder(tempOrder, product, booking);
|
|
2586
2869
|
await this.finalizeProductOrderMutation(tempOrder);
|
|
2870
|
+
this.logInfo("addProductToOrder success", {
|
|
2871
|
+
product_id: product.product_id,
|
|
2872
|
+
with_booking: !!booking
|
|
2873
|
+
});
|
|
2587
2874
|
return tempOrder.products;
|
|
2588
2875
|
}
|
|
2589
2876
|
/**
|
|
@@ -2625,6 +2912,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2625
2912
|
await this.appendProductLineToTempOrder(tempOrder, product, booking);
|
|
2626
2913
|
}
|
|
2627
2914
|
await this.finalizeProductOrderMutation(tempOrder, options);
|
|
2915
|
+
this.logInfo("addProductsToOrder success", {
|
|
2916
|
+
itemsCount: items.length
|
|
2917
|
+
});
|
|
2628
2918
|
return tempOrder.products;
|
|
2629
2919
|
}
|
|
2630
2920
|
hasGoodPassDiscount(product) {
|
|
@@ -2847,6 +3137,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2847
3137
|
this.sanitizeTempOrderProducts(tempOrder);
|
|
2848
3138
|
await this.recalculateSummary({ createIfMissing: true });
|
|
2849
3139
|
this.persistTempOrder();
|
|
3140
|
+
this.logInfo("updateOrderProduct success", {
|
|
3141
|
+
params
|
|
3142
|
+
});
|
|
2850
3143
|
return tempOrder.products;
|
|
2851
3144
|
}
|
|
2852
3145
|
async updateOrderProducts(paramsList) {
|
|
@@ -2858,6 +3151,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2858
3151
|
this.applyOrderProductUpdateToTempOrder(tempOrder, params);
|
|
2859
3152
|
});
|
|
2860
3153
|
await this.finalizeAfterProductsMutation(tempOrder);
|
|
3154
|
+
this.logInfo("updateOrderProduct success", {
|
|
3155
|
+
paramsList
|
|
3156
|
+
});
|
|
2861
3157
|
return tempOrder.products;
|
|
2862
3158
|
}
|
|
2863
3159
|
async updateOrderProductQuantity(params) {
|
|
@@ -2922,6 +3218,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2922
3218
|
this.sanitizeTempOrderProducts(tempOrder);
|
|
2923
3219
|
await this.recalculateSummary({ createIfMissing: true });
|
|
2924
3220
|
this.persistTempOrder();
|
|
3221
|
+
this.logInfo("updateOrderProductQuantity success", {
|
|
3222
|
+
params
|
|
3223
|
+
});
|
|
2925
3224
|
return tempOrder.products;
|
|
2926
3225
|
}
|
|
2927
3226
|
updateOrderBooking(params) {
|
|
@@ -3023,6 +3322,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3023
3322
|
});
|
|
3024
3323
|
}
|
|
3025
3324
|
await this.finalizeAfterProductsMutation(tempOrder);
|
|
3325
|
+
this.logInfo("removeProductsFromOrder success", {
|
|
3326
|
+
identities
|
|
3327
|
+
});
|
|
3026
3328
|
return tempOrder.products;
|
|
3027
3329
|
}
|
|
3028
3330
|
async removeProductFromOrder(identity) {
|
|
@@ -3048,6 +3350,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3048
3350
|
this.sanitizeTempOrderProducts(tempOrder);
|
|
3049
3351
|
await this.recalculateSummary({ createIfMissing: true });
|
|
3050
3352
|
this.persistTempOrder();
|
|
3353
|
+
this.logInfo("clearOrderCartLines success", {});
|
|
3051
3354
|
return tempOrder;
|
|
3052
3355
|
}
|
|
3053
3356
|
// ─── TempOrder: 提交 ───
|
|
@@ -3108,37 +3411,55 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3108
3411
|
async runSubmitTempOrder(params) {
|
|
3109
3412
|
var _a, _b, _c, _d, _e;
|
|
3110
3413
|
const tempOrder = this.ensureTempOrder();
|
|
3414
|
+
const shouldConfirmPendingVoucherPayments = (params == null ? void 0 : params.confirmPendingVoucherPayments) !== false;
|
|
3415
|
+
const hasPaymentOverride = (params == null ? void 0 : params.payments) !== void 0;
|
|
3416
|
+
const preparedPaymentOverride = hasPaymentOverride ? this.prepareVoucherPaymentsForSubmit(
|
|
3417
|
+
(params == null ? void 0 : params.payments) || [],
|
|
3418
|
+
shouldConfirmPendingVoucherPayments
|
|
3419
|
+
) : void 0;
|
|
3420
|
+
if (!hasPaymentOverride) {
|
|
3421
|
+
if (shouldConfirmPendingVoucherPayments) {
|
|
3422
|
+
this.confirmPendingVoucherPayments({
|
|
3423
|
+
persist: false,
|
|
3424
|
+
recalculateSummary: false
|
|
3425
|
+
});
|
|
3426
|
+
} else {
|
|
3427
|
+
this.discardPendingVoucherPayments({
|
|
3428
|
+
persist: false,
|
|
3429
|
+
recalculateSummary: false
|
|
3430
|
+
});
|
|
3431
|
+
}
|
|
3432
|
+
}
|
|
3111
3433
|
this.persistTempOrder();
|
|
3112
3434
|
const latestSummary = await this.recalculateSummary({ createIfMissing: true }) || this.store.summary || (0, import_utils.createEmptySummary)();
|
|
3113
3435
|
const effectiveCacheId = (params == null ? void 0 : params.cacheId) ?? this.cacheId;
|
|
3114
|
-
const hasPaymentOverride = (params == null ? void 0 : params.payments) !== void 0;
|
|
3115
3436
|
const hasPaymentStatusOverride = (params == null ? void 0 : params.paymentStatus) !== void 0;
|
|
3116
3437
|
const hasSmallTicketDataFlagOverride = (params == null ? void 0 : params.smallTicketDataFlag) !== void 0;
|
|
3117
3438
|
const enhancePayload = hasPaymentOverride || hasPaymentStatusOverride || hasSmallTicketDataFlagOverride || (params == null ? void 0 : params.enhancePayload) ? (payload2, ctx) => {
|
|
3118
3439
|
const nextPayload = {
|
|
3119
3440
|
...payload2,
|
|
3120
3441
|
...hasPaymentOverride ? {
|
|
3121
|
-
payments:
|
|
3122
|
-
(params == null ? void 0 : params.payments) || []
|
|
3123
|
-
)
|
|
3442
|
+
payments: preparedPaymentOverride || []
|
|
3124
3443
|
} : {},
|
|
3125
|
-
...hasPaymentStatusOverride ? { payment_status: params == null ? void 0 : params.paymentStatus } : {},
|
|
3444
|
+
...hasPaymentStatusOverride && !shouldConfirmPendingVoucherPayments ? { payment_status: params == null ? void 0 : params.paymentStatus } : {},
|
|
3126
3445
|
...hasSmallTicketDataFlagOverride ? { small_ticket_data_flag: params == null ? void 0 : params.smallTicketDataFlag } : {}
|
|
3127
3446
|
};
|
|
3128
3447
|
const enhancedPayload = (params == null ? void 0 : params.enhancePayload) ? params.enhancePayload(nextPayload, ctx) : nextPayload;
|
|
3129
3448
|
return enhancedPayload;
|
|
3130
3449
|
} : void 0;
|
|
3450
|
+
const submitSnapshot = this.getLastOrderSubmitSnapshot();
|
|
3131
3451
|
const payload = (0, import_utils.buildSubmitPayload)({
|
|
3132
3452
|
tempOrder,
|
|
3133
3453
|
cacheId: effectiveCacheId,
|
|
3134
3454
|
platform: (params == null ? void 0 : params.platform) || ((_a = this.otherParams) == null ? void 0 : _a.platform),
|
|
3135
|
-
businessCode: (params == null ? void 0 : params.businessCode) ?? ((_b = this.otherParams) == null ? void 0 : _b.businessCode) ?? ((_c = this.otherParams) == null ? void 0 : _c.business_code),
|
|
3455
|
+
businessCode: submitSnapshot.businessCode ?? (params == null ? void 0 : params.businessCode) ?? ((_b = this.otherParams) == null ? void 0 : _b.businessCode) ?? ((_c = this.otherParams) == null ? void 0 : _c.business_code),
|
|
3136
3456
|
channel: params == null ? void 0 : params.channel,
|
|
3137
|
-
type: params == null ? void 0 : params.type,
|
|
3457
|
+
type: submitSnapshot.type ?? (params == null ? void 0 : params.type),
|
|
3138
3458
|
summary: latestSummary,
|
|
3139
3459
|
request_unique_idempotency_token: params == null ? void 0 : params.request_unique_idempotency_token,
|
|
3140
3460
|
enhance: enhancePayload
|
|
3141
3461
|
});
|
|
3462
|
+
console.log("[Order.runSubmitTempOrder.payload]", payload);
|
|
3142
3463
|
if (params == null ? void 0 : params.syncMode) {
|
|
3143
3464
|
payload.sync_mode = true;
|
|
3144
3465
|
}
|
|
@@ -3186,7 +3507,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3186
3507
|
this.logInfo("runSubmitTempOrder: 提交成功", {
|
|
3187
3508
|
submittedOrderId,
|
|
3188
3509
|
result,
|
|
3189
|
-
tempOrder
|
|
3510
|
+
tempOrder: {
|
|
3511
|
+
...tempOrder,
|
|
3512
|
+
_extend: void 0
|
|
3513
|
+
}
|
|
3190
3514
|
});
|
|
3191
3515
|
if (submittedOrderId !== null && submittedOrderId !== void 0) {
|
|
3192
3516
|
tempOrder.order_id = submittedOrderId;
|
|
@@ -3272,31 +3596,33 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3272
3596
|
const mappedPayments = (0, import_utils.mapPaymentItemsToOrderPayments)(
|
|
3273
3597
|
params.payments || []
|
|
3274
3598
|
);
|
|
3275
|
-
const
|
|
3276
|
-
const
|
|
3277
|
-
const
|
|
3278
|
-
const
|
|
3279
|
-
|
|
3599
|
+
const shouldConfirmPendingVoucherPayments = params.confirmPendingVoucherPayments ?? params.submitWhenPaid === true;
|
|
3600
|
+
const effectivePayments = shouldConfirmPendingVoucherPayments ? this.confirmPendingVoucherPaymentsInList(mappedPayments) : params.confirmPendingVoucherPayments === false ? this.discardPendingVoucherPaymentsFromList(mappedPayments) : mappedPayments;
|
|
3601
|
+
const completion = this.getPaymentCompletion(effectivePayments);
|
|
3602
|
+
const paidPaymentTotal = this.calculatePaymentTotal(effectivePayments);
|
|
3603
|
+
const paymentStatus = completion.isOrderFullyPaid ? params.paymentStatus || "paid" : paidPaymentTotal.gt(0) ? "partially_paid" : "payment_processing";
|
|
3604
|
+
tempOrder.payments = effectivePayments;
|
|
3280
3605
|
tempOrder.payment_status = paymentStatus;
|
|
3281
3606
|
this.persistTempOrder();
|
|
3282
3607
|
await this.saveDraft();
|
|
3283
3608
|
if (!params.submitWhenPaid) {
|
|
3284
|
-
return
|
|
3609
|
+
return completion;
|
|
3285
3610
|
}
|
|
3286
3611
|
if (this.store.syncState === "submitting") {
|
|
3287
|
-
return
|
|
3612
|
+
return completion;
|
|
3288
3613
|
}
|
|
3289
3614
|
this.store.syncState = "submitting";
|
|
3290
3615
|
const paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(
|
|
3291
3616
|
tempOrder,
|
|
3292
|
-
|
|
3617
|
+
effectivePayments
|
|
3293
3618
|
);
|
|
3294
3619
|
const submitResult = await this.submitTempOrder({
|
|
3295
|
-
payments:
|
|
3620
|
+
payments: effectivePayments,
|
|
3296
3621
|
paymentStatus,
|
|
3297
3622
|
smallTicketDataFlag: params.smallTicketDataFlag,
|
|
3298
3623
|
businessCode: params.businessCode,
|
|
3299
3624
|
channel: params.channel,
|
|
3625
|
+
confirmPendingVoucherPayments: true,
|
|
3300
3626
|
enhancePayload: (payload) => {
|
|
3301
3627
|
const nextPayload = {
|
|
3302
3628
|
...payload,
|
|
@@ -3305,7 +3631,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3305
3631
|
return nextPayload;
|
|
3306
3632
|
}
|
|
3307
3633
|
});
|
|
3308
|
-
return {
|
|
3634
|
+
return { ...completion, submitResult };
|
|
3309
3635
|
}
|
|
3310
3636
|
createOrder(params) {
|
|
3311
3637
|
var _a;
|
|
@@ -3631,6 +3957,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3631
3957
|
products: (0, import_lodash_es.cloneDeep)(nextTempOrder.products || []),
|
|
3632
3958
|
payments: (0, import_lodash_es.cloneDeep)(nextTempOrder.payments || []),
|
|
3633
3959
|
surcharges: (0, import_lodash_es.cloneDeep)(nextTempOrder.surcharges || []),
|
|
3960
|
+
shop_discount: nextTempOrder.shop_discount || "0.00",
|
|
3634
3961
|
productFingerprint: this.buildOrderProductsFingerprint(nextTempOrder.products || [])
|
|
3635
3962
|
}
|
|
3636
3963
|
};
|
|
@@ -3639,6 +3966,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3639
3966
|
const currentDiscounts = typeof ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList) === "function" ? this.store.discount.getDiscountList() || [] : [];
|
|
3640
3967
|
const shouldSkipEmptyDiscountSync = hydratedEditDiscounts.length === 0 && currentDiscounts.length === 0;
|
|
3641
3968
|
if (!shouldSkipEmptyDiscountSync) {
|
|
3969
|
+
OrderModule.populateSavedAmounts(
|
|
3970
|
+
nextTempOrder.products,
|
|
3971
|
+
hydratedEditDiscounts
|
|
3972
|
+
);
|
|
3642
3973
|
await ((_b = this.store.discount) == null ? void 0 : _b.setOriginalDiscountList(hydratedEditDiscounts));
|
|
3643
3974
|
await ((_c = this.store.discount) == null ? void 0 : _c.setDiscountList(hydratedEditDiscounts));
|
|
3644
3975
|
}
|
|
@@ -3792,6 +4123,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3792
4123
|
product.booking_uid = linkedBookingUid;
|
|
3793
4124
|
product.metadata.booking_uid = linkedBookingUid;
|
|
3794
4125
|
});
|
|
4126
|
+
this.syncLinkedBookingHoldersToProducts(tempOrder);
|
|
3795
4127
|
}
|
|
3796
4128
|
pickHydratedDisplayText(value) {
|
|
3797
4129
|
if (value === void 0 || value === null)
|
|
@@ -3843,7 +4175,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3843
4175
|
return normalized;
|
|
3844
4176
|
}
|
|
3845
4177
|
normalizeHydratedOrderProduct(product) {
|
|
3846
|
-
|
|
4178
|
+
let row = { ...product || {} };
|
|
3847
4179
|
if (row.num === void 0 && row.product_quantity !== void 0) {
|
|
3848
4180
|
row.num = row.product_quantity;
|
|
3849
4181
|
}
|
|
@@ -3864,6 +4196,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3864
4196
|
if (row.booking_uid && !row.metadata.booking_uid) {
|
|
3865
4197
|
row.metadata.booking_uid = row.booking_uid;
|
|
3866
4198
|
}
|
|
4199
|
+
row = (0, import_bundleDiscountHydration.restoreHydratedBundleDiscounts)(row, import_utils.normalizeOrderProductDiscountList);
|
|
3867
4200
|
const existingIdentity = row.metadata.unique_identification_number || row.unique_identification_number;
|
|
3868
4201
|
if (!existingIdentity) {
|
|
3869
4202
|
row.metadata.unique_identification_number = (0, import_utils.createUuidV4)();
|
|
@@ -3883,7 +4216,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3883
4216
|
};
|
|
3884
4217
|
if (result.metadata)
|
|
3885
4218
|
delete result.metadata.price_schema_version;
|
|
3886
|
-
|
|
4219
|
+
const restored = (0, import_bundleDiscountHydration.restoreHydratedBundleDiscounts)(result, import_utils.normalizeOrderProductDiscountList);
|
|
4220
|
+
return this.sanitizeOrderProductForTempOrder(restored);
|
|
3887
4221
|
}
|
|
3888
4222
|
getLastOrderInfo() {
|
|
3889
4223
|
var _a;
|
|
@@ -3897,6 +4231,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3897
4231
|
});
|
|
3898
4232
|
return res;
|
|
3899
4233
|
}
|
|
4234
|
+
getVouchers() {
|
|
4235
|
+
var _a;
|
|
4236
|
+
return ((_a = this.store.tempOrder) == null ? void 0 : _a.vouchers) || [];
|
|
4237
|
+
}
|
|
3900
4238
|
};
|
|
3901
4239
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3902
4240
|
0 && (module.exports = {
|