@pisell/pisellos 2.3.126 → 2.3.128
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/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/server/utils/small-ticket.js +1 -1
- package/dist/solution/BaseSales/index.d.ts +2 -2
- package/dist/solution/BaseSales/index.js +75 -39
- package/dist/solution/BaseSales/types.d.ts +5 -1
- 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/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/server/utils/small-ticket.js +1 -1
- package/lib/solution/BaseSales/index.d.ts +2 -2
- package/lib/solution/BaseSales/index.js +15 -6
- package/lib/solution/BaseSales/types.d.ts +5 -1
- 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/ScanOrder/utils.js +2 -1
- package/package.json +1 -1
|
@@ -110,6 +110,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
110
110
|
}>;
|
|
111
111
|
applyDiscount(options?: {
|
|
112
112
|
reapplyBookingDiscountProductUids?: string[];
|
|
113
|
+
reapplyWeighedDiscountProductUids?: string[];
|
|
113
114
|
}): void;
|
|
114
115
|
/**
|
|
115
116
|
* 注入促销评估器。
|
|
@@ -34,6 +34,7 @@ import { BaseModule } from "../BaseModule";
|
|
|
34
34
|
import { OrderHooks } from "./types";
|
|
35
35
|
import { composeLinePrice, generateDuration, getAllDiscountList, mergeRelationForms, ensureCartItemOriginHolder, buildSubmitPayload, createDefaultTempOrder, createDefaultOrderRulesHooks, createEmptySummary, createUuidV4, formatDateTime, isTempOrder, normalizeOrderMetaList, normalizeBookingIsAll, normalizeBookingSubType, mapPaymentItemsToOrderPayments, normalizeOrderProductDiscountList, resolveEffectivePerUnitDiscount, ensureProductSku, getProductSkuOptions, normalizeProductSkuOptions, sumOptionUnitPrice, clearTempOrderHolderAssignments, getOrderProductLineUid, indexOrderProductsByUid, calculateOrderProductsDeposit, collectPointCardSnapshotCodeCandidates, mergePointCardSnapshotCodes as _mergePointCardSnapshotCodes, buildVirtualCurrencySnapshotFromList, mergeOrderProductDisplayFields, resolveIsFormSubject, isMarkdownBundle } from "./utils";
|
|
36
36
|
import { isNormalProduct } from "../Product/utils";
|
|
37
|
+
import { getWeighedProductPriceFingerprint, resolveWeighedSourcePrice, withOriginalBundleOptionPrices } from "./utils/weighedProduct";
|
|
37
38
|
import dayjs from 'dayjs';
|
|
38
39
|
import { stripOsPrivatePayloadFields } from "../../utils/os-private-payload";
|
|
39
40
|
import { buildSalesNoteText, decodeSalesNotesSnapshot, getSalesNotePolicy } from "./salesNotes";
|
|
@@ -41,7 +42,7 @@ import { ensureOrderPaymentNumber, mergeOrderPaymentRecord, resolveOrderPaymentI
|
|
|
41
42
|
import { resolvePaymentNumberDevicePrefix, resolvePaymentNumberDevicePrefixFromDeviceId } from "../../utils/payment-number";
|
|
42
43
|
import { processCartPromotion, appendPromotionTags as _appendPromotionTags, getOrderProductUid as getPromotionUid, PRODUCT_LINE_MERGE_DISABLED_METADATA_KEY } from "../../solution/BaseSales/utils/cartPromotion";
|
|
43
44
|
import { buildProductLineFingerprint, getProductIdentityIndex, getSafeProductNum, isIdentityMatch, normalizeOrderProduct } from "../../solution/ScanOrder/utils";
|
|
44
|
-
import { hasManualProductDiscountFlag, syncManualProductDiscountProductNum } from "./utils/manualProductDiscount";
|
|
45
|
+
import { hasManualProductDiscountFlag, syncManualProductDiscountProductNum, buildManualProductDiscountItem, findManualProductDiscountItem, mergeManualProductDiscountIntoList } from "./utils/manualProductDiscount";
|
|
45
46
|
import { expandHydratedProductsForDiscountCollection, restoreHydratedBundleDiscounts } from "./utils/bundleDiscountHydration";
|
|
46
47
|
import { getOrderCollectionPersistentId, getOrderCollectionUid, normalizeOrderCollections, repairDuplicateProductLineIdentities as repairDuplicateOrderProductLineIdentities, setOrderCollectionUid } from "./utils/orderCollectionIdentity";
|
|
47
48
|
import { consolidateDiscountFreeProductLines, ensureUniqueProductLineUids } from "./utils/discountProductLineIdentity";
|
|
@@ -983,7 +984,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
983
984
|
},
|
|
984
985
|
orderTotalAmount: Number(((_this$store$summary2 = this.store.summary) === null || _this$store$summary2 === void 0 ? void 0 : _this$store$summary2.total_amount) || 0)
|
|
985
986
|
}, {
|
|
986
|
-
reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids
|
|
987
|
+
reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids,
|
|
988
|
+
reapplyWeighedDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyWeighedDiscountProductUids
|
|
987
989
|
});
|
|
988
990
|
if (result !== null && result !== void 0 && result.productList) {
|
|
989
991
|
var previousProductsByUid = indexOrderProductsByUid(tempOrder.products);
|
|
@@ -5262,8 +5264,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5262
5264
|
}
|
|
5263
5265
|
}, {
|
|
5264
5266
|
key: "applyOrderProductUpdateToTempOrder",
|
|
5265
|
-
value: function applyOrderProductUpdateToTempOrder(tempOrder, params) {
|
|
5266
|
-
var _targetProduct$metada2, _product_sku, _metadata2, _metadata3, _metadata4, _metadata5, _metadata6, _metadata7, _metadata8, _metadata9, _metadata10, _nextProduct$
|
|
5267
|
+
value: function applyOrderProductUpdateToTempOrder(tempOrder, params, reapplyWeighedDiscountProductUids) {
|
|
5268
|
+
var _targetProduct$metada2, _product_sku, _metadata2, _metadata3, _metadata4, _metadata5, _metadata6, _metadata7, _metadata8, _metadata9, _metadata10, _nextProduct$metadata2, _targetProduct$metada20, _tempOrder$products$p, _tempOrder$products$p2;
|
|
5267
5269
|
var product_id = params.product_id,
|
|
5268
5270
|
product_variant_id = params.product_variant_id,
|
|
5269
5271
|
updates = params.updates,
|
|
@@ -5329,7 +5331,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5329
5331
|
var previousLineFingerprint = buildProductLineFingerprint(getProductSkuOptions(targetProduct), targetProduct.product_bundle);
|
|
5330
5332
|
var nextLineFingerprint = buildProductLineFingerprint(getProductSkuOptions(nextProduct), nextProduct.product_bundle);
|
|
5331
5333
|
var callerChangesVariant = Number(product_variant_id || 0) !== Number(targetProduct.product_variant_id || 0);
|
|
5332
|
-
var
|
|
5334
|
+
var callerChangesWeighing = getWeighedProductPriceFingerprint(targetProduct.product_sku) !== getWeighedProductPriceFingerprint(nextProduct.product_sku);
|
|
5335
|
+
var callerChangesLineConfiguration = callerChangesVariant || callerChangesWeighing || previousLineFingerprint !== nextLineFingerprint;
|
|
5333
5336
|
var isPersistedOrderLine = targetProduct.order_detail_id !== undefined && targetProduct.order_detail_id !== null;
|
|
5334
5337
|
var callerChangesDiscountList = Array.isArray(updates === null || updates === void 0 ? void 0 : updates.discount_list) && updates.discount_list.length > 0 && !isSameDiscountList(updates.discount_list, targetProduct.discount_list);
|
|
5335
5338
|
var callerUpdatesManualPrice = (updates === null || updates === void 0 || (_metadata8 = updates.metadata) === null || _metadata8 === void 0 ? void 0 : _metadata8.price_override) !== undefined || (updates === null || updates === void 0 || (_metadata9 = updates.metadata) === null || _metadata9 === void 0 ? void 0 : _metadata9.is_manual_discount) !== undefined || (updates === null || updates === void 0 || (_metadata10 = updates.metadata) === null || _metadata10 === void 0 ? void 0 : _metadata10.product_discount_reason) !== undefined || callerChangesDiscountList;
|
|
@@ -5345,33 +5348,50 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5345
5348
|
};
|
|
5346
5349
|
return hasChangedPrice(updates.selling_price, targetProduct.selling_price) || hasChangedPrice(updates.original_price, targetProduct.original_price);
|
|
5347
5350
|
}();
|
|
5351
|
+
var weighedSourcePrice = callerChangesWeighing ? resolveWeighedSourcePrice(nextProduct.product_sku) : undefined;
|
|
5352
|
+
var hasResolvedWeighedPrice = weighedSourcePrice !== undefined;
|
|
5353
|
+
if (hasResolvedWeighedPrice && !callerUpdatesSourcePrice) {
|
|
5354
|
+
var _ref78, _targetProduct$metada3, _targetProduct$metada4, _ref79, _targetProduct$metada5, _targetProduct$metada6;
|
|
5355
|
+
var nextMainOriginal = new Decimal(weighedSourcePrice).plus(sumOptionUnitPrice(getProductSkuOptions(nextProduct)));
|
|
5356
|
+
var previousMainOriginal = new Decimal((_ref78 = (_targetProduct$metada3 = (_targetProduct$metada4 = targetProduct.metadata) === null || _targetProduct$metada4 === void 0 ? void 0 : _targetProduct$metada4.main_product_original_price) !== null && _targetProduct$metada3 !== void 0 ? _targetProduct$metada3 : targetProduct.original_price) !== null && _ref78 !== void 0 ? _ref78 : 0);
|
|
5357
|
+
var previousMainSelling = new Decimal((_ref79 = (_targetProduct$metada5 = (_targetProduct$metada6 = targetProduct.metadata) === null || _targetProduct$metada6 === void 0 ? void 0 : _targetProduct$metada6.main_product_selling_price) !== null && _targetProduct$metada5 !== void 0 ? _targetProduct$metada5 : targetProduct.selling_price) !== null && _ref79 !== void 0 ? _ref79 : 0);
|
|
5358
|
+
// A manual final price remains fixed; other legacy discounts keep their amount
|
|
5359
|
+
// until Rules reapplies the currently selected wallet discount below.
|
|
5360
|
+
var nextMainSelling = isManualProductDiscountProduct(nextProduct) ? previousMainSelling : nextMainOriginal.minus(previousMainOriginal.minus(previousMainSelling));
|
|
5361
|
+
nextProduct.metadata = _objectSpread(_objectSpread({}, nextProduct.metadata), {}, {
|
|
5362
|
+
source_product_price: weighedSourcePrice,
|
|
5363
|
+
main_product_original_price: callerUpdatesMainOriginalPrice ? nextProduct.metadata.main_product_original_price : nextMainOriginal.toFixed(2),
|
|
5364
|
+
main_product_selling_price: callerUpdatesMainSellingPrice ? nextProduct.metadata.main_product_selling_price : Decimal.max(0, nextMainSelling).toFixed(2),
|
|
5365
|
+
price_schema_version: 2
|
|
5366
|
+
});
|
|
5367
|
+
}
|
|
5348
5368
|
if (isPersistedOrderLine && !callerChangesLineConfiguration && !callerUpdatesManualPrice && !callerAllowsBookingReprice) {
|
|
5349
|
-
var _targetProduct$
|
|
5369
|
+
var _targetProduct$metada7, _targetProduct$metada8, _targetProduct$metada9, _targetProduct$metada10, _targetProduct$metada11;
|
|
5350
5370
|
nextProduct.selling_price = targetProduct.selling_price;
|
|
5351
5371
|
nextProduct.original_price = targetProduct.original_price;
|
|
5352
5372
|
nextProduct.payment_price = targetProduct.payment_price;
|
|
5353
5373
|
nextProduct.metadata = _objectSpread(_objectSpread({}, nextProduct.metadata || {}), {}, {
|
|
5354
|
-
source_product_price: (_targetProduct$
|
|
5355
|
-
main_product_selling_price: (_targetProduct$
|
|
5356
|
-
main_product_original_price: (_targetProduct$
|
|
5357
|
-
price_schema_version: (_targetProduct$
|
|
5374
|
+
source_product_price: (_targetProduct$metada7 = targetProduct.metadata) === null || _targetProduct$metada7 === void 0 ? void 0 : _targetProduct$metada7.source_product_price,
|
|
5375
|
+
main_product_selling_price: (_targetProduct$metada8 = targetProduct.metadata) === null || _targetProduct$metada8 === void 0 ? void 0 : _targetProduct$metada8.main_product_selling_price,
|
|
5376
|
+
main_product_original_price: (_targetProduct$metada9 = targetProduct.metadata) === null || _targetProduct$metada9 === void 0 ? void 0 : _targetProduct$metada9.main_product_original_price,
|
|
5377
|
+
price_schema_version: (_targetProduct$metada10 = (_targetProduct$metada11 = targetProduct.metadata) === null || _targetProduct$metada11 === void 0 ? void 0 : _targetProduct$metada11.price_schema_version) !== null && _targetProduct$metada10 !== void 0 ? _targetProduct$metada10 : 2
|
|
5358
5378
|
});
|
|
5359
5379
|
nextProduct.product_bundle = this.preservePersistedBundlePriceFields(targetProduct.product_bundle, nextProduct.product_bundle);
|
|
5360
5380
|
} else if (callerChangesLineConfiguration && callerUpdatesSourcePrice && (!callerUpdatesMainSellingPrice || !callerUpdatesMainOriginalPrice)) {
|
|
5361
|
-
var _targetProduct$
|
|
5381
|
+
var _targetProduct$metada12, _targetProduct$metada13, _targetProduct$metada14;
|
|
5362
5382
|
// 新配置只传了 source 时,不能把未传的 main_product_* 从旧行继承下来。
|
|
5363
5383
|
// 以新 source + 新 option 重建券前价;券后价未显式提供时保留旧主商品折扣额。
|
|
5364
|
-
var
|
|
5365
|
-
var
|
|
5366
|
-
var preservedDiscount =
|
|
5367
|
-
var
|
|
5384
|
+
var _previousMainOriginal = new Decimal(Number((_targetProduct$metada12 = targetProduct.metadata) === null || _targetProduct$metada12 === void 0 ? void 0 : _targetProduct$metada12.main_product_original_price) || 0);
|
|
5385
|
+
var _previousMainSelling = new Decimal(Number((_targetProduct$metada13 = (_targetProduct$metada14 = targetProduct.metadata) === null || _targetProduct$metada14 === void 0 ? void 0 : _targetProduct$metada14.main_product_selling_price) !== null && _targetProduct$metada13 !== void 0 ? _targetProduct$metada13 : _previousMainOriginal.toNumber()));
|
|
5386
|
+
var preservedDiscount = _previousMainOriginal.minus(_previousMainSelling);
|
|
5387
|
+
var _nextMainOriginal = new Decimal(Number(updates.metadata.source_product_price) || 0).plus(sumOptionUnitPrice(getProductSkuOptions(nextProduct)));
|
|
5368
5388
|
nextProduct.metadata = _objectSpread(_objectSpread({}, nextProduct.metadata || {}), {}, {
|
|
5369
5389
|
source_product_price: String(updates.metadata.source_product_price),
|
|
5370
|
-
main_product_original_price: callerUpdatesMainOriginalPrice ? String(updates.metadata.main_product_original_price) :
|
|
5371
|
-
main_product_selling_price: callerUpdatesMainSellingPrice ? String(updates.metadata.main_product_selling_price) :
|
|
5390
|
+
main_product_original_price: callerUpdatesMainOriginalPrice ? String(updates.metadata.main_product_original_price) : _nextMainOriginal.toDecimalPlaces(2).toFixed(2),
|
|
5391
|
+
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),
|
|
5372
5392
|
price_schema_version: 2
|
|
5373
5393
|
});
|
|
5374
|
-
} else if (callerChangesVariant && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
5394
|
+
} else if (callerChangesVariant && !hasResolvedWeighedPrice && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
5375
5395
|
// variant 已变化但 caller 没有显式报价时,旧 v2 metadata 不能继续充当权威价格源。
|
|
5376
5396
|
// 清理后由 normalize 优先读取 metadata.origin.variant 中新 variant 的目录价;
|
|
5377
5397
|
// 顶层 original/selling 的旧差额仍会作为 legacy discount 迁移到新价格。
|
|
@@ -5381,24 +5401,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5381
5401
|
delete nextProduct.metadata.main_product_selling_price;
|
|
5382
5402
|
delete nextProduct.metadata.main_product_original_price;
|
|
5383
5403
|
delete nextProduct.metadata.price_schema_version;
|
|
5384
|
-
} else if (callerChangesLineConfiguration && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
5385
|
-
var
|
|
5404
|
+
} else if (callerChangesLineConfiguration && !hasResolvedWeighedPrice && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
5405
|
+
var _ref80, _targetProduct$metada15, _targetProduct$metada16, _ref81, _targetProduct$metada17, _targetProduct$metada18, _targetProduct$metada19;
|
|
5386
5406
|
// 仅 option / bundle 变化时,保留历史 source 和主商品折扣金额,
|
|
5387
5407
|
// 但必须让 original 与 selling 一起随新的 option 金额移动。
|
|
5388
5408
|
var previousOptionSum = sumOptionUnitPrice(getProductSkuOptions(targetProduct));
|
|
5389
5409
|
var nextOptionSum = sumOptionUnitPrice(getProductSkuOptions(nextProduct));
|
|
5390
|
-
var
|
|
5391
|
-
var
|
|
5392
|
-
var _preservedDiscount =
|
|
5393
|
-
var previousSource = ((_targetProduct$
|
|
5394
|
-
var
|
|
5410
|
+
var _previousMainOriginal2 = new Decimal(Number((_ref80 = (_targetProduct$metada15 = (_targetProduct$metada16 = targetProduct.metadata) === null || _targetProduct$metada16 === void 0 ? void 0 : _targetProduct$metada16.main_product_original_price) !== null && _targetProduct$metada15 !== void 0 ? _targetProduct$metada15 : targetProduct.original_price) !== null && _ref80 !== void 0 ? _ref80 : 0) || 0);
|
|
5411
|
+
var _previousMainSelling2 = new Decimal(Number((_ref81 = (_targetProduct$metada17 = (_targetProduct$metada18 = targetProduct.metadata) === null || _targetProduct$metada18 === void 0 ? void 0 : _targetProduct$metada18.main_product_selling_price) !== null && _targetProduct$metada17 !== void 0 ? _targetProduct$metada17 : targetProduct.selling_price) !== null && _ref81 !== void 0 ? _ref81 : _previousMainOriginal2.toNumber()) || 0);
|
|
5412
|
+
var _preservedDiscount = _previousMainOriginal2.minus(_previousMainSelling2);
|
|
5413
|
+
var previousSource = ((_targetProduct$metada19 = targetProduct.metadata) === null || _targetProduct$metada19 === void 0 ? void 0 : _targetProduct$metada19.source_product_price) != null ? new Decimal(Number(targetProduct.metadata.source_product_price) || 0) : _previousMainOriginal2.minus(previousOptionSum);
|
|
5414
|
+
var _nextMainOriginal2 = previousSource.plus(nextOptionSum);
|
|
5395
5415
|
nextProduct.metadata = _objectSpread(_objectSpread({}, nextProduct.metadata || {}), {}, {
|
|
5396
5416
|
source_product_price: previousSource.toDecimalPlaces(2).toFixed(2),
|
|
5397
|
-
main_product_original_price:
|
|
5398
|
-
main_product_selling_price:
|
|
5417
|
+
main_product_original_price: _nextMainOriginal2.toDecimalPlaces(2).toFixed(2),
|
|
5418
|
+
main_product_selling_price: _nextMainOriginal2.minus(_preservedDiscount).toDecimalPlaces(2).toFixed(2),
|
|
5399
5419
|
price_schema_version: 2
|
|
5400
5420
|
});
|
|
5401
|
-
} else if (callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
5421
|
+
} else if (callerUpdatesTopPrice && !callerUpdatesMainMeta && !hasResolvedWeighedPrice) {
|
|
5402
5422
|
var _existedMeta = nextProduct.metadata || {};
|
|
5403
5423
|
nextProduct.metadata = _objectSpread({}, _existedMeta);
|
|
5404
5424
|
delete nextProduct.metadata.source_product_price;
|
|
@@ -5406,11 +5426,40 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5406
5426
|
delete nextProduct.metadata.main_product_original_price;
|
|
5407
5427
|
delete nextProduct.metadata.price_schema_version;
|
|
5408
5428
|
}
|
|
5429
|
+
if (callerChangesLineConfiguration && resolveWeighedSourcePrice(nextProduct.product_sku) !== undefined && nextProduct.metadata.main_product_original_price != null && nextProduct.metadata.main_product_selling_price != null && isManualProductDiscountProduct(nextProduct)) {
|
|
5430
|
+
var _nextProduct$metadata;
|
|
5431
|
+
var originalPrice = composeLinePrice({
|
|
5432
|
+
mainPrice: nextProduct.metadata.main_product_original_price,
|
|
5433
|
+
bundle: withOriginalBundleOptionPrices(nextProduct.product_bundle),
|
|
5434
|
+
useOriginalBundle: true
|
|
5435
|
+
});
|
|
5436
|
+
var sellingPrice = composeLinePrice({
|
|
5437
|
+
mainPrice: nextProduct.metadata.main_product_selling_price,
|
|
5438
|
+
bundle: nextProduct.product_bundle
|
|
5439
|
+
});
|
|
5440
|
+
var previousManualDiscount = findManualProductDiscountItem(nextProduct.discount_list);
|
|
5441
|
+
nextProduct.original_price = originalPrice;
|
|
5442
|
+
nextProduct.metadata = _objectSpread(_objectSpread({}, nextProduct.metadata), {}, {
|
|
5443
|
+
origin: _objectSpread(_objectSpread({}, nextProduct.metadata.origin), {}, {
|
|
5444
|
+
_extend: _objectSpread(_objectSpread({}, (_nextProduct$metadata = nextProduct.metadata.origin) === null || _nextProduct$metadata === void 0 ? void 0 : _nextProduct$metadata._extend), {}, {
|
|
5445
|
+
origin_total: Number(originalPrice)
|
|
5446
|
+
})
|
|
5447
|
+
})
|
|
5448
|
+
});
|
|
5449
|
+
nextProduct.discount_list = mergeManualProductDiscountIntoList(nextProduct.discount_list, buildManualProductDiscountItem({
|
|
5450
|
+
originTotal: Number(originalPrice),
|
|
5451
|
+
sellingTotal: Number(sellingPrice),
|
|
5452
|
+
quantity: nextProduct.num,
|
|
5453
|
+
message: previousManualDiscount === null || previousManualDiscount === void 0 ? void 0 : previousManualDiscount.discount.message,
|
|
5454
|
+
discountway: previousManualDiscount === null || previousManualDiscount === void 0 ? void 0 : previousManualDiscount.discount.discountway,
|
|
5455
|
+
discount_per: previousManualDiscount === null || previousManualDiscount === void 0 ? void 0 : previousManualDiscount.discount.discount_per
|
|
5456
|
+
}));
|
|
5457
|
+
}
|
|
5409
5458
|
// normalizeOrderProduct 幂等:v2 metadata 存在 → 保留 main_product_* 折扣重算 composite;
|
|
5410
5459
|
// 否则 → 把顶层 selling_price 视作 source,派生 main_product_* 并写 price_schema_version: 2。
|
|
5411
5460
|
var normalizedProduct = this.normalizeVirtualSettlementProductIfEnabled(mergeOrderProductDisplayFields(nextProduct, normalizeOrderProduct(nextProduct)));
|
|
5412
5461
|
normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
|
|
5413
|
-
var preservedBookingUid = nextProduct.booking_uid || ((_nextProduct$
|
|
5462
|
+
var preservedBookingUid = nextProduct.booking_uid || ((_nextProduct$metadata2 = nextProduct.metadata) === null || _nextProduct$metadata2 === void 0 ? void 0 : _nextProduct$metadata2.booking_uid) || targetProduct.booking_uid || ((_targetProduct$metada20 = targetProduct.metadata) === null || _targetProduct$metada20 === void 0 ? void 0 : _targetProduct$metada20.booking_uid);
|
|
5414
5463
|
if (!booking && preservedBookingUid) {
|
|
5415
5464
|
normalizedProduct.booking_uid = preservedBookingUid;
|
|
5416
5465
|
normalizedProduct.metadata = _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
|
|
@@ -5418,8 +5467,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5418
5467
|
});
|
|
5419
5468
|
}
|
|
5420
5469
|
if (booking) {
|
|
5421
|
-
var _normalizedProduct$me, _targetProduct$
|
|
5422
|
-
var productUid = String(((_normalizedProduct$me = normalizedProduct.metadata) === null || _normalizedProduct$me === void 0 ? void 0 : _normalizedProduct$me.unique_identification_number) || ((_targetProduct$
|
|
5470
|
+
var _normalizedProduct$me, _targetProduct$metada21;
|
|
5471
|
+
var productUid = String(((_normalizedProduct$me = normalizedProduct.metadata) === null || _normalizedProduct$me === void 0 ? void 0 : _normalizedProduct$me.unique_identification_number) || ((_targetProduct$metada21 = targetProduct.metadata) === null || _targetProduct$metada21 === void 0 ? void 0 : _targetProduct$metada21.unique_identification_number) || unique_identification_number || createUuidV4());
|
|
5423
5472
|
normalizedProduct.metadata = _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
|
|
5424
5473
|
unique_identification_number: productUid
|
|
5425
5474
|
});
|
|
@@ -5439,6 +5488,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5439
5488
|
});
|
|
5440
5489
|
tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
|
|
5441
5490
|
}
|
|
5491
|
+
if (callerChangesWeighing && !isManualProductDiscountProduct(normalizedProduct)) {
|
|
5492
|
+
var _normalizedProduct$me2;
|
|
5493
|
+
var uid = (_normalizedProduct$me2 = normalizedProduct.metadata) === null || _normalizedProduct$me2 === void 0 ? void 0 : _normalizedProduct$me2.unique_identification_number;
|
|
5494
|
+
if (uid) reapplyWeighedDiscountProductUids === null || reapplyWeighedDiscountProductUids === void 0 || reapplyWeighedDiscountProductUids.push(String(uid));
|
|
5495
|
+
}
|
|
5442
5496
|
tempOrder.products[productIndex] = normalizedProduct;
|
|
5443
5497
|
this.syncTempOrderHolderFromBookings(tempOrder);
|
|
5444
5498
|
this.captureProductRuntime(tempOrder, updates, tempOrder.products[productIndex], (_tempOrder$products$p = tempOrder.products[productIndex].metadata) === null || _tempOrder$products$p === void 0 ? void 0 : _tempOrder$products$p.unique_identification_number);
|
|
@@ -5448,32 +5502,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5448
5502
|
key: "updateOrderProduct",
|
|
5449
5503
|
value: function () {
|
|
5450
5504
|
var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
|
|
5451
|
-
var tempOrder, updatedProductUid, promotionPayload;
|
|
5505
|
+
var tempOrder, reapplyWeighedDiscountProductUids, updatedProductUid, promotionPayload;
|
|
5452
5506
|
return _regeneratorRuntime().wrap(function _callee25$(_context27) {
|
|
5453
5507
|
while (1) switch (_context27.prev = _context27.next) {
|
|
5454
5508
|
case 0:
|
|
5455
5509
|
tempOrder = this.ensureTempOrder();
|
|
5456
|
-
|
|
5457
|
-
|
|
5510
|
+
reapplyWeighedDiscountProductUids = [];
|
|
5511
|
+
updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params, reapplyWeighedDiscountProductUids);
|
|
5512
|
+
_context27.next = 5;
|
|
5458
5513
|
return this.evaluatePromotion();
|
|
5459
|
-
case
|
|
5514
|
+
case 5:
|
|
5460
5515
|
promotionPayload = _context27.sent;
|
|
5461
5516
|
this.applyDiscount({
|
|
5517
|
+
reapplyWeighedDiscountProductUids: reapplyWeighedDiscountProductUids,
|
|
5462
5518
|
reapplyBookingDiscountProductUids: params.allow_booking_discount_reapply && updatedProductUid ? [String(updatedProductUid)] : undefined
|
|
5463
5519
|
});
|
|
5464
5520
|
this.sanitizeTempOrderProducts(tempOrder);
|
|
5465
|
-
_context27.next =
|
|
5521
|
+
_context27.next = 10;
|
|
5466
5522
|
return this.recalculateSummary({
|
|
5467
5523
|
createIfMissing: true
|
|
5468
5524
|
});
|
|
5469
|
-
case
|
|
5525
|
+
case 10:
|
|
5470
5526
|
this.persistTempOrder();
|
|
5471
5527
|
this.emitPromotionApplied(promotionPayload);
|
|
5472
5528
|
this.logInfo('updateOrderProduct success', {
|
|
5473
5529
|
params: params
|
|
5474
5530
|
});
|
|
5475
5531
|
return _context27.abrupt("return", tempOrder.products);
|
|
5476
|
-
case
|
|
5532
|
+
case 14:
|
|
5477
5533
|
case "end":
|
|
5478
5534
|
return _context27.stop();
|
|
5479
5535
|
}
|
|
@@ -5489,7 +5545,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5489
5545
|
value: function () {
|
|
5490
5546
|
var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(paramsList) {
|
|
5491
5547
|
var _this34 = this;
|
|
5492
|
-
var tempOrder, reapplyBookingDiscountProductUids;
|
|
5548
|
+
var tempOrder, reapplyWeighedDiscountProductUids, reapplyBookingDiscountProductUids;
|
|
5493
5549
|
return _regeneratorRuntime().wrap(function _callee26$(_context28) {
|
|
5494
5550
|
while (1) switch (_context28.prev = _context28.next) {
|
|
5495
5551
|
case 0:
|
|
@@ -5500,24 +5556,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5500
5556
|
}
|
|
5501
5557
|
return _context28.abrupt("return", tempOrder.products);
|
|
5502
5558
|
case 3:
|
|
5559
|
+
reapplyWeighedDiscountProductUids = [];
|
|
5503
5560
|
reapplyBookingDiscountProductUids = paramsList.reduce(function (acc, params) {
|
|
5504
|
-
var updatedProductUid = _this34.applyOrderProductUpdateToTempOrder(tempOrder, params);
|
|
5561
|
+
var updatedProductUid = _this34.applyOrderProductUpdateToTempOrder(tempOrder, params, reapplyWeighedDiscountProductUids);
|
|
5505
5562
|
// 批量改预约时间时,延迟到最后一次折扣计算里统一恢复已选预约折扣卡。
|
|
5506
5563
|
if (params.allow_booking_discount_reapply && updatedProductUid) {
|
|
5507
5564
|
acc.push(String(updatedProductUid));
|
|
5508
5565
|
}
|
|
5509
5566
|
return acc;
|
|
5510
5567
|
}, []);
|
|
5511
|
-
_context28.next =
|
|
5568
|
+
_context28.next = 7;
|
|
5512
5569
|
return this.finalizeAfterProductsMutation(tempOrder, {
|
|
5570
|
+
reapplyWeighedDiscountProductUids: reapplyWeighedDiscountProductUids,
|
|
5513
5571
|
reapplyBookingDiscountProductUids: reapplyBookingDiscountProductUids.length ? reapplyBookingDiscountProductUids : undefined
|
|
5514
5572
|
});
|
|
5515
|
-
case
|
|
5573
|
+
case 7:
|
|
5516
5574
|
this.logInfo('updateOrderProduct success', {
|
|
5517
5575
|
paramsList: paramsList
|
|
5518
5576
|
});
|
|
5519
5577
|
return _context28.abrupt("return", tempOrder.products);
|
|
5520
|
-
case
|
|
5578
|
+
case 9:
|
|
5521
5579
|
case "end":
|
|
5522
5580
|
return _context28.stop();
|
|
5523
5581
|
}
|
|
@@ -5532,7 +5590,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5532
5590
|
key: "updateOrderProductQuantity",
|
|
5533
5591
|
value: function () {
|
|
5534
5592
|
var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
|
|
5535
|
-
var _targetProduct$
|
|
5593
|
+
var _targetProduct$metada22;
|
|
5536
5594
|
var product_id, product_variant_id, num, unique_identification_number, identity_key, product_sku, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct, settlementSnapshot, currencyProductId, asset, requiredAmount, balance, isVirtualSettlement, promotionPayload;
|
|
5537
5595
|
return _regeneratorRuntime().wrap(function _callee27$(_context29) {
|
|
5538
5596
|
while (1) switch (_context29.prev = _context29.next) {
|
|
@@ -5574,7 +5632,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5574
5632
|
normalizedProduct = this.normalizeVirtualSettlementProductIfEnabled(normalizeOrderProduct(_objectSpread(_objectSpread({}, targetProduct), {}, {
|
|
5575
5633
|
num: getSafeProductNum(num),
|
|
5576
5634
|
metadata: _objectSpread(_objectSpread({}, targetProduct.metadata || {}), {}, {
|
|
5577
|
-
unique_identification_number: ((_targetProduct$
|
|
5635
|
+
unique_identification_number: ((_targetProduct$metada22 = targetProduct.metadata) === null || _targetProduct$metada22 === void 0 ? void 0 : _targetProduct$metada22.unique_identification_number) || unique_identification_number
|
|
5578
5636
|
})
|
|
5579
5637
|
})));
|
|
5580
5638
|
normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
|
|
@@ -5695,7 +5753,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5695
5753
|
case 3:
|
|
5696
5754
|
promotionPayload = _context30.sent;
|
|
5697
5755
|
this.applyDiscount({
|
|
5698
|
-
reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids
|
|
5756
|
+
reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids,
|
|
5757
|
+
reapplyWeighedDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyWeighedDiscountProductUids
|
|
5699
5758
|
});
|
|
5700
5759
|
this.sanitizeTempOrderProducts(tempOrder);
|
|
5701
5760
|
_context30.next = 8;
|
|
@@ -6007,23 +6066,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
6007
6066
|
}, {
|
|
6008
6067
|
key: "buildCurrentSubmitPayloadForLocalPrint",
|
|
6009
6068
|
value: function buildCurrentSubmitPayloadForLocalPrint(params) {
|
|
6010
|
-
var _params$cacheId, _this$otherParams5,
|
|
6069
|
+
var _params$cacheId, _this$otherParams5, _ref82, _params$businessCode, _this$otherParams6, _this$otherParams7;
|
|
6011
6070
|
var tempOrder = this.ensureTempOrder();
|
|
6012
6071
|
this.persistTempOrder();
|
|
6013
6072
|
var payload = buildSubmitPayload({
|
|
6014
6073
|
tempOrder: tempOrder,
|
|
6015
6074
|
cacheId: (_params$cacheId = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId !== void 0 ? _params$cacheId : this.cacheId,
|
|
6016
6075
|
platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.platform),
|
|
6017
|
-
businessCode: (
|
|
6076
|
+
businessCode: (_ref82 = (_params$businessCode = params === null || params === void 0 ? void 0 : params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.businessCode) !== null && _ref82 !== void 0 ? _ref82 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.business_code,
|
|
6018
6077
|
channel: params === null || params === void 0 ? void 0 : params.channel,
|
|
6019
6078
|
type: params === null || params === void 0 ? void 0 : params.type,
|
|
6020
6079
|
summary: this.store.summary || createEmptySummary(),
|
|
6021
6080
|
enhance: function enhance(nextPayload) {
|
|
6022
|
-
var
|
|
6081
|
+
var _ref83, _tempOrder$order_numb, _ref84, _tempOrder$shop_order2, _ref85, _tempOrder$shop_full_;
|
|
6023
6082
|
return _objectSpread(_objectSpread({}, nextPayload), {}, {
|
|
6024
|
-
order_number: (
|
|
6025
|
-
shop_order_number: (
|
|
6026
|
-
shop_full_order_number: (
|
|
6083
|
+
order_number: (_ref83 = (_tempOrder$order_numb = tempOrder.order_number) !== null && _tempOrder$order_numb !== void 0 ? _tempOrder$order_numb : nextPayload.order_number) !== null && _ref83 !== void 0 ? _ref83 : null,
|
|
6084
|
+
shop_order_number: (_ref84 = (_tempOrder$shop_order2 = tempOrder.shop_order_number) !== null && _tempOrder$shop_order2 !== void 0 ? _tempOrder$shop_order2 : nextPayload.shop_order_number) !== null && _ref84 !== void 0 ? _ref84 : null,
|
|
6085
|
+
shop_full_order_number: (_ref85 = (_tempOrder$shop_full_ = tempOrder.shop_full_order_number) !== null && _tempOrder$shop_full_ !== void 0 ? _tempOrder$shop_full_ : nextPayload.shop_full_order_number) !== null && _ref85 !== void 0 ? _ref85 : null,
|
|
6027
6086
|
small_ticket_data_flag: 1
|
|
6028
6087
|
});
|
|
6029
6088
|
}
|
|
@@ -6187,7 +6246,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
6187
6246
|
key: "runSubmitTempOrder",
|
|
6188
6247
|
value: function () {
|
|
6189
6248
|
var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(params) {
|
|
6190
|
-
var _params$cacheId3, _this$otherParams12,
|
|
6249
|
+
var _params$cacheId3, _this$otherParams12, _ref86, _ref87, _submitSnapshot$busin, _this$otherParams13, _this$otherParams14, _submitSnapshot$type;
|
|
6191
6250
|
var tempOrder, isOnlineStorePlatform, shouldConfirmPendingVoucherPayments, hasPaymentOverride, preparedPaymentOverride, latestSummary, effectiveCacheId, hasPaymentStatusOverride, shouldOverridePaymentStatus, hasSmallTicketDataFlagOverride, enhancePayload, submitSnapshot, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, isLocalPendingSubmit, salesNotesState, submittedOrderId, resultRecord;
|
|
6192
6251
|
return _regeneratorRuntime().wrap(function _callee37$(_context40) {
|
|
6193
6252
|
while (1) switch (_context40.prev = _context40.next) {
|
|
@@ -6254,7 +6313,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
6254
6313
|
tempOrder: tempOrder,
|
|
6255
6314
|
cacheId: effectiveCacheId,
|
|
6256
6315
|
platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12.platform),
|
|
6257
|
-
businessCode: (
|
|
6316
|
+
businessCode: (_ref86 = (_ref87 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref87 !== void 0 ? _ref87 : (_this$otherParams13 = this.otherParams) === null || _this$otherParams13 === void 0 ? void 0 : _this$otherParams13.businessCode) !== null && _ref86 !== void 0 ? _ref86 : (_this$otherParams14 = this.otherParams) === null || _this$otherParams14 === void 0 ? void 0 : _this$otherParams14.business_code,
|
|
6258
6317
|
channel: params === null || params === void 0 ? void 0 : params.channel,
|
|
6259
6318
|
type: (_submitSnapshot$type = submitSnapshot.type) !== null && _submitSnapshot$type !== void 0 ? _submitSnapshot$type : params === null || params === void 0 ? void 0 : params.type,
|
|
6260
6319
|
summary: latestSummary,
|
|
@@ -7374,7 +7433,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
7374
7433
|
_step24;
|
|
7375
7434
|
try {
|
|
7376
7435
|
for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
|
|
7377
|
-
var _product$metadata12,
|
|
7436
|
+
var _product$metadata12, _ref88, _ref89, _existed$origin, _rawProduct$metadata;
|
|
7378
7437
|
var _step24$value = _slicedToArray(_step24.value, 2),
|
|
7379
7438
|
index = _step24$value[0],
|
|
7380
7439
|
product = _step24$value[1];
|
|
@@ -7382,7 +7441,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
7382
7441
|
if (!uid) continue;
|
|
7383
7442
|
var existed = productsByUid[uid] && _typeof(productsByUid[uid]) === 'object' ? productsByUid[uid] : {};
|
|
7384
7443
|
var rawProduct = rawProducts[index] && _typeof(rawProducts[index]) === 'object' ? rawProducts[index] : product;
|
|
7385
|
-
var origin = (
|
|
7444
|
+
var origin = (_ref88 = (_ref89 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref89 !== void 0 ? _ref89 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref88 !== void 0 ? _ref88 : rawProduct;
|
|
7386
7445
|
var originSnapshot = cloneDeep(origin);
|
|
7387
7446
|
var productOptionString = this.buildHydratedProductOptionString(rawProduct) || this.buildHydratedProductOptionString(product);
|
|
7388
7447
|
if (productOptionString && originSnapshot && _typeof(originSnapshot) === 'object') {
|
|
@@ -7511,10 +7570,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
7511
7570
|
}, {
|
|
7512
7571
|
key: "normalizeHydratedProductOptionItem",
|
|
7513
7572
|
value: function normalizeHydratedProductOptionItem(optionItem) {
|
|
7514
|
-
var
|
|
7515
|
-
var rawNum = (
|
|
7573
|
+
var _ref90, _optionItem$num, _ref91, _optionItem$add_price;
|
|
7574
|
+
var rawNum = (_ref90 = (_optionItem$num = optionItem === null || optionItem === void 0 ? void 0 : optionItem.num) !== null && _optionItem$num !== void 0 ? _optionItem$num : optionItem === null || optionItem === void 0 ? void 0 : optionItem.quantity) !== null && _ref90 !== void 0 ? _ref90 : 1;
|
|
7516
7575
|
var parsedNum = Number(rawNum);
|
|
7517
|
-
var rawPrice = (
|
|
7576
|
+
var rawPrice = (_ref91 = (_optionItem$add_price = optionItem === null || optionItem === void 0 ? void 0 : optionItem.add_price) !== null && _optionItem$add_price !== void 0 ? _optionItem$add_price : optionItem === null || optionItem === void 0 ? void 0 : optionItem.price) !== null && _ref91 !== void 0 ? _ref91 : 0;
|
|
7518
7577
|
var parsedPrice = Number(rawPrice);
|
|
7519
7578
|
var normalized = _objectSpread(_objectSpread({}, optionItem), {}, {
|
|
7520
7579
|
option_group_item_id: optionItem === null || optionItem === void 0 ? void 0 : optionItem.option_group_item_id,
|
|
@@ -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,94 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
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
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
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 Decimal from 'decimal.js';
|
|
8
|
+
var UNIT_GRAMS = {
|
|
9
|
+
kg: '1000',
|
|
10
|
+
KILOGRAMS: '1000',
|
|
11
|
+
g: '1',
|
|
12
|
+
GRAMS: '1',
|
|
13
|
+
lb: '453.59237',
|
|
14
|
+
POUNDS: '453.59237',
|
|
15
|
+
oz: '28.349523125',
|
|
16
|
+
OUNCES: '28.349523125'
|
|
17
|
+
};
|
|
18
|
+
function nonNegative(value) {
|
|
19
|
+
if (value === null || value === undefined || value === '') return undefined;
|
|
20
|
+
try {
|
|
21
|
+
var result = new Decimal(value);
|
|
22
|
+
return result.isFinite() && result.gte(0) ? result : undefined;
|
|
23
|
+
} catch (_unused) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function numericKey(value) {
|
|
28
|
+
var _nonNegative;
|
|
29
|
+
return (_nonNegative = nonNegative(value)) === null || _nonNegative === void 0 ? void 0 : _nonNegative.toString();
|
|
30
|
+
}
|
|
31
|
+
function unitKey(value) {
|
|
32
|
+
return UNIT_GRAMS[String(value)] || (value == null ? undefined : String(value));
|
|
33
|
+
}
|
|
34
|
+
function snapshotKey(snapshot) {
|
|
35
|
+
var _snapshot$unit_value;
|
|
36
|
+
return [numericKey(snapshot === null || snapshot === void 0 ? void 0 : snapshot.price), unitKey(snapshot === null || snapshot === void 0 ? void 0 : snapshot.unit), numericKey((_snapshot$unit_value = snapshot === null || snapshot === void 0 ? void 0 : snapshot.unit_value) !== null && _snapshot$unit_value !== void 0 ? _snapshot$unit_value : 1)];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Only pricing/measurement fields participate; display and option data do not. */
|
|
40
|
+
export function getWeighedProductPriceFingerprint(sku) {
|
|
41
|
+
var _sku$unit_weight;
|
|
42
|
+
if (Number(sku === null || sku === void 0 ? void 0 : sku.open_sold_weight) !== 1) return 'unweighed';
|
|
43
|
+
return JSON.stringify([1, numericKey(sku === null || sku === void 0 ? void 0 : sku.net_weight), unitKey(sku === null || sku === void 0 ? void 0 : sku.unit), numericKey(sku === null || sku === void 0 ? void 0 : sku.unit_price), numericKey((_sku$unit_weight = sku === null || sku === void 0 ? void 0 : sku.unit_weight) !== null && _sku$unit_weight !== void 0 ? _sku$unit_weight : 1), snapshotKey(sku === null || sku === void 0 ? void 0 : 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
|
+
export function resolveWeighedSourcePrice(sku, weighing) {
|
|
52
|
+
var _snapshot$unit_value2, _weighing$unit_weight, _sku$unit_weight2, _measurement$unit_wei;
|
|
53
|
+
if ((sku === null || sku === void 0 ? void 0 : sku.open_sold_weight) != null && Number(sku.open_sold_weight) !== 1) return undefined;
|
|
54
|
+
if (Number(sku === null || sku === void 0 ? void 0 : sku.open_sold_weight) !== 1 && !weighing) return undefined;
|
|
55
|
+
var hasSkuMeasurement = (sku === null || sku === void 0 ? void 0 : sku.net_weight) !== undefined && (sku === null || sku === void 0 ? void 0 : sku.net_weight) !== null;
|
|
56
|
+
var measurement = hasSkuMeasurement ? sku : weighing;
|
|
57
|
+
var netWeight = nonNegative(measurement === null || measurement === void 0 ? void 0 : measurement.net_weight);
|
|
58
|
+
if (netWeight === undefined) return undefined;
|
|
59
|
+
var snapshot = hasSkuMeasurement ? sku === null || sku === void 0 ? void 0 : sku.unit_data_snapshot : weighing === null || weighing === void 0 ? void 0 : weighing.scalePriceProduct;
|
|
60
|
+
var snapshotPrice = nonNegative(snapshot === null || snapshot === void 0 ? void 0 : snapshot.price);
|
|
61
|
+
var snapshotUnits = nonNegative((_snapshot$unit_value2 = snapshot === null || snapshot === void 0 ? void 0 : snapshot.unit_value) !== null && _snapshot$unit_value2 !== void 0 ? _snapshot$unit_value2 : 1);
|
|
62
|
+
var sourceGrams = UNIT_GRAMS[String(snapshot === null || snapshot === void 0 ? void 0 : snapshot.unit)];
|
|
63
|
+
var targetGrams = UNIT_GRAMS[String(measurement === null || measurement === void 0 ? void 0 : measurement.unit)];
|
|
64
|
+
if (snapshotPrice && snapshotUnits !== null && snapshotUnits !== void 0 && snapshotUnits.gt(0) && sourceGrams && targetGrams) {
|
|
65
|
+
return snapshotPrice.mul(netWeight).mul(targetGrams).div(sourceGrams).div(snapshotUnits).toFixed(2);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Legacy callers may only retain the native scale's amount. Do not let an old
|
|
69
|
+
// amount overwrite a changed SKU measurement, unit price, or pricing snapshot.
|
|
70
|
+
var runtimeAmount = nonNegative(weighing === null || weighing === void 0 ? void 0 : weighing.total_amount);
|
|
71
|
+
var runtimeMatchesSku = !hasSkuMeasurement || numericKey(weighing === null || weighing === void 0 ? void 0 : weighing.net_weight) === numericKey(sku === null || sku === void 0 ? void 0 : sku.net_weight) && unitKey(weighing === null || weighing === void 0 ? void 0 : weighing.unit) === unitKey(sku === null || sku === void 0 ? void 0 : sku.unit) && numericKey(weighing === null || weighing === void 0 ? void 0 : weighing.unit_price) === numericKey(sku === null || sku === void 0 ? void 0 : sku.unit_price) && numericKey((_weighing$unit_weight = weighing === null || weighing === void 0 ? void 0 : weighing.unit_weight) !== null && _weighing$unit_weight !== void 0 ? _weighing$unit_weight : 1) === numericKey((_sku$unit_weight2 = sku === null || sku === void 0 ? void 0 : sku.unit_weight) !== null && _sku$unit_weight2 !== void 0 ? _sku$unit_weight2 : 1) && JSON.stringify(snapshotKey(weighing === null || weighing === void 0 ? void 0 : weighing.scalePriceProduct)) === JSON.stringify(snapshotKey(sku === null || sku === void 0 ? void 0 : sku.unit_data_snapshot));
|
|
72
|
+
if (runtimeAmount && runtimeMatchesSku) return runtimeAmount.toFixed(2);
|
|
73
|
+
|
|
74
|
+
// Older persisted orders have only a rounded per-scale-unit price.
|
|
75
|
+
var unitPrice = nonNegative(measurement === null || measurement === void 0 ? void 0 : measurement.unit_price);
|
|
76
|
+
var unitWeight = nonNegative((_measurement$unit_wei = measurement === null || measurement === void 0 ? void 0 : measurement.unit_weight) !== null && _measurement$unit_wei !== void 0 ? _measurement$unit_wei : 1);
|
|
77
|
+
if (!unitPrice || !(unitWeight !== null && unitWeight !== void 0 && unitWeight.gt(0))) return undefined;
|
|
78
|
+
return netWeight.div(unitWeight).mul(unitPrice).toFixed(2);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Original bundle totals must use the nested options before manual distribution. */
|
|
82
|
+
export function withOriginalBundleOptionPrices(bundles) {
|
|
83
|
+
return bundles === null || bundles === void 0 ? void 0 : bundles.map(function (bundle) {
|
|
84
|
+
var _bundle$option;
|
|
85
|
+
return _objectSpread(_objectSpread({}, bundle), {}, {
|
|
86
|
+
option: (_bundle$option = bundle.option) === null || _bundle$option === void 0 ? void 0 : _bundle$option.map(function (option) {
|
|
87
|
+
var _ref, _option$original_pric;
|
|
88
|
+
return _objectSpread(_objectSpread({}, option), {}, {
|
|
89
|
+
add_price: (_ref = (_option$original_pric = option.original_price) !== null && _option$original_pric !== void 0 ? _option$original_pric : option.add_price) !== null && _ref !== void 0 ? _ref : option.price
|
|
90
|
+
});
|
|
91
|
+
})
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
@@ -24,6 +24,8 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
24
24
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
25
25
|
import dayjs from "dayjs";
|
|
26
26
|
import Decimal from 'decimal.js';
|
|
27
|
+
import { withOriginalBundleOptionPrices } from "./utils/weighedProduct";
|
|
28
|
+
import { hasManualProductDiscountFlag } from "./utils/manualProductDiscount";
|
|
27
29
|
import { getProductHolderConfig } from "../Holder/utils";
|
|
28
30
|
import { buildProductLineFingerprint, createEmptySummary } from "../../solution/ScanOrder/utils";
|
|
29
31
|
import { createUuidV4 } from "./utils/orderCollectionIdentity";
|
|
@@ -856,7 +858,7 @@ export function createDefaultOrderRulesHooks() {
|
|
|
856
858
|
};
|
|
857
859
|
},
|
|
858
860
|
setProduct: function setProduct(product, values) {
|
|
859
|
-
var _ref28, _values$quantity, _ref29, _metadataAny$source_p, _values$discount_list, _values$quantity2;
|
|
861
|
+
var _ref28, _values$quantity, _ref29, _metadataAny$source_p, _product$product_sku, _values$discount_list, _values$quantity2;
|
|
860
862
|
var nextNum = Number((_ref28 = (_values$quantity = values.quantity) !== null && _values$quantity !== void 0 ? _values$quantity : product.num) !== null && _ref28 !== void 0 ? _ref28 : 1) || 1;
|
|
861
863
|
var metadataAny = product.metadata || {};
|
|
862
864
|
var existedSource = (_ref29 = (_metadataAny$source_p = metadataAny.source_product_price) !== null && _metadataAny$source_p !== void 0 ? _metadataAny$source_p : product.selling_price) !== null && _ref29 !== void 0 ? _ref29 : '0';
|
|
@@ -882,7 +884,7 @@ export function createDefaultOrderRulesHooks() {
|
|
|
882
884
|
});
|
|
883
885
|
var composedOriginalPrice = composeLinePrice({
|
|
884
886
|
mainPrice: nextMainOriginalPrice,
|
|
885
|
-
bundle: nextBundle,
|
|
887
|
+
bundle: Number((_product$product_sku = product.product_sku) === null || _product$product_sku === void 0 ? void 0 : _product$product_sku.open_sold_weight) === 1 && hasManualProductDiscountFlag(metadataAny) ? withOriginalBundleOptionPrices(nextBundle) : nextBundle,
|
|
886
888
|
useOriginalBundle: true
|
|
887
889
|
});
|
|
888
890
|
var finalOriginalPrice = resolveManualOverrideLineOriginalPrice({
|
|
@@ -1586,11 +1588,11 @@ export function mapPaymentItemsToOrderPayments(paymentItems) {
|
|
|
1586
1588
|
*/
|
|
1587
1589
|
export function formatV1Product(products) {
|
|
1588
1590
|
return products.map(function (product) {
|
|
1589
|
-
var _product$
|
|
1591
|
+
var _product$product_sku2, _product$note;
|
|
1590
1592
|
return {
|
|
1591
1593
|
bundle: product.product_bundle,
|
|
1592
1594
|
key: product.product_id,
|
|
1593
|
-
option: ((_product$
|
|
1595
|
+
option: ((_product$product_sku2 = product.product_sku) === null || _product$product_sku2 === void 0 ? void 0 : _product$product_sku2.option) || [],
|
|
1594
1596
|
product_id: product.product_id,
|
|
1595
1597
|
product_variant_id: product.product_variant_id,
|
|
1596
1598
|
num: product.product_quantity,
|
|
@@ -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
|
}
|