@pisell/pisellos 0.0.355 → 0.0.356
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/Product/index.d.ts +1 -1
- package/dist/modules/Rules/index.js +16 -9
- package/dist/modules/Rules/types.d.ts +1 -0
- package/dist/solution/BookingByStep/index.js +1 -0
- package/dist/solution/ShopDiscount/index.d.ts +0 -2
- package/dist/solution/ShopDiscount/index.js +123 -155
- package/dist/solution/ShopDiscount/utils.js +160 -42
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Rules/index.js +9 -1
- package/lib/modules/Rules/types.d.ts +1 -0
- package/lib/solution/BookingByStep/index.js +4 -0
- package/lib/solution/BookingTicket/index.js +0 -6
- package/lib/solution/ShopDiscount/index.d.ts +0 -2
- package/lib/solution/ShopDiscount/index.js +25 -21
- package/lib/solution/ShopDiscount/utils.js +81 -13
- package/package.json +1 -1
|
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
|
|
|
49
49
|
getCategories(): ProductCategory[];
|
|
50
50
|
setOtherParams(key: string, value: any): void;
|
|
51
51
|
getOtherParams(): any;
|
|
52
|
-
getProductType(): "
|
|
52
|
+
getProductType(): "normal" | "duration" | "session";
|
|
53
53
|
}
|
|
@@ -24,10 +24,11 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
24
24
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
25
25
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
26
26
|
import { BaseModule } from "../BaseModule";
|
|
27
|
-
import { uniqueById, getDiscountAmount, getDiscountListAmountTotal, getDiscountListAmount } from "../../solution/ShopDiscount/utils";
|
|
27
|
+
import { uniqueById, getDiscountAmount, getDiscountListAmountTotal, getDiscountListAmount, filterDiscountListByBookingTime } from "../../solution/ShopDiscount/utils";
|
|
28
28
|
import { getProductOriginTotalPrice, getProductTotalPrice } from "../Cart/utils";
|
|
29
29
|
import Decimal from 'decimal.js';
|
|
30
30
|
import { isBoolean } from 'lodash-es';
|
|
31
|
+
import dayjs from 'dayjs';
|
|
31
32
|
export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
32
33
|
_inherits(RulesModule, _BaseModule);
|
|
33
34
|
var _super = _createSuper(RulesModule);
|
|
@@ -400,19 +401,20 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
400
401
|
originProduct = flatItem.originProduct;
|
|
401
402
|
}
|
|
402
403
|
addModeDiscount.forEach(function (discount) {
|
|
403
|
-
var _product, _product2, _product3, _flatItem$bundleItem;
|
|
404
|
+
var _product, _product2, _product3, _product4, _flatItem$bundleItem;
|
|
404
405
|
var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
|
|
405
|
-
|
|
406
|
+
var timeLimit = true;
|
|
407
|
+
timeLimit = !!filterDiscountListByBookingTime([discount], (((_product = product) === null || _product === void 0 ? void 0 : _product.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
|
|
406
408
|
// 是符合折扣的商品
|
|
407
409
|
var isLimitedProduct = limitedData.type === 'product_all' || limitedData.product_ids && limitedData.product_ids.includes(product.id);
|
|
408
410
|
|
|
409
411
|
// 编辑的商品 使用了优惠券不可用
|
|
410
|
-
var isAvailableProduct = flatItem.type === 'main' ? !((
|
|
412
|
+
var isAvailableProduct = flatItem.type === 'main' ? !((_product2 = product) !== null && _product2 !== void 0 && _product2.booking_id && (_product3 = product) !== null && _product3 !== void 0 && (_product3 = _product3.discount_list) !== null && _product3 !== void 0 && _product3.length && (_product4 = product) !== null && _product4 !== void 0 && (_product4 = _product4.discount_list) !== null && _product4 !== void 0 && _product4.every(function (discount) {
|
|
411
413
|
return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
|
|
412
414
|
})) : !(flatItem !== null && flatItem !== void 0 && flatItem.booking_id && flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem = flatItem.bundleItem) !== null && _flatItem$bundleItem !== void 0 && (_flatItem$bundleItem = _flatItem$bundleItem.metadata) !== null && _flatItem$bundleItem !== void 0 && _flatItem$bundleItem.custom_product_bundle_map_id);
|
|
413
415
|
|
|
414
416
|
// 判断优惠券是否适用于该商品
|
|
415
|
-
if (isAvailableProduct && isLimitedProduct) {
|
|
417
|
+
if (isAvailableProduct && isLimitedProduct && timeLimit) {
|
|
416
418
|
var _discountApplicabilit, _discount$metadata;
|
|
417
419
|
// 记录此优惠券适用的商品
|
|
418
420
|
(_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
|
|
@@ -451,7 +453,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
451
453
|
// 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
|
|
452
454
|
// 🔥 使用扁平化后的列表进行处理
|
|
453
455
|
sortedFlattenedList.forEach(function (flatItem, index) {
|
|
454
|
-
var
|
|
456
|
+
var _product5, _product$discount_lis2, _product6;
|
|
455
457
|
// 获取商品数据
|
|
456
458
|
var product, originProduct;
|
|
457
459
|
if (flatItem.type === 'main') {
|
|
@@ -476,7 +478,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
476
478
|
}
|
|
477
479
|
|
|
478
480
|
// 已有优惠的商品跳过
|
|
479
|
-
if ((
|
|
481
|
+
if ((_product5 = product) !== null && _product5 !== void 0 && _product5.booking_id && (_product$discount_lis2 = product.discount_list) !== null && _product$discount_lis2 !== void 0 && _product$discount_lis2.length && (_product6 = product) !== null && _product6 !== void 0 && (_product6 = _product6.discount_list) !== null && _product6 !== void 0 && _product6.every(function (discount) {
|
|
480
482
|
return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
|
|
481
483
|
})) {
|
|
482
484
|
if (flatItem.type === 'main') {
|
|
@@ -505,6 +507,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
505
507
|
var targetUsedDiscounts = usedDiscounts.get(discount.id);
|
|
506
508
|
if (targetUsedDiscounts && (discount.tag || discount.type) === 'good_pass') return false;
|
|
507
509
|
var limitedData = discount.limited_relation_product_data;
|
|
510
|
+
var timeLimit = true;
|
|
511
|
+
timeLimit = !!filterDiscountListByBookingTime([discount], (product.startDate || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
|
|
512
|
+
if (!timeLimit) {
|
|
513
|
+
return false;
|
|
514
|
+
}
|
|
508
515
|
|
|
509
516
|
// 判断优惠券是否适用于该商品
|
|
510
517
|
if (limitedData.type === 'product_all') {
|
|
@@ -534,12 +541,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
534
541
|
// 如果是手动折扣,则不适用优惠券
|
|
535
542
|
var isManualDiscount = false;
|
|
536
543
|
if (flatItem.type === 'main') {
|
|
537
|
-
var _product$discount_lis4,
|
|
544
|
+
var _product$discount_lis4, _product7, _product7$every;
|
|
538
545
|
// 主商品:判断自身是否手动折扣
|
|
539
546
|
isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(function (item) {
|
|
540
547
|
var _ref3;
|
|
541
548
|
return !((_ref3 = item.discount_list || []) !== null && _ref3 !== void 0 && _ref3.length);
|
|
542
|
-
}) && (!((_product$discount_lis4 = product.discount_list) !== null && _product$discount_lis4 !== void 0 && _product$discount_lis4.length) || ((
|
|
549
|
+
}) && (!((_product$discount_lis4 = product.discount_list) !== null && _product$discount_lis4 !== void 0 && _product$discount_lis4.length) || ((_product7 = product) === null || _product7 === void 0 || (_product7 = _product7.discount_list) === null || _product7 === void 0 || (_product7$every = _product7.every) === null || _product7$every === void 0 ? void 0 : _product7$every.call(_product7, function (item) {
|
|
543
550
|
return item.type === 'product';
|
|
544
551
|
})));
|
|
545
552
|
} else {
|
|
@@ -18,10 +18,8 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
18
18
|
private initializePlugins;
|
|
19
19
|
private registerDependentModules;
|
|
20
20
|
private registerEventListeners;
|
|
21
|
-
setBookingTime(bookingTime: string | null): Promise<void>;
|
|
22
21
|
getCurrentBookingTime(): string | null;
|
|
23
22
|
private filterDiscountListByBookingTime;
|
|
24
|
-
private updateFilteredDiscountList;
|
|
25
23
|
setCustomer(customer: Customer): Promise<void>;
|
|
26
24
|
calcDiscount(productList: Record<string, any>[], options?: SetDiscountSelectedParams): {
|
|
27
25
|
productList: Record<string, any>[];
|
|
@@ -25,7 +25,6 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
25
25
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
26
26
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
27
27
|
import { BaseModule } from "../../modules/BaseModule";
|
|
28
|
-
import { ShopDiscountHooks } from "./types";
|
|
29
28
|
import { DiscountModule } from "../../modules/Discount";
|
|
30
29
|
import { RulesModule } from "../../modules/Rules";
|
|
31
30
|
import { filterDiscountListByBookingTime as _filterDiscountListByBookingTime, isAllNormalProduct } from "./utils";
|
|
@@ -212,33 +211,16 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
212
211
|
// =========== 公共 API ===========
|
|
213
212
|
|
|
214
213
|
// 设置预约时间
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
_context4.next = 4;
|
|
224
|
-
break;
|
|
225
|
-
}
|
|
226
|
-
this.store.currentBookingTime = bookingTime;
|
|
214
|
+
// public async setBookingTime(bookingTime: string | null): Promise<void> {
|
|
215
|
+
// if (this.store.currentBookingTime !== bookingTime) {
|
|
216
|
+
// this.store.currentBookingTime = bookingTime;
|
|
217
|
+
//
|
|
218
|
+
// // 更新过滤后的优惠券列表
|
|
219
|
+
// await this.updateFilteredDiscountList();
|
|
220
|
+
// }
|
|
221
|
+
// }
|
|
227
222
|
|
|
228
|
-
|
|
229
|
-
_context4.next = 4;
|
|
230
|
-
return this.updateFilteredDiscountList();
|
|
231
|
-
case 4:
|
|
232
|
-
case "end":
|
|
233
|
-
return _context4.stop();
|
|
234
|
-
}
|
|
235
|
-
}, _callee4, this);
|
|
236
|
-
}));
|
|
237
|
-
function setBookingTime(_x3) {
|
|
238
|
-
return _setBookingTime.apply(this, arguments);
|
|
239
|
-
}
|
|
240
|
-
return setBookingTime;
|
|
241
|
-
}() // 获取当前预约时间
|
|
223
|
+
// 获取当前预约时间
|
|
242
224
|
}, {
|
|
243
225
|
key: "getCurrentBookingTime",
|
|
244
226
|
value: function getCurrentBookingTime() {
|
|
@@ -259,61 +241,47 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
259
241
|
}
|
|
260
242
|
|
|
261
243
|
// 更新过滤后的优惠券列表
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
244
|
+
// private async updateFilteredDiscountList(): Promise<void> {
|
|
245
|
+
// const originalList = this.store.originalDiscountList;
|
|
246
|
+
// const filteredList = this.filterDiscountListByBookingTime(originalList, this.store.currentBookingTime);
|
|
247
|
+
//
|
|
248
|
+
// this.store.filteredDiscountList = filteredList;
|
|
249
|
+
//
|
|
250
|
+
// // 更新 DiscountModule 中的优惠券列表
|
|
251
|
+
// this.setDiscountList(filteredList);
|
|
252
|
+
//
|
|
253
|
+
// if (this.store.productList?.length) {
|
|
254
|
+
// const result = this.calcDiscount(this.store.productList);
|
|
255
|
+
// await this.core.effects.emit(
|
|
256
|
+
// ShopDiscountHooks.onLoadPrepareCalcResult,
|
|
257
|
+
// result,
|
|
258
|
+
// );
|
|
259
|
+
// }
|
|
260
|
+
// }
|
|
274
261
|
|
|
275
|
-
|
|
276
|
-
this.setDiscountList(filteredList);
|
|
277
|
-
if (!((_this$store$productLi = this.store.productList) !== null && _this$store$productLi !== void 0 && _this$store$productLi.length)) {
|
|
278
|
-
_context5.next = 8;
|
|
279
|
-
break;
|
|
280
|
-
}
|
|
281
|
-
_result = this.calcDiscount(this.store.productList);
|
|
282
|
-
_context5.next = 8;
|
|
283
|
-
return this.core.effects.emit(ShopDiscountHooks.onLoadPrepareCalcResult, _result);
|
|
284
|
-
case 8:
|
|
285
|
-
case "end":
|
|
286
|
-
return _context5.stop();
|
|
287
|
-
}
|
|
288
|
-
}, _callee5, this);
|
|
289
|
-
}));
|
|
290
|
-
function updateFilteredDiscountList() {
|
|
291
|
-
return _updateFilteredDiscountList.apply(this, arguments);
|
|
292
|
-
}
|
|
293
|
-
return updateFilteredDiscountList;
|
|
294
|
-
}() // 设置客户
|
|
262
|
+
// 设置客户
|
|
295
263
|
}, {
|
|
296
264
|
key: "setCustomer",
|
|
297
265
|
value: function () {
|
|
298
|
-
var _setCustomer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
266
|
+
var _setCustomer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(customer) {
|
|
299
267
|
var _this$store$customer;
|
|
300
|
-
return _regeneratorRuntime().wrap(function
|
|
301
|
-
while (1) switch (
|
|
268
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
269
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
302
270
|
case 0:
|
|
303
271
|
if (!(((_this$store$customer = this.store.customer) === null || _this$store$customer === void 0 ? void 0 : _this$store$customer.id) !== customer.id)) {
|
|
304
|
-
|
|
272
|
+
_context4.next = 4;
|
|
305
273
|
break;
|
|
306
274
|
}
|
|
307
275
|
this.store.customer = customer;
|
|
308
|
-
|
|
276
|
+
_context4.next = 4;
|
|
309
277
|
return this.core.effects.emit("".concat(this.name, ":onCustomerChange"), customer);
|
|
310
278
|
case 4:
|
|
311
279
|
case "end":
|
|
312
|
-
return
|
|
280
|
+
return _context4.stop();
|
|
313
281
|
}
|
|
314
|
-
},
|
|
282
|
+
}, _callee4, this);
|
|
315
283
|
}));
|
|
316
|
-
function setCustomer(
|
|
284
|
+
function setCustomer(_x3) {
|
|
317
285
|
return _setCustomer.apply(this, arguments);
|
|
318
286
|
}
|
|
319
287
|
return setCustomer;
|
|
@@ -403,29 +371,29 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
403
371
|
}, {
|
|
404
372
|
key: "scanCode",
|
|
405
373
|
value: function () {
|
|
406
|
-
var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
374
|
+
var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(code, customerId) {
|
|
407
375
|
var _this$store$discount3, resultDiscountList, rulesModule, withScanList, currentSelectedDiscountList, _ref2, newProductList, newDiscountList, isAvailable, _this$options$otherPa6;
|
|
408
|
-
return _regeneratorRuntime().wrap(function
|
|
409
|
-
while (1) switch (
|
|
376
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
377
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
410
378
|
case 0:
|
|
411
|
-
|
|
412
|
-
|
|
379
|
+
_context5.prev = 0;
|
|
380
|
+
_context5.next = 3;
|
|
413
381
|
return (_this$store$discount3 = this.store.discount) === null || _this$store$discount3 === void 0 ? void 0 : _this$store$discount3.batchSearch(code, customerId);
|
|
414
382
|
case 3:
|
|
415
|
-
|
|
416
|
-
if (
|
|
417
|
-
|
|
383
|
+
_context5.t0 = _context5.sent;
|
|
384
|
+
if (_context5.t0) {
|
|
385
|
+
_context5.next = 6;
|
|
418
386
|
break;
|
|
419
387
|
}
|
|
420
|
-
|
|
388
|
+
_context5.t0 = [];
|
|
421
389
|
case 6:
|
|
422
|
-
resultDiscountList =
|
|
390
|
+
resultDiscountList = _context5.t0;
|
|
423
391
|
rulesModule = this.store.rules;
|
|
424
392
|
if (rulesModule) {
|
|
425
|
-
|
|
393
|
+
_context5.next = 10;
|
|
426
394
|
break;
|
|
427
395
|
}
|
|
428
|
-
return
|
|
396
|
+
return _context5.abrupt("return", {
|
|
429
397
|
type: "clientCalc",
|
|
430
398
|
isAvailable: false,
|
|
431
399
|
productList: this.store.productList || [],
|
|
@@ -433,10 +401,10 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
433
401
|
});
|
|
434
402
|
case 10:
|
|
435
403
|
if (resultDiscountList.length) {
|
|
436
|
-
|
|
404
|
+
_context5.next = 12;
|
|
437
405
|
break;
|
|
438
406
|
}
|
|
439
|
-
return
|
|
407
|
+
return _context5.abrupt("return", {
|
|
440
408
|
type: "server",
|
|
441
409
|
isAvailable: false,
|
|
442
410
|
productList: this.store.productList || [],
|
|
@@ -456,10 +424,10 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
456
424
|
return m.id === n.id;
|
|
457
425
|
});
|
|
458
426
|
}))) {
|
|
459
|
-
|
|
427
|
+
_context5.next = 16;
|
|
460
428
|
break;
|
|
461
429
|
}
|
|
462
|
-
return
|
|
430
|
+
return _context5.abrupt("return", {
|
|
463
431
|
type: "clientCalc",
|
|
464
432
|
isAvailable: true,
|
|
465
433
|
productList: this.store.productList || [],
|
|
@@ -476,30 +444,30 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
476
444
|
discountList: this.getDiscountList()
|
|
477
445
|
}, newProductList = _ref2.productList, newDiscountList = _ref2.discountList, isAvailable = _ref2.isAvailable;
|
|
478
446
|
if (!isAvailable) {
|
|
479
|
-
|
|
447
|
+
_context5.next = 24;
|
|
480
448
|
break;
|
|
481
449
|
}
|
|
482
450
|
this.setDiscountList(newDiscountList || []);
|
|
483
451
|
this.store.originalDiscountList = newDiscountList || [];
|
|
484
452
|
this.setProductList(newProductList || []);
|
|
485
453
|
if (!(this.isWalkIn() && resultDiscountList.length && ((_this$options$otherPa6 = this.options.otherParams) === null || _this$options$otherPa6 === void 0 ? void 0 : _this$options$otherPa6.platform) === 'shop')) {
|
|
486
|
-
|
|
454
|
+
_context5.next = 24;
|
|
487
455
|
break;
|
|
488
456
|
}
|
|
489
|
-
|
|
457
|
+
_context5.next = 24;
|
|
490
458
|
return this.getCustomerWallet(resultDiscountList[0].customer_id);
|
|
491
459
|
case 24:
|
|
492
|
-
return
|
|
460
|
+
return _context5.abrupt("return", {
|
|
493
461
|
type: "clientCalc",
|
|
494
462
|
isAvailable: isAvailable || false,
|
|
495
463
|
productList: newProductList || this.store.productList || [],
|
|
496
464
|
discountList: newDiscountList || this.getDiscountList()
|
|
497
465
|
});
|
|
498
466
|
case 27:
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
console.error('[ShopDiscount] 扫码出错:',
|
|
502
|
-
return
|
|
467
|
+
_context5.prev = 27;
|
|
468
|
+
_context5.t1 = _context5["catch"](0);
|
|
469
|
+
console.error('[ShopDiscount] 扫码出错:', _context5.t1);
|
|
470
|
+
return _context5.abrupt("return", {
|
|
503
471
|
type: "clientCalc",
|
|
504
472
|
isAvailable: false,
|
|
505
473
|
productList: this.store.productList || [],
|
|
@@ -507,11 +475,11 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
507
475
|
});
|
|
508
476
|
case 31:
|
|
509
477
|
case "end":
|
|
510
|
-
return
|
|
478
|
+
return _context5.stop();
|
|
511
479
|
}
|
|
512
|
-
},
|
|
480
|
+
}, _callee5, this, [[0, 27]]);
|
|
513
481
|
}));
|
|
514
|
-
function scanCode(
|
|
482
|
+
function scanCode(_x4, _x5) {
|
|
515
483
|
return _scanCode.apply(this, arguments);
|
|
516
484
|
}
|
|
517
485
|
return scanCode;
|
|
@@ -544,19 +512,19 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
544
512
|
}, {
|
|
545
513
|
key: "emitDiscountListChange",
|
|
546
514
|
value: function () {
|
|
547
|
-
var _emitDiscountListChange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
548
|
-
return _regeneratorRuntime().wrap(function
|
|
549
|
-
while (1) switch (
|
|
515
|
+
var _emitDiscountListChange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(discountList) {
|
|
516
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
517
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
550
518
|
case 0:
|
|
551
|
-
|
|
519
|
+
_context6.next = 2;
|
|
552
520
|
return this.core.effects.emit("".concat(this.name, ":onDiscountListChange"), discountList);
|
|
553
521
|
case 2:
|
|
554
522
|
case "end":
|
|
555
|
-
return
|
|
523
|
+
return _context6.stop();
|
|
556
524
|
}
|
|
557
|
-
},
|
|
525
|
+
}, _callee6, this);
|
|
558
526
|
}));
|
|
559
|
-
function emitDiscountListChange(
|
|
527
|
+
function emitDiscountListChange(_x6) {
|
|
560
528
|
return _emitDiscountListChange.apply(this, arguments);
|
|
561
529
|
}
|
|
562
530
|
return emitDiscountListChange;
|
|
@@ -663,40 +631,40 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
663
631
|
}, {
|
|
664
632
|
key: "getCustomerWallet",
|
|
665
633
|
value: function () {
|
|
666
|
-
var _getCustomerWallet = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
667
|
-
var
|
|
668
|
-
return _regeneratorRuntime().wrap(function
|
|
669
|
-
while (1) switch (
|
|
634
|
+
var _getCustomerWallet = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(id) {
|
|
635
|
+
var _result, customer;
|
|
636
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
637
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
670
638
|
case 0:
|
|
671
|
-
|
|
672
|
-
|
|
639
|
+
_context7.prev = 0;
|
|
640
|
+
_context7.next = 3;
|
|
673
641
|
return this.request.get("/customer/info/".concat(id), {
|
|
674
642
|
with_trashed: 1
|
|
675
643
|
});
|
|
676
644
|
case 3:
|
|
677
|
-
|
|
678
|
-
if (!(
|
|
679
|
-
|
|
645
|
+
_result = _context7.sent;
|
|
646
|
+
if (!(_result !== null && _result !== void 0 && _result.data)) {
|
|
647
|
+
_context7.next = 9;
|
|
680
648
|
break;
|
|
681
649
|
}
|
|
682
|
-
customer = Object.assign({}, (_objectDestructuringEmpty(
|
|
650
|
+
customer = Object.assign({}, (_objectDestructuringEmpty(_result.data), _result.data));
|
|
683
651
|
this.setCustomer(customer);
|
|
684
|
-
|
|
652
|
+
_context7.next = 9;
|
|
685
653
|
return this.core.effects.emit("".concat(this.name, ":onScanCustomerChange"), customer);
|
|
686
654
|
case 9:
|
|
687
|
-
|
|
655
|
+
_context7.next = 14;
|
|
688
656
|
break;
|
|
689
657
|
case 11:
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
console.error('[ShopDiscount] 获取客户钱包信息出错:',
|
|
658
|
+
_context7.prev = 11;
|
|
659
|
+
_context7.t0 = _context7["catch"](0);
|
|
660
|
+
console.error('[ShopDiscount] 获取客户钱包信息出错:', _context7.t0);
|
|
693
661
|
case 14:
|
|
694
662
|
case "end":
|
|
695
|
-
return
|
|
663
|
+
return _context7.stop();
|
|
696
664
|
}
|
|
697
|
-
},
|
|
665
|
+
}, _callee7, this, [[0, 11]]);
|
|
698
666
|
}));
|
|
699
|
-
function getCustomerWallet(
|
|
667
|
+
function getCustomerWallet(_x7) {
|
|
700
668
|
return _getCustomerWallet.apply(this, arguments);
|
|
701
669
|
}
|
|
702
670
|
return getCustomerWallet;
|
|
@@ -704,32 +672,32 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
704
672
|
}, {
|
|
705
673
|
key: "bestDiscount",
|
|
706
674
|
value: function () {
|
|
707
|
-
var _bestDiscount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
708
|
-
var _this$store$
|
|
709
|
-
var newDiscountList,
|
|
710
|
-
return _regeneratorRuntime().wrap(function
|
|
711
|
-
while (1) switch (
|
|
675
|
+
var _bestDiscount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(cb) {
|
|
676
|
+
var _this$store$productLi;
|
|
677
|
+
var newDiscountList, _result2;
|
|
678
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
679
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
712
680
|
case 0:
|
|
713
681
|
newDiscountList = this.store.originalDiscountList;
|
|
714
682
|
this.setDiscountList(newDiscountList);
|
|
715
|
-
if (!((_this$store$
|
|
716
|
-
|
|
683
|
+
if (!((_this$store$productLi = this.store.productList) !== null && _this$store$productLi !== void 0 && _this$store$productLi.length)) {
|
|
684
|
+
_context8.next = 7;
|
|
717
685
|
break;
|
|
718
686
|
}
|
|
719
|
-
|
|
720
|
-
cb === null || cb === void 0 || cb(
|
|
721
|
-
|
|
722
|
-
return this.core.effects.emit("".concat(this.name, ":onLoadPrepareCalcResult"),
|
|
687
|
+
_result2 = this.calcDiscount(this.store.productList);
|
|
688
|
+
cb === null || cb === void 0 || cb(_result2);
|
|
689
|
+
_context8.next = 7;
|
|
690
|
+
return this.core.effects.emit("".concat(this.name, ":onLoadPrepareCalcResult"), _result2);
|
|
723
691
|
case 7:
|
|
724
|
-
|
|
692
|
+
_context8.next = 9;
|
|
725
693
|
return this.core.effects.emit("".concat(this.name, ":onLoadDiscountList"), newDiscountList);
|
|
726
694
|
case 9:
|
|
727
695
|
case "end":
|
|
728
|
-
return
|
|
696
|
+
return _context8.stop();
|
|
729
697
|
}
|
|
730
|
-
},
|
|
698
|
+
}, _callee8, this);
|
|
731
699
|
}));
|
|
732
|
-
function bestDiscount(
|
|
700
|
+
function bestDiscount(_x8) {
|
|
733
701
|
return _bestDiscount.apply(this, arguments);
|
|
734
702
|
}
|
|
735
703
|
return bestDiscount;
|
|
@@ -737,16 +705,16 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
737
705
|
}, {
|
|
738
706
|
key: "loadPrepareConfig",
|
|
739
707
|
value: function () {
|
|
740
|
-
var _loadPrepareConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
741
|
-
var _this$getCustomer2, _this$store$discount7, _this$getDiscountList, _this$store$discount8, _this$store$
|
|
742
|
-
return _regeneratorRuntime().wrap(function
|
|
743
|
-
while (1) switch (
|
|
708
|
+
var _loadPrepareConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(params) {
|
|
709
|
+
var _this$getCustomer2, _this$store$discount7, _this$getDiscountList, _this$store$discount8, _this$store$productLi2, customerId, goodPassList, scanDiscount, scanDiscountIds, newGoodPassList, newDiscountList, filteredDiscountList, _result3;
|
|
710
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
711
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
744
712
|
case 0:
|
|
745
|
-
|
|
713
|
+
_context9.prev = 0;
|
|
746
714
|
customerId = params.customerId || ((_this$getCustomer2 = this.getCustomer()) === null || _this$getCustomer2 === void 0 ? void 0 : _this$getCustomer2.id); // if (customerId === 1 || !customerId) {
|
|
747
715
|
// return
|
|
748
716
|
// }
|
|
749
|
-
|
|
717
|
+
_context9.next = 4;
|
|
750
718
|
return (_this$store$discount7 = this.store.discount) === null || _this$store$discount7 === void 0 ? void 0 : _this$store$discount7.loadPrepareConfig({
|
|
751
719
|
customer_id: customerId,
|
|
752
720
|
action: 'create',
|
|
@@ -754,7 +722,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
754
722
|
with_discount_card: 1
|
|
755
723
|
});
|
|
756
724
|
case 4:
|
|
757
|
-
goodPassList =
|
|
725
|
+
goodPassList = _context9.sent;
|
|
758
726
|
scanDiscount = (_this$getDiscountList = this.getDiscountList()) === null || _this$getDiscountList === void 0 ? void 0 : _this$getDiscountList.filter(function (item) {
|
|
759
727
|
return item.isScan;
|
|
760
728
|
}); // goodPassList 里可能有 scanDiscount 重合的部分,goodPassList 需要剔除
|
|
@@ -766,37 +734,37 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
766
734
|
});
|
|
767
735
|
newDiscountList = [].concat(_toConsumableArray(scanDiscount), _toConsumableArray(newGoodPassList || [])); // 存储原始优惠券列表
|
|
768
736
|
this.store.originalDiscountList = newDiscountList;
|
|
769
|
-
|
|
737
|
+
_context9.next = 12;
|
|
770
738
|
return (_this$store$discount8 = this.store.discount) === null || _this$store$discount8 === void 0 ? void 0 : _this$store$discount8.setOriginalDiscountList(newDiscountList);
|
|
771
739
|
case 12:
|
|
772
740
|
// 根据当前预约时间过滤优惠券列表
|
|
773
741
|
filteredDiscountList = this.filterDiscountListByBookingTime(newDiscountList, this.store.currentBookingTime);
|
|
774
742
|
this.store.filteredDiscountList = filteredDiscountList;
|
|
775
743
|
this.setDiscountList(filteredDiscountList || []);
|
|
776
|
-
if (!((_this$store$
|
|
777
|
-
|
|
744
|
+
if (!((_this$store$productLi2 = this.store.productList) !== null && _this$store$productLi2 !== void 0 && _this$store$productLi2.length)) {
|
|
745
|
+
_context9.next = 19;
|
|
778
746
|
break;
|
|
779
747
|
}
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
return this.core.effects.emit("".concat(this.name, ":onLoadPrepareCalcResult"),
|
|
748
|
+
_result3 = this.calcDiscount(this.store.productList);
|
|
749
|
+
_context9.next = 19;
|
|
750
|
+
return this.core.effects.emit("".concat(this.name, ":onLoadPrepareCalcResult"), _result3);
|
|
783
751
|
case 19:
|
|
784
|
-
|
|
752
|
+
_context9.next = 21;
|
|
785
753
|
return this.core.effects.emit("".concat(this.name, ":onLoadDiscountList"), filteredDiscountList);
|
|
786
754
|
case 21:
|
|
787
|
-
|
|
755
|
+
_context9.next = 26;
|
|
788
756
|
break;
|
|
789
757
|
case 23:
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
console.error('[ShopDiscount] 加载准备配置出错:',
|
|
758
|
+
_context9.prev = 23;
|
|
759
|
+
_context9.t0 = _context9["catch"](0);
|
|
760
|
+
console.error('[ShopDiscount] 加载准备配置出错:', _context9.t0);
|
|
793
761
|
case 26:
|
|
794
762
|
case "end":
|
|
795
|
-
return
|
|
763
|
+
return _context9.stop();
|
|
796
764
|
}
|
|
797
|
-
},
|
|
765
|
+
}, _callee9, this, [[0, 23]]);
|
|
798
766
|
}));
|
|
799
|
-
function loadPrepareConfig(
|
|
767
|
+
function loadPrepareConfig(_x9) {
|
|
800
768
|
return _loadPrepareConfig.apply(this, arguments);
|
|
801
769
|
}
|
|
802
770
|
return loadPrepareConfig;
|
|
@@ -139,33 +139,22 @@ var isInTimeSlotsSchedule = function isInTimeSlotsSchedule(targetDate, targetDat
|
|
|
139
139
|
if (!schedule.start_time) {
|
|
140
140
|
return false;
|
|
141
141
|
}
|
|
142
|
-
var scheduleDate = schedule.start_time.split(' ')[0];
|
|
143
142
|
|
|
144
|
-
//
|
|
145
|
-
if (
|
|
146
|
-
|
|
147
|
-
}
|
|
143
|
+
// 如果不重复,使用原有逻辑
|
|
144
|
+
if (schedule.repeat_type === 'none') {
|
|
145
|
+
var scheduleDate = schedule.start_time.split(' ')[0];
|
|
148
146
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
try {
|
|
153
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
154
|
-
var timeSlot = _step2.value;
|
|
155
|
-
var slotStart = "".concat(scheduleDate, " ").concat(timeSlot.start_time, ":00");
|
|
156
|
-
var slotEnd = "".concat(scheduleDate, " ").concat(timeSlot.end_time, ":00");
|
|
157
|
-
var slotStartDate = dayjs(slotStart);
|
|
158
|
-
var slotEndDate = dayjs(slotEnd);
|
|
159
|
-
if (targetDate.isSameOrAfter(slotStartDate) && targetDate.isSameOrBefore(slotEndDate)) {
|
|
160
|
-
return true;
|
|
161
|
-
}
|
|
147
|
+
// 检查日期是否匹配
|
|
148
|
+
if (targetDateString !== scheduleDate) {
|
|
149
|
+
return false;
|
|
162
150
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
_iterator2.f();
|
|
151
|
+
|
|
152
|
+
// 检查是否在任一时间段内
|
|
153
|
+
return checkTimeSlotsForDate(targetDate, targetDateString, schedule.time_slot);
|
|
167
154
|
}
|
|
168
|
-
|
|
155
|
+
|
|
156
|
+
// 处理重复日程
|
|
157
|
+
return isInTimeSlotsRepeatingSchedule(targetDate, targetDateString, targetTimeString, schedule);
|
|
169
158
|
};
|
|
170
159
|
|
|
171
160
|
// 处理指定类型日程
|
|
@@ -173,11 +162,11 @@ var isInDesignationSchedule = function isInDesignationSchedule(targetDate, targe
|
|
|
173
162
|
if (!schedule.designation) {
|
|
174
163
|
return false;
|
|
175
164
|
}
|
|
176
|
-
var
|
|
177
|
-
|
|
165
|
+
var _iterator2 = _createForOfIteratorHelper(schedule.designation),
|
|
166
|
+
_step2;
|
|
178
167
|
try {
|
|
179
|
-
for (
|
|
180
|
-
var designation =
|
|
168
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
169
|
+
var designation = _step2.value;
|
|
181
170
|
var startDateTime = "".concat(designation.start_date, " ").concat(designation.start_time, ":00");
|
|
182
171
|
var endDateTime = "".concat(designation.end_date, " ").concat(designation.end_time, ":00");
|
|
183
172
|
var startDate = dayjs(startDateTime);
|
|
@@ -187,9 +176,9 @@ var isInDesignationSchedule = function isInDesignationSchedule(targetDate, targe
|
|
|
187
176
|
}
|
|
188
177
|
}
|
|
189
178
|
} catch (err) {
|
|
190
|
-
|
|
179
|
+
_iterator2.e(err);
|
|
191
180
|
} finally {
|
|
192
|
-
|
|
181
|
+
_iterator2.f();
|
|
193
182
|
}
|
|
194
183
|
return false;
|
|
195
184
|
};
|
|
@@ -205,11 +194,11 @@ var isInRepeatingSchedule = function isInRepeatingSchedule(targetDate, targetDat
|
|
|
205
194
|
|
|
206
195
|
// 首先检查是否在包含日期中(包含日期是额外增加的有效日期)
|
|
207
196
|
if (repeat_rule.included_date && repeat_rule.included_date.length > 0) {
|
|
208
|
-
var
|
|
209
|
-
|
|
197
|
+
var _iterator3 = _createForOfIteratorHelper(repeat_rule.included_date),
|
|
198
|
+
_step3;
|
|
210
199
|
try {
|
|
211
|
-
for (
|
|
212
|
-
var includedDate =
|
|
200
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
201
|
+
var includedDate = _step3.value;
|
|
213
202
|
var includeStartDate = dayjs(includedDate.start);
|
|
214
203
|
var includeEndDate = dayjs(includedDate.end);
|
|
215
204
|
if (targetDateOnly.isSameOrAfter(includeStartDate, 'day') && targetDateOnly.isSameOrBefore(includeEndDate, 'day')) {
|
|
@@ -218,18 +207,18 @@ var isInRepeatingSchedule = function isInRepeatingSchedule(targetDate, targetDat
|
|
|
218
207
|
}
|
|
219
208
|
}
|
|
220
209
|
} catch (err) {
|
|
221
|
-
|
|
210
|
+
_iterator3.e(err);
|
|
222
211
|
} finally {
|
|
223
|
-
|
|
212
|
+
_iterator3.f();
|
|
224
213
|
}
|
|
225
214
|
}
|
|
226
215
|
|
|
227
216
|
// 检查是否在排除日期中
|
|
228
|
-
var
|
|
229
|
-
|
|
217
|
+
var _iterator4 = _createForOfIteratorHelper(repeat_rule.excluded_date),
|
|
218
|
+
_step4;
|
|
230
219
|
try {
|
|
231
|
-
for (
|
|
232
|
-
var excludedDate =
|
|
220
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
221
|
+
var excludedDate = _step4.value;
|
|
233
222
|
var excludeStartDate = dayjs(excludedDate.start);
|
|
234
223
|
var excludeEndDate = dayjs(excludedDate.end);
|
|
235
224
|
// 检查目标日期是否在排除范围内(包含边界)
|
|
@@ -240,9 +229,9 @@ var isInRepeatingSchedule = function isInRepeatingSchedule(targetDate, targetDat
|
|
|
240
229
|
|
|
241
230
|
// 检查重复规则的结束条件
|
|
242
231
|
} catch (err) {
|
|
243
|
-
|
|
232
|
+
_iterator4.e(err);
|
|
244
233
|
} finally {
|
|
245
|
-
|
|
234
|
+
_iterator4.f();
|
|
246
235
|
}
|
|
247
236
|
if (repeat_rule.end.type === 'date' && repeat_rule.end.end_date) {
|
|
248
237
|
var ruleEndDate = dayjs(repeat_rule.end.end_date);
|
|
@@ -312,6 +301,136 @@ var isInWeeklyRepeat = function isInWeeklyRepeat(targetDate, startDate, endDate,
|
|
|
312
301
|
return targetTimeOfDay >= startTimeOfDay && targetTimeOfDay <= endTimeOfDay;
|
|
313
302
|
};
|
|
314
303
|
|
|
304
|
+
// 处理 time-slots 类型的重复日程
|
|
305
|
+
var isInTimeSlotsRepeatingSchedule = function isInTimeSlotsRepeatingSchedule(targetDate, targetDateString, targetTimeString, schedule) {
|
|
306
|
+
if (!schedule.repeat_rule || !schedule.start_time) {
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
var repeat_rule = schedule.repeat_rule,
|
|
310
|
+
repeat_type = schedule.repeat_type;
|
|
311
|
+
var startDate = dayjs(schedule.start_time);
|
|
312
|
+
var targetDateOnly = dayjs(targetDateString);
|
|
313
|
+
|
|
314
|
+
// 检查包含日期
|
|
315
|
+
if (repeat_rule.included_date && repeat_rule.included_date.length > 0) {
|
|
316
|
+
var _iterator5 = _createForOfIteratorHelper(repeat_rule.included_date),
|
|
317
|
+
_step5;
|
|
318
|
+
try {
|
|
319
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
320
|
+
var includedDate = _step5.value;
|
|
321
|
+
var includeStartDate = dayjs(includedDate.start);
|
|
322
|
+
var includeEndDate = dayjs(includedDate.end);
|
|
323
|
+
if (targetDateOnly.isSameOrAfter(includeStartDate, 'day') && targetDateOnly.isSameOrBefore(includeEndDate, 'day')) {
|
|
324
|
+
// 在包含日期中,检查时间段
|
|
325
|
+
return checkTimeSlotsForDate(targetDate, targetDateString, schedule.time_slot);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
} catch (err) {
|
|
329
|
+
_iterator5.e(err);
|
|
330
|
+
} finally {
|
|
331
|
+
_iterator5.f();
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// 检查排除日期
|
|
336
|
+
var _iterator6 = _createForOfIteratorHelper(repeat_rule.excluded_date),
|
|
337
|
+
_step6;
|
|
338
|
+
try {
|
|
339
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
340
|
+
var excludedDate = _step6.value;
|
|
341
|
+
var excludeStartDate = dayjs(excludedDate.start);
|
|
342
|
+
var excludeEndDate = dayjs(excludedDate.end);
|
|
343
|
+
if (targetDateOnly.isSameOrAfter(excludeStartDate, 'day') && targetDateOnly.isSameOrBefore(excludeEndDate, 'day')) {
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// 检查重复规则的结束条件
|
|
349
|
+
} catch (err) {
|
|
350
|
+
_iterator6.e(err);
|
|
351
|
+
} finally {
|
|
352
|
+
_iterator6.f();
|
|
353
|
+
}
|
|
354
|
+
if (repeat_rule.end.type === 'date' && repeat_rule.end.end_date) {
|
|
355
|
+
var ruleEndDate = dayjs(repeat_rule.end.end_date);
|
|
356
|
+
if (targetDateOnly.isAfter(ruleEndDate, 'day')) {
|
|
357
|
+
return false;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// 检查目标日期是否在重复规则范围内
|
|
362
|
+
var isDateValid = false;
|
|
363
|
+
switch (repeat_type) {
|
|
364
|
+
case 'daily':
|
|
365
|
+
isDateValid = isInDailyRepeatForDate(targetDateOnly, startDate, repeat_rule);
|
|
366
|
+
break;
|
|
367
|
+
case 'weekly':
|
|
368
|
+
isDateValid = isInWeeklyRepeatForDate(targetDateOnly, startDate, repeat_rule);
|
|
369
|
+
break;
|
|
370
|
+
default:
|
|
371
|
+
return false;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// 如果日期有效,检查时间段
|
|
375
|
+
if (isDateValid) {
|
|
376
|
+
return checkTimeSlotsForDate(targetDate, targetDateString, schedule.time_slot);
|
|
377
|
+
}
|
|
378
|
+
return false;
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
// 检查目标时间是否在某个时间段内(使用目标日期 + time_slot 时间)
|
|
382
|
+
var checkTimeSlotsForDate = function checkTimeSlotsForDate(targetDate, targetDateString, timeSlots) {
|
|
383
|
+
var _iterator7 = _createForOfIteratorHelper(timeSlots),
|
|
384
|
+
_step7;
|
|
385
|
+
try {
|
|
386
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
387
|
+
var timeSlot = _step7.value;
|
|
388
|
+
var slotStart = "".concat(targetDateString, " ").concat(timeSlot.start_time, ":00");
|
|
389
|
+
var slotEnd = "".concat(targetDateString, " ").concat(timeSlot.end_time, ":00");
|
|
390
|
+
var slotStartDate = dayjs(slotStart);
|
|
391
|
+
var slotEndDate = dayjs(slotEnd);
|
|
392
|
+
if (targetDate.isSameOrAfter(slotStartDate) && targetDate.isSameOrBefore(slotEndDate)) {
|
|
393
|
+
return true;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
} catch (err) {
|
|
397
|
+
_iterator7.e(err);
|
|
398
|
+
} finally {
|
|
399
|
+
_iterator7.f();
|
|
400
|
+
}
|
|
401
|
+
return false;
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
// 检查日期是否满足每日重复规则(只检查日期,不检查时间)
|
|
405
|
+
var isInDailyRepeatForDate = function isInDailyRepeatForDate(targetDate, startDate, repeatRule) {
|
|
406
|
+
var daysDiff = targetDate.diff(startDate, 'day');
|
|
407
|
+
if (daysDiff < 0) {
|
|
408
|
+
return false;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// 检查频率
|
|
412
|
+
return daysDiff % repeatRule.frequency === 0;
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
// 检查日期是否满足每周重复规则(只检查日期,不检查时间)
|
|
416
|
+
var isInWeeklyRepeatForDate = function isInWeeklyRepeatForDate(targetDate, startDate, repeatRule) {
|
|
417
|
+
var targetDayOfWeek = targetDate.day(); // 0=周日, 1=周一, ..., 6=周六
|
|
418
|
+
|
|
419
|
+
// 检查是否在指定的星期几内
|
|
420
|
+
if (!repeatRule.frequency_date.includes(targetDayOfWeek)) {
|
|
421
|
+
return false;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// 计算周差
|
|
425
|
+
var weeksDiff = targetDate.diff(startDate, 'week');
|
|
426
|
+
if (weeksDiff < 0) {
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// 检查频率
|
|
431
|
+
return weeksDiff % repeatRule.frequency === 0;
|
|
432
|
+
};
|
|
433
|
+
|
|
315
434
|
/**
|
|
316
435
|
* 根据预约时间过滤优惠券列表
|
|
317
436
|
* @param discountList 优惠券列表
|
|
@@ -324,7 +443,6 @@ export var filterDiscountListByBookingTime = function filterDiscountListByBookin
|
|
|
324
443
|
}
|
|
325
444
|
return discountList.filter(function (discount) {
|
|
326
445
|
var _discount$metadata2, _discount$metadata3, _discount$custom_sche;
|
|
327
|
-
debugger;
|
|
328
446
|
if (!(discount !== null && discount !== void 0 && (_discount$metadata2 = discount.metadata) !== null && _discount$metadata2 !== void 0 && _discount$metadata2.validity_type) || (discount === null || discount === void 0 || (_discount$metadata3 = discount.metadata) === null || _discount$metadata3 === void 0 ? void 0 : _discount$metadata3.validity_type) === "fixed_validity") {
|
|
329
447
|
return true;
|
|
330
448
|
}
|
|
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
|
|
|
49
49
|
getCategories(): ProductCategory[];
|
|
50
50
|
setOtherParams(key: string, value: any): void;
|
|
51
51
|
getOtherParams(): any;
|
|
52
|
-
getProductType(): "
|
|
52
|
+
getProductType(): "normal" | "duration" | "session";
|
|
53
53
|
}
|
|
@@ -37,6 +37,7 @@ var import_utils = require("../../solution/ShopDiscount/utils");
|
|
|
37
37
|
var import_utils2 = require("../Cart/utils");
|
|
38
38
|
var import_decimal = __toESM(require("decimal.js"));
|
|
39
39
|
var import_lodash_es = require("lodash-es");
|
|
40
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
40
41
|
var RulesModule = class extends import_BaseModule.BaseModule {
|
|
41
42
|
constructor(name, version) {
|
|
42
43
|
super(name, version);
|
|
@@ -266,9 +267,11 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
266
267
|
addModeDiscount.forEach((discount) => {
|
|
267
268
|
var _a, _b, _c, _d, _e, _f;
|
|
268
269
|
const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
|
|
270
|
+
let timeLimit = true;
|
|
271
|
+
timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], ((product == null ? void 0 : product.startDate) || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
|
|
269
272
|
const isLimitedProduct = limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id);
|
|
270
273
|
const isAvailableProduct = flatItem.type === "main" ? !((product == null ? void 0 : product.booking_id) && ((_a = product == null ? void 0 : product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount2) => discount2.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount2.tag || discount2.type)))) : !((flatItem == null ? void 0 : flatItem.booking_id) && ((_d = (_c = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _c.metadata) == null ? void 0 : _d.custom_product_bundle_map_id));
|
|
271
|
-
if (isAvailableProduct && isLimitedProduct) {
|
|
274
|
+
if (isAvailableProduct && isLimitedProduct && timeLimit) {
|
|
272
275
|
(_e = discountApplicability.get(discount.id)) == null ? void 0 : _e.push(product.id);
|
|
273
276
|
const applicableProducts = discountApplicableProducts.get(discount.id) || [];
|
|
274
277
|
const discountType = discount.tag || discount.type;
|
|
@@ -340,6 +343,11 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
340
343
|
if (targetUsedDiscounts && (discount.tag || discount.type) === "good_pass")
|
|
341
344
|
return false;
|
|
342
345
|
const limitedData = discount.limited_relation_product_data;
|
|
346
|
+
let timeLimit = true;
|
|
347
|
+
timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], (product.startDate || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
|
|
348
|
+
if (!timeLimit) {
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
343
351
|
if (limitedData.type === "product_all") {
|
|
344
352
|
if (!this.checkPackageSubItemUsageRules(discount, flatItem)) {
|
|
345
353
|
return false;
|
|
@@ -1622,6 +1622,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1622
1622
|
}
|
|
1623
1623
|
});
|
|
1624
1624
|
});
|
|
1625
|
+
this.core.effects.emit(
|
|
1626
|
+
`${this.store.cart.name}:onUpdateBookingDate`,
|
|
1627
|
+
{}
|
|
1628
|
+
);
|
|
1625
1629
|
}
|
|
1626
1630
|
getScheduleDataByIds(scheduleIds) {
|
|
1627
1631
|
const targetSchedules = this.store.schedule.getScheduleListByIds(scheduleIds);
|
|
@@ -122,12 +122,6 @@ var BookingTicketImpl = class extends import_BaseModule.BaseModule {
|
|
|
122
122
|
throw error;
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
/**
|
|
126
|
-
* 初始化外设扫码结果监听
|
|
127
|
-
*/
|
|
128
|
-
initPeripheralsListener() {
|
|
129
|
-
this.scan.initPeripheralsListener();
|
|
130
|
-
}
|
|
131
125
|
/**
|
|
132
126
|
* 获取商品列表(不加载到模块中)
|
|
133
127
|
* @returns 商品列表
|
|
@@ -18,10 +18,8 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
18
18
|
private initializePlugins;
|
|
19
19
|
private registerDependentModules;
|
|
20
20
|
private registerEventListeners;
|
|
21
|
-
setBookingTime(bookingTime: string | null): Promise<void>;
|
|
22
21
|
getCurrentBookingTime(): string | null;
|
|
23
22
|
private filterDiscountListByBookingTime;
|
|
24
|
-
private updateFilteredDiscountList;
|
|
25
23
|
setCustomer(customer: Customer): Promise<void>;
|
|
26
24
|
calcDiscount(productList: Record<string, any>[], options?: SetDiscountSelectedParams): {
|
|
27
25
|
productList: Record<string, any>[];
|
|
@@ -34,7 +34,6 @@ __export(ShopDiscount_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(ShopDiscount_exports);
|
|
36
36
|
var import_BaseModule = require("../../modules/BaseModule");
|
|
37
|
-
var import_types = require("./types");
|
|
38
37
|
var import_Discount = require("../../modules/Discount");
|
|
39
38
|
var import_Rules = require("../../modules/Rules");
|
|
40
39
|
var import_utils = require("./utils");
|
|
@@ -144,12 +143,14 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
144
143
|
}
|
|
145
144
|
// =========== 公共 API ===========
|
|
146
145
|
// 设置预约时间
|
|
147
|
-
async setBookingTime(bookingTime) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
146
|
+
// public async setBookingTime(bookingTime: string | null): Promise<void> {
|
|
147
|
+
// if (this.store.currentBookingTime !== bookingTime) {
|
|
148
|
+
// this.store.currentBookingTime = bookingTime;
|
|
149
|
+
//
|
|
150
|
+
// // 更新过滤后的优惠券列表
|
|
151
|
+
// await this.updateFilteredDiscountList();
|
|
152
|
+
// }
|
|
153
|
+
// }
|
|
153
154
|
// 获取当前预约时间
|
|
154
155
|
getCurrentBookingTime() {
|
|
155
156
|
return this.store.currentBookingTime;
|
|
@@ -162,20 +163,23 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
162
163
|
return (0, import_utils.filterDiscountListByBookingTime)(discountList, bookingTime);
|
|
163
164
|
}
|
|
164
165
|
// 更新过滤后的优惠券列表
|
|
165
|
-
async updateFilteredDiscountList() {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
166
|
+
// private async updateFilteredDiscountList(): Promise<void> {
|
|
167
|
+
// const originalList = this.store.originalDiscountList;
|
|
168
|
+
// const filteredList = this.filterDiscountListByBookingTime(originalList, this.store.currentBookingTime);
|
|
169
|
+
//
|
|
170
|
+
// this.store.filteredDiscountList = filteredList;
|
|
171
|
+
//
|
|
172
|
+
// // 更新 DiscountModule 中的优惠券列表
|
|
173
|
+
// this.setDiscountList(filteredList);
|
|
174
|
+
//
|
|
175
|
+
// if (this.store.productList?.length) {
|
|
176
|
+
// const result = this.calcDiscount(this.store.productList);
|
|
177
|
+
// await this.core.effects.emit(
|
|
178
|
+
// ShopDiscountHooks.onLoadPrepareCalcResult,
|
|
179
|
+
// result,
|
|
180
|
+
// );
|
|
181
|
+
// }
|
|
182
|
+
// }
|
|
179
183
|
// 设置客户
|
|
180
184
|
async setCustomer(customer) {
|
|
181
185
|
var _a;
|
|
@@ -119,20 +119,14 @@ var isInTimeSlotsSchedule = (targetDate, targetDateString, targetTimeString, sch
|
|
|
119
119
|
if (!schedule.start_time) {
|
|
120
120
|
return false;
|
|
121
121
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
for (const timeSlot of schedule.time_slot) {
|
|
127
|
-
const slotStart = `${scheduleDate} ${timeSlot.start_time}:00`;
|
|
128
|
-
const slotEnd = `${scheduleDate} ${timeSlot.end_time}:00`;
|
|
129
|
-
const slotStartDate = (0, import_dayjs.default)(slotStart);
|
|
130
|
-
const slotEndDate = (0, import_dayjs.default)(slotEnd);
|
|
131
|
-
if (targetDate.isSameOrAfter(slotStartDate) && targetDate.isSameOrBefore(slotEndDate)) {
|
|
132
|
-
return true;
|
|
122
|
+
if (schedule.repeat_type === "none") {
|
|
123
|
+
const scheduleDate = schedule.start_time.split(" ")[0];
|
|
124
|
+
if (targetDateString !== scheduleDate) {
|
|
125
|
+
return false;
|
|
133
126
|
}
|
|
127
|
+
return checkTimeSlotsForDate(targetDate, targetDateString, schedule.time_slot);
|
|
134
128
|
}
|
|
135
|
-
return
|
|
129
|
+
return isInTimeSlotsRepeatingSchedule(targetDate, targetDateString, targetTimeString, schedule);
|
|
136
130
|
};
|
|
137
131
|
var isInDesignationSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
|
|
138
132
|
if (!schedule.designation) {
|
|
@@ -216,13 +210,87 @@ var isInWeeklyRepeat = (targetDate, startDate, endDate, repeatRule) => {
|
|
|
216
210
|
const endTimeOfDay = endDate.hour() * 3600 + endDate.minute() * 60 + endDate.second();
|
|
217
211
|
return targetTimeOfDay >= startTimeOfDay && targetTimeOfDay <= endTimeOfDay;
|
|
218
212
|
};
|
|
213
|
+
var isInTimeSlotsRepeatingSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
|
|
214
|
+
if (!schedule.repeat_rule || !schedule.start_time) {
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
const { repeat_rule, repeat_type } = schedule;
|
|
218
|
+
const startDate = (0, import_dayjs.default)(schedule.start_time);
|
|
219
|
+
const targetDateOnly = (0, import_dayjs.default)(targetDateString);
|
|
220
|
+
if (repeat_rule.included_date && repeat_rule.included_date.length > 0) {
|
|
221
|
+
for (const includedDate of repeat_rule.included_date) {
|
|
222
|
+
const includeStartDate = (0, import_dayjs.default)(includedDate.start);
|
|
223
|
+
const includeEndDate = (0, import_dayjs.default)(includedDate.end);
|
|
224
|
+
if (targetDateOnly.isSameOrAfter(includeStartDate, "day") && targetDateOnly.isSameOrBefore(includeEndDate, "day")) {
|
|
225
|
+
return checkTimeSlotsForDate(targetDate, targetDateString, schedule.time_slot);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
for (const excludedDate of repeat_rule.excluded_date) {
|
|
230
|
+
const excludeStartDate = (0, import_dayjs.default)(excludedDate.start);
|
|
231
|
+
const excludeEndDate = (0, import_dayjs.default)(excludedDate.end);
|
|
232
|
+
if (targetDateOnly.isSameOrAfter(excludeStartDate, "day") && targetDateOnly.isSameOrBefore(excludeEndDate, "day")) {
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (repeat_rule.end.type === "date" && repeat_rule.end.end_date) {
|
|
237
|
+
const ruleEndDate = (0, import_dayjs.default)(repeat_rule.end.end_date);
|
|
238
|
+
if (targetDateOnly.isAfter(ruleEndDate, "day")) {
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
let isDateValid = false;
|
|
243
|
+
switch (repeat_type) {
|
|
244
|
+
case "daily":
|
|
245
|
+
isDateValid = isInDailyRepeatForDate(targetDateOnly, startDate, repeat_rule);
|
|
246
|
+
break;
|
|
247
|
+
case "weekly":
|
|
248
|
+
isDateValid = isInWeeklyRepeatForDate(targetDateOnly, startDate, repeat_rule);
|
|
249
|
+
break;
|
|
250
|
+
default:
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
if (isDateValid) {
|
|
254
|
+
return checkTimeSlotsForDate(targetDate, targetDateString, schedule.time_slot);
|
|
255
|
+
}
|
|
256
|
+
return false;
|
|
257
|
+
};
|
|
258
|
+
var checkTimeSlotsForDate = (targetDate, targetDateString, timeSlots) => {
|
|
259
|
+
for (const timeSlot of timeSlots) {
|
|
260
|
+
const slotStart = `${targetDateString} ${timeSlot.start_time}:00`;
|
|
261
|
+
const slotEnd = `${targetDateString} ${timeSlot.end_time}:00`;
|
|
262
|
+
const slotStartDate = (0, import_dayjs.default)(slotStart);
|
|
263
|
+
const slotEndDate = (0, import_dayjs.default)(slotEnd);
|
|
264
|
+
if (targetDate.isSameOrAfter(slotStartDate) && targetDate.isSameOrBefore(slotEndDate)) {
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return false;
|
|
269
|
+
};
|
|
270
|
+
var isInDailyRepeatForDate = (targetDate, startDate, repeatRule) => {
|
|
271
|
+
const daysDiff = targetDate.diff(startDate, "day");
|
|
272
|
+
if (daysDiff < 0) {
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
return daysDiff % repeatRule.frequency === 0;
|
|
276
|
+
};
|
|
277
|
+
var isInWeeklyRepeatForDate = (targetDate, startDate, repeatRule) => {
|
|
278
|
+
const targetDayOfWeek = targetDate.day();
|
|
279
|
+
if (!repeatRule.frequency_date.includes(targetDayOfWeek)) {
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
const weeksDiff = targetDate.diff(startDate, "week");
|
|
283
|
+
if (weeksDiff < 0) {
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
return weeksDiff % repeatRule.frequency === 0;
|
|
287
|
+
};
|
|
219
288
|
var filterDiscountListByBookingTime = (discountList, bookingTime) => {
|
|
220
289
|
if (!bookingTime) {
|
|
221
290
|
return discountList;
|
|
222
291
|
}
|
|
223
292
|
return discountList.filter((discount) => {
|
|
224
293
|
var _a, _b, _c;
|
|
225
|
-
debugger;
|
|
226
294
|
if (!((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.validity_type) || ((_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.validity_type) === "fixed_validity") {
|
|
227
295
|
return true;
|
|
228
296
|
}
|