@pisell/pisellos 1.0.15 → 1.0.17

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.
@@ -303,7 +303,7 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
303
303
  key: "removeAccount",
304
304
  value: function () {
305
305
  var _removeAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(id) {
306
- var index;
306
+ var _this$getActiveAccoun, index;
307
307
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
308
308
  while (1) switch (_context6.prev = _context6.next) {
309
309
  case 0:
@@ -324,26 +324,31 @@ export var AccountListModule = /*#__PURE__*/function (_BaseModule) {
324
324
  this.store.accountList = this.store.accountList.filter(function (account) {
325
325
  return account.id !== id;
326
326
  });
327
- _context6.next = 11;
327
+
328
+ // 检测 如果被删除的是活跃账号,则默认把第一个账号设置为 activeAccount
329
+ if (((_this$getActiveAccoun = this.getActiveAccount()) === null || _this$getActiveAccoun === void 0 ? void 0 : _this$getActiveAccoun.getId()) === id) {
330
+ this.setActiveAccount(this.store.accounts[0].getId());
331
+ }
332
+ _context6.next = 12;
328
333
  return this.core.effects.emit(AccountListHooks.OnAccountListUpdate, this.store);
329
- case 11:
330
- _context6.next = 18;
334
+ case 12:
335
+ _context6.next = 19;
331
336
  break;
332
- case 13:
333
- _context6.prev = 13;
337
+ case 14:
338
+ _context6.prev = 14;
334
339
  _context6.t0 = _context6["catch"](0);
335
340
  this.store.error = _context6.t0 instanceof Error ? _context6.t0.message : 'Failed to remove account';
336
- _context6.next = 18;
341
+ _context6.next = 19;
337
342
  return this.core.effects.emit(AccountListHooks.OnAccountListError, this.store.error);
338
- case 18:
339
- _context6.prev = 18;
343
+ case 19:
344
+ _context6.prev = 19;
340
345
  this.store.isLoading = false;
341
- return _context6.finish(18);
342
- case 21:
346
+ return _context6.finish(19);
347
+ case 22:
343
348
  case "end":
344
349
  return _context6.stop();
345
350
  }
346
- }, _callee6, this, [[0, 13, 18, 21]]);
351
+ }, _callee6, this, [[0, 14, 19, 22]]);
347
352
  }));
348
353
  function removeAccount(_x9) {
349
354
  return _removeAccount.apply(this, arguments);
@@ -256,7 +256,8 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
256
256
  bundle: bundle,
257
257
  options: options,
258
258
  product_variant_id: newProduct.product_variant_id,
259
- quantity: quantity
259
+ quantity: quantity,
260
+ discounts: discounts
260
261
  });
261
262
  }
