@pisell/pisellos 2.2.308 → 2.2.309
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/promotion/index.js +9 -0
- package/dist/modules/Order/index.d.ts +1 -0
- package/dist/modules/Order/index.js +118 -59
- package/dist/modules/Order/utils/weighedProduct.d.ts +12 -0
- package/dist/modules/Order/utils/weighedProduct.js +94 -0
- package/dist/modules/Order/utils.js +6 -4
- package/dist/modules/Rules/index.js +4 -2
- package/dist/modules/Rules/types.d.ts +2 -0
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +40 -25
- package/dist/solution/BaseSales/utils.js +3 -2
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/ScanOrder/utils.js +3 -2
- package/lib/modules/Order/index.d.ts +1 -0
- package/lib/modules/Order/index.js +71 -11
- package/lib/modules/Order/utils/weighedProduct.d.ts +12 -0
- package/lib/modules/Order/utils/weighedProduct.js +89 -0
- package/lib/modules/Order/utils.js +3 -2
- package/lib/modules/Rules/index.js +4 -2
- package/lib/modules/Rules/types.d.ts +2 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +24 -9
- package/lib/solution/BaseSales/utils.js +2 -1
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/ScanOrder/utils.js +2 -1
- package/package.json +1 -1
|
@@ -365,7 +365,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
365
365
|
}) && productList.find(function (n) {
|
|
366
366
|
return !n.booking_id;
|
|
367
367
|
});
|
|
368
|
-
var
|
|
368
|
+
var reapplyWeighedDiscountProductUids = new Set(((options === null || options === void 0 ? void 0 : options.reapplyWeighedDiscountProductUids) || []).map(String));
|
|
369
|
+
var reapplyBookingDiscountProductUids = new Set([].concat(_toConsumableArray((options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids) || []), _toConsumableArray(reapplyWeighedDiscountProductUids)).filter(function (uid) {
|
|
369
370
|
return uid !== undefined && uid !== null && uid !== '';
|
|
370
371
|
}).map(String));
|
|
371
372
|
var getOriginProductUid = function getOriginProductUid(originProduct) {
|
|
@@ -1110,7 +1111,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1110
1111
|
}));
|
|
1111
1112
|
|
|
1112
1113
|
// 已持久化且已有钱包券/折扣卡的商品行跳过,保留后端历史折扣结果。
|
|
1113
|
-
|
|
1114
|
+
var isReweighedProduct = reapplyWeighedDiscountProductUids.has(getOriginProductUid(originProduct) || '');
|
|
1115
|
+
if (isPersistedProduct && hasExistingWalletDiscount && !isReweighedProduct) {
|
|
1114
1116
|
if (flatItem.type === 'main') {
|
|
1115
1117
|
processedProductsMap.set(product._id, [originProduct]);
|
|
1116
1118
|
}
|
|
@@ -31,6 +31,8 @@ export interface RulesCalcDiscountOptions {
|
|
|
31
31
|
scan?: boolean;
|
|
32
32
|
/** Change time 重报价目标行:允许已选编辑态折扣卡重新应用到这些 booking 商品。 */
|
|
33
33
|
reapplyBookingDiscountProductUids?: string[];
|
|
34
|
+
/** Reweighed order lines only: reapply selected wallet discounts against their new amount. */
|
|
35
|
+
reapplyWeighedDiscountProductUids?: string[];
|
|
34
36
|
}
|
|
35
37
|
export interface RulesModuleAPI {
|
|
36
38
|
setRulesList: (rulesList: Rules[]) => Promise<void>;
|
|
@@ -11,6 +11,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
11
11
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
12
12
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
13
13
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
14
|
+
import { resolveWeighedSourcePrice, withOriginalBundleOptionPrices } from "../../../modules/Order/utils/weighedProduct";
|
|
14
15
|
import { composeLinePrice, getBundleSellingMagnitude, normalizeProductSkuOptions, sumOptionUnitPrice } from "../../../modules/Order/utils";
|
|
15
16
|
import { buildManualProductDiscountItem, mergeManualProductDiscountIntoList, resolveManualDiscountOriginTotal, resolveManualDiscountReasonFromSources, shouldBuildManualProductDiscount } from "../../../modules/Order/utils/manualProductDiscount";
|
|
16
17
|
function toNumber(value) {
|
|
@@ -101,11 +102,12 @@ function appendDataVariantIds(base) {
|
|
|
101
102
|
return Array.isArray(base) || result.length ? result : undefined;
|
|
102
103
|
}
|
|
103
104
|
function normalizeOptionItems(optionItems) {
|
|
105
|
+
var useOriginalPrice = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
104
106
|
if (!Array.isArray(optionItems)) return [];
|
|
105
107
|
return optionItems.map(function (optionItem) {
|
|
106
|
-
var _optionItem$option_gr, _ref,
|
|
108
|
+
var _optionItem$option_gr, _ref, _ref2, _ref3, _optionItem$num;
|
|
107
109
|
var optionGroupItemId = toNumber((_optionItem$option_gr = optionItem === null || optionItem === void 0 ? void 0 : optionItem.option_group_item_id) !== null && _optionItem$option_gr !== void 0 ? _optionItem$option_gr : optionItem === null || optionItem === void 0 ? void 0 : optionItem.id);
|
|
108
|
-
var price = (_ref = (
|
|
110
|
+
var price = (_ref = (_ref2 = (_ref3 = useOriginalPrice ? optionItem === null || optionItem === void 0 ? void 0 : optionItem.original_price : undefined) !== null && _ref3 !== void 0 ? _ref3 : optionItem === null || optionItem === void 0 ? void 0 : optionItem.price) !== null && _ref2 !== void 0 ? _ref2 : optionItem === null || optionItem === void 0 ? void 0 : optionItem.add_price) !== null && _ref !== void 0 ? _ref : 0;
|
|
109
111
|
return _objectSpread(_objectSpread({}, optionItem), {}, {
|
|
110
112
|
option_group_item_id: optionGroupItemId,
|
|
111
113
|
option_group_id: toNumber(optionItem === null || optionItem === void 0 ? void 0 : optionItem.option_group_id),
|
|
@@ -117,10 +119,13 @@ function normalizeOptionItems(optionItems) {
|
|
|
117
119
|
}
|
|
118
120
|
function normalizeBundleItems(bundleItems) {
|
|
119
121
|
var preferPriceField = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
122
|
+
var preferBundleSellingPrice = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
120
123
|
if (!Array.isArray(bundleItems)) return [];
|
|
121
124
|
return bundleItems.map(function (bundleItem) {
|
|
122
|
-
var
|
|
123
|
-
|
|
125
|
+
var _ref4, _ref5, _ref6, _bundleItem$price, _ref7, _ref8, _ref9, _bundleItem$bundle_se, _bundleItem$num, _bundleItem$price2, _bundleItem$quantity, _bundleItem$price3, _ref10, _ref11, _bundleItem$original_, _normalizedItem$price;
|
|
126
|
+
// Weighed manual prices distribute the bundle base and nested options separately.
|
|
127
|
+
// Its explicit selling amount already includes those options.
|
|
128
|
+
var unitSelling = preferPriceField && !preferBundleSellingPrice ? (_ref4 = (_ref5 = (_ref6 = (_bundleItem$price = bundleItem.price) !== null && _bundleItem$price !== void 0 ? _bundleItem$price : bundleItem.bundle_selling_price) !== null && _ref6 !== void 0 ? _ref6 : bundleItem.custom_price) !== null && _ref5 !== void 0 ? _ref5 : bundleItem.product_price) !== null && _ref4 !== void 0 ? _ref4 : '0' : (_ref7 = (_ref8 = (_ref9 = (_bundleItem$bundle_se = bundleItem.bundle_selling_price) !== null && _bundleItem$bundle_se !== void 0 ? _bundleItem$bundle_se : bundleItem.price) !== null && _ref9 !== void 0 ? _ref9 : bundleItem.custom_price) !== null && _ref8 !== void 0 ? _ref8 : bundleItem.product_price) !== null && _ref7 !== void 0 ? _ref7 : '0';
|
|
124
129
|
var unitStr = toPriceString(unitSelling, '0.00');
|
|
125
130
|
var num = toSafePositiveInt((_bundleItem$num = bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.num) !== null && _bundleItem$num !== void 0 ? _bundleItem$num : bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.quantity, 1);
|
|
126
131
|
var magnitudeSource = _objectSpread(_objectSpread({}, bundleItem), {}, {
|
|
@@ -135,7 +140,7 @@ function normalizeBundleItems(bundleItems) {
|
|
|
135
140
|
// price 保留毛价(markdown 仍为正),由 price_type 决定符号。
|
|
136
141
|
price: (_bundleItem$price3 = bundleItem.price) !== null && _bundleItem$price3 !== void 0 ? _bundleItem$price3 : unitStr,
|
|
137
142
|
bundle_selling_price: unitStr,
|
|
138
|
-
original_price: (
|
|
143
|
+
original_price: (_ref10 = (_ref11 = (_bundleItem$original_ = bundleItem.original_price) !== null && _bundleItem$original_ !== void 0 ? _bundleItem$original_ : bundleItem.product_price) !== null && _ref11 !== void 0 ? _ref11 : bundleItem.price) !== null && _ref10 !== void 0 ? _ref10 : unitStr,
|
|
139
144
|
option: normalizeOptionItems(bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.option),
|
|
140
145
|
discount_list: preferPriceField ? [] : bundleItem.discount_list
|
|
141
146
|
});
|
|
@@ -163,49 +168,55 @@ function findVariantById(origin, variantId) {
|
|
|
163
168
|
* 注意:这里不生成 identity,缺省时由 OrderModule 自动补齐。
|
|
164
169
|
*/
|
|
165
170
|
export function transformBaseProductToOrderProduct(params) {
|
|
166
|
-
var
|
|
171
|
+
var _ref12, _ref13, _ref14, _payload$product_id, _ref15, _ref16, _payload$product_vari, _payload$_origin, _payload$_origin2, _payload$metadata, _sourceProduct$metada, _callbackOrigin$metad, _origin$metadata, _payload$metadata2, _payload$_extend, _sourceProduct$metada2, _sourceProduct$_exten, _callbackOrigin$metad2, _callbackOrigin$_exte, _payload$_dataVariant, _sourceProduct$_dataV, _callbackOrigin$_data, _origin$_dataVariant, _ref17, _findVariantById, _origin$production_co, _ref18, _ref19, _ref20, _ref21, _ref22, _matchedVariant$price, _payload$product_sku, _payload$_extend$weig, _payload$_extend2, _origin$_extend, _ref23, _ref24, _payload$price, _ref25, _payload$line_total, _payload$_extend3, _ref26, _ref27, _payload$product_sku$, _payload$product_sku2, _payload$bundle, _payload$quantity, _payload$_extend4, _extend, _extend2, _ref28, _ref29, _origin$base_price, _ref30, _ref31, _payload$line_total2, _payload$_extend5, _payload$_extend6, _extend3, _payload$_extend7, _payload$_extend8, _ref32, _ref33, _payload$tax_fee, _ref34, _ref35, _payload$is_charge_ta;
|
|
167
172
|
var payload = params.payload,
|
|
168
173
|
_params$fallbackProdu = params.fallbackProductId,
|
|
169
174
|
fallbackProductId = _params$fallbackProdu === void 0 ? null : _params$fallbackProdu;
|
|
170
175
|
if (!payload || _typeof(payload) !== 'object') return null;
|
|
171
176
|
var sourceProduct = params.sourceProduct || params.sourceItem || {};
|
|
172
|
-
var productId = toProductId((
|
|
177
|
+
var productId = toProductId((_ref12 = (_ref13 = (_ref14 = (_payload$product_id = payload.product_id) !== null && _payload$product_id !== void 0 ? _payload$product_id : payload.id) !== null && _ref14 !== void 0 ? _ref14 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.product_id) !== null && _ref13 !== void 0 ? _ref13 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.id) !== null && _ref12 !== void 0 ? _ref12 : fallbackProductId);
|
|
173
178
|
if (productId === null) return null;
|
|
174
|
-
var productVariantId = toNumber((
|
|
179
|
+
var productVariantId = toNumber((_ref15 = (_ref16 = (_payload$product_vari = payload.product_variant_id) !== null && _payload$product_vari !== void 0 ? _payload$product_vari : payload.variant_id) !== null && _ref16 !== void 0 ? _ref16 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.product_variant_id) !== null && _ref15 !== void 0 ? _ref15 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.variant_id, 0);
|
|
175
180
|
var callbackOrigin = payload.origin || ((_payload$_origin = payload._origin) === null || _payload$_origin === void 0 ? void 0 : _payload$_origin.sourceProduct) || ((_payload$_origin2 = payload._origin) === null || _payload$_origin2 === void 0 ? void 0 : _payload$_origin2.sourceItem) || payload._origin || {};
|
|
176
181
|
var origin = _objectSpread(_objectSpread({}, sourceProduct || {}), callbackOrigin || {});
|
|
177
182
|
var authoritativeDataVariantIds = cloneFirstDataVariantIds((_payload$metadata = payload.metadata) === null || _payload$metadata === void 0 ? void 0 : _payload$metadata.data_variant_ids, sourceProduct === null || sourceProduct === void 0 || (_sourceProduct$metada = sourceProduct.metadata) === null || _sourceProduct$metada === void 0 ? void 0 : _sourceProduct$metada.data_variant_ids, callbackOrigin === null || callbackOrigin === void 0 || (_callbackOrigin$metad = callbackOrigin.metadata) === null || _callbackOrigin$metad === void 0 ? void 0 : _callbackOrigin$metad.data_variant_ids, origin === null || origin === void 0 || (_origin$metadata = origin.metadata) === null || _origin$metadata === void 0 ? void 0 : _origin$metadata.data_variant_ids);
|
|
178
183
|
var selectedSettlementSnapshot = firstNonBlank(payload.selected_settlement_snapshot, (_payload$metadata2 = payload.metadata) === null || _payload$metadata2 === void 0 ? void 0 : _payload$metadata2.selected_settlement_snapshot, (_payload$_extend = payload._extend) === null || _payload$_extend === void 0 || (_payload$_extend = _payload$_extend.metadata) === null || _payload$_extend === void 0 ? void 0 : _payload$_extend.selected_settlement_snapshot, sourceProduct === null || sourceProduct === void 0 || (_sourceProduct$metada2 = sourceProduct.metadata) === null || _sourceProduct$metada2 === void 0 ? void 0 : _sourceProduct$metada2.selected_settlement_snapshot, sourceProduct === null || sourceProduct === void 0 || (_sourceProduct$_exten = sourceProduct._extend) === null || _sourceProduct$_exten === void 0 || (_sourceProduct$_exten = _sourceProduct$_exten.metadata) === null || _sourceProduct$_exten === void 0 ? void 0 : _sourceProduct$_exten.selected_settlement_snapshot, callbackOrigin === null || callbackOrigin === void 0 || (_callbackOrigin$metad2 = callbackOrigin.metadata) === null || _callbackOrigin$metad2 === void 0 ? void 0 : _callbackOrigin$metad2.selected_settlement_snapshot, callbackOrigin === null || callbackOrigin === void 0 || (_callbackOrigin$_exte = callbackOrigin._extend) === null || _callbackOrigin$_exte === void 0 || (_callbackOrigin$_exte = _callbackOrigin$_exte.metadata) === null || _callbackOrigin$_exte === void 0 ? void 0 : _callbackOrigin$_exte.selected_settlement_snapshot);
|
|
179
184
|
var locallyAppliedVariantIds = authoritativeDataVariantIds === undefined ? cloneFirstDataVariantIds((_payload$_dataVariant = payload._dataVariant) === null || _payload$_dataVariant === void 0 ? void 0 : _payload$_dataVariant.appliedVariantIds, sourceProduct === null || sourceProduct === void 0 || (_sourceProduct$_dataV = sourceProduct._dataVariant) === null || _sourceProduct$_dataV === void 0 ? void 0 : _sourceProduct$_dataV.appliedVariantIds, callbackOrigin === null || callbackOrigin === void 0 || (_callbackOrigin$_data = callbackOrigin._dataVariant) === null || _callbackOrigin$_data === void 0 ? void 0 : _callbackOrigin$_data.appliedVariantIds, origin === null || origin === void 0 || (_origin$_dataVariant = origin._dataVariant) === null || _origin$_dataVariant === void 0 ? void 0 : _origin$_dataVariant.appliedVariantIds) : undefined;
|
|
180
185
|
var dataVariantIds = appendDataVariantIds(authoritativeDataVariantIds, locallyAppliedVariantIds, selectedSettlementSnapshot === null || selectedSettlementSnapshot === void 0 ? void 0 : selectedSettlementSnapshot.data_variant_id);
|
|
181
|
-
var matchedVariant = (
|
|
186
|
+
var matchedVariant = (_ref17 = (_findVariantById = findVariantById(callbackOrigin, productVariantId)) !== null && _findVariantById !== void 0 ? _findVariantById : findVariantById(sourceProduct, productVariantId)) !== null && _ref17 !== void 0 ? _ref17 : findVariantById(origin, productVariantId);
|
|
182
187
|
var productionCode = normalizeProductionCode(Object.prototype.hasOwnProperty.call(payload, 'production_code') ? payload.production_code : productVariantId > 0 ? matchedVariant === null || matchedVariant === void 0 ? void 0 : matchedVariant.production_code : (_origin$production_co = origin === null || origin === void 0 ? void 0 : origin.production_code) !== null && _origin$production_co !== void 0 ? _origin$production_co : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.production_code);
|
|
183
188
|
var hasPriceOverride = payload.price_override !== undefined && payload.price_override !== null && payload.price_override !== '';
|
|
184
189
|
// 手动改价后 payload.price 是分摊后的主商品售价,不能再作为券前 source。
|
|
185
|
-
//
|
|
186
|
-
|
|
187
|
-
var
|
|
188
|
-
var
|
|
190
|
+
// 称重商品使用改价前净重金额;其它商品从商品/variant 快照读取目录价。
|
|
191
|
+
// 售价仍由 line_total - bundle 推导。
|
|
192
|
+
var catalogSourcePrice = (_ref18 = (_ref19 = (_ref20 = (_ref21 = (_ref22 = (_matchedVariant$price = matchedVariant === null || matchedVariant === void 0 ? void 0 : matchedVariant.price) !== null && _matchedVariant$price !== void 0 ? _matchedVariant$price : matchedVariant === null || matchedVariant === void 0 ? void 0 : matchedVariant.base_price) !== null && _ref22 !== void 0 ? _ref22 : origin === null || origin === void 0 ? void 0 : origin.price) !== null && _ref21 !== void 0 ? _ref21 : origin === null || origin === void 0 ? void 0 : origin.base_price) !== null && _ref20 !== void 0 ? _ref20 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.price) !== null && _ref19 !== void 0 ? _ref19 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.selling_price) !== null && _ref18 !== void 0 ? _ref18 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.base_price;
|
|
193
|
+
var weighedSourcePrice = resolveWeighedSourcePrice((_payload$product_sku = payload.product_sku) !== null && _payload$product_sku !== void 0 ? _payload$product_sku : origin.product_sku, (_payload$_extend$weig = (_payload$_extend2 = payload._extend) === null || _payload$_extend2 === void 0 ? void 0 : _payload$_extend2.weighing) !== null && _payload$_extend$weig !== void 0 ? _payload$_extend$weig : (_origin$_extend = origin._extend) === null || _origin$_extend === void 0 ? void 0 : _origin$_extend.weighing);
|
|
194
|
+
var sourceProductPrice = toPriceString(weighedSourcePrice !== null && weighedSourcePrice !== void 0 ? weighedSourcePrice : hasPriceOverride ? (_ref23 = catalogSourcePrice !== null && catalogSourcePrice !== void 0 ? catalogSourcePrice : payload.price) !== null && _ref23 !== void 0 ? _ref23 : payload.selling_price : (_ref24 = (_payload$price = payload.price) !== null && _payload$price !== void 0 ? _payload$price : payload.selling_price) !== null && _ref24 !== void 0 ? _ref24 : catalogSourcePrice, '0.00');
|
|
195
|
+
var explicitLineTotal = (_ref25 = (_payload$line_total = payload.line_total) !== null && _payload$line_total !== void 0 ? _payload$line_total : payload.total) !== null && _ref25 !== void 0 ? _ref25 : (_payload$_extend3 = payload._extend) === null || _payload$_extend3 === void 0 ? void 0 : _payload$_extend3.total;
|
|
189
196
|
var hasExplicitLineTotal = Number.isFinite(Number(explicitLineTotal));
|
|
190
197
|
var lineCompositeTotal = toPriceString(explicitLineTotal, sourceProductPrice);
|
|
191
|
-
var productOptionItem = normalizeProductSkuOptions(normalizeOptionItems((
|
|
192
|
-
var productBundle = normalizeBundleItems((_payload$bundle = payload.bundle) !== null && _payload$bundle !== void 0 ? _payload$bundle : payload.product_bundle, hasPriceOverride);
|
|
198
|
+
var productOptionItem = normalizeProductSkuOptions(normalizeOptionItems((_ref26 = (_ref27 = (_payload$product_sku$ = (_payload$product_sku2 = payload.product_sku) === null || _payload$product_sku2 === void 0 ? void 0 : _payload$product_sku2.option) !== null && _payload$product_sku$ !== void 0 ? _payload$product_sku$ : payload.option) !== null && _ref27 !== void 0 ? _ref27 : payload.options) !== null && _ref26 !== void 0 ? _ref26 : payload.product_option_item, hasPriceOverride || weighedSourcePrice !== undefined));
|
|
199
|
+
var productBundle = normalizeBundleItems((_payload$bundle = payload.bundle) !== null && _payload$bundle !== void 0 ? _payload$bundle : payload.product_bundle, hasPriceOverride, hasPriceOverride && weighedSourcePrice !== undefined);
|
|
193
200
|
// `payload.unique` 是业务侧商品/票务标识,可能在连续加同一商品时重复;
|
|
194
201
|
// 行级唯一值只接受显式协议字段,缺省交给 OrderModule 生成。
|
|
195
202
|
var uniqueIdentificationNumber = payload.unique_identification_number;
|
|
196
203
|
var resolvedQuantity = toSafePositiveInt((_payload$quantity = payload.quantity) !== null && _payload$quantity !== void 0 ? _payload$quantity : payload.num, 1);
|
|
197
|
-
var originTotal =
|
|
204
|
+
var originTotal = weighedSourcePrice !== undefined ? Number(composeLinePrice({
|
|
205
|
+
mainPrice: Number(weighedSourcePrice) + sumOptionUnitPrice(productOptionItem).toNumber(),
|
|
206
|
+
bundle: hasPriceOverride ? withOriginalBundleOptionPrices(productBundle) : productBundle,
|
|
207
|
+
useOriginalBundle: true
|
|
208
|
+
})) : resolveManualDiscountOriginTotal({
|
|
198
209
|
originTotal: payload.origin_total,
|
|
199
|
-
extendOriginTotal: (_payload$
|
|
210
|
+
extendOriginTotal: (_payload$_extend4 = payload._extend) === null || _payload$_extend4 === void 0 ? void 0 : _payload$_extend4.origin_total,
|
|
200
211
|
originExtendOriginTotal: origin === null || origin === void 0 || (_extend = origin._extend) === null || _extend === void 0 ? void 0 : _extend.origin_total,
|
|
201
212
|
sourceExtendOriginTotal: sourceProduct === null || sourceProduct === void 0 || (_extend2 = sourceProduct._extend) === null || _extend2 === void 0 ? void 0 : _extend2.origin_total,
|
|
202
|
-
catalogUnitPrice: (
|
|
213
|
+
catalogUnitPrice: (_ref28 = (_ref29 = (_origin$base_price = origin === null || origin === void 0 ? void 0 : origin.base_price) !== null && _origin$base_price !== void 0 ? _origin$base_price : origin === null || origin === void 0 ? void 0 : origin.price) !== null && _ref29 !== void 0 ? _ref29 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.base_price) !== null && _ref28 !== void 0 ? _ref28 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.price,
|
|
203
214
|
quantity: resolvedQuantity
|
|
204
215
|
});
|
|
205
|
-
var sellingTotal = Number((
|
|
216
|
+
var sellingTotal = Number((_ref30 = (_ref31 = (_payload$line_total2 = payload.line_total) !== null && _payload$line_total2 !== void 0 ? _payload$line_total2 : payload.total) !== null && _ref31 !== void 0 ? _ref31 : (_payload$_extend5 = payload._extend) === null || _payload$_extend5 === void 0 ? void 0 : _payload$_extend5.total) !== null && _ref30 !== void 0 ? _ref30 : lineCompositeTotal);
|
|
206
217
|
var discountReason = resolveManualDiscountReasonFromSources({
|
|
207
218
|
discountReason: payload.discount_reason,
|
|
208
|
-
extendDiscountReason: (_payload$
|
|
219
|
+
extendDiscountReason: (_payload$_extend6 = payload._extend) === null || _payload$_extend6 === void 0 ? void 0 : _payload$_extend6.discount_reason,
|
|
209
220
|
originExtendDiscountReason: origin === null || origin === void 0 || (_extend3 = origin._extend) === null || _extend3 === void 0 ? void 0 : _extend3.discount_reason
|
|
210
221
|
});
|
|
211
222
|
var lineOriginalPrice = hasPriceOverride && Number.isFinite(originTotal) ? toPriceString(originTotal) : lineCompositeTotal;
|
|
@@ -218,8 +229,8 @@ export function transformBaseProductToOrderProduct(params) {
|
|
|
218
229
|
sellingTotal: Number.isFinite(sellingTotal) ? sellingTotal : Number(lineCompositeTotal),
|
|
219
230
|
quantity: resolvedQuantity,
|
|
220
231
|
message: discountReason,
|
|
221
|
-
discountway: (_payload$
|
|
222
|
-
discount_per: (_payload$
|
|
232
|
+
discountway: (_payload$_extend7 = payload._extend) === null || _payload$_extend7 === void 0 ? void 0 : _payload$_extend7.discountway,
|
|
233
|
+
discount_per: (_payload$_extend8 = payload._extend) === null || _payload$_extend8 === void 0 ? void 0 : _payload$_extend8.discount_per
|
|
223
234
|
})) : payload.discount_list || [];
|
|
224
235
|
|
|
225
236
|
// v2:source 不含 option;main_product_* 含 option(与 normalizeOrderProduct 一致)
|
|
@@ -281,13 +292,17 @@ export function transformBaseProductToOrderProduct(params) {
|
|
|
281
292
|
// 折后行价由 normalizeOrderProduct 按 main + bundle 合成;手动改价时 bundle 已为分摊后单价
|
|
282
293
|
selling_price: lineCompositeTotal,
|
|
283
294
|
original_price: lineOriginalPrice,
|
|
284
|
-
tax_fee: toPriceString((
|
|
285
|
-
is_charge_tax: toNumber((
|
|
295
|
+
tax_fee: toPriceString((_ref32 = (_ref33 = (_payload$tax_fee = payload.tax_fee) !== null && _payload$tax_fee !== void 0 ? _payload$tax_fee : matchedVariant === null || matchedVariant === void 0 ? void 0 : matchedVariant.tax_fee) !== null && _ref33 !== void 0 ? _ref33 : origin === null || origin === void 0 ? void 0 : origin.tax_fee) !== null && _ref32 !== void 0 ? _ref32 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.tax_fee, '0.00'),
|
|
296
|
+
is_charge_tax: toNumber((_ref34 = (_ref35 = (_payload$is_charge_ta = payload.is_charge_tax) !== null && _payload$is_charge_ta !== void 0 ? _payload$is_charge_ta : matchedVariant === null || matchedVariant === void 0 ? void 0 : matchedVariant.is_charge_tax) !== null && _ref35 !== void 0 ? _ref35 : origin === null || origin === void 0 ? void 0 : origin.is_charge_tax) !== null && _ref34 !== void 0 ? _ref34 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.is_charge_tax, 0),
|
|
286
297
|
metadata: metadata,
|
|
287
298
|
note: payload.note != null ? String(payload.note) : '',
|
|
288
299
|
product_title: productTitle,
|
|
289
300
|
product_cover: firstNonBlank(matchedVariant === null || matchedVariant === void 0 ? void 0 : matchedVariant.cover, sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.cover),
|
|
290
|
-
_origin: _objectSpread(_objectSpread({}, sourceProduct || {}),
|
|
301
|
+
_origin: _objectSpread(_objectSpread(_objectSpread({}, sourceProduct || {}), weighedSourcePrice !== undefined && hasPriceOverride ? {
|
|
302
|
+
_extend: _objectSpread(_objectSpread({}, sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct._extend), {}, {
|
|
303
|
+
origin_total: originTotal
|
|
304
|
+
})
|
|
305
|
+
} : {}), {}, {
|
|
291
306
|
callbackData: payload
|
|
292
307
|
})
|
|
293
308
|
});
|
|
@@ -4,9 +4,10 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
4
4
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
5
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
6
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
import { withOriginalBundleOptionPrices } from "../../modules/Order/utils/weighedProduct";
|
|
7
8
|
import Decimal from 'decimal.js';
|
|
8
9
|
import { composeLinePrice, createUuidV4, ensureProductSku, normalizeProductSkuOptions, resolveManualOverrideLineOriginalPrice, sumOptionUnitPrice } from "../../modules/Order/utils";
|
|
9
|
-
import { ensureManualProductDiscountList } from "../../modules/Order/utils/manualProductDiscount";
|
|
10
|
+
import { ensureManualProductDiscountList, hasManualProductDiscountFlag } from "../../modules/Order/utils/manualProductDiscount";
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* 构建金额全为 0 的空 summary。
|
|
@@ -241,7 +242,7 @@ export function normalizeOrderProduct(product) {
|
|
|
241
242
|
});
|
|
242
243
|
var composedOriginalPrice = composeLinePrice({
|
|
243
244
|
mainPrice: mainOriginalStr,
|
|
244
|
-
bundle: normalizedBundle,
|
|
245
|
+
bundle: Number(productSku.open_sold_weight) === 1 && hasManualProductDiscountFlag(metadata) ? withOriginalBundleOptionPrices(normalizedBundle) : normalizedBundle,
|
|
245
246
|
useOriginalBundle: true
|
|
246
247
|
});
|
|
247
248
|
var finalOriginalPrice = resolveManualOverrideLineOriginalPrice({
|
|
@@ -326,7 +326,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
326
326
|
date: string;
|
|
327
327
|
status: string;
|
|
328
328
|
week: string;
|
|
329
|
-
weekNum: 0 | 2 | 1 |
|
|
329
|
+
weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
|
|
330
330
|
}[]>;
|
|
331
331
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
332
332
|
private getScheduleDataByIds;
|
|
@@ -339,7 +339,7 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
|
|
|
339
339
|
* 获取当前的客户搜索条件
|
|
340
340
|
* @returns 当前搜索条件
|
|
341
341
|
*/
|
|
342
|
-
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "
|
|
342
|
+
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
|
|
343
343
|
/**
|
|
344
344
|
* 获取客户列表状态(包含滚动加载相关状态)
|
|
345
345
|
* @returns 客户状态
|
|
@@ -11,10 +11,11 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
11
11
|
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; } } }; }
|
|
12
12
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
13
13
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
14
|
+
import { withOriginalBundleOptionPrices } from "../../modules/Order/utils/weighedProduct";
|
|
14
15
|
import dayjs from 'dayjs';
|
|
15
16
|
import Decimal from 'decimal.js';
|
|
16
17
|
import { composeLinePrice, createUuidV4, ensureProductSku, getBundleSellingMagnitude, getProductSkuOptions, normalizeProductSkuOptions, resolveManualOverrideLineOriginalPrice, sumOptionUnitPrice } from "../../modules/Order/utils";
|
|
17
|
-
import { ensureManualProductDiscountList } from "../../modules/Order/utils/manualProductDiscount";
|
|
18
|
+
import { ensureManualProductDiscountList, hasManualProductDiscountFlag } from "../../modules/Order/utils/manualProductDiscount";
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* 构建金额全为 0 的空 summary。
|
|
@@ -643,7 +644,7 @@ export function normalizeOrderProduct(product) {
|
|
|
643
644
|
});
|
|
644
645
|
var composedOriginalPrice = composeLinePrice({
|
|
645
646
|
mainPrice: mainOriginalStr,
|
|
646
|
-
bundle: normalizedBundle,
|
|
647
|
+
bundle: Number(productSku.open_sold_weight) === 1 && hasManualProductDiscountFlag(metadata) ? withOriginalBundleOptionPrices(normalizedBundle) : normalizedBundle,
|
|
647
648
|
useOriginalBundle: true
|
|
648
649
|
});
|
|
649
650
|
var finalOriginalPrice = resolveManualOverrideLineOriginalPrice({
|
|
@@ -100,6 +100,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
100
100
|
}>;
|
|
101
101
|
applyDiscount(options?: {
|
|
102
102
|
reapplyBookingDiscountProductUids?: string[];
|
|
103
|
+
reapplyWeighedDiscountProductUids?: string[];
|
|
103
104
|
}): void;
|
|
104
105
|
/**
|
|
105
106
|
* 注入促销评估器。
|
|
@@ -8,6 +8,7 @@ var _BaseModule = require("../BaseModule");
|
|
|
8
8
|
var _types = require("./types");
|
|
9
9
|
var _utils = require("./utils");
|
|
10
10
|
var _utils2 = require("../Product/utils");
|
|
11
|
+
var _weighedProduct = require("./utils/weighedProduct");
|
|
11
12
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
12
13
|
var _salesNotes = require("./salesNotes");
|
|
13
14
|
var _paymentUtils = require("./payment-utils");
|
|
@@ -667,7 +668,8 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
667
668
|
isFormSubject: product => (0, _utils.resolveIsFormSubject)(tempOrder, product),
|
|
668
669
|
orderTotalAmount: Number(this.store.summary?.total_amount || 0)
|
|
669
670
|
}, {
|
|
670
|
-
reapplyBookingDiscountProductUids: options?.reapplyBookingDiscountProductUids
|
|
671
|
+
reapplyBookingDiscountProductUids: options?.reapplyBookingDiscountProductUids,
|
|
672
|
+
reapplyWeighedDiscountProductUids: options?.reapplyWeighedDiscountProductUids
|
|
671
673
|
});
|
|
672
674
|
if (result?.productList) {
|
|
673
675
|
const previousProductsByUid = (0, _utils.indexOrderProductsByUid)(tempOrder.products);
|
|
@@ -3599,7 +3601,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3599
3601
|
};
|
|
3600
3602
|
});
|
|
3601
3603
|
}
|
|
3602
|
-
applyOrderProductUpdateToTempOrder(tempOrder, params) {
|
|
3604
|
+
applyOrderProductUpdateToTempOrder(tempOrder, params, reapplyWeighedDiscountProductUids) {
|
|
3603
3605
|
const {
|
|
3604
3606
|
product_id,
|
|
3605
3607
|
product_variant_id,
|
|
@@ -3672,7 +3674,8 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3672
3674
|
const previousLineFingerprint = (0, _utils3.buildProductLineFingerprint)((0, _utils.getProductSkuOptions)(targetProduct), targetProduct.product_bundle);
|
|
3673
3675
|
const nextLineFingerprint = (0, _utils3.buildProductLineFingerprint)((0, _utils.getProductSkuOptions)(nextProduct), nextProduct.product_bundle);
|
|
3674
3676
|
const callerChangesVariant = Number(product_variant_id || 0) !== Number(targetProduct.product_variant_id || 0);
|
|
3675
|
-
const
|
|
3677
|
+
const callerChangesWeighing = (0, _weighedProduct.getWeighedProductPriceFingerprint)(targetProduct.product_sku) !== (0, _weighedProduct.getWeighedProductPriceFingerprint)(nextProduct.product_sku);
|
|
3678
|
+
const callerChangesLineConfiguration = callerChangesVariant || callerChangesWeighing || previousLineFingerprint !== nextLineFingerprint;
|
|
3676
3679
|
const isPersistedOrderLine = targetProduct.order_detail_id !== undefined && targetProduct.order_detail_id !== null;
|
|
3677
3680
|
const callerChangesDiscountList = Array.isArray(updates?.discount_list) && updates.discount_list.length > 0 && !isSameDiscountList(updates.discount_list, targetProduct.discount_list);
|
|
3678
3681
|
const callerUpdatesManualPrice = updates?.metadata?.price_override !== undefined || updates?.metadata?.is_manual_discount !== undefined || updates?.metadata?.product_discount_reason !== undefined || callerChangesDiscountList;
|
|
@@ -3688,6 +3691,23 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3688
3691
|
};
|
|
3689
3692
|
return hasChangedPrice(updates.selling_price, targetProduct.selling_price) || hasChangedPrice(updates.original_price, targetProduct.original_price);
|
|
3690
3693
|
})();
|
|
3694
|
+
const weighedSourcePrice = callerChangesWeighing ? (0, _weighedProduct.resolveWeighedSourcePrice)(nextProduct.product_sku) : undefined;
|
|
3695
|
+
const hasResolvedWeighedPrice = weighedSourcePrice !== undefined;
|
|
3696
|
+
if (hasResolvedWeighedPrice && !callerUpdatesSourcePrice) {
|
|
3697
|
+
const nextMainOriginal = new _decimal.default(weighedSourcePrice).plus((0, _utils.sumOptionUnitPrice)((0, _utils.getProductSkuOptions)(nextProduct)));
|
|
3698
|
+
const previousMainOriginal = new _decimal.default(targetProduct.metadata?.main_product_original_price ?? targetProduct.original_price ?? 0);
|
|
3699
|
+
const previousMainSelling = new _decimal.default(targetProduct.metadata?.main_product_selling_price ?? targetProduct.selling_price ?? 0);
|
|
3700
|
+
// A manual final price remains fixed; other legacy discounts keep their amount
|
|
3701
|
+
// until Rules reapplies the currently selected wallet discount below.
|
|
3702
|
+
const nextMainSelling = isManualProductDiscountProduct(nextProduct) ? previousMainSelling : nextMainOriginal.minus(previousMainOriginal.minus(previousMainSelling));
|
|
3703
|
+
nextProduct.metadata = {
|
|
3704
|
+
...nextProduct.metadata,
|
|
3705
|
+
source_product_price: weighedSourcePrice,
|
|
3706
|
+
main_product_original_price: callerUpdatesMainOriginalPrice ? nextProduct.metadata.main_product_original_price : nextMainOriginal.toFixed(2),
|
|
3707
|
+
main_product_selling_price: callerUpdatesMainSellingPrice ? nextProduct.metadata.main_product_selling_price : _decimal.default.max(0, nextMainSelling).toFixed(2),
|
|
3708
|
+
price_schema_version: 2
|
|
3709
|
+
};
|
|
3710
|
+
}
|
|
3691
3711
|
if (isPersistedOrderLine && !callerChangesLineConfiguration && !callerUpdatesManualPrice && !callerAllowsBookingReprice) {
|
|
3692
3712
|
nextProduct.selling_price = targetProduct.selling_price;
|
|
3693
3713
|
nextProduct.original_price = targetProduct.original_price;
|
|
@@ -3704,17 +3724,17 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3704
3724
|
// 新配置只传了 source 时,不能把未传的 main_product_* 从旧行继承下来。
|
|
3705
3725
|
// 以新 source + 新 option 重建券前价;券后价未显式提供时保留旧主商品折扣额。
|
|
3706
3726
|
const previousMainOriginal = new _decimal.default(Number(targetProduct.metadata?.main_product_original_price) || 0);
|
|
3707
|
-
const previousMainSelling = new _decimal.default(Number(targetProduct.metadata?.main_product_selling_price
|
|
3727
|
+
const previousMainSelling = new _decimal.default(Number(targetProduct.metadata?.main_product_selling_price ?? previousMainOriginal.toNumber()));
|
|
3708
3728
|
const preservedDiscount = previousMainOriginal.minus(previousMainSelling);
|
|
3709
3729
|
const nextMainOriginal = new _decimal.default(Number(updates.metadata.source_product_price) || 0).plus((0, _utils.sumOptionUnitPrice)((0, _utils.getProductSkuOptions)(nextProduct)));
|
|
3710
3730
|
nextProduct.metadata = {
|
|
3711
3731
|
...(nextProduct.metadata || {}),
|
|
3712
3732
|
source_product_price: String(updates.metadata.source_product_price),
|
|
3713
3733
|
main_product_original_price: callerUpdatesMainOriginalPrice ? String(updates.metadata.main_product_original_price) : nextMainOriginal.toDecimalPlaces(2).toFixed(2),
|
|
3714
|
-
main_product_selling_price: callerUpdatesMainSellingPrice ? String(updates.metadata.main_product_selling_price) : nextMainOriginal.minus(preservedDiscount).toDecimalPlaces(2).toFixed(2),
|
|
3734
|
+
main_product_selling_price: callerUpdatesMainSellingPrice ? String(updates.metadata.main_product_selling_price) : hasResolvedWeighedPrice && isManualProductDiscountProduct(nextProduct) ? previousMainSelling.toFixed(2) : nextMainOriginal.minus(preservedDiscount).toDecimalPlaces(2).toFixed(2),
|
|
3715
3735
|
price_schema_version: 2
|
|
3716
3736
|
};
|
|
3717
|
-
} else if (callerChangesVariant && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
3737
|
+
} else if (callerChangesVariant && !hasResolvedWeighedPrice && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
3718
3738
|
// variant 已变化但 caller 没有显式报价时,旧 v2 metadata 不能继续充当权威价格源。
|
|
3719
3739
|
// 清理后由 normalize 优先读取 metadata.origin.variant 中新 variant 的目录价;
|
|
3720
3740
|
// 顶层 original/selling 的旧差额仍会作为 legacy discount 迁移到新价格。
|
|
@@ -3726,7 +3746,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3726
3746
|
delete nextProduct.metadata.main_product_selling_price;
|
|
3727
3747
|
delete nextProduct.metadata.main_product_original_price;
|
|
3728
3748
|
delete nextProduct.metadata.price_schema_version;
|
|
3729
|
-
} else if (callerChangesLineConfiguration && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
3749
|
+
} else if (callerChangesLineConfiguration && !hasResolvedWeighedPrice && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
3730
3750
|
// 仅 option / bundle 变化时,保留历史 source 和主商品折扣金额,
|
|
3731
3751
|
// 但必须让 original 与 selling 一起随新的 option 金额移动。
|
|
3732
3752
|
const previousOptionSum = (0, _utils.sumOptionUnitPrice)((0, _utils.getProductSkuOptions)(targetProduct));
|
|
@@ -3743,7 +3763,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3743
3763
|
main_product_selling_price: nextMainOriginal.minus(preservedDiscount).toDecimalPlaces(2).toFixed(2),
|
|
3744
3764
|
price_schema_version: 2
|
|
3745
3765
|
};
|
|
3746
|
-
} else if (callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
3766
|
+
} else if (callerUpdatesTopPrice && !callerUpdatesMainMeta && !hasResolvedWeighedPrice) {
|
|
3747
3767
|
const existedMeta = nextProduct.metadata || {};
|
|
3748
3768
|
nextProduct.metadata = {
|
|
3749
3769
|
...existedMeta
|
|
@@ -3753,6 +3773,37 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3753
3773
|
delete nextProduct.metadata.main_product_original_price;
|
|
3754
3774
|
delete nextProduct.metadata.price_schema_version;
|
|
3755
3775
|
}
|
|
3776
|
+
if (callerChangesLineConfiguration && (0, _weighedProduct.resolveWeighedSourcePrice)(nextProduct.product_sku) !== undefined && nextProduct.metadata.main_product_original_price != null && nextProduct.metadata.main_product_selling_price != null && isManualProductDiscountProduct(nextProduct)) {
|
|
3777
|
+
const originalPrice = (0, _utils.composeLinePrice)({
|
|
3778
|
+
mainPrice: nextProduct.metadata.main_product_original_price,
|
|
3779
|
+
bundle: (0, _weighedProduct.withOriginalBundleOptionPrices)(nextProduct.product_bundle),
|
|
3780
|
+
useOriginalBundle: true
|
|
3781
|
+
});
|
|
3782
|
+
const sellingPrice = (0, _utils.composeLinePrice)({
|
|
3783
|
+
mainPrice: nextProduct.metadata.main_product_selling_price,
|
|
3784
|
+
bundle: nextProduct.product_bundle
|
|
3785
|
+
});
|
|
3786
|
+
const previousManualDiscount = (0, _manualProductDiscount.findManualProductDiscountItem)(nextProduct.discount_list);
|
|
3787
|
+
nextProduct.original_price = originalPrice;
|
|
3788
|
+
nextProduct.metadata = {
|
|
3789
|
+
...nextProduct.metadata,
|
|
3790
|
+
origin: {
|
|
3791
|
+
...nextProduct.metadata.origin,
|
|
3792
|
+
_extend: {
|
|
3793
|
+
...nextProduct.metadata.origin?._extend,
|
|
3794
|
+
origin_total: Number(originalPrice)
|
|
3795
|
+
}
|
|
3796
|
+
}
|
|
3797
|
+
};
|
|
3798
|
+
nextProduct.discount_list = (0, _manualProductDiscount.mergeManualProductDiscountIntoList)(nextProduct.discount_list, (0, _manualProductDiscount.buildManualProductDiscountItem)({
|
|
3799
|
+
originTotal: Number(originalPrice),
|
|
3800
|
+
sellingTotal: Number(sellingPrice),
|
|
3801
|
+
quantity: nextProduct.num,
|
|
3802
|
+
message: previousManualDiscount?.discount.message,
|
|
3803
|
+
discountway: previousManualDiscount?.discount.discountway,
|
|
3804
|
+
discount_per: previousManualDiscount?.discount.discount_per
|
|
3805
|
+
}));
|
|
3806
|
+
}
|
|
3756
3807
|
// normalizeOrderProduct 幂等:v2 metadata 存在 → 保留 main_product_* 折扣重算 composite;
|
|
3757
3808
|
// 否则 → 把顶层 selling_price 视作 source,派生 main_product_* 并写 price_schema_version: 2。
|
|
3758
3809
|
let normalizedProduct = this.normalizeVirtualSettlementProductIfEnabled((0, _utils.mergeOrderProductDisplayFields)(nextProduct, (0, _utils3.normalizeOrderProduct)(nextProduct)));
|
|
@@ -3790,6 +3841,10 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3790
3841
|
};
|
|
3791
3842
|
tempOrder.bookings = [...(tempOrder.bookings || []), linked.booking];
|
|
3792
3843
|
}
|
|
3844
|
+
if (callerChangesWeighing && !isManualProductDiscountProduct(normalizedProduct)) {
|
|
3845
|
+
const uid = normalizedProduct.metadata?.unique_identification_number;
|
|
3846
|
+
if (uid) reapplyWeighedDiscountProductUids?.push(String(uid));
|
|
3847
|
+
}
|
|
3793
3848
|
tempOrder.products[productIndex] = normalizedProduct;
|
|
3794
3849
|
this.syncTempOrderHolderFromBookings(tempOrder);
|
|
3795
3850
|
this.captureProductRuntime(tempOrder, updates, tempOrder.products[productIndex], tempOrder.products[productIndex].metadata?.unique_identification_number);
|
|
@@ -3797,9 +3852,11 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3797
3852
|
}
|
|
3798
3853
|
async updateOrderProduct(params) {
|
|
3799
3854
|
const tempOrder = this.ensureTempOrder();
|
|
3800
|
-
const
|
|
3855
|
+
const reapplyWeighedDiscountProductUids = [];
|
|
3856
|
+
const updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params, reapplyWeighedDiscountProductUids);
|
|
3801
3857
|
const promotionPayload = await this.evaluatePromotion();
|
|
3802
3858
|
this.applyDiscount({
|
|
3859
|
+
reapplyWeighedDiscountProductUids,
|
|
3803
3860
|
reapplyBookingDiscountProductUids: params.allow_booking_discount_reapply && updatedProductUid ? [String(updatedProductUid)] : undefined
|
|
3804
3861
|
});
|
|
3805
3862
|
this.sanitizeTempOrderProducts(tempOrder);
|
|
@@ -3818,8 +3875,9 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3818
3875
|
if (!paramsList.length) {
|
|
3819
3876
|
return tempOrder.products;
|
|
3820
3877
|
}
|
|
3878
|
+
const reapplyWeighedDiscountProductUids = [];
|
|
3821
3879
|
const reapplyBookingDiscountProductUids = paramsList.reduce((acc, params) => {
|
|
3822
|
-
const updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params);
|
|
3880
|
+
const updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params, reapplyWeighedDiscountProductUids);
|
|
3823
3881
|
// 批量改预约时间时,延迟到最后一次折扣计算里统一恢复已选预约折扣卡。
|
|
3824
3882
|
if (params.allow_booking_discount_reapply && updatedProductUid) {
|
|
3825
3883
|
acc.push(String(updatedProductUid));
|
|
@@ -3827,6 +3885,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3827
3885
|
return acc;
|
|
3828
3886
|
}, []);
|
|
3829
3887
|
await this.finalizeAfterProductsMutation(tempOrder, {
|
|
3888
|
+
reapplyWeighedDiscountProductUids,
|
|
3830
3889
|
reapplyBookingDiscountProductUids: reapplyBookingDiscountProductUids.length ? reapplyBookingDiscountProductUids : undefined
|
|
3831
3890
|
});
|
|
3832
3891
|
this.logInfo('updateOrderProduct success', {
|
|
@@ -3958,7 +4017,8 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3958
4017
|
this.syncTempOrderHolderFromBookings(tempOrder);
|
|
3959
4018
|
const promotionPayload = await this.evaluatePromotion();
|
|
3960
4019
|
this.applyDiscount({
|
|
3961
|
-
reapplyBookingDiscountProductUids: options?.reapplyBookingDiscountProductUids
|
|
4020
|
+
reapplyBookingDiscountProductUids: options?.reapplyBookingDiscountProductUids,
|
|
4021
|
+
reapplyWeighedDiscountProductUids: options?.reapplyWeighedDiscountProductUids
|
|
3962
4022
|
});
|
|
3963
4023
|
this.sanitizeTempOrderProducts(tempOrder);
|
|
3964
4024
|
await this.recalculateSummary({
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Only pricing/measurement fields participate; display and option data do not. */
|
|
2
|
+
export declare function getWeighedProductPriceFingerprint(sku?: Record<string, any>): string;
|
|
3
|
+
/**
|
|
4
|
+
* A weighed line's source is the amount for its net weight, never its catalog unit price.
|
|
5
|
+
* Persisted SKU measurements and the full catalog snapshot take priority over runtime
|
|
6
|
+
* _extend.weighing, which can survive repricing with an obsolete total_amount.
|
|
7
|
+
*/
|
|
8
|
+
export declare function resolveWeighedSourcePrice(sku?: Record<string, any>, weighing?: Record<string, any>): string | undefined;
|
|
9
|
+
/** Original bundle totals must use the nested options before manual distribution. */
|
|
10
|
+
export declare function withOriginalBundleOptionPrices(bundles?: Array<Record<string, any>>): {
|
|
11
|
+
option: any;
|
|
12
|
+
}[] | undefined;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getWeighedProductPriceFingerprint = getWeighedProductPriceFingerprint;
|
|
7
|
+
exports.resolveWeighedSourcePrice = resolveWeighedSourcePrice;
|
|
8
|
+
exports.withOriginalBundleOptionPrices = withOriginalBundleOptionPrices;
|
|
9
|
+
var _decimal = _interopRequireDefault(require("decimal.js"));
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
const UNIT_GRAMS = {
|
|
12
|
+
kg: '1000',
|
|
13
|
+
KILOGRAMS: '1000',
|
|
14
|
+
g: '1',
|
|
15
|
+
GRAMS: '1',
|
|
16
|
+
lb: '453.59237',
|
|
17
|
+
POUNDS: '453.59237',
|
|
18
|
+
oz: '28.349523125',
|
|
19
|
+
OUNCES: '28.349523125'
|
|
20
|
+
};
|
|
21
|
+
function nonNegative(value) {
|
|
22
|
+
if (value === null || value === undefined || value === '') return undefined;
|
|
23
|
+
try {
|
|
24
|
+
const result = new _decimal.default(value);
|
|
25
|
+
return result.isFinite() && result.gte(0) ? result : undefined;
|
|
26
|
+
} catch {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function numericKey(value) {
|
|
31
|
+
return nonNegative(value)?.toString();
|
|
32
|
+
}
|
|
33
|
+
function unitKey(value) {
|
|
34
|
+
return UNIT_GRAMS[String(value)] || (value == null ? undefined : String(value));
|
|
35
|
+
}
|
|
36
|
+
function snapshotKey(snapshot) {
|
|
37
|
+
return [numericKey(snapshot?.price), unitKey(snapshot?.unit), numericKey(snapshot?.unit_value ?? 1)];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Only pricing/measurement fields participate; display and option data do not. */
|
|
41
|
+
function getWeighedProductPriceFingerprint(sku) {
|
|
42
|
+
if (Number(sku?.open_sold_weight) !== 1) return 'unweighed';
|
|
43
|
+
return JSON.stringify([1, numericKey(sku?.net_weight), unitKey(sku?.unit), numericKey(sku?.unit_price), numericKey(sku?.unit_weight ?? 1), snapshotKey(sku?.unit_data_snapshot)]);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A weighed line's source is the amount for its net weight, never its catalog unit price.
|
|
48
|
+
* Persisted SKU measurements and the full catalog snapshot take priority over runtime
|
|
49
|
+
* _extend.weighing, which can survive repricing with an obsolete total_amount.
|
|
50
|
+
*/
|
|
51
|
+
function resolveWeighedSourcePrice(sku, weighing) {
|
|
52
|
+
if (sku?.open_sold_weight != null && Number(sku.open_sold_weight) !== 1) return undefined;
|
|
53
|
+
if (Number(sku?.open_sold_weight) !== 1 && !weighing) return undefined;
|
|
54
|
+
const hasSkuMeasurement = sku?.net_weight !== undefined && sku?.net_weight !== null;
|
|
55
|
+
const measurement = hasSkuMeasurement ? sku : weighing;
|
|
56
|
+
const netWeight = nonNegative(measurement?.net_weight);
|
|
57
|
+
if (netWeight === undefined) return undefined;
|
|
58
|
+
const snapshot = hasSkuMeasurement ? sku?.unit_data_snapshot : weighing?.scalePriceProduct;
|
|
59
|
+
const snapshotPrice = nonNegative(snapshot?.price);
|
|
60
|
+
const snapshotUnits = nonNegative(snapshot?.unit_value ?? 1);
|
|
61
|
+
const sourceGrams = UNIT_GRAMS[String(snapshot?.unit)];
|
|
62
|
+
const targetGrams = UNIT_GRAMS[String(measurement?.unit)];
|
|
63
|
+
if (snapshotPrice && snapshotUnits?.gt(0) && sourceGrams && targetGrams) {
|
|
64
|
+
return snapshotPrice.mul(netWeight).mul(targetGrams).div(sourceGrams).div(snapshotUnits).toFixed(2);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Legacy callers may only retain the native scale's amount. Do not let an old
|
|
68
|
+
// amount overwrite a changed SKU measurement, unit price, or pricing snapshot.
|
|
69
|
+
const runtimeAmount = nonNegative(weighing?.total_amount);
|
|
70
|
+
const runtimeMatchesSku = !hasSkuMeasurement || numericKey(weighing?.net_weight) === numericKey(sku?.net_weight) && unitKey(weighing?.unit) === unitKey(sku?.unit) && numericKey(weighing?.unit_price) === numericKey(sku?.unit_price) && numericKey(weighing?.unit_weight ?? 1) === numericKey(sku?.unit_weight ?? 1) && JSON.stringify(snapshotKey(weighing?.scalePriceProduct)) === JSON.stringify(snapshotKey(sku?.unit_data_snapshot));
|
|
71
|
+
if (runtimeAmount && runtimeMatchesSku) return runtimeAmount.toFixed(2);
|
|
72
|
+
|
|
73
|
+
// Older persisted orders have only a rounded per-scale-unit price.
|
|
74
|
+
const unitPrice = nonNegative(measurement?.unit_price);
|
|
75
|
+
const unitWeight = nonNegative(measurement?.unit_weight ?? 1);
|
|
76
|
+
if (!unitPrice || !unitWeight?.gt(0)) return undefined;
|
|
77
|
+
return netWeight.div(unitWeight).mul(unitPrice).toFixed(2);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Original bundle totals must use the nested options before manual distribution. */
|
|
81
|
+
function withOriginalBundleOptionPrices(bundles) {
|
|
82
|
+
return bundles?.map(bundle => ({
|
|
83
|
+
...bundle,
|
|
84
|
+
option: bundle.option?.map(option => ({
|
|
85
|
+
...option,
|
|
86
|
+
add_price: option.original_price ?? option.add_price ?? option.price
|
|
87
|
+
}))
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
@@ -126,11 +126,12 @@ Object.defineProperty(exports, "syncManualProductDiscountProductNum", {
|
|
|
126
126
|
});
|
|
127
127
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
128
128
|
var _decimal = _interopRequireDefault(require("decimal.js"));
|
|
129
|
+
var _weighedProduct = require("./utils/weighedProduct");
|
|
130
|
+
var _manualProductDiscount = require("./utils/manualProductDiscount");
|
|
129
131
|
var _utils = require("../Holder/utils");
|
|
130
132
|
var _utils2 = require("../../solution/ScanOrder/utils");
|
|
131
133
|
var _orderCollectionIdentity = require("./utils/orderCollectionIdentity");
|
|
132
134
|
var _salesNotes = require("./salesNotes");
|
|
133
|
-
var _manualProductDiscount = require("./utils/manualProductDiscount");
|
|
134
135
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
135
136
|
const POINT_CARD_SNAPSHOT_TAG = 'point_card';
|
|
136
137
|
function isPlainObject(value) {
|
|
@@ -773,7 +774,7 @@ function createDefaultOrderRulesHooks() {
|
|
|
773
774
|
});
|
|
774
775
|
const composedOriginalPrice = composeLinePrice({
|
|
775
776
|
mainPrice: nextMainOriginalPrice,
|
|
776
|
-
bundle: nextBundle,
|
|
777
|
+
bundle: Number(product.product_sku?.open_sold_weight) === 1 && (0, _manualProductDiscount.hasManualProductDiscountFlag)(metadataAny) ? (0, _weighedProduct.withOriginalBundleOptionPrices)(nextBundle) : nextBundle,
|
|
777
778
|
useOriginalBundle: true
|
|
778
779
|
});
|
|
779
780
|
const finalOriginalPrice = resolveManualOverrideLineOriginalPrice({
|