@pisell/pisellos 0.0.148 → 0.0.150

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.
@@ -28,6 +28,13 @@ interface ApplicableProductDetails {
28
28
  title: string;
29
29
  original_amount: string;
30
30
  num: number;
31
+ discount?: {
32
+ product_id?: number;
33
+ original_amount?: string;
34
+ percent?: string;
35
+ resource_id?: number;
36
+ title?: string;
37
+ };
31
38
  }
32
39
  export interface Discount {
33
40
  id: number;
@@ -200,13 +200,33 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
200
200
  }
201
201
  });
202
202
 
203
- // 对productList按价格降序排序(用于应用优惠券时优先选择高价商品)
203
+ // const newProductList = [];
204
+ //
205
+ // productList.forEach(item => {
206
+ // const product = this.hooks.getProduct(item);
207
+ // if (product.quantity > 1) {
208
+ // for (let i = 1; i < product.quantity; i++) {
209
+ // newProductList.push(product)
210
+ // }
211
+ // } else {
212
+ // newProductList.push(item)
213
+ // }
214
+ // })
215
+
216
+ // 对productList按价格降序排序(用于应用优惠券时优先选择高价商品) 价格相同时使用quantity 排序
204
217
  var sortedProductList = _toConsumableArray(productList).sort(function (a, b) {
205
218
  var aProduct = _this3.hooks.getProduct(a);
206
219
  var bProduct = _this3.hooks.getProduct(b);
207
220
  var priceA = new Decimal(aProduct.price || '0');
208
221
  var priceB = new Decimal(bProduct.price || '0');
209
- return priceB.minus(priceA).toNumber();
222
+ if (priceA.toNumber() === priceB.toNumber()) {
223
+ if (aProduct.quantity === bProduct.quantity) {
224
+ var _bProduct$discount_li, _aProduct$discount_li;
225
+ return ((_bProduct$discount_li = bProduct.discount_list) === null || _bProduct$discount_li === void 0 ? void 0 : _bProduct$discount_li.length) - ((_aProduct$discount_li = aProduct.discount_list) === null || _aProduct$discount_li === void 0 ? void 0 : _aProduct$discount_li.length);
226
+ }
227
+ return aProduct.quantity - bProduct.quantity;
228
+ }
229
+ return priceB.toNumber() - priceA.toNumber();
210
230
  });
211
231
 
212
232
  // 标记已使用的优惠券
@@ -242,7 +262,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
242
262
 
243
263
  // 编辑的商品 使用了优惠券不可用
244
264
  var isAvailableProduct = !(product !== null && product !== void 0 && product.booking_id && product !== null && product !== void 0 && (_product$discount_lis = product.discount_list) !== null && _product$discount_lis !== void 0 && _product$discount_lis.length && product !== null && product !== void 0 && (_product$discount_lis2 = product.discount_list) !== null && _product$discount_lis2 !== void 0 && _product$discount_lis2.every(function (discount) {
245
- return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.type);
265
+ return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag);
246
266
  }));
247
267
 
248
268
  // 判断优惠券是否适用于该商品
@@ -260,7 +280,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
260
280
  resource_id: discount.id,
261
281
  title: discount.format_title,
262
282
  original_amount: product.origin_total,
263
- pre_value: discount.par_value
283
+ pre_value: discount.par_value,
284
+ product_id: originProduct.id
264
285
  },
265
286
  num: product.num || 1
266
287
  });
@@ -268,15 +289,16 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
268
289
  }
269
290
  });
270
291
  });
292
+ console.log(sortedProductList, 'sortedProductListsortedProductList');
271
293
 
272
294
  // 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
