@pisell/pisellos 2.2.96 → 2.2.98
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/walletPass/type.d.ts +2 -2
- package/dist/model/strategy/adapter/walletPass/utils.js +70 -57
- package/dist/server/modules/resource/index.d.ts +0 -5
- package/dist/server/modules/resource/index.js +186 -269
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/lib/model/strategy/adapter/walletPass/type.d.ts +2 -2
- package/lib/model/strategy/adapter/walletPass/utils.js +58 -51
- package/lib/server/modules/resource/index.d.ts +0 -5
- package/lib/server/modules/resource/index.js +60 -73
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -344,7 +344,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
344
344
|
};
|
|
345
345
|
setOtherData(key: string, value: any): void;
|
|
346
346
|
getOtherData(key: string): any;
|
|
347
|
-
getProductTypeById(id: number): Promise<"
|
|
347
|
+
getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
|
|
348
348
|
/**
|
|
349
349
|
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
350
350
|
*
|
|
@@ -131,7 +131,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
|
|
|
131
131
|
* 获取当前的客户搜索条件
|
|
132
132
|
* @returns 当前搜索条件
|
|
133
133
|
*/
|
|
134
|
-
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "
|
|
134
|
+
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
|
|
135
135
|
/**
|
|
136
136
|
* 获取客户列表状态(包含滚动加载相关状态)
|
|
137
137
|
* @returns 客户状态
|
|
@@ -41,7 +41,7 @@ export interface Voucher {
|
|
|
41
41
|
allowCrossProduct: boolean;
|
|
42
42
|
/** 可用商品数量上限 (仅多商品) 默认为0,表示不限制商品数量。 */
|
|
43
43
|
applicableProductLimit: number;
|
|
44
|
-
/** 单商品可用卡券上限(同一 Wallet Pass
|
|
44
|
+
/** 单商品可用卡券上限(同一 Wallet Pass 商品生成的卡券对同一商品的每个 unit 最多抵扣次数,总上限 = maxPassesPerItem × quantity)。默认为 0,表示不限制。 */
|
|
45
45
|
maxPassesPerItem: number;
|
|
46
46
|
};
|
|
47
47
|
}
|
|
@@ -129,7 +129,7 @@ export interface EvaluatorInput {
|
|
|
129
129
|
allowCrossProduct: boolean;
|
|
130
130
|
/** 可用商品数量上限 (仅多商品) 默认为0,表示不限制商品数量。 */
|
|
131
131
|
applicableProductLimit: number;
|
|
132
|
-
/** 单商品可用卡券上限(同一 Wallet Pass
|
|
132
|
+
/** 单商品可用卡券上限(同一 Wallet Pass 商品生成的卡券对同一商品的每个 unit 最多抵扣次数,总上限 = maxPassesPerItem × quantity)。默认为 0,表示不限制。 */
|
|
133
133
|
maxPassesPerItem: number;
|
|
134
134
|
}>[];
|
|
135
135
|
}
|
|
@@ -82,6 +82,9 @@ var getApplicableProducts = (voucher, productsData) => {
|
|
|
82
82
|
}
|
|
83
83
|
return productsData.filter((p) => applicableProductIds.includes(p.product_id));
|
|
84
84
|
};
|
|
85
|
+
var getTotalQuantityByProductId = (allProducts, productId) => {
|
|
86
|
+
return allProducts.filter((p) => p.product_id === productId).reduce((sum, p) => sum + getProductQuantity(p), 0);
|
|
87
|
+
};
|
|
85
88
|
function processVouchers(applicableVouchers, orderTotalAmount, products) {
|
|
86
89
|
console.log(products, "products123");
|
|
87
90
|
const productsCopy = expandProductsWithBundleItems(products, true);
|
|
@@ -90,18 +93,18 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
|
|
|
90
93
|
var _a;
|
|
91
94
|
return ((_a = usageMap.get(walletPassProductId)) == null ? void 0 : _a.get(orderItemProductId)) || 0;
|
|
92
95
|
};
|
|
93
|
-
const incrementItemPassUsage = (usageMap, walletPassProductId, orderItemProductId) => {
|
|
96
|
+
const incrementItemPassUsage = (usageMap, walletPassProductId, orderItemProductId, count = 1) => {
|
|
94
97
|
if (!usageMap.has(walletPassProductId)) {
|
|
95
98
|
usageMap.set(walletPassProductId, /* @__PURE__ */ new Map());
|
|
96
99
|
}
|
|
97
100
|
const innerMap = usageMap.get(walletPassProductId);
|
|
98
|
-
innerMap.set(orderItemProductId, (innerMap.get(orderItemProductId) || 0) +
|
|
101
|
+
innerMap.set(orderItemProductId, (innerMap.get(orderItemProductId) || 0) + count);
|
|
99
102
|
};
|
|
100
|
-
const filterByMaxPassesPerItem = (products2, usageMap, walletPassProductId, maxPassesPerItem) => {
|
|
103
|
+
const filterByMaxPassesPerItem = (products2, allProducts, usageMap, walletPassProductId, maxPassesPerItem) => {
|
|
101
104
|
if (maxPassesPerItem <= 0)
|
|
102
105
|
return products2;
|
|
103
106
|
return products2.filter(
|
|
104
|
-
(p) => getItemPassUsage(usageMap, walletPassProductId, p.product_id) < maxPassesPerItem
|
|
107
|
+
(p) => getItemPassUsage(usageMap, walletPassProductId, p.product_id) < maxPassesPerItem * getTotalQuantityByProductId(allProducts, p.product_id)
|
|
105
108
|
);
|
|
106
109
|
};
|
|
107
110
|
const calculateAvailableMaxAmount = (voucher, productsData, itemPassUsage) => {
|
|
@@ -116,7 +119,7 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
|
|
|
116
119
|
const amountField = deductTaxAndFee ? "remainingAmountWithTax" : "remainingAmountPure";
|
|
117
120
|
let applicableProducts = getApplicableProducts(voucher, productsData).filter((p) => p[amountField].greaterThan(0));
|
|
118
121
|
if (itemPassUsage) {
|
|
119
|
-
applicableProducts = filterByMaxPassesPerItem(applicableProducts, itemPassUsage, voucher.product_id, maxPassesPerItem);
|
|
122
|
+
applicableProducts = filterByMaxPassesPerItem(applicableProducts, productsData, itemPassUsage, voucher.product_id, maxPassesPerItem);
|
|
120
123
|
}
|
|
121
124
|
if (applicableProducts.length === 0) {
|
|
122
125
|
return new import_decimal.default(0);
|
|
@@ -146,14 +149,16 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
|
|
|
146
149
|
}
|
|
147
150
|
} else {
|
|
148
151
|
const maxProduct = applicableProducts.reduce(
|
|
149
|
-
(max, p) => p[
|
|
150
|
-
);
|
|
151
|
-
const currentAvailableQty = Math.ceil(maxProduct[amountField].dividedBy(maxProduct[unitPriceField]).toNumber());
|
|
152
|
-
const deductQty = applicableProductLimit > 0 ? Math.min(currentAvailableQty, applicableProductLimit) : currentAvailableQty;
|
|
153
|
-
finalApplicableAmount = import_decimal.default.min(
|
|
154
|
-
maxProduct[unitPriceField].times(deductQty),
|
|
155
|
-
maxProduct[amountField]
|
|
152
|
+
(max, p) => p[unitPriceField].greaterThan(max[unitPriceField]) ? p : max
|
|
156
153
|
);
|
|
154
|
+
if (maxPassesPerItem > 0) {
|
|
155
|
+
finalApplicableAmount = import_decimal.default.min(
|
|
156
|
+
maxProduct[unitPriceField].times(maxPassesPerItem),
|
|
157
|
+
maxProduct[amountField]
|
|
158
|
+
);
|
|
159
|
+
} else {
|
|
160
|
+
finalApplicableAmount = maxProduct[amountField];
|
|
161
|
+
}
|
|
157
162
|
}
|
|
158
163
|
return import_decimal.default.min(baseAmount, finalApplicableAmount, remainingOrderAmount);
|
|
159
164
|
};
|
|
@@ -180,7 +185,7 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
|
|
|
180
185
|
if (maxPassesPerItem > 0 && itemPassUsage) {
|
|
181
186
|
const deductTaxAndFee = (config == null ? void 0 : config.deductTaxAndFee) ?? true;
|
|
182
187
|
const amountField = deductTaxAndFee ? "remainingAmountWithTax" : "remainingAmountPure";
|
|
183
|
-
const availableAfterPassLimit = getApplicableProducts(voucher, productsData).filter((p) => p[amountField].greaterThan(0)).filter((p) => getItemPassUsage(itemPassUsage, product_id, p.product_id) < maxPassesPerItem);
|
|
188
|
+
const availableAfterPassLimit = getApplicableProducts(voucher, productsData).filter((p) => p[amountField].greaterThan(0)).filter((p) => getItemPassUsage(itemPassUsage, product_id, p.product_id) < maxPassesPerItem * getTotalQuantityByProductId(productsData, p.product_id));
|
|
184
189
|
if (availableAfterPassLimit.length === 0) {
|
|
185
190
|
return { isAvailable: false, reasonCode: "max_passes_per_item_reached" };
|
|
186
191
|
}
|
|
@@ -230,7 +235,7 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
|
|
|
230
235
|
voucher,
|
|
231
236
|
productsForRecommendation
|
|
232
237
|
).filter((p) => p[amountField].greaterThan(0));
|
|
233
|
-
applicableProducts = filterByMaxPassesPerItem(applicableProducts, itemPassUsageMap, product_id, maxPassesPerItem);
|
|
238
|
+
applicableProducts = filterByMaxPassesPerItem(applicableProducts, productsForRecommendation, itemPassUsageMap, product_id, maxPassesPerItem);
|
|
234
239
|
if (applicableProducts.length === 0)
|
|
235
240
|
return false;
|
|
236
241
|
const usageAmount = typeof voucher.edit_current_amount === "number" ? voucher.edit_current_amount : getRecommendedAmount(voucher);
|
|
@@ -263,14 +268,16 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
|
|
|
263
268
|
}
|
|
264
269
|
} else {
|
|
265
270
|
const maxProduct = applicableProducts.reduce(
|
|
266
|
-
(max, p) => p[
|
|
267
|
-
);
|
|
268
|
-
const currentAvailableQty = Math.ceil(maxProduct[amountField].dividedBy(maxProduct[unitPriceField]).toNumber());
|
|
269
|
-
const deductQty = applicableProductLimit > 0 ? Math.min(currentAvailableQty, applicableProductLimit) : currentAvailableQty;
|
|
270
|
-
calculatedAvailableMaxAmount = import_decimal.default.min(
|
|
271
|
-
maxProduct[unitPriceField].times(deductQty),
|
|
272
|
-
maxProduct[amountField]
|
|
271
|
+
(max, p) => p[unitPriceField].greaterThan(max[unitPriceField]) ? p : max
|
|
273
272
|
);
|
|
273
|
+
if (maxPassesPerItem > 0) {
|
|
274
|
+
calculatedAvailableMaxAmount = import_decimal.default.min(
|
|
275
|
+
maxProduct[unitPriceField].times(maxPassesPerItem),
|
|
276
|
+
maxProduct[amountField]
|
|
277
|
+
);
|
|
278
|
+
} else {
|
|
279
|
+
calculatedAvailableMaxAmount = maxProduct[amountField];
|
|
280
|
+
}
|
|
274
281
|
}
|
|
275
282
|
const availableMaxAmount = import_decimal.default.min(
|
|
276
283
|
baseAmount,
|
|
@@ -314,14 +321,15 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
|
|
|
314
321
|
}
|
|
315
322
|
} else {
|
|
316
323
|
const targetProduct = applicableProducts.reduce(
|
|
317
|
-
(max, p) => p[
|
|
318
|
-
);
|
|
319
|
-
const currentAvailableQty = Math.ceil(targetProduct[amountField].dividedBy(targetProduct[unitPriceField]).toNumber());
|
|
320
|
-
const availableQty = applicableProductLimit > 0 ? Math.min(currentAvailableQty, applicableProductLimit) : currentAvailableQty;
|
|
321
|
-
const maxDeductForProduct = import_decimal.default.min(
|
|
322
|
-
targetProduct[unitPriceField].times(availableQty),
|
|
323
|
-
targetProduct[amountField]
|
|
324
|
+
(max, p) => p[unitPriceField].greaterThan(max[unitPriceField]) ? p : max
|
|
324
325
|
);
|
|
326
|
+
let maxDeductForProduct = targetProduct[amountField];
|
|
327
|
+
if (maxPassesPerItem > 0) {
|
|
328
|
+
maxDeductForProduct = import_decimal.default.min(
|
|
329
|
+
targetProduct[unitPriceField].times(maxPassesPerItem),
|
|
330
|
+
targetProduct[amountField]
|
|
331
|
+
);
|
|
332
|
+
}
|
|
325
333
|
const actualDeductAmount = import_decimal.default.min(deductionLeft, maxDeductForProduct);
|
|
326
334
|
const actualDeductQty = Math.ceil(actualDeductAmount.dividedBy(targetProduct[unitPriceField]).toNumber());
|
|
327
335
|
targetProduct[amountField] = targetProduct[amountField].minus(actualDeductAmount);
|
|
@@ -331,9 +339,7 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
|
|
|
331
339
|
parent_product_id: targetProduct.parent_product_id || null,
|
|
332
340
|
is_bundle_item: targetProduct.is_bundle_item || false,
|
|
333
341
|
deductAmount: actualDeductAmount.toNumber(),
|
|
334
|
-
// 转换为数字
|
|
335
342
|
deductQuantity: actualDeductQty
|
|
336
|
-
// 抵扣涉及的数量(用于记录)
|
|
337
343
|
});
|
|
338
344
|
}
|
|
339
345
|
const totalDeducted = maxDeduction.minus(deductionLeft);
|
|
@@ -341,7 +347,7 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
|
|
|
341
347
|
remainingOrderAmount = remainingOrderAmount.minus(totalDeducted);
|
|
342
348
|
usedVoucherCounts.set(product_id, (usedVoucherCounts.get(product_id) || 0) + 1);
|
|
343
349
|
deductionDetails.forEach((detail) => {
|
|
344
|
-
incrementItemPassUsage(itemPassUsageMap, product_id, detail.product_id);
|
|
350
|
+
incrementItemPassUsage(itemPassUsageMap, product_id, detail.product_id, detail.deductQuantity);
|
|
345
351
|
});
|
|
346
352
|
recommendedVouchers.push({
|
|
347
353
|
...voucher,
|
|
@@ -389,18 +395,18 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
|
|
|
389
395
|
var _a;
|
|
390
396
|
return ((_a = itemPassUsageMap.get(walletPassProductId)) == null ? void 0 : _a.get(orderItemProductId)) || 0;
|
|
391
397
|
};
|
|
392
|
-
const incrementItemPassUsage = (walletPassProductId, orderItemProductId) => {
|
|
398
|
+
const incrementItemPassUsage = (walletPassProductId, orderItemProductId, count = 1) => {
|
|
393
399
|
if (!itemPassUsageMap.has(walletPassProductId)) {
|
|
394
400
|
itemPassUsageMap.set(walletPassProductId, /* @__PURE__ */ new Map());
|
|
395
401
|
}
|
|
396
402
|
const innerMap = itemPassUsageMap.get(walletPassProductId);
|
|
397
|
-
innerMap.set(orderItemProductId, (innerMap.get(orderItemProductId) || 0) +
|
|
403
|
+
innerMap.set(orderItemProductId, (innerMap.get(orderItemProductId) || 0) + count);
|
|
398
404
|
};
|
|
399
405
|
const filterByMaxPassesPerItem = (products2, walletPassProductId, maxPassesPerItem) => {
|
|
400
406
|
if (maxPassesPerItem <= 0)
|
|
401
407
|
return products2;
|
|
402
408
|
return products2.filter(
|
|
403
|
-
(p) => getItemPassUsage(walletPassProductId, p.product_id) < maxPassesPerItem
|
|
409
|
+
(p) => getItemPassUsage(walletPassProductId, p.product_id) < maxPassesPerItem * getTotalQuantityByProductId(productsForCalc, p.product_id)
|
|
404
410
|
);
|
|
405
411
|
};
|
|
406
412
|
selectedVouchers.forEach((selectedVoucher) => {
|
|
@@ -463,14 +469,15 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
|
|
|
463
469
|
}
|
|
464
470
|
} else {
|
|
465
471
|
const targetProduct = applicableProducts.reduce(
|
|
466
|
-
(max, p) => p[
|
|
467
|
-
);
|
|
468
|
-
const currentAvailableQty = Math.ceil(targetProduct[amountField].dividedBy(targetProduct[unitPriceField]).toNumber());
|
|
469
|
-
const availableQty = applicableProductLimit > 0 ? Math.min(currentAvailableQty, applicableProductLimit) : currentAvailableQty;
|
|
470
|
-
const maxDeductForProduct = import_decimal.default.min(
|
|
471
|
-
targetProduct[unitPriceField].times(availableQty),
|
|
472
|
-
targetProduct[amountField]
|
|
472
|
+
(max, p) => p[unitPriceField].greaterThan(max[unitPriceField]) ? p : max
|
|
473
473
|
);
|
|
474
|
+
let maxDeductForProduct = targetProduct[amountField];
|
|
475
|
+
if (maxPassesPerItem > 0) {
|
|
476
|
+
maxDeductForProduct = import_decimal.default.min(
|
|
477
|
+
targetProduct[unitPriceField].times(maxPassesPerItem),
|
|
478
|
+
targetProduct[amountField]
|
|
479
|
+
);
|
|
480
|
+
}
|
|
474
481
|
const actualDeductAmount = import_decimal.default.min(deductionLeft, maxDeductForProduct);
|
|
475
482
|
const actualDeductQty = Math.ceil(actualDeductAmount.dividedBy(targetProduct[unitPriceField]).toNumber());
|
|
476
483
|
targetProduct[amountField] = targetProduct[amountField].minus(actualDeductAmount);
|
|
@@ -480,15 +487,13 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
|
|
|
480
487
|
parent_product_id: targetProduct.parent_product_id || null,
|
|
481
488
|
is_bundle_item: targetProduct.is_bundle_item || false,
|
|
482
489
|
deductAmount: actualDeductAmount.toNumber(),
|
|
483
|
-
// 转换为数字
|
|
484
490
|
deductQuantity: actualDeductQty
|
|
485
|
-
// 抵扣涉及的数量(用于记录)
|
|
486
491
|
});
|
|
487
492
|
}
|
|
488
493
|
const totalDeducted = maxDeduction.minus(deductionLeft);
|
|
489
494
|
remainingOrderAmount = remainingOrderAmount.minus(totalDeducted);
|
|
490
495
|
deductionDetails.forEach((detail) => {
|
|
491
|
-
incrementItemPassUsage(selectedVoucher.product_id, detail.product_id);
|
|
496
|
+
incrementItemPassUsage(selectedVoucher.product_id, detail.product_id, detail.deductQuantity);
|
|
492
497
|
});
|
|
493
498
|
selectedWithDetails.push({
|
|
494
499
|
...selectedVoucher,
|
|
@@ -572,14 +577,16 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
|
|
|
572
577
|
}
|
|
573
578
|
} else {
|
|
574
579
|
const maxProduct = applicableProducts.reduce(
|
|
575
|
-
(max, p) => p[
|
|
576
|
-
);
|
|
577
|
-
const currentAvailableQty = Math.ceil(maxProduct[amountField].dividedBy(maxProduct[unitPriceField]).toNumber());
|
|
578
|
-
const deductQty = applicableProductLimit > 0 ? Math.min(currentAvailableQty, applicableProductLimit) : currentAvailableQty;
|
|
579
|
-
calculatedMaxAmount = import_decimal.default.min(
|
|
580
|
-
maxProduct[unitPriceField].times(deductQty),
|
|
581
|
-
maxProduct[amountField]
|
|
580
|
+
(max, p) => p[unitPriceField].greaterThan(max[unitPriceField]) ? p : max
|
|
582
581
|
);
|
|
582
|
+
if (maxPassesPerItem > 0) {
|
|
583
|
+
calculatedMaxAmount = import_decimal.default.min(
|
|
584
|
+
maxProduct[unitPriceField].times(maxPassesPerItem),
|
|
585
|
+
maxProduct[amountField]
|
|
586
|
+
);
|
|
587
|
+
} else {
|
|
588
|
+
calculatedMaxAmount = maxProduct[amountField];
|
|
589
|
+
}
|
|
583
590
|
}
|
|
584
591
|
calculatedMaxAmount = import_decimal.default.min(
|
|
585
592
|
baseAmount,
|
|
@@ -50,15 +50,12 @@ export declare class ResourceModule extends BaseModule implements Module {
|
|
|
50
50
|
/**
|
|
51
51
|
* 创建预订
|
|
52
52
|
*/
|
|
53
|
-
createBooking(booking: Partial<ResourceBooking>): ResourceBooking;
|
|
54
53
|
/**
|
|
55
54
|
* 更新预订
|
|
56
55
|
*/
|
|
57
|
-
updateBooking(id: ResourceId, data: Partial<ResourceBooking>): ResourceBooking | undefined;
|
|
58
56
|
/**
|
|
59
57
|
* 删除预订
|
|
60
58
|
*/
|
|
61
|
-
deleteBooking(id: ResourceId): boolean;
|
|
62
59
|
/**
|
|
63
60
|
* 清空缓存
|
|
64
61
|
*/
|
|
@@ -73,8 +70,6 @@ export declare class ResourceModule extends BaseModule implements Module {
|
|
|
73
70
|
private loadResourcesByServer;
|
|
74
71
|
private loadResourcesFromSQLite;
|
|
75
72
|
private saveResourcesToSQLite;
|
|
76
|
-
private loadBookingsFromSQLite;
|
|
77
|
-
private saveBookingsToSQLite;
|
|
78
73
|
private initResourceDataSource;
|
|
79
74
|
private setupResourceSync;
|
|
80
75
|
private processSyncMessages;
|
|
@@ -29,7 +29,6 @@ var import_BaseModule = require("../../../modules/BaseModule");
|
|
|
29
29
|
var import_types = require("./types");
|
|
30
30
|
var import_types2 = require("./types");
|
|
31
31
|
var RESOURCE_STORE_NAME = "resources";
|
|
32
|
-
var BOOKING_STORE_NAME = "resource_bookings";
|
|
33
32
|
var DEFAULT_PAGE_SIZE = 999;
|
|
34
33
|
var RESOURCE_SYNC_DEBOUNCE_MS = 1e4;
|
|
35
34
|
var ResourceModule = class extends import_BaseModule.BaseModule {
|
|
@@ -103,11 +102,6 @@ var ResourceModule = class extends import_BaseModule.BaseModule {
|
|
|
103
102
|
await this.safeEmit(import_types.ResourceHooks.onResourcesChanged, this.store.list);
|
|
104
103
|
}
|
|
105
104
|
}
|
|
106
|
-
const cachedBookings = await this.loadBookingsFromSQLite();
|
|
107
|
-
if (cachedBookings.length > 0) {
|
|
108
|
-
this.store.bookings = (0, import_lodash_es.cloneDeep)(cachedBookings);
|
|
109
|
-
this.syncBookingsIndex();
|
|
110
|
-
}
|
|
111
105
|
}
|
|
112
106
|
getRoutes() {
|
|
113
107
|
return [];
|
|
@@ -205,54 +199,49 @@ var ResourceModule = class extends import_BaseModule.BaseModule {
|
|
|
205
199
|
/**
|
|
206
200
|
* 创建预订
|
|
207
201
|
*/
|
|
208
|
-
createBooking(booking) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
202
|
+
// createBooking(booking: Partial<ResourceBooking>): ResourceBooking {
|
|
203
|
+
// const id = booking?.id ?? Date.now()
|
|
204
|
+
// const normalized: ResourceBooking = {
|
|
205
|
+
// id,
|
|
206
|
+
// ...booking,
|
|
207
|
+
// } as ResourceBooking
|
|
208
|
+
// this.store.bookings.push(normalized)
|
|
209
|
+
// const rid = normalized.resource_id ?? normalized.resourceId
|
|
210
|
+
// if (rid !== undefined) {
|
|
211
|
+
// const existing = this.resourceIdIndex.get(rid) || []
|
|
212
|
+
// existing.push(normalized)
|
|
213
|
+
// this.resourceIdIndex.set(rid, existing)
|
|
214
|
+
// }
|
|
215
|
+
// this.saveBookingsToSQLite(this.store.bookings).catch(() => {})
|
|
216
|
+
// this.safeEmit(ResourceHooks.onBookingsChanged, this.store.bookings)
|
|
217
|
+
// return normalized
|
|
218
|
+
// }
|
|
226
219
|
/**
|
|
227
220
|
* 更新预订
|
|
228
221
|
*/
|
|
229
|
-
updateBooking(id, data) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
return updated;
|
|
241
|
-
}
|
|
222
|
+
// updateBooking(id: ResourceId, data: Partial<ResourceBooking>): ResourceBooking | undefined {
|
|
223
|
+
// const index = this.store.bookings.findIndex(b => this.getIdKey(b.id) === this.getIdKey(id))
|
|
224
|
+
// if (index === -1) return undefined
|
|
225
|
+
// const old = this.store.bookings[index]
|
|
226
|
+
// const updated: ResourceBooking = { ...old, ...data, id: old.id } as ResourceBooking
|
|
227
|
+
// this.store.bookings[index] = updated
|
|
228
|
+
// this.rebuildBookingsIndex()
|
|
229
|
+
// this.saveBookingsToSQLite(this.store.bookings).catch(() => {})
|
|
230
|
+
// this.safeEmit(ResourceHooks.onBookingsChanged, this.store.bookings)
|
|
231
|
+
// return updated
|
|
232
|
+
// }
|
|
242
233
|
/**
|
|
243
234
|
* 删除预订
|
|
244
235
|
*/
|
|
245
|
-
deleteBooking(id) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
return true;
|
|
255
|
-
}
|
|
236
|
+
// deleteBooking(id: ResourceId): boolean {
|
|
237
|
+
// const index = this.store.bookings.findIndex(b => this.getIdKey(b.id) === this.getIdKey(id))
|
|
238
|
+
// if (index === -1) return false
|
|
239
|
+
// this.store.bookings.splice(index, 1)
|
|
240
|
+
// this.rebuildBookingsIndex()
|
|
241
|
+
// this.saveBookingsToSQLite(this.store.bookings).catch(() => {})
|
|
242
|
+
// this.safeEmit(ResourceHooks.onBookingsChanged, this.store.bookings)
|
|
243
|
+
// return true
|
|
244
|
+
// }
|
|
256
245
|
/**
|
|
257
246
|
* 清空缓存
|
|
258
247
|
*/
|
|
@@ -396,31 +385,29 @@ var ResourceModule = class extends import_BaseModule.BaseModule {
|
|
|
396
385
|
});
|
|
397
386
|
}
|
|
398
387
|
}
|
|
399
|
-
async loadBookingsFromSQLite() {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
}
|
|
423
|
-
}
|
|
388
|
+
// private async loadBookingsFromSQLite(): Promise<ResourceBooking[]> {
|
|
389
|
+
// if (!this.dbManager) return []
|
|
390
|
+
// try {
|
|
391
|
+
// const bookings = await this.dbManager.getAll(BOOKING_STORE_NAME)
|
|
392
|
+
// return bookings || []
|
|
393
|
+
// } catch {
|
|
394
|
+
// return []
|
|
395
|
+
// }
|
|
396
|
+
// }
|
|
397
|
+
// private async saveBookingsToSQLite(bookings: ResourceBooking[]): Promise<void> {
|
|
398
|
+
// if (!this.dbManager) return
|
|
399
|
+
// try {
|
|
400
|
+
// await this.dbManager.clear(BOOKING_STORE_NAME)
|
|
401
|
+
// if (bookings.length === 0) return
|
|
402
|
+
// if (this.dbManager.bulkAdd) {
|
|
403
|
+
// await this.dbManager.bulkAdd(BOOKING_STORE_NAME, bookings)
|
|
404
|
+
// return
|
|
405
|
+
// }
|
|
406
|
+
// await Promise.all(bookings.map(b => this.dbManager.add(BOOKING_STORE_NAME, b)))
|
|
407
|
+
// } catch {
|
|
408
|
+
// // 忽略 SQLite 异常
|
|
409
|
+
// }
|
|
410
|
+
// }
|
|
424
411
|
// ─────────────────────────────────────────────────────────────────
|
|
425
412
|
// pubsub 同步
|
|
426
413
|
// ─────────────────────────────────────────────────────────────────
|
|
@@ -344,7 +344,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
344
344
|
};
|
|
345
345
|
setOtherData(key: string, value: any): void;
|
|
346
346
|
getOtherData(key: string): any;
|
|
347
|
-
getProductTypeById(id: number): Promise<"
|
|
347
|
+
getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
|
|
348
348
|
/**
|
|
349
349
|
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
350
350
|
*
|
|
@@ -131,7 +131,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
|
|
|
131
131
|
* 获取当前的客户搜索条件
|
|
132
132
|
* @returns 当前搜索条件
|
|
133
133
|
*/
|
|
134
|
-
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "
|
|
134
|
+
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
|
|
135
135
|
/**
|
|
136
136
|
* 获取客户列表状态(包含滚动加载相关状态)
|
|
137
137
|
* @returns 客户状态
|