@pisell/pisellos 0.0.510 → 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,6 +1,6 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
- import { OrderModuleAPI, CommitOrderParams, SubmitScanOrderParams, ScanOrderMoreParams, CheckoutOrderParams } from './types';
3
+ import { OrderModuleAPI, CommitOrderParams, SubmitScanOrderParams, ScanOrderMoreParams, CheckoutOrderParams, UpdateProductInOrderParams } from './types';
4
4
  import { CartItem } from '../Cart/types';
5
5
  import { type SubmitPayloadEnhancer } from './utils';
6
6
  import type { ScanOrderOrderProduct, ScanOrderOrderProductIdentity, ScanOrderSummary, ScanOrderTempOrder } from '../../solution/ScanOrder/types';
@@ -71,11 +71,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
71
71
  updateTempOrderBuzzer(buzzer: string): string;
72
72
  updateTempOrderContactsInfo(contactsInfo: any[]): any[];
73
73
  addProductToOrder(product: Partial<ScanOrderOrderProduct> & ScanOrderOrderProductIdentity): Promise<ScanOrderOrderProduct[]>;
74
- updateProductInOrder(params: {
75
- product_id: number | null;
76
- product_variant_id: number;
77
- updates: Partial<ScanOrderOrderProduct>;
78
- }): Promise<ScanOrderOrderProduct[]>;
74
+ updateProductInOrder(params: UpdateProductInOrderParams): Promise<ScanOrderOrderProduct[]>;
79
75
  removeProductFromOrder(identity: ScanOrderOrderProductIdentity): Promise<ScanOrderOrderProduct[]>;
80
76
  submitTempOrder<T = any>(params?: {
81
77
  cacheId?: string;
@@ -119,3 +115,4 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
119
115
  getOrderInfoByRemote(order_id: number): Promise<any>;
120
116
  getLastOrderInfo(): Record<string, any> | undefined;
121
117
  }
118
+ export type { UpdateProductInOrderParams } from './types';
@@ -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,10 +25,10 @@ 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, 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
- import { getProductIdentityIndex, getSafeProductNum, isIdentityMatch, normalizeOrderProduct } from "../../solution/ScanOrder/utils";
31
+ import { buildProductLineFingerprint, getProductIdentityIndex, getSafeProductNum, isIdentityMatch, normalizeOrderProduct } from "../../solution/ScanOrder/utils";
32
32
  import { DiscountModule } from "../Discount";
33
33
  import { RulesModule } from "../Rules";
34
34
  import { UnavailableReason } from "../Rules/types";
@@ -388,23 +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 = [];
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 = {};
399
409
  }
400
- if (!Array.isArray(p.product_bundle)) {
401
- p.product_bundle = [];
410
+ if (!row.metadata.unique_identification_number) {
411
+ row.metadata.unique_identification_number = newKey;
402
412
  }
403
413
  }
404
- } catch (err) {
405
- _iterator.e(err);
406
- } finally {
407
- _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);
408
420
  }
409
421
  }
410
422
  this.store.tempOrder = parsedData;
@@ -611,31 +623,59 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
611
623
  key: "addProductToOrder",
