@pisell/pisellos 1.0.143 → 1.0.145
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 +4 -2
- package/dist/modules/Discount/index.js +92 -4
- package/dist/modules/Discount/types.d.ts +7 -0
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/ShopDiscount/index.d.ts +1 -0
- package/dist/solution/ShopDiscount/index.js +23 -18
- package/lib/model/strategy/adapter/promotion/index.js +49 -0
- package/lib/modules/Discount/index.d.ts +4 -2
- package/lib/modules/Discount/index.js +62 -3
- package/lib/modules/Discount/types.d.ts +7 -0
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/ShopDiscount/index.d.ts +1 -0
- package/lib/solution/ShopDiscount/index.js +4 -2
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Module, PisellCore, ModuleOptions } from '../../types';
|
|
2
2
|
import { BaseModule } from '../BaseModule';
|
|
3
|
-
import { Discount, DiscountModuleAPI } from './types';
|
|
3
|
+
import { Discount, DiscountModuleAPI, DiscountWithReason } from './types';
|
|
4
4
|
export declare class DiscountModule extends BaseModule implements Module, DiscountModuleAPI {
|
|
5
5
|
protected defaultName: string;
|
|
6
6
|
protected defaultVersion: string;
|
|
@@ -24,10 +24,12 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
|
|
|
24
24
|
with_wallet_pass_holder: 0 | 1;
|
|
25
25
|
request_timezone: string;
|
|
26
26
|
}): Promise<Discount[]>;
|
|
27
|
-
batchSearch(code: string, customerId?: number): Promise<
|
|
27
|
+
batchSearch(code: string, customerId?: number): Promise<DiscountWithReason>;
|
|
28
28
|
batchSearchByProductIds(productIds: number[]): Promise<any>;
|
|
29
29
|
filterEnabledDiscountList(discountList: Discount[]): Discount[];
|
|
30
30
|
private checkUsageCreditsLimit;
|
|
31
|
+
filterEnabledDiscountListWithReason(discountList: Discount[]): DiscountWithReason;
|
|
32
|
+
private checkUsageCreditsLimitWithFailKey;
|
|
31
33
|
uniqueByProductId(discountList: Discount[]): Discount[];
|
|
32
34
|
filterDiscountListByProductIds(discountList: Discount[], productIds: number[]): Discount[];
|
|
33
35
|
calcDiscountApplicableProductTotalPrice(discount: Discount): number | undefined;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
2
4
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
5
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
6
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -177,7 +179,7 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
177
179
|
key: "batchSearch",
|
|
178
180
|
value: function () {
|
|
179
181
|
var _batchSearch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(code, customerId) {
|
|
180
|
-
var result,
|
|
182
|
+
var result, resultDiscountWithReason;
|
|
181
183
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
182
184
|
while (1) switch (_context5.prev = _context5.next) {
|
|
183
185
|
case 0:
|
|
@@ -186,17 +188,18 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
186
188
|
code: code,
|
|
187
189
|
translate_flag: 1,
|
|
188
190
|
tags: ['good_pass', 'product_discount_card'],
|
|
189
|
-
available: 1,
|
|
191
|
+
// available: 1,
|
|
190
192
|
relation_product: 1,
|
|
191
193
|
with: ['extensionData', 'customScheduleSnapshot', 'holder.detail'],
|
|
192
194
|
order_behavior_count: 1,
|
|
193
195
|
order_behavior_count_customer_id: customerId || 1,
|
|
196
|
+
unified_status_info_flag: 1,
|
|
194
197
|
request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
195
198
|
});
|
|
196
199
|
case 2:
|
|
197
200
|
result = _context5.sent;
|
|
198
|
-
|
|
199
|
-
return _context5.abrupt("return",
|
|
201
|
+
resultDiscountWithReason = this.filterEnabledDiscountListWithReason((result === null || result === void 0 ? void 0 : result.data) || []) || [];
|
|
202
|
+
return _context5.abrupt("return", resultDiscountWithReason);
|
|
200
203
|
case 5:
|
|
201
204
|
case "end":
|
|
202
205
|
return _context5.stop();
|
|
@@ -305,6 +308,91 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
305
308
|
return true;
|
|
306
309
|
}
|
|
307
310
|
|
|
311
|
+
// 过滤启用且可用的优惠券,并返回校验失败原因
|
|
312
|
+
}, {
|
|
313
|
+
key: "filterEnabledDiscountListWithReason",
|
|
314
|
+
value: function filterEnabledDiscountListWithReason(discountList) {
|
|
315
|
+
var _this3 = this;
|
|
316
|
+
var lists = discountList.filter(function (discount) {
|
|
317
|
+
return discount.limit_status === 'enable';
|
|
318
|
+
}).filter(function (discount) {
|
|
319
|
+
var remaining = 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);
|
|
320
|
+
return remaining;
|
|
321
|
+
}).map(function (discount) {
|
|
322
|
+
var limitFailKey = _this3.checkUsageCreditsLimitWithFailKey(discount);
|
|
323
|
+
return _objectSpread(_objectSpread({}, discount), {}, {
|
|
324
|
+
usageLimitFailKey: limitFailKey
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
// 可用的列表
|
|
329
|
+
var availableLists = lists.filter(function (item) {
|
|
330
|
+
return !item.usageLimitFailKey && item.unified_available_status !== 0;
|
|
331
|
+
});
|
|
332
|
+
// 不可用数据
|
|
333
|
+
var currentFailDiscount = lists.find(function (item) {
|
|
334
|
+
return item.usageLimitFailKey;
|
|
335
|
+
});
|
|
336
|
+
return {
|
|
337
|
+
discountList: availableLists,
|
|
338
|
+
unavailableReasonKey: currentFailDiscount === null || currentFailDiscount === void 0 ? void 0 : currentFailDiscount.usageLimitFailKey
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// 检查使用次数限制,并返回校验失败原因
|
|
343
|
+
}, {
|
|
344
|
+
key: "checkUsageCreditsLimitWithFailKey",
|
|
345
|
+
value: function checkUsageCreditsLimitWithFailKey(discount) {
|
|
346
|
+
if (!discount.extension_data || discount.extension_data.length === 0) {
|
|
347
|
+
return null;
|
|
348
|
+
}
|
|
349
|
+
var usageCreditsData = discount.extension_data.find(function (data) {
|
|
350
|
+
return data.field_key === 'usage_credits';
|
|
351
|
+
});
|
|
352
|
+
if (!usageCreditsData) {
|
|
353
|
+
return null;
|
|
354
|
+
}
|
|
355
|
+
var value = usageCreditsData.value;
|
|
356
|
+
|
|
357
|
+
// 总次数限制
|
|
358
|
+
if (value.total_credits && value.total_credits > 0) {
|
|
359
|
+
if ((discount.total_order_behavior_count || 0) >= value.total_credits) {
|
|
360
|
+
return 'total_credits';
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// 单用户限制
|
|
365
|
+
if (value.per_user_limit && value.per_user_limit > 0) {
|
|
366
|
+
if ((discount.customer_order_behavior_count || 0) >= value.per_user_limit) {
|
|
367
|
+
return 'per_user_limit';
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// 单日限制
|
|
372
|
+
if (value.max_per_day && value.max_per_day > 0) {
|
|
373
|
+
if ((discount.today_order_behavior_count || 0) >= value.max_per_day) {
|
|
374
|
+
return 'max_per_day';
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// 单周限制
|
|
379
|
+
if (value.max_per_week && value.max_per_week > 0) {
|
|
380
|
+
if ((discount.week_order_behavior_count || 0) >= value.max_per_week) {
|
|
381
|
+
return 'max_per_week';
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// 单月限制
|
|
386
|
+
if (value.max_per_month && value.max_per_month > 0) {
|
|
387
|
+
if ((discount.month_order_behavior_count || 0) >= value.max_per_month) {
|
|
388
|
+
return 'max_per_month';
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// 全部通过
|
|
393
|
+
return null;
|
|
394
|
+
}
|
|
395
|
+
|
|
308
396
|
// 根据productIds去重
|
|
309
397
|
}, {
|
|
310
398
|
key: "uniqueByProductId",
|
|
@@ -63,6 +63,11 @@ interface UsageCreditsValue {
|
|
|
63
63
|
max_per_week: number;
|
|
64
64
|
max_per_month: number;
|
|
65
65
|
}
|
|
66
|
+
export type DiscountFilterRejectKey = 'total_credits' | 'per_user_limit' | 'max_per_day' | 'max_per_week' | 'max_per_month';
|
|
67
|
+
export interface DiscountWithReason {
|
|
68
|
+
discountList: Discount[];
|
|
69
|
+
unavailableReasonKey: DiscountFilterRejectKey | null;
|
|
70
|
+
}
|
|
66
71
|
interface ExtensionData {
|
|
67
72
|
id: number;
|
|
68
73
|
shop_id: number;
|
|
@@ -147,6 +152,8 @@ export interface Discount {
|
|
|
147
152
|
start_date?: string;
|
|
148
153
|
start_time?: string;
|
|
149
154
|
discount_rule_uncheck_flag?: boolean;
|
|
155
|
+
usageLimitFailKey?: string | null;
|
|
156
|
+
unified_available_status?: number | undefined | null;
|
|
150
157
|
}
|
|
151
158
|
export interface DiscountState {
|
|
152
159
|
discountList: Discount[];
|
|
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
311
311
|
date: string;
|
|
312
312
|
status: string;
|
|
313
313
|
week: string;
|
|
314
|
-
weekNum: 0 |
|
|
314
|
+
weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
|
|
315
315
|
}[]>;
|
|
316
316
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
317
317
|
private getScheduleDataByIds;
|
|
@@ -115,7 +115,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
|
|
|
115
115
|
* 获取当前的客户搜索条件
|
|
116
116
|
* @returns 当前搜索条件
|
|
117
117
|
*/
|
|
118
|
-
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "
|
|
118
|
+
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
|
|
119
119
|
/**
|
|
120
120
|
* 获取客户列表状态(包含滚动加载相关状态)
|
|
121
121
|
* @returns 客户状态
|
|
@@ -46,6 +46,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
46
46
|
discountList: Discount[];
|
|
47
47
|
type: "server" | "clientCalc";
|
|
48
48
|
unavailableReason?: UnavailableReason;
|
|
49
|
+
unavailableReasonKey?: string | null;
|
|
49
50
|
}>;
|
|
50
51
|
calcDiscountApplicableProductTotalPrice(discount: Discount): number | undefined;
|
|
51
52
|
private getCustomer;
|
|
@@ -437,7 +437,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
437
437
|
key: "scanCode",
|
|
438
438
|
value: function () {
|
|
439
439
|
var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(code, customerId) {
|
|
440
|
-
var _this$store$discount4, _this$store$bookingSu2, resultDiscountList, rulesModule, withScanList, currentSelectedDiscountList, _ref2, newProductList, newDiscountList, isAvailable, unavailableReason, _this$options$otherPa6;
|
|
440
|
+
var _this$store$discount4, _this$store$bookingSu2, resultDiscountWithReason, resultDiscountList, unavailableReasonKey, rulesModule, withScanList, currentSelectedDiscountList, _ref2, newProductList, newDiscountList, isAvailable, unavailableReason, _this$options$otherPa6;
|
|
441
441
|
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
442
442
|
while (1) switch (_context6.prev = _context6.next) {
|
|
443
443
|
case 0:
|
|
@@ -450,12 +450,16 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
450
450
|
_context6.next = 6;
|
|
451
451
|
break;
|
|
452
452
|
}
|
|
453
|
-
_context6.t0 =
|
|
453
|
+
_context6.t0 = {
|
|
454
|
+
discountList: [],
|
|
455
|
+
unavailableReasonKey: null
|
|
456
|
+
};
|
|
454
457
|
case 6:
|
|
455
|
-
|
|
458
|
+
resultDiscountWithReason = _context6.t0;
|
|
459
|
+
resultDiscountList = resultDiscountWithReason.discountList, unavailableReasonKey = resultDiscountWithReason.unavailableReasonKey;
|
|
456
460
|
rulesModule = this.store.rules;
|
|
457
461
|
if (rulesModule) {
|
|
458
|
-
_context6.next =
|
|
462
|
+
_context6.next = 11;
|
|
459
463
|
break;
|
|
460
464
|
}
|
|
461
465
|
return _context6.abrupt("return", {
|
|
@@ -465,18 +469,19 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
465
469
|
discountList: this.getDiscountList(),
|
|
466
470
|
unavailableReason: UnavailableReason.Unknown
|
|
467
471
|
});
|
|
468
|
-
case
|
|
472
|
+
case 11:
|
|
469
473
|
if (resultDiscountList.length) {
|
|
470
|
-
_context6.next =
|
|
474
|
+
_context6.next = 13;
|
|
471
475
|
break;
|
|
472
476
|
}
|
|
473
477
|
return _context6.abrupt("return", {
|
|
474
478
|
type: "server",
|
|
475
479
|
isAvailable: false,
|
|
476
480
|
productList: this.store.productList || [],
|
|
477
|
-
discountList: this.getDiscountList()
|
|
481
|
+
discountList: this.getDiscountList(),
|
|
482
|
+
unavailableReasonKey: unavailableReasonKey
|
|
478
483
|
});
|
|
479
|
-
case
|
|
484
|
+
case 13:
|
|
480
485
|
withScanList = resultDiscountList.map(function (item) {
|
|
481
486
|
return _objectSpread(_objectSpread({}, item), {}, {
|
|
482
487
|
isScan: true
|
|
@@ -490,7 +495,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
490
495
|
return m.id === n.id;
|
|
491
496
|
});
|
|
492
497
|
}))) {
|
|
493
|
-
_context6.next =
|
|
498
|
+
_context6.next = 17;
|
|
494
499
|
break;
|
|
495
500
|
}
|
|
496
501
|
return _context6.abrupt("return", {
|
|
@@ -499,7 +504,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
499
504
|
productList: this.store.productList || [],
|
|
500
505
|
discountList: this.getDiscountList()
|
|
501
506
|
});
|
|
502
|
-
case
|
|
507
|
+
case 17:
|
|
503
508
|
_ref2 = rulesModule.isDiscountListAvailable({
|
|
504
509
|
productList: this.store.productList || [],
|
|
505
510
|
oldDiscountList: this.getDiscountList(),
|
|
@@ -513,19 +518,19 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
513
518
|
discountList: this.getDiscountList()
|
|
514
519
|
}, newProductList = _ref2.productList, newDiscountList = _ref2.discountList, isAvailable = _ref2.isAvailable, unavailableReason = _ref2.unavailableReason;
|
|
515
520
|
if (!isAvailable) {
|
|
516
|
-
_context6.next =
|
|
521
|
+
_context6.next = 25;
|
|
517
522
|
break;
|
|
518
523
|
}
|
|
519
524
|
this.setDiscountList(newDiscountList || []);
|
|
520
525
|
this.store.originalDiscountList = newDiscountList || [];
|
|
521
526
|
this.setProductList(newProductList || []);
|
|
522
527
|
if (!(this.isWalkIn() && resultDiscountList.length && ((_this$options$otherPa6 = this.options.otherParams) === null || _this$options$otherPa6 === void 0 ? void 0 : _this$options$otherPa6.platform) === 'shop')) {
|
|
523
|
-
_context6.next =
|
|
528
|
+
_context6.next = 25;
|
|
524
529
|
break;
|
|
525
530
|
}
|
|
526
|
-
_context6.next =
|
|
531
|
+
_context6.next = 25;
|
|
527
532
|
return this.getCustomerWallet(resultDiscountList[0].customer_id);
|
|
528
|
-
case
|
|
533
|
+
case 25:
|
|
529
534
|
return _context6.abrupt("return", {
|
|
530
535
|
type: "clientCalc",
|
|
531
536
|
isAvailable: isAvailable || false,
|
|
@@ -533,8 +538,8 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
533
538
|
discountList: newDiscountList || this.getDiscountList(),
|
|
534
539
|
unavailableReason: unavailableReason
|
|
535
540
|
});
|
|
536
|
-
case
|
|
537
|
-
_context6.prev =
|
|
541
|
+
case 28:
|
|
542
|
+
_context6.prev = 28;
|
|
538
543
|
_context6.t1 = _context6["catch"](0);
|
|
539
544
|
console.error('[ShopDiscount] 扫码出错:', _context6.t1);
|
|
540
545
|
return _context6.abrupt("return", {
|
|
@@ -544,11 +549,11 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
544
549
|
discountList: this.getDiscountList(),
|
|
545
550
|
unavailableReason: UnavailableReason.Unknown
|
|
546
551
|
});
|
|
547
|
-
case
|
|
552
|
+
case 32:
|
|
548
553
|
case "end":
|
|
549
554
|
return _context6.stop();
|
|
550
555
|
}
|
|
551
|
-
}, _callee6, this, [[0,
|
|
556
|
+
}, _callee6, this, [[0, 28]]);
|
|
552
557
|
}));
|
|
553
558
|
function scanCode(_x5, _x6) {
|
|
554
559
|
return _scanCode.apply(this, arguments);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
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
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/model/strategy/adapter/promotion/index.ts
|
|
30
|
+
var promotion_exports = {};
|
|
31
|
+
__export(promotion_exports, {
|
|
32
|
+
BUY_X_GET_Y_FREE_STRATEGY: () => import_examples.BUY_X_GET_Y_FREE_STRATEGY,
|
|
33
|
+
PromotionAdapter: () => import_adapter.PromotionAdapter,
|
|
34
|
+
PromotionEvaluator: () => import_evaluator.PromotionEvaluator,
|
|
35
|
+
X_ITEMS_FOR_Y_PRICE_STRATEGY: () => import_examples.X_ITEMS_FOR_Y_PRICE_STRATEGY,
|
|
36
|
+
default: () => import_adapter2.default
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(promotion_exports);
|
|
39
|
+
var import_evaluator = require("./evaluator");
|
|
40
|
+
var import_adapter = require("./adapter");
|
|
41
|
+
var import_adapter2 = __toESM(require("./adapter"));
|
|
42
|
+
var import_examples = require("./examples");
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
BUY_X_GET_Y_FREE_STRATEGY,
|
|
46
|
+
PromotionAdapter,
|
|
47
|
+
PromotionEvaluator,
|
|
48
|
+
X_ITEMS_FOR_Y_PRICE_STRATEGY
|
|
49
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Module, PisellCore, ModuleOptions } from '../../types';
|
|
2
2
|
import { BaseModule } from '../BaseModule';
|
|
3
|
-
import { Discount, DiscountModuleAPI } from './types';
|
|
3
|
+
import { Discount, DiscountModuleAPI, DiscountWithReason } from './types';
|
|
4
4
|
export declare class DiscountModule extends BaseModule implements Module, DiscountModuleAPI {
|
|
5
5
|
protected defaultName: string;
|
|
6
6
|
protected defaultVersion: string;
|
|
@@ -24,10 +24,12 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
|
|
|
24
24
|
with_wallet_pass_holder: 0 | 1;
|
|
25
25
|
request_timezone: string;
|
|
26
26
|
}): Promise<Discount[]>;
|
|
27
|
-
batchSearch(code: string, customerId?: number): Promise<
|
|
27
|
+
batchSearch(code: string, customerId?: number): Promise<DiscountWithReason>;
|
|
28
28
|
batchSearchByProductIds(productIds: number[]): Promise<any>;
|
|
29
29
|
filterEnabledDiscountList(discountList: Discount[]): Discount[];
|
|
30
30
|
private checkUsageCreditsLimit;
|
|
31
|
+
filterEnabledDiscountListWithReason(discountList: Discount[]): DiscountWithReason;
|
|
32
|
+
private checkUsageCreditsLimitWithFailKey;
|
|
31
33
|
uniqueByProductId(discountList: Discount[]): Discount[];
|
|
32
34
|
filterDiscountListByProductIds(discountList: Discount[], productIds: number[]): Discount[];
|
|
33
35
|
calcDiscountApplicableProductTotalPrice(discount: Discount): number | undefined;
|
|
@@ -107,15 +107,16 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
|
|
|
107
107
|
code,
|
|
108
108
|
translate_flag: 1,
|
|
109
109
|
tags: ["good_pass", "product_discount_card"],
|
|
110
|
-
available: 1,
|
|
110
|
+
// available: 1,
|
|
111
111
|
relation_product: 1,
|
|
112
112
|
with: ["extensionData", "customScheduleSnapshot", "holder.detail"],
|
|
113
113
|
order_behavior_count: 1,
|
|
114
114
|
order_behavior_count_customer_id: customerId || 1,
|
|
115
|
+
unified_status_info_flag: 1,
|
|
115
116
|
request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
116
117
|
});
|
|
117
|
-
const
|
|
118
|
-
return
|
|
118
|
+
const resultDiscountWithReason = this.filterEnabledDiscountListWithReason((result == null ? void 0 : result.data) || []) || [];
|
|
119
|
+
return resultDiscountWithReason;
|
|
119
120
|
}
|
|
120
121
|
async batchSearchByProductIds(productIds) {
|
|
121
122
|
const result = await this.request.get(`/machinecode/batch-search`, {
|
|
@@ -170,6 +171,64 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
|
|
|
170
171
|
}
|
|
171
172
|
return true;
|
|
172
173
|
}
|
|
174
|
+
// 过滤启用且可用的优惠券,并返回校验失败原因
|
|
175
|
+
filterEnabledDiscountListWithReason(discountList) {
|
|
176
|
+
let lists = discountList.filter((discount) => discount.limit_status === "enable").filter((discount) => {
|
|
177
|
+
const remaining = 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);
|
|
178
|
+
return remaining;
|
|
179
|
+
}).map((discount) => {
|
|
180
|
+
const limitFailKey = this.checkUsageCreditsLimitWithFailKey(discount);
|
|
181
|
+
return {
|
|
182
|
+
...discount,
|
|
183
|
+
usageLimitFailKey: limitFailKey
|
|
184
|
+
};
|
|
185
|
+
});
|
|
186
|
+
const availableLists = lists.filter((item) => !item.usageLimitFailKey && item.unified_available_status !== 0);
|
|
187
|
+
const currentFailDiscount = lists.find((item) => item.usageLimitFailKey);
|
|
188
|
+
return {
|
|
189
|
+
discountList: availableLists,
|
|
190
|
+
unavailableReasonKey: currentFailDiscount == null ? void 0 : currentFailDiscount.usageLimitFailKey
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
// 检查使用次数限制,并返回校验失败原因
|
|
194
|
+
checkUsageCreditsLimitWithFailKey(discount) {
|
|
195
|
+
if (!discount.extension_data || discount.extension_data.length === 0) {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
const usageCreditsData = discount.extension_data.find(
|
|
199
|
+
(data) => data.field_key === "usage_credits"
|
|
200
|
+
);
|
|
201
|
+
if (!usageCreditsData) {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
const value = usageCreditsData.value;
|
|
205
|
+
if (value.total_credits && value.total_credits > 0) {
|
|
206
|
+
if ((discount.total_order_behavior_count || 0) >= value.total_credits) {
|
|
207
|
+
return "total_credits";
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (value.per_user_limit && value.per_user_limit > 0) {
|
|
211
|
+
if ((discount.customer_order_behavior_count || 0) >= value.per_user_limit) {
|
|
212
|
+
return "per_user_limit";
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (value.max_per_day && value.max_per_day > 0) {
|
|
216
|
+
if ((discount.today_order_behavior_count || 0) >= value.max_per_day) {
|
|
217
|
+
return "max_per_day";
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
if (value.max_per_week && value.max_per_week > 0) {
|
|
221
|
+
if ((discount.week_order_behavior_count || 0) >= value.max_per_week) {
|
|
222
|
+
return "max_per_week";
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (value.max_per_month && value.max_per_month > 0) {
|
|
226
|
+
if ((discount.month_order_behavior_count || 0) >= value.max_per_month) {
|
|
227
|
+
return "max_per_month";
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
173
232
|
// 根据productIds去重
|
|
174
233
|
uniqueByProductId(discountList) {
|
|
175
234
|
return (0, import_utils.uniqueById)(discountList, "product_id");
|
|
@@ -63,6 +63,11 @@ interface UsageCreditsValue {
|
|
|
63
63
|
max_per_week: number;
|
|
64
64
|
max_per_month: number;
|
|
65
65
|
}
|
|
66
|
+
export type DiscountFilterRejectKey = 'total_credits' | 'per_user_limit' | 'max_per_day' | 'max_per_week' | 'max_per_month';
|
|
67
|
+
export interface DiscountWithReason {
|
|
68
|
+
discountList: Discount[];
|
|
69
|
+
unavailableReasonKey: DiscountFilterRejectKey | null;
|
|
70
|
+
}
|
|
66
71
|
interface ExtensionData {
|
|
67
72
|
id: number;
|
|
68
73
|
shop_id: number;
|
|
@@ -147,6 +152,8 @@ export interface Discount {
|
|
|
147
152
|
start_date?: string;
|
|
148
153
|
start_time?: string;
|
|
149
154
|
discount_rule_uncheck_flag?: boolean;
|
|
155
|
+
usageLimitFailKey?: string | null;
|
|
156
|
+
unified_available_status?: number | undefined | null;
|
|
150
157
|
}
|
|
151
158
|
export interface DiscountState {
|
|
152
159
|
discountList: Discount[];
|
|
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
311
311
|
date: string;
|
|
312
312
|
status: string;
|
|
313
313
|
week: string;
|
|
314
|
-
weekNum: 0 |
|
|
314
|
+
weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
|
|
315
315
|
}[]>;
|
|
316
316
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
317
317
|
private getScheduleDataByIds;
|
|
@@ -115,7 +115,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
|
|
|
115
115
|
* 获取当前的客户搜索条件
|
|
116
116
|
* @returns 当前搜索条件
|
|
117
117
|
*/
|
|
118
|
-
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "
|
|
118
|
+
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
|
|
119
119
|
/**
|
|
120
120
|
* 获取客户列表状态(包含滚动加载相关状态)
|
|
121
121
|
* @returns 客户状态
|
|
@@ -46,6 +46,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
46
46
|
discountList: Discount[];
|
|
47
47
|
type: "server" | "clientCalc";
|
|
48
48
|
unavailableReason?: UnavailableReason;
|
|
49
|
+
unavailableReasonKey?: string | null;
|
|
49
50
|
}>;
|
|
50
51
|
calcDiscountApplicableProductTotalPrice(discount: Discount): number | undefined;
|
|
51
52
|
private getCustomer;
|
|
@@ -282,7 +282,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
282
282
|
async scanCode(code, customerId) {
|
|
283
283
|
var _a, _b, _c;
|
|
284
284
|
try {
|
|
285
|
-
const
|
|
285
|
+
const resultDiscountWithReason = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, customerId)) || { discountList: [], unavailableReasonKey: null };
|
|
286
|
+
const { discountList: resultDiscountList, unavailableReasonKey } = resultDiscountWithReason;
|
|
286
287
|
const rulesModule = this.store.rules;
|
|
287
288
|
if (!rulesModule) {
|
|
288
289
|
return {
|
|
@@ -298,7 +299,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
298
299
|
type: "server",
|
|
299
300
|
isAvailable: false,
|
|
300
301
|
productList: this.store.productList || [],
|
|
301
|
-
discountList: this.getDiscountList()
|
|
302
|
+
discountList: this.getDiscountList(),
|
|
303
|
+
unavailableReasonKey
|
|
302
304
|
};
|
|
303
305
|
}
|
|
304
306
|
const withScanList = resultDiscountList.map((item) => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"private": false,
|
|
3
3
|
"name": "@pisell/pisellos",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.145",
|
|
5
5
|
"description": "一个可扩展的前端模块化SDK框架,支持插件系统",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"format": "prettier --write \"src/**/*.{ts,tsx,js,jsx,json,md}\"",
|
|
19
19
|
"changeset": "changeset",
|
|
20
20
|
"version": "changeset version",
|
|
21
|
-
"release": "changeset publish
|
|
21
|
+
"release": "changeset publish && npm run sync && git push",
|
|
22
22
|
"example": "npx parcel-bundler examples/index.html",
|
|
23
23
|
"docs": "typedoc --out docs src/index.ts",
|
|
24
24
|
"sync": "node sync.js",
|