@pisell/pisellos 0.0.567 → 0.0.568
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/index.js +6 -9
- package/dist/model/strategy/adapter/walletPass/evaluator.js +0 -2
- package/dist/model/strategy/adapter/walletPass/example.js +3 -26
- package/dist/model/strategy/adapter/walletPass/utils.js +0 -3
- package/dist/model/strategy/strategy-example.js +5 -19
- package/dist/modules/Cart/index.js +0 -3
- package/dist/modules/Cart/utils/cartProduct.js +0 -1
- package/dist/modules/Date/index.js +1 -5
- package/dist/modules/Discount/index.js +1 -4
- package/dist/modules/OpenData/index.js +0 -2
- package/dist/modules/Order/index.d.ts +1 -1
- package/dist/modules/Order/index.js +14 -41
- package/dist/modules/Payment/index.js +142 -270
- package/dist/modules/Payment/walletpass.js +4 -5
- package/dist/modules/Rules/index.js +0 -7
- package/dist/modules/Schedule/utils.js +0 -1
- package/dist/modules/Step/index.js +0 -1
- package/dist/plugins/request.js +1 -4
- package/dist/plugins/window.js +2 -6
- package/dist/server/index.js +88 -121
- package/dist/server/modules/menu/index.js +32 -41
- package/dist/server/modules/products/index.js +29 -49
- package/dist/server/modules/quotation/index.js +29 -38
- package/dist/server/modules/resource/index.js +3 -4
- package/dist/server/modules/schedule/index.js +32 -40
- package/dist/server/utils/product.js +0 -1
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingByStep/index.js +7 -59
- package/dist/solution/BookingByStep/utils/capacity.js +1 -11
- package/dist/solution/BookingByStep/utils/resources.js +1 -3
- package/dist/solution/BookingByStep/utils/timeslots.js +2 -43
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.js +5 -7
- package/dist/solution/BookingTicket/utils/scan/handleScan.js +25 -31
- package/dist/solution/BookingTicket/utils/scan/index.js +6 -10
- package/dist/solution/BuyTickets/index.js +9 -12
- package/dist/solution/Checkout/index.js +177 -246
- package/dist/solution/Checkout/utils/index.js +4 -16
- package/dist/solution/RegisterAndLogin/index.js +30 -76
- package/dist/solution/ScanOrder/index.js +50 -60
- package/dist/solution/ShopDiscount/index.js +2 -7
- package/dist/solution/VenueBooking/index.d.ts +5 -0
- package/dist/solution/VenueBooking/index.js +364 -327
- package/dist/utils/task.js +15 -18
- package/dist/utils/watch.js +0 -1
- package/lib/apis/picoding.js +2 -0
- package/lib/core/index.js +130 -131
- package/lib/effects/index.js +46 -57
- package/lib/index.js +92 -53
- package/lib/model/index.js +14 -21
- package/lib/model/strategy/adapter/dataVariant/adapter.js +38 -50
- package/lib/model/strategy/adapter/dataVariant/evaluator.js +162 -236
- package/lib/model/strategy/adapter/dataVariant/examples.js +229 -237
- package/lib/model/strategy/adapter/dataVariant/index.js +39 -34
- package/lib/model/strategy/adapter/dataVariant/type.js +57 -28
- package/lib/model/strategy/adapter/index.js +100 -64
- package/lib/model/strategy/adapter/itemRule/adapter.js +156 -144
- package/lib/model/strategy/adapter/itemRule/evaluator.js +36 -48
- package/lib/model/strategy/adapter/itemRule/examples.js +295 -225
- package/lib/model/strategy/adapter/itemRule/index.js +83 -57
- package/lib/model/strategy/adapter/itemRule/type.js +97 -36
- package/lib/model/strategy/adapter/promotion/adapter.js +84 -63
- package/lib/model/strategy/adapter/promotion/evaluator.js +381 -231
- package/lib/model/strategy/adapter/promotion/examples.js +139 -159
- package/lib/model/strategy/adapter/promotion/index.js +1 -49
- package/lib/model/strategy/adapter/promotion/type.js +199 -35
- package/lib/model/strategy/adapter/type.js +4 -16
- package/lib/model/strategy/adapter/walletPass/evaluator.js +180 -152
- package/lib/model/strategy/adapter/walletPass/example.js +217 -190
- package/lib/model/strategy/adapter/walletPass/index.js +75 -51
- package/lib/model/strategy/adapter/walletPass/locales.js +36 -58
- package/lib/model/strategy/adapter/walletPass/type.js +4 -16
- package/lib/model/strategy/adapter/walletPass/utils.js +652 -402
- package/lib/model/strategy/engine.js +270 -168
- package/lib/model/strategy/index.js +49 -34
- package/lib/model/strategy/strategy-example.js +243 -239
- package/lib/model/strategy/type.js +100 -40
- package/lib/modules/Account/index.js +39 -53
- package/lib/modules/Account/types.js +20 -33
- package/lib/modules/AccountList/index.js +116 -154
- package/lib/modules/AccountList/types.js +30 -31
- package/lib/modules/AccountList/utils.js +18 -30
- package/lib/modules/BaseModule.js +22 -45
- package/lib/modules/Cart/index.js +170 -124
- package/lib/modules/Cart/types.js +46 -51
- package/lib/modules/Cart/utils/cartAccount.js +40 -39
- package/lib/modules/Cart/utils/cartDate.js +56 -61
- package/lib/modules/Cart/utils/cartDiscount.js +28 -33
- package/lib/modules/Cart/utils/cartNote.js +27 -32
- package/lib/modules/Cart/utils/cartProduct.js +306 -241
- package/lib/modules/Cart/utils/cartRelationForms.js +29 -35
- package/lib/modules/Cart/utils/cartResource.js +72 -78
- package/lib/modules/Cart/utils/changePrice.js +26 -62
- package/lib/modules/Cart/utils/index.js +106 -48
- package/lib/modules/Customer/constants.js +13 -34
- package/lib/modules/Customer/index.js +216 -153
- package/lib/modules/Customer/types.js +38 -35
- package/lib/modules/Date/index.js +116 -115
- package/lib/modules/Date/types.js +16 -28
- package/lib/modules/Date/utils.js +174 -123
- package/lib/modules/Discount/index.js +117 -113
- package/lib/modules/Discount/types.js +9 -31
- package/lib/modules/Guests/index.js +30 -56
- package/lib/modules/Guests/types.js +23 -33
- package/lib/modules/Holder/index.js +209 -189
- package/lib/modules/Holder/types.js +4 -16
- package/lib/modules/Holder/utils.js +20 -49
- package/lib/modules/OpenData/index.js +63 -74
- package/lib/modules/OpenData/types.js +4 -16
- package/lib/modules/OpenData/utils.js +44 -78
- package/lib/modules/Order/index.d.ts +1 -1
- package/lib/modules/Order/index.js +332 -320
- package/lib/modules/Order/types.js +24 -33
- package/lib/modules/Order/utils.js +350 -284
- package/lib/modules/Payment/cash.js +20 -33
- package/lib/modules/Payment/cashRecommendationAlgorithm.js +145 -76
- package/lib/modules/Payment/eftpos.js +16 -30
- package/lib/modules/Payment/index.js +566 -432
- package/lib/modules/Payment/mx51.js +1 -0
- package/lib/modules/Payment/types.js +216 -107
- package/lib/modules/Payment/utils.js +50 -47
- package/lib/modules/Payment/walletpass.js +221 -203
- package/lib/modules/Product/index.js +51 -46
- package/lib/modules/Product/types.js +4 -16
- package/lib/modules/Product/utils.js +32 -33
- package/lib/modules/ProductList/index.js +111 -110
- package/lib/modules/ProductList/types.js +9 -31
- package/lib/modules/Quotation/index.js +60 -82
- package/lib/modules/Quotation/types.js +4 -16
- package/lib/modules/Resource/index.js +27 -59
- package/lib/modules/Resource/types.js +22 -32
- package/lib/modules/Resource/utils.js +30 -38
- package/lib/modules/Rules/index.js +1172 -872
- package/lib/modules/Rules/types.js +17 -40
- package/lib/modules/SalesSummary/index.js +59 -68
- package/lib/modules/SalesSummary/types.js +4 -16
- package/lib/modules/SalesSummary/utils.js +176 -193
- package/lib/modules/ScanOrderLogger/index.js +59 -79
- package/lib/modules/ScanOrderLogger/providers/feishu.js +54 -78
- package/lib/modules/ScanOrderLogger/providers/grafana.js +13 -36
- package/lib/modules/ScanOrderLogger/types.js +4 -16
- package/lib/modules/Schedule/getDateIsInSchedule.js +334 -167
- package/lib/modules/Schedule/index.js +97 -107
- package/lib/modules/Schedule/type.js +4 -16
- package/lib/modules/Schedule/types.js +4 -16
- package/lib/modules/Schedule/utils.js +433 -291
- package/lib/modules/Step/index.js +40 -52
- package/lib/modules/Step/tyeps.js +4 -16
- package/lib/modules/Summary/index.js +66 -70
- package/lib/modules/Summary/types.js +4 -16
- package/lib/modules/Summary/utils.js +782 -429
- package/lib/modules/index.js +212 -57
- package/lib/plugins/app.js +4 -16
- package/lib/plugins/index.js +36 -25
- package/lib/plugins/request.js +137 -126
- package/lib/plugins/shopStore.js +4 -16
- package/lib/plugins/user.js +4 -16
- package/lib/plugins/window.js +171 -179
- package/lib/server/index.js +882 -623
- package/lib/server/modules/index.js +85 -59
- package/lib/server/modules/menu/index.js +146 -122
- package/lib/server/modules/menu/types.js +18 -31
- package/lib/server/modules/order/index.js +195 -231
- package/lib/server/modules/order/types.js +107 -32
- package/lib/server/modules/order/utils/filterBookings.js +174 -140
- package/lib/server/modules/order/utils/filterOrders.js +89 -60
- package/lib/server/modules/products/index.js +430 -335
- package/lib/server/modules/products/types.js +41 -34
- package/lib/server/modules/quotation/index.js +76 -77
- package/lib/server/modules/quotation/types.js +21 -31
- package/lib/server/modules/resource/index.js +216 -187
- package/lib/server/modules/resource/types.js +42 -33
- package/lib/server/modules/schedule/index.js +134 -119
- package/lib/server/modules/schedule/types.js +14 -21
- package/lib/server/modules/schedule/utils.js +334 -163
- package/lib/server/types.js +4 -16
- package/lib/server/utils/index.js +25 -23
- package/lib/server/utils/product.js +196 -139
- package/lib/server/utils/schedule.js +34 -41
- package/lib/server/utils/time.js +40 -49
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingByStep/index.js +1530 -1343
- package/lib/solution/BookingByStep/types.js +40 -99
- package/lib/solution/BookingByStep/utils/capacity.js +192 -160
- package/lib/solution/BookingByStep/utils/products.js +42 -52
- package/lib/solution/BookingByStep/utils/resources.js +527 -330
- package/lib/solution/BookingByStep/utils/stock.js +65 -44
- package/lib/solution/BookingByStep/utils/timeslots.js +129 -131
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.js +147 -122
- package/lib/solution/BookingTicket/types.js +38 -64
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +64 -80
- package/lib/solution/BookingTicket/utils/scan/handleScan.js +82 -80
- package/lib/solution/BookingTicket/utils/scan/index.js +90 -94
- package/lib/solution/BookingTicket/utils/scan/scanCache.js +90 -43
- package/lib/solution/BuyTickets/index.js +67 -70
- package/lib/solution/BuyTickets/types.js +22 -38
- package/lib/solution/Checkout/index.js +1451 -1158
- package/lib/solution/Checkout/types.js +91 -61
- package/lib/solution/Checkout/utils/index.js +227 -158
- package/lib/solution/PlaceOrder/index.js +55 -0
- package/lib/solution/RegisterAndLogin/config.js +493 -460
- package/lib/solution/RegisterAndLogin/index.js +633 -630
- package/lib/solution/RegisterAndLogin/types.js +189 -76
- package/lib/solution/RegisterAndLogin/utils.js +183 -125
- package/lib/solution/Sales/index.js +218 -200
- package/lib/solution/Sales/types.js +27 -33
- package/lib/solution/ScanOrder/index.js +803 -840
- package/lib/solution/ScanOrder/types.js +34 -34
- package/lib/solution/ScanOrder/utils.js +372 -331
- package/lib/solution/ShopDiscount/index.js +230 -236
- package/lib/solution/ShopDiscount/types.js +15 -37
- package/lib/solution/ShopDiscount/utils.js +309 -172
- package/lib/solution/VenueBooking/index.d.ts +5 -0
- package/lib/solution/VenueBooking/index.js +886 -929
- package/lib/solution/VenueBooking/types.js +20 -40
- package/lib/solution/VenueBooking/utils/dateSummary.js +22 -54
- package/lib/solution/VenueBooking/utils/resource.js +31 -54
- package/lib/solution/VenueBooking/utils/slotMerge.js +88 -106
- package/lib/solution/VenueBooking/utils/smartPricing.js +112 -100
- package/lib/solution/VenueBooking/utils/timeSlot.js +133 -132
- package/lib/solution/VenueBooking/utils.js +130 -67
- package/lib/solution/index.js +102 -37
- package/lib/store/createStore.js +32 -29
- package/lib/types/index.js +4 -16
- package/lib/utils/task.js +36 -36
- package/lib/utils/watch.js +81 -47
- package/package.json +2 -1
|
@@ -1,71 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
"use strict";
|
|
28
2
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
__export(cartProduct_exports, {
|
|
32
|
-
formatBundle: () => formatBundle,
|
|
33
|
-
formatBundleToOrigin: () => formatBundleToOrigin,
|
|
34
|
-
formatOptions: () => formatOptions,
|
|
35
|
-
formatOptionsToOrigin: () => formatOptionsToOrigin,
|
|
36
|
-
formatProductToCartItem: () => formatProductToCartItem,
|
|
37
|
-
formatProductToCartItemOrigin: () => formatProductToCartItemOrigin,
|
|
38
|
-
getProductDeposit: () => getProductDeposit,
|
|
39
|
-
getProductOriginTotalPrice: () => getProductOriginTotalPrice,
|
|
40
|
-
getProductTotalPrice: () => getProductTotalPrice,
|
|
41
|
-
handleProductDeposit: () => handleProductDeposit,
|
|
42
|
-
handleVariantProduct: () => handleVariantProduct
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
43
5
|
});
|
|
44
|
-
|
|
45
|
-
var
|
|
46
|
-
var
|
|
47
|
-
var
|
|
48
|
-
var
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
6
|
+
exports.handleVariantProduct = exports.handleProductDeposit = exports.getProductTotalPrice = exports.getProductOriginTotalPrice = exports.getProductDeposit = exports.formatProductToCartItemOrigin = exports.formatProductToCartItem = exports.formatOptionsToOrigin = exports.formatOptions = exports.formatBundleToOrigin = exports.formatBundle = void 0;
|
|
7
|
+
var _decimal = _interopRequireDefault(require("decimal.js"));
|
|
8
|
+
var _utils = require("../../Product/utils");
|
|
9
|
+
var _utils2 = require("../../../solution/ShopDiscount/utils");
|
|
10
|
+
var _utils3 = require("../../Summary/utils");
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
/** 与 Rules / ShopDiscount 一致的折扣入参,用于主价与 option 单价 */
|
|
13
|
+
const toDiscountPayload = discountItem => ({
|
|
14
|
+
amount: discountItem.amount,
|
|
15
|
+
tag: discountItem.type,
|
|
16
|
+
par_value: discountItem.discount?.percent,
|
|
17
|
+
config: discountItem.config,
|
|
18
|
+
metadata: {
|
|
19
|
+
discount_card_type: discountItem?.discount?.discount_card_type
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @title 处理组合商品
|
|
25
|
+
* @description 组合商品需要直接修改 product 里的价格和 is_charge_tax
|
|
26
|
+
* @param product 商品
|
|
27
|
+
* @returns 处理后的商品
|
|
28
|
+
*/
|
|
29
|
+
const handleVariantProduct = product => {
|
|
30
|
+
// 判断组合商品,然后直接修改 product 里的价格和 is_charge_tax
|
|
31
|
+
if (product?.product_variant_id) {
|
|
32
|
+
// 还需要判断 能从 variant 里找到对应的组合规格信息,才可以替换
|
|
33
|
+
const targetVariant = product?.variant?.find(n => n.id === product.product_variant_id);
|
|
67
34
|
if (targetVariant) {
|
|
68
35
|
product.price = targetVariant.price;
|
|
36
|
+
// 如果 original_price 为 0,就不改了
|
|
69
37
|
if (Number(targetVariant.original_price) > 0) {
|
|
70
38
|
product.original_price = targetVariant.original_price;
|
|
71
39
|
}
|
|
@@ -74,9 +42,14 @@ var handleVariantProduct = (product) => {
|
|
|
74
42
|
}
|
|
75
43
|
return product;
|
|
76
44
|
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 格式化商品到购物车
|
|
48
|
+
* @param product 商品
|
|
49
|
+
* @returns 格式化后的商品
|
|
50
|
+
*/
|
|
51
|
+
exports.handleVariantProduct = handleVariantProduct;
|
|
52
|
+
const formatProductToCartItem = params => {
|
|
80
53
|
const {
|
|
81
54
|
cartItem,
|
|
82
55
|
product,
|
|
@@ -86,14 +59,25 @@ var formatProductToCartItem = (params) => {
|
|
|
86
59
|
quantity = 1,
|
|
87
60
|
discounts
|
|
88
61
|
} = params;
|
|
89
|
-
const num = quantity;
|
|
62
|
+
const num = quantity; // 当前按照单个商品加入购物车
|
|
63
|
+
|
|
90
64
|
if (product) {
|
|
91
|
-
cartItem.id = product
|
|
92
|
-
cartItem.name = product
|
|
93
|
-
cartItem.price = product
|
|
65
|
+
cartItem.id = product?.id;
|
|
66
|
+
cartItem.name = product?.title;
|
|
67
|
+
cartItem.price = product?.price;
|
|
94
68
|
cartItem.num = num;
|
|
95
|
-
cartItem.total = getProductTotalPrice({
|
|
96
|
-
|
|
69
|
+
cartItem.total = getProductTotalPrice({
|
|
70
|
+
product,
|
|
71
|
+
bundle,
|
|
72
|
+
options,
|
|
73
|
+
num,
|
|
74
|
+
discounts
|
|
75
|
+
});
|
|
76
|
+
cartItem.totalDifference = getTotalDifference({
|
|
77
|
+
product,
|
|
78
|
+
bundle,
|
|
79
|
+
discounts
|
|
80
|
+
});
|
|
97
81
|
cartItem.summaryTotal = cartItem.total * (num || 1);
|
|
98
82
|
cartItem.origin_total = getProductOriginTotalPrice({
|
|
99
83
|
product,
|
|
@@ -102,6 +86,7 @@ var formatProductToCartItem = (params) => {
|
|
|
102
86
|
num,
|
|
103
87
|
discounts
|
|
104
88
|
});
|
|
89
|
+
// 不包含折扣卡商品券的总价
|
|
105
90
|
const origin_total = getProductTotalPrice({
|
|
106
91
|
product: cartItem._productInit || cartItem._productOrigin,
|
|
107
92
|
bundle,
|
|
@@ -110,44 +95,38 @@ var formatProductToCartItem = (params) => {
|
|
|
110
95
|
discounts: []
|
|
111
96
|
});
|
|
112
97
|
cartItem.summaryOriginTotal = (origin_total || 0) * (num || 1);
|
|
113
|
-
cartItem.image = product
|
|
114
|
-
cartItem.like_status =
|
|
115
|
-
cartItem.duration = product
|
|
116
|
-
cartItem.isNormalProduct = (0,
|
|
117
|
-
cartItem.is_charge_tax = product
|
|
98
|
+
cartItem.image = product?.cover;
|
|
99
|
+
cartItem.like_status = 'common';
|
|
100
|
+
cartItem.duration = product?.duration;
|
|
101
|
+
cartItem.isNormalProduct = (0, _utils.isNormalProduct)(product);
|
|
102
|
+
cartItem.is_charge_tax = product?.is_charge_tax;
|
|
118
103
|
}
|
|
119
|
-
if (bundle
|
|
104
|
+
if (bundle?.length) {
|
|
120
105
|
cartItem.bundle = formatBundle(bundle);
|
|
121
106
|
}
|
|
122
|
-
if (options
|
|
107
|
+
if (options?.length) {
|
|
123
108
|
cartItem.options = formatOptions(options);
|
|
124
109
|
}
|
|
110
|
+
// 拼装出 product_option_string
|
|
125
111
|
if (product_variant_id) {
|
|
126
|
-
const sku_key = (
|
|
127
|
-
(n) => n.id === product_variant_id
|
|
128
|
-
)) == null ? void 0 : _b.sku_key;
|
|
112
|
+
const sku_key = product?.variant?.find(n => n.id === product_variant_id)?.sku_key;
|
|
129
113
|
if (sku_key) {
|
|
130
|
-
const sku_key_arr = sku_key.split(
|
|
114
|
+
const sku_key_arr = sku_key.split('_');
|
|
131
115
|
const product_option_string = [];
|
|
132
|
-
sku_key_arr.forEach(
|
|
133
|
-
|
|
134
|
-
const
|
|
135
|
-
const
|
|
136
|
-
(n) => String(n.position_id) === keyMap[0]
|
|
137
|
-
);
|
|
138
|
-
const targetVariantItem = (_b2 = targetVariantGroup == null ? void 0 : targetVariantGroup.variant_item) == null ? void 0 : _b2.find(
|
|
139
|
-
(n) => String(n.position_id) === keyMap[1]
|
|
140
|
-
);
|
|
116
|
+
sku_key_arr.forEach(item => {
|
|
117
|
+
const keyMap = item.split(':');
|
|
118
|
+
const targetVariantGroup = product?.variant_group?.find(n => String(n.position_id) === keyMap[0]);
|
|
119
|
+
const targetVariantItem = targetVariantGroup?.variant_item?.find(n => String(n.position_id) === keyMap[1]);
|
|
141
120
|
if (targetVariantGroup && targetVariantItem) {
|
|
142
|
-
product_option_string.push(
|
|
143
|
-
`${targetVariantGroup.name}:${targetVariantItem.name}`
|
|
144
|
-
);
|
|
121
|
+
product_option_string.push(`${targetVariantGroup.name}:${targetVariantItem.name}`);
|
|
145
122
|
}
|
|
146
123
|
});
|
|
147
|
-
cartItem.product_option_string = product_option_string.join(
|
|
124
|
+
cartItem.product_option_string = product_option_string.join(', ');
|
|
148
125
|
}
|
|
149
126
|
}
|
|
150
|
-
|
|
127
|
+
|
|
128
|
+
// 如果商品有定金规则,则计算定金
|
|
129
|
+
if (product?.custom_deposit_data?.has_deposit == 1) {
|
|
151
130
|
cartItem.deposit = getProductDeposit({
|
|
152
131
|
cartItem,
|
|
153
132
|
product,
|
|
@@ -160,8 +139,8 @@ var formatProductToCartItem = (params) => {
|
|
|
160
139
|
cartItem._origin = oringin;
|
|
161
140
|
return cartItem;
|
|
162
141
|
};
|
|
163
|
-
|
|
164
|
-
|
|
142
|
+
exports.formatProductToCartItem = formatProductToCartItem;
|
|
143
|
+
const formatProductToCartItemOrigin = params => {
|
|
165
144
|
const {
|
|
166
145
|
cartItem,
|
|
167
146
|
product,
|
|
@@ -171,122 +150,161 @@ var formatProductToCartItemOrigin = (params) => {
|
|
|
171
150
|
quantity = 1
|
|
172
151
|
} = params;
|
|
173
152
|
let origin = cartItem._origin;
|
|
174
|
-
const product_discount_difference = (
|
|
175
|
-
|
|
176
|
-
return !((_a2 = item == null ? void 0 : item.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id);
|
|
177
|
-
}).reduce((pre, cur) => {
|
|
178
|
-
var _a2;
|
|
179
|
-
return pre + (((_a2 = cur == null ? void 0 : cur.metadata) == null ? void 0 : _a2.product_discount_difference) || 0);
|
|
153
|
+
const product_discount_difference = (origin.product?.discount_list || []).filter(item => !item?.metadata?.custom_product_bundle_map_id).reduce((pre, cur) => {
|
|
154
|
+
return pre + (cur?.metadata?.product_discount_difference || 0);
|
|
180
155
|
}, 0);
|
|
181
156
|
if (product) {
|
|
182
157
|
origin.product = {
|
|
183
|
-
...origin.product || {},
|
|
158
|
+
...(origin.product || {}),
|
|
184
159
|
num: quantity,
|
|
185
160
|
product_id: product.id,
|
|
186
161
|
product_variant_id: product_variant_id || 0,
|
|
187
|
-
product_bundle:
|
|
188
|
-
product_option_item:
|
|
162
|
+
product_bundle: origin.product?.product_bundle || [],
|
|
163
|
+
product_option_item: origin.product?.product_option_item || [],
|
|
189
164
|
metadata: {
|
|
190
165
|
product_discount_difference
|
|
191
166
|
}
|
|
192
167
|
};
|
|
193
|
-
|
|
194
|
-
origin.
|
|
195
|
-
|
|
168
|
+
// 时长类型
|
|
169
|
+
origin.sub_type = product?.duration?.type;
|
|
170
|
+
// 时长
|
|
171
|
+
origin.duration = product?.duration?.value;
|
|
172
|
+
if (bundle?.length) {
|
|
196
173
|
origin.product.product_bundle = formatBundleToOrigin(bundle);
|
|
197
174
|
}
|
|
198
|
-
if (options
|
|
175
|
+
if (options?.length) {
|
|
199
176
|
origin.product.product_option_item = formatOptionsToOrigin(options);
|
|
200
177
|
}
|
|
201
178
|
}
|
|
202
179
|
return origin;
|
|
203
180
|
};
|
|
204
|
-
|
|
205
|
-
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* 获取商品总价
|
|
184
|
+
* @description 当前总价计算基于商品数量为1
|
|
185
|
+
* @param item 商品
|
|
186
|
+
* @returns 商品总价
|
|
187
|
+
*/
|
|
188
|
+
exports.formatProductToCartItemOrigin = formatProductToCartItemOrigin;
|
|
189
|
+
const getProductTotalPrice = params => {
|
|
190
|
+
const {
|
|
191
|
+
product,
|
|
192
|
+
bundle,
|
|
193
|
+
options,
|
|
194
|
+
discounts
|
|
195
|
+
} = params;
|
|
196
|
+
// const num = params.num || 1;
|
|
206
197
|
let price = Number(product.price);
|
|
207
|
-
|
|
198
|
+
|
|
199
|
+
// option 行:unit 折后价在循环中与主商品使用同一套 getDiscountAmount(含 deductOptionPrice)
|
|
200
|
+
const optionRows = options?.map(currentValue => ({
|
|
208
201
|
unit: Number(currentValue.price ?? currentValue.add_price ?? 0),
|
|
209
202
|
num: Number(currentValue.num ?? currentValue.quantity ?? 1)
|
|
210
|
-
}))
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
203
|
+
})) ?? [];
|
|
204
|
+
|
|
205
|
+
// 如果商品有折扣,则计算折扣
|
|
206
|
+
if (discounts?.length) {
|
|
207
|
+
discounts.forEach(currentValue => {
|
|
214
208
|
const payload = toDiscountPayload(currentValue);
|
|
215
|
-
price = (0,
|
|
216
|
-
if (
|
|
209
|
+
price = (0, _utils2.getDiscountAmount)(payload, price, price);
|
|
210
|
+
if (currentValue?.config?.deductOptionPrice && optionRows.length) {
|
|
217
211
|
for (let i = 0; i < optionRows.length; i++) {
|
|
218
212
|
const row = optionRows[i];
|
|
219
213
|
optionRows[i] = {
|
|
220
214
|
...row,
|
|
221
|
-
unit: (0,
|
|
215
|
+
unit: (0, _utils2.getDiscountAmount)(payload, row.unit, row.unit)
|
|
222
216
|
};
|
|
223
217
|
}
|
|
224
218
|
}
|
|
225
219
|
});
|
|
226
220
|
}
|
|
227
|
-
if (bundle
|
|
221
|
+
if (bundle?.length) {
|
|
228
222
|
price = bundle.reduce((accumulator, currentValue) => {
|
|
229
223
|
return accumulator + Number(currentValue.price) * Number(currentValue.num);
|
|
230
224
|
}, price);
|
|
231
225
|
}
|
|
226
|
+
|
|
227
|
+
// 单规格 / 加购 option
|
|
232
228
|
if (optionRows.length) {
|
|
233
|
-
price = optionRows.reduce(
|
|
234
|
-
(accumulator, row) => accumulator + row.unit * row.num,
|
|
235
|
-
price
|
|
236
|
-
);
|
|
229
|
+
price = optionRows.reduce((accumulator, row) => accumulator + row.unit * row.num, price);
|
|
237
230
|
}
|
|
238
231
|
return Math.max(0, price);
|
|
239
232
|
};
|
|
240
|
-
|
|
241
|
-
|
|
233
|
+
exports.getProductTotalPrice = getProductTotalPrice;
|
|
234
|
+
const getTotalDifference = params => {
|
|
235
|
+
const {
|
|
236
|
+
bundle,
|
|
237
|
+
discounts
|
|
238
|
+
} = params;
|
|
242
239
|
const bundleDiscountList = [];
|
|
243
|
-
if (bundle
|
|
244
|
-
bundle.forEach(
|
|
245
|
-
bundleDiscountList.push(...(currentValue
|
|
240
|
+
if (bundle?.length) {
|
|
241
|
+
bundle.forEach(currentValue => {
|
|
242
|
+
bundleDiscountList.push(...(currentValue?.discount_list || []));
|
|
246
243
|
});
|
|
247
244
|
}
|
|
248
|
-
const allDiscounts = [...discounts || [], ...bundleDiscountList];
|
|
249
|
-
const productDiscountProductDiscountDifference = (0,
|
|
245
|
+
const allDiscounts = [...(discounts || []), ...bundleDiscountList];
|
|
246
|
+
const productDiscountProductDiscountDifference = (0, _utils3.calcDiscountListDifference)(allDiscounts);
|
|
250
247
|
return productDiscountProductDiscountDifference || 0;
|
|
251
248
|
};
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* 获取商品原始总价
|
|
252
|
+
* @description 当前总价计算基于商品数量为1
|
|
253
|
+
* @param item 商品
|
|
254
|
+
* @returns 商品原始总价
|
|
255
|
+
*/
|
|
256
|
+
const getProductOriginTotalPrice = params => {
|
|
257
|
+
const {
|
|
258
|
+
product,
|
|
259
|
+
bundle,
|
|
260
|
+
options,
|
|
261
|
+
discounts
|
|
262
|
+
} = params;
|
|
263
|
+
const num = params?.num || 1;
|
|
255
264
|
let price = Number(product.original_price);
|
|
256
|
-
if ((isNaN(price) || price === 0) && !
|
|
257
|
-
return
|
|
265
|
+
if ((isNaN(price) || price === 0) && !discounts?.length) {
|
|
266
|
+
return undefined;
|
|
258
267
|
}
|
|
259
|
-
if (bundle
|
|
268
|
+
if (bundle?.length) {
|
|
260
269
|
price = bundle.reduce((accumulator, currentValue) => {
|
|
261
270
|
return accumulator + Number(currentValue.price) * Number(currentValue.num);
|
|
262
271
|
}, price);
|
|
263
272
|
}
|
|
264
|
-
|
|
273
|
+
|
|
274
|
+
// 单规格
|
|
275
|
+
if (options?.length) {
|
|
265
276
|
price = options.reduce((accumulator, currentValue) => {
|
|
266
277
|
return accumulator + Number(currentValue.price) * Number(currentValue.num);
|
|
267
278
|
}, price);
|
|
268
279
|
}
|
|
269
280
|
return price;
|
|
270
281
|
};
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* 格式化套餐规格信息
|
|
285
|
+
* @param options 套餐规格信息
|
|
286
|
+
* @returns 格式化后的套餐规格信息
|
|
287
|
+
*/
|
|
288
|
+
exports.getProductOriginTotalPrice = getProductOriginTotalPrice;
|
|
289
|
+
const formatOptions = options => {
|
|
290
|
+
if (!options?.length) return [];
|
|
291
|
+
return options.map(item => {
|
|
275
292
|
return {
|
|
276
|
-
id: item
|
|
277
|
-
name: item
|
|
278
|
-
num: item
|
|
279
|
-
price: item
|
|
280
|
-
total: item
|
|
281
|
-
origin_total: item
|
|
293
|
+
id: item?.id,
|
|
294
|
+
name: item?.name,
|
|
295
|
+
num: item?.num,
|
|
296
|
+
price: item?.price,
|
|
297
|
+
total: item?.price,
|
|
298
|
+
origin_total: item?.original_price
|
|
282
299
|
};
|
|
283
300
|
});
|
|
284
301
|
};
|
|
285
|
-
|
|
286
|
-
|
|
302
|
+
exports.formatOptions = formatOptions;
|
|
303
|
+
const formatOptionsToOrigin = options => {
|
|
304
|
+
if (!options?.length) {
|
|
287
305
|
return [];
|
|
288
306
|
}
|
|
289
|
-
return options.map(
|
|
307
|
+
return options.map(d => {
|
|
290
308
|
return {
|
|
291
309
|
num: d.num,
|
|
292
310
|
option_group_item_id: d.product_option_item_id,
|
|
@@ -294,53 +312,57 @@ var formatOptionsToOrigin = (options) => {
|
|
|
294
312
|
};
|
|
295
313
|
});
|
|
296
314
|
};
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* 格式化商品套餐信息
|
|
318
|
+
* @param bundle 商品套餐信息
|
|
319
|
+
* @returns 格式化后的商品套餐信息
|
|
320
|
+
*/
|
|
321
|
+
exports.formatOptionsToOrigin = formatOptionsToOrigin;
|
|
322
|
+
const formatBundle = bundle => {
|
|
323
|
+
if (!bundle?.length) return [];
|
|
324
|
+
return bundle.map(item => {
|
|
301
325
|
return {
|
|
302
|
-
id: item
|
|
303
|
-
title: item
|
|
304
|
-
num: item
|
|
305
|
-
price: item
|
|
306
|
-
total: item
|
|
307
|
-
price_type: item
|
|
308
|
-
original_price: item
|
|
309
|
-
original_total: item
|
|
310
|
-
price_type_ext: item
|
|
311
|
-
bundle_sum_price: item
|
|
312
|
-
bundle_sum_type: item
|
|
313
|
-
options: formatOptions(item
|
|
326
|
+
id: item?.id,
|
|
327
|
+
title: item?.title,
|
|
328
|
+
num: item?.num,
|
|
329
|
+
price: item?.price,
|
|
330
|
+
total: item?.price,
|
|
331
|
+
price_type: item?.price_type,
|
|
332
|
+
original_price: item?.original_price,
|
|
333
|
+
original_total: item?.original_total,
|
|
334
|
+
price_type_ext: item?.price_type_ext,
|
|
335
|
+
bundle_sum_price: item?.bundle_sum_price,
|
|
336
|
+
bundle_sum_type: item?.bundle_sum_type,
|
|
337
|
+
options: formatOptions(item?.option),
|
|
314
338
|
_bundle_product_id: item._bundle_product_id,
|
|
315
339
|
discount_list: item.discount_list,
|
|
316
340
|
originBundleItem: item.originBundleItem || item,
|
|
317
|
-
is_charge_tax: item
|
|
341
|
+
is_charge_tax: item?.is_charge_tax
|
|
318
342
|
};
|
|
319
343
|
});
|
|
320
344
|
};
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
return bundle.map(
|
|
325
|
-
const getBundleValueByKey =
|
|
326
|
-
|
|
327
|
-
return (d == null ? void 0 : d[key]) || ((_a = d == null ? void 0 : d.originBundleItem) == null ? void 0 : _a[key]);
|
|
345
|
+
exports.formatBundle = formatBundle;
|
|
346
|
+
const formatBundleToOrigin = bundle => {
|
|
347
|
+
if (!bundle?.length) return [];
|
|
348
|
+
return bundle.map(d => {
|
|
349
|
+
const getBundleValueByKey = key => {
|
|
350
|
+
return d?.[key] || d?.originBundleItem?.[key];
|
|
328
351
|
};
|
|
329
|
-
const product_discount_difference = (
|
|
330
|
-
|
|
331
|
-
return pre + (((_a = cur == null ? void 0 : cur.metadata) == null ? void 0 : _a.product_discount_difference) || 0);
|
|
352
|
+
const product_discount_difference = (d?.discount_list || []).reduce((pre, cur) => {
|
|
353
|
+
return pre + (cur?.metadata?.product_discount_difference || 0);
|
|
332
354
|
}, 0);
|
|
333
355
|
return {
|
|
334
|
-
bundle_group_id: getBundleValueByKey(
|
|
356
|
+
bundle_group_id: getBundleValueByKey('group_id'),
|
|
335
357
|
bundle_id: d.id,
|
|
336
|
-
bundle_product_id: getBundleValueByKey(
|
|
337
|
-
bundle_variant_id: getBundleValueByKey(
|
|
358
|
+
bundle_product_id: getBundleValueByKey('_bundle_product_id') || getBundleValueByKey('product_id'),
|
|
359
|
+
bundle_variant_id: getBundleValueByKey('bundle_variant_id'),
|
|
338
360
|
num: d.num,
|
|
339
|
-
extension_id: getBundleValueByKey(
|
|
340
|
-
extension_type: getBundleValueByKey(
|
|
341
|
-
option: formatOptionsToOrigin(getBundleValueByKey(
|
|
361
|
+
extension_id: getBundleValueByKey('extension_id'),
|
|
362
|
+
extension_type: getBundleValueByKey('extension_type'),
|
|
363
|
+
option: formatOptionsToOrigin(getBundleValueByKey('option')),
|
|
342
364
|
discount_list: d.discount_list,
|
|
343
|
-
"bundle_selling_price": d
|
|
365
|
+
"bundle_selling_price": d?.price,
|
|
344
366
|
// "custom_price": d?.price,
|
|
345
367
|
metadata: {
|
|
346
368
|
custom_product_bundle_map_id: d._id,
|
|
@@ -349,103 +371,146 @@ var formatBundleToOrigin = (bundle) => {
|
|
|
349
371
|
};
|
|
350
372
|
});
|
|
351
373
|
};
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* 获取商品定金
|
|
377
|
+
* @description 定金基于商品售价来算,最终乘商品数量
|
|
378
|
+
* 1、如果套餐主商品有定金规则,则定金为:(套餐商品总售价 * 定金百分比 + 定金固定金额)* 商品数量
|
|
379
|
+
* 2、如果套餐主商品没有定金规则,子商品有定金规则,则定金为:(套餐子商品售价 * 套餐子商品定金百分比 + 套餐子商品定金固定金额)* 商品数量,最终将所有子商品定金相加
|
|
380
|
+
* 3、普通商品/单规格商品/组合规则商品,定金规则:(商品总售价 * 定金百分比 + 定金固定金额)* 商品数量
|
|
381
|
+
* @param params 参数
|
|
382
|
+
* @returns 商品定金
|
|
383
|
+
*/
|
|
384
|
+
exports.formatBundleToOrigin = formatBundleToOrigin;
|
|
385
|
+
const getProductDeposit = params => {
|
|
386
|
+
const {
|
|
387
|
+
cartItem,
|
|
388
|
+
product,
|
|
389
|
+
bundle,
|
|
390
|
+
options
|
|
391
|
+
} = params;
|
|
392
|
+
const num = params?.num || 1;
|
|
393
|
+
|
|
394
|
+
// 判定商品是否有定金规则
|
|
395
|
+
if (product?.custom_deposit_data?.has_deposit == 1) {
|
|
396
|
+
let total = new _decimal.default(0);
|
|
358
397
|
const {
|
|
359
398
|
deposit_fixed,
|
|
360
399
|
deposit_percentage,
|
|
361
400
|
deposit_policy_data,
|
|
362
401
|
self_deposit_policy_ids
|
|
363
|
-
} =
|
|
402
|
+
} = product?.custom_deposit_data || {};
|
|
403
|
+
// 所有协议数据
|
|
364
404
|
const allProtocols = deposit_policy_data || [];
|
|
405
|
+
// 是否存在定金,主商品has_deposit为1,但是自身没有定金设置,需要判定子商品是否存在定金,如果不存在最终判定也是不存在定金
|
|
365
406
|
let productHasDeposit = false;
|
|
407
|
+
// 关联的定金协议id
|
|
366
408
|
const protocolIds = [];
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
409
|
+
|
|
410
|
+
// 判断主商品是否有定金规则
|
|
411
|
+
if (typeof deposit_fixed === 'string' && typeof deposit_percentage === 'string') {
|
|
412
|
+
const {
|
|
413
|
+
depositTotal,
|
|
414
|
+
result
|
|
415
|
+
} = handleProductDeposit({
|
|
416
|
+
depositData: product?.custom_deposit_data,
|
|
370
417
|
total: cartItem.total || 0,
|
|
371
418
|
num
|
|
372
419
|
});
|
|
373
420
|
if (result) {
|
|
374
421
|
total = depositTotal;
|
|
375
|
-
protocolIds.push(...self_deposit_policy_ids || []);
|
|
422
|
+
protocolIds.push(...(self_deposit_policy_ids || []));
|
|
376
423
|
productHasDeposit = true;
|
|
377
424
|
}
|
|
378
425
|
} else {
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
);
|
|
426
|
+
// 组合规格商品
|
|
427
|
+
if (product?.product_variant_id) {
|
|
428
|
+
const variantProduct = product?.variant?.find(item => item?.id === product?.product_variant_id);
|
|
383
429
|
if (variantProduct) {
|
|
384
|
-
const depositData = variantProduct
|
|
385
|
-
const {
|
|
430
|
+
const depositData = variantProduct?.custom_deposit_data;
|
|
431
|
+
const {
|
|
432
|
+
depositTotal,
|
|
433
|
+
result
|
|
434
|
+
} = handleProductDeposit({
|
|
386
435
|
depositData,
|
|
387
|
-
total:
|
|
436
|
+
total: cartItem?.total || 0,
|
|
388
437
|
num
|
|
389
438
|
});
|
|
390
439
|
if (result) {
|
|
391
440
|
total = depositTotal;
|
|
392
|
-
protocolIds.push(...(depositData
|
|
441
|
+
protocolIds.push(...(depositData?.self_deposit_policy_ids || []));
|
|
393
442
|
productHasDeposit = true;
|
|
394
443
|
}
|
|
395
444
|
}
|
|
396
445
|
}
|
|
397
|
-
if (bundle
|
|
446
|
+
if (bundle?.length) {
|
|
398
447
|
total = bundle.reduce((accumulator, currBundleProduct) => {
|
|
399
|
-
const depositData = currBundleProduct
|
|
400
|
-
const {
|
|
448
|
+
const depositData = currBundleProduct?.custom_deposit_data;
|
|
449
|
+
const {
|
|
450
|
+
depositTotal,
|
|
451
|
+
result
|
|
452
|
+
} = handleProductDeposit({
|
|
401
453
|
depositData,
|
|
402
|
-
total: currBundleProduct
|
|
403
|
-
num:
|
|
454
|
+
total: currBundleProduct?.price,
|
|
455
|
+
num: currBundleProduct?.num || 1
|
|
404
456
|
});
|
|
405
457
|
if (result) {
|
|
406
|
-
protocolIds.push(...(depositData
|
|
458
|
+
protocolIds.push(...(depositData?.self_deposit_policy_ids || []));
|
|
407
459
|
productHasDeposit = true;
|
|
408
460
|
return accumulator.plus(depositTotal);
|
|
409
461
|
}
|
|
410
462
|
return accumulator;
|
|
411
|
-
}, new
|
|
463
|
+
}, new _decimal.default(0));
|
|
412
464
|
}
|
|
413
465
|
}
|
|
414
466
|
if (productHasDeposit) {
|
|
415
467
|
const ids = new Set(protocolIds);
|
|
416
|
-
const protocols = allProtocols.filter(
|
|
417
|
-
return {
|
|
468
|
+
const protocols = allProtocols.filter(item => ids.has(item.id));
|
|
469
|
+
return {
|
|
470
|
+
total: total.toNumber(),
|
|
471
|
+
protocols
|
|
472
|
+
};
|
|
418
473
|
}
|
|
419
474
|
return null;
|
|
420
475
|
}
|
|
421
476
|
return null;
|
|
422
477
|
};
|
|
423
|
-
|
|
424
|
-
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* 计算商品定金
|
|
481
|
+
* @param params 参数
|
|
482
|
+
* @returns 商品定金
|
|
483
|
+
*/
|
|
484
|
+
exports.getProductDeposit = getProductDeposit;
|
|
485
|
+
const handleProductDeposit = params => {
|
|
486
|
+
const {
|
|
487
|
+
depositData,
|
|
488
|
+
total,
|
|
489
|
+
num
|
|
490
|
+
} = params;
|
|
425
491
|
if (!depositData) {
|
|
426
|
-
return {
|
|
492
|
+
return {
|
|
493
|
+
result: false,
|
|
494
|
+
depositTotal: new _decimal.default(0)
|
|
495
|
+
};
|
|
427
496
|
}
|
|
428
|
-
const {
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
497
|
+
const {
|
|
498
|
+
deposit_fixed,
|
|
499
|
+
deposit_percentage
|
|
500
|
+
} = depositData || {};
|
|
501
|
+
if (typeof deposit_fixed === 'string' && typeof deposit_percentage === 'string') {
|
|
502
|
+
const depositFixed = (0, _decimal.default)(deposit_fixed || 0);
|
|
503
|
+
const depositPercent = (0, _decimal.default)(deposit_percentage || 0);
|
|
504
|
+
const productTotalPrice = (0, _decimal.default)(total || 0);
|
|
433
505
|
const deposit = depositFixed.plus(depositPercent.times(productTotalPrice));
|
|
434
|
-
return {
|
|
506
|
+
return {
|
|
507
|
+
depositTotal: deposit.times(num),
|
|
508
|
+
result: true
|
|
509
|
+
};
|
|
435
510
|
}
|
|
436
|
-
return {
|
|
511
|
+
return {
|
|
512
|
+
result: false,
|
|
513
|
+
depositTotal: new _decimal.default(0)
|
|
514
|
+
};
|
|
437
515
|
};
|
|
438
|
-
|
|
439
|
-
0 && (module.exports = {
|
|
440
|
-
formatBundle,
|
|
441
|
-
formatBundleToOrigin,
|
|
442
|
-
formatOptions,
|
|
443
|
-
formatOptionsToOrigin,
|
|
444
|
-
formatProductToCartItem,
|
|
445
|
-
formatProductToCartItemOrigin,
|
|
446
|
-
getProductDeposit,
|
|
447
|
-
getProductOriginTotalPrice,
|
|
448
|
-
getProductTotalPrice,
|
|
449
|
-
handleProductDeposit,
|
|
450
|
-
handleVariantProduct
|
|
451
|
-
});
|
|
516
|
+
exports.handleProductDeposit = handleProductDeposit;
|