@pisell/pisellos 1.0.55 → 1.0.57
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/Cart/utils/changePrice.d.ts +2 -2
- package/dist/modules/Cart/utils/changePrice.js +1 -1
- package/dist/modules/Discount/index.d.ts +2 -1
- package/dist/modules/Discount/index.js +67 -4
- package/dist/modules/Discount/types.d.ts +25 -0
- package/dist/modules/ProductList/index.d.ts +1 -2
- package/dist/modules/ProductList/index.js +26 -40
- package/dist/modules/ProductList/types.d.ts +0 -1
- package/dist/solution/BookingByStep/index.js +51 -35
- package/dist/solution/BookingByStep/types.d.ts +3 -2
- package/dist/solution/BuyTickets/index.d.ts +2 -2
- package/dist/solution/BuyTickets/index.js +1 -1
- package/dist/solution/ShopDiscount/index.d.ts +1 -1
- package/dist/solution/ShopDiscount/index.js +6 -6
- package/lib/modules/Cart/utils/changePrice.d.ts +2 -2
- package/lib/modules/Cart/utils/changePrice.js +1 -1
- package/lib/modules/Discount/index.d.ts +2 -1
- package/lib/modules/Discount/index.js +45 -3
- package/lib/modules/Discount/types.d.ts +25 -0
- package/lib/modules/ProductList/index.d.ts +1 -2
- package/lib/modules/ProductList/index.js +8 -24
- package/lib/modules/ProductList/types.d.ts +0 -1
- package/lib/solution/BookingByStep/index.js +40 -28
- package/lib/solution/BookingByStep/types.d.ts +3 -2
- package/lib/solution/BuyTickets/index.d.ts +2 -2
- package/lib/solution/BuyTickets/index.js +1 -1
- package/lib/solution/ShopDiscount/index.d.ts +1 -1
- package/lib/solution/ShopDiscount/index.js +2 -2
- package/package.json +1 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProductData } from "../../Product";
|
|
2
2
|
import { CartItem, IUpdateItemParams } from "../types";
|
|
3
|
-
export declare function updateAllCartItemPrice(cartItems: CartItem[], priceData: any, getProduct: (id: number) => Promise<
|
|
3
|
+
export declare function updateAllCartItemPrice(cartItems: CartItem[], priceData: any, getProduct: (id: number) => Promise<ProductData | undefined>, updateCart: (item: IUpdateItemParams) => void, updateItemInitInfo: (item: IUpdateItemParams) => void): Promise<void>;
|
|
@@ -36,7 +36,7 @@ function _updateAllCartItemPrice() {
|
|
|
36
36
|
return getProduct(item.id);
|
|
37
37
|
case 4:
|
|
38
38
|
cartProduct = _context.sent;
|
|
39
|
-
productInfo = cartProduct
|
|
39
|
+
productInfo = cartProduct;
|
|
40
40
|
if (!productInfo) {
|
|
41
41
|
productInfo = item._productOrigin;
|
|
42
42
|
}
|
|
@@ -20,8 +20,9 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
|
|
|
20
20
|
with_discount_card: 0 | 1;
|
|
21
21
|
customer_id: number;
|
|
22
22
|
}): Promise<Discount[]>;
|
|
23
|
-
batchSearch(code: string): Promise<Discount[]>;
|
|
23
|
+
batchSearch(code: string, customerId?: number): Promise<Discount[]>;
|
|
24
24
|
filterEnabledDiscountList(discountList: Discount[]): Discount[];
|
|
25
|
+
private checkUsageCreditsLimit;
|
|
25
26
|
uniqueByProductId(discountList: Discount[]): Discount[];
|
|
26
27
|
filterDiscountListByProductIds(discountList: Discount[], productIds: number[]): Discount[];
|
|
27
28
|
calcDiscountApplicableProductTotalPrice(discount: Discount): number | undefined;
|
|
@@ -145,7 +145,7 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
145
145
|
}, {
|
|
146
146
|
key: "batchSearch",
|
|
147
147
|
value: function () {
|
|
148
|
-
var _batchSearch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(code) {
|
|
148
|
+
var _batchSearch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(code, customerId) {
|
|
149
149
|
var result, resultDiscountList;
|
|
150
150
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
151
151
|
while (1) switch (_context4.prev = _context4.next) {
|
|
@@ -156,7 +156,10 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
156
156
|
translate_flag: 1,
|
|
157
157
|
tags: ['good_pass', 'product_discount_card'],
|
|
158
158
|
available: 1,
|
|
159
|
-
relation_product: 1
|
|
159
|
+
relation_product: 1,
|
|
160
|
+
with: ['extensionData'],
|
|
161
|
+
order_behavior_count: 1,
|
|
162
|
+
order_behavior_count_customer_id: customerId || 1
|
|
160
163
|
});
|
|
161
164
|
case 2:
|
|
162
165
|
result = _context4.sent;
|
|
@@ -168,7 +171,7 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
168
171
|
}
|
|
169
172
|
}, _callee4, this);
|
|
170
173
|
}));
|
|
171
|
-
function batchSearch(_x5) {
|
|
174
|
+
function batchSearch(_x5, _x6) {
|
|
172
175
|
return _batchSearch.apply(this, arguments);
|
|
173
176
|
}
|
|
174
177
|
return batchSearch;
|
|
@@ -176,11 +179,71 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
176
179
|
}, {
|
|
177
180
|
key: "filterEnabledDiscountList",
|
|
178
181
|
value: function filterEnabledDiscountList(discountList) {
|
|
182
|
+
var _this2 = this;
|
|
179
183
|
return discountList.filter(function (discount) {
|
|
180
|
-
return discount.limit_status === 'enable' && new Decimal((discount === null || discount === void 0 ? void 0 : discount.par_value) || 0).minus(new Decimal((discount === null || discount === void 0 ? void 0 : discount.used_par_value) || 0)).greaterThan(0);
|
|
184
|
+
return discount.limit_status === 'enable' && new Decimal((discount === null || discount === void 0 ? void 0 : discount.par_value) || 0).minus(new Decimal((discount === null || discount === void 0 ? void 0 : discount.used_par_value) || 0)).greaterThan(0) && _this2.checkUsageCreditsLimit(discount);
|
|
181
185
|
});
|
|
182
186
|
}
|
|
183
187
|
|
|
188
|
+
// 检查使用次数限制
|
|
189
|
+
}, {
|
|
190
|
+
key: "checkUsageCreditsLimit",
|
|
191
|
+
value: function checkUsageCreditsLimit(discount) {
|
|
192
|
+
// 如果没有 extension_data,则不需要限制
|
|
193
|
+
if (!discount.extension_data || discount.extension_data.length === 0) {
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// 查找 field_key 为 usage_credits 的数据
|
|
198
|
+
var usageCreditsData = discount.extension_data.find(function (data) {
|
|
199
|
+
return data.field_key === 'usage_credits';
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// 如果没有找到 usage_credits 数据,则不需要限制
|
|
203
|
+
if (!usageCreditsData) {
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
var value = usageCreditsData.value;
|
|
207
|
+
|
|
208
|
+
// 检查总次数限制
|
|
209
|
+
if (value.total_credits && value.total_credits > 0) {
|
|
210
|
+
if ((discount.total_order_behavior_count || 0) >= value.total_credits) {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// 检查单用户限制
|
|
216
|
+
if (value.per_user_limit && value.per_user_limit > 0) {
|
|
217
|
+
if ((discount.customer_order_behavior_count || 0) >= value.per_user_limit) {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// 检查单日限制
|
|
223
|
+
if (value.max_per_day && value.max_per_day > 0) {
|
|
224
|
+
if ((discount.today_order_behavior_count || 0) >= value.max_per_day) {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// 检查单周限制
|
|
230
|
+
if (value.max_per_week && value.max_per_week > 0) {
|
|
231
|
+
if ((discount.week_order_behavior_count || 0) >= value.max_per_week) {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// 检查单月限制
|
|
237
|
+
if (value.max_per_month && value.max_per_month > 0) {
|
|
238
|
+
if ((discount.month_order_behavior_count || 0) >= value.max_per_month) {
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// 所有检查都通过
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
|
|
184
247
|
// 根据productIds去重
|
|
185
248
|
}, {
|
|
186
249
|
key: "uniqueByProductId",
|
|
@@ -36,6 +36,25 @@ interface ApplicableProductDetails {
|
|
|
36
36
|
title?: string;
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
|
+
interface UsageCreditsValue {
|
|
40
|
+
total_credits: number;
|
|
41
|
+
per_user_limit: number;
|
|
42
|
+
max_per_day: number;
|
|
43
|
+
max_per_week: number;
|
|
44
|
+
max_per_month: number;
|
|
45
|
+
}
|
|
46
|
+
interface ExtensionData {
|
|
47
|
+
id: number;
|
|
48
|
+
shop_id: number;
|
|
49
|
+
product_id: number;
|
|
50
|
+
field_id: number;
|
|
51
|
+
field_key: string;
|
|
52
|
+
type: string;
|
|
53
|
+
value: UsageCreditsValue | Record<string, any> | string | number | boolean | any[];
|
|
54
|
+
created_at: string | null;
|
|
55
|
+
updated_at: string | null;
|
|
56
|
+
deleted_at: string | null;
|
|
57
|
+
}
|
|
39
58
|
export interface Discount {
|
|
40
59
|
id: number;
|
|
41
60
|
product_name: string;
|
|
@@ -70,6 +89,12 @@ export interface Discount {
|
|
|
70
89
|
appliedProductDetails: ApplicableProductDetails[];
|
|
71
90
|
isDisabledForProductUsed?: boolean;
|
|
72
91
|
amount?: number;
|
|
92
|
+
extension_data?: ExtensionData[];
|
|
93
|
+
total_order_behavior_count?: number;
|
|
94
|
+
today_order_behavior_count?: number;
|
|
95
|
+
week_order_behavior_count?: number;
|
|
96
|
+
month_order_behavior_count?: number;
|
|
97
|
+
customer_order_behavior_count?: number;
|
|
73
98
|
}
|
|
74
99
|
export interface DiscountState {
|
|
75
100
|
discountList: Discount[];
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Module, PisellCore } from '../../types';
|
|
2
2
|
import { BaseModule } from '../BaseModule';
|
|
3
|
-
import { Product } from '../Product';
|
|
4
3
|
import { ProductData } from '../Product/types';
|
|
5
4
|
export * from './types';
|
|
6
5
|
export declare class ProductList extends BaseModule implements Module {
|
|
@@ -31,7 +30,7 @@ export declare class ProductList extends BaseModule implements Module {
|
|
|
31
30
|
channel?: string;
|
|
32
31
|
}): Promise<any>;
|
|
33
32
|
getProducts(): Promise<ProductData[]>;
|
|
34
|
-
getProduct(id: number): Promise<
|
|
33
|
+
getProduct(id: number): Promise<ProductData | undefined>;
|
|
35
34
|
addProduct(products: ProductData[]): Promise<void>;
|
|
36
35
|
selectProducts(products: ProductData[]): Promise<void>;
|
|
37
36
|
/**
|
|
@@ -16,7 +16,6 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
16
16
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
17
17
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
18
18
|
import { BaseModule } from "../BaseModule";
|
|
19
|
-
import { Product } from "../Product";
|
|
20
19
|
import { ProductListHooks } from "./types";
|
|
21
20
|
import { cloneDeep } from 'lodash-es';
|
|
22
21
|
export * from "./types";
|
|
@@ -46,12 +45,12 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
46
45
|
this.store = options.store;
|
|
47
46
|
this.otherParams = options.otherParams || {};
|
|
48
47
|
if (Array.isArray((_options$initialState = options.initialState) === null || _options$initialState === void 0 ? void 0 : _options$initialState.list)) {
|
|
49
|
-
this.store.list = options.initialState.list
|
|
48
|
+
this.store.list = options.initialState.list.slice().sort(function (a, b) {
|
|
49
|
+
return Number(b.sort) - Number(a.sort);
|
|
50
|
+
});
|
|
50
51
|
this.core.effects.emit("".concat(this.name, ":changed"), this.store.list);
|
|
51
|
-
this.storeChange();
|
|
52
52
|
} else {
|
|
53
53
|
this.store.list = [];
|
|
54
|
-
this.store.productMap = new Map();
|
|
55
54
|
this.store.selectProducts = [];
|
|
56
55
|
}
|
|
57
56
|
this.request = core.getPlugin('request');
|
|
@@ -70,28 +69,13 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
70
69
|
key: "storeChange",
|
|
71
70
|
value: function () {
|
|
72
71
|
var _storeChange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(path, value) {
|
|
73
|
-
var _this$store$list,
|
|
74
|
-
_this2 = this;
|
|
75
72
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
76
73
|
while (1) switch (_context2.prev = _context2.next) {
|
|
77
74
|
case 0:
|
|
78
|
-
(_this$store$list = this.store.list) === null || _this$store$list === void 0 || _this$store$list.forEach(function (product) {
|
|
79
|
-
var productModule = _this2.store.productMap.get("product-".concat(product.id));
|
|
80
|
-
if (!productModule) {
|
|
81
|
-
var newProductModule = new Product("product_".concat(product.id.toString()));
|
|
82
|
-
_this2.core.registerModule(newProductModule, {
|
|
83
|
-
initialState: product
|
|
84
|
-
});
|
|
85
|
-
_this2.store.productMap.set(product.id.toString(), newProductModule);
|
|
86
|
-
} else {
|
|
87
|
-
productModule.updateData(product);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
case 1:
|
|
91
75
|
case "end":
|
|
92
76
|
return _context2.stop();
|
|
93
77
|
}
|
|
94
|
-
}, _callee2
|
|
78
|
+
}, _callee2);
|
|
95
79
|
}));
|
|
96
80
|
function storeChange(_x3, _x4) {
|
|
97
81
|
return _storeChange.apply(this, arguments);
|
|
@@ -103,7 +87,7 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
103
87
|
value: function () {
|
|
104
88
|
var _loadProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref) {
|
|
105
89
|
var _this$otherParams;
|
|
106
|
-
var _ref$category_ids, category_ids, _ref$product_ids, product_ids, _ref$collection, collection, _ref$menu_list_ids, menu_list_ids, paramsCustomerId, _ref$with_count, with_count, schedule_datetime, schedule_date, cacheId, with_schedule, userPlugin, customer_id, _userPlugin$get, productsData;
|
|
90
|
+
var _ref$category_ids, category_ids, _ref$product_ids, product_ids, _ref$collection, collection, _ref$menu_list_ids, menu_list_ids, paramsCustomerId, _ref$with_count, with_count, schedule_datetime, schedule_date, cacheId, with_schedule, userPlugin, customer_id, _userPlugin$get, productsData, sortedList;
|
|
107
91
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
108
92
|
while (1) switch (_context3.prev = _context3.next) {
|
|
109
93
|
case 0:
|
|
@@ -154,9 +138,12 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
154
138
|
});
|
|
155
139
|
case 6:
|
|
156
140
|
productsData = _context3.sent;
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
141
|
+
sortedList = (productsData.data.list || []).slice().sort(function (a, b) {
|
|
142
|
+
return Number(b.sort) - Number(a.sort);
|
|
143
|
+
});
|
|
144
|
+
this.addProduct(sortedList);
|
|
145
|
+
return _context3.abrupt("return", sortedList);
|
|
146
|
+
case 10:
|
|
160
147
|
case "end":
|
|
161
148
|
return _context3.stop();
|
|
162
149
|
}
|
|
@@ -232,15 +219,11 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
232
219
|
_context6.next = 2;
|
|
233
220
|
return this.core.effects.emit(ProductListHooks.onGetProduct, this.store.list);
|
|
234
221
|
case 2:
|
|
235
|
-
product = this.store.
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
return _context6.abrupt("return", product);
|
|
241
|
-
case 5:
|
|
242
|
-
return _context6.abrupt("return", undefined);
|
|
243
|
-
case 6:
|
|
222
|
+
product = this.store.list.find(function (product) {
|
|
223
|
+
return product.id === id;
|
|
224
|
+
});
|
|
225
|
+
return _context6.abrupt("return", product ? cloneDeep(product) : undefined);
|
|
226
|
+
case 4:
|
|
244
227
|
case "end":
|
|
245
228
|
return _context6.stop();
|
|
246
229
|
}
|
|
@@ -255,27 +238,30 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
255
238
|
key: "addProduct",
|
|
256
239
|
value: function () {
|
|
257
240
|
var _addProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(products) {
|
|
258
|
-
var
|
|
241
|
+
var _this2 = this;
|
|
259
242
|
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
260
243
|
while (1) switch (_context7.prev = _context7.next) {
|
|
261
244
|
case 0:
|
|
262
|
-
// 加到 list 以后上面的storeChange 会自动初始化商品详情的 module 实例
|
|
263
245
|
// list 需要根据 id 去重
|
|
264
246
|
if (!this.store.list) {
|
|
265
247
|
this.store.list = [];
|
|
266
248
|
}
|
|
267
249
|
products.forEach(function (n) {
|
|
268
|
-
var index =
|
|
250
|
+
var index = _this2.store.list.findIndex(function (m) {
|
|
269
251
|
return m.id === n.id;
|
|
270
252
|
});
|
|
271
253
|
if (index === -1) {
|
|
272
|
-
|
|
254
|
+
_this2.store.list.push(n);
|
|
273
255
|
} else {
|
|
274
|
-
|
|
256
|
+
_this2.store.list[index] = n;
|
|
275
257
|
}
|
|
276
258
|
});
|
|
277
|
-
|
|
278
|
-
|
|
259
|
+
// 根据 sort 值做降序排序(数字越大越靠前)
|
|
260
|
+
this.store.list.sort(function (a, b) {
|
|
261
|
+
return Number(b.sort) - Number(a.sort);
|
|
262
|
+
});
|
|
263
|
+
this.core.effects.emit("".concat(this.name, ":changed"), this.store.list);
|
|
264
|
+
case 4:
|
|
279
265
|
case "end":
|
|
280
266
|
return _context7.stop();
|
|
281
267
|
}
|
|
@@ -701,6 +701,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
701
701
|
_params$useCache,
|
|
702
702
|
useCache,
|
|
703
703
|
tempProducts,
|
|
704
|
+
_this$store$currentPr,
|
|
704
705
|
dateRange,
|
|
705
706
|
tempStartDate,
|
|
706
707
|
tempEndDate,
|
|
@@ -732,8 +733,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
732
733
|
}
|
|
733
734
|
// 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
|
|
734
735
|
if (this.store.currentProduct) {
|
|
735
|
-
tempProducts = [_objectSpread(_objectSpread({}, this.store.currentProduct
|
|
736
|
-
_schedule: this.store.
|
|
736
|
+
tempProducts = [_objectSpread(_objectSpread({}, this.store.currentProduct), {}, {
|
|
737
|
+
_schedule: (_this$store$currentPr = this.store.currentProductMeta) === null || _this$store$currentPr === void 0 ? void 0 : _this$store$currentPr['schedule']
|
|
737
738
|
})];
|
|
738
739
|
}
|
|
739
740
|
dateRange = this.store.date.getDateRange();
|
|
@@ -1272,7 +1273,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1272
1273
|
// 如果此时 resources 为空,视作购物车里已经有了 dateRange 数据,此时 dateList 里明确就是那一天的数据
|
|
1273
1274
|
if (!allOriginResources.length) {
|
|
1274
1275
|
var dateList = this.store.date.getDateList();
|
|
1275
|
-
dateList.forEach(function (n) {
|
|
1276
|
+
dateList === null || dateList === void 0 || dateList.forEach(function (n) {
|
|
1276
1277
|
if (n.resource) allOriginResources.push.apply(allOriginResources, _toConsumableArray(n.resource));
|
|
1277
1278
|
});
|
|
1278
1279
|
}
|
|
@@ -2281,41 +2282,42 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2281
2282
|
key: "openProductDetail",
|
|
2282
2283
|
value: function () {
|
|
2283
2284
|
var _openProductDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(productId) {
|
|
2284
|
-
var
|
|
2285
|
+
var targetProductData, newScheduleArr, dateRange;
|
|
2285
2286
|
return _regeneratorRuntime().wrap(function _callee25$(_context25) {
|
|
2286
2287
|
while (1) switch (_context25.prev = _context25.next) {
|
|
2287
2288
|
case 0:
|
|
2288
2289
|
_context25.next = 2;
|
|
2289
2290
|
return this.store.products.getProduct(productId);
|
|
2290
2291
|
case 2:
|
|
2291
|
-
|
|
2292
|
-
if (!
|
|
2293
|
-
_context25.next =
|
|
2292
|
+
targetProductData = _context25.sent;
|
|
2293
|
+
if (!targetProductData) {
|
|
2294
|
+
_context25.next = 17;
|
|
2294
2295
|
break;
|
|
2295
2296
|
}
|
|
2296
|
-
|
|
2297
|
-
this.store.
|
|
2297
|
+
this.store.currentProduct = targetProductData;
|
|
2298
|
+
this.store.currentProductMeta = {};
|
|
2298
2299
|
// 资源预加载,如果是 duration 类型的商品,且是先选日期的流程,在这里预拉取资源数据
|
|
2299
2300
|
if (!targetProductData['schedule.ids']) {
|
|
2300
|
-
_context25.next =
|
|
2301
|
+
_context25.next = 12;
|
|
2301
2302
|
break;
|
|
2302
2303
|
}
|
|
2303
2304
|
newScheduleArr = this.getScheduleDataByIds(targetProductData['schedule.ids']);
|
|
2304
|
-
|
|
2305
|
-
|
|
2305
|
+
if (!this.store.currentProductMeta) this.store.currentProductMeta = {};
|
|
2306
|
+
this.store.currentProductMeta.schedule = newScheduleArr;
|
|
2307
|
+
_context25.next = 17;
|
|
2306
2308
|
break;
|
|
2307
|
-
case
|
|
2309
|
+
case 12:
|
|
2308
2310
|
if (!targetProductData.duration) {
|
|
2309
|
-
_context25.next =
|
|
2311
|
+
_context25.next = 17;
|
|
2310
2312
|
break;
|
|
2311
2313
|
}
|
|
2312
2314
|
dateRange = this.store.date.getDateRange(); // 如果不是先选日期的流程 duration 商品就啥也不做
|
|
2313
2315
|
if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
|
|
2314
|
-
_context25.next =
|
|
2316
|
+
_context25.next = 16;
|
|
2315
2317
|
break;
|
|
2316
2318
|
}
|
|
2317
2319
|
return _context25.abrupt("return");
|
|
2318
|
-
case
|
|
2320
|
+
case 16:
|
|
2319
2321
|
// this.store.date.getResourceDates({
|
|
2320
2322
|
// query: {
|
|
2321
2323
|
// start_date: dateRange[0].date,
|
|
@@ -2328,7 +2330,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2328
2330
|
endDate: dateRange[dateRange.length - 1].date,
|
|
2329
2331
|
products: [targetProductData]
|
|
2330
2332
|
});
|
|
2331
|
-
case
|
|
2333
|
+
case 17:
|
|
2332
2334
|
case "end":
|
|
2333
2335
|
return _context25.stop();
|
|
2334
2336
|
}
|
|
@@ -2342,8 +2344,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2342
2344
|
}, {
|
|
2343
2345
|
key: "closeProductDetail",
|
|
2344
2346
|
value: function closeProductDetail() {
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
+
if (this.store.currentProductMeta) {
|
|
2348
|
+
this.store.currentProductMeta.schedule = [];
|
|
2349
|
+
}
|
|
2347
2350
|
this.store.currentProduct = undefined;
|
|
2348
2351
|
}
|
|
2349
2352
|
}, {
|
|
@@ -2356,7 +2359,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2356
2359
|
product = _ref10.product;
|
|
2357
2360
|
var targetProduct = this.store.currentProduct;
|
|
2358
2361
|
// 如果外面传递了product 优先用外面的
|
|
2359
|
-
var targetProductData = product ||
|
|
2362
|
+
var targetProductData = product || targetProduct;
|
|
2360
2363
|
var targetSchedules = [];
|
|
2361
2364
|
// 如果外面传递了 scheduleIds,优先取入参
|
|
2362
2365
|
if (scheduleIds !== null && scheduleIds !== void 0 && scheduleIds.length) {
|
|
@@ -2371,7 +2374,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2371
2374
|
var cartItems = cloneDeep(this.store.cart.getItems());
|
|
2372
2375
|
var resourcesMap = getResourcesMap((targetResourceDate === null || targetResourceDate === void 0 ? void 0 : targetResourceDate.resource) || []);
|
|
2373
2376
|
var selectedResources = getOthersSelectedResources(cartItems, '', resourcesMap);
|
|
2374
|
-
var productResources = getResourcesByProduct(resourcesMap, resources || ((_this$store$currentPr2 = this.store.currentProduct) === null || _this$store$currentPr2 === void 0 || (_this$store$currentPr2 = _this$store$currentPr2.
|
|
2377
|
+
var productResources = getResourcesByProduct(resourcesMap, resources || ((_this$store$currentPr2 = this.store.currentProduct) === null || _this$store$currentPr2 === void 0 || (_this$store$currentPr2 = _this$store$currentPr2.product_resource) === null || _this$store$currentPr2 === void 0 ? void 0 : _this$store$currentPr2.resources) || [], selectedResources, 1);
|
|
2375
2378
|
var minTimeMaxTime = calcMinTimeMaxTimeBySchedules(targetSchedules, {}, date);
|
|
2376
2379
|
var scheduleTimeSlots = getAllSortedDateRanges(minTimeMaxTime);
|
|
2377
2380
|
// 当前所有待选择资源的集合,先提出来,提升性能
|
|
@@ -2491,22 +2494,34 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2491
2494
|
key: "getProductTypeById",
|
|
2492
2495
|
value: function () {
|
|
2493
2496
|
var _getProductTypeById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(id) {
|
|
2494
|
-
var
|
|
2497
|
+
var productData, _productData$schedule;
|
|
2495
2498
|
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
2496
2499
|
while (1) switch (_context26.prev = _context26.next) {
|
|
2497
2500
|
case 0:
|
|
2498
2501
|
_context26.next = 2;
|
|
2499
2502
|
return this.store.products.getProduct(id);
|
|
2500
2503
|
case 2:
|
|
2501
|
-
|
|
2502
|
-
if (!
|
|
2503
|
-
_context26.next =
|
|
2504
|
+
productData = _context26.sent;
|
|
2505
|
+
if (!productData) {
|
|
2506
|
+
_context26.next = 9;
|
|
2504
2507
|
break;
|
|
2505
2508
|
}
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
+
if (!productData.duration) {
|
|
2510
|
+
_context26.next = 6;
|
|
2511
|
+
break;
|
|
2512
|
+
}
|
|
2513
|
+
return _context26.abrupt("return", 'duration');
|
|
2509
2514
|
case 6:
|
|
2515
|
+
if (!((_productData$schedule = productData['schedule.ids']) !== null && _productData$schedule !== void 0 && _productData$schedule.length)) {
|
|
2516
|
+
_context26.next = 8;
|
|
2517
|
+
break;
|
|
2518
|
+
}
|
|
2519
|
+
return _context26.abrupt("return", 'session');
|
|
2520
|
+
case 8:
|
|
2521
|
+
return _context26.abrupt("return", 'normal');
|
|
2522
|
+
case 9:
|
|
2523
|
+
return _context26.abrupt("return", 'normal');
|
|
2524
|
+
case 10:
|
|
2510
2525
|
case "end":
|
|
2511
2526
|
return _context26.stop();
|
|
2512
2527
|
}
|
|
@@ -2678,7 +2693,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2678
2693
|
key: "getAvailableDateForSessionOptimize",
|
|
2679
2694
|
value: function () {
|
|
2680
2695
|
var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
|
|
2681
|
-
var _this$store$currentPr3, _this$store$currentPr4,
|
|
2696
|
+
var _this$store$currentPr3, _this$store$currentPr4, _tempProducts;
|
|
2682
2697
|
var params,
|
|
2683
2698
|
startDate,
|
|
2684
2699
|
endDate,
|
|
@@ -2724,7 +2739,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2724
2739
|
endDate = tempEndDate;
|
|
2725
2740
|
|
|
2726
2741
|
// 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
|
|
2727
|
-
cache = (_this$store$currentPr3 = this.store.
|
|
2742
|
+
cache = (_this$store$currentPr3 = this.store.currentProductMeta) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3['timeSlotBySchedule'];
|
|
2728
2743
|
if (!cache) {
|
|
2729
2744
|
_context29.next = 13;
|
|
2730
2745
|
break;
|
|
@@ -2740,8 +2755,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2740
2755
|
});
|
|
2741
2756
|
case 13:
|
|
2742
2757
|
// 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
|
|
2743
|
-
tempProducts =
|
|
2744
|
-
schedule = (_this$store$
|
|
2758
|
+
tempProducts = this.store.currentProduct;
|
|
2759
|
+
schedule = (_this$store$currentPr4 = this.store.currentProductMeta) === null || _this$store$currentPr4 === void 0 ? void 0 : _this$store$currentPr4['schedule'];
|
|
2745
2760
|
filteredSchedule = filterScheduleByDateRange(schedule, startDate || '', endDate || ''); // 1.后端返回的数据,确定资源在每一天的可用和使用情况
|
|
2746
2761
|
tempResourceIds = getResourcesIdsByProduct(tempProducts);
|
|
2747
2762
|
_context29.next = 19;
|
|
@@ -2901,17 +2916,18 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2901
2916
|
this.store.date.setDateList(dates);
|
|
2902
2917
|
|
|
2903
2918
|
// 缓存这次结果,以防后面他小幅度范围内去修改天数
|
|
2904
|
-
(
|
|
2919
|
+
if (!this.store.currentProductMeta) this.store.currentProductMeta = {};
|
|
2920
|
+
this.store.currentProductMeta.timeSlotBySchedule = {
|
|
2905
2921
|
dateList: dates,
|
|
2906
2922
|
firstAvailableDate: firstAvailableDate,
|
|
2907
2923
|
startDate: startDate,
|
|
2908
2924
|
endDate: dayjs(currentDate).format('YYYY-MM-DD')
|
|
2909
|
-
}
|
|
2925
|
+
};
|
|
2910
2926
|
return _context29.abrupt("return", {
|
|
2911
2927
|
dateList: dates,
|
|
2912
2928
|
firstAvailableDate: firstAvailableDate
|
|
2913
2929
|
});
|
|
2914
|
-
case
|
|
2930
|
+
case 39:
|
|
2915
2931
|
case "end":
|
|
2916
2932
|
return _context29.stop();
|
|
2917
2933
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ProductList, CartModule,
|
|
1
|
+
import { ProductList, CartModule, ProductData, AccountModule, AccountListModule, DateModule, GuestListModule, OrderModule, PaymentModule, ResourceListModule, StepModule, SummaryModule, ScheduleModule } from '../../modules';
|
|
2
2
|
export interface BookingByStepState {
|
|
3
3
|
cart: CartModule;
|
|
4
4
|
summary: SummaryModule;
|
|
@@ -11,7 +11,8 @@ export interface BookingByStepState {
|
|
|
11
11
|
accountList: AccountListModule;
|
|
12
12
|
order: OrderModule;
|
|
13
13
|
payment: PaymentModule;
|
|
14
|
-
currentProduct?:
|
|
14
|
+
currentProduct?: ProductData;
|
|
15
|
+
currentProductMeta?: Record<string, any>;
|
|
15
16
|
schedule: ScheduleModule;
|
|
16
17
|
}
|
|
17
18
|
export declare function createModule<T extends keyof BookingByStepState>(moduleName: T, solutionName: string, name?: string, version?: string): BookingByStepState[T];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Module, PisellCore } from '../../types';
|
|
2
|
-
import {
|
|
2
|
+
import { ProductData } from '../../modules/';
|
|
3
3
|
import { BaseModule } from '../../modules/BaseModule';
|
|
4
4
|
export * from './types';
|
|
5
5
|
export declare class BuyTicketsImpl extends BaseModule implements Module {
|
|
@@ -16,7 +16,7 @@ export declare class BuyTicketsImpl extends BaseModule implements Module {
|
|
|
16
16
|
loadProductsByCategory(categoryId: number): Promise<void>;
|
|
17
17
|
destroy(): Promise<void>;
|
|
18
18
|
getProducts(): Promise<ProductData[]>;
|
|
19
|
-
getProduct(id: number): Promise<
|
|
19
|
+
getProduct(id: number): Promise<ProductData>;
|
|
20
20
|
listSubmit(data: Record<string, any>): Promise<{
|
|
21
21
|
status: boolean;
|
|
22
22
|
data: any;
|
|
@@ -238,7 +238,7 @@ export var BuyTicketsImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
238
238
|
}
|
|
239
239
|
return _context6.abrupt("return", otherProduct);
|
|
240
240
|
case 10:
|
|
241
|
-
|
|
241
|
+
throw new Error("Product not found: ".concat(id));
|
|
242
242
|
case 11:
|
|
243
243
|
case "end":
|
|
244
244
|
return _context6.stop();
|
|
@@ -34,7 +34,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
34
34
|
discountList: Discount[];
|
|
35
35
|
};
|
|
36
36
|
setProductList(productList: Record<string, any>[]): void;
|
|
37
|
-
scanCode(code: string): Promise<{
|
|
37
|
+
scanCode(code: string, customerId?: number): Promise<{
|
|
38
38
|
isAvailable: boolean;
|
|
39
39
|
productList: Record<string, any>[];
|
|
40
40
|
discountList: Discount[];
|
|
@@ -305,14 +305,14 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
305
305
|
}, {
|
|
306
306
|
key: "scanCode",
|
|
307
307
|
value: function () {
|
|
308
|
-
var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(code) {
|
|
308
|
+
var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(code, customerId) {
|
|
309
309
|
var _this$store$discount3, resultDiscountList, rulesModule, withScanList, _ref3, newProductList, newDiscountList, isAvailable, _this$options$otherPa6;
|
|
310
310
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
311
311
|
while (1) switch (_context5.prev = _context5.next) {
|
|
312
312
|
case 0:
|
|
313
313
|
_context5.prev = 0;
|
|
314
314
|
_context5.next = 3;
|
|
315
|
-
return (_this$store$discount3 = this.store.discount) === null || _this$store$discount3 === void 0 ? void 0 : _this$store$discount3.batchSearch(code);
|
|
315
|
+
return (_this$store$discount3 = this.store.discount) === null || _this$store$discount3 === void 0 ? void 0 : _this$store$discount3.batchSearch(code, customerId);
|
|
316
316
|
case 3:
|
|
317
317
|
_context5.t0 = _context5.sent;
|
|
318
318
|
if (_context5.t0) {
|
|
@@ -394,7 +394,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
394
394
|
}
|
|
395
395
|
}, _callee5, this, [[0, 23]]);
|
|
396
396
|
}));
|
|
397
|
-
function scanCode(_x4) {
|
|
397
|
+
function scanCode(_x4, _x5) {
|
|
398
398
|
return _scanCode.apply(this, arguments);
|
|
399
399
|
}
|
|
400
400
|
return scanCode;
|
|
@@ -439,7 +439,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
439
439
|
}
|
|
440
440
|
}, _callee6, this);
|
|
441
441
|
}));
|
|
442
|
-
function emitDiscountListChange(
|
|
442
|
+
function emitDiscountListChange(_x6) {
|
|
443
443
|
return _emitDiscountListChange.apply(this, arguments);
|
|
444
444
|
}
|
|
445
445
|
return emitDiscountListChange;
|
|
@@ -576,7 +576,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
576
576
|
}
|
|
577
577
|
}, _callee7, this, [[0, 11]]);
|
|
578
578
|
}));
|
|
579
|
-
function getCustomerWallet(
|
|
579
|
+
function getCustomerWallet(_x7) {
|
|
580
580
|
return _getCustomerWallet.apply(this, arguments);
|
|
581
581
|
}
|
|
582
582
|
return getCustomerWallet;
|
|
@@ -636,7 +636,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
636
636
|
}
|
|
637
637
|
}, _callee8, this, [[0, 18]]);
|
|
638
638
|
}));
|
|
639
|
-
function loadPrepareConfig(
|
|
639
|
+
function loadPrepareConfig(_x8) {
|
|
640
640
|
return _loadPrepareConfig.apply(this, arguments);
|
|
641
641
|
}
|
|
642
642
|
return loadPrepareConfig;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProductData } from "../../Product";
|
|
2
2
|
import { CartItem, IUpdateItemParams } from "../types";
|
|
3
|
-
export declare function updateAllCartItemPrice(cartItems: CartItem[], priceData: any, getProduct: (id: number) => Promise<
|
|
3
|
+
export declare function updateAllCartItemPrice(cartItems: CartItem[], priceData: any, getProduct: (id: number) => Promise<ProductData | undefined>, updateCart: (item: IUpdateItemParams) => void, updateItemInitInfo: (item: IUpdateItemParams) => void): Promise<void>;
|
|
@@ -40,7 +40,7 @@ async function updateAllCartItemPrice(cartItems, priceData, getProduct, updateCa
|
|
|
40
40
|
const cartProduct = await getProduct(
|
|
41
41
|
item.id
|
|
42
42
|
);
|
|
43
|
-
let productInfo = cartProduct
|
|
43
|
+
let productInfo = cartProduct;
|
|
44
44
|
if (!productInfo) {
|
|
45
45
|
productInfo = item._productOrigin;
|
|
46
46
|
}
|
|
@@ -20,8 +20,9 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
|
|
|
20
20
|
with_discount_card: 0 | 1;
|
|
21
21
|
customer_id: number;
|
|
22
22
|
}): Promise<Discount[]>;
|
|
23
|
-
batchSearch(code: string): Promise<Discount[]>;
|
|
23
|
+
batchSearch(code: string, customerId?: number): Promise<Discount[]>;
|
|
24
24
|
filterEnabledDiscountList(discountList: Discount[]): Discount[];
|
|
25
|
+
private checkUsageCreditsLimit;
|
|
25
26
|
uniqueByProductId(discountList: Discount[]): Discount[];
|
|
26
27
|
filterDiscountListByProductIds(discountList: Discount[], productIds: number[]): Discount[];
|
|
27
28
|
calcDiscountApplicableProductTotalPrice(discount: Discount): number | undefined;
|
|
@@ -89,22 +89,64 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
|
|
|
89
89
|
) || [];
|
|
90
90
|
return goodPassList;
|
|
91
91
|
}
|
|
92
|
-
async batchSearch(code) {
|
|
92
|
+
async batchSearch(code, customerId) {
|
|
93
93
|
const result = await this.request.get(`/machinecode/batch-search`, {
|
|
94
94
|
code,
|
|
95
95
|
translate_flag: 1,
|
|
96
96
|
tags: ["good_pass", "product_discount_card"],
|
|
97
97
|
available: 1,
|
|
98
|
-
relation_product: 1
|
|
98
|
+
relation_product: 1,
|
|
99
|
+
with: ["extensionData"],
|
|
100
|
+
order_behavior_count: 1,
|
|
101
|
+
order_behavior_count_customer_id: customerId || 1
|
|
99
102
|
});
|
|
100
103
|
const resultDiscountList = this.filterEnabledDiscountList((result == null ? void 0 : result.data) || []) || [];
|
|
101
104
|
return resultDiscountList;
|
|
102
105
|
}
|
|
103
106
|
filterEnabledDiscountList(discountList) {
|
|
104
107
|
return discountList.filter(
|
|
105
|
-
(discount) => discount.limit_status === "enable" && new import_decimal.default((discount == null ? void 0 : discount.par_value) || 0).minus(new import_decimal.default((discount == null ? void 0 : discount.used_par_value) || 0)).greaterThan(0)
|
|
108
|
+
(discount) => discount.limit_status === "enable" && new import_decimal.default((discount == null ? void 0 : discount.par_value) || 0).minus(new import_decimal.default((discount == null ? void 0 : discount.used_par_value) || 0)).greaterThan(0) && this.checkUsageCreditsLimit(discount)
|
|
106
109
|
);
|
|
107
110
|
}
|
|
111
|
+
// 检查使用次数限制
|
|
112
|
+
checkUsageCreditsLimit(discount) {
|
|
113
|
+
if (!discount.extension_data || discount.extension_data.length === 0) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
const usageCreditsData = discount.extension_data.find(
|
|
117
|
+
(data) => data.field_key === "usage_credits"
|
|
118
|
+
);
|
|
119
|
+
if (!usageCreditsData) {
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
const value = usageCreditsData.value;
|
|
123
|
+
if (value.total_credits && value.total_credits > 0) {
|
|
124
|
+
if ((discount.total_order_behavior_count || 0) >= value.total_credits) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (value.per_user_limit && value.per_user_limit > 0) {
|
|
129
|
+
if ((discount.customer_order_behavior_count || 0) >= value.per_user_limit) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (value.max_per_day && value.max_per_day > 0) {
|
|
134
|
+
if ((discount.today_order_behavior_count || 0) >= value.max_per_day) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (value.max_per_week && value.max_per_week > 0) {
|
|
139
|
+
if ((discount.week_order_behavior_count || 0) >= value.max_per_week) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (value.max_per_month && value.max_per_month > 0) {
|
|
144
|
+
if ((discount.month_order_behavior_count || 0) >= value.max_per_month) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
108
150
|
// 根据productIds去重
|
|
109
151
|
uniqueByProductId(discountList) {
|
|
110
152
|
return (0, import_utils.uniqueById)(discountList, "product_id");
|
|
@@ -36,6 +36,25 @@ interface ApplicableProductDetails {
|
|
|
36
36
|
title?: string;
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
|
+
interface UsageCreditsValue {
|
|
40
|
+
total_credits: number;
|
|
41
|
+
per_user_limit: number;
|
|
42
|
+
max_per_day: number;
|
|
43
|
+
max_per_week: number;
|
|
44
|
+
max_per_month: number;
|
|
45
|
+
}
|
|
46
|
+
interface ExtensionData {
|
|
47
|
+
id: number;
|
|
48
|
+
shop_id: number;
|
|
49
|
+
product_id: number;
|
|
50
|
+
field_id: number;
|
|
51
|
+
field_key: string;
|
|
52
|
+
type: string;
|
|
53
|
+
value: UsageCreditsValue | Record<string, any> | string | number | boolean | any[];
|
|
54
|
+
created_at: string | null;
|
|
55
|
+
updated_at: string | null;
|
|
56
|
+
deleted_at: string | null;
|
|
57
|
+
}
|
|
39
58
|
export interface Discount {
|
|
40
59
|
id: number;
|
|
41
60
|
product_name: string;
|
|
@@ -70,6 +89,12 @@ export interface Discount {
|
|
|
70
89
|
appliedProductDetails: ApplicableProductDetails[];
|
|
71
90
|
isDisabledForProductUsed?: boolean;
|
|
72
91
|
amount?: number;
|
|
92
|
+
extension_data?: ExtensionData[];
|
|
93
|
+
total_order_behavior_count?: number;
|
|
94
|
+
today_order_behavior_count?: number;
|
|
95
|
+
week_order_behavior_count?: number;
|
|
96
|
+
month_order_behavior_count?: number;
|
|
97
|
+
customer_order_behavior_count?: number;
|
|
73
98
|
}
|
|
74
99
|
export interface DiscountState {
|
|
75
100
|
discountList: Discount[];
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Module, PisellCore } from '../../types';
|
|
2
2
|
import { BaseModule } from '../BaseModule';
|
|
3
|
-
import { Product } from '../Product';
|
|
4
3
|
import { ProductData } from '../Product/types';
|
|
5
4
|
export * from './types';
|
|
6
5
|
export declare class ProductList extends BaseModule implements Module {
|
|
@@ -31,7 +30,7 @@ export declare class ProductList extends BaseModule implements Module {
|
|
|
31
30
|
channel?: string;
|
|
32
31
|
}): Promise<any>;
|
|
33
32
|
getProducts(): Promise<ProductData[]>;
|
|
34
|
-
getProduct(id: number): Promise<
|
|
33
|
+
getProduct(id: number): Promise<ProductData | undefined>;
|
|
35
34
|
addProduct(products: ProductData[]): Promise<void>;
|
|
36
35
|
selectProducts(products: ProductData[]): Promise<void>;
|
|
37
36
|
/**
|
|
@@ -24,7 +24,6 @@ __export(ProductList_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(ProductList_exports);
|
|
26
26
|
var import_BaseModule = require("../BaseModule");
|
|
27
|
-
var import_Product = require("../Product");
|
|
28
27
|
var import_types = require("./types");
|
|
29
28
|
var import_lodash_es = require("lodash-es");
|
|
30
29
|
__reExport(ProductList_exports, require("./types"), module.exports);
|
|
@@ -41,30 +40,15 @@ var ProductList = class extends import_BaseModule.BaseModule {
|
|
|
41
40
|
this.store = options.store;
|
|
42
41
|
this.otherParams = options.otherParams || {};
|
|
43
42
|
if (Array.isArray((_a = options.initialState) == null ? void 0 : _a.list)) {
|
|
44
|
-
this.store.list = options.initialState.list;
|
|
43
|
+
this.store.list = options.initialState.list.slice().sort((a, b) => Number(b.sort) - Number(a.sort));
|
|
45
44
|
this.core.effects.emit(`${this.name}:changed`, this.store.list);
|
|
46
|
-
this.storeChange();
|
|
47
45
|
} else {
|
|
48
46
|
this.store.list = [];
|
|
49
|
-
this.store.productMap = /* @__PURE__ */ new Map();
|
|
50
47
|
this.store.selectProducts = [];
|
|
51
48
|
}
|
|
52
49
|
this.request = core.getPlugin("request");
|
|
53
50
|
}
|
|
54
51
|
async storeChange(path, value) {
|
|
55
|
-
var _a;
|
|
56
|
-
(_a = this.store.list) == null ? void 0 : _a.forEach((product) => {
|
|
57
|
-
const productModule = this.store.productMap.get(`product-${product.id}`);
|
|
58
|
-
if (!productModule) {
|
|
59
|
-
const newProductModule = new import_Product.Product(
|
|
60
|
-
`product_${product.id.toString()}`
|
|
61
|
-
);
|
|
62
|
-
this.core.registerModule(newProductModule, { initialState: product });
|
|
63
|
-
this.store.productMap.set(product.id.toString(), newProductModule);
|
|
64
|
-
} else {
|
|
65
|
-
productModule.updateData(product);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
52
|
}
|
|
69
53
|
async loadProducts({
|
|
70
54
|
category_ids = [],
|
|
@@ -118,8 +102,9 @@ var ProductList = class extends import_BaseModule.BaseModule {
|
|
|
118
102
|
},
|
|
119
103
|
{ useCache: true }
|
|
120
104
|
);
|
|
121
|
-
|
|
122
|
-
|
|
105
|
+
const sortedList = (productsData.data.list || []).slice().sort((a, b) => Number(b.sort) - Number(a.sort));
|
|
106
|
+
this.addProduct(sortedList);
|
|
107
|
+
return sortedList;
|
|
123
108
|
}
|
|
124
109
|
async loadProductsPrice({
|
|
125
110
|
ids = [],
|
|
@@ -151,10 +136,8 @@ var ProductList = class extends import_BaseModule.BaseModule {
|
|
|
151
136
|
import_types.ProductListHooks.onGetProduct,
|
|
152
137
|
this.store.list
|
|
153
138
|
);
|
|
154
|
-
const product = this.store.
|
|
155
|
-
|
|
156
|
-
return product;
|
|
157
|
-
return void 0;
|
|
139
|
+
const product = this.store.list.find((product2) => product2.id === id);
|
|
140
|
+
return product ? (0, import_lodash_es.cloneDeep)(product) : void 0;
|
|
158
141
|
}
|
|
159
142
|
async addProduct(products) {
|
|
160
143
|
if (!this.store.list) {
|
|
@@ -168,7 +151,8 @@ var ProductList = class extends import_BaseModule.BaseModule {
|
|
|
168
151
|
this.store.list[index] = n;
|
|
169
152
|
}
|
|
170
153
|
});
|
|
171
|
-
this.
|
|
154
|
+
this.store.list.sort((a, b) => Number(b.sort) - Number(a.sort));
|
|
155
|
+
this.core.effects.emit(`${this.name}:changed`, this.store.list);
|
|
172
156
|
}
|
|
173
157
|
async selectProducts(products) {
|
|
174
158
|
this.store.selectProducts = products;
|
|
@@ -390,7 +390,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
390
390
|
}
|
|
391
391
|
// 获取商品/服务的可用日期
|
|
392
392
|
async getAvailableDate(params = {}) {
|
|
393
|
-
var _a, _b, _c;
|
|
393
|
+
var _a, _b, _c, _d;
|
|
394
394
|
let { products, startDate, endDate, type, useCache = true } = params;
|
|
395
395
|
if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day") && ((0, import_dayjs.default)(endDate).isAfter((0, import_dayjs.default)(), "day") || (0, import_dayjs.default)(endDate).isSame((0, import_dayjs.default)(), "day"))) {
|
|
396
396
|
startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
|
|
@@ -407,14 +407,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
407
407
|
if (this.store.currentProduct) {
|
|
408
408
|
tempProducts = [
|
|
409
409
|
{
|
|
410
|
-
...this.store.currentProduct
|
|
411
|
-
_schedule: this.store.
|
|
410
|
+
...this.store.currentProduct,
|
|
411
|
+
_schedule: (_a = this.store.currentProductMeta) == null ? void 0 : _a["schedule"]
|
|
412
412
|
}
|
|
413
413
|
];
|
|
414
414
|
}
|
|
415
415
|
let dateRange = this.store.date.getDateRange();
|
|
416
|
-
const tempStartDate = startDate || ((
|
|
417
|
-
const tempEndDate = endDate || ((
|
|
416
|
+
const tempStartDate = startDate || ((_b = dateRange == null ? void 0 : dateRange[0]) == null ? void 0 : _b.date);
|
|
417
|
+
const tempEndDate = endDate || ((_c = dateRange == null ? void 0 : dateRange[1]) == null ? void 0 : _c.date) || ((_d = dateRange == null ? void 0 : dateRange[0]) == null ? void 0 : _d.date);
|
|
418
418
|
if (!tempProducts.length) {
|
|
419
419
|
return [];
|
|
420
420
|
}
|
|
@@ -694,7 +694,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
694
694
|
}
|
|
695
695
|
if (!allOriginResources.length) {
|
|
696
696
|
const dateList = this.store.date.getDateList();
|
|
697
|
-
dateList.forEach((n) => {
|
|
697
|
+
dateList == null ? void 0 : dateList.forEach((n) => {
|
|
698
698
|
if (n.resource)
|
|
699
699
|
allOriginResources.push(...n.resource);
|
|
700
700
|
});
|
|
@@ -1599,15 +1599,17 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1599
1599
|
}
|
|
1600
1600
|
// 打开某个商品详情的弹窗,OS 层这边会记录当前选中的商品,适用于 session 类商品预约
|
|
1601
1601
|
async openProductDetail(productId) {
|
|
1602
|
-
const
|
|
1603
|
-
if (
|
|
1604
|
-
|
|
1605
|
-
this.store.
|
|
1602
|
+
const targetProductData = await this.store.products.getProduct(productId);
|
|
1603
|
+
if (targetProductData) {
|
|
1604
|
+
this.store.currentProduct = targetProductData;
|
|
1605
|
+
this.store.currentProductMeta = {};
|
|
1606
1606
|
if (targetProductData["schedule.ids"]) {
|
|
1607
1607
|
const newScheduleArr = this.getScheduleDataByIds(
|
|
1608
1608
|
targetProductData["schedule.ids"]
|
|
1609
1609
|
);
|
|
1610
|
-
|
|
1610
|
+
if (!this.store.currentProductMeta)
|
|
1611
|
+
this.store.currentProductMeta = {};
|
|
1612
|
+
this.store.currentProductMeta.schedule = newScheduleArr;
|
|
1611
1613
|
} else if (targetProductData.duration) {
|
|
1612
1614
|
const dateRange = this.store.date.getDateRange();
|
|
1613
1615
|
if (!(dateRange == null ? void 0 : dateRange.length))
|
|
@@ -1621,8 +1623,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1621
1623
|
}
|
|
1622
1624
|
}
|
|
1623
1625
|
closeProductDetail() {
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
+
if (this.store.currentProductMeta) {
|
|
1627
|
+
this.store.currentProductMeta.schedule = [];
|
|
1628
|
+
}
|
|
1626
1629
|
this.store.currentProduct = void 0;
|
|
1627
1630
|
}
|
|
1628
1631
|
getTimeslotBySchedule({
|
|
@@ -1631,9 +1634,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1631
1634
|
resources,
|
|
1632
1635
|
product
|
|
1633
1636
|
}) {
|
|
1634
|
-
var _a, _b, _c, _d, _e
|
|
1637
|
+
var _a, _b, _c, _d, _e;
|
|
1635
1638
|
const targetProduct = this.store.currentProduct;
|
|
1636
|
-
const targetProductData = product ||
|
|
1639
|
+
const targetProductData = product || targetProduct;
|
|
1637
1640
|
let targetSchedules = [];
|
|
1638
1641
|
if (scheduleIds == null ? void 0 : scheduleIds.length) {
|
|
1639
1642
|
targetSchedules = this.store.schedule.getScheduleListByIds(scheduleIds);
|
|
@@ -1653,7 +1656,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1653
1656
|
);
|
|
1654
1657
|
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
1655
1658
|
resourcesMap,
|
|
1656
|
-
resources || ((
|
|
1659
|
+
resources || ((_b = (_a = this.store.currentProduct) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) || [],
|
|
1657
1660
|
selectedResources,
|
|
1658
1661
|
1
|
|
1659
1662
|
);
|
|
@@ -1674,9 +1677,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1674
1677
|
return -1;
|
|
1675
1678
|
return 0;
|
|
1676
1679
|
});
|
|
1677
|
-
const firstEnabledResourceId = (
|
|
1680
|
+
const firstEnabledResourceId = (_e = (_d = (_c = targetProductData == null ? void 0 : targetProductData.product_resource) == null ? void 0 : _c.resources) == null ? void 0 : _d.find(
|
|
1678
1681
|
(n) => n.status === 1
|
|
1679
|
-
)) == null ? void 0 :
|
|
1682
|
+
)) == null ? void 0 : _e.id;
|
|
1680
1683
|
const formatScheduleTimeSlots = scheduleTimeSlots.map((item) => {
|
|
1681
1684
|
const resourcesUseableMap = {};
|
|
1682
1685
|
let count = 0;
|
|
@@ -1750,9 +1753,16 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1750
1753
|
return this.otherData[key];
|
|
1751
1754
|
}
|
|
1752
1755
|
async getProductTypeById(id) {
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
+
var _a;
|
|
1757
|
+
const productData = await this.store.products.getProduct(id);
|
|
1758
|
+
if (productData) {
|
|
1759
|
+
if (productData.duration) {
|
|
1760
|
+
return "duration";
|
|
1761
|
+
}
|
|
1762
|
+
if ((_a = productData["schedule.ids"]) == null ? void 0 : _a.length) {
|
|
1763
|
+
return "session";
|
|
1764
|
+
}
|
|
1765
|
+
return "normal";
|
|
1756
1766
|
}
|
|
1757
1767
|
return "normal";
|
|
1758
1768
|
}
|
|
@@ -1913,7 +1923,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1913
1923
|
return results;
|
|
1914
1924
|
}
|
|
1915
1925
|
async getAvailableDateForSessionOptimize(params = {}) {
|
|
1916
|
-
var _a, _b, _c, _d
|
|
1926
|
+
var _a, _b, _c, _d;
|
|
1917
1927
|
let { startDate, endDate } = params;
|
|
1918
1928
|
if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day") && ((0, import_dayjs.default)(endDate).isAfter((0, import_dayjs.default)(), "day") || (0, import_dayjs.default)(endDate).isSame((0, import_dayjs.default)(), "day"))) {
|
|
1919
1929
|
startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
|
|
@@ -1929,7 +1939,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1929
1939
|
tempEndDate = endDate || "";
|
|
1930
1940
|
}
|
|
1931
1941
|
endDate = tempEndDate;
|
|
1932
|
-
const cache = (_a = this.store.
|
|
1942
|
+
const cache = (_a = this.store.currentProductMeta) == null ? void 0 : _a["timeSlotBySchedule"];
|
|
1933
1943
|
if (cache) {
|
|
1934
1944
|
if ((0, import_dayjs.default)(params.startDate).isSameOrAfter((0, import_dayjs.default)(cache.startDate), "day") && (0, import_dayjs.default)(params.endDate).isSameOrBefore((0, import_dayjs.default)(cache.endDate), "day")) {
|
|
1935
1945
|
this.store.date.setDateList(cache.dateList);
|
|
@@ -1940,8 +1950,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1940
1950
|
}
|
|
1941
1951
|
}
|
|
1942
1952
|
let tempProducts;
|
|
1943
|
-
tempProducts =
|
|
1944
|
-
const schedule = (
|
|
1953
|
+
tempProducts = this.store.currentProduct;
|
|
1954
|
+
const schedule = (_b = this.store.currentProductMeta) == null ? void 0 : _b["schedule"];
|
|
1945
1955
|
const filteredSchedule = (0, import_resources.filterScheduleByDateRange)(
|
|
1946
1956
|
schedule,
|
|
1947
1957
|
startDate || "",
|
|
@@ -1958,7 +1968,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1958
1968
|
let dates = [];
|
|
1959
1969
|
let currentDate = (0, import_dayjs.default)(startDate);
|
|
1960
1970
|
let firstAvailableDate = "";
|
|
1961
|
-
const openResources = ((
|
|
1971
|
+
const openResources = ((_d = (_c = tempProducts == null ? void 0 : tempProducts.product_resource) == null ? void 0 : _c.resources) == null ? void 0 : _d.filter(
|
|
1962
1972
|
(m) => m.status === 1
|
|
1963
1973
|
)) || [];
|
|
1964
1974
|
const allProductResources = (0, import_resources.sortCombinedResources)(res.data);
|
|
@@ -2059,12 +2069,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2059
2069
|
}
|
|
2060
2070
|
dates = (0, import_utils3.handleAvailableDateByResource)(res.data, dates);
|
|
2061
2071
|
this.store.date.setDateList(dates);
|
|
2062
|
-
(
|
|
2072
|
+
if (!this.store.currentProductMeta)
|
|
2073
|
+
this.store.currentProductMeta = {};
|
|
2074
|
+
this.store.currentProductMeta.timeSlotBySchedule = {
|
|
2063
2075
|
dateList: dates,
|
|
2064
2076
|
firstAvailableDate,
|
|
2065
2077
|
startDate,
|
|
2066
2078
|
endDate: (0, import_dayjs.default)(currentDate).format("YYYY-MM-DD")
|
|
2067
|
-
}
|
|
2079
|
+
};
|
|
2068
2080
|
return {
|
|
2069
2081
|
dateList: dates,
|
|
2070
2082
|
firstAvailableDate
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ProductList, CartModule,
|
|
1
|
+
import { ProductList, CartModule, ProductData, AccountModule, AccountListModule, DateModule, GuestListModule, OrderModule, PaymentModule, ResourceListModule, StepModule, SummaryModule, ScheduleModule } from '../../modules';
|
|
2
2
|
export interface BookingByStepState {
|
|
3
3
|
cart: CartModule;
|
|
4
4
|
summary: SummaryModule;
|
|
@@ -11,7 +11,8 @@ export interface BookingByStepState {
|
|
|
11
11
|
accountList: AccountListModule;
|
|
12
12
|
order: OrderModule;
|
|
13
13
|
payment: PaymentModule;
|
|
14
|
-
currentProduct?:
|
|
14
|
+
currentProduct?: ProductData;
|
|
15
|
+
currentProductMeta?: Record<string, any>;
|
|
15
16
|
schedule: ScheduleModule;
|
|
16
17
|
}
|
|
17
18
|
export declare function createModule<T extends keyof BookingByStepState>(moduleName: T, solutionName: string, name?: string, version?: string): BookingByStepState[T];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Module, PisellCore } from '../../types';
|
|
2
|
-
import {
|
|
2
|
+
import { ProductData } from '../../modules/';
|
|
3
3
|
import { BaseModule } from '../../modules/BaseModule';
|
|
4
4
|
export * from './types';
|
|
5
5
|
export declare class BuyTicketsImpl extends BaseModule implements Module {
|
|
@@ -16,7 +16,7 @@ export declare class BuyTicketsImpl extends BaseModule implements Module {
|
|
|
16
16
|
loadProductsByCategory(categoryId: number): Promise<void>;
|
|
17
17
|
destroy(): Promise<void>;
|
|
18
18
|
getProducts(): Promise<ProductData[]>;
|
|
19
|
-
getProduct(id: number): Promise<
|
|
19
|
+
getProduct(id: number): Promise<ProductData>;
|
|
20
20
|
listSubmit(data: Record<string, any>): Promise<{
|
|
21
21
|
status: boolean;
|
|
22
22
|
data: any;
|
|
@@ -98,7 +98,7 @@ var BuyTicketsImpl = class extends import_BaseModule.BaseModule {
|
|
|
98
98
|
return mainProduct;
|
|
99
99
|
if (otherProduct)
|
|
100
100
|
return otherProduct;
|
|
101
|
-
|
|
101
|
+
throw new Error(`Product not found: ${id}`);
|
|
102
102
|
}
|
|
103
103
|
// 商品列表页提交
|
|
104
104
|
async listSubmit(data) {
|
|
@@ -34,7 +34,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
34
34
|
discountList: Discount[];
|
|
35
35
|
};
|
|
36
36
|
setProductList(productList: Record<string, any>[]): void;
|
|
37
|
-
scanCode(code: string): Promise<{
|
|
37
|
+
scanCode(code: string, customerId?: number): Promise<{
|
|
38
38
|
isAvailable: boolean;
|
|
39
39
|
productList: Record<string, any>[];
|
|
40
40
|
discountList: Discount[];
|
|
@@ -199,10 +199,10 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
199
199
|
this.store.productList = productList;
|
|
200
200
|
}
|
|
201
201
|
// 扫码输入code
|
|
202
|
-
async scanCode(code) {
|
|
202
|
+
async scanCode(code, customerId) {
|
|
203
203
|
var _a, _b;
|
|
204
204
|
try {
|
|
205
|
-
const resultDiscountList = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code)) || [];
|
|
205
|
+
const resultDiscountList = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, customerId)) || [];
|
|
206
206
|
const rulesModule = this.store.rules;
|
|
207
207
|
if (!rulesModule) {
|
|
208
208
|
return {
|