@pisell/pisellos 2.1.51 → 2.1.53
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/Discount/index.d.ts +1 -0
- package/dist/modules/Discount/index.js +1 -1
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/Rules/index.d.ts +9 -2
- package/dist/modules/Rules/index.js +49 -6
- package/dist/modules/Rules/types.d.ts +4 -0
- package/dist/solution/BookingByStep/utils/capacity.js +1 -2
- package/dist/solution/ShopDiscount/index.d.ts +3 -0
- package/dist/solution/ShopDiscount/index.js +15 -4
- package/dist/solution/ShopDiscount/types.d.ts +5 -0
- package/lib/modules/Discount/index.d.ts +1 -0
- package/lib/modules/Discount/index.js +1 -1
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Rules/index.d.ts +9 -2
- package/lib/modules/Rules/index.js +45 -6
- package/lib/modules/Rules/types.d.ts +4 -0
- package/lib/solution/BookingByStep/utils/capacity.js +1 -2
- package/lib/solution/ShopDiscount/index.d.ts +3 -0
- package/lib/solution/ShopDiscount/index.js +11 -3
- package/lib/solution/ShopDiscount/types.d.ts +5 -0
- package/package.json +1 -1
|
@@ -21,6 +21,7 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
|
|
|
21
21
|
with_good_pass: 0 | 1;
|
|
22
22
|
with_discount_card: 0 | 1;
|
|
23
23
|
customer_id: number;
|
|
24
|
+
with_wallet_pass_holder: 0 | 1;
|
|
24
25
|
}): Promise<Discount[]>;
|
|
25
26
|
batchSearch(code: string, customerId?: number): Promise<Discount[]>;
|
|
26
27
|
filterEnabledDiscountList(discountList: Discount[]): Discount[];
|
|
@@ -188,7 +188,7 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
188
188
|
tags: ['good_pass', 'product_discount_card'],
|
|
189
189
|
available: 1,
|
|
190
190
|
relation_product: 1,
|
|
191
|
-
with: ['extensionData'],
|
|
191
|
+
with: ['extensionData', 'holder.detail'],
|
|
192
192
|
order_behavior_count: 1,
|
|
193
193
|
order_behavior_count_customer_id: customerId || 1
|
|
194
194
|
});
|
|
@@ -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(): "normal" | "duration" | "session";
|
|
53
53
|
}
|
|
@@ -12,18 +12,25 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
|
|
|
12
12
|
initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
|
|
13
13
|
setRulesList(rulesList: Rules[]): Promise<void>;
|
|
14
14
|
getRulesList(): Rules[];
|
|
15
|
-
|
|
15
|
+
private checkHolderMatch;
|
|
16
|
+
isDiscountListAvailable({ oldDiscountList, newDiscountList, productList, holders, }: {
|
|
16
17
|
oldDiscountList: Discount[];
|
|
17
18
|
newDiscountList: Discount[];
|
|
18
19
|
productList: any[];
|
|
20
|
+
holders: {
|
|
21
|
+
form_record_id: number;
|
|
22
|
+
}[];
|
|
19
23
|
}): {
|
|
20
24
|
isAvailable: boolean;
|
|
21
25
|
discountList: Discount[];
|
|
22
26
|
productList: any[];
|
|
23
27
|
};
|
|
24
|
-
calcDiscount({ discountList, productList, }: {
|
|
28
|
+
calcDiscount({ discountList, productList, holders, }: {
|
|
25
29
|
discountList: Discount[];
|
|
26
30
|
productList: any[];
|
|
31
|
+
holders: {
|
|
32
|
+
form_record_id: number;
|
|
33
|
+
}[];
|
|
27
34
|
}, options?: {
|
|
28
35
|
isSelected?: boolean;
|
|
29
36
|
discountId?: number;
|
|
@@ -29,6 +29,9 @@ import { getProductOriginTotalPrice, getProductTotalPrice } from "../Cart/utils"
|
|
|
29
29
|
import Decimal from 'decimal.js';
|
|
30
30
|
import { isBoolean } from 'lodash-es';
|
|
31
31
|
import dayjs from 'dayjs';
|
|
32
|
+
|
|
33
|
+
// 临时变量
|
|
34
|
+
var flatItem;
|
|
32
35
|
export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
33
36
|
_inherits(RulesModule, _BaseModule);
|
|
34
37
|
var _super = _createSuper(RulesModule);
|
|
@@ -91,6 +94,25 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
91
94
|
return this.store.rulesList;
|
|
92
95
|
}
|
|
93
96
|
|
|
97
|
+
// 商品不需要holder,则不需要判断,直接返回true,商品需要holder但是还没填写,那么暂时不使用带有holder的券,直到填写才去匹配
|
|
98
|
+
}, {
|
|
99
|
+
key: "checkHolderMatch",
|
|
100
|
+
value: function checkHolderMatch(discount, product, holders) {
|
|
101
|
+
var _discount$holder;
|
|
102
|
+
// 非表单类型 holder 视为匹配
|
|
103
|
+
if (((_discount$holder = discount.holder) === null || _discount$holder === void 0 ? void 0 : _discount$holder.holder_type) !== 'form') return true;
|
|
104
|
+
// 主预约holder, 目前(20251124)默认只考虑单个holder的情况
|
|
105
|
+
var orderHolderId = Array.isArray(holders) && holders.length > 0 ? holders[0].form_record_id : undefined;
|
|
106
|
+
var productHolderId = Array.isArray(product.holder_id) ? product.holder_id[0] : product.holder_id;
|
|
107
|
+
// 商品不需要选holder,则不对比holder,直接返回true,
|
|
108
|
+
if (!product.isNeedHolder) return true;
|
|
109
|
+
// 商品需要holder,但父预约及商品都无holder,返回false
|
|
110
|
+
if (!orderHolderId && !productHolderId) return false;
|
|
111
|
+
|
|
112
|
+
// 最终直接匹配 holder 是否相同
|
|
113
|
+
return (productHolderId || orderHolderId) === discount.holder.holder_id;
|
|
114
|
+
}
|
|
115
|
+
|
|
94
116
|
// 判断discountList 是否可以对当前productList生效
|
|
95
117
|
}, {
|
|
96
118
|
key: "isDiscountListAvailable",
|
|
@@ -98,7 +120,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
98
120
|
var _this2 = this;
|
|
99
121
|
var oldDiscountList = _ref.oldDiscountList,
|
|
100
122
|
newDiscountList = _ref.newDiscountList,
|
|
101
|
-
productList = _ref.productList
|
|
123
|
+
productList = _ref.productList,
|
|
124
|
+
holders = _ref.holders;
|
|
102
125
|
// 首先检查是否有新的优惠券可应用
|
|
103
126
|
if (!newDiscountList || newDiscountList.length === 0) {
|
|
104
127
|
return {
|
|
@@ -128,7 +151,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
128
151
|
var mergedDiscountList = uniqueById(uniqueById([].concat(_toConsumableArray(filteredOldDiscountList), _toConsumableArray(newDiscountList))), 'product_id');
|
|
129
152
|
var result = this.calcDiscount({
|
|
130
153
|
discountList: mergedDiscountList,
|
|
131
|
-
productList: _toConsumableArray(productList)
|
|
154
|
+
productList: _toConsumableArray(productList),
|
|
155
|
+
holders: holders
|
|
132
156
|
}, {
|
|
133
157
|
scan: true
|
|
134
158
|
});
|
|
@@ -170,7 +194,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
170
194
|
value: function calcDiscount(_ref2, options) {
|
|
171
195
|
var _this3 = this;
|
|
172
196
|
var discountList = _ref2.discountList,
|
|
173
|
-
productList = _ref2.productList
|
|
197
|
+
productList = _ref2.productList,
|
|
198
|
+
holders = _ref2.holders;
|
|
174
199
|
// 识别出来是不是在编辑的界面里又新增了商品
|
|
175
200
|
// 这种情况下,如果有可用的优惠券,也会自动勾选上
|
|
176
201
|
var isEditModeAddNewProduct = productList.find(function (n) {
|
|
@@ -408,10 +433,16 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
408
433
|
addModeDiscount.forEach(function (discount) {
|
|
409
434
|
var _product, _product2, _product3, _product4, _flatItem$bundleItem;
|
|
410
435
|
var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
|
|
436
|
+
// 拿到discount配置的holder信息 product信息 product.holder 加在 isLimitedProduct
|
|
437
|
+
var _tempVar = (flatItem === null || flatItem === void 0 ? void 0 : flatItem.type) === 'bundle' ? flatItem === null || flatItem === void 0 ? void 0 : flatItem.parentProduct : flatItem === null || flatItem === void 0 ? void 0 : flatItem.product;
|
|
438
|
+
var isHolderMatch = _this3.checkHolderMatch(discount, {
|
|
439
|
+
isNeedHolder: _tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.isNeedHolder,
|
|
440
|
+
holder_id: (_tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.holder_id) || product.holder_id
|
|
441
|
+
}, holders);
|
|
411
442
|
var timeLimit = true;
|
|
412
443
|
timeLimit = !!filterDiscountListByBookingTime([discount], (((_product = product) === null || _product === void 0 ? void 0 : _product.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
|
|
413
444
|
// 是符合折扣的商品
|
|
414
|
-
var isLimitedProduct = limitedData.type === 'product_all' || limitedData.product_ids && limitedData.product_ids.includes(product.id);
|
|
445
|
+
var isLimitedProduct = (limitedData.type === 'product_all' || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
|
|
415
446
|
|
|
416
447
|
// 编辑的商品 使用了优惠券不可用
|
|
417
448
|
var isAvailableProduct = flatItem.type === 'main' ? !((_product2 = product) !== null && _product2 !== void 0 && _product2.booking_id && (_product3 = product) !== null && _product3 !== void 0 && (_product3 = _product3.discount_list) !== null && _product3 !== void 0 && _product3.length && (_product4 = product) !== null && _product4 !== void 0 && (_product4 = _product4.discount_list) !== null && _product4 !== void 0 && _product4.every(function (discount) {
|
|
@@ -520,6 +551,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
520
551
|
var targetUsedDiscounts = usedDiscounts.get(discount.id);
|
|
521
552
|
if (targetUsedDiscounts && (discount.tag || discount.type) === 'good_pass') return false;
|
|
522
553
|
var limitedData = discount.limited_relation_product_data;
|
|
554
|
+
|
|
555
|
+
// 拿到discount配置的holder信息 product信息 product.holder 不可用return false
|
|
556
|
+
var _tempVar = (flatItem === null || flatItem === void 0 ? void 0 : flatItem.type) === 'bundle' ? flatItem === null || flatItem === void 0 ? void 0 : flatItem.parentProduct : flatItem === null || flatItem === void 0 ? void 0 : flatItem.product;
|
|
557
|
+
var isHolderMatch = _this3.checkHolderMatch(discount, {
|
|
558
|
+
isNeedHolder: _tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.isNeedHolder,
|
|
559
|
+
holder_id: (_tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.holder_id) || product.holder_id
|
|
560
|
+
}, holders);
|
|
561
|
+
// 如果 holder 不匹配,则不适用
|
|
562
|
+
if (!isHolderMatch) return false;
|
|
523
563
|
var timeLimit = true;
|
|
524
564
|
timeLimit = !!filterDiscountListByBookingTime([discount], (product.startDate || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
|
|
525
565
|
if (!timeLimit) {
|
|
@@ -660,7 +700,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
660
700
|
discount_list: []
|
|
661
701
|
}))]);
|
|
662
702
|
} else {
|
|
663
|
-
processedProductsMap.set(product._id, [_this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {
|
|
703
|
+
processedProductsMap.set(product._id, [_this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {
|
|
704
|
+
price: product.price,
|
|
705
|
+
main_product_selling_price: product.price
|
|
706
|
+
} : {
|
|
664
707
|
_id: product._id.split('___')[0] + '___' + index,
|
|
665
708
|
total: product.origin_total || product.total,
|
|
666
709
|
price: product.price,
|
|
@@ -673,7 +716,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
673
716
|
// bundle子商品:保存到扁平化Map
|
|
674
717
|
processedFlatItemsMap.set(flatItem._id, [_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
675
718
|
discount_list: [],
|
|
676
|
-
price: flatItem.bundleItem.original_price,
|
|
719
|
+
price: isManualDiscount ? flatItem.bundleItem.price : flatItem.bundleItem.original_price,
|
|
677
720
|
processed: true
|
|
678
721
|
})]);
|
|
679
722
|
}
|
|
@@ -22,6 +22,9 @@ export interface RulesModuleAPI {
|
|
|
22
22
|
calcDiscount: (params: {
|
|
23
23
|
discountList: any[];
|
|
24
24
|
productList: any[];
|
|
25
|
+
holders: {
|
|
26
|
+
form_record_id: number;
|
|
27
|
+
}[];
|
|
25
28
|
}) => DiscountResult;
|
|
26
29
|
}
|
|
27
30
|
type ProductDetail = {
|
|
@@ -39,6 +42,7 @@ type ProductDetail = {
|
|
|
39
42
|
original_price?: number | string;
|
|
40
43
|
num?: number;
|
|
41
44
|
quantity: number;
|
|
45
|
+
holder_id?: number | string;
|
|
42
46
|
vouchersApplicable?: boolean;
|
|
43
47
|
startDate?: any;
|
|
44
48
|
};
|
|
@@ -344,8 +344,7 @@ export function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, all
|
|
|
344
344
|
resourcesInType.forEach(function (resource) {
|
|
345
345
|
// 过滤出在时间段内的资源时间片
|
|
346
346
|
var availableTimes = resource.times.filter(function (time) {
|
|
347
|
-
|
|
348
|
-
return !dayjs(time.start_at).isAfter(dayjs(timeSlotStart), 'minute') && !dayjs(time.end_at).isBefore(dayjs(timeSlotEnd), 'minute') || dayjs(time.start_at).isBefore(dayjs(timeSlotEnd), 'minute') && dayjs(time.end_at).isAfter(dayjs(timeSlotStart), 'minute') && ((_time$event_list = time.event_list) === null || _time$event_list === void 0 ? void 0 : _time$event_list.length) === 0;
|
|
347
|
+
return !dayjs(time.start_at).isAfter(dayjs(timeSlotStart), 'minute') && !dayjs(time.end_at).isBefore(dayjs(timeSlotEnd), 'minute') || dayjs(time.start_at).isBefore(dayjs(timeSlotEnd), 'minute') && dayjs(time.end_at).isAfter(dayjs(timeSlotStart), 'minute');
|
|
349
348
|
});
|
|
350
349
|
if (availableTimes.length > 0) {
|
|
351
350
|
availableResourceCount++;
|
|
@@ -21,6 +21,9 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
21
21
|
getCurrentBookingTime(): string | null;
|
|
22
22
|
private filterDiscountListByBookingTime;
|
|
23
23
|
setCustomer(customer: Customer): Promise<void>;
|
|
24
|
+
setHolders(holders: {
|
|
25
|
+
form_record_id: number;
|
|
26
|
+
}[]): void;
|
|
24
27
|
calcDiscount(productList: Record<string, any>[], options?: SetDiscountSelectedParams): {
|
|
25
28
|
productList: Record<string, any>[];
|
|
26
29
|
discountList: Discount[];
|
|
@@ -51,6 +51,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
51
51
|
productList: [],
|
|
52
52
|
discount: null,
|
|
53
53
|
rules: null,
|
|
54
|
+
holders: [],
|
|
54
55
|
originalDiscountList: [],
|
|
55
56
|
currentBookingTime: "",
|
|
56
57
|
filteredDiscountList: []
|
|
@@ -285,7 +286,14 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
285
286
|
return _setCustomer.apply(this, arguments);
|
|
286
287
|
}
|
|
287
288
|
return setCustomer;
|
|
288
|
-
}() //
|
|
289
|
+
}() // 设置holders
|
|
290
|
+
}, {
|
|
291
|
+
key: "setHolders",
|
|
292
|
+
value: function setHolders(holders) {
|
|
293
|
+
this.store.holders = holders;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// 计算优惠券
|
|
289
297
|
}, {
|
|
290
298
|
key: "calcDiscount",
|
|
291
299
|
value: function calcDiscount(productList, options) {
|
|
@@ -299,7 +307,8 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
299
307
|
}
|
|
300
308
|
var _ref = rulesModule.calcDiscount({
|
|
301
309
|
productList: productList,
|
|
302
|
-
discountList: this.getDiscountList()
|
|
310
|
+
discountList: this.getDiscountList(),
|
|
311
|
+
holders: this.store.holders || []
|
|
303
312
|
}, options) || {
|
|
304
313
|
productList: productList,
|
|
305
314
|
discountList: this.getDiscountList()
|
|
@@ -437,7 +446,8 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
437
446
|
_ref2 = rulesModule.isDiscountListAvailable({
|
|
438
447
|
productList: this.store.productList || [],
|
|
439
448
|
oldDiscountList: this.getDiscountList(),
|
|
440
|
-
newDiscountList: withScanList
|
|
449
|
+
newDiscountList: withScanList,
|
|
450
|
+
holders: this.store.holders || []
|
|
441
451
|
}) || {
|
|
442
452
|
isAvailable: false,
|
|
443
453
|
productList: this.store.productList || [],
|
|
@@ -720,7 +730,8 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
720
730
|
customer_id: customerId,
|
|
721
731
|
action: 'create',
|
|
722
732
|
with_good_pass: 1,
|
|
723
|
-
with_discount_card: 1
|
|
733
|
+
with_discount_card: 1,
|
|
734
|
+
with_wallet_pass_holder: 1
|
|
724
735
|
});
|
|
725
736
|
case 4:
|
|
726
737
|
goodPassList = _context9.sent;
|
|
@@ -23,6 +23,11 @@ export interface ShopDiscountState {
|
|
|
23
23
|
discount: DiscountModule | null;
|
|
24
24
|
rules: RulesModule | null;
|
|
25
25
|
productList: Record<string, any>[];
|
|
26
|
+
holders?: {
|
|
27
|
+
form_record_id: number;
|
|
28
|
+
form_id?: number;
|
|
29
|
+
main_field?: string;
|
|
30
|
+
}[];
|
|
26
31
|
originalDiscountList: Discount[];
|
|
27
32
|
currentBookingTime: string | null;
|
|
28
33
|
filteredDiscountList: Discount[];
|
|
@@ -21,6 +21,7 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
|
|
|
21
21
|
with_good_pass: 0 | 1;
|
|
22
22
|
with_discount_card: 0 | 1;
|
|
23
23
|
customer_id: number;
|
|
24
|
+
with_wallet_pass_holder: 0 | 1;
|
|
24
25
|
}): Promise<Discount[]>;
|
|
25
26
|
batchSearch(code: string, customerId?: number): Promise<Discount[]>;
|
|
26
27
|
filterEnabledDiscountList(discountList: Discount[]): Discount[];
|
|
@@ -109,7 +109,7 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
|
|
|
109
109
|
tags: ["good_pass", "product_discount_card"],
|
|
110
110
|
available: 1,
|
|
111
111
|
relation_product: 1,
|
|
112
|
-
with: ["extensionData"],
|
|
112
|
+
with: ["extensionData", "holder.detail"],
|
|
113
113
|
order_behavior_count: 1,
|
|
114
114
|
order_behavior_count_customer_id: customerId || 1
|
|
115
115
|
});
|
|
@@ -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(): "normal" | "duration" | "session";
|
|
53
53
|
}
|
|
@@ -12,18 +12,25 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
|
|
|
12
12
|
initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
|
|
13
13
|
setRulesList(rulesList: Rules[]): Promise<void>;
|
|
14
14
|
getRulesList(): Rules[];
|
|
15
|
-
|
|
15
|
+
private checkHolderMatch;
|
|
16
|
+
isDiscountListAvailable({ oldDiscountList, newDiscountList, productList, holders, }: {
|
|
16
17
|
oldDiscountList: Discount[];
|
|
17
18
|
newDiscountList: Discount[];
|
|
18
19
|
productList: any[];
|
|
20
|
+
holders: {
|
|
21
|
+
form_record_id: number;
|
|
22
|
+
}[];
|
|
19
23
|
}): {
|
|
20
24
|
isAvailable: boolean;
|
|
21
25
|
discountList: Discount[];
|
|
22
26
|
productList: any[];
|
|
23
27
|
};
|
|
24
|
-
calcDiscount({ discountList, productList, }: {
|
|
28
|
+
calcDiscount({ discountList, productList, holders, }: {
|
|
25
29
|
discountList: Discount[];
|
|
26
30
|
productList: any[];
|
|
31
|
+
holders: {
|
|
32
|
+
form_record_id: number;
|
|
33
|
+
}[];
|
|
27
34
|
}, options?: {
|
|
28
35
|
isSelected?: boolean;
|
|
29
36
|
discountId?: number;
|
|
@@ -57,11 +57,25 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
57
57
|
getRulesList() {
|
|
58
58
|
return this.store.rulesList;
|
|
59
59
|
}
|
|
60
|
+
// 商品不需要holder,则不需要判断,直接返回true,商品需要holder但是还没填写,那么暂时不使用带有holder的券,直到填写才去匹配
|
|
61
|
+
checkHolderMatch(discount, product, holders) {
|
|
62
|
+
var _a;
|
|
63
|
+
if (((_a = discount.holder) == null ? void 0 : _a.holder_type) !== "form")
|
|
64
|
+
return true;
|
|
65
|
+
const orderHolderId = Array.isArray(holders) && holders.length > 0 ? holders[0].form_record_id : void 0;
|
|
66
|
+
const productHolderId = Array.isArray(product.holder_id) ? product.holder_id[0] : product.holder_id;
|
|
67
|
+
if (!product.isNeedHolder)
|
|
68
|
+
return true;
|
|
69
|
+
if (!orderHolderId && !productHolderId)
|
|
70
|
+
return false;
|
|
71
|
+
return (productHolderId || orderHolderId) === discount.holder.holder_id;
|
|
72
|
+
}
|
|
60
73
|
// 判断discountList 是否可以对当前productList生效
|
|
61
74
|
isDiscountListAvailable({
|
|
62
75
|
oldDiscountList,
|
|
63
76
|
newDiscountList,
|
|
64
|
-
productList
|
|
77
|
+
productList,
|
|
78
|
+
holders
|
|
65
79
|
}) {
|
|
66
80
|
if (!newDiscountList || newDiscountList.length === 0) {
|
|
67
81
|
return {
|
|
@@ -88,7 +102,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
88
102
|
]), "product_id");
|
|
89
103
|
const result = this.calcDiscount({
|
|
90
104
|
discountList: mergedDiscountList,
|
|
91
|
-
productList: [...productList]
|
|
105
|
+
productList: [...productList],
|
|
106
|
+
holders
|
|
92
107
|
}, {
|
|
93
108
|
scan: true
|
|
94
109
|
});
|
|
@@ -120,7 +135,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
120
135
|
}
|
|
121
136
|
calcDiscount({
|
|
122
137
|
discountList,
|
|
123
|
-
productList
|
|
138
|
+
productList,
|
|
139
|
+
holders
|
|
124
140
|
}, options) {
|
|
125
141
|
const isEditModeAddNewProduct = productList.find((n) => n.booking_id) && productList.find((n) => !n.booking_id);
|
|
126
142
|
const editModeDiscount = [];
|
|
@@ -271,9 +287,18 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
271
287
|
addModeDiscount.forEach((discount) => {
|
|
272
288
|
var _a, _b, _c, _d, _e, _f;
|
|
273
289
|
const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
|
|
290
|
+
const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
|
|
291
|
+
const isHolderMatch = this.checkHolderMatch(
|
|
292
|
+
discount,
|
|
293
|
+
{
|
|
294
|
+
isNeedHolder: _tempVar == null ? void 0 : _tempVar.isNeedHolder,
|
|
295
|
+
holder_id: (_tempVar == null ? void 0 : _tempVar.holder_id) || product.holder_id
|
|
296
|
+
},
|
|
297
|
+
holders
|
|
298
|
+
);
|
|
274
299
|
let timeLimit = true;
|
|
275
300
|
timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], ((product == null ? void 0 : product.startDate) || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
|
|
276
|
-
const isLimitedProduct = limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id);
|
|
301
|
+
const isLimitedProduct = (limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
|
|
277
302
|
const isAvailableProduct = flatItem.type === "main" ? !((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)))) : !((flatItem == null ? void 0 : flatItem.booking_id) && ((_d = (_c = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _c.metadata) == null ? void 0 : _d.custom_product_bundle_map_id));
|
|
278
303
|
const isBundleAvailable = this.checkPackageSubItemUsageRules(discount, flatItem);
|
|
279
304
|
if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable) {
|
|
@@ -353,6 +378,17 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
353
378
|
if (targetUsedDiscounts && (discount.tag || discount.type) === "good_pass")
|
|
354
379
|
return false;
|
|
355
380
|
const limitedData = discount.limited_relation_product_data;
|
|
381
|
+
const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
|
|
382
|
+
const isHolderMatch = this.checkHolderMatch(
|
|
383
|
+
discount,
|
|
384
|
+
{
|
|
385
|
+
isNeedHolder: _tempVar == null ? void 0 : _tempVar.isNeedHolder,
|
|
386
|
+
holder_id: (_tempVar == null ? void 0 : _tempVar.holder_id) || product.holder_id
|
|
387
|
+
},
|
|
388
|
+
holders
|
|
389
|
+
);
|
|
390
|
+
if (!isHolderMatch)
|
|
391
|
+
return false;
|
|
356
392
|
let timeLimit = true;
|
|
357
393
|
timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], (product.startDate || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
|
|
358
394
|
if (!timeLimit) {
|
|
@@ -467,7 +503,10 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
467
503
|
processedProductsMap.set(
|
|
468
504
|
product._id,
|
|
469
505
|
[this.hooks.setProduct(originProduct, {
|
|
470
|
-
...isManualDiscount ? {
|
|
506
|
+
...isManualDiscount ? {
|
|
507
|
+
price: product.price,
|
|
508
|
+
main_product_selling_price: product.price
|
|
509
|
+
} : {
|
|
471
510
|
_id: product._id.split("___")[0] + "___" + index,
|
|
472
511
|
total: product.origin_total || product.total,
|
|
473
512
|
price: product.price,
|
|
@@ -481,7 +520,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
481
520
|
processedFlatItemsMap.set(flatItem._id, [{
|
|
482
521
|
...flatItem,
|
|
483
522
|
discount_list: [],
|
|
484
|
-
price: flatItem.bundleItem.original_price,
|
|
523
|
+
price: isManualDiscount ? flatItem.bundleItem.price : flatItem.bundleItem.original_price,
|
|
485
524
|
processed: true
|
|
486
525
|
}]);
|
|
487
526
|
}
|
|
@@ -22,6 +22,9 @@ export interface RulesModuleAPI {
|
|
|
22
22
|
calcDiscount: (params: {
|
|
23
23
|
discountList: any[];
|
|
24
24
|
productList: any[];
|
|
25
|
+
holders: {
|
|
26
|
+
form_record_id: number;
|
|
27
|
+
}[];
|
|
25
28
|
}) => DiscountResult;
|
|
26
29
|
}
|
|
27
30
|
type ProductDetail = {
|
|
@@ -39,6 +42,7 @@ type ProductDetail = {
|
|
|
39
42
|
original_price?: number | string;
|
|
40
43
|
num?: number;
|
|
41
44
|
quantity: number;
|
|
45
|
+
holder_id?: number | string;
|
|
42
46
|
vouchersApplicable?: boolean;
|
|
43
47
|
startDate?: any;
|
|
44
48
|
};
|
|
@@ -249,8 +249,7 @@ function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, allResourc
|
|
|
249
249
|
let availableResourceCount = 0;
|
|
250
250
|
resourcesInType.forEach((resource) => {
|
|
251
251
|
const availableTimes = resource.times.filter((time) => {
|
|
252
|
-
|
|
253
|
-
return !(0, import_dayjs.default)(time.start_at).isAfter((0, import_dayjs.default)(timeSlotStart), "minute") && !(0, import_dayjs.default)(time.end_at).isBefore((0, import_dayjs.default)(timeSlotEnd), "minute") || (0, import_dayjs.default)(time.start_at).isBefore((0, import_dayjs.default)(timeSlotEnd), "minute") && (0, import_dayjs.default)(time.end_at).isAfter((0, import_dayjs.default)(timeSlotStart), "minute") && ((_a2 = time.event_list) == null ? void 0 : _a2.length) === 0;
|
|
252
|
+
return !(0, import_dayjs.default)(time.start_at).isAfter((0, import_dayjs.default)(timeSlotStart), "minute") && !(0, import_dayjs.default)(time.end_at).isBefore((0, import_dayjs.default)(timeSlotEnd), "minute") || (0, import_dayjs.default)(time.start_at).isBefore((0, import_dayjs.default)(timeSlotEnd), "minute") && (0, import_dayjs.default)(time.end_at).isAfter((0, import_dayjs.default)(timeSlotStart), "minute");
|
|
254
253
|
});
|
|
255
254
|
if (availableTimes.length > 0) {
|
|
256
255
|
availableResourceCount++;
|
|
@@ -21,6 +21,9 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
21
21
|
getCurrentBookingTime(): string | null;
|
|
22
22
|
private filterDiscountListByBookingTime;
|
|
23
23
|
setCustomer(customer: Customer): Promise<void>;
|
|
24
|
+
setHolders(holders: {
|
|
25
|
+
form_record_id: number;
|
|
26
|
+
}[]): void;
|
|
24
27
|
calcDiscount(productList: Record<string, any>[], options?: SetDiscountSelectedParams): {
|
|
25
28
|
productList: Record<string, any>[];
|
|
26
29
|
discountList: Discount[];
|
|
@@ -51,6 +51,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
51
51
|
productList: [],
|
|
52
52
|
discount: null,
|
|
53
53
|
rules: null,
|
|
54
|
+
holders: [],
|
|
54
55
|
originalDiscountList: [],
|
|
55
56
|
currentBookingTime: "",
|
|
56
57
|
filteredDiscountList: []
|
|
@@ -191,6 +192,10 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
191
192
|
);
|
|
192
193
|
}
|
|
193
194
|
}
|
|
195
|
+
// 设置holders
|
|
196
|
+
setHolders(holders) {
|
|
197
|
+
this.store.holders = holders;
|
|
198
|
+
}
|
|
194
199
|
// 计算优惠券
|
|
195
200
|
calcDiscount(productList, options) {
|
|
196
201
|
this.store.productList = productList;
|
|
@@ -201,7 +206,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
201
206
|
let { productList: newProductList, discountList: newDiscountList } = rulesModule.calcDiscount(
|
|
202
207
|
{
|
|
203
208
|
productList,
|
|
204
|
-
discountList: this.getDiscountList()
|
|
209
|
+
discountList: this.getDiscountList(),
|
|
210
|
+
holders: this.store.holders || []
|
|
205
211
|
},
|
|
206
212
|
options
|
|
207
213
|
) || { productList, discountList: this.getDiscountList() };
|
|
@@ -290,7 +296,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
290
296
|
} = rulesModule.isDiscountListAvailable({
|
|
291
297
|
productList: this.store.productList || [],
|
|
292
298
|
oldDiscountList: this.getDiscountList(),
|
|
293
|
-
newDiscountList: withScanList
|
|
299
|
+
newDiscountList: withScanList,
|
|
300
|
+
holders: this.store.holders || []
|
|
294
301
|
}) || {
|
|
295
302
|
isAvailable: false,
|
|
296
303
|
productList: this.store.productList || [],
|
|
@@ -475,7 +482,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
475
482
|
customer_id: customerId,
|
|
476
483
|
action: "create",
|
|
477
484
|
with_good_pass: 1,
|
|
478
|
-
with_discount_card: 1
|
|
485
|
+
with_discount_card: 1,
|
|
486
|
+
with_wallet_pass_holder: 1
|
|
479
487
|
}));
|
|
480
488
|
const scanDiscount = (_c = this.getDiscountList()) == null ? void 0 : _c.filter(
|
|
481
489
|
(item) => item.isScan
|
|
@@ -23,6 +23,11 @@ export interface ShopDiscountState {
|
|
|
23
23
|
discount: DiscountModule | null;
|
|
24
24
|
rules: RulesModule | null;
|
|
25
25
|
productList: Record<string, any>[];
|
|
26
|
+
holders?: {
|
|
27
|
+
form_record_id: number;
|
|
28
|
+
form_id?: number;
|
|
29
|
+
main_field?: string;
|
|
30
|
+
}[];
|
|
26
31
|
originalDiscountList: Discount[];
|
|
27
32
|
currentBookingTime: string | null;
|
|
28
33
|
filteredDiscountList: Discount[];
|