@pisell/pisellos 0.0.567 → 0.0.568
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/core/index.js +6 -9
- package/dist/model/strategy/adapter/walletPass/evaluator.js +0 -2
- package/dist/model/strategy/adapter/walletPass/example.js +3 -26
- package/dist/model/strategy/adapter/walletPass/utils.js +0 -3
- package/dist/model/strategy/strategy-example.js +5 -19
- package/dist/modules/Cart/index.js +0 -3
- package/dist/modules/Cart/utils/cartProduct.js +0 -1
- package/dist/modules/Date/index.js +1 -5
- package/dist/modules/Discount/index.js +1 -4
- package/dist/modules/OpenData/index.js +0 -2
- package/dist/modules/Order/index.d.ts +1 -1
- package/dist/modules/Order/index.js +14 -41
- package/dist/modules/Payment/index.js +142 -270
- package/dist/modules/Payment/walletpass.js +4 -5
- package/dist/modules/Rules/index.js +0 -7
- package/dist/modules/Schedule/utils.js +0 -1
- package/dist/modules/Step/index.js +0 -1
- package/dist/plugins/request.js +1 -4
- package/dist/plugins/window.js +2 -6
- package/dist/server/index.js +88 -121
- package/dist/server/modules/menu/index.js +32 -41
- package/dist/server/modules/products/index.js +29 -49
- package/dist/server/modules/quotation/index.js +29 -38
- package/dist/server/modules/resource/index.js +3 -4
- package/dist/server/modules/schedule/index.js +32 -40
- package/dist/server/utils/product.js +0 -1
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingByStep/index.js +7 -59
- package/dist/solution/BookingByStep/utils/capacity.js +1 -11
- package/dist/solution/BookingByStep/utils/resources.js +1 -3
- package/dist/solution/BookingByStep/utils/timeslots.js +2 -43
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.js +5 -7
- package/dist/solution/BookingTicket/utils/scan/handleScan.js +25 -31
- package/dist/solution/BookingTicket/utils/scan/index.js +6 -10
- package/dist/solution/BuyTickets/index.js +9 -12
- package/dist/solution/Checkout/index.js +177 -246
- package/dist/solution/Checkout/utils/index.js +4 -16
- package/dist/solution/RegisterAndLogin/index.js +30 -76
- package/dist/solution/ScanOrder/index.js +50 -60
- package/dist/solution/ShopDiscount/index.js +2 -7
- package/dist/solution/VenueBooking/index.d.ts +5 -0
- package/dist/solution/VenueBooking/index.js +364 -327
- package/dist/utils/task.js +15 -18
- package/dist/utils/watch.js +0 -1
- package/lib/apis/picoding.js +2 -0
- package/lib/core/index.js +130 -131
- package/lib/effects/index.js +46 -57
- package/lib/index.js +92 -53
- package/lib/model/index.js +14 -21
- package/lib/model/strategy/adapter/dataVariant/adapter.js +38 -50
- package/lib/model/strategy/adapter/dataVariant/evaluator.js +162 -236
- package/lib/model/strategy/adapter/dataVariant/examples.js +229 -237
- package/lib/model/strategy/adapter/dataVariant/index.js +39 -34
- package/lib/model/strategy/adapter/dataVariant/type.js +57 -28
- package/lib/model/strategy/adapter/index.js +100 -64
- package/lib/model/strategy/adapter/itemRule/adapter.js +156 -144
- package/lib/model/strategy/adapter/itemRule/evaluator.js +36 -48
- package/lib/model/strategy/adapter/itemRule/examples.js +295 -225
- package/lib/model/strategy/adapter/itemRule/index.js +83 -57
- package/lib/model/strategy/adapter/itemRule/type.js +97 -36
- package/lib/model/strategy/adapter/promotion/adapter.js +84 -63
- package/lib/model/strategy/adapter/promotion/evaluator.js +381 -231
- package/lib/model/strategy/adapter/promotion/examples.js +139 -159
- package/lib/model/strategy/adapter/promotion/index.js +1 -49
- package/lib/model/strategy/adapter/promotion/type.js +199 -35
- package/lib/model/strategy/adapter/type.js +4 -16
- package/lib/model/strategy/adapter/walletPass/evaluator.js +180 -152
- package/lib/model/strategy/adapter/walletPass/example.js +217 -190
- package/lib/model/strategy/adapter/walletPass/index.js +75 -51
- package/lib/model/strategy/adapter/walletPass/locales.js +36 -58
- package/lib/model/strategy/adapter/walletPass/type.js +4 -16
- package/lib/model/strategy/adapter/walletPass/utils.js +652 -402
- package/lib/model/strategy/engine.js +270 -168
- package/lib/model/strategy/index.js +49 -34
- package/lib/model/strategy/strategy-example.js +243 -239
- package/lib/model/strategy/type.js +100 -40
- package/lib/modules/Account/index.js +39 -53
- package/lib/modules/Account/types.js +20 -33
- package/lib/modules/AccountList/index.js +116 -154
- package/lib/modules/AccountList/types.js +30 -31
- package/lib/modules/AccountList/utils.js +18 -30
- package/lib/modules/BaseModule.js +22 -45
- package/lib/modules/Cart/index.js +170 -124
- package/lib/modules/Cart/types.js +46 -51
- package/lib/modules/Cart/utils/cartAccount.js +40 -39
- package/lib/modules/Cart/utils/cartDate.js +56 -61
- package/lib/modules/Cart/utils/cartDiscount.js +28 -33
- package/lib/modules/Cart/utils/cartNote.js +27 -32
- package/lib/modules/Cart/utils/cartProduct.js +306 -241
- package/lib/modules/Cart/utils/cartRelationForms.js +29 -35
- package/lib/modules/Cart/utils/cartResource.js +72 -78
- package/lib/modules/Cart/utils/changePrice.js +26 -62
- package/lib/modules/Cart/utils/index.js +106 -48
- package/lib/modules/Customer/constants.js +13 -34
- package/lib/modules/Customer/index.js +216 -153
- package/lib/modules/Customer/types.js +38 -35
- package/lib/modules/Date/index.js +116 -115
- package/lib/modules/Date/types.js +16 -28
- package/lib/modules/Date/utils.js +174 -123
- package/lib/modules/Discount/index.js +117 -113
- package/lib/modules/Discount/types.js +9 -31
- package/lib/modules/Guests/index.js +30 -56
- package/lib/modules/Guests/types.js +23 -33
- package/lib/modules/Holder/index.js +209 -189
- package/lib/modules/Holder/types.js +4 -16
- package/lib/modules/Holder/utils.js +20 -49
- package/lib/modules/OpenData/index.js +63 -74
- package/lib/modules/OpenData/types.js +4 -16
- package/lib/modules/OpenData/utils.js +44 -78
- package/lib/modules/Order/index.d.ts +1 -1
- package/lib/modules/Order/index.js +332 -320
- package/lib/modules/Order/types.js +24 -33
- package/lib/modules/Order/utils.js +350 -284
- package/lib/modules/Payment/cash.js +20 -33
- package/lib/modules/Payment/cashRecommendationAlgorithm.js +145 -76
- package/lib/modules/Payment/eftpos.js +16 -30
- package/lib/modules/Payment/index.js +566 -432
- package/lib/modules/Payment/mx51.js +1 -0
- package/lib/modules/Payment/types.js +216 -107
- package/lib/modules/Payment/utils.js +50 -47
- package/lib/modules/Payment/walletpass.js +221 -203
- package/lib/modules/Product/index.js +51 -46
- package/lib/modules/Product/types.js +4 -16
- package/lib/modules/Product/utils.js +32 -33
- package/lib/modules/ProductList/index.js +111 -110
- package/lib/modules/ProductList/types.js +9 -31
- package/lib/modules/Quotation/index.js +60 -82
- package/lib/modules/Quotation/types.js +4 -16
- package/lib/modules/Resource/index.js +27 -59
- package/lib/modules/Resource/types.js +22 -32
- package/lib/modules/Resource/utils.js +30 -38
- package/lib/modules/Rules/index.js +1172 -872
- package/lib/modules/Rules/types.js +17 -40
- package/lib/modules/SalesSummary/index.js +59 -68
- package/lib/modules/SalesSummary/types.js +4 -16
- package/lib/modules/SalesSummary/utils.js +176 -193
- package/lib/modules/ScanOrderLogger/index.js +59 -79
- package/lib/modules/ScanOrderLogger/providers/feishu.js +54 -78
- package/lib/modules/ScanOrderLogger/providers/grafana.js +13 -36
- package/lib/modules/ScanOrderLogger/types.js +4 -16
- package/lib/modules/Schedule/getDateIsInSchedule.js +334 -167
- package/lib/modules/Schedule/index.js +97 -107
- package/lib/modules/Schedule/type.js +4 -16
- package/lib/modules/Schedule/types.js +4 -16
- package/lib/modules/Schedule/utils.js +433 -291
- package/lib/modules/Step/index.js +40 -52
- package/lib/modules/Step/tyeps.js +4 -16
- package/lib/modules/Summary/index.js +66 -70
- package/lib/modules/Summary/types.js +4 -16
- package/lib/modules/Summary/utils.js +782 -429
- package/lib/modules/index.js +212 -57
- package/lib/plugins/app.js +4 -16
- package/lib/plugins/index.js +36 -25
- package/lib/plugins/request.js +137 -126
- package/lib/plugins/shopStore.js +4 -16
- package/lib/plugins/user.js +4 -16
- package/lib/plugins/window.js +171 -179
- package/lib/server/index.js +882 -623
- package/lib/server/modules/index.js +85 -59
- package/lib/server/modules/menu/index.js +146 -122
- package/lib/server/modules/menu/types.js +18 -31
- package/lib/server/modules/order/index.js +195 -231
- package/lib/server/modules/order/types.js +107 -32
- package/lib/server/modules/order/utils/filterBookings.js +174 -140
- package/lib/server/modules/order/utils/filterOrders.js +89 -60
- package/lib/server/modules/products/index.js +430 -335
- package/lib/server/modules/products/types.js +41 -34
- package/lib/server/modules/quotation/index.js +76 -77
- package/lib/server/modules/quotation/types.js +21 -31
- package/lib/server/modules/resource/index.js +216 -187
- package/lib/server/modules/resource/types.js +42 -33
- package/lib/server/modules/schedule/index.js +134 -119
- package/lib/server/modules/schedule/types.js +14 -21
- package/lib/server/modules/schedule/utils.js +334 -163
- package/lib/server/types.js +4 -16
- package/lib/server/utils/index.js +25 -23
- package/lib/server/utils/product.js +196 -139
- package/lib/server/utils/schedule.js +34 -41
- package/lib/server/utils/time.js +40 -49
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingByStep/index.js +1530 -1343
- package/lib/solution/BookingByStep/types.js +40 -99
- package/lib/solution/BookingByStep/utils/capacity.js +192 -160
- package/lib/solution/BookingByStep/utils/products.js +42 -52
- package/lib/solution/BookingByStep/utils/resources.js +527 -330
- package/lib/solution/BookingByStep/utils/stock.js +65 -44
- package/lib/solution/BookingByStep/utils/timeslots.js +129 -131
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.js +147 -122
- package/lib/solution/BookingTicket/types.js +38 -64
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +64 -80
- package/lib/solution/BookingTicket/utils/scan/handleScan.js +82 -80
- package/lib/solution/BookingTicket/utils/scan/index.js +90 -94
- package/lib/solution/BookingTicket/utils/scan/scanCache.js +90 -43
- package/lib/solution/BuyTickets/index.js +67 -70
- package/lib/solution/BuyTickets/types.js +22 -38
- package/lib/solution/Checkout/index.js +1451 -1158
- package/lib/solution/Checkout/types.js +91 -61
- package/lib/solution/Checkout/utils/index.js +227 -158
- package/lib/solution/PlaceOrder/index.js +55 -0
- package/lib/solution/RegisterAndLogin/config.js +493 -460
- package/lib/solution/RegisterAndLogin/index.js +633 -630
- package/lib/solution/RegisterAndLogin/types.js +189 -76
- package/lib/solution/RegisterAndLogin/utils.js +183 -125
- package/lib/solution/Sales/index.js +218 -200
- package/lib/solution/Sales/types.js +27 -33
- package/lib/solution/ScanOrder/index.js +803 -840
- package/lib/solution/ScanOrder/types.js +34 -34
- package/lib/solution/ScanOrder/utils.js +372 -331
- package/lib/solution/ShopDiscount/index.js +230 -236
- package/lib/solution/ShopDiscount/types.js +15 -37
- package/lib/solution/ShopDiscount/utils.js +309 -172
- package/lib/solution/VenueBooking/index.d.ts +5 -0
- package/lib/solution/VenueBooking/index.js +886 -929
- package/lib/solution/VenueBooking/types.js +20 -40
- package/lib/solution/VenueBooking/utils/dateSummary.js +22 -54
- package/lib/solution/VenueBooking/utils/resource.js +31 -54
- package/lib/solution/VenueBooking/utils/slotMerge.js +88 -106
- package/lib/solution/VenueBooking/utils/smartPricing.js +112 -100
- package/lib/solution/VenueBooking/utils/timeSlot.js +133 -132
- package/lib/solution/VenueBooking/utils.js +130 -67
- package/lib/solution/index.js +102 -37
- package/lib/store/createStore.js +32 -29
- package/lib/types/index.js +4 -16
- package/lib/utils/task.js +36 -36
- package/lib/utils/watch.js +81 -47
- package/package.json +2 -1
|
@@ -1,52 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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/solution/ShopDiscount/index.ts
|
|
30
|
-
var ShopDiscount_exports = {};
|
|
31
|
-
__export(ShopDiscount_exports, {
|
|
32
|
-
ShopDiscountImpl: () => ShopDiscountImpl,
|
|
33
|
-
default: () => ShopDiscount_default
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
34
5
|
});
|
|
35
|
-
|
|
36
|
-
var
|
|
37
|
-
var
|
|
38
|
-
var
|
|
39
|
-
var
|
|
40
|
-
var
|
|
41
|
-
var
|
|
42
|
-
var
|
|
43
|
-
|
|
6
|
+
exports.default = exports.ShopDiscountImpl = void 0;
|
|
7
|
+
var _BaseModule = require("../../modules/BaseModule");
|
|
8
|
+
var _Discount = require("../../modules/Discount");
|
|
9
|
+
var _Rules = require("../../modules/Rules");
|
|
10
|
+
var _utils = require("./utils");
|
|
11
|
+
var _types = require("../../modules/Rules/types");
|
|
12
|
+
var _decimal = _interopRequireDefault(require("decimal.js"));
|
|
13
|
+
var _lodashEs = require("lodash-es");
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
class ShopDiscountImpl extends _BaseModule.BaseModule {
|
|
16
|
+
defaultName = 'shopDiscount';
|
|
17
|
+
defaultVersion = '1.0.0';
|
|
18
|
+
isSolution = true;
|
|
19
|
+
request;
|
|
20
|
+
window;
|
|
21
|
+
store;
|
|
22
|
+
options = {};
|
|
23
|
+
hooks;
|
|
44
24
|
constructor(name, version) {
|
|
45
25
|
super(name, version);
|
|
46
|
-
|
|
47
|
-
this.defaultVersion = "1.0.0";
|
|
48
|
-
this.isSolution = true;
|
|
49
|
-
this.options = {};
|
|
26
|
+
// 初始化所有必要的状态属性
|
|
50
27
|
this.store = {
|
|
51
28
|
customer: null,
|
|
52
29
|
productList: [],
|
|
@@ -57,96 +34,104 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
57
34
|
filteredDiscountList: [],
|
|
58
35
|
orderTotalAmount: 0,
|
|
59
36
|
holders: [],
|
|
60
|
-
bookingSubject:
|
|
61
|
-
orderId:
|
|
37
|
+
bookingSubject: undefined,
|
|
38
|
+
orderId: undefined
|
|
62
39
|
};
|
|
63
40
|
}
|
|
41
|
+
|
|
64
42
|
// =========== 生命周期方法 ===========
|
|
43
|
+
|
|
65
44
|
async initialize(core, options) {
|
|
66
|
-
var _a, _b;
|
|
67
45
|
this.core = core;
|
|
68
46
|
this.options = options;
|
|
69
|
-
this.store = {
|
|
70
|
-
|
|
71
|
-
|
|
47
|
+
this.store = {
|
|
48
|
+
...this.store,
|
|
49
|
+
...(options.store || {})
|
|
50
|
+
};
|
|
51
|
+
this.hooks = options.otherParams?.rules?.hooks;
|
|
52
|
+
// 获取依赖的插件
|
|
72
53
|
this.initializePlugins();
|
|
54
|
+
|
|
55
|
+
// 注册依赖模块
|
|
73
56
|
this.registerDependentModules();
|
|
57
|
+
|
|
58
|
+
// 注册事件监听
|
|
74
59
|
this.registerEventListeners();
|
|
75
60
|
}
|
|
76
61
|
async destroy() {
|
|
77
|
-
var _a, _b;
|
|
78
62
|
this.store.productList = [];
|
|
79
63
|
this.store.customer = null;
|
|
80
|
-
|
|
81
|
-
|
|
64
|
+
this.store.discount?.destroy();
|
|
65
|
+
this.store.rules?.destroy();
|
|
82
66
|
this.core.effects.offByModuleDestroy(this.name);
|
|
83
67
|
await this.core.effects.emit(`${this.name}:onDestroy`, {});
|
|
84
|
-
console.log("[ShopDiscount] 已销毁");
|
|
85
68
|
}
|
|
86
69
|
async clear() {
|
|
87
|
-
var _a, _b;
|
|
88
70
|
this.store.productList = [];
|
|
89
71
|
this.store.customer = null;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
console.log("[ShopDiscount] clear");
|
|
72
|
+
this.store.discount?.clear();
|
|
73
|
+
this.store.rules?.clear();
|
|
93
74
|
}
|
|
75
|
+
|
|
94
76
|
// =========== 初始化辅助方法 ===========
|
|
77
|
+
|
|
95
78
|
initializePlugins() {
|
|
96
|
-
this.request = this.core.getPlugin(
|
|
97
|
-
this.window = this.core.getPlugin(
|
|
79
|
+
this.request = this.core.getPlugin('request');
|
|
80
|
+
this.window = this.core.getPlugin('window');
|
|
98
81
|
if (!this.request) {
|
|
99
|
-
throw new Error(
|
|
82
|
+
throw new Error('ShopDiscount需要 request 插件支持');
|
|
100
83
|
}
|
|
101
84
|
if (!this.window) {
|
|
102
|
-
throw new Error(
|
|
85
|
+
throw new Error('ShopDiscount需要 window 插件支持');
|
|
103
86
|
}
|
|
104
87
|
}
|
|
105
88
|
registerDependentModules() {
|
|
106
|
-
|
|
89
|
+
// 如果有传 cacheid,默认需要收集上面这些模块里用户操作选中的数据
|
|
90
|
+
// 并且在上面 registerModule 的时候,读取 sessionStroage 里的数据,塞进默认值
|
|
107
91
|
let targetCacheData = {};
|
|
108
|
-
if (
|
|
92
|
+
if (this.options.otherParams?.cacheId) {
|
|
109
93
|
const sessionData = this.window.sessionStorage.getItem(this.name);
|
|
110
94
|
if (sessionData) {
|
|
111
95
|
const data = JSON.parse(sessionData);
|
|
112
96
|
targetCacheData = data[this.options.otherParams.cacheId];
|
|
113
97
|
}
|
|
114
98
|
}
|
|
115
|
-
|
|
99
|
+
// 注册优惠模块
|
|
100
|
+
const discount = new _Discount.DiscountModule(`${this.name}_discount`);
|
|
116
101
|
this.core.registerModule(discount, {
|
|
117
|
-
initialState: targetCacheData
|
|
118
|
-
hooks:
|
|
102
|
+
initialState: targetCacheData?.[discount.name],
|
|
103
|
+
hooks: this.options.otherParams?.discount?.hooks,
|
|
119
104
|
otherParams: {
|
|
120
105
|
fatherModule: this.name,
|
|
121
|
-
openCache:
|
|
122
|
-
cacheId:
|
|
106
|
+
openCache: this.options.otherParams?.cacheId ? true : false,
|
|
107
|
+
cacheId: this.options.otherParams?.cacheId
|
|
123
108
|
}
|
|
124
109
|
});
|
|
125
110
|
this.store.discount = discount;
|
|
126
|
-
|
|
111
|
+
|
|
112
|
+
// 注册规则模块
|
|
113
|
+
const rules = new _Rules.RulesModule(`${this.name}_rules`);
|
|
127
114
|
this.core.registerModule(rules, {
|
|
128
|
-
hooks:
|
|
115
|
+
hooks: this.options.otherParams?.rules?.hooks
|
|
129
116
|
});
|
|
130
117
|
this.store.rules = rules;
|
|
131
118
|
}
|
|
132
119
|
registerEventListeners() {
|
|
133
|
-
this.core.effects.only(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
var _a;
|
|
137
|
-
if (((_a = this.options.otherParams) == null ? void 0 : _a.cacheId) && this.getDiscountList().length) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
this.loadPrepareConfig({
|
|
141
|
-
customerId: customer.id,
|
|
142
|
-
action: "create",
|
|
143
|
-
with_good_pass: 1,
|
|
144
|
-
with_discount_card: 1
|
|
145
|
-
});
|
|
120
|
+
this.core.effects.only(`${this.name}:onCustomerChange`, customer => {
|
|
121
|
+
if (this.options.otherParams?.cacheId && this.getDiscountList().length) {
|
|
122
|
+
return;
|
|
146
123
|
}
|
|
147
|
-
|
|
124
|
+
this.loadPrepareConfig({
|
|
125
|
+
customerId: customer.id,
|
|
126
|
+
action: 'create',
|
|
127
|
+
with_good_pass: 1,
|
|
128
|
+
with_discount_card: 1
|
|
129
|
+
});
|
|
130
|
+
});
|
|
148
131
|
}
|
|
132
|
+
|
|
149
133
|
// =========== 公共 API ===========
|
|
134
|
+
|
|
150
135
|
// 设置预约时间
|
|
151
136
|
// public async setBookingTime(bookingTime: string | null): Promise<void> {
|
|
152
137
|
// if (this.store.currentBookingTime !== bookingTime) {
|
|
@@ -156,17 +141,23 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
156
141
|
// await this.updateFilteredDiscountList();
|
|
157
142
|
// }
|
|
158
143
|
// }
|
|
144
|
+
|
|
159
145
|
// 获取当前预约时间
|
|
160
146
|
getCurrentBookingTime() {
|
|
161
147
|
return this.store.currentBookingTime;
|
|
162
148
|
}
|
|
149
|
+
|
|
163
150
|
// 根据预约时间过滤优惠券列表
|
|
164
151
|
filterDiscountListByBookingTime(discountList, bookingTime) {
|
|
165
|
-
|
|
152
|
+
// 如果全部是普通商品,不需要过滤,直接返回当前数据
|
|
153
|
+
if ((0, _utils.isAllNormalProduct)(this.store.productList || [])) {
|
|
166
154
|
return discountList;
|
|
167
155
|
}
|
|
168
|
-
|
|
156
|
+
|
|
157
|
+
// 否则使用 bookingTime 进行过滤
|
|
158
|
+
return (0, _utils.filterDiscountListByBookingTime)(discountList, bookingTime);
|
|
169
159
|
}
|
|
160
|
+
|
|
170
161
|
// 更新过滤后的优惠券列表
|
|
171
162
|
// private async updateFilteredDiscountList(): Promise<void> {
|
|
172
163
|
// const originalList = this.store.originalDiscountList;
|
|
@@ -185,20 +176,18 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
185
176
|
// );
|
|
186
177
|
// }
|
|
187
178
|
// }
|
|
179
|
+
|
|
188
180
|
// 设置客户
|
|
189
181
|
async setCustomer(customer) {
|
|
190
|
-
|
|
191
|
-
if (((_a = this.store.customer) == null ? void 0 : _a.id) !== customer.id) {
|
|
182
|
+
if (this.store.customer?.id !== customer.id) {
|
|
192
183
|
this.store.customer = customer;
|
|
193
|
-
await this.core.effects.emit(
|
|
194
|
-
`${this.name}:onCustomerChange`,
|
|
195
|
-
customer
|
|
196
|
-
);
|
|
184
|
+
await this.core.effects.emit(`${this.name}:onCustomerChange`, customer);
|
|
197
185
|
}
|
|
198
186
|
}
|
|
199
187
|
setOriginTotalAmount(amount) {
|
|
200
188
|
this.store.orderTotalAmount = amount;
|
|
201
189
|
}
|
|
190
|
+
|
|
202
191
|
// 设置holders
|
|
203
192
|
setHolders(holders) {
|
|
204
193
|
this.store.holders = holders;
|
|
@@ -209,24 +198,30 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
209
198
|
setOrderId(id) {
|
|
210
199
|
this.store.orderId = id;
|
|
211
200
|
}
|
|
201
|
+
|
|
212
202
|
// 计算优惠券
|
|
213
203
|
calcDiscount(productList, options) {
|
|
214
|
-
var _a;
|
|
215
204
|
this.store.productList = productList;
|
|
216
205
|
const rulesModule = this.core.getModule(`${this.name}_rules`);
|
|
217
206
|
if (!rulesModule) {
|
|
218
|
-
return {
|
|
219
|
-
}
|
|
220
|
-
let { productList: newProductList, discountList: newDiscountList } = rulesModule.calcDiscount(
|
|
221
|
-
{
|
|
207
|
+
return {
|
|
222
208
|
productList,
|
|
223
|
-
discountList: this.getDiscountList()
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
209
|
+
discountList: this.getDiscountList()
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
let {
|
|
213
|
+
productList: newProductList,
|
|
214
|
+
discountList: newDiscountList
|
|
215
|
+
} = rulesModule.calcDiscount({
|
|
216
|
+
productList,
|
|
217
|
+
discountList: this.getDiscountList(),
|
|
218
|
+
orderTotalAmount: this.store.orderTotalAmount || 0,
|
|
219
|
+
holders: this.store.holders || [],
|
|
220
|
+
isFormSubject: this.store.bookingSubject?.type === 'form'
|
|
221
|
+
}, options) || {
|
|
222
|
+
productList,
|
|
223
|
+
discountList: this.getDiscountList()
|
|
224
|
+
};
|
|
230
225
|
if (newDiscountList) {
|
|
231
226
|
newDiscountList = this.setDiscountList(newDiscountList);
|
|
232
227
|
}
|
|
@@ -235,24 +230,35 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
235
230
|
discountList: newDiscountList || this.getDiscountList()
|
|
236
231
|
};
|
|
237
232
|
}
|
|
233
|
+
|
|
238
234
|
// 设置优惠券使用状态
|
|
239
235
|
setDiscountSelected(params) {
|
|
236
|
+
// 获取当前优惠券列表
|
|
240
237
|
const discountList = this.getDiscountList();
|
|
238
|
+
|
|
239
|
+
// 构建选择操作列表
|
|
241
240
|
const selectionOperations = [];
|
|
241
|
+
|
|
242
|
+
// 主要操作
|
|
242
243
|
selectionOperations.push({
|
|
243
244
|
discountId: params.discountId,
|
|
244
245
|
isSelected: params.isSelected
|
|
245
246
|
});
|
|
247
|
+
|
|
248
|
+
// 如果有批量操作列表,添加到操作列表中
|
|
246
249
|
if (params.selectedList && params.selectedList.length > 0) {
|
|
247
250
|
selectionOperations.push(...params.selectedList);
|
|
248
251
|
}
|
|
249
|
-
|
|
250
|
-
|
|
252
|
+
|
|
253
|
+
// 创建选择状态映射(去重处理,后面的操作会覆盖前面的)
|
|
254
|
+
const selectionMap = new Map();
|
|
255
|
+
selectionOperations.forEach(operation => {
|
|
251
256
|
selectionMap.set(operation.discountId, operation.isSelected);
|
|
252
257
|
});
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
258
|
+
|
|
259
|
+
// 找到需要修改状态的优惠券
|
|
260
|
+
const newDiscountList = discountList.map(discount => {
|
|
261
|
+
if (discount.isEditMode) return discount;
|
|
256
262
|
if (selectionMap.has(discount.id)) {
|
|
257
263
|
const targetIsSelected = selectionMap.get(discount.id);
|
|
258
264
|
return {
|
|
@@ -262,8 +268,13 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
262
268
|
isManualSelect: !targetIsSelected
|
|
263
269
|
};
|
|
264
270
|
}
|
|
265
|
-
return {
|
|
271
|
+
return {
|
|
272
|
+
...discount,
|
|
273
|
+
isManualSelect: !discount?.isSelected
|
|
274
|
+
};
|
|
266
275
|
});
|
|
276
|
+
|
|
277
|
+
// 更新优惠券列表
|
|
267
278
|
this.setDiscountList(newDiscountList);
|
|
268
279
|
return this.calcDiscount(this.store.productList || [], params);
|
|
269
280
|
}
|
|
@@ -271,9 +282,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
271
282
|
this.store.productList = productList;
|
|
272
283
|
}
|
|
273
284
|
async batchSearchByProductIds(productIds) {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
resultDiscountList = resultDiscountList.map((item) => {
|
|
285
|
+
let resultDiscountList = (await this.store.discount?.batchSearchByProductIds(productIds)) || [];
|
|
286
|
+
resultDiscountList = resultDiscountList.map(item => {
|
|
277
287
|
return {
|
|
278
288
|
...item,
|
|
279
289
|
discount_rule_uncheck_flag: true
|
|
@@ -284,12 +294,21 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
284
294
|
this.setDiscountList(newDiscountList);
|
|
285
295
|
return newDiscountList;
|
|
286
296
|
}
|
|
297
|
+
|
|
287
298
|
// 扫码输入code
|
|
288
299
|
async scanCode(code, customerId) {
|
|
289
|
-
var _a, _b, _c;
|
|
290
300
|
try {
|
|
291
|
-
const resultDiscountWithReason = await
|
|
292
|
-
|
|
301
|
+
const resultDiscountWithReason = (await this.store.discount?.batchSearch(code, {
|
|
302
|
+
customerId,
|
|
303
|
+
orderId: this.store.orderId
|
|
304
|
+
})) || {
|
|
305
|
+
discountList: [],
|
|
306
|
+
unavailableReasonKey: null
|
|
307
|
+
};
|
|
308
|
+
const {
|
|
309
|
+
discountList: resultDiscountList,
|
|
310
|
+
unavailableReasonKey
|
|
311
|
+
} = resultDiscountWithReason;
|
|
293
312
|
const rulesModule = this.store.rules;
|
|
294
313
|
if (!rulesModule) {
|
|
295
314
|
return {
|
|
@@ -297,7 +316,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
297
316
|
isAvailable: false,
|
|
298
317
|
productList: this.store.productList || [],
|
|
299
318
|
discountList: this.getDiscountList(),
|
|
300
|
-
unavailableReason:
|
|
319
|
+
unavailableReason: _types.UnavailableReason.Unknown
|
|
301
320
|
};
|
|
302
321
|
}
|
|
303
322
|
if (!resultDiscountList.length) {
|
|
@@ -309,14 +328,15 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
309
328
|
unavailableReasonKey
|
|
310
329
|
};
|
|
311
330
|
}
|
|
312
|
-
const withScanList = resultDiscountList.map(
|
|
331
|
+
const withScanList = resultDiscountList.map(item => {
|
|
313
332
|
return {
|
|
314
333
|
...item,
|
|
315
334
|
isScan: true
|
|
316
335
|
};
|
|
317
336
|
});
|
|
318
|
-
|
|
319
|
-
|
|
337
|
+
// 如果扫回来的券当前有选中的,则不进行计算
|
|
338
|
+
const currentSelectedDiscountList = this.getDiscountList().filter(n => n.isSelected);
|
|
339
|
+
if (currentSelectedDiscountList.length && currentSelectedDiscountList.some(n => withScanList.some(m => m.id === n.id))) {
|
|
320
340
|
return {
|
|
321
341
|
type: "clientCalc",
|
|
322
342
|
isAvailable: true,
|
|
@@ -334,7 +354,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
334
354
|
oldDiscountList: this.getDiscountList(),
|
|
335
355
|
newDiscountList: withScanList,
|
|
336
356
|
holders: this.store.holders || [],
|
|
337
|
-
isFormSubject:
|
|
357
|
+
isFormSubject: this.store.bookingSubject?.type === 'form',
|
|
338
358
|
orderTotalAmount: this.store.orderTotalAmount || 0
|
|
339
359
|
}) || {
|
|
340
360
|
isAvailable: false,
|
|
@@ -345,10 +365,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
345
365
|
this.setDiscountList(newDiscountList || []);
|
|
346
366
|
this.store.originalDiscountList = newDiscountList || [];
|
|
347
367
|
this.setProductList(newProductList || []);
|
|
348
|
-
if (this.isWalkIn() && resultDiscountList.length &&
|
|
349
|
-
await this.getCustomerWallet(
|
|
350
|
-
resultDiscountList[0].customer_id
|
|
351
|
-
);
|
|
368
|
+
if (this.isWalkIn() && resultDiscountList.length && this.options.otherParams?.platform === 'shop') {
|
|
369
|
+
await this.getCustomerWallet(resultDiscountList[0].customer_id);
|
|
352
370
|
}
|
|
353
371
|
}
|
|
354
372
|
return {
|
|
@@ -359,64 +377,56 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
359
377
|
unavailableReason
|
|
360
378
|
};
|
|
361
379
|
} catch (error) {
|
|
362
|
-
console.error(
|
|
380
|
+
console.error('[ShopDiscount] 扫码出错:', error);
|
|
363
381
|
return {
|
|
364
382
|
type: "clientCalc",
|
|
365
383
|
isAvailable: false,
|
|
366
384
|
productList: this.store.productList || [],
|
|
367
385
|
discountList: this.getDiscountList(),
|
|
368
|
-
unavailableReason:
|
|
386
|
+
unavailableReason: _types.UnavailableReason.Unknown
|
|
369
387
|
};
|
|
370
388
|
}
|
|
371
389
|
}
|
|
372
390
|
calcDiscountApplicableProductTotalPrice(discount) {
|
|
373
|
-
|
|
374
|
-
return (_a = this.store.discount) == null ? void 0 : _a.calcDiscountApplicableProductTotalPrice(
|
|
375
|
-
discount
|
|
376
|
-
);
|
|
391
|
+
return this.store.discount?.calcDiscountApplicableProductTotalPrice(discount);
|
|
377
392
|
}
|
|
393
|
+
|
|
378
394
|
// =========== 私有辅助方法 ===========
|
|
395
|
+
|
|
379
396
|
// 获取客户
|
|
380
397
|
getCustomer() {
|
|
381
398
|
return this.store.customer;
|
|
382
399
|
}
|
|
400
|
+
|
|
383
401
|
// 是否是walkIn
|
|
384
402
|
isWalkIn() {
|
|
385
|
-
|
|
386
|
-
return (((_a = this.getCustomer()) == null ? void 0 : _a.id) || 1) === 1;
|
|
403
|
+
return (this.getCustomer()?.id || 1) === 1;
|
|
387
404
|
}
|
|
405
|
+
|
|
388
406
|
// 触发优惠列表变更事件
|
|
389
407
|
async emitDiscountListChange(discountList) {
|
|
390
|
-
await this.core.effects.emit(
|
|
391
|
-
`${this.name}:onDiscountListChange`,
|
|
392
|
-
discountList
|
|
393
|
-
);
|
|
408
|
+
await this.core.effects.emit(`${this.name}:onDiscountListChange`, discountList);
|
|
394
409
|
}
|
|
410
|
+
|
|
395
411
|
// 设置优惠券列表
|
|
396
412
|
setDiscountList(discountList) {
|
|
397
|
-
var _a;
|
|
398
413
|
const productList = this.store.productList || [];
|
|
399
414
|
const editModeDiscountList = [];
|
|
400
|
-
productList.forEach(
|
|
401
|
-
var _a2;
|
|
415
|
+
productList.forEach(item => {
|
|
402
416
|
if (item.booking_id) {
|
|
403
|
-
const product =
|
|
404
|
-
(item.discount_list || []).forEach(
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
const index = editModeDiscountList.findIndex((n) => {
|
|
408
|
-
var _a4;
|
|
409
|
-
return n.id === (((_a4 = discount.discount) == null ? void 0 : _a4.resource_id) || discount.id);
|
|
410
|
-
});
|
|
417
|
+
const product = this.hooks?.getProduct(item);
|
|
418
|
+
(item.discount_list || []).forEach(discount => {
|
|
419
|
+
if (discount.id && ['good_pass', 'discount_card'].includes(discount.type)) {
|
|
420
|
+
const index = editModeDiscountList.findIndex(n => n.id === (discount.discount?.resource_id || discount.id));
|
|
411
421
|
if (index !== -1) {
|
|
412
422
|
editModeDiscountList[index] = {
|
|
413
423
|
...editModeDiscountList[index],
|
|
414
424
|
metadata: {
|
|
415
|
-
...discount.metadata || {},
|
|
416
|
-
num: (
|
|
425
|
+
...(discount.metadata || {}),
|
|
426
|
+
num: (editModeDiscountList?.[index]?.metadata?.num || 1) + (discount.metadata?.num || 1)
|
|
417
427
|
},
|
|
418
|
-
amount: new
|
|
419
|
-
savedAmount: new
|
|
428
|
+
amount: new _decimal.default(discount.amount || 0).plus(new _decimal.default(editModeDiscountList[index].amount || 0)).toNumber(),
|
|
429
|
+
savedAmount: new _decimal.default(discount.amount || 0).times(product?.quantity || product?.num || 1).plus(discount?.metadata?.product_discount_difference || 0).plus(new _decimal.default(editModeDiscountList[index].savedAmount || 0)).toNumber()
|
|
420
430
|
};
|
|
421
431
|
} else {
|
|
422
432
|
if (discount.type && !discount.tag) {
|
|
@@ -425,50 +435,40 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
425
435
|
editModeDiscountList.push({
|
|
426
436
|
...discount,
|
|
427
437
|
metadata: {
|
|
428
|
-
...discount.metadata || {},
|
|
429
|
-
num:
|
|
438
|
+
...(discount.metadata || {}),
|
|
439
|
+
num: discount.metadata?.num || 1
|
|
430
440
|
},
|
|
431
441
|
name: discount.name || discount.discount.title.auto,
|
|
432
442
|
isEditMode: true,
|
|
433
443
|
limited_relation_product_data: {},
|
|
434
|
-
savedAmount: new
|
|
444
|
+
savedAmount: new _decimal.default(discount.amount || 0).times(product?.quantity || product?.num || 1).plus(discount?.metadata?.product_discount_difference || 0).toNumber(),
|
|
435
445
|
isAvailable: true,
|
|
436
|
-
id:
|
|
437
|
-
format_title:
|
|
446
|
+
id: discount.discount?.resource_id || discount.id,
|
|
447
|
+
format_title: discount.discount?.title || discount.format_title,
|
|
438
448
|
isDisabled: true,
|
|
439
449
|
isSelected: true,
|
|
440
|
-
product_id:
|
|
450
|
+
product_id: discount.discount?.product_id || discount.product_id
|
|
441
451
|
});
|
|
442
452
|
}
|
|
443
453
|
}
|
|
444
454
|
});
|
|
445
455
|
}
|
|
446
456
|
});
|
|
447
|
-
const newDiscountList = [
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
return false;
|
|
456
|
-
const product = (_a2 = this.hooks) == null ? void 0 : _a2.getProduct(targetProduct);
|
|
457
|
-
return Number(product == null ? void 0 : product.total) <= 0 && (Number(product == null ? void 0 : product.origin_total) <= 0 || !(product == null ? void 0 : product.origin_total)) || (0, import_lodash_es.isBoolean)(product == null ? void 0 : product.vouchersApplicable) && !(product == null ? void 0 : product.vouchersApplicable);
|
|
457
|
+
const newDiscountList = [...editModeDiscountList, ...discountList.filter(item => !item.isDisabled)];
|
|
458
|
+
const isProductFree = id => {
|
|
459
|
+
const targetProduct = productList.find(n => n.id === id);
|
|
460
|
+
if (!targetProduct) return false;
|
|
461
|
+
const product = this.hooks?.getProduct(targetProduct);
|
|
462
|
+
// 如果 product.total 是小于等于0有可能是她已经用过商品券或者折扣卡导致的,或者本身就是负数价格,所以此时还需要判断 origin_total 是否小于等于0
|
|
463
|
+
// 如果 product.vouchersApplicable是布尔值,并且是 false,也当做免费商品处理,此商品不可用优惠券或折扣卡
|
|
464
|
+
return Number(product?.total) <= 0 && (Number(product?.origin_total) <= 0 || !product?.origin_total) || (0, _lodashEs.isBoolean)(product?.vouchersApplicable) && !product?.vouchersApplicable;
|
|
458
465
|
};
|
|
459
|
-
const allUsedProductIds = newDiscountList.filter(
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
}).flat();
|
|
466
|
-
newDiscountList.forEach((item) => {
|
|
467
|
-
var _a2;
|
|
468
|
-
const isAllProductUsedOrFree = (_a2 = item.applicableProductIds) == null ? void 0 : _a2.every((id) => {
|
|
469
|
-
var _a3;
|
|
470
|
-
const sameIdTimes = ((_a3 = item.applicableProductIds) == null ? void 0 : _a3.filter((n) => n === id).length) || 1;
|
|
471
|
-
const targetIdTimes = (allUsedProductIds == null ? void 0 : allUsedProductIds.filter((n) => n === id).length) || 0;
|
|
466
|
+
const allUsedProductIds = newDiscountList.filter(item => !item?.isEditMode).map(n => n.isSelected ? n.appliedProductDetails?.map(n => n.discount?.product_id) || n.product_id : []).flat();
|
|
467
|
+
newDiscountList.forEach(item => {
|
|
468
|
+
const isAllProductUsedOrFree = item.applicableProductIds?.every(id => {
|
|
469
|
+
// 检查当前 id是否在 item.applicableProductIds 里出现了几次,且要求次数和 item.applicableProductIds 里出现的次数一致
|
|
470
|
+
const sameIdTimes = item.applicableProductIds?.filter(n => n === id).length || 1;
|
|
471
|
+
const targetIdTimes = allUsedProductIds?.filter(n => n === id).length || 0;
|
|
472
472
|
return targetIdTimes >= sameIdTimes || isProductFree(id);
|
|
473
473
|
});
|
|
474
474
|
if (!item.isSelected && isAllProductUsedOrFree) {
|
|
@@ -477,95 +477,89 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
477
477
|
item.isDisabledForProductUsed = false;
|
|
478
478
|
}
|
|
479
479
|
});
|
|
480
|
-
|
|
480
|
+
this.store.discount?.setDiscountList(newDiscountList);
|
|
481
481
|
this.emitDiscountListChange(newDiscountList);
|
|
482
482
|
return newDiscountList;
|
|
483
483
|
}
|
|
484
|
+
|
|
484
485
|
// 获取优惠券列表
|
|
485
486
|
getDiscountList() {
|
|
486
|
-
|
|
487
|
-
return ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList()) || [];
|
|
487
|
+
return this.store.discount?.getDiscountList() || [];
|
|
488
488
|
}
|
|
489
|
+
|
|
489
490
|
// 获取客户钱包信息
|
|
490
491
|
async getCustomerWallet(id) {
|
|
491
492
|
try {
|
|
492
493
|
const result = await this.request.get(`/customer/info/${id}`, {
|
|
493
494
|
with_trashed: 1
|
|
494
495
|
});
|
|
495
|
-
if (result
|
|
496
|
-
const {
|
|
496
|
+
if (result?.data) {
|
|
497
|
+
const {
|
|
498
|
+
...customer
|
|
499
|
+
} = result.data;
|
|
497
500
|
this.setCustomer(customer);
|
|
498
|
-
await this.core.effects.emit(
|
|
499
|
-
`${this.name}:onScanCustomerChange`,
|
|
500
|
-
customer
|
|
501
|
-
);
|
|
501
|
+
await this.core.effects.emit(`${this.name}:onScanCustomerChange`, customer);
|
|
502
502
|
}
|
|
503
503
|
} catch (error) {
|
|
504
|
-
console.error(
|
|
504
|
+
console.error('[ShopDiscount] 获取客户钱包信息出错:', error);
|
|
505
505
|
}
|
|
506
506
|
}
|
|
507
507
|
async bestDiscount(cb) {
|
|
508
|
-
var _a;
|
|
509
508
|
const newDiscountList = this.store.originalDiscountList;
|
|
510
509
|
this.setDiscountList(newDiscountList);
|
|
511
|
-
if (
|
|
510
|
+
if (this.store.productList?.length) {
|
|
512
511
|
const result = this.calcDiscount(this.store.productList);
|
|
513
|
-
cb
|
|
514
|
-
await this.core.effects.emit(
|
|
515
|
-
`${this.name}:onLoadPrepareCalcResult`,
|
|
516
|
-
result
|
|
517
|
-
);
|
|
512
|
+
cb?.(result);
|
|
513
|
+
await this.core.effects.emit(`${this.name}:onLoadPrepareCalcResult`, result);
|
|
518
514
|
}
|
|
519
|
-
await this.core.effects.emit(
|
|
520
|
-
`${this.name}:onLoadDiscountList`,
|
|
521
|
-
newDiscountList
|
|
522
|
-
);
|
|
515
|
+
await this.core.effects.emit(`${this.name}:onLoadDiscountList`, newDiscountList);
|
|
523
516
|
}
|
|
517
|
+
|
|
524
518
|
// 加载准备配置
|
|
525
519
|
async loadPrepareConfig(params) {
|
|
526
|
-
var _a, _b, _c, _d, _e;
|
|
527
520
|
try {
|
|
528
521
|
const orderId = this.store.orderId;
|
|
529
|
-
const customerId = params.customerId ||
|
|
530
|
-
|
|
522
|
+
const customerId = params.customerId || this.getCustomer()?.id;
|
|
523
|
+
// if (customerId === 1 || !customerId) {
|
|
524
|
+
// return
|
|
525
|
+
// }
|
|
526
|
+
|
|
527
|
+
const prepareConfig = await this.store.discount?.loadPrepareConfig({
|
|
531
528
|
customer_id: customerId,
|
|
532
|
-
action: orderId ?
|
|
529
|
+
action: orderId ? 'edit' : 'create',
|
|
533
530
|
with_good_pass: 1,
|
|
534
531
|
with_discount_card: 1,
|
|
535
532
|
with_wallet_pass_holder: 1,
|
|
536
533
|
request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
537
|
-
...orderId ? {
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
);
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
const
|
|
534
|
+
...(orderId ? {
|
|
535
|
+
order_id: orderId
|
|
536
|
+
} : {})
|
|
537
|
+
});
|
|
538
|
+
const goodPassList = prepareConfig?.discountList || [];
|
|
539
|
+
const scanDiscount = this.getDiscountList()?.filter(item => item.isScan);
|
|
540
|
+
|
|
541
|
+
// goodPassList 里可能有 scanDiscount 重合的部分,goodPassList 需要剔除
|
|
542
|
+
const scanDiscountIds = scanDiscount.map(n => n.id);
|
|
543
|
+
const newGoodPassList = goodPassList.filter(n => !scanDiscountIds.includes(n.id));
|
|
544
|
+
const newDiscountList = [...scanDiscount, ...(newGoodPassList || [])];
|
|
545
|
+
|
|
546
|
+
// 存储原始优惠券列表
|
|
546
547
|
this.store.originalDiscountList = newDiscountList;
|
|
547
|
-
await
|
|
548
|
+
await this.store.discount?.setOriginalDiscountList(newDiscountList);
|
|
549
|
+
|
|
550
|
+
// 根据当前预约时间过滤优惠券列表
|
|
548
551
|
const filteredDiscountList = this.filterDiscountListByBookingTime(newDiscountList, this.store.currentBookingTime);
|
|
549
552
|
this.store.filteredDiscountList = filteredDiscountList;
|
|
550
553
|
this.setDiscountList(filteredDiscountList || []);
|
|
551
|
-
if (
|
|
554
|
+
if (this.store.productList?.length) {
|
|
552
555
|
const result = this.calcDiscount(this.store.productList);
|
|
553
|
-
await this.core.effects.emit(
|
|
554
|
-
`${this.name}:onLoadPrepareCalcResult`,
|
|
555
|
-
result
|
|
556
|
-
);
|
|
556
|
+
await this.core.effects.emit(`${this.name}:onLoadPrepareCalcResult`, result);
|
|
557
557
|
}
|
|
558
|
-
await this.core.effects.emit(
|
|
559
|
-
`${this.name}:onLoadDiscountList`,
|
|
560
|
-
filteredDiscountList
|
|
561
|
-
);
|
|
558
|
+
await this.core.effects.emit(`${this.name}:onLoadDiscountList`, filteredDiscountList);
|
|
562
559
|
} catch (error) {
|
|
563
|
-
console.error(
|
|
560
|
+
console.error('[ShopDiscount] 加载准备配置出错:', error);
|
|
564
561
|
}
|
|
565
562
|
}
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
0 && (module.exports = {
|
|
570
|
-
ShopDiscountImpl
|
|
571
|
-
});
|
|
563
|
+
}
|
|
564
|
+
exports.ShopDiscountImpl = ShopDiscountImpl;
|
|
565
|
+
var _default = exports.default = ShopDiscountImpl;
|