@pisell/pisellos 3.0.42 → 3.0.44

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.
Files changed (53) hide show
  1. package/dist/modules/AccountList/index.js +17 -12
  2. package/dist/modules/Cart/index.d.ts +14 -0
  3. package/dist/modules/Cart/index.js +38 -1
  4. package/dist/modules/Cart/utils/cartProduct.d.ts +3 -0
  5. package/dist/modules/Cart/utils/cartProduct.js +28 -8
  6. package/dist/modules/Date/index.js +70 -6
  7. package/dist/modules/Discount/index.d.ts +1 -0
  8. package/dist/modules/Discount/index.js +13 -6
  9. package/dist/modules/Discount/types.d.ts +10 -0
  10. package/dist/modules/ProductList/index.d.ts +7 -0
  11. package/dist/modules/ProductList/index.js +102 -39
  12. package/dist/modules/Rules/index.js +218 -80
  13. package/dist/modules/Rules/types.d.ts +7 -1
  14. package/dist/modules/Schedule/index.d.ts +9 -1
  15. package/dist/modules/Schedule/index.js +122 -2
  16. package/dist/modules/Schedule/types.d.ts +13 -0
  17. package/dist/solution/BookingByStep/index.d.ts +120 -30
  18. package/dist/solution/BookingByStep/index.js +755 -1078
  19. package/dist/solution/BookingByStep/utils/capacity.d.ts +47 -0
  20. package/dist/solution/BookingByStep/utils/capacity.js +132 -0
  21. package/dist/solution/BookingByStep/utils/resources.d.ts +21 -29
  22. package/dist/solution/BookingByStep/utils/resources.js +39 -95
  23. package/dist/solution/BookingByStep/utils/timeslots.d.ts +11 -0
  24. package/dist/solution/BookingByStep/utils/timeslots.js +15 -0
  25. package/dist/solution/ShopDiscount/index.d.ts +2 -0
  26. package/dist/solution/ShopDiscount/index.js +119 -44
  27. package/lib/modules/AccountList/index.js +4 -0
  28. package/lib/modules/Cart/index.d.ts +14 -0
  29. package/lib/modules/Cart/index.js +34 -1
  30. package/lib/modules/Cart/utils/cartProduct.d.ts +3 -0
  31. package/lib/modules/Cart/utils/cartProduct.js +20 -8
  32. package/lib/modules/Date/index.js +59 -2
  33. package/lib/modules/Discount/index.d.ts +1 -0
  34. package/lib/modules/Discount/index.js +17 -6
  35. package/lib/modules/Discount/types.d.ts +10 -0
  36. package/lib/modules/ProductList/index.d.ts +7 -0
  37. package/lib/modules/ProductList/index.js +45 -0
  38. package/lib/modules/Rules/index.js +154 -63
  39. package/lib/modules/Rules/types.d.ts +7 -1
  40. package/lib/modules/Schedule/index.d.ts +9 -1
  41. package/lib/modules/Schedule/index.js +79 -1
  42. package/lib/modules/Schedule/types.d.ts +13 -0
  43. package/lib/solution/BookingByStep/index.d.ts +120 -30
  44. package/lib/solution/BookingByStep/index.js +391 -589
  45. package/lib/solution/BookingByStep/utils/capacity.d.ts +47 -0
  46. package/lib/solution/BookingByStep/utils/capacity.js +106 -0
  47. package/lib/solution/BookingByStep/utils/resources.d.ts +21 -29
  48. package/lib/solution/BookingByStep/utils/resources.js +21 -58
  49. package/lib/solution/BookingByStep/utils/timeslots.d.ts +11 -0
  50. package/lib/solution/BookingByStep/utils/timeslots.js +7 -0
  51. package/lib/solution/ShopDiscount/index.d.ts +2 -0
  52. package/lib/solution/ShopDiscount/index.js +91 -19
  53. package/package.json +1 -1
@@ -1,7 +1,5 @@
1
- var _excluded = ["wallet_pass_list"];
2
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
4
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
2
+ function _objectDestructuringEmpty(obj) { if (obj == null) throw new TypeError("Cannot destructure " + obj); }
5
3
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
6
4
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
5
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -30,6 +28,7 @@ import { BaseModule } from "../../modules/BaseModule";
30
28
  import { ShopDiscountHooks } from "./types";
