@pisell/pisellos 0.0.319 → 0.0.321
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/Discount/index.d.ts +2 -0
- package/dist/modules/Discount/index.js +67 -35
- package/dist/modules/Discount/types.d.ts +5 -0
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/Checkout/index.d.ts +4 -0
- package/dist/solution/Checkout/index.js +262 -209
- package/dist/solution/ShopDiscount/index.d.ts +4 -0
- package/dist/solution/ShopDiscount/index.js +190 -101
- package/dist/solution/ShopDiscount/types.d.ts +4 -1
- package/dist/solution/ShopDiscount/utils.d.ts +48 -0
- package/dist/solution/ShopDiscount/utils.js +281 -0
- package/lib/modules/Discount/index.d.ts +2 -0
- package/lib/modules/Discount/index.js +17 -3
- package/lib/modules/Discount/types.d.ts +5 -0
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/Checkout/index.d.ts +4 -0
- package/lib/solution/Checkout/index.js +22 -2
- package/lib/solution/ShopDiscount/index.d.ts +4 -0
- package/lib/solution/ShopDiscount/index.js +44 -5
- package/lib/solution/ShopDiscount/types.d.ts +4 -1
- package/lib/solution/ShopDiscount/utils.d.ts +48 -0
- package/lib/solution/ShopDiscount/utils.js +172 -0
- package/package.json +1 -1
|
@@ -18,6 +18,10 @@ 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
|
+
getCurrentBookingTime(): string | null;
|
|
23
|
+
private filterDiscountListByBookingTime;
|
|
24
|
+
private updateFilteredDiscountList;
|
|
21
25
|
setCustomer(customer: Customer): Promise<void>;
|
|
22
26
|
calcDiscount(productList: Record<string, any>[], options?: SetDiscountSelectedParams): {
|
|
23
27
|
productList: Record<string, any>[];
|
|
@@ -28,6 +28,7 @@ import { BaseModule } from "../../modules/BaseModule";
|
|
|
28
28
|
import { ShopDiscountHooks } from "./types";
|
|
29
29
|
import { DiscountModule } from "../../modules/Discount";
|
|
30
30
|
import { RulesModule } from "../../modules/Rules";
|
|
31
|
+
import { filterDiscountListByBookingTime as _filterDiscountListByBookingTime, isAllNormalProduct } from "./utils";
|
|
31
32
|
import Decimal from 'decimal.js';
|
|
32
33
|
import { isBoolean } from 'lodash-es';
|
|
33
34
|
export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
@@ -51,7 +52,9 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
51
52
|
productList: [],
|
|
52
53
|
discount: null,
|
|
53
54
|
rules: null,
|
|
54
|
-
originalDiscountList: []
|
|
55
|
+
originalDiscountList: [],
|
|
56
|
+
currentBookingTime: "",
|
|
57
|
+
filteredDiscountList: []
|
|
55
58
|
};
|
|
56
59
|
return _this;
|
|
57
60
|
}
|
|
@@ -208,29 +211,109 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
208
211
|
|
|
209
212
|
// =========== 公共 API ===========
|
|
210
213
|
|
|
211
|
-
//
|
|
214
|
+
// 设置预约时间
|
|
212
215
|
}, {
|
|
213
|
-
key: "
|
|
216
|
+
key: "setBookingTime",
|
|
214
217
|
value: function () {
|
|
215
|
-
var
|
|
216
|
-
var _this$store$customer;
|
|
218
|
+
var _setBookingTime = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(bookingTime) {
|
|
217
219
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
218
220
|
while (1) switch (_context4.prev = _context4.next) {
|
|
219
221
|
case 0:
|
|
220
|
-
if (!(
|
|
222
|
+
if (!(this.store.currentBookingTime !== bookingTime)) {
|
|
221
223
|
_context4.next = 4;
|
|
222
224
|
break;
|
|
223
225
|
}
|
|
224
|
-
this.store.
|
|
226
|
+
this.store.currentBookingTime = bookingTime;
|
|
227
|
+
|
|
228
|
+
// 更新过滤后的优惠券列表
|
|
225
229
|
_context4.next = 4;
|
|
226
|
-
return this.
|
|
230
|
+
return this.updateFilteredDiscountList();
|
|
227
231
|
case 4:
|
|
228
232
|
case "end":
|
|
229
233
|
return _context4.stop();
|
|
230
234
|
}
|
|
231
235
|
}, _callee4, this);
|
|
232
236
|
}));
|
|
233
|
-
function
|
|
237
|
+
function setBookingTime(_x3) {
|
|
238
|
+
return _setBookingTime.apply(this, arguments);
|
|
239
|
+
}
|
|
240
|
+
return setBookingTime;
|
|
241
|
+
}() // 获取当前预约时间
|
|
242
|
+
}, {
|
|
243
|
+
key: "getCurrentBookingTime",
|
|
244
|
+
value: function getCurrentBookingTime() {
|
|
245
|
+
return this.store.currentBookingTime;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// 根据预约时间过滤优惠券列表
|
|
249
|
+
}, {
|
|
250
|
+
key: "filterDiscountListByBookingTime",
|
|
251
|
+
value: function filterDiscountListByBookingTime(discountList, bookingTime) {
|
|
252
|
+
// 如果全部是普通商品,不需要过滤,直接返回当前数据
|
|
253
|
+
if (isAllNormalProduct(this.store.productList || [])) {
|
|
254
|
+
return discountList;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// 否则使用 bookingTime 进行过滤
|
|
258
|
+
return _filterDiscountListByBookingTime(discountList, bookingTime);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// 更新过滤后的优惠券列表
|
|
262
|
+
}, {
|
|
263
|
+
key: "updateFilteredDiscountList",
|
|
264
|
+
value: function () {
|
|
265
|
+
var _updateFilteredDiscountList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
266
|
+
var _this$store$productLi;
|
|
267
|
+
var originalList, filteredList, _result;
|
|
268
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
269
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
270
|
+
case 0:
|
|
271
|
+
originalList = this.store.originalDiscountList;
|
|
272
|
+
filteredList = this.filterDiscountListByBookingTime(originalList, this.store.currentBookingTime);
|
|
273
|
+
this.store.filteredDiscountList = filteredList;
|
|
274
|
+
|
|
275
|
+
// 更新 DiscountModule 中的优惠券列表
|
|
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
|
+
}() // 设置客户
|
|
295
|
+
}, {
|
|
296
|
+
key: "setCustomer",
|
|
297
|
+
value: function () {
|
|
298
|
+
var _setCustomer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(customer) {
|
|
299
|
+
var _this$store$customer;
|
|
300
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
301
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
302
|
+
case 0:
|
|
303
|
+
if (!(((_this$store$customer = this.store.customer) === null || _this$store$customer === void 0 ? void 0 : _this$store$customer.id) !== customer.id)) {
|
|
304
|
+
_context6.next = 4;
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
this.store.customer = customer;
|
|
308
|
+
_context6.next = 4;
|
|
309
|
+
return this.core.effects.emit(ShopDiscountHooks.onCustomerChange, customer);
|
|
310
|
+
case 4:
|
|
311
|
+
case "end":
|
|
312
|
+
return _context6.stop();
|
|
313
|
+
}
|
|
314
|
+
}, _callee6, this);
|
|
315
|
+
}));
|
|
316
|
+
function setCustomer(_x4) {
|
|
234
317
|
return _setCustomer.apply(this, arguments);
|
|
235
318
|
}
|
|
236
319
|
return setCustomer;
|
|
@@ -320,29 +403,29 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
320
403
|
}, {
|
|
321
404
|
key: "scanCode",
|
|
322
405
|
value: function () {
|
|
323
|
-
var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
406
|
+
var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(code, customerId) {
|
|
324
407
|
var _this$store$discount3, resultDiscountList, rulesModule, withScanList, _ref2, newProductList, newDiscountList, isAvailable, _this$options$otherPa6;
|
|
325
|
-
return _regeneratorRuntime().wrap(function
|
|
326
|
-
while (1) switch (
|
|
408
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
409
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
327
410
|
case 0:
|
|
328
|
-
|
|
329
|
-
|
|
411
|
+
_context7.prev = 0;
|
|
412
|
+
_context7.next = 3;
|
|
330
413
|
return (_this$store$discount3 = this.store.discount) === null || _this$store$discount3 === void 0 ? void 0 : _this$store$discount3.batchSearch(code, customerId);
|
|
331
414
|
case 3:
|
|
332
|
-
|
|
333
|
-
if (
|
|
334
|
-
|
|
415
|
+
_context7.t0 = _context7.sent;
|
|
416
|
+
if (_context7.t0) {
|
|
417
|
+
_context7.next = 6;
|
|
335
418
|
break;
|
|
336
419
|
}
|
|
337
|
-
|
|
420
|
+
_context7.t0 = [];
|
|
338
421
|
case 6:
|
|
339
|
-
resultDiscountList =
|
|
422
|
+
resultDiscountList = _context7.t0;
|
|
340
423
|
rulesModule = this.store.rules;
|
|
341
424
|
if (rulesModule) {
|
|
342
|
-
|
|
425
|
+
_context7.next = 10;
|
|
343
426
|
break;
|
|
344
427
|
}
|
|
345
|
-
return
|
|
428
|
+
return _context7.abrupt("return", {
|
|
346
429
|
type: "clientCalc",
|
|
347
430
|
isAvailable: false,
|
|
348
431
|
productList: this.store.productList || [],
|
|
@@ -350,10 +433,10 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
350
433
|
});
|
|
351
434
|
case 10:
|
|
352
435
|
if (resultDiscountList.length) {
|
|
353
|
-
|
|
436
|
+
_context7.next = 12;
|
|
354
437
|
break;
|
|
355
438
|
}
|
|
356
|
-
return
|
|
439
|
+
return _context7.abrupt("return", {
|
|
357
440
|
type: "server",
|
|
358
441
|
isAvailable: false,
|
|
359
442
|
productList: this.store.productList || [],
|
|
@@ -375,30 +458,30 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
375
458
|
discountList: this.getDiscountList()
|
|
376
459
|
}, newProductList = _ref2.productList, newDiscountList = _ref2.discountList, isAvailable = _ref2.isAvailable;
|
|
377
460
|
if (!isAvailable) {
|
|
378
|
-
|
|
461
|
+
_context7.next = 21;
|
|
379
462
|
break;
|
|
380
463
|
}
|
|
381
464
|
this.setDiscountList(newDiscountList || []);
|
|
382
465
|
this.store.originalDiscountList = newDiscountList || [];
|
|
383
466
|
this.setProductList(newProductList || []);
|
|
384
467
|
if (!(this.isWalkIn() && resultDiscountList.length && ((_this$options$otherPa6 = this.options.otherParams) === null || _this$options$otherPa6 === void 0 ? void 0 : _this$options$otherPa6.platform) === 'shop')) {
|
|
385
|
-
|
|
468
|
+
_context7.next = 21;
|
|
386
469
|
break;
|
|
387
470
|
}
|
|
388
|
-
|
|
471
|
+
_context7.next = 21;
|
|
389
472
|
return this.getCustomerWallet(resultDiscountList[0].customer_id);
|
|
390
473
|
case 21:
|
|
391
|
-
return
|
|
474
|
+
return _context7.abrupt("return", {
|
|
392
475
|
type: "clientCalc",
|
|
393
476
|
isAvailable: isAvailable || false,
|
|
394
477
|
productList: newProductList || this.store.productList || [],
|
|
395
478
|
discountList: newDiscountList || this.getDiscountList()
|
|
396
479
|
});
|
|
397
480
|
case 24:
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
console.error('[ShopDiscount] 扫码出错:',
|
|
401
|
-
return
|
|
481
|
+
_context7.prev = 24;
|
|
482
|
+
_context7.t1 = _context7["catch"](0);
|
|
483
|
+
console.error('[ShopDiscount] 扫码出错:', _context7.t1);
|
|
484
|
+
return _context7.abrupt("return", {
|
|
402
485
|
type: "clientCalc",
|
|
403
486
|
isAvailable: false,
|
|
404
487
|
productList: this.store.productList || [],
|
|
@@ -406,11 +489,11 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
406
489
|
});
|
|
407
490
|
case 28:
|
|
408
491
|
case "end":
|
|
409
|
-
return
|
|
492
|
+
return _context7.stop();
|
|
410
493
|
}
|
|
411
|
-
},
|
|
494
|
+
}, _callee7, this, [[0, 24]]);
|
|
412
495
|
}));
|
|
413
|
-
function scanCode(
|
|
496
|
+
function scanCode(_x5, _x6) {
|
|
414
497
|
return _scanCode.apply(this, arguments);
|
|
415
498
|
}
|
|
416
499
|
return scanCode;
|
|
@@ -443,19 +526,19 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
443
526
|
}, {
|
|
444
527
|
key: "emitDiscountListChange",
|
|
445
528
|
value: function () {
|
|
446
|
-
var _emitDiscountListChange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
447
|
-
return _regeneratorRuntime().wrap(function
|
|
448
|
-
while (1) switch (
|
|
529
|
+
var _emitDiscountListChange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(discountList) {
|
|
530
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
531
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
449
532
|
case 0:
|
|
450
|
-
|
|
533
|
+
_context8.next = 2;
|
|
451
534
|
return this.core.effects.emit(ShopDiscountHooks.onDiscountListChange, discountList);
|
|
452
535
|
case 2:
|
|
453
536
|
case "end":
|
|
454
|
-
return
|
|
537
|
+
return _context8.stop();
|
|
455
538
|
}
|
|
456
|
-
},
|
|
539
|
+
}, _callee8, this);
|
|
457
540
|
}));
|
|
458
|
-
function emitDiscountListChange(
|
|
541
|
+
function emitDiscountListChange(_x7) {
|
|
459
542
|
return _emitDiscountListChange.apply(this, arguments);
|
|
460
543
|
}
|
|
461
544
|
return emitDiscountListChange;
|
|
@@ -560,40 +643,40 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
560
643
|
}, {
|
|
561
644
|
key: "getCustomerWallet",
|
|
562
645
|
value: function () {
|
|
563
|
-
var _getCustomerWallet = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
564
|
-
var
|
|
565
|
-
return _regeneratorRuntime().wrap(function
|
|
566
|
-
while (1) switch (
|
|
646
|
+
var _getCustomerWallet = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(id) {
|
|
647
|
+
var _result2, customer;
|
|
648
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
649
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
567
650
|
case 0:
|
|
568
|
-
|
|
569
|
-
|
|
651
|
+
_context9.prev = 0;
|
|
652
|
+
_context9.next = 3;
|
|
570
653
|
return this.request.get("/customer/info/".concat(id), {
|
|
571
654
|
with_trashed: 1
|
|
572
655
|
});
|
|
573
656
|
case 3:
|
|
574
|
-
|
|
575
|
-
if (!(
|
|
576
|
-
|
|
657
|
+
_result2 = _context9.sent;
|
|
658
|
+
if (!(_result2 !== null && _result2 !== void 0 && _result2.data)) {
|
|
659
|
+
_context9.next = 9;
|
|
577
660
|
break;
|
|
578
661
|
}
|
|
579
|
-
customer = Object.assign({}, (_objectDestructuringEmpty(
|
|
662
|
+
customer = Object.assign({}, (_objectDestructuringEmpty(_result2.data), _result2.data));
|
|
580
663
|
this.setCustomer(customer);
|
|
581
|
-
|
|
664
|
+
_context9.next = 9;
|
|
582
665
|
return this.core.effects.emit(ShopDiscountHooks.onScanCustomerChange, customer);
|
|
583
666
|
case 9:
|
|
584
|
-
|
|
667
|
+
_context9.next = 14;
|
|
585
668
|
break;
|
|
586
669
|
case 11:
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
console.error('[ShopDiscount] 获取客户钱包信息出错:',
|
|
670
|
+
_context9.prev = 11;
|
|
671
|
+
_context9.t0 = _context9["catch"](0);
|
|
672
|
+
console.error('[ShopDiscount] 获取客户钱包信息出错:', _context9.t0);
|
|
590
673
|
case 14:
|
|
591
674
|
case "end":
|
|
592
|
-
return
|
|
675
|
+
return _context9.stop();
|
|
593
676
|
}
|
|
594
|
-
},
|
|
677
|
+
}, _callee9, this, [[0, 11]]);
|
|
595
678
|
}));
|
|
596
|
-
function getCustomerWallet(
|
|
679
|
+
function getCustomerWallet(_x8) {
|
|
597
680
|
return _getCustomerWallet.apply(this, arguments);
|
|
598
681
|
}
|
|
599
682
|
return getCustomerWallet;
|
|
@@ -601,32 +684,32 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
601
684
|
}, {
|
|
602
685
|
key: "bestDiscount",
|
|
603
686
|
value: function () {
|
|
604
|
-
var _bestDiscount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
605
|
-
var _this$store$
|
|
606
|
-
var newDiscountList,
|
|
607
|
-
return _regeneratorRuntime().wrap(function
|
|
608
|
-
while (1) switch (
|
|
687
|
+
var _bestDiscount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(cb) {
|
|
688
|
+
var _this$store$productLi2;
|
|
689
|
+
var newDiscountList, _result3;
|
|
690
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
691
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
609
692
|
case 0:
|
|
610
693
|
newDiscountList = this.store.originalDiscountList;
|
|
611
694
|
this.setDiscountList(newDiscountList);
|
|
612
|
-
if (!((_this$store$
|
|
613
|
-
|
|
695
|
+
if (!((_this$store$productLi2 = this.store.productList) !== null && _this$store$productLi2 !== void 0 && _this$store$productLi2.length)) {
|
|
696
|
+
_context10.next = 7;
|
|
614
697
|
break;
|
|
615
698
|
}
|
|
616
|
-
|
|
617
|
-
cb === null || cb === void 0 || cb(
|
|
618
|
-
|
|
619
|
-
return this.core.effects.emit(ShopDiscountHooks.onLoadPrepareCalcResult,
|
|
699
|
+
_result3 = this.calcDiscount(this.store.productList);
|
|
700
|
+
cb === null || cb === void 0 || cb(_result3);
|
|
701
|
+
_context10.next = 7;
|
|
702
|
+
return this.core.effects.emit(ShopDiscountHooks.onLoadPrepareCalcResult, _result3);
|
|
620
703
|
case 7:
|
|
621
|
-
|
|
704
|
+
_context10.next = 9;
|
|
622
705
|
return this.core.effects.emit(ShopDiscountHooks.onLoadDiscountList, newDiscountList);
|
|
623
706
|
case 9:
|
|
624
707
|
case "end":
|
|
625
|
-
return
|
|
708
|
+
return _context10.stop();
|
|
626
709
|
}
|
|
627
|
-
},
|
|
710
|
+
}, _callee10, this);
|
|
628
711
|
}));
|
|
629
|
-
function bestDiscount(
|
|
712
|
+
function bestDiscount(_x9) {
|
|
630
713
|
return _bestDiscount.apply(this, arguments);
|
|
631
714
|
}
|
|
632
715
|
return bestDiscount;
|
|
@@ -634,16 +717,16 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
634
717
|
}, {
|
|
635
718
|
key: "loadPrepareConfig",
|
|
636
719
|
value: function () {
|
|
637
|
-
var _loadPrepareConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
638
|
-
var _this$getCustomer2, _this$store$discount7, _this$getDiscountList, _this$store$
|
|
639
|
-
return _regeneratorRuntime().wrap(function
|
|
640
|
-
while (1) switch (
|
|
720
|
+
var _loadPrepareConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(params) {
|
|
721
|
+
var _this$getCustomer2, _this$store$discount7, _this$getDiscountList, _this$store$discount8, _this$store$productLi3, customerId, goodPassList, scanDiscount, scanDiscountIds, newGoodPassList, newDiscountList, filteredDiscountList, _result4;
|
|
722
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
723
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
641
724
|
case 0:
|
|
642
|
-
|
|
725
|
+
_context11.prev = 0;
|
|
643
726
|
customerId = params.customerId || ((_this$getCustomer2 = this.getCustomer()) === null || _this$getCustomer2 === void 0 ? void 0 : _this$getCustomer2.id); // if (customerId === 1 || !customerId) {
|
|
644
727
|
// return
|
|
645
728
|
// }
|
|
646
|
-
|
|
729
|
+
_context11.next = 4;
|
|
647
730
|
return (_this$store$discount7 = this.store.discount) === null || _this$store$discount7 === void 0 ? void 0 : _this$store$discount7.loadPrepareConfig({
|
|
648
731
|
customer_id: customerId,
|
|
649
732
|
action: 'create',
|
|
@@ -651,7 +734,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
651
734
|
with_discount_card: 1
|
|
652
735
|
});
|
|
653
736
|
case 4:
|
|
654
|
-
goodPassList =
|
|
737
|
+
goodPassList = _context11.sent;
|
|
655
738
|
scanDiscount = (_this$getDiscountList = this.getDiscountList()) === null || _this$getDiscountList === void 0 ? void 0 : _this$getDiscountList.filter(function (item) {
|
|
656
739
|
return item.isScan;
|
|
657
740
|
}); // goodPassList 里可能有 scanDiscount 重合的部分,goodPassList 需要剔除
|
|
@@ -661,33 +744,39 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
661
744
|
newGoodPassList = goodPassList === null || goodPassList === void 0 ? void 0 : goodPassList.filter(function (n) {
|
|
662
745
|
return !scanDiscountIds.includes(n.id);
|
|
663
746
|
});
|
|
664
|
-
newDiscountList = [].concat(_toConsumableArray(scanDiscount), _toConsumableArray(newGoodPassList || []));
|
|
747
|
+
newDiscountList = [].concat(_toConsumableArray(scanDiscount), _toConsumableArray(newGoodPassList || [])); // 存储原始优惠券列表
|
|
665
748
|
this.store.originalDiscountList = newDiscountList;
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
749
|
+
_context11.next = 12;
|
|
750
|
+
return (_this$store$discount8 = this.store.discount) === null || _this$store$discount8 === void 0 ? void 0 : _this$store$discount8.setOriginalDiscountList(newDiscountList);
|
|
751
|
+
case 12:
|
|
752
|
+
// 根据当前预约时间过滤优惠券列表
|
|
753
|
+
filteredDiscountList = this.filterDiscountListByBookingTime(newDiscountList, this.store.currentBookingTime);
|
|
754
|
+
this.store.filteredDiscountList = filteredDiscountList;
|
|
755
|
+
this.setDiscountList(filteredDiscountList || []);
|
|
756
|
+
if (!((_this$store$productLi3 = this.store.productList) !== null && _this$store$productLi3 !== void 0 && _this$store$productLi3.length)) {
|
|
757
|
+
_context11.next = 19;
|
|
669
758
|
break;
|
|
670
759
|
}
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
return this.core.effects.emit(ShopDiscountHooks.onLoadPrepareCalcResult,
|
|
674
|
-
case 15:
|
|
675
|
-
_context9.next = 17;
|
|
676
|
-
return this.core.effects.emit(ShopDiscountHooks.onLoadDiscountList, newDiscountList);
|
|
677
|
-
case 17:
|
|
678
|
-
_context9.next = 22;
|
|
679
|
-
break;
|
|
760
|
+
_result4 = this.calcDiscount(this.store.productList);
|
|
761
|
+
_context11.next = 19;
|
|
762
|
+
return this.core.effects.emit(ShopDiscountHooks.onLoadPrepareCalcResult, _result4);
|
|
680
763
|
case 19:
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
764
|
+
_context11.next = 21;
|
|
765
|
+
return this.core.effects.emit(ShopDiscountHooks.onLoadDiscountList, filteredDiscountList);
|
|
766
|
+
case 21:
|
|
767
|
+
_context11.next = 26;
|
|
768
|
+
break;
|
|
769
|
+
case 23:
|
|
770
|
+
_context11.prev = 23;
|
|
771
|
+
_context11.t0 = _context11["catch"](0);
|
|
772
|
+
console.error('[ShopDiscount] 加载准备配置出错:', _context11.t0);
|
|
773
|
+
case 26:
|
|
685
774
|
case "end":
|
|
686
|
-
return
|
|
775
|
+
return _context11.stop();
|
|
687
776
|
}
|
|
688
|
-
},
|
|
777
|
+
}, _callee11, this, [[0, 23]]);
|
|
689
778
|
}));
|
|
690
|
-
function loadPrepareConfig(
|
|
779
|
+
function loadPrepareConfig(_x10) {
|
|
691
780
|
return _loadPrepareConfig.apply(this, arguments);
|
|
692
781
|
}
|
|
693
782
|
return loadPrepareConfig;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { DiscountModule
|
|
1
|
+
import { DiscountModule } from '../../modules/Discount';
|
|
2
2
|
import { RulesModule } from '../../modules/Rules';
|
|
3
|
+
import { Discount } from "../../modules/Discount/types";
|
|
3
4
|
export declare enum ShopDiscountHooks {
|
|
4
5
|
onInited = "shopDiscount:onInited",
|
|
5
6
|
onDestroy = "shopDiscount:onDestroy",
|
|
@@ -23,6 +24,8 @@ export interface ShopDiscountState {
|
|
|
23
24
|
rules: RulesModule | null;
|
|
24
25
|
productList: Record<string, any>[];
|
|
25
26
|
originalDiscountList: Discount[];
|
|
27
|
+
currentBookingTime: string | null;
|
|
28
|
+
filteredDiscountList: Discount[];
|
|
26
29
|
}
|
|
27
30
|
export interface SetDiscountSelectedParams {
|
|
28
31
|
discountId: number;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Discount } from "../../modules/Discount/types";
|
|
2
2
|
export declare const uniqueById: <T>(arr: T[], key?: string) => T[];
|
|
3
|
+
export declare const isNormalProductByDurationSchedule: (item: any) => boolean;
|
|
4
|
+
export declare const isAllNormalProduct: (items: any[]) => boolean;
|
|
3
5
|
/**
|
|
4
6
|
* 获取折扣金额 基于折扣卡类型计算
|
|
5
7
|
* 商品券:直接返回商品价格
|
|
@@ -10,3 +12,49 @@ export declare const uniqueById: <T>(arr: T[], key?: string) => T[];
|
|
|
10
12
|
* @returns
|
|
11
13
|
*/
|
|
12
14
|
export declare const getDiscountAmount: (discount: Discount, total: number, price: number) => number;
|
|
15
|
+
export interface ScheduleItem {
|
|
16
|
+
id: number;
|
|
17
|
+
name: string | {
|
|
18
|
+
[key: string]: string;
|
|
19
|
+
};
|
|
20
|
+
type: 'standard' | 'time-slots' | 'designation';
|
|
21
|
+
start_time: string | null;
|
|
22
|
+
end_time: string | null;
|
|
23
|
+
repeat_type: 'none' | 'daily' | 'weekly';
|
|
24
|
+
repeat_rule: {
|
|
25
|
+
end: {
|
|
26
|
+
type: 'never' | 'date' | 'occurrence';
|
|
27
|
+
end_date: string | null;
|
|
28
|
+
occurrence: number | null;
|
|
29
|
+
};
|
|
30
|
+
frequency: number;
|
|
31
|
+
excluded_date: Array<{
|
|
32
|
+
start: string;
|
|
33
|
+
end: string;
|
|
34
|
+
}>;
|
|
35
|
+
included_date: Array<{
|
|
36
|
+
start: string;
|
|
37
|
+
end: string;
|
|
38
|
+
}>;
|
|
39
|
+
frequency_date: number[];
|
|
40
|
+
} | null;
|
|
41
|
+
designation: Array<{
|
|
42
|
+
start_date: string;
|
|
43
|
+
start_time: string;
|
|
44
|
+
end_date: string;
|
|
45
|
+
end_time: string;
|
|
46
|
+
}> | null;
|
|
47
|
+
is_all: number;
|
|
48
|
+
time_slot: Array<{
|
|
49
|
+
start_time: string;
|
|
50
|
+
end_time: string;
|
|
51
|
+
}>;
|
|
52
|
+
}
|
|
53
|
+
export declare const getDateIsInSchedule: (dateTime: string, scheduleList: ScheduleItem[]) => boolean;
|
|
54
|
+
/**
|
|
55
|
+
* 根据预约时间过滤优惠券列表
|
|
56
|
+
* @param discountList 优惠券列表
|
|
57
|
+
* @param bookingTime 预约时间 (格式: YYYY-MM-DD HH:mm:ss)
|
|
58
|
+
* @returns 过滤后的优惠券列表
|
|
59
|
+
*/
|
|
60
|
+
export declare const filterDiscountListByBookingTime: (discountList: Discount[], bookingTime: string | null) => Discount[];
|