@pisell/pisellos 0.0.156 → 0.0.158

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.
@@ -191,6 +191,15 @@ export var getProductOriginTotalPrice = function getProductOriginTotalPrice(para
191
191
  options = params.options;
192
192
  var num = (params === null || params === void 0 ? void 0 : params.num) || 1;
193
193
  var price = Number(product.original_price);
194
+
195
+ // if (product.discount_list?.length) {
196
+ // price = product.discount_list.reduce((accumulator: any, currentValue: any) => {
197
+ // return (
198
+ // accumulator + Number(currentValue.price) * Number(currentValue.num)
199
+ // );
200
+ // }, price);
201
+ // }
202
+
194
203
  if (isNaN(price) || price === 0) {
195
204
  return undefined;
196
205
  }
@@ -110,7 +110,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
110
110
  // 编辑商品已有商品券
111
111
  if (productList.every(function (item) {
112
112
  var _item$discount_list;
113
- return item.booking_id && ((_item$discount_list = item.discount_list) === null || _item$discount_list === void 0 ? void 0 : _item$discount_list.length);
113
+ return item.booking_id && (((_item$discount_list = item.discount_list) === null || _item$discount_list === void 0 ? void 0 : _item$discount_list.length) || item.price == 0);
114
114
  })) {
115
115
  return {
116
116
  isAvailable: false,
@@ -161,8 +161,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
161
161
  var _this3 = this;
162
162
  var discountList = _ref2.discountList,
163
163
  productList = _ref2.productList;
164
- // debugger
165
-
166
164
  // 识别出来是不是在编辑的界面里又新增了商品
167
165
  // 这种情况下,如果有可用的优惠券,也会自动勾选上
168
166
  var isEditModeAddNewProduct = productList.find(function (n) {
@@ -369,6 +367,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
369
367
  bundle: product.bundle,
370
368
  options: product.options
371
369
  }),
370
+ variant: originProduct._productInit.variant,
371
+ original_price: originProduct._productInit.original_price,
372
372
  total: getProductTotalPrice({
373
373
  product: {
374
374
  price: product.price
@@ -410,43 +410,55 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
410
410
  _id: product._id.split('___')[0]
411
411
  }));
412
412
  }
413
- for (var _i = 0; _i < splitCount; _i++) {
414
- var _selectedDiscount = applicableDiscounts[_i];
413
+ var _loop = function _loop() {
414
+ var selectedDiscount = applicableDiscounts[_i];
415
415
  // 标记优惠券为已使用
416
- usedDiscounts.set(_selectedDiscount.id, true);
416
+ usedDiscounts.set(selectedDiscount.id, true);
417
417
 
418
418
  // 记录实际应用了优惠券的商品信息
419
- var appliedProducts = appliedDiscountProducts.get(_selectedDiscount.id) || [];
420
- 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);
419
+ var appliedProducts = appliedDiscountProducts.get(selectedDiscount.id) || [];
420
+ 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);
421
421
  var discountDetail = {
422
- amount: _selectedDiscount.tag === 'product_discount_card' ? new Decimal(product.price || 0).minus(new Decimal(targetProductPrice)).toNumber() : product.price,
423
- type: _selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : _selectedDiscount.tag,
422
+ amount: selectedDiscount.tag === 'good_pass' ? product.price : new Decimal(product.price || 0).minus(new Decimal(targetProductPrice)).toNumber(),
423
+ type: selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : selectedDiscount.tag,
424
424
  discount: {
425
- resource_id: _selectedDiscount.id,
426
- title: _selectedDiscount.format_title,
427
- original_amount: product.origin_total,
425
+ resource_id: selectedDiscount.id,
426
+ title: selectedDiscount.format_title,
427
+ original_amount: product.origin_total || product.price,
428
428
  product_id: originProduct.id,
429
- percent: _selectedDiscount.par_value
429
+ percent: selectedDiscount.par_value
430
430
  },
431
431
  num: product.num || 1
432
432
  };
433
433
  appliedProducts.push(discountDetail);
434
- appliedDiscountProducts.set(_selectedDiscount.id, appliedProducts);
434
+ appliedDiscountProducts.set(selectedDiscount.id, appliedProducts);
435
435
 
436
436
  // 记录应用了优惠券的商品
437
437
  // 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
438
438
  if (product.isClient) {
439
+ var _originProduct$_produ;
440
+ var variant = (_originProduct$_produ = originProduct._productOrigin.variant) === null || _originProduct$_produ === void 0 ? void 0 : _originProduct$_produ.map(function (n) {
441
+ var _originProduct$_produ2;
442
+ if (n.id === ((_originProduct$_produ2 = originProduct._productOrigin) === null || _originProduct$_produ2 === void 0 ? void 0 : _originProduct$_produ2.product_variant_id)) {
443
+ n.original_price = n.price;
444
+ var _targetProductPrice = selectedDiscount.tag === 'good_pass' ? '0' : new Decimal(100).minus(selectedDiscount.par_value || 0).div(100).mul(new Decimal(n.price || 0)).toFixed(2);
445
+ n.price = _targetProductPrice;
446
+ }
447
+ return n;
448
+ });
439
449
  arr.push(_this3.hooks.setProduct(originProduct, {
440
450
  discount_list: [discountDetail],
441
451
  price: new Decimal(targetProductPrice).toNumber(),
442
452
  quantity: isNeedSplit ? 1 : product.quantity,
443
453
  origin_total: getProductOriginTotalPrice({
444
454
  product: {
445
- original_price: product.original_price
455
+ original_price: targetProductPrice
446
456
  },
447
457
  bundle: product.bundle,
448
458
  options: product.options
449
459
  }),
460
+ variant: variant,
461
+ original_price: new Decimal(targetProductPrice).toNumber(),
450
462
  total: getProductTotalPrice({
451
463
  product: {
452
464
  price: targetProductPrice
@@ -458,13 +470,16 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
458
470
  } else {
459
471
  arr.push(_this3.hooks.setProduct(originProduct, {
460
472
  discount_list: [discountDetail],
461
- _id: product._id.split('___')[0] + "___" + _selectedDiscount.id,
473
+ _id: product._id.split('___')[0] + "___" + selectedDiscount.id,
462
474
  price: new Decimal(targetProductPrice).toNumber(),
463
475
  quantity: isNeedSplit ? 1 : product.quantity,
464
476
  total: new Decimal(product.origin_total || product.total || 0).minus(new Decimal(product.price || 0).minus(new Decimal(targetProductPrice))).toNumber(),
465
477
  origin_total: product.origin_total || product.total
466
478
  }));
467
479
  }
480
+ };
481
+ for (var _i = 0; _i < splitCount; _i++) {
482
+ _loop();
468
483
  }
469
484
  console.log(arr, 'arrarrarr');
470
485
  processedProductsMap.set(product._id, arr);
@@ -486,6 +501,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
486
501
  bundle: product.bundle,
487
502
  options: product.options
488
503
  }),
504
+ variant: originProduct._productInit.variant,
505
+ original_price: originProduct._productInit.original_price,
489
506
  total: getProductTotalPrice({
490
507
  product: {
491
508
  price: product.price
@@ -49,6 +49,8 @@ export interface RulesParamsHooks {
49
49
  origin_total?: number;
50
50
  price?: number;
51
51
  quantity?: number;
52
+ variant?: any[];
53
+ original_price?: number;
52
54
  }) => Record<string, any>;
53
55
  }
54
56
  export {};
@@ -71,7 +71,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
71
71
  }
72
72
  if (productList.every((item) => {
73
73
  var _a;
74
- return item.booking_id && ((_a = item.discount_list) == null ? void 0 : _a.length);
74
+ return item.booking_id && (((_a = item.discount_list) == null ? void 0 : _a.length) || item.price == 0);
75
75
  })) {
76
76
  return {
77
77
  isAvailable: false,
@@ -205,7 +205,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
205
205
  });
206
206
  console.log(sortedProductList, "sortedProductListsortedProductList");
207
207
  sortedProductList.forEach((originProduct, i) => {
208
- var _a, _b, _c, _d, _e;
208
+ var _a, _b, _c, _d, _e, _f;
209
209
  const product = this.hooks.getProduct(originProduct);
210
210
  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
211
  processedProductsMap.set(product._id, [originProduct]);
@@ -246,6 +246,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
246
246
  bundle: product.bundle,
247
247
  options: product.options
248
248
  }),
249
+ variant: originProduct._productInit.variant,
250
+ original_price: originProduct._productInit.original_price,
249
251
  total: (0, import_utils2.getProductTotalPrice)({
250
252
  product: {
251
253
  price: product.price
@@ -292,12 +294,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
292
294
  const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
293
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);
294
296
  const discountDetail = {
295
- amount: selectedDiscount2.tag === "product_discount_card" ? new import_decimal.default(product.price || 0).minus(new import_decimal.default(targetProductPrice)).toNumber() : product.price,
297
+ amount: selectedDiscount2.tag === "good_pass" ? product.price : new import_decimal.default(product.price || 0).minus(new import_decimal.default(targetProductPrice)).toNumber(),
296
298
  type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag,
297
299
  discount: {
298
300
  resource_id: selectedDiscount2.id,
299
301
  title: selectedDiscount2.format_title,
300
- original_amount: product.origin_total,
302
+ original_amount: product.origin_total || product.price,
301
303
  product_id: originProduct.id,
302
304
  percent: selectedDiscount2.par_value
303
305
  },
@@ -306,17 +308,28 @@ var RulesModule = class extends import_BaseModule.BaseModule {
306
308
  appliedProducts.push(discountDetail);
307
309
  appliedDiscountProducts.set(selectedDiscount2.id, appliedProducts);
308
310
  if (product.isClient) {
311
+ const variant = (_f = originProduct._productOrigin.variant) == null ? void 0 : _f.map((n) => {
312
+ var _a2;
313
+ if (n.id === ((_a2 = originProduct._productOrigin) == null ? void 0 : _a2.product_variant_id)) {
314
+ n.original_price = n.price;
315
+ const targetProductPrice2 = selectedDiscount2.tag === "good_pass" ? "0" : new import_decimal.default(100).minus(selectedDiscount2.par_value || 0).div(100).mul(new import_decimal.default(n.price || 0)).toFixed(2);
316
+ n.price = targetProductPrice2;
317
+ }
318
+ return n;
319
+ });
309
320
  arr.push(this.hooks.setProduct(originProduct, {
310
321
  discount_list: [discountDetail],
311
322
  price: new import_decimal.default(targetProductPrice).toNumber(),
312
323
  quantity: isNeedSplit ? 1 : product.quantity,
313
324
  origin_total: (0, import_utils2.getProductOriginTotalPrice)({
314
325
  product: {
315
- original_price: product.original_price
326
+ original_price: targetProductPrice
316
327
  },
317
328
  bundle: product.bundle,
318
329
  options: product.options
319
330
  }),
331
+ variant,
332
+ original_price: new import_decimal.default(targetProductPrice).toNumber(),
320
333
  total: (0, import_utils2.getProductTotalPrice)({
321
334
  product: {
322
335
  price: targetProductPrice
@@ -354,6 +367,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
354
367
  bundle: product.bundle,
355
368
  options: product.options
356
369
  }),
370
+ variant: originProduct._productInit.variant,
371
+ original_price: originProduct._productInit.original_price,
357
372
  total: (0, import_utils2.getProductTotalPrice)({
358
373
  product: {
359
374
  price: product.price
@@ -49,6 +49,8 @@ export interface RulesParamsHooks {
49
49
  origin_total?: number;
50
50
  price?: number;
51
51
  quantity?: number;
52
+ variant?: any[];
53
+ original_price?: number;
52
54
  }) => Record<string, any>;
53
55
  }
54
56
  export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.156",
4
+ "version": "0.0.158",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",