@pisell/pisellos 2.2.198 → 2.2.199

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +7 -3
  2. package/dist/modules/Cart/utils/cartProduct.js +11 -1
  3. package/dist/modules/Cart/utils/changePrice.js +11 -11
  4. package/dist/modules/Order/index.js +155 -104
  5. package/dist/modules/Order/types.d.ts +1 -0
  6. package/dist/modules/Order/utils.d.ts +33 -2
  7. package/dist/modules/Order/utils.js +112 -55
  8. package/dist/modules/SalesSummary/utils.js +97 -63
  9. package/dist/server/index.d.ts +3 -0
  10. package/dist/server/index.js +294 -190
  11. package/dist/server/modules/order/index.d.ts +8 -0
  12. package/dist/server/modules/order/index.js +536 -317
  13. package/dist/server/modules/order/types.d.ts +2 -0
  14. package/dist/solution/BaseSales/index.js +2 -1
  15. package/dist/solution/BaseSales/types.d.ts +1 -0
  16. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +19 -4
  17. package/dist/solution/BookingByStep/index.d.ts +1 -1
  18. package/dist/solution/ScanOrder/types.d.ts +1 -0
  19. package/dist/solution/ScanOrder/utils.js +26 -9
  20. package/dist/solution/VenueBooking/index.js +2 -1
  21. package/lib/model/strategy/adapter/promotion/index.js +49 -0
  22. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +4 -1
  23. package/lib/modules/Cart/utils/cartProduct.js +11 -1
  24. package/lib/modules/Cart/utils/changePrice.js +12 -20
  25. package/lib/modules/Order/index.js +58 -6
  26. package/lib/modules/Order/types.d.ts +1 -0
  27. package/lib/modules/Order/utils.d.ts +33 -2
  28. package/lib/modules/Order/utils.js +44 -9
  29. package/lib/modules/SalesSummary/utils.js +41 -44
  30. package/lib/server/index.d.ts +3 -0
  31. package/lib/server/index.js +82 -3
  32. package/lib/server/modules/order/index.d.ts +8 -0
  33. package/lib/server/modules/order/index.js +106 -4
  34. package/lib/server/modules/order/types.d.ts +2 -0
  35. package/lib/solution/BaseSales/index.js +2 -1
  36. package/lib/solution/BaseSales/types.d.ts +1 -0
  37. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +15 -1
  38. package/lib/solution/BookingByStep/index.d.ts +1 -1
  39. package/lib/solution/ScanOrder/types.d.ts +1 -0
  40. package/lib/solution/ScanOrder/utils.js +28 -10
  41. package/lib/solution/VenueBooking/index.js +2 -1
  42. package/package.json +1 -1
@@ -393,6 +393,8 @@ export interface OrderData {
393
393
  /** 本地辅助字段 */
394
394
  shop_id?: number;
395
395
  create_date?: string;
396
+ /** 本地待同步标记:1 表示需要后续同步到云端 */
397
+ need_sync?: 0 | 1 | number;
396
398
  /** 兼容:部分场景仍使用顶层 total_amount */
397
399
  total_amount?: OrderMoneyString | number;
398
400
  /** 扩展字段(物流、标签等);使用 any 以便筛选与数据源扩展 */
@@ -2033,7 +2033,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2033
2033
  var products = tempOrder === null || tempOrder === void 0 || (_tempOrder$products2 = tempOrder.products) === null || _tempOrder$products2 === void 0 ? void 0 : _tempOrder$products2.filter(function (n) {
2034
2034
  return n.product_id;
2035
2035
  });
2036
- return products.map(function (product) {
2036
+ var walletProducts = products.map(function (product) {
2037
2037
  var _product$product_vari2, _product$is_charge_ta, _product$holder_id, _metadata$main_produc, _metadata$main_produc2;
2038
2038
  var metadata = product.metadata || {};
2039
2039
  return {
@@ -2079,6 +2079,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2079
2079
  })
2080
2080
  };
2081
2081
  });
2082
+ return walletProducts;
2082
2083
  }
