@pisell/pisellos 2.1.170 → 2.1.172

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/index.d.ts +1 -1
  2. package/dist/index.js +1 -3
  3. package/dist/model/strategy/adapter/index.d.ts +0 -4
  4. package/dist/model/strategy/adapter/index.js +1 -5
  5. package/dist/model/strategy/adapter/promotion/evaluator.js +99 -26
  6. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  7. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  8. package/dist/model/strategy/adapter/walletPass/evaluator.js +61 -8
  9. package/dist/model/strategy/adapter/walletPass/locales.js +12 -3
  10. package/dist/model/strategy/engine.d.ts +18 -5
  11. package/dist/model/strategy/engine.js +145 -45
  12. package/dist/model/strategy/type.d.ts +17 -0
  13. package/dist/model/strategy/type.js +4 -0
  14. package/dist/modules/Cart/types.d.ts +2 -0
  15. package/dist/modules/Cart/utils/cartProduct.js +56 -25
  16. package/dist/modules/Cart/utils/changePrice.js +9 -16
  17. package/dist/modules/Discount/index.d.ts +4 -13
  18. package/dist/modules/Discount/index.js +12 -124
  19. package/dist/modules/Discount/types.d.ts +18 -13
  20. package/dist/modules/Order/index.d.ts +1 -67
  21. package/dist/modules/Order/index.js +30 -918
  22. package/dist/modules/Order/types.d.ts +12 -176
  23. package/dist/modules/Order/types.js +0 -2
  24. package/dist/modules/Order/utils.d.ts +0 -118
  25. package/dist/modules/Order/utils.js +2 -586
  26. package/dist/modules/Payment/index.d.ts +2 -1
  27. package/dist/modules/Payment/index.js +10 -7
  28. package/dist/modules/Payment/utils.js +3 -0
  29. package/dist/modules/Payment/walletpass.d.ts +23 -0
  30. package/dist/modules/Payment/walletpass.js +191 -95
  31. package/dist/modules/Product/utils.js +2 -2
  32. package/dist/modules/ProductList/index.d.ts +2 -4
  33. package/dist/modules/ProductList/index.js +12 -24
  34. package/dist/modules/Rules/index.d.ts +9 -5
  35. package/dist/modules/Rules/index.js +669 -173
  36. package/dist/modules/Rules/types.d.ts +2 -0
  37. package/dist/modules/Schedule/getDateIsInSchedule.js +18 -16
  38. package/dist/modules/Schedule/utils.d.ts +1 -1
  39. package/dist/modules/Summary/types.d.ts +2 -0
  40. package/dist/modules/Summary/utils.d.ts +9 -3
  41. package/dist/modules/Summary/utils.js +57 -67
  42. package/dist/modules/index.d.ts +0 -4
  43. package/dist/modules/index.js +1 -5
  44. package/dist/plugins/window.d.ts +2 -0
  45. package/dist/solution/BookingByStep/index.d.ts +3 -2
  46. package/dist/solution/BookingByStep/index.js +43 -46
  47. package/dist/solution/BookingByStep/types.d.ts +1 -3
  48. package/dist/solution/BookingByStep/types.js +1 -5
  49. package/dist/solution/BookingByStep/utils/timeslots.d.ts +1 -3
  50. package/dist/solution/BookingByStep/utils/timeslots.js +12 -19
  51. package/dist/solution/Checkout/index.js +2 -0
  52. package/dist/solution/ShopDiscount/index.d.ts +2 -3
  53. package/dist/solution/ShopDiscount/index.js +60 -62
  54. package/dist/solution/ShopDiscount/types.d.ts +1 -1
  55. package/dist/solution/ShopDiscount/types.js +2 -1
  56. package/dist/solution/ShopDiscount/utils.js +26 -12
  57. package/dist/solution/index.d.ts +0 -2
  58. package/dist/solution/index.js +1 -3
  59. package/lib/index.d.ts +1 -1
  60. package/lib/index.js +3 -4
  61. package/lib/model/strategy/adapter/index.d.ts +0 -4
  62. package/lib/model/strategy/adapter/index.js +2 -13
  63. package/lib/model/strategy/adapter/promotion/evaluator.js +57 -8
  64. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  65. package/lib/model/strategy/adapter/walletPass/evaluator.js +34 -3
  66. package/lib/model/strategy/adapter/walletPass/locales.js +12 -3
  67. package/lib/model/strategy/engine.d.ts +18 -5
  68. package/lib/model/strategy/engine.js +85 -21
  69. package/lib/model/strategy/type.d.ts +17 -0
  70. package/lib/modules/Cart/types.d.ts +2 -0
  71. package/lib/modules/Cart/utils/cartProduct.js +39 -12
  72. package/lib/modules/Cart/utils/changePrice.js +9 -13
  73. package/lib/modules/Discount/index.d.ts +4 -13
  74. package/lib/modules/Discount/index.js +5 -76
  75. package/lib/modules/Discount/types.d.ts +18 -13
  76. package/lib/modules/Order/index.d.ts +1 -67
  77. package/lib/modules/Order/index.js +1 -525
  78. package/lib/modules/Order/types.d.ts +12 -176
  79. package/lib/modules/Order/utils.d.ts +0 -118
  80. package/lib/modules/Order/utils.js +2 -483
  81. package/lib/modules/Payment/index.d.ts +2 -1
  82. package/lib/modules/Payment/index.js +1 -0
  83. package/lib/modules/Payment/utils.js +3 -0
  84. package/lib/modules/Payment/walletpass.d.ts +23 -0
  85. package/lib/modules/Payment/walletpass.js +94 -17
  86. package/lib/modules/Product/utils.js +2 -2
  87. package/lib/modules/ProductList/index.d.ts +2 -4
  88. package/lib/modules/ProductList/index.js +39 -46
  89. package/lib/modules/Rules/index.d.ts +9 -5
  90. package/lib/modules/Rules/index.js +776 -292
  91. package/lib/modules/Rules/types.d.ts +2 -0
  92. package/lib/modules/Schedule/getDateIsInSchedule.js +11 -13
  93. package/lib/modules/Schedule/utils.d.ts +1 -1
  94. package/lib/modules/Summary/types.d.ts +2 -0
  95. package/lib/modules/Summary/utils.d.ts +9 -3
  96. package/lib/modules/Summary/utils.js +34 -45
  97. package/lib/modules/index.d.ts +0 -4
  98. package/lib/modules/index.js +1 -9
  99. package/lib/plugins/window.d.ts +2 -0
  100. package/lib/solution/BookingByStep/index.d.ts +3 -2
  101. package/lib/solution/BookingByStep/index.js +4 -6
  102. package/lib/solution/BookingByStep/types.d.ts +1 -3
  103. package/lib/solution/BookingByStep/types.js +0 -10
  104. package/lib/solution/BookingByStep/utils/timeslots.d.ts +1 -3
  105. package/lib/solution/BookingByStep/utils/timeslots.js +11 -19
  106. package/lib/solution/Checkout/index.js +2 -0
  107. package/lib/solution/ShopDiscount/index.d.ts +2 -3
  108. package/lib/solution/ShopDiscount/index.js +27 -22
  109. package/lib/solution/ShopDiscount/types.d.ts +1 -1
  110. package/lib/solution/ShopDiscount/utils.js +10 -6
  111. package/lib/solution/index.d.ts +0 -2
  112. package/lib/solution/index.js +1 -5
  113. package/package.json +2 -2
  114. package/dist/apis/picoding.d.ts +0 -0
  115. package/dist/apis/picoding.js +0 -1
  116. package/dist/model/strategy/adapter/dataVariant/adapter.d.ts +0 -50
  117. package/dist/model/strategy/adapter/dataVariant/adapter.js +0 -167
  118. package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +0 -89
  119. package/dist/model/strategy/adapter/dataVariant/evaluator.js +0 -867
  120. package/dist/model/strategy/adapter/dataVariant/examples.d.ts +0 -39
  121. package/dist/model/strategy/adapter/dataVariant/examples.js +0 -277
  122. package/dist/model/strategy/adapter/dataVariant/index.d.ts +0 -4
  123. package/dist/model/strategy/adapter/dataVariant/index.js +0 -4
  124. package/dist/model/strategy/adapter/dataVariant/type.d.ts +0 -149
  125. package/dist/model/strategy/adapter/dataVariant/type.js +0 -54
  126. package/dist/modules/OpenData/index.d.ts +0 -24
  127. package/dist/modules/OpenData/index.js +0 -173
  128. package/dist/modules/OpenData/types.d.ts +0 -73
  129. package/dist/modules/OpenData/types.js +0 -1
  130. package/dist/modules/OpenData/utils.d.ts +0 -2
  131. package/dist/modules/OpenData/utils.js +0 -75
  132. package/dist/modules/Quotation/index.d.ts +0 -48
  133. package/dist/modules/Quotation/index.js +0 -248
  134. package/dist/modules/Quotation/types.d.ts +0 -42
  135. package/dist/modules/Quotation/types.js +0 -1
  136. package/dist/modules/SalesSummary/index.d.ts +0 -63
  137. package/dist/modules/SalesSummary/index.js +0 -174
  138. package/dist/modules/SalesSummary/types.d.ts +0 -60
  139. package/dist/modules/SalesSummary/types.js +0 -1
  140. package/dist/modules/SalesSummary/utils.d.ts +0 -30
  141. package/dist/modules/SalesSummary/utils.js +0 -480
  142. package/dist/modules/ScanOrderLogger/index.d.ts +0 -23
  143. package/dist/modules/ScanOrderLogger/index.js +0 -174
  144. package/dist/modules/ScanOrderLogger/providers/feishu.d.ts +0 -2
  145. package/dist/modules/ScanOrderLogger/providers/feishu.js +0 -221
  146. package/dist/modules/ScanOrderLogger/providers/grafana.d.ts +0 -2
  147. package/dist/modules/ScanOrderLogger/providers/grafana.js +0 -50
  148. package/dist/modules/ScanOrderLogger/types.d.ts +0 -53
  149. package/dist/modules/ScanOrderLogger/types.js +0 -1
  150. package/dist/solution/ScanOrder/index.d.ts +0 -158
  151. package/dist/solution/ScanOrder/index.js +0 -3474
  152. package/dist/solution/ScanOrder/types.d.ts +0 -306
  153. package/dist/solution/ScanOrder/types.js +0 -35
  154. package/dist/solution/ScanOrder/utils.d.ts +0 -172
  155. package/dist/solution/ScanOrder/utils.js +0 -796
  156. package/dist/solution/VenueBooking/index.d.ts +0 -252
  157. package/dist/solution/VenueBooking/index.js +0 -3769
  158. package/dist/solution/VenueBooking/sales-section-4-annotated.json +0 -343
  159. package/dist/solution/VenueBooking/types.d.ts +0 -156
  160. package/dist/solution/VenueBooking/types.js +0 -22
  161. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +0 -11
  162. package/dist/solution/VenueBooking/utils/dateSummary.js +0 -91
  163. package/dist/solution/VenueBooking/utils/resource.d.ts +0 -14
  164. package/dist/solution/VenueBooking/utils/resource.js +0 -131
  165. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +0 -32
  166. package/dist/solution/VenueBooking/utils/slotMerge.js +0 -233
  167. package/dist/solution/VenueBooking/utils/smartPricing.d.ts +0 -71
  168. package/dist/solution/VenueBooking/utils/smartPricing.js +0 -302
  169. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +0 -34
  170. package/dist/solution/VenueBooking/utils/timeSlot.js +0 -458
  171. package/dist/solution/VenueBooking/utils.d.ts +0 -1
  172. package/dist/solution/VenueBooking/utils.js +0 -1
  173. package/lib/apis/picoding.d.ts +0 -0
  174. package/lib/apis/picoding.js +0 -0
  175. package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +0 -50
  176. package/lib/model/strategy/adapter/dataVariant/adapter.js +0 -149
  177. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +0 -89
  178. package/lib/model/strategy/adapter/dataVariant/evaluator.js +0 -666
  179. package/lib/model/strategy/adapter/dataVariant/examples.d.ts +0 -39
  180. package/lib/model/strategy/adapter/dataVariant/examples.js +0 -293
  181. package/lib/model/strategy/adapter/dataVariant/index.d.ts +0 -4
  182. package/lib/model/strategy/adapter/dataVariant/index.js +0 -38
  183. package/lib/model/strategy/adapter/dataVariant/type.d.ts +0 -149
  184. package/lib/model/strategy/adapter/dataVariant/type.js +0 -31
  185. package/lib/modules/OpenData/index.d.ts +0 -24
  186. package/lib/modules/OpenData/index.js +0 -119
  187. package/lib/modules/OpenData/types.d.ts +0 -73
  188. package/lib/modules/OpenData/types.js +0 -17
  189. package/lib/modules/OpenData/utils.d.ts +0 -2
  190. package/lib/modules/OpenData/utils.js +0 -111
  191. package/lib/modules/Quotation/index.d.ts +0 -48
  192. package/lib/modules/Quotation/index.js +0 -152
  193. package/lib/modules/Quotation/types.d.ts +0 -42
  194. package/lib/modules/Quotation/types.js +0 -17
  195. package/lib/modules/SalesSummary/index.d.ts +0 -63
  196. package/lib/modules/SalesSummary/index.js +0 -105
  197. package/lib/modules/SalesSummary/types.d.ts +0 -60
  198. package/lib/modules/SalesSummary/types.js +0 -17
  199. package/lib/modules/SalesSummary/utils.d.ts +0 -30
  200. package/lib/modules/SalesSummary/utils.js +0 -420
  201. package/lib/modules/ScanOrderLogger/index.d.ts +0 -23
  202. package/lib/modules/ScanOrderLogger/index.js +0 -147
  203. package/lib/modules/ScanOrderLogger/providers/feishu.d.ts +0 -2
  204. package/lib/modules/ScanOrderLogger/providers/feishu.js +0 -157
  205. package/lib/modules/ScanOrderLogger/providers/grafana.d.ts +0 -2
  206. package/lib/modules/ScanOrderLogger/providers/grafana.js +0 -52
  207. package/lib/modules/ScanOrderLogger/types.d.ts +0 -53
  208. package/lib/modules/ScanOrderLogger/types.js +0 -17
  209. package/lib/solution/ScanOrder/index.d.ts +0 -158
  210. package/lib/solution/ScanOrder/index.js +0 -2135
  211. package/lib/solution/ScanOrder/types.d.ts +0 -306
  212. package/lib/solution/ScanOrder/types.js +0 -36
  213. package/lib/solution/ScanOrder/utils.d.ts +0 -172
  214. package/lib/solution/ScanOrder/utils.js +0 -658
  215. package/lib/solution/VenueBooking/index.d.ts +0 -252
  216. package/lib/solution/VenueBooking/index.js +0 -2204
  217. package/lib/solution/VenueBooking/sales-section-4-annotated.json +0 -343
  218. package/lib/solution/VenueBooking/types.d.ts +0 -156
  219. package/lib/solution/VenueBooking/types.js +0 -45
  220. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +0 -11
  221. package/lib/solution/VenueBooking/utils/dateSummary.js +0 -105
  222. package/lib/solution/VenueBooking/utils/resource.d.ts +0 -14
  223. package/lib/solution/VenueBooking/utils/resource.js +0 -92
  224. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +0 -32
  225. package/lib/solution/VenueBooking/utils/slotMerge.js +0 -236
  226. package/lib/solution/VenueBooking/utils/smartPricing.d.ts +0 -71
  227. package/lib/solution/VenueBooking/utils/smartPricing.js +0 -225
  228. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +0 -34
  229. package/lib/solution/VenueBooking/utils/timeSlot.js +0 -343
  230. package/lib/solution/VenueBooking/utils.d.ts +0 -1
  231. package/lib/solution/VenueBooking/utils.js +0 -69
