@pisell/pisellos 2.1.119 → 2.1.120

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 (231) hide show
  1. package/dist/apis/picoding.d.ts +0 -0
  2. package/dist/apis/picoding.js +1 -0
  3. package/dist/model/index.d.ts +1 -0
  4. package/dist/model/index.js +1 -0
  5. package/dist/model/strategy/adapter/index.d.ts +7 -0
  6. package/dist/model/strategy/adapter/index.js +7 -0
  7. package/dist/model/strategy/adapter/itemRule/adapter.d.ts +59 -0
  8. package/dist/model/strategy/adapter/itemRule/adapter.js +439 -0
  9. package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
  10. package/dist/model/strategy/adapter/itemRule/evaluator.js +169 -0
  11. package/dist/model/strategy/adapter/itemRule/examples.d.ts +64 -0
  12. package/dist/model/strategy/adapter/itemRule/examples.js +315 -0
  13. package/dist/model/strategy/adapter/itemRule/index.d.ts +5 -0
  14. package/dist/model/strategy/adapter/itemRule/index.js +5 -0
  15. package/dist/model/strategy/adapter/itemRule/type.d.ts +206 -0
  16. package/dist/model/strategy/adapter/itemRule/type.js +101 -0
  17. package/dist/model/strategy/adapter/promotion/adapter.d.ts +66 -0
  18. package/dist/model/strategy/adapter/promotion/adapter.js +271 -0
  19. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +213 -0
  20. package/dist/model/strategy/adapter/promotion/evaluator.js +1206 -0
  21. package/dist/model/strategy/adapter/promotion/examples.d.ts +138 -0
  22. package/dist/model/strategy/adapter/promotion/examples.js +166 -0
  23. package/dist/model/strategy/adapter/promotion/index.d.ts +4 -0
  24. package/dist/model/strategy/adapter/promotion/index.js +0 -0
  25. package/dist/model/strategy/adapter/promotion/type.d.ts +447 -0
  26. package/dist/model/strategy/adapter/promotion/type.js +209 -0
  27. package/dist/model/strategy/adapter/type.d.ts +28 -0
  28. package/dist/model/strategy/adapter/type.js +1 -0
  29. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
  30. package/dist/model/strategy/adapter/walletPass/evaluator.js +502 -0
  31. package/dist/model/strategy/adapter/walletPass/example.d.ts +4 -0
  32. package/dist/model/strategy/adapter/walletPass/example.js +258 -0
  33. package/dist/model/strategy/adapter/walletPass/index.d.ts +32 -0
  34. package/dist/model/strategy/adapter/walletPass/index.js +182 -0
  35. package/dist/model/strategy/adapter/walletPass/locales.d.ts +1 -0
  36. package/dist/model/strategy/adapter/walletPass/locales.js +26 -0
  37. package/dist/model/strategy/adapter/walletPass/type.d.ts +187 -0
  38. package/dist/model/strategy/adapter/walletPass/type.js +1 -0
  39. package/dist/model/strategy/adapter/walletPass/utils.d.ts +50 -0
  40. package/dist/model/strategy/adapter/walletPass/utils.js +1104 -0
  41. package/dist/model/strategy/engine.d.ts +106 -0
  42. package/dist/model/strategy/engine.js +611 -0
  43. package/dist/model/strategy/index.d.ts +3 -0
  44. package/dist/model/strategy/index.js +8 -0
  45. package/dist/model/strategy/strategy-example.d.ts +5 -0
  46. package/dist/model/strategy/strategy-example.js +331 -0
  47. package/dist/model/strategy/type.d.ts +228 -0
  48. package/dist/model/strategy/type.js +94 -0
  49. package/dist/modules/Cart/utils/cartProduct.js +1 -0
  50. package/dist/modules/OpenData/index.d.ts +23 -0
  51. package/dist/modules/OpenData/index.js +167 -0
  52. package/dist/modules/OpenData/types.d.ts +73 -0
  53. package/dist/modules/OpenData/types.js +1 -0
  54. package/dist/modules/OpenData/utils.d.ts +2 -0
  55. package/dist/modules/OpenData/utils.js +75 -0
  56. package/dist/modules/Order/index.d.ts +58 -1
  57. package/dist/modules/Order/index.js +780 -29
  58. package/dist/modules/Order/types.d.ts +144 -12
  59. package/dist/modules/Order/utils.d.ts +25 -0
  60. package/dist/modules/Order/utils.js +225 -1
  61. package/dist/modules/Product/index.d.ts +1 -1
  62. package/dist/modules/Product/utils.js +2 -2
  63. package/dist/modules/ProductList/index.d.ts +1 -1
  64. package/dist/modules/ProductList/index.js +2 -1
  65. package/dist/modules/Quotation/index.d.ts +48 -0
  66. package/dist/modules/Quotation/index.js +245 -0
  67. package/dist/modules/Quotation/types.d.ts +42 -0
  68. package/dist/modules/Quotation/types.js +1 -0
  69. package/dist/modules/Rules/index.js +4 -1
  70. package/dist/modules/SalesSummary/index.d.ts +63 -0
  71. package/dist/modules/SalesSummary/index.js +174 -0
  72. package/dist/modules/SalesSummary/types.d.ts +59 -0
  73. package/dist/modules/SalesSummary/types.js +1 -0
  74. package/dist/modules/SalesSummary/utils.d.ts +30 -0
  75. package/dist/modules/SalesSummary/utils.js +513 -0
  76. package/dist/modules/ScanOrderLogger/index.d.ts +21 -0
  77. package/dist/modules/ScanOrderLogger/index.js +161 -0
  78. package/dist/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
  79. package/dist/modules/ScanOrderLogger/providers/feishu.js +95 -0
  80. package/dist/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
  81. package/dist/modules/ScanOrderLogger/providers/grafana.js +50 -0
  82. package/dist/modules/ScanOrderLogger/types.d.ts +46 -0
  83. package/dist/modules/ScanOrderLogger/types.js +1 -0
  84. package/dist/modules/Schedule/getDateIsInSchedule.js +11 -18
  85. package/dist/modules/Summary/utils.d.ts +3 -3
  86. package/dist/modules/Summary/utils.js +4 -4
  87. package/dist/modules/index.d.ts +4 -0
  88. package/dist/modules/index.js +5 -1
  89. package/dist/solution/BookingByStep/index.d.ts +1 -1
  90. package/dist/solution/BookingByStep/types.d.ts +3 -1
  91. package/dist/solution/BookingByStep/types.js +5 -1
  92. package/dist/solution/BookingTicket/index.d.ts +1 -1
  93. package/dist/solution/ScanOrder/index.d.ts +90 -0
  94. package/dist/solution/ScanOrder/index.js +1853 -0
  95. package/dist/solution/ScanOrder/types.d.ts +210 -0
  96. package/dist/solution/ScanOrder/types.js +16 -0
  97. package/dist/solution/ScanOrder/utils.d.ts +93 -0
  98. package/dist/solution/ScanOrder/utils.js +397 -0
  99. package/dist/solution/VenueBooking/index.d.ts +158 -0
  100. package/dist/solution/VenueBooking/index.js +2873 -0
  101. package/dist/solution/VenueBooking/sales-section-4-annotated.json +343 -0
  102. package/dist/solution/VenueBooking/types.d.ts +130 -0
  103. package/dist/solution/VenueBooking/types.js +21 -0
  104. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +10 -0
  105. package/dist/solution/VenueBooking/utils/dateSummary.js +102 -0
  106. package/dist/solution/VenueBooking/utils/resource.d.ts +4 -0
  107. package/dist/solution/VenueBooking/utils/resource.js +94 -0
  108. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +29 -0
  109. package/dist/solution/VenueBooking/utils/slotMerge.js +204 -0
  110. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
  111. package/dist/solution/VenueBooking/utils/timeSlot.js +256 -0
  112. package/dist/solution/VenueBooking/utils.d.ts +1 -0
  113. package/dist/solution/VenueBooking/utils.js +1 -0
  114. package/dist/solution/index.d.ts +2 -0
  115. package/dist/solution/index.js +3 -1
  116. package/lib/apis/picoding.d.ts +0 -0
  117. package/lib/apis/picoding.js +0 -0
  118. package/lib/model/index.d.ts +1 -0
  119. package/lib/model/index.js +23 -0
  120. package/lib/model/strategy/adapter/index.d.ts +7 -0
  121. package/lib/model/strategy/adapter/index.js +57 -0
  122. package/lib/model/strategy/adapter/itemRule/adapter.d.ts +59 -0
  123. package/lib/model/strategy/adapter/itemRule/adapter.js +338 -0
  124. package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
  125. package/lib/model/strategy/adapter/itemRule/evaluator.js +124 -0
  126. package/lib/model/strategy/adapter/itemRule/examples.d.ts +64 -0
  127. package/lib/model/strategy/adapter/itemRule/examples.js +269 -0
  128. package/lib/model/strategy/adapter/itemRule/index.d.ts +5 -0
  129. package/lib/model/strategy/adapter/itemRule/index.js +58 -0
  130. package/lib/model/strategy/adapter/itemRule/type.d.ts +206 -0
  131. package/lib/model/strategy/adapter/itemRule/type.js +46 -0
  132. package/lib/model/strategy/adapter/promotion/adapter.d.ts +66 -0
  133. package/lib/model/strategy/adapter/promotion/adapter.js +217 -0
  134. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +213 -0
  135. package/lib/model/strategy/adapter/promotion/evaluator.js +844 -0
  136. package/lib/model/strategy/adapter/promotion/examples.d.ts +138 -0
  137. package/lib/model/strategy/adapter/promotion/examples.js +192 -0
  138. package/lib/model/strategy/adapter/promotion/index.d.ts +4 -0
  139. package/lib/model/strategy/adapter/promotion/index.js +0 -0
  140. package/lib/model/strategy/adapter/promotion/type.d.ts +447 -0
  141. package/lib/model/strategy/adapter/promotion/type.js +51 -0
  142. package/lib/model/strategy/adapter/type.d.ts +28 -0
  143. package/lib/model/strategy/adapter/type.js +17 -0
  144. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
  145. package/lib/model/strategy/adapter/walletPass/evaluator.js +424 -0
  146. package/lib/model/strategy/adapter/walletPass/example.d.ts +4 -0
  147. package/lib/model/strategy/adapter/walletPass/example.js +207 -0
  148. package/lib/model/strategy/adapter/walletPass/index.d.ts +32 -0
  149. package/lib/model/strategy/adapter/walletPass/index.js +142 -0
  150. package/lib/model/strategy/adapter/walletPass/locales.d.ts +1 -0
  151. package/lib/model/strategy/adapter/walletPass/locales.js +54 -0
  152. package/lib/model/strategy/adapter/walletPass/type.d.ts +187 -0
  153. package/lib/model/strategy/adapter/walletPass/type.js +17 -0
  154. package/lib/model/strategy/adapter/walletPass/utils.d.ts +50 -0
  155. package/lib/model/strategy/adapter/walletPass/utils.js +791 -0
  156. package/lib/model/strategy/engine.d.ts +106 -0
  157. package/lib/model/strategy/engine.js +450 -0
  158. package/lib/model/strategy/index.d.ts +3 -0
  159. package/lib/model/strategy/index.js +38 -0
  160. package/lib/model/strategy/strategy-example.d.ts +5 -0
  161. package/lib/model/strategy/strategy-example.js +318 -0
  162. package/lib/model/strategy/type.d.ts +228 -0
  163. package/lib/model/strategy/type.js +44 -0
  164. package/lib/modules/Cart/utils/cartProduct.js +1 -0
  165. package/lib/modules/OpenData/index.d.ts +23 -0
  166. package/lib/modules/OpenData/index.js +116 -0
  167. package/lib/modules/OpenData/types.d.ts +73 -0
  168. package/lib/modules/OpenData/types.js +17 -0
  169. package/lib/modules/OpenData/utils.d.ts +2 -0
  170. package/lib/modules/OpenData/utils.js +111 -0
  171. package/lib/modules/Order/index.d.ts +58 -1
  172. package/lib/modules/Order/index.js +423 -1
  173. package/lib/modules/Order/types.d.ts +144 -12
  174. package/lib/modules/Order/utils.d.ts +25 -0
  175. package/lib/modules/Order/utils.js +229 -0
  176. package/lib/modules/Product/index.d.ts +1 -1
  177. package/lib/modules/Product/utils.js +2 -2
  178. package/lib/modules/ProductList/index.d.ts +1 -1
  179. package/lib/modules/ProductList/index.js +2 -1
  180. package/lib/modules/Quotation/index.d.ts +48 -0
  181. package/lib/modules/Quotation/index.js +149 -0
  182. package/lib/modules/Quotation/types.d.ts +42 -0
  183. package/lib/modules/Quotation/types.js +17 -0
  184. package/lib/modules/Rules/index.js +4 -1
  185. package/lib/modules/SalesSummary/index.d.ts +63 -0
  186. package/lib/modules/SalesSummary/index.js +105 -0
  187. package/lib/modules/SalesSummary/types.d.ts +59 -0
  188. package/lib/modules/SalesSummary/types.js +17 -0
  189. package/lib/modules/SalesSummary/utils.d.ts +30 -0
  190. package/lib/modules/SalesSummary/utils.js +452 -0
  191. package/lib/modules/ScanOrderLogger/index.d.ts +21 -0
  192. package/lib/modules/ScanOrderLogger/index.js +135 -0
  193. package/lib/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
  194. package/lib/modules/ScanOrderLogger/providers/feishu.js +82 -0
  195. package/lib/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
  196. package/lib/modules/ScanOrderLogger/providers/grafana.js +52 -0
  197. package/lib/modules/ScanOrderLogger/types.d.ts +46 -0
  198. package/lib/modules/ScanOrderLogger/types.js +17 -0
  199. package/lib/modules/Schedule/getDateIsInSchedule.js +9 -11
  200. package/lib/modules/Summary/utils.d.ts +3 -3
  201. package/lib/modules/Summary/utils.js +4 -4
  202. package/lib/modules/index.d.ts +4 -0
  203. package/lib/modules/index.js +9 -1
  204. package/lib/solution/BookingByStep/index.d.ts +1 -1
  205. package/lib/solution/BookingByStep/types.d.ts +3 -1
  206. package/lib/solution/BookingByStep/types.js +10 -0
  207. package/lib/solution/BookingTicket/index.d.ts +1 -1
  208. package/lib/solution/ScanOrder/index.d.ts +90 -0
  209. package/lib/solution/ScanOrder/index.js +1071 -0
  210. package/lib/solution/ScanOrder/types.d.ts +210 -0
  211. package/lib/solution/ScanOrder/types.js +36 -0
  212. package/lib/solution/ScanOrder/utils.d.ts +93 -0
  213. package/lib/solution/ScanOrder/utils.js +359 -0
  214. package/lib/solution/VenueBooking/index.d.ts +158 -0
  215. package/lib/solution/VenueBooking/index.js +1545 -0
  216. package/lib/solution/VenueBooking/sales-section-4-annotated.json +343 -0
  217. package/lib/solution/VenueBooking/types.d.ts +130 -0
  218. package/lib/solution/VenueBooking/types.js +44 -0
  219. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +10 -0
  220. package/lib/solution/VenueBooking/utils/dateSummary.js +101 -0
  221. package/lib/solution/VenueBooking/utils/resource.d.ts +4 -0
  222. package/lib/solution/VenueBooking/utils/resource.js +80 -0
  223. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +29 -0
  224. package/lib/solution/VenueBooking/utils/slotMerge.js +209 -0
  225. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
  226. package/lib/solution/VenueBooking/utils/timeSlot.js +200 -0
  227. package/lib/solution/VenueBooking/utils.d.ts +1 -0
  228. package/lib/solution/VenueBooking/utils.js +69 -0
  229. package/lib/solution/index.d.ts +2 -0
  230. package/lib/solution/index.js +5 -1
  231. package/package.json +1 -1