273
- sortedProductList.forEach(function (originProduct) {
295
+ sortedProductList.forEach(function (originProduct, i) {
274
296
  var _product$discount_lis3, _product$discount_lis4, _product$discount_lis5, _product$discount_lis6, _product$discount_lis7;
275
297
  var product = _this3.hooks.getProduct(originProduct);
276
298
  if (product !== null && product !== void 0 && product.booking_id && (_product$discount_lis3 = product.discount_list) !== null && _product$discount_lis3 !== void 0 && _product$discount_lis3.length && product !== null && product !== void 0 && (_product$discount_lis4 = product.discount_list) !== null && _product$discount_lis4 !== void 0 && _product$discount_lis4.every(function (discount) {
277
- return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.type);
299
+ return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag);
278
300
  })) {
279
- processedProductsMap.set(product._id, originProduct);
301
+ processedProductsMap.set(product._id, [originProduct]);
280
302
  return;
281
303
  }
282
304
 
@@ -286,7 +308,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
286
308
  if (Number(product.price) === 0 || !product.price) return false;
287
309
  // 如果优惠券已被使用,则跳过
288
310
  var targetUsedDiscounts = usedDiscounts.get(discount.id);
289
- if (targetUsedDiscounts && discount.type === 'good_pass') return false;
311
+ if (targetUsedDiscounts && discount.tag === 'good_pass') return false;
290
312
  var limitedData = discount.limited_relation_product_data;
291
313
 
292
314
  // 判断优惠券是否适用于该商品
@@ -307,14 +329,17 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
307
329
  })));
308
330
 
309
331
  // 勾选时覆盖手动折扣
310
- if (options !== null && options !== void 0 && options.discountId && (options === null || options === void 0 ? void 0 : options.discountId) === (selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.id)) {
332
+ if (options !== null && options !== void 0 && options.discountId && product.discount_list.some(function (item) {
333
+ var _item$discount;
334
+ return ((_item$discount = item.discount) === null || _item$discount === void 0 ? void 0 : _item$discount.resource_id) === options.discountId;
335
+ })) {
311
336
  isManualDiscount = false;
312
337
  }
313
338
 
314
339
  // 如果没有适用的优惠券,或者手动折扣,则不适用优惠券
315
340
  if (applicableDiscounts.length === 0 || isManualDiscount) {
316
341
  if (product.isClient) {
317
- processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
342
+ processedProductsMap.set(product._id, [_this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
318
343
  origin_total: getProductOriginTotalPrice({
319
344
  product: {
320
345
  original_price: product.original_price
@@ -332,14 +357,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
332
357
  price: product.price
333
358
  }), {}, {
334
359
  discount_list: []
335
- })));
360
+ }))]);
336
361
  } else {
337
- processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
362
+ processedProductsMap.set(product._id, [_this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
363
+ _id: product._id.split('___')[0] + '___' + i,
338
364
  total: product.origin_total || product.total,
339
365
  price: product.price
340
366
  }), {}, {
341
367
  discount_list: []
342
- })));
368
+ }))]);
343
369
  }
344
370
  return;
345
371
  }
@@ -347,60 +373,80 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
347
373
  return;
348
374
  }
349
375
 
