@pisell/pisellos 0.0.481 → 0.0.483
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/model/strategy/adapter/walletPass/evaluator.js +2 -1
- package/dist/model/strategy/adapter/walletPass/type.d.ts +11 -0
- package/dist/modules/Discount/index.d.ts +1 -1
- package/dist/modules/Discount/types.d.ts +2 -0
- package/dist/modules/Order/index.d.ts +1 -1
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/Rules/index.js +119 -43
- package/dist/modules/Rules/types.d.ts +1 -0
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/ShopDiscount/index.d.ts +1 -1
- package/dist/solution/ShopDiscount/index.js +1 -1
- package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -1
- package/lib/model/strategy/adapter/walletPass/type.d.ts +11 -0
- package/lib/modules/Discount/index.d.ts +1 -1
- package/lib/modules/Discount/types.d.ts +2 -0
- package/lib/modules/Order/index.d.ts +1 -1
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Rules/index.js +113 -46
- package/lib/modules/Rules/types.d.ts +1 -0
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/ShopDiscount/index.d.ts +1 -1
- package/lib/solution/ShopDiscount/index.js +1 -1
- package/package.json +1 -1
|
@@ -43,6 +43,8 @@ export interface Voucher {
|
|
|
43
43
|
applicableProductLimit: number;
|
|
44
44
|
/** 单订单行每单位可用同一 Wallet Pass 券次数;该行总券次上限 = maxPassesPerItem × 该行 quantity(按行唯一键区分)。0 表示不限制。 */
|
|
45
45
|
maxPassesPerItem: number;
|
|
46
|
+
/** 是否抵扣单规格价格 (Option Price),默认 false。开启后折扣范围包含 option 的 add_price */
|
|
47
|
+
deductOptionPrice: boolean;
|
|
46
48
|
};
|
|
47
49
|
}
|
|
48
50
|
/**
|
|
@@ -62,6 +64,13 @@ export interface Product {
|
|
|
62
64
|
main_product_original_price?: number;
|
|
63
65
|
/** 主商品折扣后金额,不包含套餐子商品 */
|
|
64
66
|
main_product_selling_price?: number;
|
|
67
|
+
/** 单规格(Option)列表 */
|
|
68
|
+
product_options?: {
|
|
69
|
+
id: number;
|
|
70
|
+
add_price: number | string;
|
|
71
|
+
num: number;
|
|
72
|
+
[key: string]: any;
|
|
73
|
+
}[];
|
|
65
74
|
/** 主商品税费 */
|
|
66
75
|
tax_fee: number;
|
|
67
76
|
metadata: {
|
|
@@ -141,6 +150,8 @@ export interface EvaluatorInput {
|
|
|
141
150
|
applicableProductLimit: number;
|
|
142
151
|
/** 单订单行每单位可用同一 Wallet Pass 券次数;行总上限 = maxPassesPerItem × 该行 quantity(按行唯一键计)。0 表示不限制。 */
|
|
143
152
|
maxPassesPerItem: number;
|
|
153
|
+
/** 是否抵扣单规格价格 (Option Price),默认 false */
|
|
154
|
+
deductOptionPrice: boolean;
|
|
144
155
|
}>[];
|
|
145
156
|
}
|
|
146
157
|
/**
|
|
@@ -17,7 +17,7 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
|
|
|
17
17
|
setOriginalDiscountList(originalDiscountList: Discount[]): Promise<void>;
|
|
18
18
|
getOriginalDiscountList(): Discount[];
|
|
19
19
|
loadPrepareConfig(params: {
|
|
20
|
-
action?: 'create' | '
|
|
20
|
+
action?: 'create' | 'edit';
|
|
21
21
|
with_good_pass: 0 | 1;
|
|
22
22
|
with_discount_card: 0 | 1;
|
|
23
23
|
customer_id: number;
|
|
@@ -120,6 +120,8 @@ export interface Discount {
|
|
|
120
120
|
allowCrossProduct?: boolean;
|
|
121
121
|
/** 可用商品数量上限 */
|
|
122
122
|
applicableProductLimit?: number;
|
|
123
|
+
/** 是否抵扣单规格价格 (Option Price) */
|
|
124
|
+
deductOptionPrice?: boolean;
|
|
123
125
|
};
|
|
124
126
|
applicableProductIds?: number[];
|
|
125
127
|
applicableProductDetails: ApplicableProductDetails[];
|
|
@@ -23,7 +23,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
23
23
|
*/
|
|
24
24
|
private logError;
|
|
25
25
|
createOrder(params: CommitOrderParams['query']): {
|
|
26
|
-
type: "
|
|
26
|
+
type: "virtual" | "appointment_booking";
|
|
27
27
|
platform: string;
|
|
28
28
|
sales_channel: string;
|
|
29
29
|
order_sales_channel: string;
|
|
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
|
|
|
49
49
|
getCategories(): ProductCategory[];
|
|
50
50
|
setOtherParams(key: string, value: any): void;
|
|
51
51
|
getOtherParams(): any;
|
|
52
|
-
getProductType(): "
|
|
52
|
+
getProductType(): "normal" | "duration" | "session";
|
|
53
53
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
var _excluded = ["_original_add_price"];
|
|
1
2
|
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); }
|
|
3
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
4
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
2
5
|
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
6
|
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
7
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
@@ -571,11 +574,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
571
574
|
|
|
572
575
|
// 转换 sortedFlattenedList 为 Product 格式
|
|
573
576
|
var productsForEvaluate = sortedFlattenedList.map(function (item) {
|
|
577
|
+
var _item$product;
|
|
574
578
|
return {
|
|
575
579
|
product_id: item.id,
|
|
576
580
|
price: item.price || 0,
|
|
577
581
|
quantity: item.quantity || item.num || 1,
|
|
578
|
-
selling_price: item.price || 0
|
|
582
|
+
selling_price: item.price || 0,
|
|
583
|
+
product_options: item.type === 'main' ? (_item$product = item.product) === null || _item$product === void 0 ? void 0 : _item$product.options : undefined
|
|
579
584
|
};
|
|
580
585
|
});
|
|
581
586
|
|
|
@@ -930,6 +935,53 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
930
935
|
// 🔥 用于存储扁平化商品处理结果的Map
|
|
931
936
|
var processedFlatItemsMap = new Map();
|
|
932
937
|
|
|
938
|
+
// 🔥 Option 折扣辅助函数
|
|
939
|
+
var applyDiscountToOptions = function applyDiscountToOptions(options, discount) {
|
|
940
|
+
if (!(options !== null && options !== void 0 && options.length)) return {
|
|
941
|
+
discountedOptions: options,
|
|
942
|
+
optionDiscountAmount: 0
|
|
943
|
+
};
|
|
944
|
+
var optionDiscountAmount = 0;
|
|
945
|
+
var discountedOptions = options.map(function (option) {
|
|
946
|
+
var _ref6, _option$num, _option$_original_add;
|
|
947
|
+
var addPrice = Number(option.add_price || 0);
|
|
948
|
+
if (addPrice <= 0) return option;
|
|
949
|
+
var discountedPrice = getDiscountAmount(discount, addPrice, addPrice);
|
|
950
|
+
var optQty = Number((_ref6 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref6 !== void 0 ? _ref6 : 1);
|
|
951
|
+
optionDiscountAmount = new Decimal(optionDiscountAmount).plus(new Decimal(addPrice).minus(discountedPrice).mul(optQty)).toNumber();
|
|
952
|
+
return _objectSpread(_objectSpread({}, option), {}, {
|
|
953
|
+
_original_add_price: (_option$_original_add = option._original_add_price) !== null && _option$_original_add !== void 0 ? _option$_original_add : option.add_price,
|
|
954
|
+
add_price: discountedPrice
|
|
955
|
+
});
|
|
956
|
+
});
|
|
957
|
+
return {
|
|
958
|
+
discountedOptions: discountedOptions,
|
|
959
|
+
optionDiscountAmount: optionDiscountAmount
|
|
960
|
+
};
|
|
961
|
+
};
|
|
962
|
+
var restoreOptionPrices = function restoreOptionPrices(options) {
|
|
963
|
+
if (!(options !== null && options !== void 0 && options.length)) return options;
|
|
964
|
+
return options.map(function (option) {
|
|
965
|
+
if (option._original_add_price !== undefined) {
|
|
966
|
+
var _original_add_price = option._original_add_price,
|
|
967
|
+
rest = _objectWithoutProperties(option, _excluded);
|
|
968
|
+
return _objectSpread(_objectSpread({}, rest), {}, {
|
|
969
|
+
add_price: _original_add_price
|
|
970
|
+
});
|
|
971
|
+
}
|
|
972
|
+
return option;
|
|
973
|
+
});
|
|
974
|
+
};
|
|
975
|
+
var getOptionTotal = function getOptionTotal(options) {
|
|
976
|
+
if (!(options !== null && options !== void 0 && options.length)) return 0;
|
|
977
|
+
return options.reduce(function (sum, opt) {
|
|
978
|
+
var _ref7, _opt$add_price, _ref8, _opt$num;
|
|
979
|
+
var unit = Number((_ref7 = (_opt$add_price = opt.add_price) !== null && _opt$add_price !== void 0 ? _opt$add_price : opt.price) !== null && _ref7 !== void 0 ? _ref7 : 0);
|
|
980
|
+
var n = Number((_ref8 = (_opt$num = opt.num) !== null && _opt$num !== void 0 ? _opt$num : opt.quantity) !== null && _ref8 !== void 0 ? _ref8 : 1);
|
|
981
|
+
return new Decimal(sum).plus(new Decimal(unit).mul(n)).toNumber();
|
|
982
|
+
}, 0);
|
|
983
|
+
};
|
|
984
|
+
|
|
933
985
|
// 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
|
|
934
986
|
// 🔥 使用扁平化后的列表进行处理
|
|
935
987
|
sortedFlattenedList.forEach(function (flatItem, index) {
|
|
@@ -1072,8 +1124,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1072
1124
|
var _product$discount_lis5, _product12, _product12$every;
|
|
1073
1125
|
// 主商品:判断自身是否手动折扣
|
|
1074
1126
|
isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(function (item) {
|
|
1075
|
-
var
|
|
1076
|
-
return !((
|
|
1127
|
+
var _ref9;
|
|
1128
|
+
return !((_ref9 = item.discount_list || []) !== null && _ref9 !== void 0 && _ref9.length);
|
|
1077
1129
|
}) && (!((_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.length) || ((_product12 = product) === null || _product12 === void 0 || (_product12 = _product12.discount_list) === null || _product12 === void 0 || (_product12$every = _product12.every) === null || _product12$every === void 0 ? void 0 : _product12$every.call(_product12, function (item) {
|
|
1078
1130
|
return item.type === 'product';
|
|
1079
1131
|
})));
|
|
@@ -1086,8 +1138,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1086
1138
|
if (parentProduct) {
|
|
1087
1139
|
var _parentProduct$discou, _parentProduct$discou2, _parentProduct$discou3;
|
|
1088
1140
|
isManualDiscount = typeof parentProduct.isManualDiscount === 'boolean' ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(function (item) {
|
|
1089
|
-
var
|
|
1090
|
-
return !((
|
|
1141
|
+
var _ref10;
|
|
1142
|
+
return !((_ref10 = item.discount_list || []) !== null && _ref10 !== void 0 && _ref10.length);
|
|
1091
1143
|
}) && (!((_parentProduct$discou = parentProduct.discount_list) !== null && _parentProduct$discou !== void 0 && _parentProduct$discou.length) || (parentProduct === null || parentProduct === void 0 || (_parentProduct$discou2 = parentProduct.discount_list) === null || _parentProduct$discou2 === void 0 || (_parentProduct$discou3 = _parentProduct$discou2.every) === null || _parentProduct$discou3 === void 0 ? void 0 : _parentProduct$discou3.call(_parentProduct$discou2, function (item) {
|
|
1092
1144
|
return item.type === 'product';
|
|
1093
1145
|
})));
|
|
@@ -1154,7 +1206,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1154
1206
|
// 如果没有适用的优惠券,或者手动折扣,则不适用优惠券
|
|
1155
1207
|
if (applicableDiscounts.length === 0 || isManualDiscount || isBoolean(product.vouchersApplicable) && !product.vouchersApplicable) {
|
|
1156
1208
|
if (flatItem.type === 'main') {
|
|
1157
|
-
//
|
|
1209
|
+
// 主商品:保持原有逻辑,还原 option 价格
|
|
1210
|
+
var restoredOptions = restoreOptionPrices(product.options);
|
|
1158
1211
|
if (product.isClient) {
|
|
1159
1212
|
processedProductsMap.set(product._id, [_this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
|
|
1160
1213
|
origin_total: getProductOriginTotalPrice({
|
|
@@ -1162,7 +1215,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1162
1215
|
original_price: product.original_price
|
|
1163
1216
|
},
|
|
1164
1217
|
bundle: product.bundle,
|
|
1165
|
-
options:
|
|
1218
|
+
options: restoredOptions
|
|
1166
1219
|
}),
|
|
1167
1220
|
variant: originProduct._productInit.variant,
|
|
1168
1221
|
original_price: originProduct._productInit.original_price,
|
|
@@ -1171,15 +1224,16 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1171
1224
|
price: product.price
|
|
1172
1225
|
},
|
|
1173
1226
|
bundle: product.bundle,
|
|
1174
|
-
options:
|
|
1227
|
+
options: restoredOptions
|
|
1175
1228
|
}),
|
|
1176
|
-
price: product.price
|
|
1229
|
+
price: product.price,
|
|
1230
|
+
options: restoredOptions
|
|
1177
1231
|
}), {}, {
|
|
1178
1232
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion')
|
|
1179
1233
|
}))]);
|
|
1180
1234
|
} else {
|
|
1181
|
-
var
|
|
1182
|
-
var total = product.inPromotion ? (
|
|
1235
|
+
var _ref11, _product$_promotion$f, _product13, _product$origin_total, _product$price2;
|
|
1236
|
+
var total = product.inPromotion ? (_ref11 = (_product$_promotion$f = (_product13 = product) === null || _product13 === void 0 || (_product13 = _product13._promotion) === null || _product13 === void 0 ? void 0 : _product13.finalPrice) !== null && _product$_promotion$f !== void 0 ? _product$_promotion$f : product.origin_total) !== null && _ref11 !== void 0 ? _ref11 : product.total : (_product$origin_total = product.origin_total) !== null && _product$origin_total !== void 0 ? _product$origin_total : product.total;
|
|
1183
1237
|
var main_product_selling_price = (_product$price2 = product.price) !== null && _product$price2 !== void 0 ? _product$price2 : product.main_product_selling_price;
|
|
1184
1238
|
if ((product.discount_list || []).some(function (item) {
|
|
1185
1239
|
return item.type === 'promotion';
|
|
@@ -1194,7 +1248,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1194
1248
|
_id: product._id.split('___')[0] + '___' + index,
|
|
1195
1249
|
total: total,
|
|
1196
1250
|
price: product.price,
|
|
1197
|
-
main_product_selling_price: main_product_selling_price
|
|
1251
|
+
main_product_selling_price: main_product_selling_price,
|
|
1252
|
+
options: restoredOptions
|
|
1198
1253
|
}), {}, {
|
|
1199
1254
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion')
|
|
1200
1255
|
}))]);
|
|
@@ -1269,7 +1324,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1269
1324
|
}));
|
|
1270
1325
|
}
|
|
1271
1326
|
for (var i = 0; i < splitCount; i++) {
|
|
1272
|
-
var _originProduct, _selectedDiscount$met, _selectedDiscount$met2;
|
|
1327
|
+
var _originProduct, _selectedDiscount$con2, _product$options, _product$options2, _selectedDiscount$met, _selectedDiscount$met2;
|
|
1273
1328
|
// 商品券:每个拆分商品使用不同的商品券(从 applicableDiscounts 按索引取)
|
|
1274
1329
|
// 折扣卡:所有拆分商品使用同一张折扣卡(selectedDiscountCard 或 applicableDiscounts[0])
|
|
1275
1330
|
var currentSelectedDiscount = isGoodPass ? selectedDiscountCard || applicableDiscounts[i] : selectedDiscountCard || applicableDiscounts[0];
|
|
@@ -1306,28 +1361,47 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1306
1361
|
var isOrderLevel = isOrderLevelFixedAmountDiscount(selectedDiscount);
|
|
1307
1362
|
var orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount.id) : null;
|
|
1308
1363
|
var productAllocation = orderLevelAllocation === null || orderLevelAllocation === void 0 ? void 0 : orderLevelAllocation.get(flatItem._id);
|
|
1309
|
-
var
|
|
1364
|
+
var isDeductOptionPrice = !!((_selectedDiscount$con2 = selectedDiscount.config) !== null && _selectedDiscount$con2 !== void 0 && _selectedDiscount$con2.deductOptionPrice);
|
|
1365
|
+
|
|
1366
|
+
// 主商品折后价(不含 option);勿与 option 合计混在同一变量,否则 main_product_selling_price 错误
|
|
1367
|
+
var mainProductSellingPrice = void 0;
|
|
1310
1368
|
var amount = void 0;
|
|
1311
1369
|
var productDiscountDifference = void 0;
|
|
1370
|
+
var discountedOptions = product.options;
|
|
1371
|
+
var optionDiscountAmount = 0;
|
|
1312
1372
|
if (isOrderLevel && productAllocation) {
|
|
1313
1373
|
// order_level:使用预计算的分摊金额
|
|
1314
1374
|
amount = productAllocation.discountAmount;
|
|
1315
1375
|
productDiscountDifference = productAllocation.difference;
|
|
1316
|
-
|
|
1376
|
+
mainProductSellingPrice = Math.max(new Decimal(product.price).minus(amount).toNumber(), 0);
|
|
1317
1377
|
} else {
|
|
1318
1378
|
// item_level 或其他类型:使用原有逻辑
|
|
1319
|
-
|
|
1320
|
-
amount = new Decimal(product.price).minus(new Decimal(
|
|
1379
|
+
mainProductSellingPrice = getDiscountAmount(currentSelectedDiscount, product.price, product.price);
|
|
1380
|
+
amount = new Decimal(product.price).minus(new Decimal(mainProductSellingPrice)).toNumber();
|
|
1381
|
+
}
|
|
1382
|
+
if (isDeductOptionPrice && (_product$options = product.options) !== null && _product$options !== void 0 && _product$options.length) {
|
|
1383
|
+
var optionResult = applyDiscountToOptions(product.options, currentSelectedDiscount);
|
|
1384
|
+
discountedOptions = optionResult.discountedOptions;
|
|
1385
|
+
optionDiscountAmount = optionResult.optionDiscountAmount;
|
|
1321
1386
|
}
|
|
1387
|
+
|
|
1388
|
+
// total = 主商品折后 + option 行合计;开启 option 抵扣时必须用 discountedOptions,不能用未折扣的 product.options 再算一遍
|
|
1389
|
+
var optionsForLineTotal = isDeductOptionPrice && (_product$options2 = product.options) !== null && _product$options2 !== void 0 && _product$options2.length ? discountedOptions : product.options;
|
|
1390
|
+
var optionsLineTotal = getOptionTotal(optionsForLineTotal || []);
|
|
1391
|
+
var _total2 = new Decimal(mainProductSellingPrice).plus(optionsLineTotal).toNumber();
|
|
1392
|
+
|
|
1393
|
+
// discount_list.amount / fixed_amount:行级总优惠 = 主商品优惠 + option 优惠(与 total 变化一致)
|
|
1394
|
+
var mainProductDiscountAmount = amount;
|
|
1395
|
+
var lineDiscountAmount = new Decimal(mainProductDiscountAmount).plus(optionDiscountAmount).toNumber();
|
|
1322
1396
|
var currentDiscountType = currentSelectedDiscount.tag === 'product_discount_card' ? 'discount_card' : currentSelectedDiscount.tag;
|
|
1323
1397
|
var _discountType = selectedDiscount.tag || selectedDiscount.type;
|
|
1324
1398
|
var currentIsGoodPass = currentDiscountType === 'good_pass';
|
|
1325
1399
|
var discountDetail = {
|
|
1326
|
-
amount:
|
|
1400
|
+
amount: lineDiscountAmount,
|
|
1327
1401
|
type: selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : _discountType,
|
|
1328
1402
|
discount: {
|
|
1329
1403
|
discount_card_type: selectedDiscount === null || selectedDiscount === void 0 || (_selectedDiscount$met = selectedDiscount.metadata) === null || _selectedDiscount$met === void 0 ? void 0 : _selectedDiscount$met.discount_card_type,
|
|
1330
|
-
fixed_amount:
|
|
1404
|
+
fixed_amount: lineDiscountAmount,
|
|
1331
1405
|
discount_calculation_mode: selectedDiscount === null || selectedDiscount === void 0 || (_selectedDiscount$met2 = selectedDiscount.metadata) === null || _selectedDiscount$met2 === void 0 ? void 0 : _selectedDiscount$met2.discount_calculation_mode,
|
|
1332
1406
|
resource_id: selectedDiscount.id,
|
|
1333
1407
|
title: selectedDiscount.format_title,
|
|
@@ -1339,41 +1413,39 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1339
1413
|
// 前端使用的num数量,为了计算优惠金额(拆分时为1)
|
|
1340
1414
|
_num: isNeedSplit ? 1 : product.num,
|
|
1341
1415
|
config: currentSelectedDiscount === null || currentSelectedDiscount === void 0 ? void 0 : currentSelectedDiscount.config,
|
|
1342
|
-
metadata: _objectSpread({
|
|
1416
|
+
metadata: _objectSpread(_objectSpread({
|
|
1343
1417
|
num: 1,
|
|
1344
1418
|
discount_rule_uncheck_flag: selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.discount_rule_uncheck_flag
|
|
1345
1419
|
}, productDiscountDifference !== undefined && {
|
|
1346
1420
|
product_discount_difference: productDiscountDifference
|
|
1421
|
+
}), {}, {
|
|
1422
|
+
/** 仅主商品上的优惠金额(不含 option) */
|
|
1423
|
+
mainProductDiscountAmount: mainProductDiscountAmount,
|
|
1424
|
+
optionDiscountAmount: optionDiscountAmount
|
|
1347
1425
|
})
|
|
1348
1426
|
};
|
|
1349
1427
|
appliedProducts.push(discountDetail);
|
|
1350
1428
|
appliedDiscountProducts.set(currentSelectedDiscount.id, appliedProducts);
|
|
1351
|
-
var _total2 = targetProductTotal;
|
|
1352
|
-
if (product.options) {
|
|
1353
|
-
_total2 = product.options.reduce(function (accumulator, currentValue) {
|
|
1354
|
-
var currentPrice = new Decimal(currentValue.price || 0);
|
|
1355
|
-
var currentNum = new Decimal(currentValue.num || 0);
|
|
1356
|
-
return accumulator.add(currentPrice.mul(currentNum));
|
|
1357
|
-
}, new Decimal(_total2)).toNumber();
|
|
1358
|
-
}
|
|
1359
1429
|
|
|
1360
1430
|
// 记录应用了优惠券的商品
|
|
1361
1431
|
// 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
|
|
1362
1432
|
if (product.isClient) {
|
|
1363
1433
|
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
1364
1434
|
discount_list: [discountDetail],
|
|
1365
|
-
|
|
1435
|
+
// good_pass:主商品价以折后价为准;勿用 product.price - amount(amount 含 option 优惠时会算错)
|
|
1436
|
+
price: currentIsGoodPass ? mainProductSellingPrice : product.price,
|
|
1366
1437
|
quantity: isNeedSplit ? 1 : product.quantity,
|
|
1367
1438
|
origin_total: getProductOriginTotalPrice({
|
|
1368
1439
|
product: {
|
|
1369
1440
|
original_price: product.original_price
|
|
1370
1441
|
},
|
|
1371
1442
|
bundle: product.bundle,
|
|
1372
|
-
options: product.options
|
|
1443
|
+
options: restoreOptionPrices(product.options)
|
|
1373
1444
|
}),
|
|
1374
1445
|
variant: originProduct._productInit.variant,
|
|
1375
1446
|
original_price: new Decimal(product.price || 0).toNumber(),
|
|
1376
|
-
total: _total2
|
|
1447
|
+
total: _total2,
|
|
1448
|
+
options: discountedOptions
|
|
1377
1449
|
}));
|
|
1378
1450
|
} else {
|
|
1379
1451
|
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
@@ -1383,7 +1455,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1383
1455
|
quantity: isNeedSplit ? 1 : product.quantity,
|
|
1384
1456
|
total: _total2,
|
|
1385
1457
|
origin_total: productOriginTotal,
|
|
1386
|
-
main_product_selling_price:
|
|
1458
|
+
main_product_selling_price: mainProductSellingPrice,
|
|
1459
|
+
options: discountedOptions
|
|
1387
1460
|
}));
|
|
1388
1461
|
}
|
|
1389
1462
|
}
|
|
@@ -1720,22 +1793,22 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1720
1793
|
var _isOrderLevel = isOrderLevelFixedAmountDiscount(selectedDiscount);
|
|
1721
1794
|
var _orderLevelAllocation = _isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount.id) : null;
|
|
1722
1795
|
var _productAllocation = _orderLevelAllocation === null || _orderLevelAllocation === void 0 ? void 0 : _orderLevelAllocation.get(flatItem._id);
|
|
1723
|
-
var
|
|
1796
|
+
var targetProductTotal;
|
|
1724
1797
|
var fixedAmountPerItem;
|
|
1725
1798
|
var _productDiscountDifference;
|
|
1726
1799
|
if (_isOrderLevel && _productAllocation) {
|
|
1727
1800
|
// order_level:使用预计算的单价折扣金额(已经是单价,无需再除以数量)
|
|
1728
1801
|
fixedAmountPerItem = _productAllocation.discountAmount;
|
|
1729
1802
|
_productDiscountDifference = _productAllocation.difference;
|
|
1730
|
-
|
|
1803
|
+
targetProductTotal = Math.max(new Decimal(_productOriginTotal).minus(fixedAmountPerItem).toNumber(), 0);
|
|
1731
1804
|
} else {
|
|
1732
1805
|
// item_level 或其他类型:使用原有逻辑
|
|
1733
|
-
|
|
1734
|
-
fixedAmountPerItem = new Decimal(_productOriginTotal).minus(
|
|
1806
|
+
targetProductTotal = getDiscountAmount(_currentBundleDiscount, _productOriginTotal, _productOriginTotal);
|
|
1807
|
+
fixedAmountPerItem = new Decimal(_productOriginTotal).minus(targetProductTotal).toNumber();
|
|
1735
1808
|
}
|
|
1736
1809
|
|
|
1737
1810
|
// 计算实际折扣金额
|
|
1738
|
-
var bundleActualDiscountAmount = new Decimal(_productOriginTotal).minus(
|
|
1811
|
+
var bundleActualDiscountAmount = new Decimal(_productOriginTotal).minus(targetProductTotal).toNumber();
|
|
1739
1812
|
|
|
1740
1813
|
// 🔥 使用当前的 _id 作为唯一标识
|
|
1741
1814
|
var _uniqueId = flatItem._id;
|
|
@@ -1770,7 +1843,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1770
1843
|
_appliedProducts2.push(_discountDetail2);
|
|
1771
1844
|
appliedDiscountProducts.set(_currentBundleDiscount.id, _appliedProducts2);
|
|
1772
1845
|
processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
1773
|
-
total:
|
|
1846
|
+
total: targetProductTotal,
|
|
1774
1847
|
price: new Decimal(_productOriginTotal || 0).minus(fixedAmountPerItem).toNumber(),
|
|
1775
1848
|
discount_list: _this3.filterDiscountListByType(flatItem.discount_list, 'promotion').concat([_discountDetail2]),
|
|
1776
1849
|
processed: true
|
|
@@ -1789,8 +1862,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1789
1862
|
// 获取主商品处理结果
|
|
1790
1863
|
var mainProductArr = processedProductsMap.get(product._id);
|
|
1791
1864
|
if (!mainProductArr || mainProductArr.length === 0) {
|
|
1792
|
-
//
|
|
1865
|
+
// 如果没有处理结果,返回默认商品(还原 option 价格)
|
|
1793
1866
|
var getDefaultProduct = function getDefaultProduct() {
|
|
1867
|
+
var restoredOptions = restoreOptionPrices(product.options);
|
|
1794
1868
|
if (product.isClient) {
|
|
1795
1869
|
return _this3.hooks.setProduct(originProduct, {
|
|
1796
1870
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion'),
|
|
@@ -1800,7 +1874,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1800
1874
|
original_price: product.original_price
|
|
1801
1875
|
},
|
|
1802
1876
|
bundle: product.bundle,
|
|
1803
|
-
options:
|
|
1877
|
+
options: restoredOptions
|
|
1804
1878
|
}),
|
|
1805
1879
|
variant: originProduct._productInit.variant,
|
|
1806
1880
|
original_price: originProduct._productInit.original_price,
|
|
@@ -1809,15 +1883,17 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1809
1883
|
price: product.price
|
|
1810
1884
|
},
|
|
1811
1885
|
bundle: product.bundle,
|
|
1812
|
-
options:
|
|
1813
|
-
})
|
|
1886
|
+
options: restoredOptions
|
|
1887
|
+
}),
|
|
1888
|
+
options: restoredOptions
|
|
1814
1889
|
});
|
|
1815
1890
|
} else {
|
|
1816
1891
|
return _this3.hooks.setProduct(originProduct, {
|
|
1817
1892
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion'),
|
|
1818
1893
|
total: product.total,
|
|
1819
1894
|
origin_total: product.origin_total,
|
|
1820
|
-
price: product.price
|
|
1895
|
+
price: product.price,
|
|
1896
|
+
options: restoreOptionPrices(product.options)
|
|
1821
1897
|
});
|
|
1822
1898
|
}
|
|
1823
1899
|
};
|
|
@@ -131,7 +131,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
|
|
|
131
131
|
* 获取当前的客户搜索条件
|
|
132
132
|
* @returns 当前搜索条件
|
|
133
133
|
*/
|
|
134
|
-
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "
|
|
134
|
+
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
|
|
135
135
|
/**
|
|
136
136
|
* 获取客户列表状态(包含滚动加载相关状态)
|
|
137
137
|
* @returns 客户状态
|
|
@@ -58,7 +58,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
58
58
|
private bestDiscount;
|
|
59
59
|
loadPrepareConfig(params: {
|
|
60
60
|
customerId: number;
|
|
61
|
-
action?: 'create' | '
|
|
61
|
+
action?: 'create' | 'edit';
|
|
62
62
|
with_good_pass?: 0 | 1;
|
|
63
63
|
with_discount_card?: 0 | 1;
|
|
64
64
|
}): Promise<void>;
|
|
@@ -807,7 +807,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
807
807
|
_context10.next = 5;
|
|
808
808
|
return (_this$store$discount8 = this.store.discount) === null || _this$store$discount8 === void 0 ? void 0 : _this$store$discount8.loadPrepareConfig(_objectSpread({
|
|
809
809
|
customer_id: customerId,
|
|
810
|
-
action: orderId ? '
|
|
810
|
+
action: orderId ? 'edit' : 'create',
|
|
811
811
|
with_good_pass: 1,
|
|
812
812
|
with_discount_card: 1,
|
|
813
813
|
with_wallet_pass_holder: 1,
|
|
@@ -42,7 +42,8 @@ var defaultStrategyMetadataCustom = {
|
|
|
42
42
|
allowCrossProduct: true,
|
|
43
43
|
applicableProductLimit: 0,
|
|
44
44
|
deductTaxAndFee: true,
|
|
45
|
-
maxPassesPerItem: 0
|
|
45
|
+
maxPassesPerItem: 0,
|
|
46
|
+
deductOptionPrice: false
|
|
46
47
|
};
|
|
47
48
|
var WalletPassEvaluator = class {
|
|
48
49
|
constructor() {
|
|
@@ -43,6 +43,8 @@ export interface Voucher {
|
|
|
43
43
|
applicableProductLimit: number;
|
|
44
44
|
/** 单订单行每单位可用同一 Wallet Pass 券次数;该行总券次上限 = maxPassesPerItem × 该行 quantity(按行唯一键区分)。0 表示不限制。 */
|
|
45
45
|
maxPassesPerItem: number;
|
|
46
|
+
/** 是否抵扣单规格价格 (Option Price),默认 false。开启后折扣范围包含 option 的 add_price */
|
|
47
|
+
deductOptionPrice: boolean;
|
|
46
48
|
};
|
|
47
49
|
}
|
|
48
50
|
/**
|
|
@@ -62,6 +64,13 @@ export interface Product {
|
|
|
62
64
|
main_product_original_price?: number;
|
|
63
65
|
/** 主商品折扣后金额,不包含套餐子商品 */
|
|
64
66
|
main_product_selling_price?: number;
|
|
67
|
+
/** 单规格(Option)列表 */
|
|
68
|
+
product_options?: {
|
|
69
|
+
id: number;
|
|
70
|
+
add_price: number | string;
|
|
71
|
+
num: number;
|
|
72
|
+
[key: string]: any;
|
|
73
|
+
}[];
|
|
65
74
|
/** 主商品税费 */
|
|
66
75
|
tax_fee: number;
|
|
67
76
|
metadata: {
|
|
@@ -141,6 +150,8 @@ export interface EvaluatorInput {
|
|
|
141
150
|
applicableProductLimit: number;
|
|
142
151
|
/** 单订单行每单位可用同一 Wallet Pass 券次数;行总上限 = maxPassesPerItem × 该行 quantity(按行唯一键计)。0 表示不限制。 */
|
|
143
152
|
maxPassesPerItem: number;
|
|
153
|
+
/** 是否抵扣单规格价格 (Option Price),默认 false */
|
|
154
|
+
deductOptionPrice: boolean;
|
|
144
155
|
}>[];
|
|
145
156
|
}
|
|
146
157
|
/**
|
|
@@ -17,7 +17,7 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
|
|
|
17
17
|
setOriginalDiscountList(originalDiscountList: Discount[]): Promise<void>;
|
|
18
18
|
getOriginalDiscountList(): Discount[];
|
|
19
19
|
loadPrepareConfig(params: {
|
|
20
|
-
action?: 'create' | '
|
|
20
|
+
action?: 'create' | 'edit';
|
|
21
21
|
with_good_pass: 0 | 1;
|
|
22
22
|
with_discount_card: 0 | 1;
|
|
23
23
|
customer_id: number;
|
|
@@ -120,6 +120,8 @@ export interface Discount {
|
|
|
120
120
|
allowCrossProduct?: boolean;
|
|
121
121
|
/** 可用商品数量上限 */
|
|
122
122
|
applicableProductLimit?: number;
|
|
123
|
+
/** 是否抵扣单规格价格 (Option Price) */
|
|
124
|
+
deductOptionPrice?: boolean;
|
|
123
125
|
};
|
|
124
126
|
applicableProductIds?: number[];
|
|
125
127
|
applicableProductDetails: ApplicableProductDetails[];
|
|
@@ -23,7 +23,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
23
23
|
*/
|
|
24
24
|
private logError;
|
|
25
25
|
createOrder(params: CommitOrderParams['query']): {
|
|
26
|
-
type: "
|
|
26
|
+
type: "virtual" | "appointment_booking";
|
|
27
27
|
platform: string;
|
|
28
28
|
sales_channel: string;
|
|
29
29
|
order_sales_channel: string;
|
|
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
|
|
|
49
49
|
getCategories(): ProductCategory[];
|
|
50
50
|
setOtherParams(key: string, value: any): void;
|
|
51
51
|
getOtherParams(): any;
|
|
52
|
-
getProductType(): "
|
|
52
|
+
getProductType(): "normal" | "duration" | "session";
|
|
53
53
|
}
|
|
@@ -390,12 +390,16 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
390
390
|
available_product_type: (_a = discount.limited_relation_product_data) == null ? void 0 : _a.type,
|
|
391
391
|
available_product_ids: (_b = discount.limited_relation_product_data) == null ? void 0 : _b.product_ids
|
|
392
392
|
};
|
|
393
|
-
const productsForEvaluate = sortedFlattenedList.map((item) =>
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
393
|
+
const productsForEvaluate = sortedFlattenedList.map((item) => {
|
|
394
|
+
var _a2;
|
|
395
|
+
return {
|
|
396
|
+
product_id: item.id,
|
|
397
|
+
price: item.price || 0,
|
|
398
|
+
quantity: item.quantity || item.num || 1,
|
|
399
|
+
selling_price: item.price || 0,
|
|
400
|
+
product_options: item.type === "main" ? (_a2 = item.product) == null ? void 0 : _a2.options : void 0
|
|
401
|
+
};
|
|
402
|
+
});
|
|
399
403
|
const result = evaluator.checkVoucherAvailability({
|
|
400
404
|
orderTotalAmount,
|
|
401
405
|
products: productsForEvaluate,
|
|
@@ -632,8 +636,47 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
632
636
|
});
|
|
633
637
|
});
|
|
634
638
|
const processedFlatItemsMap = /* @__PURE__ */ new Map();
|
|
639
|
+
const applyDiscountToOptions = (options2, discount) => {
|
|
640
|
+
if (!(options2 == null ? void 0 : options2.length))
|
|
641
|
+
return { discountedOptions: options2, optionDiscountAmount: 0 };
|
|
642
|
+
let optionDiscountAmount = 0;
|
|
643
|
+
const discountedOptions = options2.map((option) => {
|
|
644
|
+
const addPrice = Number(option.add_price || 0);
|
|
645
|
+
if (addPrice <= 0)
|
|
646
|
+
return option;
|
|
647
|
+
const discountedPrice = (0, import_utils.getDiscountAmount)(discount, addPrice, addPrice);
|
|
648
|
+
const optQty = Number(option.num ?? option.quantity ?? 1);
|
|
649
|
+
optionDiscountAmount = new import_decimal.default(optionDiscountAmount).plus(new import_decimal.default(addPrice).minus(discountedPrice).mul(optQty)).toNumber();
|
|
650
|
+
return {
|
|
651
|
+
...option,
|
|
652
|
+
_original_add_price: option._original_add_price ?? option.add_price,
|
|
653
|
+
add_price: discountedPrice
|
|
654
|
+
};
|
|
655
|
+
});
|
|
656
|
+
return { discountedOptions, optionDiscountAmount };
|
|
657
|
+
};
|
|
658
|
+
const restoreOptionPrices = (options2) => {
|
|
659
|
+
if (!(options2 == null ? void 0 : options2.length))
|
|
660
|
+
return options2;
|
|
661
|
+
return options2.map((option) => {
|
|
662
|
+
if (option._original_add_price !== void 0) {
|
|
663
|
+
const { _original_add_price, ...rest } = option;
|
|
664
|
+
return { ...rest, add_price: _original_add_price };
|
|
665
|
+
}
|
|
666
|
+
return option;
|
|
667
|
+
});
|
|
668
|
+
};
|
|
669
|
+
const getOptionTotal = (options2) => {
|
|
670
|
+
if (!(options2 == null ? void 0 : options2.length))
|
|
671
|
+
return 0;
|
|
672
|
+
return options2.reduce((sum, opt) => {
|
|
673
|
+
const unit = Number(opt.add_price ?? opt.price ?? 0);
|
|
674
|
+
const n = Number(opt.num ?? opt.quantity ?? 1);
|
|
675
|
+
return new import_decimal.default(sum).plus(new import_decimal.default(unit).mul(n)).toNumber();
|
|
676
|
+
}, 0);
|
|
677
|
+
};
|
|
635
678
|
sortedFlattenedList.forEach((flatItem, index) => {
|
|
636
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J;
|
|
679
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M;
|
|
637
680
|
let product, originProduct;
|
|
638
681
|
if (flatItem.type === "main") {
|
|
639
682
|
product = flatItem.product;
|
|
@@ -842,6 +885,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
842
885
|
}
|
|
843
886
|
if (applicableDiscounts.length === 0 || isManualDiscount || (0, import_lodash_es.isBoolean)(product.vouchersApplicable) && !product.vouchersApplicable) {
|
|
844
887
|
if (flatItem.type === "main") {
|
|
888
|
+
const restoredOptions = restoreOptionPrices(product.options);
|
|
845
889
|
if (product.isClient) {
|
|
846
890
|
processedProductsMap.set(product._id, [
|
|
847
891
|
this.hooks.setProduct(originProduct, {
|
|
@@ -851,7 +895,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
851
895
|
original_price: product.original_price
|
|
852
896
|
},
|
|
853
897
|
bundle: product.bundle,
|
|
854
|
-
options:
|
|
898
|
+
options: restoredOptions
|
|
855
899
|
}),
|
|
856
900
|
variant: originProduct._productInit.variant,
|
|
857
901
|
original_price: originProduct._productInit.original_price,
|
|
@@ -860,9 +904,10 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
860
904
|
price: product.price
|
|
861
905
|
},
|
|
862
906
|
bundle: product.bundle,
|
|
863
|
-
options:
|
|
907
|
+
options: restoredOptions
|
|
864
908
|
}),
|
|
865
|
-
price: product.price
|
|
909
|
+
price: product.price,
|
|
910
|
+
options: restoredOptions
|
|
866
911
|
},
|
|
867
912
|
discount_list: this.filterDiscountListByType(product.discount_list, "promotion")
|
|
868
913
|
})
|
|
@@ -882,7 +927,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
882
927
|
_id: product._id.split("___")[0] + "___" + index,
|
|
883
928
|
total,
|
|
884
929
|
price: product.price,
|
|
885
|
-
main_product_selling_price
|
|
930
|
+
main_product_selling_price,
|
|
931
|
+
options: restoredOptions
|
|
886
932
|
},
|
|
887
933
|
discount_list: this.filterDiscountListByType(product.discount_list, "promotion")
|
|
888
934
|
})
|
|
@@ -965,27 +1011,47 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
965
1011
|
const isOrderLevel = (0, import_utils3.isOrderLevelFixedAmountDiscount)(selectedDiscount);
|
|
966
1012
|
const orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount.id) : null;
|
|
967
1013
|
const productAllocation = orderLevelAllocation == null ? void 0 : orderLevelAllocation.get(flatItem._id);
|
|
968
|
-
|
|
1014
|
+
const isDeductOptionPrice = !!((_y = selectedDiscount.config) == null ? void 0 : _y.deductOptionPrice);
|
|
1015
|
+
let mainProductSellingPrice;
|
|
969
1016
|
let amount;
|
|
970
1017
|
let productDiscountDifference;
|
|
1018
|
+
let discountedOptions = product.options;
|
|
1019
|
+
let optionDiscountAmount = 0;
|
|
971
1020
|
if (isOrderLevel && productAllocation) {
|
|
972
1021
|
amount = productAllocation.discountAmount;
|
|
973
1022
|
productDiscountDifference = productAllocation.difference;
|
|
974
|
-
|
|
1023
|
+
mainProductSellingPrice = Math.max(new import_decimal.default(product.price).minus(amount).toNumber(), 0);
|
|
975
1024
|
} else {
|
|
976
|
-
|
|
977
|
-
|
|
1025
|
+
mainProductSellingPrice = (0, import_utils.getDiscountAmount)(
|
|
1026
|
+
currentSelectedDiscount,
|
|
1027
|
+
product.price,
|
|
1028
|
+
product.price
|
|
1029
|
+
);
|
|
1030
|
+
amount = new import_decimal.default(product.price).minus(new import_decimal.default(mainProductSellingPrice)).toNumber();
|
|
978
1031
|
}
|
|
1032
|
+
if (isDeductOptionPrice && ((_z = product.options) == null ? void 0 : _z.length)) {
|
|
1033
|
+
const optionResult = applyDiscountToOptions(
|
|
1034
|
+
product.options,
|
|
1035
|
+
currentSelectedDiscount
|
|
1036
|
+
);
|
|
1037
|
+
discountedOptions = optionResult.discountedOptions;
|
|
1038
|
+
optionDiscountAmount = optionResult.optionDiscountAmount;
|
|
1039
|
+
}
|
|
1040
|
+
const optionsForLineTotal = isDeductOptionPrice && ((_A = product.options) == null ? void 0 : _A.length) ? discountedOptions : product.options;
|
|
1041
|
+
const optionsLineTotal = getOptionTotal(optionsForLineTotal || []);
|
|
1042
|
+
const total = new import_decimal.default(mainProductSellingPrice).plus(optionsLineTotal).toNumber();
|
|
1043
|
+
const mainProductDiscountAmount = amount;
|
|
1044
|
+
const lineDiscountAmount = new import_decimal.default(mainProductDiscountAmount).plus(optionDiscountAmount).toNumber();
|
|
979
1045
|
const currentDiscountType = currentSelectedDiscount.tag === "product_discount_card" ? "discount_card" : currentSelectedDiscount.tag;
|
|
980
1046
|
const discountType2 = selectedDiscount.tag || selectedDiscount.type;
|
|
981
1047
|
const currentIsGoodPass = currentDiscountType === "good_pass";
|
|
982
1048
|
const discountDetail = {
|
|
983
|
-
amount,
|
|
1049
|
+
amount: lineDiscountAmount,
|
|
984
1050
|
type: selectedDiscount.tag === "product_discount_card" ? "discount_card" : discountType2,
|
|
985
1051
|
discount: {
|
|
986
|
-
discount_card_type: (
|
|
987
|
-
fixed_amount:
|
|
988
|
-
discount_calculation_mode: (
|
|
1052
|
+
discount_card_type: (_B = selectedDiscount == null ? void 0 : selectedDiscount.metadata) == null ? void 0 : _B.discount_card_type,
|
|
1053
|
+
fixed_amount: lineDiscountAmount,
|
|
1054
|
+
discount_calculation_mode: (_C = selectedDiscount == null ? void 0 : selectedDiscount.metadata) == null ? void 0 : _C.discount_calculation_mode,
|
|
989
1055
|
resource_id: selectedDiscount.id,
|
|
990
1056
|
title: selectedDiscount.format_title,
|
|
991
1057
|
original_amount: product.price,
|
|
@@ -1000,35 +1066,32 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1000
1066
|
num: 1,
|
|
1001
1067
|
discount_rule_uncheck_flag: selectedDiscount == null ? void 0 : selectedDiscount.discount_rule_uncheck_flag,
|
|
1002
1068
|
// 🔥 order_level 分摊差值
|
|
1003
|
-
...productDiscountDifference !== void 0 && { product_discount_difference: productDiscountDifference }
|
|
1069
|
+
...productDiscountDifference !== void 0 && { product_discount_difference: productDiscountDifference },
|
|
1070
|
+
/** 仅主商品上的优惠金额(不含 option) */
|
|
1071
|
+
mainProductDiscountAmount,
|
|
1072
|
+
optionDiscountAmount
|
|
1004
1073
|
}
|
|
1005
1074
|
};
|
|
1006
1075
|
appliedProducts.push(discountDetail);
|
|
1007
1076
|
appliedDiscountProducts.set(currentSelectedDiscount.id, appliedProducts);
|
|
1008
|
-
let total = targetProductTotal;
|
|
1009
|
-
if (product.options) {
|
|
1010
|
-
total = product.options.reduce((accumulator, currentValue) => {
|
|
1011
|
-
const currentPrice = new import_decimal.default(currentValue.price || 0);
|
|
1012
|
-
const currentNum = new import_decimal.default(currentValue.num || 0);
|
|
1013
|
-
return accumulator.add(currentPrice.mul(currentNum));
|
|
1014
|
-
}, new import_decimal.default(total)).toNumber();
|
|
1015
|
-
}
|
|
1016
1077
|
if (product.isClient) {
|
|
1017
1078
|
arr.push(
|
|
1018
1079
|
this.hooks.setProduct(originProduct, {
|
|
1019
1080
|
discount_list: [discountDetail],
|
|
1020
|
-
|
|
1081
|
+
// good_pass:主商品价以折后价为准;勿用 product.price - amount(amount 含 option 优惠时会算错)
|
|
1082
|
+
price: currentIsGoodPass ? mainProductSellingPrice : product.price,
|
|
1021
1083
|
quantity: isNeedSplit ? 1 : product.quantity,
|
|
1022
1084
|
origin_total: (0, import_utils2.getProductOriginTotalPrice)({
|
|
1023
1085
|
product: {
|
|
1024
1086
|
original_price: product.original_price
|
|
1025
1087
|
},
|
|
1026
1088
|
bundle: product.bundle,
|
|
1027
|
-
options: product.options
|
|
1089
|
+
options: restoreOptionPrices(product.options)
|
|
1028
1090
|
}),
|
|
1029
1091
|
variant: originProduct._productInit.variant,
|
|
1030
1092
|
original_price: new import_decimal.default(product.price || 0).toNumber(),
|
|
1031
|
-
total
|
|
1093
|
+
total,
|
|
1094
|
+
options: discountedOptions
|
|
1032
1095
|
})
|
|
1033
1096
|
);
|
|
1034
1097
|
} else {
|
|
@@ -1040,7 +1103,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1040
1103
|
quantity: isNeedSplit ? 1 : product.quantity,
|
|
1041
1104
|
total,
|
|
1042
1105
|
origin_total: productOriginTotal,
|
|
1043
|
-
main_product_selling_price:
|
|
1106
|
+
main_product_selling_price: mainProductSellingPrice,
|
|
1107
|
+
options: discountedOptions
|
|
1044
1108
|
})
|
|
1045
1109
|
);
|
|
1046
1110
|
}
|
|
@@ -1075,8 +1139,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1075
1139
|
amount: bundleDiscountAmount,
|
|
1076
1140
|
type: bundleDiscountType,
|
|
1077
1141
|
discount: {
|
|
1078
|
-
discount_card_type: (
|
|
1079
|
-
discount_calculation_mode: (
|
|
1142
|
+
discount_card_type: (_D = currentBundleDiscount == null ? void 0 : currentBundleDiscount.metadata) == null ? void 0 : _D.discount_card_type,
|
|
1143
|
+
discount_calculation_mode: (_E = currentBundleDiscount == null ? void 0 : currentBundleDiscount.metadata) == null ? void 0 : _E.discount_calculation_mode,
|
|
1080
1144
|
fixed_amount: bundleDiscountAmount,
|
|
1081
1145
|
resource_id: currentBundleDiscount.id,
|
|
1082
1146
|
title: currentBundleDiscount.format_title,
|
|
@@ -1184,7 +1248,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1184
1248
|
const nextDiscType = nextSelectedDiscount.tag || nextSelectedDiscount.type;
|
|
1185
1249
|
const nextIsGoodPass = nextDiscType === "good_pass";
|
|
1186
1250
|
const nextIsDiscountCard = ["discount_card", "product_discount_card"].includes(nextDiscType);
|
|
1187
|
-
const nextApplicableProductLimit = ((
|
|
1251
|
+
const nextApplicableProductLimit = ((_F = nextSelectedDiscount.config) == null ? void 0 : _F.applicableProductLimit) || 0;
|
|
1188
1252
|
const nextIsNeedSplit = nextIsGoodPass || nextIsDiscountCard && nextApplicableProductLimit > 0;
|
|
1189
1253
|
if (!nextIsNeedSplit) {
|
|
1190
1254
|
const nextBundleDiscount = nextSelectedDiscountCard || nextApplicableDiscounts[0];
|
|
@@ -1207,7 +1271,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1207
1271
|
amount: nextDiscountAmount * remainingNum,
|
|
1208
1272
|
type: nextBundleDiscType,
|
|
1209
1273
|
discount: {
|
|
1210
|
-
discount_card_type: (
|
|
1274
|
+
discount_card_type: (_G = nextBundleDiscount == null ? void 0 : nextBundleDiscount.metadata) == null ? void 0 : _G.discount_card_type,
|
|
1211
1275
|
fixed_amount: nextDiscountAmount,
|
|
1212
1276
|
resource_id: nextBundleDiscount.id,
|
|
1213
1277
|
title: nextBundleDiscount.format_title,
|
|
@@ -1221,7 +1285,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1221
1285
|
num: remainingNum
|
|
1222
1286
|
},
|
|
1223
1287
|
config: nextBundleDiscount == null ? void 0 : nextBundleDiscount.config,
|
|
1224
|
-
_num: remainingNum * (((
|
|
1288
|
+
_num: remainingNum * (((_H = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _H.num) || 1)
|
|
1225
1289
|
};
|
|
1226
1290
|
const nextAppliedProducts = appliedDiscountProducts.get(nextBundleDiscount.id) || [];
|
|
1227
1291
|
nextAppliedProducts.push(nextDiscountDetail);
|
|
@@ -1245,7 +1309,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1245
1309
|
(item) => (item.tag || item.type) === "good_pass"
|
|
1246
1310
|
).length;
|
|
1247
1311
|
nextMaxUsageLimit = nextGoodPassCount;
|
|
1248
|
-
if ((
|
|
1312
|
+
if ((_I = nextSelectedDiscount.config) == null ? void 0 : _I.maxUsagePerOrder) {
|
|
1249
1313
|
const usedCount = usedProductIdCounts.get(nextSelectedDiscount.product_id) || 0;
|
|
1250
1314
|
nextMaxUsageLimit = Math.min(
|
|
1251
1315
|
nextGoodPassCount,
|
|
@@ -1294,7 +1358,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1294
1358
|
amount: nextBundleDiscAmount,
|
|
1295
1359
|
type: nextBundleDiscTypeStr,
|
|
1296
1360
|
discount: {
|
|
1297
|
-
discount_card_type: (
|
|
1361
|
+
discount_card_type: (_J = nextBundleDiscount == null ? void 0 : nextBundleDiscount.metadata) == null ? void 0 : _J.discount_card_type,
|
|
1298
1362
|
fixed_amount: nextBundleDiscAmount,
|
|
1299
1363
|
resource_id: nextBundleDiscount.id,
|
|
1300
1364
|
title: nextBundleDiscount.format_title,
|
|
@@ -1366,9 +1430,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1366
1430
|
amount: bundleActualDiscountAmount * (product.num || 1),
|
|
1367
1431
|
type: currentBundleDiscount.tag === "product_discount_card" ? "discount_card" : currentBundleDiscount.tag,
|
|
1368
1432
|
discount: {
|
|
1369
|
-
discount_card_type: (
|
|
1433
|
+
discount_card_type: (_K = currentBundleDiscount == null ? void 0 : currentBundleDiscount.metadata) == null ? void 0 : _K.discount_card_type,
|
|
1370
1434
|
fixed_amount: bundleActualDiscountAmount,
|
|
1371
|
-
discount_calculation_mode: (
|
|
1435
|
+
discount_calculation_mode: (_L = currentBundleDiscount == null ? void 0 : currentBundleDiscount.metadata) == null ? void 0 : _L.discount_calculation_mode,
|
|
1372
1436
|
resource_id: currentBundleDiscount.id,
|
|
1373
1437
|
title: currentBundleDiscount.format_title,
|
|
1374
1438
|
original_amount: product.original_price,
|
|
@@ -1385,7 +1449,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1385
1449
|
...productDiscountDifference !== void 0 && { product_discount_difference: productDiscountDifference }
|
|
1386
1450
|
},
|
|
1387
1451
|
config: currentBundleDiscount == null ? void 0 : currentBundleDiscount.config,
|
|
1388
|
-
_num: (product.num || 1) * (((
|
|
1452
|
+
_num: (product.num || 1) * (((_M = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _M.num) || 1)
|
|
1389
1453
|
};
|
|
1390
1454
|
const appliedProducts = appliedDiscountProducts.get(currentBundleDiscount.id) || [];
|
|
1391
1455
|
appliedProducts.push(discountDetail);
|
|
@@ -1408,6 +1472,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1408
1472
|
const mainProductArr = processedProductsMap2.get(product._id);
|
|
1409
1473
|
if (!mainProductArr || mainProductArr.length === 0) {
|
|
1410
1474
|
const getDefaultProduct = () => {
|
|
1475
|
+
const restoredOptions = restoreOptionPrices(product.options);
|
|
1411
1476
|
if (product.isClient) {
|
|
1412
1477
|
return this.hooks.setProduct(originProduct, {
|
|
1413
1478
|
discount_list: this.filterDiscountListByType(product.discount_list, "promotion"),
|
|
@@ -1417,7 +1482,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1417
1482
|
original_price: product.original_price
|
|
1418
1483
|
},
|
|
1419
1484
|
bundle: product.bundle,
|
|
1420
|
-
options:
|
|
1485
|
+
options: restoredOptions
|
|
1421
1486
|
}),
|
|
1422
1487
|
variant: originProduct._productInit.variant,
|
|
1423
1488
|
original_price: originProduct._productInit.original_price,
|
|
@@ -1426,15 +1491,17 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
1426
1491
|
price: product.price
|
|
1427
1492
|
},
|
|
1428
1493
|
bundle: product.bundle,
|
|
1429
|
-
options:
|
|
1430
|
-
})
|
|
1494
|
+
options: restoredOptions
|
|
1495
|
+
}),
|
|
1496
|
+
options: restoredOptions
|
|
1431
1497
|
});
|
|
1432
1498
|
} else {
|
|
1433
1499
|
return this.hooks.setProduct(originProduct, {
|
|
1434
1500
|
discount_list: this.filterDiscountListByType(product.discount_list, "promotion"),
|
|
1435
1501
|
total: product.total,
|
|
1436
1502
|
origin_total: product.origin_total,
|
|
1437
|
-
price: product.price
|
|
1503
|
+
price: product.price,
|
|
1504
|
+
options: restoreOptionPrices(product.options)
|
|
1438
1505
|
});
|
|
1439
1506
|
}
|
|
1440
1507
|
};
|
|
@@ -131,7 +131,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
|
|
|
131
131
|
* 获取当前的客户搜索条件
|
|
132
132
|
* @returns 当前搜索条件
|
|
133
133
|
*/
|
|
134
|
-
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "
|
|
134
|
+
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
|
|
135
135
|
/**
|
|
136
136
|
* 获取客户列表状态(包含滚动加载相关状态)
|
|
137
137
|
* @returns 客户状态
|
|
@@ -58,7 +58,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
58
58
|
private bestDiscount;
|
|
59
59
|
loadPrepareConfig(params: {
|
|
60
60
|
customerId: number;
|
|
61
|
-
action?: 'create' | '
|
|
61
|
+
action?: 'create' | 'edit';
|
|
62
62
|
with_good_pass?: 0 | 1;
|
|
63
63
|
with_discount_card?: 0 | 1;
|
|
64
64
|
}): Promise<void>;
|
|
@@ -527,7 +527,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
527
527
|
const customerId = params.customerId || ((_a = this.getCustomer()) == null ? void 0 : _a.id);
|
|
528
528
|
const goodPassList = await ((_b = this.store.discount) == null ? void 0 : _b.loadPrepareConfig({
|
|
529
529
|
customer_id: customerId,
|
|
530
|
-
action: orderId ? "
|
|
530
|
+
action: orderId ? "edit" : "create",
|
|
531
531
|
with_good_pass: 1,
|
|
532
532
|
with_discount_card: 1,
|
|
533
533
|
with_wallet_pass_holder: 1,
|