262
263
  if (discounts) {
@@ -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
  * 获取商品原始总价
@@ -48,7 +48,8 @@ export var formatProductToCartItem = function formatProductToCartItem(params) {
48
48
  options = params.options,
49
49
  product_variant_id = params.product_variant_id,
50
50
  _params$quantity = params.quantity,
51
- quantity = _params$quantity === void 0 ? 1 : _params$quantity;
51
+ quantity = _params$quantity === void 0 ? 1 : _params$quantity,
52
+ discounts = params.discounts;
52
53
  var num = quantity; // 当前按照单个商品加入购物车
53
54
  if (product) {
54
55
  cartItem.id = product === null || product === void 0 ? void 0 : product.id;
@@ -59,7 +60,8 @@ export var formatProductToCartItem = function formatProductToCartItem(params) {
59
60
  product: product,
60
61
  bundle: bundle,
61
62
  options: options,
62
- num: num
63
+ num: num,
64
+ discounts: discounts
63
65
  });
64
66
  cartItem.summaryTotal = cartItem.total * (num || 1);
65
67
  cartItem.origin_total = getProductOriginTotalPrice({
@@ -161,7 +163,8 @@ export var formatProductToCartItemOrigin = function formatProductToCartItemOrigi
161
163
  export var getProductTotalPrice = function getProductTotalPrice(params) {
162
164
  var product = params.product,
163
165
  bundle = params.bundle,
164
- options = params.options;
166
+ options = params.options,
167
+ discounts = params.discounts;
165
168
  // const num = params.num || 1;
166
169
  var price = Number(product.price);
167
170
  if (bundle !== null && bundle !== void 0 && bundle.length) {
@@ -176,6 +179,18 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
176
179
  return accumulator + Number(currentValue.price) * Number(currentValue.num);
177
180
  }, price);
178
181
  }
182
+
183
+ // 如果商品有折扣,则计算折扣
184
+ if (discounts !== null && discounts !== void 0 && discounts.length) {
185
+ discounts.forEach(function (currentValue) {
186
+ // 不是商品券则代表折扣卡,计算打折后的价格
187
+ // 一个商品折扣卡只能存在于一张
188
+ if (currentValue.type !== 'good_pass') {
189
+ var discountPrice = new Decimal(100).minus(currentValue.discount.percent || 0).div(100).mul(new Decimal(price || 0)).toFixed(2);
190
+ price = Number(discountPrice);
191
+ }
192
+ });
193
+ }
179
194
  return price;
180
195
  };
181
196
 
@@ -129,10 +129,9 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
129
129
  return this.request.post("/order/prepare/config", params);
130
130
  case 2:
131
131
  prepareConfig = _context3.sent;
132
- goodPassList = this.filterEnabledDiscountList([].concat(_toConsumableArray((prepareConfig === null || prepareConfig === void 0 || (_prepareConfig$data = prepareConfig.data) === null || _prepareConfig$data === void 0 ? void 0 : _prepareConfig$data.good_pass_list) || []), _toConsumableArray((prepareConfig === null || prepareConfig === void 0 || (_prepareConfig$data2 = prepareConfig.data) === null || _prepareConfig$data2 === void 0 ? void 0 : _prepareConfig$data2.discount_card_list) || []))) || [];
133
- this.setDiscountList(goodPassList);
132
+ goodPassList = this.filterEnabledDiscountList([].concat(_toConsumableArray((prepareConfig === null || prepareConfig === void 0 || (_prepareConfig$data = prepareConfig.data) === null || _prepareConfig$data === void 0 ? void 0 : _prepareConfig$data.good_pass_list) || []), _toConsumableArray((prepareConfig === null || prepareConfig === void 0 || (_prepareConfig$data2 = prepareConfig.data) === null || _prepareConfig$data2 === void 0 ? void 0 : _prepareConfig$data2.discount_card_list) || []))) || []; // this.setDiscountList(goodPassList);
134
133
  return _context3.abrupt("return", goodPassList);
135
- case 6:
134
+ case 5:
136
135
  case "end":
137
136
  return _context3.stop();
138
137
  }
@@ -119,8 +119,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
119
119
  };
120
120
  }
121
121
 
122
- // 合并新旧折扣列表,并计算折扣结果
123
- var mergedDiscountList = uniqueById(uniqueById([].concat(_toConsumableArray(oldDiscountList), _toConsumableArray(newDiscountList))), 'product_id');
122
+ // 合并新旧折扣列表,并计算折扣结果,注意,如果旧折扣里有 isEditMode 为 true 的优惠券,则不合并
123
+ var filteredOldDiscountList = oldDiscountList.filter(function (discount) {
124
+ return !discount.isEditMode && discount.tag !== 'good_pass';
125
+ });
126
+ var mergedDiscountList = uniqueById(uniqueById([].concat(_toConsumableArray(filteredOldDiscountList), _toConsumableArray(newDiscountList))), 'product_id');
124
127
  var result = this.calcDiscount({
125
128
  discountList: mergedDiscountList,
126
129
  productList: _toConsumableArray(productList)
@@ -412,44 +415,37 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
412
415
  _id: product._id.split('___')[0]
413
416
  }));
414
417
  }