350
- // 标记优惠券为已使用
351
- usedDiscounts.set(selectedDiscount.id, true);
352
-
353
- // 记录实际应用了优惠券的商品信息
354
- var appliedProducts = appliedDiscountProducts.get(selectedDiscount.id) || [];
355
- 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);
356
- var discountDetail = {
357
- amount: selectedDiscount.tag === 'product_discount_card' ? new Decimal(product.price || 0).minus(new Decimal(targetProductPrice)).toNumber() : product.price,
358
- type: selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : selectedDiscount.tag,
359
- discount: {
360
- resource_id: selectedDiscount.id,
361
- title: selectedDiscount.format_title,
362
- original_amount: product.price,
363
- product_id: selectedDiscount.product_id,
364
- percent: selectedDiscount.par_value
365
- },
366
- num: product.num || 1
367
- };
368
- appliedProducts.push(discountDetail);
369
- appliedDiscountProducts.set(selectedDiscount.id, appliedProducts);
370
-
371
- // 记录应用了优惠券的商品
372
- // 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
373
- if (product.isClient) {
374
- processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, {
375
- discount_list: [discountDetail],
376
- price: new Decimal(targetProductPrice).toNumber(),
377
- origin_total: getProductOriginTotalPrice({
378
- product: {
379
- original_price: product.original_price
380
- },
381
- bundle: product.bundle,
382
- options: product.options
383
- }),
384
- total: getProductTotalPrice({
385
- product: {
386
- price: targetProductPrice
387
- },
388
- bundle: product.bundle,
389
- options: product.options
390
- })
391
- }));
392
- } else {
393
- processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, {
394
- discount_list: [discountDetail],
395
- price: new Decimal(targetProductPrice).toNumber(),
396
- total: new Decimal(product.origin_total || product.total || 0).minus(new Decimal(product.price || 0).minus(new Decimal(targetProductPrice))).toNumber(),
397
- origin_total: product.origin_total || product.total
376
+ // 需要拆分出来的数量
377
+ var splitCount = Math.min(product.quantity, applicableDiscounts.length);
378
+ debugger;
379
+ var arr = [];
380
+ if (splitCount < product.quantity) {
381
+ arr.push(_this3.hooks.setProduct(originProduct, {
382
+ discount_list: [],
383
+ quantity: product.quantity - splitCount,
384
+ _id: product._id.split('___')[0]
398
385
  }));
399
386
  }
387
+ for (var _i = 0; _i < splitCount; _i++) {
388
+ var _selectedDiscount = applicableDiscounts[_i];
389
+ // 标记优惠券为已使用
390
+ usedDiscounts.set(_selectedDiscount.id, true);
391
+
392
+ // 记录实际应用了优惠券的商品信息
393
+ var appliedProducts = appliedDiscountProducts.get(_selectedDiscount.id) || [];
394
+ 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);
395
+ var discountDetail = {
396
+ amount: _selectedDiscount.tag === 'product_discount_card' ? new Decimal(product.price || 0).minus(new Decimal(targetProductPrice)).toNumber() : product.price,
397
+ type: _selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : _selectedDiscount.tag,
398
+ discount: {
399
+ resource_id: _selectedDiscount.id,
400
+ title: _selectedDiscount.format_title,
401
+ original_amount: product.origin_total,
402
+ product_id: originProduct.id,
403
+ percent: _selectedDiscount.par_value
404
+ },
405
+ num: product.num || 1
406
+ };
407
+ appliedProducts.push(discountDetail);
408
+ appliedDiscountProducts.set(_selectedDiscount.id, appliedProducts);
409
+
410
+ // 记录应用了优惠券的商品
411
+ // 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
412
+ if (product.isClient) {
413
+ arr.push(_this3.hooks.setProduct(originProduct, {
414
+ discount_list: [discountDetail],
415
+ price: new Decimal(targetProductPrice).toNumber(),
416
+ quantity: 1,
417
+ origin_total: getProductOriginTotalPrice({
418
+ product: {
419
+ original_price: product.original_price
420
+ },
421
+ bundle: product.bundle,
422
+ options: product.options
423
+ }),
424
+ total: getProductTotalPrice({
425
+ product: {
426
+ price: targetProductPrice
427
+ },
428
+ bundle: product.bundle,
429
+ options: product.options
430
+ })
431
+ }));
432
+ } else {
433
+ arr.push(_this3.hooks.setProduct(originProduct, {
434
+ discount_list: [discountDetail],
435
+ _id: product._id.split('___')[0] + "___" + _selectedDiscount.id,
436
+ price: new Decimal(targetProductPrice).toNumber(),
437
+ quantity: 1,
438
+ total: new Decimal(product.origin_total || product.total || 0).minus(new Decimal(product.price || 0).minus(new Decimal(targetProductPrice))).toNumber(),
439
+ origin_total: product.origin_total || product.total
440
+ }));
441
+ }
442
+ }
443
+ console.log(arr, 'arrarrarr');
444
+ processedProductsMap.set(product._id, arr);
400
445
  });
401
446
 
402
447
  // 按原始顺序构建处理后的商品列表
403
- var processedProductList = productList.map(function (originProduct) {
448
+ var processedProductList = [];
449
+ productList.forEach(function (originProduct) {
404
450
  var product = _this3.hooks.getProduct(originProduct);
405
451
  var getDefaultProduct = function getDefaultProduct() {
406
452
  if (product.isClient) {
@@ -431,7 +477,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
431
477
  });
432
478
  }
433
479
  };
434
- return processedProductsMap.get(product._id) || getDefaultProduct();
480
+ var arr = processedProductsMap.get(product._id);
481
+ arr.length ? processedProductList.push.apply(processedProductList, _toConsumableArray(arr)) : processedProductList.push(getDefaultProduct());
435
482
  });
436
483
 
437
484
  // 按原始顺序更新优惠券列表,标记已使用和可用的优惠券
