@pisell/pisellos 2.2.171 → 2.2.172
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/BookingContext/index.d.ts +37 -0
- package/dist/modules/BookingContext/index.js +436 -0
- package/dist/modules/BookingContext/types.d.ts +102 -0
- package/dist/modules/BookingContext/types.js +51 -0
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +193 -0
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +137 -0
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +75 -0
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +215 -0
- package/dist/modules/BookingContext/utils/flexible.d.ts +28 -0
- package/dist/modules/BookingContext/utils/flexible.js +56 -0
- package/dist/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
- package/dist/modules/BookingContext/utils/formatResourceList.js +38 -0
- package/dist/modules/BookingContext/utils/index.d.ts +11 -0
- package/dist/modules/BookingContext/utils/index.js +11 -0
- package/dist/modules/BookingContext/utils/noResource.d.ts +13 -0
- package/dist/modules/BookingContext/utils/noResource.js +77 -0
- package/dist/modules/BookingContext/utils/productExtend.d.ts +72 -0
- package/dist/modules/BookingContext/utils/productExtend.js +339 -0
- package/dist/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
- package/dist/modules/BookingContext/utils/resourceErrors.js +74 -0
- package/dist/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
- package/dist/modules/BookingContext/utils/resourceSelection.js +24 -0
- package/dist/modules/BookingContext/utils/resources.d.ts +80 -0
- package/dist/modules/BookingContext/utils/resources.js +486 -0
- package/dist/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
- package/dist/modules/BookingContext/utils/serviceTimes.js +151 -0
- package/dist/modules/BookingContext/utils/timeSlices.d.ts +42 -0
- package/dist/modules/BookingContext/utils/timeSlices.js +100 -0
- package/dist/modules/Customer/index.d.ts +6 -0
- package/dist/modules/Customer/index.js +129 -83
- package/dist/modules/Customer/types.d.ts +2 -0
- package/dist/modules/Discount/index.d.ts +2 -4
- package/dist/modules/Discount/index.js +8 -93
- package/dist/modules/Discount/types.d.ts +1 -7
- package/dist/modules/Order/index.d.ts +47 -16
- package/dist/modules/Order/index.js +743 -334
- package/dist/modules/Order/types.d.ts +57 -17
- package/dist/modules/Order/types.js +2 -0
- package/dist/modules/Order/utils/manualProductDiscount.d.ts +106 -0
- package/dist/modules/Order/utils/manualProductDiscount.js +212 -0
- package/dist/modules/Order/utils.d.ts +23 -1
- package/dist/modules/Order/utils.js +139 -30
- package/dist/modules/Quotation/index.js +16 -5
- package/dist/modules/Rules/index.d.ts +4 -0
- package/dist/modules/Rules/index.js +26 -10
- package/dist/modules/SalesSummary/index.js +4 -2
- package/dist/modules/Schedule/index.js +6 -2
- package/dist/modules/index.d.ts +1 -0
- package/dist/modules/index.js +2 -1
- package/dist/server/index.js +10 -6
- package/dist/server/modules/order/utils/filterOrders.js +20 -6
- package/dist/server/modules/products/index.js +9 -8
- package/dist/server/modules/schedule/index.js +13 -6
- package/dist/solution/BaseSales/index.d.ts +65 -7
- package/dist/solution/BaseSales/index.js +1066 -315
- package/dist/solution/BaseSales/types.d.ts +53 -1
- package/dist/solution/BaseSales/types.js +3 -1
- package/dist/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
- package/dist/solution/BaseSales/utils/quotationPrice.js +159 -0
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +65 -15
- package/dist/solution/BaseSales/utils.js +46 -8
- package/dist/solution/BookingTicket/index.d.ts +134 -2
- package/dist/solution/BookingTicket/index.js +768 -175
- package/dist/solution/BookingTicket/types.d.ts +2 -0
- package/dist/solution/BookingTicket/types.js +3 -0
- package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
- package/dist/solution/BookingTicket/utils/addProductDecision.js +346 -0
- package/dist/solution/ScanOrder/index.d.ts +9 -3
- package/dist/solution/ScanOrder/index.js +231 -128
- package/dist/solution/ScanOrder/utils.js +46 -8
- package/dist/solution/ShopDiscount/index.d.ts +0 -1
- package/dist/solution/ShopDiscount/index.js +18 -23
- package/dist/solution/VenueBooking/index.d.ts +5 -9
- package/dist/solution/VenueBooking/index.js +103 -55
- package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
- package/dist/solution/VenueBooking/utils/slotMerge.js +10 -0
- package/lib/modules/BookingContext/index.d.ts +37 -0
- package/lib/modules/BookingContext/index.js +297 -0
- package/lib/modules/BookingContext/types.d.ts +102 -0
- package/lib/modules/BookingContext/types.js +34 -0
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +207 -0
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +141 -0
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +75 -0
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +198 -0
- package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
- package/lib/modules/BookingContext/utils/flexible.js +80 -0
- package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
- package/lib/modules/BookingContext/utils/formatResourceList.js +50 -0
- package/lib/modules/BookingContext/utils/index.d.ts +11 -0
- package/lib/modules/BookingContext/utils/index.js +43 -0
- package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
- package/lib/modules/BookingContext/utils/noResource.js +90 -0
- package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
- package/lib/modules/BookingContext/utils/productExtend.js +283 -0
- package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
- package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
- package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
- package/lib/modules/BookingContext/utils/resourceSelection.js +46 -0
- package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
- package/lib/modules/BookingContext/utils/resources.js +377 -0
- package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
- package/lib/modules/BookingContext/utils/serviceTimes.js +162 -0
- package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
- package/lib/modules/BookingContext/utils/timeSlices.js +124 -0
- package/lib/modules/Customer/index.d.ts +6 -0
- package/lib/modules/Customer/index.js +26 -11
- package/lib/modules/Customer/types.d.ts +2 -0
- package/lib/modules/Discount/index.d.ts +2 -4
- package/lib/modules/Discount/index.js +8 -63
- package/lib/modules/Discount/types.d.ts +1 -7
- package/lib/modules/Order/index.d.ts +47 -16
- package/lib/modules/Order/index.js +389 -90
- package/lib/modules/Order/types.d.ts +57 -17
- package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
- package/lib/modules/Order/utils/manualProductDiscount.js +207 -0
- package/lib/modules/Order/utils.d.ts +23 -1
- package/lib/modules/Order/utils.js +145 -21
- package/lib/modules/Quotation/index.js +17 -6
- package/lib/modules/Rules/index.d.ts +4 -0
- package/lib/modules/Rules/index.js +22 -14
- package/lib/modules/SalesSummary/index.js +4 -2
- package/lib/modules/Schedule/index.js +3 -1
- package/lib/modules/index.d.ts +1 -0
- package/lib/modules/index.js +3 -1
- package/lib/server/index.js +2 -0
- package/lib/server/modules/order/utils/filterOrders.js +12 -4
- package/lib/server/modules/products/index.js +8 -9
- package/lib/server/modules/schedule/index.js +2 -1
- package/lib/solution/BaseSales/index.d.ts +65 -7
- package/lib/solution/BaseSales/index.js +492 -20
- package/lib/solution/BaseSales/types.d.ts +53 -1
- package/lib/solution/BaseSales/types.js +3 -1
- package/lib/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
- package/lib/solution/BaseSales/utils/quotationPrice.js +201 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +70 -11
- package/lib/solution/BaseSales/utils.js +46 -6
- package/lib/solution/BookingTicket/index.d.ts +134 -2
- package/lib/solution/BookingTicket/index.js +341 -8
- package/lib/solution/BookingTicket/types.d.ts +2 -0
- package/lib/solution/BookingTicket/types.js +6 -0
- package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
- package/lib/solution/BookingTicket/utils/addProductDecision.js +318 -0
- package/lib/solution/ScanOrder/index.d.ts +9 -3
- package/lib/solution/ScanOrder/index.js +147 -66
- package/lib/solution/ScanOrder/utils.js +46 -6
- package/lib/solution/ShopDiscount/index.d.ts +0 -1
- package/lib/solution/ShopDiscount/index.js +2 -4
- package/lib/solution/VenueBooking/index.d.ts +5 -9
- package/lib/solution/VenueBooking/index.js +50 -14
- package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
- package/lib/solution/VenueBooking/utils/slotMerge.js +10 -0
- package/package.json +2 -2
|
@@ -38,6 +38,7 @@ var import_utils = require("./utils");
|
|
|
38
38
|
var import_utils2 = require("../Product/utils");
|
|
39
39
|
var import_dayjs = __toESM(require("dayjs"));
|
|
40
40
|
var import_utils3 = require("../../solution/ScanOrder/utils");
|
|
41
|
+
var import_manualProductDiscount = require("./utils/manualProductDiscount");
|
|
41
42
|
var import_Discount = require("../Discount");
|
|
42
43
|
var import_Rules = require("../Rules");
|
|
43
44
|
var import_types2 = require("../Rules/types");
|
|
@@ -49,6 +50,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
49
50
|
super(name || "order", version);
|
|
50
51
|
this.defaultName = "order";
|
|
51
52
|
this.defaultVersion = "1.0.0";
|
|
53
|
+
/** 是否将 tempOrder 写入 localStorage;默认 true,SalesSdk 等内存态场景可关闭。 */
|
|
54
|
+
this.enableTempOrderPersist = true;
|
|
52
55
|
}
|
|
53
56
|
/**
|
|
54
57
|
* Populate `savedAmount` on each discount based on product-level discount details.
|
|
@@ -100,8 +103,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
100
103
|
this.rulesHooksOverride = (_a = otherParams.rules) == null ? void 0 : _a.hooks;
|
|
101
104
|
this.orderHooks = options.hooks || ((_b = otherParams.order) == null ? void 0 : _b.hooks) || ((_c = otherParams.hooks) == null ? void 0 : _c.order);
|
|
102
105
|
this.otherParams = otherParams;
|
|
106
|
+
this.enableTempOrderPersist = otherParams.enableTempOrderPersist !== false;
|
|
103
107
|
this.registerDiscountModules(options);
|
|
104
|
-
this.
|
|
108
|
+
if (this.enableTempOrderPersist) {
|
|
109
|
+
this.restoreTempOrderFromStorage();
|
|
110
|
+
}
|
|
105
111
|
this.logInfo("OrderModule initialized successfully");
|
|
106
112
|
}
|
|
107
113
|
/**
|
|
@@ -174,21 +180,25 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
174
180
|
}
|
|
175
181
|
// ─── Discount: 公共 API ───
|
|
176
182
|
async loadDiscountConfig(params) {
|
|
177
|
-
var _a, _b, _c, _d;
|
|
178
|
-
const
|
|
183
|
+
var _a, _b, _c, _d, _e, _f;
|
|
184
|
+
const orderId = params.orderId || ((_a = this.store.tempOrder) == null ? void 0 : _a.order_id) || void 0;
|
|
185
|
+
const discountList = await ((_b = this.store.discount) == null ? void 0 : _b.loadPrepareConfig({
|
|
179
186
|
customer_id: params.customerId,
|
|
180
|
-
action: params.action || "create",
|
|
187
|
+
action: params.action || (orderId ? "edit" : "create"),
|
|
181
188
|
with_good_pass: 1,
|
|
182
189
|
with_discount_card: 1,
|
|
183
190
|
with_wallet_pass_holder: 1,
|
|
184
|
-
request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
191
|
+
request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
192
|
+
...orderId ? { order_id: orderId } : {}
|
|
185
193
|
}));
|
|
186
194
|
if (discountList) {
|
|
187
|
-
(
|
|
195
|
+
await ((_c = this.store.discount) == null ? void 0 : _c.setOriginalDiscountList(discountList));
|
|
196
|
+
await ((_d = this.store.discount) == null ? void 0 : _d.setDiscountList(discountList));
|
|
188
197
|
}
|
|
189
|
-
if ((
|
|
198
|
+
if (params.apply !== false && ((_f = (_e = this.store.tempOrder) == null ? void 0 : _e.products) == null ? void 0 : _f.length)) {
|
|
190
199
|
this.applyDiscount();
|
|
191
200
|
}
|
|
201
|
+
return this.getDiscountList();
|
|
192
202
|
}
|
|
193
203
|
getDiscountList() {
|
|
194
204
|
var _a;
|
|
@@ -196,14 +206,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
196
206
|
}
|
|
197
207
|
async scanCode(code, customerId) {
|
|
198
208
|
var _a, _b, _c, _d, _e;
|
|
199
|
-
const
|
|
200
|
-
const { discountList: resultDiscountList, unavailableReasonKey } = resultDiscountWithReason;
|
|
209
|
+
const resultDiscountList = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, { customerId })) || [];
|
|
201
210
|
const rulesModule = this.store.rules;
|
|
202
211
|
if (!rulesModule) {
|
|
203
212
|
return {
|
|
204
213
|
type: "clientCalc",
|
|
205
214
|
isAvailable: false,
|
|
206
215
|
discountList: this.getDiscountList(),
|
|
216
|
+
scannedDiscountList: resultDiscountList,
|
|
207
217
|
unavailableReason: import_types2.UnavailableReason.Unknown
|
|
208
218
|
};
|
|
209
219
|
}
|
|
@@ -212,7 +222,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
212
222
|
type: "server",
|
|
213
223
|
isAvailable: false,
|
|
214
224
|
discountList: this.getDiscountList(),
|
|
215
|
-
|
|
225
|
+
scannedDiscountList: resultDiscountList
|
|
216
226
|
};
|
|
217
227
|
}
|
|
218
228
|
const withScanList = resultDiscountList.map((item) => ({
|
|
@@ -224,7 +234,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
224
234
|
return {
|
|
225
235
|
type: "clientCalc",
|
|
226
236
|
isAvailable: true,
|
|
227
|
-
discountList: this.getDiscountList()
|
|
237
|
+
discountList: this.getDiscountList(),
|
|
238
|
+
scannedDiscountList: resultDiscountList
|
|
228
239
|
};
|
|
229
240
|
}
|
|
230
241
|
const tempOrder = this.store.tempOrder;
|
|
@@ -245,6 +256,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
245
256
|
type: "clientCalc",
|
|
246
257
|
isAvailable: isAvailable || false,
|
|
247
258
|
discountList: newDiscountList || this.getDiscountList(),
|
|
259
|
+
scannedDiscountList: resultDiscountList,
|
|
248
260
|
unavailableReason
|
|
249
261
|
};
|
|
250
262
|
}
|
|
@@ -253,6 +265,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
253
265
|
const tempOrder = this.store.tempOrder;
|
|
254
266
|
if (!tempOrder)
|
|
255
267
|
return;
|
|
268
|
+
delete tempOrder.discount_list;
|
|
256
269
|
const rulesModule = this.store.rules;
|
|
257
270
|
if (!rulesModule)
|
|
258
271
|
return;
|
|
@@ -266,7 +279,15 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
266
279
|
orderTotalAmount: Number(((_d = this.store.summary) == null ? void 0 : _d.total_amount) || 0)
|
|
267
280
|
});
|
|
268
281
|
if (result == null ? void 0 : result.productList) {
|
|
269
|
-
tempOrder.products = result.productList
|
|
282
|
+
tempOrder.products = (result.productList || []).map((product) => ({
|
|
283
|
+
...product,
|
|
284
|
+
discount_list: (0, import_utils.normalizeOrderProductDiscountList)(
|
|
285
|
+
(0, import_manualProductDiscount.syncManualProductDiscountProductNum)(
|
|
286
|
+
product.discount_list,
|
|
287
|
+
product.num
|
|
288
|
+
)
|
|
289
|
+
)
|
|
290
|
+
}));
|
|
270
291
|
}
|
|
271
292
|
if (result == null ? void 0 : result.discountList) {
|
|
272
293
|
OrderModule.populateSavedAmounts(
|
|
@@ -274,9 +295,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
274
295
|
result.discountList
|
|
275
296
|
);
|
|
276
297
|
(_e = this.store.discount) == null ? void 0 : _e.setDiscountList(result.discountList);
|
|
277
|
-
tempOrder.discount_list = result.discountList.filter(
|
|
278
|
-
(d) => d.isSelected
|
|
279
|
-
);
|
|
280
298
|
}
|
|
281
299
|
}
|
|
282
300
|
// ─── TempOrder: 初始化入口 ───
|
|
@@ -321,9 +339,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
321
339
|
p.product_bundle = [];
|
|
322
340
|
}
|
|
323
341
|
const row = p;
|
|
324
|
-
|
|
342
|
+
const normalized = (0, import_utils3.normalizeOrderProduct)(row);
|
|
343
|
+
normalized.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
|
|
344
|
+
normalized.discount_list
|
|
345
|
+
);
|
|
346
|
+
parsedData.products[i] = normalized;
|
|
325
347
|
}
|
|
326
348
|
}
|
|
349
|
+
delete parsedData.discount_list;
|
|
327
350
|
const parsedRecord = parsedData;
|
|
328
351
|
this.store.summary = parsedRecord.summary || (0, import_utils.createEmptySummary)();
|
|
329
352
|
delete parsedData.summary;
|
|
@@ -341,7 +364,30 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
341
364
|
(_b = (_a = this.window) == null ? void 0 : _a.localStorage) == null ? void 0 : _b.removeItem(key);
|
|
342
365
|
}
|
|
343
366
|
}
|
|
367
|
+
/**
|
|
368
|
+
* 运行时切换 tempOrder localStorage 持久化。
|
|
369
|
+
*
|
|
370
|
+
* @example
|
|
371
|
+
* orderModule.setEnableTempOrderPersist(false);
|
|
372
|
+
* orderModule.addProductToOrder(product); // 不会写入 localStorage
|
|
373
|
+
*/
|
|
374
|
+
setEnableTempOrderPersist(enabled) {
|
|
375
|
+
this.enableTempOrderPersist = enabled;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* 读取当前是否启用 tempOrder localStorage 持久化。
|
|
379
|
+
*
|
|
380
|
+
* @example
|
|
381
|
+
* if (orderModule.isTempOrderPersistEnabled()) {
|
|
382
|
+
* orderModule.persistTempOrder();
|
|
383
|
+
* }
|
|
384
|
+
*/
|
|
385
|
+
isTempOrderPersistEnabled() {
|
|
386
|
+
return this.enableTempOrderPersist;
|
|
387
|
+
}
|
|
344
388
|
persistTempOrder() {
|
|
389
|
+
if (!this.enableTempOrderPersist)
|
|
390
|
+
return;
|
|
345
391
|
const key = this.getTempOrderStorageKey();
|
|
346
392
|
if (!key || !this.store.tempOrder)
|
|
347
393
|
return;
|
|
@@ -493,6 +539,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
493
539
|
});
|
|
494
540
|
}
|
|
495
541
|
}
|
|
542
|
+
saveDraftInBackground() {
|
|
543
|
+
void this.saveDraft();
|
|
544
|
+
}
|
|
496
545
|
async hydrateTempOrderFromLocalRecord(record) {
|
|
497
546
|
return this.hydrateTempOrderFromRecord(record);
|
|
498
547
|
}
|
|
@@ -559,17 +608,43 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
559
608
|
return newOrder;
|
|
560
609
|
}
|
|
561
610
|
restoreOrder() {
|
|
611
|
+
var _a, _b;
|
|
562
612
|
const freshTempOrder = this.createDefaultTempOrderInstance();
|
|
563
613
|
this.ensureExternalSaleNumber(freshTempOrder);
|
|
564
614
|
this.store.tempOrder = freshTempOrder;
|
|
565
615
|
this.store.summary = (0, import_utils.createEmptySummary)();
|
|
566
616
|
this.store.lastOrderInfo = void 0;
|
|
617
|
+
this.store.syncState = void 0;
|
|
618
|
+
void ((_a = this.store.discount) == null ? void 0 : _a.setOriginalDiscountList([]));
|
|
619
|
+
void ((_b = this.store.discount) == null ? void 0 : _b.setDiscountList([]));
|
|
567
620
|
this.persistTempOrder();
|
|
568
621
|
return freshTempOrder;
|
|
569
622
|
}
|
|
570
623
|
getTempOrder() {
|
|
571
624
|
return this.store.tempOrder;
|
|
572
625
|
}
|
|
626
|
+
async replaceTempOrder(tempOrder, options) {
|
|
627
|
+
if (!(0, import_utils.isTempOrder)(tempOrder)) {
|
|
628
|
+
throw new Error("无效的 tempOrder 数据");
|
|
629
|
+
}
|
|
630
|
+
const nextTempOrder = this.normalizeTempOrderForRuntime(
|
|
631
|
+
(0, import_lodash_es.cloneDeep)(tempOrder),
|
|
632
|
+
{ ensureIdentity: false }
|
|
633
|
+
);
|
|
634
|
+
this.store.tempOrder = nextTempOrder;
|
|
635
|
+
if ((options == null ? void 0 : options.recalculateSummary) !== false) {
|
|
636
|
+
await this.recalculateSummary({ createIfMissing: false });
|
|
637
|
+
} else {
|
|
638
|
+
this.store.summary = (0, import_utils.createEmptySummary)();
|
|
639
|
+
}
|
|
640
|
+
if ((options == null ? void 0 : options.persist) !== false) {
|
|
641
|
+
this.persistTempOrder();
|
|
642
|
+
}
|
|
643
|
+
if (options == null ? void 0 : options.saveDraft) {
|
|
644
|
+
await this.saveDraft();
|
|
645
|
+
}
|
|
646
|
+
return nextTempOrder;
|
|
647
|
+
}
|
|
573
648
|
getOrderIdentity() {
|
|
574
649
|
var _a;
|
|
575
650
|
const tempOrder = this.store.tempOrder;
|
|
@@ -718,6 +793,33 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
718
793
|
}
|
|
719
794
|
};
|
|
720
795
|
}
|
|
796
|
+
getBookingUniqueIdentificationNumber(booking) {
|
|
797
|
+
var _a;
|
|
798
|
+
const uid = (_a = booking == null ? void 0 : booking.metadata) == null ? void 0 : _a.unique_identification_number;
|
|
799
|
+
if (uid === void 0 || uid === null || uid === "")
|
|
800
|
+
return null;
|
|
801
|
+
return String(uid);
|
|
802
|
+
}
|
|
803
|
+
findBookingIndexByUniqueIdentificationNumber(tempOrder, uniqueIdentificationNumber) {
|
|
804
|
+
return (tempOrder.bookings || []).findIndex((booking) => {
|
|
805
|
+
return this.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
removeLinkedBookingsForProduct(tempOrder, product) {
|
|
809
|
+
var _a, _b;
|
|
810
|
+
const productUid = ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.unique_identification_number) || (product == null ? void 0 : product.unique_identification_number);
|
|
811
|
+
const bookingUid = (product == null ? void 0 : product.booking_uid) || ((_b = product == null ? void 0 : product.metadata) == null ? void 0 : _b.booking_uid);
|
|
812
|
+
if (!productUid && !bookingUid)
|
|
813
|
+
return;
|
|
814
|
+
tempOrder.bookings = (tempOrder.bookings || []).filter((booking) => {
|
|
815
|
+
const currentBookingUid = this.getBookingUniqueIdentificationNumber(booking);
|
|
816
|
+
if (bookingUid && currentBookingUid === String(bookingUid))
|
|
817
|
+
return false;
|
|
818
|
+
if (productUid && String((booking == null ? void 0 : booking.product_uid) || "") === String(productUid))
|
|
819
|
+
return false;
|
|
820
|
+
return true;
|
|
821
|
+
});
|
|
822
|
+
}
|
|
721
823
|
// ─── TempOrder: 金额汇总 ───
|
|
722
824
|
getSalesSummary() {
|
|
723
825
|
if (!this.salesSummaryModuleName)
|
|
@@ -777,13 +879,22 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
777
879
|
this.persistTempOrder();
|
|
778
880
|
return summary;
|
|
779
881
|
}
|
|
780
|
-
|
|
781
|
-
updateTempOrderNote(note) {
|
|
882
|
+
updateTempOrderNote(note, sync = false) {
|
|
782
883
|
const tempOrder = this.ensureTempOrder();
|
|
783
884
|
tempOrder.note = String(note || "");
|
|
784
885
|
this.persistTempOrder();
|
|
886
|
+
if (sync) {
|
|
887
|
+
const orderId = tempOrder.order_id;
|
|
888
|
+
if (!orderId)
|
|
889
|
+
return tempOrder.note;
|
|
890
|
+
return this.syncTempOrderNoteToRemote(orderId, tempOrder.note);
|
|
891
|
+
}
|
|
785
892
|
return tempOrder.note;
|
|
786
893
|
}
|
|
894
|
+
async syncTempOrderNoteToRemote(orderId, note) {
|
|
895
|
+
await this.request.put(`/order/order/${orderId}/note`, { note });
|
|
896
|
+
return note;
|
|
897
|
+
}
|
|
787
898
|
getTempOrderNote() {
|
|
788
899
|
var _a;
|
|
789
900
|
return ((_a = this.store.tempOrder) == null ? void 0 : _a.note) || "";
|
|
@@ -807,10 +918,29 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
807
918
|
this.persistTempOrder();
|
|
808
919
|
return tempOrder.contacts_info;
|
|
809
920
|
}
|
|
921
|
+
buildTempOrderCustomer(params) {
|
|
922
|
+
if (!params.customerId)
|
|
923
|
+
return null;
|
|
924
|
+
const source = params.source ? (0, import_lodash_es.cloneDeep)(params.source) : {};
|
|
925
|
+
const name = source.name ?? source.display_name ?? source.customerName ?? source.customer_name ?? params.customerName;
|
|
926
|
+
const customerName = source.customer_name ?? source.customerName ?? source.display_name ?? source.name ?? params.customerName;
|
|
927
|
+
return {
|
|
928
|
+
...source,
|
|
929
|
+
id: source.id ?? params.customerId,
|
|
930
|
+
customer_id: source.customer_id ?? params.customerId,
|
|
931
|
+
name: String(name || ""),
|
|
932
|
+
customer_name: String(customerName || ""),
|
|
933
|
+
country_calling_code: String(
|
|
934
|
+
source.country_calling_code ?? source.countryCallingCode ?? params.countryCallingCode
|
|
935
|
+
),
|
|
936
|
+
phone: String(source.phone ?? params.phone),
|
|
937
|
+
email: String(source.email ?? params.email)
|
|
938
|
+
};
|
|
939
|
+
}
|
|
810
940
|
/**
|
|
811
941
|
* 更新当前 tempOrder 的客户协议字段。
|
|
812
942
|
*
|
|
813
|
-
* PaymentModal
|
|
943
|
+
* PaymentModal 只需要修改订单里的客户事实;如果外部还有客户模块需要同步,
|
|
814
944
|
* 应由调用方通过回调处理,不能把外部 UI 状态写进 tempOrder。
|
|
815
945
|
*/
|
|
816
946
|
updateTempOrderCustomer(customer) {
|
|
@@ -824,6 +954,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
824
954
|
);
|
|
825
955
|
tempOrder.phone = String(customer.phone || "");
|
|
826
956
|
tempOrder.email = String(customer.email || "");
|
|
957
|
+
tempOrder.customer = this.buildTempOrderCustomer({
|
|
958
|
+
source: customer,
|
|
959
|
+
customerId: tempOrder.customer_id,
|
|
960
|
+
customerName: tempOrder.customer_name,
|
|
961
|
+
countryCallingCode: tempOrder.country_calling_code,
|
|
962
|
+
phone: tempOrder.phone,
|
|
963
|
+
email: tempOrder.email
|
|
964
|
+
});
|
|
827
965
|
this.persistTempOrder();
|
|
828
966
|
return {
|
|
829
967
|
customerId: tempOrder.customer_id,
|
|
@@ -843,6 +981,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
843
981
|
tempOrder.country_calling_code = String(patch.country_calling_code || "");
|
|
844
982
|
tempOrder.phone = String(patch.phone || "");
|
|
845
983
|
tempOrder.email = String(patch.email || "");
|
|
984
|
+
tempOrder.customer = this.buildTempOrderCustomer({
|
|
985
|
+
source: snapshot || null,
|
|
986
|
+
customerId: tempOrder.customer_id,
|
|
987
|
+
customerName: tempOrder.customer_name,
|
|
988
|
+
countryCallingCode: tempOrder.country_calling_code,
|
|
989
|
+
phone: tempOrder.phone,
|
|
990
|
+
email: tempOrder.email
|
|
991
|
+
});
|
|
846
992
|
if (snapshot !== void 0) {
|
|
847
993
|
const extend = this.ensureExtend(tempOrder);
|
|
848
994
|
if (snapshot === null)
|
|
@@ -851,11 +997,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
851
997
|
extend.customerSnapshot = (0, import_lodash_es.cloneDeep)(snapshot);
|
|
852
998
|
}
|
|
853
999
|
this.persistTempOrder();
|
|
1000
|
+
this.saveDraftInBackground();
|
|
854
1001
|
this.emitOrderCustomerChange();
|
|
855
1002
|
}
|
|
856
1003
|
getOrderCustomer() {
|
|
857
1004
|
const tempOrder = this.store.tempOrder;
|
|
858
|
-
if (!tempOrder || tempOrder.customer_id
|
|
1005
|
+
if (!tempOrder || !tempOrder.customer_id) {
|
|
859
1006
|
return null;
|
|
860
1007
|
}
|
|
861
1008
|
return {
|
|
@@ -878,9 +1025,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
878
1025
|
tempOrder.country_calling_code = "";
|
|
879
1026
|
tempOrder.phone = "";
|
|
880
1027
|
tempOrder.email = "";
|
|
1028
|
+
tempOrder.customer = null;
|
|
881
1029
|
if (tempOrder._extend)
|
|
882
1030
|
delete tempOrder._extend.customerSnapshot;
|
|
883
1031
|
this.persistTempOrder();
|
|
1032
|
+
this.saveDraftInBackground();
|
|
884
1033
|
this.core.effects.emit(import_types.OrderHooks.OnOrderCustomerChange, null);
|
|
885
1034
|
}
|
|
886
1035
|
emitOrderCustomerChange() {
|
|
@@ -920,6 +1069,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
920
1069
|
}
|
|
921
1070
|
/** 追加单个支付项,并立即持久化当前 tempOrder。 */
|
|
922
1071
|
addOrderPayment(payment) {
|
|
1072
|
+
this.logInfo("addOrderPayment", {
|
|
1073
|
+
payment
|
|
1074
|
+
});
|
|
923
1075
|
const tempOrder = this.ensureTempOrder();
|
|
924
1076
|
const mapped = (0, import_utils.mapPaymentItemsToOrderPayments)([payment]);
|
|
925
1077
|
tempOrder.payments = [...tempOrder.payments || [], ...mapped];
|
|
@@ -1026,6 +1178,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1026
1178
|
productToAdd.product_bundle
|
|
1027
1179
|
);
|
|
1028
1180
|
const normalizedIncoming = (0, import_utils3.normalizeOrderProduct)(productToAdd);
|
|
1181
|
+
normalizedIncoming.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
|
|
1182
|
+
normalizedIncoming.discount_list
|
|
1183
|
+
);
|
|
1029
1184
|
const hasIncomingGoodPass = this.hasGoodPassDiscount(
|
|
1030
1185
|
normalizedIncoming
|
|
1031
1186
|
);
|
|
@@ -1082,6 +1237,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1082
1237
|
unique_identification_number: targetUid
|
|
1083
1238
|
}
|
|
1084
1239
|
});
|
|
1240
|
+
normalizedProduct.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
|
|
1241
|
+
normalizedProduct.discount_list
|
|
1242
|
+
);
|
|
1085
1243
|
tempOrder.products[matchedIndex] = {
|
|
1086
1244
|
...targetProduct,
|
|
1087
1245
|
...normalizedProduct,
|
|
@@ -1127,15 +1285,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1127
1285
|
(item) => (item == null ? void 0 : item.type) === "good_pass" || (item == null ? void 0 : item.tag) === "good_pass"
|
|
1128
1286
|
);
|
|
1129
1287
|
}
|
|
1130
|
-
async
|
|
1131
|
-
var _a, _b, _c, _d, _e;
|
|
1288
|
+
async updateOrderProduct(params) {
|
|
1289
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1132
1290
|
const {
|
|
1133
1291
|
product_id,
|
|
1134
1292
|
product_variant_id,
|
|
1135
1293
|
updates,
|
|
1136
1294
|
unique_identification_number,
|
|
1295
|
+
identity_key,
|
|
1137
1296
|
product_option_item,
|
|
1138
|
-
product_bundle
|
|
1297
|
+
product_bundle,
|
|
1298
|
+
booking
|
|
1139
1299
|
} = params;
|
|
1140
1300
|
const tempOrder = this.ensureTempOrder();
|
|
1141
1301
|
const identityLookup = {
|
|
@@ -1144,12 +1304,30 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1144
1304
|
};
|
|
1145
1305
|
if (unique_identification_number !== void 0) {
|
|
1146
1306
|
identityLookup.unique_identification_number = unique_identification_number;
|
|
1307
|
+
if (identity_key === void 0) {
|
|
1308
|
+
identityLookup.identity_key = unique_identification_number;
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
if (identity_key !== void 0) {
|
|
1312
|
+
identityLookup.identity_key = identity_key;
|
|
1147
1313
|
}
|
|
1148
1314
|
if (product_option_item !== void 0)
|
|
1149
1315
|
identityLookup.product_option_item = product_option_item;
|
|
1150
1316
|
if (product_bundle !== void 0)
|
|
1151
1317
|
identityLookup.product_bundle = product_bundle;
|
|
1152
|
-
|
|
1318
|
+
let productIndex = -1;
|
|
1319
|
+
if (unique_identification_number !== void 0) {
|
|
1320
|
+
const targetUid = String(unique_identification_number);
|
|
1321
|
+
productIndex = tempOrder.products.findIndex((item) => {
|
|
1322
|
+
var _a2;
|
|
1323
|
+
return String(
|
|
1324
|
+
((_a2 = item.metadata) == null ? void 0 : _a2.unique_identification_number) || item.unique_identification_number || ""
|
|
1325
|
+
) === targetUid;
|
|
1326
|
+
});
|
|
1327
|
+
}
|
|
1328
|
+
if (productIndex === -1) {
|
|
1329
|
+
productIndex = (0, import_utils3.getProductIdentityIndex)(tempOrder.products, identityLookup);
|
|
1330
|
+
}
|
|
1153
1331
|
if (productIndex === -1) {
|
|
1154
1332
|
throw new Error("[Order] 目标商品不存在,无法更新");
|
|
1155
1333
|
}
|
|
@@ -1176,28 +1354,174 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1176
1354
|
delete nextProduct.metadata.main_product_original_price;
|
|
1177
1355
|
delete nextProduct.metadata.price_schema_version;
|
|
1178
1356
|
}
|
|
1179
|
-
|
|
1357
|
+
let normalizedProduct = (0, import_utils3.normalizeOrderProduct)(nextProduct);
|
|
1358
|
+
normalizedProduct.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
|
|
1359
|
+
normalizedProduct.discount_list
|
|
1360
|
+
);
|
|
1361
|
+
if (booking) {
|
|
1362
|
+
const productUid = String(
|
|
1363
|
+
((_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)()
|
|
1364
|
+
);
|
|
1365
|
+
normalizedProduct.metadata = {
|
|
1366
|
+
...normalizedProduct.metadata || {},
|
|
1367
|
+
unique_identification_number: productUid
|
|
1368
|
+
};
|
|
1369
|
+
const linked = this.createLinkedProductAndBooking({
|
|
1370
|
+
product: {
|
|
1371
|
+
...normalizedProduct,
|
|
1372
|
+
unique_identification_number: productUid
|
|
1373
|
+
},
|
|
1374
|
+
booking
|
|
1375
|
+
});
|
|
1376
|
+
this.removeLinkedBookingsForProduct(tempOrder, targetProduct);
|
|
1377
|
+
normalizedProduct = {
|
|
1378
|
+
...normalizedProduct,
|
|
1379
|
+
booking_uid: linked.bookingUid,
|
|
1380
|
+
metadata: {
|
|
1381
|
+
...normalizedProduct.metadata || {},
|
|
1382
|
+
booking_uid: linked.bookingUid,
|
|
1383
|
+
unique_identification_number: productUid
|
|
1384
|
+
}
|
|
1385
|
+
};
|
|
1386
|
+
tempOrder.bookings = [...tempOrder.bookings || [], linked.booking];
|
|
1387
|
+
}
|
|
1388
|
+
tempOrder.products[productIndex] = normalizedProduct;
|
|
1180
1389
|
this.captureProductRuntime(
|
|
1181
1390
|
tempOrder,
|
|
1182
1391
|
updates,
|
|
1183
1392
|
tempOrder.products[productIndex],
|
|
1184
|
-
(
|
|
1393
|
+
(_g = tempOrder.products[productIndex].metadata) == null ? void 0 : _g.unique_identification_number
|
|
1185
1394
|
);
|
|
1186
1395
|
this.applyDiscount();
|
|
1187
1396
|
await this.recalculateSummary({ createIfMissing: true });
|
|
1188
1397
|
this.persistTempOrder();
|
|
1189
1398
|
return tempOrder.products;
|
|
1190
1399
|
}
|
|
1191
|
-
async
|
|
1400
|
+
async updateOrderProductQuantity(params) {
|
|
1401
|
+
var _a;
|
|
1402
|
+
const {
|
|
1403
|
+
product_id,
|
|
1404
|
+
product_variant_id,
|
|
1405
|
+
num,
|
|
1406
|
+
unique_identification_number,
|
|
1407
|
+
identity_key,
|
|
1408
|
+
product_option_item,
|
|
1409
|
+
product_bundle
|
|
1410
|
+
} = params;
|
|
1192
1411
|
const tempOrder = this.ensureTempOrder();
|
|
1193
|
-
|
|
1194
|
-
|
|
1412
|
+
const identityLookup = {
|
|
1413
|
+
product_id,
|
|
1414
|
+
product_variant_id
|
|
1415
|
+
};
|
|
1416
|
+
if (unique_identification_number !== void 0) {
|
|
1417
|
+
identityLookup.unique_identification_number = unique_identification_number;
|
|
1418
|
+
if (identity_key === void 0) {
|
|
1419
|
+
identityLookup.identity_key = unique_identification_number;
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
if (identity_key !== void 0)
|
|
1423
|
+
identityLookup.identity_key = identity_key;
|
|
1424
|
+
if (product_option_item !== void 0)
|
|
1425
|
+
identityLookup.product_option_item = product_option_item;
|
|
1426
|
+
if (product_bundle !== void 0)
|
|
1427
|
+
identityLookup.product_bundle = product_bundle;
|
|
1428
|
+
let productIndex = -1;
|
|
1429
|
+
if (unique_identification_number !== void 0) {
|
|
1430
|
+
const targetUid = String(unique_identification_number);
|
|
1431
|
+
productIndex = tempOrder.products.findIndex((item) => {
|
|
1432
|
+
var _a2;
|
|
1433
|
+
return String(
|
|
1434
|
+
((_a2 = item.metadata) == null ? void 0 : _a2.unique_identification_number) || item.unique_identification_number || ""
|
|
1435
|
+
) === targetUid;
|
|
1436
|
+
});
|
|
1437
|
+
}
|
|
1438
|
+
if (productIndex === -1) {
|
|
1439
|
+
productIndex = (0, import_utils3.getProductIdentityIndex)(tempOrder.products, identityLookup);
|
|
1440
|
+
}
|
|
1441
|
+
if (productIndex === -1) {
|
|
1442
|
+
throw new Error("[Order] 目标商品不存在,无法更新数量");
|
|
1443
|
+
}
|
|
1444
|
+
const targetProduct = tempOrder.products[productIndex];
|
|
1445
|
+
const normalizedProduct = (0, import_utils3.normalizeOrderProduct)({
|
|
1446
|
+
...targetProduct,
|
|
1447
|
+
num: (0, import_utils3.getSafeProductNum)(num),
|
|
1448
|
+
metadata: {
|
|
1449
|
+
...targetProduct.metadata || {},
|
|
1450
|
+
unique_identification_number: ((_a = targetProduct.metadata) == null ? void 0 : _a.unique_identification_number) || unique_identification_number
|
|
1451
|
+
}
|
|
1452
|
+
});
|
|
1453
|
+
normalizedProduct.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
|
|
1454
|
+
normalizedProduct.discount_list
|
|
1195
1455
|
);
|
|
1456
|
+
tempOrder.products[productIndex] = normalizedProduct;
|
|
1196
1457
|
this.applyDiscount();
|
|
1197
1458
|
await this.recalculateSummary({ createIfMissing: true });
|
|
1198
1459
|
this.persistTempOrder();
|
|
1199
1460
|
return tempOrder.products;
|
|
1200
1461
|
}
|
|
1462
|
+
updateOrderBooking(params) {
|
|
1463
|
+
const { unique_identification_number, updates } = params;
|
|
1464
|
+
const tempOrder = this.ensureTempOrder();
|
|
1465
|
+
const bookingUid = String(unique_identification_number || "");
|
|
1466
|
+
const bookingIndex = this.findBookingIndexByUniqueIdentificationNumber(
|
|
1467
|
+
tempOrder,
|
|
1468
|
+
bookingUid
|
|
1469
|
+
);
|
|
1470
|
+
if (!bookingUid || bookingIndex === -1) {
|
|
1471
|
+
throw new Error("[Order] 目标 booking 不存在,无法更新");
|
|
1472
|
+
}
|
|
1473
|
+
const targetBooking = tempOrder.bookings[bookingIndex] || {};
|
|
1474
|
+
const nextBooking = {
|
|
1475
|
+
...targetBooking,
|
|
1476
|
+
...updates,
|
|
1477
|
+
metadata: {
|
|
1478
|
+
...targetBooking.metadata || {},
|
|
1479
|
+
...updates.metadata || {},
|
|
1480
|
+
unique_identification_number: bookingUid
|
|
1481
|
+
}
|
|
1482
|
+
};
|
|
1483
|
+
nextBooking.is_all = (0, import_utils.normalizeBookingIsAll)(nextBooking);
|
|
1484
|
+
nextBooking.sub_type = (0, import_utils.normalizeBookingSubType)(nextBooking);
|
|
1485
|
+
tempOrder.bookings[bookingIndex] = nextBooking;
|
|
1486
|
+
this.persistTempOrder();
|
|
1487
|
+
return tempOrder.bookings;
|
|
1488
|
+
}
|
|
1489
|
+
async removeProductFromOrder(identity) {
|
|
1490
|
+
const tempOrder = this.ensureTempOrder();
|
|
1491
|
+
const removedProducts = [];
|
|
1492
|
+
tempOrder.products = tempOrder.products.filter((item) => {
|
|
1493
|
+
const shouldRemove = (0, import_utils3.isIdentityMatch)(item, identity);
|
|
1494
|
+
if (shouldRemove)
|
|
1495
|
+
removedProducts.push(item);
|
|
1496
|
+
return !shouldRemove;
|
|
1497
|
+
});
|
|
1498
|
+
for (const product of removedProducts) {
|
|
1499
|
+
this.removeLinkedBookingsForProduct(tempOrder, product);
|
|
1500
|
+
}
|
|
1501
|
+
this.applyDiscount();
|
|
1502
|
+
await this.recalculateSummary({ createIfMissing: true });
|
|
1503
|
+
this.persistTempOrder();
|
|
1504
|
+
return tempOrder.products;
|
|
1505
|
+
}
|
|
1506
|
+
/**
|
|
1507
|
+
* 仅清空购物车行(products / bookings),不重置整单。
|
|
1508
|
+
* 用于「仅清空商品」;客户、备注、支付等协议字段保持不变。
|
|
1509
|
+
*/
|
|
1510
|
+
async clearOrderCartLines() {
|
|
1511
|
+
const tempOrder = this.ensureTempOrder();
|
|
1512
|
+
tempOrder.products = [];
|
|
1513
|
+
tempOrder.bookings = [];
|
|
1514
|
+
if (tempOrder._extend && typeof tempOrder._extend === "object") {
|
|
1515
|
+
tempOrder._extend = {
|
|
1516
|
+
...tempOrder._extend,
|
|
1517
|
+
productsByUid: {}
|
|
1518
|
+
};
|
|
1519
|
+
}
|
|
1520
|
+
this.applyDiscount();
|
|
1521
|
+
await this.recalculateSummary({ createIfMissing: true });
|
|
1522
|
+
this.persistTempOrder();
|
|
1523
|
+
return tempOrder;
|
|
1524
|
+
}
|
|
1201
1525
|
// ─── TempOrder: 提交 ───
|
|
1202
1526
|
/**
|
|
1203
1527
|
* 提交当前 Sales tempOrder。
|
|
@@ -1327,21 +1651,26 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1327
1651
|
const mappedPayments = (0, import_utils.mapPaymentItemsToOrderPayments)(
|
|
1328
1652
|
params.payments || []
|
|
1329
1653
|
);
|
|
1330
|
-
tempOrder.payments = mappedPayments;
|
|
1331
|
-
if (params.paymentStatus)
|
|
1332
|
-
tempOrder.payment_status = params.paymentStatus;
|
|
1333
|
-
this.persistTempOrder();
|
|
1334
|
-
await this.saveDraft();
|
|
1335
1654
|
const paymentTotal = this.calculatePaymentTotal(mappedPayments);
|
|
1336
1655
|
const targetAmount = this.getPaymentTargetAmount();
|
|
1337
1656
|
const isFullyPaid = targetAmount.lte(0) ? false : paymentTotal.gte(targetAmount);
|
|
1338
|
-
|
|
1657
|
+
const paymentStatus = isFullyPaid ? params.paymentStatus || "paid" : "partially_paid";
|
|
1658
|
+
tempOrder.payments = mappedPayments;
|
|
1659
|
+
tempOrder.payment_status = paymentStatus;
|
|
1660
|
+
this.persistTempOrder();
|
|
1661
|
+
await this.saveDraft();
|
|
1662
|
+
if (!params.submitWhenPaid) {
|
|
1339
1663
|
return { isFullyPaid };
|
|
1340
1664
|
}
|
|
1665
|
+
if (this.store.syncState === "submitting") {
|
|
1666
|
+
return { isFullyPaid };
|
|
1667
|
+
}
|
|
1668
|
+
this.store.syncState = "submitting";
|
|
1341
1669
|
const submitResult = await this.submitTempOrder({
|
|
1342
1670
|
payments: mappedPayments,
|
|
1343
|
-
paymentStatus
|
|
1344
|
-
smallTicketDataFlag: params.smallTicketDataFlag
|
|
1671
|
+
paymentStatus,
|
|
1672
|
+
smallTicketDataFlag: params.smallTicketDataFlag,
|
|
1673
|
+
channel: params.channel
|
|
1345
1674
|
});
|
|
1346
1675
|
return { isFullyPaid, submitResult };
|
|
1347
1676
|
}
|
|
@@ -1641,53 +1970,26 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1641
1970
|
*/
|
|
1642
1971
|
async hydrateTempOrderFromRecord(record, options) {
|
|
1643
1972
|
const raw = record && typeof record === "object" && record.data && record.order_id == null ? record.data : record || {};
|
|
1644
|
-
const
|
|
1973
|
+
const nextTempOrder = this.normalizeTempOrderForRuntime(raw, {
|
|
1974
|
+
ensureIdentity: true
|
|
1975
|
+
});
|
|
1976
|
+
this.store.tempOrder = nextTempOrder;
|
|
1977
|
+
this.store.summary = raw.summary && typeof raw.summary === "object" ? { ...(0, import_utils.createEmptySummary)(), ...raw.summary } : (0, import_utils.createEmptySummary)();
|
|
1978
|
+
this.store.lastOrderInfo = raw.lastOrderInfo || raw;
|
|
1979
|
+
if (options == null ? void 0 : options.recalcOnHydrate) {
|
|
1980
|
+
await this.recalculateSummary({ createIfMissing: false });
|
|
1981
|
+
}
|
|
1982
|
+
this.persistTempOrder();
|
|
1983
|
+
return nextTempOrder;
|
|
1984
|
+
}
|
|
1985
|
+
normalizeTempOrderForRuntime(raw, options) {
|
|
1645
1986
|
const nextTempOrder = {
|
|
1646
|
-
...
|
|
1987
|
+
...this.createDefaultTempOrderInstance(),
|
|
1988
|
+
...raw || {}
|
|
1647
1989
|
};
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
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
|
-
"status",
|
|
1660
|
-
"payment_status",
|
|
1661
|
-
"shipping_status",
|
|
1662
|
-
"customer_id",
|
|
1663
|
-
"customer_name",
|
|
1664
|
-
"country_calling_code",
|
|
1665
|
-
"phone",
|
|
1666
|
-
"email",
|
|
1667
|
-
"customer",
|
|
1668
|
-
"is_price_include_tax",
|
|
1669
|
-
"tax_title",
|
|
1670
|
-
"tax_country_code",
|
|
1671
|
-
"currency_code",
|
|
1672
|
-
"currency_symbol",
|
|
1673
|
-
"currency_format",
|
|
1674
|
-
"is_deposit",
|
|
1675
|
-
"deposit_amount",
|
|
1676
|
-
"shop_discount",
|
|
1677
|
-
"surcharge_fee",
|
|
1678
|
-
"note",
|
|
1679
|
-
"buzzer",
|
|
1680
|
-
"delivery_type",
|
|
1681
|
-
"table_number",
|
|
1682
|
-
"schedule_date",
|
|
1683
|
-
"created_at",
|
|
1684
|
-
"request_unique_idempotency_token"
|
|
1685
|
-
];
|
|
1686
|
-
TEMP_ORDER_KEYS.forEach((key) => {
|
|
1687
|
-
if (raw[key] !== void 0) {
|
|
1688
|
-
nextTempOrder[key] = raw[key];
|
|
1689
|
-
}
|
|
1690
|
-
});
|
|
1990
|
+
delete nextTempOrder.summary;
|
|
1991
|
+
delete nextTempOrder.lastOrderInfo;
|
|
1992
|
+
delete nextTempOrder.discount_list;
|
|
1691
1993
|
nextTempOrder.metadata = raw.metadata && typeof raw.metadata === "object" ? { ...raw.metadata } : {};
|
|
1692
1994
|
nextTempOrder.holder = raw.holder && typeof raw.holder === "object" ? { ...raw.holder } : null;
|
|
1693
1995
|
nextTempOrder.products = Array.isArray(raw.products) ? raw.products.map((p) => this.normalizeHydratedOrderProduct(p)) : [];
|
|
@@ -1698,7 +2000,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1698
2000
|
})) : [];
|
|
1699
2001
|
nextTempOrder.payments = Array.isArray(raw.payments) ? raw.payments.map((p) => ({ ...p || {} })) : [];
|
|
1700
2002
|
nextTempOrder.surcharges = Array.isArray(raw.surcharges) ? raw.surcharges.map((s) => ({ ...s || {} })) : [];
|
|
1701
|
-
nextTempOrder.discount_list = Array.isArray(raw.discount_list) ? raw.discount_list.map((d) => ({ ...d || {} })) : [];
|
|
1702
2003
|
nextTempOrder.relation_forms = Array.isArray(raw.relation_forms) ? raw.relation_forms.map((f) => ({ ...f || {} })) : [];
|
|
1703
2004
|
nextTempOrder.contacts = Array.isArray(raw.contacts) ? raw.contacts.map((c) => ({ ...c || {} })) : [];
|
|
1704
2005
|
nextTempOrder.contacts_info = raw.contacts_info && typeof raw.contacts_info === "object" && !Array.isArray(raw.contacts_info) ? { ...raw.contacts_info } : null;
|
|
@@ -1706,14 +2007,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1706
2007
|
...raw._extend,
|
|
1707
2008
|
productsByUid: raw._extend.productsByUid || {}
|
|
1708
2009
|
} : { productsByUid: {} };
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
this.store.summary = raw.summary && typeof raw.summary === "object" ? { ...(0, import_utils.createEmptySummary)(), ...raw.summary } : (0, import_utils.createEmptySummary)();
|
|
1712
|
-
this.store.lastOrderInfo = raw.lastOrderInfo || raw;
|
|
1713
|
-
if (options == null ? void 0 : options.recalcOnHydrate) {
|
|
1714
|
-
await this.recalculateSummary({ createIfMissing: false });
|
|
2010
|
+
if ((options == null ? void 0 : options.ensureIdentity) !== false) {
|
|
2011
|
+
this.ensureExternalSaleNumber(nextTempOrder);
|
|
1715
2012
|
}
|
|
1716
|
-
this.persistTempOrder();
|
|
1717
2013
|
return nextTempOrder;
|
|
1718
2014
|
}
|
|
1719
2015
|
normalizeHydratedOrderProduct(product) {
|
|
@@ -1732,6 +2028,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1732
2028
|
row.metadata.unique_identification_number = (0, import_utils.createUuidV4)();
|
|
1733
2029
|
}
|
|
1734
2030
|
const normalized = (0, import_utils3.normalizeOrderProduct)(row);
|
|
2031
|
+
normalized.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
|
|
2032
|
+
normalized.discount_list
|
|
2033
|
+
);
|
|
1735
2034
|
const result = {
|
|
1736
2035
|
...row,
|
|
1737
2036
|
...normalized,
|