@pisell/pisellos 2.1.130 → 2.1.132

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 (37) hide show
  1. package/dist/modules/Order/index.d.ts +3 -6
  2. package/dist/modules/Order/index.js +119 -41
  3. package/dist/modules/Order/types.d.ts +23 -5
  4. package/dist/modules/Order/types.js +2 -0
  5. package/dist/modules/Order/utils.d.ts +66 -11
  6. package/dist/modules/Order/utils.js +281 -45
  7. package/dist/modules/ProductList/index.js +2 -2
  8. package/dist/modules/SalesSummary/utils.js +36 -69
  9. package/dist/modules/ScanOrderLogger/providers/feishu.js +168 -60
  10. package/dist/modules/ScanOrderLogger/types.d.ts +6 -0
  11. package/dist/modules/Summary/utils.js +6 -21
  12. package/dist/solution/ScanOrder/index.d.ts +31 -6
  13. package/dist/solution/ScanOrder/index.js +1062 -498
  14. package/dist/solution/ScanOrder/types.d.ts +52 -2
  15. package/dist/solution/ScanOrder/types.js +16 -1
  16. package/dist/solution/ScanOrder/utils.d.ts +41 -5
  17. package/dist/solution/ScanOrder/utils.js +214 -33
  18. package/dist/solution/VenueBooking/index.d.ts +2 -5
  19. package/dist/solution/VenueBooking/index.js +35 -27
  20. package/lib/modules/Order/index.d.ts +3 -6
  21. package/lib/modules/Order/index.js +109 -30
  22. package/lib/modules/Order/types.d.ts +23 -5
  23. package/lib/modules/Order/utils.d.ts +66 -11
  24. package/lib/modules/Order/utils.js +181 -16
  25. package/lib/modules/ProductList/index.js +3 -2
  26. package/lib/modules/SalesSummary/utils.js +16 -48
  27. package/lib/modules/ScanOrderLogger/providers/feishu.js +100 -34
  28. package/lib/modules/ScanOrderLogger/types.d.ts +6 -0
  29. package/lib/modules/Summary/utils.js +4 -18
  30. package/lib/solution/ScanOrder/index.d.ts +31 -6
  31. package/lib/solution/ScanOrder/index.js +315 -14
  32. package/lib/solution/ScanOrder/types.d.ts +52 -2
  33. package/lib/solution/ScanOrder/utils.d.ts +41 -5
  34. package/lib/solution/ScanOrder/utils.js +150 -20
  35. package/lib/solution/VenueBooking/index.d.ts +2 -5
  36. package/lib/solution/VenueBooking/index.js +13 -6
  37. package/package.json +1 -1
@@ -1,39 +1,114 @@
1
1
  var _excluded = ["_origin", "identity_key"],
2
2
  _excluded2 = ["created_at", "summary", "surcharges"],
3
3
  _excluded3 = ["collect_pax", "table_occupancy_duration"];
4
- 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; } } }; }
5
4
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
6
5
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
7
6
  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); }
8
7
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
9
8
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
- 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); }
11
9
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
12
10
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
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
11
  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; }
15
12
  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; }
16
13
  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; }
17
14
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
18
15
  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); }
16
+ 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; } } }; }
17
+ 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); }
18
+ 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; }
19
19
  import dayjs from "dayjs";
20
20
  import Decimal from 'decimal.js';
