@pisell/pisellos 0.0.39 → 0.0.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/Cart/index.js +1 -1
- package/dist/modules/Cart/types.d.ts +12 -0
- package/dist/modules/Cart/utils.d.ts +43 -0
- package/dist/modules/Cart/utils.js +122 -5
- package/dist/modules/Product/types.d.ts +16 -0
- package/dist/modules/Rules/index.js +86 -18
- package/dist/modules/Rules/types.d.ts +4 -0
- package/dist/modules/Summary/types.d.ts +21 -0
- package/dist/modules/Summary/utils.d.ts +9 -0
- package/dist/modules/Summary/utils.js +38 -1
- package/dist/solution/BookingByStep/index.d.ts +4 -0
- package/lib/modules/Cart/index.js +4 -10
- package/lib/modules/Cart/types.d.ts +12 -0
- package/lib/modules/Cart/utils.d.ts +43 -0
- package/lib/modules/Cart/utils.js +66 -5
- package/lib/modules/Product/types.d.ts +16 -0
- package/lib/modules/Rules/index.js +100 -25
- package/lib/modules/Rules/types.d.ts +4 -0
- package/lib/modules/Summary/types.d.ts +21 -0
- package/lib/modules/Summary/utils.d.ts +9 -0
- package/lib/modules/Summary/utils.js +28 -1
- package/lib/solution/BookingByStep/index.d.ts +4 -0
- package/package.json +1 -1
|
@@ -21,9 +21,9 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
21
21
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
22
22
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
23
23
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
24
|
+
import { cloneDeep } from "lodash-es";
|
|
24
25
|
import { BaseModule } from "../BaseModule";
|
|
25
26
|
import { createCartItemOrigin, deleteResourceFromCartItem, deleteTimeFromCartItem, formatAccountToCartItem, formatDiscountToCartItem, formatNoteToCartItem, formatProductToCartItem, formatResourceToCartItem, getUniqueId } from "./utils";
|
|
26
|
-
import { cloneDeep } from "lodash-es";
|
|
27
27
|
export * from "./types";
|
|
28
28
|
|
|
29
29
|
/**
|
|
@@ -84,6 +84,18 @@ export interface CartItem {
|
|
|
84
84
|
resource_id?: string | number;
|
|
85
85
|
/** 资源名称 */
|
|
86
86
|
relation_form_name?: string;
|
|
87
|
+
/** 定金 */
|
|
88
|
+
deposit?: {
|
|
89
|
+
/** 定金总价 */
|
|
90
|
+
total: number | string;
|
|
91
|
+
/** 定金协议 */
|
|
92
|
+
protocols: {
|
|
93
|
+
/** 定金协议ID */
|
|
94
|
+
id: number;
|
|
95
|
+
/** 定金协议标题 */
|
|
96
|
+
title: string;
|
|
97
|
+
}[];
|
|
98
|
+
} | null;
|
|
87
99
|
/** 原始数据 */
|
|
88
100
|
_origin: any;
|
|
89
101
|
/** 商品原始数据 */
|
|
@@ -2,6 +2,7 @@ import { Account } from "../Account";
|
|
|
2
2
|
import { ProductData } from "../Product/types";
|
|
3
3
|
import { Resource } from "../Resource/types";
|
|
4
4
|
import { CartItem, IDiscount } from "./types";
|
|
5
|
+
import Decimal from "decimal.js";
|
|
5
6
|
/**
|
|
6
7
|
* 生成一个唯一的 ID
|
|
7
8
|
*/
|
|
@@ -141,6 +142,7 @@ export declare const formatBundleToOrigin: (bundle: any) => any;
|
|
|
141
142
|
export declare const isNormalProduct: (product: any) => boolean;
|
|
142
143
|
/**
|
|
143
144
|
* 获取商品总价
|
|
145
|
+
* @description 当前总价计算基于商品数量为1
|
|
144
146
|
* @param item 商品
|
|
145
147
|
* @returns 商品总价
|
|
146
148
|
*/
|
|
@@ -148,9 +150,11 @@ export declare const getProductTotalPrice: (params: {
|
|
|
148
150
|
product: ProductData;
|
|
149
151
|
bundle?: any;
|
|
150
152
|
options?: any;
|
|
153
|
+
num?: number;
|
|
151
154
|
}) => number;
|
|
152
155
|
/**
|
|
153
156
|
* 获取商品原始总价
|
|
157
|
+
* @description 当前总价计算基于商品数量为1
|
|
154
158
|
* @param item 商品
|
|
155
159
|
* @returns 商品原始总价
|
|
156
160
|
*/
|
|
@@ -158,4 +162,43 @@ export declare const getProductOriginTotalPrice: (params: {
|
|
|
158
162
|
product: ProductData;
|
|
159
163
|
bundle?: any;
|
|
160
164
|
options?: any;
|
|
165
|
+
num?: number;
|
|
161
166
|
}) => number | undefined;
|
|
167
|
+
/**
|
|
168
|
+
* 获取商品定金
|
|
169
|
+
* @description 定金基于商品售价来算,最终乘商品数量
|
|
170
|
+
* 1、如果套餐主商品有定金规则,则定金为:(套餐商品总售价 * 定金百分比 + 定金固定金额)* 商品数量
|
|
171
|
+
* 2、如果套餐主商品没有定金规则,子商品有定金规则,则定金为:(套餐子商品售价 * 套餐子商品定金百分比 + 套餐子商品定金固定金额)* 商品数量,最终将所有子商品定金相加
|
|
172
|
+
* 3、普通商品/单规格商品/组合规则商品,定金规则:(商品总售价 * 定金百分比 + 定金固定金额)* 商品数量
|
|
173
|
+
* @param params 参数
|
|
174
|
+
* @returns 商品定金
|
|
175
|
+
*/
|
|
176
|
+
export declare const getProductDeposit: (params: {
|
|
177
|
+
cartItem: CartItem;
|
|
178
|
+
product: ProductData;
|
|
179
|
+
bundle?: any;
|
|
180
|
+
options?: any;
|
|
181
|
+
num?: number;
|
|
182
|
+
}) => {
|
|
183
|
+
total: string;
|
|
184
|
+
protocols: {
|
|
185
|
+
id: number;
|
|
186
|
+
title: string;
|
|
187
|
+
}[];
|
|
188
|
+
} | null;
|
|
189
|
+
/**
|
|
190
|
+
* 计算商品定金
|
|
191
|
+
* @param params 参数
|
|
192
|
+
* @returns 商品定金
|
|
193
|
+
*/
|
|
194
|
+
export declare const handleProductDeposit: (params: {
|
|
195
|
+
depositData: {
|
|
196
|
+
deposit_fixed?: string;
|
|
197
|
+
deposit_percentage?: string;
|
|
198
|
+
};
|
|
199
|
+
total: string | number;
|
|
200
|
+
num: number;
|
|
201
|
+
}) => {
|
|
202
|
+
depositTotal: Decimal;
|
|
203
|
+
result: boolean;
|
|
204
|
+
};
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
5
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
7
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
2
8
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
9
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
10
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
11
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
12
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
13
|
import dayjs from "dayjs";
|
|
14
|
+
import Decimal from "decimal.js";
|
|
15
|
+
|
|
8
16
|
/**
|
|
9
17
|
* 生成一个唯一的 ID
|
|
10
18
|
*/
|
|
@@ -68,25 +76,29 @@ export var createCartItemOrigin = function createCartItemOrigin() {
|
|
|
68
76
|
* @returns 格式化后的商品
|
|
69
77
|
*/
|
|
70
78
|
export var formatProductToCartItem = function formatProductToCartItem(params) {
|
|
79
|
+
var _product$custom_depos;
|
|
71
80
|
var cartItem = params.cartItem,
|
|
72
81
|
product = params.product,
|
|
73
82
|
bundle = params.bundle,
|
|
74
83
|
options = params.options;
|
|
84
|
+
var num = 1; // 当前按照单个商品加入购物车
|
|
75
85
|
if (product) {
|
|
76
86
|
cartItem.id = product === null || product === void 0 ? void 0 : product.id;
|
|
77
87
|
cartItem.name = product === null || product === void 0 ? void 0 : product.title;
|
|
78
88
|
cartItem.price = product === null || product === void 0 ? void 0 : product.price;
|
|
89
|
+
cartItem.num = num;
|
|
79
90
|
cartItem.total = getProductTotalPrice({
|
|
80
91
|
product: product,
|
|
81
92
|
bundle: bundle,
|
|
82
|
-
options: options
|
|
93
|
+
options: options,
|
|
94
|
+
num: num
|
|
83
95
|
});
|
|
84
96
|
cartItem.origin_total = getProductOriginTotalPrice({
|
|
85
97
|
product: product,
|
|
86
98
|
bundle: bundle,
|
|
87
|
-
options: options
|
|
99
|
+
options: options,
|
|
100
|
+
num: num
|
|
88
101
|
});
|
|
89
|
-
cartItem.num = 1;
|
|
90
102
|
cartItem.image = product === null || product === void 0 ? void 0 : product.cover;
|
|
91
103
|
cartItem.like_status = "common";
|
|
92
104
|
cartItem.duration = product === null || product === void 0 ? void 0 : product.duration;
|
|
@@ -99,6 +111,17 @@ export var formatProductToCartItem = function formatProductToCartItem(params) {
|
|
|
99
111
|
if (options !== null && options !== void 0 && options.length) {
|
|
100
112
|
cartItem.options = formatOptions(options);
|
|
101
113
|
}
|
|
114
|
+
|
|
115
|
+
// 如果商品有定金规则,则计算定金
|
|
116
|
+
if (product !== null && product !== void 0 && (_product$custom_depos = product.custom_deposit_data) !== null && _product$custom_depos !== void 0 && _product$custom_depos.has_deposit) {
|
|
117
|
+
cartItem.deposit = getProductDeposit({
|
|
118
|
+
cartItem: cartItem,
|
|
119
|
+
product: product,
|
|
120
|
+
bundle: bundle,
|
|
121
|
+
options: options,
|
|
122
|
+
num: num
|
|
123
|
+
});
|
|
124
|
+
}
|
|
102
125
|
var oringin = formatProductToCartItemOrigin(params);
|
|
103
126
|
cartItem._origin = oringin;
|
|
104
127
|
return cartItem;
|
|
@@ -429,6 +452,7 @@ export var isNormalProduct = function isNormalProduct(product) {
|
|
|
429
452
|
|
|
430
453
|
/**
|
|
431
454
|
* 获取商品总价
|
|
455
|
+
* @description 当前总价计算基于商品数量为1
|
|
432
456
|
* @param item 商品
|
|
433
457
|
* @returns 商品总价
|
|
434
458
|
*/
|
|
@@ -436,6 +460,7 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
|
|
|
436
460
|
var product = params.product,
|
|
437
461
|
bundle = params.bundle,
|
|
438
462
|
options = params.options;
|
|
463
|
+
var num = params.num || 1;
|
|
439
464
|
var price = Number(product.price);
|
|
440
465
|
if (bundle !== null && bundle !== void 0 && bundle.length) {
|
|
441
466
|
price = bundle.reduce(function (accumulator, currentValue) {
|
|
@@ -449,11 +474,12 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
|
|
|
449
474
|
return accumulator + Number(currentValue.price) * Number(currentValue.num);
|
|
450
475
|
}, price);
|
|
451
476
|
}
|
|
452
|
-
return price;
|
|
477
|
+
return price * num;
|
|
453
478
|
};
|
|
454
479
|
|
|
455
480
|
/**
|
|
456
481
|
* 获取商品原始总价
|
|
482
|
+
* @description 当前总价计算基于商品数量为1
|
|
457
483
|
* @param item 商品
|
|
458
484
|
* @returns 商品原始总价
|
|
459
485
|
*/
|
|
@@ -461,6 +487,7 @@ export var getProductOriginTotalPrice = function getProductOriginTotalPrice(para
|
|
|
461
487
|
var product = params.product,
|
|
462
488
|
bundle = params.bundle,
|
|
463
489
|
options = params.options;
|
|
490
|
+
var num = (params === null || params === void 0 ? void 0 : params.num) || 1;
|
|
464
491
|
var price = Number(product.original_price);
|
|
465
492
|
if (isNaN(price) || price === 0) {
|
|
466
493
|
return undefined;
|
|
@@ -477,5 +504,95 @@ export var getProductOriginTotalPrice = function getProductOriginTotalPrice(para
|
|
|
477
504
|
return accumulator + Number(currentValue.price) * Number(currentValue.num);
|
|
478
505
|
}, price);
|
|
479
506
|
}
|
|
480
|
-
return price;
|
|
507
|
+
return price * num;
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* 获取商品定金
|
|
512
|
+
* @description 定金基于商品售价来算,最终乘商品数量
|
|
513
|
+
* 1、如果套餐主商品有定金规则,则定金为:(套餐商品总售价 * 定金百分比 + 定金固定金额)* 商品数量
|
|
514
|
+
* 2、如果套餐主商品没有定金规则,子商品有定金规则,则定金为:(套餐子商品售价 * 套餐子商品定金百分比 + 套餐子商品定金固定金额)* 商品数量,最终将所有子商品定金相加
|
|
515
|
+
* 3、普通商品/单规格商品/组合规则商品,定金规则:(商品总售价 * 定金百分比 + 定金固定金额)* 商品数量
|
|
516
|
+
* @param params 参数
|
|
517
|
+
* @returns 商品定金
|
|
518
|
+
*/
|
|
519
|
+
export var getProductDeposit = function getProductDeposit(params) {
|
|
520
|
+
var _product$custom_depos2;
|
|
521
|
+
var cartItem = params.cartItem,
|
|
522
|
+
product = params.product,
|
|
523
|
+
bundle = params.bundle,
|
|
524
|
+
options = params.options;
|
|
525
|
+
var num = (params === null || params === void 0 ? void 0 : params.num) || 1;
|
|
526
|
+
|
|
527
|
+
// 判定商品是否有定金规则
|
|
528
|
+
if ((product === null || product === void 0 || (_product$custom_depos2 = product.custom_deposit_data) === null || _product$custom_depos2 === void 0 ? void 0 : _product$custom_depos2.has_deposit) == 1) {
|
|
529
|
+
var protocols = [];
|
|
530
|
+
var total = new Decimal(0);
|
|
531
|
+
var _ref = (product === null || product === void 0 ? void 0 : product.custom_deposit_data) || {},
|
|
532
|
+
deposit_fixed = _ref.deposit_fixed,
|
|
533
|
+
deposit_percentage = _ref.deposit_percentage,
|
|
534
|
+
deposit_policy_data = _ref.deposit_policy_data;
|
|
535
|
+
protocols.push.apply(protocols, _toConsumableArray(deposit_policy_data || []));
|
|
536
|
+
// 判断主商品是否有定金规则
|
|
537
|
+
if (typeof deposit_fixed === "string" && typeof deposit_percentage === "string") {
|
|
538
|
+
var _handleProductDeposit = handleProductDeposit({
|
|
539
|
+
depositData: product === null || product === void 0 ? void 0 : product.custom_deposit_data,
|
|
540
|
+
total: cartItem.total || 0,
|
|
541
|
+
num: num
|
|
542
|
+
}),
|
|
543
|
+
depositTotal = _handleProductDeposit.depositTotal,
|
|
544
|
+
result = _handleProductDeposit.result;
|
|
545
|
+
if (result) {
|
|
546
|
+
total = depositTotal;
|
|
547
|
+
}
|
|
548
|
+
} else {
|
|
549
|
+
if (bundle !== null && bundle !== void 0 && bundle.length) {
|
|
550
|
+
total = bundle.reduce(function (accumulator, currentBundleProduct) {
|
|
551
|
+
var _handleProductDeposit2 = handleProductDeposit({
|
|
552
|
+
depositData: currentBundleProduct === null || currentBundleProduct === void 0 ? void 0 : currentBundleProduct.custom_deposit_data,
|
|
553
|
+
total: currentBundleProduct.price,
|
|
554
|
+
num: currentBundleProduct.num
|
|
555
|
+
}),
|
|
556
|
+
depositTotal = _handleProductDeposit2.depositTotal,
|
|
557
|
+
result = _handleProductDeposit2.result;
|
|
558
|
+
if (result) {
|
|
559
|
+
return accumulator.plus(depositTotal);
|
|
560
|
+
}
|
|
561
|
+
return accumulator;
|
|
562
|
+
}, new Decimal(0));
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
return {
|
|
566
|
+
total: total.toFixed(2),
|
|
567
|
+
protocols: protocols
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
return null;
|
|
571
|
+
};
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* 计算商品定金
|
|
575
|
+
* @param params 参数
|
|
576
|
+
* @returns 商品定金
|
|
577
|
+
*/
|
|
578
|
+
export var handleProductDeposit = function handleProductDeposit(params) {
|
|
579
|
+
var depositData = params.depositData,
|
|
580
|
+
total = params.total,
|
|
581
|
+
num = params.num;
|
|
582
|
+
var deposit_fixed = depositData.deposit_fixed,
|
|
583
|
+
deposit_percentage = depositData.deposit_percentage;
|
|
584
|
+
if (typeof deposit_fixed === "string" && typeof deposit_percentage === "string") {
|
|
585
|
+
var depositFixed = Decimal(deposit_fixed || 0);
|
|
586
|
+
var depositPercent = Decimal(deposit_percentage || 0);
|
|
587
|
+
var productTotalPrice = Decimal(total || 0);
|
|
588
|
+
var deposit = depositFixed.plus(depositPercent.times(productTotalPrice));
|
|
589
|
+
return {
|
|
590
|
+
depositTotal: deposit.times(num),
|
|
591
|
+
result: true
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
return {
|
|
595
|
+
result: false,
|
|
596
|
+
depositTotal: new Decimal(0)
|
|
597
|
+
};
|
|
481
598
|
};
|
|
@@ -156,6 +156,22 @@ export interface ProductData {
|
|
|
156
156
|
capacity?: any;
|
|
157
157
|
/** 商品套餐 */
|
|
158
158
|
product_bundle?: any;
|
|
159
|
+
/** 商品定金信息 */
|
|
160
|
+
custom_deposit_data?: {
|
|
161
|
+
/** 商品是否包含定金 1:是 0:否 */
|
|
162
|
+
has_deposit: 0 | 1;
|
|
163
|
+
/** 定金固定金额 */
|
|
164
|
+
deposit_fixed?: string;
|
|
165
|
+
/** 定金百分比 */
|
|
166
|
+
deposit_percentage?: string;
|
|
167
|
+
/** 定金协议数据 */
|
|
168
|
+
deposit_policy_data?: Array<{
|
|
169
|
+
/** 定金协议id */
|
|
170
|
+
id: number;
|
|
171
|
+
/** 定金协议标题 */
|
|
172
|
+
title: string;
|
|
173
|
+
}>;
|
|
174
|
+
};
|
|
159
175
|
}
|
|
160
176
|
/**
|
|
161
177
|
* 商品媒体信息接口
|
|
@@ -26,6 +26,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
26
26
|
import { BaseModule } from "../BaseModule";
|
|
27
27
|
import { RulesHooks } from "./types";
|
|
28
28
|
import { uniqueById } from "../../solution/ShopDiscount/utils";
|
|
29
|
+
import { getProductOriginTotalPrice, getProductTotalPrice } from "../Cart/utils";
|
|
29
30
|
export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
30
31
|
_inherits(RulesModule, _BaseModule);
|
|
31
32
|
var _super = _createSuper(RulesModule);
|
|
@@ -277,12 +278,34 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
277
278
|
|
|
278
279
|
// 如果没有适用的优惠券,或者手动折扣,则不适用优惠券
|
|
279
280
|
if (applicableDiscounts.length === 0 || isManualDiscount) {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
281
|
+
if (product.isClient) {
|
|
282
|
+
processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
|
|
283
|
+
origin_total: getProductOriginTotalPrice({
|
|
284
|
+
product: {
|
|
285
|
+
original_price: product.original_price
|
|
286
|
+
},
|
|
287
|
+
bundle: product.bundle,
|
|
288
|
+
options: product.options
|
|
289
|
+
}),
|
|
290
|
+
total: getProductTotalPrice({
|
|
291
|
+
product: {
|
|
292
|
+
price: product.price
|
|
293
|
+
},
|
|
294
|
+
bundle: product.bundle,
|
|
295
|
+
options: product.options
|
|
296
|
+
}),
|
|
297
|
+
price: product.price
|
|
298
|
+
}), {}, {
|
|
299
|
+
discount_list: []
|
|
300
|
+
})));
|
|
301
|
+
} else {
|
|
302
|
+
processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
|
|
303
|
+
total: product.origin_total || product.total,
|
|
304
|
+
price: product.price
|
|
305
|
+
}), {}, {
|
|
306
|
+
discount_list: []
|
|
307
|
+
})));
|
|
308
|
+
}
|
|
286
309
|
return;
|
|
287
310
|
}
|
|
288
311
|
if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === 'undefined') {
|
|
@@ -309,23 +332,68 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
309
332
|
|
|
310
333
|
// 记录应用了优惠券的商品
|
|
311
334
|
// 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
335
|
+
if (product.isClient) {
|
|
336
|
+
processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, {
|
|
337
|
+
discount_list: [discountDetail],
|
|
338
|
+
price: 0,
|
|
339
|
+
origin_total: getProductOriginTotalPrice({
|
|
340
|
+
product: {
|
|
341
|
+
original_price: product.original_price
|
|
342
|
+
},
|
|
343
|
+
bundle: product.bundle,
|
|
344
|
+
options: product.options
|
|
345
|
+
}),
|
|
346
|
+
total: getProductTotalPrice({
|
|
347
|
+
product: {
|
|
348
|
+
price: '0'
|
|
349
|
+
},
|
|
350
|
+
bundle: product.bundle,
|
|
351
|
+
options: product.options
|
|
352
|
+
})
|
|
353
|
+
}));
|
|
354
|
+
} else {
|
|
355
|
+
processedProductsMap.set(product._id, _this3.hooks.setProduct(originProduct, {
|
|
356
|
+
discount_list: [discountDetail],
|
|
357
|
+
price: 0,
|
|
358
|
+
total: (product.origin_total || product.total) - product.price,
|
|
359
|
+
origin_total: product.origin_total || product.total
|
|
360
|
+
}));
|
|
361
|
+
}
|
|
318
362
|
});
|
|
319
363
|
|
|
320
364
|
// 按原始顺序构建处理后的商品列表
|
|
321
365
|
var processedProductList = productList.map(function (originProduct) {
|
|
322
366
|
var product = _this3.hooks.getProduct(originProduct);
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
367
|
+
var getDefaultProduct = function getDefaultProduct() {
|
|
368
|
+
if (product.isClient) {
|
|
369
|
+
_this3.hooks.setProduct(originProduct, {
|
|
370
|
+
discount_list: [],
|
|
371
|
+
price: product.price,
|
|
372
|
+
origin_total: getProductOriginTotalPrice({
|
|
373
|
+
product: {
|
|
374
|
+
original_price: product.original_price
|
|
375
|
+
},
|
|
376
|
+
bundle: product.bundle,
|
|
377
|
+
options: product.options
|
|
378
|
+
}),
|
|
379
|
+
total: getProductTotalPrice({
|
|
380
|
+
product: {
|
|
381
|
+
price: product.price
|
|
382
|
+
},
|
|
383
|
+
bundle: product.bundle,
|
|
384
|
+
options: product.options
|
|
385
|
+
})
|
|
386
|
+
});
|
|
387
|
+
} else {
|
|
388
|
+
_this3.hooks.setProduct(originProduct, {
|
|
389
|
+
discount_list: [],
|
|
390
|
+
total: product.total,
|
|
391
|
+
origin_total: product.origin_total,
|
|
392
|
+
price: product.price
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
return processedProductsMap.get(product._id) || getDefaultProduct();
|
|
329
397
|
});
|
|
330
398
|
|
|
331
399
|
// 按原始顺序更新优惠券列表,标记已使用和可用的优惠券
|
|
@@ -25,6 +25,7 @@ export interface RulesModuleAPI {
|
|
|
25
25
|
}) => DiscountResult;
|
|
26
26
|
}
|
|
27
27
|
type ProductDetail = {
|
|
28
|
+
isClient?: boolean;
|
|
28
29
|
isManualDiscount?: boolean;
|
|
29
30
|
booking_id: any;
|
|
30
31
|
id: number;
|
|
@@ -33,6 +34,9 @@ type ProductDetail = {
|
|
|
33
34
|
discount_list: Discount[];
|
|
34
35
|
origin_total: number;
|
|
35
36
|
_id: string;
|
|
37
|
+
options?: any[];
|
|
38
|
+
bundle?: any[];
|
|
39
|
+
original_price?: number | string;
|
|
36
40
|
};
|
|
37
41
|
export interface RulesParamsHooks {
|
|
38
42
|
getProduct: (product: Record<string, any>) => ProductDetail;
|
|
@@ -1,13 +1,34 @@
|
|
|
1
1
|
import { CartItem } from "../Cart/types";
|
|
2
2
|
export interface ISummaryState {
|
|
3
3
|
summary: {
|
|
4
|
+
/** 商品总价 */
|
|
4
5
|
subtotal: string | number;
|
|
6
|
+
/** 最终总价 */
|
|
5
7
|
total: string | number;
|
|
8
|
+
/** 税率标题 */
|
|
6
9
|
taxTitle?: string;
|
|
10
|
+
/** 商品总费率 */
|
|
7
11
|
totalTaxFee?: string | number;
|
|
12
|
+
/** 商品价格是否包含费率 */
|
|
8
13
|
isPriceIncludeTax?: 0 | 1;
|
|
14
|
+
/** 定金 */
|
|
15
|
+
deposit?: {
|
|
16
|
+
/** 定金总价 */
|
|
17
|
+
total?: string | number;
|
|
18
|
+
/** */
|
|
19
|
+
policies?: IProtocol[];
|
|
20
|
+
};
|
|
9
21
|
};
|
|
10
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* 定金协议
|
|
25
|
+
*/
|
|
26
|
+
export interface IProtocol {
|
|
27
|
+
/** 协议名称 */
|
|
28
|
+
title: string;
|
|
29
|
+
/** 协议id */
|
|
30
|
+
id: string;
|
|
31
|
+
}
|
|
11
32
|
export interface ISummaryModuleAPI {
|
|
12
33
|
getSummary(cartItems: CartItem[]): Promise<ISummaryState["summary"]>;
|
|
13
34
|
}
|
|
@@ -17,3 +17,12 @@ export declare const calculateSubtotal: (items: CartItem[]) => string;
|
|
|
17
17
|
* @Author: xiangfeng.xue
|
|
18
18
|
*/
|
|
19
19
|
export declare const calculateTaxFee: (shopInfo: any, items: CartItem[]) => Decimal | "0.00";
|
|
20
|
+
/**
|
|
21
|
+
* @title: 计算定金
|
|
22
|
+
* @param items - 购物车商品数组
|
|
23
|
+
* @returns 定金字符串,保留2位小数
|
|
24
|
+
*/
|
|
25
|
+
export declare const calculateDeposit: (items: CartItem[]) => {
|
|
26
|
+
total: string;
|
|
27
|
+
protocols: any[];
|
|
28
|
+
} | undefined;
|
|
@@ -5,12 +5,16 @@ export var calculatePriceDetails = function calculatePriceDetails(shopInfo, item
|
|
|
5
5
|
|
|
6
6
|
// 计算总价
|
|
7
7
|
var total = shopInfo !== null && shopInfo !== void 0 && shopInfo.is_price_include_tax ? subtotal : subtotal.plus(totalTaxFee);
|
|
8
|
+
|
|
9
|
+
// 计算定金
|
|
10
|
+
var deposit = calculateDeposit(items);
|
|
8
11
|
return {
|
|
9
12
|
subtotal: subtotal.toFixed(2),
|
|
10
13
|
total: total.toFixed(2),
|
|
11
14
|
taxTitle: shopInfo === null || shopInfo === void 0 ? void 0 : shopInfo.tax_title,
|
|
12
15
|
totalTaxFee: totalTaxFee.toFixed(2),
|
|
13
|
-
isPriceIncludeTax: shopInfo === null || shopInfo === void 0 ? void 0 : shopInfo.is_price_include_tax
|
|
16
|
+
isPriceIncludeTax: shopInfo === null || shopInfo === void 0 ? void 0 : shopInfo.is_price_include_tax,
|
|
17
|
+
deposit: deposit
|
|
14
18
|
};
|
|
15
19
|
};
|
|
16
20
|
|
|
@@ -52,4 +56,37 @@ export var calculateTaxFee = function calculateTaxFee(shopInfo, items) {
|
|
|
52
56
|
return sum.plus(productTaxRate);
|
|
53
57
|
}, new Decimal(0));
|
|
54
58
|
return totalTaxFee;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @title: 计算定金
|
|
63
|
+
* @param items - 购物车商品数组
|
|
64
|
+
* @returns 定金字符串,保留2位小数
|
|
65
|
+
*/
|
|
66
|
+
export var calculateDeposit = function calculateDeposit(items) {
|
|
67
|
+
if (!(items !== null && items !== void 0 && items.length)) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
var protocols = [];
|
|
71
|
+
var total = items.reduce(function (sum, item) {
|
|
72
|
+
var _item$deposit;
|
|
73
|
+
if (item !== null && item !== void 0 && (_item$deposit = item.deposit) !== null && _item$deposit !== void 0 && (_item$deposit = _item$deposit.protocols) !== null && _item$deposit !== void 0 && _item$deposit.length) {
|
|
74
|
+
var _item$deposit2, _item$deposit3;
|
|
75
|
+
var cartItemTotalPrice = new Decimal((item === null || item === void 0 || (_item$deposit2 = item.deposit) === null || _item$deposit2 === void 0 ? void 0 : _item$deposit2.total) || 0);
|
|
76
|
+
// 将协议数据去重合并
|
|
77
|
+
item === null || item === void 0 || (_item$deposit3 = item.deposit) === null || _item$deposit3 === void 0 || (_item$deposit3 = _item$deposit3.protocols) === null || _item$deposit3 === void 0 || _item$deposit3.forEach(function (protocol) {
|
|
78
|
+
if (protocols.findIndex(function (p) {
|
|
79
|
+
return p.id === protocol.id;
|
|
80
|
+
}) === -1) {
|
|
81
|
+
protocols.push(protocol);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
return sum.plus(cartItemTotalPrice);
|
|
85
|
+
}
|
|
86
|
+
return sum;
|
|
87
|
+
}, new Decimal(0));
|
|
88
|
+
return {
|
|
89
|
+
total: total.toFixed(2),
|
|
90
|
+
protocols: protocols
|
|
91
|
+
};
|
|
55
92
|
};
|
|
@@ -65,6 +65,10 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
65
65
|
taxTitle?: string | undefined;
|
|
66
66
|
totalTaxFee?: string | number | undefined;
|
|
67
67
|
isPriceIncludeTax?: 0 | 1 | undefined;
|
|
68
|
+
deposit?: {
|
|
69
|
+
total?: string | number | undefined;
|
|
70
|
+
policies?: import("../../modules/Summary/types").IProtocol[] | undefined;
|
|
71
|
+
} | undefined;
|
|
68
72
|
}>;
|
|
69
73
|
getProducts(): Promise<ProductData[]>;
|
|
70
74
|
setLoginAccount(accountId: string, accountInfo: Account): Promise<void>;
|
|
@@ -23,9 +23,9 @@ __export(Cart_exports, {
|
|
|
23
23
|
CartModule: () => CartModule
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(Cart_exports);
|
|
26
|
+
var import_lodash_es = require("lodash-es");
|
|
26
27
|
var import_BaseModule = require("../BaseModule");
|
|
27
28
|
var import_utils = require("./utils");
|
|
28
|
-
var import_lodash_es = require("lodash-es");
|
|
29
29
|
__reExport(Cart_exports, require("./types"), module.exports);
|
|
30
30
|
var CartModule = class extends import_BaseModule.BaseModule {
|
|
31
31
|
constructor(name, version) {
|
|
@@ -172,9 +172,7 @@ var CartModule = class extends import_BaseModule.BaseModule {
|
|
|
172
172
|
* 根据账户ID获取购物车
|
|
173
173
|
*/
|
|
174
174
|
getCartByAccount(account_id) {
|
|
175
|
-
return this.store.list.filter(
|
|
176
|
-
(item) => item.holder_id === account_id
|
|
177
|
-
);
|
|
175
|
+
return this.store.list.filter((item) => item.holder_id === account_id);
|
|
178
176
|
}
|
|
179
177
|
/**
|
|
180
178
|
* 移除购物车商品
|
|
@@ -188,9 +186,7 @@ var CartModule = class extends import_BaseModule.BaseModule {
|
|
|
188
186
|
* 根据账户ID清除购物车
|
|
189
187
|
*/
|
|
190
188
|
clearCartByAccount(account_id) {
|
|
191
|
-
const items = this.store.list.filter(
|
|
192
|
-
(item) => item.holder_id !== account_id
|
|
193
|
-
);
|
|
189
|
+
const items = this.store.list.filter((item) => item.holder_id !== account_id);
|
|
194
190
|
this.store.list = [...items || []];
|
|
195
191
|
}
|
|
196
192
|
/**
|
|
@@ -216,9 +212,7 @@ var CartModule = class extends import_BaseModule.BaseModule {
|
|
|
216
212
|
storeChange() {
|
|
217
213
|
if (this.openCache) {
|
|
218
214
|
const store = (0, import_lodash_es.cloneDeep)(this.store);
|
|
219
|
-
store.list = store.list.filter(
|
|
220
|
-
(item, index, self) => index === self.findIndex((t) => t._id === item._id)
|
|
221
|
-
);
|
|
215
|
+
store.list = store.list.filter((item, index, self) => index === self.findIndex((t) => t._id === item._id));
|
|
222
216
|
this.checkSaveCache({
|
|
223
217
|
cacheId: this.cacheId,
|
|
224
218
|
fatherModule: this.fatherModule,
|
|
@@ -84,6 +84,18 @@ export interface CartItem {
|
|
|
84
84
|
resource_id?: string | number;
|
|
85
85
|
/** 资源名称 */
|
|
86
86
|
relation_form_name?: string;
|
|
87
|
+
/** 定金 */
|
|
88
|
+
deposit?: {
|
|
89
|
+
/** 定金总价 */
|
|
90
|
+
total: number | string;
|
|
91
|
+
/** 定金协议 */
|
|
92
|
+
protocols: {
|
|
93
|
+
/** 定金协议ID */
|
|
94
|
+
id: number;
|
|
95
|
+
/** 定金协议标题 */
|
|
96
|
+
title: string;
|
|
97
|
+
}[];
|
|
98
|
+
} | null;
|
|
87
99
|
/** 原始数据 */
|
|
88
100
|
_origin: any;
|
|
89
101
|
/** 商品原始数据 */
|
|
@@ -2,6 +2,7 @@ import { Account } from "../Account";
|
|
|
2
2
|
import { ProductData } from "../Product/types";
|
|
3
3
|
import { Resource } from "../Resource/types";
|
|
4
4
|
import { CartItem, IDiscount } from "./types";
|
|
5
|
+
import Decimal from "decimal.js";
|
|
5
6
|
/**
|
|
6
7
|
* 生成一个唯一的 ID
|
|
7
8
|
*/
|
|
@@ -141,6 +142,7 @@ export declare const formatBundleToOrigin: (bundle: any) => any;
|
|
|
141
142
|
export declare const isNormalProduct: (product: any) => boolean;
|
|
142
143
|
/**
|
|
143
144
|
* 获取商品总价
|
|
145
|
+
* @description 当前总价计算基于商品数量为1
|
|
144
146
|
* @param item 商品
|
|
145
147
|
* @returns 商品总价
|
|
146
148
|
*/
|
|
@@ -148,9 +150,11 @@ export declare const getProductTotalPrice: (params: {
|
|
|
148
150
|
product: ProductData;
|
|
149
151
|
bundle?: any;
|
|
150
152
|
options?: any;
|
|
153
|
+
num?: number;
|
|
151
154
|
}) => number;
|
|
152
155
|
/**
|
|
153
156
|
* 获取商品原始总价
|
|
157
|
+
* @description 当前总价计算基于商品数量为1
|
|
154
158
|
* @param item 商品
|
|
155
159
|
* @returns 商品原始总价
|
|
156
160
|
*/
|
|
@@ -158,4 +162,43 @@ export declare const getProductOriginTotalPrice: (params: {
|
|
|
158
162
|
product: ProductData;
|
|
159
163
|
bundle?: any;
|
|
160
164
|
options?: any;
|
|
165
|
+
num?: number;
|
|
161
166
|
}) => number | undefined;
|
|
167
|
+
/**
|
|
168
|
+
* 获取商品定金
|
|
169
|
+
* @description 定金基于商品售价来算,最终乘商品数量
|
|
170
|
+
* 1、如果套餐主商品有定金规则,则定金为:(套餐商品总售价 * 定金百分比 + 定金固定金额)* 商品数量
|
|
171
|
+
* 2、如果套餐主商品没有定金规则,子商品有定金规则,则定金为:(套餐子商品售价 * 套餐子商品定金百分比 + 套餐子商品定金固定金额)* 商品数量,最终将所有子商品定金相加
|
|
172
|
+
* 3、普通商品/单规格商品/组合规则商品,定金规则:(商品总售价 * 定金百分比 + 定金固定金额)* 商品数量
|
|
173
|
+
* @param params 参数
|
|
174
|
+
* @returns 商品定金
|
|
175
|
+
*/
|
|
176
|
+
export declare const getProductDeposit: (params: {
|
|
177
|
+
cartItem: CartItem;
|
|
178
|
+
product: ProductData;
|
|
179
|
+
bundle?: any;
|
|
180
|
+
options?: any;
|
|
181
|
+
num?: number;
|
|
182
|
+
}) => {
|
|
183
|
+
total: string;
|
|
184
|
+
protocols: {
|
|
185
|
+
id: number;
|
|
186
|
+
title: string;
|
|
187
|
+
}[];
|
|
188
|
+
} | null;
|
|
189
|
+
/**
|
|
190
|
+
* 计算商品定金
|
|
191
|
+
* @param params 参数
|
|
192
|
+
* @returns 商品定金
|
|
193
|
+
*/
|
|
194
|
+
export declare const handleProductDeposit: (params: {
|
|
195
|
+
depositData: {
|
|
196
|
+
deposit_fixed?: string;
|
|
197
|
+
deposit_percentage?: string;
|
|
198
|
+
};
|
|
199
|
+
total: string | number;
|
|
200
|
+
num: number;
|
|
201
|
+
}) => {
|
|
202
|
+
depositTotal: Decimal;
|
|
203
|
+
result: boolean;
|
|
204
|
+
};
|
|
@@ -46,13 +46,16 @@ __export(utils_exports, {
|
|
|
46
46
|
formatProductToCartItemOrigin: () => formatProductToCartItemOrigin,
|
|
47
47
|
formatResourceToCartItem: () => formatResourceToCartItem,
|
|
48
48
|
formatResourceToCartItemOrigin: () => formatResourceToCartItemOrigin,
|
|
49
|
+
getProductDeposit: () => getProductDeposit,
|
|
49
50
|
getProductOriginTotalPrice: () => getProductOriginTotalPrice,
|
|
50
51
|
getProductTotalPrice: () => getProductTotalPrice,
|
|
51
52
|
getUniqueId: () => getUniqueId,
|
|
53
|
+
handleProductDeposit: () => handleProductDeposit,
|
|
52
54
|
isNormalProduct: () => isNormalProduct
|
|
53
55
|
});
|
|
54
56
|
module.exports = __toCommonJS(utils_exports);
|
|
55
57
|
var import_dayjs = __toESM(require("dayjs"));
|
|
58
|
+
var import_decimal = __toESM(require("decimal.js"));
|
|
56
59
|
var getUniqueId = (prefix = "", maxLength = 11) => {
|
|
57
60
|
return prefix + (Math.random() + "").replace(/\D/g, "").substring(0, maxLength);
|
|
58
61
|
};
|
|
@@ -100,14 +103,16 @@ var createCartItemOrigin = () => {
|
|
|
100
103
|
};
|
|
101
104
|
};
|
|
102
105
|
var formatProductToCartItem = (params) => {
|
|
106
|
+
var _a;
|
|
103
107
|
const { cartItem, product, bundle, options } = params;
|
|
108
|
+
const num = 1;
|
|
104
109
|
if (product) {
|
|
105
110
|
cartItem.id = product == null ? void 0 : product.id;
|
|
106
111
|
cartItem.name = product == null ? void 0 : product.title;
|
|
107
112
|
cartItem.price = product == null ? void 0 : product.price;
|
|
108
|
-
cartItem.
|
|
109
|
-
cartItem.
|
|
110
|
-
cartItem.
|
|
113
|
+
cartItem.num = num;
|
|
114
|
+
cartItem.total = getProductTotalPrice({ product, bundle, options, num });
|
|
115
|
+
cartItem.origin_total = getProductOriginTotalPrice({ product, bundle, options, num });
|
|
111
116
|
cartItem.image = product == null ? void 0 : product.cover;
|
|
112
117
|
cartItem.like_status = "common";
|
|
113
118
|
cartItem.duration = product == null ? void 0 : product.duration;
|
|
@@ -120,6 +125,9 @@ var formatProductToCartItem = (params) => {
|
|
|
120
125
|
if (options == null ? void 0 : options.length) {
|
|
121
126
|
cartItem.options = formatOptions(options);
|
|
122
127
|
}
|
|
128
|
+
if ((_a = product == null ? void 0 : product.custom_deposit_data) == null ? void 0 : _a.has_deposit) {
|
|
129
|
+
cartItem.deposit = getProductDeposit({ cartItem, product, bundle, options, num });
|
|
130
|
+
}
|
|
123
131
|
const oringin = formatProductToCartItemOrigin(params);
|
|
124
132
|
cartItem._origin = oringin;
|
|
125
133
|
return cartItem;
|
|
@@ -365,6 +373,7 @@ var isNormalProduct = (product) => {
|
|
|
365
373
|
};
|
|
366
374
|
var getProductTotalPrice = (params) => {
|
|
367
375
|
const { product, bundle, options } = params;
|
|
376
|
+
const num = params.num || 1;
|
|
368
377
|
let price = Number(product.price);
|
|
369
378
|
if (bundle == null ? void 0 : bundle.length) {
|
|
370
379
|
price = bundle.reduce((accumulator, currentValue) => {
|
|
@@ -376,10 +385,11 @@ var getProductTotalPrice = (params) => {
|
|
|
376
385
|
return accumulator + Number(currentValue.price) * Number(currentValue.num);
|
|
377
386
|
}, price);
|
|
378
387
|
}
|
|
379
|
-
return price;
|
|
388
|
+
return price * num;
|
|
380
389
|
};
|
|
381
390
|
var getProductOriginTotalPrice = (params) => {
|
|
382
391
|
const { product, bundle, options } = params;
|
|
392
|
+
const num = (params == null ? void 0 : params.num) || 1;
|
|
383
393
|
let price = Number(product.original_price);
|
|
384
394
|
if (isNaN(price) || price === 0) {
|
|
385
395
|
return void 0;
|
|
@@ -394,7 +404,56 @@ var getProductOriginTotalPrice = (params) => {
|
|
|
394
404
|
return accumulator + Number(currentValue.price) * Number(currentValue.num);
|
|
395
405
|
}, price);
|
|
396
406
|
}
|
|
397
|
-
return price;
|
|
407
|
+
return price * num;
|
|
408
|
+
};
|
|
409
|
+
var getProductDeposit = (params) => {
|
|
410
|
+
var _a;
|
|
411
|
+
const { cartItem, product, bundle, options } = params;
|
|
412
|
+
const num = (params == null ? void 0 : params.num) || 1;
|
|
413
|
+
if (((_a = product == null ? void 0 : product.custom_deposit_data) == null ? void 0 : _a.has_deposit) == 1) {
|
|
414
|
+
const protocols = [];
|
|
415
|
+
let total = new import_decimal.default(0);
|
|
416
|
+
const { deposit_fixed, deposit_percentage, deposit_policy_data } = (product == null ? void 0 : product.custom_deposit_data) || {};
|
|
417
|
+
protocols.push(...deposit_policy_data || []);
|
|
418
|
+
if (typeof deposit_fixed === "string" && typeof deposit_percentage === "string") {
|
|
419
|
+
const { depositTotal, result } = handleProductDeposit({
|
|
420
|
+
depositData: product == null ? void 0 : product.custom_deposit_data,
|
|
421
|
+
total: cartItem.total || 0,
|
|
422
|
+
num
|
|
423
|
+
});
|
|
424
|
+
if (result) {
|
|
425
|
+
total = depositTotal;
|
|
426
|
+
}
|
|
427
|
+
} else {
|
|
428
|
+
if (bundle == null ? void 0 : bundle.length) {
|
|
429
|
+
total = bundle.reduce((accumulator, currentBundleProduct) => {
|
|
430
|
+
const { depositTotal, result } = handleProductDeposit({
|
|
431
|
+
depositData: currentBundleProduct == null ? void 0 : currentBundleProduct.custom_deposit_data,
|
|
432
|
+
total: currentBundleProduct.price,
|
|
433
|
+
num: currentBundleProduct.num
|
|
434
|
+
});
|
|
435
|
+
if (result) {
|
|
436
|
+
return accumulator.plus(depositTotal);
|
|
437
|
+
}
|
|
438
|
+
return accumulator;
|
|
439
|
+
}, new import_decimal.default(0));
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
return { total: total.toFixed(2), protocols };
|
|
443
|
+
}
|
|
444
|
+
return null;
|
|
445
|
+
};
|
|
446
|
+
var handleProductDeposit = (params) => {
|
|
447
|
+
const { depositData, total, num } = params;
|
|
448
|
+
const { deposit_fixed, deposit_percentage } = depositData;
|
|
449
|
+
if (typeof deposit_fixed === "string" && typeof deposit_percentage === "string") {
|
|
450
|
+
const depositFixed = (0, import_decimal.default)(deposit_fixed || 0);
|
|
451
|
+
const depositPercent = (0, import_decimal.default)(deposit_percentage || 0);
|
|
452
|
+
const productTotalPrice = (0, import_decimal.default)(total || 0);
|
|
453
|
+
const deposit = depositFixed.plus(depositPercent.times(productTotalPrice));
|
|
454
|
+
return { depositTotal: deposit.times(num), result: true };
|
|
455
|
+
}
|
|
456
|
+
return { result: false, depositTotal: new import_decimal.default(0) };
|
|
398
457
|
};
|
|
399
458
|
// Annotate the CommonJS export names for ESM import in node:
|
|
400
459
|
0 && (module.exports = {
|
|
@@ -415,8 +474,10 @@ var getProductOriginTotalPrice = (params) => {
|
|
|
415
474
|
formatProductToCartItemOrigin,
|
|
416
475
|
formatResourceToCartItem,
|
|
417
476
|
formatResourceToCartItemOrigin,
|
|
477
|
+
getProductDeposit,
|
|
418
478
|
getProductOriginTotalPrice,
|
|
419
479
|
getProductTotalPrice,
|
|
420
480
|
getUniqueId,
|
|
481
|
+
handleProductDeposit,
|
|
421
482
|
isNormalProduct
|
|
422
483
|
});
|
|
@@ -156,6 +156,22 @@ export interface ProductData {
|
|
|
156
156
|
capacity?: any;
|
|
157
157
|
/** 商品套餐 */
|
|
158
158
|
product_bundle?: any;
|
|
159
|
+
/** 商品定金信息 */
|
|
160
|
+
custom_deposit_data?: {
|
|
161
|
+
/** 商品是否包含定金 1:是 0:否 */
|
|
162
|
+
has_deposit: 0 | 1;
|
|
163
|
+
/** 定金固定金额 */
|
|
164
|
+
deposit_fixed?: string;
|
|
165
|
+
/** 定金百分比 */
|
|
166
|
+
deposit_percentage?: string;
|
|
167
|
+
/** 定金协议数据 */
|
|
168
|
+
deposit_policy_data?: Array<{
|
|
169
|
+
/** 定金协议id */
|
|
170
|
+
id: number;
|
|
171
|
+
/** 定金协议标题 */
|
|
172
|
+
title: string;
|
|
173
|
+
}>;
|
|
174
|
+
};
|
|
159
175
|
}
|
|
160
176
|
/**
|
|
161
177
|
* 商品媒体信息接口
|
|
@@ -25,6 +25,7 @@ module.exports = __toCommonJS(Rules_exports);
|
|
|
25
25
|
var import_BaseModule = require("../BaseModule");
|
|
26
26
|
var import_types = require("./types");
|
|
27
27
|
var import_utils = require("../../solution/ShopDiscount/utils");
|
|
28
|
+
var import_utils2 = require("../Cart/utils");
|
|
28
29
|
var RulesModule = class extends import_BaseModule.BaseModule {
|
|
29
30
|
constructor(name, version) {
|
|
30
31
|
super(name, version);
|
|
@@ -174,16 +175,42 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
174
175
|
isManualDiscount = false;
|
|
175
176
|
}
|
|
176
177
|
if (applicableDiscounts.length === 0 || isManualDiscount) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
178
|
+
if (product.isClient) {
|
|
179
|
+
processedProductsMap.set(
|
|
180
|
+
product._id,
|
|
181
|
+
this.hooks.setProduct(originProduct, {
|
|
182
|
+
...isManualDiscount ? {} : {
|
|
183
|
+
origin_total: (0, import_utils2.getProductOriginTotalPrice)({
|
|
184
|
+
product: {
|
|
185
|
+
original_price: product.original_price
|
|
186
|
+
},
|
|
187
|
+
bundle: product.bundle,
|
|
188
|
+
options: product.options
|
|
189
|
+
}),
|
|
190
|
+
total: (0, import_utils2.getProductTotalPrice)({
|
|
191
|
+
product: {
|
|
192
|
+
price: product.price
|
|
193
|
+
},
|
|
194
|
+
bundle: product.bundle,
|
|
195
|
+
options: product.options
|
|
196
|
+
}),
|
|
197
|
+
price: product.price
|
|
198
|
+
},
|
|
199
|
+
discount_list: []
|
|
200
|
+
})
|
|
201
|
+
);
|
|
202
|
+
} else {
|
|
203
|
+
processedProductsMap.set(
|
|
204
|
+
product._id,
|
|
205
|
+
this.hooks.setProduct(originProduct, {
|
|
206
|
+
...isManualDiscount ? {} : {
|
|
207
|
+
total: product.origin_total || product.total,
|
|
208
|
+
price: product.price
|
|
209
|
+
},
|
|
210
|
+
discount_list: []
|
|
211
|
+
})
|
|
212
|
+
);
|
|
213
|
+
}
|
|
187
214
|
return;
|
|
188
215
|
}
|
|
189
216
|
if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === "undefined") {
|
|
@@ -203,24 +230,72 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
203
230
|
};
|
|
204
231
|
appliedProducts.push(discountDetail);
|
|
205
232
|
appliedDiscountProducts.set(selectedDiscount.id, appliedProducts);
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
233
|
+
if (product.isClient) {
|
|
234
|
+
processedProductsMap.set(
|
|
235
|
+
product._id,
|
|
236
|
+
this.hooks.setProduct(originProduct, {
|
|
237
|
+
discount_list: [discountDetail],
|
|
238
|
+
price: 0,
|
|
239
|
+
origin_total: (0, import_utils2.getProductOriginTotalPrice)({
|
|
240
|
+
product: {
|
|
241
|
+
original_price: product.original_price
|
|
242
|
+
},
|
|
243
|
+
bundle: product.bundle,
|
|
244
|
+
options: product.options
|
|
245
|
+
}),
|
|
246
|
+
total: (0, import_utils2.getProductTotalPrice)({
|
|
247
|
+
product: {
|
|
248
|
+
price: "0"
|
|
249
|
+
},
|
|
250
|
+
bundle: product.bundle,
|
|
251
|
+
options: product.options
|
|
252
|
+
})
|
|
253
|
+
})
|
|
254
|
+
);
|
|
255
|
+
} else {
|
|
256
|
+
processedProductsMap.set(
|
|
257
|
+
product._id,
|
|
258
|
+
this.hooks.setProduct(originProduct, {
|
|
259
|
+
discount_list: [discountDetail],
|
|
260
|
+
price: 0,
|
|
261
|
+
total: (product.origin_total || product.total) - product.price,
|
|
262
|
+
origin_total: product.origin_total || product.total
|
|
263
|
+
})
|
|
264
|
+
);
|
|
265
|
+
}
|
|
215
266
|
});
|
|
216
267
|
const processedProductList = productList.map((originProduct) => {
|
|
217
268
|
const product = this.hooks.getProduct(originProduct);
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
269
|
+
const getDefaultProduct = () => {
|
|
270
|
+
if (product.isClient) {
|
|
271
|
+
this.hooks.setProduct(originProduct, {
|
|
272
|
+
discount_list: [],
|
|
273
|
+
price: product.price,
|
|
274
|
+
origin_total: (0, import_utils2.getProductOriginTotalPrice)({
|
|
275
|
+
product: {
|
|
276
|
+
original_price: product.original_price
|
|
277
|
+
},
|
|
278
|
+
bundle: product.bundle,
|
|
279
|
+
options: product.options
|
|
280
|
+
}),
|
|
281
|
+
total: (0, import_utils2.getProductTotalPrice)({
|
|
282
|
+
product: {
|
|
283
|
+
price: product.price
|
|
284
|
+
},
|
|
285
|
+
bundle: product.bundle,
|
|
286
|
+
options: product.options
|
|
287
|
+
})
|
|
288
|
+
});
|
|
289
|
+
} else {
|
|
290
|
+
this.hooks.setProduct(originProduct, {
|
|
291
|
+
discount_list: [],
|
|
292
|
+
total: product.total,
|
|
293
|
+
origin_total: product.origin_total,
|
|
294
|
+
price: product.price
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
return processedProductsMap.get(product._id) || getDefaultProduct();
|
|
224
299
|
});
|
|
225
300
|
const updatedDiscountList = addModeDiscount.map((discount) => {
|
|
226
301
|
const applicableProducts = discountApplicability.get(discount.id) || [];
|
|
@@ -25,6 +25,7 @@ export interface RulesModuleAPI {
|
|
|
25
25
|
}) => DiscountResult;
|
|
26
26
|
}
|
|
27
27
|
type ProductDetail = {
|
|
28
|
+
isClient?: boolean;
|
|
28
29
|
isManualDiscount?: boolean;
|
|
29
30
|
booking_id: any;
|
|
30
31
|
id: number;
|
|
@@ -33,6 +34,9 @@ type ProductDetail = {
|
|
|
33
34
|
discount_list: Discount[];
|
|
34
35
|
origin_total: number;
|
|
35
36
|
_id: string;
|
|
37
|
+
options?: any[];
|
|
38
|
+
bundle?: any[];
|
|
39
|
+
original_price?: number | string;
|
|
36
40
|
};
|
|
37
41
|
export interface RulesParamsHooks {
|
|
38
42
|
getProduct: (product: Record<string, any>) => ProductDetail;
|
|
@@ -1,13 +1,34 @@
|
|
|
1
1
|
import { CartItem } from "../Cart/types";
|
|
2
2
|
export interface ISummaryState {
|
|
3
3
|
summary: {
|
|
4
|
+
/** 商品总价 */
|
|
4
5
|
subtotal: string | number;
|
|
6
|
+
/** 最终总价 */
|
|
5
7
|
total: string | number;
|
|
8
|
+
/** 税率标题 */
|
|
6
9
|
taxTitle?: string;
|
|
10
|
+
/** 商品总费率 */
|
|
7
11
|
totalTaxFee?: string | number;
|
|
12
|
+
/** 商品价格是否包含费率 */
|
|
8
13
|
isPriceIncludeTax?: 0 | 1;
|
|
14
|
+
/** 定金 */
|
|
15
|
+
deposit?: {
|
|
16
|
+
/** 定金总价 */
|
|
17
|
+
total?: string | number;
|
|
18
|
+
/** */
|
|
19
|
+
policies?: IProtocol[];
|
|
20
|
+
};
|
|
9
21
|
};
|
|
10
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* 定金协议
|
|
25
|
+
*/
|
|
26
|
+
export interface IProtocol {
|
|
27
|
+
/** 协议名称 */
|
|
28
|
+
title: string;
|
|
29
|
+
/** 协议id */
|
|
30
|
+
id: string;
|
|
31
|
+
}
|
|
11
32
|
export interface ISummaryModuleAPI {
|
|
12
33
|
getSummary(cartItems: CartItem[]): Promise<ISummaryState["summary"]>;
|
|
13
34
|
}
|
|
@@ -17,3 +17,12 @@ export declare const calculateSubtotal: (items: CartItem[]) => string;
|
|
|
17
17
|
* @Author: xiangfeng.xue
|
|
18
18
|
*/
|
|
19
19
|
export declare const calculateTaxFee: (shopInfo: any, items: CartItem[]) => Decimal | "0.00";
|
|
20
|
+
/**
|
|
21
|
+
* @title: 计算定金
|
|
22
|
+
* @param items - 购物车商品数组
|
|
23
|
+
* @returns 定金字符串,保留2位小数
|
|
24
|
+
*/
|
|
25
|
+
export declare const calculateDeposit: (items: CartItem[]) => {
|
|
26
|
+
total: string;
|
|
27
|
+
protocols: any[];
|
|
28
|
+
} | undefined;
|
|
@@ -29,6 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
// src/modules/Summary/utils.ts
|
|
30
30
|
var utils_exports = {};
|
|
31
31
|
__export(utils_exports, {
|
|
32
|
+
calculateDeposit: () => calculateDeposit,
|
|
32
33
|
calculatePriceDetails: () => calculatePriceDetails,
|
|
33
34
|
calculateSubtotal: () => calculateSubtotal,
|
|
34
35
|
calculateTaxFee: () => calculateTaxFee
|
|
@@ -39,12 +40,14 @@ var calculatePriceDetails = (shopInfo, items) => {
|
|
|
39
40
|
const subtotal = new import_decimal.default(calculateSubtotal(items));
|
|
40
41
|
const totalTaxFee = new import_decimal.default(calculateTaxFee(shopInfo, items));
|
|
41
42
|
const total = (shopInfo == null ? void 0 : shopInfo.is_price_include_tax) ? subtotal : subtotal.plus(totalTaxFee);
|
|
43
|
+
const deposit = calculateDeposit(items);
|
|
42
44
|
return {
|
|
43
45
|
subtotal: subtotal.toFixed(2),
|
|
44
46
|
total: total.toFixed(2),
|
|
45
47
|
taxTitle: shopInfo == null ? void 0 : shopInfo.tax_title,
|
|
46
48
|
totalTaxFee: totalTaxFee.toFixed(2),
|
|
47
|
-
isPriceIncludeTax: shopInfo == null ? void 0 : shopInfo.is_price_include_tax
|
|
49
|
+
isPriceIncludeTax: shopInfo == null ? void 0 : shopInfo.is_price_include_tax,
|
|
50
|
+
deposit
|
|
48
51
|
};
|
|
49
52
|
};
|
|
50
53
|
var calculateSubtotal = (items) => {
|
|
@@ -70,8 +73,32 @@ var calculateTaxFee = (shopInfo, items) => {
|
|
|
70
73
|
}, new import_decimal.default(0));
|
|
71
74
|
return totalTaxFee;
|
|
72
75
|
};
|
|
76
|
+
var calculateDeposit = (items) => {
|
|
77
|
+
if (!(items == null ? void 0 : items.length)) {
|
|
78
|
+
return void 0;
|
|
79
|
+
}
|
|
80
|
+
const protocols = [];
|
|
81
|
+
const total = items.reduce((sum, item) => {
|
|
82
|
+
var _a, _b, _c, _d, _e;
|
|
83
|
+
if ((_b = (_a = item == null ? void 0 : item.deposit) == null ? void 0 : _a.protocols) == null ? void 0 : _b.length) {
|
|
84
|
+
const cartItemTotalPrice = new import_decimal.default(((_c = item == null ? void 0 : item.deposit) == null ? void 0 : _c.total) || 0);
|
|
85
|
+
(_e = (_d = item == null ? void 0 : item.deposit) == null ? void 0 : _d.protocols) == null ? void 0 : _e.forEach((protocol) => {
|
|
86
|
+
if (protocols.findIndex((p) => p.id === protocol.id) === -1) {
|
|
87
|
+
protocols.push(protocol);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
return sum.plus(cartItemTotalPrice);
|
|
91
|
+
}
|
|
92
|
+
return sum;
|
|
93
|
+
}, new import_decimal.default(0));
|
|
94
|
+
return {
|
|
95
|
+
total: total.toFixed(2),
|
|
96
|
+
protocols
|
|
97
|
+
};
|
|
98
|
+
};
|
|
73
99
|
// Annotate the CommonJS export names for ESM import in node:
|
|
74
100
|
0 && (module.exports = {
|
|
101
|
+
calculateDeposit,
|
|
75
102
|
calculatePriceDetails,
|
|
76
103
|
calculateSubtotal,
|
|
77
104
|
calculateTaxFee
|
|
@@ -65,6 +65,10 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
65
65
|
taxTitle?: string | undefined;
|
|
66
66
|
totalTaxFee?: string | number | undefined;
|
|
67
67
|
isPriceIncludeTax?: 0 | 1 | undefined;
|
|
68
|
+
deposit?: {
|
|
69
|
+
total?: string | number | undefined;
|
|
70
|
+
policies?: import("../../modules/Summary/types").IProtocol[] | undefined;
|
|
71
|
+
} | undefined;
|
|
68
72
|
}>;
|
|
69
73
|
getProducts(): Promise<ProductData[]>;
|
|
70
74
|
setLoginAccount(accountId: string, accountInfo: Account): Promise<void>;
|