@pisell/pisellos 1.0.0 → 1.0.1
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 +0 -14
- package/dist/modules/Cart/index.js +0 -36
- package/dist/modules/Cart/utils/cartProduct.js +1 -10
- package/dist/modules/Date/index.js +6 -57
- package/dist/modules/Discount/index.d.ts +0 -1
- package/dist/modules/Discount/index.js +7 -15
- package/dist/modules/Discount/types.d.ts +0 -10
- package/dist/modules/ProductList/index.d.ts +0 -7
- package/dist/modules/ProductList/index.js +39 -102
- package/dist/modules/Rules/index.js +71 -196
- package/dist/modules/Rules/types.d.ts +0 -6
- package/dist/modules/Schedule/index.d.ts +1 -9
- package/dist/modules/Schedule/index.js +2 -122
- package/dist/modules/Schedule/types.d.ts +0 -13
- package/dist/solution/BookingByStep/index.d.ts +30 -120
- package/dist/solution/BookingByStep/index.js +1065 -750
- package/dist/solution/BookingByStep/utils/resources.d.ts +31 -29
- package/dist/solution/BookingByStep/utils/resources.js +94 -39
- package/dist/solution/BookingByStep/utils/timeslots.d.ts +0 -11
- package/dist/solution/BookingByStep/utils/timeslots.js +0 -15
- package/dist/solution/ShopDiscount/index.d.ts +0 -2
- package/dist/solution/ShopDiscount/index.js +32 -93
- package/lib/modules/Cart/index.d.ts +0 -14
- package/lib/modules/Cart/index.js +0 -32
- package/lib/modules/Cart/utils/cartProduct.js +1 -1
- package/lib/modules/Date/index.js +10 -62
- package/lib/modules/Discount/index.d.ts +0 -1
- package/lib/modules/Discount/index.js +6 -18
- package/lib/modules/Discount/types.d.ts +0 -10
- package/lib/modules/ProductList/index.d.ts +0 -7
- package/lib/modules/ProductList/index.js +0 -45
- package/lib/modules/Rules/index.js +56 -147
- package/lib/modules/Rules/types.d.ts +0 -6
- package/lib/modules/Schedule/index.d.ts +1 -9
- package/lib/modules/Schedule/index.js +1 -79
- package/lib/modules/Schedule/types.d.ts +0 -13
- package/lib/solution/BookingByStep/index.d.ts +30 -120
- package/lib/solution/BookingByStep/index.js +581 -392
- package/lib/solution/BookingByStep/utils/resources.d.ts +31 -29
- package/lib/solution/BookingByStep/utils/resources.js +59 -23
- package/lib/solution/BookingByStep/utils/timeslots.d.ts +0 -11
- package/lib/solution/BookingByStep/utils/timeslots.js +0 -7
- package/lib/solution/ShopDiscount/index.d.ts +0 -2
- package/lib/solution/ShopDiscount/index.js +18 -85
- package/package.json +1 -1
- package/dist/modules/Cart/utils/changePrice.d.ts +0 -3
- package/dist/modules/Cart/utils/changePrice.js +0 -104
- package/dist/solution/BookingByStep/utils/capacity.d.ts +0 -47
- package/dist/solution/BookingByStep/utils/capacity.js +0 -132
- package/lib/modules/Cart/utils/changePrice.d.ts +0 -3
- package/lib/modules/Cart/utils/changePrice.js +0 -78
- package/lib/solution/BookingByStep/utils/capacity.d.ts +0 -47
- package/lib/solution/BookingByStep/utils/capacity.js +0 -106
|
@@ -27,7 +27,6 @@ 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';
|
|
31
30
|
export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
32
31
|
_inherits(RulesModule, _BaseModule);
|
|
33
32
|
var _super = _createSuper(RulesModule);
|
|
@@ -107,18 +106,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
107
106
|
};
|
|
108
107
|
}
|
|
109
108
|
|
|
110
|
-
// 编辑商品已有商品券
|
|
111
|
-
if (productList.every(function (item) {
|
|
112
|
-
var _item$discount_list;
|
|
113
|
-
return item.booking_id && (((_item$discount_list = item.discount_list) === null || _item$discount_list === void 0 ? void 0 : _item$discount_list.length) || item.price == 0);
|
|
114
|
-
})) {
|
|
115
|
-
return {
|
|
116
|
-
isAvailable: false,
|
|
117
|
-
discountList: oldDiscountList,
|
|
118
|
-
productList: productList
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
|
|
122
109
|
// 合并新旧折扣列表,并计算折扣结果
|
|
123
110
|
var mergedDiscountList = uniqueById(uniqueById([].concat(_toConsumableArray(oldDiscountList), _toConsumableArray(newDiscountList))), 'product_id');
|
|
124
111
|
var result = this.calcDiscount({
|
|
@@ -161,13 +148,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
161
148
|
var _this3 = this;
|
|
162
149
|
var discountList = _ref2.discountList,
|
|
163
150
|
productList = _ref2.productList;
|
|
164
|
-
// 识别出来是不是在编辑的界面里又新增了商品
|
|
165
|
-
// 这种情况下,如果有可用的优惠券,也会自动勾选上
|
|
166
|
-
var isEditModeAddNewProduct = productList.find(function (n) {
|
|
167
|
-
return n.booking_id;
|
|
168
|
-
}) && productList.find(function (n) {
|
|
169
|
-
return !n.booking_id;
|
|
170
|
-
});
|
|
171
151
|
var editModeDiscount = [];
|
|
172
152
|
var addModeDiscount = [];
|
|
173
153
|
discountList.forEach(function (discount) {
|
|
@@ -183,69 +163,24 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
183
163
|
return !discount.isManualSelect;
|
|
184
164
|
});
|
|
185
165
|
|
|
186
|
-
//
|
|
187
|
-
// 商品券(n.tag=good_pass)视为最优惠(免费),折扣券(n.tag=product_discount_card)按照n.par_value排序
|
|
188
|
-
// 如果最后拍出来商品券有多个,或者说没有商品券,但是有多个相同折扣的折扣券(比如 6 折券有 3张),则按照过期时间(n.expire_time)排序
|
|
166
|
+
// 优惠券按过期时间排序(即将过期优先)
|
|
189
167
|
var sortedDiscountList = _toConsumableArray(filteredDiscountList).sort(function (a, b) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
// 2. 如果都是商品券或都不是商品券,按照类型和折扣力度排序
|
|
195
|
-
if (a.tag === 'good_pass' && b.tag === 'good_pass') {
|
|
196
|
-
// 都是商品券,按照过期时间排序
|
|
197
|
-
return compareByExpireTime(a, b);
|
|
198
|
-
} else if (a.tag === 'product_discount_card' && b.tag === 'product_discount_card') {
|
|
199
|
-
// 都是折扣券,按照par_value排序(折扣越大越优先,即par_value越小越优先)
|
|
200
|
-
if (a.par_value !== b.par_value) {
|
|
201
|
-
var valueA = new Decimal(100).minus(a.par_value || 0);
|
|
202
|
-
var valueB = new Decimal(100).minus(b.par_value || 0);
|
|
203
|
-
return valueA.minus(valueB).toNumber();
|
|
204
|
-
}
|
|
205
|
-
// 相同折扣的情况下,按照过期时间排序
|
|
206
|
-
return compareByExpireTime(a, b);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// 3. 其他情况按照过期时间排序
|
|
210
|
-
return compareByExpireTime(a, b);
|
|
211
|
-
function compareByExpireTime(itemA, itemB) {
|
|
212
|
-
if (itemA.expire_time && itemB.expire_time) {
|
|
213
|
-
var timeA = new Date(itemA.expire_time).getTime();
|
|
214
|
-
var timeB = new Date(itemB.expire_time).getTime();
|
|
215
|
-
return timeA - timeB;
|
|
216
|
-
}
|
|
217
|
-
// 有过期时间的优先级高于永久的
|
|
218
|
-
return itemA.expire_time ? -1 : itemB.expire_time ? 1 : 0;
|
|
168
|
+
if (a.expire_time && b.expire_time) {
|
|
169
|
+
var timeA = new Date(a.expire_time).getTime();
|
|
170
|
+
var timeB = new Date(b.expire_time).getTime();
|
|
171
|
+
return timeA - timeB;
|
|
219
172
|
}
|
|
173
|
+
// 有过期时间的优先级高于永久的
|
|
174
|
+
return a.expire_time ? -1 : b.expire_time ? 1 : 0;
|
|
220
175
|
});
|
|
221
176
|
|
|
222
|
-
//
|
|
223
|
-
//
|
|
224
|
-
// productList.forEach(item => {
|
|
225
|
-
// const product = this.hooks.getProduct(item);
|
|
226
|
-
// if (product.quantity > 1) {
|
|
227
|
-
// for (let i = 1; i < product.quantity; i++) {
|
|
228
|
-
// newProductList.push(product)
|
|
229
|
-
// }
|
|
230
|
-
// } else {
|
|
231
|
-
// newProductList.push(item)
|
|
232
|
-
// }
|
|
233
|
-
// })
|
|
234
|
-
|
|
235
|
-
// 对productList按价格降序排序(用于应用优惠券时优先选择高价商品) 价格相同时使用quantity 排序
|
|
177
|
+
// 对productList按价格降序排序(用于应用优惠券时优先选择高价商品)
|
|
236
178
|
var sortedProductList = _toConsumableArray(productList).sort(function (a, b) {
|
|
237
179
|
var aProduct = _this3.hooks.getProduct(a);
|
|
238
180
|
var bProduct = _this3.hooks.getProduct(b);
|
|
239
|
-
var priceA =
|
|
240
|
-
var priceB =
|
|
241
|
-
|
|
242
|
-
if (aProduct.quantity === bProduct.quantity) {
|
|
243
|
-
var _bProduct$discount_li, _aProduct$discount_li;
|
|
244
|
-
return ((_bProduct$discount_li = bProduct.discount_list) === null || _bProduct$discount_li === void 0 ? void 0 : _bProduct$discount_li.length) - ((_aProduct$discount_li = aProduct.discount_list) === null || _aProduct$discount_li === void 0 ? void 0 : _aProduct$discount_li.length);
|
|
245
|
-
}
|
|
246
|
-
return aProduct.quantity - bProduct.quantity;
|
|
247
|
-
}
|
|
248
|
-
return priceB.toNumber() - priceA.toNumber();
|
|
181
|
+
var priceA = parseFloat(aProduct.price || '0');
|
|
182
|
+
var priceB = parseFloat(bProduct.price || '0');
|
|
183
|
+
return priceB - priceA;
|
|
249
184
|
});
|
|
250
185
|
|
|
251
186
|
// 标记已使用的优惠券
|
|
@@ -281,7 +216,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
281
216
|
|
|
282
217
|
// 编辑的商品 使用了优惠券不可用
|
|
283
218
|
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) {
|
|
284
|
-
return discount.id &&
|
|
219
|
+
return discount.id && discount.type === 'good_pass';
|
|
285
220
|
}));
|
|
286
221
|
|
|
287
222
|
// 判断优惠券是否适用于该商品
|
|
@@ -294,41 +229,33 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
294
229
|
var applicableProducts = discountApplicableProducts.get(discount.id) || [];
|
|
295
230
|
applicableProducts.push({
|
|
296
231
|
amount: product.price,
|
|
297
|
-
type: discount.tag
|
|
298
|
-
tag: discount.tag || discount.type,
|
|
232
|
+
type: discount.tag,
|
|
299
233
|
discount: {
|
|
300
234
|
resource_id: discount.id,
|
|
301
235
|
title: discount.format_title,
|
|
302
|
-
original_amount: product.origin_total
|
|
303
|
-
|
|
304
|
-
product_id: originProduct.id
|
|
305
|
-
},
|
|
306
|
-
num: product.num || 1
|
|
236
|
+
original_amount: product.origin_total
|
|
237
|
+
}
|
|
307
238
|
});
|
|
308
239
|
discountApplicableProducts.set(discount.id, applicableProducts);
|
|
309
240
|
}
|
|
310
241
|
});
|
|
311
242
|
});
|
|
312
|
-
console.log(sortedProductList, 'sortedProductListsortedProductList');
|
|
313
243
|
|
|
314
244
|
// 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
|
|
315
|
-
sortedProductList.forEach(function (originProduct
|
|
245
|
+
sortedProductList.forEach(function (originProduct) {
|
|
316
246
|
var _product$discount_lis3, _product$discount_lis4, _product$discount_lis5, _product$discount_lis6, _product$discount_lis7;
|
|
317
247
|
var product = _this3.hooks.getProduct(originProduct);
|
|
318
248
|
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) {
|
|
319
|
-
return discount.id &&
|
|
249
|
+
return discount.id && discount.type === 'good_pass';
|
|
320
250
|
})) {
|
|
321
|
-
processedProductsMap.set(product._id,
|
|
251
|
+
processedProductsMap.set(product._id, originProduct);
|
|
322
252
|
return;
|
|
323
253
|
}
|
|
324
254
|
|
|
325
255
|
// 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
|
|
326
256
|
var applicableDiscounts = sortedDiscountList.filter(function (discount) {
|
|
327
|
-
// 如果商品价格为 0,其实不需要使用任何优惠券,直接 return true
|
|
328
|
-
if (Number(product.price) === 0 || !product.price) return false;
|
|
329
257
|
// 如果优惠券已被使用,则跳过
|
|
330
|
-
|
|
331
|
-
if (targetUsedDiscounts && (discount.tag || discount.type) === 'good_pass') return false;
|
|
258
|
+
if (usedDiscounts.get(discount.id)) return false;
|
|
332
259
|
var limitedData = discount.limited_relation_product_data;
|
|
333
260
|
|
|
334
261
|
// 判断优惠券是否适用于该商品
|
|
@@ -349,17 +276,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
349
276
|
})));
|
|
350
277
|
|
|
351
278
|
// 勾选时覆盖手动折扣
|
|
352
|
-
if (options !== null && options !== void 0 && options.discountId &&
|
|
353
|
-
var _item$discount;
|
|
354
|
-
return ((_item$discount = item.discount) === null || _item$discount === void 0 ? void 0 : _item$discount.resource_id) === options.discountId;
|
|
355
|
-
})) {
|
|
279
|
+
if (options !== null && options !== void 0 && options.discountId && (options === null || options === void 0 ? void 0 : options.discountId) === (selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.id)) {
|
|
356
280
|
isManualDiscount = false;
|
|
357
281
|
}
|
|
358
282
|
|
|
359
283
|
// 如果没有适用的优惠券,或者手动折扣,则不适用优惠券
|
|
360
284
|
if (applicableDiscounts.length === 0 || isManualDiscount) {
|
|
361
285
|
if (product.isClient) {
|
|
362
|
-
processedProductsMap.set(product._id,
|
|
286
|
+
processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
|
|
363
287
|
origin_total: getProductOriginTotalPrice({
|
|
364
288
|
product: {
|
|
365
289
|
original_price: product.original_price
|
|
@@ -367,8 +291,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
367
291
|
bundle: product.bundle,
|
|
368
292
|
options: product.options
|
|
369
293
|
}),
|
|
370
|
-
variant: originProduct._productInit.variant,
|
|
371
|
-
original_price: originProduct._productInit.original_price,
|
|
372
294
|
total: getProductTotalPrice({
|
|
373
295
|
product: {
|
|
374
296
|
price: product.price
|
|
@@ -379,115 +301,72 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
379
301
|
price: product.price
|
|
380
302
|
}), {}, {
|
|
381
303
|
discount_list: []
|
|
382
|
-
}))
|
|
304
|
+
})));
|
|
383
305
|
} else {
|
|
384
|
-
processedProductsMap.set(product._id,
|
|
385
|
-
_id: product._id.split('___')[0] + '___' + i,
|
|
306
|
+
processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
|
|
386
307
|
total: product.origin_total || product.total,
|
|
387
308
|
price: product.price
|
|
388
309
|
}), {}, {
|
|
389
310
|
discount_list: []
|
|
390
|
-
}))
|
|
311
|
+
})));
|
|
391
312
|
}
|
|
392
313
|
return;
|
|
393
314
|
}
|
|
394
|
-
if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === 'undefined' && !(options !== null && options !== void 0 && options.scan)
|
|
315
|
+
if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === 'undefined' && !(options !== null && options !== void 0 && options.scan)) {
|
|
395
316
|
return;
|
|
396
317
|
}
|
|
397
318
|
|
|
398
|
-
//
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
//
|
|
402
|
-
var
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
}));
|
|
412
|
-
}
|
|
413
|
-
var _loop = function _loop() {
|
|
414
|
-
var selectedDiscount = applicableDiscounts[_i];
|
|
415
|
-
// 标记优惠券为已使用
|
|
416
|
-
usedDiscounts.set(selectedDiscount.id, true);
|
|
417
|
-
|
|
418
|
-
// 记录实际应用了优惠券的商品信息
|
|
419
|
-
var appliedProducts = appliedDiscountProducts.get(selectedDiscount.id) || [];
|
|
420
|
-
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);
|
|
421
|
-
var discountDetail = {
|
|
422
|
-
amount: selectedDiscount.tag === 'good_pass' ? product.price : new Decimal(product.price || 0).minus(new Decimal(targetProductPrice)).toNumber(),
|
|
423
|
-
type: selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : selectedDiscount.tag,
|
|
424
|
-
discount: {
|
|
425
|
-
resource_id: selectedDiscount.id,
|
|
426
|
-
title: selectedDiscount.format_title,
|
|
427
|
-
original_amount: product.origin_total || product.price,
|
|
428
|
-
product_id: originProduct.id,
|
|
429
|
-
percent: selectedDiscount.par_value
|
|
430
|
-
},
|
|
431
|
-
num: product.num || 1
|
|
432
|
-
};
|
|
433
|
-
appliedProducts.push(discountDetail);
|
|
434
|
-
appliedDiscountProducts.set(selectedDiscount.id, appliedProducts);
|
|
435
|
-
|
|
436
|
-
// 记录应用了优惠券的商品
|
|
437
|
-
// 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
|
|
438
|
-
if (product.isClient) {
|
|
439
|
-
var _originProduct$_produ;
|
|
440
|
-
var variant = (_originProduct$_produ = originProduct._productOrigin.variant) === null || _originProduct$_produ === void 0 ? void 0 : _originProduct$_produ.map(function (n) {
|
|
441
|
-
var _originProduct$_produ2;
|
|
442
|
-
if (n.id === ((_originProduct$_produ2 = originProduct._productOrigin) === null || _originProduct$_produ2 === void 0 ? void 0 : _originProduct$_produ2.product_variant_id)) {
|
|
443
|
-
n.original_price = n.price;
|
|
444
|
-
var _targetProductPrice = selectedDiscount.tag === 'good_pass' ? '0' : new Decimal(100).minus(selectedDiscount.par_value || 0).div(100).mul(new Decimal(n.price || 0)).toFixed(2);
|
|
445
|
-
n.price = _targetProductPrice;
|
|
446
|
-
}
|
|
447
|
-
return n;
|
|
448
|
-
});
|
|
449
|
-
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
450
|
-
discount_list: [discountDetail],
|
|
451
|
-
price: new Decimal(targetProductPrice).toNumber(),
|
|
452
|
-
quantity: isNeedSplit ? 1 : product.quantity,
|
|
453
|
-
origin_total: getProductOriginTotalPrice({
|
|
454
|
-
product: {
|
|
455
|
-
original_price: targetProductPrice
|
|
456
|
-
},
|
|
457
|
-
bundle: product.bundle,
|
|
458
|
-
options: product.options
|
|
459
|
-
}),
|
|
460
|
-
variant: variant,
|
|
461
|
-
original_price: new Decimal(product.price).toNumber(),
|
|
462
|
-
total: getProductTotalPrice({
|
|
463
|
-
product: {
|
|
464
|
-
price: targetProductPrice
|
|
465
|
-
},
|
|
466
|
-
bundle: product.bundle,
|
|
467
|
-
options: product.options
|
|
468
|
-
})
|
|
469
|
-
}));
|
|
470
|
-
} else {
|
|
471
|
-
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
472
|
-
discount_list: [discountDetail],
|
|
473
|
-
_id: product._id.split('___')[0] + "___" + selectedDiscount.id,
|
|
474
|
-
price: new Decimal(targetProductPrice).toNumber(),
|
|
475
|
-
quantity: isNeedSplit ? 1 : product.quantity,
|
|
476
|
-
total: new Decimal(product.origin_total || product.total || 0).minus(new Decimal(product.price || 0).minus(new Decimal(targetProductPrice))).toNumber(),
|
|
477
|
-
origin_total: product.origin_total || product.total
|
|
478
|
-
}));
|
|
319
|
+
// 标记优惠券为已使用
|
|
320
|
+
usedDiscounts.set(selectedDiscount.id, true);
|
|
321
|
+
|
|
322
|
+
// 记录实际应用了优惠券的商品信息
|
|
323
|
+
var appliedProducts = appliedDiscountProducts.get(selectedDiscount.id) || [];
|
|
324
|
+
var discountDetail = {
|
|
325
|
+
amount: product.price,
|
|
326
|
+
type: selectedDiscount.tag,
|
|
327
|
+
discount: {
|
|
328
|
+
resource_id: selectedDiscount.id,
|
|
329
|
+
title: selectedDiscount.format_title,
|
|
330
|
+
original_amount: product.origin_total,
|
|
331
|
+
product_id: selectedDiscount.product_id
|
|
479
332
|
}
|
|
480
333
|
};
|
|
481
|
-
|
|
482
|
-
|
|
334
|
+
appliedProducts.push(discountDetail);
|
|
335
|
+
appliedDiscountProducts.set(selectedDiscount.id, appliedProducts);
|
|
336
|
+
|
|
337
|
+
// 记录应用了优惠券的商品
|
|
338
|
+
// 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
|
|
339
|
+
if (product.isClient) {
|
|
340
|
+
processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, {
|
|
341
|
+
discount_list: [discountDetail],
|
|
342
|
+
price: 0,
|
|
343
|
+
origin_total: getProductOriginTotalPrice({
|
|
344
|
+
product: {
|
|
345
|
+
original_price: product.original_price
|
|
346
|
+
},
|
|
347
|
+
bundle: product.bundle,
|
|
348
|
+
options: product.options
|
|
349
|
+
}),
|
|
350
|
+
total: getProductTotalPrice({
|
|
351
|
+
product: {
|
|
352
|
+
price: '0'
|
|
353
|
+
},
|
|
354
|
+
bundle: product.bundle,
|
|
355
|
+
options: product.options
|
|
356
|
+
})
|
|
357
|
+
}));
|
|
358
|
+
} else {
|
|
359
|
+
processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, {
|
|
360
|
+
discount_list: [discountDetail],
|
|
361
|
+
price: 0,
|
|
362
|
+
total: (product.origin_total || product.total) - product.price,
|
|
363
|
+
origin_total: product.origin_total || product.total
|
|
364
|
+
}));
|
|
483
365
|
}
|
|
484
|
-
console.log(arr, 'arrarrarr');
|
|
485
|
-
processedProductsMap.set(product._id, arr);
|
|
486
366
|
});
|
|
487
367
|
|
|
488
368
|
// 按原始顺序构建处理后的商品列表
|
|
489
|
-
var processedProductList =
|
|
490
|
-
productList.forEach(function (originProduct) {
|
|
369
|
+
var processedProductList = productList.map(function (originProduct) {
|
|
491
370
|
var product = _this3.hooks.getProduct(originProduct);
|
|
492
371
|
var getDefaultProduct = function getDefaultProduct() {
|
|
493
372
|
if (product.isClient) {
|
|
@@ -501,8 +380,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
501
380
|
bundle: product.bundle,
|
|
502
381
|
options: product.options
|
|
503
382
|
}),
|
|
504
|
-
variant: originProduct._productInit.variant,
|
|
505
|
-
original_price: originProduct._productInit.original_price,
|
|
506
383
|
total: getProductTotalPrice({
|
|
507
384
|
product: {
|
|
508
385
|
price: product.price
|
|
@@ -520,8 +397,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
520
397
|
});
|
|
521
398
|
}
|
|
522
399
|
};
|
|
523
|
-
|
|
524
|
-
arr !== null && arr !== void 0 && arr.length ? processedProductList.push.apply(processedProductList, _toConsumableArray(arr)) : processedProductList.push(getDefaultProduct());
|
|
400
|
+
return processedProductsMap.get(product._id) || getDefaultProduct();
|
|
525
401
|
});
|
|
526
402
|
|
|
527
403
|
// 按原始顺序更新优惠券列表,标记已使用和可用的优惠券
|
|
@@ -584,7 +460,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
584
460
|
appliedProductDetails: []
|
|
585
461
|
});
|
|
586
462
|
});
|
|
587
|
-
console.log(processedProductList, 'processedProductList');
|
|
588
463
|
return {
|
|
589
464
|
productList: processedProductList,
|
|
590
465
|
discountList: [].concat(editModeDiscount, _toConsumableArray(updatedDiscountList))
|
|
@@ -37,20 +37,14 @@ type ProductDetail = {
|
|
|
37
37
|
options?: any[];
|
|
38
38
|
bundle?: any[];
|
|
39
39
|
original_price?: number | string;
|
|
40
|
-
num?: number;
|
|
41
|
-
quantity: number;
|
|
42
40
|
};
|
|
43
41
|
export interface RulesParamsHooks {
|
|
44
42
|
getProduct: (product: Record<string, any>) => ProductDetail;
|
|
45
43
|
setProduct: (product: Record<string, any>, values: {
|
|
46
|
-
_id?: string;
|
|
47
44
|
total?: number;
|
|
48
45
|
discount_list: any[];
|
|
49
46
|
origin_total?: number;
|
|
50
47
|
price?: number;
|
|
51
|
-
quantity?: number;
|
|
52
|
-
variant?: any[];
|
|
53
|
-
original_price?: number;
|
|
54
48
|
}) => Record<string, any>;
|
|
55
49
|
}
|
|
56
50
|
export {};
|
|
@@ -1,24 +1,16 @@
|
|
|
1
1
|
import { Module, PisellCore, ModuleOptions } from '../../types';
|
|
2
2
|
import { BaseModule } from '../BaseModule';
|
|
3
|
-
import { ScheduleModuleAPI, ScheduleAvailabilityDateItem, ScheduleItem
|
|
3
|
+
import { ScheduleModuleAPI, ScheduleAvailabilityDateItem, ScheduleItem } 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;
|
|
8
7
|
private store;
|
|
9
8
|
private cacheId;
|
|
10
9
|
private openCache;
|
|
11
10
|
private fatherModule;
|
|
12
11
|
constructor(name?: string, version?: string);
|
|
13
12
|
initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
|
|
14
|
-
/**
|
|
15
|
-
* 加载当前店铺下所有 schedule
|
|
16
|
-
*
|
|
17
|
-
* @memberof ScheduleModule
|
|
18
|
-
*/
|
|
19
|
-
loadAllSchedule(): Promise<void>;
|
|
20
13
|
setScheduleList(list: ScheduleItem[]): void;
|
|
21
|
-
loadScheduleAvailableDate({ startDate, endDate, custom_page_id, channel, }: LoadScheduleAvailableDateParams): Promise<import("../Date/types").ITime[]>;
|
|
22
14
|
getScheduleListByIds(ids: number[]): ScheduleItem[];
|
|
23
15
|
setAvailabilityScheduleDateList(list: ScheduleAvailabilityDateItem[]): void;
|
|
24
16
|
getAvailabilityScheduleDateList(): ScheduleAvailabilityDateItem[];
|
|
@@ -17,12 +17,6 @@ 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);
|
|
26
20
|
export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
|
|
27
21
|
_inherits(ScheduleModule, _BaseModule);
|
|
28
22
|
var _super = _createSuper(ScheduleModule);
|
|
@@ -32,7 +26,6 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
32
26
|
_this = _super.call(this, name, version);
|
|
33
27
|
_defineProperty(_assertThisInitialized(_this), "defaultName", 'schedule');
|
|
34
28
|
_defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
|
|
35
|
-
_defineProperty(_assertThisInitialized(_this), "request", void 0);
|
|
36
29
|
_defineProperty(_assertThisInitialized(_this), "store", {});
|
|
37
30
|
_defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
|
|
38
31
|
_defineProperty(_assertThisInitialized(_this), "openCache", false);
|
|
@@ -48,15 +41,6 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
48
41
|
while (1) switch (_context.prev = _context.next) {
|
|
49
42
|
case 0:
|
|
50
43
|
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:
|
|
60
44
|
// if (options?.initialState) {
|
|
61
45
|
// this.state = { ...this.state, ...options.initialState }
|
|
62
46
|
// }
|
|
@@ -75,7 +59,7 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
75
59
|
if ((_options$otherParams2 = options.otherParams) !== null && _options$otherParams2 !== void 0 && _options$otherParams2.fatherModule) {
|
|
76
60
|
this.fatherModule = options.otherParams.fatherModule;
|
|
77
61
|
}
|
|
78
|
-
case
|
|
62
|
+
case 5:
|
|
79
63
|
case "end":
|
|
80
64
|
return _context.stop();
|
|
81
65
|
}
|
|
@@ -86,115 +70,11 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
86
70
|
}
|
|
87
71
|
return initialize;
|
|
88
72
|
}()
|
|
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
|
-
}())
|
|
123
73
|
}, {
|
|
124
74
|
key: "setScheduleList",
|
|
125
75
|
value: function setScheduleList(list) {
|
|
126
76
|
this.store.scheduleList = list;
|
|
127
77
|
}
|
|
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
|
-
}()
|
|
198
78
|
}, {
|
|
199
79
|
key: "getScheduleListByIds",
|
|
200
80
|
value: function getScheduleListByIds(ids) {
|
|
@@ -232,7 +112,7 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
232
112
|
cacheId: this.cacheId,
|
|
233
113
|
fatherModule: this.fatherModule,
|
|
234
114
|
store: store,
|
|
235
|
-
cacheKey: ['scheduleList', 'availabilityDateList'
|
|
115
|
+
cacheKey: ['scheduleList', 'availabilityDateList']
|
|
236
116
|
});
|
|
237
117
|
}
|
|
238
118
|
}
|
|
@@ -9,19 +9,6 @@ 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
|
-
}
|
|
25
12
|
export interface ScheduleModuleAPI {
|
|
26
13
|
}
|
|
27
14
|
export type ScheduleItem = {
|