@pisell/pisellos 2.3.74 → 2.3.75
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 -10
- package/dist/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/model/strategy/adapter/walletPass/example.js +3 -26
- 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 +2 -4
- package/dist/modules/OpenData/index.js +0 -2
- package/dist/modules/Order/index.js +36 -64
- package/dist/modules/Payment/index.js +97 -162
- package/dist/modules/Rules/index.js +1 -4
- package/dist/modules/Schedule/index.js +0 -1
- 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 +97 -129
- package/dist/server/modules/menu/index.js +32 -41
- package/dist/server/modules/order/index.js +2 -4
- package/dist/server/modules/products/index.js +24 -42
- 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 +27 -35
- package/dist/server/utils/product.js +0 -1
- package/dist/solution/BaseSales/index.js +38 -41
- 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.js +0 -2
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +6 -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 -252
- 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.js +45 -55
- 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 +134 -134
- package/lib/effects/index.js +46 -57
- package/lib/index.js +82 -49
- 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 +91 -69
- package/lib/model/strategy/adapter/promotion/evaluator.js +444 -310
- package/lib/model/strategy/adapter/promotion/examples.js +222 -234
- package/lib/model/strategy/adapter/promotion/index.js +1 -0
- package/lib/model/strategy/adapter/promotion/type.js +243 -36
- package/lib/model/strategy/adapter/type.js +4 -16
- package/lib/model/strategy/adapter/walletPass/evaluator.js +180 -150
- 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 +588 -378
- 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 +23 -42
- package/lib/modules/BookingContext/index.js +158 -136
- package/lib/modules/BookingContext/types.js +46 -32
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +138 -146
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +78 -83
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +170 -150
- package/lib/modules/BookingContext/utils/flexible.js +38 -55
- package/lib/modules/BookingContext/utils/formatResourceList.js +19 -34
- package/lib/modules/BookingContext/utils/index.js +124 -41
- package/lib/modules/BookingContext/utils/noResource.js +58 -70
- package/lib/modules/BookingContext/utils/orderLineDisplay.js +14 -41
- package/lib/modules/BookingContext/utils/productExtend.js +202 -155
- package/lib/modules/BookingContext/utils/resourceErrors.js +53 -53
- package/lib/modules/BookingContext/utils/resourceSelection.js +19 -41
- package/lib/modules/BookingContext/utils/resources.js +209 -167
- package/lib/modules/BookingContext/utils/serviceTimes.js +115 -116
- package/lib/modules/BookingContext/utils/timeSlices.js +76 -86
- 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 +321 -251
- package/lib/modules/Cart/utils/cartRelationForms.js +29 -35
- package/lib/modules/Cart/utils/cartResource.js +70 -78
- package/lib/modules/Cart/utils/changePrice.js +22 -50
- package/lib/modules/Cart/utils/index.js +106 -48
- package/lib/modules/Customer/constants.js +13 -34
- package/lib/modules/Customer/index.js +235 -172
- 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 +122 -127
- 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 +70 -76
- package/lib/modules/OpenData/types.js +4 -16
- package/lib/modules/OpenData/utils.js +44 -78
- package/lib/modules/Order/index.js +1713 -2118
- package/lib/modules/Order/payment-utils.js +77 -120
- package/lib/modules/Order/types.js +88 -35
- package/lib/modules/Order/utils/bundleDiscountHydration.js +41 -74
- package/lib/modules/Order/utils/discountProductLineIdentity.js +142 -100
- package/lib/modules/Order/utils/manualProductDiscount.js +124 -123
- package/lib/modules/Order/utils/orderCollectionIdentity.js +184 -244
- package/lib/modules/Order/utils.js +814 -647
- 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 +532 -399
- package/lib/modules/Payment/mx51.js +1 -0
- package/lib/modules/Payment/types.js +230 -108
- package/lib/modules/Payment/utils.js +52 -51
- package/lib/modules/Payment/walletpass.js +485 -660
- 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 +113 -123
- package/lib/modules/ProductList/types.js +9 -31
- package/lib/modules/Quotation/index.js +81 -118
- 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/ResourcePlanner/index.js +25 -23
- package/lib/modules/ResourcePlanner/localClock.js +54 -119
- package/lib/modules/ResourcePlanner/planner.js +589 -770
- package/lib/modules/ResourcePlanner/types.js +10 -29
- package/lib/modules/Rules/index.js +1218 -959
- package/lib/modules/Rules/types.js +17 -40
- package/lib/modules/SalesSummary/index.js +85 -90
- package/lib/modules/SalesSummary/types.js +4 -16
- package/lib/modules/SalesSummary/utils.js +355 -430
- 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 -163
- package/lib/modules/Schedule/index.js +100 -114
- 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 -71
- package/lib/modules/Summary/types.js +4 -16
- package/lib/modules/Summary/utils.js +773 -418
- package/lib/modules/SurchargeList/index.js +46 -60
- package/lib/modules/SurchargeList/types.js +4 -16
- package/lib/modules/index.js +245 -63
- 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 +3050 -2665
- package/lib/server/modules/floor-plan/index.js +118 -134
- package/lib/server/modules/floor-plan/types.js +15 -30
- package/lib/server/modules/index.js +106 -68
- package/lib/server/modules/menu/index.js +142 -122
- package/lib/server/modules/menu/types.js +18 -31
- package/lib/server/modules/order/index.js +784 -1002
- package/lib/server/modules/order/types.js +122 -33
- package/lib/server/modules/order/utils/filterBookings.js +219 -194
- package/lib/server/modules/order/utils/filterOrders.js +118 -92
- package/lib/server/modules/payment/index.js +59 -83
- package/lib/server/modules/payment/types.js +4 -16
- package/lib/server/modules/products/index.js +583 -471
- package/lib/server/modules/products/types.js +44 -34
- package/lib/server/modules/quotation/index.js +137 -172
- package/lib/server/modules/quotation/types.js +21 -31
- package/lib/server/modules/resource/index.js +220 -186
- package/lib/server/modules/resource/types.js +42 -33
- package/lib/server/modules/schedule/index.js +135 -123
- 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/small-ticket.js +479 -456
- package/lib/server/utils/time.js +40 -49
- package/lib/solution/BaseSales/index.js +1186 -1410
- package/lib/solution/BaseSales/types.js +42 -38
- package/lib/solution/BaseSales/utils/cartPromotion.js +642 -498
- package/lib/solution/BaseSales/utils/parseSalesResponse.js +85 -105
- package/lib/solution/BaseSales/utils/quotationPrice.js +56 -114
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +108 -145
- package/lib/solution/BaseSales/utils.js +158 -143
- package/lib/solution/BookingByStep/index.js +1527 -1340
- 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.js +607 -522
- package/lib/solution/BookingTicket/types.js +99 -77
- package/lib/solution/BookingTicket/utils/addProductDecision.js +226 -189
- package/lib/solution/BookingTicket/utils/addTimeAvailability.js +58 -89
- package/lib/solution/BookingTicket/utils/bookingStatus.js +107 -78
- package/lib/solution/BookingTicket/utils/cartView.js +114 -99
- package/lib/solution/BookingTicket/utils/exampleData.js +185 -0
- package/lib/solution/BookingTicket/utils/orderCustomer.js +18 -41
- package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +219 -86
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +168 -116
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +79 -91
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +54 -41
- package/lib/solution/BookingTicket/utils/scan/handleScan.js +84 -81
- package/lib/solution/BookingTicket/utils/scan/index.js +98 -104
- package/lib/solution/BookingTicket/utils/scan/scanCache.js +90 -43
- package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +52 -64
- package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +56 -58
- package/lib/solution/BookingTicket/utils/weighingProductSku.js +34 -48
- 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 +228 -156
- 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 +328 -324
- package/lib/solution/Sales/types.js +27 -33
- package/lib/solution/ScanOrder/index.js +832 -864
- package/lib/solution/ScanOrder/types.js +33 -34
- package/lib/solution/ScanOrder/utils.js +409 -374
- package/lib/solution/ShopDiscount/index.js +226 -232
- package/lib/solution/ShopDiscount/types.js +15 -37
- package/lib/solution/ShopDiscount/utils.js +300 -172
- package/lib/solution/UnifiedBookingSales/index.js +1035 -1201
- package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.js +99 -159
- package/lib/solution/UnifiedBookingSales/types.js +10 -32
- package/lib/solution/VenueBooking/index.js +811 -879
- package/lib/solution/VenueBooking/types.js +19 -39
- package/lib/solution/VenueBooking/utils/dateSummary.js +27 -56
- package/lib/solution/VenueBooking/utils/resource.js +31 -54
- package/lib/solution/VenueBooking/utils/slotMerge.js +94 -107
- package/lib/solution/VenueBooking/utils/timeSlot.js +132 -132
- package/lib/solution/VenueBooking/utils.js +130 -67
- package/lib/solution/index.js +124 -41
- package/lib/store/createStore.js +32 -29
- package/lib/types/index.js +4 -16
- package/lib/utils/payment-number.js +26 -46
- package/lib/utils/task.js +36 -36
- package/lib/utils/watch.js +81 -47
- package/package.json +2 -1
|
@@ -1,72 +1,40 @@
|
|
|
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
|
-
var
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
+
var _utils4 = require("../../Order/utils");
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
/** 与 Rules / ShopDiscount 一致的折扣入参,用于主价与 option 单价 */
|
|
14
|
+
const toDiscountPayload = discountItem => ({
|
|
15
|
+
amount: discountItem.amount,
|
|
16
|
+
tag: discountItem.type,
|
|
17
|
+
par_value: discountItem.discount?.percent,
|
|
18
|
+
config: discountItem.config,
|
|
19
|
+
metadata: {
|
|
20
|
+
discount_card_type: discountItem?.discount?.discount_card_type
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @title 处理组合商品
|
|
26
|
+
* @description 组合商品需要直接修改 product 里的价格和 is_charge_tax
|
|
27
|
+
* @param product 商品
|
|
28
|
+
* @returns 处理后的商品
|
|
29
|
+
*/
|
|
30
|
+
const handleVariantProduct = product => {
|
|
31
|
+
// 判断组合商品,然后直接修改 product 里的价格和 is_charge_tax
|
|
32
|
+
if (product?.product_variant_id) {
|
|
33
|
+
// 还需要判断 能从 variant 里找到对应的组合规格信息,才可以替换
|
|
34
|
+
const targetVariant = product?.variant?.find(n => n.id === product.product_variant_id);
|
|
68
35
|
if (targetVariant) {
|
|
69
36
|
product.price = targetVariant.price;
|
|
37
|
+
// 如果 original_price 为 0,就不改了
|
|
70
38
|
if (Number(targetVariant.original_price) > 0) {
|
|
71
39
|
product.original_price = targetVariant.original_price;
|
|
72
40
|
}
|
|
@@ -75,9 +43,14 @@ var handleVariantProduct = (product) => {
|
|
|
75
43
|
}
|
|
76
44
|
return product;
|
|
77
45
|
};
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 格式化商品到购物车
|
|
49
|
+
* @param product 商品
|
|
50
|
+
* @returns 格式化后的商品
|
|
51
|
+
*/
|
|
52
|
+
exports.handleVariantProduct = handleVariantProduct;
|
|
53
|
+
const formatProductToCartItem = params => {
|
|
81
54
|
const {
|
|
82
55
|
cartItem,
|
|
83
56
|
product,
|
|
@@ -87,14 +60,25 @@ var formatProductToCartItem = (params) => {
|
|
|
87
60
|
quantity = 1,
|
|
88
61
|
discounts
|
|
89
62
|
} = params;
|
|
90
|
-
const num = quantity;
|
|
63
|
+
const num = quantity; // 当前按照单个商品加入购物车
|
|
64
|
+
|
|
91
65
|
if (product) {
|
|
92
|
-
cartItem.id = product
|
|
93
|
-
cartItem.name = product
|
|
94
|
-
cartItem.price = product
|
|
66
|
+
cartItem.id = product?.id;
|
|
67
|
+
cartItem.name = product?.title;
|
|
68
|
+
cartItem.price = product?.price;
|
|
95
69
|
cartItem.num = num;
|
|
96
|
-
cartItem.total = getProductTotalPrice({
|
|
97
|
-
|
|
70
|
+
cartItem.total = getProductTotalPrice({
|
|
71
|
+
product,
|
|
72
|
+
bundle,
|
|
73
|
+
options,
|
|
74
|
+
num,
|
|
75
|
+
discounts
|
|
76
|
+
});
|
|
77
|
+
cartItem.totalDifference = getTotalDifference({
|
|
78
|
+
product,
|
|
79
|
+
bundle,
|
|
80
|
+
discounts
|
|
81
|
+
});
|
|
98
82
|
cartItem.summaryTotal = cartItem.total * (num || 1);
|
|
99
83
|
cartItem.origin_total = getProductOriginTotalPrice({
|
|
100
84
|
product,
|
|
@@ -103,6 +87,7 @@ var formatProductToCartItem = (params) => {
|
|
|
103
87
|
num,
|
|
104
88
|
discounts
|
|
105
89
|
});
|
|
90
|
+
// 不包含折扣卡商品券的总价
|
|
106
91
|
const origin_total = getProductTotalPrice({
|
|
107
92
|
product: cartItem._productInit || cartItem._productOrigin,
|
|
108
93
|
bundle,
|
|
@@ -111,44 +96,38 @@ var formatProductToCartItem = (params) => {
|
|
|
111
96
|
discounts: []
|
|
112
97
|
});
|
|
113
98
|
cartItem.summaryOriginTotal = (origin_total || 0) * (num || 1);
|
|
114
|
-
cartItem.image = product
|
|
115
|
-
cartItem.like_status =
|
|
116
|
-
cartItem.duration = product
|
|
117
|
-
cartItem.isNormalProduct = (0,
|
|
118
|
-
cartItem.is_charge_tax = product
|
|
99
|
+
cartItem.image = product?.cover;
|
|
100
|
+
cartItem.like_status = 'common';
|
|
101
|
+
cartItem.duration = product?.duration;
|
|
102
|
+
cartItem.isNormalProduct = (0, _utils.isNormalProduct)(product);
|
|
103
|
+
cartItem.is_charge_tax = product?.is_charge_tax;
|
|
119
104
|
}
|
|
120
|
-
if (bundle
|
|
105
|
+
if (bundle?.length) {
|
|
121
106
|
cartItem.bundle = formatBundle(bundle);
|
|
122
107
|
}
|
|
123
|
-
if (options
|
|
108
|
+
if (options?.length) {
|
|
124
109
|
cartItem.options = formatOptions(options);
|
|
125
110
|
}
|
|
111
|
+
// 拼装出 product_option_string
|
|
126
112
|
if (product_variant_id) {
|
|
127
|
-
const sku_key = (
|
|
128
|
-
(n) => n.id === product_variant_id
|
|
129
|
-
)) == null ? void 0 : _b.sku_key;
|
|
113
|
+
const sku_key = product?.variant?.find(n => n.id === product_variant_id)?.sku_key;
|
|
130
114
|
if (sku_key) {
|
|
131
|
-
const sku_key_arr = sku_key.split(
|
|
115
|
+
const sku_key_arr = sku_key.split('_');
|
|
132
116
|
const product_option_string = [];
|
|
133
|
-
sku_key_arr.forEach(
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
const
|
|
137
|
-
(n) => String(n.position_id) === keyMap[0]
|
|
138
|
-
);
|
|
139
|
-
const targetVariantItem = (_b2 = targetVariantGroup == null ? void 0 : targetVariantGroup.variant_item) == null ? void 0 : _b2.find(
|
|
140
|
-
(n) => String(n.position_id) === keyMap[1]
|
|
141
|
-
);
|
|
117
|
+
sku_key_arr.forEach(item => {
|
|
118
|
+
const keyMap = item.split(':');
|
|
119
|
+
const targetVariantGroup = product?.variant_group?.find(n => String(n.position_id) === keyMap[0]);
|
|
120
|
+
const targetVariantItem = targetVariantGroup?.variant_item?.find(n => String(n.position_id) === keyMap[1]);
|
|
142
121
|
if (targetVariantGroup && targetVariantItem) {
|
|
143
|
-
product_option_string.push(
|
|
144
|
-
`${targetVariantGroup.name}:${targetVariantItem.name}`
|
|
145
|
-
);
|
|
122
|
+
product_option_string.push(`${targetVariantGroup.name}:${targetVariantItem.name}`);
|
|
146
123
|
}
|
|
147
124
|
});
|
|
148
|
-
cartItem.product_option_string = product_option_string.join(
|
|
125
|
+
cartItem.product_option_string = product_option_string.join(', ');
|
|
149
126
|
}
|
|
150
127
|
}
|
|
151
|
-
|
|
128
|
+
|
|
129
|
+
// 如果商品有定金规则,则计算定金
|
|
130
|
+
if (product?.custom_deposit_data?.has_deposit == 1) {
|
|
152
131
|
cartItem.deposit = getProductDeposit({
|
|
153
132
|
cartItem,
|
|
154
133
|
product,
|
|
@@ -161,8 +140,8 @@ var formatProductToCartItem = (params) => {
|
|
|
161
140
|
cartItem._origin = oringin;
|
|
162
141
|
return cartItem;
|
|
163
142
|
};
|
|
164
|
-
|
|
165
|
-
|
|
143
|
+
exports.formatProductToCartItem = formatProductToCartItem;
|
|
144
|
+
const formatProductToCartItemOrigin = params => {
|
|
166
145
|
const {
|
|
167
146
|
cartItem,
|
|
168
147
|
product,
|
|
@@ -172,35 +151,38 @@ var formatProductToCartItemOrigin = (params) => {
|
|
|
172
151
|
quantity = 1
|
|
173
152
|
} = params;
|
|
174
153
|
let origin = cartItem._origin;
|
|
175
|
-
const product_discount_difference = (
|
|
176
|
-
|
|
177
|
-
return !((_a2 = item == null ? void 0 : item.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id);
|
|
178
|
-
}).reduce((pre, cur) => {
|
|
179
|
-
var _a2;
|
|
180
|
-
return pre + (((_a2 = cur == null ? void 0 : cur.metadata) == null ? void 0 : _a2.product_discount_difference) || 0);
|
|
154
|
+
const product_discount_difference = (origin.product?.discount_list || []).filter(item => !item?.metadata?.custom_product_bundle_map_id).reduce((pre, cur) => {
|
|
155
|
+
return pre + (cur?.metadata?.product_discount_difference || 0);
|
|
181
156
|
}, 0);
|
|
182
157
|
if (product) {
|
|
183
158
|
origin.product = {
|
|
184
|
-
...origin.product || {},
|
|
159
|
+
...(origin.product || {}),
|
|
185
160
|
num: quantity,
|
|
186
161
|
product_id: product.id,
|
|
187
162
|
product_variant_id: product_variant_id || 0,
|
|
188
|
-
product_bundle:
|
|
189
|
-
product_sku:
|
|
163
|
+
product_bundle: origin.product?.product_bundle || [],
|
|
164
|
+
product_sku: origin.product?.product_sku || {
|
|
165
|
+
option: []
|
|
166
|
+
},
|
|
190
167
|
metadata: {
|
|
191
168
|
product_discount_difference
|
|
192
169
|
}
|
|
193
170
|
};
|
|
194
|
-
|
|
195
|
-
origin.
|
|
196
|
-
|
|
171
|
+
// 时长类型
|
|
172
|
+
origin.sub_type = product?.duration?.type;
|
|
173
|
+
// 时长
|
|
174
|
+
origin.duration = product?.duration?.value;
|
|
175
|
+
if (bundle?.length) {
|
|
197
176
|
origin.product.product_bundle = formatBundleToOrigin(bundle);
|
|
198
177
|
}
|
|
199
|
-
if (options
|
|
178
|
+
if (options?.length) {
|
|
200
179
|
origin.product.product_sku = {
|
|
201
|
-
...origin.product.product_sku || {},
|
|
202
|
-
option: formatOptionsToOrigin(options).map(
|
|
203
|
-
const next = {
|
|
180
|
+
...(origin.product.product_sku || {}),
|
|
181
|
+
option: formatOptionsToOrigin(options).map(option => {
|
|
182
|
+
const next = {
|
|
183
|
+
...option,
|
|
184
|
+
add_price: option.add_price ?? option.price
|
|
185
|
+
};
|
|
204
186
|
delete next.price;
|
|
205
187
|
return next;
|
|
206
188
|
})
|
|
@@ -209,92 +191,133 @@ var formatProductToCartItemOrigin = (params) => {
|
|
|
209
191
|
}
|
|
210
192
|
return origin;
|
|
211
193
|
};
|
|
212
|
-
|
|
213
|
-
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* 获取商品总价
|
|
197
|
+
* @description 当前总价计算基于商品数量为1
|
|
198
|
+
* @param item 商品
|
|
199
|
+
* @returns 商品总价
|
|
200
|
+
*/
|
|
201
|
+
exports.formatProductToCartItemOrigin = formatProductToCartItemOrigin;
|
|
202
|
+
const getProductTotalPrice = params => {
|
|
203
|
+
const {
|
|
204
|
+
product,
|
|
205
|
+
bundle,
|
|
206
|
+
options,
|
|
207
|
+
discounts
|
|
208
|
+
} = params;
|
|
209
|
+
// const num = params.num || 1;
|
|
214
210
|
let price = Number(product.price);
|
|
215
|
-
|
|
211
|
+
|
|
212
|
+
// option 行:unit 折后价在循环中与主商品使用同一套 getDiscountAmount(含 deductOptionPrice)
|
|
213
|
+
const optionRows = options?.map(currentValue => ({
|
|
216
214
|
unit: Number(currentValue.price ?? currentValue.add_price ?? 0),
|
|
217
215
|
num: Number(currentValue.num ?? currentValue.quantity ?? 1)
|
|
218
|
-
}))
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
216
|
+
})) ?? [];
|
|
217
|
+
|
|
218
|
+
// 如果商品有折扣,则计算折扣
|
|
219
|
+
if (discounts?.length) {
|
|
220
|
+
discounts.forEach(currentValue => {
|
|
222
221
|
const payload = toDiscountPayload(currentValue);
|
|
223
|
-
price = (0,
|
|
224
|
-
if (
|
|
222
|
+
price = (0, _utils2.getDiscountAmount)(payload, price, price);
|
|
223
|
+
if (currentValue?.config?.deductOptionPrice && optionRows.length) {
|
|
225
224
|
for (let i = 0; i < optionRows.length; i++) {
|
|
226
225
|
const row = optionRows[i];
|
|
227
226
|
optionRows[i] = {
|
|
228
227
|
...row,
|
|
229
|
-
unit: (0,
|
|
228
|
+
unit: (0, _utils2.getDiscountAmount)(payload, row.unit, row.unit)
|
|
230
229
|
};
|
|
231
230
|
}
|
|
232
231
|
}
|
|
233
232
|
});
|
|
234
233
|
}
|
|
235
|
-
if (bundle
|
|
234
|
+
if (bundle?.length) {
|
|
236
235
|
price = bundle.reduce((accumulator, currentValue) => {
|
|
237
236
|
return accumulator + Number(currentValue.price) * Number(currentValue.num);
|
|
238
237
|
}, price);
|
|
239
238
|
}
|
|
239
|
+
|
|
240
|
+
// 单规格 / 加购 option
|
|
240
241
|
if (optionRows.length) {
|
|
241
|
-
price = optionRows.reduce(
|
|
242
|
-
(accumulator, row) => accumulator + row.unit * row.num,
|
|
243
|
-
price
|
|
244
|
-
);
|
|
242
|
+
price = optionRows.reduce((accumulator, row) => accumulator + row.unit * row.num, price);
|
|
245
243
|
}
|
|
246
244
|
return Math.max(0, price);
|
|
247
245
|
};
|
|
248
|
-
|
|
249
|
-
|
|
246
|
+
exports.getProductTotalPrice = getProductTotalPrice;
|
|
247
|
+
const getTotalDifference = params => {
|
|
248
|
+
const {
|
|
249
|
+
bundle,
|
|
250
|
+
discounts
|
|
251
|
+
} = params;
|
|
250
252
|
const bundleDiscountList = [];
|
|
251
|
-
if (bundle
|
|
252
|
-
bundle.forEach(
|
|
253
|
-
bundleDiscountList.push(...(currentValue
|
|
253
|
+
if (bundle?.length) {
|
|
254
|
+
bundle.forEach(currentValue => {
|
|
255
|
+
bundleDiscountList.push(...(currentValue?.discount_list || []));
|
|
254
256
|
});
|
|
255
257
|
}
|
|
256
|
-
const allDiscounts = [...discounts || [], ...bundleDiscountList];
|
|
257
|
-
const productDiscountProductDiscountDifference = (0,
|
|
258
|
+
const allDiscounts = [...(discounts || []), ...bundleDiscountList];
|
|
259
|
+
const productDiscountProductDiscountDifference = (0, _utils3.calcDiscountListDifference)(allDiscounts);
|
|
258
260
|
return productDiscountProductDiscountDifference || 0;
|
|
259
261
|
};
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* 获取商品原始总价
|
|
265
|
+
* @description 当前总价计算基于商品数量为1
|
|
266
|
+
* @param item 商品
|
|
267
|
+
* @returns 商品原始总价
|
|
268
|
+
*/
|
|
269
|
+
const getProductOriginTotalPrice = params => {
|
|
270
|
+
const {
|
|
271
|
+
product,
|
|
272
|
+
bundle,
|
|
273
|
+
options,
|
|
274
|
+
discounts
|
|
275
|
+
} = params;
|
|
276
|
+
const num = params?.num || 1;
|
|
263
277
|
let price = Number(product.original_price);
|
|
264
|
-
if ((isNaN(price) || price === 0) && !
|
|
265
|
-
return
|
|
278
|
+
if ((isNaN(price) || price === 0) && !discounts?.length) {
|
|
279
|
+
return undefined;
|
|
266
280
|
}
|
|
267
|
-
if (bundle
|
|
281
|
+
if (bundle?.length) {
|
|
268
282
|
price = bundle.reduce((accumulator, currentValue) => {
|
|
269
283
|
return accumulator + Number(currentValue.price) * Number(currentValue.num);
|
|
270
284
|
}, price);
|
|
271
285
|
}
|
|
272
|
-
|
|
286
|
+
|
|
287
|
+
// 单规格
|
|
288
|
+
if (options?.length) {
|
|
273
289
|
price = options.reduce((accumulator, currentValue) => {
|
|
274
290
|
return accumulator + Number(currentValue.price) * Number(currentValue.num);
|
|
275
291
|
}, price);
|
|
276
292
|
}
|
|
277
293
|
return price;
|
|
278
294
|
};
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* 格式化套餐规格信息
|
|
298
|
+
* @param options 套餐规格信息
|
|
299
|
+
* @returns 格式化后的套餐规格信息
|
|
300
|
+
*/
|
|
301
|
+
exports.getProductOriginTotalPrice = getProductOriginTotalPrice;
|
|
302
|
+
const formatOptions = options => {
|
|
303
|
+
if (!options?.length) return [];
|
|
304
|
+
return options.map(item => {
|
|
283
305
|
return {
|
|
284
|
-
id: item
|
|
285
|
-
name: item
|
|
286
|
-
num: item
|
|
287
|
-
price: item
|
|
288
|
-
total: item
|
|
289
|
-
origin_total: item
|
|
306
|
+
id: item?.id,
|
|
307
|
+
name: item?.name,
|
|
308
|
+
num: item?.num,
|
|
309
|
+
price: item?.price,
|
|
310
|
+
total: item?.price,
|
|
311
|
+
origin_total: item?.original_price
|
|
290
312
|
};
|
|
291
313
|
});
|
|
292
314
|
};
|
|
293
|
-
|
|
294
|
-
|
|
315
|
+
exports.formatOptions = formatOptions;
|
|
316
|
+
const formatOptionsToOrigin = options => {
|
|
317
|
+
if (!options?.length) {
|
|
295
318
|
return [];
|
|
296
319
|
}
|
|
297
|
-
return options.map(
|
|
320
|
+
return options.map(d => {
|
|
298
321
|
return {
|
|
299
322
|
num: d.num,
|
|
300
323
|
option_group_item_id: d.option_group_item_id,
|
|
@@ -302,63 +325,67 @@ var formatOptionsToOrigin = (options) => {
|
|
|
302
325
|
};
|
|
303
326
|
});
|
|
304
327
|
};
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* 格式化商品套餐信息
|
|
331
|
+
* @param bundle 商品套餐信息
|
|
332
|
+
* @returns 格式化后的商品套餐信息
|
|
333
|
+
*/
|
|
334
|
+
exports.formatOptionsToOrigin = formatOptionsToOrigin;
|
|
335
|
+
const formatBundle = bundle => {
|
|
336
|
+
if (!bundle?.length) return [];
|
|
337
|
+
return bundle.map(item => {
|
|
309
338
|
return {
|
|
310
|
-
id: item
|
|
311
|
-
title: item
|
|
312
|
-
num: item
|
|
313
|
-
price: item
|
|
314
|
-
total: item
|
|
315
|
-
price_type: item
|
|
316
|
-
original_price: item
|
|
317
|
-
original_total: item
|
|
318
|
-
price_type_ext: item
|
|
319
|
-
bundle_sum_price: item
|
|
320
|
-
bundle_sum_type: item
|
|
321
|
-
options: formatOptions(item
|
|
339
|
+
id: item?.id,
|
|
340
|
+
title: item?.title,
|
|
341
|
+
num: item?.num,
|
|
342
|
+
price: item?.price,
|
|
343
|
+
total: item?.price,
|
|
344
|
+
price_type: item?.price_type,
|
|
345
|
+
original_price: item?.original_price,
|
|
346
|
+
original_total: item?.original_total,
|
|
347
|
+
price_type_ext: item?.price_type_ext,
|
|
348
|
+
bundle_sum_price: item?.bundle_sum_price,
|
|
349
|
+
bundle_sum_type: item?.bundle_sum_type,
|
|
350
|
+
options: formatOptions(item?.option),
|
|
322
351
|
_bundle_product_id: item._bundle_product_id,
|
|
323
352
|
discount_list: item.discount_list,
|
|
324
353
|
originBundleItem: item.originBundleItem || item,
|
|
325
|
-
is_charge_tax: item
|
|
354
|
+
is_charge_tax: item?.is_charge_tax
|
|
326
355
|
};
|
|
327
356
|
});
|
|
328
357
|
};
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
return bundle.map(
|
|
333
|
-
const getBundleValueByKey =
|
|
334
|
-
|
|
335
|
-
return (d == null ? void 0 : d[key]) || ((_a = d == null ? void 0 : d.originBundleItem) == null ? void 0 : _a[key]);
|
|
358
|
+
exports.formatBundle = formatBundle;
|
|
359
|
+
const formatBundleToOrigin = bundle => {
|
|
360
|
+
if (!bundle?.length) return [];
|
|
361
|
+
return bundle.map(d => {
|
|
362
|
+
const getBundleValueByKey = key => {
|
|
363
|
+
return d?.[key] || d?.originBundleItem?.[key];
|
|
336
364
|
};
|
|
337
|
-
const product_discount_difference = (
|
|
338
|
-
|
|
339
|
-
return pre + (((_a = cur == null ? void 0 : cur.metadata) == null ? void 0 : _a.product_discount_difference) || 0);
|
|
365
|
+
const product_discount_difference = (d?.discount_list || []).reduce((pre, cur) => {
|
|
366
|
+
return pre + (cur?.metadata?.product_discount_difference || 0);
|
|
340
367
|
}, 0);
|
|
341
368
|
const normalizedBundle = {
|
|
342
369
|
...d,
|
|
343
370
|
// 计算 markdown 净额时只传真实毛价;若仅有 bundle_selling_price,则由 helper 当历史净额兜底。
|
|
344
|
-
price:
|
|
345
|
-
bundle_selling_price: d
|
|
346
|
-
price_type:
|
|
347
|
-
price_type_ext:
|
|
348
|
-
option: getBundleValueByKey(
|
|
371
|
+
price: d?.price ?? d?.custom_price,
|
|
372
|
+
bundle_selling_price: d?.bundle_selling_price,
|
|
373
|
+
price_type: d?.price_type ?? d?.custom_price_type,
|
|
374
|
+
price_type_ext: d?.price_type_ext ?? d?.custom_price_type_ext,
|
|
375
|
+
option: getBundleValueByKey('option')
|
|
349
376
|
};
|
|
350
377
|
return {
|
|
351
|
-
bundle_group_id: getBundleValueByKey(
|
|
378
|
+
bundle_group_id: getBundleValueByKey('group_id'),
|
|
352
379
|
bundle_id: d.id,
|
|
353
|
-
bundle_product_id: getBundleValueByKey(
|
|
354
|
-
bundle_variant_id: getBundleValueByKey(
|
|
380
|
+
bundle_product_id: getBundleValueByKey('_bundle_product_id') || getBundleValueByKey('product_id'),
|
|
381
|
+
bundle_variant_id: getBundleValueByKey('bundle_variant_id'),
|
|
355
382
|
num: d.num,
|
|
356
|
-
extension_id: getBundleValueByKey(
|
|
357
|
-
extension_type: getBundleValueByKey(
|
|
358
|
-
option: formatOptionsToOrigin(getBundleValueByKey(
|
|
383
|
+
extension_id: getBundleValueByKey('extension_id'),
|
|
384
|
+
extension_type: getBundleValueByKey('extension_type'),
|
|
385
|
+
option: formatOptionsToOrigin(getBundleValueByKey('option')),
|
|
359
386
|
discount_list: d.discount_list,
|
|
360
|
-
"bundle_selling_price": (0,
|
|
361
|
-
"custom_price": d
|
|
387
|
+
"bundle_selling_price": (0, _utils4.getBundleSellingMagnitude)(normalizedBundle).toFixed(2),
|
|
388
|
+
"custom_price": d?.price,
|
|
362
389
|
metadata: {
|
|
363
390
|
custom_product_bundle_map_id: d._id,
|
|
364
391
|
product_discount_difference
|
|
@@ -366,103 +393,146 @@ var formatBundleToOrigin = (bundle) => {
|
|
|
366
393
|
};
|
|
367
394
|
});
|
|
368
395
|
};
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* 获取商品定金
|
|
399
|
+
* @description 定金基于商品售价来算,最终乘商品数量
|
|
400
|
+
* 1、如果套餐主商品有定金规则,则定金为:(套餐商品总售价 * 定金百分比 + 定金固定金额)* 商品数量
|
|
401
|
+
* 2、如果套餐主商品没有定金规则,子商品有定金规则,则定金为:(套餐子商品售价 * 套餐子商品定金百分比 + 套餐子商品定金固定金额)* 商品数量,最终将所有子商品定金相加
|
|
402
|
+
* 3、普通商品/单规格商品/组合规则商品,定金规则:(商品总售价 * 定金百分比 + 定金固定金额)* 商品数量
|
|
403
|
+
* @param params 参数
|
|
404
|
+
* @returns 商品定金
|
|
405
|
+
*/
|
|
406
|
+
exports.formatBundleToOrigin = formatBundleToOrigin;
|
|
407
|
+
const getProductDeposit = params => {
|
|
408
|
+
const {
|
|
409
|
+
cartItem,
|
|
410
|
+
product,
|
|
411
|
+
bundle,
|
|
412
|
+
options
|
|
413
|
+
} = params;
|
|
414
|
+
const num = params?.num || 1;
|
|
415
|
+
|
|
416
|
+
// 判定商品是否有定金规则
|
|
417
|
+
if (product?.custom_deposit_data?.has_deposit == 1) {
|
|
418
|
+
let total = new _decimal.default(0);
|
|
375
419
|
const {
|
|
376
420
|
deposit_fixed,
|
|
377
421
|
deposit_percentage,
|
|
378
422
|
deposit_policy_data,
|
|
379
423
|
self_deposit_policy_ids
|
|
380
|
-
} =
|
|
424
|
+
} = product?.custom_deposit_data || {};
|
|
425
|
+
// 所有协议数据
|
|
381
426
|
const allProtocols = deposit_policy_data || [];
|
|
427
|
+
// 是否存在定金,主商品has_deposit为1,但是自身没有定金设置,需要判定子商品是否存在定金,如果不存在最终判定也是不存在定金
|
|
382
428
|
let productHasDeposit = false;
|
|
429
|
+
// 关联的定金协议id
|
|
383
430
|
const protocolIds = [];
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
431
|
+
|
|
432
|
+
// 判断主商品是否有定金规则
|
|
433
|
+
if (typeof deposit_fixed === 'string' && typeof deposit_percentage === 'string') {
|
|
434
|
+
const {
|
|
435
|
+
depositTotal,
|
|
436
|
+
result
|
|
437
|
+
} = handleProductDeposit({
|
|
438
|
+
depositData: product?.custom_deposit_data,
|
|
387
439
|
total: cartItem.total || 0,
|
|
388
440
|
num
|
|
389
441
|
});
|
|
390
442
|
if (result) {
|
|
391
443
|
total = depositTotal;
|
|
392
|
-
protocolIds.push(...self_deposit_policy_ids || []);
|
|
444
|
+
protocolIds.push(...(self_deposit_policy_ids || []));
|
|
393
445
|
productHasDeposit = true;
|
|
394
446
|
}
|
|
395
447
|
} else {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
);
|
|
448
|
+
// 组合规格商品
|
|
449
|
+
if (product?.product_variant_id) {
|
|
450
|
+
const variantProduct = product?.variant?.find(item => item?.id === product?.product_variant_id);
|
|
400
451
|
if (variantProduct) {
|
|
401
|
-
const depositData = variantProduct
|
|
402
|
-
const {
|
|
452
|
+
const depositData = variantProduct?.custom_deposit_data;
|
|
453
|
+
const {
|
|
454
|
+
depositTotal,
|
|
455
|
+
result
|
|
456
|
+
} = handleProductDeposit({
|
|
403
457
|
depositData,
|
|
404
|
-
total:
|
|
458
|
+
total: cartItem?.total || 0,
|
|
405
459
|
num
|
|
406
460
|
});
|
|
407
461
|
if (result) {
|
|
408
462
|
total = depositTotal;
|
|
409
|
-
protocolIds.push(...(depositData
|
|
463
|
+
protocolIds.push(...(depositData?.self_deposit_policy_ids || []));
|
|
410
464
|
productHasDeposit = true;
|
|
411
465
|
}
|
|
412
466
|
}
|
|
413
467
|
}
|
|
414
|
-
if (bundle
|
|
468
|
+
if (bundle?.length) {
|
|
415
469
|
total = bundle.reduce((accumulator, currBundleProduct) => {
|
|
416
|
-
const depositData = currBundleProduct
|
|
417
|
-
const {
|
|
470
|
+
const depositData = currBundleProduct?.custom_deposit_data;
|
|
471
|
+
const {
|
|
472
|
+
depositTotal,
|
|
473
|
+
result
|
|
474
|
+
} = handleProductDeposit({
|
|
418
475
|
depositData,
|
|
419
|
-
total: currBundleProduct
|
|
420
|
-
num:
|
|
476
|
+
total: currBundleProduct?.price,
|
|
477
|
+
num: currBundleProduct?.num || 1
|
|
421
478
|
});
|
|
422
479
|
if (result) {
|
|
423
|
-
protocolIds.push(...(depositData
|
|
480
|
+
protocolIds.push(...(depositData?.self_deposit_policy_ids || []));
|
|
424
481
|
productHasDeposit = true;
|
|
425
482
|
return accumulator.plus(depositTotal);
|
|
426
483
|
}
|
|
427
484
|
return accumulator;
|
|
428
|
-
}, new
|
|
485
|
+
}, new _decimal.default(0));
|
|
429
486
|
}
|
|
430
487
|
}
|
|
431
488
|
if (productHasDeposit) {
|
|
432
489
|
const ids = new Set(protocolIds);
|
|
433
|
-
const protocols = allProtocols.filter(
|
|
434
|
-
return {
|
|
490
|
+
const protocols = allProtocols.filter(item => ids.has(item.id));
|
|
491
|
+
return {
|
|
492
|
+
total: total.toNumber(),
|
|
493
|
+
protocols
|
|
494
|
+
};
|
|
435
495
|
}
|
|
436
496
|
return null;
|
|
437
497
|
}
|
|
438
498
|
return null;
|
|
439
499
|
};
|
|
440
|
-
|
|
441
|
-
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* 计算商品定金
|
|
503
|
+
* @param params 参数
|
|
504
|
+
* @returns 商品定金
|
|
505
|
+
*/
|
|
506
|
+
exports.getProductDeposit = getProductDeposit;
|
|
507
|
+
const handleProductDeposit = params => {
|
|
508
|
+
const {
|
|
509
|
+
depositData,
|
|
510
|
+
total,
|
|
511
|
+
num
|
|
512
|
+
} = params;
|
|
442
513
|
if (!depositData) {
|
|
443
|
-
return {
|
|
514
|
+
return {
|
|
515
|
+
result: false,
|
|
516
|
+
depositTotal: new _decimal.default(0)
|
|
517
|
+
};
|
|
444
518
|
}
|
|
445
|
-
const {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
519
|
+
const {
|
|
520
|
+
deposit_fixed,
|
|
521
|
+
deposit_percentage
|
|
522
|
+
} = depositData || {};
|
|
523
|
+
if (typeof deposit_fixed === 'string' && typeof deposit_percentage === 'string') {
|
|
524
|
+
const depositFixed = (0, _decimal.default)(deposit_fixed || 0);
|
|
525
|
+
const depositPercent = (0, _decimal.default)(deposit_percentage || 0);
|
|
526
|
+
const productTotalPrice = (0, _decimal.default)(total || 0);
|
|
450
527
|
const deposit = depositFixed.plus(depositPercent.times(productTotalPrice));
|
|
451
|
-
return {
|
|
528
|
+
return {
|
|
529
|
+
depositTotal: deposit.times(num),
|
|
530
|
+
result: true
|
|
531
|
+
};
|
|
452
532
|
}
|
|
453
|
-
return {
|
|
533
|
+
return {
|
|
534
|
+
result: false,
|
|
535
|
+
depositTotal: new _decimal.default(0)
|
|
536
|
+
};
|
|
454
537
|
};
|
|
455
|
-
|
|
456
|
-
0 && (module.exports = {
|
|
457
|
-
formatBundle,
|
|
458
|
-
formatBundleToOrigin,
|
|
459
|
-
formatOptions,
|
|
460
|
-
formatOptionsToOrigin,
|
|
461
|
-
formatProductToCartItem,
|
|
462
|
-
formatProductToCartItemOrigin,
|
|
463
|
-
getProductDeposit,
|
|
464
|
-
getProductOriginTotalPrice,
|
|
465
|
-
getProductTotalPrice,
|
|
466
|
-
handleProductDeposit,
|
|
467
|
-
handleVariantProduct
|
|
468
|
-
});
|
|
538
|
+
exports.handleProductDeposit = handleProductDeposit;
|