@pisell/pisellos 2.2.171 → 2.2.173
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/model/strategy/adapter/promotion/index.js +9 -0
- 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 +33 -17
- package/dist/modules/Order/index.js +757 -395
- package/dist/modules/Order/types.d.ts +58 -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 +39 -1
- package/dist/modules/Order/utils.js +219 -31
- 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 +113 -94
- package/dist/server/modules/schedule/index.js +13 -6
- package/dist/solution/BaseSales/index.d.ts +53 -7
- package/dist/solution/BaseSales/index.js +1160 -339
- package/dist/solution/BaseSales/types.d.ts +67 -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 +237 -0
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +65 -15
- package/dist/solution/BaseSales/utils.js +46 -8
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +134 -2
- package/dist/solution/BookingTicket/index.js +776 -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/model/strategy/adapter/promotion/index.js +49 -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 +33 -17
- package/lib/modules/Order/index.js +402 -148
- package/lib/modules/Order/types.d.ts +58 -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 +39 -1
- package/lib/modules/Order/utils.js +197 -22
- 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 +23 -12
- package/lib/server/modules/schedule/index.js +2 -1
- package/lib/solution/BaseSales/index.d.ts +53 -7
- package/lib/solution/BaseSales/index.js +527 -20
- package/lib/solution/BaseSales/types.d.ts +67 -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 +277 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +70 -11
- package/lib/solution/BaseSales/utils.js +46 -6
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +134 -2
- package/lib/solution/BookingTicket/index.js +349 -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");
|
|
@@ -75,6 +76,30 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
75
76
|
d.savedAmount = d.isSelected && key != null && savedMap.has(key) ? savedMap.get(key).toNumber() : 0;
|
|
76
77
|
}
|
|
77
78
|
}
|
|
79
|
+
applyProductDiscountPrices(products) {
|
|
80
|
+
return (products || []).map((product) => {
|
|
81
|
+
var _a, _b, _c;
|
|
82
|
+
if ((_a = product.metadata) == null ? void 0 : _a.is_manual_discount)
|
|
83
|
+
return product;
|
|
84
|
+
const totalPerUnitDiscount = (product.discount_list || []).reduce(
|
|
85
|
+
(sum, discount) => sum + Number(discount.amount || 0),
|
|
86
|
+
0
|
|
87
|
+
);
|
|
88
|
+
const optionSum = (0, import_utils.sumOptionUnitPrice)(product.product_option_item);
|
|
89
|
+
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");
|
|
90
|
+
const newSourceSellingPrice = new import_decimal.default(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
|
|
91
|
+
const newMainSellingPrice = new import_decimal.default(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
|
|
92
|
+
if (product.metadata) {
|
|
93
|
+
product.metadata.main_product_selling_price = newMainSellingPrice;
|
|
94
|
+
product.metadata.price_schema_version = 2;
|
|
95
|
+
}
|
|
96
|
+
product.selling_price = (0, import_utils.composeLinePrice)({
|
|
97
|
+
mainPrice: newMainSellingPrice,
|
|
98
|
+
bundle: product.product_bundle
|
|
99
|
+
});
|
|
100
|
+
return product;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
78
103
|
async initialize(core, options) {
|
|
79
104
|
var _a, _b, _c;
|
|
80
105
|
this.core = core;
|
|
@@ -101,7 +126,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
101
126
|
this.orderHooks = options.hooks || ((_b = otherParams.order) == null ? void 0 : _b.hooks) || ((_c = otherParams.hooks) == null ? void 0 : _c.order);
|
|
102
127
|
this.otherParams = otherParams;
|
|
103
128
|
this.registerDiscountModules(options);
|
|
104
|
-
this.restoreTempOrderFromStorage();
|
|
105
129
|
this.logInfo("OrderModule initialized successfully");
|
|
106
130
|
}
|
|
107
131
|
/**
|
|
@@ -174,21 +198,25 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
174
198
|
}
|
|
175
199
|
// ─── Discount: 公共 API ───
|
|
176
200
|
async loadDiscountConfig(params) {
|
|
177
|
-
var _a, _b, _c, _d;
|
|
178
|
-
const
|
|
201
|
+
var _a, _b, _c, _d, _e, _f;
|
|
202
|
+
const orderId = params.orderId || ((_a = this.store.tempOrder) == null ? void 0 : _a.order_id) || void 0;
|
|
203
|
+
const discountList = await ((_b = this.store.discount) == null ? void 0 : _b.loadPrepareConfig({
|
|
179
204
|
customer_id: params.customerId,
|
|
180
|
-
action: params.action || "create",
|
|
205
|
+
action: params.action || (orderId ? "edit" : "create"),
|
|
181
206
|
with_good_pass: 1,
|
|
182
207
|
with_discount_card: 1,
|
|
183
208
|
with_wallet_pass_holder: 1,
|
|
184
|
-
request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
209
|
+
request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
210
|
+
...orderId ? { order_id: orderId } : {}
|
|
185
211
|
}));
|
|
186
212
|
if (discountList) {
|
|
187
|
-
(
|
|
213
|
+
await ((_c = this.store.discount) == null ? void 0 : _c.setOriginalDiscountList(discountList));
|
|
214
|
+
await ((_d = this.store.discount) == null ? void 0 : _d.setDiscountList(discountList));
|
|
188
215
|
}
|
|
189
|
-
if ((
|
|
216
|
+
if (params.apply !== false && ((_f = (_e = this.store.tempOrder) == null ? void 0 : _e.products) == null ? void 0 : _f.length)) {
|
|
190
217
|
this.applyDiscount();
|
|
191
218
|
}
|
|
219
|
+
return this.getDiscountList();
|
|
192
220
|
}
|
|
193
221
|
getDiscountList() {
|
|
194
222
|
var _a;
|
|
@@ -196,14 +224,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
196
224
|
}
|
|
197
225
|
async scanCode(code, customerId) {
|
|
198
226
|
var _a, _b, _c, _d, _e;
|
|
199
|
-
const
|
|
200
|
-
const { discountList: resultDiscountList, unavailableReasonKey } = resultDiscountWithReason;
|
|
227
|
+
const resultDiscountList = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, { customerId })) || [];
|
|
201
228
|
const rulesModule = this.store.rules;
|
|
202
229
|
if (!rulesModule) {
|
|
203
230
|
return {
|
|
204
231
|
type: "clientCalc",
|
|
205
232
|
isAvailable: false,
|
|
206
233
|
discountList: this.getDiscountList(),
|
|
234
|
+
scannedDiscountList: resultDiscountList,
|
|
207
235
|
unavailableReason: import_types2.UnavailableReason.Unknown
|
|
208
236
|
};
|
|
209
237
|
}
|
|
@@ -212,7 +240,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
212
240
|
type: "server",
|
|
213
241
|
isAvailable: false,
|
|
214
242
|
discountList: this.getDiscountList(),
|
|
215
|
-
|
|
243
|
+
scannedDiscountList: resultDiscountList
|
|
216
244
|
};
|
|
217
245
|
}
|
|
218
246
|
const withScanList = resultDiscountList.map((item) => ({
|
|
@@ -224,7 +252,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
224
252
|
return {
|
|
225
253
|
type: "clientCalc",
|
|
226
254
|
isAvailable: true,
|
|
227
|
-
discountList: this.getDiscountList()
|
|
255
|
+
discountList: this.getDiscountList(),
|
|
256
|
+
scannedDiscountList: resultDiscountList
|
|
228
257
|
};
|
|
229
258
|
}
|
|
230
259
|
const tempOrder = this.store.tempOrder;
|
|
@@ -245,6 +274,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
245
274
|
type: "clientCalc",
|
|
246
275
|
isAvailable: isAvailable || false,
|
|
247
276
|
discountList: newDiscountList || this.getDiscountList(),
|
|
277
|
+
scannedDiscountList: resultDiscountList,
|
|
248
278
|
unavailableReason
|
|
249
279
|
};
|
|
250
280
|
}
|
|
@@ -253,6 +283,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
253
283
|
const tempOrder = this.store.tempOrder;
|
|
254
284
|
if (!tempOrder)
|
|
255
285
|
return;
|
|
286
|
+
delete tempOrder.discount_list;
|
|
256
287
|
const rulesModule = this.store.rules;
|
|
257
288
|
if (!rulesModule)
|
|
258
289
|
return;
|
|
@@ -266,7 +297,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
266
297
|
orderTotalAmount: Number(((_d = this.store.summary) == null ? void 0 : _d.total_amount) || 0)
|
|
267
298
|
});
|
|
268
299
|
if (result == null ? void 0 : result.productList) {
|
|
269
|
-
tempOrder.products =
|
|
300
|
+
tempOrder.products = this.applyProductDiscountPrices(
|
|
301
|
+
(result.productList || []).map((product) => ({
|
|
302
|
+
...product,
|
|
303
|
+
discount_list: (0, import_utils.normalizeOrderProductDiscountList)(
|
|
304
|
+
(0, import_manualProductDiscount.syncManualProductDiscountProductNum)(
|
|
305
|
+
product.discount_list,
|
|
306
|
+
product.num
|
|
307
|
+
)
|
|
308
|
+
)
|
|
309
|
+
}))
|
|
310
|
+
);
|
|
270
311
|
}
|
|
271
312
|
if (result == null ? void 0 : result.discountList) {
|
|
272
313
|
OrderModule.populateSavedAmounts(
|
|
@@ -274,9 +315,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
274
315
|
result.discountList
|
|
275
316
|
);
|
|
276
317
|
(_e = this.store.discount) == null ? void 0 : _e.setDiscountList(result.discountList);
|
|
277
|
-
tempOrder.discount_list = result.discountList.filter(
|
|
278
|
-
(d) => d.isSelected
|
|
279
|
-
);
|
|
280
318
|
}
|
|
281
319
|
}
|
|
282
320
|
// ─── TempOrder: 初始化入口 ───
|
|
@@ -285,69 +323,16 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
285
323
|
this.cacheId = params.cacheId;
|
|
286
324
|
if (params.salesSummaryModuleName !== void 0)
|
|
287
325
|
this.salesSummaryModuleName = params.salesSummaryModuleName;
|
|
288
|
-
this.restoreTempOrderFromStorage();
|
|
289
326
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
if (!this.cacheId)
|
|
293
|
-
return null;
|
|
294
|
-
return `scanOrder:tempOrder:${this.cacheId}`;
|
|
327
|
+
/** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化。 */
|
|
328
|
+
setEnableTempOrderPersist(_enabled) {
|
|
295
329
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
if (!key)
|
|
300
|
-
return;
|
|
301
|
-
if (!this.window)
|
|
302
|
-
return;
|
|
303
|
-
const cachedData = this.window.localStorage.getItem(key);
|
|
304
|
-
if (!cachedData)
|
|
305
|
-
return;
|
|
306
|
-
try {
|
|
307
|
-
const parsedData = JSON.parse(cachedData);
|
|
308
|
-
if (!(0, import_utils.isTempOrder)(parsedData)) {
|
|
309
|
-
this.window.localStorage.removeItem(key);
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
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 = [];
|
|
319
|
-
}
|
|
320
|
-
if (!Array.isArray(p.product_bundle)) {
|
|
321
|
-
p.product_bundle = [];
|
|
322
|
-
}
|
|
323
|
-
const row = p;
|
|
324
|
-
parsedData.products[i] = (0, import_utils3.normalizeOrderProduct)(row);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
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);
|
|
342
|
-
}
|
|
330
|
+
/** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化。 */
|
|
331
|
+
isTempOrderPersistEnabled() {
|
|
332
|
+
return false;
|
|
343
333
|
}
|
|
334
|
+
/** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化;草稿保存请使用 IndexedDB saveDraft。 */
|
|
344
335
|
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));
|
|
351
336
|
}
|
|
352
337
|
// ─── TempOrder: 创建 & 获取 ───
|
|
353
338
|
createDefaultTempOrderInstance() {
|
|
@@ -493,6 +478,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
493
478
|
});
|
|
494
479
|
}
|
|
495
480
|
}
|
|
481
|
+
saveDraftInBackground() {
|
|
482
|
+
void this.saveDraft();
|
|
483
|
+
}
|
|
496
484
|
async hydrateTempOrderFromLocalRecord(record) {
|
|
497
485
|
return this.hydrateTempOrderFromRecord(record);
|
|
498
486
|
}
|
|
@@ -559,17 +547,43 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
559
547
|
return newOrder;
|
|
560
548
|
}
|
|
561
549
|
restoreOrder() {
|
|
550
|
+
var _a, _b;
|
|
562
551
|
const freshTempOrder = this.createDefaultTempOrderInstance();
|
|
563
552
|
this.ensureExternalSaleNumber(freshTempOrder);
|
|
564
553
|
this.store.tempOrder = freshTempOrder;
|
|
565
554
|
this.store.summary = (0, import_utils.createEmptySummary)();
|
|
566
555
|
this.store.lastOrderInfo = void 0;
|
|
556
|
+
this.store.syncState = void 0;
|
|
557
|
+
void ((_a = this.store.discount) == null ? void 0 : _a.setOriginalDiscountList([]));
|
|
558
|
+
void ((_b = this.store.discount) == null ? void 0 : _b.setDiscountList([]));
|
|
567
559
|
this.persistTempOrder();
|
|
568
560
|
return freshTempOrder;
|
|
569
561
|
}
|
|
570
562
|
getTempOrder() {
|
|
571
563
|
return this.store.tempOrder;
|
|
572
564
|
}
|
|
565
|
+
async replaceTempOrder(tempOrder, options) {
|
|
566
|
+
if (!(0, import_utils.isTempOrder)(tempOrder)) {
|
|
567
|
+
throw new Error("无效的 tempOrder 数据");
|
|
568
|
+
}
|
|
569
|
+
const nextTempOrder = this.normalizeTempOrderForRuntime(
|
|
570
|
+
(0, import_lodash_es.cloneDeep)(tempOrder),
|
|
571
|
+
{ ensureIdentity: false }
|
|
572
|
+
);
|
|
573
|
+
this.store.tempOrder = nextTempOrder;
|
|
574
|
+
if ((options == null ? void 0 : options.recalculateSummary) !== false) {
|
|
575
|
+
await this.recalculateSummary({ createIfMissing: false });
|
|
576
|
+
} else {
|
|
577
|
+
this.store.summary = (0, import_utils.createEmptySummary)();
|
|
578
|
+
}
|
|
579
|
+
if ((options == null ? void 0 : options.persist) !== false) {
|
|
580
|
+
this.persistTempOrder();
|
|
581
|
+
}
|
|
582
|
+
if (options == null ? void 0 : options.saveDraft) {
|
|
583
|
+
await this.saveDraft();
|
|
584
|
+
}
|
|
585
|
+
return nextTempOrder;
|
|
586
|
+
}
|
|
573
587
|
getOrderIdentity() {
|
|
574
588
|
var _a;
|
|
575
589
|
const tempOrder = this.store.tempOrder;
|
|
@@ -718,6 +732,33 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
718
732
|
}
|
|
719
733
|
};
|
|
720
734
|
}
|
|
735
|
+
getBookingUniqueIdentificationNumber(booking) {
|
|
736
|
+
var _a;
|
|
737
|
+
const uid = (_a = booking == null ? void 0 : booking.metadata) == null ? void 0 : _a.unique_identification_number;
|
|
738
|
+
if (uid === void 0 || uid === null || uid === "")
|
|
739
|
+
return null;
|
|
740
|
+
return String(uid);
|
|
741
|
+
}
|
|
742
|
+
findBookingIndexByUniqueIdentificationNumber(tempOrder, uniqueIdentificationNumber) {
|
|
743
|
+
return (tempOrder.bookings || []).findIndex((booking) => {
|
|
744
|
+
return this.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
removeLinkedBookingsForProduct(tempOrder, product) {
|
|
748
|
+
var _a, _b;
|
|
749
|
+
const productUid = ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.unique_identification_number) || (product == null ? void 0 : product.unique_identification_number);
|
|
750
|
+
const bookingUid = (product == null ? void 0 : product.booking_uid) || ((_b = product == null ? void 0 : product.metadata) == null ? void 0 : _b.booking_uid);
|
|
751
|
+
if (!productUid && !bookingUid)
|
|
752
|
+
return;
|
|
753
|
+
tempOrder.bookings = (tempOrder.bookings || []).filter((booking) => {
|
|
754
|
+
const currentBookingUid = this.getBookingUniqueIdentificationNumber(booking);
|
|
755
|
+
if (bookingUid && currentBookingUid === String(bookingUid))
|
|
756
|
+
return false;
|
|
757
|
+
if (productUid && String((booking == null ? void 0 : booking.product_uid) || "") === String(productUid))
|
|
758
|
+
return false;
|
|
759
|
+
return true;
|
|
760
|
+
});
|
|
761
|
+
}
|
|
721
762
|
// ─── TempOrder: 金额汇总 ───
|
|
722
763
|
getSalesSummary() {
|
|
723
764
|
if (!this.salesSummaryModuleName)
|
|
@@ -777,13 +818,22 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
777
818
|
this.persistTempOrder();
|
|
778
819
|
return summary;
|
|
779
820
|
}
|
|
780
|
-
|
|
781
|
-
updateTempOrderNote(note) {
|
|
821
|
+
updateTempOrderNote(note, sync = false) {
|
|
782
822
|
const tempOrder = this.ensureTempOrder();
|
|
783
823
|
tempOrder.note = String(note || "");
|
|
784
824
|
this.persistTempOrder();
|
|
825
|
+
if (sync) {
|
|
826
|
+
const orderId = tempOrder.order_id;
|
|
827
|
+
if (!orderId)
|
|
828
|
+
return tempOrder.note;
|
|
829
|
+
return this.syncTempOrderNoteToRemote(orderId, tempOrder.note);
|
|
830
|
+
}
|
|
785
831
|
return tempOrder.note;
|
|
786
832
|
}
|
|
833
|
+
async syncTempOrderNoteToRemote(orderId, note) {
|
|
834
|
+
await this.request.put(`/order/order/${orderId}/note`, { note });
|
|
835
|
+
return note;
|
|
836
|
+
}
|
|
787
837
|
getTempOrderNote() {
|
|
788
838
|
var _a;
|
|
789
839
|
return ((_a = this.store.tempOrder) == null ? void 0 : _a.note) || "";
|
|
@@ -807,10 +857,29 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
807
857
|
this.persistTempOrder();
|
|
808
858
|
return tempOrder.contacts_info;
|
|
809
859
|
}
|
|
860
|
+
buildTempOrderCustomer(params) {
|
|
861
|
+
if (!params.customerId)
|
|
862
|
+
return null;
|
|
863
|
+
const source = params.source ? (0, import_lodash_es.cloneDeep)(params.source) : {};
|
|
864
|
+
const name = source.name ?? source.display_name ?? source.customerName ?? source.customer_name ?? params.customerName;
|
|
865
|
+
const customerName = source.customer_name ?? source.customerName ?? source.display_name ?? source.name ?? params.customerName;
|
|
866
|
+
return {
|
|
867
|
+
...source,
|
|
868
|
+
id: source.id ?? params.customerId,
|
|
869
|
+
customer_id: source.customer_id ?? params.customerId,
|
|
870
|
+
name: String(name || ""),
|
|
871
|
+
customer_name: String(customerName || ""),
|
|
872
|
+
country_calling_code: String(
|
|
873
|
+
source.country_calling_code ?? source.countryCallingCode ?? params.countryCallingCode
|
|
874
|
+
),
|
|
875
|
+
phone: String(source.phone ?? params.phone),
|
|
876
|
+
email: String(source.email ?? params.email)
|
|
877
|
+
};
|
|
878
|
+
}
|
|
810
879
|
/**
|
|
811
880
|
* 更新当前 tempOrder 的客户协议字段。
|
|
812
881
|
*
|
|
813
|
-
* PaymentModal
|
|
882
|
+
* PaymentModal 只需要修改订单里的客户事实;如果外部还有客户模块需要同步,
|
|
814
883
|
* 应由调用方通过回调处理,不能把外部 UI 状态写进 tempOrder。
|
|
815
884
|
*/
|
|
816
885
|
updateTempOrderCustomer(customer) {
|
|
@@ -824,6 +893,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
824
893
|
);
|
|
825
894
|
tempOrder.phone = String(customer.phone || "");
|
|
826
895
|
tempOrder.email = String(customer.email || "");
|
|
896
|
+
tempOrder.customer = this.buildTempOrderCustomer({
|
|
897
|
+
source: customer,
|
|
898
|
+
customerId: tempOrder.customer_id,
|
|
899
|
+
customerName: tempOrder.customer_name,
|
|
900
|
+
countryCallingCode: tempOrder.country_calling_code,
|
|
901
|
+
phone: tempOrder.phone,
|
|
902
|
+
email: tempOrder.email
|
|
903
|
+
});
|
|
827
904
|
this.persistTempOrder();
|
|
828
905
|
return {
|
|
829
906
|
customerId: tempOrder.customer_id,
|
|
@@ -838,11 +915,20 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
838
915
|
return;
|
|
839
916
|
}
|
|
840
917
|
const tempOrder = this.ensureTempOrder();
|
|
918
|
+
const previousCustomerId = tempOrder.customer_id ?? null;
|
|
841
919
|
tempOrder.customer_id = patch.customer_id || patch.id || null;
|
|
842
920
|
tempOrder.customer_name = String(patch.customer_name || "");
|
|
843
921
|
tempOrder.country_calling_code = String(patch.country_calling_code || "");
|
|
844
922
|
tempOrder.phone = String(patch.phone || "");
|
|
845
923
|
tempOrder.email = String(patch.email || "");
|
|
924
|
+
tempOrder.customer = this.buildTempOrderCustomer({
|
|
925
|
+
source: snapshot || null,
|
|
926
|
+
customerId: tempOrder.customer_id,
|
|
927
|
+
customerName: tempOrder.customer_name,
|
|
928
|
+
countryCallingCode: tempOrder.country_calling_code,
|
|
929
|
+
phone: tempOrder.phone,
|
|
930
|
+
email: tempOrder.email
|
|
931
|
+
});
|
|
846
932
|
if (snapshot !== void 0) {
|
|
847
933
|
const extend = this.ensureExtend(tempOrder);
|
|
848
934
|
if (snapshot === null)
|
|
@@ -850,12 +936,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
850
936
|
else
|
|
851
937
|
extend.customerSnapshot = (0, import_lodash_es.cloneDeep)(snapshot);
|
|
852
938
|
}
|
|
939
|
+
const nextCustomerId = tempOrder.customer_id ?? null;
|
|
940
|
+
if (String(previousCustomerId ?? "") !== String(nextCustomerId ?? "")) {
|
|
941
|
+
(0, import_utils.clearTempOrderHolderAssignments)(tempOrder);
|
|
942
|
+
}
|
|
853
943
|
this.persistTempOrder();
|
|
944
|
+
this.saveDraftInBackground();
|
|
854
945
|
this.emitOrderCustomerChange();
|
|
855
946
|
}
|
|
856
947
|
getOrderCustomer() {
|
|
857
948
|
const tempOrder = this.store.tempOrder;
|
|
858
|
-
if (!tempOrder || tempOrder.customer_id
|
|
949
|
+
if (!tempOrder || !tempOrder.customer_id) {
|
|
859
950
|
return null;
|
|
860
951
|
}
|
|
861
952
|
return {
|
|
@@ -873,14 +964,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
873
964
|
}
|
|
874
965
|
clearOrderCustomer() {
|
|
875
966
|
const tempOrder = this.ensureTempOrder();
|
|
967
|
+
(0, import_utils.clearTempOrderHolderAssignments)(tempOrder);
|
|
876
968
|
tempOrder.customer_id = null;
|
|
877
969
|
tempOrder.customer_name = "";
|
|
878
970
|
tempOrder.country_calling_code = "";
|
|
879
971
|
tempOrder.phone = "";
|
|
880
972
|
tempOrder.email = "";
|
|
973
|
+
tempOrder.customer = null;
|
|
881
974
|
if (tempOrder._extend)
|
|
882
975
|
delete tempOrder._extend.customerSnapshot;
|
|
883
976
|
this.persistTempOrder();
|
|
977
|
+
this.saveDraftInBackground();
|
|
884
978
|
this.core.effects.emit(import_types.OrderHooks.OnOrderCustomerChange, null);
|
|
885
979
|
}
|
|
886
980
|
emitOrderCustomerChange() {
|
|
@@ -920,6 +1014,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
920
1014
|
}
|
|
921
1015
|
/** 追加单个支付项,并立即持久化当前 tempOrder。 */
|
|
922
1016
|
addOrderPayment(payment) {
|
|
1017
|
+
this.logInfo("addOrderPayment", {
|
|
1018
|
+
payment
|
|
1019
|
+
});
|
|
923
1020
|
const tempOrder = this.ensureTempOrder();
|
|
924
1021
|
const mapped = (0, import_utils.mapPaymentItemsToOrderPayments)([payment]);
|
|
925
1022
|
tempOrder.payments = [...tempOrder.payments || [], ...mapped];
|
|
@@ -1026,6 +1123,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1026
1123
|
productToAdd.product_bundle
|
|
1027
1124
|
);
|
|
1028
1125
|
const normalizedIncoming = (0, import_utils3.normalizeOrderProduct)(productToAdd);
|
|
1126
|
+
normalizedIncoming.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
|
|
1127
|
+
normalizedIncoming.discount_list
|
|
1128
|
+
);
|
|
1029
1129
|
const hasIncomingGoodPass = this.hasGoodPassDiscount(
|
|
1030
1130
|
normalizedIncoming
|
|
1031
1131
|
);
|
|
@@ -1082,6 +1182,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1082
1182
|
unique_identification_number: targetUid
|
|
1083
1183
|
}
|
|
1084
1184
|
});
|
|
1185
|
+
normalizedProduct.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
|
|
1186
|
+
normalizedProduct.discount_list
|
|
1187
|
+
);
|
|
1085
1188
|
tempOrder.products[matchedIndex] = {
|
|
1086
1189
|
...targetProduct,
|
|
1087
1190
|
...normalizedProduct,
|
|
@@ -1127,15 +1230,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1127
1230
|
(item) => (item == null ? void 0 : item.type) === "good_pass" || (item == null ? void 0 : item.tag) === "good_pass"
|
|
1128
1231
|
);
|
|
1129
1232
|
}
|
|
1130
|
-
async
|
|
1131
|
-
var _a, _b, _c, _d, _e;
|
|
1233
|
+
async updateOrderProduct(params) {
|
|
1234
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1132
1235
|
const {
|
|
1133
1236
|
product_id,
|
|
1134
1237
|
product_variant_id,
|
|
1135
1238
|
updates,
|
|
1136
1239
|
unique_identification_number,
|
|
1240
|
+
identity_key,
|
|
1137
1241
|
product_option_item,
|
|
1138
|
-
product_bundle
|
|
1242
|
+
product_bundle,
|
|
1243
|
+
booking
|
|
1139
1244
|
} = params;
|
|
1140
1245
|
const tempOrder = this.ensureTempOrder();
|
|
1141
1246
|
const identityLookup = {
|
|
@@ -1144,12 +1249,30 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1144
1249
|
};
|
|
1145
1250
|
if (unique_identification_number !== void 0) {
|
|
1146
1251
|
identityLookup.unique_identification_number = unique_identification_number;
|
|
1252
|
+
if (identity_key === void 0) {
|
|
1253
|
+
identityLookup.identity_key = unique_identification_number;
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
if (identity_key !== void 0) {
|
|
1257
|
+
identityLookup.identity_key = identity_key;
|
|
1147
1258
|
}
|
|
1148
1259
|
if (product_option_item !== void 0)
|
|
1149
1260
|
identityLookup.product_option_item = product_option_item;
|
|
1150
1261
|
if (product_bundle !== void 0)
|
|
1151
1262
|
identityLookup.product_bundle = product_bundle;
|
|
1152
|
-
|
|
1263
|
+
let productIndex = -1;
|
|
1264
|
+
if (unique_identification_number !== void 0) {
|
|
1265
|
+
const targetUid = String(unique_identification_number);
|
|
1266
|
+
productIndex = tempOrder.products.findIndex((item) => {
|
|
1267
|
+
var _a2;
|
|
1268
|
+
return String(
|
|
1269
|
+
((_a2 = item.metadata) == null ? void 0 : _a2.unique_identification_number) || item.unique_identification_number || ""
|
|
1270
|
+
) === targetUid;
|
|
1271
|
+
});
|
|
1272
|
+
}
|
|
1273
|
+
if (productIndex === -1) {
|
|
1274
|
+
productIndex = (0, import_utils3.getProductIdentityIndex)(tempOrder.products, identityLookup);
|
|
1275
|
+
}
|
|
1153
1276
|
if (productIndex === -1) {
|
|
1154
1277
|
throw new Error("[Order] 目标商品不存在,无法更新");
|
|
1155
1278
|
}
|
|
@@ -1176,28 +1299,174 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1176
1299
|
delete nextProduct.metadata.main_product_original_price;
|
|
1177
1300
|
delete nextProduct.metadata.price_schema_version;
|
|
1178
1301
|
}
|
|
1179
|
-
|
|
1302
|
+
let normalizedProduct = (0, import_utils3.normalizeOrderProduct)(nextProduct);
|
|
1303
|
+
normalizedProduct.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
|
|
1304
|
+
normalizedProduct.discount_list
|
|
1305
|
+
);
|
|
1306
|
+
if (booking) {
|
|
1307
|
+
const productUid = String(
|
|
1308
|
+
((_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)()
|
|
1309
|
+
);
|
|
1310
|
+
normalizedProduct.metadata = {
|
|
1311
|
+
...normalizedProduct.metadata || {},
|
|
1312
|
+
unique_identification_number: productUid
|
|
1313
|
+
};
|
|
1314
|
+
const linked = this.createLinkedProductAndBooking({
|
|
1315
|
+
product: {
|
|
1316
|
+
...normalizedProduct,
|
|
1317
|
+
unique_identification_number: productUid
|
|
1318
|
+
},
|
|
1319
|
+
booking
|
|
1320
|
+
});
|
|
1321
|
+
this.removeLinkedBookingsForProduct(tempOrder, targetProduct);
|
|
1322
|
+
normalizedProduct = {
|
|
1323
|
+
...normalizedProduct,
|
|
1324
|
+
booking_uid: linked.bookingUid,
|
|
1325
|
+
metadata: {
|
|
1326
|
+
...normalizedProduct.metadata || {},
|
|
1327
|
+
booking_uid: linked.bookingUid,
|
|
1328
|
+
unique_identification_number: productUid
|
|
1329
|
+
}
|
|
1330
|
+
};
|
|
1331
|
+
tempOrder.bookings = [...tempOrder.bookings || [], linked.booking];
|
|
1332
|
+
}
|
|
1333
|
+
tempOrder.products[productIndex] = normalizedProduct;
|
|
1180
1334
|
this.captureProductRuntime(
|
|
1181
1335
|
tempOrder,
|
|
1182
1336
|
updates,
|
|
1183
1337
|
tempOrder.products[productIndex],
|
|
1184
|
-
(
|
|
1338
|
+
(_g = tempOrder.products[productIndex].metadata) == null ? void 0 : _g.unique_identification_number
|
|
1185
1339
|
);
|
|
1186
1340
|
this.applyDiscount();
|
|
1187
1341
|
await this.recalculateSummary({ createIfMissing: true });
|
|
1188
1342
|
this.persistTempOrder();
|
|
1189
1343
|
return tempOrder.products;
|
|
1190
1344
|
}
|
|
1191
|
-
async
|
|
1345
|
+
async updateOrderProductQuantity(params) {
|
|
1346
|
+
var _a;
|
|
1347
|
+
const {
|
|
1348
|
+
product_id,
|
|
1349
|
+
product_variant_id,
|
|
1350
|
+
num,
|
|
1351
|
+
unique_identification_number,
|
|
1352
|
+
identity_key,
|
|
1353
|
+
product_option_item,
|
|
1354
|
+
product_bundle
|
|
1355
|
+
} = params;
|
|
1356
|
+
const tempOrder = this.ensureTempOrder();
|
|
1357
|
+
const identityLookup = {
|
|
1358
|
+
product_id,
|
|
1359
|
+
product_variant_id
|
|
1360
|
+
};
|
|
1361
|
+
if (unique_identification_number !== void 0) {
|
|
1362
|
+
identityLookup.unique_identification_number = unique_identification_number;
|
|
1363
|
+
if (identity_key === void 0) {
|
|
1364
|
+
identityLookup.identity_key = unique_identification_number;
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
if (identity_key !== void 0)
|
|
1368
|
+
identityLookup.identity_key = identity_key;
|
|
1369
|
+
if (product_option_item !== void 0)
|
|
1370
|
+
identityLookup.product_option_item = product_option_item;
|
|
1371
|
+
if (product_bundle !== void 0)
|
|
1372
|
+
identityLookup.product_bundle = product_bundle;
|
|
1373
|
+
let productIndex = -1;
|
|
1374
|
+
if (unique_identification_number !== void 0) {
|
|
1375
|
+
const targetUid = String(unique_identification_number);
|
|
1376
|
+
productIndex = tempOrder.products.findIndex((item) => {
|
|
1377
|
+
var _a2;
|
|
1378
|
+
return String(
|
|
1379
|
+
((_a2 = item.metadata) == null ? void 0 : _a2.unique_identification_number) || item.unique_identification_number || ""
|
|
1380
|
+
) === targetUid;
|
|
1381
|
+
});
|
|
1382
|
+
}
|
|
1383
|
+
if (productIndex === -1) {
|
|
1384
|
+
productIndex = (0, import_utils3.getProductIdentityIndex)(tempOrder.products, identityLookup);
|
|
1385
|
+
}
|
|
1386
|
+
if (productIndex === -1) {
|
|
1387
|
+
throw new Error("[Order] 目标商品不存在,无法更新数量");
|
|
1388
|
+
}
|
|
1389
|
+
const targetProduct = tempOrder.products[productIndex];
|
|
1390
|
+
const normalizedProduct = (0, import_utils3.normalizeOrderProduct)({
|
|
1391
|
+
...targetProduct,
|
|
1392
|
+
num: (0, import_utils3.getSafeProductNum)(num),
|
|
1393
|
+
metadata: {
|
|
1394
|
+
...targetProduct.metadata || {},
|
|
1395
|
+
unique_identification_number: ((_a = targetProduct.metadata) == null ? void 0 : _a.unique_identification_number) || unique_identification_number
|
|
1396
|
+
}
|
|
1397
|
+
});
|
|
1398
|
+
normalizedProduct.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
|
|
1399
|
+
normalizedProduct.discount_list
|
|
1400
|
+
);
|
|
1401
|
+
tempOrder.products[productIndex] = normalizedProduct;
|
|
1402
|
+
this.applyDiscount();
|
|
1403
|
+
await this.recalculateSummary({ createIfMissing: true });
|
|
1404
|
+
this.persistTempOrder();
|
|
1405
|
+
return tempOrder.products;
|
|
1406
|
+
}
|
|
1407
|
+
updateOrderBooking(params) {
|
|
1408
|
+
const { unique_identification_number, updates } = params;
|
|
1192
1409
|
const tempOrder = this.ensureTempOrder();
|
|
1193
|
-
|
|
1194
|
-
|
|
1410
|
+
const bookingUid = String(unique_identification_number || "");
|
|
1411
|
+
const bookingIndex = this.findBookingIndexByUniqueIdentificationNumber(
|
|
1412
|
+
tempOrder,
|
|
1413
|
+
bookingUid
|
|
1195
1414
|
);
|
|
1415
|
+
if (!bookingUid || bookingIndex === -1) {
|
|
1416
|
+
throw new Error("[Order] 目标 booking 不存在,无法更新");
|
|
1417
|
+
}
|
|
1418
|
+
const targetBooking = tempOrder.bookings[bookingIndex] || {};
|
|
1419
|
+
const nextBooking = {
|
|
1420
|
+
...targetBooking,
|
|
1421
|
+
...updates,
|
|
1422
|
+
metadata: {
|
|
1423
|
+
...targetBooking.metadata || {},
|
|
1424
|
+
...updates.metadata || {},
|
|
1425
|
+
unique_identification_number: bookingUid
|
|
1426
|
+
}
|
|
1427
|
+
};
|
|
1428
|
+
nextBooking.is_all = (0, import_utils.normalizeBookingIsAll)(nextBooking);
|
|
1429
|
+
nextBooking.sub_type = (0, import_utils.normalizeBookingSubType)(nextBooking);
|
|
1430
|
+
tempOrder.bookings[bookingIndex] = nextBooking;
|
|
1431
|
+
this.persistTempOrder();
|
|
1432
|
+
return tempOrder.bookings;
|
|
1433
|
+
}
|
|
1434
|
+
async removeProductFromOrder(identity) {
|
|
1435
|
+
const tempOrder = this.ensureTempOrder();
|
|
1436
|
+
const removedProducts = [];
|
|
1437
|
+
tempOrder.products = tempOrder.products.filter((item) => {
|
|
1438
|
+
const shouldRemove = (0, import_utils3.isIdentityMatch)(item, identity);
|
|
1439
|
+
if (shouldRemove)
|
|
1440
|
+
removedProducts.push(item);
|
|
1441
|
+
return !shouldRemove;
|
|
1442
|
+
});
|
|
1443
|
+
for (const product of removedProducts) {
|
|
1444
|
+
this.removeLinkedBookingsForProduct(tempOrder, product);
|
|
1445
|
+
}
|
|
1196
1446
|
this.applyDiscount();
|
|
1197
1447
|
await this.recalculateSummary({ createIfMissing: true });
|
|
1198
1448
|
this.persistTempOrder();
|
|
1199
1449
|
return tempOrder.products;
|
|
1200
1450
|
}
|
|
1451
|
+
/**
|
|
1452
|
+
* 仅清空购物车行(products / bookings),不重置整单。
|
|
1453
|
+
* 用于「仅清空商品」;客户、备注、支付等协议字段保持不变。
|
|
1454
|
+
*/
|
|
1455
|
+
async clearOrderCartLines() {
|
|
1456
|
+
const tempOrder = this.ensureTempOrder();
|
|
1457
|
+
tempOrder.products = [];
|
|
1458
|
+
tempOrder.bookings = [];
|
|
1459
|
+
if (tempOrder._extend && typeof tempOrder._extend === "object") {
|
|
1460
|
+
tempOrder._extend = {
|
|
1461
|
+
...tempOrder._extend,
|
|
1462
|
+
productsByUid: {}
|
|
1463
|
+
};
|
|
1464
|
+
}
|
|
1465
|
+
this.applyDiscount();
|
|
1466
|
+
await this.recalculateSummary({ createIfMissing: true });
|
|
1467
|
+
this.persistTempOrder();
|
|
1468
|
+
return tempOrder;
|
|
1469
|
+
}
|
|
1201
1470
|
// ─── TempOrder: 提交 ───
|
|
1202
1471
|
/**
|
|
1203
1472
|
* 提交当前 Sales tempOrder。
|
|
@@ -1327,21 +1596,26 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1327
1596
|
const mappedPayments = (0, import_utils.mapPaymentItemsToOrderPayments)(
|
|
1328
1597
|
params.payments || []
|
|
1329
1598
|
);
|
|
1330
|
-
tempOrder.payments = mappedPayments;
|
|
1331
|
-
if (params.paymentStatus)
|
|
1332
|
-
tempOrder.payment_status = params.paymentStatus;
|
|
1333
|
-
this.persistTempOrder();
|
|
1334
|
-
await this.saveDraft();
|
|
1335
1599
|
const paymentTotal = this.calculatePaymentTotal(mappedPayments);
|
|
1336
1600
|
const targetAmount = this.getPaymentTargetAmount();
|
|
1337
1601
|
const isFullyPaid = targetAmount.lte(0) ? false : paymentTotal.gte(targetAmount);
|
|
1338
|
-
|
|
1602
|
+
const paymentStatus = isFullyPaid ? params.paymentStatus || "paid" : "partially_paid";
|
|
1603
|
+
tempOrder.payments = mappedPayments;
|
|
1604
|
+
tempOrder.payment_status = paymentStatus;
|
|
1605
|
+
this.persistTempOrder();
|
|
1606
|
+
await this.saveDraft();
|
|
1607
|
+
if (!params.submitWhenPaid) {
|
|
1608
|
+
return { isFullyPaid };
|
|
1609
|
+
}
|
|
1610
|
+
if (this.store.syncState === "submitting") {
|
|
1339
1611
|
return { isFullyPaid };
|
|
1340
1612
|
}
|
|
1613
|
+
this.store.syncState = "submitting";
|
|
1341
1614
|
const submitResult = await this.submitTempOrder({
|
|
1342
1615
|
payments: mappedPayments,
|
|
1343
|
-
paymentStatus
|
|
1344
|
-
smallTicketDataFlag: params.smallTicketDataFlag
|
|
1616
|
+
paymentStatus,
|
|
1617
|
+
smallTicketDataFlag: params.smallTicketDataFlag,
|
|
1618
|
+
channel: params.channel
|
|
1345
1619
|
});
|
|
1346
1620
|
return { isFullyPaid, submitResult };
|
|
1347
1621
|
}
|
|
@@ -1641,53 +1915,36 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1641
1915
|
*/
|
|
1642
1916
|
async hydrateTempOrderFromRecord(record, options) {
|
|
1643
1917
|
const raw = record && typeof record === "object" && record.data && record.order_id == null ? record.data : record || {};
|
|
1644
|
-
const
|
|
1918
|
+
const nextTempOrder = this.normalizeTempOrderForRuntime(raw, {
|
|
1919
|
+
ensureIdentity: true
|
|
1920
|
+
});
|
|
1921
|
+
this.store.tempOrder = nextTempOrder;
|
|
1922
|
+
this.store.summary = raw.summary && typeof raw.summary === "object" ? { ...(0, import_utils.createEmptySummary)(), ...raw.summary } : (0, import_utils.createEmptySummary)();
|
|
1923
|
+
this.store.lastOrderInfo = raw.lastOrderInfo || raw;
|
|
1924
|
+
if (options == null ? void 0 : options.recalcOnHydrate) {
|
|
1925
|
+
await this.recalculateSummary({ createIfMissing: false });
|
|
1926
|
+
}
|
|
1927
|
+
this.persistTempOrder();
|
|
1928
|
+
return nextTempOrder;
|
|
1929
|
+
}
|
|
1930
|
+
normalizeTempOrderForRuntime(raw, options) {
|
|
1645
1931
|
const nextTempOrder = {
|
|
1646
|
-
...
|
|
1932
|
+
...this.createDefaultTempOrderInstance(),
|
|
1933
|
+
...raw || {}
|
|
1647
1934
|
};
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
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
|
-
});
|
|
1935
|
+
delete nextTempOrder.summary;
|
|
1936
|
+
delete nextTempOrder.lastOrderInfo;
|
|
1937
|
+
delete nextTempOrder.discount_list;
|
|
1938
|
+
delete nextTempOrder.shop_id;
|
|
1939
|
+
delete nextTempOrder.create_date;
|
|
1940
|
+
delete nextTempOrder.total_amount;
|
|
1941
|
+
delete nextTempOrder.expect_amount;
|
|
1942
|
+
delete nextTempOrder.paid_amount;
|
|
1943
|
+
delete nextTempOrder.shop_note;
|
|
1944
|
+
delete nextTempOrder.start_time;
|
|
1945
|
+
delete nextTempOrder.tax_fee;
|
|
1946
|
+
delete nextTempOrder.total_refund_amount;
|
|
1947
|
+
delete nextTempOrder.holder_id;
|
|
1691
1948
|
nextTempOrder.metadata = raw.metadata && typeof raw.metadata === "object" ? { ...raw.metadata } : {};
|
|
1692
1949
|
nextTempOrder.holder = raw.holder && typeof raw.holder === "object" ? { ...raw.holder } : null;
|
|
1693
1950
|
nextTempOrder.products = Array.isArray(raw.products) ? raw.products.map((p) => this.normalizeHydratedOrderProduct(p)) : [];
|
|
@@ -1698,7 +1955,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1698
1955
|
})) : [];
|
|
1699
1956
|
nextTempOrder.payments = Array.isArray(raw.payments) ? raw.payments.map((p) => ({ ...p || {} })) : [];
|
|
1700
1957
|
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
1958
|
nextTempOrder.relation_forms = Array.isArray(raw.relation_forms) ? raw.relation_forms.map((f) => ({ ...f || {} })) : [];
|
|
1703
1959
|
nextTempOrder.contacts = Array.isArray(raw.contacts) ? raw.contacts.map((c) => ({ ...c || {} })) : [];
|
|
1704
1960
|
nextTempOrder.contacts_info = raw.contacts_info && typeof raw.contacts_info === "object" && !Array.isArray(raw.contacts_info) ? { ...raw.contacts_info } : null;
|
|
@@ -1706,14 +1962,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1706
1962
|
...raw._extend,
|
|
1707
1963
|
productsByUid: raw._extend.productsByUid || {}
|
|
1708
1964
|
} : { 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 });
|
|
1965
|
+
if ((options == null ? void 0 : options.ensureIdentity) !== false) {
|
|
1966
|
+
this.ensureExternalSaleNumber(nextTempOrder);
|
|
1715
1967
|
}
|
|
1716
|
-
this.persistTempOrder();
|
|
1717
1968
|
return nextTempOrder;
|
|
1718
1969
|
}
|
|
1719
1970
|
normalizeHydratedOrderProduct(product) {
|
|
@@ -1732,6 +1983,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1732
1983
|
row.metadata.unique_identification_number = (0, import_utils.createUuidV4)();
|
|
1733
1984
|
}
|
|
1734
1985
|
const normalized = (0, import_utils3.normalizeOrderProduct)(row);
|
|
1986
|
+
normalized.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
|
|
1987
|
+
normalized.discount_list
|
|
1988
|
+
);
|
|
1735
1989
|
const result = {
|
|
1736
1990
|
...row,
|
|
1737
1991
|
...normalized,
|