@pisell/pisellos 0.0.263 → 0.0.265

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.
@@ -12,6 +12,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
12
12
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
13
  import Decimal from 'decimal.js';
14
14
  import { isNormalProduct } from "../../Product/utils";
15
+ import { getDiscountAmount } from "../../../solution/ShopDiscount/utils";
15
16
 
16
17
  /**
17
18
  * @title 处理组合商品
@@ -192,8 +193,14 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
192
193
  // 不是商品券则代表折扣卡,计算打折后的价格
193
194
  // 一个商品折扣卡只能存在于一张
194
195
  if (currentValue.type !== 'good_pass') {
195
- var discountPrice = new Decimal(100).minus(currentValue.discount.percent || 0).div(100).mul(new Decimal(price || 0)).toFixed(2);
196
- price = Number(discountPrice);
196
+ var _currentValue$discoun;
197
+ price = getDiscountAmount({
198
+ tag: currentValue.type,
199
+ par_value: currentValue.discount.percent,
200
+ metadata: {
201
+ discount_card_type: currentValue === null || currentValue === void 0 || (_currentValue$discoun = currentValue.discount) === null || _currentValue$discoun === void 0 ? void 0 : _currentValue$discoun.discount_card_type
202
+ }
203
+ }, price, price);
197
204
  }
198
205
  });
199
206
  }
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "duration" | "session" | "normal";
52
+ getProductType(): "normal" | "duration" | "session";
53
53
  }
@@ -316,7 +316,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
316
316
 
317
317
  // 判断优惠券是否适用于该商品
318
318
  if (isAvailableProduct && isLimitedProduct) {
319
- var _discountApplicabilit;
319
+ var _discountApplicabilit, _discount$metadata;
320
320
  // 记录此优惠券适用的商品
321
321
  (_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
322
322
 
@@ -328,6 +328,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
328
328
  type: discountType,
329
329
  tag: discountType,
330
330
  discount: {
331
+ discount_card_type: discount === null || discount === void 0 || (_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.discount_card_type,
331
332
  resource_id: discount.id,
332
333
  title: discount.format_title,
333
334
  original_amount: product.origin_total,
@@ -469,7 +470,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
469
470
  }));
470
471
  }
471
472
  for (var _i = 0; _i < splitCount; _i++) {
472
- var _product$discount_lis12, _originProduct$_produ;
473
+ var _product$discount_lis12, _originProduct$_produ, _selectedDiscount$met;
473
474
  // 如果用过折扣卡,也就不存在拆分的情况了,这里直接使用上面计算出来的折扣卡
474
475
  var _selectedDiscount = selectedDiscountCard || applicableDiscounts[_i];
475
476
  // 标记优惠券为已使用
@@ -496,6 +497,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
496
497
  amount: new Decimal(productOriginTotal).minus(new Decimal(targetProductTotal)).toNumber(),
497
498
  type: discountType,
498
499
  discount: {
500
+ discount_card_type: _selectedDiscount === null || _selectedDiscount === void 0 || (_selectedDiscount$met = _selectedDiscount.metadata) === null || _selectedDiscount$met === void 0 ? void 0 : _selectedDiscount$met.discount_card_type,
499
501
  resource_id: _selectedDiscount.id,
500
502
  title: _selectedDiscount.format_title,
501
503
  original_amount: productOriginTotal,
@@ -314,7 +314,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
314
314
  }[];
315
315
  setOtherData(key: string, value: any): void;
316
316
  getOtherData(key: string): any;
317
- getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
317
+ getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
318
318
  /**
319
319
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
320
320
  *
@@ -44,6 +44,7 @@ __export(cartProduct_exports, {
44
44
  module.exports = __toCommonJS(cartProduct_exports);
45
45
  var import_decimal = __toESM(require("decimal.js"));
46
46
  var import_utils = require("../../Product/utils");
47
+ var import_utils2 = require("../../../solution/ShopDiscount/utils");
47
48
  var handleVariantProduct = (product) => {
48
49
  var _a;
49
50
  if (product == null ? void 0 : product.product_variant_id) {
@@ -183,9 +184,15 @@ var getProductTotalPrice = (params) => {
183
184
  }
184
185
  if (discounts == null ? void 0 : discounts.length) {
185
186
  discounts.forEach((currentValue) => {
187
+ var _a;
186
188
  if (currentValue.type !== "good_pass") {
187
- const discountPrice = new import_decimal.default(100).minus(currentValue.discount.percent || 0).div(100).mul(new import_decimal.default(price || 0)).toFixed(2);
188
- price = Number(discountPrice);
189
+ price = (0, import_utils2.getDiscountAmount)({
190
+ tag: currentValue.type,
191
+ par_value: currentValue.discount.percent,
192
+ metadata: {
193
+ discount_card_type: (_a = currentValue == null ? void 0 : currentValue.discount) == null ? void 0 : _a.discount_card_type
194
+ }
195
+ }, price, price);
189
196
  }
190
197
  });
191
198
  }
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "duration" | "session" | "normal";
52
+ getProductType(): "normal" | "duration" | "session";
53
53
  }
@@ -198,7 +198,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
198
198
  sortedProductList.forEach((originProduct) => {
199
199
  const product = this.hooks.getProduct(originProduct);
200
200
  addModeDiscount.forEach((discount) => {
201
- var _a, _b, _c;
201
+ var _a, _b, _c, _d;
202
202
  const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
203
203
  const isLimitedProduct = limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id);
204
204
  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 || discount2.type))));
@@ -211,6 +211,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
211
211
  type: discountType,
212
212
  tag: discountType,
213
213
  discount: {
214
+ discount_card_type: (_d = discount == null ? void 0 : discount.metadata) == null ? void 0 : _d.discount_card_type,
214
215
  resource_id: discount.id,
215
216
  title: discount.format_title,
216
217
  original_amount: product.origin_total,
@@ -228,7 +229,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
228
229
  });
229
230
  console.log(sortedProductList, "sortedProductListsortedProductList");
230
231
  sortedProductList.forEach((originProduct, i) => {
231
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
232
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
232
233
  const product = this.hooks.getProduct(originProduct);
233
234
  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)))) {
234
235
  processedProductsMap.set(product._id, [originProduct]);
@@ -344,6 +345,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
344
345
  amount: new import_decimal.default(productOriginTotal).minus(new import_decimal.default(targetProductTotal)).toNumber(),
345
346
  type: discountType,
346
347
  discount: {
348
+ discount_card_type: (_j = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _j.discount_card_type,
347
349
  resource_id: selectedDiscount2.id,
348
350
  title: selectedDiscount2.format_title,
349
351
  original_amount: productOriginTotal,
@@ -314,7 +314,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
314
314
  }[];
315
315
  setOtherData(key: string, value: any): void;
316
316
  getOtherData(key: string): any;
317
- getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
317
+ getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
318
318
  /**
319
319
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
320
320
  *
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.263",
4
+ "version": "0.0.265",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",