@pisell/pisellos 1.0.5 → 1.0.7
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/index.d.ts +14 -0
- package/dist/modules/Cart/index.js +36 -0
- package/dist/modules/Cart/utils/cartProduct.js +1 -1
- package/dist/modules/Cart/utils/changePrice.d.ts +3 -0
- package/dist/modules/Cart/utils/changePrice.js +100 -0
- package/dist/modules/Date/index.js +57 -6
- package/dist/modules/Discount/index.d.ts +1 -0
- package/dist/modules/Discount/index.js +15 -7
- package/dist/modules/Discount/types.d.ts +10 -0
- package/dist/modules/ProductList/index.d.ts +7 -0
- package/dist/modules/ProductList/index.js +102 -39
- package/dist/modules/Rules/index.js +59 -24
- package/dist/modules/Rules/types.d.ts +1 -0
- package/dist/modules/Schedule/index.d.ts +9 -1
- package/dist/modules/Schedule/index.js +121 -1
- package/dist/modules/Schedule/types.d.ts +13 -0
- package/dist/solution/BookingByStep/index.d.ts +120 -30
- package/dist/solution/BookingByStep/index.js +749 -1083
- package/dist/solution/BookingByStep/utils/capacity.d.ts +47 -0
- package/dist/solution/BookingByStep/utils/capacity.js +132 -0
- package/dist/solution/BookingByStep/utils/resources.d.ts +29 -31
- package/dist/solution/BookingByStep/utils/resources.js +39 -94
- package/dist/solution/BookingByStep/utils/timeslots.d.ts +11 -0
- package/dist/solution/BookingByStep/utils/timeslots.js +15 -0
- package/dist/solution/ShopDiscount/index.d.ts +1 -0
- package/dist/solution/ShopDiscount/index.js +63 -24
- package/lib/modules/Cart/index.d.ts +14 -0
- package/lib/modules/Cart/index.js +32 -0
- package/lib/modules/Cart/utils/cartProduct.js +1 -1
- package/lib/modules/Cart/utils/changePrice.d.ts +3 -0
- package/lib/modules/Cart/utils/changePrice.js +64 -0
- package/lib/modules/Date/index.js +62 -10
- package/lib/modules/Discount/index.d.ts +1 -0
- package/lib/modules/Discount/index.js +18 -6
- package/lib/modules/Discount/types.d.ts +10 -0
- package/lib/modules/ProductList/index.d.ts +7 -0
- package/lib/modules/ProductList/index.js +45 -0
- package/lib/modules/Rules/index.js +59 -22
- package/lib/modules/Rules/types.d.ts +1 -0
- package/lib/modules/Schedule/index.d.ts +9 -1
- package/lib/modules/Schedule/index.js +78 -0
- package/lib/modules/Schedule/types.d.ts +13 -0
- package/lib/solution/BookingByStep/index.d.ts +120 -30
- package/lib/solution/BookingByStep/index.js +379 -581
- package/lib/solution/BookingByStep/utils/capacity.d.ts +47 -0
- package/lib/solution/BookingByStep/utils/capacity.js +106 -0
- package/lib/solution/BookingByStep/utils/resources.d.ts +29 -31
- package/lib/solution/BookingByStep/utils/resources.js +23 -59
- package/lib/solution/BookingByStep/utils/timeslots.d.ts +11 -0
- package/lib/solution/BookingByStep/utils/timeslots.js +7 -0
- package/lib/solution/ShopDiscount/index.d.ts +1 -0
- package/lib/solution/ShopDiscount/index.js +68 -18
- package/package.json +1 -1
|
@@ -97,15 +97,78 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
97
97
|
return storeChange;
|
|
98
98
|
}()
|
|
99
99
|
}, {
|
|
100
|
-
key: "
|
|
100
|
+
key: "loadProducts",
|
|
101
101
|
value: function () {
|
|
102
|
-
var
|
|
103
|
-
var _ref$
|
|
102
|
+
var _loadProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref) {
|
|
103
|
+
var _ref$category_ids, category_ids, _ref$product_ids, product_ids, _ref$collection, collection, schedule_date, cacheId, userPlugin, customer_id, _userPlugin$get, productsData;
|
|
104
104
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
105
105
|
while (1) switch (_context3.prev = _context3.next) {
|
|
106
106
|
case 0:
|
|
107
|
-
_ref$
|
|
108
|
-
|
|
107
|
+
_ref$category_ids = _ref.category_ids, category_ids = _ref$category_ids === void 0 ? [] : _ref$category_ids, _ref$product_ids = _ref.product_ids, product_ids = _ref$product_ids === void 0 ? [] : _ref$product_ids, _ref$collection = _ref.collection, collection = _ref$collection === void 0 ? [] : _ref$collection, schedule_date = _ref.schedule_date, cacheId = _ref.cacheId;
|
|
108
|
+
// // 如果 schedule_ids 为空,则需要尝试从 schedule 模块里获取
|
|
109
|
+
// if (!schedule_ids?.length) {
|
|
110
|
+
// const schedule_ids_data = this.store.schedule
|
|
111
|
+
// .getScheduleListByIds(schedule_ids)
|
|
112
|
+
// .map((n) => n.id);
|
|
113
|
+
// if (schedule_ids_data.length) {
|
|
114
|
+
// schedule_ids = schedule_ids_data;
|
|
115
|
+
// } else if (schedule_date) {
|
|
116
|
+
// // 后端说如果 schedule_ids 如果为空,需要给[0]
|
|
117
|
+
// schedule_ids = [0];
|
|
118
|
+
// }
|
|
119
|
+
// }
|
|
120
|
+
userPlugin = this.core.getPlugin('user');
|
|
121
|
+
customer_id = undefined;
|
|
122
|
+
try {
|
|
123
|
+
customer_id = userPlugin === null || userPlugin === void 0 || (_userPlugin$get = userPlugin.get()) === null || _userPlugin$get === void 0 ? void 0 : _userPlugin$get.id;
|
|
124
|
+
} catch (error) {
|
|
125
|
+
console.error(error);
|
|
126
|
+
}
|
|
127
|
+
// 如果没传schedule_date,则从
|
|
128
|
+
_context3.next = 6;
|
|
129
|
+
return this.request.post("/product/query", {
|
|
130
|
+
open_quotation: 1,
|
|
131
|
+
open_bundle: 0,
|
|
132
|
+
exclude_extension_type: ['product_party', 'product_event', 'product_series_event', 'product_package_ticket', 'ticket', 'event_item'],
|
|
133
|
+
with: ['category', 'collection', 'resourceRelation'],
|
|
134
|
+
status: 'published',
|
|
135
|
+
num: 500,
|
|
136
|
+
skip: 1,
|
|
137
|
+
customer_id: customer_id,
|
|
138
|
+
category_ids: category_ids,
|
|
139
|
+
ids: product_ids,
|
|
140
|
+
collection: collection,
|
|
141
|
+
front_end_cache_id: cacheId,
|
|
142
|
+
// client_schedule_ids: schedule_ids,
|
|
143
|
+
schedule_date: schedule_date
|
|
144
|
+
}, {
|
|
145
|
+
useCache: true
|
|
146
|
+
});
|
|
147
|
+
case 6:
|
|
148
|
+
productsData = _context3.sent;
|
|
149
|
+
this.addProduct(productsData.data.list);
|
|
150
|
+
return _context3.abrupt("return", productsData.data.list);
|
|
151
|
+
case 9:
|
|
152
|
+
case "end":
|
|
153
|
+
return _context3.stop();
|
|
154
|
+
}
|
|
155
|
+
}, _callee3, this);
|
|
156
|
+
}));
|
|
157
|
+
function loadProducts(_x5) {
|
|
158
|
+
return _loadProducts.apply(this, arguments);
|
|
159
|
+
}
|
|
160
|
+
return loadProducts;
|
|
161
|
+
}()
|
|
162
|
+
}, {
|
|
163
|
+
key: "loadProductsPrice",
|
|
164
|
+
value: function () {
|
|
165
|
+
var _loadProductsPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref2) {
|
|
166
|
+
var _ref2$ids, ids, customer_id, schedule_date, channel, productsData;
|
|
167
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
168
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
169
|
+
case 0:
|
|
170
|
+
_ref2$ids = _ref2.ids, ids = _ref2$ids === void 0 ? [] : _ref2$ids, customer_id = _ref2.customer_id, schedule_date = _ref2.schedule_date, channel = _ref2.channel;
|
|
171
|
+
_context4.next = 3;
|
|
109
172
|
return this.request.post("/product/query/price", {
|
|
110
173
|
ids: ids,
|
|
111
174
|
customer_id: customer_id,
|
|
@@ -115,15 +178,15 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
115
178
|
useCache: true
|
|
116
179
|
});
|
|
117
180
|
case 3:
|
|
118
|
-
productsData =
|
|
119
|
-
return
|
|
181
|
+
productsData = _context4.sent;
|
|
182
|
+
return _context4.abrupt("return", productsData.data);
|
|
120
183
|
case 5:
|
|
121
184
|
case "end":
|
|
122
|
-
return
|
|
185
|
+
return _context4.stop();
|
|
123
186
|
}
|
|
124
|
-
},
|
|
187
|
+
}, _callee4, this);
|
|
125
188
|
}));
|
|
126
|
-
function loadProductsPrice(
|
|
189
|
+
function loadProductsPrice(_x6) {
|
|
127
190
|
return _loadProductsPrice.apply(this, arguments);
|
|
128
191
|
}
|
|
129
192
|
return loadProductsPrice;
|
|
@@ -131,19 +194,19 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
131
194
|
}, {
|
|
132
195
|
key: "getProducts",
|
|
133
196
|
value: function () {
|
|
134
|
-
var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
135
|
-
return _regeneratorRuntime().wrap(function
|
|
136
|
-
while (1) switch (
|
|
197
|
+
var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
198
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
199
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
137
200
|
case 0:
|
|
138
|
-
|
|
201
|
+
_context5.next = 2;
|
|
139
202
|
return this.core.effects.emit(ProductListHooks.onGetProducts, this.store.list);
|
|
140
203
|
case 2:
|
|
141
|
-
return
|
|
204
|
+
return _context5.abrupt("return", cloneDeep(this.store.list));
|
|
142
205
|
case 3:
|
|
143
206
|
case "end":
|
|
144
|
-
return
|
|
207
|
+
return _context5.stop();
|
|
145
208
|
}
|
|
146
|
-
},
|
|
209
|
+
}, _callee5, this);
|
|
147
210
|
}));
|
|
148
211
|
function getProducts() {
|
|
149
212
|
return _getProducts.apply(this, arguments);
|
|
@@ -153,29 +216,29 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
153
216
|
}, {
|
|
154
217
|
key: "getProduct",
|
|
155
218
|
value: function () {
|
|
156
|
-
var _getProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
219
|
+
var _getProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(id) {
|
|
157
220
|
var product;
|
|
158
|
-
return _regeneratorRuntime().wrap(function
|
|
159
|
-
while (1) switch (
|
|
221
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
222
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
160
223
|
case 0:
|
|
161
|
-
|
|
224
|
+
_context6.next = 2;
|
|
162
225
|
return this.core.effects.emit(ProductListHooks.onGetProduct, this.store.list);
|
|
163
226
|
case 2:
|
|
164
227
|
product = this.store.productMap.get("".concat(id));
|
|
165
228
|
if (!product) {
|
|
166
|
-
|
|
229
|
+
_context6.next = 5;
|
|
167
230
|
break;
|
|
168
231
|
}
|
|
169
|
-
return
|
|
232
|
+
return _context6.abrupt("return", product);
|
|
170
233
|
case 5:
|
|
171
|
-
return
|
|
234
|
+
return _context6.abrupt("return", undefined);
|
|
172
235
|
case 6:
|
|
173
236
|
case "end":
|
|
174
|
-
return
|
|
237
|
+
return _context6.stop();
|
|
175
238
|
}
|
|
176
|
-
},
|
|
239
|
+
}, _callee6, this);
|
|
177
240
|
}));
|
|
178
|
-
function getProduct(
|
|
241
|
+
function getProduct(_x7) {
|
|
179
242
|
return _getProduct.apply(this, arguments);
|
|
180
243
|
}
|
|
181
244
|
return getProduct;
|
|
@@ -183,10 +246,10 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
183
246
|
}, {
|
|
184
247
|
key: "addProduct",
|
|
185
248
|
value: function () {
|
|
186
|
-
var _addProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
249
|
+
var _addProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(products) {
|
|
187
250
|
var _this3 = this;
|
|
188
|
-
return _regeneratorRuntime().wrap(function
|
|
189
|
-
while (1) switch (
|
|
251
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
252
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
190
253
|
case 0:
|
|
191
254
|
// 加到 list 以后上面的storeChange 会自动初始化商品详情的 module 实例
|
|
192
255
|
// list 需要根据 id 去重
|
|
@@ -206,11 +269,11 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
206
269
|
this.storeChange();
|
|
207
270
|
case 3:
|
|
208
271
|
case "end":
|
|
209
|
-
return
|
|
272
|
+
return _context7.stop();
|
|
210
273
|
}
|
|
211
|
-
},
|
|
274
|
+
}, _callee7, this);
|
|
212
275
|
}));
|
|
213
|
-
function addProduct(
|
|
276
|
+
function addProduct(_x8) {
|
|
214
277
|
return _addProduct.apply(this, arguments);
|
|
215
278
|
}
|
|
216
279
|
return addProduct;
|
|
@@ -218,18 +281,18 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
|
|
|
218
281
|
}, {
|
|
219
282
|
key: "selectProducts",
|
|
220
283
|
value: function () {
|
|
221
|
-
var _selectProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
222
|
-
return _regeneratorRuntime().wrap(function
|
|
223
|
-
while (1) switch (
|
|
284
|
+
var _selectProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(products) {
|
|
285
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
286
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
224
287
|
case 0:
|
|
225
288
|
this.store.selectProducts = products;
|
|
226
289
|
case 1:
|
|
227
290
|
case "end":
|
|
228
|
-
return
|
|
291
|
+
return _context8.stop();
|
|
229
292
|
}
|
|
230
|
-
},
|
|
293
|
+
}, _callee8, this);
|
|
231
294
|
}));
|
|
232
|
-
function selectProducts(
|
|
295
|
+
function selectProducts(_x9) {
|
|
233
296
|
return _selectProducts.apply(this, arguments);
|
|
234
297
|
}
|
|
235
298
|
return selectProducts;
|
|
@@ -27,6 +27,7 @@ import { BaseModule } from "../BaseModule";
|
|
|
27
27
|
import { RulesHooks } from "./types";
|
|
28
28
|
import { uniqueById } from "../../solution/ShopDiscount/utils";
|
|
29
29
|
import { getProductOriginTotalPrice, getProductTotalPrice } from "../Cart/utils";
|
|
30
|
+
import Decimal from 'decimal.js';
|
|
30
31
|
export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
31
32
|
_inherits(RulesModule, _BaseModule);
|
|
32
33
|
var _super = _createSuper(RulesModule);
|
|
@@ -163,24 +164,49 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
163
164
|
return !discount.isManualSelect;
|
|
164
165
|
});
|
|
165
166
|
|
|
166
|
-
//
|
|
167
|
+
// 优惠力度排序,传进来的数据里可能有商品券,也可能有优惠券
|
|
168
|
+
// 商品券(n.tag=good_pass)视为最优惠(免费),折扣券(n.tag=product_discount_card)按照n.par_value排序
|
|
169
|
+
// 如果最后拍出来商品券有多个,或者说没有商品券,但是有多个相同折扣的折扣券(比如 6 折券有 3张),则按照过期时间(n.expire_time)排序
|
|
167
170
|
var sortedDiscountList = _toConsumableArray(filteredDiscountList).sort(function (a, b) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
171
|
+
// 1. 商品券优先级最高
|
|
172
|
+
if (a.tag === 'good_pass' && b.tag !== 'good_pass') return -1;
|
|
173
|
+
if (b.tag === 'good_pass' && a.tag !== 'good_pass') return 1;
|
|
174
|
+
|
|
175
|
+
// 2. 如果都是商品券或都不是商品券,按照类型和折扣力度排序
|
|
176
|
+
if (a.tag === 'good_pass' && b.tag === 'good_pass') {
|
|
177
|
+
// 都是商品券,按照过期时间排序
|
|
178
|
+
return compareByExpireTime(a, b);
|
|
179
|
+
} else if (a.tag === 'product_discount_card' && b.tag === 'product_discount_card') {
|
|
180
|
+
// 都是折扣券,按照par_value排序(折扣越大越优先,即par_value越小越优先)
|
|
181
|
+
if (a.par_value !== b.par_value) {
|
|
182
|
+
var valueA = new Decimal(100).minus(a.par_value || 0);
|
|
183
|
+
var valueB = new Decimal(100).minus(b.par_value || 0);
|
|
184
|
+
return valueA.minus(valueB).toNumber();
|
|
185
|
+
}
|
|
186
|
+
// 相同折扣的情况下,按照过期时间排序
|
|
187
|
+
return compareByExpireTime(a, b);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// 3. 其他情况按照过期时间排序
|
|
191
|
+
return compareByExpireTime(a, b);
|
|
192
|
+
function compareByExpireTime(itemA, itemB) {
|
|
193
|
+
if (itemA.expire_time && itemB.expire_time) {
|
|
194
|
+
var timeA = new Date(itemA.expire_time).getTime();
|
|
195
|
+
var timeB = new Date(itemB.expire_time).getTime();
|
|
196
|
+
return timeA - timeB;
|
|
197
|
+
}
|
|
198
|
+
// 有过期时间的优先级高于永久的
|
|
199
|
+
return itemA.expire_time ? -1 : itemB.expire_time ? 1 : 0;
|
|
172
200
|
}
|
|
173
|
-
// 有过期时间的优先级高于永久的
|
|
174
|
-
return a.expire_time ? -1 : b.expire_time ? 1 : 0;
|
|
175
201
|
});
|
|
176
202
|
|
|
177
203
|
// 对productList按价格降序排序(用于应用优惠券时优先选择高价商品)
|
|
178
204
|
var sortedProductList = _toConsumableArray(productList).sort(function (a, b) {
|
|
179
205
|
var aProduct = _this3.hooks.getProduct(a);
|
|
180
206
|
var bProduct = _this3.hooks.getProduct(b);
|
|
181
|
-
var priceA =
|
|
182
|
-
var priceB =
|
|
183
|
-
return priceB
|
|
207
|
+
var priceA = new Decimal(aProduct.price || '0');
|
|
208
|
+
var priceB = new Decimal(bProduct.price || '0');
|
|
209
|
+
return priceB.minus(priceA).toNumber();
|
|
184
210
|
});
|
|
185
211
|
|
|
186
212
|
// 标记已使用的优惠券
|
|
@@ -216,7 +242,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
216
242
|
|
|
217
243
|
// 编辑的商品 使用了优惠券不可用
|
|
218
244
|
var isAvailableProduct = !(product !== null && product !== void 0 && product.booking_id && product !== null && product !== void 0 && (_product$discount_lis = product.discount_list) !== null && _product$discount_lis !== void 0 && _product$discount_lis.length && product !== null && product !== void 0 && (_product$discount_lis2 = product.discount_list) !== null && _product$discount_lis2 !== void 0 && _product$discount_lis2.every(function (discount) {
|
|
219
|
-
return discount.id &&
|
|
245
|
+
return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag);
|
|
220
246
|
}));
|
|
221
247
|
|
|
222
248
|
// 判断优惠券是否适用于该商品
|
|
@@ -233,8 +259,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
233
259
|
discount: {
|
|
234
260
|
resource_id: discount.id,
|
|
235
261
|
title: discount.format_title,
|
|
236
|
-
original_amount: product.origin_total
|
|
237
|
-
|
|
262
|
+
original_amount: product.origin_total,
|
|
263
|
+
pre_value: discount.par_value,
|
|
264
|
+
product_id: originProduct.id
|
|
265
|
+
},
|
|
266
|
+
num: product.num || 1
|
|
238
267
|
});
|
|
239
268
|
discountApplicableProducts.set(discount.id, applicableProducts);
|
|
240
269
|
}
|
|
@@ -246,7 +275,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
246
275
|
var _product$discount_lis3, _product$discount_lis4, _product$discount_lis5, _product$discount_lis6, _product$discount_lis7;
|
|
247
276
|
var product = _this3.hooks.getProduct(originProduct);
|
|
248
277
|
if (product !== null && product !== void 0 && product.booking_id && (_product$discount_lis3 = product.discount_list) !== null && _product$discount_lis3 !== void 0 && _product$discount_lis3.length && product !== null && product !== void 0 && (_product$discount_lis4 = product.discount_list) !== null && _product$discount_lis4 !== void 0 && _product$discount_lis4.every(function (discount) {
|
|
249
|
-
return discount.id &&
|
|
278
|
+
return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag);
|
|
250
279
|
})) {
|
|
251
280
|
processedProductsMap.set(product._id, originProduct);
|
|
252
281
|
return;
|
|
@@ -254,8 +283,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
254
283
|
|
|
255
284
|
// 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
|
|
256
285
|
var applicableDiscounts = sortedDiscountList.filter(function (discount) {
|
|
286
|
+
// 如果商品价格为 0,其实不需要使用任何优惠券,直接 return true
|
|
287
|
+
if (Number(product.price) === 0 || !product.price) return false;
|
|
257
288
|
// 如果优惠券已被使用,则跳过
|
|
258
|
-
|
|
289
|
+
var targetUsedDiscounts = usedDiscounts.get(discount.id);
|
|
290
|
+
if (targetUsedDiscounts && discount.tag === 'good_pass') return false;
|
|
259
291
|
var limitedData = discount.limited_relation_product_data;
|
|
260
292
|
|
|
261
293
|
// 判断优惠券是否适用于该商品
|
|
@@ -321,15 +353,18 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
321
353
|
|
|
322
354
|
// 记录实际应用了优惠券的商品信息
|
|
323
355
|
var appliedProducts = appliedDiscountProducts.get(selectedDiscount.id) || [];
|
|
356
|
+
var targetProductPrice = selectedDiscount.tag === 'good_pass' ? '0' : new Decimal(100).minus(selectedDiscount.par_value || 0).div(100).mul(new Decimal(product.price || 0)).toFixed(2);
|
|
324
357
|
var discountDetail = {
|
|
325
|
-
amount: product.price,
|
|
326
|
-
type: selectedDiscount.tag,
|
|
358
|
+
amount: selectedDiscount.tag === 'product_discount_card' ? new Decimal(product.price || 0).minus(new Decimal(targetProductPrice)).toNumber() : product.price,
|
|
359
|
+
type: selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : selectedDiscount.tag,
|
|
327
360
|
discount: {
|
|
328
361
|
resource_id: selectedDiscount.id,
|
|
329
362
|
title: selectedDiscount.format_title,
|
|
330
|
-
original_amount: product.
|
|
331
|
-
product_id:
|
|
332
|
-
|
|
363
|
+
original_amount: product.price,
|
|
364
|
+
product_id: originProduct.id,
|
|
365
|
+
percent: selectedDiscount.par_value
|
|
366
|
+
},
|
|
367
|
+
num: product.num || 1
|
|
333
368
|
};
|
|
334
369
|
appliedProducts.push(discountDetail);
|
|
335
370
|
appliedDiscountProducts.set(selectedDiscount.id, appliedProducts);
|
|
@@ -339,7 +374,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
339
374
|
if (product.isClient) {
|
|
340
375
|
processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, {
|
|
341
376
|
discount_list: [discountDetail],
|
|
342
|
-
price:
|
|
377
|
+
price: new Decimal(targetProductPrice).toNumber(),
|
|
343
378
|
origin_total: getProductOriginTotalPrice({
|
|
344
379
|
product: {
|
|
345
380
|
original_price: product.original_price
|
|
@@ -349,7 +384,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
349
384
|
}),
|
|
350
385
|
total: getProductTotalPrice({
|
|
351
386
|
product: {
|
|
352
|
-
price:
|
|
387
|
+
price: targetProductPrice
|
|
353
388
|
},
|
|
354
389
|
bundle: product.bundle,
|
|
355
390
|
options: product.options
|
|
@@ -358,8 +393,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
358
393
|
} else {
|
|
359
394
|
processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, {
|
|
360
395
|
discount_list: [discountDetail],
|
|
361
|
-
price:
|
|
362
|
-
total: (product.origin_total || product.total)
|
|
396
|
+
price: new Decimal(targetProductPrice).toNumber(),
|
|
397
|
+
total: new Decimal(product.origin_total || product.total || 0).minus(new Decimal(product.price || 0).minus(new Decimal(targetProductPrice))).toNumber(),
|
|
363
398
|
origin_total: product.origin_total || product.total
|
|
364
399
|
}));
|
|
365
400
|
}
|
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import { Module, PisellCore, ModuleOptions } from '../../types';
|
|
2
2
|
import { BaseModule } from '../BaseModule';
|
|
3
|
-
import { ScheduleModuleAPI, ScheduleAvailabilityDateItem, ScheduleItem } from './types';
|
|
3
|
+
import { ScheduleModuleAPI, ScheduleAvailabilityDateItem, ScheduleItem, LoadScheduleAvailableDateParams } from './types';
|
|
4
4
|
export declare class ScheduleModule extends BaseModule implements Module, ScheduleModuleAPI {
|
|
5
5
|
protected defaultName: string;
|
|
6
6
|
protected defaultVersion: string;
|
|
7
|
+
private request;
|
|
7
8
|
private store;
|
|
8
9
|
private cacheId;
|
|
9
10
|
private openCache;
|
|
10
11
|
private fatherModule;
|
|
11
12
|
constructor(name?: string, version?: string);
|
|
12
13
|
initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* 加载当前店铺下所有 schedule
|
|
16
|
+
*
|
|
17
|
+
* @memberof ScheduleModule
|
|
18
|
+
*/
|
|
19
|
+
loadAllSchedule(): Promise<void>;
|
|
13
20
|
setScheduleList(list: ScheduleItem[]): void;
|
|
21
|
+
loadScheduleAvailableDate({ startDate, endDate, custom_page_id, channel, }: LoadScheduleAvailableDateParams): Promise<import("../Date/types").ITime[]>;
|
|
14
22
|
getScheduleListByIds(ids: number[]): ScheduleItem[];
|
|
15
23
|
setAvailabilityScheduleDateList(list: ScheduleAvailabilityDateItem[]): void;
|
|
16
24
|
getAvailabilityScheduleDateList(): ScheduleAvailabilityDateItem[];
|
|
@@ -17,6 +17,12 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
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 { cloneDeep } from 'lodash-es';
|
|
19
19
|
import { BaseModule } from "../BaseModule";
|
|
20
|
+
import dayjs from 'dayjs';
|
|
21
|
+
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
|
|
22
|
+
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
|
|
23
|
+
import { generateMonthDates, disableAllDates, disableDatesBeforeOneDay } from "../Date/utils";
|
|
24
|
+
dayjs.extend(isSameOrBefore);
|
|
25
|
+
dayjs.extend(isSameOrAfter);
|
|
20
26
|
export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
|
|
21
27
|
_inherits(ScheduleModule, _BaseModule);
|
|
22
28
|
var _super = _createSuper(ScheduleModule);
|
|
@@ -26,6 +32,7 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
26
32
|
_this = _super.call(this, name, version);
|
|
27
33
|
_defineProperty(_assertThisInitialized(_this), "defaultName", 'schedule');
|
|
28
34
|
_defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
|
|
35
|
+
_defineProperty(_assertThisInitialized(_this), "request", void 0);
|
|
29
36
|
_defineProperty(_assertThisInitialized(_this), "store", {});
|
|
30
37
|
_defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
|
|
31
38
|
_defineProperty(_assertThisInitialized(_this), "openCache", false);
|
|
@@ -41,6 +48,15 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
41
48
|
while (1) switch (_context.prev = _context.next) {
|
|
42
49
|
case 0:
|
|
43
50
|
this.core = core;
|
|
51
|
+
|
|
52
|
+
// 获取依赖的插件
|
|
53
|
+
this.request = core.getPlugin('request');
|
|
54
|
+
if (this.request) {
|
|
55
|
+
_context.next = 4;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
throw new Error('ScheduleModule 需要 request 插件支持');
|
|
59
|
+
case 4:
|
|
44
60
|
// if (options?.initialState) {
|
|
45
61
|
// this.state = { ...this.state, ...options.initialState }
|
|
46
62
|
// }
|
|
@@ -59,7 +75,7 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
59
75
|
if ((_options$otherParams2 = options.otherParams) !== null && _options$otherParams2 !== void 0 && _options$otherParams2.fatherModule) {
|
|
60
76
|
this.fatherModule = options.otherParams.fatherModule;
|
|
61
77
|
}
|
|
62
|
-
case
|
|
78
|
+
case 8:
|
|
63
79
|
case "end":
|
|
64
80
|
return _context.stop();
|
|
65
81
|
}
|
|
@@ -70,11 +86,115 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
70
86
|
}
|
|
71
87
|
return initialize;
|
|
72
88
|
}()
|
|
89
|
+
/**
|
|
90
|
+
* 加载当前店铺下所有 schedule
|
|
91
|
+
*
|
|
92
|
+
* @memberof ScheduleModule
|
|
93
|
+
*/
|
|
94
|
+
}, {
|
|
95
|
+
key: "loadAllSchedule",
|
|
96
|
+
value: (function () {
|
|
97
|
+
var _loadAllSchedule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
98
|
+
var _scheduleList$data;
|
|
99
|
+
var scheduleList;
|
|
100
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
101
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
102
|
+
case 0:
|
|
103
|
+
_context2.next = 2;
|
|
104
|
+
return this.request.get("/schedule", {
|
|
105
|
+
num: 999
|
|
106
|
+
}, {
|
|
107
|
+
useCache: true
|
|
108
|
+
});
|
|
109
|
+
case 2:
|
|
110
|
+
scheduleList = _context2.sent;
|
|
111
|
+
this.setScheduleList(((_scheduleList$data = scheduleList.data) === null || _scheduleList$data === void 0 ? void 0 : _scheduleList$data.list) || []);
|
|
112
|
+
case 4:
|
|
113
|
+
case "end":
|
|
114
|
+
return _context2.stop();
|
|
115
|
+
}
|
|
116
|
+
}, _callee2, this);
|
|
117
|
+
}));
|
|
118
|
+
function loadAllSchedule() {
|
|
119
|
+
return _loadAllSchedule.apply(this, arguments);
|
|
120
|
+
}
|
|
121
|
+
return loadAllSchedule;
|
|
122
|
+
}())
|
|
73
123
|
}, {
|
|
74
124
|
key: "setScheduleList",
|
|
75
125
|
value: function setScheduleList(list) {
|
|
76
126
|
this.store.scheduleList = list;
|
|
77
127
|
}
|
|
128
|
+
}, {
|
|
129
|
+
key: "loadScheduleAvailableDate",
|
|
130
|
+
value: function () {
|
|
131
|
+
var _loadScheduleAvailableDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref) {
|
|
132
|
+
var _res$data$date_list, _res$data$other_produ, _res$data$other_produ2;
|
|
133
|
+
var startDate, endDate, custom_page_id, channel, dates, res;
|
|
134
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
135
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
136
|
+
case 0:
|
|
137
|
+
startDate = _ref.startDate, endDate = _ref.endDate, custom_page_id = _ref.custom_page_id, channel = _ref.channel;
|
|
138
|
+
// 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天,需要把 startDate 置为今天
|
|
139
|
+
if (dayjs(startDate).isBefore(dayjs(), 'day')) {
|
|
140
|
+
startDate = dayjs().format('YYYY-MM-DD');
|
|
141
|
+
}
|
|
142
|
+
// 1.生成当前月份的所有日期,默认都不可用
|
|
143
|
+
dates = generateMonthDates(startDate, endDate);
|
|
144
|
+
dates = disableAllDates(dates);
|
|
145
|
+
// 如果 endDate 在今天之前,则不用查接口,直接返回 dates
|
|
146
|
+
if (!dayjs(endDate).isBefore(dayjs(), 'day')) {
|
|
147
|
+
_context3.next = 6;
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
return _context3.abrupt("return", dates);
|
|
151
|
+
case 6:
|
|
152
|
+
_context3.next = 8;
|
|
153
|
+
return this.request.get("/schedule/product/availability/v2", {
|
|
154
|
+
start_date: startDate,
|
|
155
|
+
end_date: endDate,
|
|
156
|
+
custom_page_id: custom_page_id,
|
|
157
|
+
channel: channel
|
|
158
|
+
});
|
|
159
|
+
case 8:
|
|
160
|
+
res = _context3.sent;
|
|
161
|
+
this.setAvailabilityScheduleDateList(res.data.date_list);
|
|
162
|
+
this.setOtherProductsIds(res.data.other_product_ids || []);
|
|
163
|
+
// 如果没有schedule或者结束日期在今天之前,则所有日期均不可用
|
|
164
|
+
if (!(!((_res$data$date_list = res.data.date_list) !== null && _res$data$date_list !== void 0 && _res$data$date_list.length) && !((_res$data$other_produ = res.data.other_product_ids) !== null && _res$data$other_produ !== void 0 && _res$data$other_produ.length) || dayjs(endDate).isBefore(dayjs(), 'day'))) {
|
|
165
|
+
_context3.next = 13;
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
return _context3.abrupt("return", dates);
|
|
169
|
+
case 13:
|
|
170
|
+
if ((_res$data$other_produ2 = res.data.other_product_ids) !== null && _res$data$other_produ2 !== void 0 && _res$data$other_produ2.length) {
|
|
171
|
+
// 如果后端有返回 other_product_ids ,意味着有 duration 商品,则今天以及今天以后的日期均可用
|
|
172
|
+
dates.forEach(function (n) {
|
|
173
|
+
n.status = 'available';
|
|
174
|
+
});
|
|
175
|
+
} else {
|
|
176
|
+
res.data.date_list.forEach(function (n) {
|
|
177
|
+
var index = dates.findIndex(function (m) {
|
|
178
|
+
return m.date === n.date;
|
|
179
|
+
});
|
|
180
|
+
if (index !== -1) {
|
|
181
|
+
dates[index].status = 'available';
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
dates = disableDatesBeforeOneDay(dates);
|
|
186
|
+
return _context3.abrupt("return", dates);
|
|
187
|
+
case 16:
|
|
188
|
+
case "end":
|
|
189
|
+
return _context3.stop();
|
|
190
|
+
}
|
|
191
|
+
}, _callee3, this);
|
|
192
|
+
}));
|
|
193
|
+
function loadScheduleAvailableDate(_x3) {
|
|
194
|
+
return _loadScheduleAvailableDate.apply(this, arguments);
|
|
195
|
+
}
|
|
196
|
+
return loadScheduleAvailableDate;
|
|
197
|
+
}()
|
|
78
198
|
}, {
|
|
79
199
|
key: "getScheduleListByIds",
|
|
80
200
|
value: function getScheduleListByIds(ids) {
|
|
@@ -9,6 +9,19 @@ export type ScheduleAvailabilityDateItem = {
|
|
|
9
9
|
schedule_id: number[];
|
|
10
10
|
product_ids: number[];
|
|
11
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* 加载日程可用日期参数接口
|
|
14
|
+
*/
|
|
15
|
+
export interface LoadScheduleAvailableDateParams {
|
|
16
|
+
/** 开始日期 */
|
|
17
|
+
startDate: string;
|
|
18
|
+
/** 结束日期 */
|
|
19
|
+
endDate: string;
|
|
20
|
+
/** 自定义页面ID */
|
|
21
|
+
custom_page_id?: number;
|
|
22
|
+
/** 渠道 */
|
|
23
|
+
channel?: string;
|
|
24
|
+
}
|
|
12
25
|
export interface ScheduleModuleAPI {
|
|
13
26
|
}
|
|
14
27
|
export type ScheduleItem = {
|