@@ -1,3769 +0,0 @@
1
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
4
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
5
- 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; } } }; }
6
- 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; }
7
- 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); } }
8
- 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); }); }; }
9
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10
- 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); } }
11
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
12
- 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); }
13
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
14
- 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); }; }
15
- 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); }
16
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
17
- 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; } }
18
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
19
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
20
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
21
- 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); }
22
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
23
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
24
- 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; }
25
- 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; }
26
- 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; }
27
- 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; }
28
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
29
- 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); }
30
- 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); }
31
- import { BaseModule } from "../../modules/BaseModule";
32
- import { DEFAULT_SLOT_CONFIG, VenueBookingHooks } from "./types";
33
- import { attachItemRuleLimitsToTopLevelProducts, buildProductKey, buildItemRuleBusinessData, createEmptySummary, getProductIdentityIndex, getSafeProductNum, normalizeOrderProduct, normalizeItemRuleStrategies, toNonNegativeInt, toPriceString } from "./utils";
34
- import { createModule } from "../BookingByStep/types";
35
- import { ProductList } from "../../modules/ProductList";
36
- import { DateModule } from "../../modules/Date";
37
- import { ScheduleModule } from "../../modules/Schedule";
38
- import { calcMinTimeMaxTimeBySchedules } from "../../modules/Schedule/utils";
39
- import { QuotationModule } from "../../modules/Quotation";
40
- import { OpenDataModule } from "../../modules/OpenData";
41
- import { AccountHooks } from "../../modules/Account/types";
42
- import dayjs from 'dayjs';
43
- import { ItemRuleEvaluator } from "../../model/strategy/adapter/itemRule";
44
- import { extractResourceIds, buildResourceProductMap } from "./utils/resource";
45
- import { buildTimeSlotGrid, isBusinessHoursCrossDay, generateTimeLabels } from "./utils/timeSlot";
46
- import { buildDateRangeSummary } from "./utils/dateSummary";
47
- import { mergeConsecutiveSlots, expandMergedSlotToIndividual, buildVenueIdentityKey, buildVenueBookingEntry, buildVenueResourceMetadata, buildPriceBreakdown } from "./utils/slotMerge";
48
- import { buildSlotPriceMapByScheduleSegments, formatProductsWithDataVariant, getPriceForProductAtDatetime, getSlotPriceFromMap } from "./utils/smartPricing";
49
- import { composeLinePrice, createUuidV4, sumOptionUnitPrice } from "../../modules/Order/utils";
50
- import { OrderModule } from "../../modules/Order";
51
- import { RegisterAndLoginHooks } from "../RegisterAndLogin/types";
52
- import Decimal from 'decimal.js';
53
- export * from "./types";
54
- var OPEN_DATA_SECTION_CODES = ['basic', 'fulfillment', 'reservation', 'sale', 'menu', 'availability', 'workflow', 'checkout'];
55
- function cloneCustomDepositData(customDepositData) {
56
- if (!customDepositData || _typeof(customDepositData) !== 'object') return undefined;
57
- return _objectSpread(_objectSpread({}, customDepositData), {}, {
58
- self_deposit_policy_ids: Array.isArray(customDepositData.self_deposit_policy_ids) ? _toConsumableArray(customDepositData.self_deposit_policy_ids) : [],
59
- deposit_policy_ids: Array.isArray(customDepositData.deposit_policy_ids) ? _toConsumableArray(customDepositData.deposit_policy_ids) : [],
60
- deposit_policy_data: Array.isArray(customDepositData.deposit_policy_data) ? _toConsumableArray(customDepositData.deposit_policy_data) : []
61
- });
62
- }
63
- export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
64
- _inherits(VenueBookingImpl, _BaseModule);
65
- var _super = _createSuper(VenueBookingImpl);
66
- function VenueBookingImpl(name, version) {
67
- var _this;
68
- _classCallCheck(this, VenueBookingImpl);
69
- _this = _super.call(this, name, version);
70
- _defineProperty(_assertThisInitialized(_this), "defaultName", 'venueBooking');
71
- _defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
72
- _defineProperty(_assertThisInitialized(_this), "isSolution", true);
73
- _defineProperty(_assertThisInitialized(_this), "initializeOptions", {});
74
- _defineProperty(_assertThisInitialized(_this), "store", {
75
- entryContext: null,
76
- status: 'idle',
77
- flow: {},
78
- error: null,
79
- products: undefined,
80
- rawResourceData: [],
81
- slotConfig: _objectSpread({}, DEFAULT_SLOT_CONFIG),
82
- itemRuleQuantityLimits: [],
83
- cartValidation: {
84
- passed: null,
85
- failures: []
86
- }
87
- });
88
- _defineProperty(_assertThisInitialized(_this), "otherParams", {});
89
- _defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
90
- _defineProperty(_assertThisInitialized(_this), "window", void 0);
91
- _defineProperty(_assertThisInitialized(_this), "request", void 0);
92
- _defineProperty(_assertThisInitialized(_this), "baseSlotConfig", _objectSpread({}, DEFAULT_SLOT_CONFIG));
93
- _defineProperty(_assertThisInitialized(_this), "itemRuleEvaluator", new ItemRuleEvaluator());
94
- _defineProperty(_assertThisInitialized(_this), "itemRuleConfigs", []);
95
- _defineProperty(_assertThisInitialized(_this), "itemRuleConfigsPromise", null);
96
- _defineProperty(_assertThisInitialized(_this), "itemRulePrefillApplied", false);
97
- _defineProperty(_assertThisInitialized(_this), "itemRuleRuntimeConfig", {});
98
- _defineProperty(_assertThisInitialized(_this), "resourceProductMap", new Map());
99
- _defineProperty(_assertThisInitialized(_this), "loginEffectDisposers", []);
100
- _defineProperty(_assertThisInitialized(_this), "customerLoginRefreshInFlight", null);
101
- _defineProperty(_assertThisInitialized(_this), "customerLoginRefreshIdInFlight", null);
102
- /** 最近一次确认登录的客户;登录事件与 user 插件更新之间可能存在时序差。 */
103
- _defineProperty(_assertThisInitialized(_this), "smartPricingCustomerId", void 0);
104
- _defineProperty(_assertThisInitialized(_this), "loadAllProductsInFlight", null);
105
- _defineProperty(_assertThisInitialized(_this), "productsLoaded", false);
106
- _defineProperty(_assertThisInitialized(_this), "loadOpenDataConfigInFlight", null);
107
- /** 按日期缓存 slot 智能定价 Map,避免同周重复 resolveProducts */
108
- _defineProperty(_assertThisInitialized(_this), "slotPriceMapCache", new Map());
109
- /** loadProducts 后缓存的全量商品(venue + addon),供分段算价复用 */
110
- _defineProperty(_assertThisInitialized(_this), "smartPricingProductCatalog", []);
111
- return _this;
112
- }
113
- _createClass(VenueBookingImpl, [{
114
- key: "getLoggerContext",
115
- value: function getLoggerContext() {
116
- return {
117
- cacheId: this.cacheId,
118
- solutionName: this.name,
119
- moduleName: 'venueBooking'
120
- };
121
- }
122
- }, {
123
- key: "safeStringify",
124
- value: function safeStringify(value) {
125
- try {
126
- return JSON.stringify(value);
127
- } catch (_unused) {
128
- return undefined;
129
- }
130
- }
131
- }, {
132
- key: "pickErrorMessage",
133
- value: function pickErrorMessage(error) {
134
- var _error$data, _error$response, _error$error;
135
- var candidates = [error.message, (_error$data = error.data) === null || _error$data === void 0 ? void 0 : _error$data.message, (_error$response = error.response) === null || _error$response === void 0 || (_error$response = _error$response.data) === null || _error$response === void 0 ? void 0 : _error$response.message, (_error$error = error.error) === null || _error$error === void 0 ? void 0 : _error$error.message];
136
- for (var _i = 0, _candidates = candidates; _i < _candidates.length; _i++) {
137
- var candidate = _candidates[_i];
138
- if (typeof candidate === 'string' && candidate.trim()) return candidate;
139
- }
140
- return undefined;
141
- }
142
- }, {
143
- key: "serializeError",
144
- value: function serializeError(error) {
145
- if (error instanceof Error) {
146
- return {
147
- name: error.name,
148
- message: error.message,
149
- stack: error.stack
150
- };
151
- }
152
- if (error && _typeof(error) === 'object') {
153
- var raw = error;
154
- var message = this.pickErrorMessage(raw) || this.safeStringify(raw) || String(error);
155
- return _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, typeof raw.name === 'string' ? {
156
- name: raw.name
157
- } : {}), {}, {
158
- message: message
159
- }, 'code' in raw ? {
160
- code: raw.code
161
- } : {}), 'status' in raw ? {
162
- status: raw.status
163
- } : {}), this.safeStringify(raw) ? {
164
- raw: this.safeStringify(raw)
165
- } : {});
166
- }
167
- return {
168
- message: String(error)
169
- };
170
- }
171
- }, {
172
- key: "addVenueBookingLog",
173
- value: function () {
174
- var _addVenueBookingLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
175
- var payload, extra, logger;
176
- return _regeneratorRuntime().wrap(function _callee$(_context) {
177
- while (1) switch (_context.prev = _context.next) {
178
- case 0:
179
- payload = _objectSpread({
180
- cacheId: this.cacheId
181
- }, params.payload || {});
182
- extra = _objectSpread({}, params.extra || {});
183
- logger = this.store.scanOrderLogger;
184
- if (logger) {
185
- _context.next = 6;
186
- break;
187
- }
188
- if ((params.level || 'info') === 'error') {
189
- console.error('[VenueBooking][log-fallback]', params.title, {
190
- payload: payload,
191
- extra: extra
192
- });
193
- } else {
194
- console.log('[VenueBooking][log-fallback]', params.title, {
195
- payload: payload,
196
- extra: extra
197
- });
198
- }
199
- return _context.abrupt("return");
200
- case 6:
201
- _context.next = 8;
202
- return logger.addLog(_objectSpread(_objectSpread({}, params), {}, {
203
- payload: payload,
204
- extra: extra
205
- }));
206
- case 8:
207
- case "end":
208
- return _context.stop();
209
- }
210
- }, _callee, this);
211
- }));
212
- function addVenueBookingLog(_x) {
213
- return _addVenueBookingLog.apply(this, arguments);
214
- }
215
- return addVenueBookingLog;
216
- }()
217
- /**
218
- * 临时线上排查日志:
219
- * - 仅对指定页面 cacheId 开启,避免影响其他页面
220
- * - 不 await,且吞掉日志上报异常,保证日志系统不会阻断登录/商品加载主流程
221
- */
222
- }, {
223
- key: "logPricingDiagnostics",
224
- value: function logPricingDiagnostics(title) {
225
- var payload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
226
- if (!this.isPricingDiagnosticsEnabled()) return;
227
- void this.addVenueBookingLog({
228
- level: 'info',
229
- title: title,
230
- payload: payload
231
- }).catch(function (error) {
232
- console.warn('[VenueBooking] pricing diagnostic log failed', error);
233
- });
234
- }
235
- }, {
236
- key: "isPricingDiagnosticsEnabled",
237
- value: function isPricingDiagnosticsEnabled() {
238
- return String(this.cacheId || '') === VenueBookingImpl.PRICING_DEBUG_CACHE_ID;
239
- }
240
- }, {
241
- key: "getAvailableWalletIdsForDiagnostics",
242
- value: function getAvailableWalletIdsForDiagnostics() {
243
- try {
244
- var _this$store$order, _this$store$order$get;
245
- return (_this$store$order = this.store.order) === null || _this$store$order === void 0 || (_this$store$order$get = _this$store$order.getAvailableWalletIds) === null || _this$store$order$get === void 0 ? void 0 : _this$store$order$get.call(_this$store$order);
246
- } catch (error) {
247
- return {
248
- readFailed: true,
249
- error: this.serializeError(error)
250
- };
251
- }
252
- }
253
- }, {
254
- key: "logMethodStart",
255
- value: function logMethodStart(method) {
256
- var payload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
257
- void this.addVenueBookingLog({
258
- level: 'info',
259
- title: "[VenueBooking] ".concat(method, " start"),
260
- payload: _objectSpread({
261
- method: method
262
- }, payload)
263
- });
264
- }
265
- }, {
266
- key: "logMethodSuccess",
267
- value: function logMethodSuccess(method) {
268
- var payload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
269
- void this.addVenueBookingLog({
270
- level: 'info',
271
- title: "[VenueBooking] ".concat(method, " success"),
272
- payload: _objectSpread({
273
- method: method
274
- }, payload)
275
- });
276
- }
277
- }, {
278
- key: "logMethodError",
279
- value: function logMethodError(method, error) {
280
- var payload = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
281
- void this.addVenueBookingLog({
282
- level: 'error',
283
- title: "[VenueBooking] ".concat(method, " failed"),
284
- payload: _objectSpread(_objectSpread({
285
- method: method
286
- }, payload), {}, {
287
- error: this.serializeError(error)
288
- })
289
- });
290
- }
291
- }, {
292
- key: "addLog",
293
- value: function () {
294
- var _addLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
295
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
296
- while (1) switch (_context2.prev = _context2.next) {
297
- case 0:
298
- _context2.next = 2;
299
- return this.addVenueBookingLog(_objectSpread(_objectSpread({}, params), {}, {
300
- payload: _objectSpread({
301
- source: 'ui-bridge'
302
- }, params.payload || {})
303
- }));
304
- case 2:
305
- case "end":
306
- return _context2.stop();
307
- }
308
- }, _callee2, this);
309
- }));
310
- function addLog(_x2) {
311
- return _addLog.apply(this, arguments);
312
- }
313
- return addLog;
314
- }()
315
- }, {
316
- key: "normalizeCustomerId",
317
- value: function normalizeCustomerId(value) {
318
- var customerId = Number(value);
319
- if (!Number.isFinite(customerId) || customerId <= 0) return null;
320
- return customerId;
321
- }
322
- }, {
323
- key: "resolveCustomerIdFromLoginPayload",
324
- value: function resolveCustomerIdFromLoginPayload(payload) {
325
- var _payload$user, _payload$user2, _payload$user3, _payload$user4, _payload$account, _payload$account2, _payload$account3, _payload$_origin;
326
- var candidates = [payload === null || payload === void 0 ? void 0 : payload.customerId, payload === null || payload === void 0 ? void 0 : payload.customer_id, payload === null || payload === void 0 ? void 0 : payload.id, payload === null || payload === void 0 || (_payload$user = payload.user) === null || _payload$user === void 0 ? void 0 : _payload$user.customerId, payload === null || payload === void 0 || (_payload$user2 = payload.user) === null || _payload$user2 === void 0 ? void 0 : _payload$user2.customer_id, payload === null || payload === void 0 || (_payload$user3 = payload.user) === null || _payload$user3 === void 0 ? void 0 : _payload$user3.id, payload === null || payload === void 0 || (_payload$user4 = payload.user) === null || _payload$user4 === void 0 || (_payload$user4 = _payload$user4._origin) === null || _payload$user4 === void 0 ? void 0 : _payload$user4.customer_id, payload === null || payload === void 0 || (_payload$account = payload.account) === null || _payload$account === void 0 ? void 0 : _payload$account.customerId, payload === null || payload === void 0 || (_payload$account2 = payload.account) === null || _payload$account2 === void 0 ? void 0 : _payload$account2.customer_id, payload === null || payload === void 0 || (_payload$account3 = payload.account) === null || _payload$account3 === void 0 ? void 0 : _payload$account3.id, payload === null || payload === void 0 || (_payload$_origin = payload._origin) === null || _payload$_origin === void 0 ? void 0 : _payload$_origin.customer_id];
327
- for (var _i2 = 0, _candidates2 = candidates; _i2 < _candidates2.length; _i2++) {
328
- var candidate = _candidates2[_i2];
329
- var customerId = this.normalizeCustomerId(candidate);
330
- if (customerId) return customerId;
331
- }
332
- return null;
333
- }
334
- }, {
335
- key: "clearLoginEffectListeners",
336
- value: function clearLoginEffectListeners() {
337
- var _iterator = _createForOfIteratorHelper(this.loginEffectDisposers),
338
- _step;
339
- try {
340
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
341
- var dispose = _step.value;
342
- dispose();
343
- }
344
- } catch (err) {
345
- _iterator.e(err);
346
- } finally {
347
- _iterator.f();
348
- }
349
- this.loginEffectDisposers = [];
350
- }
351
- }, {
352
- key: "registerLoginEffect",
353
- value: function registerLoginEffect(event, callback) {
354
- var _this$core;
355
- var effects = (_this$core = this.core) === null || _this$core === void 0 ? void 0 : _this$core.effects;
356
- if (!(effects !== null && effects !== void 0 && effects.on)) return;
357
- effects.on(event, callback);
358
- this.loginEffectDisposers.push(function () {
359
- if (typeof effects.off === 'function') {
360
- effects.off(event, callback);
361
- }
362
- });
363
- }
364
- }, {
365
- key: "registerCustomerLoginListeners",
366
- value: function registerCustomerLoginListeners() {
367
- var _this2 = this;
368
- this.clearLoginEffectListeners();
369
- var createHandleLogin = function createHandleLogin() {
370
- return /*#__PURE__*/function () {
371
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(payload) {
372
- var customerId;
373
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
374
- while (1) switch (_context3.prev = _context3.next) {
375
- case 0:
376
- customerId = _this2.resolveCustomerIdFromLoginPayload(payload);
377
- _this2.logPricingDiagnostics('[VenueBooking] customer login event received', {
378
- customerId: customerId,
379
- hasLoadAllProductsInFlight: !!_this2.loadAllProductsInFlight,
380
- productsLoaded: _this2.productsLoaded,
381
- smartPricingProductCatalogCount: _this2.smartPricingProductCatalog.length
382
- });
383
- if (customerId) {
384
- _context3.next = 5;
385
- break;
386
- }
387
- _this2.logPricingDiagnostics('[VenueBooking] customer login event skipped customerId not found in login payload');
388
- return _context3.abrupt("return");
389
- case 5:
390
- _context3.next = 7;
391
- return _this2.refreshOrderMarketingAfterLogin({
392
- customerId: customerId
393
- });
394
- case 7:
395
- case "end":
396
- return _context3.stop();
397
- }
398
- }, _callee3);
399
- }));
400
- return function (_x3) {
401
- return _ref.apply(this, arguments);
402
- };
403
- }();
404
- };
405
- this.registerLoginEffect(VenueBookingImpl.PISELL1_LOGIN_SUCCESS, createHandleLogin());
406
- this.registerLoginEffect(AccountHooks.OnLogin, createHandleLogin());
407
- this.registerLoginEffect(RegisterAndLoginHooks.onLoginSuccess, createHandleLogin());
408
- }
409
- }, {
410
- key: "refreshOrderMarketingAfterLogin",
411
- value: function () {
412
- var _refreshOrderMarketingAfterLogin = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(params) {
413
- var _this3 = this;
414
- var refreshTask;
415
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
416
- while (1) switch (_context5.prev = _context5.next) {
417
- case 0:
418
- if (this.store.order) {
419
- _context5.next = 2;
420
- break;
421
- }
422
- throw new Error('order 模块未初始化');
423
- case 2:
424
- this.logPricingDiagnostics('[VenueBooking] refreshOrderMarketingAfterLogin entered', {
425
- customerId: params.customerId,
426
- hasCustomerLoginRefreshInFlight: !!this.customerLoginRefreshInFlight,
427
- customerLoginRefreshIdInFlight: this.customerLoginRefreshIdInFlight,
428
- hasLoadAllProductsInFlight: !!this.loadAllProductsInFlight,
429
- productsLoaded: this.productsLoaded,
430
- smartPricingProductCatalogCount: this.smartPricingProductCatalog.length,
431
- note: 'This login refresh recalculates the loaded catalog and does not call loadAllProducts'
432
- });
433
- if (!this.customerLoginRefreshInFlight) {
434
- _context5.next = 11;
435
- break;
436
- }
437
- if (!(this.customerLoginRefreshIdInFlight === params.customerId)) {
438
- _context5.next = 9;
439
- break;
440
- }
441
- this.logPricingDiagnostics('[VenueBooking] customer login refresh reused', {
442
- customerId: params.customerId,
443
- reason: 'same customer refresh is already in flight'
444
- });
445
- _context5.next = 8;
446
- return this.customerLoginRefreshInFlight;
447
- case 8:
448
- return _context5.abrupt("return");
449
- case 9:
450
- _context5.next = 11;
451
- return this.customerLoginRefreshInFlight;
452
- case 11:
453
- this.customerLoginRefreshIdInFlight = params.customerId;
454
- refreshTask = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
455
- var _this3$core, _this3$core$emit;
456
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
457
- while (1) switch (_context4.prev = _context4.next) {
458
- case 0:
459
- // 用户插件可能晚于登录 effect 更新;以已确认的登录 payload 作为本次及后续网格算价的身份来源。
460
- _this3.smartPricingCustomerId = params.customerId;
461
- _context4.next = 3;
462
- return _this3.store.order.loadDiscountConfig({
463
- customerId: params.customerId
464
- });
465
- case 3:
466
- _this3.clearSlotPriceMapCache();
467
- _this3.recalculateOrderPricesFromSmartPricing();
468
- // loadDiscountConfig 会按登录前的订单价格预计算一次券;智能价更新后必须用新的
469
- // source/main 价格字段重新套券,否则购物车行价与 Summary 会使用两套基数。
470
- _this3.store.order.applyDiscount();
471
- _this3.normalizeDiscountedOrderPrices(_this3.store.order.getDiscountList());
472
- _context4.next = 9;
473
- return _this3.store.order.recalculateSummary({
474
- createIfMissing: true
475
- });
476
- case 9:
477
- _this3.store.order.persistTempOrder();
478
- _context4.next = 12;
479
- return _this3.refreshItemRuleQuantityLimits();
480
- case 12:
481
- _context4.next = 14;
482
- return _this3.refreshCartValidationPassed();
483
- case 14:
484
- _context4.next = 16;
485
- return (_this3$core = _this3.core) === null || _this3$core === void 0 || (_this3$core = _this3$core.effects) === null || _this3$core === void 0 || (_this3$core$emit = _this3$core.emit) === null || _this3$core$emit === void 0 ? void 0 : _this3$core$emit.call(_this3$core, VenueBookingHooks.onSmartPricingUpdated, {
486
- customerId: params.customerId
487
- });
488
- case 16:
489
- case "end":
490
- return _context4.stop();
491
- }
492
- }, _callee4);
493
- }))();
494
- this.customerLoginRefreshInFlight = refreshTask;
495
- _context5.prev = 14;
496
- _context5.next = 17;
497
- return refreshTask;
498
- case 17:
499
- _context5.next = 22;
500
- break;
501
- case 19:
502
- _context5.prev = 19;
503
- _context5.t0 = _context5["catch"](14);
504
- throw _context5.t0;
505
- case 22:
506
- _context5.prev = 22;
507
- if (this.customerLoginRefreshInFlight === refreshTask) {
508
- this.customerLoginRefreshInFlight = null;
509
- this.customerLoginRefreshIdInFlight = null;
510
- }
511
- return _context5.finish(22);
512
- case 25:
513
- case "end":
514
- return _context5.stop();
515
- }
516
- }, _callee5, this, [[14, 19, 22, 25]]);
517
- }));
518
- function refreshOrderMarketingAfterLogin(_x4) {
519
- return _refreshOrderMarketingAfterLogin.apply(this, arguments);
520
- }
521
- return refreshOrderMarketingAfterLogin;
522
- }()
523
- }, {
524
- key: "initialize",
525
- value: function () {
526
- var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(core) {
527
- var _options$otherParams,
528
- _options$otherParams2,
529
- _this$otherParams,
530
- _this$otherParams2,
531
- _this$otherParams3,
532
- _this4 = this,
533
- _this$otherParams4,
534
- _this$otherParams5;
535
- var options,
536
- baseModules,
537
- venueProductsModule,
538
- addonProductsModule,
539
- dateModule,
540
- scheduleModule,
541
- quotationModule,
542
- openDataModule,
543
- _this$store$order2,
544
- _this$store$order3,
545
- _args6 = arguments;
546
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
547
- while (1) switch (_context6.prev = _context6.next) {
548
- case 0:
549
- options = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : {};
550
- this.logMethodStart('initialize');
551
- this.core = core;
552
- this.initializeOptions = options || {};
553
- this.store = _objectSpread(_objectSpread({}, this.store), options.store);
554
- this.smartPricingCustomerId = undefined;
555
- this.store.entryContext = ((_options$otherParams = options.otherParams) === null || _options$otherParams === void 0 ? void 0 : _options$otherParams.entryContext) || this.store.entryContext;
556
- this.store.status = 'initializing';
557
- this.store.error = null;
558
- this.store.rawResourceData = [];
559
- this.baseSlotConfig = _objectSpread(_objectSpread({}, DEFAULT_SLOT_CONFIG), ((_options$otherParams2 = options.otherParams) === null || _options$otherParams2 === void 0 ? void 0 : _options$otherParams2.slotConfig) || {});
560
- this.store.slotConfig = _objectSpread({}, this.baseSlotConfig);
561
- this.otherParams = options.otherParams || {};
562
- this.cacheId = (_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.cacheId;
563
- this.logPricingDiagnostics('[VenueBooking] initialize product loading state', {
564
- hasLoadAllProductsInFlight: !!this.loadAllProductsInFlight,
565
- productsLoaded: this.productsLoaded,
566
- smartPricingProductCatalogCount: this.smartPricingProductCatalog.length,
567
- note: 'initialize currently does not reset the product loading state'
568
- });
569
- this.itemRuleRuntimeConfig = ((_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 ? void 0 : _this$otherParams2.venueBookingItemRule) || ((_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3.itemRule) || {};
570
- this.itemRuleConfigs = [];
571
- this.itemRuleConfigsPromise = null;
572
- this.itemRulePrefillApplied = false;
573
- this.store.itemRuleQuantityLimits = [];
574
- this.store.cartValidation = {
575
- passed: null,
576
- failures: []
577
- };
578
- this.window = core.getPlugin('window');
579
- this.request = core.getPlugin('request');
580
- if (this.window) {
581
- _context6.next = 26;
582
- break;
583
- }
584
- this.logMethodError('initialize', 'window plugin missing');
585
- throw new Error('venueBooking解决方案需要 window 插件支持');
586
- case 26:
587
- if (this.request) {
588
- _context6.next = 29;
589
- break;
590
- }
591
- this.logMethodError('initialize', 'request plugin missing');
592
- throw new Error('venueBooking解决方案需要 request 插件支持');
593
- case 29:
594
- // 注册基础模块(order, salesSummary, products, logger)
595
- baseModules = ['scanOrderLogger', 'products', 'order', 'salesSummary'];
596
- baseModules.forEach(function (step) {
597
- var targetModule = createModule(step, _this4.name);
598
- if (targetModule) {
599
- var _this4$store$order, _this4$otherParams, _this4$otherParams2, _this4$otherParams3, _this4$otherParams4;
600
- _this4.store[step] = targetModule;
601
- var initialState = step === 'salesSummary' ? {
602
- summary: ((_this4$store$order = _this4.store.order) === null || _this4$store$order === void 0 || (_this4$store$order = _this4$store$order.getTempOrder()) === null || _this4$store$order === void 0 ? void 0 : _this4$store$order.summary) || createEmptySummary()
603
- } : {};
604
- var loggerProvider = ((_this4$otherParams = _this4.otherParams) === null || _this4$otherParams === void 0 ? void 0 : _this4$otherParams.loggerProvider) || 'feishu';
605
- var loggerConfig = ((_this4$otherParams2 = _this4.otherParams) === null || _this4$otherParams2 === void 0 ? void 0 : _this4$otherParams2.loggerConfig) || {
606
- feishu: {
607
- webhook: 'https://open.feishu.cn/open-apis/bot/v2/hook/8f069b14-9d39-4728-8f78-b56f393bfde8',
608
- errorHook: 'https://open.feishu.cn/open-apis/bot/v2/hook/bdefae5e-f233-4705-8688-946887d9543d'
609
- }
610
- };
611
- _this4.core.registerModule(targetModule, {
612
- initialState: initialState,
613
- otherParams: _objectSpread(_objectSpread({}, _this4.otherParams), {}, {
614
- fatherModule: _this4.name,
615
- openCache: (_this4$otherParams3 = _this4.otherParams) !== null && _this4$otherParams3 !== void 0 && _this4$otherParams3.cacheId ? true : false,
616
- cacheId: (_this4$otherParams4 = _this4.otherParams) === null || _this4$otherParams4 === void 0 ? void 0 : _this4$otherParams4.cacheId,
617
- salesSummaryModuleName: "".concat(_this4.name, "_salesSummary"),
618
- provider: loggerProvider,
619
- providerConfig: loggerConfig,
620
- context: _this4.getLoggerContext()
621
- })
622
- });
623
- } else {
624
- _this4.logMethodError('initialize', "module ".concat(step, " missing"));
625
- throw new Error("\u6A21\u5757 ".concat(step, " \u4E0D\u5B58\u5728"));
626
- }
627
- });
628
-
629
- // 注册场地商品列表模块
630
- venueProductsModule = new ProductList("".concat(this.name, "_venueProducts"));
631
- this.store.venueProducts = venueProductsModule;
632
- this.core.registerModule(venueProductsModule, {
633
- otherParams: _objectSpread(_objectSpread({}, this.otherParams), {}, {
634
- fatherModule: this.name
635
- })
636
- });
637
-
638
- // 注册附加商品列表模块
639
- addonProductsModule = new ProductList("".concat(this.name, "_addonProducts"));
640
- this.store.addonProducts = addonProductsModule;
641
- this.core.registerModule(addonProductsModule, {
642
- otherParams: _objectSpread(_objectSpread({}, this.otherParams), {}, {
643
- fatherModule: this.name
644
- })
645
- });
646
-
647
- // 注册日期模块
648
- dateModule = new DateModule("".concat(this.name, "_date"));
649
- this.store.date = dateModule;
650
- this.core.registerModule(dateModule, {
651
- otherParams: _objectSpread(_objectSpread({}, this.otherParams), {}, {
652
- fatherModule: this.name,
653
- cacheId: this.cacheId
654
- })
655
- });
656
-
657
- // 注册日程模块
658
- scheduleModule = new ScheduleModule("".concat(this.name, "_schedule"));
659
- this.store.schedule = scheduleModule;
660
- this.core.registerModule(scheduleModule, {
661
- otherParams: _objectSpread(_objectSpread({}, this.otherParams), {}, {
662
- fatherModule: this.name
663
- })
664
- });
665
-
666
- // 注册报价单模块
667
- quotationModule = new QuotationModule("".concat(this.name, "_quotation"));
668
- this.store.quotation = quotationModule;
669
- this.core.registerModule(quotationModule, {
670
- otherParams: _objectSpread(_objectSpread({}, this.otherParams), {}, {
671
- fatherModule: this.name
672
- })
673
- });
674
-
675
- // 注册 OpenData 配置模块
676
- openDataModule = new OpenDataModule("".concat(this.name, "_openData"));
677
- this.store.openData = openDataModule;
678
- this.core.registerModule(openDataModule, {
679
- otherParams: _objectSpread(_objectSpread({}, this.otherParams), {}, {
680
- fatherModule: this.name,
681
- openCache: !!((_this$otherParams4 = this.otherParams) !== null && _this$otherParams4 !== void 0 && _this$otherParams4.cacheId),
682
- cacheId: (_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.cacheId
683
- })
684
- });
685
- if (this.store.scanOrderLogger) {
686
- this.store.scanOrderLogger.setContext(this.getLoggerContext());
687
- }
688
- this.registerCustomerLoginListeners();
689
- console.log('[VenueBooking] 初始化开始');
690
- _context6.prev = 52;
691
- _context6.next = 55;
692
- return (_this$store$order2 = this.store.order) === null || _this$store$order2 === void 0 ? void 0 : _this$store$order2.recalculateSummary({
693
- createIfMissing: false
694
- });
695
- case 55:
696
- (_this$store$order3 = this.store.order) === null || _this$store$order3 === void 0 || _this$store$order3.persistTempOrder();
697
- _context6.next = 58;
698
- return this.loadRuntimeConfigs();
699
- case 58:
700
- if (!this.store.schedule) {
701
- _context6.next = 61;
702
- break;
703
- }
704
- _context6.next = 61;
705
- return this.store.schedule.loadAllSchedule();
706
- case 61:
707
- _context6.next = 63;
708
- return this.refreshItemRuleQuantityLimits();
709
- case 63:
710
- this.store.status = 'ready';
711
- console.log('[VenueBooking] 初始化完成');
712
- _context6.next = 67;
713
- return this.core.effects.emit(VenueBookingHooks.onInited, {
714
- status: this.store.status
715
- });
716
- case 67:
717
- this.logMethodSuccess('initialize', {
718
- status: this.store.status
719
- });
720
- _context6.next = 77;
721
- break;
722
- case 70:
723
- _context6.prev = 70;
724
- _context6.t0 = _context6["catch"](52);
725
- this.store.status = 'error';
726
- this.store.error = _context6.t0 instanceof Error ? _context6.t0.message : '初始化失败';
727
- console.error('[VenueBooking] 初始化失败', _context6.t0);
728
- this.logMethodError('initialize', _context6.t0, {
729
- status: this.store.status
730
- });
731
- throw _context6.t0;
732
- case 77:
733
- case "end":
734
- return _context6.stop();
735
- }
736
- }, _callee6, this, [[52, 70]]);
737
- }));
738
- function initialize(_x5) {
739
- return _initialize.apply(this, arguments);
740
- }
741
- return initialize;
742
- }()
743
- }, {
744
- key: "destroy",
745
- value: function () {
746
- var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
747
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
748
- while (1) switch (_context7.prev = _context7.next) {
749
- case 0:
750
- this.logMethodStart('destroy');
751
- this.clearLoginEffectListeners();
752
- _context7.next = 4;
753
- return this.core.effects.emit(VenueBookingHooks.onDestroy, {});
754
- case 4:
755
- console.log('[VenueBooking] 已销毁');
756
- this.logMethodSuccess('destroy');
757
- case 6:
758
- case "end":
759
- return _context7.stop();
760
- }
761
- }, _callee7, this);
762
- }));
763
- function destroy() {
764
- return _destroy.apply(this, arguments);
765
- }
766
- return destroy;
767
- }()
768
- }, {
769
- key: "retryInit",
770
- value: function () {
771
- var _retryInit = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
772
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
773
- while (1) switch (_context8.prev = _context8.next) {
774
- case 0:
775
- this.logMethodStart('retryInit');
776
- console.log('[VenueBooking] retryInit 调用');
777
- _context8.next = 4;
778
- return this.core.effects.emit(VenueBookingHooks.onRetryInit, {});
779
- case 4:
780
- _context8.prev = 4;
781
- _context8.next = 7;
782
- return this.initialize(this.core, this.initializeOptions);
783
- case 7:
784
- this.logMethodSuccess('retryInit');
785
- _context8.next = 14;
786
- break;
787
- case 10:
788
- _context8.prev = 10;
789
- _context8.t0 = _context8["catch"](4);
790
- this.logMethodError('retryInit', _context8.t0);
791
- throw _context8.t0;
792
- case 14:
793
- case "end":
794
- return _context8.stop();
795
- }
796
- }, _callee8, this, [[4, 10]]);
797
- }));
798
- function retryInit() {
799
- return _retryInit.apply(this, arguments);
800
- }
801
- return retryInit;
802
- }()
803
- }, {
804
- key: "refresh",
805
- value: function () {
806
- var _refresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
807
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
808
- while (1) switch (_context9.prev = _context9.next) {
809
- case 0:
810
- this.logMethodStart('refresh');
811
- console.log('[VenueBooking] refresh 调用');
812
- _context9.prev = 2;
813
- this.store.status = 'initializing';
814
- _context9.next = 6;
815
- return this.loadRuntimeConfigs();
816
- case 6:
817
- _context9.next = 8;
818
- return this.refreshItemRuleQuantityLimits();
819
- case 8:
820
- this.store.status = 'ready';
821
- _context9.next = 11;
822
- return this.core.effects.emit(VenueBookingHooks.onRefresh, {
823
- status: this.store.status
824
- });
825
- case 11:
826
- this.logMethodSuccess('refresh', {
827
- status: this.store.status
828
- });
829
- _context9.next = 18;
830
- break;
831
- case 14:
832
- _context9.prev = 14;
833
- _context9.t0 = _context9["catch"](2);
834
- this.logMethodError('refresh', _context9.t0);
835
- throw _context9.t0;
836
- case 18:
837
- case "end":
838
- return _context9.stop();
839
- }
840
- }, _callee9, this, [[2, 14]]);
841
- }));
842
- function refresh() {
843
- return _refresh.apply(this, arguments);
844
- }
845
- return refresh;
846
- }() // ─── 状态查询 ───
847
- }, {
848
- key: "getStatus",
849
- value: function getStatus() {
850
- return this.store.status;
851
- }
852
- }, {
853
- key: "getEntryContext",
854
- value: function getEntryContext() {
855
- return this.store.entryContext;
856
- }
857
- }, {
858
- key: "getItemRuleQuantityLimits",
859
- value: function getItemRuleQuantityLimits() {
860
- return this.store.itemRuleQuantityLimits || [];
861
- }
862
- }, {
863
- key: "getCartValidationPassed",
864
- value: function getCartValidationPassed() {
865
- var _this$store$cartValid, _this$store$cartValid2;
866
- return (_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;
867
- }
868
- }, {
869
- key: "getCartValidation",
870
- value: function getCartValidation() {
871
- return this.store.cartValidation || {
872
- passed: null,
873
- failures: []
874
- };
875
- }
876
-
877
- /** 清除 slot 价格分段缓存(商品重载 / 登录后 customerId 变化时调用) */
878
- }, {
879
- key: "clearSlotPriceMapCache",
880
- value: function clearSlotPriceMapCache() {
881
- this.slotPriceMapCache.clear();
882
- }
883
-
884
- /** 读取当前登录 customerId */
885
- }, {
886
- key: "resolveCustomerIdForSmartPricing",
887
- value: function resolveCustomerIdForSmartPricing() {
888
- if (this.smartPricingCustomerId) return this.smartPricingCustomerId;
889
- try {
890
- var _this$core2, _userPlugin$get;
891
- var userPlugin = (_this$core2 = this.core) === null || _this$core2 === void 0 ? void 0 : _this$core2.getPlugin('user');
892
- var customerId = Number(userPlugin === null || userPlugin === void 0 || (_userPlugin$get = userPlugin.get) === null || _userPlugin$get === void 0 || (_userPlugin$get = _userPlugin$get.call(userPlugin)) === null || _userPlugin$get === void 0 ? void 0 : _userPlugin$get.id);
893
- return Number.isFinite(customerId) && customerId > 0 ? customerId : undefined;
894
- } catch (_unused2) {
895
- return undefined;
896
- }
897
- }
898
- }, {
899
- key: "resolveAvailableWalletIdsForSmartPricing",
900
- value: function resolveAvailableWalletIdsForSmartPricing() {
901
- var _this$store$order4, _this$store$order4$ge, _this$otherParams6, _this$otherParams7, _this$otherParams8, _this$otherParams9;
902
- var orderWalletIds = (_this$store$order4 = this.store.order) === null || _this$store$order4 === void 0 || (_this$store$order4$ge = _this$store$order4.getAvailableWalletIds) === null || _this$store$order4$ge === void 0 ? void 0 : _this$store$order4$ge.call(_this$store$order4);
903
- var fallbackWalletIds = ((_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.available_wallet_ids) || ((_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.availableWalletIds) || ((_this$otherParams8 = this.otherParams) === null || _this$otherParams8 === void 0 || (_this$otherParams8 = _this$otherParams8.strategy_context) === null || _this$otherParams8 === void 0 ? void 0 : _this$otherParams8.available_wallet_ids) || ((_this$otherParams9 = this.otherParams) === null || _this$otherParams9 === void 0 || (_this$otherParams9 = _this$otherParams9.strategy_context) === null || _this$otherParams9 === void 0 ? void 0 : _this$otherParams9.availableWalletIds);
904
- var source = Array.isArray(orderWalletIds) && orderWalletIds.length ? orderWalletIds : fallbackWalletIds;
905
- if (!Array.isArray(source)) return [];
906
- var ids = source.map(function (item) {
907
- return Number(item);
908
- }).filter(function (item) {
909
- return Number.isFinite(item) && item > 0;
910
- });
911
- return Array.from(new Set(ids));
912
- }
913
-
914
- /** 读取 schedule 全量列表,供智能定价 schedule_match 使用 */
915
- }, {
916
- key: "getScheduleListForSmartPricing",
917
- value: function getScheduleListForSmartPricing() {
918
- var _store;
919
- var scheduleModule = this.store.schedule;
920
- var list = scheduleModule === null || scheduleModule === void 0 || (_store = scheduleModule.store) === null || _store === void 0 ? void 0 : _store.scheduleList;
921
- return Array.isArray(list) ? list : [];
922
- }
923
-
924
- /** 构建智能定价上下文,对齐 OS Server buildProductFormatterContext */
925
- }, {
926
- key: "buildSmartPricingContext",
927
- value: function buildSmartPricingContext(customerId) {
928
- var _this$core3,
929
- _this$otherParams10,
930
- _this$otherParams11,
931
- _this$otherParams12,
932
- _this$otherParams13,
933
- _this$otherParams14,
934
- _this$otherParams15,
935
- _this$otherParams16,
936
- _this5 = this;
937
- var evaluator = (_this$core3 = this.core) === null || _this$core3 === void 0 || (_this$core3 = _this$core3.context) === null || _this$core3 === void 0 ? void 0 : _this$core3.dataVariantEvaluator;
938
- return _objectSpread({
939
- evaluator: evaluator,
940
- scheduleList: this.getScheduleListForSmartPricing(),
941
- menuList: ((_this$otherParams10 = this.otherParams) === null || _this$otherParams10 === void 0 ? void 0 : _this$otherParams10.menuList) || ((_this$otherParams11 = this.otherParams) === null || _this$otherParams11 === void 0 || (_this$otherParams11 = _this$otherParams11.openData) === null || _this$otherParams11 === void 0 ? void 0 : _this$otherParams11.menuList) || [],
942
- customerId: customerId !== null && customerId !== void 0 ? customerId : this.resolveCustomerIdForSmartPricing(),
943
- availableWalletIds: this.resolveAvailableWalletIdsForSmartPricing(),
944
- channel: (_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12.channel,
945
- businessCode: (_this$otherParams13 = this.otherParams) === null || _this$otherParams13 === void 0 ? void 0 : _this$otherParams13.businessCode,
946
- orderType: ((_this$otherParams14 = this.otherParams) === null || _this$otherParams14 === void 0 ? void 0 : _this$otherParams14.orderType) || ((_this$otherParams15 = this.otherParams) === null || _this$otherParams15 === void 0 ? void 0 : _this$otherParams15.type),
947
- strategy_context: (_this$otherParams16 = this.otherParams) === null || _this$otherParams16 === void 0 ? void 0 : _this$otherParams16.strategy_context
948
- }, this.isPricingDiagnosticsEnabled() ? {
949
- debugLog: function debugLog(title) {
950
- var payload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
951
- return _this5.logPricingDiagnostics(title, payload);
952
- }
953
- } : {});
954
- }
955
-
956
- /** venue + addon 全量商品,供智能定价评估 */
957
- }, {
958
- key: "getAllProductsForSmartPricing",
959
- value: function getAllProductsForSmartPricing() {
960
- if (this.smartPricingProductCatalog.length) {
961
- return this.smartPricingProductCatalog;
962
- }
963
- var venueList = this.getVenueProducts();
964
- var addonList = this.getAddonProductsList();
965
- return [].concat(_toConsumableArray(venueList), _toConsumableArray(addonList));
966
- }
967
- }, {
968
- key: "getSlotPriceMapCacheKey",
969
- value: function getSlotPriceMapCacheKey(date, context) {
970
- var _context$customerId, _context$channel, _context$businessCode;
971
- return [date, (_context$customerId = context.customerId) !== null && _context$customerId !== void 0 ? _context$customerId : '', (context.availableWalletIds || []).join(','), (_context$channel = context.channel) !== null && _context$channel !== void 0 ? _context$channel : '', (_context$businessCode = context.businessCode) !== null && _context$businessCode !== void 0 ? _context$businessCode : ''].join('|');
972
- }
973
-
974
- /**
975
- * 按 schedule 分段构建 slot 价格 Map,带实例级缓存。
976
- */
977
- }, {
978
- key: "buildSlotPriceMapForDate",
979
- value: function buildSlotPriceMapForDate(date, config, productIds) {
980
- var context = this.buildSmartPricingContext();
981
- var cacheKey = this.getSlotPriceMapCacheKey(date, context);
982
- var cached = this.slotPriceMapCache.get(cacheKey);
983
- if (cached) return cached;
984
- var timeLabels = generateTimeLabels(config);
985
- var slotPriceMap = buildSlotPriceMapByScheduleSegments({
986
- products: this.getAllProductsForSmartPricing(),
987
- productIds: productIds,
988
- date: date,
989
- timeLabels: timeLabels,
990
- config: config,
991
- context: context
992
- });
993
- this.slotPriceMapCache.set(cacheKey, slotPriceMap);
994
- return slotPriceMap;
995
- }
996
-
997
- // ─── 场地商品 & 附加商品 ───
998
- }, {
999
- key: "loadAllProducts",
1000
- value: function () {
1001
- var _loadAllProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
1002
- var _this6 = this;
1003
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1004
- while (1) switch (_context10.prev = _context10.next) {
1005
- case 0:
1006
- this.logPricingDiagnostics('[VenueBooking] loadAllProducts called', {
1007
- hasLoadAllProductsInFlight: !!this.loadAllProductsInFlight,
1008
- productsLoaded: this.productsLoaded,
1009
- smartPricingCustomerId: this.smartPricingCustomerId,
1010
- smartPricingProductCatalogCount: this.smartPricingProductCatalog.length,
1011
- venueProducts: !this.store.venueProducts,
1012
- addonProducts: !this.store.addonProducts
1013
- });
1014
- if (!this.loadAllProductsInFlight) {
1015
- _context10.next = 4;
1016
- break;
1017
- }
1018
- this.logPricingDiagnostics('[VenueBooking] loadAllProducts request skipped', {
1019
- reason: 'reusing existing loadAllProductsInFlight promise',
1020
- productsLoaded: this.productsLoaded
1021
- });
1022
- return _context10.abrupt("return", this.loadAllProductsInFlight);
1023
- case 4:
1024
- this.logPricingDiagnostics('[VenueBooking] loadAllProducts request starting', {
1025
- productsLoaded: this.productsLoaded,
1026
- smartPricingCustomerId: this.smartPricingCustomerId
1027
- });
1028
- this.loadAllProductsInFlight = this._doLoadAllProducts().finally(function () {
1029
- _this6.logPricingDiagnostics('[VenueBooking] loadAllProducts request settled', {
1030
- productsLoaded: _this6.productsLoaded,
1031
- smartPricingProductCatalogCount: _this6.smartPricingProductCatalog.length
1032
- });
1033
- _this6.loadAllProductsInFlight = null;
1034
- });
1035
- return _context10.abrupt("return", this.loadAllProductsInFlight);
1036
- case 7:
1037
- case "end":
1038
- return _context10.stop();
1039
- }
1040
- }, _callee10, this);
1041
- }));
1042
- function loadAllProducts() {
1043
- return _loadAllProducts.apply(this, arguments);
1044
- }
1045
- return loadAllProducts;
1046
- }()
1047
- }, {
1048
- key: "_doLoadAllProducts",
1049
- value: function () {
1050
- var _doLoadAllProducts2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
1051
- var _this$otherParams17, _this$store$venueProd, associatedMenus, menuListIds, allProducts, rawList, list, smartPricingContext, venueList, addonList, venueStore;
1052
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1053
- while (1) switch (_context11.prev = _context11.next) {
1054
- case 0:
1055
- this.logMethodStart('loadAllProducts');
1056
- _context11.prev = 1;
1057
- if (this.store.venueProducts) {
1058
- _context11.next = 4;
1059
- break;
1060
- }
1061
- throw new Error('venueProducts 模块未初始化');
1062
- case 4:
1063
- if (this.store.addonProducts) {
1064
- _context11.next = 6;
1065
- break;
1066
- }
1067
- throw new Error('addonProducts 模块未初始化');
1068
- case 6:
1069
- _context11.next = 8;
1070
- return this.loadOpenDataConfig();
1071
- case 8:
1072
- associatedMenus = ((_this$otherParams17 = this.otherParams) === null || _this$otherParams17 === void 0 || (_this$otherParams17 = _this$otherParams17.openData) === null || _this$otherParams17 === void 0 ? void 0 : _this$otherParams17['menu.associated_menus']) || [];
1073
- if (associatedMenus.length) {
1074
- _context11.next = 12;
1075
- break;
1076
- }
1077
- this.logMethodError('loadAllProducts', new Error('未获取到餐牌配置(menu.associated_menus),请检查 OpenData 配置'));
1078
- throw new Error('未获取到餐牌配置(menu.associated_menus),请检查 OpenData 配置');
1079
- case 12:
1080
- menuListIds = associatedMenus.map(function (n) {
1081
- return Number(n.value);
1082
- });
1083
- _context11.next = 15;
1084
- return this.store.venueProducts.loadProducts({
1085
- menu_list_ids: menuListIds,
1086
- cacheId: this.cacheId,
1087
- schedule_date: dayjs().format('YYYY-MM-DD'),
1088
- schedule_datetime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
1089
- with_extra: ['dataVariants']
1090
- });
1091
- case 15:
1092
- allProducts = _context11.sent;
1093
- rawList = Array.isArray(allProducts) ? allProducts : [];
1094
- list = rawList;
1095
- this.smartPricingProductCatalog = rawList.slice();
1096
- smartPricingContext = this.buildSmartPricingContext();
1097
- list = formatProductsWithDataVariant(list, smartPricingContext, dayjs().format('YYYY-MM-DD HH:mm:ss'));
1098
-
1099
- // 增加日志排查智能定价
1100
- if (this.isPricingDiagnosticsEnabled()) {
1101
- this.logPricingDiagnostics('[VenueBooking] loadAllProducts smart pricing context', {
1102
- smartPricingContext: smartPricingContext,
1103
- rawList: rawList,
1104
- list: list,
1105
- otherParams: this.otherParams,
1106
- availableWalletIds: this.getAvailableWalletIdsForDiagnostics()
1107
- });
1108
- }
1109
- this.clearSlotPriceMapCache();
1110
- venueList = list.filter(function (p) {
1111
- return p.duration != null;
1112
- });
1113
- addonList = list.filter(function (p) {
1114
- return p.duration == null;
1115
- });
1116
- venueStore = (_this$store$venueProd = this.store.venueProducts) === null || _this$store$venueProd === void 0 ? void 0 : _this$store$venueProd.store;
1117
- if (venueStore) {
1118
- venueStore.list = venueList.slice().sort(function (a, b) {
1119
- return Number(b.sort) - Number(a.sort);
1120
- });
1121
- }
1122
- this.store.addonProducts.addProduct(addonList);
1123
- this.resourceProductMap = buildResourceProductMap(venueList);
1124
- this.productsLoaded = true;
1125
- this.logMethodSuccess('loadAllProducts', {
1126
- total: list.length,
1127
- venueCount: venueList.length,
1128
- addonCount: addonList.length,
1129
- resourceCount: this.resourceProductMap.size
1130
- });
1131
- return _context11.abrupt("return", {
1132
- venueProducts: venueList,
1133
- addonProducts: addonList
1134
- });
1135
- case 34:
1136
- _context11.prev = 34;
1137
- _context11.t0 = _context11["catch"](1);
1138
- this.logMethodError('loadAllProducts', _context11.t0);
1139
- throw _context11.t0;
1140
- case 38:
1141
- case "end":
1142
- return _context11.stop();
1143
- }
1144
- }, _callee11, this, [[1, 34]]);
1145
- }));
1146
- function _doLoadAllProducts() {
1147
- return _doLoadAllProducts2.apply(this, arguments);
1148
- }
1149
- return _doLoadAllProducts;
1150
- }()
1151
- }, {
1152
- key: "loadVenueProducts",
1153
- value: function () {
1154
- var _loadVenueProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
1155
- var result;
1156
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1157
- while (1) switch (_context12.prev = _context12.next) {
1158
- case 0:
1159
- this.logPricingDiagnostics('[VenueBooking] loadVenueProducts called', {
1160
- hasLoadAllProductsInFlight: !!this.loadAllProductsInFlight,
1161
- productsLoaded: this.productsLoaded
1162
- });
1163
- _context12.next = 3;
1164
- return this.loadAllProducts();
1165
- case 3:
1166
- result = _context12.sent;
1167
- return _context12.abrupt("return", result.venueProducts);
1168
- case 5:
1169
- case "end":
1170
- return _context12.stop();
1171
- }
1172
- }, _callee12, this);
1173
- }));
1174
- function loadVenueProducts() {
1175
- return _loadVenueProducts.apply(this, arguments);
1176
- }
1177
- return loadVenueProducts;
1178
- }()
1179
- }, {
1180
- key: "loadAddonProducts",
1181
- value: function () {
1182
- var _loadAddonProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
1183
- var result;
1184
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1185
- while (1) switch (_context13.prev = _context13.next) {
1186
- case 0:
1187
- _context13.next = 2;
1188
- return this.loadAllProducts();
1189
- case 2:
1190
- result = _context13.sent;
1191
- return _context13.abrupt("return", result.addonProducts);
1192
- case 4:
1193
- case "end":
1194
- return _context13.stop();
1195
- }
1196
- }, _callee13, this);
1197
- }));
1198
- function loadAddonProducts() {
1199
- return _loadAddonProducts.apply(this, arguments);
1200
- }
1201
- return loadAddonProducts;
1202
- }()
1203
- }, {
1204
- key: "getVenueProducts",
1205
- value: function getVenueProducts() {
1206
- var _this$store$venueProd2;
1207
- return ((_this$store$venueProd2 = this.store.venueProducts) === null || _this$store$venueProd2 === void 0 || (_this$store$venueProd2 = _this$store$venueProd2.store) === null || _this$store$venueProd2 === void 0 ? void 0 : _this$store$venueProd2.list) || [];
1208
- }
1209
- }, {
1210
- key: "getAddonProductsList",
1211
- value: function getAddonProductsList() {
1212
- var _this$store$addonProd;
1213
- return ((_this$store$addonProd = this.store.addonProducts) === null || _this$store$addonProd === void 0 || (_this$store$addonProd = _this$store$addonProd.store) === null || _this$store$addonProd === void 0 ? void 0 : _this$store$addonProd.list) || [];
1214
- }
1215
-
1216
- // ─── 报价单 ───
1217
- }, {
1218
- key: "loadQuotations",
1219
- value: function () {
1220
- var _loadQuotations = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(params) {
1221
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1222
- while (1) switch (_context14.prev = _context14.next) {
1223
- case 0:
1224
- this.logMethodStart('loadQuotations');
1225
- _context14.prev = 1;
1226
- if (this.store.quotation) {
1227
- _context14.next = 4;
1228
- break;
1229
- }
1230
- throw new Error('quotation 模块未初始化');
1231
- case 4:
1232
- _context14.next = 6;
1233
- return this.store.quotation.loadQuotations(params);
1234
- case 6:
1235
- this.logMethodSuccess('loadQuotations', {
1236
- count: this.store.quotation.getQuotationList().length
1237
- });
1238
- _context14.next = 13;
1239
- break;
1240
- case 9:
1241
- _context14.prev = 9;
1242
- _context14.t0 = _context14["catch"](1);
1243
- this.logMethodError('loadQuotations', _context14.t0);
1244
- throw _context14.t0;
1245
- case 13:
1246
- case "end":
1247
- return _context14.stop();
1248
- }
1249
- }, _callee14, this, [[1, 9]]);
1250
- }));
1251
- function loadQuotations(_x6) {
1252
- return _loadQuotations.apply(this, arguments);
1253
- }
1254
- return loadQuotations;
1255
- }() // ─── 资源可用性 ───
1256
- }, {
1257
- key: "fetchResourceAvailability",
1258
- value: function () {
1259
- var _fetchResourceAvailability = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
1260
- var venueProducts, resourceIds, config, crossDay, effectiveEndDate, res, rawData, _iterator2, _step2, item, _i3, _rawData, _item, mappings, _iterator3, _step3, mapping;
1261
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1262
- while (1) switch (_context15.prev = _context15.next) {
1263
- case 0:
1264
- this.logMethodStart('fetchResourceAvailability', params);
1265
- _context15.prev = 1;
1266
- venueProducts = this.getVenueProducts();
1267
- if (venueProducts.length) {
1268
- _context15.next = 7;
1269
- break;
1270
- }
1271
- this.store.rawResourceData = [];
1272
- this.logMethodSuccess('fetchResourceAvailability', {
1273
- resourceCount: 0
1274
- });
1275
- return _context15.abrupt("return");
1276
- case 7:
1277
- resourceIds = extractResourceIds(venueProducts);
1278
- if (resourceIds.length) {
1279
- _context15.next = 12;
1280
- break;
1281
- }
1282
- this.store.rawResourceData = [];
1283
- this.logMethodSuccess('fetchResourceAvailability', {
1284
- resourceIds: []
1285
- });
1286
- return _context15.abrupt("return");
1287
- case 12:
1288
- // 跨天营业时,endDate 扩展一天以覆盖次日凌晨时段
1289
- config = this.store.slotConfig;
1290
- crossDay = isBusinessHoursCrossDay(config);
1291
- effectiveEndDate = crossDay ? dayjs(params.endDate).add(1, 'day').format('YYYY-MM-DD') : params.endDate;
1292
- if (this.store.date) {
1293
- _context15.next = 17;
1294
- break;
1295
- }
1296
- throw new Error('date 模块未初始化');
1297
- case 17:
1298
- _context15.next = 19;
1299
- return this.store.date.fetchResourceDates({
1300
- query: {
1301
- start_date: params.startDate,
1302
- end_date: effectiveEndDate,
1303
- resource_ids: resourceIds
1304
- },
1305
- useCache: false
1306
- });
1307
- case 19:
1308
- res = _context15.sent;
1309
- rawData = [];
1310
- if (res !== null && res !== void 0 && res.data && Array.isArray(res.data)) {
1311
- _iterator2 = _createForOfIteratorHelper(res.data);
1312
- try {
1313
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1314
- item = _step2.value;
1315
- rawData.push(_objectSpread({
1316
- resourceId: item.id,
1317
- formId: item.form_id,
1318
- times: Array.isArray(item.times) ? item.times : []
1319
- }, item));
1320
- }
1321
- } catch (err) {
1322
- _iterator2.e(err);
1323
- } finally {
1324
- _iterator2.f();
1325
- }
1326
- }
1327
- this.store.rawResourceData = rawData;
1328
- _i3 = 0, _rawData = rawData;
1329
- case 24:
1330
- if (!(_i3 < _rawData.length)) {
1331
- _context15.next = 34;
1332
- break;
1333
- }
1334
- _item = _rawData[_i3];
1335
- mappings = this.resourceProductMap.get(_item.resourceId);
1336
- if (mappings) {
1337
- _context15.next = 29;
1338
- break;
1339
- }
1340
- return _context15.abrupt("continue", 31);
1341
- case 29:
1342
- _iterator3 = _createForOfIteratorHelper(mappings);
1343
- try {
1344
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1345
- mapping = _step3.value;
1346
- if (_item.main_field) mapping.resourceName = _item.main_field;
1347
- if (_item.resource_form_id) mapping.formId = _item.resource_form_id;
1348
- }
1349
- } catch (err) {
1350
- _iterator3.e(err);
1351
- } finally {
1352
- _iterator3.f();
1353
- }
1354
- case 31:
1355
- _i3++;
1356
- _context15.next = 24;
1357
- break;
1358
- case 34:
1359
- this.logMethodSuccess('fetchResourceAvailability', {
1360
- resourceCount: rawData.length,
1361
- totalTimes: rawData.reduce(function (sum, r) {
1362
- return sum + r.times.length;
1363
- }, 0)
1364
- });
1365
- _context15.next = 42;
1366
- break;
1367
- case 37:
1368
- _context15.prev = 37;
1369
- _context15.t0 = _context15["catch"](1);
1370
- this.store.rawResourceData = [];
1371
- this.logMethodError('fetchResourceAvailability', _context15.t0);
1372
- throw _context15.t0;
1373
- case 42:
1374
- case "end":
1375
- return _context15.stop();
1376
- }
1377
- }, _callee15, this, [[1, 37]]);
1378
- }));
1379
- function fetchResourceAvailability(_x7) {
1380
- return _fetchResourceAvailability.apply(this, arguments);
1381
- }
1382
- return fetchResourceAvailability;
1383
- }() // ─── 日期概览 & 时间槽矩阵(纯计算,不发请求) ───
1384
- }, {
1385
- key: "getOperatingHoursScheduleIds",
1386
- value: function getOperatingHoursScheduleIds() {
1387
- var _this$store$openData, _this$store$openData$;
1388
- var openData = this.otherParams.openData || ((_this$store$openData = this.store.openData) === null || _this$store$openData === void 0 || (_this$store$openData$ = _this$store$openData.getOpenData) === null || _this$store$openData$ === void 0 ? void 0 : _this$store$openData$.call(_this$store$openData)) || null;
1389
- var rawIds = openData === null || openData === void 0 ? void 0 : openData['availability.operating_hours'];
1390
- if (!Array.isArray(rawIds)) return [];
1391
- return _toConsumableArray(new Set(rawIds.map(function (id) {
1392
- return Number(id);
1393
- }).filter(function (id) {
1394
- return Number.isFinite(id) && id > 0;
1395
- }).map(function (id) {
1396
- return Math.floor(id);
1397
- })));
1398
- }
1399
- }, {
1400
- key: "resolveSlotConfigForDate",
1401
- value: function resolveSlotConfigForDate(date) {
1402
- var nextSlotConfig = _objectSpread({}, this.baseSlotConfig);
1403
- if (!date || !this.store.schedule) return nextSlotConfig;
1404
- var operatingHoursScheduleIds = this.getOperatingHoursScheduleIds();
1405
- if (!operatingHoursScheduleIds.length) return nextSlotConfig;
1406
- var scheduleList = this.store.schedule.getScheduleListByIds(operatingHoursScheduleIds);
1407
- if (!scheduleList.length) return nextSlotConfig;
1408
- var timeRangeMap = calcMinTimeMaxTimeBySchedules(scheduleList, undefined, date);
1409
- var earliestStart = null;
1410
- var latestEnd = null;
1411
- var _iterator4 = _createForOfIteratorHelper(scheduleList),
1412
- _step4;
1413
- try {
1414
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
1415
- var _timeRangeMap$schedul;
1416
- var schedule = _step4.value;
1417
- var dateRangeList = (timeRangeMap === null || timeRangeMap === void 0 || (_timeRangeMap$schedul = timeRangeMap[schedule.id]) === null || _timeRangeMap$schedul === void 0 ? void 0 : _timeRangeMap$schedul.dateRangeFormat) || [];
1418
- var _iterator5 = _createForOfIteratorHelper(dateRangeList),
1419
- _step5;
1420
- try {
1421
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1422
- var range = _step5.value;
1423
- var start = dayjs(range === null || range === void 0 ? void 0 : range.start);
1424
- var end = dayjs(range === null || range === void 0 ? void 0 : range.end);
1425
- if (!start.isValid() || !end.isValid()) continue;
1426
- if (!earliestStart || start.isBefore(earliestStart)) {
1427
- earliestStart = start;
1428
- }
1429
- if (!latestEnd || end.isAfter(latestEnd)) {
1430
- latestEnd = end;
1431
- }
1432
- }
1433
- } catch (err) {
1434
- _iterator5.e(err);
1435
- } finally {
1436
- _iterator5.f();
1437
- }
1438
- }
1439
- } catch (err) {
1440
- _iterator4.e(err);
1441
- } finally {
1442
- _iterator4.f();
1443
- }
1444
- if (!earliestStart || !latestEnd) return nextSlotConfig;
1445
- return _objectSpread(_objectSpread({}, nextSlotConfig), {}, {
1446
- businessStartTime: earliestStart.format('HH:mm'),
1447
- businessEndTime: latestEnd.format('HH:mm')
1448
- });
1449
- }
1450
- }, {
1451
- key: "syncOperatingHoursToSlotConfig",
1452
- value: function syncOperatingHoursToSlotConfig(date) {
1453
- var resolvedSlotConfig = this.resolveSlotConfigForDate(date);
1454
- this.store.slotConfig = resolvedSlotConfig;
1455
- return resolvedSlotConfig;
1456
- }
1457
- }, {
1458
- key: "getDateRangeSummary",
1459
- value: function getDateRangeSummary(params) {
1460
- var _this7 = this;
1461
- return buildDateRangeSummary({
1462
- startDate: params.startDate,
1463
- endDate: params.endDate,
1464
- config: this.baseSlotConfig,
1465
- rawResources: this.store.rawResourceData,
1466
- resourceProductMap: this.resourceProductMap,
1467
- resolveConfig: function resolveConfig(date) {
1468
- return _this7.resolveSlotConfigForDate(date);
1469
- },
1470
- buildSlotPriceMap: function buildSlotPriceMap(date, config, productIds) {
1471
- return _this7.buildSlotPriceMapForDate(date, config, productIds);
1472
- }
1473
- });
1474
- }
1475
- }, {
1476
- key: "getTimeSlotGrid",
1477
- value: function getTimeSlotGrid(date) {
1478
- var resolvedSlotConfig = this.syncOperatingHoursToSlotConfig(date);
1479
- var productIds = _toConsumableArray(new Set(_toConsumableArray(this.resourceProductMap.values()).flat().map(function (m) {
1480
- return m.productId;
1481
- })));
1482
- var slotPriceMap = productIds.length ? this.buildSlotPriceMapForDate(date, resolvedSlotConfig, productIds) : undefined;
1483
- return buildTimeSlotGrid({
1484
- date: date,
1485
- config: resolvedSlotConfig,
1486
- rawResources: this.store.rawResourceData,
1487
- resourceProductMap: this.resourceProductMap,
1488
- slotPriceMap: slotPriceMap
1489
- });
1490
- }
1491
-
1492
- // ─── 时间槽订单操作 ───
1493
-
1494
- /**
1495
- * 切换单个时段的选中状态(选中/取消)。
1496
- * 内部自动处理连续时段的合并与拆分,订单是唯一真相源。
1497
- *
1498
- * slot.productId 指定当前操作针对的是该 resourceId 下的哪一个商品。
1499
- * 同一资源下不同 productId 之间互相隔离,不会相互合并。
1500
- */
1501
- }, {
1502
- key: "toggleSlot",
1503
- value: function () {
1504
- var _toggleSlot = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(slot) {
1505
- var mappings, mapping, currentSlots, existIndex, nextSlots, products;
1506
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1507
- while (1) switch (_context16.prev = _context16.next) {
1508
- case 0:
1509
- this.logMethodStart('toggleSlot', {
1510
- resourceId: slot.resourceId,
1511
- productId: slot.productId,
1512
- startTime: slot.startTime
1513
- });
1514
- _context16.prev = 1;
1515
- mappings = this.resourceProductMap.get(slot.resourceId);
1516
- if (!(!mappings || !mappings.length)) {
1517
- _context16.next = 5;
1518
- break;
1519
- }
1520
- throw new Error("\u672A\u627E\u5230\u8D44\u6E90 ".concat(slot.resourceId, " \u7684\u5546\u54C1\u6620\u5C04"));
1521
- case 5:
1522
- mapping = mappings.find(function (m) {
1523
- return m.productId === slot.productId;
1524
- });
1525
- if (mapping) {
1526
- _context16.next = 8;
1527
- break;
1528
- }
1529
- throw new Error("\u8D44\u6E90 ".concat(slot.resourceId, " \u672A\u5173\u8054\u5546\u54C1 ").concat(slot.productId));
1530
- case 8:
1531
- if (this.store.order) {
1532
- _context16.next = 10;
1533
- break;
1534
- }
1535
- throw new Error('order 模块未初始化');
1536
- case 10:
1537
- currentSlots = this.getSelectedSlotsForResourceProduct(slot.resourceId, slot.productId);
1538
- existIndex = currentSlots.findIndex(function (s) {
1539
- return s.startTime === slot.startTime;
1540
- });
1541
- if (existIndex !== -1) {
1542
- nextSlots = currentSlots.filter(function (_, i) {
1543
- return i !== existIndex;
1544
- });
1545
- } else {
1546
- nextSlots = [].concat(_toConsumableArray(currentSlots), [slot]);
1547
- }
1548
- _context16.next = 15;
1549
- return this.reconcileOrderForResourceProduct(slot.resourceId, slot.productId, nextSlots);
1550
- case 15:
1551
- products = this.store.order.getOrderProducts();
1552
- _context16.next = 18;
1553
- return this.refreshItemRuleQuantityLimits();
1554
- case 18:
1555
- _context16.next = 20;
1556
- return this.refreshCartValidationPassed();
1557
- case 20:
1558
- this.logMethodSuccess('toggleSlot', {
1559
- action: existIndex !== -1 ? 'remove' : 'add',
1560
- resourceId: slot.resourceId,
1561
- productId: slot.productId,
1562
- slotCount: nextSlots.length
1563
- });
1564
- return _context16.abrupt("return", products);
1565
- case 24:
1566
- _context16.prev = 24;
1567
- _context16.t0 = _context16["catch"](1);
1568
- this.logMethodError('toggleSlot', _context16.t0);
1569
- throw _context16.t0;
1570
- case 28:
1571
- case "end":
1572
- return _context16.stop();
1573
- }
1574
- }, _callee16, this, [[1, 24]]);
1575
- }));
1576
- function toggleSlot(_x8) {
1577
- return _toggleSlot.apply(this, arguments);
1578
- }
1579
- return toggleSlot;
1580
- }()
1581
- /**
1582
- * 获取某资源当前选中的所有独立时段(从订单中解析)。
1583
- * 不传 productId 时返回该资源下所有商品的选中时段;传了则精确匹配。
1584
- */
1585
- }, {
1586
- key: "getSelectedSlotsForResource",
1587
- value: function getSelectedSlotsForResource(resourceId, productId) {
1588
- var _this$store$order5;
1589
- var tempOrder = (_this$store$order5 = this.store.order) === null || _this$store$order5 === void 0 ? void 0 : _this$store$order5.getTempOrder();
1590
- if (!tempOrder) return [];
1591
- var venueProducts = tempOrder.products.filter(function (p) {
1592
- var _p$metadata, _p$metadata2;
1593
- if (!((_p$metadata = p.metadata) !== null && _p$metadata !== void 0 && _p$metadata.venue_booking)) return false;
1594
- if (String((_p$metadata2 = p.metadata) === null || _p$metadata2 === void 0 ? void 0 : _p$metadata2.resource_id) !== String(resourceId)) return false;
1595
- if (productId != null && Number(p.product_id) !== Number(productId)) return false;
1596
- return true;
1597
- });
1598
- var slotDuration = this.store.slotConfig.slotDurationMinutes;
1599
- var slots = [];
1600
- var _iterator6 = _createForOfIteratorHelper(venueProducts),
1601
- _step6;
1602
- try {
1603
- var _loop = function _loop() {
1604
- var product = _step6.value;
1605
- slots.push.apply(slots, _toConsumableArray(expandMergedSlotToIndividual(product, slotDuration).map(function (s) {
1606
- return _objectSpread(_objectSpread({}, s), {}, {
1607
- productId: Number(product.product_id)
1608
- });
1609
- })));
1610
- };
1611
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1612
- _loop();
1613
- }
1614
- } catch (err) {
1615
- _iterator6.e(err);
1616
- } finally {
1617
- _iterator6.f();
1618
- }
1619
- return slots.sort(function (a, b) {
1620
- return a.startTime.localeCompare(b.startTime);
1621
- });
1622
- }
1623
-
1624
- /** getSelectedSlotsForResource 的 (resourceId, productId) 精确版,内部使用。 */
1625
- }, {
1626
- key: "getSelectedSlotsForResourceProduct",
1627
- value: function getSelectedSlotsForResourceProduct(resourceId, productId) {
1628
- return this.getSelectedSlotsForResource(resourceId, productId);
1629
- }
1630
-
1631
- /**
1632
- * 判断某个时段是否已选中。
1633
- * 不传 productId 时:只要该资源下任一商品在 startTime 被选中即返回 true;传了则精确匹配。
1634
- */
1635
- }, {
1636
- key: "isSlotSelected",
1637
- value: function isSlotSelected(resourceId, startTime, productId) {
1638
- return this.getSelectedSlotsForResource(resourceId, productId).some(function (s) {
1639
- return s.startTime === startTime;
1640
- });
1641
- }
1642
-
1643
- /**
1644
- * 判断指定 (resourceId, productId, startTime) 格子是否应因其它已选项而被禁用。
1645
- * 规则:
1646
- * 1) 同一 resourceId 下若已选了另一个 productId 的同 startTime → 禁用
1647
- * 2) 当前 resource 是组合资源:若其任一 child resource 在 startTime 被选中 → 禁用
1648
- * 3) 当前 resource 是某些组合资源的 child:若该组合资源在 startTime 被选中 → 禁用
1649
- * 4) 两个组合资源的 child 集合有交集,且对方在该 startTime 被选中 → 禁用
1650
- */
1651
- }, {
1652
- key: "isSlotDisabledBySelection",
1653
- value: function isSlotDisabledBySelection(params) {
1654
- var _this8 = this;
1655
- var resourceId = params.resourceId,
1656
- productId = params.productId,
1657
- startTime = params.startTime;
1658
- var allSelected = this.getAllSelectedSlots();
1659
- var getSelectedAt = function getSelectedAt(resId) {
1660
- var list = allSelected.get(resId) || [];
1661
- return list.filter(function (s) {
1662
- return s.startTime === startTime;
1663
- });
1664
- };
1665
-
1666
- // 规则 1:同场地、不同 productId 的已选
1667
- var sameResourceSelections = getSelectedAt(resourceId);
1668
- if (sameResourceSelections.some(function (s) {
1669
- return Number(s.productId) !== Number(productId);
1670
- })) {
1671
- return true;
1672
- }
1673
-
1674
- // 组合资源字段缓存
1675
- var getCombinedChildIds = function getCombinedChildIds(resId) {
1676
- var raw = _this8.store.rawResourceData.find(function (r) {
1677
- return String(r.resourceId) === String(resId);
1678
- });
1679
- var combined = raw === null || raw === void 0 ? void 0 : raw.combined_resource;
1680
- if (combined && combined.status === 1 && Array.isArray(combined.resource_ids)) {
1681
- return combined.resource_ids;
1682
- }
1683
- return [];
1684
- };
1685
- var currentChildIds = getCombinedChildIds(resourceId);
1686
- var currentIsCombined = currentChildIds.length > 0;
1687
-
1688
- // 规则 2:当前是组合资源,任一子资源被选 → 禁用
1689
- if (currentIsCombined) {
1690
- var _iterator7 = _createForOfIteratorHelper(currentChildIds),
1691
- _step7;
1692
- try {
1693
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1694
- var childId = _step7.value;
1695
- if (getSelectedAt(childId).length > 0) return true;
1696
- }
1697
- } catch (err) {
1698
- _iterator7.e(err);
1699
- } finally {
1700
- _iterator7.f();
1701
- }
1702
- }
1703
-
1704
- // 规则 3 & 4:扫描所有已选的 (resId),若是组合资源,检查其 children 是否包含当前 resourceId 或与当前 child 集合有交集
1705
- var _iterator8 = _createForOfIteratorHelper(allSelected),
1706
- _step8;
1707
- try {
1708
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1709
- var _step8$value = _slicedToArray(_step8.value, 2),
1710
- selectedResId = _step8$value[0],
1711
- slots = _step8$value[1];
1712
- if (!slots.some(function (s) {
1713
- return s.startTime === startTime;
1714
- })) continue;
1715
- if (String(selectedResId) === String(resourceId)) continue;
1716
- var selectedChildIds = getCombinedChildIds(selectedResId);
1717
- if (selectedChildIds.length === 0) continue;
1718
-
1719
- // 对方是组合资源,其 children 包含当前 resourceId(规则 3)
1720
- if (selectedChildIds.some(function (id) {
1721
- return String(id) === String(resourceId);
1722
- })) {
1723
- return true;
1724
- }
1725
-
1726
- // 双方都是组合资源,child 集合有交集(规则 4)
1727
- if (currentIsCombined) {
1728
- var intersect = selectedChildIds.some(function (id) {
1729
- return currentChildIds.some(function (cid) {
1730
- return String(cid) === String(id);
1731
- });
1732
- });
1733
- if (intersect) return true;
1734
- }
1735
- }
1736
- } catch (err) {
1737
- _iterator8.e(err);
1738
- } finally {
1739
- _iterator8.f();
1740
- }
1741
- return false;
1742
- }
1743
-
1744
- /**
1745
- * 获取所有已选时段(按资源分组)。每个 slot 上带 productId,便于 UI 做 per-product 判定。
1746
- */
1747
- }, {
1748
- key: "getAllSelectedSlots",
1749
- value: function getAllSelectedSlots() {
1750
- var _this$store$order6;
1751
- var result = new Map();
1752
- var tempOrder = (_this$store$order6 = this.store.order) === null || _this$store$order6 === void 0 ? void 0 : _this$store$order6.getTempOrder();
1753
- if (!tempOrder) return result;
1754
- var venueProducts = tempOrder.products.filter(function (p) {
1755
- var _p$metadata3;
1756
- return (_p$metadata3 = p.metadata) === null || _p$metadata3 === void 0 ? void 0 : _p$metadata3.venue_booking;
1757
- });
1758
- var slotDuration = this.store.slotConfig.slotDurationMinutes;
1759
- var _iterator9 = _createForOfIteratorHelper(venueProducts),
1760
- _step9;
1761
- try {
1762
- var _loop2 = function _loop2() {
1763
- var _product$metadata;
1764
- var product = _step9.value;
1765
- var resourceId = (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.resource_id;
1766
- if (resourceId == null) return 1; // continue
1767
- var productId = Number(product.product_id);
1768
- var existing = result.get(resourceId) || [];
1769
- existing.push.apply(existing, _toConsumableArray(expandMergedSlotToIndividual(product, slotDuration).map(function (s) {
1770
- return _objectSpread(_objectSpread({}, s), {}, {
1771
- productId: productId
1772
- });
1773
- })));
1774
- result.set(resourceId, existing);
1775
- };
1776
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1777
- if (_loop2()) continue;
1778
- }
1779
- } catch (err) {
1780
- _iterator9.e(err);
1781
- } finally {
1782
- _iterator9.f();
1783
- }
1784
- var _iterator10 = _createForOfIteratorHelper(result),
1785
- _step10;
1786
- try {
1787
- for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
1788
- var _step10$value = _slicedToArray(_step10.value, 2),
1789
- key = _step10$value[0],
1790
- slots = _step10$value[1];
1791
- result.set(key, slots.sort(function (a, b) {
1792
- return a.startTime.localeCompare(b.startTime);
1793
- }));
1794
- }
1795
- } catch (err) {
1796
- _iterator10.e(err);
1797
- } finally {
1798
- _iterator10.f();
1799
- }
1800
- return result;
1801
- }
1802
-
1803
- /**
1804
- * 对指定 (resourceId, productId) 的订单商品进行 reconcile:
1805
- * 清除旧商品 → 合并连续时段 → 重新写入。
1806
- * 同一场地下不同商品互不干扰,各自单独 reconcile。
1807
- */
1808
- }, {
1809
- key: "reconcileOrderForResourceProduct",
1810
- value: (function () {
1811
- var _reconcileOrderForResourceProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(resourceId, productId, slots) {
1812
- var mappings, mapping, tempOrder, matchesCurrent, merged, rawResource, childRawResources, venueProduct, i, _rawResource$form_id, _venueProduct$is_char, group, identityKey, bookingUuid, startMoment, endMoment, duration, customDepositData, resourceEntry, booking;
1813
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1814
- while (1) switch (_context17.prev = _context17.next) {
1815
- case 0:
1816
- mappings = this.resourceProductMap.get(resourceId);
1817
- if (!(!mappings || !mappings.length || !this.store.order)) {
1818
- _context17.next = 3;
1819
- break;
1820
- }
1821
- return _context17.abrupt("return");
1822
- case 3:
1823
- mapping = mappings.find(function (m) {
1824
- return m.productId === productId;
1825
- });
1826
- if (mapping) {
1827
- _context17.next = 6;
1828
- break;
1829
- }
1830
- return _context17.abrupt("return");
1831
- case 6:
1832
- tempOrder = this.store.order.ensureTempOrder();
1833
- matchesCurrent = function matchesCurrent(meta, pid) {
1834
- return !!(meta !== null && meta !== void 0 && meta.venue_booking) && String(meta === null || meta === void 0 ? void 0 : meta.resource_id) === String(resourceId) && Number(pid) === Number(productId);
1835
- };
1836
- tempOrder.products = tempOrder.products.filter(function (p) {
1837
- return !matchesCurrent(p.metadata, p.product_id);
1838
- });
1839
- tempOrder.bookings = (tempOrder.bookings || []).filter(function (b) {
1840
- var _b$metadata, _b$metadata2, _b$metadata$product_i, _b$metadata3, _b$product;
1841
- if (!((_b$metadata = b.metadata) !== null && _b$metadata !== void 0 && _b$metadata.venue_booking)) return true;
1842
- if (String((_b$metadata2 = b.metadata) === null || _b$metadata2 === void 0 ? void 0 : _b$metadata2.resource_id) !== String(resourceId)) return true;
1843
- var bookingProductId = (_b$metadata$product_i = (_b$metadata3 = b.metadata) === null || _b$metadata3 === void 0 ? void 0 : _b$metadata3.product_id) !== null && _b$metadata$product_i !== void 0 ? _b$metadata$product_i : b === null || b === void 0 || (_b$product = b.product) === null || _b$product === void 0 ? void 0 : _b$product.product_id;
1844
- if (bookingProductId == null) return false;
1845
- return Number(bookingProductId) !== Number(productId);
1846
- });
1847
- if (slots.length) {
1848
- _context17.next = 16;
1849
- break;
1850
- }
1851
- this.store.order.applyDiscount();
1852
- _context17.next = 14;
1853
- return this.store.order.recalculateSummary({
1854
- createIfMissing: true
1855
- });
1856
- case 14:
1857
- this.store.order.persistTempOrder();
1858
- return _context17.abrupt("return");
1859
- case 16:
1860
- merged = mergeConsecutiveSlots(slots);
1861
- rawResource = this.store.rawResourceData.find(function (r) {
1862
- return String(r.resourceId) === String(resourceId);
1863
- });
1864
- childRawResources = this.getCombinedChildRawResources(rawResource);
1865
- venueProduct = this.getVenueProducts().find(function (p) {
1866
- return p.id === mapping.productId;
1867
- });
1868
- tempOrder.bookings = tempOrder.bookings || [];
1869
- for (i = 0; i < merged.length; i++) {
1870
- group = merged[i];
1871
- identityKey = buildVenueIdentityKey(resourceId, i);
1872
- bookingUuid = createUuidV4();
1873
- startMoment = dayjs(group.startTime, 'YYYY-MM-DD HH:mm');
1874
- endMoment = dayjs(group.endTime, 'YYYY-MM-DD HH:mm');
1875
- duration = endMoment.diff(startMoment, 'minute');
1876
- customDepositData = cloneCustomDepositData(venueProduct === null || venueProduct === void 0 ? void 0 : venueProduct.custom_deposit_data);
1877
- resourceEntry = {
1878
- relation_type: 'form',
1879
- like_status: 'common',
1880
- id: resourceId,
1881
- main_field: mapping.resourceName,
1882
- form_id: (_rawResource$form_id = rawResource === null || rawResource === void 0 ? void 0 : rawResource.form_id) !== null && _rawResource$form_id !== void 0 ? _rawResource$form_id : mapping.formId,
1883
- relation_id: resourceId,
1884
- capacity: 1,
1885
- metadata: buildVenueResourceMetadata({
1886
- mapping: mapping,
1887
- rawResource: rawResource
1888
- })
1889
- };
1890
- if (childRawResources && childRawResources.length) {
1891
- resourceEntry.children = childRawResources.map(function (child) {
1892
- var _child$form_id, _child$capacity;
1893
- return {
1894
- relation_type: 'form',
1895
- like_status: 'common',
1896
- id: child.resourceId,
1897
- main_field: child.main_field || '',
1898
- form_id: (_child$form_id = child.form_id) !== null && _child$form_id !== void 0 ? _child$form_id : child.formId,
1899
- relation_id: child.resourceId,
1900
- capacity: (_child$capacity = child.capacity) !== null && _child$capacity !== void 0 ? _child$capacity : 1,
1901
- metadata: {}
1902
- };
1903
- });
1904
- }
1905
- tempOrder.products.push(normalizeOrderProduct({
1906
- product_id: mapping.productId,
1907
- product_variant_id: 0,
1908
- identity_key: identityKey,
1909
- num: 1,
1910
- selling_price: group.totalPrice,
1911
- original_price: group.totalPrice,
1912
- is_charge_tax: (_venueProduct$is_char = venueProduct === null || venueProduct === void 0 ? void 0 : venueProduct.is_charge_tax) !== null && _venueProduct$is_char !== void 0 ? _venueProduct$is_char : 0,
1913
- metadata: {
1914
- venue_booking: true,
1915
- resource_id: resourceId,
1916
- resource_form_id: mapping.formId,
1917
- resource_name: mapping.resourceName,
1918
- start_time: group.startTime,
1919
- end_time: group.endTime,
1920
- slot_count: group.slotCount,
1921
- booking_uid: bookingUuid,
1922
- price_breakdown: buildPriceBreakdown({
1923
- group: group,
1924
- productId: mapping.productId
1925
- })
1926
- },
1927
- _origin: {
1928
- name: mapping.productTitle,
1929
- cover: (venueProduct === null || venueProduct === void 0 ? void 0 : venueProduct.cover) || '',
1930
- custom_deposit_data: customDepositData,
1931
- id: 0,
1932
- number: 1,
1933
- registration_type: 'all',
1934
- relation_products: [],
1935
- is_all: false,
1936
- product: {
1937
- product_id: mapping.productId,
1938
- product_variant_id: 0,
1939
- num: 1,
1940
- product_bundle: [],
1941
- product_option_item: [],
1942
- discount_list: [],
1943
- custom_deposit_data: customDepositData,
1944
- metadata: {}
1945
- },
1946
- sub_type: 'minutes',
1947
- duration: duration,
1948
- like_status: 'common',
1949
- resources: [resourceEntry],
1950
- schedule_id: 0,
1951
- select_date: startMoment.format('YYYY-MM-DD'),
1952
- start_date: startMoment.format('YYYY-MM-DD'),
1953
- start_time: startMoment.format('HH:mm'),
1954
- end_date: endMoment.format('YYYY-MM-DD'),
1955
- end_time: endMoment.format('HH:mm'),
1956
- metadata: {
1957
- venue_booking: true,
1958
- slot_count: group.slotCount
1959
- },
1960
- holder: null
1961
- }
1962
- }));
1963
- booking = buildVenueBookingEntry({
1964
- group: group,
1965
- resourceId: resourceId,
1966
- mapping: mapping,
1967
- rawResource: rawResource,
1968
- bookingUuid: bookingUuid,
1969
- productUid: identityKey,
1970
- childResources: childRawResources
1971
- });
1972
- tempOrder.bookings.push(booking);
1973
- }
1974
- this.store.order.applyDiscount();
1975
- _context17.next = 25;
1976
- return this.store.order.recalculateSummary({
1977
- createIfMissing: true
1978
- });
1979
- case 25:
1980
- this.store.order.persistTempOrder();
1981
- case 26:
1982
- case "end":
1983
- return _context17.stop();
1984
- }
1985
- }, _callee17, this);
1986
- }));
1987
- function reconcileOrderForResourceProduct(_x9, _x10, _x11) {
1988
- return _reconcileOrderForResourceProduct.apply(this, arguments);
1989
- }
1990
- return reconcileOrderForResourceProduct;
1991
- }() /** 给定一个父 rawResource,返回其 combined_resource.resource_ids 对应的子 rawResource 列表。 */)
1992
- }, {
1993
- key: "getCombinedChildRawResources",
1994
- value: function getCombinedChildRawResources(rawResource) {
1995
- var _this9 = this;
1996
- if (!rawResource) return undefined;
1997
- var combined = rawResource.combined_resource;
1998
- if (!combined || combined.status !== 1 || !Array.isArray(combined.resource_ids) || !combined.resource_ids.length) {
1999
- return undefined;
2000
- }
2001
- var children = [];
2002
- var _iterator11 = _createForOfIteratorHelper(combined.resource_ids),
2003
- _step11;
2004
- try {
2005
- var _loop3 = function _loop3() {
2006
- var id = _step11.value;
2007
- var child = _this9.store.rawResourceData.find(function (r) {
2008
- return String(r.resourceId) === String(id);
2009
- });
2010
- if (child) children.push(child);
2011
- };
2012
- for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
2013
- _loop3();
2014
- }
2015
- } catch (err) {
2016
- _iterator11.e(err);
2017
- } finally {
2018
- _iterator11.f();
2019
- }
2020
- return children.length ? children : undefined;
2021
- }
2022
-
2023
- // ─── 配置 ───
2024
- }, {
2025
- key: "setSlotConfig",
2026
- value: function setSlotConfig(config) {
2027
- this.baseSlotConfig = _objectSpread(_objectSpread({}, this.baseSlotConfig), config);
2028
- this.store.slotConfig = _objectSpread({}, this.baseSlotConfig);
2029
- }
2030
- }, {
2031
- key: "getSlotConfig",
2032
- value: function getSlotConfig() {
2033
- return _objectSpread({}, this.store.slotConfig);
2034
- }
2035
-
2036
- // ─── 日程 ───
2037
- }, {
2038
- key: "loadSchedules",
2039
- value: function () {
2040
- var _loadSchedules = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
2041
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
2042
- while (1) switch (_context18.prev = _context18.next) {
2043
- case 0:
2044
- this.logMethodStart('loadSchedules');
2045
- _context18.prev = 1;
2046
- if (this.store.schedule) {
2047
- _context18.next = 4;
2048
- break;
2049
- }
2050
- throw new Error('schedule 模块未初始化');
2051
- case 4:
2052
- _context18.next = 6;
2053
- return this.store.schedule.loadAllSchedule();
2054
- case 6:
2055
- this.logMethodSuccess('loadSchedules');
2056
- _context18.next = 13;
2057
- break;
2058
- case 9:
2059
- _context18.prev = 9;
2060
- _context18.t0 = _context18["catch"](1);
2061
- this.logMethodError('loadSchedules', _context18.t0);
2062
- throw _context18.t0;
2063
- case 13:
2064
- case "end":
2065
- return _context18.stop();
2066
- }
2067
- }, _callee18, this, [[1, 9]]);
2068
- }));
2069
- function loadSchedules() {
2070
- return _loadSchedules.apply(this, arguments);
2071
- }
2072
- return loadSchedules;
2073
- }()
2074
- }, {
2075
- key: "getScheduleListByIds",
2076
- value: function getScheduleListByIds(ids) {
2077
- if (!this.store.schedule) return [];
2078
- return this.store.schedule.getScheduleListByIds(ids);
2079
- }
2080
-
2081
- // ─── 临时订单操作(保留原有能力) ───
2082
- }, {
2083
- key: "getTempOrder",
2084
- value: function getTempOrder() {
2085
- var _this$store$order7;
2086
- var result = ((_this$store$order7 = this.store.order) === null || _this$store$order7 === void 0 ? void 0 : _this$store$order7.getTempOrder()) || null;
2087
- return result;
2088
- }
2089
- }, {
2090
- key: "updateTempOrderNote",
2091
- value: function updateTempOrderNote(note) {
2092
- if (!this.store.order) throw new Error('order 模块未初始化');
2093
- return this.store.order.updateTempOrderNote(note);
2094
- }
2095
- }, {
2096
- key: "updateTempOrderContactsInfo",
2097
- value: function updateTempOrderContactsInfo(contactsInfo) {
2098
- if (!this.store.order) throw new Error('order 模块未初始化');
2099
- return this.store.order.updateTempOrderContactsInfo(contactsInfo);
2100
- }
2101
- }, {
2102
- key: "ensureTempOrder",
2103
- value: function ensureTempOrder() {
2104
- if (!this.store.order) throw new Error('order 模块未初始化');
2105
- return this.store.order.ensureTempOrder();
2106
- }
2107
- }, {
2108
- key: "onCustomerLogin",
2109
- value: function () {
2110
- var _onCustomerLogin = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(params) {
2111
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
2112
- while (1) switch (_context19.prev = _context19.next) {
2113
- case 0:
2114
- this.logMethodStart('onCustomerLogin', {
2115
- customerId: params.customerId
2116
- });
2117
- _context19.prev = 1;
2118
- _context19.next = 4;
2119
- return this.refreshOrderMarketingAfterLogin({
2120
- customerId: params.customerId
2121
- });
2122
- case 4:
2123
- this.logMethodSuccess('onCustomerLogin', {
2124
- customerId: params.customerId
2125
- });
2126
- _context19.next = 11;
2127
- break;
2128
- case 7:
2129
- _context19.prev = 7;
2130
- _context19.t0 = _context19["catch"](1);
2131
- this.logMethodError('onCustomerLogin', _context19.t0);
2132
- throw _context19.t0;
2133
- case 11:
2134
- case "end":
2135
- return _context19.stop();
2136
- }
2137
- }, _callee19, this, [[1, 7]]);
2138
- }));
2139
- function onCustomerLogin(_x12) {
2140
- return _onCustomerLogin.apply(this, arguments);
2141
- }
2142
- return onCustomerLogin;
2143
- }()
2144
- }, {
2145
- key: "recalculateOrderPricesFromSmartPricing",
2146
- value: function recalculateOrderPricesFromSmartPricing() {
2147
- var _tempOrder$products,
2148
- _this10 = this;
2149
- if (!this.store.order) return;
2150
- var tempOrder = this.store.order.getTempOrder();
2151
- if (!(tempOrder !== null && tempOrder !== void 0 && (_tempOrder$products = tempOrder.products) !== null && _tempOrder$products !== void 0 && _tempOrder$products.length)) return;
2152
- var now = dayjs().format('YYYY-MM-DD HH:mm:ss');
2153
- var catalog = this.getAllProductsForSmartPricing();
2154
- var context = this.buildSmartPricingContext();
2155
- var _iterator12 = _createForOfIteratorHelper(tempOrder.products),
2156
- _step12;
2157
- try {
2158
- var _loop4 = function _loop4() {
2159
- var _product$metadata2;
2160
- var product = _step12.value;
2161
- if ((_product$metadata2 = product.metadata) !== null && _product$metadata2 !== void 0 && _product$metadata2.venue_booking) {
2162
- var mappings = _this10.resourceProductMap.get(product.metadata.resource_id);
2163
- if (!mappings || !mappings.length) return 0; // continue
2164
- var mapping = mappings.find(function (m) {
2165
- return Number(m.productId) === Number(product.product_id);
2166
- }) || mappings[0];
2167
- if (!mapping) return 0; // continue
2168
- var slots = expandMergedSlotToIndividual(product, _this10.store.slotConfig.slotDurationMinutes);
2169
- var uniqueDates = _toConsumableArray(new Set(slots.map(function (slot) {
2170
- return dayjs(slot.startTime).format('YYYY-MM-DD');
2171
- })));
2172
- var slotPriceMaps = new Map();
2173
- var _iterator13 = _createForOfIteratorHelper(uniqueDates),
2174
- _step13;
2175
- try {
2176
- for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
2177
- var slotDate = _step13.value;
2178
- slotPriceMaps.set(slotDate, _this10.buildSlotPriceMapForDate(slotDate, _this10.store.slotConfig, [mapping.productId]));
2179
- }
2180
- } catch (err) {
2181
- _iterator13.e(err);
2182
- } finally {
2183
- _iterator13.f();
2184
- }
2185
- var updatedSlots = slots.map(function (slot) {
2186
- var slotDate = dayjs(slot.startTime).format('YYYY-MM-DD');
2187
- var slotPriceMap = slotPriceMaps.get(slotDate);
2188
- return _objectSpread(_objectSpread({}, slot), {}, {
2189
- productId: mapping.productId,
2190
- price: slotPriceMap ? getSlotPriceFromMap({
2191
- slotPriceMap: slotPriceMap,
2192
- productId: mapping.productId,
2193
- slotStartTime: slot.startTime,
2194
- fallbackPrice: mapping.price
2195
- }) : mapping.price
2196
- });
2197
- });
2198
- var merged = mergeConsecutiveSlots(updatedSlots);
2199
- if (merged.length === 1) {
2200
- _this10.resetProductPriceForSmartPricing({
2201
- product: product,
2202
- price: merged[0].totalPrice,
2203
- priceBreakdown: buildPriceBreakdown({
2204
- group: merged[0],
2205
- productId: mapping.productId
2206
- })
2207
- });
2208
- }
2209
- } else if (product.product_id != null) {
2210
- var smartPrice = getPriceForProductAtDatetime({
2211
- products: catalog,
2212
- context: context,
2213
- productId: Number(product.product_id),
2214
- datetime: now,
2215
- fallbackPrice: product.selling_price
2216
- });
2217
- _this10.resetProductPriceForSmartPricing({
2218
- product: product,
2219
- price: smartPrice
2220
- });
2221
- }
2222
- },
2223
- _ret;
2224
- for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
2225
- _ret = _loop4();
2226
- if (_ret === 0) continue;
2227
- }
2228
- } catch (err) {
2229
- _iterator12.e(err);
2230
- } finally {
2231
- _iterator12.f();
2232
- }
2233
- }
2234
-
2235
- /**
2236
- * DataVariant 重算价格后,同步刷新订单展示、Rules 与 Summary 共用的价格口径。
2237
- * Rules 会在本轮结束后根据当前客户的 discountList 重新写入实际折扣。
2238
- */
2239
- }, {
2240
- key: "resetProductPriceForSmartPricing",
2241
- value: function resetProductPriceForSmartPricing(params) {
2242
- var product = params.product,
2243
- price = params.price,
2244
- priceBreakdown = params.priceBreakdown;
2245
- var metadata = product.metadata || {};
2246
- product.selling_price = price;
2247
- product.original_price = price;
2248
- product.discount_list = [];
2249
- product.metadata = _objectSpread(_objectSpread(_objectSpread({}, metadata), priceBreakdown ? {
2250
- price_breakdown: priceBreakdown
2251
- } : {}), {}, {
2252
- source_product_price: price,
2253
- main_product_original_price: price,
2254
- main_product_selling_price: price,
2255
- price_schema_version: 2
2256
- });
2257
- }
2258
- }, {
2259
- key: "scanCode",
2260
- value: function () {
2261
- var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(code, customerId) {
2262
- var result;
2263
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
2264
- while (1) switch (_context20.prev = _context20.next) {
2265
- case 0:
2266
- this.logMethodStart('scanCode', {
2267
- code: code
2268
- });
2269
- _context20.prev = 1;
2270
- if (this.store.order) {
2271
- _context20.next = 4;
2272
- break;
2273
- }
2274
- throw new Error('order 模块未初始化');
2275
- case 4:
2276
- _context20.next = 6;
2277
- return this.store.order.scanCode(code, customerId);
2278
- case 6:
2279
- result = _context20.sent;
2280
- if (!result.isAvailable) {
2281
- _context20.next = 11;
2282
- break;
2283
- }
2284
- _context20.next = 10;
2285
- return this.store.order.recalculateSummary({
2286
- createIfMissing: true
2287
- });
2288
- case 10:
2289
- this.store.order.persistTempOrder();
2290
- case 11:
2291
- this.logMethodSuccess('scanCode', {
2292
- isAvailable: result.isAvailable
2293
- });
2294
- return _context20.abrupt("return", result);
2295
- case 15:
2296
- _context20.prev = 15;
2297
- _context20.t0 = _context20["catch"](1);
2298
- this.logMethodError('scanCode', _context20.t0);
2299
- throw _context20.t0;
2300
- case 19:
2301
- case "end":
2302
- return _context20.stop();
2303
- }
2304
- }, _callee20, this, [[1, 15]]);
2305
- }));
2306
- function scanCode(_x13, _x14) {
2307
- return _scanCode.apply(this, arguments);
2308
- }
2309
- return scanCode;
2310
- }() /** 获取当前折扣列表(包装 order.getDiscountList) */
2311
- }, {
2312
- key: "getDiscountList",
2313
- value: function getDiscountList() {
2314
- if (!this.store.order) return [];
2315
- return this.store.order.getDiscountList();
2316
- }
2317
-
2318
- /** 勾选/取消勾选某张折扣券,重新计算折扣并持久化 */
2319
- }, {
2320
- key: "setDiscountSelected",
2321
- value: (function () {
2322
- var _setDiscountSelected = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
2323
- var _tempOrder$holder, _this$store$order$get2, _this$store$order$get3, list, beforeTarget, updated, updatedTarget, tempOrder, orderStore, discountModule, rulesModule, holders, nextDiscountList, _tempOrder$holder2, result, beforeSelectedIds, _iterator14, _step14, d, afterApplyTarget, finalSummary, finalProduct, finalTarget;
2324
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2325
- while (1) switch (_context21.prev = _context21.next) {
2326
- case 0:
2327
- this.logMethodStart('setDiscountSelected', params);
2328
- _context21.prev = 1;
2329
- if (this.store.order) {
2330
- _context21.next = 4;
2331
- break;
2332
- }
2333
- throw new Error('order 模块未初始化');
2334
- case 4:
2335
- list = this.store.order.getDiscountList();
2336
- beforeTarget = list.find(function (d) {
2337
- return d.id === params.discountId;
2338
- }) || null;
2339
- updated = list.map(function (d) {
2340
- return d.id === params.discountId ? _objectSpread(_objectSpread({}, d), {}, {
2341
- isSelected: params.isSelected,
2342
- isManualSelect: !params.isSelected
2343
- }) : d;
2344
- });
2345
- updatedTarget = updated.find(function (d) {
2346
- return d.id === params.discountId;
2347
- }) || null;
2348
- tempOrder = this.store.order.ensureTempOrder();
2349
- orderStore = this.store.order.store || {};
2350
- discountModule = orderStore.discount;
2351
- rulesModule = orderStore.rules;
2352
- holders = (_tempOrder$holder = tempOrder.holder) !== null && _tempOrder$holder !== void 0 && _tempOrder$holder.form_record_id ? [{
2353
- form_record_id: tempOrder.holder.form_record_id
2354
- }] : [];
2355
- nextDiscountList = updated;
2356
- _context21.next = 16;
2357
- return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(updated);
2358
- case 16:
2359
- if (rulesModule) {
2360
- result = rulesModule.calcDiscount({
2361
- productList: tempOrder.products,
2362
- discountList: updated,
2363
- holders: holders,
2364
- isFormSubject: !!((_tempOrder$holder2 = tempOrder.holder) !== null && _tempOrder$holder2 !== void 0 && _tempOrder$holder2.type) && tempOrder.holder.type === 'form'
2365
- }, {
2366
- discountId: params.discountId,
2367
- isSelected: params.isSelected
2368
- }) || {
2369
- productList: tempOrder.products,
2370
- discountList: updated
2371
- };
2372
- if (result !== null && result !== void 0 && result.productList) {
2373
- tempOrder.products = result.productList;
2374
- }
2375
- if (result !== null && result !== void 0 && result.discountList) {
2376
- nextDiscountList = result.discountList;
2377
- if (!params.isSelected) {
2378
- beforeSelectedIds = new Set(updated.filter(function (d) {
2379
- return d.isSelected;
2380
- }).map(function (d) {
2381
- return d.id;
2382
- }));
2383
- _iterator14 = _createForOfIteratorHelper(nextDiscountList);
2384
- try {
2385
- for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
2386
- d = _step14.value;
2387
- if (d.isSelected && !beforeSelectedIds.has(d.id)) {
2388
- d.isSelected = false;
2389
- }
2390
- }
2391
- } catch (err) {
2392
- _iterator14.e(err);
2393
- } finally {
2394
- _iterator14.f();
2395
- }
2396
- }
2397
- }
2398
- }
2399
- this.normalizeDiscountedOrderPrices(nextDiscountList);
2400
- OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
2401
- _context21.next = 21;
2402
- return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
2403
- case 21:
2404
- tempOrder.discount_list = (nextDiscountList || []).filter(function (d) {
2405
- return d.isSelected;
2406
- });
2407
- afterApplyTarget = this.store.order.getDiscountList().find(function (d) {
2408
- return d.id === params.discountId;
2409
- }) || null;
2410
- _context21.next = 25;
2411
- return this.store.order.recalculateSummary({
2412
- createIfMissing: true
2413
- });
2414
- case 25:
2415
- this.store.order.persistTempOrder();
2416
- finalSummary = ((_this$store$order$get2 = this.store.order.getTempOrder()) === null || _this$store$order$get2 === void 0 ? void 0 : _this$store$order$get2.summary) || null;
2417
- finalProduct = ((_this$store$order$get3 = this.store.order.getTempOrder()) === null || _this$store$order$get3 === void 0 || (_this$store$order$get3 = _this$store$order$get3.products) === null || _this$store$order$get3 === void 0 ? void 0 : _this$store$order$get3[0]) || null;
2418
- this.logMethodSuccess('setDiscountSelected', params);
2419
- finalTarget = this.store.order.getDiscountList().find(function (d) {
2420
- return d.id === params.discountId;
2421
- }) || null;
2422
- return _context21.abrupt("return", this.store.order.getDiscountList());
2423
- case 33:
2424
- _context21.prev = 33;
2425
- _context21.t0 = _context21["catch"](1);
2426
- this.logMethodError('setDiscountSelected', _context21.t0);
2427
- throw _context21.t0;
2428
- case 37:
2429
- case "end":
2430
- return _context21.stop();
2431
- }
2432
- }, _callee21, this, [[1, 33]]);
2433
- }));
2434
- function setDiscountSelected(_x15) {
2435
- return _setDiscountSelected.apply(this, arguments);
2436
- }
2437
- return setDiscountSelected;
2438
- }()
2439
- /**
2440
- * 统一 VenueBooking 折扣后的订单行价。
2441
- *
2442
- * Rules 的 `discount_list.amount` 是已经按适用规则计算出的每件优惠额;它是这里唯一
2443
- * 的折扣金额来源。使用智能定价写入的 source_product_price 减去该金额,再同步
2444
- * selling_price 与 Summary 使用的 main_product_selling_price,避免 UI 的购物车行价、
2445
- * 小计和提交订单各自读取到不同的价格字段。
2446
- */
2447
- )
2448
- }, {
2449
- key: "normalizeDiscountedOrderPrices",
2450
- value: function normalizeDiscountedOrderPrices(discountList) {
2451
- var order = this.store.order;
2452
- if (!order) return;
2453
- var tempOrder = order.ensureTempOrder();
2454
- var selectedResourceIds = new Set((discountList || []).filter(function (discount) {
2455
- return discount.isSelected;
2456
- }).map(function (discount) {
2457
- return discount.id;
2458
- }));
2459
- var _iterator15 = _createForOfIteratorHelper(tempOrder.products),
2460
- _step15;
2461
- try {
2462
- for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
2463
- var _product$_origin, _metadata$source_prod, _product$original_pri;
2464
- var product = _step15.value;
2465
- // 手动改价商品不参与券流程归一化,保留手工价格。
2466
- if ((_product$_origin = product._origin) !== null && _product$_origin !== void 0 && _product$_origin.isManualDiscount) continue;
2467
-
2468
- // Rules 可能保留已取消折扣的明细;先使行级明细和当前选择状态一致。
2469
- product.discount_list = (product.discount_list || []).filter(function (detail) {
2470
- var _detail$discount$reso, _detail$discount;
2471
- var resourceId = (_detail$discount$reso = (_detail$discount = detail.discount) === null || _detail$discount === void 0 ? void 0 : _detail$discount.resource_id) !== null && _detail$discount$reso !== void 0 ? _detail$discount$reso : detail.id;
2472
- return resourceId != null && selectedResourceIds.has(resourceId);
2473
- });
2474
- var totalPerUnitDiscount = (product.discount_list || []).reduce(function (total, detail) {
2475
- return total.plus(detail.amount || 0);
2476
- }, new Decimal(0));
2477
- var metadata = product.metadata || (product.metadata = {});
2478
- var optionSum = sumOptionUnitPrice(product.product_option_item);
2479
- var sourcePrice = (_metadata$source_prod = metadata.source_product_price) !== null && _metadata$source_prod !== void 0 ? _metadata$source_prod : metadata.main_product_original_price != null ? new Decimal(Number(metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : (_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : '0';
2480
- var nextSourceSellingPrice = Decimal.max(0, new Decimal(Number(sourcePrice) || 0).minus(totalPerUnitDiscount)).toDecimalPlaces(2).toString();
2481
- var nextMainSellingPrice = new Decimal(Number(nextSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
2482
- metadata.main_product_selling_price = nextMainSellingPrice;
2483
- metadata.price_schema_version = 2;
2484
- product.selling_price = composeLinePrice({
2485
- mainPrice: nextMainSellingPrice,
2486
- bundle: product.product_bundle
2487
- });
2488
- }
2489
- } catch (err) {
2490
- _iterator15.e(err);
2491
- } finally {
2492
- _iterator15.f();
2493
- }
2494
- }
2495
- }, {
2496
- key: "addNewOrder",
2497
- value: function () {
2498
- var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
2499
- var tempOrder;
2500
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2501
- while (1) switch (_context22.prev = _context22.next) {
2502
- case 0:
2503
- this.logMethodStart('addNewOrder');
2504
- _context22.prev = 1;
2505
- if (this.store.order) {
2506
- _context22.next = 4;
2507
- break;
2508
- }
2509
- throw new Error('order 模块未初始化');
2510
- case 4:
2511
- _context22.next = 6;
2512
- return this.store.order.addNewOrder();
2513
- case 6:
2514
- tempOrder = _context22.sent;
2515
- this.logMethodSuccess('addNewOrder', {
2516
- productCount: tempOrder.products.length
2517
- });
2518
- return _context22.abrupt("return", tempOrder);
2519
- case 11:
2520
- _context22.prev = 11;
2521
- _context22.t0 = _context22["catch"](1);
2522
- this.logMethodError('addNewOrder', _context22.t0);
2523
- throw _context22.t0;
2524
- case 15:
2525
- case "end":
2526
- return _context22.stop();
2527
- }
2528
- }, _callee22, this, [[1, 11]]);
2529
- }));
2530
- function addNewOrder() {
2531
- return _addNewOrder.apply(this, arguments);
2532
- }
2533
- return addNewOrder;
2534
- }()
2535
- }, {
2536
- key: "getOrderProducts",
2537
- value: function getOrderProducts() {
2538
- if (!this.store.order) throw new Error('order 模块未初始化');
2539
- return this.store.order.getOrderProducts();
2540
- }
2541
- }, {
2542
- key: "getSummary",
2543
- value: function () {
2544
- var _getSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
2545
- var summary;
2546
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2547
- while (1) switch (_context23.prev = _context23.next) {
2548
- case 0:
2549
- this.logMethodStart('getSummary');
2550
- _context23.prev = 1;
2551
- if (this.store.order) {
2552
- _context23.next = 4;
2553
- break;
2554
- }
2555
- throw new Error('order 模块未初始化');
2556
- case 4:
2557
- _context23.next = 6;
2558
- return this.store.order.getScanOrderSummary();
2559
- case 6:
2560
- summary = _context23.sent;
2561
- this.logMethodSuccess('getSummary', {
2562
- totalAmount: summary.total_amount
2563
- });
2564
- return _context23.abrupt("return", summary);
2565
- case 11:
2566
- _context23.prev = 11;
2567
- _context23.t0 = _context23["catch"](1);
2568
- this.logMethodError('getSummary', _context23.t0);
2569
- throw _context23.t0;
2570
- case 15:
2571
- case "end":
2572
- return _context23.stop();
2573
- }
2574
- }, _callee23, this, [[1, 11]]);
2575
- }));
2576
- function getSummary() {
2577
- return _getSummary.apply(this, arguments);
2578
- }
2579
- return getSummary;
2580
- }()
2581
- }, {
2582
- key: "submitOrder",
2583
- value: function () {
2584
- var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
2585
- var _this$otherParams18, _this$otherParams19, _this$otherParams20, _this$otherParams21, _tempOrder$products2, result, tempOrder;
2586
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2587
- while (1) switch (_context24.prev = _context24.next) {
2588
- case 0:
2589
- this.logMethodStart('submitOrder');
2590
- _context24.prev = 1;
2591
- _context24.next = 4;
2592
- return this.validateBeforeSubmitByItemRule();
2593
- case 4:
2594
- if (this.store.order) {
2595
- _context24.next = 6;
2596
- break;
2597
- }
2598
- throw new Error('venueBooking解决方案需要 order 模块支持');
2599
- case 6:
2600
- _context24.next = 8;
2601
- return this.store.order.submitTempOrder({
2602
- cacheId: this.cacheId,
2603
- platform: (_this$otherParams18 = this.otherParams) === null || _this$otherParams18 === void 0 ? void 0 : _this$otherParams18.platform,
2604
- businessCode: (_this$otherParams19 = this.otherParams) === null || _this$otherParams19 === void 0 ? void 0 : _this$otherParams19.businessCode,
2605
- channel: (_this$otherParams20 = this.otherParams) === null || _this$otherParams20 === void 0 ? void 0 : _this$otherParams20.channel,
2606
- type: (_this$otherParams21 = this.otherParams) === null || _this$otherParams21 === void 0 ? void 0 : _this$otherParams21.type
2607
- });
2608
- case 8:
2609
- result = _context24.sent;
2610
- tempOrder = this.store.order.getTempOrder();
2611
- this.logMethodSuccess('submitOrder', {
2612
- productCount: (tempOrder === null || tempOrder === void 0 || (_tempOrder$products2 = tempOrder.products) === null || _tempOrder$products2 === void 0 ? void 0 : _tempOrder$products2.length) || 0
2613
- });
2614
- return _context24.abrupt("return", result);
2615
- case 14:
2616
- _context24.prev = 14;
2617
- _context24.t0 = _context24["catch"](1);
2618
- this.logMethodError('submitOrder', _context24.t0);
2619
- throw _context24.t0;
2620
- case 18:
2621
- case "end":
2622
- return _context24.stop();
2623
- }
2624
- }, _callee24, this, [[1, 14]]);
2625
- }));
2626
- function submitOrder() {
2627
- return _submitOrder.apply(this, arguments);
2628
- }
2629
- return submitOrder;
2630
- }()
2631
- /**
2632
- * 0 元订单免费领取(非定金场景)
2633
- * 与 appointment getFreeProduct 同接口:POST /pay/order/free-pay/:id
2634
- */
2635
- }, {
2636
- key: "submitFreeOrder",
2637
- value: (function () {
2638
- var _submitFreeOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(id) {
2639
- var res;
2640
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2641
- while (1) switch (_context25.prev = _context25.next) {
2642
- case 0:
2643
- this.logMethodStart('submitFreeOrder', {
2644
- id: id
2645
- });
2646
- _context25.prev = 1;
2647
- if (id) {
2648
- _context25.next = 4;
2649
- break;
2650
- }
2651
- throw new Error('订单 ID 不能为空');
2652
- case 4:
2653
- _context25.next = 6;
2654
- return this.request.post("/pay/order/free-pay/".concat(id));
2655
- case 6:
2656
- res = _context25.sent;
2657
- this.logMethodSuccess('submitFreeOrder', {
2658
- id: id,
2659
- status: res === null || res === void 0 ? void 0 : res.status
2660
- });
2661
- return _context25.abrupt("return", res);
2662
- case 11:
2663
- _context25.prev = 11;
2664
- _context25.t0 = _context25["catch"](1);
2665
- this.logMethodError('submitFreeOrder', _context25.t0);
2666
- throw _context25.t0;
2667
- case 15:
2668
- case "end":
2669
- return _context25.stop();
2670
- }
2671
- }, _callee25, this, [[1, 11]]);
2672
- }));
2673
- function submitFreeOrder(_x16) {
2674
- return _submitFreeOrder.apply(this, arguments);
2675
- }
2676
- return submitFreeOrder;
2677
- }())
2678
- }, {
2679
- key: "addProductToOrder",
2680
- value: function () {
2681
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(product) {
2682
- var _product$metadata3, _product$metadata4, smartPrice, products;
2683
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2684
- while (1) switch (_context26.prev = _context26.next) {
2685
- case 0:
2686
- this.logMethodStart('addProductToOrder', {
2687
- product_id: product.product_id,
2688
- product_variant_id: product.product_variant_id
2689
- });
2690
- _context26.prev = 1;
2691
- if (this.store.order) {
2692
- _context26.next = 4;
2693
- break;
2694
- }
2695
- throw new Error('order 模块未初始化');
2696
- case 4:
2697
- if (!((_product$metadata3 = product.metadata) !== null && _product$metadata3 !== void 0 && _product$metadata3.venue_booking) && product.product_id != null) {
2698
- smartPrice = getPriceForProductAtDatetime({
2699
- products: this.getAllProductsForSmartPricing(),
2700
- context: this.buildSmartPricingContext(),
2701
- productId: Number(product.product_id),
2702
- datetime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
2703
- fallbackPrice: product.selling_price
2704
- });
2705
- product.selling_price = smartPrice;
2706
- product.original_price = smartPrice;
2707
- } else if (product.selling_price != null && !((_product$metadata4 = product.metadata) !== null && _product$metadata4 !== void 0 && _product$metadata4.venue_booking)) {
2708
- product.original_price = product.selling_price;
2709
- }
2710
- _context26.next = 7;
2711
- return this.store.order.addProductToOrder(product);
2712
- case 7:
2713
- products = _context26.sent;
2714
- _context26.next = 10;
2715
- return this.refreshItemRuleQuantityLimits();
2716
- case 10:
2717
- _context26.next = 12;
2718
- return this.refreshCartValidationPassed();
2719
- case 12:
2720
- this.logMethodSuccess('addProductToOrder', {
2721
- productCount: products.length
2722
- });
2723
- return _context26.abrupt("return", products);
2724
- case 16:
2725
- _context26.prev = 16;
2726
- _context26.t0 = _context26["catch"](1);
2727
- this.logMethodError('addProductToOrder', _context26.t0);
2728
- throw _context26.t0;
2729
- case 20:
2730
- case "end":
2731
- return _context26.stop();
2732
- }
2733
- }, _callee26, this, [[1, 16]]);
2734
- }));
2735
- function addProductToOrder(_x17) {
2736
- return _addProductToOrder.apply(this, arguments);
2737
- }
2738
- return addProductToOrder;
2739
- }()
2740
- }, {
2741
- key: "updateProductInOrder",
2742
- value: function () {
2743
- var _updateProductInOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
2744
- var products;
2745
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2746
- while (1) switch (_context27.prev = _context27.next) {
2747
- case 0:
2748
- this.logMethodStart('updateProductInOrder', {
2749
- product_id: params.product_id,
2750
- product_variant_id: params.product_variant_id
2751
- });
2752
- _context27.prev = 1;
2753
- if (this.store.order) {
2754
- _context27.next = 4;
2755
- break;
2756
- }
2757
- throw new Error('order 模块未初始化');
2758
- case 4:
2759
- _context27.next = 6;
2760
- return this.store.order.updateProductInOrder(params);
2761
- case 6:
2762
- products = _context27.sent;
2763
- _context27.next = 9;
2764
- return this.refreshItemRuleQuantityLimits();
2765
- case 9:
2766
- _context27.next = 11;
2767
- return this.refreshCartValidationPassed();
2768
- case 11:
2769
- this.logMethodSuccess('updateProductInOrder', {
2770
- productCount: products.length
2771
- });
2772
- return _context27.abrupt("return", products);
2773
- case 15:
2774
- _context27.prev = 15;
2775
- _context27.t0 = _context27["catch"](1);
2776
- this.logMethodError('updateProductInOrder', _context27.t0);
2777
- throw _context27.t0;
2778
- case 19:
2779
- case "end":
2780
- return _context27.stop();
2781
- }
2782
- }, _callee27, this, [[1, 15]]);
2783
- }));
2784
- function updateProductInOrder(_x18) {
2785
- return _updateProductInOrder.apply(this, arguments);
2786
- }
2787
- return updateProductInOrder;
2788
- }()
2789
- }, {
2790
- key: "removeProductFromOrder",
2791
- value: function () {
2792
- var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(identity) {
2793
- var _this$store$order$get4, _this$store$order8, _this$store$order$ens, _this$store$order9, _tempOrder$bookings, tempOrder, products, _tempOrder$bookings2, _tempOrder$bookings3, venueProductUids, venueBookingUids, _iterator16, _step16, _product$metadata5, _product$metadata6, product, beforeBookingCount, _this$store$order$per, _this$store$order10;
2794
- return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2795
- while (1) switch (_context28.prev = _context28.next) {
2796
- case 0:
2797
- this.logMethodStart('removeProductFromOrder', {
2798
- product_id: identity.product_id,
2799
- product_variant_id: identity.product_variant_id
2800
- });
2801
- _context28.prev = 1;
2802
- if (this.store.order) {
2803
- _context28.next = 4;
2804
- break;
2805
- }
2806
- throw new Error('order 模块未初始化');
2807
- case 4:
2808
- tempOrder = ((_this$store$order$get4 = (_this$store$order8 = this.store.order).getTempOrder) === null || _this$store$order$get4 === void 0 ? void 0 : _this$store$order$get4.call(_this$store$order8)) || ((_this$store$order$ens = (_this$store$order9 = this.store.order).ensureTempOrder) === null || _this$store$order$ens === void 0 ? void 0 : _this$store$order$ens.call(_this$store$order9));
2809
- _context28.next = 7;
2810
- return this.store.order.removeProductFromOrder(identity);
2811
- case 7:
2812
- products = _context28.sent;
2813
- if (!(tempOrder !== null && tempOrder !== void 0 && (_tempOrder$bookings = tempOrder.bookings) !== null && _tempOrder$bookings !== void 0 && _tempOrder$bookings.length)) {
2814
- _context28.next = 33;
2815
- break;
2816
- }
2817
- venueProductUids = new Set();
2818
- venueBookingUids = new Set();
2819
- _iterator16 = _createForOfIteratorHelper(tempOrder.products || []);
2820
- _context28.prev = 12;
2821
- _iterator16.s();
2822
- case 14:
2823
- if ((_step16 = _iterator16.n()).done) {
2824
- _context28.next = 22;
2825
- break;
2826
- }
2827
- product = _step16.value;
2828
- if (product !== null && product !== void 0 && (_product$metadata5 = product.metadata) !== null && _product$metadata5 !== void 0 && _product$metadata5.venue_booking) {
2829
- _context28.next = 18;
2830
- break;
2831
- }
2832
- return _context28.abrupt("continue", 20);
2833
- case 18:
2834
- if (product.identity_key) venueProductUids.add(String(product.identity_key));
2835
- if ((_product$metadata6 = product.metadata) !== null && _product$metadata6 !== void 0 && _product$metadata6.booking_uid) {
2836
- venueBookingUids.add(String(product.metadata.booking_uid));
2837
- }
2838
- case 20:
2839
- _context28.next = 14;
2840
- break;
2841
- case 22:
2842
- _context28.next = 27;
2843
- break;
2844
- case 24:
2845
- _context28.prev = 24;
2846
- _context28.t0 = _context28["catch"](12);
2847
- _iterator16.e(_context28.t0);
2848
- case 27:
2849
- _context28.prev = 27;
2850
- _iterator16.f();
2851
- return _context28.finish(27);
2852
- case 30:
2853
- beforeBookingCount = ((_tempOrder$bookings2 = tempOrder.bookings) === null || _tempOrder$bookings2 === void 0 ? void 0 : _tempOrder$bookings2.length) || 0;
2854
- tempOrder.bookings = (tempOrder.bookings || []).filter(function (booking) {
2855
- var _booking$metadata, _booking$metadata2;
2856
- if (!(booking !== null && booking !== void 0 && (_booking$metadata = booking.metadata) !== null && _booking$metadata !== void 0 && _booking$metadata.venue_booking)) return true;
2857
- if (booking.product_uid) {
2858
- return venueProductUids.has(String(booking.product_uid));
2859
- }
2860
- var bookingUid = (_booking$metadata2 = booking.metadata) === null || _booking$metadata2 === void 0 ? void 0 : _booking$metadata2.unique_identification_number;
2861
- if (bookingUid) return venueBookingUids.has(String(bookingUid));
2862
- return true;
2863
- });
2864
- if ((((_tempOrder$bookings3 = tempOrder.bookings) === null || _tempOrder$bookings3 === void 0 ? void 0 : _tempOrder$bookings3.length) || 0) !== beforeBookingCount) {
2865
- (_this$store$order$per = (_this$store$order10 = this.store.order).persistTempOrder) === null || _this$store$order$per === void 0 || _this$store$order$per.call(_this$store$order10);
2866
- }
2867
- case 33:
2868
- _context28.next = 35;
2869
- return this.refreshItemRuleQuantityLimits();
2870
- case 35:
2871
- _context28.next = 37;
2872
- return this.refreshCartValidationPassed();
2873
- case 37:
2874
- this.logMethodSuccess('removeProductFromOrder', {
2875
- productCount: products.length
2876
- });
2877
- return _context28.abrupt("return", products);
2878
- case 41:
2879
- _context28.prev = 41;
2880
- _context28.t1 = _context28["catch"](1);
2881
- this.logMethodError('removeProductFromOrder', _context28.t1);
2882
- throw _context28.t1;
2883
- case 45:
2884
- case "end":
2885
- return _context28.stop();
2886
- }
2887
- }, _callee28, this, [[1, 41], [12, 24, 27, 30]]);
2888
- }));
2889
- function removeProductFromOrder(_x19) {
2890
- return _removeProductFromOrder.apply(this, arguments);
2891
- }
2892
- return removeProductFromOrder;
2893
- }()
2894
- }, {
2895
- key: "getProductList",
2896
- value: function () {
2897
- var _getProductList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
2898
- var result;
2899
- return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2900
- while (1) switch (_context29.prev = _context29.next) {
2901
- case 0:
2902
- if (!this.productsLoaded) {
2903
- _context29.next = 3;
2904
- break;
2905
- }
2906
- this.logPricingDiagnostics('[VenueBooking] getProductList loadAllProducts skipped', {
2907
- reason: 'productsLoaded is true',
2908
- addonProductCount: this.getAddonProductsList().length,
2909
- smartPricingProductCatalogCount: this.smartPricingProductCatalog.length
2910
- });
2911
- return _context29.abrupt("return", attachItemRuleLimitsToTopLevelProducts(this.getAddonProductsList(), this.store.itemRuleQuantityLimits || []));
2912
- case 3:
2913
- _context29.next = 5;
2914
- return this.loadAllProducts();
2915
- case 5:
2916
- result = _context29.sent;
2917
- return _context29.abrupt("return", attachItemRuleLimitsToTopLevelProducts(result.addonProducts, this.store.itemRuleQuantityLimits || []));
2918
- case 7:
2919
- case "end":
2920
- return _context29.stop();
2921
- }
2922
- }, _callee29, this);
2923
- }));
2924
- function getProductList() {
2925
- return _getProductList.apply(this, arguments);
2926
- }
2927
- return getProductList;
2928
- }() // ─── ItemRule 引擎 ───
2929
- }, {
2930
- key: "loadOpenDataConfig",
2931
- value: function () {
2932
- var _loadOpenDataConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
2933
- var lastFetchedAt, cachedData, openDataConfig;
2934
- return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2935
- while (1) switch (_context30.prev = _context30.next) {
2936
- case 0:
2937
- if (this.store.openData) {
2938
- _context30.next = 2;
2939
- break;
2940
- }
2941
- throw new Error('openData 模块未初始化');
2942
- case 2:
2943
- lastFetchedAt = this.store.openData.getLastFetchedAt();
2944
- cachedData = this.store.openData.getOpenData();
2945
- if (!(cachedData && lastFetchedAt && Date.now() - lastFetchedAt < VenueBookingImpl.OPEN_DATA_CACHE_TTL)) {
2946
- _context30.next = 7;
2947
- break;
2948
- }
2949
- this.otherParams.openData = cachedData;
2950
- return _context30.abrupt("return", cachedData);
2951
- case 7:
2952
- if (!this.loadOpenDataConfigInFlight) {
2953
- _context30.next = 11;
2954
- break;
2955
- }
2956
- _context30.next = 10;
2957
- return this.loadOpenDataConfigInFlight;
2958
- case 10:
2959
- return _context30.abrupt("return", _context30.sent);
2960
- case 11:
2961
- this.loadOpenDataConfigInFlight = this.store.openData.fetchOpenData({
2962
- scope: 'board',
2963
- target: 'venue_booking+online_store',
2964
- section_code: [].concat(OPEN_DATA_SECTION_CODES)
2965
- });
2966
- _context30.prev = 12;
2967
- _context30.next = 15;
2968
- return this.loadOpenDataConfigInFlight;
2969
- case 15:
2970
- openDataConfig = _context30.sent;
2971
- this.otherParams.openData = openDataConfig;
2972
- return _context30.abrupt("return", openDataConfig);
2973
- case 18:
2974
- _context30.prev = 18;
2975
- this.loadOpenDataConfigInFlight = null;
2976
- return _context30.finish(18);
2977
- case 21:
2978
- case "end":
2979
- return _context30.stop();
2980
- }
2981
- }, _callee30, this, [[12,, 18, 21]]);
2982
- }));
2983
- function loadOpenDataConfig() {
2984
- return _loadOpenDataConfig.apply(this, arguments);
2985
- }
2986
- return loadOpenDataConfig;
2987
- }()
2988
- }, {
2989
- key: "loadRuntimeConfigs",
2990
- value: function () {
2991
- var _loadRuntimeConfigs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
2992
- var itemRuleConfigs;
2993
- return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2994
- while (1) switch (_context31.prev = _context31.next) {
2995
- case 0:
2996
- _context31.next = 2;
2997
- return this.loadOpenDataConfig();
2998
- case 2:
2999
- _context31.next = 4;
3000
- return this.ensureItemRuleConfigsLoaded();
3001
- case 4:
3002
- itemRuleConfigs = _context31.sent;
3003
- this.logMethodSuccess('loadRuntimeConfigs', {
3004
- itemRuleCount: itemRuleConfigs.length
3005
- });
3006
- return _context31.abrupt("return", {
3007
- itemRuleConfigs: itemRuleConfigs
3008
- });
3009
- case 7:
3010
- case "end":
3011
- return _context31.stop();
3012
- }
3013
- }, _callee31, this);
3014
- }));
3015
- function loadRuntimeConfigs() {
3016
- return _loadRuntimeConfigs.apply(this, arguments);
3017
- }
3018
- return loadRuntimeConfigs;
3019
- }()
3020
- }, {
3021
- key: "fetchItemRuleConfigsByModelIds",
3022
- value: function () {
3023
- var _fetchItemRuleConfigsByModelIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(strategyModelIds) {
3024
- var result, configs;
3025
- return _regeneratorRuntime().wrap(function _callee32$(_context32) {
3026
- while (1) switch (_context32.prev = _context32.next) {
3027
- case 0:
3028
- this.logMethodStart('fetchItemRuleConfigsByModelIds', {
3029
- strategyModelIds: strategyModelIds
3030
- });
3031
- if (strategyModelIds.length) {
3032
- _context32.next = 3;
3033
- break;
3034
- }
3035
- return _context32.abrupt("return", []);
3036
- case 3:
3037
- _context32.prev = 3;
3038
- _context32.next = 6;
3039
- return this.request.get('/promotion', {
3040
- skip: 1,
3041
- num: 99,
3042
- status: 'active',
3043
- ids: strategyModelIds
3044
- });
3045
- case 6:
3046
- result = _context32.sent;
3047
- configs = [];
3048
- if (result.code === 200) {
3049
- configs = result.data.list.map(function (item) {
3050
- return item.metadata;
3051
- });
3052
- }
3053
- this.logMethodSuccess('fetchItemRuleConfigsByModelIds', {
3054
- strategyModelIds: strategyModelIds,
3055
- strategyCount: configs.length
3056
- });
3057
- return _context32.abrupt("return", configs);
3058
- case 13:
3059
- _context32.prev = 13;
3060
- _context32.t0 = _context32["catch"](3);
3061
- this.logMethodError('fetchItemRuleConfigsByModelIds', _context32.t0, {
3062
- strategyModelIds: strategyModelIds
3063
- });
3064
- return _context32.abrupt("return", []);
3065
- case 17:
3066
- case "end":
3067
- return _context32.stop();
3068
- }
3069
- }, _callee32, this, [[3, 13]]);
3070
- }));
3071
- function fetchItemRuleConfigsByModelIds(_x20) {
3072
- return _fetchItemRuleConfigsByModelIds.apply(this, arguments);
3073
- }
3074
- return fetchItemRuleConfigsByModelIds;
3075
- }()
3076
- }, {
3077
- key: "buildPrefillProductSourceMap",
3078
- value: function () {
3079
- var _buildPrefillProductSourceMap = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
3080
- var sourceMap, productList, visited, collectFromValue;
3081
- return _regeneratorRuntime().wrap(function _callee33$(_context33) {
3082
- while (1) switch (_context33.prev = _context33.next) {
3083
- case 0:
3084
- sourceMap = new Map();
3085
- _context33.prev = 1;
3086
- _context33.next = 4;
3087
- return this.getProductList();
3088
- case 4:
3089
- productList = _context33.sent;
3090
- if (Array.isArray(productList)) {
3091
- _context33.next = 7;
3092
- break;
3093
- }
3094
- return _context33.abrupt("return", sourceMap);
3095
- case 7:
3096
- visited = new Set();
3097
- collectFromValue = function collectFromValue(value) {
3098
- var _node$product_id;
3099
- if (!value || _typeof(value) !== 'object') return;
3100
- if (visited.has(value)) return;
3101
- visited.add(value);
3102
- if (Array.isArray(value)) {
3103
- var _iterator17 = _createForOfIteratorHelper(value),
3104
- _step17;
3105
- try {
3106
- for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
3107
- var item = _step17.value;
3108
- collectFromValue(item);
3109
- }
3110
- } catch (err) {
3111
- _iterator17.e(err);
3112
- } finally {
3113
- _iterator17.f();
3114
- }
3115
- return;
3116
- }
3117
- var node = value;
3118
- var rawProductId = (_node$product_id = node.product_id) !== null && _node$product_id !== void 0 ? _node$product_id : node.id;
3119
- var productId = Number(rawProductId);
3120
- if (Number.isFinite(productId) && productId > 0) {
3121
- var _ref3, _node$product_variant;
3122
- var productVariantId = Number((_ref3 = (_node$product_variant = node.product_variant_id) !== null && _node$product_variant !== void 0 ? _node$product_variant : node.variant_id) !== null && _ref3 !== void 0 ? _ref3 : 0);
3123
- var normalizedVariantId = Number.isNaN(productVariantId) ? 0 : productVariantId;
3124
- var key = buildProductKey(productId, normalizedVariantId);
3125
- if (!sourceMap.has(key)) sourceMap.set(key, node);
3126
- }
3127
- for (var _i4 = 0, _Object$values = Object.values(node); _i4 < _Object$values.length; _i4++) {
3128
- var childValue = _Object$values[_i4];
3129
- if (childValue && _typeof(childValue) === 'object') collectFromValue(childValue);
3130
- }
3131
- };
3132
- collectFromValue(productList);
3133
- _context33.next = 15;
3134
- break;
3135
- case 12:
3136
- _context33.prev = 12;
3137
- _context33.t0 = _context33["catch"](1);
3138
- this.logMethodError('buildPrefillProductSourceMap', _context33.t0);
3139
- case 15:
3140
- return _context33.abrupt("return", sourceMap);
3141
- case 16:
3142
- case "end":
3143
- return _context33.stop();
3144
- }
3145
- }, _callee33, this, [[1, 12]]);
3146
- }));
3147
- function buildPrefillProductSourceMap() {
3148
- return _buildPrefillProductSourceMap.apply(this, arguments);
3149
- }
3150
- return buildPrefillProductSourceMap;
3151
- }()
3152
- }, {
3153
- key: "getItemRuleRuntimeConfig",
3154
- value: function getItemRuleRuntimeConfig() {
3155
- return this.itemRuleRuntimeConfig || {};
3156
- }
3157
- }, {
3158
- key: "ensureItemRuleConfigsLoaded",
3159
- value: function () {
3160
- var _ensureItemRuleConfigsLoaded = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35() {
3161
- var _this11 = this;
3162
- return _regeneratorRuntime().wrap(function _callee35$(_context35) {
3163
- while (1) switch (_context35.prev = _context35.next) {
3164
- case 0:
3165
- if (!(this.itemRuleConfigs.length > 0)) {
3166
- _context35.next = 2;
3167
- break;
3168
- }
3169
- return _context35.abrupt("return", this.itemRuleConfigs);
3170
- case 2:
3171
- if (!this.itemRuleConfigsPromise) {
3172
- _context35.next = 4;
3173
- break;
3174
- }
3175
- return _context35.abrupt("return", this.itemRuleConfigsPromise);
3176
- case 4:
3177
- this.itemRuleConfigsPromise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34() {
3178
- var runtimeConfig, staticConfigs;
3179
- return _regeneratorRuntime().wrap(function _callee34$(_context34) {
3180
- while (1) switch (_context34.prev = _context34.next) {
3181
- case 0:
3182
- runtimeConfig = _this11.getItemRuleRuntimeConfig();
3183
- staticConfigs = normalizeItemRuleStrategies(runtimeConfig.strategyConfigs);
3184
- if (!(staticConfigs.length > 0)) {
3185
- _context34.next = 6;
3186
- break;
3187
- }
3188
- _this11.itemRuleConfigs = staticConfigs;
3189
- _this11.itemRuleEvaluator.setStrategyConfigs(staticConfigs);
3190
- return _context34.abrupt("return", _this11.itemRuleConfigs);
3191
- case 6:
3192
- _this11.itemRuleConfigs = [];
3193
- _this11.itemRuleEvaluator.setStrategyConfigs([]);
3194
- return _context34.abrupt("return", _this11.itemRuleConfigs);
3195
- case 9:
3196
- case "end":
3197
- return _context34.stop();
3198
- }
3199
- }, _callee34);
3200
- }))();
3201
- _context35.next = 7;
3202
- return this.itemRuleConfigsPromise;
3203
- case 7:
3204
- return _context35.abrupt("return", _context35.sent);
3205
- case 8:
3206
- case "end":
3207
- return _context35.stop();
3208
- }
3209
- }, _callee35, this);
3210
- }));
3211
- function ensureItemRuleConfigsLoaded() {
3212
- return _ensureItemRuleConfigsLoaded.apply(this, arguments);
3213
- }
3214
- return ensureItemRuleConfigsLoaded;
3215
- }()
3216
- }, {
3217
- key: "refreshItemRuleQuantityLimits",
3218
- value: function () {
3219
- var _refreshItemRuleQuantityLimits = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36() {
3220
- var strategyConfigs, businessData, limits;
3221
- return _regeneratorRuntime().wrap(function _callee36$(_context36) {
3222
- while (1) switch (_context36.prev = _context36.next) {
3223
- case 0:
3224
- _context36.prev = 0;
3225
- _context36.next = 3;
3226
- return this.ensureItemRuleConfigsLoaded();
3227
- case 3:
3228
- strategyConfigs = _context36.sent;
3229
- if (strategyConfigs.length) {
3230
- _context36.next = 7;
3231
- break;
3232
- }
3233
- this.store.itemRuleQuantityLimits = [];
3234
- return _context36.abrupt("return", []);
3235
- case 7:
3236
- businessData = buildItemRuleBusinessData({
3237
- tempOrder: this.ensureTempOrder(),
3238
- runtimeConfig: this.getItemRuleRuntimeConfig(),
3239
- itemRuleConfigs: this.itemRuleConfigs
3240
- });
3241
- limits = this.itemRuleEvaluator.getQuantityLimits(businessData);
3242
- this.store.itemRuleQuantityLimits = limits;
3243
- this.logMethodSuccess('refreshItemRuleQuantityLimits', {
3244
- limitCount: limits.length
3245
- });
3246
- return _context36.abrupt("return", limits);
3247
- case 14:
3248
- _context36.prev = 14;
3249
- _context36.t0 = _context36["catch"](0);
3250
- this.store.itemRuleQuantityLimits = [];
3251
- this.logMethodError('refreshItemRuleQuantityLimits', _context36.t0);
3252
- return _context36.abrupt("return", []);
3253
- case 19:
3254
- case "end":
3255
- return _context36.stop();
3256
- }
3257
- }, _callee36, this, [[0, 14]]);
3258
- }));
3259
- function refreshItemRuleQuantityLimits() {
3260
- return _refreshItemRuleQuantityLimits.apply(this, arguments);
3261
- }
3262
- return refreshItemRuleQuantityLimits;
3263
- }()
3264
- }, {
3265
- key: "applyPrefillByItemRule",
3266
- value: function () {
3267
- var _applyPrefillByItemRule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37() {
3268
- var strategyConfigs, businessData, prefillItems, productSourceMap, tempOrder, hasChanges, _iterator18, _step18, _prefillItem$product_, _targetProduct$_origi, prefillItem, productId, productVariantId, targetQuantity, sourceItem, productIndex, _sourceItem$price, sellingPrice, targetProduct, existedQuantity, delta, nextProduct;
3269
- return _regeneratorRuntime().wrap(function _callee37$(_context37) {
3270
- while (1) switch (_context37.prev = _context37.next) {
3271
- case 0:
3272
- if (!this.itemRulePrefillApplied) {
3273
- _context37.next = 2;
3274
- break;
3275
- }
3276
- return _context37.abrupt("return");
3277
- case 2:
3278
- if (this.store.order) {
3279
- _context37.next = 4;
3280
- break;
3281
- }
3282
- return _context37.abrupt("return");
3283
- case 4:
3284
- _context37.next = 6;
3285
- return this.ensureItemRuleConfigsLoaded();
3286
- case 6:
3287
- strategyConfigs = _context37.sent;
3288
- if (strategyConfigs.length) {
3289
- _context37.next = 9;
3290
- break;
3291
- }
3292
- return _context37.abrupt("return");
3293
- case 9:
3294
- businessData = buildItemRuleBusinessData({
3295
- tempOrder: this.ensureTempOrder(),
3296
- runtimeConfig: this.getItemRuleRuntimeConfig(),
3297
- itemRuleConfigs: this.itemRuleConfigs
3298
- });
3299
- prefillItems = this.itemRuleEvaluator.getPrefillItems(businessData);
3300
- if (prefillItems.length) {
3301
- _context37.next = 14;
3302
- break;
3303
- }
3304
- this.itemRulePrefillApplied = true;
3305
- return _context37.abrupt("return");
3306
- case 14:
3307
- _context37.next = 16;
3308
- return this.buildPrefillProductSourceMap();
3309
- case 16:
3310
- productSourceMap = _context37.sent;
3311
- tempOrder = this.ensureTempOrder();
3312
- hasChanges = false;
3313
- _iterator18 = _createForOfIteratorHelper(prefillItems);
3314
- _context37.prev = 20;
3315
- _iterator18.s();
3316
- case 22:
3317
- if ((_step18 = _iterator18.n()).done) {
3318
- _context37.next = 45;
3319
- break;
3320
- }
3321
- prefillItem = _step18.value;
3322
- productId = Number(prefillItem.product_id);
3323
- productVariantId = Number((_prefillItem$product_ = prefillItem.product_variant_id) !== null && _prefillItem$product_ !== void 0 ? _prefillItem$product_ : 0);
3324
- targetQuantity = toNonNegativeInt(prefillItem.quantity);
3325
- if (!(!Number.isFinite(productId) || targetQuantity <= 0)) {
3326
- _context37.next = 29;
3327
- break;
3328
- }
3329
- return _context37.abrupt("continue", 43);
3330
- case 29:
3331
- if (!Number.isNaN(productVariantId)) {
3332
- _context37.next = 31;
3333
- break;
3334
- }
3335
- return _context37.abrupt("continue", 43);
3336
- case 31:
3337
- sourceItem = productSourceMap.get(buildProductKey(productId, productVariantId)) || productSourceMap.get(buildProductKey(productId, 0)) || null;
3338
- productIndex = getProductIdentityIndex(tempOrder.products, {
3339
- product_id: productId,
3340
- product_variant_id: productVariantId
3341
- });
3342
- if (!(productIndex === -1)) {
3343
- _context37.next = 38;
3344
- break;
3345
- }
3346
- 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');
3347
- tempOrder.products.push(normalizeOrderProduct({
3348
- product_id: productId,
3349
- product_variant_id: productVariantId,
3350
- num: targetQuantity,
3351
- selling_price: sellingPrice,
3352
- original_price: sellingPrice,
3353
- metadata: {
3354
- item_rule_prefill: true,
3355
- item_rule_id: prefillItem.ruleId
3356
- },
3357
- _origin: _objectSpread(_objectSpread({}, sourceItem || {}), {}, {
3358
- item_rule_prefill: true,
3359
- item_rule_id: prefillItem.ruleId
3360
- })
3361
- }));
3362
- hasChanges = true;
3363
- return _context37.abrupt("continue", 43);
3364
- case 38:
3365
- targetProduct = tempOrder.products[productIndex];
3366
- existedQuantity = toNonNegativeInt(targetProduct.num);
3367
- delta = targetQuantity - existedQuantity;
3368
- nextProduct = _objectSpread(_objectSpread(_objectSpread({}, targetProduct), delta > 0 ? {
3369
- num: getSafeProductNum(existedQuantity + delta)
3370
- } : {}), {}, {
3371
- metadata: _objectSpread(_objectSpread({}, targetProduct.metadata || {}), {}, {
3372
- item_rule_prefill: true,
3373
- item_rule_id: prefillItem.ruleId
3374
- }),
3375
- _origin: sourceItem ? _objectSpread(_objectSpread({}, targetProduct._origin || {}), sourceItem) : targetProduct._origin
3376
- });
3377
- if (delta > 0 || Boolean(sourceItem && (!targetProduct._origin || ((_targetProduct$_origi = targetProduct._origin) === null || _targetProduct$_origi === void 0 ? void 0 : _targetProduct$_origi.price) !== (sourceItem === null || sourceItem === void 0 ? void 0 : sourceItem.price)))) {
3378
- tempOrder.products[productIndex] = nextProduct;
3379
- hasChanges = true;
3380
- }
3381
- case 43:
3382
- _context37.next = 22;
3383
- break;
3384
- case 45:
3385
- _context37.next = 50;
3386
- break;
3387
- case 47:
3388
- _context37.prev = 47;
3389
- _context37.t0 = _context37["catch"](20);
3390
- _iterator18.e(_context37.t0);
3391
- case 50:
3392
- _context37.prev = 50;
3393
- _iterator18.f();
3394
- return _context37.finish(50);
3395
- case 53:
3396
- if (!hasChanges) {
3397
- _context37.next = 58;
3398
- break;
3399
- }
3400
- // Prefill 属于 products CRUD 的一种形式:新增后让 Rules 重算,以支持自动应用可用优惠券。
3401
- this.store.order.applyDiscount();
3402
- _context37.next = 57;
3403
- return this.store.order.recalculateSummary({
3404
- createIfMissing: true
3405
- });
3406
- case 57:
3407
- this.store.order.persistTempOrder();
3408
- case 58:
3409
- _context37.next = 60;
3410
- return this.refreshItemRuleQuantityLimits();
3411
- case 60:
3412
- this.itemRulePrefillApplied = true;
3413
- this.logMethodSuccess('applyPrefillByItemRule', {
3414
- prefillCount: prefillItems.length,
3415
- hasChanges: hasChanges
3416
- });
3417
- case 62:
3418
- case "end":
3419
- return _context37.stop();
3420
- }
3421
- }, _callee37, this, [[20, 47, 50, 53]]);
3422
- }));
3423
- function applyPrefillByItemRule() {
3424
- return _applyPrefillByItemRule.apply(this, arguments);
3425
- }
3426
- return applyPrefillByItemRule;
3427
- }()
3428
- }, {
3429
- key: "applyItemRulePrefill",
3430
- value: function () {
3431
- var _applyItemRulePrefill = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38() {
3432
- return _regeneratorRuntime().wrap(function _callee38$(_context38) {
3433
- while (1) switch (_context38.prev = _context38.next) {
3434
- case 0:
3435
- this.logMethodStart('applyItemRulePrefill');
3436
- _context38.next = 3;
3437
- return this.applyPrefillByItemRule();
3438
- case 3:
3439
- _context38.next = 5;
3440
- return this.refreshItemRuleQuantityLimits();
3441
- case 5:
3442
- _context38.next = 7;
3443
- return this.refreshCartValidationPassed();
3444
- case 7:
3445
- case "end":
3446
- return _context38.stop();
3447
- }
3448
- }, _callee38, this);
3449
- }));
3450
- function applyItemRulePrefill() {
3451
- return _applyItemRulePrefill.apply(this, arguments);
3452
- }
3453
- return applyItemRulePrefill;
3454
- }()
3455
- }, {
3456
- key: "evaluateCartValidationByItemRule",
3457
- value: function () {
3458
- var _evaluateCartValidationByItemRule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39() {
3459
- var strategyConfigs, businessData;
3460
- return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3461
- while (1) switch (_context39.prev = _context39.next) {
3462
- case 0:
3463
- _context39.next = 2;
3464
- return this.ensureItemRuleConfigsLoaded();
3465
- case 2:
3466
- strategyConfigs = _context39.sent;
3467
- if (strategyConfigs.length) {
3468
- _context39.next = 5;
3469
- break;
3470
- }
3471
- return _context39.abrupt("return", {
3472
- passed: true,
3473
- failures: []
3474
- });
3475
- case 5:
3476
- businessData = buildItemRuleBusinessData({
3477
- tempOrder: this.ensureTempOrder(),
3478
- runtimeConfig: this.getItemRuleRuntimeConfig(),
3479
- itemRuleConfigs: this.itemRuleConfigs
3480
- });
3481
- return _context39.abrupt("return", this.itemRuleEvaluator.validateCart(businessData));
3482
- case 7:
3483
- case "end":
3484
- return _context39.stop();
3485
- }
3486
- }, _callee39, this);
3487
- }));
3488
- function evaluateCartValidationByItemRule() {
3489
- return _evaluateCartValidationByItemRule.apply(this, arguments);
3490
- }
3491
- return evaluateCartValidationByItemRule;
3492
- }()
3493
- }, {
3494
- key: "validateBeforeSubmitByItemRule",
3495
- value: function () {
3496
- var _validateBeforeSubmitByItemRule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40() {
3497
- var validationResult, firstFailure, errorMessage, error;
3498
- return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3499
- while (1) switch (_context40.prev = _context40.next) {
3500
- case 0:
3501
- _context40.next = 2;
3502
- return this.evaluateCartValidationByItemRule();
3503
- case 2:
3504
- validationResult = _context40.sent;
3505
- if (!validationResult.passed) {
3506
- _context40.next = 5;
3507
- break;
3508
- }
3509
- return _context40.abrupt("return");
3510
- case 5:
3511
- firstFailure = validationResult.failures[0];
3512
- errorMessage = (firstFailure === null || firstFailure === void 0 ? void 0 : firstFailure.validationMessage) || '当前购物车未满足商品规则,请调整后再提交';
3513
- error = new Error(String(errorMessage));
3514
- error.failures = validationResult.failures;
3515
- throw error;
3516
- case 10:
3517
- case "end":
3518
- return _context40.stop();
3519
- }
3520
- }, _callee40, this);
3521
- }));
3522
- function validateBeforeSubmitByItemRule() {
3523
- return _validateBeforeSubmitByItemRule.apply(this, arguments);
3524
- }
3525
- return validateBeforeSubmitByItemRule;
3526
- }()
3527
- }, {
3528
- key: "refreshCartValidationPassed",
3529
- value: function () {
3530
- var _refreshCartValidationPassed = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41() {
3531
- var previous, nextState, validationResult, changed;
3532
- return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3533
- while (1) switch (_context41.prev = _context41.next) {
3534
- case 0:
3535
- previous = this.store.cartValidation || {
3536
- passed: null,
3537
- failures: []
3538
- };
3539
- nextState = {
3540
- passed: null,
3541
- failures: []
3542
- };
3543
- _context41.prev = 2;
3544
- _context41.next = 5;
3545
- return this.evaluateCartValidationByItemRule();
3546
- case 5:
3547
- validationResult = _context41.sent;
3548
- nextState = {
3549
- passed: validationResult.passed,
3550
- failures: validationResult.failures || []
3551
- };
3552
- _context41.next = 12;
3553
- break;
3554
- case 9:
3555
- _context41.prev = 9;
3556
- _context41.t0 = _context41["catch"](2);
3557
- nextState = {
3558
- passed: false,
3559
- failures: []
3560
- };
3561
- case 12:
3562
- this.store.cartValidation = nextState;
3563
- changed = previous.passed !== nextState.passed || previous.failures !== nextState.failures;
3564
- if (!changed) {
3565
- _context41.next = 17;
3566
- break;
3567
- }
3568
- _context41.next = 17;
3569
- return this.core.effects.emit(VenueBookingHooks.onCartValidationChanged, {
3570
- cartValidation: nextState,
3571
- cartValidationPassed: nextState.passed
3572
- });
3573
- case 17:
3574
- return _context41.abrupt("return", nextState.passed);
3575
- case 18:
3576
- case "end":
3577
- return _context41.stop();
3578
- }
3579
- }, _callee41, this, [[2, 9]]);
3580
- }));
3581
- function refreshCartValidationPassed() {
3582
- return _refreshCartValidationPassed.apply(this, arguments);
3583
- }
3584
- return refreshCartValidationPassed;
3585
- }()
3586
- }, {
3587
- key: "setItemRuleRuntimeConfig",
3588
- value: function () {
3589
- var _setItemRuleRuntimeConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42() {
3590
- var _this$itemRuleRuntime, _this$itemRuleRuntime2;
3591
- var config,
3592
- _args42 = arguments;
3593
- return _regeneratorRuntime().wrap(function _callee42$(_context42) {
3594
- while (1) switch (_context42.prev = _context42.next) {
3595
- case 0:
3596
- config = _args42.length > 0 && _args42[0] !== undefined ? _args42[0] : {};
3597
- this.logMethodStart('setItemRuleRuntimeConfig');
3598
- this.itemRuleRuntimeConfig = _objectSpread(_objectSpread(_objectSpread({}, this.itemRuleRuntimeConfig), config), {}, {
3599
- 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) || {}),
3600
- 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) || {})
3601
- });
3602
- if ('strategyConfigs' in config) {
3603
- this.itemRuleConfigs = [];
3604
- this.itemRuleConfigsPromise = null;
3605
- this.itemRuleEvaluator.setStrategyConfigs([]);
3606
- }
3607
- this.itemRulePrefillApplied = false;
3608
- _context42.next = 7;
3609
- return this.refreshItemRuleQuantityLimits();
3610
- case 7:
3611
- _context42.next = 9;
3612
- return this.refreshCartValidationPassed();
3613
- case 9:
3614
- this.logMethodSuccess('setItemRuleRuntimeConfig', {
3615
- strategyCount: Array.isArray(this.itemRuleRuntimeConfig.strategyConfigs) ? this.itemRuleRuntimeConfig.strategyConfigs.length : 0
3616
- });
3617
- case 10:
3618
- case "end":
3619
- return _context42.stop();
3620
- }
3621
- }, _callee42, this);
3622
- }));
3623
- function setItemRuleRuntimeConfig() {
3624
- return _setItemRuleRuntimeConfig.apply(this, arguments);
3625
- }
3626
- return setItemRuleRuntimeConfig;
3627
- }()
3628
- }, {
3629
- key: "getOtherParams",
3630
- value: function getOtherParams() {
3631
- return this.otherParams;
3632
- }
3633
-
3634
- // ─── UI 状态缓存(按 cacheId 分桶,sessionStorage) ───
3635
- //
3636
- // 用于物料层持久化 UI 层面的轻量状态(如当前步骤、登录回跳意图等)。
3637
- // 桶键:pisell.venueBooking.uiState:<cacheId>;内部以 JSON object 形式存储多个字段。
3638
- // 无 cacheId 时所有方法自动降级为 no-op,上层不用判空。
3639
- }, {
3640
- key: "getUIStateBucketKey",
3641
- value: function getUIStateBucketKey() {
3642
- if (!this.cacheId) return null;
3643
- return "".concat(VenueBookingImpl.UI_STATE_KEY_PREFIX).concat(this.cacheId);
3644
- }
3645
- }, {
3646
- key: "readUIStateBucket",
3647
- value: function readUIStateBucket() {
3648
- var _this$window;
3649
- var key = this.getUIStateBucketKey();
3650
- if (!key || !((_this$window = this.window) !== null && _this$window !== void 0 && _this$window.sessionStorage)) return {};
3651
- try {
3652
- var raw = this.window.sessionStorage.getItem(key) || '{}';
3653
- var parsed = JSON.parse(raw);
3654
- return parsed && _typeof(parsed) === 'object' ? parsed : {};
3655
- } catch (_unused4) {
3656
- return {};
3657
- }
3658
- }
3659
- }, {
3660
- key: "writeUIStateBucket",
3661
- value: function writeUIStateBucket(bucket) {
3662
- var _this$window2;
3663
- var key = this.getUIStateBucketKey();
3664
- if (!key || !((_this$window2 = this.window) !== null && _this$window2 !== void 0 && _this$window2.sessionStorage)) return;
3665
- this.window.sessionStorage.setItem(key, JSON.stringify(bucket));
3666
- }
3667
- }, {
3668
- key: "setUIState",
3669
- value: function setUIState(key, value) {
3670
- if (!this.getUIStateBucketKey()) return;
3671
- var bucket = this.readUIStateBucket();
3672
- bucket[key] = value;
3673
- this.writeUIStateBucket(bucket);
3674
- }
3675
- }, {
3676
- key: "getUIState",
3677
- value: function getUIState(key) {
3678
- if (!this.getUIStateBucketKey()) return undefined;
3679
- var bucket = this.readUIStateBucket();
3680
- return bucket[key];
3681
- }
3682
- }, {
3683
- key: "deleteUIState",
3684
- value: function deleteUIState(key) {
3685
- if (!this.getUIStateBucketKey()) return;
3686
- var bucket = this.readUIStateBucket();
3687
- if (key in bucket) {
3688
- delete bucket[key];
3689
- this.writeUIStateBucket(bucket);
3690
- }
3691
- }
3692
- }, {
3693
- key: "setBookingHolder",
3694
- value: function setBookingHolder(bookingUid, holder) {
3695
- var _order$bookings;
3696
- var order = this.getTempOrder();
3697
- var booking = order === null || order === void 0 || (_order$bookings = order.bookings) === null || _order$bookings === void 0 ? void 0 : _order$bookings.find(function (b) {
3698
- var _b$metadata4;
3699
- return ((_b$metadata4 = b.metadata) === null || _b$metadata4 === void 0 ? void 0 : _b$metadata4.unique_identification_number) === bookingUid;
3700
- });
3701
- if (booking) {
3702
- booking.holder = holder;
3703
- }
3704
- }
3705
-
3706
- // ─── OpenData 可用性 ───
3707
- }, {
3708
- key: "checkOpenDataAvailability",
3709
- value: function () {
3710
- var _checkOpenDataAvailability = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43() {
3711
- return _regeneratorRuntime().wrap(function _callee43$(_context43) {
3712
- while (1) switch (_context43.prev = _context43.next) {
3713
- case 0:
3714
- if (this.store.openData) {
3715
- _context43.next = 2;
3716
- break;
3717
- }
3718
- throw new Error('openData 模块未初始化');
3719
- case 2:
3720
- _context43.next = 4;
3721
- return this.loadOpenDataConfig();
3722
- case 4:
3723
- return _context43.abrupt("return", this.store.openData.checkAvailability(this.store.schedule));
3724
- case 5:
3725
- case "end":
3726
- return _context43.stop();
3727
- }
3728
- }, _callee43, this);
3729
- }));
3730
- function checkOpenDataAvailability() {
3731
- return _checkOpenDataAvailability.apply(this, arguments);
3732
- }
3733
- return checkOpenDataAvailability;
3734
- }()
3735
- }, {
3736
- key: "setOtherParams",
3737
- value: function () {
3738
- var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(params) {
3739
- var _ref5,
3740
- _ref5$cover,
3741
- cover,
3742
- _args44 = arguments;
3743
- return _regeneratorRuntime().wrap(function _callee44$(_context44) {
3744
- while (1) switch (_context44.prev = _context44.next) {
3745
- case 0:
3746
- _ref5 = _args44.length > 1 && _args44[1] !== undefined ? _args44[1] : {}, _ref5$cover = _ref5.cover, cover = _ref5$cover === void 0 ? false : _ref5$cover;
3747
- if (cover) {
3748
- this.otherParams = params;
3749
- } else {
3750
- this.otherParams = _objectSpread(_objectSpread({}, this.otherParams), params);
3751
- }
3752
- case 2:
3753
- case "end":
3754
- return _context44.stop();
3755
- }
3756
- }, _callee44, this);
3757
- }));
3758
- function setOtherParams(_x21) {
3759
- return _setOtherParams.apply(this, arguments);
3760
- }
3761
- return setOtherParams;
3762
- }()
3763
- }]);
3764
- return VenueBookingImpl;
3765
- }(BaseModule);
3766
- _defineProperty(VenueBookingImpl, "PRICING_DEBUG_CACHE_ID", '031596279011848516');
3767
- _defineProperty(VenueBookingImpl, "OPEN_DATA_CACHE_TTL", 5 * 60 * 1000);
3768
- _defineProperty(VenueBookingImpl, "PISELL1_LOGIN_SUCCESS", 'pisell1.login.success');
3769
- _defineProperty(VenueBookingImpl, "UI_STATE_KEY_PREFIX", 'pisell.venueBooking.uiState:');