@pisell/pisellos 3.0.95 → 3.0.97
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/promotion/index.js +0 -9
- package/dist/modules/Discount/index.d.ts +2 -1
- package/dist/modules/Rules/index.js +2 -1
- package/dist/solution/ShopDiscount/index.d.ts +1 -0
- package/dist/solution/ShopDiscount/index.js +28 -19
- package/dist/solution/ShopDiscount/types.d.ts +1 -0
- package/dist/solution/ShopDiscount/utils.js +8 -5
- package/lib/model/strategy/adapter/promotion/index.js +0 -49
- package/lib/modules/Discount/index.d.ts +2 -1
- package/lib/modules/Rules/index.js +1 -1
- package/lib/solution/ShopDiscount/index.d.ts +1 -0
- package/lib/solution/ShopDiscount/index.js +9 -3
- package/lib/solution/ShopDiscount/types.d.ts +1 -0
- package/lib/solution/ShopDiscount/utils.js +5 -5
- package/package.json +1 -1
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// 导出评估器
|
|
2
|
-
export { PromotionEvaluator } from "./evaluator";
|
|
3
|
-
|
|
4
|
-
// 导出适配器
|
|
5
|
-
export { PromotionAdapter } from "./adapter";
|
|
6
|
-
export { default } from "./adapter";
|
|
7
|
-
|
|
8
|
-
// 导出策略配置示例常量
|
|
9
|
-
export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY } from "./examples";
|
|
@@ -17,12 +17,13 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
|
|
|
17
17
|
setOriginalDiscountList(originalDiscountList: Discount[]): Promise<void>;
|
|
18
18
|
getOriginalDiscountList(): Discount[];
|
|
19
19
|
loadPrepareConfig(params: {
|
|
20
|
-
action?: 'create';
|
|
20
|
+
action?: 'create' | 'edit';
|
|
21
21
|
with_good_pass: 0 | 1;
|
|
22
22
|
with_discount_card: 0 | 1;
|
|
23
23
|
customer_id: number;
|
|
24
24
|
with_wallet_pass_holder: 0 | 1;
|
|
25
25
|
request_timezone: string;
|
|
26
|
+
order_id?: number;
|
|
26
27
|
}): Promise<Discount[]>;
|
|
27
28
|
batchSearch(code: string, customerId?: number): Promise<DiscountWithReason>;
|
|
28
29
|
filterEnabledDiscountList(discountList: Discount[]): Discount[];
|
|
@@ -1805,7 +1805,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1805
1805
|
// 套餐适用范围配置
|
|
1806
1806
|
var packageScope = usageRules === null || usageRules === void 0 ? void 0 : usageRules.package_scope;
|
|
1807
1807
|
var _ref8 = packageScope || {},
|
|
1808
|
-
|
|
1808
|
+
_ref8$type = _ref8.type,
|
|
1809
|
+
scopeType = _ref8$type === void 0 ? 'product_all' : _ref8$type,
|
|
1809
1810
|
_ref8$exclude_bundle_ = _ref8.exclude_bundle_product_ids,
|
|
1810
1811
|
exclude_bundle_product_ids = _ref8$exclude_bundle_ === void 0 ? [] : _ref8$exclude_bundle_,
|
|
1811
1812
|
_ref8$include_bundle_ = _ref8.include_bundle_product_ids,
|
|
@@ -25,6 +25,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
25
25
|
setHolders(holders: {
|
|
26
26
|
form_record_id: number;
|
|
27
27
|
}[]): void;
|
|
28
|
+
setOrderId(id?: number): void;
|
|
28
29
|
setBookingSubject(bookingSubject: {
|
|
29
30
|
type?: 'form' | 'customer';
|
|
30
31
|
[key: string]: any;
|
|
@@ -56,7 +56,8 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
56
56
|
originalDiscountList: [],
|
|
57
57
|
currentBookingTime: "",
|
|
58
58
|
filteredDiscountList: [],
|
|
59
|
-
bookingSubject: undefined
|
|
59
|
+
bookingSubject: undefined,
|
|
60
|
+
orderId: undefined
|
|
60
61
|
};
|
|
61
62
|
return _this;
|
|
62
63
|
}
|
|
@@ -294,6 +295,11 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
294
295
|
value: function setHolders(holders) {
|
|
295
296
|
this.store.holders = holders;
|
|
296
297
|
}
|
|
298
|
+
}, {
|
|
299
|
+
key: "setOrderId",
|
|
300
|
+
value: function setOrderId(id) {
|
|
301
|
+
this.store.orderId = id;
|
|
302
|
+
}
|
|
297
303
|
}, {
|
|
298
304
|
key: "setBookingSubject",
|
|
299
305
|
value: function setBookingSubject(bookingSubject) {
|
|
@@ -686,24 +692,27 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
686
692
|
key: "loadPrepareConfig",
|
|
687
693
|
value: function () {
|
|
688
694
|
var _loadPrepareConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
|
|
689
|
-
var _this$getCustomer2, _this$store$discount7, _this$getDiscountList, _this$store$discount8, _this$store$productLi, customerId, goodPassList, scanDiscount, scanDiscountIds, newGoodPassList, newDiscountList, filteredDiscountList, result;
|
|
695
|
+
var _this$getCustomer2, _this$store$discount7, _this$getDiscountList, _this$store$discount8, _this$store$productLi, orderId, customerId, goodPassList, scanDiscount, scanDiscountIds, newGoodPassList, newDiscountList, filteredDiscountList, result;
|
|
690
696
|
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
691
697
|
while (1) switch (_context8.prev = _context8.next) {
|
|
692
698
|
case 0:
|
|
693
699
|
_context8.prev = 0;
|
|
700
|
+
orderId = this.store.orderId;
|
|
694
701
|
customerId = params.customerId || ((_this$getCustomer2 = this.getCustomer()) === null || _this$getCustomer2 === void 0 ? void 0 : _this$getCustomer2.id); // if (customerId === 1 || !customerId) {
|
|
695
702
|
// return
|
|
696
703
|
// }
|
|
697
|
-
_context8.next =
|
|
698
|
-
return (_this$store$discount7 = this.store.discount) === null || _this$store$discount7 === void 0 ? void 0 : _this$store$discount7.loadPrepareConfig({
|
|
704
|
+
_context8.next = 5;
|
|
705
|
+
return (_this$store$discount7 = this.store.discount) === null || _this$store$discount7 === void 0 ? void 0 : _this$store$discount7.loadPrepareConfig(_objectSpread({
|
|
699
706
|
customer_id: customerId,
|
|
700
|
-
action: 'create',
|
|
707
|
+
action: orderId ? 'edit' : 'create',
|
|
701
708
|
with_good_pass: 1,
|
|
702
709
|
with_discount_card: 1,
|
|
703
710
|
with_wallet_pass_holder: 1,
|
|
704
711
|
request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
705
|
-
}
|
|
706
|
-
|
|
712
|
+
}, orderId ? {
|
|
713
|
+
order_id: orderId
|
|
714
|
+
} : {}));
|
|
715
|
+
case 5:
|
|
707
716
|
goodPassList = _context8.sent;
|
|
708
717
|
scanDiscount = (_this$getDiscountList = this.getDiscountList()) === null || _this$getDiscountList === void 0 ? void 0 : _this$getDiscountList.filter(function (item) {
|
|
709
718
|
return item.isScan;
|
|
@@ -716,35 +725,35 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
716
725
|
});
|
|
717
726
|
newDiscountList = [].concat(_toConsumableArray(scanDiscount), _toConsumableArray(newGoodPassList || [])); // 存储原始优惠券列表
|
|
718
727
|
this.store.originalDiscountList = newDiscountList;
|
|
719
|
-
_context8.next =
|
|
728
|
+
_context8.next = 13;
|
|
720
729
|
return (_this$store$discount8 = this.store.discount) === null || _this$store$discount8 === void 0 ? void 0 : _this$store$discount8.setOriginalDiscountList(newDiscountList);
|
|
721
|
-
case
|
|
730
|
+
case 13:
|
|
722
731
|
// 根据当前预约时间过滤优惠券列表
|
|
723
732
|
filteredDiscountList = this.filterDiscountListByBookingTime(newDiscountList, this.store.currentBookingTime);
|
|
724
733
|
this.store.filteredDiscountList = filteredDiscountList;
|
|
725
734
|
this.setDiscountList(filteredDiscountList || []);
|
|
726
735
|
if (!((_this$store$productLi = this.store.productList) !== null && _this$store$productLi !== void 0 && _this$store$productLi.length)) {
|
|
727
|
-
_context8.next =
|
|
736
|
+
_context8.next = 20;
|
|
728
737
|
break;
|
|
729
738
|
}
|
|
730
739
|
result = this.calcDiscount(this.store.productList);
|
|
731
|
-
_context8.next =
|
|
740
|
+
_context8.next = 20;
|
|
732
741
|
return this.core.effects.emit(ShopDiscountHooks.onLoadPrepareCalcResult, result);
|
|
733
|
-
case
|
|
734
|
-
_context8.next =
|
|
742
|
+
case 20:
|
|
743
|
+
_context8.next = 22;
|
|
735
744
|
return this.core.effects.emit(ShopDiscountHooks.onLoadDiscountList, filteredDiscountList);
|
|
736
|
-
case
|
|
737
|
-
_context8.next =
|
|
745
|
+
case 22:
|
|
746
|
+
_context8.next = 27;
|
|
738
747
|
break;
|
|
739
|
-
case
|
|
740
|
-
_context8.prev =
|
|
748
|
+
case 24:
|
|
749
|
+
_context8.prev = 24;
|
|
741
750
|
_context8.t0 = _context8["catch"](0);
|
|
742
751
|
console.error('[ShopDiscount] 加载准备配置出错:', _context8.t0);
|
|
743
|
-
case
|
|
752
|
+
case 27:
|
|
744
753
|
case "end":
|
|
745
754
|
return _context8.stop();
|
|
746
755
|
}
|
|
747
|
-
}, _callee8, this, [[0,
|
|
756
|
+
}, _callee8, this, [[0, 24]]);
|
|
748
757
|
}));
|
|
749
758
|
function loadPrepareConfig(_x8) {
|
|
750
759
|
return _loadPrepareConfig.apply(this, arguments);
|
|
@@ -261,10 +261,12 @@ var isInRepeatingSchedule = function isInRepeatingSchedule(targetDate, targetDat
|
|
|
261
261
|
|
|
262
262
|
// 每日重复逻辑
|
|
263
263
|
var isInDailyRepeat = function isInDailyRepeat(targetDate, startDate, endDate, repeatRule) {
|
|
264
|
-
|
|
265
|
-
|
|
264
|
+
// dayjs#diff 会截断不足一天的负差值;必须先比较完整时刻,避免开始日前的
|
|
265
|
+
// 当天时段被误判为第 0 天。
|
|
266
|
+
if (targetDate.isBefore(startDate)) {
|
|
266
267
|
return false;
|
|
267
268
|
}
|
|
269
|
+
var daysDiff = targetDate.diff(startDate, 'day');
|
|
268
270
|
|
|
269
271
|
// 检查频率
|
|
270
272
|
if (daysDiff % repeatRule.frequency !== 0) {
|
|
@@ -283,6 +285,10 @@ var isInDailyRepeat = function isInDailyRepeat(targetDate, startDate, endDate, r
|
|
|
283
285
|
|
|
284
286
|
// 每周重复逻辑
|
|
285
287
|
var isInWeeklyRepeat = function isInWeeklyRepeat(targetDate, startDate, endDate, repeatRule) {
|
|
288
|
+
// 同上:不足一周的负差值会被截断为 0,开始时刻前不能命中重复规则。
|
|
289
|
+
if (targetDate.isBefore(startDate)) {
|
|
290
|
+
return false;
|
|
291
|
+
}
|
|
286
292
|
var targetDayOfWeek = targetDate.day(); // 0=周日, 1=周一, ..., 6=周六
|
|
287
293
|
|
|
288
294
|
// 检查是否在指定的星期几内
|
|
@@ -292,9 +298,6 @@ var isInWeeklyRepeat = function isInWeeklyRepeat(targetDate, startDate, endDate,
|
|
|
292
298
|
|
|
293
299
|
// 计算周差
|
|
294
300
|
var weeksDiff = targetDate.diff(startDate, 'week');
|
|
295
|
-
if (weeksDiff < 0) {
|
|
296
|
-
return false;
|
|
297
|
-
}
|
|
298
301
|
|
|
299
302
|
// 检查频率
|
|
300
303
|
if (weeksDiff % repeatRule.frequency !== 0) {
|
|
@@ -1,49 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -17,12 +17,13 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
|
|
|
17
17
|
setOriginalDiscountList(originalDiscountList: Discount[]): Promise<void>;
|
|
18
18
|
getOriginalDiscountList(): Discount[];
|
|
19
19
|
loadPrepareConfig(params: {
|
|
20
|
-
action?: 'create';
|
|
20
|
+
action?: 'create' | 'edit';
|
|
21
21
|
with_good_pass: 0 | 1;
|
|
22
22
|
with_discount_card: 0 | 1;
|
|
23
23
|
customer_id: number;
|
|
24
24
|
with_wallet_pass_holder: 0 | 1;
|
|
25
25
|
request_timezone: string;
|
|
26
|
+
order_id?: number;
|
|
26
27
|
}): Promise<Discount[]>;
|
|
27
28
|
batchSearch(code: string, customerId?: number): Promise<DiscountWithReason>;
|
|
28
29
|
filterEnabledDiscountList(discountList: Discount[]): Discount[];
|
|
@@ -1382,7 +1382,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1382
1382
|
}
|
|
1383
1383
|
const ruleType = usageRules.type;
|
|
1384
1384
|
const packageScope = usageRules == null ? void 0 : usageRules.package_scope;
|
|
1385
|
-
const { type: scopeType, exclude_bundle_product_ids = [], include_bundle_product_ids = [], filter = 0 } = packageScope || {};
|
|
1385
|
+
const { type: scopeType = "product_all", exclude_bundle_product_ids = [], include_bundle_product_ids = [], filter = 0 } = packageScope || {};
|
|
1386
1386
|
const isMainProduct = flatItem.type === "main";
|
|
1387
1387
|
const isBundleItem = flatItem.type === "bundle";
|
|
1388
1388
|
if (isMainProduct) {
|
|
@@ -25,6 +25,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
25
25
|
setHolders(holders: {
|
|
26
26
|
form_record_id: number;
|
|
27
27
|
}[]): void;
|
|
28
|
+
setOrderId(id?: number): void;
|
|
28
29
|
setBookingSubject(bookingSubject: {
|
|
29
30
|
type?: 'form' | 'customer';
|
|
30
31
|
[key: string]: any;
|
|
@@ -56,7 +56,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
56
56
|
originalDiscountList: [],
|
|
57
57
|
currentBookingTime: "",
|
|
58
58
|
filteredDiscountList: [],
|
|
59
|
-
bookingSubject: void 0
|
|
59
|
+
bookingSubject: void 0,
|
|
60
|
+
orderId: void 0
|
|
60
61
|
};
|
|
61
62
|
}
|
|
62
63
|
// =========== 生命周期方法 ===========
|
|
@@ -198,6 +199,9 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
198
199
|
setHolders(holders) {
|
|
199
200
|
this.store.holders = holders;
|
|
200
201
|
}
|
|
202
|
+
setOrderId(id) {
|
|
203
|
+
this.store.orderId = id;
|
|
204
|
+
}
|
|
201
205
|
setBookingSubject(bookingSubject) {
|
|
202
206
|
this.store.bookingSubject = bookingSubject;
|
|
203
207
|
}
|
|
@@ -465,14 +469,16 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
465
469
|
async loadPrepareConfig(params) {
|
|
466
470
|
var _a, _b, _c, _d, _e;
|
|
467
471
|
try {
|
|
472
|
+
const orderId = this.store.orderId;
|
|
468
473
|
const customerId = params.customerId || ((_a = this.getCustomer()) == null ? void 0 : _a.id);
|
|
469
474
|
const goodPassList = await ((_b = this.store.discount) == null ? void 0 : _b.loadPrepareConfig({
|
|
470
475
|
customer_id: customerId,
|
|
471
|
-
action: "create",
|
|
476
|
+
action: orderId ? "edit" : "create",
|
|
472
477
|
with_good_pass: 1,
|
|
473
478
|
with_discount_card: 1,
|
|
474
479
|
with_wallet_pass_holder: 1,
|
|
475
|
-
request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
480
|
+
request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
481
|
+
...orderId ? { order_id: orderId } : {}
|
|
476
482
|
}));
|
|
477
483
|
const scanDiscount = (_c = this.getDiscountList()) == null ? void 0 : _c.filter(
|
|
478
484
|
(item) => item.isScan
|
|
@@ -183,10 +183,10 @@ var isInRepeatingSchedule = (targetDate, targetDateString, targetTimeString, sch
|
|
|
183
183
|
}
|
|
184
184
|
};
|
|
185
185
|
var isInDailyRepeat = (targetDate, startDate, endDate, repeatRule) => {
|
|
186
|
-
|
|
187
|
-
if (daysDiff < 0) {
|
|
186
|
+
if (targetDate.isBefore(startDate)) {
|
|
188
187
|
return false;
|
|
189
188
|
}
|
|
189
|
+
const daysDiff = targetDate.diff(startDate, "day");
|
|
190
190
|
if (daysDiff % repeatRule.frequency !== 0) {
|
|
191
191
|
return false;
|
|
192
192
|
}
|
|
@@ -196,14 +196,14 @@ var isInDailyRepeat = (targetDate, startDate, endDate, repeatRule) => {
|
|
|
196
196
|
return targetTimeOfDay >= startTimeOfDay && targetTimeOfDay <= endTimeOfDay;
|
|
197
197
|
};
|
|
198
198
|
var isInWeeklyRepeat = (targetDate, startDate, endDate, repeatRule) => {
|
|
199
|
+
if (targetDate.isBefore(startDate)) {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
199
202
|
const targetDayOfWeek = targetDate.day();
|
|
200
203
|
if (!repeatRule.frequency_date.includes(targetDayOfWeek)) {
|
|
201
204
|
return false;
|
|
202
205
|
}
|
|
203
206
|
const weeksDiff = targetDate.diff(startDate, "week");
|
|
204
|
-
if (weeksDiff < 0) {
|
|
205
|
-
return false;
|
|
206
|
-
}
|
|
207
207
|
if (weeksDiff % repeatRule.frequency !== 0) {
|
|
208
208
|
return false;
|
|
209
209
|
}
|