415
- var _loop = function _loop() {
416
- var selectedDiscount = applicableDiscounts[_i];
418
+ for (var _i = 0; _i < splitCount; _i++) {
419
+ var _selectedDiscount = applicableDiscounts[_i];
417
420
  // 标记优惠券为已使用
418
- usedDiscounts.set(selectedDiscount.id, true);
421
+ usedDiscounts.set(_selectedDiscount.id, true);
419
422
 
420
423
  // 记录实际应用了优惠券的商品信息
421
- var appliedProducts = appliedDiscountProducts.get(selectedDiscount.id) || [];
422
- var targetProductPrice = selectedDiscount.tag === 'good_pass' ? '0' : new Decimal(100).minus(selectedDiscount.par_value || 0).div(100).mul(new Decimal(product.price || 0)).toFixed(2);
424
+ var appliedProducts = appliedDiscountProducts.get(_selectedDiscount.id) || [];
425
+
426
+ // 计算使用折扣卡/商品券以后,单个商品的总 total
427
+ var targetProductTotal = _selectedDiscount.tag === 'good_pass' ? new Decimal(product.origin_total || 0).minus(new Decimal(product.price || 0)).toNumber() : new Decimal(100).minus(_selectedDiscount.par_value || 0).div(100).mul(new Decimal(product.origin_total || 0)).toNumber();
423
428
  var discountDetail = {
424
- amount: selectedDiscount.tag === 'product_discount_card' ? new Decimal(product.price || 0).minus(new Decimal(targetProductPrice)).toNumber() : product.price,
425
- type: selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : selectedDiscount.tag,
429
+ amount: new Decimal(product.origin_total || 0).minus(new Decimal(targetProductTotal)).toNumber(),
430
+ type: _selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : _selectedDiscount.tag,
426
431
  discount: {
427
- resource_id: selectedDiscount.id,
428
- title: selectedDiscount.format_title,
432
+ resource_id: _selectedDiscount.id,
433
+ title: _selectedDiscount.format_title,
429
434
  original_amount: product.origin_total,
430
435
  product_id: originProduct.id,
431
- percent: selectedDiscount.par_value
436
+ percent: _selectedDiscount.par_value
432
437
  },
433
438
  num: product.num || 1
434
439
  };
435
440
  appliedProducts.push(discountDetail);
436
- appliedDiscountProducts.set(selectedDiscount.id, appliedProducts);
441
+ appliedDiscountProducts.set(_selectedDiscount.id, appliedProducts);
437
442
 
438
443
  // 记录应用了优惠券的商品
439
444
  // 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
440
445
  if (product.isClient) {
441
- var _originProduct$_produ;
442
- var variant = (_originProduct$_produ = originProduct._productOrigin.variant) === null || _originProduct$_produ === void 0 ? void 0 : _originProduct$_produ.map(function (n) {
443
- if (n.id === originProduct._productOrigin.product_variant_id) {
444
- n.original_price = originProduct._productInit.price;
445
- var _targetProductPrice = selectedDiscount.tag === 'good_pass' ? '0' : new Decimal(100).minus(selectedDiscount.par_value || 0).div(100).mul(new Decimal(originProduct._productInit.price || 0)).toFixed(2);
446
- n.price = _targetProductPrice;
447
- }
448
- return n;
449
- });
450
446
  arr.push(_this3.hooks.setProduct(originProduct, {
451
447
  discount_list: [discountDetail],
452
- price: new Decimal(targetProductPrice).toNumber(),
448
+ price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
453
449
  quantity: isNeedSplit ? 1 : product.quantity,
454
450
  origin_total: getProductOriginTotalPrice({
455
451
  product: {
@@ -458,29 +454,19 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
458
454
  bundle: product.bundle,
459
455
  options: product.options
460
456
  }),
461
- variant: variant,
462
- original_price: new Decimal(product.price).toNumber(),
463
- total: getProductTotalPrice({
464
- product: {
465
- price: targetProductPrice
466
- },
467
- bundle: product.bundle,
468
- options: product.options
469
- })
457
+ original_price: new Decimal(product.price || 0).toNumber(),
458
+ total: targetProductTotal
470
459
  }));
471
460
  } else {
472
461
  arr.push(_this3.hooks.setProduct(originProduct, {
473
462
  discount_list: [discountDetail],
474
- _id: product._id.split('___')[0] + "___" + selectedDiscount.id,
475
- price: new Decimal(targetProductPrice).toNumber(),
463
+ _id: product._id.split('___')[0] + "___" + _selectedDiscount.id,
464
+ price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
476
465
  quantity: isNeedSplit ? 1 : product.quantity,
477
- total: new Decimal(product.origin_total || product.total || 0).minus(new Decimal(product.price || 0).minus(new Decimal(targetProductPrice))).toNumber(),
466
+ total: targetProductTotal,
478
467
  origin_total: product.origin_total || product.total
479
468
  }));
480
469
  }
481
- };
482
- for (var _i = 0; _i < splitCount; _i++) {
483
- _loop();
484
470
  }
485
471
  console.log(arr, 'arrarrarr');
486
472
  processedProductsMap.set(product._id, arr);
@@ -555,6 +541,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
555
541
  if (usedDiscounts.get(discount.id)) {
556
542
  return _objectSpread(_objectSpread({}, discount), {}, {
557
543
  isSelected: true,
544
+ isManualSelect: options !== null && options !== void 0 && options.scan ? false : discount.isManualSelect,
558
545
  // 标记为可用,因为它已被应用
559
546
  isAvailable: true,
560
547
  // 记录适用的商品IDs
@@ -577,6 +564,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
577
564
  // 如果有适用的商品,标记为可用
578
565
  isAvailable: isAvailable,
579
566
  isSelected: isSelected,
567
+ // 如果是扫码进来的,要手动设置为手动选择:false
568
+ isManualSelect: options !== null && options !== void 0 && options.scan ? false : discount.isManualSelect,
580
569
  // 记录适用的商品IDs
581
570
  applicableProductIds: applicableProducts,
582
571
  // 添加可抵扣的商品详情
@@ -47,7 +47,7 @@ export interface RulesParamsHooks {
47
47
  total?: number;
48
48
  discount_list: any[];
49
49
  origin_total?: number;
50
- price?: number;
50
+ price?: string | number;
51
51
  variant?: any[];
52
52
  original_price?: number;
53
53
  quantity?: number;
@@ -1410,17 +1410,27 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1410
1410
  resources.push.apply(resources, _toConsumableArray(_this10.store.date.getResourcesListByDate(n.date) || []));
1411
1411
  });
1412
1412
  }
1413
+ var cartItems = this.store.cart.getItems().filter(function (n) {
1414
+ return !isNormalProduct(n._productOrigin);
1415
+ });
1416
+
1413
1417
  // 如果此时 resources 为空,视作购物车里已经有了 dateRange 数据,此时 dateList 里明确就是那一天的数据
1414
1418
  if (!resources.length) {
1415
- var dateList = this.store.date.getDateList();
1416
- dateList.forEach(function (n) {
1417
- if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1419
+ // 如果此时购物车里已经有了开始时间,则直接取那天的数据即可
1420
+ var firstDateCartItem = cartItems === null || cartItems === void 0 ? void 0 : cartItems.find(function (n) {
1421
+ return n.start_date;
1418
1422
  });
1423
+ if (firstDateCartItem !== null && firstDateCartItem !== void 0 && firstDateCartItem.start_date) {
1424
+ var dateResources = this.store.date.getResourcesListByDate(firstDateCartItem.start_date);
1425
+ resources.push.apply(resources, _toConsumableArray(dateResources || []));
1426
+ } else {
1427
+ var dateList = this.store.date.getDateList();
1428
+ dateList.forEach(function (n) {
1429
+ if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1430
+ });
1431
+ }
1419
1432
  }
1420
1433
  var resourcesMap = getResourcesMap(cloneDeep(resources));
1421
- var cartItems = this.store.cart.getItems().filter(function (n) {
1422
- return !isNormalProduct(n._productOrigin);
1423
- });
1424
1434
  var arr = [];
1425
1435
  cartItems.forEach(function (cartItem) {
1426
1436
  var _cartItem$_productOri;
@@ -574,7 +574,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
574
574
  key: "loadPrepareConfig",
575
575
  value: function () {
576
576
  var _loadPrepareConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
577
- var _this$getCustomer2, _this$store$discount7, _this$getDiscountList, _this$store$productLi, customerId, goodPassList, scanDiscount, newDiscountList, result;
577
+ var _this$getCustomer2, _this$store$discount7, _this$getDiscountList, _this$store$productLi, customerId, goodPassList, scanDiscount, scanDiscountIds, newGoodPassList, newDiscountList, result;
578
578
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
579
579
  while (1) switch (_context8.prev = _context8.next) {
580
580
  case 0:
@@ -593,31 +593,37 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
593
593
  goodPassList = _context8.sent;
594
594
  scanDiscount = (_this$getDiscountList = this.getDiscountList()) === null || _this$getDiscountList === void 0 ? void 0 : _this$getDiscountList.filter(function (item) {
595
595
  return item.isScan;
596
+ }); // goodPassList 里可能有 scanDiscount 重合的部分,goodPassList 需要剔除
597
+ scanDiscountIds = scanDiscount.map(function (n) {
598
+ return n.id;
596
599
  });
597
- newDiscountList = [].concat(_toConsumableArray(scanDiscount), _toConsumableArray(goodPassList || []));
600
+ newGoodPassList = goodPassList === null || goodPassList === void 0 ? void 0 : goodPassList.filter(function (n) {
601
+ return !scanDiscountIds.includes(n.id);
602
+ });
603
+ newDiscountList = [].concat(_toConsumableArray(scanDiscount), _toConsumableArray(newGoodPassList || []));
598
604
  this.setDiscountList(newDiscountList || []);
599
605
  if (!((_this$store$productLi = this.store.productList) !== null && _this$store$productLi !== void 0 && _this$store$productLi.length)) {
600
- _context8.next = 12;
606
+ _context8.next = 14;
601
607
  break;
602
608
  }
603
609
  result = this.calcDiscount(this.store.productList);
604
- _context8.next = 12;
605
- return this.core.effects.emit(ShopDiscountHooks.onLoadPrepareCalcResult, result);
606
- case 12:
607
610
  _context8.next = 14;
608
- return this.core.effects.emit(ShopDiscountHooks.onLoadDiscountList, newDiscountList);
611
+ return this.core.effects.emit(ShopDiscountHooks.onLoadPrepareCalcResult, result);
609
612
  case 14:
610
- _context8.next = 19;
611
- break;
613
+ _context8.next = 16;
614
+ return this.core.effects.emit(ShopDiscountHooks.onLoadDiscountList, newDiscountList);
612
615
  case 16:
613
- _context8.prev = 16;
616
+ _context8.next = 21;
617
+ break;
618
+ case 18:
619
+ _context8.prev = 18;
614
620
  _context8.t0 = _context8["catch"](0);
615
621
  console.error('[ShopDiscount] 加载准备配置出错:', _context8.t0);
616
- case 19:
622
+ case 21:
617
623
  case "end":
618
624
  return _context8.stop();
619
625
  }
620
- }, _callee8, this, [[0, 16]]);
626
+ }, _callee8, this, [[0, 18]]);
621
627
  }));
622
628
  function loadPrepareConfig(_x7) {
623
629
  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 (((_a = this.getActiveAccount()) == null ? void 0 : _a.getId()) === id) {
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
@@ -158,7 +158,8 @@ var CartModule = class extends import_BaseModule.BaseModule {
158
158
  bundle,
159
159
  options,
160
160
  product_variant_id: newProduct.product_variant_id,
161
- quantity
161
+ quantity,
162
+ discounts
162
163
  });
163
164
  }
164
165
  if (discounts) {
@@ -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
  * 获取商品原始总价
@@ -65,7 +65,8 @@ var formatProductToCartItem = (params) => {
65
65
  bundle,
66
66
  options,
67
67
  product_variant_id,
68
- quantity = 1
68
+ quantity = 1,
69
+ discounts
69
70
  } = params;
70
71
  const num = quantity;
71
72
  if (product) {
@@ -73,7 +74,7 @@ var formatProductToCartItem = (params) => {
73
74
  cartItem.name = product == null ? void 0 : product.title;
74
75
  cartItem.price = product == null ? void 0 : product.price;
75
76
  cartItem.num = num;
76
- cartItem.total = getProductTotalPrice({ product, bundle, options, num });
77
+ cartItem.total = getProductTotalPrice({ product, bundle, options, num, discounts });
77
78
  cartItem.summaryTotal = cartItem.total * (num || 1);
78
79
  cartItem.origin_total = getProductOriginTotalPrice({
79
80
  product,
@@ -163,7 +164,7 @@ var formatProductToCartItemOrigin = (params) => {
163
164
  return origin;
164
165
  };
165
166
  var getProductTotalPrice = (params) => {
166
- const { product, bundle, options } = params;
167
+ const { product, bundle, options, discounts } = params;
167
168
  let price = Number(product.price);
168
169
  if (bundle == null ? void 0 : bundle.length) {
169
170
  price = bundle.reduce((accumulator, currentValue) => {
@@ -175,6 +176,14 @@ var getProductTotalPrice = (params) => {
175
176
  return accumulator + Number(currentValue.price) * Number(currentValue.num);
176
177
  }, price);
177
178
  }
179
+ if (discounts == null ? void 0 : discounts.length) {
180
+ discounts.forEach((currentValue) => {
181
+ if (currentValue.type !== "good_pass") {
182
+ const discountPrice = new import_decimal.default(100).minus(currentValue.discount.percent || 0).div(100).mul(new import_decimal.default(price || 0)).toFixed(2);
183
+ price = Number(discountPrice);
184
+ }
185
+ });
186
+ }
178
187
  return price;
179
188
  };
180
189
  var getProductOriginTotalPrice = (params) => {
@@ -87,7 +87,6 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
87
87
  const goodPassList = this.filterEnabledDiscountList(
88
88
  [...((_a = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _a.good_pass_list) || [], ...((_b = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _b.discount_card_list) || []]
89
89
  ) || [];
90
- this.setDiscountList(goodPassList);
91
90
  return goodPassList;
92
91
  }
93
92
  async batchSearch(code) {
@@ -79,8 +79,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
79
79
  productList
80
80
  };
81
81
  }
82
+ const filteredOldDiscountList = oldDiscountList.filter((discount) => !discount.isEditMode && discount.tag !== "good_pass");
82
83
  const mergedDiscountList = (0, import_utils.uniqueById)((0, import_utils.uniqueById)([
83
- ...oldDiscountList,
84
+ ...filteredOldDiscountList,
84
85
  ...newDiscountList
85
86
  ]), "product_id");
86
87
  const result = this.calcDiscount({
@@ -205,7 +206,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
205
206
  });
206
207
  console.log(sortedProductList, "sortedProductListsortedProductList");
207
208
  sortedProductList.forEach((originProduct, i) => {
208
- var _a, _b, _c, _d, _e, _f;
209
+ var _a, _b, _c, _d, _e;
209
210
  const product = this.hooks.getProduct(originProduct);
210
211
  if ((product == null ? void 0 : product.booking_id) && ((_a = product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount) => discount.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount.tag || discount.type)))) {
211
212
  processedProductsMap.set(product._id, [originProduct]);
@@ -292,9 +293,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
292
293
  const selectedDiscount2 = applicableDiscounts[i2];
293
294
  usedDiscounts.set(selectedDiscount2.id, true);
294
295
  const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
295
- const targetProductPrice = selectedDiscount2.tag === "good_pass" ? "0" : new import_decimal.default(100).minus(selectedDiscount2.par_value || 0).div(100).mul(new import_decimal.default(product.price || 0)).toFixed(2);
296
+ const targetProductTotal = selectedDiscount2.tag === "good_pass" ? new import_decimal.default(product.origin_total || 0).minus(new import_decimal.default(product.price || 0)).toNumber() : new import_decimal.default(100).minus(selectedDiscount2.par_value || 0).div(100).mul(new import_decimal.default(product.origin_total || 0)).toNumber();
296
297
  const discountDetail = {
297
- amount: selectedDiscount2.tag === "product_discount_card" ? new import_decimal.default(product.price || 0).minus(new import_decimal.default(targetProductPrice)).toNumber() : product.price,
298
+ amount: new import_decimal.default(product.origin_total || 0).minus(new import_decimal.default(targetProductTotal)).toNumber(),
298
299
  type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag,
299
300
  discount: {
300
301
  resource_id: selectedDiscount2.id,
@@ -308,17 +309,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
308
309
  appliedProducts.push(discountDetail);
309
310
  appliedDiscountProducts.set(selectedDiscount2.id, appliedProducts);
310
311
  if (product.isClient) {
311
- const variant = (_f = originProduct._productOrigin.variant) == null ? void 0 : _f.map((n) => {
312
- if (n.id === originProduct._productOrigin.product_variant_id) {
313
- n.original_price = originProduct._productInit.price;
314
- const targetProductPrice2 = selectedDiscount2.tag === "good_pass" ? "0" : new import_decimal.default(100).minus(selectedDiscount2.par_value || 0).div(100).mul(new import_decimal.default(originProduct._productInit.price || 0)).toFixed(2);
315
- n.price = targetProductPrice2;
316
- }
317
- return n;
318
- });
319
312
  arr.push(this.hooks.setProduct(originProduct, {
320
313
  discount_list: [discountDetail],
321
- price: new import_decimal.default(targetProductPrice).toNumber(),
314
+ price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
322
315
  quantity: isNeedSplit ? 1 : product.quantity,
323
316
  origin_total: (0, import_utils2.getProductOriginTotalPrice)({
324
317
  product: {
@@ -327,23 +320,16 @@ var RulesModule = class extends import_BaseModule.BaseModule {
327
320
  bundle: product.bundle,
328
321
  options: product.options
329
322
  }),
330
- variant,
331
- original_price: new import_decimal.default(product.price).toNumber(),
332
- total: (0, import_utils2.getProductTotalPrice)({
333
- product: {
334
- price: targetProductPrice
335
- },
336
- bundle: product.bundle,
337
- options: product.options
338
- })
323
+ original_price: new import_decimal.default(product.price || 0).toNumber(),
324
+ total: targetProductTotal
339
325
  }));
340
326
  } else {
341
327
  arr.push(this.hooks.setProduct(originProduct, {
342
328
  discount_list: [discountDetail],
343
329
  _id: product._id.split("___")[0] + "___" + selectedDiscount2.id,
344
- price: new import_decimal.default(targetProductPrice).toNumber(),
330
+ price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
345
331
  quantity: isNeedSplit ? 1 : product.quantity,
346
- total: new import_decimal.default(product.origin_total || product.total || 0).minus(new import_decimal.default(product.price || 0).minus(new import_decimal.default(targetProductPrice))).toNumber(),
332
+ total: targetProductTotal,
347
333
  origin_total: product.origin_total || product.total
348
334
  }));
349
335
  }
@@ -410,6 +396,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
410
396
  return {
411
397
  ...discount,
412
398
  isSelected: true,
399
+ isManualSelect: (options == null ? void 0 : options.scan) ? false : discount.isManualSelect,
413
400
  // 标记为可用,因为它已被应用
414
401
  isAvailable: true,
415
402
  // 记录适用的商品IDs
@@ -431,6 +418,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
431
418
  // 如果有适用的商品,标记为可用
432
419
  isAvailable,
433
420
  isSelected,
421
+ // 如果是扫码进来的,要手动设置为手动选择:false
422
+ isManualSelect: (options == null ? void 0 : options.scan) ? false : discount.isManualSelect,
434
423
  // 记录适用的商品IDs
435
424
  applicableProductIds: applicableProducts,
436
425
  // 添加可抵扣的商品详情
@@ -47,7 +47,7 @@ export interface RulesParamsHooks {
47
47
  total?: number;
48
48
  discount_list: any[];
49
49
  origin_total?: number;
50
- price?: number;
50
+ price?: string | number;
51
51
  variant?: any[];
52
52
  original_price?: number;
53
53
  quantity?: number;
@@ -820,15 +820,21 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
820
820
  resources.push(...this.store.date.getResourcesListByDate(n.date) || []);
821
821
  });
822
822
  }
823
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
823
824
  if (!resources.length) {
824
- const dateList = this.store.date.getDateList();
825
- dateList.forEach((n) => {
826
- if (n.resource)
827
- resources.push(...n.resource);
828
- });
825
+ const firstDateCartItem = cartItems == null ? void 0 : cartItems.find((n) => n.start_date);
826
+ if (firstDateCartItem == null ? void 0 : firstDateCartItem.start_date) {
827
+ const dateResources = this.store.date.getResourcesListByDate(firstDateCartItem.start_date);
828
+ resources.push(...dateResources || []);
829
+ } else {
830
+ const dateList = this.store.date.getDateList();
831
+ dateList.forEach((n) => {
832
+ if (n.resource)
833
+ resources.push(...n.resource);
834
+ });
835
+ }
829
836
  }
830
837
  const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
831
- const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
832
838
  const arr = [];
833
839
  cartItems.forEach((cartItem) => {
834
840
  var _a, _b, _c, _d, _e, _f;
@@ -398,7 +398,9 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
398
398
  const scanDiscount = (_c = this.getDiscountList()) == null ? void 0 : _c.filter(
399
399
  (item) => item.isScan
400
400
  );
401
- const newDiscountList = [...scanDiscount, ...goodPassList || []];
401
+ const scanDiscountIds = scanDiscount.map((n) => n.id);
402
+ const newGoodPassList = goodPassList == null ? void 0 : goodPassList.filter((n) => !scanDiscountIds.includes(n.id));
403
+ const newDiscountList = [...scanDiscount, ...newGoodPassList || []];
402
404
  this.setDiscountList(newDiscountList || []);
403
405
  if ((_d = this.store.productList) == null ? void 0 : _d.length) {
404
406
  const result = this.calcDiscount(this.store.productList);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "1.0.15",
4
+ "version": "1.0.17",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",