31
29
  import { DiscountModule } from "../../modules/Discount";
32
30
  import { RulesModule } from "../../modules/Rules";
31
+ import Decimal from 'decimal.js';
33
32
  export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
34
33
  _inherits(ShopDiscountImpl, _BaseModule);
35
34
  var _super = _createSuper(ShopDiscountImpl);
@@ -45,6 +44,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
45
44
  _defineProperty(_assertThisInitialized(_this), "window", void 0);
46
45
  _defineProperty(_assertThisInitialized(_this), "store", void 0);
47
46
  _defineProperty(_assertThisInitialized(_this), "options", {});
47
+ _defineProperty(_assertThisInitialized(_this), "hooks", void 0);
48
48
  _this.store = {
49
49
  customer: null,
50
50
  productList: [],
@@ -59,12 +59,14 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
59
59
  key: "initialize",
60
60
  value: function () {
61
61
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
62
+ var _options$otherParams;
62
63
  return _regeneratorRuntime().wrap(function _callee$(_context) {
63
64
  while (1) switch (_context.prev = _context.next) {
64
65
  case 0:
65
66
  this.core = core;
66
67
  this.options = options;
67
68
  this.store = _objectSpread(_objectSpread({}, this.store), options.store || {});
69
+ this.hooks = (_options$otherParams = options.otherParams) === null || _options$otherParams === void 0 || (_options$otherParams = _options$otherParams.rules) === null || _options$otherParams === void 0 ? void 0 : _options$otherParams.hooks;
68
70
  console.log('[ShopDiscount] 初始化完成');
69
71
 
70
72
  // 获取依赖的插件
@@ -75,7 +77,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
75
77
 
76
78
  // 注册事件监听
77
79
  this.registerEventListeners();
78
- case 7:
80
+ case 8:
79
81
  case "end":
80
82
  return _context.stop();
81
83
  }
@@ -196,7 +198,8 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
196
198
  _this2.loadPrepareConfig({
197
199
  customerId: customer.id,
198
200
  action: 'create',
199
- with_good_pass: 1
201
+ with_good_pass: 1,
202
+ with_discount_card: 1
200
203
  });
201
204
  });
202
205
  }
@@ -324,11 +327,23 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
324
327
  break;
325
328
  }
326
329
  return _context5.abrupt("return", {
330
+ type: "clientCalc",
327
331
  isAvailable: false,
328
332
  productList: this.store.productList || [],
329
333
  discountList: this.getDiscountList()
330
334
  });
331
335
  case 10:
336
+ if (resultDiscountList.length) {
337
+ _context5.next = 12;
338
+ break;
339
+ }
340
+ return _context5.abrupt("return", {
341
+ type: "server",
342
+ isAvailable: false,
343
+ productList: this.store.productList || [],
344
+ discountList: this.getDiscountList()
345
+ });
346
+ case 12:
332
347
  withScanList = resultDiscountList.map(function (item) {
333
348
  return _objectSpread(_objectSpread({}, item), {}, {
334
349
  isScan: true
@@ -344,37 +359,39 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
344
359
  discountList: this.getDiscountList()
345
360
  }, newProductList = _ref3.productList, newDiscountList = _ref3.discountList, isAvailable = _ref3.isAvailable;
346
361
  if (!isAvailable) {
347
- _context5.next = 18;
362
+ _context5.next = 20;
348
363
  break;
349
364
  }
350
365
  this.setDiscountList(newDiscountList || []);
351
366
  this.setProductList(newProductList || []);
352
367
  if (!(this.isWalkIn() && resultDiscountList.length && ((_this$options$otherPa6 = this.options.otherParams) === null || _this$options$otherPa6 === void 0 ? void 0 : _this$options$otherPa6.platform) === 'shop')) {
353
- _context5.next = 18;
368
+ _context5.next = 20;
354
369
  break;
355
370
  }
356
- _context5.next = 18;
371
+ _context5.next = 20;
357
372
  return this.getCustomerWallet(resultDiscountList[0].customer_id);
358
- case 18:
373
+ case 20:
359
374
  return _context5.abrupt("return", {
375
+ type: "clientCalc",
360
376
  isAvailable: isAvailable || false,
361
377
  productList: newProductList || this.store.productList || [],
362
378
  discountList: newDiscountList || this.getDiscountList()
363
379
  });
364
- case 21:
365
- _context5.prev = 21;
380
+ case 23:
381
+ _context5.prev = 23;
366
382
  _context5.t1 = _context5["catch"](0);
367
383
  console.error('[ShopDiscount] 扫码出错:', _context5.t1);
368
384
  return _context5.abrupt("return", {
385
+ type: "clientCalc",
369
386
  isAvailable: false,
370
387
  productList: this.store.productList || [],
371
388
  discountList: this.getDiscountList()
372
389
  });
373
- case 25:
390
+ case 27:
374
391
  case "end":
375
392
  return _context5.stop();
376
393
  }
377
- }, _callee5, this, [[0, 21]]);
394
+ }, _callee5, this, [[0, 23]]);
378
395
  }));
