@pisell/pisellos 2.1.129 → 2.1.131

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 (54) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  2. package/dist/modules/Order/index.d.ts +7 -6
  3. package/dist/modules/Order/index.js +137 -42
  4. package/dist/modules/Order/types.d.ts +32 -6
  5. package/dist/modules/Order/types.js +2 -0
  6. package/dist/modules/Order/utils.d.ts +73 -11
  7. package/dist/modules/Order/utils.js +304 -52
  8. package/dist/modules/SalesSummary/utils.js +33 -68
  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 +57 -8
  13. package/dist/solution/ScanOrder/index.js +1531 -583
  14. package/dist/solution/ScanOrder/types.d.ts +86 -26
  15. package/dist/solution/ScanOrder/types.js +20 -1
  16. package/dist/solution/ScanOrder/utils.d.ts +53 -5
  17. package/dist/solution/ScanOrder/utils.js +257 -37
  18. package/dist/solution/VenueBooking/index.d.ts +30 -10
  19. package/dist/solution/VenueBooking/index.js +460 -217
  20. package/dist/solution/VenueBooking/types.d.ts +23 -0
  21. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +1 -1
  22. package/dist/solution/VenueBooking/utils/dateSummary.js +1 -1
  23. package/dist/solution/VenueBooking/utils/resource.d.ts +11 -1
  24. package/dist/solution/VenueBooking/utils/resource.js +57 -21
  25. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +5 -0
  26. package/dist/solution/VenueBooking/utils/slotMerge.js +33 -12
  27. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +1 -1
  28. package/dist/solution/VenueBooking/utils/timeSlot.js +259 -62
  29. package/lib/modules/Order/index.d.ts +7 -6
  30. package/lib/modules/Order/index.js +123 -31
  31. package/lib/modules/Order/types.d.ts +32 -6
  32. package/lib/modules/Order/utils.d.ts +73 -11
  33. package/lib/modules/Order/utils.js +203 -28
  34. package/lib/modules/SalesSummary/utils.js +13 -47
  35. package/lib/modules/ScanOrderLogger/providers/feishu.js +100 -34
  36. package/lib/modules/ScanOrderLogger/types.d.ts +6 -0
  37. package/lib/modules/Summary/utils.js +4 -18
  38. package/lib/solution/ScanOrder/index.d.ts +57 -8
  39. package/lib/solution/ScanOrder/index.js +713 -117
  40. package/lib/solution/ScanOrder/types.d.ts +86 -26
  41. package/lib/solution/ScanOrder/utils.d.ts +53 -5
  42. package/lib/solution/ScanOrder/utils.js +186 -19
  43. package/lib/solution/VenueBooking/index.d.ts +30 -10
  44. package/lib/solution/VenueBooking/index.js +206 -51
  45. package/lib/solution/VenueBooking/types.d.ts +23 -0
  46. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +1 -1
  47. package/lib/solution/VenueBooking/utils/dateSummary.js +1 -1
  48. package/lib/solution/VenueBooking/utils/resource.d.ts +11 -1
  49. package/lib/solution/VenueBooking/utils/resource.js +15 -4
  50. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +5 -0
  51. package/lib/solution/VenueBooking/utils/slotMerge.js +29 -12
  52. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +1 -1
  53. package/lib/solution/VenueBooking/utils/timeSlot.js +182 -43
  54. package/package.json +1 -1
@@ -1,38 +1,114 @@
1
1
  var _excluded = ["_origin", "identity_key"],
2
- _excluded2 = ["created_at", "summary", "surcharges"];
3
- 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; } } }; }
2
+ _excluded2 = ["created_at", "summary", "surcharges"],
3
+ _excluded3 = ["collect_pax", "table_occupancy_duration"];
4
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; }
5
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; }
6
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); }
7
7
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
8
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."); }
9
- 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); }
10
9
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
11
10
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
12
- 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; }
13
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; }
14
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; }
15
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; }
16
14
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
17
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; }
18
19
  import dayjs from "dayjs";
19
20
  import Decimal from 'decimal.js';
