@pisell/pisellos 3.0.60 → 3.0.61
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 +2 -1
- package/dist/modules/Discount/index.js +67 -4
- package/dist/modules/Discount/types.d.ts +25 -0
- package/dist/solution/BookingByStep/index.js +1 -1
- package/dist/solution/ShopDiscount/index.d.ts +1 -1
- package/dist/solution/ShopDiscount/index.js +6 -6
- package/lib/modules/Discount/index.d.ts +2 -1
- package/lib/modules/Discount/index.js +45 -3
- package/lib/modules/Discount/types.d.ts +25 -0
- package/lib/solution/BookingByStep/index.js +1 -1
- package/lib/solution/ShopDiscount/index.d.ts +1 -1
- package/lib/solution/ShopDiscount/index.js +2 -2
- package/package.json +1 -1
|
@@ -20,8 +20,9 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
|
|
|
20
20
|
with_discount_card: 0 | 1;
|
|
21
21
|
customer_id: number;
|
|
22
22
|
}): Promise<Discount[]>;
|
|
23
|
-
batchSearch(code: string): Promise<Discount[]>;
|
|
23
|
+
batchSearch(code: string, customerId?: number): Promise<Discount[]>;
|
|
24
24
|
filterEnabledDiscountList(discountList: Discount[]): Discount[];
|
|
25
|
+
private checkUsageCreditsLimit;
|
|
25
26
|
uniqueByProductId(discountList: Discount[]): Discount[];
|
|
26
27
|
filterDiscountListByProductIds(discountList: Discount[], productIds: number[]): Discount[];
|
|
27
28
|
calcDiscountApplicableProductTotalPrice(discount: Discount): number | undefined;
|
|
@@ -145,7 +145,7 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
145
145
|
}, {
|
|
146
146
|
key: "batchSearch",
|
|
147
147
|
value: function () {
|
|
148
|
-
var _batchSearch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(code) {
|
|
148
|
+
var _batchSearch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(code, customerId) {
|
|
149
149
|
var result, resultDiscountList;
|
|
150
150
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
151
151
|
while (1) switch (_context4.prev = _context4.next) {
|
|
@@ -156,7 +156,10 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
156
156
|
translate_flag: 1,
|
|
157
157
|
tags: ['good_pass', 'product_discount_card'],
|
|
158
158
|
available: 1,
|
|
159
|
-
relation_product: 1
|
|
159
|
+
relation_product: 1,
|
|
160
|
+
with: ['extensionData'],
|
|
161
|
+
order_behavior_count: 1,
|
|
162
|
+
order_behavior_count_customer_id: customerId || 1
|
|
160
163
|
});
|
|
161
164
|
case 2:
|
|
162
165
|
result = _context4.sent;
|
|
@@ -168,7 +171,7 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
168
171
|
}
|
|
169
172
|
}, _callee4, this);
|
|
170
173
|
}));
|
|
171
|
-
function batchSearch(_x5) {
|
|
174
|
+
function batchSearch(_x5, _x6) {
|
|
172
175
|
return _batchSearch.apply(this, arguments);
|
|
173
176
|
}
|
|
174
177
|
return batchSearch;
|
|
@@ -176,11 +179,71 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
176
179
|
}, {
|
|
177
180
|
key: "filterEnabledDiscountList",
|
|
178
181
|
value: function filterEnabledDiscountList(discountList) {
|
|
182
|
+
var _this2 = this;
|
|
179
183
|
return discountList.filter(function (discount) {
|
|
180
|
-
return discount.limit_status === 'enable' && new Decimal((discount === null || discount === void 0 ? void 0 : discount.par_value) || 0).minus(new Decimal((discount === null || discount === void 0 ? void 0 : discount.used_par_value) || 0)).greaterThan(0);
|
|
184
|
+
return discount.limit_status === 'enable' && new Decimal((discount === null || discount === void 0 ? void 0 : discount.par_value) || 0).minus(new Decimal((discount === null || discount === void 0 ? void 0 : discount.used_par_value) || 0)).greaterThan(0) && _this2.checkUsageCreditsLimit(discount);
|
|
181
185
|
});
|
|
182
186
|
}
|
|
183
187
|
|
|
188
|
+
// 检查使用次数限制
|
|
189
|
+
}, {
|
|
190
|
+
key: "checkUsageCreditsLimit",
|
|
191
|
+
value: function checkUsageCreditsLimit(discount) {
|
|
192
|
+
// 如果没有 extension_data,则不需要限制
|
|
193
|
+
if (!discount.extension_data || discount.extension_data.length === 0) {
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// 查找 field_key 为 usage_credits 的数据
|
|
198
|
+
var usageCreditsData = discount.extension_data.find(function (data) {
|
|
199
|
+
return data.field_key === 'usage_credits';
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// 如果没有找到 usage_credits 数据,则不需要限制
|
|
203
|
+
if (!usageCreditsData) {
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
var value = usageCreditsData.value;
|
|
207
|
+
|
|
208
|
+
// 检查总次数限制
|
|
209
|
+
if (value.total_credits && value.total_credits > 0) {
|
|
210
|
+
if ((discount.total_order_behavior_count || 0) >= value.total_credits) {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// 检查单用户限制
|
|
216
|
+
if (value.per_user_limit && value.per_user_limit > 0) {
|
|
217
|
+
if ((discount.customer_order_behavior_count || 0) >= value.per_user_limit) {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// 检查单日限制
|
|
223
|
+
if (value.max_per_day && value.max_per_day > 0) {
|
|
224
|
+
if ((discount.today_order_behavior_count || 0) >= value.max_per_day) {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// 检查单周限制
|
|
230
|
+
if (value.max_per_week && value.max_per_week > 0) {
|
|
231
|
+
if ((discount.week_order_behavior_count || 0) >= value.max_per_week) {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// 检查单月限制
|
|
237
|
+
if (value.max_per_month && value.max_per_month > 0) {
|
|
238
|
+
if ((discount.month_order_behavior_count || 0) >= value.max_per_month) {
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// 所有检查都通过
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
|
|
184
247
|
// 根据productIds去重
|
|
185
248
|
}, {
|
|
186
249
|
key: "uniqueByProductId",
|
|
@@ -36,6 +36,25 @@ interface ApplicableProductDetails {
|
|
|
36
36
|
title?: string;
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
|
+
interface UsageCreditsValue {
|
|
40
|
+
total_credits: number;
|
|
41
|
+
per_user_limit: number;
|
|
42
|
+
max_per_day: number;
|
|
43
|
+
max_per_week: number;
|
|
44
|
+
max_per_month: number;
|
|
45
|
+
}
|
|
46
|
+
interface ExtensionData {
|
|
47
|
+
id: number;
|
|
48
|
+
shop_id: number;
|
|
49
|
+
product_id: number;
|
|
50
|
+
field_id: number;
|
|
51
|
+
field_key: string;
|
|
52
|
+
type: string;
|
|
53
|
+
value: UsageCreditsValue | Record<string, any> | string | number | boolean | any[];
|
|
54
|
+
created_at: string | null;
|
|
55
|
+
updated_at: string | null;
|
|
56
|
+
deleted_at: string | null;
|
|
57
|
+
}
|
|
39
58
|
export interface Discount {
|
|
40
59
|
id: number;
|
|
41
60
|
product_name: string;
|
|
@@ -70,6 +89,12 @@ export interface Discount {
|
|
|
70
89
|
appliedProductDetails: ApplicableProductDetails[];
|
|
71
90
|
isDisabledForProductUsed?: boolean;
|
|
72
91
|
amount?: number;
|
|
92
|
+
extension_data?: ExtensionData[];
|
|
93
|
+
total_order_behavior_count?: number;
|
|
94
|
+
today_order_behavior_count?: number;
|
|
95
|
+
week_order_behavior_count?: number;
|
|
96
|
+
month_order_behavior_count?: number;
|
|
97
|
+
customer_order_behavior_count?: number;
|
|
73
98
|
}
|
|
74
99
|
export interface DiscountState {
|
|
75
100
|
discountList: Discount[];
|
|
@@ -1273,7 +1273,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1273
1273
|
// 如果此时 resources 为空,视作购物车里已经有了 dateRange 数据,此时 dateList 里明确就是那一天的数据
|
|
1274
1274
|
if (!allOriginResources.length) {
|
|
1275
1275
|
var dateList = this.store.date.getDateList();
|
|
1276
|
-
dateList.forEach(function (n) {
|
|
1276
|
+
dateList === null || dateList === void 0 || dateList.forEach(function (n) {
|
|
1277
1277
|
if (n.resource) allOriginResources.push.apply(allOriginResources, _toConsumableArray(n.resource));
|
|
1278
1278
|
});
|
|
1279
1279
|
}
|
|
@@ -34,7 +34,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
34
34
|
discountList: Discount[];
|
|
35
35
|
};
|
|
36
36
|
setProductList(productList: Record<string, any>[]): void;
|
|
37
|
-
scanCode(code: string): Promise<{
|
|
37
|
+
scanCode(code: string, customerId?: number): Promise<{
|
|
38
38
|
isAvailable: boolean;
|
|
39
39
|
productList: Record<string, any>[];
|
|
40
40
|
discountList: Discount[];
|
|
@@ -304,14 +304,14 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
304
304
|
}, {
|
|
305
305
|
key: "scanCode",
|
|
306
306
|
value: function () {
|
|
307
|
-
var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(code) {
|
|
307
|
+
var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(code, customerId) {
|
|
308
308
|
var _this$store$discount3, resultDiscountList, rulesModule, withScanList, _ref3, newProductList, newDiscountList, isAvailable, _this$options$otherPa6;
|
|
309
309
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
310
310
|
while (1) switch (_context5.prev = _context5.next) {
|
|
311
311
|
case 0:
|
|
312
312
|
_context5.prev = 0;
|
|
313
313
|
_context5.next = 3;
|
|
314
|
-
return (_this$store$discount3 = this.store.discount) === null || _this$store$discount3 === void 0 ? void 0 : _this$store$discount3.batchSearch(code);
|
|
314
|
+
return (_this$store$discount3 = this.store.discount) === null || _this$store$discount3 === void 0 ? void 0 : _this$store$discount3.batchSearch(code, customerId);
|
|
315
315
|
case 3:
|
|
316
316
|
_context5.t0 = _context5.sent;
|
|
317
317
|
if (_context5.t0) {
|
|
@@ -393,7 +393,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
393
393
|
}
|
|
394
394
|
}, _callee5, this, [[0, 23]]);
|
|
395
395
|
}));
|
|
396
|
-
function scanCode(_x4) {
|
|
396
|
+
function scanCode(_x4, _x5) {
|
|
397
397
|
return _scanCode.apply(this, arguments);
|
|
398
398
|
}
|
|
399
399
|
return scanCode;
|
|
@@ -438,7 +438,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
438
438
|
}
|
|
439
439
|
}, _callee6, this);
|
|
440
440
|
}));
|
|
441
|
-
function emitDiscountListChange(
|
|
441
|
+
function emitDiscountListChange(_x6) {
|
|
442
442
|
return _emitDiscountListChange.apply(this, arguments);
|
|
443
443
|
}
|
|
444
444
|
return emitDiscountListChange;
|
|
@@ -574,7 +574,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
574
574
|
}
|
|
575
575
|
}, _callee7, this, [[0, 11]]);
|
|
576
576
|
}));
|
|
577
|
-
function getCustomerWallet(
|
|
577
|
+
function getCustomerWallet(_x7) {
|
|
578
578
|
return _getCustomerWallet.apply(this, arguments);
|
|
579
579
|
}
|
|
580
580
|
return getCustomerWallet;
|
|
@@ -634,7 +634,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
634
634
|
}
|
|
635
635
|
}, _callee8, this, [[0, 18]]);
|
|
636
636
|
}));
|
|
637
|
-
function loadPrepareConfig(
|
|
637
|
+
function loadPrepareConfig(_x8) {
|
|
638
638
|
return _loadPrepareConfig.apply(this, arguments);
|
|
639
639
|
}
|
|
640
640
|
return loadPrepareConfig;
|
|
@@ -20,8 +20,9 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
|
|
|
20
20
|
with_discount_card: 0 | 1;
|
|
21
21
|
customer_id: number;
|
|
22
22
|
}): Promise<Discount[]>;
|
|
23
|
-
batchSearch(code: string): Promise<Discount[]>;
|
|
23
|
+
batchSearch(code: string, customerId?: number): Promise<Discount[]>;
|
|
24
24
|
filterEnabledDiscountList(discountList: Discount[]): Discount[];
|
|
25
|
+
private checkUsageCreditsLimit;
|
|
25
26
|
uniqueByProductId(discountList: Discount[]): Discount[];
|
|
26
27
|
filterDiscountListByProductIds(discountList: Discount[], productIds: number[]): Discount[];
|
|
27
28
|
calcDiscountApplicableProductTotalPrice(discount: Discount): number | undefined;
|
|
@@ -89,22 +89,64 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
|
|
|
89
89
|
) || [];
|
|
90
90
|
return goodPassList;
|
|
91
91
|
}
|
|
92
|
-
async batchSearch(code) {
|
|
92
|
+
async batchSearch(code, customerId) {
|
|
93
93
|
const result = await this.request.get(`/machinecode/batch-search`, {
|
|
94
94
|
code,
|
|
95
95
|
translate_flag: 1,
|
|
96
96
|
tags: ["good_pass", "product_discount_card"],
|
|
97
97
|
available: 1,
|
|
98
|
-
relation_product: 1
|
|
98
|
+
relation_product: 1,
|
|
99
|
+
with: ["extensionData"],
|
|
100
|
+
order_behavior_count: 1,
|
|
101
|
+
order_behavior_count_customer_id: customerId || 1
|
|
99
102
|
});
|
|
100
103
|
const resultDiscountList = this.filterEnabledDiscountList((result == null ? void 0 : result.data) || []) || [];
|
|
101
104
|
return resultDiscountList;
|
|
102
105
|
}
|
|
103
106
|
filterEnabledDiscountList(discountList) {
|
|
104
107
|
return discountList.filter(
|
|
105
|
-
(discount) => discount.limit_status === "enable" && new import_decimal.default((discount == null ? void 0 : discount.par_value) || 0).minus(new import_decimal.default((discount == null ? void 0 : discount.used_par_value) || 0)).greaterThan(0)
|
|
108
|
+
(discount) => discount.limit_status === "enable" && new import_decimal.default((discount == null ? void 0 : discount.par_value) || 0).minus(new import_decimal.default((discount == null ? void 0 : discount.used_par_value) || 0)).greaterThan(0) && this.checkUsageCreditsLimit(discount)
|
|
106
109
|
);
|
|
107
110
|
}
|
|
111
|
+
// 检查使用次数限制
|
|
112
|
+
checkUsageCreditsLimit(discount) {
|
|
113
|
+
if (!discount.extension_data || discount.extension_data.length === 0) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
const usageCreditsData = discount.extension_data.find(
|
|
117
|
+
(data) => data.field_key === "usage_credits"
|
|
118
|
+
);
|
|
119
|
+
if (!usageCreditsData) {
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
const value = usageCreditsData.value;
|
|
123
|
+
if (value.total_credits && value.total_credits > 0) {
|
|
124
|
+
if ((discount.total_order_behavior_count || 0) >= value.total_credits) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (value.per_user_limit && value.per_user_limit > 0) {
|
|
129
|
+
if ((discount.customer_order_behavior_count || 0) >= value.per_user_limit) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (value.max_per_day && value.max_per_day > 0) {
|
|
134
|
+
if ((discount.today_order_behavior_count || 0) >= value.max_per_day) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (value.max_per_week && value.max_per_week > 0) {
|
|
139
|
+
if ((discount.week_order_behavior_count || 0) >= value.max_per_week) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (value.max_per_month && value.max_per_month > 0) {
|
|
144
|
+
if ((discount.month_order_behavior_count || 0) >= value.max_per_month) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
108
150
|
// 根据productIds去重
|
|
109
151
|
uniqueByProductId(discountList) {
|
|
110
152
|
return (0, import_utils.uniqueById)(discountList, "product_id");
|
|
@@ -36,6 +36,25 @@ interface ApplicableProductDetails {
|
|
|
36
36
|
title?: string;
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
|
+
interface UsageCreditsValue {
|
|
40
|
+
total_credits: number;
|
|
41
|
+
per_user_limit: number;
|
|
42
|
+
max_per_day: number;
|
|
43
|
+
max_per_week: number;
|
|
44
|
+
max_per_month: number;
|
|
45
|
+
}
|
|
46
|
+
interface ExtensionData {
|
|
47
|
+
id: number;
|
|
48
|
+
shop_id: number;
|
|
49
|
+
product_id: number;
|
|
50
|
+
field_id: number;
|
|
51
|
+
field_key: string;
|
|
52
|
+
type: string;
|
|
53
|
+
value: UsageCreditsValue | Record<string, any> | string | number | boolean | any[];
|
|
54
|
+
created_at: string | null;
|
|
55
|
+
updated_at: string | null;
|
|
56
|
+
deleted_at: string | null;
|
|
57
|
+
}
|
|
39
58
|
export interface Discount {
|
|
40
59
|
id: number;
|
|
41
60
|
product_name: string;
|
|
@@ -70,6 +89,12 @@ export interface Discount {
|
|
|
70
89
|
appliedProductDetails: ApplicableProductDetails[];
|
|
71
90
|
isDisabledForProductUsed?: boolean;
|
|
72
91
|
amount?: number;
|
|
92
|
+
extension_data?: ExtensionData[];
|
|
93
|
+
total_order_behavior_count?: number;
|
|
94
|
+
today_order_behavior_count?: number;
|
|
95
|
+
week_order_behavior_count?: number;
|
|
96
|
+
month_order_behavior_count?: number;
|
|
97
|
+
customer_order_behavior_count?: number;
|
|
73
98
|
}
|
|
74
99
|
export interface DiscountState {
|
|
75
100
|
discountList: Discount[];
|
|
@@ -694,7 +694,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
694
694
|
}
|
|
695
695
|
if (!allOriginResources.length) {
|
|
696
696
|
const dateList = this.store.date.getDateList();
|
|
697
|
-
dateList.forEach((n) => {
|
|
697
|
+
dateList == null ? void 0 : dateList.forEach((n) => {
|
|
698
698
|
if (n.resource)
|
|
699
699
|
allOriginResources.push(...n.resource);
|
|
700
700
|
});
|
|
@@ -34,7 +34,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
34
34
|
discountList: Discount[];
|
|
35
35
|
};
|
|
36
36
|
setProductList(productList: Record<string, any>[]): void;
|
|
37
|
-
scanCode(code: string): Promise<{
|
|
37
|
+
scanCode(code: string, customerId?: number): Promise<{
|
|
38
38
|
isAvailable: boolean;
|
|
39
39
|
productList: Record<string, any>[];
|
|
40
40
|
discountList: Discount[];
|
|
@@ -198,10 +198,10 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
198
198
|
this.store.productList = productList;
|
|
199
199
|
}
|
|
200
200
|
// 扫码输入code
|
|
201
|
-
async scanCode(code) {
|
|
201
|
+
async scanCode(code, customerId) {
|
|
202
202
|
var _a, _b;
|
|
203
203
|
try {
|
|
204
|
-
const resultDiscountList = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code)) || [];
|
|
204
|
+
const resultDiscountList = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, customerId)) || [];
|
|
205
205
|
const rulesModule = this.store.rules;
|
|
206
206
|
if (!rulesModule) {
|
|
207
207
|
return {
|