2083
2084
  }, {
2084
2085
  key: "initWalletData",
@@ -126,6 +126,7 @@ export interface BaseSalesSummary {
126
126
  shipping_tax_fee: string;
127
127
  tax_fee: string;
128
128
  surcharge_fee: string;
129
+ surcharges?: any[];
129
130
  discount_amount: string;
130
131
  deposit_amount: string;
131
132
  deposit?: {
@@ -4,7 +4,7 @@ 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 { composeLinePrice, normalizeProductSkuOptions, sumOptionUnitPrice } from "../../../modules/Order/utils";
7
+ import { composeLinePrice, getBundleSellingMagnitude, normalizeProductSkuOptions, sumOptionUnitPrice } from "../../../modules/Order/utils";
8
8
  import { buildManualProductDiscountItem, mergeManualProductDiscountIntoList, resolveManualDiscountOriginTotal, resolveManualDiscountReasonFromSources, shouldBuildManualProductDiscount } from "../../../modules/Order/utils/manualProductDiscount";
9
9
  function toNumber(value) {
10
10
  var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
@@ -49,18 +49,33 @@ function normalizeBundleItems(bundleItems) {
49
49
  var preferPriceField = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
50
50
  if (!Array.isArray(bundleItems)) return [];
51
51
  return bundleItems.map(function (bundleItem) {
52
- var _ref2, _ref3, _ref4, _bundleItem$price, _ref5, _ref6, _ref7, _bundleItem$bundle_se, _bundleItem$num, _bundleItem$quantity, _bundleItem$price2, _ref8, _ref9, _bundleItem$original_;
52
+ var _ref2, _ref3, _ref4, _bundleItem$price, _ref5, _ref6, _ref7, _bundleItem$bundle_se, _bundleItem$num, _bundleItem$price2, _bundleItem$quantity, _bundleItem$price3, _ref8, _ref9, _bundleItem$original_, _normalizedItem$price;
53
53
  var unitSelling = preferPriceField ? (_ref2 = (_ref3 = (_ref4 = (_bundleItem$price = bundleItem.price) !== null && _bundleItem$price !== void 0 ? _bundleItem$price : bundleItem.bundle_selling_price) !== null && _ref4 !== void 0 ? _ref4 : bundleItem.custom_price) !== null && _ref3 !== void 0 ? _ref3 : bundleItem.product_price) !== null && _ref2 !== void 0 ? _ref2 : '0' : (_ref5 = (_ref6 = (_ref7 = (_bundleItem$bundle_se = bundleItem.bundle_selling_price) !== null && _bundleItem$bundle_se !== void 0 ? _bundleItem$bundle_se : bundleItem.price) !== null && _ref7 !== void 0 ? _ref7 : bundleItem.custom_price) !== null && _ref6 !== void 0 ? _ref6 : bundleItem.product_price) !== null && _ref5 !== void 0 ? _ref5 : '0';
54
54
  var unitStr = toPriceString(unitSelling, '0.00');
55
55
  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);
56
- return _objectSpread(_objectSpread({}, bundleItem), {}, {
56
+ var magnitudeSource = _objectSpread(_objectSpread({}, bundleItem), {}, {
57
+ option: normalizeOptionItems(bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.option),
58
+ bundle_selling_price: unitStr,
59
+ // 计算 markdown 净额时,只传真实毛价;仅有 bundle_selling_price 时按历史净额兜底。
60
+ price: (_bundleItem$price2 = bundleItem.price) !== null && _bundleItem$price2 !== void 0 ? _bundleItem$price2 : bundleItem.custom_price
61
+ });
62
+ var normalizedItem = _objectSpread(_objectSpread({}, bundleItem), {}, {
57
63
  num: num,
58
64
  quantity: (_bundleItem$quantity = bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.quantity) !== null && _bundleItem$quantity !== void 0 ? _bundleItem$quantity : num,
59
- price: (_bundleItem$price2 = bundleItem.price) !== null && _bundleItem$price2 !== void 0 ? _bundleItem$price2 : unitStr,
65
+ // price 保留毛价(markdown 仍为正),由 price_type 决定符号。
66
+ price: (_bundleItem$price3 = bundleItem.price) !== null && _bundleItem$price3 !== void 0 ? _bundleItem$price3 : unitStr,
60
67
  bundle_selling_price: unitStr,
61
68
  original_price: (_ref8 = (_ref9 = (_bundleItem$original_ = bundleItem.original_price) !== null && _bundleItem$original_ !== void 0 ? _bundleItem$original_ : bundleItem.product_price) !== null && _ref9 !== void 0 ? _ref9 : bundleItem.price) !== null && _ref8 !== void 0 ? _ref8 : unitStr,
62
69
  option: normalizeOptionItems(bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.option)
63
70
  });
71
+ // bundle_selling_price 落「正净额」:markdown = |price| − Σoptions;markup/原价维持原值。
72
+ normalizedItem.bundle_selling_price = getBundleSellingMagnitude(magnitudeSource).toFixed(2);
73
+ if (((_normalizedItem$price = normalizedItem.price_type) !== null && _normalizedItem$price !== void 0 ? _normalizedItem$price : normalizedItem.custom_price_type) === 'markdown' && (normalizedItem.price_type_ext === '' || normalizedItem.price_type_ext === undefined || normalizedItem.price_type_ext === null)) {
74
+ var _normalizedItem$custo;
75
+ normalizedItem.custom_price = (_normalizedItem$custo = normalizedItem.custom_price) !== null && _normalizedItem$custo !== void 0 ? _normalizedItem$custo : normalizedItem.price;
76
+ normalizedItem.price = normalizedItem.bundle_selling_price;
77
+ }
78
+ return normalizedItem;
64
79
  });
65
80
  }
66
81
  function findVariantById(origin, variantId) {
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
311
311
  date: string;
312
312
  status: string;
313
313
  week: string;
314
- weekNum: 0 | 2 | 1 | 6 | 3 | 4 | 5;
314
+ weekNum: 0 | 1 | 2 | 3 | 5 | 4 | 6;
315
315
  }[]>;
316
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
317
317
  private getScheduleDataByIds;
@@ -115,6 +115,7 @@ export interface ScanOrderSummary {
115
115
  shipping_tax_fee: string;
116
116
  tax_fee: string;
117
117
  surcharge_fee: string;
118
+ surcharges: any[];
118
119
  discount_amount: string;
119
120
  deposit_amount: string;
120
121
  deposit?: {
@@ -13,7 +13,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
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
14
  import dayjs from 'dayjs';
15
15
  import Decimal from 'decimal.js';
16
- import { composeLinePrice, createUuidV4, ensureProductSku, getProductSkuOptions, normalizeProductSkuOptions, resolveManualOverrideLineOriginalPrice, sumOptionUnitPrice } from "../../modules/Order/utils";
16
+ import { composeLinePrice, createUuidV4, ensureProductSku, getBundleSellingMagnitude, getProductSkuOptions, normalizeProductSkuOptions, resolveManualOverrideLineOriginalPrice, sumOptionUnitPrice } from "../../modules/Order/utils";
17
17
  import { ensureManualProductDiscountList } from "../../modules/Order/utils/manualProductDiscount";
18
18
 
19
19
  /**
@@ -31,6 +31,7 @@ export function createEmptySummary() {
31
31
  shipping_tax_fee: '0.00',
32
32
  tax_fee: '0.00',
33
33
  surcharge_fee: '0.00',
34
+ surcharges: [],
34
35
  discount_amount: '0.00',
35
36
  deposit_amount: '0.00',
36
37
  expect_amount: '0.00',
@@ -510,16 +511,32 @@ export function normalizeOrderProduct(product) {
510
511
  });
511
512
  }
512
513
  var normalizedBundle = bundleInput.map(function (item) {
513
- var _item$bundle_id2, _item$bundle_product_, _item$bundle_group_id, _ref5, _item$bundle_selling_, _ref6, _ref7, _item$price2, _ref8, _item$price_type, _ref9, _item$price_type_ext;
514
- return _objectSpread(_objectSpread({}, item), {}, {
514
+ var _item$price2, _item$bundle_id2, _item$bundle_product_, _item$bundle_group_id, _ref5, _ref6, _item$price3, _ref7, _item$price_type, _ref8, _item$price_type_ext;
515
+ var magnitudeSource = _objectSpread(_objectSpread({}, item), {}, {
516
+ // 计算 markdown 净额时,只把真实毛价交给 helper;若只有 bundle_selling_price,
517
+ // helper 会按历史净额兜底,避免 option 二次扣减。
518
+ price: (_item$price2 = item.price) !== null && _item$price2 !== void 0 ? _item$price2 : item.custom_price
519
+ });
520
+ var normalizedItem = _objectSpread(_objectSpread({}, item), {}, {
515
521
  bundle_id: (_item$bundle_id2 = item.bundle_id) !== null && _item$bundle_id2 !== void 0 ? _item$bundle_id2 : item.id,
516
522
  bundle_product_id: (_item$bundle_product_ = item.bundle_product_id) !== null && _item$bundle_product_ !== void 0 ? _item$bundle_product_ : item._bundle_product_id,
517
523
  bundle_group_id: (_item$bundle_group_id = item.bundle_group_id) !== null && _item$bundle_group_id !== void 0 ? _item$bundle_group_id : item.group_id,
518
- bundle_selling_price: (_ref5 = (_item$bundle_selling_ = item.bundle_selling_price) !== null && _item$bundle_selling_ !== void 0 ? _item$bundle_selling_ : item.price) !== null && _ref5 !== void 0 ? _ref5 : '0.00',
519
- price: (_ref6 = (_ref7 = (_item$price2 = item.price) !== null && _item$price2 !== void 0 ? _item$price2 : item.custom_price) !== null && _ref7 !== void 0 ? _ref7 : item.bundle_selling_price) !== null && _ref6 !== void 0 ? _ref6 : '0.00',
520
- price_type: (_ref8 = (_item$price_type = item.price_type) !== null && _item$price_type !== void 0 ? _item$price_type : item.custom_price_type) !== null && _ref8 !== void 0 ? _ref8 : '',
521
- price_type_ext: (_ref9 = (_item$price_type_ext = item.price_type_ext) !== null && _item$price_type_ext !== void 0 ? _item$price_type_ext : item.custom_price_type_ext) !== null && _ref9 !== void 0 ? _ref9 : ''
524
+ // price 保留毛价(markdown 仍为 5),由 price_type 决定符号。
525
+ price: (_ref5 = (_ref6 = (_item$price3 = item.price) !== null && _item$price3 !== void 0 ? _item$price3 : item.custom_price) !== null && _ref6 !== void 0 ? _ref6 : item.bundle_selling_price) !== null && _ref5 !== void 0 ? _ref5 : '0.00',
526
+ price_type: (_ref7 = (_item$price_type = item.price_type) !== null && _item$price_type !== void 0 ? _item$price_type : item.custom_price_type) !== null && _ref7 !== void 0 ? _ref7 : '',
527
+ price_type_ext: (_ref8 = (_item$price_type_ext = item.price_type_ext) !== null && _item$price_type_ext !== void 0 ? _item$price_type_ext : item.custom_price_type_ext) !== null && _ref8 !== void 0 ? _ref8 : ''
522
528
  });
529
+ // bundle_selling_price 落「正净额」:markdown = |price| − Σoptions;markup/原价维持原值。
530
+ normalizedItem.bundle_selling_price = getBundleSellingMagnitude(magnitudeSource).toFixed(2);
531
+ if (normalizedItem.price_type === 'markdown' && (normalizedItem.price_type_ext === '' || normalizedItem.price_type_ext === undefined || normalizedItem.price_type_ext === null)) {
532
+ var _normalizedItem$custo;
533
+ normalizedItem.custom_price = (_normalizedItem$custo = normalizedItem.custom_price) !== null && _normalizedItem$custo !== void 0 ? _normalizedItem$custo : normalizedItem.price;
534
+ normalizedItem.price = normalizedItem.bundle_selling_price;
535
+ }
536
+ if ((normalizedItem.price_type === 'markdown' || normalizedItem.price_type === 'markup') && (normalizedItem.price_type_ext === '' || normalizedItem.price_type_ext === undefined || normalizedItem.price_type_ext === null)) {
537
+ delete normalizedItem.original_total;
538
+ }
539
+ return normalizedItem;
523
540
  });
524
541
  var normalizedOptions = normalizeProductSkuOptions((_product$product_sku = product.product_sku) === null || _product$product_sku === void 0 ? void 0 : _product$product_sku.option);
525
542
  var optionSum = sumOptionUnitPrice(normalizedOptions);
@@ -541,7 +558,7 @@ export function normalizeOrderProduct(product) {
541
558
  var variantPrice = Array.isArray(variantList) ? (_variantList$find = variantList.find(function (v) {
542
559
  return Number(v === null || v === void 0 ? void 0 : v.id) === variantId;
543
560
  })) === null || _variantList$find === void 0 ? void 0 : _variantList$find.price : undefined;
544
- var resolvedSource = function (_product$_origin, _product$_origin2, _ref10, _product$original_pri) {
561
+ var resolvedSource = function (_product$_origin, _product$_origin2, _ref9, _product$original_pri) {
545
562
  if (metadata.source_product_price !== undefined) {
546
563
  return String(metadata.source_product_price);
547
564
  }
@@ -559,7 +576,7 @@ export function normalizeOrderProduct(product) {
559
576
  if (!isV2 && metadata.main_product_original_price !== undefined) {
560
577
  return String(metadata.main_product_original_price);
561
578
  }
562
- return (_ref10 = (_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : product.selling_price) !== null && _ref10 !== void 0 ? _ref10 : '0.00';
579
+ return (_ref9 = (_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : product.selling_price) !== null && _ref9 !== void 0 ? _ref9 : '0.00';
563
580
  }();
564
581
 
565
582
  // 2) 派生 main_product_original_price(含 option、不含折扣)
@@ -2295,7 +2295,8 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
2295
2295
  key: "getOrderProducts",
2296
2296
  value: function getOrderProducts() {
2297
2297
  if (!this.store.order) throw new Error('order 模块未初始化');
2298
- return this.store.order.getOrderProducts();
2298
+ var products = this.store.order.getOrderProducts();
2299
+ return products;
2299
2300
  }
2300
2301
  }, {
2301
2302
  key: "getSummary",
@@ -0,0 +1,49 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/model/strategy/adapter/promotion/index.ts
30
+ var promotion_exports = {};
31
+ __export(promotion_exports, {
32
+ BUY_X_GET_Y_FREE_STRATEGY: () => import_examples.BUY_X_GET_Y_FREE_STRATEGY,
33
+ PromotionAdapter: () => import_adapter.PromotionAdapter,
34
+ PromotionEvaluator: () => import_evaluator.PromotionEvaluator,
35
+ X_ITEMS_FOR_Y_PRICE_STRATEGY: () => import_examples.X_ITEMS_FOR_Y_PRICE_STRATEGY,
36
+ default: () => import_adapter2.default
37
+ });
38
+ module.exports = __toCommonJS(promotion_exports);
39
+ var import_evaluator = require("./evaluator");
40
+ var import_adapter = require("./adapter");
41
+ var import_adapter2 = __toESM(require("./adapter"));
42
+ var import_examples = require("./examples");
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ BUY_X_GET_Y_FREE_STRATEGY,
46
+ PromotionAdapter,
47
+ PromotionEvaluator,
48
+ X_ITEMS_FOR_Y_PRICE_STRATEGY
49
+ });
@@ -64,11 +64,14 @@ function mapOrderBundleToOtherBundle(bundle) {
64
64
  const catalogOriginal = item.original_price ?? item.product_price ?? item.price ?? item.bundle_selling_price;
65
65
  const selling = item.bundle_selling_price ?? item.price ?? catalogOriginal;
66
66
  const { bundle_selling_price: _omitBundleSelling, ...rest } = item;
67
+ const isMarkupOrMarkdown = (item.price_type === "markdown" || item.price_type === "markup") && (item.price_type_ext === "" || item.price_type_ext === void 0 || item.price_type_ext === null);
68
+ if (isMarkupOrMarkdown)
69
+ delete rest.original_total;
67
70
  return {
68
71
  ...rest,
69
72
  price: selling,
70
73
  original_price: catalogOriginal,
71
- original_total: item.original_total ?? catalogOriginal,
74
+ ...isMarkupOrMarkdown ? {} : { original_total: item.original_total ?? catalogOriginal },
72
75
  num: item.num ?? item.quantity ?? 1,
73
76
  quantity: item.quantity ?? item.num ?? 1
74
77
  };
@@ -46,6 +46,7 @@ var import_decimal = __toESM(require("decimal.js"));
46
46
  var import_utils = require("../../Product/utils");
47
47
  var import_utils2 = require("../../../solution/ShopDiscount/utils");
48
48
  var import_utils3 = require("../../Summary/utils");
49
+ var import_utils4 = require("../../Order/utils");
49
50
  var toDiscountPayload = (discountItem) => {
50
51
  var _a, _b;
51
52
  return {
@@ -337,6 +338,15 @@ var formatBundleToOrigin = (bundle) => {
337
338
  var _a;
338
339
  return pre + (((_a = cur == null ? void 0 : cur.metadata) == null ? void 0 : _a.product_discount_difference) || 0);
339
340
  }, 0);
341
+ const normalizedBundle = {
342
+ ...d,
343
+ // 计算 markdown 净额时只传真实毛价;若仅有 bundle_selling_price,则由 helper 当历史净额兜底。
344
+ price: (d == null ? void 0 : d.price) ?? (d == null ? void 0 : d.custom_price),
345
+ bundle_selling_price: d == null ? void 0 : d.bundle_selling_price,
346
+ price_type: (d == null ? void 0 : d.price_type) ?? (d == null ? void 0 : d.custom_price_type),
347
+ price_type_ext: (d == null ? void 0 : d.price_type_ext) ?? (d == null ? void 0 : d.custom_price_type_ext),
348
+ option: getBundleValueByKey("option")
349
+ };
340
350
  return {
341
351
  bundle_group_id: getBundleValueByKey("group_id"),
342
352
  bundle_id: d.id,
@@ -347,7 +357,7 @@ var formatBundleToOrigin = (bundle) => {
347
357
  extension_type: getBundleValueByKey("extension_type"),
348
358
  option: formatOptionsToOrigin(getBundleValueByKey("option")),
349
359
  discount_list: d.discount_list,
350
- "bundle_selling_price": d == null ? void 0 : d.price,
360
+ "bundle_selling_price": (0, import_utils4.getBundleSellingMagnitude)(normalizedBundle).toFixed(2),
351
361
  "custom_price": d == null ? void 0 : d.price,
352
362
  metadata: {
353
363
  custom_product_bundle_map_id: d._id,
@@ -1,8 +1,6 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
5
  var __export = (target, all) => {
8
6
  for (var name in all)
@@ -16,14 +14,6 @@ var __copyProps = (to, from, except, desc) => {
16
14
  }
17
15
  return to;
18
16
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
18
 
29
19
  // src/modules/Cart/utils/changePrice.ts
@@ -32,7 +22,7 @@ __export(changePrice_exports, {
32
22
  updateAllCartItemPrice: () => updateAllCartItemPrice
33
23
  });
34
24
  module.exports = __toCommonJS(changePrice_exports);
35
- var import_decimal = __toESM(require("decimal.js"));
25
+ var import_utils = require("../../Order/utils");
36
26
  async function updateAllCartItemPrice(cartItems, priceData, getProduct, updateCart, updateItemInitInfo) {
37
27
  var _a, _b;
38
28
  for (const item of cartItems) {
@@ -57,18 +47,20 @@ async function updateAllCartItemPrice(cartItems, priceData, getProduct, updateCa
57
47
  const targetBundleItem = targetBundle.bundle_item.find(
58
48
  (m) => m.id === n.id
59
49
  );
60
- if (targetBundleItem.price_type === "markdown") {
61
- targetBundleItem.price = new import_decimal.default(targetBundleItem.price || 0).mul(-1).toNumber();
62
- }
63
- if (n.option) {
64
- targetBundleItem.price = new import_decimal.default(targetBundleItem.price || 0).add(n.option.reduce((pre, cur) => {
65
- return pre + new import_decimal.default(cur.price || 0).mul(cur.num || 1).toNumber();
66
- }, 0)).toNumber();
67
- }
68
50
  if (targetBundleItem) {
69
- return {
51
+ const normalizedBundle = {
70
52
  ...n,
71
53
  price: targetBundleItem.price,
54
+ custom_price: targetBundleItem.price,
55
+ price_type: targetBundleItem.price_type,
56
+ price_type_ext: targetBundleItem.price_type_ext
57
+ };
58
+ const bundleSellingPrice = (0, import_utils.getBundleSellingMagnitude)(normalizedBundle).toFixed(2);
59
+ return {
60
+ ...n,
61
+ custom_price: targetBundleItem.price,
62
+ price: targetBundleItem.price_type === "markdown" ? bundleSellingPrice : targetBundleItem.price,
63
+ bundle_selling_price: bundleSellingPrice,
72
64
  base_price: targetBundleItem.base_price
73
65
  };
74
66
  }
@@ -891,6 +891,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
891
891
  "surcharge_rounding_remainder",
892
892
  "tax_fee_rounding_remainder"
893
893
  ];
894
+ const metadataMoneyKeys = [
895
+ "main_product_attached_bundle_selling_price",
896
+ "main_product_attached_bundle_payment_price"
897
+ ];
894
898
  for (const product of products || []) {
895
899
  const productRecord = product;
896
900
  const metadata = productRecord.metadata && typeof productRecord.metadata === "object" ? { ...productRecord.metadata } : {};
@@ -902,10 +906,26 @@ var OrderModule = class extends import_BaseModule.BaseModule {
902
906
  metadata[key] = value;
903
907
  hasMetadataPatch = true;
904
908
  }
909
+ for (const key of metadataMoneyKeys) {
910
+ const value = this.formatSummaryMetadataMoney(metadata[key]);
911
+ if (value === void 0)
912
+ continue;
913
+ metadata[key] = value;
914
+ hasMetadataPatch = true;
915
+ }
916
+ if (metadata.average_discount_amount_rate !== void 0) {
917
+ hasMetadataPatch = true;
918
+ }
905
919
  if (Array.isArray(productRecord.relation_surcharge_ids)) {
906
920
  metadata.relation_surcharge_ids = productRecord.relation_surcharge_ids;
907
921
  hasMetadataPatch = true;
908
922
  }
923
+ const productPaymentPrice = this.formatSummaryMetadataMoney(
924
+ productRecord.payment_price
925
+ );
926
+ if (productPaymentPrice !== void 0) {
927
+ productRecord.payment_price = productPaymentPrice;
928
+ }
909
929
  if (hasMetadataPatch)
910
930
  productRecord.metadata = metadata;
911
931
  if (!Array.isArray(productRecord.product_bundle))
@@ -921,6 +941,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
921
941
  bundleMetadata.surcharge_fee = bundleSurchargeFee;
922
942
  hasBundleMetadataPatch = true;
923
943
  }
944
+ const bundlePaymentPrice = this.formatSummaryMetadataMoney(
945
+ bundleRecord.bundle_payment_price
946
+ );
947
+ if (bundlePaymentPrice !== void 0) {
948
+ bundleRecord.bundle_payment_price = bundlePaymentPrice;
949
+ }
924
950
  if (Array.isArray(bundleRecord.relation_surcharge_ids)) {
925
951
  bundleMetadata.relation_surcharge_ids = bundleRecord.relation_surcharge_ids;
926
952
  hasBundleMetadataPatch = true;
@@ -1843,21 +1869,41 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1843
1869
  */
1844
1870
  updateVoucherOrderPayments(payments) {
1845
1871
  const tempOrder = this.ensureTempOrder();
1872
+ const isVoucherPayment = (payment) => {
1873
+ return payment.voucher_id !== void 0 && Number(payment.voucher_id) !== 0;
1874
+ };
1875
+ const hasSyncedOrderPayment = (payment) => {
1876
+ return payment.order_payment_id !== void 0 && payment.order_payment_id !== null;
1877
+ };
1846
1878
  const mappedVouchers = (0, import_utils.mapPaymentItemsToOrderPayments)(
1847
1879
  payments.map(
1848
1880
  (payment) => this.normalizePaymentSource(payment, { defaultPaid: true })
1849
1881
  )
1850
1882
  ).filter((payment) => {
1851
- return payment.voucher_id !== void 0 && Number(payment.voucher_id) !== 0;
1883
+ return isVoucherPayment(payment);
1852
1884
  });
1853
1885
  const nonVoucherPayments = (tempOrder.payments || []).filter((payment) => {
1854
- return payment.voucher_id === void 0 || Number(payment.voucher_id) === 0;
1886
+ return !isVoucherPayment(payment);
1887
+ });
1888
+ const syncedVoucherPayments = (tempOrder.payments || []).filter((payment) => {
1889
+ return isVoucherPayment(payment) && hasSyncedOrderPayment(payment);
1890
+ });
1891
+ const syncedVoucherPaymentIds = new Set(
1892
+ syncedVoucherPayments.map((payment) => String(payment.order_payment_id))
1893
+ );
1894
+ const replaceableVouchers = mappedVouchers.filter((payment) => {
1895
+ if (!hasSyncedOrderPayment(payment))
1896
+ return true;
1897
+ return !syncedVoucherPaymentIds.has(String(payment.order_payment_id));
1855
1898
  });
1856
1899
  const cappedVouchers = this.capVoucherPaymentsByRemainingAmount({
1857
- vouchers: mappedVouchers,
1858
- nonVoucherPayments
1900
+ vouchers: replaceableVouchers,
1901
+ nonVoucherPayments: [
1902
+ ...nonVoucherPayments,
1903
+ ...syncedVoucherPayments
1904
+ ]
1859
1905
  });
1860
- tempOrder.payments = [...nonVoucherPayments, ...cappedVouchers];
1906
+ tempOrder.payments = [...nonVoucherPayments, ...syncedVoucherPayments, ...cappedVouchers];
1861
1907
  this.updateTempOrderPaymentStatus(tempOrder);
1862
1908
  this.persistTempOrder();
1863
1909
  void this.recalculateSummary({ createIfMissing: true }).catch((error) => {
@@ -2824,8 +2870,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2824
2870
  var _a, _b;
2825
2871
  const raw = record && typeof record === "object" && record.data && record.order_id == null ? record.data : record || {};
2826
2872
  const nextTempOrder = this.normalizeTempOrderForRuntime(raw);
2873
+ const rawSummary = raw.summary && typeof raw.summary === "object" ? raw.summary : {};
2874
+ const summarySurcharges = Array.isArray(rawSummary.surcharges) ? rawSummary.surcharges.map((s) => ({ ...s || {} })) : (0, import_lodash_es.cloneDeep)(nextTempOrder.surcharges || []);
2827
2875
  this.store.tempOrder = nextTempOrder;
2828
- this.store.summary = raw.summary && typeof raw.summary === "object" ? { ...(0, import_utils.createEmptySummary)(), ...raw.summary } : (0, import_utils.createEmptySummary)();
2876
+ this.store.summary = {
2877
+ ...(0, import_utils.createEmptySummary)(),
2878
+ ...rawSummary,
2879
+ surcharges: summarySurcharges
2880
+ };
2829
2881
  nextTempOrder._extend = {
2830
2882
  ...nextTempOrder._extend || {},
2831
2883
  originalSalesSnapshot: {
@@ -194,6 +194,7 @@ export interface OrderSummary {
194
194
  shipping_tax_fee: string;
195
195
  tax_fee: string;
196
196
  surcharge_fee: string;
197
+ surcharges: any[];
197
198
  discount_amount: string;
198
199
  deposit_amount: string;
199
200
  deposit?: {
@@ -1,5 +1,5 @@
1
1
  import Decimal from 'decimal.js';
2
- import { CartItem } from "../Cart";
2
+ import type { CartItem } from "../Cart";
3
3
  import type { OrderProductDiscountItem, OrderSubmitPayload, OrderSubmitProduct, OrderSummary, OrderTempOrder } from './types';
4
4
  import type { RulesParamsHooks } from '../Rules/types';
5
5
  import type { MapOrderPaymentsOptions, OrderPaymentData, OrderPaymentSource } from './types';
@@ -21,10 +21,20 @@ export declare function composeLinePrice(params: {
21
21
  bundle?: Array<{
22
22
  bundle_selling_price?: any;
23
23
  price?: any;
24
+ custom_price?: any;
24
25
  num?: any;
25
26
  quantity?: any;
26
27
  original_price?: any;
27
28
  product_price?: any;
29
+ price_type?: any;
30
+ price_type_ext?: any;
31
+ custom_price_type?: any;
32
+ custom_price_type_ext?: any;
33
+ option?: Array<{
34
+ add_price?: any;
35
+ price?: any;
36
+ num?: any;
37
+ }>;
28
38
  }> | null;
29
39
  useOriginalBundle?: boolean;
30
40
  }): string;
@@ -43,6 +53,27 @@ export declare function sumOptionUnitPrice(options?: Array<{
43
53
  price?: any;
44
54
  num?: any;
45
55
  }> | null): Decimal;
56
+ /**
57
+ * 判定套餐子商品是否为 markdown(减价)类型。
58
+ * 与后端口径一致:price_type='markdown' 且 price_type_ext 非 'product_price'(原价子商品)。
59
+ */
60
+ export declare function isMarkdownBundle(bundle: Record<string, any> | null | undefined): boolean;
61
+ /**
62
+ * 套餐子商品对「行价」的带符号单位贡献(与后端 markdown 口径对齐)。
63
+ *
64
+ * - markdown(减价):净额 = |catalog 毛价| − Σ(option.add_price×num),**取负**(行内减)。
65
+ * catalog 毛价优先 `price`/`custom_price`(避免读已落净额的 `bundle_selling_price` 造成 option 二次扣减);
66
+ * 仅当毛价缺失(历史/hydrate 仅剩净额)时退回 `bundle_selling_price`,且此时不再扣 option。
67
+ * - markup(加价)/原价子商品:维持 `+(bundle_selling_price ?? price)`,行为不变。
68
+ */
69
+ export declare function getBundleSignedUnit(bundle: Record<string, any> | null | undefined, options?: {
70
+ useOriginal?: boolean;
71
+ }): Decimal;
72
+ /**
73
+ * 套餐子商品 `bundle_selling_price` 的存储净额(正值幅度)。
74
+ * markdown 取净额绝对值(3.70);markup/原价维持原值。
75
+ */
76
+ export declare function getBundleSellingMagnitude(bundle: Record<string, any> | null | undefined): Decimal;
46
77
  /**
47
78
  * OrderModule 默认 Rules 钩子工厂。
48
79
  *
@@ -55,7 +86,7 @@ export declare function sumOptionUnitPrice(options?: Array<{
55
86
  * 不含折扣。**权威源**。
56
87
  * - `metadata.main_product_original_price` = source + Σ(option.price × option.num)(含 option、不含折扣)。
57
88
  * - `metadata.main_product_selling_price` = main_original − 主商品券 per-unit amount(含 option、含折扣)。
58
- * - `payment_price`:出站 payload 中由 `selling_price` 派生以兼容后端(composite)。
89
+ * - `payment_price`:出站 payload 中为行 composite 已减整单折扣均摊价(无折扣时与 `selling_price` 同义)。
59
90
  *
60
91
  * Rules 钩子契约(hook_adapt 方案,Rules 内部保持不变):
61
92
  * - `getProduct.price` / `getProduct.original_price` 回传 **source-level 主价**