20
- 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
+
21
86
  /**
22
87
  * OrderModule 默认 Rules 钩子工厂。
23
88
  *
24
- * 价格语义约定(订单域):
25
- * - `selling_price`:券后单品单价(实际成交单价)。初次加购 = `original_price`;券应用后由 Rules 引擎更新。
26
- * - `original_price`:券前单品单价(店铺售价)。不承载后台划线价语义。
27
- * - `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)。
28
99
  *
29
- * Rules 钩子契约:
30
- * - `getProduct.total` = `selling_price × num`(当前成交总价)
31
- * - `getProduct.origin_total` = `original_price × num`(券前总价)
32
- * - `setProduct` 写回 `selling_price` 的优先级:
33
- * 1. `values.main_product_selling_price`(券应用分支,per-unit 券后主价)
34
- * 2. `values.price`(还原分支 `restoredPrice`、good_pass 归零)
35
- * 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 只给出总价时的兜底)
36
112
  *
37
113
  * 导出为纯函数方便单测直接驱动钩子,不依赖 OrderModule 实例。
38
114
  */
@@ -44,13 +120,40 @@ export function createDefaultOrderRulesHooks() {
44
120
  return {
45
121
  getProduct: function getProduct(product) {
46
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
+ }
47
143
  return {
48
144
  id: product.product_id,
49
- _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),
50
- 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)。
51
154
  total: new Decimal(product.selling_price || 0).times(product.num || 1).toNumber(),
52
155
  origin_total: new Decimal(product.original_price || product.selling_price || 0).times(product.num || 1).toNumber(),
53
- original_price: product.original_price,
156
+ original_price: sourceOriginalPrice,
54
157
  quantity: product.num || 1,
55
158
  num: product.num || 1,
56
159
  discount_list: product.discount_list || [],
@@ -63,18 +166,47 @@ export function createDefaultOrderRulesHooks() {
63
166
  };
64
167
  },
65
168
  setProduct: function setProduct(product, values) {
66
- var _ref, _values$quantity, _values$discount_list, _values$quantity2, _values$bundle;
67
- var nextNum = Number((_ref = (_values$quantity = values.quantity) !== null && _values$quantity !== void 0 ? _values$quantity : product.num) !== null && _ref !== void 0 ? _ref : 1) || 1;
68
- 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
+ });
69
198
  return _objectSpread(_objectSpread({}, product), {}, {
70
- selling_price: nextSellingPrice,
71
- original_price: values.original_price !== undefined ? String(values.original_price) : product.original_price,
199
+ selling_price: composedSellingPrice,
200
+ original_price: composedOriginalPrice,
72
201
  discount_list: (_values$discount_list = values.discount_list) !== null && _values$discount_list !== void 0 ? _values$discount_list : product.discount_list,
73
202
  num: (_values$quantity2 = values.quantity) !== null && _values$quantity2 !== void 0 ? _values$quantity2 : product.num,
74
- product_bundle: (_values$bundle = values.bundle) !== null && _values$bundle !== void 0 ? _values$bundle : product.product_bundle,
75
- metadata: _objectSpread(_objectSpread({}, product.metadata || {}), values.main_product_selling_price !== undefined ? {
76
- main_product_selling_price: String(values.main_product_selling_price)
77
- } : {})
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
+ })
78
210
  });
79
211
  }
80
212
  };
