@pisell/pisellos 2.2.198 → 2.2.199
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/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +7 -3
- package/dist/modules/Cart/utils/cartProduct.js +11 -1
- package/dist/modules/Cart/utils/changePrice.js +11 -11
- package/dist/modules/Order/index.js +155 -104
- package/dist/modules/Order/types.d.ts +1 -0
- package/dist/modules/Order/utils.d.ts +33 -2
- package/dist/modules/Order/utils.js +112 -55
- package/dist/modules/SalesSummary/utils.js +97 -63
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.js +294 -190
- package/dist/server/modules/order/index.d.ts +8 -0
- package/dist/server/modules/order/index.js +536 -317
- package/dist/server/modules/order/types.d.ts +2 -0
- package/dist/solution/BaseSales/index.js +2 -1
- package/dist/solution/BaseSales/types.d.ts +1 -0
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +19 -4
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/ScanOrder/types.d.ts +1 -0
- package/dist/solution/ScanOrder/utils.js +26 -9
- package/dist/solution/VenueBooking/index.js +2 -1
- package/lib/model/strategy/adapter/promotion/index.js +49 -0
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +4 -1
- package/lib/modules/Cart/utils/cartProduct.js +11 -1
- package/lib/modules/Cart/utils/changePrice.js +12 -20
- package/lib/modules/Order/index.js +58 -6
- package/lib/modules/Order/types.d.ts +1 -0
- package/lib/modules/Order/utils.d.ts +33 -2
- package/lib/modules/Order/utils.js +44 -9
- package/lib/modules/SalesSummary/utils.js +41 -44
- package/lib/server/index.d.ts +3 -0
- package/lib/server/index.js +82 -3
- package/lib/server/modules/order/index.d.ts +8 -0
- package/lib/server/modules/order/index.js +106 -4
- package/lib/server/modules/order/types.d.ts +2 -0
- package/lib/solution/BaseSales/index.js +2 -1
- package/lib/solution/BaseSales/types.d.ts +1 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +15 -1
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/ScanOrder/types.d.ts +1 -0
- package/lib/solution/ScanOrder/utils.js +28 -10
- package/lib/solution/VenueBooking/index.js +2 -1
- package/package.json +1 -1
|
@@ -43,13 +43,15 @@ export function composeLinePrice(params) {
|
|
|
43
43
|
_step;
|
|
44
44
|
try {
|
|
45
45
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
46
|
-
var _ref, _item$
|
|
46
|
+
var _ref, _item$num;
|
|
47
47
|
var item = _step.value;
|
|
48
|
-
|
|
49
|
-
var
|
|
50
|
-
|
|
48
|
+
// markdown(减价)按带符号净额取减;markup/原价维持相加。
|
|
49
|
+
var signedUnit = getBundleSignedUnit(item, {
|
|
50
|
+
useOriginal: useOriginalBundle
|
|
51
|
+
});
|
|
52
|
+
var rawNum = (_ref = (_item$num = item === null || item === void 0 ? void 0 : item.num) !== null && _item$num !== void 0 ? _item$num : item === null || item === void 0 ? void 0 : item.quantity) !== null && _ref !== void 0 ? _ref : 1;
|
|
51
53
|
var num = new Decimal(Number(rawNum) || 0);
|
|
52
|
-
total = total.plus(
|
|
54
|
+
total = total.plus(signedUnit.times(num));
|
|
53
55
|
}
|
|
54
56
|
} catch (err) {
|
|
55
57
|
_iterator.e(err);
|
|
@@ -106,6 +108,55 @@ export function sumOptionUnitPrice(options) {
|
|
|
106
108
|
return total;
|
|
107
109
|
}
|
|
108
110
|
|
|
111
|
+
/**
|
|
112
|
+
* 判定套餐子商品是否为 markdown(减价)类型。
|
|
113
|
+
* 与后端口径一致:price_type='markdown' 且 price_type_ext 非 'product_price'(原价子商品)。
|
|
114
|
+
*/
|
|
115
|
+
export function isMarkdownBundle(bundle) {
|
|
116
|
+
var _bundle$price_type_ex, _bundle$price_type;
|
|
117
|
+
if (!bundle || _typeof(bundle) !== 'object') return false;
|
|
118
|
+
var ext = (_bundle$price_type_ex = bundle.price_type_ext) !== null && _bundle$price_type_ex !== void 0 ? _bundle$price_type_ex : bundle.custom_price_type_ext;
|
|
119
|
+
var type = (_bundle$price_type = bundle.price_type) !== null && _bundle$price_type !== void 0 ? _bundle$price_type : bundle.custom_price_type;
|
|
120
|
+
return type === 'markdown' && ext !== 'product_price';
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* 套餐子商品对「行价」的带符号单位贡献(与后端 markdown 口径对齐)。
|
|
125
|
+
*
|
|
126
|
+
* - markdown(减价):净额 = |catalog 毛价| − Σ(option.add_price×num),**取负**(行内减)。
|
|
127
|
+
* catalog 毛价优先 `price`/`custom_price`(避免读已落净额的 `bundle_selling_price` 造成 option 二次扣减);
|
|
128
|
+
* 仅当毛价缺失(历史/hydrate 仅剩净额)时退回 `bundle_selling_price`,且此时不再扣 option。
|
|
129
|
+
* - markup(加价)/原价子商品:维持 `+(bundle_selling_price ?? price)`,行为不变。
|
|
130
|
+
*/
|
|
131
|
+
export function getBundleSignedUnit(bundle, options) {
|
|
132
|
+
var _options$useOriginal, _ref8, _bundle$original_pric2, _bundle$bundle_sellin;
|
|
133
|
+
if (!bundle || _typeof(bundle) !== 'object') return new Decimal(0);
|
|
134
|
+
var useOriginal = (_options$useOriginal = options === null || options === void 0 ? void 0 : options.useOriginal) !== null && _options$useOriginal !== void 0 ? _options$useOriginal : false;
|
|
135
|
+
if (isMarkdownBundle(bundle)) {
|
|
136
|
+
var _ref2, _ref3, _ref4, _bundle$original_pric, _ref5, _ref6, _ref7, _bundle$custom_price;
|
|
137
|
+
var catalog = useOriginal ? (_ref2 = (_ref3 = (_ref4 = (_bundle$original_pric = bundle.original_price) !== null && _bundle$original_pric !== void 0 ? _bundle$original_pric : bundle.product_price) !== null && _ref4 !== void 0 ? _ref4 : bundle.custom_price) !== null && _ref3 !== void 0 ? _ref3 : bundle.base_price) !== null && _ref2 !== void 0 ? _ref2 : bundle.price : (_ref5 = (_ref6 = (_ref7 = (_bundle$custom_price = bundle.custom_price) !== null && _bundle$custom_price !== void 0 ? _bundle$custom_price : bundle.product_price) !== null && _ref7 !== void 0 ? _ref7 : bundle.original_price) !== null && _ref6 !== void 0 ? _ref6 : bundle.base_price) !== null && _ref5 !== void 0 ? _ref5 : bundle.price;
|
|
138
|
+
if (catalog !== undefined && catalog !== null && catalog !== '') {
|
|
139
|
+
var raw = new Decimal(Number(catalog) || 0);
|
|
140
|
+
// 负值表示价格已是「带符号净额」(如 cart/changePrice 产出的 -3.7),直接取用不再扣 option,
|
|
141
|
+
// 避免与下游 option 二次扣减;正值为毛价(H5 路径,如 5),净额 = price − Σoptions 后取负。
|
|
142
|
+
if (raw.lt(0)) return raw;
|
|
143
|
+
return raw.minus(sumOptionUnitPrice(bundle.option)).negated();
|
|
144
|
+
}
|
|
145
|
+
// 仅剩净额(无毛价)兜底:直接取负,不再扣 option
|
|
146
|
+
return new Decimal(Number(bundle.bundle_selling_price) || 0).abs().negated();
|
|
147
|
+
}
|
|
148
|
+
var rawPrice = useOriginal ? (_ref8 = (_bundle$original_pric2 = bundle.original_price) !== null && _bundle$original_pric2 !== void 0 ? _bundle$original_pric2 : bundle.product_price) !== null && _ref8 !== void 0 ? _ref8 : bundle.price : (_bundle$bundle_sellin = bundle.bundle_selling_price) !== null && _bundle$bundle_sellin !== void 0 ? _bundle$bundle_sellin : bundle.price;
|
|
149
|
+
return new Decimal(Number(rawPrice) || 0);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* 套餐子商品 `bundle_selling_price` 的存储净额(正值幅度)。
|
|
154
|
+
* markdown 取净额绝对值(3.70);markup/原价维持原值。
|
|
155
|
+
*/
|
|
156
|
+
export function getBundleSellingMagnitude(bundle) {
|
|
157
|
+
return getBundleSignedUnit(bundle).abs();
|
|
158
|
+
}
|
|
159
|
+
|
|
109
160
|
/**
|
|
110
161
|
* OrderModule 默认 Rules 钩子工厂。
|
|
111
162
|
*
|
|
@@ -118,7 +169,7 @@ export function sumOptionUnitPrice(options) {
|
|
|
118
169
|
* 不含折扣。**权威源**。
|
|
119
170
|
* - `metadata.main_product_original_price` = source + Σ(option.price × option.num)(含 option、不含折扣)。
|
|
120
171
|
* - `metadata.main_product_selling_price` = main_original − 主商品券 per-unit amount(含 option、含折扣)。
|
|
121
|
-
* - `payment_price`:出站 payload
|
|
172
|
+
* - `payment_price`:出站 payload 中为行 composite 已减整单折扣均摊价(无折扣时与 `selling_price` 同义)。
|
|
122
173
|
*
|
|
123
174
|
* Rules 钩子契约(hook_adapt 方案,Rules 内部保持不变):
|
|
124
175
|
* - `getProduct.price` / `getProduct.original_price` 回传 **source-level 主价**
|
|
@@ -263,8 +314,8 @@ export function createDefaultOrderRulesHooks() {
|
|
|
263
314
|
return new Decimal(Number(totalLike) || 0).dividedBy(effectiveNum).toDecimalPlaces(2).toString();
|
|
264
315
|
};
|
|
265
316
|
var getBundleIdentity = function getBundleIdentity(bundle) {
|
|
266
|
-
var
|
|
267
|
-
return [(
|
|
317
|
+
var _ref9, _bundle$bundle_id, _ref10, _ref11, _bundle$bundle_produc, _ref12, _ref13, _bundle$bundle_varian, _ref14, _bundle$bundle_group_;
|
|
318
|
+
return [(_ref9 = (_bundle$bundle_id = bundle.bundle_id) !== null && _bundle$bundle_id !== void 0 ? _bundle$bundle_id : bundle.id) !== null && _ref9 !== void 0 ? _ref9 : '', (_ref10 = (_ref11 = (_bundle$bundle_produc = bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle._bundle_product_id) !== null && _ref11 !== void 0 ? _ref11 : bundle.product_id) !== null && _ref10 !== void 0 ? _ref10 : '', (_ref12 = (_ref13 = (_bundle$bundle_varian = bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle.variant_id) !== null && _ref13 !== void 0 ? _ref13 : bundle.product_variant_id) !== null && _ref12 !== void 0 ? _ref12 : 0, (_ref14 = (_bundle$bundle_group_ = bundle.bundle_group_id) !== null && _bundle$bundle_group_ !== void 0 ? _bundle$bundle_group_ : bundle.group_id) !== null && _ref14 !== void 0 ? _ref14 : ''].join('|');
|
|
268
319
|
};
|
|
269
320
|
var mergeRulesBundlePrices = function mergeRulesBundlePrices(currentBundle, rulesBundle) {
|
|
270
321
|
if (!Array.isArray(rulesBundle)) return rulesBundle;
|
|
@@ -274,14 +325,14 @@ export function createDefaultOrderRulesHooks() {
|
|
|
274
325
|
currentByIdentity.set(getBundleIdentity(bundle), bundle);
|
|
275
326
|
});
|
|
276
327
|
return rulesBundle.map(function (bundle) {
|
|
277
|
-
var _bundle$
|
|
328
|
+
var _bundle$price_type_ex2, _ref15, _ref16, _current$price, _ref17, _ref18, _ref19, _current$original_pri;
|
|
278
329
|
if (!bundle || _typeof(bundle) !== 'object') return bundle;
|
|
279
330
|
var current = currentByIdentity.get(getBundleIdentity(bundle));
|
|
280
331
|
if (!current) return bundle;
|
|
281
|
-
var isProductPriceBundle = ((_bundle$
|
|
332
|
+
var isProductPriceBundle = ((_bundle$price_type_ex2 = bundle.price_type_ext) !== null && _bundle$price_type_ex2 !== void 0 ? _bundle$price_type_ex2 : current.price_type_ext) === 'product_price';
|
|
282
333
|
if (!isProductPriceBundle) return bundle;
|
|
283
|
-
var sourcePrice = (
|
|
284
|
-
var originalPrice = (
|
|
334
|
+
var sourcePrice = (_ref15 = (_ref16 = (_current$price = current.price) !== null && _current$price !== void 0 ? _current$price : current.custom_price) !== null && _ref16 !== void 0 ? _ref16 : current.original_price) !== null && _ref15 !== void 0 ? _ref15 : current.bundle_selling_price;
|
|
335
|
+
var originalPrice = (_ref17 = (_ref18 = (_ref19 = (_current$original_pri = current.original_price) !== null && _current$original_pri !== void 0 ? _current$original_pri : current.product_price) !== null && _ref19 !== void 0 ? _ref19 : current.price) !== null && _ref18 !== void 0 ? _ref18 : current.custom_price) !== null && _ref17 !== void 0 ? _ref17 : sourcePrice;
|
|
285
336
|
return _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, bundle), sourcePrice !== undefined ? {
|
|
286
337
|
price: sourcePrice
|
|
287
338
|
} : {}), originalPrice !== undefined ? {
|
|
@@ -345,10 +396,10 @@ export function createDefaultOrderRulesHooks() {
|
|
|
345
396
|
};
|
|
346
397
|
},
|
|
347
398
|
setProduct: function setProduct(product, values) {
|
|
348
|
-
var
|
|
349
|
-
var nextNum = Number((
|
|
399
|
+
var _ref20, _values$quantity, _ref21, _metadataAny$source_p, _values$discount_list, _values$quantity2;
|
|
400
|
+
var nextNum = Number((_ref20 = (_values$quantity = values.quantity) !== null && _values$quantity !== void 0 ? _values$quantity : product.num) !== null && _ref20 !== void 0 ? _ref20 : 1) || 1;
|
|
350
401
|
var metadataAny = product.metadata || {};
|
|
351
|
-
var existedSource = (
|
|
402
|
+
var existedSource = (_ref21 = (_metadataAny$source_p = metadataAny.source_product_price) !== null && _metadataAny$source_p !== void 0 ? _metadataAny$source_p : product.selling_price) !== null && _ref21 !== void 0 ? _ref21 : '0';
|
|
352
403
|
var nextOptions = getProductSkuOptions(product);
|
|
353
404
|
var optionSum = sumOptionUnitPrice(nextOptions);
|
|
354
405
|
|
|
@@ -521,11 +572,16 @@ function toMoneyString(value) {
|
|
|
521
572
|
function formatSubmitBundleItems(bundle) {
|
|
522
573
|
if (!Array.isArray(bundle)) return [];
|
|
523
574
|
return bundle.map(function (b) {
|
|
524
|
-
var
|
|
575
|
+
var _ref22, _rawBundle$price, _rawBundle$surcharge_, _rawBundle$num, _rawBundle$is_charge_, _rawBundle$bundle_var, _rawBundle$quantity, _rawBundle$extension_, _rawBundle$extension_2, _ref23, _rawBundle$price_type, _ref24, _rawBundle$price_type2, _rawBundle$bundle_gro, _rawBundle$bundle_id, _rawBundle$bundle_pro;
|
|
525
576
|
var rawBundle = b && _typeof(b) === 'object' ? b : {};
|
|
526
577
|
var existedMetadata = rawBundle.metadata && _typeof(rawBundle.metadata) === 'object' ? rawBundle.metadata : {};
|
|
527
|
-
|
|
528
|
-
|
|
578
|
+
|
|
579
|
+
// bundle_selling_price 出站存「正净额」:markdown 为 |price| − Σoptions(如 3.70),
|
|
580
|
+
// markup/原价维持原值;与后端口径一致(price 仍为毛价)。
|
|
581
|
+
var sellingPrice = getBundleSellingMagnitude(rawBundle).toFixed(2);
|
|
582
|
+
// payment 价由整单折扣均摊层产出;缺省(无折扣)时与 selling 净额同义。
|
|
583
|
+
var paymentPrice = rawBundle.bundle_payment_price !== undefined && rawBundle.bundle_payment_price !== null && rawBundle.bundle_payment_price !== '' ? toMoneyString(rawBundle.bundle_payment_price) : sellingPrice;
|
|
584
|
+
var priceValue = (_ref22 = (_rawBundle$price = rawBundle.price) !== null && _rawBundle$price !== void 0 ? _rawBundle$price : rawBundle.custom_price) !== null && _ref22 !== void 0 ? _ref22 : rawBundle.bundle_selling_price;
|
|
529
585
|
var relationSurchargeIds = Array.isArray(rawBundle.relation_surcharge_ids) ? rawBundle.relation_surcharge_ids : Array.isArray(existedMetadata.relation_surcharge_ids) ? existedMetadata.relation_surcharge_ids : [];
|
|
530
586
|
var surchargeFee = toMoneyString((_rawBundle$surcharge_ = rawBundle.surcharge_fee) !== null && _rawBundle$surcharge_ !== void 0 ? _rawBundle$surcharge_ : existedMetadata.surcharge_fee);
|
|
531
587
|
var productDiscountDifference = toBundleNumber(existedMetadata.product_discount_difference, 0);
|
|
@@ -538,9 +594,10 @@ function formatSubmitBundleItems(bundle) {
|
|
|
538
594
|
extension_id: (_rawBundle$extension_ = rawBundle.extension_id) !== null && _rawBundle$extension_ !== void 0 ? _rawBundle$extension_ : 0,
|
|
539
595
|
extension_type: (_rawBundle$extension_2 = rawBundle.extension_type) !== null && _rawBundle$extension_2 !== void 0 ? _rawBundle$extension_2 : 'normal',
|
|
540
596
|
price: priceValue,
|
|
541
|
-
price_type: (
|
|
542
|
-
price_type_ext: (
|
|
597
|
+
price_type: (_ref23 = (_rawBundle$price_type = rawBundle.price_type) !== null && _rawBundle$price_type !== void 0 ? _rawBundle$price_type : rawBundle.custom_price_type) !== null && _ref23 !== void 0 ? _ref23 : '',
|
|
598
|
+
price_type_ext: (_ref24 = (_rawBundle$price_type2 = rawBundle.price_type_ext) !== null && _rawBundle$price_type2 !== void 0 ? _rawBundle$price_type2 : rawBundle.custom_price_type_ext) !== null && _ref24 !== void 0 ? _ref24 : '',
|
|
543
599
|
bundle_selling_price: sellingPrice,
|
|
600
|
+
bundle_payment_price: paymentPrice,
|
|
544
601
|
option: formatSubmitOptionItems(rawBundle.option),
|
|
545
602
|
bundle_group_id: (_rawBundle$bundle_gro = rawBundle === null || rawBundle === void 0 ? void 0 : rawBundle.bundle_group_id) !== null && _rawBundle$bundle_gro !== void 0 ? _rawBundle$bundle_gro : rawBundle === null || rawBundle === void 0 ? void 0 : rawBundle.group_id,
|
|
546
603
|
bundle_id: (_rawBundle$bundle_id = rawBundle === null || rawBundle === void 0 ? void 0 : rawBundle.bundle_id) !== null && _rawBundle$bundle_id !== void 0 ? _rawBundle$bundle_id : rawBundle === null || rawBundle === void 0 ? void 0 : rawBundle.id,
|
|
@@ -562,7 +619,7 @@ function formatSubmitBundleItems(bundle) {
|
|
|
562
619
|
* = `metadata.main_product_selling_price` + Σ(bundle_selling_price × num)。
|
|
563
620
|
* - `original_price`:**行 composite 券前单价**
|
|
564
621
|
* = `metadata.main_product_original_price` + Σ(bundle 原价 × num)。
|
|
565
|
-
* - `payment_price
|
|
622
|
+
* - `payment_price`:兼容后端的出站字段,行 composite 已减整单折扣均摊(无折扣时与 `selling_price` 同义)。
|
|
566
623
|
* - `metadata.source_product_price`:主商品/variant 基础价(不含 option、不含折扣),权威源。
|
|
567
624
|
* - `metadata.main_product_original_price`:含 option、不含折扣。
|
|
568
625
|
* - `metadata.main_product_selling_price`:含 option、含主商品折扣。
|
|
@@ -571,10 +628,10 @@ function formatSubmitBundleItems(bundle) {
|
|
|
571
628
|
* 本函数不再改造价格字段形状,仅做字段/metadata 裁剪。
|
|
572
629
|
*/
|
|
573
630
|
function normalizeSubmitProduct(product) {
|
|
574
|
-
var _rawMetadata$product_, _submitProduct$produc;
|
|
575
|
-
var
|
|
576
|
-
_runtimeUid =
|
|
577
|
-
submitProduct = _objectWithoutProperties(
|
|
631
|
+
var _rawMetadata$product_, _submitProduct$produc, _submitProduct$paymen;
|
|
632
|
+
var _ref25 = product,
|
|
633
|
+
_runtimeUid = _ref25.unique_identification_number,
|
|
634
|
+
submitProduct = _objectWithoutProperties(_ref25, _excluded);
|
|
578
635
|
var num = submitProduct.num,
|
|
579
636
|
_productSurchargeFee = submitProduct.surcharge_fee,
|
|
580
637
|
_deprecatedDiscountAmount = submitProduct.discount_amount,
|
|
@@ -590,7 +647,7 @@ function normalizeSubmitProduct(product) {
|
|
|
590
647
|
if (rawMetadata.unique_identification_number) {
|
|
591
648
|
cleanMetadata.unique_identification_number = rawMetadata.unique_identification_number;
|
|
592
649
|
}
|
|
593
|
-
var priceMetaKeys = ['main_product_original_price', 'main_product_selling_price', 'source_product_price', 'main_product_attached_bundle_surcharge_fee', 'main_product_attached_bundle_tax_fee', 'surcharge_rounding_remainder', 'tax_fee_rounding_remainder', 'relation_surcharge_ids', 'discountable_flag', 'parent_unique_identification_number', 'product_add_schedule_time'];
|
|
650
|
+
var priceMetaKeys = ['main_product_original_price', 'main_product_selling_price', 'main_product_attached_bundle_selling_price', 'main_product_attached_bundle_payment_price', 'average_discount_amount_rate', 'source_product_price', 'main_product_attached_bundle_surcharge_fee', 'main_product_attached_bundle_tax_fee', 'surcharge_rounding_remainder', 'tax_fee_rounding_remainder', 'relation_surcharge_ids', 'discountable_flag', 'parent_unique_identification_number', 'product_add_schedule_time'];
|
|
594
651
|
for (var _i = 0, _priceMetaKeys = priceMetaKeys; _i < _priceMetaKeys.length; _i++) {
|
|
595
652
|
var key = _priceMetaKeys[_i];
|
|
596
653
|
if (rawMetadata[key] !== undefined) {
|
|
@@ -615,9 +672,9 @@ function normalizeSubmitProduct(product) {
|
|
|
615
672
|
discount_list: normalizeOrderProductDiscountList(submitProduct.discount_list),
|
|
616
673
|
product_bundle: formatSubmitBundleItems(submitProduct.product_bundle),
|
|
617
674
|
metadata: cleanMetadata,
|
|
618
|
-
// 出站兼容:后端消费 payment_price
|
|
619
|
-
//
|
|
620
|
-
payment_price: submitProduct.selling_price
|
|
675
|
+
// 出站兼容:后端消费 payment_price 字段(行 composite 已减整单折扣均摊)。
|
|
676
|
+
// 由整单折扣均摊层产出;缺省(无折扣)时与 selling_price 同义。
|
|
677
|
+
payment_price: (_submitProduct$paymen = submitProduct.payment_price) !== null && _submitProduct$paymen !== void 0 ? _submitProduct$paymen : submitProduct.selling_price
|
|
621
678
|
});
|
|
622
679
|
}
|
|
623
680
|
var SUBMIT_BOOKING_METADATA_WHITELIST = ['unique_identification_number', 'collect_pax', 'capacity', 'holder_id', 'resource_select_type'];
|
|
@@ -738,7 +795,7 @@ export function createDefaultTempOrder(params) {
|
|
|
738
795
|
};
|
|
739
796
|
}
|
|
740
797
|
export function buildSubmitPayload(params) {
|
|
741
|
-
var _tempOrder$customer_i,
|
|
798
|
+
var _tempOrder$customer_i, _ref27, _tempOrder$is_price_i, _tempOrder$is_deposit;
|
|
742
799
|
var tempOrder = params.tempOrder,
|
|
743
800
|
cacheId = params.cacheId,
|
|
744
801
|
_params$now = params.now,
|
|
@@ -750,26 +807,26 @@ export function buildSubmitPayload(params) {
|
|
|
750
807
|
enhance = params.enhance;
|
|
751
808
|
var scheduleDate = tempOrder.schedule_date || tempOrder.created_at || formatDateTime(now);
|
|
752
809
|
var bookingUuid = createUuidV4();
|
|
753
|
-
var
|
|
754
|
-
_extend =
|
|
755
|
-
_relationId =
|
|
756
|
-
_tableFormId =
|
|
757
|
-
_resourceId =
|
|
758
|
-
_summary =
|
|
759
|
-
_lastOrderInfo =
|
|
760
|
-
_paidAmount =
|
|
761
|
-
_shopId =
|
|
762
|
-
_shopNote =
|
|
763
|
-
_shopServiceType =
|
|
764
|
-
_startTime =
|
|
765
|
-
_customer =
|
|
766
|
-
_discountList =
|
|
767
|
-
_rootTaxFee =
|
|
768
|
-
_totalAmount =
|
|
769
|
-
_totalRefundAmount =
|
|
770
|
-
_createDate =
|
|
771
|
-
_holderId =
|
|
772
|
-
tempOrderRest = _objectWithoutProperties(
|
|
810
|
+
var _ref26 = tempOrder,
|
|
811
|
+
_extend = _ref26._extend,
|
|
812
|
+
_relationId = _ref26.relation_id,
|
|
813
|
+
_tableFormId = _ref26.table_form_id,
|
|
814
|
+
_resourceId = _ref26.resource_id,
|
|
815
|
+
_summary = _ref26.summary,
|
|
816
|
+
_lastOrderInfo = _ref26.lastOrderInfo,
|
|
817
|
+
_paidAmount = _ref26.paid_amount,
|
|
818
|
+
_shopId = _ref26.shop_id,
|
|
819
|
+
_shopNote = _ref26.shop_note,
|
|
820
|
+
_shopServiceType = _ref26.shop_service_type,
|
|
821
|
+
_startTime = _ref26.start_time,
|
|
822
|
+
_customer = _ref26.customer,
|
|
823
|
+
_discountList = _ref26.discount_list,
|
|
824
|
+
_rootTaxFee = _ref26.tax_fee,
|
|
825
|
+
_totalAmount = _ref26.total_amount,
|
|
826
|
+
_totalRefundAmount = _ref26.total_refund_amount,
|
|
827
|
+
_createDate = _ref26.create_date,
|
|
828
|
+
_holderId = _ref26.holder_id,
|
|
829
|
+
tempOrderRest = _objectWithoutProperties(_ref26, _excluded3);
|
|
773
830
|
var submitType = type !== null && type !== void 0 ? type : tempOrder.type;
|
|
774
831
|
if (!submitType) {
|
|
775
832
|
var _tempOrder$bookings;
|
|
@@ -791,7 +848,7 @@ export function buildSubmitPayload(params) {
|
|
|
791
848
|
type: submitType,
|
|
792
849
|
business_code: businessCode !== null && businessCode !== void 0 ? businessCode : tempOrder.business_code,
|
|
793
850
|
sales_channel: tempOrder.sales_channel || 'my_pisel',
|
|
794
|
-
order_sales_channel: (
|
|
851
|
+
order_sales_channel: (_ref27 = channel !== null && channel !== void 0 ? channel : tempOrder.order_sales_channel) !== null && _ref27 !== void 0 ? _ref27 : 'online_store',
|
|
795
852
|
status: tempOrder.status || 'normal',
|
|
796
853
|
payment_status: tempOrder.payment_status || 'payment_processing',
|
|
797
854
|
// shipping_status: tempOrder.shipping_status || 'unfulfilled',
|
|
@@ -817,10 +874,10 @@ export function buildSubmitPayload(params) {
|
|
|
817
874
|
// holder: tempOrder.holder || null,
|
|
818
875
|
// summary,
|
|
819
876
|
metadata: function () {
|
|
820
|
-
var
|
|
821
|
-
_collectPax =
|
|
822
|
-
_tableOccupancyDuration =
|
|
823
|
-
rest = _objectWithoutProperties(
|
|
877
|
+
var _ref28 = tempOrder.metadata || {},
|
|
878
|
+
_collectPax = _ref28.collect_pax,
|
|
879
|
+
_tableOccupancyDuration = _ref28.table_occupancy_duration,
|
|
880
|
+
rest = _objectWithoutProperties(_ref28, _excluded4);
|
|
824
881
|
return _objectSpread({}, rest);
|
|
825
882
|
}(),
|
|
826
883
|
products: (tempOrder.products || []).map(function (product) {
|
|
@@ -17,7 +17,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
17
17
|
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); }
|
|
18
18
|
import Decimal from 'decimal.js';
|
|
19
19
|
import { getSurcharge, getSurchargeAmount } from "../Summary/utils";
|
|
20
|
-
import { getProductSkuOptions } from "../Order/utils";
|
|
20
|
+
import { getBundleSellingMagnitude, getBundleSignedUnit, getProductSkuOptions, isMarkdownBundle } from "../Order/utils";
|
|
21
21
|
function toDecimal(value) {
|
|
22
22
|
return new Decimal(value || 0);
|
|
23
23
|
}
|
|
@@ -57,10 +57,12 @@ function getBundleUnitPrice(product) {
|
|
|
57
57
|
var useOriginal = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
58
58
|
var bundleItems = product.product_bundle || [];
|
|
59
59
|
return bundleItems.reduce(function (sum, item) {
|
|
60
|
-
var _ref, _item$original_price, _item$bundle_selling_;
|
|
61
60
|
var quantity = getSafeNum(item === null || item === void 0 ? void 0 : item.num);
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
// markdown(减价)按带符号净额取减;markup/原价维持相加。
|
|
62
|
+
var signedUnit = getBundleSignedUnit(item, {
|
|
63
|
+
useOriginal: useOriginal
|
|
64
|
+
});
|
|
65
|
+
return sum.plus(signedUnit.times(quantity));
|
|
64
66
|
}, new Decimal(0));
|
|
65
67
|
}
|
|
66
68
|
|
|
@@ -151,26 +153,26 @@ function getSurchargeConfigById(surchargeList) {
|
|
|
151
153
|
return map;
|
|
152
154
|
}
|
|
153
155
|
function getMainSurchargeUnitAmount(product) {
|
|
154
|
-
var
|
|
156
|
+
var _ref, _ref2, _record$metadata$main, _record$metadata, _record$metadata2;
|
|
155
157
|
var record = product;
|
|
156
|
-
return toDecimal((
|
|
158
|
+
return toDecimal((_ref = (_ref2 = (_record$metadata$main = (_record$metadata = record.metadata) === null || _record$metadata === void 0 ? void 0 : _record$metadata.main_product_attached_bundle_selling_price) !== null && _record$metadata$main !== void 0 ? _record$metadata$main : (_record$metadata2 = record.metadata) === null || _record$metadata2 === void 0 ? void 0 : _record$metadata2.main_product_selling_price) !== null && _ref2 !== void 0 ? _ref2 : record.selling_price) !== null && _ref !== void 0 ? _ref : 0);
|
|
157
159
|
}
|
|
158
160
|
function getBundleSurchargeUnitAmount(bundle) {
|
|
159
|
-
var
|
|
160
|
-
return toDecimal((
|
|
161
|
+
var _ref3, _ref4, _bundle$bundle_sellin;
|
|
162
|
+
return toDecimal((_ref3 = (_ref4 = (_bundle$bundle_sellin = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price) !== null && _bundle$bundle_sellin !== void 0 ? _bundle$bundle_sellin : bundle === null || bundle === void 0 ? void 0 : bundle.bundle_sum_price) !== null && _ref4 !== void 0 ? _ref4 : bundle === null || bundle === void 0 ? void 0 : bundle.price) !== null && _ref3 !== void 0 ? _ref3 : 0);
|
|
161
163
|
}
|
|
162
164
|
function getBundleProductId(bundle) {
|
|
163
|
-
var
|
|
164
|
-
var id = (
|
|
165
|
+
var _ref5, _bundle$bundle_produc;
|
|
166
|
+
var id = (_ref5 = (_bundle$bundle_produc = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle === null || bundle === void 0 ? void 0 : bundle._bundle_product_id) !== null && _ref5 !== void 0 ? _ref5 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id;
|
|
165
167
|
if (id === undefined || id === null || id === '') return null;
|
|
166
168
|
var parsed = Number(id);
|
|
167
169
|
if (!Number.isFinite(parsed)) return null;
|
|
168
170
|
return parsed;
|
|
169
171
|
}
|
|
170
172
|
function getPersistedMainSurchargeFee(product) {
|
|
171
|
-
var
|
|
173
|
+
var _ref6, _product$surcharge_fe, _product$metadata7;
|
|
172
174
|
if ((product === null || product === void 0 ? void 0 : product.order_detail_id) === undefined || (product === null || product === void 0 ? void 0 : product.order_detail_id) === null) return null;
|
|
173
|
-
var value = (
|
|
175
|
+
var value = (_ref6 = (_product$surcharge_fe = product === null || product === void 0 ? void 0 : product.surcharge_fee) !== null && _product$surcharge_fe !== void 0 ? _product$surcharge_fe : product === null || product === void 0 ? void 0 : product.main_product_attached_bundle_surcharge_fee) !== null && _ref6 !== void 0 ? _ref6 : product === null || product === void 0 || (_product$metadata7 = product.metadata) === null || _product$metadata7 === void 0 ? void 0 : _product$metadata7.main_product_attached_bundle_surcharge_fee;
|
|
174
176
|
if (value === undefined || value === null || value === '') return null;
|
|
175
177
|
return toDecimal(value);
|
|
176
178
|
}
|
|
@@ -181,8 +183,8 @@ function getPersistedSourceSurchargeFee(sourceItem) {
|
|
|
181
183
|
return toDecimal(value);
|
|
182
184
|
}
|
|
183
185
|
function getPersistedSurchargeRemainder(item, sourceItem) {
|
|
184
|
-
var
|
|
185
|
-
var value = (
|
|
186
|
+
var _ref7, _sourceItem$metadata$, _sourceItem$metadata2, _item$metadata2;
|
|
187
|
+
var value = (_ref7 = (_sourceItem$metadata$ = sourceItem === null || sourceItem === void 0 || (_sourceItem$metadata2 = sourceItem.metadata) === null || _sourceItem$metadata2 === void 0 ? void 0 : _sourceItem$metadata2.surcharge_rounding_remainder) !== null && _sourceItem$metadata$ !== void 0 ? _sourceItem$metadata$ : item === null || item === void 0 ? void 0 : item.surcharge_rounding_remainder) !== null && _ref7 !== void 0 ? _ref7 : item === null || item === void 0 || (_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.surcharge_rounding_remainder;
|
|
186
188
|
if (value === undefined || value === null || value === '') return null;
|
|
187
189
|
return toDecimal(value);
|
|
188
190
|
}
|
|
@@ -683,16 +685,15 @@ function calculateSingleItemTax(params) {
|
|
|
683
685
|
}
|
|
684
686
|
|
|
685
687
|
/**
|
|
686
|
-
*
|
|
688
|
+
* 主商品 + 非原价(加价/减价)子商品的"折扣后"售价合计(含 option、含主商品折扣,未减整单折扣)。
|
|
687
689
|
*
|
|
688
|
-
*
|
|
689
|
-
* - `metadata.main_product_selling_price` 已是"含 option、含折扣"
|
|
690
|
-
* -
|
|
691
|
-
* - 仅需叠加 `markup` / `markdown` 类 bundle(原价 bundle 已由 `calculateProductsTax` 独立处理)。
|
|
690
|
+
* 对齐后端 metadata.main_product_attached_bundle_selling_price:
|
|
691
|
+
* - `metadata.main_product_selling_price` 已是"含 option、含折扣"的主价;
|
|
692
|
+
* - 叠加 `markup` / `markdown` 类 bundle(原价 bundle 由 `calculateProductsTax` 独立处理)。
|
|
692
693
|
*/
|
|
693
|
-
function
|
|
694
|
-
var
|
|
695
|
-
var mainSelling = (
|
|
694
|
+
function getMainAttachedBundleSellingTotal(product) {
|
|
695
|
+
var _ref8, _product$metadata$mai, _product$metadata8, _product$metadata9;
|
|
696
|
+
var mainSelling = (_ref8 = (_product$metadata$mai = (_product$metadata8 = product.metadata) === null || _product$metadata8 === void 0 ? void 0 : _product$metadata8.main_product_selling_price) !== null && _product$metadata$mai !== void 0 ? _product$metadata$mai : (_product$metadata9 = product.metadata) === null || _product$metadata9 === void 0 ? void 0 : _product$metadata9.main_product_original_price) !== null && _ref8 !== void 0 ? _ref8 : 0;
|
|
696
697
|
var total = toDecimal(mainSelling);
|
|
697
698
|
var bundleItems = product.product_bundle || [];
|
|
698
699
|
var _iterator15 = _createForOfIteratorHelper(bundleItems),
|
|
@@ -701,8 +702,9 @@ function getMainProductPaymentTotal(product) {
|
|
|
701
702
|
for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
|
|
702
703
|
var bundleItem = _step15.value;
|
|
703
704
|
if (isBundleMarkupOrDiscount(bundleItem)) {
|
|
704
|
-
var
|
|
705
|
-
|
|
705
|
+
var _bundleItem$num;
|
|
706
|
+
// markdown(减价)按带符号净额取减;markup 维持相加。
|
|
707
|
+
var unit = getBundleSignedUnit(bundleItem);
|
|
706
708
|
var qty = getSafeNum((_bundleItem$num = bundleItem.num) !== null && _bundleItem$num !== void 0 ? _bundleItem$num : bundleItem.quantity);
|
|
707
709
|
total = total.plus(unit.times(qty));
|
|
708
710
|
}
|
|
@@ -714,6 +716,22 @@ function getMainProductPaymentTotal(product) {
|
|
|
714
716
|
}
|
|
715
717
|
return Decimal.max(total, 0);
|
|
716
718
|
}
|
|
719
|
+
|
|
720
|
+
/**
|
|
721
|
+
* 获取主商品税费基数(含 option、含主商品折扣、含加价/减价 bundle、已减整单折扣均摊)。
|
|
722
|
+
*
|
|
723
|
+
* 对齐后端 handleMainProductTaxFee:税基使用 main_product_attached_bundle_payment_price。
|
|
724
|
+
* - 优先读取均摊层写入的 payment 价;
|
|
725
|
+
* - 兜底退化为 selling 合计(无整单折扣时两者相等)。
|
|
726
|
+
*/
|
|
727
|
+
function getMainProductPaymentTotal(product) {
|
|
728
|
+
var _product$metadata10;
|
|
729
|
+
var attachedPayment = (_product$metadata10 = product.metadata) === null || _product$metadata10 === void 0 ? void 0 : _product$metadata10.main_product_attached_bundle_payment_price;
|
|
730
|
+
if (attachedPayment !== undefined && attachedPayment !== null && attachedPayment !== '') {
|
|
731
|
+
return Decimal.max(toDecimal(attachedPayment), 0);
|
|
732
|
+
}
|
|
733
|
+
return getMainAttachedBundleSellingTotal(product);
|
|
734
|
+
}
|
|
717
735
|
function getExplicitTaxRemainder(item) {
|
|
718
736
|
var _item$tax_fee_roundin, _item$metadata3;
|
|
719
737
|
var value = (_item$tax_fee_roundin = item === null || item === void 0 ? void 0 : item.tax_fee_rounding_remainder) !== null && _item$tax_fee_roundin !== void 0 ? _item$tax_fee_roundin : item === null || item === void 0 || (_item$metadata3 = item.metadata) === null || _item$metadata3 === void 0 ? void 0 : _item$metadata3.tax_fee_rounding_remainder;
|
|
@@ -726,9 +744,9 @@ function getPersistedTaxRemainder(item, parentProduct) {
|
|
|
726
744
|
return getExplicitTaxRemainder(item);
|
|
727
745
|
}
|
|
728
746
|
function getPersistedMainTaxFee(product) {
|
|
729
|
-
var
|
|
747
|
+
var _ref9, _product$metadata$mai2, _product$metadata11;
|
|
730
748
|
if ((product === null || product === void 0 ? void 0 : product.order_detail_id) === undefined || (product === null || product === void 0 ? void 0 : product.order_detail_id) === null) return null;
|
|
731
|
-
var value = (
|
|
749
|
+
var value = (_ref9 = (_product$metadata$mai2 = product === null || product === void 0 || (_product$metadata11 = product.metadata) === null || _product$metadata11 === void 0 ? void 0 : _product$metadata11.main_product_attached_bundle_tax_fee) !== null && _product$metadata$mai2 !== void 0 ? _product$metadata$mai2 : product === null || product === void 0 ? void 0 : product.main_product_attached_bundle_tax_fee) !== null && _ref9 !== void 0 ? _ref9 : product === null || product === void 0 ? void 0 : product.tax_fee;
|
|
732
750
|
if (value === undefined || value === null || value === '') return null;
|
|
733
751
|
return toDecimal(value);
|
|
734
752
|
}
|
|
@@ -772,9 +790,9 @@ function resetTaxRemainderFields(products) {
|
|
|
772
790
|
}
|
|
773
791
|
}
|
|
774
792
|
function getBundlePaymentPrice(bundle, product) {
|
|
775
|
-
var
|
|
793
|
+
var _ref10, _ref11, _bundle$bundle_sellin2, _metadata$average_dis, _metadata;
|
|
776
794
|
if ((bundle === null || bundle === void 0 ? void 0 : bundle.bundle_payment_price) !== undefined) return toDecimal(bundle.bundle_payment_price);
|
|
777
|
-
var basePrice = toDecimal((
|
|
795
|
+
var basePrice = toDecimal((_ref10 = (_ref11 = (_bundle$bundle_sellin2 = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price) !== null && _bundle$bundle_sellin2 !== void 0 ? _bundle$bundle_sellin2 : bundle === null || bundle === void 0 ? void 0 : bundle.bundle_sum_price) !== null && _ref11 !== void 0 ? _ref11 : bundle === null || bundle === void 0 ? void 0 : bundle.price) !== null && _ref10 !== void 0 ? _ref10 : 0);
|
|
778
796
|
if (!isBundleOriginalPrice(bundle)) return basePrice;
|
|
779
797
|
var averageDiscountRate = toDecimal((_metadata$average_dis = (_metadata = product.metadata) === null || _metadata === void 0 ? void 0 : _metadata.average_discount_amount_rate) !== null && _metadata$average_dis !== void 0 ? _metadata$average_dis : 1);
|
|
780
798
|
return toAmountFormat(bcMul(basePrice, averageDiscountRate, 6));
|
|
@@ -820,19 +838,19 @@ function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
|
|
|
820
838
|
_step18;
|
|
821
839
|
try {
|
|
822
840
|
for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
|
|
823
|
-
var _bundleItem$num2,
|
|
841
|
+
var _bundleItem$num2, _ref12, _ref13, _bundleItem$original_, _ref14, _bundleItem$is_charge, _ref15, _bundleItem$is_charge2;
|
|
824
842
|
var bundleItem = _step18.value;
|
|
825
843
|
if (!isBundleOriginalPrice(bundleItem)) continue;
|
|
826
844
|
var bundleQuantity = new Decimal(getSafeNum((_bundleItem$num2 = bundleItem.num) !== null && _bundleItem$num2 !== void 0 ? _bundleItem$num2 : bundleItem.quantity));
|
|
827
845
|
var totalBundleQuantity = bundleQuantity.times(quantity);
|
|
828
846
|
var bundlePrice = getBundlePaymentPrice(bundleItem, product);
|
|
829
|
-
var bundleOriginalPrice = toDecimal((
|
|
847
|
+
var bundleOriginalPrice = toDecimal((_ref12 = (_ref13 = (_bundleItem$original_ = bundleItem.original_price) !== null && _bundleItem$original_ !== void 0 ? _bundleItem$original_ : bundleItem.product_price) !== null && _ref13 !== void 0 ? _ref13 : bundleItem.price) !== null && _ref12 !== void 0 ? _ref12 : 0);
|
|
830
848
|
var bundleSurchargeFee = toDecimal(bundleItem.surcharge_fee);
|
|
831
849
|
var bundleTaxPrecise = calculateSingleItemTax({
|
|
832
850
|
price: bundlePrice.plus(bundleSurchargeFee),
|
|
833
851
|
taxRate: rate,
|
|
834
852
|
isPriceIncludeTax: isPriceIncludeTax,
|
|
835
|
-
isChargeTax: (
|
|
853
|
+
isChargeTax: (_ref14 = (_bundleItem$is_charge = bundleItem.is_charge_tax) !== null && _bundleItem$is_charge !== void 0 ? _bundleItem$is_charge : product.is_charge_tax) !== null && _ref14 !== void 0 ? _ref14 : 0
|
|
836
854
|
});
|
|
837
855
|
var bundleTaxRounded = toBackendTaxFee(bundleTaxPrecise);
|
|
838
856
|
bundleItem.tax_fee = bundleTaxRounded.toNumber();
|
|
@@ -849,7 +867,7 @@ function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
|
|
|
849
867
|
price: bundleOriginalPrice.plus(bundleSurchargeFee),
|
|
850
868
|
taxRate: rate,
|
|
851
869
|
isPriceIncludeTax: isPriceIncludeTax,
|
|
852
|
-
isChargeTax: (
|
|
870
|
+
isChargeTax: (_ref15 = (_bundleItem$is_charge2 = bundleItem.is_charge_tax) !== null && _bundleItem$is_charge2 !== void 0 ? _bundleItem$is_charge2 : product.is_charge_tax) !== null && _ref15 !== void 0 ? _ref15 : 0
|
|
853
871
|
});
|
|
854
872
|
var bundleOrigTaxRounded = toAmountFormat(bundleOrigTaxPrecise);
|
|
855
873
|
bundleItem.original_tax_fee = bundleOrigTaxRounded.toNumber();
|
|
@@ -920,46 +938,58 @@ function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
|
|
|
920
938
|
originTax: totalOriginTax.toDecimalPlaces(2, Decimal.ROUND_HALF_UP)
|
|
921
939
|
};
|
|
922
940
|
}
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
941
|
+
|
|
942
|
+
/**
|
|
943
|
+
* 整单折扣(shop_discount)按各行 selling 合计占比均摊到 payment 维度。
|
|
944
|
+
*
|
|
945
|
+
* 文档口径:
|
|
946
|
+
* - payment_price = selling_price − 整单折扣均摊;rate = payment/selling(全行同一 rate);
|
|
947
|
+
* - 附加费不受整单折扣影响(基数仍用 selling,本函数写 main_product_attached_bundle_selling_price);
|
|
948
|
+
* - 税费受整单折扣影响(基数用 payment,本函数写 main_product_attached_bundle_payment_price 与
|
|
949
|
+
* 原价子商品 bundle_payment_price)。
|
|
950
|
+
*
|
|
951
|
+
* 与后端一致:bundle_payment_price = bundle_selling_price × rate,
|
|
952
|
+
* main_product_attached_bundle_payment_price = main_product_attached_bundle_selling_price × rate。
|
|
953
|
+
*/
|
|
954
|
+
function allocateShopDiscountToPayment(products, productAmount, shopDiscountAmount) {
|
|
955
|
+
var effectiveDiscount = productAmount.lte(0) ? new Decimal(0) : Decimal.max(Decimal.min(productAmount, shopDiscountAmount), 0);
|
|
935
956
|
var allocatedDiscount = new Decimal(0);
|
|
936
957
|
products.forEach(function (product, index) {
|
|
937
958
|
var quantity = new Decimal(getSafeNum(product.num));
|
|
938
|
-
var
|
|
939
|
-
var
|
|
959
|
+
var sellingUnit = getUnitPaymentTotal(product);
|
|
960
|
+
var lineSellingTotal = sellingUnit.times(quantity);
|
|
961
|
+
var lineDiscount = effectiveDiscount.lte(0) ? new Decimal(0) : index === products.length - 1 ? Decimal.max(effectiveDiscount.minus(allocatedDiscount), 0) : toAmountFormat(lineSellingTotal.div(productAmount).times(effectiveDiscount));
|
|
940
962
|
allocatedDiscount = allocatedDiscount.plus(lineDiscount);
|
|
941
963
|
var unitDiscount = quantity.lte(0) ? new Decimal(0) : lineDiscount.div(quantity);
|
|
942
|
-
var
|
|
943
|
-
var
|
|
964
|
+
var paymentUnit = Decimal.max(sellingUnit.minus(unitDiscount), 0);
|
|
965
|
+
var rate = sellingUnit.lte(0) ? new Decimal(1) : toBcScale(paymentUnit.div(sellingUnit), 6);
|
|
966
|
+
var mainSellingTotal = getMainAttachedBundleSellingTotal(product);
|
|
967
|
+
var mainPaymentTotal = toAmountFormat(bcMul(mainSellingTotal, rate, 6));
|
|
944
968
|
product.metadata = _objectSpread(_objectSpread({}, product.metadata || {}), {}, {
|
|
945
|
-
|
|
969
|
+
average_discount_amount_rate: rate.toString(),
|
|
970
|
+
main_product_attached_bundle_selling_price: mainSellingTotal.toFixed(2),
|
|
971
|
+
main_product_attached_bundle_payment_price: mainPaymentTotal.toFixed(2)
|
|
946
972
|
});
|
|
947
|
-
|
|
948
|
-
return function () {
|
|
949
|
-
var _iterator19 = _createForOfIteratorHelper(snapshots),
|
|
973
|
+
var _iterator19 = _createForOfIteratorHelper(product.product_bundle || []),
|
|
950
974
|
_step19;
|
|
951
975
|
try {
|
|
952
976
|
for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
|
|
953
|
-
var
|
|
954
|
-
|
|
955
|
-
|
|
977
|
+
var bundle = _step19.value;
|
|
978
|
+
// 原价子商品:bundle_payment_price = bundle_selling_price × rate
|
|
979
|
+
// markdown 子商品:以净额幅度 × rate(与后端一致,存正净额)
|
|
980
|
+
if (isBundleOriginalPrice(bundle)) {
|
|
981
|
+
var _ref16, _ref17, _bundle$bundle_sellin3;
|
|
982
|
+
var bundleSelling = toDecimal((_ref16 = (_ref17 = (_bundle$bundle_sellin3 = bundle.bundle_selling_price) !== null && _bundle$bundle_sellin3 !== void 0 ? _bundle$bundle_sellin3 : bundle.bundle_sum_price) !== null && _ref17 !== void 0 ? _ref17 : bundle.price) !== null && _ref16 !== void 0 ? _ref16 : 0);
|
|
983
|
+
bundle.bundle_payment_price = toAmountFormat(bcMul(bundleSelling, rate, 6)).toFixed(2);
|
|
956
984
|
continue;
|
|
957
985
|
}
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
986
|
+
if (isMarkdownBundle(bundle)) {
|
|
987
|
+
var _bundle$custom_price;
|
|
988
|
+
var magnitude = getBundleSellingMagnitude(bundle);
|
|
989
|
+
bundle.custom_price = (_bundle$custom_price = bundle.custom_price) !== null && _bundle$custom_price !== void 0 ? _bundle$custom_price : bundle.price;
|
|
990
|
+
bundle.price = magnitude.toFixed(2);
|
|
991
|
+
bundle.bundle_selling_price = magnitude.toFixed(2);
|
|
992
|
+
bundle.bundle_payment_price = toAmountFormat(bcMul(magnitude, rate, 6)).toFixed(2);
|
|
963
993
|
}
|
|
964
994
|
}
|
|
965
995
|
} catch (err) {
|
|
@@ -967,7 +997,8 @@ function applyShopDiscountToSurchargeBase(products, productAmount, shopDiscountA
|
|
|
967
997
|
} finally {
|
|
968
998
|
_iterator19.f();
|
|
969
999
|
}
|
|
970
|
-
|
|
1000
|
+
product.payment_price = paymentUnit.toFixed(2);
|
|
1001
|
+
});
|
|
971
1002
|
}
|
|
972
1003
|
export function createEmptySalesSummary() {
|
|
973
1004
|
return {
|
|
@@ -1021,7 +1052,11 @@ export function calculateSalesSummary(params) {
|
|
|
1021
1052
|
var _getPersistedMainSurc;
|
|
1022
1053
|
return (_getPersistedMainSurc = getPersistedMainSurchargeFee(product)) === null || _getPersistedMainSurc === void 0 ? void 0 : _getPersistedMainSurc.gt(0);
|
|
1023
1054
|
});
|
|
1024
|
-
|
|
1055
|
+
// 整单折扣均摊:附加费基数用 selling(不受折扣),税费基数用 payment(受折扣)。
|
|
1056
|
+
// persisted 快照(已下单编辑)优先采信后端回传值,不重算均摊。
|
|
1057
|
+
if (!hasPersistedSurchargeSnapshot) {
|
|
1058
|
+
allocateShopDiscountToPayment(summaryProducts, productAmount, shopDiscountAmount);
|
|
1059
|
+
}
|
|
1025
1060
|
var surchargeServiceItems = buildSurchargeServiceItems(summaryProducts);
|
|
1026
1061
|
getSurcharge({
|
|
1027
1062
|
service: surchargeServiceItems,
|
|
@@ -1039,7 +1074,6 @@ export function calculateSalesSummary(params) {
|
|
|
1039
1074
|
sourceItems: surchargeServiceItems,
|
|
1040
1075
|
surchargeList: surchargeList
|
|
1041
1076
|
});
|
|
1042
|
-
restoreSurchargeBase();
|
|
1043
1077
|
var surchargeAmount = new Decimal(getSurchargeAmount({
|
|
1044
1078
|
bookingDetail: null,
|
|
1045
1079
|
bookingId: undefined
|