@pisell/pisellos 2.2.178 → 2.2.180
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/Customer/index.d.ts +0 -6
- package/dist/modules/Customer/index.js +83 -129
- package/dist/modules/Customer/types.d.ts +0 -2
- package/dist/modules/Discount/index.d.ts +4 -2
- package/dist/modules/Discount/index.js +93 -8
- package/dist/modules/Discount/types.d.ts +7 -1
- package/dist/modules/Order/index.d.ts +17 -87
- package/dist/modules/Order/index.js +501 -1357
- package/dist/modules/Order/types.d.ts +19 -198
- package/dist/modules/Order/types.js +0 -31
- package/dist/modules/Order/utils.d.ts +1 -50
- package/dist/modules/Order/utils.js +32 -261
- package/dist/modules/Quotation/index.d.ts +1 -0
- package/dist/modules/Quotation/index.js +21 -23
- package/dist/modules/Rules/index.d.ts +0 -4
- package/dist/modules/Rules/index.js +10 -26
- package/dist/modules/SalesSummary/index.js +2 -4
- package/dist/modules/SalesSummary/utils.js +7 -21
- package/dist/modules/Schedule/index.js +2 -6
- package/dist/modules/index.d.ts +0 -1
- package/dist/modules/index.js +1 -2
- package/dist/server/index.js +29 -87
- package/dist/server/modules/order/index.d.ts +0 -23
- package/dist/server/modules/order/index.js +46 -123
- package/dist/server/modules/order/types.d.ts +2 -0
- package/dist/server/modules/order/utils/filterOrders.js +6 -20
- package/dist/server/modules/products/index.d.ts +1 -1
- package/dist/server/modules/products/index.js +113 -130
- package/dist/server/modules/schedule/index.js +6 -13
- package/dist/solution/BaseSales/index.d.ts +7 -89
- package/dist/solution/BaseSales/index.js +375 -1494
- package/dist/solution/BaseSales/types.d.ts +1 -67
- package/dist/solution/BaseSales/types.js +1 -3
- package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +1 -0
- package/dist/solution/BaseSales/utils/parseSalesResponse.js +1 -1
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +16 -68
- package/dist/solution/BaseSales/utils.js +8 -46
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +1 -133
- package/dist/solution/BookingTicket/index.js +175 -780
- package/dist/solution/BookingTicket/types.d.ts +0 -2
- package/dist/solution/BookingTicket/types.js +0 -3
- package/dist/solution/BookingTicket/utils/cartView.js +2 -4
- package/dist/solution/ScanOrder/index.d.ts +3 -9
- package/dist/solution/ScanOrder/index.js +128 -231
- package/dist/solution/ScanOrder/utils.js +8 -46
- package/dist/solution/ShopDiscount/index.d.ts +1 -0
- package/dist/solution/ShopDiscount/index.js +23 -18
- package/dist/solution/VenueBooking/index.d.ts +9 -5
- package/dist/solution/VenueBooking/index.js +55 -103
- package/dist/solution/VenueBooking/utils/slotMerge.d.ts +0 -4
- package/dist/solution/VenueBooking/utils/slotMerge.js +0 -10
- package/lib/model/strategy/adapter/promotion/index.js +0 -49
- package/lib/modules/Customer/index.d.ts +0 -6
- package/lib/modules/Customer/index.js +11 -26
- package/lib/modules/Customer/types.d.ts +0 -2
- package/lib/modules/Discount/index.d.ts +4 -2
- package/lib/modules/Discount/index.js +63 -8
- package/lib/modules/Discount/types.d.ts +7 -1
- package/lib/modules/Order/index.d.ts +17 -87
- package/lib/modules/Order/index.js +150 -677
- package/lib/modules/Order/types.d.ts +19 -198
- package/lib/modules/Order/types.js +0 -1
- package/lib/modules/Order/utils.d.ts +1 -50
- package/lib/modules/Order/utils.js +22 -229
- package/lib/modules/Quotation/index.d.ts +1 -0
- package/lib/modules/Quotation/index.js +15 -18
- package/lib/modules/Rules/index.d.ts +0 -4
- package/lib/modules/Rules/index.js +14 -22
- package/lib/modules/SalesSummary/index.js +2 -4
- package/lib/modules/SalesSummary/utils.js +7 -21
- package/lib/modules/Schedule/index.js +1 -3
- package/lib/modules/index.d.ts +0 -1
- package/lib/modules/index.js +1 -3
- package/lib/server/index.js +4 -41
- package/lib/server/modules/order/index.d.ts +0 -23
- package/lib/server/modules/order/index.js +14 -46
- package/lib/server/modules/order/types.d.ts +2 -0
- package/lib/server/modules/order/utils/filterOrders.js +4 -12
- package/lib/server/modules/products/index.d.ts +1 -1
- package/lib/server/modules/products/index.js +20 -30
- package/lib/server/modules/schedule/index.js +1 -2
- package/lib/solution/BaseSales/index.d.ts +7 -89
- package/lib/solution/BaseSales/index.js +22 -736
- package/lib/solution/BaseSales/types.d.ts +1 -67
- package/lib/solution/BaseSales/types.js +1 -3
- package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +1 -0
- package/lib/solution/BaseSales/utils/parseSalesResponse.js +1 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +12 -71
- package/lib/solution/BaseSales/utils.js +6 -46
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +1 -133
- package/lib/solution/BookingTicket/index.js +8 -352
- package/lib/solution/BookingTicket/types.d.ts +0 -2
- package/lib/solution/BookingTicket/types.js +0 -6
- package/lib/solution/BookingTicket/utils/cartView.js +2 -4
- package/lib/solution/ScanOrder/index.d.ts +3 -9
- package/lib/solution/ScanOrder/index.js +66 -147
- package/lib/solution/ScanOrder/utils.js +6 -46
- package/lib/solution/ShopDiscount/index.d.ts +1 -0
- package/lib/solution/ShopDiscount/index.js +4 -2
- package/lib/solution/VenueBooking/index.d.ts +9 -5
- package/lib/solution/VenueBooking/index.js +14 -50
- package/lib/solution/VenueBooking/utils/slotMerge.d.ts +0 -4
- package/lib/solution/VenueBooking/utils/slotMerge.js +0 -10
- package/package.json +2 -2
- package/dist/modules/BookingContext/index.d.ts +0 -37
- package/dist/modules/BookingContext/index.js +0 -436
- package/dist/modules/BookingContext/types.d.ts +0 -102
- package/dist/modules/BookingContext/types.js +0 -51
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +0 -16
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +0 -193
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +0 -8
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +0 -137
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +0 -75
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +0 -215
- package/dist/modules/BookingContext/utils/flexible.d.ts +0 -28
- package/dist/modules/BookingContext/utils/flexible.js +0 -56
- package/dist/modules/BookingContext/utils/formatResourceList.d.ts +0 -8
- package/dist/modules/BookingContext/utils/formatResourceList.js +0 -38
- package/dist/modules/BookingContext/utils/index.d.ts +0 -11
- package/dist/modules/BookingContext/utils/index.js +0 -11
- package/dist/modules/BookingContext/utils/noResource.d.ts +0 -13
- package/dist/modules/BookingContext/utils/noResource.js +0 -77
- package/dist/modules/BookingContext/utils/productExtend.d.ts +0 -72
- package/dist/modules/BookingContext/utils/productExtend.js +0 -339
- package/dist/modules/BookingContext/utils/resourceErrors.d.ts +0 -41
- package/dist/modules/BookingContext/utils/resourceErrors.js +0 -74
- package/dist/modules/BookingContext/utils/resourceSelection.d.ts +0 -7
- package/dist/modules/BookingContext/utils/resourceSelection.js +0 -24
- package/dist/modules/BookingContext/utils/resources.d.ts +0 -80
- package/dist/modules/BookingContext/utils/resources.js +0 -486
- package/dist/modules/BookingContext/utils/serviceTimes.d.ts +0 -55
- package/dist/modules/BookingContext/utils/serviceTimes.js +0 -151
- package/dist/modules/BookingContext/utils/timeSlices.d.ts +0 -42
- package/dist/modules/BookingContext/utils/timeSlices.js +0 -100
- package/dist/modules/Order/utils/manualProductDiscount.d.ts +0 -106
- package/dist/modules/Order/utils/manualProductDiscount.js +0 -212
- package/dist/solution/BaseSales/utils/cartPromotion.d.ts +0 -275
- package/dist/solution/BaseSales/utils/cartPromotion.js +0 -1258
- package/dist/solution/BaseSales/utils/quotationPrice.d.ts +0 -7
- package/dist/solution/BaseSales/utils/quotationPrice.js +0 -237
- package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +0 -113
- package/dist/solution/BookingTicket/utils/addProductDecision.js +0 -346
- package/lib/modules/BookingContext/index.d.ts +0 -37
- package/lib/modules/BookingContext/index.js +0 -297
- package/lib/modules/BookingContext/types.d.ts +0 -102
- package/lib/modules/BookingContext/types.js +0 -34
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +0 -16
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +0 -207
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +0 -8
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +0 -141
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +0 -75
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +0 -198
- package/lib/modules/BookingContext/utils/flexible.d.ts +0 -28
- package/lib/modules/BookingContext/utils/flexible.js +0 -80
- package/lib/modules/BookingContext/utils/formatResourceList.d.ts +0 -8
- package/lib/modules/BookingContext/utils/formatResourceList.js +0 -50
- package/lib/modules/BookingContext/utils/index.d.ts +0 -11
- package/lib/modules/BookingContext/utils/index.js +0 -43
- package/lib/modules/BookingContext/utils/noResource.d.ts +0 -13
- package/lib/modules/BookingContext/utils/noResource.js +0 -90
- package/lib/modules/BookingContext/utils/productExtend.d.ts +0 -72
- package/lib/modules/BookingContext/utils/productExtend.js +0 -283
- package/lib/modules/BookingContext/utils/resourceErrors.d.ts +0 -41
- package/lib/modules/BookingContext/utils/resourceErrors.js +0 -80
- package/lib/modules/BookingContext/utils/resourceSelection.d.ts +0 -7
- package/lib/modules/BookingContext/utils/resourceSelection.js +0 -46
- package/lib/modules/BookingContext/utils/resources.d.ts +0 -80
- package/lib/modules/BookingContext/utils/resources.js +0 -377
- package/lib/modules/BookingContext/utils/serviceTimes.d.ts +0 -55
- package/lib/modules/BookingContext/utils/serviceTimes.js +0 -162
- package/lib/modules/BookingContext/utils/timeSlices.d.ts +0 -42
- package/lib/modules/BookingContext/utils/timeSlices.js +0 -124
- package/lib/modules/Order/utils/manualProductDiscount.d.ts +0 -106
- package/lib/modules/Order/utils/manualProductDiscount.js +0 -207
- package/lib/solution/BaseSales/utils/cartPromotion.d.ts +0 -275
- package/lib/solution/BaseSales/utils/cartPromotion.js +0 -836
- package/lib/solution/BaseSales/utils/quotationPrice.d.ts +0 -7
- package/lib/solution/BaseSales/utils/quotationPrice.js +0 -277
- package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +0 -113
- package/lib/solution/BookingTicket/utils/addProductDecision.js +0 -318
|
@@ -37,9 +37,7 @@ var import_types = require("./types");
|
|
|
37
37
|
var import_utils = require("./utils");
|
|
38
38
|
var import_utils2 = require("../Product/utils");
|
|
39
39
|
var import_dayjs = __toESM(require("dayjs"));
|
|
40
|
-
var import_cartPromotion = require("../../solution/BaseSales/utils/cartPromotion");
|
|
41
40
|
var import_utils3 = require("../../solution/ScanOrder/utils");
|
|
42
|
-
var import_manualProductDiscount = require("./utils/manualProductDiscount");
|
|
43
41
|
var import_Discount = require("../Discount");
|
|
44
42
|
var import_Rules = require("../Rules");
|
|
45
43
|
var import_types2 = require("../Rules/types");
|
|
@@ -51,17 +49,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
51
49
|
super(name || "order", version);
|
|
52
50
|
this.defaultName = "order";
|
|
53
51
|
this.defaultVersion = "1.0.0";
|
|
54
|
-
// ─── 促销/赠品 ────────────────────────────────────
|
|
55
|
-
/** 评估器引用;由 SalesSdkProvider 注入,未注入时 applyPromotion 静默跳过 */
|
|
56
|
-
this.promotionEvaluator = null;
|
|
57
|
-
/** 赠品选择 resolver;由 SDK host bridge 注入 */
|
|
58
|
-
this.giftSelectResolver = null;
|
|
59
|
-
/** applyPromotion 递归保护 flag(写路径同步调 applyPromotion,禁止重入) */
|
|
60
|
-
this.isApplyingPromotion = false;
|
|
61
|
-
/** 最近一次 applyPromotion 的未满足促销提示 */
|
|
62
|
-
this.lastUnfulfilledPromotions = [];
|
|
63
|
-
/** 最近一次 applyPromotion 的赠品操作 diff(debug / SDK 读取使用) */
|
|
64
|
-
this.lastGiftActions = null;
|
|
65
52
|
}
|
|
66
53
|
/**
|
|
67
54
|
* Populate `savedAmount` on each discount based on product-level discount details.
|
|
@@ -88,27 +75,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
88
75
|
d.savedAmount = d.isSelected && key != null && savedMap.has(key) ? savedMap.get(key).toNumber() : 0;
|
|
89
76
|
}
|
|
90
77
|
}
|
|
91
|
-
applyProductDiscountPrices(products) {
|
|
92
|
-
return (products || []).map((product) => {
|
|
93
|
-
var _a, _b, _c;
|
|
94
|
-
if ((_a = product.metadata) == null ? void 0 : _a.is_manual_discount)
|
|
95
|
-
return product;
|
|
96
|
-
const totalPerUnitDiscount = (0, import_utils.resolveEffectivePerUnitDiscount)(product);
|
|
97
|
-
const optionSum = (0, import_utils.sumOptionUnitPrice)(product.product_option_item);
|
|
98
|
-
const sourcePrice = ((_b = product.metadata) == null ? void 0 : _b.source_product_price) ?? (((_c = product.metadata) == null ? void 0 : _c.main_product_original_price) != null ? new import_decimal.default(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : product.original_price ?? "0");
|
|
99
|
-
const newSourceSellingPrice = new import_decimal.default(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
|
|
100
|
-
const newMainSellingPrice = new import_decimal.default(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
|
|
101
|
-
if (product.metadata) {
|
|
102
|
-
product.metadata.main_product_selling_price = newMainSellingPrice;
|
|
103
|
-
product.metadata.price_schema_version = 2;
|
|
104
|
-
}
|
|
105
|
-
product.selling_price = (0, import_utils.composeLinePrice)({
|
|
106
|
-
mainPrice: newMainSellingPrice,
|
|
107
|
-
bundle: product.product_bundle
|
|
108
|
-
});
|
|
109
|
-
return product;
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
78
|
async initialize(core, options) {
|
|
113
79
|
var _a, _b, _c;
|
|
114
80
|
this.core = core;
|
|
@@ -135,6 +101,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
135
101
|
this.orderHooks = options.hooks || ((_b = otherParams.order) == null ? void 0 : _b.hooks) || ((_c = otherParams.hooks) == null ? void 0 : _c.order);
|
|
136
102
|
this.otherParams = otherParams;
|
|
137
103
|
this.registerDiscountModules(options);
|
|
104
|
+
this.restoreTempOrderFromStorage();
|
|
138
105
|
this.logInfo("OrderModule initialized successfully");
|
|
139
106
|
}
|
|
140
107
|
/**
|
|
@@ -207,25 +174,21 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
207
174
|
}
|
|
208
175
|
// ─── Discount: 公共 API ───
|
|
209
176
|
async loadDiscountConfig(params) {
|
|
210
|
-
var _a, _b, _c, _d
|
|
211
|
-
const
|
|
212
|
-
const discountList = await ((_b = this.store.discount) == null ? void 0 : _b.loadPrepareConfig({
|
|
177
|
+
var _a, _b, _c, _d;
|
|
178
|
+
const discountList = await ((_a = this.store.discount) == null ? void 0 : _a.loadPrepareConfig({
|
|
213
179
|
customer_id: params.customerId,
|
|
214
|
-
action: params.action ||
|
|
180
|
+
action: params.action || "create",
|
|
215
181
|
with_good_pass: 1,
|
|
216
182
|
with_discount_card: 1,
|
|
217
183
|
with_wallet_pass_holder: 1,
|
|
218
|
-
request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
219
|
-
...orderId ? { order_id: orderId } : {}
|
|
184
|
+
request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
220
185
|
}));
|
|
221
186
|
if (discountList) {
|
|
222
|
-
|
|
223
|
-
await ((_d = this.store.discount) == null ? void 0 : _d.setDiscountList(discountList));
|
|
187
|
+
(_b = this.store.discount) == null ? void 0 : _b.setDiscountList(discountList);
|
|
224
188
|
}
|
|
225
|
-
if (
|
|
189
|
+
if ((_d = (_c = this.store.tempOrder) == null ? void 0 : _c.products) == null ? void 0 : _d.length) {
|
|
226
190
|
this.applyDiscount();
|
|
227
191
|
}
|
|
228
|
-
return this.getDiscountList();
|
|
229
192
|
}
|
|
230
193
|
getDiscountList() {
|
|
231
194
|
var _a;
|
|
@@ -233,14 +196,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
233
196
|
}
|
|
234
197
|
async scanCode(code, customerId) {
|
|
235
198
|
var _a, _b, _c, _d, _e;
|
|
236
|
-
const
|
|
199
|
+
const resultDiscountWithReason = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, { customerId })) || { discountList: [], unavailableReasonKey: null };
|
|
200
|
+
const { discountList: resultDiscountList, unavailableReasonKey } = resultDiscountWithReason;
|
|
237
201
|
const rulesModule = this.store.rules;
|
|
238
202
|
if (!rulesModule) {
|
|
239
203
|
return {
|
|
240
204
|
type: "clientCalc",
|
|
241
205
|
isAvailable: false,
|
|
242
206
|
discountList: this.getDiscountList(),
|
|
243
|
-
scannedDiscountList: resultDiscountList,
|
|
244
207
|
unavailableReason: import_types2.UnavailableReason.Unknown
|
|
245
208
|
};
|
|
246
209
|
}
|
|
@@ -249,7 +212,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
249
212
|
type: "server",
|
|
250
213
|
isAvailable: false,
|
|
251
214
|
discountList: this.getDiscountList(),
|
|
252
|
-
|
|
215
|
+
unavailableReasonKey
|
|
253
216
|
};
|
|
254
217
|
}
|
|
255
218
|
const withScanList = resultDiscountList.map((item) => ({
|
|
@@ -261,8 +224,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
261
224
|
return {
|
|
262
225
|
type: "clientCalc",
|
|
263
226
|
isAvailable: true,
|
|
264
|
-
discountList: this.getDiscountList()
|
|
265
|
-
scannedDiscountList: resultDiscountList
|
|
227
|
+
discountList: this.getDiscountList()
|
|
266
228
|
};
|
|
267
229
|
}
|
|
268
230
|
const tempOrder = this.store.tempOrder;
|
|
@@ -283,7 +245,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
283
245
|
type: "clientCalc",
|
|
284
246
|
isAvailable: isAvailable || false,
|
|
285
247
|
discountList: newDiscountList || this.getDiscountList(),
|
|
286
|
-
scannedDiscountList: resultDiscountList,
|
|
287
248
|
unavailableReason
|
|
288
249
|
};
|
|
289
250
|
}
|
|
@@ -292,7 +253,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
292
253
|
const tempOrder = this.store.tempOrder;
|
|
293
254
|
if (!tempOrder)
|
|
294
255
|
return;
|
|
295
|
-
delete tempOrder.discount_list;
|
|
296
256
|
const rulesModule = this.store.rules;
|
|
297
257
|
if (!rulesModule)
|
|
298
258
|
return;
|
|
@@ -306,17 +266,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
306
266
|
orderTotalAmount: Number(((_d = this.store.summary) == null ? void 0 : _d.total_amount) || 0)
|
|
307
267
|
});
|
|
308
268
|
if (result == null ? void 0 : result.productList) {
|
|
309
|
-
tempOrder.products =
|
|
310
|
-
(result.productList || []).map((product) => ({
|
|
311
|
-
...product,
|
|
312
|
-
discount_list: (0, import_utils.normalizeOrderProductDiscountList)(
|
|
313
|
-
(0, import_manualProductDiscount.syncManualProductDiscountProductNum)(
|
|
314
|
-
product.discount_list,
|
|
315
|
-
product.num
|
|
316
|
-
)
|
|
317
|
-
)
|
|
318
|
-
}))
|
|
319
|
-
);
|
|
269
|
+
tempOrder.products = result.productList;
|
|
320
270
|
}
|
|
321
271
|
if (result == null ? void 0 : result.discountList) {
|
|
322
272
|
OrderModule.populateSavedAmounts(
|
|
@@ -324,178 +274,80 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
324
274
|
result.discountList
|
|
325
275
|
);
|
|
326
276
|
(_e = this.store.discount) == null ? void 0 : _e.setDiscountList(result.discountList);
|
|
277
|
+
tempOrder.discount_list = result.discountList.filter(
|
|
278
|
+
(d) => d.isSelected
|
|
279
|
+
);
|
|
327
280
|
}
|
|
328
281
|
}
|
|
329
|
-
// ───
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
setPromotionEvaluator(evaluator) {
|
|
337
|
-
this.promotionEvaluator = evaluator || null;
|
|
338
|
-
}
|
|
339
|
-
/**
|
|
340
|
-
* 注入赠品选择 resolver。OS 需要补赠品时会 await 调用 resolver;缺省时跳过新增并 console.warn。
|
|
341
|
-
*
|
|
342
|
-
* @example
|
|
343
|
-
* order.setGiftSelectResolver(async (ctx) => {
|
|
344
|
-
* // SDK 内部决定弹窗 or 自动选第一项,返回完整 OrderProduct[]
|
|
345
|
-
* return giftSelectBridge.request(ctx);
|
|
346
|
-
* });
|
|
347
|
-
*/
|
|
348
|
-
setGiftSelectResolver(resolver) {
|
|
349
|
-
this.giftSelectResolver = resolver || null;
|
|
282
|
+
// ─── TempOrder: 初始化入口 ───
|
|
283
|
+
initTempOrder(params) {
|
|
284
|
+
if (params.cacheId !== void 0)
|
|
285
|
+
this.cacheId = params.cacheId;
|
|
286
|
+
if (params.salesSummaryModuleName !== void 0)
|
|
287
|
+
this.salesSummaryModuleName = params.salesSummaryModuleName;
|
|
288
|
+
this.restoreTempOrderFromStorage();
|
|
350
289
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
*/
|
|
357
|
-
appendPromotionTags(products) {
|
|
358
|
-
return (0, import_cartPromotion.appendPromotionTags)(products, this.promotionEvaluator);
|
|
290
|
+
// ─── TempOrder: localStorage 持久化 ───
|
|
291
|
+
getTempOrderStorageKey() {
|
|
292
|
+
if (!this.cacheId)
|
|
293
|
+
return null;
|
|
294
|
+
return `scanOrder:tempOrder:${this.cacheId}`;
|
|
359
295
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
*
|
|
365
|
-
* 关键约束:
|
|
366
|
-
* - 不调用任何公开 CRUD API(如 removeProductFromOrder),全部内部 mutate tempOrder.products,避免事件风暴;
|
|
367
|
-
* - 用 `isApplyingPromotion` 防递归;
|
|
368
|
-
* - 多选项赠品依赖 giftSelectResolver,未注入则跳过且 console.warn;
|
|
369
|
-
* - 不主动调用 applyDiscount / recalculateSummary,调用方负责跟进。
|
|
370
|
-
*/
|
|
371
|
-
async applyPromotion() {
|
|
372
|
-
if (this.isApplyingPromotion)
|
|
296
|
+
restoreTempOrderFromStorage() {
|
|
297
|
+
var _a, _b;
|
|
298
|
+
const key = this.getTempOrderStorageKey();
|
|
299
|
+
if (!key)
|
|
373
300
|
return;
|
|
374
|
-
if (!this.
|
|
301
|
+
if (!this.window)
|
|
375
302
|
return;
|
|
376
|
-
const
|
|
377
|
-
if (!
|
|
303
|
+
const cachedData = this.window.localStorage.getItem(key);
|
|
304
|
+
if (!cachedData)
|
|
378
305
|
return;
|
|
379
|
-
this.isApplyingPromotion = true;
|
|
380
306
|
try {
|
|
381
|
-
const
|
|
382
|
-
|
|
383
|
-
this.
|
|
384
|
-
|
|
385
|
-
if (result.giftActions.toRemove.length > 0) {
|
|
386
|
-
const removeSet = new Set(result.giftActions.toRemove.map(String));
|
|
387
|
-
result.products = result.products.filter((p) => {
|
|
388
|
-
const uid = (0, import_cartPromotion.getOrderProductUid)(p);
|
|
389
|
-
return uid ? !removeSet.has(String(uid)) : true;
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
for (const reduce of result.giftActions.toReduce) {
|
|
393
|
-
for (const item of reduce.items) {
|
|
394
|
-
const product = result.products.find(
|
|
395
|
-
(p) => (0, import_cartPromotion.getOrderProductUid)(p) === item.uid
|
|
396
|
-
);
|
|
397
|
-
if (product) {
|
|
398
|
-
product.num = item.newQuantity;
|
|
399
|
-
}
|
|
400
|
-
}
|
|
307
|
+
const parsedData = JSON.parse(cachedData);
|
|
308
|
+
if (!(0, import_utils.isTempOrder)(parsedData)) {
|
|
309
|
+
this.window.localStorage.removeItem(key);
|
|
310
|
+
return;
|
|
401
311
|
}
|
|
402
|
-
if (
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
} else {
|
|
410
|
-
console.warn(
|
|
411
|
-
"[OrderModule] giftSelectResolver not set, skip applying single-option gifts",
|
|
412
|
-
result.giftActions.toAdd
|
|
413
|
-
);
|
|
312
|
+
if (Array.isArray(parsedData.products)) {
|
|
313
|
+
for (let i = 0; i < parsedData.products.length; i++) {
|
|
314
|
+
const p = parsedData.products[i];
|
|
315
|
+
if (!p || typeof p !== "object")
|
|
316
|
+
continue;
|
|
317
|
+
if (!Array.isArray(p.product_option_item)) {
|
|
318
|
+
p.product_option_item = [];
|
|
414
319
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
if (addAction.giftOptions.length === 1) {
|
|
418
|
-
const sameStrategy = result.products.find(
|
|
419
|
-
(p) => {
|
|
420
|
-
var _a, _b;
|
|
421
|
-
return ((_b = (_a = p.metadata) == null ? void 0 : _a._giftInfo) == null ? void 0 : _b.strategyId) === addAction.strategyId;
|
|
422
|
-
}
|
|
423
|
-
);
|
|
424
|
-
if (sameStrategy) {
|
|
425
|
-
sameStrategy.num = (Number(sameStrategy.num) || 0) + (addAction.giftCount || 1);
|
|
426
|
-
continue;
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
try {
|
|
430
|
-
const giftProducts = await this.giftSelectResolver({
|
|
431
|
-
strategyId: addAction.strategyId,
|
|
432
|
-
strategyName: addAction.strategyName,
|
|
433
|
-
giftCount: addAction.giftCount,
|
|
434
|
-
giftOptions: addAction.giftOptions,
|
|
435
|
-
sourceProductIds: addAction.sourceProductIds
|
|
436
|
-
});
|
|
437
|
-
if (Array.isArray(giftProducts) && giftProducts.length > 0) {
|
|
438
|
-
for (const gp of giftProducts) {
|
|
439
|
-
if (!gp)
|
|
440
|
-
continue;
|
|
441
|
-
result.products.push(gp);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
} catch (error) {
|
|
445
|
-
console.warn(
|
|
446
|
-
"[OrderModule] giftSelectResolver rejected, skip add gift",
|
|
447
|
-
addAction.strategyId,
|
|
448
|
-
error
|
|
449
|
-
);
|
|
450
|
-
}
|
|
320
|
+
if (!Array.isArray(p.product_bundle)) {
|
|
321
|
+
p.product_bundle = [];
|
|
451
322
|
}
|
|
323
|
+
const row = p;
|
|
324
|
+
parsedData.products[i] = (0, import_utils3.normalizeOrderProduct)(row);
|
|
452
325
|
}
|
|
453
326
|
}
|
|
454
|
-
|
|
455
|
-
this.
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
this.
|
|
469
|
-
} catch (error) {
|
|
470
|
-
console.error("[OrderModule] applyPromotion failed", error);
|
|
471
|
-
} finally {
|
|
472
|
-
this.isApplyingPromotion = false;
|
|
327
|
+
const parsedRecord = parsedData;
|
|
328
|
+
this.store.summary = parsedRecord.summary || (0, import_utils.createEmptySummary)();
|
|
329
|
+
delete parsedData.summary;
|
|
330
|
+
if (parsedRecord.lastOrderInfo) {
|
|
331
|
+
this.store.lastOrderInfo = parsedRecord.lastOrderInfo;
|
|
332
|
+
delete parsedData.lastOrderInfo;
|
|
333
|
+
}
|
|
334
|
+
if (!parsedData._extend || typeof parsedData._extend !== "object") {
|
|
335
|
+
parsedData._extend = { productsByUid: {} };
|
|
336
|
+
} else if (!parsedData._extend.productsByUid) {
|
|
337
|
+
parsedData._extend.productsByUid = {};
|
|
338
|
+
}
|
|
339
|
+
this.store.tempOrder = parsedData;
|
|
340
|
+
} catch {
|
|
341
|
+
(_b = (_a = this.window) == null ? void 0 : _a.localStorage) == null ? void 0 : _b.removeItem(key);
|
|
473
342
|
}
|
|
474
343
|
}
|
|
475
|
-
/** 最近一次 applyPromotion 输出的未满足促销列表 */
|
|
476
|
-
getUnfulfilledPromotions() {
|
|
477
|
-
return this.lastUnfulfilledPromotions;
|
|
478
|
-
}
|
|
479
|
-
/** 最近一次 applyPromotion 输出的赠品操作 diff */
|
|
480
|
-
getLastGiftActions() {
|
|
481
|
-
return this.lastGiftActions;
|
|
482
|
-
}
|
|
483
|
-
// ─── TempOrder: 初始化入口 ───
|
|
484
|
-
initTempOrder(params) {
|
|
485
|
-
if (params.cacheId !== void 0)
|
|
486
|
-
this.cacheId = params.cacheId;
|
|
487
|
-
if (params.salesSummaryModuleName !== void 0)
|
|
488
|
-
this.salesSummaryModuleName = params.salesSummaryModuleName;
|
|
489
|
-
}
|
|
490
|
-
/** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化。 */
|
|
491
|
-
setEnableTempOrderPersist(_enabled) {
|
|
492
|
-
}
|
|
493
|
-
/** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化。 */
|
|
494
|
-
isTempOrderPersistEnabled() {
|
|
495
|
-
return false;
|
|
496
|
-
}
|
|
497
|
-
/** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化;草稿保存请使用 IndexedDB saveDraft。 */
|
|
498
344
|
persistTempOrder() {
|
|
345
|
+
const key = this.getTempOrderStorageKey();
|
|
346
|
+
if (!key || !this.store.tempOrder)
|
|
347
|
+
return;
|
|
348
|
+
if (!this.window)
|
|
349
|
+
return;
|
|
350
|
+
this.window.localStorage.setItem(key, JSON.stringify(this.store.tempOrder));
|
|
499
351
|
}
|
|
500
352
|
// ─── TempOrder: 创建 & 获取 ───
|
|
501
353
|
createDefaultTempOrderInstance() {
|
|
@@ -539,14 +391,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
539
391
|
}
|
|
540
392
|
return tempOrder.request_unique_idempotency_token;
|
|
541
393
|
}
|
|
542
|
-
buildPaymentSyncIdempotencyToken(tempOrder, payments) {
|
|
543
|
-
const baseToken = this.ensureRequestUniqueIdempotencyToken(tempOrder);
|
|
544
|
-
const paidPaymentsCount = (payments || []).filter((payment) => {
|
|
545
|
-
return String((payment == null ? void 0 : payment.status) || "").toLowerCase() === "paid";
|
|
546
|
-
}).length;
|
|
547
|
-
const paidCount = paidPaymentsCount > 0 ? paidPaymentsCount : payments.length;
|
|
548
|
-
return `${baseToken}_payment_${paidCount}`;
|
|
549
|
-
}
|
|
550
394
|
hasLocalDatabase() {
|
|
551
395
|
return !!this.dbManager;
|
|
552
396
|
}
|
|
@@ -649,9 +493,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
649
493
|
});
|
|
650
494
|
}
|
|
651
495
|
}
|
|
652
|
-
saveDraftInBackground() {
|
|
653
|
-
void this.saveDraft();
|
|
654
|
-
}
|
|
655
496
|
async hydrateTempOrderFromLocalRecord(record) {
|
|
656
497
|
return this.hydrateTempOrderFromRecord(record);
|
|
657
498
|
}
|
|
@@ -696,69 +537,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
696
537
|
const fixedAmount = new import_decimal.default(serviceCharge.amount || 0);
|
|
697
538
|
return new import_decimal.default(payment.amount || 0).times(percentage).plus(fixedAmount);
|
|
698
539
|
}
|
|
699
|
-
formatSummaryMetadataMoney(value) {
|
|
700
|
-
if (value === void 0 || value === null || value === "")
|
|
701
|
-
return void 0;
|
|
702
|
-
if (value instanceof import_decimal.default)
|
|
703
|
-
return value.toFixed(2);
|
|
704
|
-
return new import_decimal.default(String(value || 0)).toFixed(2);
|
|
705
|
-
}
|
|
706
|
-
syncSummaryProductMetadata(products) {
|
|
707
|
-
const moneyKeys = [
|
|
708
|
-
"main_product_attached_bundle_surcharge_fee",
|
|
709
|
-
"main_product_attached_bundle_tax_fee",
|
|
710
|
-
"surcharge_rounding_remainder",
|
|
711
|
-
"tax_fee_rounding_remainder"
|
|
712
|
-
];
|
|
713
|
-
for (const product of products || []) {
|
|
714
|
-
const productRecord = product;
|
|
715
|
-
const metadata = productRecord.metadata && typeof productRecord.metadata === "object" ? { ...productRecord.metadata } : {};
|
|
716
|
-
let hasMetadataPatch = false;
|
|
717
|
-
for (const key of moneyKeys) {
|
|
718
|
-
const value = this.formatSummaryMetadataMoney(productRecord[key]);
|
|
719
|
-
if (value === void 0)
|
|
720
|
-
continue;
|
|
721
|
-
metadata[key] = value;
|
|
722
|
-
hasMetadataPatch = true;
|
|
723
|
-
}
|
|
724
|
-
if (Array.isArray(productRecord.relation_surcharge_ids)) {
|
|
725
|
-
metadata.relation_surcharge_ids = productRecord.relation_surcharge_ids;
|
|
726
|
-
hasMetadataPatch = true;
|
|
727
|
-
}
|
|
728
|
-
if (hasMetadataPatch)
|
|
729
|
-
productRecord.metadata = metadata;
|
|
730
|
-
if (!Array.isArray(productRecord.product_bundle))
|
|
731
|
-
continue;
|
|
732
|
-
for (const bundle of productRecord.product_bundle) {
|
|
733
|
-
const bundleRecord = bundle;
|
|
734
|
-
const bundleMetadata = bundleRecord.metadata && typeof bundleRecord.metadata === "object" ? { ...bundleRecord.metadata } : {};
|
|
735
|
-
let hasBundleMetadataPatch = false;
|
|
736
|
-
const bundleSurchargeFee = this.formatSummaryMetadataMoney(
|
|
737
|
-
bundleRecord.surcharge_fee
|
|
738
|
-
);
|
|
739
|
-
if (bundleSurchargeFee !== void 0) {
|
|
740
|
-
bundleMetadata.surcharge_fee = bundleSurchargeFee;
|
|
741
|
-
hasBundleMetadataPatch = true;
|
|
742
|
-
}
|
|
743
|
-
if (Array.isArray(bundleRecord.relation_surcharge_ids)) {
|
|
744
|
-
bundleMetadata.relation_surcharge_ids = bundleRecord.relation_surcharge_ids;
|
|
745
|
-
hasBundleMetadataPatch = true;
|
|
746
|
-
}
|
|
747
|
-
if (hasBundleMetadataPatch)
|
|
748
|
-
bundleRecord.metadata = bundleMetadata;
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
calculateSummaryPaymentBalance(params) {
|
|
753
|
-
const { tempOrder, summary, orderPaidAmount } = params;
|
|
754
|
-
const depositAmount = summary.deposit_amount || tempOrder.deposit_amount || "0.00";
|
|
755
|
-
const isDeposit = tempOrder.is_deposit === 1 || new import_decimal.default(depositAmount || 0).gt(0);
|
|
756
|
-
const targetAmount = isDeposit ? new import_decimal.default(depositAmount || 0) : new import_decimal.default(summary.total_amount || summary.expect_amount || 0);
|
|
757
|
-
return {
|
|
758
|
-
amountGap: import_decimal.default.max(0, targetAmount.minus(orderPaidAmount)).toFixed(2),
|
|
759
|
-
totalRefundAmount: import_decimal.default.max(0, orderPaidAmount.minus(targetAmount)).toFixed(2)
|
|
760
|
-
};
|
|
761
|
-
}
|
|
762
540
|
getPaymentTargetAmount() {
|
|
763
541
|
const tempOrder = this.ensureTempOrder();
|
|
764
542
|
const summary = this.store.summary || (0, import_utils.createEmptySummary)();
|
|
@@ -781,43 +559,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
781
559
|
return newOrder;
|
|
782
560
|
}
|
|
783
561
|
restoreOrder() {
|
|
784
|
-
var _a, _b;
|
|
785
562
|
const freshTempOrder = this.createDefaultTempOrderInstance();
|
|
786
563
|
this.ensureExternalSaleNumber(freshTempOrder);
|
|
787
564
|
this.store.tempOrder = freshTempOrder;
|
|
788
565
|
this.store.summary = (0, import_utils.createEmptySummary)();
|
|
789
566
|
this.store.lastOrderInfo = void 0;
|
|
790
|
-
this.store.syncState = void 0;
|
|
791
|
-
void ((_a = this.store.discount) == null ? void 0 : _a.setOriginalDiscountList([]));
|
|
792
|
-
void ((_b = this.store.discount) == null ? void 0 : _b.setDiscountList([]));
|
|
793
567
|
this.persistTempOrder();
|
|
794
568
|
return freshTempOrder;
|
|
795
569
|
}
|
|
796
570
|
getTempOrder() {
|
|
797
571
|
return this.store.tempOrder;
|
|
798
572
|
}
|
|
799
|
-
async replaceTempOrder(tempOrder, options) {
|
|
800
|
-
if (!(0, import_utils.isTempOrder)(tempOrder)) {
|
|
801
|
-
throw new Error("无效的 tempOrder 数据");
|
|
802
|
-
}
|
|
803
|
-
const nextTempOrder = this.normalizeTempOrderForRuntime(
|
|
804
|
-
(0, import_lodash_es.cloneDeep)(tempOrder),
|
|
805
|
-
{ ensureIdentity: false }
|
|
806
|
-
);
|
|
807
|
-
this.store.tempOrder = nextTempOrder;
|
|
808
|
-
if ((options == null ? void 0 : options.recalculateSummary) !== false) {
|
|
809
|
-
await this.recalculateSummary({ createIfMissing: false });
|
|
810
|
-
} else {
|
|
811
|
-
this.store.summary = (0, import_utils.createEmptySummary)();
|
|
812
|
-
}
|
|
813
|
-
if ((options == null ? void 0 : options.persist) !== false) {
|
|
814
|
-
this.persistTempOrder();
|
|
815
|
-
}
|
|
816
|
-
if (options == null ? void 0 : options.saveDraft) {
|
|
817
|
-
await this.saveDraft();
|
|
818
|
-
}
|
|
819
|
-
return nextTempOrder;
|
|
820
|
-
}
|
|
821
573
|
getOrderIdentity() {
|
|
822
574
|
var _a;
|
|
823
575
|
const tempOrder = this.store.tempOrder;
|
|
@@ -966,33 +718,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
966
718
|
}
|
|
967
719
|
};
|
|
968
720
|
}
|
|
969
|
-
getBookingUniqueIdentificationNumber(booking) {
|
|
970
|
-
var _a;
|
|
971
|
-
const uid = (_a = booking == null ? void 0 : booking.metadata) == null ? void 0 : _a.unique_identification_number;
|
|
972
|
-
if (uid === void 0 || uid === null || uid === "")
|
|
973
|
-
return null;
|
|
974
|
-
return String(uid);
|
|
975
|
-
}
|
|
976
|
-
findBookingIndexByUniqueIdentificationNumber(tempOrder, uniqueIdentificationNumber) {
|
|
977
|
-
return (tempOrder.bookings || []).findIndex((booking) => {
|
|
978
|
-
return this.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
|
|
979
|
-
});
|
|
980
|
-
}
|
|
981
|
-
removeLinkedBookingsForProduct(tempOrder, product) {
|
|
982
|
-
var _a, _b;
|
|
983
|
-
const productUid = ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.unique_identification_number) || (product == null ? void 0 : product.unique_identification_number);
|
|
984
|
-
const bookingUid = (product == null ? void 0 : product.booking_uid) || ((_b = product == null ? void 0 : product.metadata) == null ? void 0 : _b.booking_uid);
|
|
985
|
-
if (!productUid && !bookingUid)
|
|
986
|
-
return;
|
|
987
|
-
tempOrder.bookings = (tempOrder.bookings || []).filter((booking) => {
|
|
988
|
-
const currentBookingUid = this.getBookingUniqueIdentificationNumber(booking);
|
|
989
|
-
if (bookingUid && currentBookingUid === String(bookingUid))
|
|
990
|
-
return false;
|
|
991
|
-
if (productUid && String((booking == null ? void 0 : booking.product_uid) || "") === String(productUid))
|
|
992
|
-
return false;
|
|
993
|
-
return true;
|
|
994
|
-
});
|
|
995
|
-
}
|
|
996
721
|
// ─── TempOrder: 金额汇总 ───
|
|
997
722
|
getSalesSummary() {
|
|
998
723
|
if (!this.salesSummaryModuleName)
|
|
@@ -1004,21 +729,16 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1004
729
|
if (!tempOrder)
|
|
1005
730
|
return null;
|
|
1006
731
|
const salesSummary = this.getSalesSummary();
|
|
732
|
+
const existedSummary = this.store.summary || (0, import_utils.createEmptySummary)();
|
|
1007
733
|
const paidPaymentSummary = this.calculatePaidPaymentSummary(
|
|
1008
734
|
tempOrder.payments || []
|
|
1009
735
|
);
|
|
1010
736
|
if (!salesSummary) {
|
|
1011
|
-
const paymentBalance2 = this.calculateSummaryPaymentBalance({
|
|
1012
|
-
tempOrder,
|
|
1013
|
-
summary: (0, import_utils.createEmptySummary)(),
|
|
1014
|
-
orderPaidAmount: paidPaymentSummary.orderPaidAmount
|
|
1015
|
-
});
|
|
1016
737
|
const emptySummary = {
|
|
1017
738
|
...(0, import_utils.createEmptySummary)(),
|
|
1018
|
-
total_refund_amount:
|
|
739
|
+
total_refund_amount: existedSummary.total_refund_amount || "0.00",
|
|
1019
740
|
customer_paid_amount: paidPaymentSummary.customerPaidAmount.toFixed(2),
|
|
1020
741
|
order_paid_amount: paidPaymentSummary.orderPaidAmount.toFixed(2),
|
|
1021
|
-
amount_gap: paymentBalance2.amountGap,
|
|
1022
742
|
pay_service_charge_amount: paidPaymentSummary.payServiceChargeAmount.toFixed(2)
|
|
1023
743
|
};
|
|
1024
744
|
this.store.summary = emptySummary;
|
|
@@ -1030,18 +750,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1030
750
|
isPriceIncludeTax: tempOrder.is_price_include_tax,
|
|
1031
751
|
shopDiscount: tempOrder.shop_discount
|
|
1032
752
|
});
|
|
1033
|
-
this.syncSummaryProductMetadata(tempOrder.products || []);
|
|
1034
|
-
const paymentBalance = this.calculateSummaryPaymentBalance({
|
|
1035
|
-
tempOrder,
|
|
1036
|
-
summary: salesSummaryResult,
|
|
1037
|
-
orderPaidAmount: paidPaymentSummary.orderPaidAmount
|
|
1038
|
-
});
|
|
1039
753
|
const summary = {
|
|
1040
754
|
...salesSummaryResult,
|
|
1041
|
-
total_refund_amount:
|
|
755
|
+
total_refund_amount: existedSummary.total_refund_amount || "0.00",
|
|
1042
756
|
customer_paid_amount: paidPaymentSummary.customerPaidAmount.toFixed(2),
|
|
1043
757
|
order_paid_amount: paidPaymentSummary.orderPaidAmount.toFixed(2),
|
|
1044
|
-
amount_gap: paymentBalance.amountGap,
|
|
1045
758
|
pay_service_charge_amount: paidPaymentSummary.payServiceChargeAmount.toFixed(2)
|
|
1046
759
|
};
|
|
1047
760
|
this.store.summary = summary;
|
|
@@ -1064,22 +777,13 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1064
777
|
this.persistTempOrder();
|
|
1065
778
|
return summary;
|
|
1066
779
|
}
|
|
1067
|
-
|
|
780
|
+
// ─── TempOrder: 备注 ───
|
|
781
|
+
updateTempOrderNote(note) {
|
|
1068
782
|
const tempOrder = this.ensureTempOrder();
|
|
1069
783
|
tempOrder.note = String(note || "");
|
|
1070
784
|
this.persistTempOrder();
|
|
1071
|
-
if (sync) {
|
|
1072
|
-
const orderId = tempOrder.order_id;
|
|
1073
|
-
if (!orderId)
|
|
1074
|
-
return tempOrder.note;
|
|
1075
|
-
return this.syncTempOrderNoteToRemote(orderId, tempOrder.note);
|
|
1076
|
-
}
|
|
1077
785
|
return tempOrder.note;
|
|
1078
786
|
}
|
|
1079
|
-
async syncTempOrderNoteToRemote(orderId, note) {
|
|
1080
|
-
await this.request.put(`/order/order/${orderId}/note`, { note });
|
|
1081
|
-
return note;
|
|
1082
|
-
}
|
|
1083
787
|
getTempOrderNote() {
|
|
1084
788
|
var _a;
|
|
1085
789
|
return ((_a = this.store.tempOrder) == null ? void 0 : _a.note) || "";
|
|
@@ -1103,29 +807,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1103
807
|
this.persistTempOrder();
|
|
1104
808
|
return tempOrder.contacts_info;
|
|
1105
809
|
}
|
|
1106
|
-
buildTempOrderCustomer(params) {
|
|
1107
|
-
if (!params.customerId)
|
|
1108
|
-
return null;
|
|
1109
|
-
const source = params.source ? (0, import_lodash_es.cloneDeep)(params.source) : {};
|
|
1110
|
-
const name = source.name ?? source.display_name ?? source.customerName ?? source.customer_name ?? params.customerName;
|
|
1111
|
-
const customerName = source.customer_name ?? source.customerName ?? source.display_name ?? source.name ?? params.customerName;
|
|
1112
|
-
return {
|
|
1113
|
-
...source,
|
|
1114
|
-
id: source.id ?? params.customerId,
|
|
1115
|
-
customer_id: source.customer_id ?? params.customerId,
|
|
1116
|
-
name: String(name || ""),
|
|
1117
|
-
customer_name: String(customerName || ""),
|
|
1118
|
-
country_calling_code: String(
|
|
1119
|
-
source.country_calling_code ?? source.countryCallingCode ?? params.countryCallingCode
|
|
1120
|
-
),
|
|
1121
|
-
phone: String(source.phone ?? params.phone),
|
|
1122
|
-
email: String(source.email ?? params.email)
|
|
1123
|
-
};
|
|
1124
|
-
}
|
|
1125
810
|
/**
|
|
1126
811
|
* 更新当前 tempOrder 的客户协议字段。
|
|
1127
812
|
*
|
|
1128
|
-
* PaymentModal
|
|
813
|
+
* PaymentModal 只需要修改订单里的客户字段;如果外部还有客户模块需要同步,
|
|
1129
814
|
* 应由调用方通过回调处理,不能把外部 UI 状态写进 tempOrder。
|
|
1130
815
|
*/
|
|
1131
816
|
updateTempOrderCustomer(customer) {
|
|
@@ -1139,14 +824,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1139
824
|
);
|
|
1140
825
|
tempOrder.phone = String(customer.phone || "");
|
|
1141
826
|
tempOrder.email = String(customer.email || "");
|
|
1142
|
-
tempOrder.customer = this.buildTempOrderCustomer({
|
|
1143
|
-
source: customer,
|
|
1144
|
-
customerId: tempOrder.customer_id,
|
|
1145
|
-
customerName: tempOrder.customer_name,
|
|
1146
|
-
countryCallingCode: tempOrder.country_calling_code,
|
|
1147
|
-
phone: tempOrder.phone,
|
|
1148
|
-
email: tempOrder.email
|
|
1149
|
-
});
|
|
1150
827
|
this.persistTempOrder();
|
|
1151
828
|
return {
|
|
1152
829
|
customerId: tempOrder.customer_id,
|
|
@@ -1161,20 +838,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1161
838
|
return;
|
|
1162
839
|
}
|
|
1163
840
|
const tempOrder = this.ensureTempOrder();
|
|
1164
|
-
const previousCustomerId = tempOrder.customer_id ?? null;
|
|
1165
841
|
tempOrder.customer_id = patch.customer_id || patch.id || null;
|
|
1166
842
|
tempOrder.customer_name = String(patch.customer_name || "");
|
|
1167
843
|
tempOrder.country_calling_code = String(patch.country_calling_code || "");
|
|
1168
844
|
tempOrder.phone = String(patch.phone || "");
|
|
1169
845
|
tempOrder.email = String(patch.email || "");
|
|
1170
|
-
tempOrder.customer = this.buildTempOrderCustomer({
|
|
1171
|
-
source: snapshot || null,
|
|
1172
|
-
customerId: tempOrder.customer_id,
|
|
1173
|
-
customerName: tempOrder.customer_name,
|
|
1174
|
-
countryCallingCode: tempOrder.country_calling_code,
|
|
1175
|
-
phone: tempOrder.phone,
|
|
1176
|
-
email: tempOrder.email
|
|
1177
|
-
});
|
|
1178
846
|
if (snapshot !== void 0) {
|
|
1179
847
|
const extend = this.ensureExtend(tempOrder);
|
|
1180
848
|
if (snapshot === null)
|
|
@@ -1182,17 +850,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1182
850
|
else
|
|
1183
851
|
extend.customerSnapshot = (0, import_lodash_es.cloneDeep)(snapshot);
|
|
1184
852
|
}
|
|
1185
|
-
const nextCustomerId = tempOrder.customer_id ?? null;
|
|
1186
|
-
if (String(previousCustomerId ?? "") !== String(nextCustomerId ?? "")) {
|
|
1187
|
-
(0, import_utils.clearTempOrderHolderAssignments)(tempOrder);
|
|
1188
|
-
}
|
|
1189
853
|
this.persistTempOrder();
|
|
1190
|
-
this.saveDraftInBackground();
|
|
1191
854
|
this.emitOrderCustomerChange();
|
|
1192
855
|
}
|
|
1193
856
|
getOrderCustomer() {
|
|
1194
857
|
const tempOrder = this.store.tempOrder;
|
|
1195
|
-
if (!tempOrder ||
|
|
858
|
+
if (!tempOrder || tempOrder.customer_id === null || tempOrder.customer_id === void 0) {
|
|
1196
859
|
return null;
|
|
1197
860
|
}
|
|
1198
861
|
return {
|
|
@@ -1210,17 +873,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1210
873
|
}
|
|
1211
874
|
clearOrderCustomer() {
|
|
1212
875
|
const tempOrder = this.ensureTempOrder();
|
|
1213
|
-
(0, import_utils.clearTempOrderHolderAssignments)(tempOrder);
|
|
1214
876
|
tempOrder.customer_id = null;
|
|
1215
877
|
tempOrder.customer_name = "";
|
|
1216
878
|
tempOrder.country_calling_code = "";
|
|
1217
879
|
tempOrder.phone = "";
|
|
1218
880
|
tempOrder.email = "";
|
|
1219
|
-
tempOrder.customer = null;
|
|
1220
881
|
if (tempOrder._extend)
|
|
1221
882
|
delete tempOrder._extend.customerSnapshot;
|
|
1222
883
|
this.persistTempOrder();
|
|
1223
|
-
this.saveDraftInBackground();
|
|
1224
884
|
this.core.effects.emit(import_types.OrderHooks.OnOrderCustomerChange, null);
|
|
1225
885
|
}
|
|
1226
886
|
emitOrderCustomerChange() {
|
|
@@ -1260,23 +920,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1260
920
|
}
|
|
1261
921
|
/** 追加单个支付项,并立即持久化当前 tempOrder。 */
|
|
1262
922
|
addOrderPayment(payment) {
|
|
1263
|
-
this.logInfo("addOrderPayment", {
|
|
1264
|
-
payment
|
|
1265
|
-
});
|
|
1266
923
|
const tempOrder = this.ensureTempOrder();
|
|
1267
|
-
const
|
|
1268
|
-
const mapped = (0, import_utils.mapPaymentItemsToOrderPayments)([{
|
|
1269
|
-
...paymentRecord,
|
|
1270
|
-
status: paymentRecord.status ?? "paid",
|
|
1271
|
-
origin_amount: paymentRecord.origin_amount ?? paymentRecord.amount ?? "0.00"
|
|
1272
|
-
}]);
|
|
924
|
+
const mapped = (0, import_utils.mapPaymentItemsToOrderPayments)([payment]);
|
|
1273
925
|
tempOrder.payments = [...tempOrder.payments || [], ...mapped];
|
|
1274
926
|
this.persistTempOrder();
|
|
1275
|
-
void this.recalculateSummary({ createIfMissing: true }).catch((error) => {
|
|
1276
|
-
this.logError("recalculate summary after addOrderPayment failed", {
|
|
1277
|
-
error: error instanceof Error ? error.message : String(error)
|
|
1278
|
-
});
|
|
1279
|
-
});
|
|
1280
927
|
return tempOrder.payments;
|
|
1281
928
|
}
|
|
1282
929
|
/**
|
|
@@ -1379,9 +1026,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1379
1026
|
productToAdd.product_bundle
|
|
1380
1027
|
);
|
|
1381
1028
|
const normalizedIncoming = (0, import_utils3.normalizeOrderProduct)(productToAdd);
|
|
1382
|
-
normalizedIncoming.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
|
|
1383
|
-
normalizedIncoming.discount_list
|
|
1384
|
-
);
|
|
1385
1029
|
const hasIncomingGoodPass = this.hasGoodPassDiscount(
|
|
1386
1030
|
normalizedIncoming
|
|
1387
1031
|
);
|
|
@@ -1438,9 +1082,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1438
1082
|
unique_identification_number: targetUid
|
|
1439
1083
|
}
|
|
1440
1084
|
});
|
|
1441
|
-
normalizedProduct.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
|
|
1442
|
-
normalizedProduct.discount_list
|
|
1443
|
-
);
|
|
1444
1085
|
tempOrder.products[matchedIndex] = {
|
|
1445
1086
|
...targetProduct,
|
|
1446
1087
|
...normalizedProduct,
|
|
@@ -1463,7 +1104,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1463
1104
|
if (linked) {
|
|
1464
1105
|
tempOrder.bookings = [...tempOrder.bookings || [], linked.booking];
|
|
1465
1106
|
}
|
|
1466
|
-
await this.applyPromotion();
|
|
1467
1107
|
this.applyDiscount();
|
|
1468
1108
|
await this.recalculateSummary({ createIfMissing: true });
|
|
1469
1109
|
this.persistTempOrder();
|
|
@@ -1487,17 +1127,15 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1487
1127
|
(item) => (item == null ? void 0 : item.type) === "good_pass" || (item == null ? void 0 : item.tag) === "good_pass"
|
|
1488
1128
|
);
|
|
1489
1129
|
}
|
|
1490
|
-
async
|
|
1491
|
-
var _a, _b, _c, _d, _e
|
|
1130
|
+
async updateProductInOrder(params) {
|
|
1131
|
+
var _a, _b, _c, _d, _e;
|
|
1492
1132
|
const {
|
|
1493
1133
|
product_id,
|
|
1494
1134
|
product_variant_id,
|
|
1495
1135
|
updates,
|
|
1496
1136
|
unique_identification_number,
|
|
1497
|
-
identity_key,
|
|
1498
1137
|
product_option_item,
|
|
1499
|
-
product_bundle
|
|
1500
|
-
booking
|
|
1138
|
+
product_bundle
|
|
1501
1139
|
} = params;
|
|
1502
1140
|
const tempOrder = this.ensureTempOrder();
|
|
1503
1141
|
const identityLookup = {
|
|
@@ -1506,30 +1144,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1506
1144
|
};
|
|
1507
1145
|
if (unique_identification_number !== void 0) {
|
|
1508
1146
|
identityLookup.unique_identification_number = unique_identification_number;
|
|
1509
|
-
if (identity_key === void 0) {
|
|
1510
|
-
identityLookup.identity_key = unique_identification_number;
|
|
1511
|
-
}
|
|
1512
|
-
}
|
|
1513
|
-
if (identity_key !== void 0) {
|
|
1514
|
-
identityLookup.identity_key = identity_key;
|
|
1515
1147
|
}
|
|
1516
1148
|
if (product_option_item !== void 0)
|
|
1517
1149
|
identityLookup.product_option_item = product_option_item;
|
|
1518
1150
|
if (product_bundle !== void 0)
|
|
1519
1151
|
identityLookup.product_bundle = product_bundle;
|
|
1520
|
-
|
|
1521
|
-
if (unique_identification_number !== void 0) {
|
|
1522
|
-
const targetUid = String(unique_identification_number);
|
|
1523
|
-
productIndex = tempOrder.products.findIndex((item) => {
|
|
1524
|
-
var _a2;
|
|
1525
|
-
return String(
|
|
1526
|
-
((_a2 = item.metadata) == null ? void 0 : _a2.unique_identification_number) || item.unique_identification_number || ""
|
|
1527
|
-
) === targetUid;
|
|
1528
|
-
});
|
|
1529
|
-
}
|
|
1530
|
-
if (productIndex === -1) {
|
|
1531
|
-
productIndex = (0, import_utils3.getProductIdentityIndex)(tempOrder.products, identityLookup);
|
|
1532
|
-
}
|
|
1152
|
+
const productIndex = (0, import_utils3.getProductIdentityIndex)(tempOrder.products, identityLookup);
|
|
1533
1153
|
if (productIndex === -1) {
|
|
1534
1154
|
throw new Error("[Order] 目标商品不存在,无法更新");
|
|
1535
1155
|
}
|
|
@@ -1556,178 +1176,28 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1556
1176
|
delete nextProduct.metadata.main_product_original_price;
|
|
1557
1177
|
delete nextProduct.metadata.price_schema_version;
|
|
1558
1178
|
}
|
|
1559
|
-
|
|
1560
|
-
normalizedProduct.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
|
|
1561
|
-
normalizedProduct.discount_list
|
|
1562
|
-
);
|
|
1563
|
-
if (booking) {
|
|
1564
|
-
const productUid = String(
|
|
1565
|
-
((_e = normalizedProduct.metadata) == null ? void 0 : _e.unique_identification_number) || ((_f = targetProduct.metadata) == null ? void 0 : _f.unique_identification_number) || unique_identification_number || (0, import_utils.createUuidV4)()
|
|
1566
|
-
);
|
|
1567
|
-
normalizedProduct.metadata = {
|
|
1568
|
-
...normalizedProduct.metadata || {},
|
|
1569
|
-
unique_identification_number: productUid
|
|
1570
|
-
};
|
|
1571
|
-
const linked = this.createLinkedProductAndBooking({
|
|
1572
|
-
product: {
|
|
1573
|
-
...normalizedProduct,
|
|
1574
|
-
unique_identification_number: productUid
|
|
1575
|
-
},
|
|
1576
|
-
booking
|
|
1577
|
-
});
|
|
1578
|
-
this.removeLinkedBookingsForProduct(tempOrder, targetProduct);
|
|
1579
|
-
normalizedProduct = {
|
|
1580
|
-
...normalizedProduct,
|
|
1581
|
-
booking_uid: linked.bookingUid,
|
|
1582
|
-
metadata: {
|
|
1583
|
-
...normalizedProduct.metadata || {},
|
|
1584
|
-
booking_uid: linked.bookingUid,
|
|
1585
|
-
unique_identification_number: productUid
|
|
1586
|
-
}
|
|
1587
|
-
};
|
|
1588
|
-
tempOrder.bookings = [...tempOrder.bookings || [], linked.booking];
|
|
1589
|
-
}
|
|
1590
|
-
tempOrder.products[productIndex] = normalizedProduct;
|
|
1179
|
+
tempOrder.products[productIndex] = (0, import_utils3.normalizeOrderProduct)(nextProduct);
|
|
1591
1180
|
this.captureProductRuntime(
|
|
1592
1181
|
tempOrder,
|
|
1593
1182
|
updates,
|
|
1594
1183
|
tempOrder.products[productIndex],
|
|
1595
|
-
(
|
|
1596
|
-
);
|
|
1597
|
-
await this.applyPromotion();
|
|
1598
|
-
this.applyDiscount();
|
|
1599
|
-
await this.recalculateSummary({ createIfMissing: true });
|
|
1600
|
-
this.persistTempOrder();
|
|
1601
|
-
return tempOrder.products;
|
|
1602
|
-
}
|
|
1603
|
-
async updateOrderProductQuantity(params) {
|
|
1604
|
-
var _a;
|
|
1605
|
-
const {
|
|
1606
|
-
product_id,
|
|
1607
|
-
product_variant_id,
|
|
1608
|
-
num,
|
|
1609
|
-
unique_identification_number,
|
|
1610
|
-
identity_key,
|
|
1611
|
-
product_option_item,
|
|
1612
|
-
product_bundle
|
|
1613
|
-
} = params;
|
|
1614
|
-
const tempOrder = this.ensureTempOrder();
|
|
1615
|
-
const identityLookup = {
|
|
1616
|
-
product_id,
|
|
1617
|
-
product_variant_id
|
|
1618
|
-
};
|
|
1619
|
-
if (unique_identification_number !== void 0) {
|
|
1620
|
-
identityLookup.unique_identification_number = unique_identification_number;
|
|
1621
|
-
if (identity_key === void 0) {
|
|
1622
|
-
identityLookup.identity_key = unique_identification_number;
|
|
1623
|
-
}
|
|
1624
|
-
}
|
|
1625
|
-
if (identity_key !== void 0)
|
|
1626
|
-
identityLookup.identity_key = identity_key;
|
|
1627
|
-
if (product_option_item !== void 0)
|
|
1628
|
-
identityLookup.product_option_item = product_option_item;
|
|
1629
|
-
if (product_bundle !== void 0)
|
|
1630
|
-
identityLookup.product_bundle = product_bundle;
|
|
1631
|
-
let productIndex = -1;
|
|
1632
|
-
if (unique_identification_number !== void 0) {
|
|
1633
|
-
const targetUid = String(unique_identification_number);
|
|
1634
|
-
productIndex = tempOrder.products.findIndex((item) => {
|
|
1635
|
-
var _a2;
|
|
1636
|
-
return String(
|
|
1637
|
-
((_a2 = item.metadata) == null ? void 0 : _a2.unique_identification_number) || item.unique_identification_number || ""
|
|
1638
|
-
) === targetUid;
|
|
1639
|
-
});
|
|
1640
|
-
}
|
|
1641
|
-
if (productIndex === -1) {
|
|
1642
|
-
productIndex = (0, import_utils3.getProductIdentityIndex)(tempOrder.products, identityLookup);
|
|
1643
|
-
}
|
|
1644
|
-
if (productIndex === -1) {
|
|
1645
|
-
throw new Error("[Order] 目标商品不存在,无法更新数量");
|
|
1646
|
-
}
|
|
1647
|
-
const targetProduct = tempOrder.products[productIndex];
|
|
1648
|
-
const normalizedProduct = (0, import_utils3.normalizeOrderProduct)({
|
|
1649
|
-
...targetProduct,
|
|
1650
|
-
num: (0, import_utils3.getSafeProductNum)(num),
|
|
1651
|
-
metadata: {
|
|
1652
|
-
...targetProduct.metadata || {},
|
|
1653
|
-
unique_identification_number: ((_a = targetProduct.metadata) == null ? void 0 : _a.unique_identification_number) || unique_identification_number
|
|
1654
|
-
}
|
|
1655
|
-
});
|
|
1656
|
-
normalizedProduct.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
|
|
1657
|
-
normalizedProduct.discount_list
|
|
1184
|
+
(_e = tempOrder.products[productIndex].metadata) == null ? void 0 : _e.unique_identification_number
|
|
1658
1185
|
);
|
|
1659
|
-
tempOrder.products[productIndex] = normalizedProduct;
|
|
1660
|
-
await this.applyPromotion();
|
|
1661
1186
|
this.applyDiscount();
|
|
1662
1187
|
await this.recalculateSummary({ createIfMissing: true });
|
|
1663
1188
|
this.persistTempOrder();
|
|
1664
1189
|
return tempOrder.products;
|
|
1665
1190
|
}
|
|
1666
|
-
updateOrderBooking(params) {
|
|
1667
|
-
const { unique_identification_number, updates } = params;
|
|
1668
|
-
const tempOrder = this.ensureTempOrder();
|
|
1669
|
-
const bookingUid = String(unique_identification_number || "");
|
|
1670
|
-
const bookingIndex = this.findBookingIndexByUniqueIdentificationNumber(
|
|
1671
|
-
tempOrder,
|
|
1672
|
-
bookingUid
|
|
1673
|
-
);
|
|
1674
|
-
if (!bookingUid || bookingIndex === -1) {
|
|
1675
|
-
throw new Error("[Order] 目标 booking 不存在,无法更新");
|
|
1676
|
-
}
|
|
1677
|
-
const targetBooking = tempOrder.bookings[bookingIndex] || {};
|
|
1678
|
-
const nextBooking = {
|
|
1679
|
-
...targetBooking,
|
|
1680
|
-
...updates,
|
|
1681
|
-
metadata: {
|
|
1682
|
-
...targetBooking.metadata || {},
|
|
1683
|
-
...updates.metadata || {},
|
|
1684
|
-
unique_identification_number: bookingUid
|
|
1685
|
-
}
|
|
1686
|
-
};
|
|
1687
|
-
nextBooking.is_all = (0, import_utils.normalizeBookingIsAll)(nextBooking);
|
|
1688
|
-
nextBooking.sub_type = (0, import_utils.normalizeBookingSubType)(nextBooking);
|
|
1689
|
-
tempOrder.bookings[bookingIndex] = nextBooking;
|
|
1690
|
-
this.persistTempOrder();
|
|
1691
|
-
return tempOrder.bookings;
|
|
1692
|
-
}
|
|
1693
1191
|
async removeProductFromOrder(identity) {
|
|
1694
1192
|
const tempOrder = this.ensureTempOrder();
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
if (shouldRemove)
|
|
1699
|
-
removedProducts.push(item);
|
|
1700
|
-
return !shouldRemove;
|
|
1701
|
-
});
|
|
1702
|
-
for (const product of removedProducts) {
|
|
1703
|
-
this.removeLinkedBookingsForProduct(tempOrder, product);
|
|
1704
|
-
}
|
|
1705
|
-
await this.applyPromotion();
|
|
1193
|
+
tempOrder.products = tempOrder.products.filter(
|
|
1194
|
+
(item) => !(0, import_utils3.isIdentityMatch)(item, identity)
|
|
1195
|
+
);
|
|
1706
1196
|
this.applyDiscount();
|
|
1707
1197
|
await this.recalculateSummary({ createIfMissing: true });
|
|
1708
1198
|
this.persistTempOrder();
|
|
1709
1199
|
return tempOrder.products;
|
|
1710
1200
|
}
|
|
1711
|
-
/**
|
|
1712
|
-
* 仅清空购物车行(products / bookings),不重置整单。
|
|
1713
|
-
* 用于「仅清空商品」;客户、备注、支付等协议字段保持不变。
|
|
1714
|
-
*/
|
|
1715
|
-
async clearOrderCartLines() {
|
|
1716
|
-
const tempOrder = this.ensureTempOrder();
|
|
1717
|
-
tempOrder.products = [];
|
|
1718
|
-
tempOrder.bookings = [];
|
|
1719
|
-
if (tempOrder._extend && typeof tempOrder._extend === "object") {
|
|
1720
|
-
tempOrder._extend = {
|
|
1721
|
-
...tempOrder._extend,
|
|
1722
|
-
productsByUid: {}
|
|
1723
|
-
};
|
|
1724
|
-
}
|
|
1725
|
-
await this.applyPromotion();
|
|
1726
|
-
this.applyDiscount();
|
|
1727
|
-
await this.recalculateSummary({ createIfMissing: true });
|
|
1728
|
-
this.persistTempOrder();
|
|
1729
|
-
return tempOrder;
|
|
1730
|
-
}
|
|
1731
1201
|
// ─── TempOrder: 提交 ───
|
|
1732
1202
|
/**
|
|
1733
1203
|
* 提交当前 Sales tempOrder。
|
|
@@ -1754,8 +1224,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1754
1224
|
...hasPaymentStatusOverride ? { payment_status: params == null ? void 0 : params.paymentStatus } : {},
|
|
1755
1225
|
...hasSmallTicketDataFlagOverride ? { small_ticket_data_flag: params == null ? void 0 : params.smallTicketDataFlag } : {}
|
|
1756
1226
|
};
|
|
1757
|
-
|
|
1758
|
-
return enhancedPayload;
|
|
1227
|
+
return (params == null ? void 0 : params.enhancePayload) ? params.enhancePayload(nextPayload, ctx) : nextPayload;
|
|
1759
1228
|
} : void 0;
|
|
1760
1229
|
const payload = (0, import_utils.buildSubmitPayload)({
|
|
1761
1230
|
tempOrder,
|
|
@@ -1772,7 +1241,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1772
1241
|
this.logInfo("submitTempOrder calling sales checkout", {
|
|
1773
1242
|
orderId: payload.order_id,
|
|
1774
1243
|
externalSaleNumber: payload.external_sale_number,
|
|
1775
|
-
requestUniqueIdempotencyToken: payload.request_unique_idempotency_token,
|
|
1776
1244
|
paymentStatus: payload.payment_status,
|
|
1777
1245
|
paymentsCount: ((_b = payload.payments) == null ? void 0 : _b.length) || 0,
|
|
1778
1246
|
smallTicketDataFlag: payload.small_ticket_data_flag
|
|
@@ -1859,37 +1327,21 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1859
1327
|
const mappedPayments = (0, import_utils.mapPaymentItemsToOrderPayments)(
|
|
1860
1328
|
params.payments || []
|
|
1861
1329
|
);
|
|
1862
|
-
const paymentTotal = this.calculatePaymentTotal(mappedPayments);
|
|
1863
|
-
const targetAmount = this.getPaymentTargetAmount();
|
|
1864
|
-
const isFullyPaid = targetAmount.lte(0) ? false : paymentTotal.gte(targetAmount);
|
|
1865
|
-
const paymentStatus = isFullyPaid ? params.paymentStatus || "paid" : "partially_paid";
|
|
1866
1330
|
tempOrder.payments = mappedPayments;
|
|
1867
|
-
|
|
1331
|
+
if (params.paymentStatus)
|
|
1332
|
+
tempOrder.payment_status = params.paymentStatus;
|
|
1868
1333
|
this.persistTempOrder();
|
|
1869
1334
|
await this.saveDraft();
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
if (
|
|
1335
|
+
const paymentTotal = this.calculatePaymentTotal(mappedPayments);
|
|
1336
|
+
const targetAmount = this.getPaymentTargetAmount();
|
|
1337
|
+
const isFullyPaid = targetAmount.lte(0) ? false : paymentTotal.gte(targetAmount);
|
|
1338
|
+
if (!isFullyPaid || !params.submitWhenPaid) {
|
|
1874
1339
|
return { isFullyPaid };
|
|
1875
1340
|
}
|
|
1876
|
-
this.store.syncState = "submitting";
|
|
1877
|
-
const paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(
|
|
1878
|
-
tempOrder,
|
|
1879
|
-
mappedPayments
|
|
1880
|
-
);
|
|
1881
1341
|
const submitResult = await this.submitTempOrder({
|
|
1882
1342
|
payments: mappedPayments,
|
|
1883
|
-
paymentStatus,
|
|
1884
|
-
smallTicketDataFlag: params.smallTicketDataFlag
|
|
1885
|
-
channel: params.channel,
|
|
1886
|
-
enhancePayload: (payload) => {
|
|
1887
|
-
const nextPayload = {
|
|
1888
|
-
...payload,
|
|
1889
|
-
request_unique_idempotency_token: paymentSyncIdempotencyToken
|
|
1890
|
-
};
|
|
1891
|
-
return nextPayload;
|
|
1892
|
-
}
|
|
1343
|
+
paymentStatus: params.paymentStatus || "paid",
|
|
1344
|
+
smallTicketDataFlag: params.smallTicketDataFlag
|
|
1893
1345
|
});
|
|
1894
1346
|
return { isFullyPaid, submitResult };
|
|
1895
1347
|
}
|
|
@@ -2189,36 +1641,54 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2189
1641
|
*/
|
|
2190
1642
|
async hydrateTempOrderFromRecord(record, options) {
|
|
2191
1643
|
const raw = record && typeof record === "object" && record.data && record.order_id == null ? record.data : record || {};
|
|
2192
|
-
const
|
|
2193
|
-
ensureIdentity: true
|
|
2194
|
-
});
|
|
2195
|
-
this.store.tempOrder = nextTempOrder;
|
|
2196
|
-
this.store.summary = raw.summary && typeof raw.summary === "object" ? { ...(0, import_utils.createEmptySummary)(), ...raw.summary } : (0, import_utils.createEmptySummary)();
|
|
2197
|
-
this.store.lastOrderInfo = raw.lastOrderInfo || raw;
|
|
2198
|
-
if (options == null ? void 0 : options.recalcOnHydrate) {
|
|
2199
|
-
await this.recalculateSummary({ createIfMissing: false });
|
|
2200
|
-
}
|
|
2201
|
-
this.persistTempOrder();
|
|
2202
|
-
return nextTempOrder;
|
|
2203
|
-
}
|
|
2204
|
-
normalizeTempOrderForRuntime(raw, options) {
|
|
1644
|
+
const defaults = this.createDefaultTempOrderInstance();
|
|
2205
1645
|
const nextTempOrder = {
|
|
2206
|
-
...
|
|
2207
|
-
...raw || {}
|
|
1646
|
+
...defaults
|
|
2208
1647
|
};
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
1648
|
+
const TEMP_ORDER_KEYS = [
|
|
1649
|
+
"order_id",
|
|
1650
|
+
"external_sale_number",
|
|
1651
|
+
"order_number",
|
|
1652
|
+
"shop_order_number",
|
|
1653
|
+
"shop_full_order_number",
|
|
1654
|
+
"type",
|
|
1655
|
+
"business_code",
|
|
1656
|
+
"platform",
|
|
1657
|
+
"sales_channel",
|
|
1658
|
+
"order_sales_channel",
|
|
1659
|
+
"vouchers",
|
|
1660
|
+
"status",
|
|
1661
|
+
"payment_status",
|
|
1662
|
+
"shipping_status",
|
|
1663
|
+
"customer_id",
|
|
1664
|
+
"customer_name",
|
|
1665
|
+
"country_calling_code",
|
|
1666
|
+
"phone",
|
|
1667
|
+
"email",
|
|
1668
|
+
"customer",
|
|
1669
|
+
"is_price_include_tax",
|
|
1670
|
+
"tax_title",
|
|
1671
|
+
"tax_country_code",
|
|
1672
|
+
"currency_code",
|
|
1673
|
+
"currency_symbol",
|
|
1674
|
+
"currency_format",
|
|
1675
|
+
"is_deposit",
|
|
1676
|
+
"deposit_amount",
|
|
1677
|
+
"shop_discount",
|
|
1678
|
+
"surcharge_fee",
|
|
1679
|
+
"note",
|
|
1680
|
+
"buzzer",
|
|
1681
|
+
"delivery_type",
|
|
1682
|
+
"table_number",
|
|
1683
|
+
"schedule_date",
|
|
1684
|
+
"created_at",
|
|
1685
|
+
"request_unique_idempotency_token"
|
|
1686
|
+
];
|
|
1687
|
+
TEMP_ORDER_KEYS.forEach((key) => {
|
|
1688
|
+
if (raw[key] !== void 0) {
|
|
1689
|
+
nextTempOrder[key] = raw[key];
|
|
1690
|
+
}
|
|
1691
|
+
});
|
|
2222
1692
|
nextTempOrder.metadata = raw.metadata && typeof raw.metadata === "object" ? { ...raw.metadata } : {};
|
|
2223
1693
|
nextTempOrder.holder = raw.holder && typeof raw.holder === "object" ? { ...raw.holder } : null;
|
|
2224
1694
|
nextTempOrder.products = Array.isArray(raw.products) ? raw.products.map((p) => this.normalizeHydratedOrderProduct(p)) : [];
|
|
@@ -2229,6 +1699,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2229
1699
|
})) : [];
|
|
2230
1700
|
nextTempOrder.payments = Array.isArray(raw.payments) ? raw.payments.map((p) => ({ ...p || {} })) : [];
|
|
2231
1701
|
nextTempOrder.surcharges = Array.isArray(raw.surcharges) ? raw.surcharges.map((s) => ({ ...s || {} })) : [];
|
|
1702
|
+
nextTempOrder.discount_list = Array.isArray(raw.discount_list) ? raw.discount_list.map((d) => ({ ...d || {} })) : [];
|
|
2232
1703
|
nextTempOrder.relation_forms = Array.isArray(raw.relation_forms) ? raw.relation_forms.map((f) => ({ ...f || {} })) : [];
|
|
2233
1704
|
nextTempOrder.contacts = Array.isArray(raw.contacts) ? raw.contacts.map((c) => ({ ...c || {} })) : [];
|
|
2234
1705
|
nextTempOrder.contacts_info = raw.contacts_info && typeof raw.contacts_info === "object" && !Array.isArray(raw.contacts_info) ? { ...raw.contacts_info } : null;
|
|
@@ -2236,9 +1707,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2236
1707
|
...raw._extend,
|
|
2237
1708
|
productsByUid: raw._extend.productsByUid || {}
|
|
2238
1709
|
} : { productsByUid: {} };
|
|
2239
|
-
|
|
2240
|
-
|
|
1710
|
+
this.ensureExternalSaleNumber(nextTempOrder);
|
|
1711
|
+
this.store.tempOrder = nextTempOrder;
|
|
1712
|
+
this.store.summary = raw.summary && typeof raw.summary === "object" ? { ...(0, import_utils.createEmptySummary)(), ...raw.summary } : (0, import_utils.createEmptySummary)();
|
|
1713
|
+
this.store.lastOrderInfo = raw.lastOrderInfo || raw;
|
|
1714
|
+
if (options == null ? void 0 : options.recalcOnHydrate) {
|
|
1715
|
+
await this.recalculateSummary({ createIfMissing: false });
|
|
2241
1716
|
}
|
|
1717
|
+
this.persistTempOrder();
|
|
2242
1718
|
return nextTempOrder;
|
|
2243
1719
|
}
|
|
2244
1720
|
normalizeHydratedOrderProduct(product) {
|
|
@@ -2257,9 +1733,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2257
1733
|
row.metadata.unique_identification_number = (0, import_utils.createUuidV4)();
|
|
2258
1734
|
}
|
|
2259
1735
|
const normalized = (0, import_utils3.normalizeOrderProduct)(row);
|
|
2260
|
-
normalized.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
|
|
2261
|
-
normalized.discount_list
|
|
2262
|
-
);
|
|
2263
1736
|
const result = {
|
|
2264
1737
|
...row,
|
|
2265
1738
|
...normalized,
|