379
396
  function scanCode(_x4) {
380
397
  return _scanCode.apply(this, arguments);
@@ -429,25 +446,42 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
429
446
  }, {
430
447
  key: "setDiscountList",
431
448
  value: function setDiscountList(discountList) {
432
- var _this$store$discount5;
449
+ var _this3 = this,
450
+ _this$store$discount5;
433
451
  var productList = this.store.productList || [];
434
452
  var editModeDiscountList = [];
435
453
  productList.forEach(function (item) {
436
454
  if (item.booking_id) {
455
+ var _this3$hooks;
456
+ var product = (_this3$hooks = _this3.hooks) === null || _this3$hooks === void 0 ? void 0 : _this3$hooks.getProduct(item);
437
457
  (item.discount_list || []).forEach(function (discount) {
438
- if (discount.id && discount.type === 'good_pass') {
439
- var _discount$discount, _discount$discount2, _discount$discount3;
440
- editModeDiscountList.push(_objectSpread(_objectSpread({}, discount), {}, {
441
- isEditMode: true,
442
- limited_relation_product_data: {},
443
- savedAmount: discount.amount,
444
- isAvailable: true,
445
- id: ((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id,
446
- format_title: ((_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.title) || discount.format_title,
447
- isDisabled: true,
448
- isSelected: true,
449
- product_id: ((_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.product_id) || discount.product_id
450
- }));
458
+ if (discount.id && ['good_pass', 'discount_card'].includes(discount.type)) {
459
+ var index = editModeDiscountList.findIndex(function (n) {
460
+ var _discount$discount;
461
+ return n.id === (((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id);
462
+ });
463
+ if (index !== -1) {
464
+ editModeDiscountList[index] = _objectSpread(_objectSpread({}, editModeDiscountList[index]), {}, {
465
+ amount: new Decimal(discount.amount || 0).plus(new Decimal(editModeDiscountList[index].amount || 0)).toNumber(),
466
+ savedAmount: new Decimal(discount.amount || 0).times((product === null || product === void 0 ? void 0 : product.num) || 1).plus(new Decimal(editModeDiscountList[index].savedAmount || 0)).toNumber()
467
+ });
468
+ } else {
469
+ var _discount$discount2, _discount$discount3, _discount$discount4;
470
+ if (discount.type && !discount.tag) {
471
+ discount.tag = discount.type;
472
+ }
473
+ editModeDiscountList.push(_objectSpread(_objectSpread({}, discount), {}, {
474
+ isEditMode: true,
475
+ limited_relation_product_data: {},
476
+ savedAmount: discount.amount * ((product === null || product === void 0 ? void 0 : product.num) || 1),
477
+ isAvailable: true,
478
+ id: ((_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.resource_id) || discount.id,
479
+ format_title: ((_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.title) || discount.format_title,
480
+ isDisabled: true,
481
+ isSelected: true,
482
+ product_id: ((_discount$discount4 = discount.discount) === null || _discount$discount4 === void 0 ? void 0 : _discount$discount4.product_id) || discount.product_id
483
+ }));
484
+ }
451
485
  }
452
486
  });
453
487
  }
@@ -455,6 +489,40 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
455
489
  var newDiscountList = [].concat(editModeDiscountList, _toConsumableArray(discountList.filter(function (item) {
456
490
  return !item.isDisabled;
457
491
  })));
492
+ var allUsedProductIds = newDiscountList.map(function (n) {
493
+ var _n$appliedProductDeta;
494
+ return n.isSelected ? (_n$appliedProductDeta = n.appliedProductDetails) === null || _n$appliedProductDeta === void 0 ? void 0 : _n$appliedProductDeta.map(function (n) {
495
+ var _n$discount;
496
+ return (_n$discount = n.discount) === null || _n$discount === void 0 ? void 0 : _n$discount.product_id;
497
+ }) : [];
498
+ }).flat();
499
+ newDiscountList.forEach(function (item) {
500
+ var _item$applicableProdu;
501
+ var isProductFree = function isProductFree(id) {
502
+ var _this3$hooks2;
503
+ var targetProduct = productList.find(function (n) {
504
+ return n.id === id;
505
+ });
506
+ var product = (_this3$hooks2 = _this3.hooks) === null || _this3$hooks2 === void 0 ? void 0 : _this3$hooks2.getProduct(targetProduct);
507
+ return Number(product === null || product === void 0 ? void 0 : product.total) === 0;
508
+ };
509
+ var isAllProductUsedOrFree = (_item$applicableProdu = item.applicableProductIds) === null || _item$applicableProdu === void 0 ? void 0 : _item$applicableProdu.every(function (id) {
510
+ var _item$applicableProdu2;
511
+ // 检查当前 id是否在 item.applicableProductIds 里出现了几次,且要求次数和 item.applicableProductIds 里出现的次数一致
512
+ var sameIdTimes = ((_item$applicableProdu2 = item.applicableProductIds) === null || _item$applicableProdu2 === void 0 ? void 0 : _item$applicableProdu2.filter(function (n) {
513
+ return n === id;
514
+ }).length) || 1;
515
+ var targetIdTimes = (allUsedProductIds === null || allUsedProductIds === void 0 ? void 0 : allUsedProductIds.filter(function (n) {
516
+ return n === id;
517
+ }).length) || 0;
518
+ return targetIdTimes >= sameIdTimes || isProductFree(id);
519
+ });
520
+ if (!item.isSelected && isAllProductUsedOrFree) {
521
+ item.isDisabledForProductUsed = true;
522
+ } else {
523
+ item.isDisabledForProductUsed = false;
524
+ }
525
+ });
458
526
  (_this$store$discount5 = this.store.discount) === null || _this$store$discount5 === void 0 || _this$store$discount5.setDiscountList(newDiscountList);
459
527
  this.emitDiscountListChange(newDiscountList);
460
528
  return newDiscountList;
@@ -473,14 +541,14 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
473
541
  key: "getCustomerWallet",
474
542
  value: function () {
475
543
  var _getCustomerWallet = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(id) {
476
- var result, _result$data, wallet_pass_list, customer;
544
+ var result, customer;
477
545
  return _regeneratorRuntime().wrap(function _callee7$(_context7) {
478
546
  while (1) switch (_context7.prev = _context7.next) {
479
547
  case 0:
480
548
  _context7.prev = 0;
481
549
  _context7.next = 3;
482
- return this.request.get("/customer/info/wallet/".concat(id), {
483
- wallet_pass_tags: ['good_pass']
550
+ return this.request.get("/customer/info/".concat(id), {
551
+ with_trashed: 1
484
552
  });
485
553
  case 3:
486
554
  result = _context7.sent;
@@ -488,7 +556,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
488
556
  _context7.next = 9;
489
557
  break;
490
558
  }
491
- _result$data = result.data, wallet_pass_list = _result$data.wallet_pass_list, customer = _objectWithoutProperties(_result$data, _excluded);
559
+ customer = Object.assign({}, (_objectDestructuringEmpty(result.data), result.data));
492
560
  this.setCustomer(customer);
493
561
  _context7.next = 9;
494
562
  return this.core.effects.emit(ShopDiscountHooks.onScanCustomerChange, customer);
@@ -514,7 +582,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
514
582
  key: "loadPrepareConfig",
515
583
  value: function () {
516
584
  var _loadPrepareConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
517
- var _this$getCustomer2, _this$store$discount7, _this$getDiscountList, _this$store$productLi, customerId, goodPassList, scanDiscount, newDiscountList, result;
585
+ var _this$getCustomer2, _this$store$discount7, _this$getDiscountList, _this$store$productLi, customerId, goodPassList, scanDiscount, scanDiscountIds, newGoodPassList, newDiscountList, result;
518
586
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
519
587
  while (1) switch (_context8.prev = _context8.next) {
520
588
  case 0:
@@ -526,37 +594,44 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
526
594
  return (_this$store$discount7 = this.store.discount) === null || _this$store$discount7 === void 0 ? void 0 : _this$store$discount7.loadPrepareConfig({
527
595
  customer_id: customerId,
528
596
  action: 'create',
529
- with_good_pass: 1
597
+ with_good_pass: 1,
598
+ with_discount_card: 1
530
599
  });
531
600
  case 4:
532
601
  goodPassList = _context8.sent;
533
602
  scanDiscount = (_this$getDiscountList = this.getDiscountList()) === null || _this$getDiscountList === void 0 ? void 0 : _this$getDiscountList.filter(function (item) {
534
603
  return item.isScan;
604
+ }); // goodPassList 里可能有 scanDiscount 重合的部分,goodPassList 需要剔除
605
+ scanDiscountIds = scanDiscount.map(function (n) {
606
+ return n.id;
607
+ });
608
+ newGoodPassList = goodPassList === null || goodPassList === void 0 ? void 0 : goodPassList.filter(function (n) {
609
+ return !scanDiscountIds.includes(n.id);
535
610
  });
536
- newDiscountList = [].concat(_toConsumableArray(scanDiscount), _toConsumableArray(goodPassList || []));
611
+ newDiscountList = [].concat(_toConsumableArray(scanDiscount), _toConsumableArray(newGoodPassList || []));
537
612
  this.setDiscountList(newDiscountList || []);
538
613
  if (!((_this$store$productLi = this.store.productList) !== null && _this$store$productLi !== void 0 && _this$store$productLi.length)) {
539
- _context8.next = 12;
614
+ _context8.next = 14;
540
615
  break;
541
616
  }
542
617
  result = this.calcDiscount(this.store.productList);
543
- _context8.next = 12;
544
- return this.core.effects.emit(ShopDiscountHooks.onLoadPrepareCalcResult, result);
545
- case 12:
546
618
  _context8.next = 14;
547
- return this.core.effects.emit(ShopDiscountHooks.onLoadDiscountList, newDiscountList);
619
+ return this.core.effects.emit(ShopDiscountHooks.onLoadPrepareCalcResult, result);
548
620
  case 14:
549
- _context8.next = 19;
550
- break;
621
+ _context8.next = 16;
622
+ return this.core.effects.emit(ShopDiscountHooks.onLoadDiscountList, newDiscountList);
551
623
  case 16:
552
- _context8.prev = 16;
624
+ _context8.next = 21;
625
+ break;
626
+ case 18:
627
+ _context8.prev = 18;
553
628
  _context8.t0 = _context8["catch"](0);
554
629
  console.error('[ShopDiscount] 加载准备配置出错:', _context8.t0);
555
- case 19:
630
+ case 21:
556
631
  case "end":
557
632
  return _context8.stop();
558
633
  }
559
- }, _callee8, this, [[0, 16]]);
634
+ }, _callee8, this, [[0, 18]]);
560
635
  }));
561
636
  function loadPrepareConfig(_x7) {
562
637
  return _loadPrepareConfig.apply(this, arguments);
@@ -179,6 +179,7 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
179
179
  });
180
180
  }
181
181
  async removeAccount(id) {
182
+ var _a;
182
183
  try {
183
184
  this.store.isLoading = true;
184
185
  this.store.error = null;
@@ -194,6 +195,9 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
194
195
  this.store.accountList = this.store.accountList.filter(
195
196
  (account) => account.id !== id
196
197
  );
198
+ if (!this.getActiveAccount() || ((_a = this.getActiveAccount()) == null ? void 0 : _a.getId()) === id || this.store.accounts.length === 1) {
199
+ this.setActiveAccount(this.store.accounts[0].getId());
200
+ }
197
201
  await this.core.effects.emit(
198
202
  import_types.AccountListHooks.OnAccountListUpdate,
199
203
  this.store
@@ -1,6 +1,7 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
3
  import { CartItem, CartModuleAPI, ECartItemCheckType, ECartItemInfoType, IAddItemParams, IUpdateItemParams } from './types';
4
+ import { Account } from '../Account';
4
5
  export * from './types';
5
6
  /**
6
7
  * 购物车模块实现
@@ -67,4 +68,17 @@ export declare class CartModule extends BaseModule implements Module, CartModule
67
68
  clear(): void;
68
69
  storeChange(): void;
69
70
  checkCartItemByType(cartItem: CartItem, type: ECartItemCheckType): boolean;
71
+ /**
72
+ * 基于rowkey 合并商品,目前只有普通商品需要合并
73
+ *
74
+ * @param {string} rowKey
75
+ * @param {number} quantity
76
+ * @return {*}
77
+ * @memberof CartModule
78
+ */
79
+ mergeCartItemByRowKey(params: {
80
+ rowKey?: string;
81
+ quantity?: number;
82
+ account?: Account;
83
+ }): boolean;
70
84
  }
@@ -27,6 +27,7 @@ var import_BaseModule = require("../BaseModule");
27
27
  var import_types = require("./types");
28
28
  var import_utils = require("./utils");
29
29
  var import_lodash_es = require("lodash-es");
30
+ var import_utils2 = require("../Product/utils");
30
31
  __reExport(Cart_exports, require("./types"), module.exports);
31
32
  var CartModule = class extends import_BaseModule.BaseModule {
32
33
  constructor(name, version) {
@@ -157,7 +158,8 @@ var CartModule = class extends import_BaseModule.BaseModule {
157
158
  bundle,
158
159
  options,
159
160
  product_variant_id: newProduct.product_variant_id,
160
- quantity
161
+ quantity,
162
+ discounts
161
163
  });
162
164
  }
163
165
  if (discounts) {
@@ -310,6 +312,37 @@ var CartModule = class extends import_BaseModule.BaseModule {
310
312
  }
311
313
  return result;
312
314
  }
315
+ /**
316
+ * 基于rowkey 合并商品,目前只有普通商品需要合并
317
+ *
318
+ * @param {string} rowKey
319
+ * @param {number} quantity
320
+ * @return {*}
321
+ * @memberof CartModule
322
+ */
323
+ mergeCartItemByRowKey(params) {
324
+ const { rowKey, quantity, account } = params;
325
+ let flag = false;
326
+ const cartItems = this.getItems();
327
+ const targetCartItem = cartItems.find(
328
+ (n) => {
329
+ var _a;
330
+ return ((_a = n._productOrigin) == null ? void 0 : _a.rowKey) === rowKey;
331
+ }
332
+ );
333
+ const isSameAccount = (account == null ? void 0 : account.id) === (targetCartItem == null ? void 0 : targetCartItem.holder_id);
334
+ if (rowKey && targetCartItem && (0, import_utils2.isNormalProduct)(targetCartItem._productOrigin) && isSameAccount) {
335
+ this.updateItem({
336
+ _id: targetCartItem._id,
337
+ product: {
338
+ ...targetCartItem._productOrigin,
339
+ quantity: (targetCartItem.num || 1) + (quantity || 1)
340
+ }
341
+ });
342
+ flag = true;
343
+ }
344
+ return flag;
345
+ }
313
346
  };
314
347
  // Annotate the CommonJS export names for ESM import in node:
315
348
  0 && (module.exports = {
@@ -20,6 +20,7 @@ export declare const formatProductToCartItem: (params: {
20
20
  options?: any;
21
21
  product_variant_id?: number;
22
22
  quantity?: number;
23
+ discounts?: any[];
23
24
  }) => CartItem;
24
25
  export declare const formatProductToCartItemOrigin: (params: {
25
26
  cartItem: CartItem;
@@ -40,6 +41,7 @@ export declare const getProductTotalPrice: (params: {
40
41
  bundle?: any;
41
42
  options?: any;
42
43
  num?: number;
44
+ discounts?: any[];
43
45
  }) => number;
44
46
  /**
45
47
  * 获取商品原始总价
@@ -52,6 +54,7 @@ export declare const getProductOriginTotalPrice: (params: {
52
54
  bundle?: any;
53
55
  options?: any;
54
56
  num?: number;
57
+ discounts?: any[];
55
58
  }) => number | undefined;
56
59
  /**
57
60
  * 格式化套餐规格信息
@@ -51,7 +51,9 @@ var handleVariantProduct = (product) => {
51
51
  );
52
52
  if (targetVariant) {
53
53
  product.price = targetVariant.price;
54
- product.original_price = targetVariant.original_price;
54
+ if (Number(targetVariant.original_price) > 0) {
55
+ product.original_price = targetVariant.original_price;
56
+ }
55
57
  product.is_charge_tax = targetVariant.is_charge_tax;
56
58
  }
57
59
  }
@@ -65,7 +67,8 @@ var formatProductToCartItem = (params) => {
65
67
  bundle,
66
68
  options,
67
69
  product_variant_id,
68
- quantity = 1
70
+ quantity = 1,
71
+ discounts
69
72
  } = params;
70
73
  const num = quantity;
71
74
  if (product) {
@@ -73,13 +76,14 @@ var formatProductToCartItem = (params) => {
73
76
  cartItem.name = product == null ? void 0 : product.title;
74
77
  cartItem.price = product == null ? void 0 : product.price;
75
78
  cartItem.num = num;
76
- cartItem.total = getProductTotalPrice({ product, bundle, options, num });
79
+ cartItem.total = getProductTotalPrice({ product, bundle, options, num, discounts });
77
80
  cartItem.summaryTotal = cartItem.total * (num || 1);
78
81
  cartItem.origin_total = getProductOriginTotalPrice({
79
82
  product,
80
83
  bundle,
81
84
  options,
82
- num
85
+ num,
86
+ discounts
83
87
  });
84
88
  cartItem.image = product == null ? void 0 : product.cover;
85
89
  cartItem.like_status = "common";
@@ -163,7 +167,7 @@ var formatProductToCartItemOrigin = (params) => {
163
167
  return origin;
164
168
  };
165
169
  var getProductTotalPrice = (params) => {
166
- const { product, bundle, options } = params;
170
+ const { product, bundle, options, discounts } = params;
167
171
  let price = Number(product.price);
168
172
  if (bundle == null ? void 0 : bundle.length) {
169
173
  price = bundle.reduce((accumulator, currentValue) => {
@@ -175,13 +179,21 @@ var getProductTotalPrice = (params) => {
175
179
  return accumulator + Number(currentValue.price) * Number(currentValue.num);
176
180
  }, price);
177
181
  }
182
+ if (discounts == null ? void 0 : discounts.length) {
183
+ discounts.forEach((currentValue) => {
184
+ if (currentValue.type !== "good_pass") {
185
+ const discountPrice = new import_decimal.default(100).minus(currentValue.discount.percent || 0).div(100).mul(new import_decimal.default(price || 0)).toFixed(2);
186
+ price = Number(discountPrice);
187
+ }
188
+ });
189
+ }
178
190
  return price;
179
191
  };
180
192
  var getProductOriginTotalPrice = (params) => {
181
- const { product, bundle, options } = params;
193
+ const { product, bundle, options, discounts } = params;
182
194
  const num = (params == null ? void 0 : params.num) || 1;
183
195
  let price = Number(product.original_price);
184
- if (isNaN(price) || price === 0) {
196
+ if ((isNaN(price) || price === 0) && !(discounts == null ? void 0 : discounts.length)) {
185
197
  return void 0;
186
198
  }
187
199
  if (bundle == null ? void 0 : bundle.length) {
@@ -194,7 +206,7 @@ var getProductOriginTotalPrice = (params) => {
194
206
  return accumulator + Number(currentValue.price) * Number(currentValue.num);
195
207
  }, price);
196
208
  }
197
- return price * num;
209
+ return price;
198
210
  };
199
211
  var formatOptions = (options) => {
200
212
  if (!(options == null ? void 0 : options.length))
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
28
 
19
29
  // src/modules/Date/index.ts
@@ -24,6 +34,7 @@ __export(Date_exports, {
24
34
  module.exports = __toCommonJS(Date_exports);
25
35
  var import_BaseModule = require("../BaseModule");
26
36
  var import_utils = require("./utils");
37
+ var import_cloneDeep = __toESM(require("lodash-es/cloneDeep"));
27
38
  var DateModule = class extends import_BaseModule.BaseModule {
28
39
  constructor(name, version) {
29
40
  super(name, version);
@@ -58,15 +69,61 @@ var DateModule = class extends import_BaseModule.BaseModule {
58
69
  return this.store.dateRange;
59
70
  }
60
71
  async getResourceDates(params) {
72
+ var _a;
73
+ if (params.useCache) {
74
+ const currentDateList = this.getDateList() || [];
75
+ const currentDateListMap = new Map(
76
+ currentDateList.map((item) => [item.date, item])
77
+ );
78
+ const resourceIds = ((_a = params.query) == null ? void 0 : _a.resource_ids) || [];
79
+ const hasResource = resourceIds.every((id) => {
80
+ var _a2;
81
+ const currentItem = currentDateListMap.get(id.toString());
82
+ return (_a2 = currentItem == null ? void 0 : currentItem.resource) == null ? void 0 : _a2.some((n) => n.id === id);
83
+ });
84
+ if (hasResource) {
85
+ return currentDateList;
86
+ }
87
+ }
61
88
  const dates = await this.getResourceAvailableTimeList(params);
62
- this.store.dateList = dates;
89
+ this.setDateList(dates);
63
90
  return dates;
64
91
  }
65
92
  getDateList() {
66
93
  return this.store.dateList;
67
94
  }
68
95
  setDateList(dateList) {
69
- this.store.dateList = dateList;
96
+ const currentDateList = (0, import_cloneDeep.default)(this.store.dateList) || [];
97
+ dateList.forEach((item) => {
98
+ var _a, _b;
99
+ const currentItemIndex = currentDateList.findIndex(
100
+ (n) => n.date === item.date
101
+ );
102
+ if (currentItemIndex !== -1) {
103
+ const currentItem = currentDateList[currentItemIndex];
104
+ const newResource = (_a = item.resource) == null ? void 0 : _a.filter(
105
+ (n) => {
106
+ var _a2;
107
+ return !((_a2 = currentItem.resource) == null ? void 0 : _a2.some((m) => m.id === n.id));
108
+ }
109
+ );
110
+ (_b = currentItem.resource) == null ? void 0 : _b.forEach((n) => {
111
+ var _a2;
112
+ const newResource2 = (_a2 = item.resource) == null ? void 0 : _a2.find((m) => m.id === n.id);
113
+ if (newResource2) {
114
+ n.times = newResource2.times;
115
+ }
116
+ });
117
+ currentItem.resource = [
118
+ ...currentItem.resource || [],
119
+ ...newResource || []
120
+ ];
121
+ currentDateList[currentItemIndex] = currentItem;
122
+ } else {
123
+ currentDateList.push(item);
124
+ }
125
+ });
126
+ this.store.dateList = currentDateList;
70
127
  }
71
128
  async fetchResourceDates(params) {
72
129
  const { url, query, useCache = true } = params;
@@ -17,6 +17,7 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
17
17
  loadPrepareConfig(params: {
18
18
  action?: 'create';
19
19
  with_good_pass: 0 | 1;
20
+ with_discount_card: 0 | 1;
20
21
  customer_id: number;
21
22
  }): Promise<Discount[]>;
22
23
  batchSearch(code: string): Promise<Discount[]>;