@pisell/pisellos 2.1.12 → 2.1.14
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.
- package/dist/modules/Cart/utils/cartProduct.js +9 -2
- package/dist/modules/Discount/types.d.ts +3 -0
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/Rules/index.js +41 -12
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/ShopDiscount/utils.d.ts +11 -0
- package/dist/solution/ShopDiscount/utils.js +29 -0
- package/lib/modules/Cart/utils/cartProduct.js +9 -2
- package/lib/modules/Discount/types.d.ts +3 -0
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Rules/index.js +27 -7
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/ShopDiscount/utils.d.ts +11 -0
- package/lib/solution/ShopDiscount/utils.js +24 -0
- package/package.json +1 -1
|
@@ -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
|
|
196
|
-
price =
|
|
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
|
}
|
|
@@ -70,6 +70,9 @@ export interface Discount {
|
|
|
70
70
|
limited_relation_product_data: Limitedrelationproductdata;
|
|
71
71
|
balance: string;
|
|
72
72
|
format_title: Formattitle;
|
|
73
|
+
metadata?: {
|
|
74
|
+
discount_card_type?: 'fixed_amount' | 'percent';
|
|
75
|
+
};
|
|
73
76
|
product: Product;
|
|
74
77
|
type: "product" | 'good_pass';
|
|
75
78
|
resource_id?: number;
|
|
@@ -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(): "
|
|
52
|
+
getProductType(): "duration" | "session" | "normal";
|
|
53
53
|
}
|
|
@@ -25,7 +25,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
25
25
|
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); }
|
|
26
26
|
import { BaseModule } from "../BaseModule";
|
|
27
27
|
import { RulesHooks } from "./types";
|
|
28
|
-
import { uniqueById } from "../../solution/ShopDiscount/utils";
|
|
28
|
+
import { uniqueById, getDiscountAmount } from "../../solution/ShopDiscount/utils";
|
|
29
29
|
import { getProductOriginTotalPrice, getProductTotalPrice } from "../Cart/utils";
|
|
30
30
|
import Decimal from 'decimal.js';
|
|
31
31
|
import { isBoolean } from 'lodash-es';
|
|
@@ -189,8 +189,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
189
189
|
});
|
|
190
190
|
|
|
191
191
|
// 优惠力度排序,传进来的数据里可能有商品券,也可能有优惠券
|
|
192
|
-
// 商品券(n.tag=good_pass
|
|
193
|
-
//
|
|
192
|
+
// 1. 商品券(n.tag=good_pass)视为最优惠(免费)
|
|
193
|
+
// 2. 折扣券(n.tag=product_discount_card)按照新的优先级排序:
|
|
194
|
+
// - 固定金额优先于百分比(固定金额 > 百分比)
|
|
195
|
+
// - 固定金额内部:金额越大越优先
|
|
196
|
+
// - 百分比内部:折扣越大越优先(par_value越小越优先)
|
|
197
|
+
// 3. 相同类型和金额的情况下,按照过期时间(n.expire_time)排序
|
|
194
198
|
var sortedDiscountList = _toConsumableArray(filteredDiscountList).sort(function (a, b) {
|
|
195
199
|
// 1. 商品券优先级最高
|
|
196
200
|
if (a.tag === 'good_pass' && b.tag !== 'good_pass') return -1;
|
|
@@ -201,13 +205,34 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
201
205
|
// 都是商品券,按照过期时间排序
|
|
202
206
|
return compareByExpireTime(a, b);
|
|
203
207
|
} else if (a.tag === 'product_discount_card' && b.tag === 'product_discount_card') {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
208
|
+
var _a$metadata, _b$metadata;
|
|
209
|
+
// 都是折扣券,按照新的优先级排序:固定金额优先于百分比
|
|
210
|
+
var typeA = ((_a$metadata = a.metadata) === null || _a$metadata === void 0 ? void 0 : _a$metadata.discount_card_type) || 'percent'; // 默认为百分比
|
|
211
|
+
var typeB = ((_b$metadata = b.metadata) === null || _b$metadata === void 0 ? void 0 : _b$metadata.discount_card_type) || 'percent'; // 默认为百分比
|
|
212
|
+
|
|
213
|
+
// 1. 固定金额优先于百分比
|
|
214
|
+
if (typeA === 'fixed_amount' && typeB === 'percent') return -1;
|
|
215
|
+
if (typeA === 'percent' && typeB === 'fixed_amount') return 1;
|
|
216
|
+
|
|
217
|
+
// 2. 都是固定金额时,金额越大越优先
|
|
218
|
+
if (typeA === 'fixed_amount' && typeB === 'fixed_amount') {
|
|
219
|
+
if (a.par_value !== b.par_value) {
|
|
220
|
+
var valueA = new Decimal(a.par_value || 0);
|
|
221
|
+
var valueB = new Decimal(b.par_value || 0);
|
|
222
|
+
return valueB.minus(valueA).toNumber(); // 金额大的在前
|
|
223
|
+
}
|
|
209
224
|
}
|
|
210
|
-
|
|
225
|
+
|
|
226
|
+
// 3. 都是百分比时,折扣越大越优先(par_value越小越优先)
|
|
227
|
+
if (typeA === 'percent' && typeB === 'percent') {
|
|
228
|
+
if (a.par_value !== b.par_value) {
|
|
229
|
+
var _valueA = new Decimal(100).minus(a.par_value || 0);
|
|
230
|
+
var _valueB = new Decimal(100).minus(b.par_value || 0);
|
|
231
|
+
return _valueB.minus(_valueA).toNumber(); // 折扣大的在前
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// 相同类型和金额的情况下,按照过期时间排序
|
|
211
236
|
return compareByExpireTime(a, b);
|
|
212
237
|
}
|
|
213
238
|
|
|
@@ -291,7 +316,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
291
316
|
|
|
292
317
|
// 判断优惠券是否适用于该商品
|
|
293
318
|
if (isAvailableProduct && isLimitedProduct) {
|
|
294
|
-
var _discountApplicabilit;
|
|
319
|
+
var _discountApplicabilit, _discount$metadata;
|
|
295
320
|
// 记录此优惠券适用的商品
|
|
296
321
|
(_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
|
|
297
322
|
|
|
@@ -303,6 +328,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
303
328
|
type: discountType,
|
|
304
329
|
tag: discountType,
|
|
305
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,
|
|
332
|
+
fixed_amount: product.price,
|
|
306
333
|
resource_id: discount.id,
|
|
307
334
|
title: discount.format_title,
|
|
308
335
|
original_amount: product.origin_total,
|
|
@@ -444,7 +471,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
444
471
|
}));
|
|
445
472
|
}
|
|
446
473
|
for (var _i = 0; _i < splitCount; _i++) {
|
|
447
|
-
var _product$discount_lis12, _originProduct$_produ;
|
|
474
|
+
var _product$discount_lis12, _originProduct$_produ, _selectedDiscount$met;
|
|
448
475
|
// 如果用过折扣卡,也就不存在拆分的情况了,这里直接使用上面计算出来的折扣卡
|
|
449
476
|
var _selectedDiscount = selectedDiscountCard || applicableDiscounts[_i];
|
|
450
477
|
// 标记优惠券为已使用
|
|
@@ -465,12 +492,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
465
492
|
}
|
|
466
493
|
|
|
467
494
|
// 计算使用折扣卡/商品券以后,单个商品的总 total
|
|
468
|
-
var targetProductTotal = _selectedDiscount
|
|
495
|
+
var targetProductTotal = getDiscountAmount(_selectedDiscount, productOriginTotal, product.price);
|
|
469
496
|
var discountType = _selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : _selectedDiscount.tag;
|
|
470
497
|
var discountDetail = {
|
|
471
498
|
amount: new Decimal(productOriginTotal).minus(new Decimal(targetProductTotal)).toNumber(),
|
|
472
499
|
type: discountType,
|
|
473
500
|
discount: {
|
|
501
|
+
discount_card_type: _selectedDiscount === null || _selectedDiscount === void 0 || (_selectedDiscount$met = _selectedDiscount.metadata) === null || _selectedDiscount$met === void 0 ? void 0 : _selectedDiscount$met.discount_card_type,
|
|
502
|
+
fixed_amount: new Decimal(productOriginTotal).minus(new Decimal(targetProductTotal)).toNumber(),
|
|
474
503
|
resource_id: _selectedDiscount.id,
|
|
475
504
|
title: _selectedDiscount.format_title,
|
|
476
505
|
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<"
|
|
317
|
+
getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
|
|
318
318
|
/**
|
|
319
319
|
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
320
320
|
*
|
|
@@ -1 +1,12 @@
|
|
|
1
|
+
import { Discount } from "../../modules/Discount/types";
|
|
1
2
|
export declare const uniqueById: <T>(arr: T[], key?: string) => T[];
|
|
3
|
+
/**
|
|
4
|
+
* 获取折扣金额 基于折扣卡类型计算
|
|
5
|
+
* 商品券:直接返回商品价格
|
|
6
|
+
* 折扣卡:根据折扣卡类型计算 固定金额:直接返回折扣卡金额 百分比:根据折扣卡金额计算
|
|
7
|
+
* @param discount
|
|
8
|
+
* @param total
|
|
9
|
+
* @param price
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare const getDiscountAmount: (discount: Discount, total: number, price: number) => number;
|
|
@@ -1,7 +1,36 @@
|
|
|
1
|
+
import Decimal from "decimal.js";
|
|
1
2
|
export var uniqueById = function uniqueById(arr) {
|
|
2
3
|
var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'id';
|
|
3
4
|
var seen = new Set();
|
|
4
5
|
return arr.filter(function (item) {
|
|
5
6
|
return !seen.has(item[key]) && seen.add(item[key]);
|
|
6
7
|
});
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 获取折扣金额 基于折扣卡类型计算
|
|
12
|
+
* 商品券:直接返回商品价格
|
|
13
|
+
* 折扣卡:根据折扣卡类型计算 固定金额:直接返回折扣卡金额 百分比:根据折扣卡金额计算
|
|
14
|
+
* @param discount
|
|
15
|
+
* @param total
|
|
16
|
+
* @param price
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
export var getDiscountAmount = function getDiscountAmount(discount, total, price) {
|
|
20
|
+
var _discount$metadata;
|
|
21
|
+
// 商品券
|
|
22
|
+
if (discount.tag === 'good_pass') {
|
|
23
|
+
return new Decimal(total).minus(new Decimal(price || 0)).toNumber();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 判断是否是固定金额
|
|
27
|
+
var isFixedAmount = (discount === null || discount === void 0 || (_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.discount_card_type) === 'fixed_amount';
|
|
28
|
+
|
|
29
|
+
// 固定金额 小于0时返回0
|
|
30
|
+
if (isFixedAmount) {
|
|
31
|
+
return Math.max(new Decimal(total).minus(new Decimal(discount.par_value || 0)).toNumber(), 0);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// 百分比:根据折扣卡金额计算
|
|
35
|
+
return new Decimal(100).minus(discount.par_value || 0).div(100).mul(new Decimal(total)).toNumber();
|
|
7
36
|
};
|
|
@@ -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
|
-
|
|
188
|
-
|
|
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
|
}
|
|
@@ -70,6 +70,9 @@ export interface Discount {
|
|
|
70
70
|
limited_relation_product_data: Limitedrelationproductdata;
|
|
71
71
|
balance: string;
|
|
72
72
|
format_title: Formattitle;
|
|
73
|
+
metadata?: {
|
|
74
|
+
discount_card_type?: 'fixed_amount' | 'percent';
|
|
75
|
+
};
|
|
73
76
|
product: Product;
|
|
74
77
|
type: "product" | 'good_pass';
|
|
75
78
|
resource_id?: number;
|
|
@@ -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(): "
|
|
52
|
+
getProductType(): "duration" | "session" | "normal";
|
|
53
53
|
}
|
|
@@ -132,6 +132,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
132
132
|
return !discount.isManualSelect;
|
|
133
133
|
});
|
|
134
134
|
const sortedDiscountList = [...filteredDiscountList].sort((a, b) => {
|
|
135
|
+
var _a, _b;
|
|
135
136
|
if (a.tag === "good_pass" && b.tag !== "good_pass")
|
|
136
137
|
return -1;
|
|
137
138
|
if (b.tag === "good_pass" && a.tag !== "good_pass")
|
|
@@ -139,10 +140,25 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
139
140
|
if (a.tag === "good_pass" && b.tag === "good_pass") {
|
|
140
141
|
return compareByExpireTime(a, b);
|
|
141
142
|
} else if (a.tag === "product_discount_card" && b.tag === "product_discount_card") {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
return
|
|
143
|
+
const typeA = ((_a = a.metadata) == null ? void 0 : _a.discount_card_type) || "percent";
|
|
144
|
+
const typeB = ((_b = b.metadata) == null ? void 0 : _b.discount_card_type) || "percent";
|
|
145
|
+
if (typeA === "fixed_amount" && typeB === "percent")
|
|
146
|
+
return -1;
|
|
147
|
+
if (typeA === "percent" && typeB === "fixed_amount")
|
|
148
|
+
return 1;
|
|
149
|
+
if (typeA === "fixed_amount" && typeB === "fixed_amount") {
|
|
150
|
+
if (a.par_value !== b.par_value) {
|
|
151
|
+
const valueA = new import_decimal.default(a.par_value || 0);
|
|
152
|
+
const valueB = new import_decimal.default(b.par_value || 0);
|
|
153
|
+
return valueB.minus(valueA).toNumber();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (typeA === "percent" && typeB === "percent") {
|
|
157
|
+
if (a.par_value !== b.par_value) {
|
|
158
|
+
const valueA = new import_decimal.default(100).minus(a.par_value || 0);
|
|
159
|
+
const valueB = new import_decimal.default(100).minus(b.par_value || 0);
|
|
160
|
+
return valueB.minus(valueA).toNumber();
|
|
161
|
+
}
|
|
146
162
|
}
|
|
147
163
|
return compareByExpireTime(a, b);
|
|
148
164
|
}
|
|
@@ -182,7 +198,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
182
198
|
sortedProductList.forEach((originProduct) => {
|
|
183
199
|
const product = this.hooks.getProduct(originProduct);
|
|
184
200
|
addModeDiscount.forEach((discount) => {
|
|
185
|
-
var _a, _b, _c;
|
|
201
|
+
var _a, _b, _c, _d;
|
|
186
202
|
const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
|
|
187
203
|
const isLimitedProduct = limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id);
|
|
188
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))));
|
|
@@ -195,6 +211,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
195
211
|
type: discountType,
|
|
196
212
|
tag: discountType,
|
|
197
213
|
discount: {
|
|
214
|
+
discount_card_type: (_d = discount == null ? void 0 : discount.metadata) == null ? void 0 : _d.discount_card_type,
|
|
215
|
+
fixed_amount: product.price,
|
|
198
216
|
resource_id: discount.id,
|
|
199
217
|
title: discount.format_title,
|
|
200
218
|
original_amount: product.origin_total,
|
|
@@ -212,7 +230,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
212
230
|
});
|
|
213
231
|
console.log(sortedProductList, "sortedProductListsortedProductList");
|
|
214
232
|
sortedProductList.forEach((originProduct, i) => {
|
|
215
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
233
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
216
234
|
const product = this.hooks.getProduct(originProduct);
|
|
217
235
|
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)))) {
|
|
218
236
|
processedProductsMap.set(product._id, [originProduct]);
|
|
@@ -322,12 +340,14 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
322
340
|
if (Number(((_i = originProduct == null ? void 0 : originProduct._productInit) == null ? void 0 : _i.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
|
|
323
341
|
productOriginTotal = product.total;
|
|
324
342
|
}
|
|
325
|
-
const targetProductTotal =
|
|
343
|
+
const targetProductTotal = (0, import_utils.getDiscountAmount)(selectedDiscount2, productOriginTotal, product.price);
|
|
326
344
|
const discountType = selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag;
|
|
327
345
|
const discountDetail = {
|
|
328
346
|
amount: new import_decimal.default(productOriginTotal).minus(new import_decimal.default(targetProductTotal)).toNumber(),
|
|
329
347
|
type: discountType,
|
|
330
348
|
discount: {
|
|
349
|
+
discount_card_type: (_j = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _j.discount_card_type,
|
|
350
|
+
fixed_amount: new import_decimal.default(productOriginTotal).minus(new import_decimal.default(targetProductTotal)).toNumber(),
|
|
331
351
|
resource_id: selectedDiscount2.id,
|
|
332
352
|
title: selectedDiscount2.format_title,
|
|
333
353
|
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<"
|
|
317
|
+
getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
|
|
318
318
|
/**
|
|
319
319
|
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
320
320
|
*
|
|
@@ -1 +1,12 @@
|
|
|
1
|
+
import { Discount } from "../../modules/Discount/types";
|
|
1
2
|
export declare const uniqueById: <T>(arr: T[], key?: string) => T[];
|
|
3
|
+
/**
|
|
4
|
+
* 获取折扣金额 基于折扣卡类型计算
|
|
5
|
+
* 商品券:直接返回商品价格
|
|
6
|
+
* 折扣卡:根据折扣卡类型计算 固定金额:直接返回折扣卡金额 百分比:根据折扣卡金额计算
|
|
7
|
+
* @param discount
|
|
8
|
+
* @param total
|
|
9
|
+
* @param price
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare const getDiscountAmount: (discount: Discount, total: number, price: number) => number;
|
|
@@ -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,19 +16,41 @@ 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/utils.ts
|
|
20
30
|
var utils_exports = {};
|
|
21
31
|
__export(utils_exports, {
|
|
32
|
+
getDiscountAmount: () => getDiscountAmount,
|
|
22
33
|
uniqueById: () => uniqueById
|
|
23
34
|
});
|
|
24
35
|
module.exports = __toCommonJS(utils_exports);
|
|
36
|
+
var import_decimal = __toESM(require("decimal.js"));
|
|
25
37
|
var uniqueById = (arr, key = "id") => {
|
|
26
38
|
const seen = /* @__PURE__ */ new Set();
|
|
27
39
|
return arr.filter((item) => !seen.has(item[key]) && seen.add(item[key]));
|
|
28
40
|
};
|
|
41
|
+
var getDiscountAmount = (discount, total, price) => {
|
|
42
|
+
var _a;
|
|
43
|
+
if (discount.tag === "good_pass") {
|
|
44
|
+
return new import_decimal.default(total).minus(new import_decimal.default(price || 0)).toNumber();
|
|
45
|
+
}
|
|
46
|
+
const isFixedAmount = ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.discount_card_type) === "fixed_amount";
|
|
47
|
+
if (isFixedAmount) {
|
|
48
|
+
return Math.max(new import_decimal.default(total).minus(new import_decimal.default(discount.par_value || 0)).toNumber(), 0);
|
|
49
|
+
}
|
|
50
|
+
return new import_decimal.default(100).minus(discount.par_value || 0).div(100).mul(new import_decimal.default(total)).toNumber();
|
|
51
|
+
};
|
|
29
52
|
// Annotate the CommonJS export names for ESM import in node:
|
|
30
53
|
0 && (module.exports = {
|
|
54
|
+
getDiscountAmount,
|
|
31
55
|
uniqueById
|
|
32
56
|
});
|