612
624
  value: function () {
613
625
  var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(product) {
614
- var tempOrder, normalizedProduct, productIndex, targetProduct;
626
+ var tempOrder, hasExplicitIdentityKey, normalizedProduct, productIndex, targetProduct, incomingFingerprint, matchedIndex, _normalizedProduct, _targetProduct, _normalizedProduct2;
615
627
  return _regeneratorRuntime().wrap(function _callee7$(_context7) {
616
628
  while (1) switch (_context7.prev = _context7.next) {
617
629
  case 0:
618
630
  tempOrder = this.ensureTempOrder();
619
- normalizedProduct = normalizeOrderProduct(product);
620
- productIndex = getProductIdentityIndex(tempOrder.products, normalizedProduct);
621
- if (productIndex === -1) {
622
- tempOrder.products.push(normalizedProduct);
631
+ hasExplicitIdentityKey = typeof product.identity_key === 'string' && product.identity_key.length > 0;
632
+ if (hasExplicitIdentityKey) {
633
+ // 调用方自持 identity_key(如 VenueBooking 外部生成)→ 走严格 identity 合并。
634
+ normalizedProduct = normalizeOrderProduct(product);
635
+ productIndex = getProductIdentityIndex(tempOrder.products, normalizedProduct);
636
+ if (productIndex === -1) {
637
+ tempOrder.products.push(normalizedProduct);
638
+ } else {
639
+ targetProduct = tempOrder.products[productIndex];
640
+ tempOrder.products[productIndex] = _objectSpread(_objectSpread(_objectSpread({}, targetProduct), normalizedProduct), {}, {
641
+ num: getSafeProductNum(targetProduct.num + normalizedProduct.num),
642
+ _origin: normalizedProduct._origin || targetProduct._origin
643
+ });
644
+ }
623
645
  } else {
624
- targetProduct = tempOrder.products[productIndex];
625
- tempOrder.products[productIndex] = _objectSpread(_objectSpread(_objectSpread({}, targetProduct), normalizedProduct), {}, {
626
- num: getSafeProductNum(targetProduct.num + normalizedProduct.num),
627
- _origin: normalizedProduct._origin || targetProduct._origin
646
+ // identity_key:按 SKU + 内容指纹(options + bundle)匹配既有行以累加数量;
647
+ // 命中时保留已有 identity_key,未命中才由 normalizeOrderProduct 自动生成 UUID。
648
+ incomingFingerprint = buildProductLineFingerprint(product.product_option_item, product.product_bundle);
649
+ matchedIndex = tempOrder.products.findIndex(function (item) {
650
+ if (item.product_id !== product.product_id) return false;
651
+ if (item.product_variant_id !== product.product_variant_id) return false;
652
+ var existedFingerprint = buildProductLineFingerprint(item.product_option_item, item.product_bundle);
653
+ return existedFingerprint === incomingFingerprint;
628
654
  });
655
+ if (matchedIndex === -1) {
656
+ _normalizedProduct = normalizeOrderProduct(product);
657
+ tempOrder.products.push(_normalizedProduct);
658
+ } else {
659
+ _targetProduct = tempOrder.products[matchedIndex];
660
+ _normalizedProduct2 = normalizeOrderProduct(_objectSpread(_objectSpread({}, product), {}, {
661
+ identity_key: _targetProduct.identity_key
662
+ }));
663
+ tempOrder.products[matchedIndex] = _objectSpread(_objectSpread(_objectSpread({}, _targetProduct), _normalizedProduct2), {}, {
664
+ identity_key: _targetProduct.identity_key,
665
+ num: getSafeProductNum(_targetProduct.num + _normalizedProduct2.num),
666
+ _origin: _normalizedProduct2._origin || _targetProduct._origin
667
+ });
668
+ }
629
669
  }
630
670
  this.applyDiscount();
631
- _context7.next = 7;
671
+ _context7.next = 6;
632
672
  return this.recalculateSummary({
633
673
  createIfMissing: true
634
674
  });
635
- case 7:
675
+ case 6:
636
676
  this.persistTempOrder();
637
677
  return _context7.abrupt("return", tempOrder.products);
638
- case 9:
678
+ case 8:
639
679
  case "end":
640
680
  return _context7.stop();
641
681
  }
@@ -650,38 +690,61 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
650
690
  key: "updateProductInOrder",
651
691
  value: function () {
652
692
  var _updateProductInOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
653
- var product_id, product_variant_id, updates, tempOrder, 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;
654
695
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
655
696
  while (1) switch (_context8.prev = _context8.next) {
656
697
  case 0:
657
- product_id = params.product_id, product_variant_id = params.product_variant_id, updates = params.updates;
698
+ product_id = params.product_id, product_variant_id = params.product_variant_id, updates = params.updates, identity_key = params.identity_key, product_option_item = params.product_option_item, product_bundle = params.product_bundle;
658
699
  tempOrder = this.ensureTempOrder();
659
- productIndex = getProductIdentityIndex(tempOrder.products, {
700
+ identityLookup = {
660
701
  product_id: product_id,
661
702
  product_variant_id: product_variant_id
662
- });
703
+ };
704
+ if (identity_key !== undefined) identityLookup.identity_key = identity_key;
705
+ if (product_option_item !== undefined) identityLookup.product_option_item = product_option_item;
706
+ if (product_bundle !== undefined) identityLookup.product_bundle = product_bundle;
707
+ productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
663
708
  if (!(productIndex === -1)) {
664
- _context8.next = 5;
709
+ _context8.next = 9;
665
710
  break;
666
711
  }
667
712
  throw new Error('[Order] 目标商品不存在,无法更新');
668
- case 5:
713
+ case 9:
669
714
  targetProduct = tempOrder.products[productIndex];
670
715
  nextProduct = _objectSpread(_objectSpread(_objectSpread({}, targetProduct), updates), {}, {
671
716
  product_id: product_id,
672
717
  product_variant_id: product_variant_id
673
718
  });
674
719
  nextProduct.num = getSafeProductNum(nextProduct.num);
675
- 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);
676
739
  this.applyDiscount();
677
- _context8.next = 12;
740
+ _context8.next = 19;
678
741
  return this.recalculateSummary({
679
742
  createIfMissing: true
680
743
  });
681
- case 12:
744
+ case 19:
682
745
  this.persistTempOrder();
683
746
  return _context8.abrupt("return", tempOrder.products);
684
- case 14:
747
+ case 21:
685
748
  case "end":
686
749
  return _context8.stop();
687
750
  }
@@ -748,7 +811,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
748
811
  _context10.next = 12;
749
812
  break;
750
813
  }
751
- products = formatV1Product(filterProductsForScanOrderMore(payload.products));
814
+ products = filterProductsForScanOrderMore(payload.products);
752
815
  _context10.next = 8;
753
816
  return this.scanOrderMore({
754
817
  query: {
@@ -1064,7 +1127,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1064
1127
  case 0:
1065
1128
  url = params.url, query = params.query;
1066
1129
  fetchUrl = url || '/order/sales/checkout';
1067
- return _context13.abrupt("return", this.request.post(fetchUrl, query));
1130
+ return _context13.abrupt("return", this.request.post(fetchUrl, query, {
1131
+ customToast: function customToast() {}
1132
+ }));
1068
1133
  case 3:
1069
1134
  case "end":
1070
1135
  return _context13.stop();
@@ -1090,7 +1155,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1090
1155
  products: query.products,
1091
1156
  request_unique_idempotency_token: query.request_unique_idempotency_token
1092
1157
  };
1093
- return _context14.abrupt("return", this.request.put(fetchUrl, requestBody));
1158
+ return _context14.abrupt("return", this.request.put(fetchUrl, requestBody, {
1159
+ customToast: function customToast() {}
1160
+ }));
1094
1161
  case 4:
1095
1162
  case "end":
1096
1163
  return _context14.stop();
@@ -1146,46 +1213,46 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1146
1213
  */
1147
1214
  function populateSavedAmounts(productList, discountList) {
1148
1215
  var savedMap = new Map();
1149
- var _iterator2 = _createForOfIteratorHelper(productList),
1150
- _step2;
1216
+ var _iterator = _createForOfIteratorHelper(productList),
1217
+ _step;
1151
1218
  try {
1152
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1153
- var product = _step2.value;
1219
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1220
+ var product = _step.value;
1154
1221
  var qty = product.num || 1;
1155
- var _iterator4 = _createForOfIteratorHelper(product.discount_list || []),
1156
- _step4;
1222
+ var _iterator3 = _createForOfIteratorHelper(product.discount_list || []),
1223
+ _step3;
1157
1224
  try {
1158
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
1225
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1159
1226
  var _pd$discount, _pd$metadata;
1160
- var pd = _step4.value;
1227
+ var pd = _step3.value;
1161
1228
  var discountKey = ((_pd$discount = pd.discount) === null || _pd$discount === void 0 ? void 0 : _pd$discount.resource_id) || pd.id;
1162
1229
  if (discountKey == null) continue;
1163
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);
1164
1231
  savedMap.set(discountKey, (savedMap.get(discountKey) || new Decimal(0)).plus(amount));
1165
1232
  }
1166
1233
  } catch (err) {
1167
- _iterator4.e(err);
1234
+ _iterator3.e(err);
1168
1235
  } finally {
1169
- _iterator4.f();
1236
+ _iterator3.f();
1170
1237
  }
1171
1238
  }
1172
1239
  } catch (err) {
1173
- _iterator2.e(err);
1240
+ _iterator.e(err);
1174
1241
  } finally {
1175
- _iterator2.f();
1242
+ _iterator.f();
1176
1243
  }
1177
- var _iterator3 = _createForOfIteratorHelper(discountList),
1178
- _step3;
1244
+ var _iterator2 = _createForOfIteratorHelper(discountList),
1245
+ _step2;
1179
1246
  try {
1180
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1181
- var d = _step3.value;
1247
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1248
+ var d = _step2.value;
1182
1249
  var key = d.id;
1183
1250
  d.savedAmount = d.isSelected && key != null && savedMap.has(key) ? savedMap.get(key).toNumber() : 0;
1184
1251
  }
1185
1252
  } catch (err) {
1186
- _iterator3.e(err);
1253
+ _iterator2.e(err);
1187
1254
  } finally {
1188
- _iterator3.f();
1255
+ _iterator2.f();
1189
1256
  }
1190
1257
  }
1191
1258
  }]);
@@ -16,6 +16,15 @@ export interface OrderState {
16
16
  discount: DiscountModule | null;
17
17
  rules: RulesModule | null;
18
18
  }
19
+ /** 更新购物车行:仅传 SKU 时命中同 SKU 第一行;多行同 SKU 须传 identity_key / 选项指纹等 */
20
+ export interface UpdateProductInOrderParams {
21
+ product_id: number | null;
22
+ product_variant_id: number;
23
+ updates: Partial<ScanOrderOrderProduct>;
24
+ identity_key?: string;
25
+ product_option_item?: any[];
26
+ product_bundle?: any[];
27
+ }
19
28
  /**
20
29
  * 订单信息
21
30
  */
@@ -35,14 +44,27 @@ export interface SubmitScanOrderProduct {
35
44
  num: number;
36
45
  product_variant_id: number;
37
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
+ */
38
52
  selling_price: string;
53
+ /**
54
+ * 行 composite 券前单价。
55
+ * 公式:`metadata.main_product_original_price` + Σ(bundle 原价 × num)。
56
+ * 主商品(含 option、不含折扣)的单价存在 `metadata.main_product_original_price`。
57
+ */
39
58
  original_price: string;
59
+ /** 出站兼容字段,直接由 `selling_price` 派生,语义同 composite。 */
40
60
  payment_price: string;
41
61
  tax_fee: string;
42
62
  is_charge_tax: number;
43
63
  discount_list: any[];
44
64
  product_bundle: any[];
45
65
  metadata: Record<string, any>;
66
+ /** 商品行备注 */
67
+ note?: string;
46
68
  }
47
69
  export interface SubmitScanOrderSummary {
48
70
  product_quantity: number;
@@ -210,11 +232,7 @@ export interface OrderModuleAPI {
210
232
  updateTempOrderBuzzer: (buzzer: string) => string;
211
233
  updateTempOrderContactsInfo: (contactsInfo: any[]) => any[];
212
234
  addProductToOrder: (product: Partial<ScanOrderOrderProduct> & ScanOrderOrderProductIdentity) => Promise<ScanOrderOrderProduct[]>;
213
- updateProductInOrder: (params: {
214
- product_id: number | null;
215
- product_variant_id: number;
216
- updates: Partial<ScanOrderOrderProduct>;
217
- }) => Promise<ScanOrderOrderProduct[]>;
235
+ updateProductInOrder: (params: UpdateProductInOrderParams) => Promise<ScanOrderOrderProduct[]>;
218
236
  removeProductFromOrder: (identity: ScanOrderOrderProductIdentity) => Promise<ScanOrderOrderProduct[]>;
219
237
  persistTempOrder: () => void;
220
238
  submitTempOrder: <T = any>(params?: {
@@ -6,6 +6,8 @@ export var OrderHooks = /*#__PURE__*/function (OrderHooks) {
6
6
  return OrderHooks;
7
7
  }({});
8
8
 
9
+ /** 更新购物车行:仅传 SKU 时命中同 SKU 第一行;多行同 SKU 须传 identity_key / 选项指纹等 */
10
+
9
11
  /**
10
12
  * 订单信息
11
13
  */
@@ -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;
@@ -81,6 +133,7 @@ export declare function formatV1Product(products: ScanOrderSubmitProduct[]): {
81
133
  product_id: number | null;
82
134
  product_variant_id: number;
83
135
  num: number;
136
+ note: string;
84
137
  rowKey: number | null;
85
138
  session: null;
86
139
  unique: string;