@pisell/pisellos 0.0.511 → 0.0.512

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.
@@ -1,9 +0,0 @@
1
- // 导出评估器
2
- export { PromotionEvaluator } from "./evaluator";
3
-
4
- // 导出适配器
5
- export { PromotionAdapter } from "./adapter";
6
- export { default } from "./adapter";
7
-
8
- // 导出策略配置示例常量
9
- export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY } from "./examples";
@@ -1,11 +1,11 @@
1
+ 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; } } }; }
1
2
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
3
  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."); }
4
+ 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); }
3
5
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
4
6
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
5
- 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); }
6
- 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; } } }; }
7
- 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); }
8
7
  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; }
8
+ 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); }
9
9
  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; }
10
10
  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; }
11
11
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
@@ -25,7 +25,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
25
25
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
26
26
  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); }
27
27
  import { BaseModule } from "../BaseModule";
28
- import { generateDuration, getAllDiscountList, mergeRelationForms, buildSubmitPayload, createDefaultTempOrder, createDefaultOrderRulesHooks, createEmptySummary, createUuidV4, formatDateTime, filterProductsForScanOrderMore, formatV1Product, isTempOrder } from "./utils";
28
+ import { generateDuration, getAllDiscountList, mergeRelationForms, buildSubmitPayload, createDefaultTempOrder, createDefaultOrderRulesHooks, createEmptySummary, createUuidV4, formatDateTime, filterProductsForScanOrderMore, isTempOrder } from "./utils";
29
29
  import { isNormalProduct } from "../Product/utils";
30
30
  import dayjs from 'dayjs';
31
31
  import { buildProductLineFingerprint, getProductIdentityIndex, getSafeProductNum, isIdentityMatch, normalizeOrderProduct } from "../../solution/ScanOrder/utils";
@@ -388,37 +388,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
388
388
  return;
389
389
  }