@@ -494,6 +541,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
494
541
  appliedProductDetails: []
495
542
  });
496
543
  });
544
+ console.log(processedProductList, 'processedProductList');
497
545
  return {
498
546
  productList: processedProductList,
499
547
  discountList: [].concat(editModeDiscount, _toConsumableArray(updatedDiscountList))
@@ -38,14 +38,17 @@ type ProductDetail = {
38
38
  bundle?: any[];
39
39
  original_price?: number | string;
40
40
  num?: number;
41
+ quantity: number;
41
42
  };
42
43
  export interface RulesParamsHooks {
43
44
  getProduct: (product: Record<string, any>) => ProductDetail;
44
45
  setProduct: (product: Record<string, any>, values: {
46
+ _id?: string;
45
47
  total?: number;
46
48
  discount_list: any[];
47
49
  origin_total?: number;
48
50
  price?: number;
51
+ quantity?: number;
49
52
  }) => Record<string, any>;
50
53
  }
51
54
  export {};
@@ -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 Decimal from 'decimal.js';
31
32
  export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
32
33
  _inherits(ShopDiscountImpl, _BaseModule);
33
34
  var _super = _createSuper(ShopDiscountImpl);
@@ -447,10 +448,14 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
447
448
  });
448
449
  if (index !== -1) {
449
450
  editModeDiscountList[index] = _objectSpread(_objectSpread({}, editModeDiscountList[index]), {}, {
450
- amount: discount.amount + editModeDiscountList[index].amount
451
+ amount: new Decimal(discount.amount || 0).plus(new Decimal(editModeDiscountList[index].amount || 0)).toNumber(),
452
+ 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()
451
453
  });
452
454
  } else {
453
455
  var _discount$discount2, _discount$discount3, _discount$discount4;
456
+ if (discount.type && !discount.tag) {
457
+ discount.tag = discount.type;
458
+ }
454
459
  editModeDiscountList.push(_objectSpread(_objectSpread({}, discount), {}, {
455
460
  isEditMode: true,
456
461
  limited_relation_product_data: {},
@@ -471,7 +476,11 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
471
476
  return !item.isDisabled;
472
477
  })));
473
478
  var allUsedProductIds = newDiscountList.map(function (n) {
474
- return n.isSelected ? n.applicableProductIds : [];
479
+ var _n$appliedProductDeta;
480
+ return n.isSelected ? (_n$appliedProductDeta = n.appliedProductDetails) === null || _n$appliedProductDeta === void 0 ? void 0 : _n$appliedProductDeta.map(function (n) {
481
+ var _n$discount;
482
+ return (_n$discount = n.discount) === null || _n$discount === void 0 ? void 0 : _n$discount.product_id;
483
+ }) : [];
475
484
  }).flat();
476
485
  newDiscountList.forEach(function (item) {
477
486
  var _item$applicableProdu;
@@ -28,6 +28,13 @@ interface ApplicableProductDetails {
28
28
  title: string;
29
29
  original_amount: string;
30
30
  num: number;
31
+ discount?: {
32
+ product_id?: number;
33
+ original_amount?: string;
34
+ percent?: string;
35
+ resource_id?: number;
36
+ title?: string;
37
+ };
31
38
  }
32
39
  export interface Discount {
33
40
  id: number;
@@ -143,11 +143,18 @@ var RulesModule = class extends import_BaseModule.BaseModule {
143
143
  }
144
144
  });
145
145
  const sortedProductList = [...productList].sort((a, b) => {
146
+ var _a, _b;
146
147
  const aProduct = this.hooks.getProduct(a);
147
148
  const bProduct = this.hooks.getProduct(b);
148
149
  const priceA = new import_decimal.default(aProduct.price || "0");
149
150
  const priceB = new import_decimal.default(bProduct.price || "0");
150
- return priceB.minus(priceA).toNumber();
151
+ if (priceA.toNumber() === priceB.toNumber()) {
152
+ if (aProduct.quantity === bProduct.quantity) {
153
+ return ((_a = bProduct.discount_list) == null ? void 0 : _a.length) - ((_b = aProduct.discount_list) == null ? void 0 : _b.length);
154
+ }
155
+ return aProduct.quantity - bProduct.quantity;
156
+ }
157
+ return priceB.toNumber() - priceA.toNumber();
151
158
  });
152
159
  const usedDiscounts = /* @__PURE__ */ new Map();
153
160
  const discountApplicability = /* @__PURE__ */ new Map();
@@ -164,7 +171,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
164
171
  var _a, _b, _c;
165
172
  const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
166
173
  const isLimitedProduct = limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id);
