@pisell/pisellos 1.0.142 → 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/model/strategy/adapter/index.d.ts +4 -0
- package/dist/model/strategy/adapter/index.js +4 -1
- package/dist/model/strategy/adapter/itemRule/adapter.d.ts +67 -0
- package/dist/model/strategy/adapter/itemRule/adapter.js +483 -0
- package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
- package/dist/model/strategy/adapter/itemRule/evaluator.js +169 -0
- package/dist/model/strategy/adapter/itemRule/examples.d.ts +79 -0
- package/dist/model/strategy/adapter/itemRule/examples.js +382 -0
- package/dist/model/strategy/adapter/itemRule/index.d.ts +5 -0
- package/dist/model/strategy/adapter/itemRule/index.js +5 -0
- package/dist/model/strategy/adapter/itemRule/type.d.ts +225 -0
- package/dist/model/strategy/adapter/itemRule/type.js +101 -0
- package/dist/model/strategy/adapter/promotion/adapter.d.ts +66 -0
- package/dist/model/strategy/adapter/promotion/adapter.js +271 -0
- package/dist/model/strategy/adapter/promotion/evaluator.d.ts +213 -0
- package/dist/model/strategy/adapter/promotion/evaluator.js +1279 -0
- package/dist/model/strategy/adapter/promotion/examples.d.ts +138 -0
- package/dist/model/strategy/adapter/promotion/examples.js +166 -0
- package/dist/model/strategy/adapter/promotion/index.d.ts +4 -0
- package/dist/model/strategy/adapter/promotion/index.js +0 -0
- package/dist/model/strategy/adapter/promotion/type.d.ts +447 -0
- package/dist/model/strategy/adapter/promotion/type.js +209 -0
- package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
- package/dist/model/strategy/adapter/walletPass/evaluator.js +67 -10
- package/dist/model/strategy/adapter/walletPass/locales.js +12 -3
- package/dist/model/strategy/adapter/walletPass/type.d.ts +20 -2
- package/dist/model/strategy/adapter/walletPass/utils.d.ts +6 -6
- package/dist/model/strategy/adapter/walletPass/utils.js +143 -103
- package/dist/model/strategy/engine.d.ts +119 -0
- package/dist/model/strategy/engine.js +711 -0
- package/dist/model/strategy/index.d.ts +2 -93
- package/dist/model/strategy/index.js +6 -549
- package/dist/model/strategy/type.d.ts +17 -0
- package/dist/model/strategy/type.js +4 -0
- 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/ShopDiscount/index.d.ts +1 -0
- package/dist/solution/ShopDiscount/index.js +23 -18
- package/lib/model/strategy/adapter/index.d.ts +4 -0
- package/lib/model/strategy/adapter/index.js +12 -0
- package/lib/model/strategy/adapter/itemRule/adapter.d.ts +67 -0
- package/lib/model/strategy/adapter/itemRule/adapter.js +377 -0
- package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
- package/lib/model/strategy/adapter/itemRule/evaluator.js +124 -0
- package/lib/model/strategy/adapter/itemRule/examples.d.ts +79 -0
- package/lib/model/strategy/adapter/itemRule/examples.js +316 -0
- package/lib/model/strategy/adapter/itemRule/index.d.ts +5 -0
- package/lib/model/strategy/adapter/itemRule/index.js +60 -0
- package/lib/model/strategy/adapter/itemRule/type.d.ts +225 -0
- package/lib/model/strategy/adapter/itemRule/type.js +46 -0
- package/lib/model/strategy/adapter/promotion/adapter.d.ts +66 -0
- package/lib/model/strategy/adapter/promotion/adapter.js +217 -0
- package/lib/model/strategy/adapter/promotion/evaluator.d.ts +213 -0
- package/lib/model/strategy/adapter/promotion/evaluator.js +893 -0
- package/lib/model/strategy/adapter/promotion/examples.d.ts +138 -0
- package/lib/model/strategy/adapter/promotion/examples.js +192 -0
- package/lib/model/strategy/adapter/promotion/index.d.ts +4 -0
- package/lib/model/strategy/adapter/promotion/index.js +49 -0
- package/lib/model/strategy/adapter/promotion/type.d.ts +447 -0
- package/lib/model/strategy/adapter/promotion/type.js +51 -0
- package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
- package/lib/model/strategy/adapter/walletPass/evaluator.js +38 -5
- package/lib/model/strategy/adapter/walletPass/locales.js +12 -3
- package/lib/model/strategy/adapter/walletPass/type.d.ts +20 -2
- package/lib/model/strategy/adapter/walletPass/utils.d.ts +6 -6
- package/lib/model/strategy/adapter/walletPass/utils.js +153 -82
- package/lib/model/strategy/engine.d.ts +119 -0
- package/lib/model/strategy/engine.js +514 -0
- package/lib/model/strategy/index.d.ts +2 -93
- package/lib/model/strategy/index.js +6 -381
- package/lib/model/strategy/type.d.ts +17 -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/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[];
|
|
@@ -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);
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
export * from './type';
|
|
2
2
|
export { default as WalletPassAdapter } from './walletPass';
|
|
3
3
|
export { WalletPassEvaluator } from './walletPass/evaluator';
|
|
4
|
+
export { PromotionEvaluator } from './promotion/evaluator';
|
|
5
|
+
export { PromotionAdapter } from './promotion/adapter';
|
|
6
|
+
export { ItemRuleEvaluator } from './itemRule/evaluator';
|
|
7
|
+
export { ItemRuleAdapter } from './itemRule/adapter';
|
|
@@ -30,6 +30,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/model/strategy/adapter/index.ts
|
|
31
31
|
var adapter_exports = {};
|
|
32
32
|
__export(adapter_exports, {
|
|
33
|
+
ItemRuleAdapter: () => import_adapter2.ItemRuleAdapter,
|
|
34
|
+
ItemRuleEvaluator: () => import_evaluator3.ItemRuleEvaluator,
|
|
35
|
+
PromotionAdapter: () => import_adapter.PromotionAdapter,
|
|
36
|
+
PromotionEvaluator: () => import_evaluator2.PromotionEvaluator,
|
|
33
37
|
WalletPassAdapter: () => import_walletPass.default,
|
|
34
38
|
WalletPassEvaluator: () => import_evaluator.WalletPassEvaluator
|
|
35
39
|
});
|
|
@@ -37,8 +41,16 @@ module.exports = __toCommonJS(adapter_exports);
|
|
|
37
41
|
__reExport(adapter_exports, require("./type"), module.exports);
|
|
38
42
|
var import_walletPass = __toESM(require("./walletPass"));
|
|
39
43
|
var import_evaluator = require("./walletPass/evaluator");
|
|
44
|
+
var import_evaluator2 = require("./promotion/evaluator");
|
|
45
|
+
var import_adapter = require("./promotion/adapter");
|
|
46
|
+
var import_evaluator3 = require("./itemRule/evaluator");
|
|
47
|
+
var import_adapter2 = require("./itemRule/adapter");
|
|
40
48
|
// Annotate the CommonJS export names for ESM import in node:
|
|
41
49
|
0 && (module.exports = {
|
|
50
|
+
ItemRuleAdapter,
|
|
51
|
+
ItemRuleEvaluator,
|
|
52
|
+
PromotionAdapter,
|
|
53
|
+
PromotionEvaluator,
|
|
42
54
|
WalletPassAdapter,
|
|
43
55
|
WalletPassEvaluator,
|
|
44
56
|
...require("./type")
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { EvaluationResult, RuntimeContext, ActionEffect } from '../../type';
|
|
2
|
+
import type { BusinessAdapter } from '../type';
|
|
3
|
+
import { type ItemRuleBusinessData, type QuantityCheckResult, type PrefillItemResult, type QuantityLimitResult } from './type';
|
|
4
|
+
/**
|
|
5
|
+
* ItemRule 适配器
|
|
6
|
+
*
|
|
7
|
+
* 将堂食扫码点餐的商品规则业务数据转换为策略引擎格式,
|
|
8
|
+
* 并将引擎结果转换为数量校验和预填购物车的业务结果。
|
|
9
|
+
*/
|
|
10
|
+
export declare class ItemRuleAdapter implements BusinessAdapter {
|
|
11
|
+
name: string;
|
|
12
|
+
version: string;
|
|
13
|
+
prepareContext(businessData: ItemRuleBusinessData): RuntimeContext;
|
|
14
|
+
transformResult(result: EvaluationResult, businessData?: ItemRuleBusinessData): {
|
|
15
|
+
quantityChecks: QuantityCheckResult[];
|
|
16
|
+
prefillItems: PrefillItemResult[];
|
|
17
|
+
};
|
|
18
|
+
formatConfig(result: EvaluationResult, businessData?: ItemRuleBusinessData): {
|
|
19
|
+
result: EvaluationResult;
|
|
20
|
+
businessData?: ItemRuleBusinessData;
|
|
21
|
+
};
|
|
22
|
+
private processQuantityCheck;
|
|
23
|
+
/**
|
|
24
|
+
* 根据 scope 判断当前提交是否需要评估此规则
|
|
25
|
+
*/
|
|
26
|
+
private shouldEvaluateForScope;
|
|
27
|
+
/**
|
|
28
|
+
* 计算目标商品在购物车中的实际数量
|
|
29
|
+
*
|
|
30
|
+
* cumulative scope 时还会加上历史订单数量。
|
|
31
|
+
*/
|
|
32
|
+
private calculateActualQuantity;
|
|
33
|
+
/**
|
|
34
|
+
* 逐条评估数量规则
|
|
35
|
+
*/
|
|
36
|
+
private evaluateQuantityRules;
|
|
37
|
+
/**
|
|
38
|
+
* 根据 source 解析出数量规则的实际数值
|
|
39
|
+
*/
|
|
40
|
+
private resolveQuantityValue;
|
|
41
|
+
/**
|
|
42
|
+
* 格式化校验提示语,替换 {min} {max} 占位符
|
|
43
|
+
*/
|
|
44
|
+
private formatValidationMessage;
|
|
45
|
+
/**
|
|
46
|
+
* 从单个 QUANTITY_CHECK action 中提取数量限制配置。
|
|
47
|
+
*
|
|
48
|
+
* 根据 scope + submissionIndex 判断是否适用,
|
|
49
|
+
* 解析动态数量来源(pax)后返回 min/max/exact/mustInclude。
|
|
50
|
+
* 不适用或无配置时返回 null。
|
|
51
|
+
*/
|
|
52
|
+
extractQuantityLimits(action: ActionEffect, businessData: ItemRuleBusinessData): QuantityLimitResult | null;
|
|
53
|
+
/**
|
|
54
|
+
* 计算当前提交剩余可选的最大数量。
|
|
55
|
+
*
|
|
56
|
+
* 仅在 scope='cumulative' 且存在 requiredMax 时生效:
|
|
57
|
+
* 用 requiredMax 减去 historicalItems 中目标商品的累计数量,保底 0。
|
|
58
|
+
* 其余场景返回 undefined,保持向后兼容。
|
|
59
|
+
*/
|
|
60
|
+
private calculateRemainingMax;
|
|
61
|
+
private processPrefillCart;
|
|
62
|
+
/**
|
|
63
|
+
* 根据 quantityFrom 计算预填数量
|
|
64
|
+
*/
|
|
65
|
+
private resolvePrefillQuantity;
|
|
66
|
+
}
|
|
67
|
+
export default ItemRuleAdapter;
|