21
- import { createEmptySummary } from "../../solution/ScanOrder/utils";
21
+ import { buildProductLineFingerprint, createEmptySummary } from "../../solution/ScanOrder/utils";
22
+ /**
23
+ * 把"含 option 的主商品单价"与 bundle 合成"单行 composite 单价"。
24
+ *
25
+ * 新语义 v2 约定:
26
+ * - `mainPrice` 必须是**已经包含 option 的主商品单价**(即 `metadata.main_product_selling_price`
27
+ * 或 `metadata.main_product_original_price`),option 价格不由本函数叠加。
28
+ * - 套餐价:Σ((bundle.bundle_selling_price ?? bundle.price) × (bundle.num ?? bundle.quantity ?? 1))
29
+ * 当 `useOriginalBundle=true` 时,改用 `bundle.original_price ?? bundle.product_price ?? bundle.price`。
30
+ * - 返回值:保留 2 位小数的字符串,方便直接写回 `selling_price` / `original_price` 字段。
31
+ *
32
+ * 被 `normalizeOrderProduct`、Rules setProduct 钩子、各 Solution 的 setDiscountSelected 共用,
33
+ * 保证合成逻辑单点来源。
34
+ */
35
+ export function composeLinePrice(params) {
36
+ var mainPrice = params.mainPrice,
37
+ bundle = params.bundle,
38
+ useOriginalBundle = params.useOriginalBundle;
39
+ var total = new Decimal(Number(mainPrice) || 0);
40
+ if (Array.isArray(bundle)) {
41
+ var _iterator = _createForOfIteratorHelper(bundle),
42
+ _step;
43
+ try {
44
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
45
+ var _ref, _item$original_price, _item$bundle_selling_, _ref2, _item$num;
46
+ var item = _step.value;
47
+ var rawPrice = useOriginalBundle ? (_ref = (_item$original_price = item === null || item === void 0 ? void 0 : item.original_price) !== null && _item$original_price !== void 0 ? _item$original_price : item === null || item === void 0 ? void 0 : item.product_price) !== null && _ref !== void 0 ? _ref : item === null || item === void 0 ? void 0 : item.price : (_item$bundle_selling_ = item === null || item === void 0 ? void 0 : item.bundle_selling_price) !== null && _item$bundle_selling_ !== void 0 ? _item$bundle_selling_ : item === null || item === void 0 ? void 0 : item.price;
48
+ var price = new Decimal(Number(rawPrice) || 0);
49
+ var rawNum = (_ref2 = (_item$num = item === null || item === void 0 ? void 0 : item.num) !== null && _item$num !== void 0 ? _item$num : item === null || item === void 0 ? void 0 : item.quantity) !== null && _ref2 !== void 0 ? _ref2 : 1;
50
+ var num = new Decimal(Number(rawNum) || 0);
51
+ total = total.plus(price.times(num));
52
+ }
53
+ } catch (err) {
54
+ _iterator.e(err);
55
+ } finally {
56
+ _iterator.f();
57
+ }
58
+ }
59
+ return total.toDecimalPlaces(2).toFixed(2);
60
+ }
61
+
62
+ /**
63
+ * 计算 option 单价合计:Σ(option.price × option.num)。
64
+ * 在新语义 v2 下,main_product_original_price = source_product_price + 本函数结果。
65
+ */
66
+ export function sumOptionUnitPrice(options) {
67
+ var total = new Decimal(0);
68
+ if (!Array.isArray(options)) return total;
69
+ var _iterator2 = _createForOfIteratorHelper(options),
70
+ _step2;
71
+ try {
72
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
73
+ var opt = _step2.value;
74
+ var price = new Decimal(Number(opt === null || opt === void 0 ? void 0 : opt.price) || 0);
75
+ var num = new Decimal(Number(opt === null || opt === void 0 ? void 0 : opt.num) || 0);
76
+ total = total.plus(price.times(num));
77
+ }
78
+ } catch (err) {
79
+ _iterator2.e(err);
80
+ } finally {
81
+ _iterator2.f();
82
+ }
83
+ return total;
84
+ }
85
+
22
86
  /**
23
87
  * OrderModule 默认 Rules 钩子工厂。
24
88
  *
25
- * 价格语义约定(订单域):
26
- * - `selling_price`:券后单品单价(实际成交单价)。初次加购 = `original_price`;券应用后由 Rules 引擎更新。
27
- * - `original_price`:券前单品单价(店铺售价)。不承载后台划线价语义。
28
- * - `payment_price`:已从内部字段移除;只在出站 payload 中由 `selling_price` 派生以兼容后端。
89
+ * 价格语义约定(订单域,v2 composite 口径):
90
+ * - `selling_price`:券后 **行 composite 单价**
91
+ * = `metadata.main_product_selling_price` + Σ(bundle_selling_price × num)。
92
+ * - `original_price`:券前 **行 composite 单价**
93
+ * = `metadata.main_product_original_price` + Σ(bundle 原价 × num)。
94
+ * - `metadata.source_product_price`:主商品/variant 基础价(已应用报价单),不含 option、
95
+ * 不含折扣。**权威源**。
96
+ * - `metadata.main_product_original_price` = source + Σ(option.price × option.num)(含 option、不含折扣)。
97
+ * - `metadata.main_product_selling_price` = main_original − 主商品券 per-unit amount(含 option、含折扣)。
98
+ * - `payment_price`:出站 payload 中由 `selling_price` 派生以兼容后端(composite)。
29
99
  *
30
- * Rules 钩子契约:
31
- * - `getProduct.total` = `selling_price × num`(当前成交总价)
32
- * - `getProduct.origin_total` = `original_price × num`(券前总价)
33
- * - `setProduct` 写回 `selling_price` 的优先级:
34
- * 1. `values.main_product_selling_price`(券应用分支,per-unit 券后主价)
35
- * 2. `values.price`(还原分支 `restoredPrice`、good_pass 归零)
36
- * 3. `values.total / num`(仅当 Rules 只给出总价时的兜底)
100
+ * Rules 钩子契约(hook_adapt 方案,Rules 内部保持不变):
101
+ * - `getProduct.price` / `getProduct.original_price` 回传 **source-level 主价**
102
+ * (`metadata.source_product_price`)。Rules 内部 `getProductTotalPrice` /
103
+ * `getProductOriginTotalPrice` 会自行叠加 option + bundle,喂 source 可避免 option 双加。
104
+ * - `getProduct.total` = `selling_price × num`(行 composite × num),与 Rules 内部产出的
105
+ * total(source + option + bundle)对齐。
106
+ * - `setProduct` 反向流程:把 Rules 返回的 source-level `main_product_selling_price` / `price`
107
+ * 加回 Σoptions,重新合成含 option 的 main_product_* 并派生 composite。
108
+ * 优先级:
109
+ * 1. `values.main_product_selling_price`(券应用分支,per-unit 券后 source-level 主价)
110
+ * 2. `values.price`(还原分支 `restoredPrice`、good_pass 归零)
111
+ * 3. `values.total / num`(仅当 Rules 只给出总价时的兜底)
37
112
  *
38
113
  * 导出为纯函数方便单测直接驱动钩子,不依赖 OrderModule 实例。
39
114
  */