390
390
  if (Array.isArray(parsedData.products)) {
391
- var _iterator = _createForOfIteratorHelper(parsedData.products),
392
- _step;
393
- try {
394
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
395
- var p = _step.value;
396
- if (!p || _typeof(p) !== 'object') continue;
397
- if (!Array.isArray(p.product_option_item)) {
398
- p.product_option_item = [];
399
- }
400
- if (!Array.isArray(p.product_bundle)) {
401
- p.product_bundle = [];
391
+ for (var i = 0; i < parsedData.products.length; i++) {
392
+ var p = parsedData.products[i];
393
+ if (!p || _typeof(p) !== 'object') continue;
394
+ if (!Array.isArray(p.product_option_item)) {
395
+ p.product_option_item = [];
396
+ }
397
+ if (!Array.isArray(p.product_bundle)) {
398
+ p.product_bundle = [];
399
+ }
400
+ // 不透明 identity 契约:旧缓存里可能没有 identity_key,
401
+ // 此处统一回填 UUID 并同步 metadata.unique_identification_number,
402
+ // 避免升级后 UI 侧持有的 rowKey 找不到对应行。
403
+ var row = p;
404
+ if (typeof row.identity_key !== 'string' || row.identity_key.length === 0) {
405
+ var newKey = createUuidV4();
406
+ row.identity_key = newKey;
407
+ if (!row.metadata || _typeof(row.metadata) !== 'object') {
408
+ row.metadata = {};
402
409
  }
403
- // 不透明 identity 契约:旧缓存里可能没有 identity_key,
404
- // 此处统一回填 UUID 并同步 metadata.unique_identification_number
405
- // 避免升级后 UI 侧持有的 rowKey 找不到对应行。
406
- var row = p;
407
- if (typeof row.identity_key !== 'string' || row.identity_key.length === 0) {
408
- var newKey = createUuidV4();
409
- row.identity_key = newKey;
410
- if (!row.metadata || _typeof(row.metadata) !== 'object') {
411
- row.metadata = {};
412
- }
413
- if (!row.metadata.unique_identification_number) {
414
- row.metadata.unique_identification_number = newKey;
415
- }
410
+ if (!row.metadata.unique_identification_number) {
411
+ row.metadata.unique_identification_number = newKey;
416
412
  }
417
413
  }
418
- } catch (err) {
419
- _iterator.e(err);
420
- } finally {
421
- _iterator.f();
414
+ // 价格 schema 迁移:重跑 normalizeOrderProduct。
415
+ // `metadata.price_schema_version === 2` → 已是新语义,保留现有 main_product_* 折扣;
416
+ // 否则(v1 或无 metadata)→ 走 legacyDiscount 反推分支,基于新的 source + options
417
+ // 重算出含 option 的 main_product_*,并打上 price_schema_version: 2。
418
+ // 幂等:多次 restore 不会重复叠加 option/bundle。
419
+ parsedData.products[i] = normalizeOrderProduct(row);
422
420
  }
423
421
  }
424
422
  this.store.tempOrder = parsedData;
@@ -692,7 +690,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
692
690
  key: "updateProductInOrder",
693
691
  value: function () {
694
692
  var _updateProductInOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
695
- var product_id, product_variant_id, updates, identity_key, product_option_item, product_bundle, tempOrder, identityLookup, productIndex, targetProduct, nextProduct;
693
+ var _metadata, _metadata2, _metadata3;
694
+ var product_id, product_variant_id, updates, identity_key, product_option_item, product_bundle, tempOrder, identityLookup, productIndex, targetProduct, nextProduct, callerUpdatesTopPrice, callerUpdatesMainMeta, existedMeta;
696
695
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
697
696
  while (1) switch (_context8.prev = _context8.next) {
698
697
  case 0:
@@ -718,16 +717,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
718
717
  product_variant_id: product_variant_id
719
718
  });
720
719
  nextProduct.num = getSafeProductNum(nextProduct.num);
721
- tempOrder.products[productIndex] = nextProduct;
720
+ // 兜底:caller 通过 updates 直接改了 selling_price / original_price 时,
721
+ // 视为 "重新给 source-level 主价"(caller 侧旧约定仍是 main-only 单价)。
722
+ // 清掉 metadata 里的 source_product_price / main_product_* / price_schema_version,
723
+ // 让 normalize 把顶层 selling_price 当作 source 来重算 main_original(=source+options) /
724
+ // main_selling / composite;否则旧 metadata 会反压顶层新值,触发口径不一致。
725
+ // 如果 caller 走推荐路径(updates.metadata.* 显式指定主价),保留 metadata 由 normalize 认它。
726
+ callerUpdatesTopPrice = Object.prototype.hasOwnProperty.call(updates || {}, 'selling_price') || Object.prototype.hasOwnProperty.call(updates || {}, 'original_price');
727
+ callerUpdatesMainMeta = (updates === null || updates === void 0 || (_metadata = updates.metadata) === null || _metadata === void 0 ? void 0 : _metadata.main_product_selling_price) !== undefined || (updates === null || updates === void 0 || (_metadata2 = updates.metadata) === null || _metadata2 === void 0 ? void 0 : _metadata2.main_product_original_price) !== undefined || (updates === null || updates === void 0 || (_metadata3 = updates.metadata) === null || _metadata3 === void 0 ? void 0 : _metadata3.source_product_price) !== undefined;
728
+ if (callerUpdatesTopPrice && !callerUpdatesMainMeta) {
729
+ existedMeta = nextProduct.metadata || {};
730
+ nextProduct.metadata = _objectSpread({}, existedMeta);
731
+ delete nextProduct.metadata.source_product_price;
732
+ delete nextProduct.metadata.main_product_selling_price;
733
+ delete nextProduct.metadata.main_product_original_price;
734
+ delete nextProduct.metadata.price_schema_version;
735
+ }
736
+ // normalizeOrderProduct 幂等:v2 metadata 存在 → 保留 main_product_* 折扣重算 composite;
737
+ // 否则 → 把顶层 selling_price 视作 source,派生 main_product_* 并写 price_schema_version: 2。
738
+ tempOrder.products[productIndex] = normalizeOrderProduct(nextProduct);
722
739
  this.applyDiscount();
723
- _context8.next = 16;
740
+ _context8.next = 19;
724
741
  return this.recalculateSummary({
725
742
  createIfMissing: true
726
743
  });
727
- case 16:
744
+ case 19:
728
745
  this.persistTempOrder();
729
746
  return _context8.abrupt("return", tempOrder.products);
730
- case 18:
747
+ case 21:
731
748
  case "end":
732
749
  return _context8.stop();
733
750
  }
@@ -794,7 +811,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
794
811
  _context10.next = 12;
795
812
  break;
796
813
  }
797
- products = formatV1Product(filterProductsForScanOrderMore(payload.products));
814
+ products = filterProductsForScanOrderMore(payload.products);
798
815
  _context10.next = 8;
799
816
  return this.scanOrderMore({
800
817
  query: {
@@ -1110,7 +1127,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1110
1127
  case 0:
1111
1128
  url = params.url, query = params.query;
1112
1129
  fetchUrl = url || '/order/sales/checkout';
1113
- return _context13.abrupt("return", this.request.post(fetchUrl, query));
1130
+ return _context13.abrupt("return", this.request.post(fetchUrl, query, {
1131
+ customToast: function customToast() {}
1132
+ }));
1114
1133
  case 3:
1115
1134
  case "end":
1116
1135
  return _context13.stop();
@@ -1136,7 +1155,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1136
1155
  products: query.products,
1137
1156
  request_unique_idempotency_token: query.request_unique_idempotency_token
1138
1157
  };
1139
- return _context14.abrupt("return", this.request.put(fetchUrl, requestBody));
1158
+ return _context14.abrupt("return", this.request.put(fetchUrl, requestBody, {
1159
+ customToast: function customToast() {}
1160
+ }));
1140
1161
  case 4:
1141
1162
  case "end":
1142
1163
  return _context14.stop();
@@ -1192,46 +1213,46 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1192
1213
  */
1193
1214
  function populateSavedAmounts(productList, discountList) {
1194
1215
  var savedMap = new Map();
1195
- var _iterator2 = _createForOfIteratorHelper(productList),
1196
- _step2;
1216
+ var _iterator = _createForOfIteratorHelper(productList),
1217
+ _step;
1197
1218
  try {
1198
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1199
- var product = _step2.value;
1219
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1220
+ var product = _step.value;
1200
1221
  var qty = product.num || 1;
1201
- var _iterator4 = _createForOfIteratorHelper(product.discount_list || []),
1202
- _step4;
1222
+ var _iterator3 = _createForOfIteratorHelper(product.discount_list || []),
1223
+ _step3;
1203
1224
  try {
1204
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
1225
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1205
1226
  var _pd$discount, _pd$metadata;
1206
- var pd = _step4.value;
1227
+ var pd = _step3.value;
1207
1228
  var discountKey = ((_pd$discount = pd.discount) === null || _pd$discount === void 0 ? void 0 : _pd$discount.resource_id) || pd.id;
1208
1229
  if (discountKey == null) continue;
1209
1230
  var amount = new Decimal(pd.amount || 0).times(qty).plus(((_pd$metadata = pd.metadata) === null || _pd$metadata === void 0 ? void 0 : _pd$metadata.product_discount_difference) || 0);
1210
1231
  savedMap.set(discountKey, (savedMap.get(discountKey) || new Decimal(0)).plus(amount));
1211
1232
  }
1212
1233
  } catch (err) {
1213
- _iterator4.e(err);
1234
+ _iterator3.e(err);
1214
1235
  } finally {
1215
- _iterator4.f();
1236
+ _iterator3.f();
1216
1237
  }
1217
1238
  }
1218
1239
  } catch (err) {
1219
- _iterator2.e(err);
1240
+ _iterator.e(err);
1220
1241
  } finally {
1221
- _iterator2.f();
1242
+ _iterator.f();
1222
1243
  }
1223
- var _iterator3 = _createForOfIteratorHelper(discountList),
1224
- _step3;
1244
+ var _iterator2 = _createForOfIteratorHelper(discountList),
1245
+ _step2;
1225
1246
  try {
1226
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1227
- var d = _step3.value;
1247
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1248
+ var d = _step2.value;
1228
1249
  var key = d.id;
1229
1250
  d.savedAmount = d.isSelected && key != null && savedMap.has(key) ? savedMap.get(key).toNumber() : 0;
1230
1251
  }
1231
1252
  } catch (err) {
1232
- _iterator3.e(err);
1253
+ _iterator2.e(err);
1233
1254
  } finally {
1234
- _iterator3.f();
1255
+ _iterator2.f();
1235
1256
  }
1236
1257
  }