@@ -0,0 +1,1853 @@
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; } } }; }
2
+ 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
+ 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; }
4
+ 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); }
5
+ 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; }
6
+ 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; }
7
+ 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; }
8
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
9
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
10
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
11
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
12
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
13
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
14
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
15
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
16
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
17
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
18
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
19
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
20
+ 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; }
21
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
22
+ 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); }
23
+ import { BaseModule } from "../../modules/BaseModule";
24
+ import { ScanOrderHooks } from "./types";
25
+ import { attachItemRuleLimitsToTopLevelProducts, buildProductKey, buildItemRuleBusinessData, createEmptySummary, getProductIdentityIndex, getSafeProductNum, normalizeEnabledItemRuleIds, normalizeOrderProduct, normalizeItemRuleStrategies, toNonNegativeInt, toNonNegativeNumber, toPriceString, toBoolean, toPositiveString } from "./utils";
26
+ import { createModule } from "../BookingByStep/types";
27
+ import dayjs from 'dayjs';
28
+ import { ItemRuleEvaluator } from "../../model/strategy/adapter/itemRule";
29
+ export * from "./types";
30
+ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
31
+ _inherits(ScanOrderImpl, _BaseModule);
32
+ var _super = _createSuper(ScanOrderImpl);
33
+ function ScanOrderImpl(name, version) {
34
+ var _this;
35
+ _classCallCheck(this, ScanOrderImpl);
36
+ _this = _super.call(this, name, version);
37
+ _defineProperty(_assertThisInitialized(_this), "defaultName", 'scanOrder');
38
+ _defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
39
+ _defineProperty(_assertThisInitialized(_this), "isSolution", true);
40
+ _defineProperty(_assertThisInitialized(_this), "initializeOptions", {});
41
+ _defineProperty(_assertThisInitialized(_this), "store", {
42
+ entryContext: null,
43
+ status: 'idle',
44
+ config: null,
45
+ resource: null,
46
+ flow: {},
47
+ error: null,
48
+ products: undefined,
49
+ itemRuleQuantityLimits: [],
50
+ cartValidation: {
51
+ passed: null,
52
+ failures: []
53
+ }
54
+ });
55
+ _defineProperty(_assertThisInitialized(_this), "otherParams", {});
56
+ _defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
57
+ _defineProperty(_assertThisInitialized(_this), "window", void 0);
58
+ _defineProperty(_assertThisInitialized(_this), "request", void 0);
59
+ _defineProperty(_assertThisInitialized(_this), "itemRuleEvaluator", new ItemRuleEvaluator());
60
+ _defineProperty(_assertThisInitialized(_this), "itemRuleConfigs", []);
61
+ _defineProperty(_assertThisInitialized(_this), "itemRuleConfigsPromise", null);
62
+ _defineProperty(_assertThisInitialized(_this), "itemRulePrefillApplied", false);
63
+ _defineProperty(_assertThisInitialized(_this), "itemRuleRuntimeConfig", {});
64
+ return _this;
65
+ }
66
+ _createClass(ScanOrderImpl, [{
67
+ key: "getScanOrderLoggerContext",
68
+ value: function getScanOrderLoggerContext() {
69
+ return {
70
+ cacheId: this.cacheId,
71
+ solutionName: this.name,
72
+ moduleName: 'scanOrder'
73
+ };
74
+ }
75
+ }, {
76
+ key: "serializeError",
77
+ value: function serializeError(error) {
78
+ if (error instanceof Error) {
79
+ return {
80
+ name: error.name,
81
+ message: error.message,
82
+ stack: error.stack
83
+ };
84
+ }
85
+ return {
86
+ message: String(error)
87
+ };
88
+ }
89
+ }, {
90
+ key: "addScanOrderLog",
91
+ value: function () {
92
+ var _addScanOrderLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
93
+ var payload, extra, logger;
94
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
95
+ while (1) switch (_context.prev = _context.next) {
96
+ case 0:
97
+ payload = _objectSpread({
98
+ cacheId: this.cacheId
99
+ }, params.payload || {});
100
+ extra = _objectSpread({}, params.extra || {});
101
+ logger = this.store.scanOrderLogger;
102
+ if (logger) {
103
+ _context.next = 6;
104
+ break;
105
+ }
106
+ if ((params.level || 'info') === 'error') {
107
+ console.error('[ScanOrder][log-fallback]', params.title, {
108
+ payload: payload,
109
+ extra: extra
110
+ });
111
+ } else {
112
+ console.log('[ScanOrder][log-fallback]', params.title, {
113
+ payload: payload,
114
+ extra: extra
115
+ });
116
+ }
117
+ return _context.abrupt("return");
118
+ case 6:
119
+ _context.next = 8;
120
+ return logger.addLog(_objectSpread(_objectSpread({}, params), {}, {
121
+ payload: payload,
122
+ extra: extra
123
+ }));
124
+ case 8:
125
+ case "end":
126
+ return _context.stop();
127
+ }
128
+ }, _callee, this);
129
+ }));
130
+ function addScanOrderLog(_x) {
131
+ return _addScanOrderLog.apply(this, arguments);
132
+ }
133
+ return addScanOrderLog;
134
+ }()
135
+ }, {
136
+ key: "logMethodStart",
137
+ value: function logMethodStart(method) {
138
+ var payload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
139
+ void this.addScanOrderLog({
140
+ level: 'info',
141
+ title: "[ScanOrder] ".concat(method, " start"),
142
+ payload: _objectSpread({
143
+ method: method
144
+ }, payload)
145
+ });
146
+ }
147
+ }, {
148
+ key: "logMethodSuccess",
149
+ value: function logMethodSuccess(method) {
150
+ var payload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
151
+ void this.addScanOrderLog({
152
+ level: 'info',
153
+ title: "[ScanOrder] ".concat(method, " success"),
154
+ payload: _objectSpread({
155
+ method: method
156
+ }, payload)
157
+ });
158
+ }
159
+ }, {
160
+ key: "logMethodError",
161
+ value: function logMethodError(method, error) {
162
+ var payload = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
163
+ void this.addScanOrderLog({
164
+ level: 'error',
165
+ title: "[ScanOrder] ".concat(method, " failed"),
166
+ payload: _objectSpread(_objectSpread({
167
+ method: method
168
+ }, payload), {}, {
169
+ error: this.serializeError(error)
170
+ })
171
+ });
172
+ }
173
+ }, {
174
+ key: "addLog",
175
+ value: function () {
176
+ var _addLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
177
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
178
+ while (1) switch (_context2.prev = _context2.next) {
179
+ case 0:
180
+ _context2.next = 2;
181
+ return this.addScanOrderLog(_objectSpread(_objectSpread({}, params), {}, {
182
+ payload: _objectSpread({
183
+ source: 'ui-bridge'
184
+ }, params.payload || {})
185
+ }));
186
+ case 2:
187
+ case "end":
188
+ return _context2.stop();
189
+ }
190
+ }, _callee2, this);
191
+ }));
192
+ function addLog(_x2) {
193
+ return _addLog.apply(this, arguments);
194
+ }
195
+ return addLog;
196
+ }()
197
+ }, {
198
+ key: "initialize",
199
+ value: function () {
200
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(core) {
201
+ var _options$otherParams,
202
+ _this$otherParams,
203
+ _this$otherParams2,
204
+ _this$otherParams3,
205
+ _this2 = this;
206
+ var options,
207
+ moduleArr,
208
+ _this$store$order,
209
+ _this$store$order2,
210
+ _args3 = arguments;
211
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
212
+ while (1) switch (_context3.prev = _context3.next) {
213
+ case 0:
214
+ options = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {};
215
+ this.logMethodStart('initialize');
216
+ this.core = core;
217
+ this.initializeOptions = options || {};
218
+ this.store = _objectSpread(_objectSpread({}, this.store), options.store);
219
+ this.store.entryContext = ((_options$otherParams = options.otherParams) === null || _options$otherParams === void 0 ? void 0 : _options$otherParams.entryContext) || this.store.entryContext;
220
+ this.store.status = 'initializing';
221
+ this.store.error = null;
222
+ this.otherParams = options.otherParams || {};
223
+ this.cacheId = (_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.cacheId;
224
+ this.itemRuleRuntimeConfig = ((_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 ? void 0 : _this$otherParams2.scanOrderItemRule) || ((_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3.itemRule) || {};
225
+ this.itemRuleConfigs = [];
226
+ this.itemRuleConfigsPromise = null;
227
+ this.itemRulePrefillApplied = false;
228
+ this.store.itemRuleQuantityLimits = [];
229
+ this.store.cartValidation = {
230
+ passed: null,
231
+ failures: []
232
+ };
233
+ this.window = core.getPlugin('window');
234
+ this.request = core.getPlugin('request');
235
+ if (this.window) {
236
+ _context3.next = 21;
237
+ break;
238
+ }
239
+ this.logMethodError('initialize', 'window plugin missing');
240
+ throw new Error('scanOrder解决方案需要 window 插件支持');
241
+ case 21:
242
+ if (this.request) {
243
+ _context3.next = 24;
244
+ break;
245
+ }
246
+ this.logMethodError('initialize', 'request plugin missing');
247
+ throw new Error('scanOrder解决方案需要 request 插件支持');
248
+ case 24:
249
+ moduleArr = ['scanOrderLogger', 'products', 'order', 'salesSummary'];
250
+ moduleArr.forEach(function (step) {
251
+ var targetModule = createModule(step, _this2.name);
252
+ if (targetModule) {
253
+ var _this2$store$order, _this2$otherParams, _this2$otherParams2, _this2$otherParams3, _this2$otherParams4;
254
+ _this2.store[step] = targetModule;
255
+ var initialState = step === 'salesSummary' ? {
256
+ summary: ((_this2$store$order = _this2.store.order) === null || _this2$store$order === void 0 || (_this2$store$order = _this2$store$order.getTempOrder()) === null || _this2$store$order === void 0 ? void 0 : _this2$store$order.summary) || createEmptySummary()
257
+ } : {};
258
+ var loggerProvider = ((_this2$otherParams = _this2.otherParams) === null || _this2$otherParams === void 0 ? void 0 : _this2$otherParams.scanOrderLoggerProvider) || 'feishu';
259
+ var loggerConfig = ((_this2$otherParams2 = _this2.otherParams) === null || _this2$otherParams2 === void 0 ? void 0 : _this2$otherParams2.scanOrderLoggerConfig) || {
260
+ feishu: {
261
+ // webhook: 'https://open.feishu.cn/open-apis/bot/v2/hook/216b3fe6-af98-424e-8706-f0471241a7ed',
262
+ }
263
+ };
264
+ _this2.core.registerModule(targetModule, {
265
+ initialState: initialState,
266
+ otherParams: _objectSpread(_objectSpread({}, _this2.otherParams), {}, {
267
+ fatherModule: _this2.name,
268
+ openCache: (_this2$otherParams3 = _this2.otherParams) !== null && _this2$otherParams3 !== void 0 && _this2$otherParams3.cacheId ? true : false,
269
+ cacheId: (_this2$otherParams4 = _this2.otherParams) === null || _this2$otherParams4 === void 0 ? void 0 : _this2$otherParams4.cacheId,
270
+ salesSummaryModuleName: "".concat(_this2.name, "_salesSummary"),
271
+ provider: loggerProvider,
272
+ providerConfig: loggerConfig,
273
+ context: _this2.getScanOrderLoggerContext()
274
+ })
275
+ });
276
+ } else {
277
+ _this2.logMethodError('initialize', "module ".concat(step, " missing"));
278
+ throw new Error("\u6A21\u5757 ".concat(step, " \u4E0D\u5B58\u5728"));
279
+ }
280
+ });
281
+ if (this.store.scanOrderLogger) {
282
+ this.store.scanOrderLogger.setContext(this.getScanOrderLoggerContext());
283
+ }
284
+ console.log('[ScanOrder] 初始化开始');
285
+ _context3.prev = 28;
286
+ _context3.next = 31;
287
+ return (_this$store$order = this.store.order) === null || _this$store$order === void 0 ? void 0 : _this$store$order.recalculateSummary({
288
+ createIfMissing: false
289
+ });
290
+ case 31:
291
+ (_this$store$order2 = this.store.order) === null || _this$store$order2 === void 0 || _this$store$order2.persistTempOrder();
292
+ _context3.next = 34;
293
+ return this.loadRuntimeConfigs();
294
+ case 34:
295
+ _context3.next = 36;
296
+ return this.refreshItemRuleQuantityLimits();
297
+ case 36:
298
+ this.store.status = 'ready';
299
+ console.log('[ScanOrder] 初始化完成');
300
+ _context3.next = 40;
301
+ return this.core.effects.emit(ScanOrderHooks.onInited, {
302
+ status: this.store.status
303
+ });
304
+ case 40:
305
+ this.logMethodSuccess('initialize', {
306
+ status: this.store.status
307
+ });
308
+ _context3.next = 50;
309
+ break;
310
+ case 43:
311
+ _context3.prev = 43;
312
+ _context3.t0 = _context3["catch"](28);
313
+ this.store.status = 'error';
314
+ this.store.error = _context3.t0 instanceof Error ? _context3.t0.message : '初始化失败';
315
+ console.error('[ScanOrder] 初始化失败', _context3.t0);
316
+ this.logMethodError('initialize', _context3.t0, {
317
+ status: this.store.status
318
+ });
319
+ throw _context3.t0;
320
+ case 50:
321
+ case "end":
322
+ return _context3.stop();
323
+ }
324
+ }, _callee3, this, [[28, 43]]);
325
+ }));
326
+ function initialize(_x3) {
327
+ return _initialize.apply(this, arguments);
328
+ }
329
+ return initialize;
330
+ }()
331
+ }, {
332
+ key: "destroy",
333
+ value: function () {
334
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
335
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
336
+ while (1) switch (_context4.prev = _context4.next) {
337
+ case 0:
338
+ this.logMethodStart('destroy');
339
+ _context4.next = 3;
340
+ return this.core.effects.emit(ScanOrderHooks.onDestroy, {});
341
+ case 3:
342
+ console.log('[ScanOrder] 已销毁');
343
+ this.logMethodSuccess('destroy');
344
+ case 5:
345
+ case "end":
346
+ return _context4.stop();
347
+ }
348
+ }, _callee4, this);
349
+ }));
350
+ function destroy() {
351
+ return _destroy.apply(this, arguments);
352
+ }
353
+ return destroy;
354
+ }()
355
+ }, {
356
+ key: "retryInit",
357
+ value: function () {
358
+ var _retryInit = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
359
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
360
+ while (1) switch (_context5.prev = _context5.next) {
361
+ case 0:
362
+ this.logMethodStart('retryInit');
363
+ // TODO: 细化重试策略(指数退避、最大重试次数)后替换当前实现
364
+ console.log('[ScanOrder] retryInit 调用');
365
+ _context5.next = 4;
366
+ return this.core.effects.emit(ScanOrderHooks.onRetryInit, {});
367
+ case 4:
368
+ _context5.prev = 4;
369
+ _context5.next = 7;
370
+ return this.initialize(this.core, this.initializeOptions);
371
+ case 7:
372
+ this.logMethodSuccess('retryInit');
373
+ _context5.next = 14;
374
+ break;
375
+ case 10:
376
+ _context5.prev = 10;
377
+ _context5.t0 = _context5["catch"](4);
378
+ this.logMethodError('retryInit', _context5.t0);
379
+ throw _context5.t0;
380
+ case 14:
381
+ case "end":
382
+ return _context5.stop();
383
+ }
384
+ }, _callee5, this, [[4, 10]]);
385
+ }));
386
+ function retryInit() {
387
+ return _retryInit.apply(this, arguments);
388
+ }
389
+ return retryInit;
390
+ }()
391
+ }, {
392
+ key: "refresh",
393
+ value: function () {
394
+ var _refresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
395
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
396
+ while (1) switch (_context6.prev = _context6.next) {
397
+ case 0:
398
+ this.logMethodStart('refresh');
399
+ // TODO: 接入真实刷新逻辑(资源重拉取、流程重建)后替换当前实现
400
+ console.log('[ScanOrder] refresh 调用');
401
+ _context6.prev = 2;
402
+ this.store.status = 'initializing';
403
+ _context6.next = 6;
404
+ return this.loadRuntimeConfigs();
405
+ case 6:
406
+ _context6.next = 8;
407
+ return this.refreshItemRuleQuantityLimits();
408
+ case 8:
409
+ this.store.status = 'ready';
410
+ _context6.next = 11;
411
+ return this.core.effects.emit(ScanOrderHooks.onRefresh, {
412
+ status: this.store.status
413
+ });
414
+ case 11:
415
+ this.logMethodSuccess('refresh', {
416
+ status: this.store.status
417
+ });
418
+ _context6.next = 18;
419
+ break;
420
+ case 14:
421
+ _context6.prev = 14;
422
+ _context6.t0 = _context6["catch"](2);
423
+ this.logMethodError('refresh', _context6.t0);
424
+ throw _context6.t0;
425
+ case 18:
426
+ case "end":
427
+ return _context6.stop();
428
+ }
429
+ }, _callee6, this, [[2, 14]]);
430
+ }));
431
+ function refresh() {
432
+ return _refresh.apply(this, arguments);
433
+ }
434
+ return refresh;
435
+ }()
436
+ }, {
437
+ key: "getStatus",
438
+ value: function getStatus() {
439
+ this.logMethodStart('getStatus');
440
+ var result = this.store.status;
441
+ this.logMethodSuccess('getStatus', {
442
+ status: result
443
+ });
444
+ return result;
445
+ }
446
+ }, {
447
+ key: "getEntryContext",
448
+ value: function getEntryContext() {
449
+ this.logMethodStart('getEntryContext');
450
+ var result = this.store.entryContext;
451
+ this.logMethodSuccess('getEntryContext', {
452
+ hasEntryContext: Boolean(result)
453
+ });
454
+ return result;
455
+ }
456
+ }, {
457
+ key: "getConfig",
458
+ value: function getConfig() {
459
+ this.logMethodStart('getConfig');
460
+ var result = this.store.config || {};
461
+ this.logMethodSuccess('getConfig', {
462
+ configKeys: Object.keys(result || {})
463
+ });
464
+ return result;
465
+ }
466
+ }, {
467
+ key: "getItemRuleQuantityLimits",
468
+ value: function getItemRuleQuantityLimits() {
469
+ this.logMethodStart('getItemRuleQuantityLimits');
470
+ var result = this.store.itemRuleQuantityLimits || [];
471
+ this.logMethodSuccess('getItemRuleQuantityLimits', {
472
+ limitCount: result.length
473
+ });
474
+ return result;
475
+ }
476
+ }, {
477
+ key: "getCartValidationPassed",
478
+ value: function getCartValidationPassed() {
479
+ var _this$store$cartValid, _this$store$cartValid2;
480
+ this.logMethodStart('getCartValidationPassed');
481
+ var result = (_this$store$cartValid = (_this$store$cartValid2 = this.store.cartValidation) === null || _this$store$cartValid2 === void 0 ? void 0 : _this$store$cartValid2.passed) !== null && _this$store$cartValid !== void 0 ? _this$store$cartValid : null;
482
+ this.logMethodSuccess('getCartValidationPassed', {
483
+ cartValidationPassed: result
484
+ });
485
+ return result;
486
+ }
487
+ }, {
488
+ key: "getCartValidation",
489
+ value: function getCartValidation() {
490
+ this.logMethodStart('getCartValidation');
491
+ var result = this.store.cartValidation || {
492
+ passed: null,
493
+ failures: []
494
+ };
495
+ this.logMethodSuccess('getCartValidation', {
496
+ cartValidationPassed: result.passed,
497
+ failureCount: Array.isArray(result.failures) ? result.failures.length : 0
498
+ });
499
+ return result;
500
+ }
501
+ }, {
502
+ key: "getTempOrder",
503
+ value: function getTempOrder() {
504
+ var _this$store$order3, _result$products, _result$note;
505
+ this.logMethodStart('getTempOrder');
506
+ var result = ((_this$store$order3 = this.store.order) === null || _this$store$order3 === void 0 ? void 0 : _this$store$order3.getTempOrder()) || null;
507
+ this.logMethodSuccess('getTempOrder', {
508
+ hasTempOrder: Boolean(result),
509
+ productCount: (result === null || result === void 0 || (_result$products = result.products) === null || _result$products === void 0 ? void 0 : _result$products.length) || 0,
510
+ noteLength: (result === null || result === void 0 || (_result$note = result.note) === null || _result$note === void 0 ? void 0 : _result$note.length) || 0
511
+ });
512
+ return result;
513
+ }
514
+ }, {
515
+ key: "updateTempOrderNote",
516
+ value: function updateTempOrderNote(note) {
517
+ this.logMethodStart('updateTempOrderNote', {
518
+ noteLength: String(note || '').length
519
+ });
520
+ try {
521
+ if (!this.store.order) throw new Error('order 模块未初始化');
522
+ var result = this.store.order.updateTempOrderNote(note);
523
+ this.logMethodSuccess('updateTempOrderNote', {
524
+ noteLength: result.length
525
+ });
526
+ return result;
527
+ } catch (error) {
528
+ this.logMethodError('updateTempOrderNote', error);
529
+ throw error;
530
+ }
531
+ }
532
+ }, {
533
+ key: "ensureTempOrder",
534
+ value: function ensureTempOrder() {
535
+ if (!this.store.order) throw new Error('order 模块未初始化');
536
+ return this.store.order.ensureTempOrder();
537
+ }
538
+
539
+ // 主动创建临时订单;若已存在则直接返回已有订单
540
+ }, {
541
+ key: "addNewOrder",
542
+ value: function () {
543
+ var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
544
+ var tempOrder;
545
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
546
+ while (1) switch (_context7.prev = _context7.next) {
547
+ case 0:
548
+ this.logMethodStart('addNewOrder');
549
+ _context7.prev = 1;
550
+ if (this.store.order) {
551
+ _context7.next = 4;
552
+ break;
553
+ }
554
+ throw new Error('order 模块未初始化');
555
+ case 4:
556
+ _context7.next = 6;
557
+ return this.store.order.addNewOrder();
558
+ case 6:
559
+ tempOrder = _context7.sent;
560
+ this.logMethodSuccess('addNewOrder', {
561
+ productCount: tempOrder.products.length
562
+ });
563
+ return _context7.abrupt("return", tempOrder);
564
+ case 11:
565
+ _context7.prev = 11;
566
+ _context7.t0 = _context7["catch"](1);
567
+ this.logMethodError('addNewOrder', _context7.t0);
568
+ throw _context7.t0;
569
+ case 15:
570
+ case "end":
571
+ return _context7.stop();
572
+ }
573
+ }, _callee7, this, [[1, 11]]);
574
+ }));
575
+ function addNewOrder() {
576
+ return _addNewOrder.apply(this, arguments);
577
+ }
578
+ return addNewOrder;
579
+ }()
580
+ }, {
581
+ key: "getOrderProducts",
582
+ value: function getOrderProducts() {
583
+ this.logMethodStart('getOrderProducts');
584
+ if (!this.store.order) throw new Error('order 模块未初始化');
585
+ var products = this.store.order.getOrderProducts();
586
+ this.logMethodSuccess('getOrderProducts', {
587
+ productCount: products.length
588
+ });
589
+ return products;
590
+ }
591
+ }, {
592
+ key: "getSummary",
593
+ value: function () {
594
+ var _getSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
595
+ var summary;
596
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
597
+ while (1) switch (_context8.prev = _context8.next) {
598
+ case 0:
599
+ this.logMethodStart('getSummary');
600
+ _context8.prev = 1;
601
+ if (this.store.order) {
602
+ _context8.next = 4;
603
+ break;
604
+ }
605
+ throw new Error('order 模块未初始化');
606
+ case 4:
607
+ _context8.next = 6;
608
+ return this.store.order.getScanOrderSummary();
609
+ case 6:
610
+ summary = _context8.sent;
611
+ this.logMethodSuccess('getSummary', {
612
+ totalAmount: summary.total_amount
613
+ });
614
+ return _context8.abrupt("return", summary);
615
+ case 11:
616
+ _context8.prev = 11;
617
+ _context8.t0 = _context8["catch"](1);
618
+ this.logMethodError('getSummary', _context8.t0);
619
+ throw _context8.t0;
620
+ case 15:
621
+ case "end":
622
+ return _context8.stop();
623
+ }
624
+ }, _callee8, this, [[1, 11]]);
625
+ }));
626
+ function getSummary() {
627
+ return _getSummary.apply(this, arguments);
628
+ }
629
+ return getSummary;
630
+ }()
631
+ }, {
632
+ key: "submitScanOrder",
633
+ value: function () {
634
+ var _submitScanOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
635
+ var _tempOrder$products, result, tempOrder;
636
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
637
+ while (1) switch (_context9.prev = _context9.next) {
638
+ case 0:
639
+ this.logMethodStart('submitScanOrder');
640
+ _context9.prev = 1;
641
+ _context9.next = 4;
642
+ return this.validateBeforeSubmitByItemRule();
643
+ case 4:
644
+ if (this.store.order) {
645
+ _context9.next = 6;
646
+ break;
647
+ }
648
+ throw new Error('scanOrder解决方案需要 order 模块支持');
649
+ case 6:
650
+ _context9.next = 8;
651
+ return this.store.order.submitTempOrder({
652
+ cacheId: this.cacheId
653
+ });
654
+ case 8:
655
+ result = _context9.sent;
656
+ tempOrder = this.store.order.getTempOrder();
657
+ this.logMethodSuccess('submitScanOrder', {
658
+ productCount: (tempOrder === null || tempOrder === void 0 || (_tempOrder$products = tempOrder.products) === null || _tempOrder$products === void 0 ? void 0 : _tempOrder$products.length) || 0
659
+ });
660
+ return _context9.abrupt("return", result);
661
+ case 14:
662
+ _context9.prev = 14;
663
+ _context9.t0 = _context9["catch"](1);
664
+ this.logMethodError('submitScanOrder', _context9.t0);
665
+ throw _context9.t0;
666
+ case 18:
667
+ case "end":
668
+ return _context9.stop();
669
+ }
670
+ }, _callee9, this, [[1, 14]]);
671
+ }));
672
+ function submitScanOrder() {
673
+ return _submitScanOrder.apply(this, arguments);
674
+ }
675
+ return submitScanOrder;
676
+ }()
677
+ }, {
678
+ key: "addProductToOrder",
679
+ value: function () {
680
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(product) {
681
+ var products;
682
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
683
+ while (1) switch (_context10.prev = _context10.next) {
684
+ case 0:
685
+ this.logMethodStart('addProductToOrder', {
686
+ product_id: product.product_id,
687
+ product_variant_id: product.product_variant_id
688
+ });
689
+ _context10.prev = 1;
690
+ if (this.store.order) {
691
+ _context10.next = 4;
692
+ break;
693
+ }
694
+ throw new Error('order 模块未初始化');
695
+ case 4:
696
+ _context10.next = 6;
697
+ return this.store.order.addProductToOrder(product);
698
+ case 6:
699
+ products = _context10.sent;
700
+ _context10.next = 9;
701
+ return this.refreshItemRuleQuantityLimits();
702
+ case 9:
703
+ _context10.next = 11;
704
+ return this.refreshCartValidationPassed();
705
+ case 11:
706
+ this.logMethodSuccess('addProductToOrder', {
707
+ productCount: products.length
708
+ });
709
+ return _context10.abrupt("return", products);
710
+ case 15:
711
+ _context10.prev = 15;
712
+ _context10.t0 = _context10["catch"](1);
713
+ this.logMethodError('addProductToOrder', _context10.t0);
714
+ throw _context10.t0;
715
+ case 19:
716
+ case "end":
717
+ return _context10.stop();
718
+ }
719
+ }, _callee10, this, [[1, 15]]);
720
+ }));
721
+ function addProductToOrder(_x4) {
722
+ return _addProductToOrder.apply(this, arguments);
723
+ }
724
+ return addProductToOrder;
725
+ }()
726
+ }, {
727
+ key: "updateProductInOrder",
728
+ value: function () {
729
+ var _updateProductInOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(params) {
730
+ var products;
731
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
732
+ while (1) switch (_context11.prev = _context11.next) {
733
+ case 0:
734
+ this.logMethodStart('updateProductInOrder', {
735
+ product_id: params.product_id,
736
+ product_variant_id: params.product_variant_id
737
+ });
738
+ _context11.prev = 1;
739
+ if (this.store.order) {
740
+ _context11.next = 4;
741
+ break;
742
+ }
743
+ throw new Error('order 模块未初始化');
744
+ case 4:
745
+ _context11.next = 6;
746
+ return this.store.order.updateProductInOrder(params);
747
+ case 6:
748
+ products = _context11.sent;
749
+ _context11.next = 9;
750
+ return this.refreshItemRuleQuantityLimits();
751
+ case 9:
752
+ _context11.next = 11;
753
+ return this.refreshCartValidationPassed();
754
+ case 11:
755
+ this.logMethodSuccess('updateProductInOrder', {
756
+ productCount: products.length
757
+ });
758
+ return _context11.abrupt("return", products);
759
+ case 15:
760
+ _context11.prev = 15;
761
+ _context11.t0 = _context11["catch"](1);
762
+ this.logMethodError('updateProductInOrder', _context11.t0);
763
+ throw _context11.t0;
764
+ case 19:
765
+ case "end":
766
+ return _context11.stop();
767
+ }
768
+ }, _callee11, this, [[1, 15]]);
769
+ }));
770
+ function updateProductInOrder(_x5) {
771
+ return _updateProductInOrder.apply(this, arguments);
772
+ }
773
+ return updateProductInOrder;
774
+ }()
775
+ }, {
776
+ key: "removeProductFromOrder",
777
+ value: function () {
778
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(identity) {
779
+ var products;
780
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
781
+ while (1) switch (_context12.prev = _context12.next) {
782
+ case 0:
783
+ this.logMethodStart('removeProductFromOrder', {
784
+ product_id: identity.product_id,
785
+ product_variant_id: identity.product_variant_id
786
+ });
787
+ _context12.prev = 1;
788
+ if (this.store.order) {
789
+ _context12.next = 4;
790
+ break;
791
+ }
792
+ throw new Error('order 模块未初始化');
793
+ case 4:
794
+ _context12.next = 6;
795
+ return this.store.order.removeProductFromOrder(identity);
796
+ case 6:
797
+ products = _context12.sent;
798
+ _context12.next = 9;
799
+ return this.refreshItemRuleQuantityLimits();
800
+ case 9:
801
+ _context12.next = 11;
802
+ return this.refreshCartValidationPassed();
803
+ case 11:
804
+ this.logMethodSuccess('removeProductFromOrder', {
805
+ productCount: products.length
806
+ });
807
+ return _context12.abrupt("return", products);
808
+ case 15:
809
+ _context12.prev = 15;
810
+ _context12.t0 = _context12["catch"](1);
811
+ this.logMethodError('removeProductFromOrder', _context12.t0);
812
+ throw _context12.t0;
813
+ case 19:
814
+ case "end":
815
+ return _context12.stop();
816
+ }
817
+ }, _callee12, this, [[1, 15]]);
818
+ }));
819
+ function removeProductFromOrder(_x6) {
820
+ return _removeProductFromOrder.apply(this, arguments);
821
+ }
822
+ return removeProductFromOrder;
823
+ }()
824
+ }, {
825
+ key: "loadRuntimeConfigs",
826
+ value: function () {
827
+ var _loadRuntimeConfigs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
828
+ var itemRuleConfigs;
829
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
830
+ while (1) switch (_context13.prev = _context13.next) {
831
+ case 0:
832
+ _context13.next = 2;
833
+ return this.ensureItemRuleConfigsLoaded();
834
+ case 2:
835
+ itemRuleConfigs = _context13.sent;
836
+ this.logMethodSuccess('loadRuntimeConfigs', {
837
+ itemRuleCount: itemRuleConfigs.length
838
+ });
839
+ return _context13.abrupt("return", {
840
+ itemRuleConfigs: itemRuleConfigs
841
+ });
842
+ case 5:
843
+ case "end":
844
+ return _context13.stop();
845
+ }
846
+ }, _callee13, this);
847
+ }));
848
+ function loadRuntimeConfigs() {
849
+ return _loadRuntimeConfigs.apply(this, arguments);
850
+ }
851
+ return loadRuntimeConfigs;
852
+ }()
853
+ }, {
854
+ key: "syncItemRuleConfigsFromDineInConfig",
855
+ value: function () {
856
+ var _syncItemRuleConfigsFromDineInConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(dineInConfig) {
857
+ var enableItemRules, strategyModelIds, itemRuleConfigs;
858
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
859
+ while (1) switch (_context14.prev = _context14.next) {
860
+ case 0:
861
+ enableItemRules = toBoolean(dineInConfig === null || dineInConfig === void 0 ? void 0 : dineInConfig['sale.enable_item_rules']);
862
+ strategyModelIds = normalizeEnabledItemRuleIds(dineInConfig === null || dineInConfig === void 0 ? void 0 : dineInConfig['sale.enabled_item_rules']);
863
+ if (!(!enableItemRules || !strategyModelIds.length)) {
864
+ _context14.next = 8;
865
+ break;
866
+ }
867
+ this.itemRuleConfigs = [];
868
+ this.itemRuleConfigsPromise = Promise.resolve([]);
869
+ this.itemRuleEvaluator.setStrategyConfigs([]);
870
+ this.logMethodSuccess('syncItemRuleConfigsFromDineInConfig', {
871
+ enabled: enableItemRules,
872
+ strategyModelIds: [],
873
+ itemRuleCount: 0
874
+ });
875
+ return _context14.abrupt("return", []);
876
+ case 8:
877
+ _context14.next = 10;
878
+ return this.fetchItemRuleConfigsByModelIds(strategyModelIds);
879
+ case 10:
880
+ itemRuleConfigs = _context14.sent;
881
+ this.itemRuleConfigs = itemRuleConfigs;
882
+ this.itemRuleConfigsPromise = Promise.resolve(itemRuleConfigs);
883
+ this.itemRuleEvaluator.setStrategyConfigs(itemRuleConfigs);
884
+ this.logMethodSuccess('syncItemRuleConfigsFromDineInConfig', {
885
+ enabled: enableItemRules,
886
+ strategyModelIds: strategyModelIds,
887
+ itemRuleCount: itemRuleConfigs.length
888
+ });
889
+ return _context14.abrupt("return", itemRuleConfigs);
890
+ case 16:
891
+ case "end":
892
+ return _context14.stop();
893
+ }
894
+ }, _callee14, this);
895
+ }));
896
+ function syncItemRuleConfigsFromDineInConfig(_x7) {
897
+ return _syncItemRuleConfigsFromDineInConfig.apply(this, arguments);
898
+ }
899
+ return syncItemRuleConfigsFromDineInConfig;
900
+ }()
901
+ }, {
902
+ key: "fetchItemRuleConfigsByModelIds",
903
+ value: function () {
904
+ var _fetchItemRuleConfigsByModelIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(strategyModelIds) {
905
+ var result, configs;
906
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
907
+ while (1) switch (_context15.prev = _context15.next) {
908
+ case 0:
909
+ this.logMethodStart('fetchItemRuleConfigsByModelIds', {
910
+ strategyModelIds: strategyModelIds
911
+ });
912
+ if (strategyModelIds.length) {
913
+ _context15.next = 3;
914
+ break;
915
+ }
916
+ return _context15.abrupt("return", []);
917
+ case 3:
918
+ _context15.prev = 3;
919
+ _context15.next = 6;
920
+ return this.request.get('/promotion', {
921
+ skip: 1,
922
+ num: 99,
923
+ status: 'active',
924
+ ids: strategyModelIds
925
+ });
926
+ case 6:
927
+ result = _context15.sent;
928
+ configs = [];
929
+ if (result.code === 200) {
930
+ configs = result.data.list.map(function (item) {
931
+ return item.metadata;
932
+ });
933
+ }
934
+ this.logMethodSuccess('fetchItemRuleConfigsByModelIds', {
935
+ strategyModelIds: strategyModelIds,
936
+ strategyCount: configs.length
937
+ });
938
+ return _context15.abrupt("return", configs);
939
+ case 13:
940
+ _context15.prev = 13;
941
+ _context15.t0 = _context15["catch"](3);
942
+ this.logMethodError('fetchItemRuleConfigsByModelIds', _context15.t0, {
943
+ strategyModelIds: strategyModelIds
944
+ });
945
+ // A:策略加载失败时不阻塞下单
946
+ return _context15.abrupt("return", []);
947
+ case 17:
948
+ case "end":
949
+ return _context15.stop();
950
+ }
951
+ }, _callee15, this, [[3, 13]]);
952
+ }));
953
+ function fetchItemRuleConfigsByModelIds(_x8) {
954
+ return _fetchItemRuleConfigsByModelIds.apply(this, arguments);
955
+ }
956
+ return fetchItemRuleConfigsByModelIds;
957
+ }()
958
+ }, {
959
+ key: "buildPrefillProductSourceMap",
960
+ value: function () {
961
+ var _buildPrefillProductSourceMap = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
962
+ var sourceMap, productList, visited, collectFromValue;
963
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
964
+ while (1) switch (_context16.prev = _context16.next) {
965
+ case 0:
966
+ sourceMap = new Map();
967
+ _context16.prev = 1;
968
+ _context16.next = 4;
969
+ return this.getProductList();
970
+ case 4:
971
+ productList = _context16.sent;
972
+ if (Array.isArray(productList)) {
973
+ _context16.next = 7;
974
+ break;
975
+ }
976
+ return _context16.abrupt("return", sourceMap);
977
+ case 7:
978
+ visited = new Set();
979
+ collectFromValue = function collectFromValue(value) {
980
+ var _node$product_id;
981
+ if (!value || _typeof(value) !== 'object') return;
982
+ if (visited.has(value)) return;
983
+ visited.add(value);
984
+ if (Array.isArray(value)) {
985
+ var _iterator = _createForOfIteratorHelper(value),
986
+ _step;
987
+ try {
988
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
989
+ var item = _step.value;
990
+ collectFromValue(item);
991
+ }
992
+ } catch (err) {
993
+ _iterator.e(err);
994
+ } finally {
995
+ _iterator.f();
996
+ }
997
+ return;
998
+ }
999
+ var node = value;
1000
+ var rawProductId = (_node$product_id = node.product_id) !== null && _node$product_id !== void 0 ? _node$product_id : node.id;
1001
+ var productId = Number(rawProductId);
1002
+ if (Number.isFinite(productId) && productId > 0) {
1003
+ var _ref, _node$product_variant;
1004
+ var productVariantId = Number((_ref = (_node$product_variant = node.product_variant_id) !== null && _node$product_variant !== void 0 ? _node$product_variant : node.variant_id) !== null && _ref !== void 0 ? _ref : 0);
1005
+ var normalizedVariantId = Number.isNaN(productVariantId) ? 0 : productVariantId;
1006
+ var key = buildProductKey(productId, normalizedVariantId);
1007
+ if (!sourceMap.has(key)) {
1008
+ sourceMap.set(key, node);
1009
+ }
1010
+ }
1011
+ for (var _i = 0, _Object$values = Object.values(node); _i < _Object$values.length; _i++) {
1012
+ var childValue = _Object$values[_i];
1013
+ if (childValue && _typeof(childValue) === 'object') {
1014
+ collectFromValue(childValue);
1015
+ }
1016
+ }
1017
+ };
1018
+ collectFromValue(productList);
1019
+ _context16.next = 15;
1020
+ break;
1021
+ case 12:
1022
+ _context16.prev = 12;
1023
+ _context16.t0 = _context16["catch"](1);
1024
+ this.logMethodError('buildPrefillProductSourceMap', _context16.t0);
1025
+ case 15:
1026
+ return _context16.abrupt("return", sourceMap);
1027
+ case 16:
1028
+ case "end":
1029
+ return _context16.stop();
1030
+ }
1031
+ }, _callee16, this, [[1, 12]]);
1032
+ }));
1033
+ function buildPrefillProductSourceMap() {
1034
+ return _buildPrefillProductSourceMap.apply(this, arguments);
1035
+ }
1036
+ return buildPrefillProductSourceMap;
1037
+ }()
1038
+ }, {
1039
+ key: "getItemRuleRuntimeConfig",
1040
+ value: function getItemRuleRuntimeConfig() {
1041
+ return this.itemRuleRuntimeConfig || {};
1042
+ }
1043
+ }, {
1044
+ key: "ensureItemRuleConfigsLoaded",
1045
+ value: function () {
1046
+ var _ensureItemRuleConfigsLoaded = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
1047
+ var _this3 = this;
1048
+ var loadedConfigs;
1049
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1050
+ while (1) switch (_context18.prev = _context18.next) {
1051
+ case 0:
1052
+ if (!(this.itemRuleConfigs.length > 0)) {
1053
+ _context18.next = 2;
1054
+ break;
1055
+ }
1056
+ return _context18.abrupt("return", this.itemRuleConfigs);
1057
+ case 2:
1058
+ if (!this.itemRuleConfigsPromise) {
1059
+ _context18.next = 4;
1060
+ break;
1061
+ }
1062
+ return _context18.abrupt("return", this.itemRuleConfigsPromise);
1063
+ case 4:
1064
+ this.itemRuleConfigsPromise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
1065
+ var runtimeConfig, staticConfigs;
1066
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1067
+ while (1) switch (_context17.prev = _context17.next) {
1068
+ case 0:
1069
+ runtimeConfig = _this3.getItemRuleRuntimeConfig();
1070
+ staticConfigs = normalizeItemRuleStrategies(runtimeConfig.strategyConfigs);
1071
+ if (!(staticConfigs.length > 0)) {
1072
+ _context17.next = 6;
1073
+ break;
1074
+ }
1075
+ _this3.itemRuleConfigs = staticConfigs;
1076
+ _this3.itemRuleEvaluator.setStrategyConfigs(staticConfigs);
1077
+ return _context17.abrupt("return", _this3.itemRuleConfigs);
1078
+ case 6:
1079
+ _this3.itemRuleConfigs = [];
1080
+ _this3.itemRuleEvaluator.setStrategyConfigs([]);
1081
+ return _context17.abrupt("return", _this3.itemRuleConfigs);
1082
+ case 9:
1083
+ case "end":
1084
+ return _context17.stop();
1085
+ }
1086
+ }, _callee17);
1087
+ }))();
1088
+ _context18.next = 7;
1089
+ return this.itemRuleConfigsPromise;
1090
+ case 7:
1091
+ loadedConfigs = _context18.sent;
1092
+ return _context18.abrupt("return", loadedConfigs);
1093
+ case 9:
1094
+ case "end":
1095
+ return _context18.stop();
1096
+ }
1097
+ }, _callee18, this);
1098
+ }));
1099
+ function ensureItemRuleConfigsLoaded() {
1100
+ return _ensureItemRuleConfigsLoaded.apply(this, arguments);
1101
+ }
1102
+ return ensureItemRuleConfigsLoaded;
1103
+ }()
1104
+ }, {
1105
+ key: "refreshItemRuleQuantityLimits",
1106
+ value: function () {
1107
+ var _refreshItemRuleQuantityLimits = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
1108
+ var strategyConfigs, businessData, limits;
1109
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1110
+ while (1) switch (_context19.prev = _context19.next) {
1111
+ case 0:
1112
+ _context19.prev = 0;
1113
+ _context19.next = 3;
1114
+ return this.ensureItemRuleConfigsLoaded();
1115
+ case 3:
1116
+ strategyConfigs = _context19.sent;
1117
+ if (strategyConfigs.length) {
1118
+ _context19.next = 7;
1119
+ break;
1120
+ }
1121
+ this.store.itemRuleQuantityLimits = [];
1122
+ return _context19.abrupt("return", []);
1123
+ case 7:
1124
+ businessData = buildItemRuleBusinessData({
1125
+ tempOrder: this.ensureTempOrder(),
1126
+ runtimeConfig: this.getItemRuleRuntimeConfig(),
1127
+ itemRuleConfigs: this.itemRuleConfigs
1128
+ });
1129
+ limits = this.itemRuleEvaluator.getQuantityLimits(businessData);
1130
+ this.store.itemRuleQuantityLimits = limits;
1131
+ this.logMethodSuccess('refreshItemRuleQuantityLimits', {
1132
+ limitCount: limits.length
1133
+ });
1134
+ return _context19.abrupt("return", limits);
1135
+ case 14:
1136
+ _context19.prev = 14;
1137
+ _context19.t0 = _context19["catch"](0);
1138
+ this.store.itemRuleQuantityLimits = [];
1139
+ this.logMethodError('refreshItemRuleQuantityLimits', _context19.t0);
1140
+ return _context19.abrupt("return", []);
1141
+ case 19:
1142
+ case "end":
1143
+ return _context19.stop();
1144
+ }
1145
+ }, _callee19, this, [[0, 14]]);
1146
+ }));
1147
+ function refreshItemRuleQuantityLimits() {
1148
+ return _refreshItemRuleQuantityLimits.apply(this, arguments);
1149
+ }
1150
+ return refreshItemRuleQuantityLimits;
1151
+ }()
1152
+ }, {
1153
+ key: "applyPrefillByItemRule",
1154
+ value: function () {
1155
+ var _applyPrefillByItemRule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
1156
+ var strategyConfigs, businessData, prefillItems, productSourceMap, tempOrder, hasChanges, _iterator2, _step2, _prefillItem$product_, _targetProduct$_origi, _targetProduct$_origi2, _targetProduct$_origi3, prefillItem, productId, productVariantId, targetQuantity, sourceItem, productIndex, _sourceItem$price, _ref3, _sourceItem$original_, _ref4, _sourceItem$payment_p, sellingPrice, originalPrice, paymentPrice, targetProduct, existedQuantity, delta, nextProduct, hasQuantityChanged, hasOriginChanged;
1157
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1158
+ while (1) switch (_context20.prev = _context20.next) {
1159
+ case 0:
1160
+ if (!this.itemRulePrefillApplied) {
1161
+ _context20.next = 2;
1162
+ break;
1163
+ }
1164
+ return _context20.abrupt("return");
1165
+ case 2:
1166
+ if (this.store.order) {
1167
+ _context20.next = 4;
1168
+ break;
1169
+ }
1170
+ return _context20.abrupt("return");
1171
+ case 4:
1172
+ _context20.next = 6;
1173
+ return this.ensureItemRuleConfigsLoaded();
1174
+ case 6:
1175
+ strategyConfigs = _context20.sent;
1176
+ if (strategyConfigs.length) {
1177
+ _context20.next = 9;
1178
+ break;
1179
+ }
1180
+ return _context20.abrupt("return");
1181
+ case 9:
1182
+ businessData = buildItemRuleBusinessData({
1183
+ tempOrder: this.ensureTempOrder(),
1184
+ runtimeConfig: this.getItemRuleRuntimeConfig(),
1185
+ itemRuleConfigs: this.itemRuleConfigs
1186
+ });
1187
+ prefillItems = this.itemRuleEvaluator.getPrefillItems(businessData);
1188
+ if (prefillItems.length) {
1189
+ _context20.next = 14;
1190
+ break;
1191
+ }
1192
+ this.itemRulePrefillApplied = true;
1193
+ return _context20.abrupt("return");
1194
+ case 14:
1195
+ _context20.next = 16;
1196
+ return this.buildPrefillProductSourceMap();
1197
+ case 16:
1198
+ productSourceMap = _context20.sent;
1199
+ tempOrder = this.ensureTempOrder();
1200
+ hasChanges = false;
1201
+ _iterator2 = _createForOfIteratorHelper(prefillItems);
1202
+ _context20.prev = 20;
1203
+ _iterator2.s();
1204
+ case 22:
1205
+ if ((_step2 = _iterator2.n()).done) {
1206
+ _context20.next = 49;
1207
+ break;
1208
+ }
1209
+ prefillItem = _step2.value;
1210
+ productId = Number(prefillItem.product_id);
1211
+ productVariantId = Number((_prefillItem$product_ = prefillItem.product_variant_id) !== null && _prefillItem$product_ !== void 0 ? _prefillItem$product_ : 0);
1212
+ targetQuantity = toNonNegativeInt(prefillItem.quantity);
1213
+ if (!(!Number.isFinite(productId) || targetQuantity <= 0)) {
1214
+ _context20.next = 29;
1215
+ break;
1216
+ }
1217
+ return _context20.abrupt("continue", 47);
1218
+ case 29:
1219
+ if (!Number.isNaN(productVariantId)) {
1220
+ _context20.next = 31;
1221
+ break;
1222
+ }
1223
+ return _context20.abrupt("continue", 47);
1224
+ case 31:
1225
+ sourceItem = productSourceMap.get(buildProductKey(productId, productVariantId)) || productSourceMap.get(buildProductKey(productId, 0)) || null;
1226
+ productIndex = getProductIdentityIndex(tempOrder.products, {
1227
+ product_id: productId,
1228
+ product_variant_id: productVariantId
1229
+ });
1230
+ if (!(productIndex === -1)) {
1231
+ _context20.next = 40;
1232
+ break;
1233
+ }
1234
+ sellingPrice = toPriceString((_sourceItem$price = sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.price) !== null && _sourceItem$price !== void 0 ? _sourceItem$price : sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.selling_price, '0.00');
1235
+ originalPrice = toPriceString((_ref3 = (_sourceItem$original_ = sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.original_price) !== null && _sourceItem$original_ !== void 0 ? _sourceItem$original_ : sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.price) !== null && _ref3 !== void 0 ? _ref3 : sellingPrice, sellingPrice);
1236
+ paymentPrice = toPriceString((_ref4 = (_sourceItem$payment_p = sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.payment_price) !== null && _sourceItem$payment_p !== void 0 ? _sourceItem$payment_p : sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.price) !== null && _ref4 !== void 0 ? _ref4 : sellingPrice, sellingPrice);
1237
+ tempOrder.products.push(normalizeOrderProduct({
1238
+ product_id: productId,
1239
+ product_variant_id: productVariantId,
1240
+ num: targetQuantity,
1241
+ selling_price: sellingPrice,
1242
+ original_price: originalPrice,
1243
+ payment_price: paymentPrice,
1244
+ metadata: {
1245
+ item_rule_prefill: true,
1246
+ item_rule_id: prefillItem.ruleId
1247
+ },
1248
+ _origin: _objectSpread(_objectSpread({}, sourceItem || {}), {}, {
1249
+ item_rule_prefill: true,
1250
+ item_rule_id: prefillItem.ruleId
1251
+ })
1252
+ }));
1253
+ hasChanges = true;
1254
+ return _context20.abrupt("continue", 47);
1255
+ case 40:
1256
+ targetProduct = tempOrder.products[productIndex];
1257
+ existedQuantity = toNonNegativeInt(targetProduct.num);
1258
+ delta = targetQuantity - existedQuantity;
1259
+ nextProduct = _objectSpread(_objectSpread(_objectSpread({}, targetProduct), delta > 0 ? {
1260
+ num: getSafeProductNum(existedQuantity + delta)
1261
+ } : {}), {}, {
1262
+ metadata: _objectSpread(_objectSpread({}, targetProduct.metadata || {}), {}, {
1263
+ item_rule_prefill: true,
1264
+ item_rule_id: prefillItem.ruleId
1265
+ }),
1266
+ _origin: sourceItem ? _objectSpread(_objectSpread({}, targetProduct._origin || {}), sourceItem) : targetProduct._origin
1267
+ });
1268
+ hasQuantityChanged = delta > 0;
1269
+ hasOriginChanged = Boolean(sourceItem && (!targetProduct._origin || ((_targetProduct$_origi = targetProduct._origin) === null || _targetProduct$_origi === void 0 ? void 0 : _targetProduct$_origi.name) !== (sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.name) || ((_targetProduct$_origi2 = targetProduct._origin) === null || _targetProduct$_origi2 === void 0 ? void 0 : _targetProduct$_origi2.title) !== (sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.title) || ((_targetProduct$_origi3 = targetProduct._origin) === null || _targetProduct$_origi3 === void 0 ? void 0 : _targetProduct$_origi3.price) !== (sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.price)));
1270
+ if (hasQuantityChanged || hasOriginChanged) {
1271
+ tempOrder.products[productIndex] = nextProduct;
1272
+ hasChanges = true;
1273
+ }
1274
+ case 47:
1275
+ _context20.next = 22;
1276
+ break;
1277
+ case 49:
1278
+ _context20.next = 54;
1279
+ break;
1280
+ case 51:
1281
+ _context20.prev = 51;
1282
+ _context20.t0 = _context20["catch"](20);
1283
+ _iterator2.e(_context20.t0);
1284
+ case 54:
1285
+ _context20.prev = 54;
1286
+ _iterator2.f();
1287
+ return _context20.finish(54);
1288
+ case 57:
1289
+ if (!hasChanges) {
1290
+ _context20.next = 61;
1291
+ break;
1292
+ }
1293
+ _context20.next = 60;
1294
+ return this.store.order.recalculateSummary({
1295
+ createIfMissing: true
1296
+ });
1297
+ case 60:
1298
+ this.store.order.persistTempOrder();
1299
+ case 61:
1300
+ _context20.next = 63;
1301
+ return this.refreshItemRuleQuantityLimits();
1302
+ case 63:
1303
+ this.itemRulePrefillApplied = true;
1304
+ this.logMethodSuccess('applyPrefillByItemRule', {
1305
+ prefillCount: prefillItems.length,
1306
+ hasChanges: hasChanges
1307
+ });
1308
+ case 65:
1309
+ case "end":
1310
+ return _context20.stop();
1311
+ }
1312
+ }, _callee20, this, [[20, 51, 54, 57]]);
1313
+ }));
1314
+ function applyPrefillByItemRule() {
1315
+ return _applyPrefillByItemRule.apply(this, arguments);
1316
+ }
1317
+ return applyPrefillByItemRule;
1318
+ }()
1319
+ }, {
1320
+ key: "applyItemRulePrefill",
1321
+ value: function () {
1322
+ var _applyItemRulePrefill = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
1323
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1324
+ while (1) switch (_context21.prev = _context21.next) {
1325
+ case 0:
1326
+ this.logMethodStart('applyItemRulePrefill');
1327
+ _context21.next = 3;
1328
+ return this.applyPrefillByItemRule();
1329
+ case 3:
1330
+ _context21.next = 5;
1331
+ return this.refreshItemRuleQuantityLimits();
1332
+ case 5:
1333
+ _context21.next = 7;
1334
+ return this.refreshCartValidationPassed();
1335
+ case 7:
1336
+ case "end":
1337
+ return _context21.stop();
1338
+ }
1339
+ }, _callee21, this);
1340
+ }));
1341
+ function applyItemRulePrefill() {
1342
+ return _applyItemRulePrefill.apply(this, arguments);
1343
+ }
1344
+ return applyItemRulePrefill;
1345
+ }()
1346
+ }, {
1347
+ key: "evaluateCartValidationByItemRule",
1348
+ value: function () {
1349
+ var _evaluateCartValidationByItemRule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
1350
+ var strategyConfigs, businessData;
1351
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1352
+ while (1) switch (_context22.prev = _context22.next) {
1353
+ case 0:
1354
+ _context22.next = 2;
1355
+ return this.ensureItemRuleConfigsLoaded();
1356
+ case 2:
1357
+ strategyConfigs = _context22.sent;
1358
+ if (strategyConfigs.length) {
1359
+ _context22.next = 5;
1360
+ break;
1361
+ }
1362
+ return _context22.abrupt("return", {
1363
+ passed: true,
1364
+ failures: []
1365
+ });
1366
+ case 5:
1367
+ businessData = buildItemRuleBusinessData({
1368
+ tempOrder: this.ensureTempOrder(),
1369
+ runtimeConfig: this.getItemRuleRuntimeConfig(),
1370
+ itemRuleConfigs: this.itemRuleConfigs
1371
+ });
1372
+ return _context22.abrupt("return", this.itemRuleEvaluator.validateCart(businessData));
1373
+ case 7:
1374
+ case "end":
1375
+ return _context22.stop();
1376
+ }
1377
+ }, _callee22, this);
1378
+ }));
1379
+ function evaluateCartValidationByItemRule() {
1380
+ return _evaluateCartValidationByItemRule.apply(this, arguments);
1381
+ }
1382
+ return evaluateCartValidationByItemRule;
1383
+ }()
1384
+ }, {
1385
+ key: "validateBeforeSubmitByItemRule",
1386
+ value: function () {
1387
+ var _validateBeforeSubmitByItemRule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
1388
+ var validationResult, firstFailure, errorMessage, error;
1389
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1390
+ while (1) switch (_context23.prev = _context23.next) {
1391
+ case 0:
1392
+ _context23.next = 2;
1393
+ return this.evaluateCartValidationByItemRule();
1394
+ case 2:
1395
+ validationResult = _context23.sent;
1396
+ if (!validationResult.passed) {
1397
+ _context23.next = 5;
1398
+ break;
1399
+ }
1400
+ return _context23.abrupt("return");
1401
+ case 5:
1402
+ firstFailure = validationResult.failures[0];
1403
+ errorMessage = (firstFailure === null || firstFailure === void 0 ? void 0 : firstFailure.validationMessage) || '当前购物车未满足商品规则,请调整后再提交';
1404
+ error = new Error(String(errorMessage));
1405
+ error.failures = validationResult.failures;
1406
+ throw error;
1407
+ case 10:
1408
+ case "end":
1409
+ return _context23.stop();
1410
+ }
1411
+ }, _callee23, this);
1412
+ }));
1413
+ function validateBeforeSubmitByItemRule() {
1414
+ return _validateBeforeSubmitByItemRule.apply(this, arguments);
1415
+ }
1416
+ return validateBeforeSubmitByItemRule;
1417
+ }()
1418
+ }, {
1419
+ key: "refreshCartValidationPassed",
1420
+ value: function () {
1421
+ var _refreshCartValidationPassed = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
1422
+ var previous, nextState, validationResult, changed;
1423
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
1424
+ while (1) switch (_context24.prev = _context24.next) {
1425
+ case 0:
1426
+ previous = this.store.cartValidation || {
1427
+ passed: null,
1428
+ failures: []
1429
+ };
1430
+ nextState = {
1431
+ passed: null,
1432
+ failures: []
1433
+ };
1434
+ _context24.prev = 2;
1435
+ _context24.next = 5;
1436
+ return this.evaluateCartValidationByItemRule();
1437
+ case 5:
1438
+ validationResult = _context24.sent;
1439
+ nextState = {
1440
+ passed: validationResult.passed,
1441
+ failures: validationResult.failures || []
1442
+ };
1443
+ _context24.next = 12;
1444
+ break;
1445
+ case 9:
1446
+ _context24.prev = 9;
1447
+ _context24.t0 = _context24["catch"](2);
1448
+ nextState = {
1449
+ passed: false,
1450
+ failures: []
1451
+ };
1452
+ case 12:
1453
+ this.store.cartValidation = nextState;
1454
+ changed = previous.passed !== nextState.passed || previous.failures !== nextState.failures;
1455
+ if (!changed) {
1456
+ _context24.next = 17;
1457
+ break;
1458
+ }
1459
+ _context24.next = 17;
1460
+ return this.core.effects.emit(ScanOrderHooks.onCartValidationChanged, {
1461
+ cartValidation: nextState,
1462
+ cartValidationPassed: nextState.passed
1463
+ });
1464
+ case 17:
1465
+ return _context24.abrupt("return", nextState.passed);
1466
+ case 18:
1467
+ case "end":
1468
+ return _context24.stop();
1469
+ }
1470
+ }, _callee24, this, [[2, 9]]);
1471
+ }));
1472
+ function refreshCartValidationPassed() {
1473
+ return _refreshCartValidationPassed.apply(this, arguments);
1474
+ }
1475
+ return refreshCartValidationPassed;
1476
+ }()
1477
+ }, {
1478
+ key: "setItemRuleRuntimeConfig",
1479
+ value: function () {
1480
+ var _setItemRuleRuntimeConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
1481
+ var _this$itemRuleRuntime, _this$itemRuleRuntime2;
1482
+ var config,
1483
+ _args25 = arguments;
1484
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
1485
+ while (1) switch (_context25.prev = _context25.next) {
1486
+ case 0:
1487
+ config = _args25.length > 0 && _args25[0] !== undefined ? _args25[0] : {};
1488
+ this.logMethodStart('setItemRuleRuntimeConfig');
1489
+ this.itemRuleRuntimeConfig = _objectSpread(_objectSpread(_objectSpread({}, this.itemRuleRuntimeConfig), config), {}, {
1490
+ pax: _objectSpread(_objectSpread({}, ((_this$itemRuleRuntime = this.itemRuleRuntimeConfig) === null || _this$itemRuleRuntime === void 0 ? void 0 : _this$itemRuleRuntime.pax) || {}), (config === null || config === void 0 ? void 0 : config.pax) || {}),
1491
+ custom: _objectSpread(_objectSpread({}, ((_this$itemRuleRuntime2 = this.itemRuleRuntimeConfig) === null || _this$itemRuleRuntime2 === void 0 ? void 0 : _this$itemRuleRuntime2.custom) || {}), (config === null || config === void 0 ? void 0 : config.custom) || {})
1492
+ });
1493
+ if ('strategyConfigs' in config) {
1494
+ this.itemRuleConfigs = [];
1495
+ this.itemRuleConfigsPromise = null;
1496
+ this.itemRuleEvaluator.setStrategyConfigs([]);
1497
+ }
1498
+ this.itemRulePrefillApplied = false;
1499
+ _context25.next = 7;
1500
+ return this.refreshItemRuleQuantityLimits();
1501
+ case 7:
1502
+ _context25.next = 9;
1503
+ return this.refreshCartValidationPassed();
1504
+ case 9:
1505
+ this.logMethodSuccess('setItemRuleRuntimeConfig', {
1506
+ strategyCount: Array.isArray(this.itemRuleRuntimeConfig.strategyConfigs) ? this.itemRuleRuntimeConfig.strategyConfigs.length : 0
1507
+ });
1508
+ case 10:
1509
+ case "end":
1510
+ return _context25.stop();
1511
+ }
1512
+ }, _callee25, this);
1513
+ }));
1514
+ function setItemRuleRuntimeConfig() {
1515
+ return _setItemRuleRuntimeConfig.apply(this, arguments);
1516
+ }
1517
+ return setItemRuleRuntimeConfig;
1518
+ }()
1519
+ }, {
1520
+ key: "normalizeResourceState",
1521
+ value: function normalizeResourceState(config, hasOrderId) {
1522
+ var _this$otherParams4;
1523
+ var orderNumberPrefix = Array.isArray(config === null || config === void 0 ? void 0 : config.order_number_prefix) ? (config === null || config === void 0 ? void 0 : config.order_number_prefix) || [] : [];
1524
+ var tableMaxNumber = Number((config === null || config === void 0 ? void 0 : config.table_max_number) || 1);
1525
+ var orderCount = toNonNegativeNumber(config === null || config === void 0 ? void 0 : config.order_count);
1526
+ var currentOrderId = toPositiveString(config === null || config === void 0 ? void 0 : config.order_id);
1527
+ var lastOrderId = toPositiveString(config === null || config === void 0 ? void 0 : config.last_order_id);
1528
+ var relationId = toPositiveString(config === null || config === void 0 ? void 0 : config.relation_id);
1529
+ var tableFormId = toPositiveString(config === null || config === void 0 ? void 0 : config.table_form_id);
1530
+ // 是否允许加餐
1531
+ var allowSnack = ((_this$otherParams4 = this.otherParams) === null || _this$otherParams4 === void 0 || (_this$otherParams4 = _this$otherParams4.dineInConfig) === null || _this$otherParams4 === void 0 ? void 0 : _this$otherParams4['workflow.allow_add_items']) || false;
1532
+ // 开启同桌验证 - 本期没有这个配置,默认关掉
1533
+ var deskmateValid = false;
1534
+ var isExclusive = tableMaxNumber > 0 ? tableMaxNumber <= 1 : false;
1535
+ var isFull = tableMaxNumber > 0 ? orderCount >= tableMaxNumber : false;
1536
+ var isBlock = tableMaxNumber === -1;
1537
+ var availabilityInfo = {
1538
+ mode: 'idle',
1539
+ deskmate_valid: deskmateValid
1540
+ };
1541
+
1542
+ // 有currentOrderId代表是我点的单
1543
+ // 如果 url 上没有 hasOrderId,则跳转到订单详情,通过返回 resource_busy 实现
1544
+ if (currentOrderId) {
1545
+ if (!hasOrderId) {
1546
+ availabilityInfo = {
1547
+ mode: 'resource_busy',
1548
+ order_id: currentOrderId,
1549
+ relation_id: relationId,
1550
+ table_form_id: tableFormId,
1551
+ deskmate_valid: deskmateValid
1552
+ };
1553
+ } else {
1554
+ // 如果有 hasOrderId,需要检测是否允许加餐,如果允许则返回additional_order,否则也是 resource_busy
1555
+ availabilityInfo = {
1556
+ mode: allowSnack ? 'additional_order' : 'resource_busy',
1557
+ order_id: currentOrderId,
1558
+ relation_id: relationId,
1559
+ table_form_id: tableFormId,
1560
+ deskmate_valid: deskmateValid
1561
+ };
1562
+ }
1563
+ } else if (lastOrderId) {
1564
+ // 如果有其他人点的单
1565
+ // TODO: 是否独占?如果非独占,其他人点的单应该不影响我下单
1566
+ availabilityInfo = allowSnack ? {
1567
+ mode: deskmateValid ? 'additional_order_with_code' : 'additional_order',
1568
+ order_id: lastOrderId,
1569
+ relation_id: relationId,
1570
+ table_form_id: tableFormId,
1571
+ deskmate_valid: deskmateValid
1572
+ } : {
1573
+ mode: 'resource_busy',
1574
+ order_id: lastOrderId,
1575
+ relation_id: relationId,
1576
+ table_form_id: tableFormId,
1577
+ deskmate_valid: deskmateValid
1578
+ };
1579
+ }
1580
+ if (isBlock) {
1581
+ availabilityInfo = {
1582
+ mode: 'resource_block',
1583
+ order_id: lastOrderId,
1584
+ relation_id: relationId,
1585
+ table_form_id: tableFormId,
1586
+ deskmate_valid: deskmateValid
1587
+ };
1588
+ }
1589
+ return _objectSpread(_objectSpread({}, availabilityInfo), {}, {
1590
+ tableMaxNumber: tableMaxNumber,
1591
+ orderCount: orderCount,
1592
+ currentOrderId: currentOrderId,
1593
+ lastOrderId: lastOrderId,
1594
+ relationId: relationId,
1595
+ tableFormId: tableFormId,
1596
+ allowSnack: allowSnack,
1597
+ deskmateValid: deskmateValid,
1598
+ isExclusive: isExclusive,
1599
+ isFull: isFull,
1600
+ orderNumberPrefix: orderNumberPrefix,
1601
+ raw: config
1602
+ });
1603
+ }
1604
+ }, {
1605
+ key: "fetchTableConfigByResourceId",
1606
+ value: function () {
1607
+ var _fetchTableConfigByResourceId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(resourceId) {
1608
+ var tableResourceId, response;
1609
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
1610
+ while (1) switch (_context26.prev = _context26.next) {
1611
+ case 0:
1612
+ tableResourceId = Number(resourceId);
1613
+ if (!(!Number.isFinite(tableResourceId) || tableResourceId <= 0)) {
1614
+ _context26.next = 3;
1615
+ break;
1616
+ }
1617
+ throw new Error("[ScanOrder] \u975E\u6CD5\u684C\u53F0 resourceId: ".concat(resourceId));
1618
+ case 3:
1619
+ _context26.next = 5;
1620
+ return this.request.get('/order/dining/table/config', {
1621
+ table_resource_id: tableResourceId,
1622
+ with_table_form_info: 1
1623
+ });
1624
+ case 5:
1625
+ response = _context26.sent;
1626
+ if (response !== null && response !== void 0 && response.status) {
1627
+ _context26.next = 8;
1628
+ break;
1629
+ }
1630
+ throw new Error((response === null || response === void 0 ? void 0 : response.message) || '获取桌台配置失败');
1631
+ case 8:
1632
+ return _context26.abrupt("return", (response === null || response === void 0 ? void 0 : response.data) || null);
1633
+ case 9:
1634
+ case "end":
1635
+ return _context26.stop();
1636
+ }
1637
+ }, _callee26, this);
1638
+ }));
1639
+ function fetchTableConfigByResourceId(_x9) {
1640
+ return _fetchTableConfigByResourceId.apply(this, arguments);
1641
+ }
1642
+ return fetchTableConfigByResourceId;
1643
+ }() // 检测当前链接是否可用
1644
+ // 通过 resource_id + 店铺配置
1645
+ // hasOrderId 表示 url 上是否有 orderid,如果是的话,后续的流程会走加单
1646
+ }, {
1647
+ key: "checkResourceAvailable",
1648
+ value: function () {
1649
+ var _checkResourceAvailable = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(resourceId, hasOrderId) {
1650
+ var _this$otherParams5, _this$otherParams5$ge, _config$table_form_re, _config$table_form_re2, _this$otherParams6, _this$store$order4, openData, dineInConfig, shopClosedInfo, config, resourceState, availabilityInfo, tempOrder;
1651
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
1652
+ while (1) switch (_context27.prev = _context27.next) {
1653
+ case 0:
1654
+ this.logMethodStart('checkResourceAvailable', {
1655
+ resourceId: resourceId
1656
+ });
1657
+ _context27.prev = 1;
1658
+ _context27.next = 4;
1659
+ return (_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 || (_this$otherParams5$ge = _this$otherParams5.getOpenData) === null || _this$otherParams5$ge === void 0 ? void 0 : _this$otherParams5$ge.call(_this$otherParams5, {
1660
+ scope: 'board',
1661
+ target: 'dine_in+scan_to_order',
1662
+ section_code: ['basic', 'fulfillment', 'reservation', 'sale', 'menu', 'availability', 'workflow']
1663
+ });
1664
+ case 4:
1665
+ openData = _context27.sent;
1666
+ if (!((openData === null || openData === void 0 ? void 0 : openData.status) === false)) {
1667
+ _context27.next = 7;
1668
+ break;
1669
+ }
1670
+ throw new Error((openData === null || openData === void 0 ? void 0 : openData.message) || '获取店铺配置失败');
1671
+ case 7:
1672
+ dineInConfig = (openData === null || openData === void 0 ? void 0 : openData.data) || {};
1673
+ this.otherParams.dineInConfig = dineInConfig;
1674
+ _context27.next = 11;
1675
+ return this.syncItemRuleConfigsFromDineInConfig(dineInConfig);
1676
+ case 11:
1677
+ shopClosedInfo = function shopClosedInfo() {
1678
+ return {
1679
+ mode: 'shop_closed',
1680
+ order_id: undefined,
1681
+ relation_id: undefined,
1682
+ table_form_id: undefined,
1683
+ deskmate_valid: false,
1684
+ errorTips: (dineInConfig === null || dineInConfig === void 0 ? void 0 : dineInConfig['availability.pause_message']) || (dineInConfig === null || dineInConfig === void 0 ? void 0 : dineInConfig['availability.closed_message']) || (dineInConfig === null || dineInConfig === void 0 ? void 0 : dineInConfig['availability.message']) || (dineInConfig === null || dineInConfig === void 0 ? void 0 : dineInConfig['basic.closed_message'])
1685
+ };
1686
+ }; // 检测是否暂停营业
1687
+ if (!toBoolean(dineInConfig === null || dineInConfig === void 0 ? void 0 : dineInConfig['availability.paused'])) {
1688
+ _context27.next = 15;
1689
+ break;
1690
+ }
1691
+ if (!((dineInConfig === null || dineInConfig === void 0 ? void 0 : dineInConfig['availability.pause_behavior']) === 'hide_all')) {
1692
+ _context27.next = 15;
1693
+ break;
1694
+ }
1695
+ return _context27.abrupt("return", shopClosedInfo());
1696
+ case 15:
1697
+ _context27.next = 17;
1698
+ return this.fetchTableConfigByResourceId(resourceId);
1699
+ case 17:
1700
+ config = _context27.sent;
1701
+ resourceState = this.normalizeResourceState(config, hasOrderId);
1702
+ this.store.resource = resourceState;
1703
+ availabilityInfo = {
1704
+ mode: resourceState.mode,
1705
+ order_id: resourceState.order_id,
1706
+ relation_id: resourceState.relationId,
1707
+ table_form_id: resourceState.tableFormId,
1708
+ deskmate_valid: resourceState.deskmate_valid,
1709
+ policy: config === null || config === void 0 || (_config$table_form_re = config.table_form_record) === null || _config$table_form_re === void 0 ? void 0 : _config$table_form_re.policy,
1710
+ partyroom_booking: config === null || config === void 0 || (_config$table_form_re2 = config.table_form_record) === null || _config$table_form_re2 === void 0 ? void 0 : _config$table_form_re2.partyroom_booking
1711
+ };
1712
+ tempOrder = this.ensureTempOrder();
1713
+ tempOrder.relation_id = resourceId || ((_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.relation_id);
1714
+ tempOrder.table_form_id = resourceState.tableFormId;
1715
+ tempOrder.resource_id = resourceId;
1716
+ (_this$store$order4 = this.store.order) === null || _this$store$order4 === void 0 || _this$store$order4.persistTempOrder();
1717
+
1718
+ // 空闲状态下自动准备本地临时订单,供后续“购物车式”商品操作使用
1719
+ if (!(availabilityInfo.mode === 'idle')) {
1720
+ _context27.next = 29;
1721
+ break;
1722
+ }
1723
+ _context27.next = 29;
1724
+ return this.addNewOrder();
1725
+ case 29:
1726
+ // 如果是加单模式,tempOrder 里 需要记录 lastOrderId,提交的时候走加单接口
1727
+ if (availabilityInfo.mode === 'additional_order' || availabilityInfo.mode === 'additional_order_with_code') {
1728
+ tempOrder.order_id = resourceState.lastOrderId;
1729
+ }
1730
+ _context27.next = 32;
1731
+ return this.refreshItemRuleQuantityLimits();
1732
+ case 32:
1733
+ _context27.next = 34;
1734
+ return this.refreshCartValidationPassed();
1735
+ case 34:
1736
+ this.logMethodSuccess('checkResourceAvailable', {
1737
+ resourceId: resourceId,
1738
+ mode: availabilityInfo.mode,
1739
+ orderId: availabilityInfo.order_id,
1740
+ relationId: availabilityInfo.relation_id,
1741
+ tableFormId: availabilityInfo.table_form_id,
1742
+ persistedRelationId: tempOrder.relation_id,
1743
+ persistedResourceId: tempOrder.resource_id,
1744
+ deskmateValid: availabilityInfo.deskmate_valid,
1745
+ orderCount: resourceState.orderCount,
1746
+ tableMaxNumber: resourceState.tableMaxNumber,
1747
+ isExclusive: resourceState.isExclusive,
1748
+ isFull: resourceState.isFull
1749
+ });
1750
+ return _context27.abrupt("return", availabilityInfo);
1751
+ case 38:
1752
+ _context27.prev = 38;
1753
+ _context27.t0 = _context27["catch"](1);
1754
+ this.logMethodError('checkResourceAvailable', _context27.t0, {
1755
+ resourceId: resourceId
1756
+ });
1757
+ throw _context27.t0;
1758
+ case 42:
1759
+ case "end":
1760
+ return _context27.stop();
1761
+ }
1762
+ }, _callee27, this, [[1, 38]]);
1763
+ }));
1764
+ function checkResourceAvailable(_x10, _x11) {
1765
+ return _checkResourceAvailable.apply(this, arguments);
1766
+ }
1767
+ return checkResourceAvailable;
1768
+ }() // 如果是加单的情况,提供返回当前订单相关信息的能力
1769
+ }, {
1770
+ key: "getAdditionalOrderInfo",
1771
+ value: function () {
1772
+ var _getAdditionalOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
1773
+ var result;
1774
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
1775
+ while (1) switch (_context28.prev = _context28.next) {
1776
+ case 0:
1777
+ this.logMethodStart('getAdditionalOrderInfo');
1778
+ result = {
1779
+ orderId: '123567890',
1780
+ orderStatus: 'pending',
1781
+ orderTime: '2026-03-31 10:00:00',
1782
+ orderAmount: 100,
1783
+ orderItems: []
1784
+ };
1785
+ this.logMethodSuccess('getAdditionalOrderInfo', {
1786
+ orderId: result.orderId,
1787
+ orderStatus: result.orderStatus
1788
+ });
1789
+ return _context28.abrupt("return", result);
1790
+ case 4:
1791
+ case "end":
1792
+ return _context28.stop();
1793
+ }
1794
+ }, _callee28, this);
1795
+ }));
1796
+ function getAdditionalOrderInfo() {
1797
+ return _getAdditionalOrderInfo.apply(this, arguments);
1798
+ }
1799
+ return getAdditionalOrderInfo;
1800
+ }() // 获取商品列表
1801
+ }, {
1802
+ key: "getProductList",
1803
+ value: function () {
1804
+ var _getProductList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
1805
+ var _this$otherParams7;
1806
+ var menu_list_ids, _this$store$products, res, formattedRes;
1807
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
1808
+ while (1) switch (_context29.prev = _context29.next) {
1809
+ case 0:
1810
+ this.logMethodStart('getProductList');
1811
+ // 可以直接通过配置里的 menu 读取
1812
+ menu_list_ids = ((_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 || (_this$otherParams7 = _this$otherParams7.dineInConfig) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7['menu.associated_menus'].map(function (n) {
1813
+ return Number(n.value);
1814
+ })) || [];
1815
+ _context29.prev = 2;
1816
+ _context29.next = 5;
1817
+ return (_this$store$products = this.store.products) === null || _this$store$products === void 0 ? void 0 : _this$store$products.loadProducts({
1818
+ menu_list_ids: menu_list_ids,
1819
+ cacheId: this.cacheId,
1820
+ schedule_date: dayjs().format('YYYY-MM-DD'),
1821
+ schedule_datetime: dayjs().format('YYYY-MM-DD HH:mm:ss')
1822
+ });
1823
+ case 5:
1824
+ res = _context29.sent;
1825
+ formattedRes = attachItemRuleLimitsToTopLevelProducts(res, this.store.itemRuleQuantityLimits || []);
1826
+ this.logMethodSuccess('getProductList', {
1827
+ menuCount: menu_list_ids.length
1828
+ });
1829
+ return _context29.abrupt("return", formattedRes);
1830
+ case 11:
1831
+ _context29.prev = 11;
1832
+ _context29.t0 = _context29["catch"](2);
1833
+ this.logMethodError('getProductList', _context29.t0);
1834
+ throw _context29.t0;
1835
+ case 15:
1836
+ case "end":
1837
+ return _context29.stop();
1838
+ }
1839
+ }, _callee29, this, [[2, 11]]);
1840
+ }));
1841
+ function getProductList() {
1842
+ return _getProductList.apply(this, arguments);
1843
+ }
1844
+ return getProductList;
1845
+ }()
1846
+ }, {
1847
+ key: "getOtherParams",
1848
+ value: function getOtherParams() {
1849
+ return this.otherParams;
1850
+ }
1851
+ }]);
1852
+ return ScanOrderImpl;
1853
+ }(BaseModule);