167
- const isAvailableProduct = !((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.type))));
174
+ const isAvailableProduct = !((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))));
168
175
  if (isAvailableProduct && isLimitedProduct) {
169
176
  (_c = discountApplicability.get(discount.id)) == null ? void 0 : _c.push(product.id);
170
177
  const applicableProducts = discountApplicableProducts.get(discount.id) || [];
@@ -175,7 +182,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
175
182
  resource_id: discount.id,
176
183
  title: discount.format_title,
177
184
  original_amount: product.origin_total,
178
- pre_value: discount.par_value
185
+ pre_value: discount.par_value,
186
+ product_id: originProduct.id
179
187
  },
180
188
  num: product.num || 1
181
189
  });
@@ -183,18 +191,19 @@ var RulesModule = class extends import_BaseModule.BaseModule {
183
191
  }
184
192
  });
185
193
  });
186
- sortedProductList.forEach((originProduct) => {
194
+ console.log(sortedProductList, "sortedProductListsortedProductList");
195
+ sortedProductList.forEach((originProduct, i) => {
187
196
  var _a, _b, _c, _d, _e;
188
197
  const product = this.hooks.getProduct(originProduct);
189
- 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.type)))) {
190
- processedProductsMap.set(product._id, originProduct);
198
+ 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)))) {
199
+ processedProductsMap.set(product._id, [originProduct]);
191
200
  return;
192
201
  }