1237
1258
  }]);
@@ -44,8 +44,19 @@ export interface SubmitScanOrderProduct {
44
44
  num: number;
45
45
  product_variant_id: number;
46
46
  product_option_item: any[];
47
+ /**
48
+ * 行 composite 券后单价。
49
+ * 公式:`metadata.main_product_selling_price` + Σ(bundle_selling_price × num)。
50
+ * 主商品(含 option、含主商品折扣)的单价存在 `metadata.main_product_selling_price`。
51
+ */
47
52
  selling_price: string;
53
+ /**
54
+ * 行 composite 券前单价。
55
+ * 公式:`metadata.main_product_original_price` + Σ(bundle 原价 × num)。
56
+ * 主商品(含 option、不含折扣)的单价存在 `metadata.main_product_original_price`。
57
+ */
48
58
  original_price: string;
59
+ /** 出站兼容字段,直接由 `selling_price` 派生,语义同 composite。 */
49
60
  payment_price: string;
50
61
  tax_fee: string;
51
62
  is_charge_tax: number;
@@ -1,21 +1,66 @@
1
+ import Decimal from 'decimal.js';
1
2
  import { CartItem } from "../Cart";
2
3
  import type { ScanOrderSubmitPayload, ScanOrderSubmitProduct, ScanOrderSummary, ScanOrderTempOrder } from '../../solution/ScanOrder/types';
3
4
  import type { RulesParamsHooks } from '../Rules/types';
5
+ /**
6
+ * 把"含 option 的主商品单价"与 bundle 合成"单行 composite 单价"。
7
+ *
8
+ * 新语义 v2 约定:
9
+ * - `mainPrice` 必须是**已经包含 option 的主商品单价**(即 `metadata.main_product_selling_price`
10
+ * 或 `metadata.main_product_original_price`),option 价格不由本函数叠加。
11
+ * - 套餐价:Σ((bundle.bundle_selling_price ?? bundle.price) × (bundle.num ?? bundle.quantity ?? 1))
12
+ * 当 `useOriginalBundle=true` 时,改用 `bundle.original_price ?? bundle.product_price ?? bundle.price`。
13
+ * - 返回值:保留 2 位小数的字符串,方便直接写回 `selling_price` / `original_price` 字段。
14
+ *
15
+ * 被 `normalizeOrderProduct`、Rules setProduct 钩子、各 Solution 的 setDiscountSelected 共用,
16
+ * 保证合成逻辑单点来源。
17
+ */
18
+ export declare function composeLinePrice(params: {
19
+ mainPrice: string | number | null | undefined;
20
+ bundle?: Array<{
21
+ bundle_selling_price?: any;
22
+ price?: any;
23
+ num?: any;
24
+ quantity?: any;
25
+ original_price?: any;
26
+ product_price?: any;
27
+ }> | null;
28
+ useOriginalBundle?: boolean;
29
+ }): string;
30
+ /**
31
+ * 计算 option 单价合计:Σ(option.price × option.num)。
32
+ * 在新语义 v2 下,main_product_original_price = source_product_price + 本函数结果。
33
+ */
34
+ export declare function sumOptionUnitPrice(options?: Array<{
35
+ price?: any;
36
+ num?: any;
37
+ }> | null): Decimal;
4
38
  /**
5
39
  * OrderModule 默认 Rules 钩子工厂。
6
40
  *
7
- * 价格语义约定(订单域):
8
- * - `selling_price`:券后单品单价(实际成交单价)。初次加购 = `original_price`;券应用后由 Rules 引擎更新。
9
- * - `original_price`:券前单品单价(店铺售价)。不承载后台划线价语义。
10
- * - `payment_price`:已从内部字段移除;只在出站 payload 中由 `selling_price` 派生以兼容后端。
41
+ * 价格语义约定(订单域,v2 composite 口径):
42
+ * - `selling_price`:券后 **行 composite 单价**
43
+ * = `metadata.main_product_selling_price` + Σ(bundle_selling_price × num)。
44
+ * - `original_price`:券前 **行 composite 单价**
45
+ * = `metadata.main_product_original_price` + Σ(bundle 原价 × num)。
46
+ * - `metadata.source_product_price`:主商品/variant 基础价(已应用报价单),不含 option、
47
+ * 不含折扣。**权威源**。
48
+ * - `metadata.main_product_original_price` = source + Σ(option.price × option.num)(含 option、不含折扣)。
49
+ * - `metadata.main_product_selling_price` = main_original − 主商品券 per-unit amount(含 option、含折扣)。
50
+ * - `payment_price`:出站 payload 中由 `selling_price` 派生以兼容后端(composite)。
11
51
  *
12
- * Rules 钩子契约:
13
- * - `getProduct.total` = `selling_price × num`(当前成交总价)
14
- * - `getProduct.origin_total` = `original_price × num`(券前总价)
15
- * - `setProduct` 写回 `selling_price` 的优先级:
16
- * 1. `values.main_product_selling_price`(券应用分支,per-unit 券后主价)
17
- * 2. `values.price`(还原分支 `restoredPrice`、good_pass 归零)
18
- * 3. `values.total / num`(仅当 Rules 只给出总价时的兜底)
52
+ * Rules 钩子契约(hook_adapt 方案,Rules 内部保持不变):
53
+ * - `getProduct.price` / `getProduct.original_price` 回传 **source-level 主价**
54
+ * (`metadata.source_product_price`)。Rules 内部 `getProductTotalPrice` /
55
+ * `getProductOriginTotalPrice` 会自行叠加 option + bundle,喂 source 可避免 option 双加。
56
+ * - `getProduct.total` = `selling_price × num`(行 composite × num),与 Rules 内部产出的
57
+ * total(source + option + bundle)对齐。
58
+ * - `setProduct` 反向流程:把 Rules 返回的 source-level `main_product_selling_price` / `price`
59
+ * 加回 Σoptions,重新合成含 option 的 main_product_* 并派生 composite。
60
+ * 优先级:
61
+ * 1. `values.main_product_selling_price`(券应用分支,per-unit 券后 source-level 主价)
62
+ * 2. `values.price`(还原分支 `restoredPrice`、good_pass 归零)
63
+ * 3. `values.total / num`(仅当 Rules 只给出总价时的兜底)
19
64
  *
20
65
  * 导出为纯函数方便单测直接驱动钩子,不依赖 OrderModule 实例。
21
66
  */
@@ -74,6 +119,13 @@ export declare function buildSubmitPayload(params: {
74
119
  }): ScanOrderSubmitPayload;
75
120
  /** 加单(scanOrderMore)不应提交 booking 关联的虚拟规则商品行 */
76
121
  export declare function filterProductsForScanOrderMore(products: ScanOrderSubmitProduct[]): ScanOrderSubmitProduct[];
122
+ /**
123
+ * 历史 V1 加餐结构映射器。
124
+ *
125
+ * @deprecated 加餐(`PUT /order/order/product/:id`)已改为与正常 checkout 共用
126
+ * `ScanOrderSubmitProduct` 新结构(见 `OrderModule.submitTempOrder` 的加餐分支)。
127
+ * 本函数仅保留以兼容历史接入方,未来会移除。新代码请勿再调用。
128
+ */
77
129
  export declare function formatV1Product(products: ScanOrderSubmitProduct[]): {
78
130
  bundle: any[];
79
131
  key: number | null;