@pisell/pisellos 0.0.189 → 0.0.191
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.js +22 -4
- package/dist/modules/Rules/index.js +6 -4
- package/dist/solution/BookingByStep/index.js +13 -5
- package/dist/solution/ShopDiscount/index.js +9 -8
- package/lib/modules/Cart/utils/changePrice.js +20 -3
- package/lib/modules/Rules/index.js +4 -1
- package/lib/solution/BookingByStep/index.js +12 -6
- package/lib/solution/ShopDiscount/index.js +6 -6
- package/package.json +1 -1
|
@@ -23,8 +23,8 @@ function _updateAllCartItemPrice() {
|
|
|
23
23
|
_iterator = _createForOfIteratorHelper(cartItems);
|
|
24
24
|
_context2.prev = 1;
|
|
25
25
|
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
|
|
26
|
-
var _bundle;
|
|
27
|
-
var item, targetProduct, cartProduct, productInfo, bundle;
|
|
26
|
+
var _item$_productOrigin, _bundle;
|
|
27
|
+
var item, targetProduct, cartProduct, productInfo, bundle, _productInfo$variant;
|
|
28
28
|
return _regeneratorRuntime().wrap(function _loop$(_context) {
|
|
29
29
|
while (1) switch (_context.prev = _context.next) {
|
|
30
30
|
case 0:
|
|
@@ -40,6 +40,7 @@ function _updateAllCartItemPrice() {
|
|
|
40
40
|
bundle = item._bundleOrigin;
|
|
41
41
|
productInfo.price = targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.price;
|
|
42
42
|
productInfo.base_price = targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.base_price;
|
|
43
|
+
productInfo.product_variant_id = (_item$_productOrigin = item._productOrigin) === null || _item$_productOrigin === void 0 ? void 0 : _item$_productOrigin.product_variant_id;
|
|
43
44
|
bundle = (_bundle = bundle) === null || _bundle === void 0 ? void 0 : _bundle.map(function (n) {
|
|
44
45
|
var _targetProduct$bundle;
|
|
45
46
|
// 更新 bundle 的价格
|
|
@@ -62,12 +63,29 @@ function _updateAllCartItemPrice() {
|
|
|
62
63
|
}
|
|
63
64
|
return n;
|
|
64
65
|
});
|
|
66
|
+
// 如果有返回variant,则把对应variant的数据也补充进去
|
|
67
|
+
if (targetProduct !== null && targetProduct !== void 0 && targetProduct.variant) {
|
|
68
|
+
productInfo.variant = (_productInfo$variant = productInfo.variant) === null || _productInfo$variant === void 0 ? void 0 : _productInfo$variant.map(function (n) {
|
|
69
|
+
var _targetProduct$varian;
|
|
70
|
+
var targetVariant = (_targetProduct$varian = targetProduct.variant) === null || _targetProduct$varian === void 0 ? void 0 : _targetProduct$varian.find(function (m) {
|
|
71
|
+
return m.id === n.id;
|
|
72
|
+
});
|
|
73
|
+
if (targetVariant) {
|
|
74
|
+
return _objectSpread(_objectSpread({}, n), {}, {
|
|
75
|
+
price: targetVariant.price,
|
|
76
|
+
base_price: targetVariant.base_price
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return n;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
65
82
|
updateCart({
|
|
66
83
|
_id: item._id,
|
|
67
84
|
product: productInfo,
|
|
68
|
-
bundle: bundle
|
|
85
|
+
bundle: bundle,
|
|
86
|
+
options: item._optionsOrigin
|
|
69
87
|
});
|
|
70
|
-
case
|
|
88
|
+
case 13:
|
|
71
89
|
case "end":
|
|
72
90
|
return _context.stop();
|
|
73
91
|
}
|
|
@@ -423,7 +423,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
423
423
|
}));
|
|
424
424
|
}
|
|
425
425
|
for (var _i = 0; _i < splitCount; _i++) {
|
|
426
|
-
var _originProduct$_produ;
|
|
426
|
+
var _originProduct$_produ, _product$discount_lis10;
|
|
427
427
|
// 如果用过折扣卡,也就不存在拆分的情况了,这里直接使用上面计算出来的折扣卡
|
|
428
428
|
var _selectedDiscount = selectedDiscountCard || applicableDiscounts[_i];
|
|
429
429
|
// 标记优惠券为已使用
|
|
@@ -434,12 +434,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
434
434
|
|
|
435
435
|
// 优先从 origin_total拿,可能会拿不到(比如用户端预约在没有配置 original_price 的情况下)
|
|
436
436
|
var productOriginTotal = product.origin_total || product.total || 0;
|
|
437
|
-
// 如果
|
|
438
|
-
// 因为用户端会涉及到划线价的概念
|
|
439
|
-
// 如果 originProduct._productInit.original_price 有值,则代表有划线价
|
|
437
|
+
// 如果originProduct?._productInit?.original_price为 0,product.origin_total可能为空,此时取 product.total
|
|
440
438
|
if (Number((originProduct === null || originProduct === void 0 || (_originProduct$_produ = originProduct._productInit) === null || _originProduct$_produ === void 0 ? void 0 : _originProduct$_produ.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
|
|
441
439
|
productOriginTotal = product.total;
|
|
442
440
|
}
|
|
441
|
+
// 如果当前 product 有 discount_list,则必须从 origin_total 拿
|
|
442
|
+
if ((_product$discount_lis10 = product.discount_list) !== null && _product$discount_lis10 !== void 0 && _product$discount_lis10.length && product.origin_total) {
|
|
443
|
+
productOriginTotal = product.origin_total;
|
|
444
|
+
}
|
|
443
445
|
|
|
444
446
|
// 计算使用折扣卡/商品券以后,单个商品的总 total
|
|
445
447
|
var targetProductTotal = _selectedDiscount.tag === 'good_pass' ? new Decimal(productOriginTotal).minus(new Decimal(product.price || 0)).toNumber() : new Decimal(100).minus(_selectedDiscount.par_value || 0).div(100).mul(new Decimal(productOriginTotal)).toNumber();
|
|
@@ -1673,10 +1673,18 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1673
1673
|
}
|
|
1674
1674
|
// 如果此时 resources 为空,视作购物车里已经有了 dateRange 数据,此时 dateList 里明确就是那一天的数据
|
|
1675
1675
|
if (!AllResources.length) {
|
|
1676
|
-
var
|
|
1677
|
-
|
|
1678
|
-
if (n.resource) AllResources.push.apply(AllResources, _toConsumableArray(n.resource));
|
|
1676
|
+
var firstDateCartItem = cartItems === null || cartItems === void 0 ? void 0 : cartItems.find(function (n) {
|
|
1677
|
+
return n.start_date;
|
|
1679
1678
|
});
|
|
1679
|
+
if (firstDateCartItem !== null && firstDateCartItem !== void 0 && firstDateCartItem.start_date) {
|
|
1680
|
+
var dateResources = this.store.date.getResourcesListByDate(firstDateCartItem.start_date);
|
|
1681
|
+
AllResources.push.apply(AllResources, _toConsumableArray(dateResources || []));
|
|
1682
|
+
} else {
|
|
1683
|
+
var dateList = this.store.date.getDateList();
|
|
1684
|
+
dateList.forEach(function (n) {
|
|
1685
|
+
if (n.resource) AllResources.push.apply(AllResources, _toConsumableArray(n.resource));
|
|
1686
|
+
});
|
|
1687
|
+
}
|
|
1680
1688
|
}
|
|
1681
1689
|
var resourcesMap = getResourcesMap(cloneDeep(AllResources));
|
|
1682
1690
|
var allCartItems = cloneDeep(this.store.cart.getItems());
|
|
@@ -2174,12 +2182,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2174
2182
|
value: 10
|
|
2175
2183
|
};
|
|
2176
2184
|
resource.startTime = timeSlots.start_at.format('YYYY-MM-DD HH:mm');
|
|
2177
|
-
// 找到resource.times
|
|
2185
|
+
// 找到resource.times里最晚的end_at
|
|
2178
2186
|
var targetResourceTimes = allResources === null || allResources === void 0 || (_allResources$find = allResources.find(function (n) {
|
|
2179
2187
|
return n.id === resource.id;
|
|
2180
2188
|
})) === null || _allResources$find === void 0 ? void 0 : _allResources$find.times;
|
|
2181
2189
|
var resourcesEndTime = targetResourceTimes.reduce(function (acc, curr) {
|
|
2182
|
-
return dayjs(curr.end_at).
|
|
2190
|
+
return dayjs(curr.end_at).isAfter(dayjs(acc.end_at)) ? curr : acc;
|
|
2183
2191
|
}, targetResourceTimes[0]);
|
|
2184
2192
|
|
|
2185
2193
|
// 将 operating_day_boundary 转换为与 resourcesEndTime.end_at 相同日期的完整日期时间
|
|
@@ -489,6 +489,15 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
489
489
|
var newDiscountList = [].concat(editModeDiscountList, _toConsumableArray(discountList.filter(function (item) {
|
|
490
490
|
return !item.isDisabled;
|
|
491
491
|
})));
|
|
492
|
+
var isProductFree = function isProductFree(id) {
|
|
493
|
+
var _this3$hooks2;
|
|
494
|
+
var targetProduct = productList.find(function (n) {
|
|
495
|
+
return n.id === id;
|
|
496
|
+
});
|
|
497
|
+
var product = (_this3$hooks2 = _this3.hooks) === null || _this3$hooks2 === void 0 ? void 0 : _this3$hooks2.getProduct(targetProduct);
|
|
498
|
+
// 如果 product.total 是 0有可能是她已经用过商品券或者折扣卡导致的 0,所以此时还需要判断 origin_total 是否为 0
|
|
499
|
+
return Number(product === null || product === void 0 ? void 0 : product.total) === 0 && (Number(product === null || product === void 0 ? void 0 : product.origin_total) === 0 || !(product !== null && product !== void 0 && product.origin_total));
|
|
500
|
+
};
|
|
492
501
|
var allUsedProductIds = newDiscountList.map(function (n) {
|
|
493
502
|
var _n$appliedProductDeta;
|
|
494
503
|
return n.isSelected ? (_n$appliedProductDeta = n.appliedProductDetails) === null || _n$appliedProductDeta === void 0 ? void 0 : _n$appliedProductDeta.map(function (n) {
|
|
@@ -498,14 +507,6 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
498
507
|
}).flat();
|
|
499
508
|
newDiscountList.forEach(function (item) {
|
|
500
509
|
var _item$applicableProdu;
|
|
501
|
-
var isProductFree = function isProductFree(id) {
|
|
502
|
-
var _this3$hooks2;
|
|
503
|
-
var targetProduct = productList.find(function (n) {
|
|
504
|
-
return n.id === id;
|
|
505
|
-
});
|
|
506
|
-
var product = (_this3$hooks2 = _this3.hooks) === null || _this3$hooks2 === void 0 ? void 0 : _this3$hooks2.getProduct(targetProduct);
|
|
507
|
-
return Number(product === null || product === void 0 ? void 0 : product.total) === 0;
|
|
508
|
-
};
|
|
509
510
|
var isAllProductUsedOrFree = (_item$applicableProdu = item.applicableProductIds) === null || _item$applicableProdu === void 0 ? void 0 : _item$applicableProdu.every(function (id) {
|
|
510
511
|
var _item$applicableProdu2;
|
|
511
512
|
// 检查当前 id是否在 item.applicableProductIds 里出现了几次,且要求次数和 item.applicableProductIds 里出现的次数一致
|
|
@@ -34,6 +34,7 @@ __export(changePrice_exports, {
|
|
|
34
34
|
module.exports = __toCommonJS(changePrice_exports);
|
|
35
35
|
var import_decimal = __toESM(require("decimal.js"));
|
|
36
36
|
async function updateAllCartItemPrice(cartItems, priceData, getProduct, updateCart) {
|
|
37
|
+
var _a, _b;
|
|
37
38
|
for (const item of cartItems) {
|
|
38
39
|
const targetProduct = priceData.find((n) => n.id === item.id);
|
|
39
40
|
const cartProduct = await getProduct(
|
|
@@ -43,9 +44,10 @@ async function updateAllCartItemPrice(cartItems, priceData, getProduct, updateCa
|
|
|
43
44
|
let bundle = item._bundleOrigin;
|
|
44
45
|
productInfo.price = targetProduct == null ? void 0 : targetProduct.price;
|
|
45
46
|
productInfo.base_price = targetProduct == null ? void 0 : targetProduct.base_price;
|
|
47
|
+
productInfo.product_variant_id = (_a = item._productOrigin) == null ? void 0 : _a.product_variant_id;
|
|
46
48
|
bundle = bundle == null ? void 0 : bundle.map((n) => {
|
|
47
|
-
var
|
|
48
|
-
const targetBundle = (
|
|
49
|
+
var _a2;
|
|
50
|
+
const targetBundle = (_a2 = targetProduct == null ? void 0 : targetProduct.bundle_group) == null ? void 0 : _a2.find(
|
|
49
51
|
(m) => m.id === n.group_id
|
|
50
52
|
);
|
|
51
53
|
if (targetBundle) {
|
|
@@ -65,10 +67,25 @@ async function updateAllCartItemPrice(cartItems, priceData, getProduct, updateCa
|
|
|
65
67
|
}
|
|
66
68
|
return n;
|
|
67
69
|
});
|
|
70
|
+
if (targetProduct == null ? void 0 : targetProduct.variant) {
|
|
71
|
+
productInfo.variant = (_b = productInfo.variant) == null ? void 0 : _b.map((n) => {
|
|
72
|
+
var _a2;
|
|
73
|
+
const targetVariant = (_a2 = targetProduct.variant) == null ? void 0 : _a2.find((m) => m.id === n.id);
|
|
74
|
+
if (targetVariant) {
|
|
75
|
+
return {
|
|
76
|
+
...n,
|
|
77
|
+
price: targetVariant.price,
|
|
78
|
+
base_price: targetVariant.base_price
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return n;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
68
84
|
updateCart({
|
|
69
85
|
_id: item._id,
|
|
70
86
|
product: productInfo,
|
|
71
|
-
bundle
|
|
87
|
+
bundle,
|
|
88
|
+
options: item._optionsOrigin
|
|
72
89
|
});
|
|
73
90
|
}
|
|
74
91
|
}
|
|
@@ -207,7 +207,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
207
207
|
});
|
|
208
208
|
console.log(sortedProductList, "sortedProductListsortedProductList");
|
|
209
209
|
sortedProductList.forEach((originProduct, i) => {
|
|
210
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
210
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
211
211
|
const product = this.hooks.getProduct(originProduct);
|
|
212
212
|
if ((product == null ? void 0 : product.booking_id) && ((_a = product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount) => discount.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount.tag || discount.type)))) {
|
|
213
213
|
processedProductsMap.set(product._id, [originProduct]);
|
|
@@ -301,6 +301,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
301
301
|
if (Number(((_g = originProduct == null ? void 0 : originProduct._productInit) == null ? void 0 : _g.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
|
|
302
302
|
productOriginTotal = product.total;
|
|
303
303
|
}
|
|
304
|
+
if (((_h = product.discount_list) == null ? void 0 : _h.length) && product.origin_total) {
|
|
305
|
+
productOriginTotal = product.origin_total;
|
|
306
|
+
}
|
|
304
307
|
const targetProductTotal = selectedDiscount2.tag === "good_pass" ? new import_decimal.default(productOriginTotal).minus(new import_decimal.default(product.price || 0)).toNumber() : new import_decimal.default(100).minus(selectedDiscount2.par_value || 0).div(100).mul(new import_decimal.default(productOriginTotal)).toNumber();
|
|
305
308
|
const discountDetail = {
|
|
306
309
|
amount: new import_decimal.default(productOriginTotal).minus(new import_decimal.default(targetProductTotal)).toNumber(),
|
|
@@ -1056,11 +1056,17 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1056
1056
|
});
|
|
1057
1057
|
}
|
|
1058
1058
|
if (!AllResources.length) {
|
|
1059
|
-
const
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
}
|
|
1059
|
+
const firstDateCartItem = cartItems == null ? void 0 : cartItems.find((n) => n.start_date);
|
|
1060
|
+
if (firstDateCartItem == null ? void 0 : firstDateCartItem.start_date) {
|
|
1061
|
+
const dateResources = this.store.date.getResourcesListByDate(firstDateCartItem.start_date);
|
|
1062
|
+
AllResources.push(...dateResources || []);
|
|
1063
|
+
} else {
|
|
1064
|
+
const dateList = this.store.date.getDateList();
|
|
1065
|
+
dateList.forEach((n) => {
|
|
1066
|
+
if (n.resource)
|
|
1067
|
+
AllResources.push(...n.resource);
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
1064
1070
|
}
|
|
1065
1071
|
const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(AllResources));
|
|
1066
1072
|
const allCartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
|
|
@@ -1504,7 +1510,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1504
1510
|
)) == null ? void 0 : _c.times;
|
|
1505
1511
|
const resourcesEndTime = targetResourceTimes.reduce(
|
|
1506
1512
|
(acc, curr) => {
|
|
1507
|
-
return (0, import_dayjs.default)(curr.end_at).
|
|
1513
|
+
return (0, import_dayjs.default)(curr.end_at).isAfter((0, import_dayjs.default)(acc.end_at)) ? curr : acc;
|
|
1508
1514
|
},
|
|
1509
1515
|
targetResourceTimes[0]
|
|
1510
1516
|
);
|
|
@@ -333,6 +333,12 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
333
333
|
...editModeDiscountList,
|
|
334
334
|
...discountList.filter((item) => !item.isDisabled)
|
|
335
335
|
];
|
|
336
|
+
const isProductFree = (id) => {
|
|
337
|
+
var _a2;
|
|
338
|
+
const targetProduct = productList.find((n) => n.id === id);
|
|
339
|
+
const product = (_a2 = this.hooks) == null ? void 0 : _a2.getProduct(targetProduct);
|
|
340
|
+
return Number(product == null ? void 0 : product.total) === 0 && (Number(product == null ? void 0 : product.origin_total) === 0 || !(product == null ? void 0 : product.origin_total));
|
|
341
|
+
};
|
|
336
342
|
const allUsedProductIds = newDiscountList.map((n) => {
|
|
337
343
|
var _a2;
|
|
338
344
|
return n.isSelected ? (_a2 = n.appliedProductDetails) == null ? void 0 : _a2.map((n2) => {
|
|
@@ -342,12 +348,6 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
342
348
|
}).flat();
|
|
343
349
|
newDiscountList.forEach((item) => {
|
|
344
350
|
var _a2;
|
|
345
|
-
const isProductFree = (id) => {
|
|
346
|
-
var _a3;
|
|
347
|
-
const targetProduct = productList.find((n) => n.id === id);
|
|
348
|
-
const product = (_a3 = this.hooks) == null ? void 0 : _a3.getProduct(targetProduct);
|
|
349
|
-
return Number(product == null ? void 0 : product.total) === 0;
|
|
350
|
-
};
|
|
351
351
|
const isAllProductUsedOrFree = (_a2 = item.applicableProductIds) == null ? void 0 : _a2.every((id) => {
|
|
352
352
|
var _a3;
|
|
353
353
|
const sameIdTimes = ((_a3 = item.applicableProductIds) == null ? void 0 : _a3.filter((n) => n === id).length) || 1;
|