193
202
  const applicableDiscounts = sortedDiscountList.filter((discount) => {
194
203
  if (Number(product.price) === 0 || !product.price)
195
204
  return false;
196
205
  const targetUsedDiscounts = usedDiscounts.get(discount.id);
197
- if (targetUsedDiscounts && discount.type === "good_pass")
206
+ if (targetUsedDiscounts && discount.tag === "good_pass")
198
207
  return false;
199
208
  const limitedData = discount.limited_relation_product_data;
200
209
  if (limitedData.type === "product_all") {
@@ -206,14 +215,17 @@ var RulesModule = class extends import_BaseModule.BaseModule {
206
215
  });
207
216
  const selectedDiscount = applicableDiscounts[0];
208
217
  let isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && (!((_c = product.discount_list) == null ? void 0 : _c.length) || ((_e = (_d = product == null ? void 0 : product.discount_list) == null ? void 0 : _d.every) == null ? void 0 : _e.call(_d, (item) => item.type === "product")));
209
- if ((options == null ? void 0 : options.discountId) && (options == null ? void 0 : options.discountId) === (selectedDiscount == null ? void 0 : selectedDiscount.id)) {
218
+ if ((options == null ? void 0 : options.discountId) && product.discount_list.some((item) => {
219
+ var _a2;
220
+ return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
221
+ })) {
210
222
  isManualDiscount = false;
211
223
  }
212
224
  if (applicableDiscounts.length === 0 || isManualDiscount) {
213
225
  if (product.isClient) {
214
226
  processedProductsMap.set(
215
227
  product._id,
216
- this.hooks.setProduct(originProduct, {
228
+ [this.hooks.setProduct(originProduct, {
217
229
  ...isManualDiscount ? {} : {
218
230
  origin_total: (0, import_utils2.getProductOriginTotalPrice)({
219
231
  product: {
@@ -232,18 +244,19 @@ var RulesModule = class extends import_BaseModule.BaseModule {
232
244
  price: product.price
233
245
  },
234
246
  discount_list: []
235
- })
247
+ })]
236
248
  );
237
249
  } else {
238
250
  processedProductsMap.set(
239
251
  product._id,
240
- this.hooks.setProduct(originProduct, {
252
+ [this.hooks.setProduct(originProduct, {
241
253
  ...isManualDiscount ? {} : {
254
+ _id: product._id.split("___")[0] + "___" + i,
242
255
  total: product.origin_total || product.total,
243
256
  price: product.price
244
257
  },
245
258
  discount_list: []
246
- })
259
+ })]
247
260
  );
248
261
  }
249
262
  return;
@@ -251,29 +264,40 @@ var RulesModule = class extends import_BaseModule.BaseModule {
251
264
  if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === "undefined" && !(options == null ? void 0 : options.scan)) {
252
265
  return;
253
266
  }
254
- usedDiscounts.set(selectedDiscount.id, true);
255
- const appliedProducts = appliedDiscountProducts.get(selectedDiscount.id) || [];
256
- const targetProductPrice = selectedDiscount.tag === "good_pass" ? "0" : new import_decimal.default(100).minus(selectedDiscount.par_value || 0).div(100).mul(new import_decimal.default(product.price || 0)).toFixed(2);
257
- const discountDetail = {
258
- amount: selectedDiscount.tag === "product_discount_card" ? new import_decimal.default(product.price || 0).minus(new import_decimal.default(targetProductPrice)).toNumber() : product.price,
259
- type: selectedDiscount.tag === "product_discount_card" ? "discount_card" : selectedDiscount.tag,
260
- discount: {
261
- resource_id: selectedDiscount.id,
262
- title: selectedDiscount.format_title,
263
- original_amount: product.price,
264
- product_id: selectedDiscount.product_id,
265
- percent: selectedDiscount.par_value
266
- },
267
- num: product.num || 1
268
- };
269
- appliedProducts.push(discountDetail);
270
- appliedDiscountProducts.set(selectedDiscount.id, appliedProducts);
271
- if (product.isClient) {
272
- processedProductsMap.set(
273
- product._id,
274
- this.hooks.setProduct(originProduct, {
267
+ const splitCount = Math.min(product.quantity, applicableDiscounts.length);
268
+ debugger;
269
+ const arr = [];
270
+ if (splitCount < product.quantity) {
271
+ arr.push(this.hooks.setProduct(originProduct, {
272
+ discount_list: [],
273
+ quantity: product.quantity - splitCount,
274
+ _id: product._id.split("___")[0]
275
+ }));
276
+ }
277
+ for (let i2 = 0; i2 < splitCount; i2++) {
278
+ const selectedDiscount2 = applicableDiscounts[i2];
279
+ usedDiscounts.set(selectedDiscount2.id, true);
280
+ const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
281
+ 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);
282
+ const discountDetail = {
283
+ amount: selectedDiscount2.tag === "product_discount_card" ? new import_decimal.default(product.price || 0).minus(new import_decimal.default(targetProductPrice)).toNumber() : product.price,
284
+ type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag,
285
+ discount: {
286
+ resource_id: selectedDiscount2.id,
287
+ title: selectedDiscount2.format_title,
288
+ original_amount: product.origin_total,
289
+ product_id: originProduct.id,
290
+ percent: selectedDiscount2.par_value
291
+ },
292
+ num: product.num || 1
293
+ };
294
+ appliedProducts.push(discountDetail);
295
+ appliedDiscountProducts.set(selectedDiscount2.id, appliedProducts);
296
+ if (product.isClient) {
297
+ arr.push(this.hooks.setProduct(originProduct, {
275
298
  discount_list: [discountDetail],
276
299
  price: new import_decimal.default(targetProductPrice).toNumber(),
300
+ quantity: 1,
277
301
  origin_total: (0, import_utils2.getProductOriginTotalPrice)({
278
302
  product: {
279
303
  original_price: product.original_price
@@ -288,21 +312,23 @@ var RulesModule = class extends import_BaseModule.BaseModule {
288
312
  bundle: product.bundle,
289
313
  options: product.options
290
314
  })
291
- })
292
- );
293
- } else {
294
- processedProductsMap.set(
295
- product._id,
296
- this.hooks.setProduct(originProduct, {
315
+ }));
316
+ } else {
317
+ arr.push(this.hooks.setProduct(originProduct, {
297
318
  discount_list: [discountDetail],
319
+ _id: product._id.split("___")[0] + "___" + selectedDiscount2.id,
298
320
  price: new import_decimal.default(targetProductPrice).toNumber(),
321
+ quantity: 1,
299
322
  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(),
300
323
  origin_total: product.origin_total || product.total
301
- })
302
- );
324
+ }));
325
+ }
303
326
  }
327
+ console.log(arr, "arrarrarr");
328
+ processedProductsMap.set(product._id, arr);
304
329
  });
305
- const processedProductList = productList.map((originProduct) => {
330
+ const processedProductList = [];
331
+ productList.forEach((originProduct) => {
306
332
  const product = this.hooks.getProduct(originProduct);
307
333
  const getDefaultProduct = () => {
308
334
  if (product.isClient) {
@@ -333,7 +359,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
333
359
  });
334
360
  }
335
361
  };
336
- return processedProductsMap.get(product._id) || getDefaultProduct();
362
+ const arr = processedProductsMap.get(product._id);
363
+ arr.length ? processedProductList.push(...arr) : processedProductList.push(getDefaultProduct());
337
364
  });
338
365
  const updatedDiscountList = addModeDiscount.map((discount) => {
339
366
  const applicableProducts = discountApplicability.get(discount.id) || [];
@@ -386,6 +413,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
386
413
  appliedProductDetails: []
387
414
  };
388
415
  });
416
+ console.log(processedProductList, "processedProductList");
389
417
  return {
390
418
  productList: processedProductList,
391
419
  discountList: [...editModeDiscount, ...updatedDiscountList]
@@ -38,14 +38,17 @@ type ProductDetail = {
38
38
  bundle?: any[];
39
39
  original_price?: number | string;
40
40
  num?: number;
41
+ quantity: number;
41
42
  };
42
43
  export interface RulesParamsHooks {
43
44
  getProduct: (product: Record<string, any>) => ProductDetail;
44
45
  setProduct: (product: Record<string, any>, values: {
46
+ _id?: string;
45
47
  total?: number;
46
48
  discount_list: any[];
47
49
  origin_total?: number;
48
50
  price?: number;
51
+ quantity?: number;
49
52
  }) => Record<string, any>;
50
53
  }
51
54
  export {};
@@ -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/solution/ShopDiscount/index.ts
@@ -27,6 +37,7 @@ var import_BaseModule = require("../../modules/BaseModule");
27
37
  var import_types = require("./types");
28
38
  var import_Discount = require("../../modules/Discount");
29
39
  var import_Rules = require("../../modules/Rules");
40
+ var import_decimal = __toESM(require("decimal.js"));
30
41
  var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
31
42
  constructor(name, version) {
32
43
  super(name, version);
@@ -283,9 +294,13 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
283
294
  if (index !== -1) {
284
295
  editModeDiscountList[index] = {
285
296
  ...editModeDiscountList[index],
286
- amount: discount.amount + editModeDiscountList[index].amount
297
+ amount: new import_decimal.default(discount.amount || 0).plus(new import_decimal.default(editModeDiscountList[index].amount || 0)).toNumber(),
298
+ savedAmount: new import_decimal.default(discount.amount || 0).times((product == null ? void 0 : product.num) || 1).plus(new import_decimal.default(editModeDiscountList[index].savedAmount || 0)).toNumber()
287
299
  };
288
300
  } else {
301
+ if (discount.type && !discount.tag) {
302
+ discount.tag = discount.type;
303
+ }
289
304
  editModeDiscountList.push({
290
305
  ...discount,
291
306
  isEditMode: true,
@@ -307,7 +322,13 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
307
322
  ...editModeDiscountList,
308
323
  ...discountList.filter((item) => !item.isDisabled)
309
324
  ];
310
- const allUsedProductIds = newDiscountList.map((n) => n.isSelected ? n.applicableProductIds : []).flat();
325
+ const allUsedProductIds = newDiscountList.map((n) => {
326
+ var _a2;
327
+ return n.isSelected ? (_a2 = n.appliedProductDetails) == null ? void 0 : _a2.map((n2) => {
328
+ var _a3;
329
+ return (_a3 = n2.discount) == null ? void 0 : _a3.product_id;
330
+ }) : [];
331
+ }).flat();
311
332
  newDiscountList.forEach((item) => {
312
333
  var _a2;
313
334
  const isAllProductUsed = (_a2 = item.applicableProductIds) == null ? void 0 : _a2.every((id) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.148",
4
+ "version": "0.0.150",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",