@@ -167,6 +299,92 @@ export function formatDateTime(date) {
167
299
  function normalizeSubmitPlatform(platform) {
168
300
  return (platform === null || platform === void 0 ? void 0 : platform.toLowerCase()) === 'pc' ? 'PC' : 'H5';
169
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
+ */
170
388
  function normalizeSubmitProduct(product) {
171
389
  var _origin = product._origin,
172
390
  identity_key = product.identity_key,
@@ -177,7 +395,7 @@ function normalizeSubmitProduct(product) {
177
395
  if (rawMetadata.unique_identification_number) {
178
396
  cleanMetadata.unique_identification_number = rawMetadata.unique_identification_number;
179
397
  }
180
- 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'];
181
399
  for (var _i = 0, _priceMetaKeys = priceMetaKeys; _i < _priceMetaKeys.length; _i++) {
182
400
  var key = _priceMetaKeys[_i];
183
401
  if (rawMetadata[key] !== undefined) {
@@ -187,14 +405,18 @@ function normalizeSubmitProduct(product) {
187
405
  if (rawMetadata.price_breakdown) {
188
406
  cleanMetadata.price_breakdown = rawMetadata.price_breakdown;
189
407
  }
408
+ if (rawMetadata.is_rule !== undefined) {
409
+ cleanMetadata.is_rule = rawMetadata.is_rule;
410
+ }
190
411
  return _objectSpread(_objectSpread(_objectSpread({}, submitProduct), bookingUid ? {
191
412
  booking_uid: bookingUid
192
413
  } : {}), {}, {
193
- product_option_item: submitProduct.product_option_item || [],
414
+ product_option_item: formatSubmitOptionItems(submitProduct.product_option_item),
194
415
  discount_list: submitProduct.discount_list || [],
195
- product_bundle: submitProduct.product_bundle || [],
416
+ product_bundle: formatSubmitBundleItems(submitProduct.product_bundle),
196
417
  metadata: cleanMetadata,
197
- // 出站兼容:后端仍消费 payment_price 字段,从 selling_price(券后单价)派生。
418
+ // 出站兼容:后端消费 payment_price 字段,这里从 selling_price 直接派生。
419
+ // 新语义下 selling_price 是 composite(含 option/bundle),payment_price 同语义。
198
420
  payment_price: submitProduct.selling_price
199
421
  });
200
422
  }
@@ -202,19 +424,19 @@ var SUBMIT_BOOKING_METADATA_WHITELIST = ['unique_identification_number', 'collec
202
424
  export function normalizeSubmitBooking(booking) {
203
425
  var rawMetadata = booking.metadata || {};
204
426
  var cleanMetadata = {};
205
- var _iterator = _createForOfIteratorHelper(SUBMIT_BOOKING_METADATA_WHITELIST),
206
- _step;
427
+ var _iterator3 = _createForOfIteratorHelper(SUBMIT_BOOKING_METADATA_WHITELIST),
428
+ _step3;
207
429
  try {
208
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
209
- var key = _step.value;
430
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
431
+ var key = _step3.value;
210
432
  if (rawMetadata[key] !== undefined) {
211
433
  cleanMetadata[key] = rawMetadata[key];
212
434
  }
213
435
  }
214
436
  } catch (err) {
215
- _iterator.e(err);
437
+ _iterator3.e(err);
216
438
  } finally {
217
- _iterator.f();
439
+ _iterator3.f();
218
440
  }
219
441
  return _objectSpread(_objectSpread({}, booking), {}, {
220
442
  metadata: cleanMetadata
@@ -295,7 +517,7 @@ export function createDefaultTempOrder(params) {
295
517
  };
296
518
  }
297
519
  export function buildSubmitPayload(params) {
298
- var _ref2, _ref3, _ref4, _tempOrder$is_price_i, _tempOrder$is_deposit;
520
+ var _ref7, _ref8, _ref9, _tempOrder$is_price_i, _tempOrder$is_deposit;
299
521
  var tempOrder = params.tempOrder,
300
522
  cacheId = params.cacheId,
301
523
  _params$now = params.now,
@@ -303,7 +525,8 @@ export function buildSubmitPayload(params) {
303
525
  platform = params.platform,
304
526
  businessCode = params.businessCode,
305
527
  channel = params.channel,
306
- type = params.type;
528
+ type = params.type,
529
+ enhance = params.enhance;
307
530
  var scheduleDate = tempOrder.schedule_date || tempOrder.created_at || formatDateTime(now);
308
531
  var summary = tempOrder.summary || createEmptySummary();
309
532
  var relationId = tempOrder.relation_id;
@@ -313,8 +536,8 @@ export function buildSubmitPayload(params) {
313
536
  var bookingDuration = resolveTableOccupancyDuration(tempOrder);
314
537
  var bookingEnd = bookingStart.add(bookingDuration, 'minute');
315
538
  var bookings = relationId && tableFormId ? [{
316
- relation_id: relationId,
317
- form_id: tableFormId,
539
+ relation_id: 0,
540
+ form_id: 0,
318
541
  start_time: bookingStart.format('HH:mm'),
319
542
  start_date: bookingStart.format('YYYY-MM-DD'),
320
543
  end_time: bookingEnd.format('HH:mm'),
@@ -326,26 +549,26 @@ export function buildSubmitPayload(params) {
326
549
  },
327
550
  select_date: bookingStart.format('YYYY-MM-DD'),
328
551
  is_all: false,
329
- "like_status": "common",
330
- "schedule_id": 0,
331
- "relation_type": "form",
332
- "number": 1
552
+ like_status: 'common',
553
+ schedule_id: 0,
554
+ relation_type: '',
555
+ number: 1
333
556
  }] : tempOrder.bookings || [];
334
557
  var formRecordIds = relationId && tableFormId ? [{
335
558
  form_id: tableFormId,
336
- form_record_ids: [relationId]
559
+ form_record_id: relationId
337
560
  }] : undefined;
338
561
  var _createdAt = tempOrder.created_at,
339
562
  _summary = tempOrder.summary,
340
563
  _surcharges = tempOrder.surcharges,
341
564
  tempOrderRest = _objectWithoutProperties(tempOrder, _excluded2);
342
- return _objectSpread(_objectSpread({}, tempOrderRest), {}, {
565
+ var payload = _objectSpread(_objectSpread({}, tempOrderRest), {}, {
343
566
  platform: normalizeSubmitPlatform(platform !== null && platform !== void 0 ? platform : tempOrder.platform),
344
567
  request_unique_idempotency_token: cacheId,
345
- type: (_ref2 = type !== null && type !== void 0 ? type : tempOrder.type) !== null && _ref2 !== void 0 ? _ref2 : 'table-order',
346
- 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',
347
570
  sales_channel: tempOrder.sales_channel || 'my_pisel',
348
- 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',
349
572
  status: tempOrder.status || 'normal',
350
573
  payment_status: tempOrder.payment_status || 'payment_processing',
351
574
  // shipping_status: tempOrder.shipping_status || 'unfulfilled',
@@ -368,14 +591,42 @@ export function buildSubmitPayload(params) {
368
591
  contacts_info: tempOrder.contacts_info || [],
369
592
  // holder: tempOrder.holder || null,
370
593
  // summary,
371
- metadata: _objectSpread({}, tempOrder.metadata),
594
+ metadata: function () {
595
+ var _ref10 = tempOrder.metadata || {},
596
+ _collectPax = _ref10.collect_pax,
597
+ _tableOccupancyDuration = _ref10.table_occupancy_duration,
598
+ rest = _objectWithoutProperties(_ref10, _excluded3);
599
+ return _objectSpread({}, rest);
600
+ }(),
372
601
  products: (tempOrder.products || []).map(function (product) {
373
602
  return normalizeSubmitProduct(product);
374
603
  })
375
604
  });
605
+ return enhance ? enhance(payload, {
606
+ tempOrder: tempOrder,
607
+ bookingUuid: bookingUuid,
608
+ now: now
609
+ }) : payload;
376
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
+ */
377
627
  export function formatV1Product(products) {
378
628
  return products.map(function (product) {
629
+ var _product$note;
379
630
  return {
380
631
  bundle: product.product_bundle,
381
632
  key: product.product_id,
@@ -383,6 +634,7 @@ export function formatV1Product(products) {
383
634
  product_id: product.product_id,
384
635
  product_variant_id: product.product_variant_id,
385
636
  num: product.num,
637
+ note: String((_product$note = product.note) !== null && _product$note !== void 0 ? _product$note : ''),
386
638
  rowKey: product.product_id,
387
639
  session: null,
388
640
  unique: createUuidV4()