@@ -45,13 +120,40 @@ export function createDefaultOrderRulesHooks() {
45
120
  return {
46
121
  getProduct: function getProduct(product) {
47
122
  var _product$_origin, _product$_origin2, _product$_origin3, _product$_origin4;
123
+ // source_product_price 是权威源;兜底链:source → mainSelling − options(反推)→ 行 selling_price
124
+ var metadataAny = product.metadata || {};
125
+ var optionSum = sumOptionUnitPrice(product.product_option_item);
126
+ var sourcePrice;
127
+ if (metadataAny.source_product_price !== undefined) {
128
+ sourcePrice = String(metadataAny.source_product_price);
129
+ } else if (metadataAny.main_product_selling_price !== undefined) {
130
+ sourcePrice = new Decimal(Number(metadataAny.main_product_selling_price) || 0).minus(optionSum).toDecimalPlaces(2).toString();
131
+ } else {
132
+ var _product$selling_pric;
133
+ sourcePrice = String((_product$selling_pric = product.selling_price) !== null && _product$selling_pric !== void 0 ? _product$selling_pric : 0);
134
+ }
135
+ var sourceOriginalPrice;
136
+ if (metadataAny.source_product_price !== undefined) {
137
+ sourceOriginalPrice = String(metadataAny.source_product_price);
138
+ } else if (metadataAny.main_product_original_price !== undefined) {
139
+ sourceOriginalPrice = new Decimal(Number(metadataAny.main_product_original_price) || 0).minus(optionSum).toDecimalPlaces(2).toString();
140
+ } else {
141
+ sourceOriginalPrice = sourcePrice;
142
+ }
48
143
  return {
49
144
  id: product.product_id,
50
- _id: product.identity_key ? "".concat(product.product_id, "_").concat(product.product_variant_id, "_").concat(product.identity_key) : "".concat(product.product_id, "_").concat(product.product_variant_id),
51
- price: product.selling_price,
145
+ // Rules 引擎用 _id 作为 processedProductsMap 键;必须与购物车行级 identity 一致,
146
+ // 否则同 SKU 不同小料会在 calcDiscount 重组时互相覆盖。
147
+ // 不透明 identity 契约下,normalizeOrderProduct / restoreTempOrderFromStorage 已保证 identity_key 必存在;
148
+ // 留 fingerprint 分支仅作 Rules 单测里直接传裸 product 时的兜底。
149
+ _id: product.identity_key ? "".concat(product.product_id, "_").concat(product.product_variant_id, "_").concat(product.identity_key) : "".concat(product.product_id, "_").concat(product.product_variant_id, "_").concat(buildProductLineFingerprint(product.product_option_item, product.product_bundle)),
150
+ // Rules 内部 getProductTotalPrice / getProductOriginTotalPrice 会各自再叠加 bundle + option,
151
+ // 所以这里必须喂 source-level(不含 option、不含 bundle、不含折扣)单价,避免双加 option。
152
+ price: sourcePrice,
153
+ // total / origin_total 使用 composite × num,跟 Rules 内部产出的 total 对齐(含 option + bundle)。
52
154
  total: new Decimal(product.selling_price || 0).times(product.num || 1).toNumber(),
53
155
  origin_total: new Decimal(product.original_price || product.selling_price || 0).times(product.num || 1).toNumber(),
54
- original_price: product.original_price,
156
+ original_price: sourceOriginalPrice,
55
157
  quantity: product.num || 1,
56
158
  num: product.num || 1,
57
159
  discount_list: product.discount_list || [],
@@ -64,18 +166,47 @@ export function createDefaultOrderRulesHooks() {
64
166
  };
65
167
  },
66
168
  setProduct: function setProduct(product, values) {
67
- var _ref, _values$quantity, _values$discount_list, _values$quantity2, _values$bundle;
68
- var nextNum = Number((_ref = (_values$quantity = values.quantity) !== null && _values$quantity !== void 0 ? _values$quantity : product.num) !== null && _ref !== void 0 ? _ref : 1) || 1;
69
- var nextSellingPrice = values.main_product_selling_price !== undefined ? String(values.main_product_selling_price) : values.price !== undefined ? String(values.price) : values.total !== undefined ? toUnitPriceString(values.total, nextNum) : product.selling_price;
169
+ var _ref3, _values$quantity, _ref4, _metadataAny$source_p, _values$bundle, _values$discount_list, _values$quantity2;
170
+ var nextNum = Number((_ref3 = (_values$quantity = values.quantity) !== null && _values$quantity !== void 0 ? _values$quantity : product.num) !== null && _ref3 !== void 0 ? _ref3 : 1) || 1;
171
+ var metadataAny = product.metadata || {};
172
+ var existedSource = (_ref4 = (_metadataAny$source_p = metadataAny.source_product_price) !== null && _metadataAny$source_p !== void 0 ? _metadataAny$source_p : product.selling_price) !== null && _ref4 !== void 0 ? _ref4 : '0';
173
+ var nextOptions = product.product_option_item;
174
+ var optionSum = sumOptionUnitPrice(nextOptions);
175
+
176
+ // Rules 返回的 main_product_selling_price / price / total 均为 source-level。
177
+ // 优先级:main_product_selling_price(per-unit 券后 source)> price(还原/good_pass 分支)>
178
+ // total/num(仅当 Rules 只给 total 时的兜底)> 保留当前 source。
179
+ var nextSourceSellingPrice = values.main_product_selling_price !== undefined ? String(values.main_product_selling_price) : values.price !== undefined ? String(values.price) : values.total !== undefined ? toUnitPriceString(values.total, nextNum) : String(existedSource);
180
+
181
+ // 券前 source:values.original_price 是 source-level(Rules 层本就不含 option),
182
+ // 缺省时保留现有 source(券前 = 当前 source)。
183
+ var nextSourceOriginalPrice = values.original_price !== undefined ? String(values.original_price) : String(existedSource);
184
+
185
+ // 含 option 的 main_product_*
186
+ var nextMainSellingPrice = new Decimal(Number(nextSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
187
+ var nextMainOriginalPrice = new Decimal(Number(nextSourceOriginalPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
188
+ var nextBundle = (_values$bundle = values.bundle) !== null && _values$bundle !== void 0 ? _values$bundle : product.product_bundle;
189
+ var composedSellingPrice = composeLinePrice({
190
+ mainPrice: nextMainSellingPrice,
191
+ bundle: nextBundle
192
+ });
193
+ var composedOriginalPrice = composeLinePrice({
194
+ mainPrice: nextMainOriginalPrice,
195
+ bundle: nextBundle,
196
+ useOriginalBundle: true
197
+ });
70
198
  return _objectSpread(_objectSpread({}, product), {}, {
71
- selling_price: nextSellingPrice,
72
- original_price: values.original_price !== undefined ? String(values.original_price) : product.original_price,
199
+ selling_price: composedSellingPrice,
200
+ original_price: composedOriginalPrice,
73
201
  discount_list: (_values$discount_list = values.discount_list) !== null && _values$discount_list !== void 0 ? _values$discount_list : product.discount_list,
74
202
  num: (_values$quantity2 = values.quantity) !== null && _values$quantity2 !== void 0 ? _values$quantity2 : product.num,
75
- product_bundle: (_values$bundle = values.bundle) !== null && _values$bundle !== void 0 ? _values$bundle : product.product_bundle,
76
- metadata: _objectSpread(_objectSpread({}, product.metadata || {}), values.main_product_selling_price !== undefined ? {
77
- main_product_selling_price: String(values.main_product_selling_price)
78
- } : {})
203
+ product_bundle: nextBundle,
204
+ metadata: _objectSpread(_objectSpread({}, metadataAny), {}, {
205
+ source_product_price: nextSourceSellingPrice,
206
+ main_product_selling_price: nextMainSellingPrice,
207
+ main_product_original_price: nextMainOriginalPrice,
208
+ price_schema_version: 2
209
+ })
79
210
  });
80
211
  }
81
212
  };
@@ -168,6 +299,92 @@ export function formatDateTime(date) {
168
299
  function normalizeSubmitPlatform(platform) {
169
300
  return (platform === null || platform === void 0 ? void 0 : platform.toLowerCase()) === 'pc' ? 'PC' : 'H5';
170
301
  }
302
+
303
+ // 出站重命名:后端 checkout 协议字段 option_group_item_id;
304
+ // tempOrder / UI 运行时一律使用 product_option_item_id。仅保留后端契约字段,
305
+ // 与 src/modules/Cart/utils/cartProduct.ts#formatOptionsToOrigin 形状一致。
306
+ function formatSubmitOptionItems(options) {
307
+ if (!Array.isArray(options)) return [];
308
+ return options.map(function (d) {
309
+ var _d$option_group_item_;
310
+ return {
311
+ num: d === null || d === void 0 ? void 0 : d.num,
312
+ option_group_item_id: (_d$option_group_item_ = d === null || d === void 0 ? void 0 : d.option_group_item_id) !== null && _d$option_group_item_ !== void 0 ? _d$option_group_item_ : d === null || d === void 0 ? void 0 : d.product_option_item_id,
313
+ option_group_id: d === null || d === void 0 ? void 0 : d.option_group_id
314
+ };
315
+ });
316
+ }
317
+ function toBundleNumber(value) {
318
+ var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
319
+ var parsed = Number(value);
320
+ return Number.isFinite(parsed) ? parsed : fallback;
321
+ }
322
+ function toBundleCustomPriceString(value) {
323
+ var parsed = Number(value);
324
+ if (Number.isFinite(parsed)) return parsed.toFixed(2);
325
+ if (value === null || value === undefined || value === '') return '0.00';
326
+ return String(value);
327
+ }
328
+
329
+ // 出站补齐:以 additive 方式把 bundle 项补足为后端 checkout 协议所需的形状,
330
+ // 同时把 Summary / Rules 运行时写到 bundle 顶层的 surcharge_fee / relation_surcharge_ids
331
+ // 和来自 _origin 的 product_discount_difference 汇总到 metadata。
332
+ // 保留原对象上已有字段(如 discount_list、metadata.custom_product_bundle_map_id)
333
+ // 以兼容运行时 bundle 归一化、Rules、Summary 的消费。
334
+ function formatSubmitBundleItems(bundle) {
335
+ if (!Array.isArray(bundle)) return [];
336
+ return bundle.map(function (b) {
337
+ var _rawBundle$bundle_sel, _rawBundle$price_type, _ref5, _rawBundle$custom_pri, _rawBundle$surcharge_, _rawBundle$is_charge_, _rawBundle$bundle_var, _rawBundle$extension_, _rawBundle$extension_2, _rawBundle$price_type2, _ref6, _rawBundle$custom_pri2;
338
+ var rawBundle = b && _typeof(b) === 'object' ? b : {};
339
+ var existedMetadata = rawBundle.metadata && _typeof(rawBundle.metadata) === 'object' ? rawBundle.metadata : {};
340
+ var sellingPriceNum = toBundleNumber((_rawBundle$bundle_sel = rawBundle.bundle_selling_price) !== null && _rawBundle$bundle_sel !== void 0 ? _rawBundle$bundle_sel : rawBundle.price, 0);
341
+ var priceNum = toBundleNumber(rawBundle.price, sellingPriceNum);
342
+ var priceType = (_rawBundle$price_type = rawBundle.price_type) !== null && _rawBundle$price_type !== void 0 ? _rawBundle$price_type : '';
343
+ var customPriceStr = toBundleCustomPriceString((_ref5 = (_rawBundle$custom_pri = rawBundle.custom_price) !== null && _rawBundle$custom_pri !== void 0 ? _rawBundle$custom_pri : rawBundle.bundle_selling_price) !== null && _ref5 !== void 0 ? _ref5 : rawBundle.price);
344
+ var relationSurchargeIds = Array.isArray(rawBundle.relation_surcharge_ids) ? rawBundle.relation_surcharge_ids : Array.isArray(existedMetadata.relation_surcharge_ids) ? existedMetadata.relation_surcharge_ids : [];
345
+ var surchargeFee = toBundleNumber((_rawBundle$surcharge_ = rawBundle.surcharge_fee) !== null && _rawBundle$surcharge_ !== void 0 ? _rawBundle$surcharge_ : existedMetadata.surcharge_fee, 0);
346
+ var productDiscountDifference = toBundleNumber(existedMetadata.product_discount_difference, 0);
347
+ return _objectSpread(_objectSpread({}, rawBundle), {}, {
348
+ is_charge_tax: (_rawBundle$is_charge_ = rawBundle.is_charge_tax) !== null && _rawBundle$is_charge_ !== void 0 ? _rawBundle$is_charge_ : 0,
349
+ tax_fee: toBundleNumber(rawBundle.tax_fee, 0),
350
+ bundle_variant_id: (_rawBundle$bundle_var = rawBundle.bundle_variant_id) !== null && _rawBundle$bundle_var !== void 0 ? _rawBundle$bundle_var : 0,
351
+ num: toBundleNumber(rawBundle.num, 1),
352
+ extension_id: (_rawBundle$extension_ = rawBundle.extension_id) !== null && _rawBundle$extension_ !== void 0 ? _rawBundle$extension_ : 0,
353
+ extension_type: (_rawBundle$extension_2 = rawBundle.extension_type) !== null && _rawBundle$extension_2 !== void 0 ? _rawBundle$extension_2 : 'normal',
354
+ price: priceNum,
355
+ price_type: priceType,
356
+ price_type_ext: (_rawBundle$price_type2 = rawBundle.price_type_ext) !== null && _rawBundle$price_type2 !== void 0 ? _rawBundle$price_type2 : '',
357
+ custom_price: customPriceStr,
358
+ custom_price_type: (_ref6 = (_rawBundle$custom_pri2 = rawBundle.custom_price_type) !== null && _rawBundle$custom_pri2 !== void 0 ? _rawBundle$custom_pri2 : priceType) !== null && _ref6 !== void 0 ? _ref6 : '',
359
+ bundle_selling_price: sellingPriceNum,
360
+ option: formatSubmitOptionItems(rawBundle.option),
361
+ bundle_group_id: rawBundle === null || rawBundle === void 0 ? void 0 : rawBundle.group_id,
362
+ bundle_id: rawBundle === null || rawBundle === void 0 ? void 0 : rawBundle.id,
363
+ metadata: _objectSpread(_objectSpread({}, existedMetadata), {}, {
364
+ surcharge_fee: surchargeFee,
365
+ relation_surcharge_ids: relationSurchargeIds,
366
+ product_discount_difference: productDiscountDifference
367
+ })
368
+ });
369
+ });
370
+ }
371
+
372
+ /**
373
+ * 把 tempOrder product 打包成出站 submit payload。
374
+ *
375
+ * 价格字段语义(出站口径,v2 composite):
376
+ * - `selling_price`:**行 composite 券后单价**
377
+ * = `metadata.main_product_selling_price` + Σ(bundle_selling_price × num)。
378
+ * - `original_price`:**行 composite 券前单价**
379
+ * = `metadata.main_product_original_price` + Σ(bundle 原价 × num)。
380
+ * - `payment_price`:兼容后端的出站字段,直接从 `selling_price` 派生(composite)。
381
+ * - `metadata.source_product_price`:主商品/variant 基础价(不含 option、不含折扣),权威源。
382
+ * - `metadata.main_product_original_price`:含 option、不含折扣。
383
+ * - `metadata.main_product_selling_price`:含 option、含主商品折扣。
384
+ * - `metadata.price_schema_version`:schema 版本号(当前 = 2),用于跨端协商价格口径。
385
+ *
386
+ * 本函数不再改造价格字段形状,仅做字段/metadata 裁剪。
387
+ */
171
388
  function normalizeSubmitProduct(product) {
172
389
  var _origin = product._origin,
173
390
  identity_key = product.identity_key,
@@ -178,7 +395,7 @@ function normalizeSubmitProduct(product) {
178
395
  if (rawMetadata.unique_identification_number) {
179
396
  cleanMetadata.unique_identification_number = rawMetadata.unique_identification_number;
180
397
  }
181
- var priceMetaKeys = ['main_product_original_price', 'main_product_selling_price', 'source_product_price'];
398
+ var priceMetaKeys = ['main_product_original_price', 'main_product_selling_price', 'source_product_price', 'price_schema_version'];
182
399
  for (var _i = 0, _priceMetaKeys = priceMetaKeys; _i < _priceMetaKeys.length; _i++) {
183
400
  var key = _priceMetaKeys[_i];
184
401
  if (rawMetadata[key] !== undefined) {
@@ -194,11 +411,12 @@ function normalizeSubmitProduct(product) {
194
411
  return _objectSpread(_objectSpread(_objectSpread({}, submitProduct), bookingUid ? {
195
412
  booking_uid: bookingUid
196
413
  } : {}), {}, {
197
- product_option_item: submitProduct.product_option_item || [],
414
+ product_option_item: formatSubmitOptionItems(submitProduct.product_option_item),
198
415
  discount_list: submitProduct.discount_list || [],
199
- product_bundle: submitProduct.product_bundle || [],
416
+ product_bundle: formatSubmitBundleItems(submitProduct.product_bundle),
200
417
  metadata: cleanMetadata,
201
- // 出站兼容:后端仍消费 payment_price 字段,从 selling_price(券后单价)派生。
418
+ // 出站兼容:后端消费 payment_price 字段,这里从 selling_price 直接派生。
419
+ // 新语义下 selling_price 是 composite(含 option/bundle),payment_price 同语义。
202
420
  payment_price: submitProduct.selling_price
203
421
  });
204
422
  }
@@ -206,19 +424,19 @@ var SUBMIT_BOOKING_METADATA_WHITELIST = ['unique_identification_number', 'collec
206
424
  export function normalizeSubmitBooking(booking) {
207
425
  var rawMetadata = booking.metadata || {};
208
426
  var cleanMetadata = {};
209
- var _iterator = _createForOfIteratorHelper(SUBMIT_BOOKING_METADATA_WHITELIST),
210
- _step;
427
+ var _iterator3 = _createForOfIteratorHelper(SUBMIT_BOOKING_METADATA_WHITELIST),
428
+ _step3;
211
429
  try {
212
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
213
- var key = _step.value;
430
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
431
+ var key = _step3.value;
214
432
  if (rawMetadata[key] !== undefined) {
215
433
  cleanMetadata[key] = rawMetadata[key];
216
434
  }
217
435
  }
218
436
  } catch (err) {
219
- _iterator.e(err);
437
+ _iterator3.e(err);
220
438
  } finally {
221
- _iterator.f();
439
+ _iterator3.f();
222
440
  }
223
441
  return _objectSpread(_objectSpread({}, booking), {}, {
224
442
  metadata: cleanMetadata
@@ -299,7 +517,7 @@ export function createDefaultTempOrder(params) {
299
517
  };
300
518
  }
301
519
  export function buildSubmitPayload(params) {
302
- var _ref2, _ref3, _ref4, _tempOrder$is_price_i, _tempOrder$is_deposit;
520
+ var _ref7, _ref8, _ref9, _tempOrder$is_price_i, _tempOrder$is_deposit;
303
521
  var tempOrder = params.tempOrder,
304
522
  cacheId = params.cacheId,
305
523
  _params$now = params.now,
@@ -347,10 +565,10 @@ export function buildSubmitPayload(params) {
347
565
  var payload = _objectSpread(_objectSpread({}, tempOrderRest), {}, {
348
566
  platform: normalizeSubmitPlatform(platform !== null && platform !== void 0 ? platform : tempOrder.platform),
349
567
  request_unique_idempotency_token: cacheId,
350
- type: (_ref2 = type !== null && type !== void 0 ? type : tempOrder.type) !== null && _ref2 !== void 0 ? _ref2 : 'table-order',
351
- business_code: (_ref3 = businessCode !== null && businessCode !== void 0 ? businessCode : tempOrder.business_code) !== null && _ref3 !== void 0 ? _ref3 : 'table-order',
568
+ type: (_ref7 = type !== null && type !== void 0 ? type : tempOrder.type) !== null && _ref7 !== void 0 ? _ref7 : 'table-order',
569
+ business_code: (_ref8 = businessCode !== null && businessCode !== void 0 ? businessCode : tempOrder.business_code) !== null && _ref8 !== void 0 ? _ref8 : 'table-order',
352
570
  sales_channel: tempOrder.sales_channel || 'my_pisel',
353
- order_sales_channel: (_ref4 = channel !== null && channel !== void 0 ? channel : tempOrder.order_sales_channel) !== null && _ref4 !== void 0 ? _ref4 : 'online_store',
571
+ order_sales_channel: (_ref9 = channel !== null && channel !== void 0 ? channel : tempOrder.order_sales_channel) !== null && _ref9 !== void 0 ? _ref9 : 'online_store',
354
572
  status: tempOrder.status || 'normal',
355
573
  payment_status: tempOrder.payment_status || 'payment_processing',
356
574
  // shipping_status: tempOrder.shipping_status || 'unfulfilled',
@@ -374,10 +592,10 @@ export function buildSubmitPayload(params) {
374
592
  // holder: tempOrder.holder || null,
375
593
  // summary,
376
594
  metadata: function () {
377
- var _ref5 = tempOrder.metadata || {},
378
- _collectPax = _ref5.collect_pax,
379
- _tableOccupancyDuration = _ref5.table_occupancy_duration,
380
- rest = _objectWithoutProperties(_ref5, _excluded3);
595
+ var _ref10 = tempOrder.metadata || {},
596
+ _collectPax = _ref10.collect_pax,
597
+ _tableOccupancyDuration = _ref10.table_occupancy_duration,
598
+ rest = _objectWithoutProperties(_ref10, _excluded3);
381
599
  return _objectSpread({}, rest);
382
600
  }(),
383
601
  products: (tempOrder.products || []).map(function (product) {
@@ -390,8 +608,25 @@ export function buildSubmitPayload(params) {
390
608
  now: now
391
609
  }) : payload;
392
610
  }
611
+
612
+ /** 加单(scanOrderMore)不应提交 booking 关联的虚拟规则商品行 */
613
+ export function filterProductsForScanOrderMore(products) {
614
+ return (products || []).filter(function (p) {
615
+ var _p$metadata;
616
+ return ((_p$metadata = p.metadata) === null || _p$metadata === void 0 ? void 0 : _p$metadata.is_rule) !== true;
617
+ });
618
+ }
619
+
620
+ /**
621
+ * 历史 V1 加餐结构映射器。
622
+ *
623
+ * @deprecated 加餐(`PUT /order/order/product/:id`)已改为与正常 checkout 共用
624
+ * `ScanOrderSubmitProduct` 新结构(见 `OrderModule.submitTempOrder` 的加餐分支)。
625
+ * 本函数仅保留以兼容历史接入方,未来会移除。新代码请勿再调用。
626
+ */
393
627
  export function formatV1Product(products) {
394
628
  return products.map(function (product) {
629
+ var _product$note;
395
630
  return {
396
631
  bundle: product.product_bundle,
397
632
  key: product.product_id,
@@ -399,6 +634,7 @@ export function formatV1Product(products) {
399
634
  product_id: product.product_id,
400
635
  product_variant_id: product.product_variant_id,
401
636
  num: product.num,
637
+ note: String((_product$note = product.note) !== null && _product$note !== void 0 ? _product$note : ''),
402
638
  rowKey: product.product_id,
403
639
  session: null,
404
640
  unique: createUuidV4()
@@ -85,7 +85,6 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
85
85
  key: "loadProducts",
86
86
  value: function () {
87
87
  var _loadProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref) {
88
- var _this$otherParams, _this$otherParams2;
89
88
  var _ref$category_ids, category_ids, _ref$product_ids, product_ids, _ref$collection, collection, _ref$menu_list_ids, menu_list_ids, paramsCustomerId, _ref$with_count, with_count, schedule_datetime, schedule_date, cacheId, with_schedule, userPlugin, customer_id, _userPlugin$get, productsData, sortedList;
90
89
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
91
90
  while (1) switch (_context3.prev = _context3.next) {
@@ -129,7 +128,8 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
129
128
  with_count: with_count,
130
129
  // client_schedule_ids: schedule_ids,
131
130
  schedule_date: schedule_date,
132
- application_code: ((_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.channel) === 'online_store' ? 'online-store' : (_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 ? void 0 : _this$otherParams2.channel,
131
+ // application_code: this.otherParams?.channel === 'online_store' ? 'online-store' : this.otherParams?.channel,
132
+ application_code: 'online-store',
133
133
  with_schedule: with_schedule,
134
134
  schedule_datetime: schedule_datetime,
135
135
  is_eject: 1