@pisell/pisellos 2.1.149 → 2.1.151

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 (197) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +1 -0
  3. package/dist/model/strategy/adapter/promotion/evaluator.js +99 -26
  4. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  5. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  6. package/dist/model/strategy/adapter/walletPass/evaluator.js +61 -8
  7. package/dist/model/strategy/adapter/walletPass/locales.js +12 -3
  8. package/dist/model/strategy/engine.d.ts +18 -5
  9. package/dist/model/strategy/engine.js +145 -45
  10. package/dist/model/strategy/type.d.ts +17 -0
  11. package/dist/model/strategy/type.js +4 -0
  12. package/dist/modules/Cart/types.d.ts +2 -0
  13. package/dist/modules/Cart/utils/cartProduct.js +56 -25
  14. package/dist/modules/Discount/types.d.ts +19 -1
  15. package/dist/modules/Order/index.d.ts +1 -65
  16. package/dist/modules/Order/index.js +30 -899
  17. package/dist/modules/Order/types.d.ts +12 -174
  18. package/dist/modules/Order/types.js +0 -2
  19. package/dist/modules/Order/utils.d.ts +0 -118
  20. package/dist/modules/Order/utils.js +2 -586
  21. package/dist/modules/Payment/index.d.ts +2 -1
  22. package/dist/modules/Payment/index.js +10 -7
  23. package/dist/modules/Payment/utils.js +3 -0
  24. package/dist/modules/Payment/walletpass.d.ts +23 -0
  25. package/dist/modules/Payment/walletpass.js +191 -95
  26. package/dist/modules/Product/utils.js +2 -2
  27. package/dist/modules/ProductList/index.d.ts +1 -1
  28. package/dist/modules/ProductList/index.js +3 -4
  29. package/dist/modules/Rules/index.d.ts +9 -5
  30. package/dist/modules/Rules/index.js +677 -168
  31. package/dist/modules/Rules/types.d.ts +2 -0
  32. package/dist/modules/Schedule/getDateIsInSchedule.js +18 -11
  33. package/dist/modules/Schedule/utils.d.ts +1 -1
  34. package/dist/modules/Summary/types.d.ts +2 -0
  35. package/dist/modules/Summary/utils.d.ts +9 -3
  36. package/dist/modules/Summary/utils.js +52 -41
  37. package/dist/modules/index.d.ts +0 -4
  38. package/dist/modules/index.js +1 -5
  39. package/dist/plugins/window.d.ts +2 -0
  40. package/dist/solution/BookingByStep/index.d.ts +3 -2
  41. package/dist/solution/BookingByStep/index.js +43 -46
  42. package/dist/solution/BookingByStep/types.d.ts +1 -3
  43. package/dist/solution/BookingByStep/types.js +1 -5
  44. package/dist/solution/BookingByStep/utils/timeslots.d.ts +1 -3
  45. package/dist/solution/BookingByStep/utils/timeslots.js +12 -19
  46. package/dist/solution/Checkout/index.js +2 -0
  47. package/dist/solution/ShopDiscount/index.d.ts +1 -0
  48. package/dist/solution/ShopDiscount/index.js +23 -7
  49. package/dist/solution/ShopDiscount/types.d.ts +1 -0
  50. package/dist/solution/ShopDiscount/types.js +2 -1
  51. package/dist/solution/ShopDiscount/utils.js +26 -12
  52. package/dist/solution/index.d.ts +0 -2
  53. package/dist/solution/index.js +1 -3
  54. package/lib/index.d.ts +1 -0
  55. package/lib/index.js +3 -1
  56. package/lib/model/strategy/adapter/promotion/evaluator.js +57 -8
  57. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  58. package/lib/model/strategy/adapter/walletPass/evaluator.js +34 -3
  59. package/lib/model/strategy/adapter/walletPass/locales.js +12 -3
  60. package/lib/model/strategy/engine.d.ts +18 -5
  61. package/lib/model/strategy/engine.js +85 -21
  62. package/lib/model/strategy/type.d.ts +17 -0
  63. package/lib/modules/Cart/types.d.ts +2 -0
  64. package/lib/modules/Cart/utils/cartProduct.js +39 -12
  65. package/lib/modules/Discount/types.d.ts +19 -1
  66. package/lib/modules/Order/index.d.ts +1 -65
  67. package/lib/modules/Order/index.js +1 -513
  68. package/lib/modules/Order/types.d.ts +12 -174
  69. package/lib/modules/Order/utils.d.ts +0 -118
  70. package/lib/modules/Order/utils.js +2 -483
  71. package/lib/modules/Payment/index.d.ts +2 -1
  72. package/lib/modules/Payment/index.js +1 -0
  73. package/lib/modules/Payment/utils.js +3 -0
  74. package/lib/modules/Payment/walletpass.d.ts +23 -0
  75. package/lib/modules/Payment/walletpass.js +94 -17
  76. package/lib/modules/Product/utils.js +2 -2
  77. package/lib/modules/ProductList/index.d.ts +1 -1
  78. package/lib/modules/ProductList/index.js +3 -5
  79. package/lib/modules/Rules/index.d.ts +9 -5
  80. package/lib/modules/Rules/index.js +780 -288
  81. package/lib/modules/Rules/types.d.ts +2 -0
  82. package/lib/modules/Schedule/getDateIsInSchedule.js +11 -9
  83. package/lib/modules/Schedule/utils.d.ts +1 -1
  84. package/lib/modules/Summary/types.d.ts +2 -0
  85. package/lib/modules/Summary/utils.d.ts +9 -3
  86. package/lib/modules/Summary/utils.js +31 -22
  87. package/lib/modules/index.d.ts +0 -4
  88. package/lib/modules/index.js +1 -9
  89. package/lib/plugins/window.d.ts +2 -0
  90. package/lib/solution/BookingByStep/index.d.ts +3 -2
  91. package/lib/solution/BookingByStep/index.js +4 -6
  92. package/lib/solution/BookingByStep/types.d.ts +1 -3
  93. package/lib/solution/BookingByStep/types.js +0 -10
  94. package/lib/solution/BookingByStep/utils/timeslots.d.ts +1 -3
  95. package/lib/solution/BookingByStep/utils/timeslots.js +11 -19
  96. package/lib/solution/Checkout/index.js +2 -0
  97. package/lib/solution/ShopDiscount/index.d.ts +1 -0
  98. package/lib/solution/ShopDiscount/index.js +22 -8
  99. package/lib/solution/ShopDiscount/types.d.ts +1 -0
  100. package/lib/solution/ShopDiscount/utils.js +10 -6
  101. package/lib/solution/index.d.ts +0 -2
  102. package/lib/solution/index.js +1 -5
  103. package/package.json +1 -1
  104. package/dist/apis/picoding.d.ts +0 -0
  105. package/dist/apis/picoding.js +0 -1
  106. package/dist/modules/OpenData/index.d.ts +0 -24
  107. package/dist/modules/OpenData/index.js +0 -173
  108. package/dist/modules/OpenData/types.d.ts +0 -73
  109. package/dist/modules/OpenData/types.js +0 -1
  110. package/dist/modules/OpenData/utils.d.ts +0 -2
  111. package/dist/modules/OpenData/utils.js +0 -75
  112. package/dist/modules/Quotation/index.d.ts +0 -48
  113. package/dist/modules/Quotation/index.js +0 -248
  114. package/dist/modules/Quotation/types.d.ts +0 -42
  115. package/dist/modules/Quotation/types.js +0 -1
  116. package/dist/modules/SalesSummary/index.d.ts +0 -63
  117. package/dist/modules/SalesSummary/index.js +0 -174
  118. package/dist/modules/SalesSummary/types.d.ts +0 -60
  119. package/dist/modules/SalesSummary/types.js +0 -1
  120. package/dist/modules/SalesSummary/utils.d.ts +0 -30
  121. package/dist/modules/SalesSummary/utils.js +0 -480
  122. package/dist/modules/ScanOrderLogger/index.d.ts +0 -23
  123. package/dist/modules/ScanOrderLogger/index.js +0 -174
  124. package/dist/modules/ScanOrderLogger/providers/feishu.d.ts +0 -2
  125. package/dist/modules/ScanOrderLogger/providers/feishu.js +0 -221
  126. package/dist/modules/ScanOrderLogger/providers/grafana.d.ts +0 -2
  127. package/dist/modules/ScanOrderLogger/providers/grafana.js +0 -50
  128. package/dist/modules/ScanOrderLogger/types.d.ts +0 -53
  129. package/dist/modules/ScanOrderLogger/types.js +0 -1
  130. package/dist/solution/ScanOrder/index.d.ts +0 -152
  131. package/dist/solution/ScanOrder/index.js +0 -3132
  132. package/dist/solution/ScanOrder/types.d.ts +0 -287
  133. package/dist/solution/ScanOrder/types.js +0 -35
  134. package/dist/solution/ScanOrder/utils.d.ts +0 -167
  135. package/dist/solution/ScanOrder/utils.js +0 -764
  136. package/dist/solution/VenueBooking/index.d.ts +0 -199
  137. package/dist/solution/VenueBooking/index.js +0 -3459
  138. package/dist/solution/VenueBooking/sales-section-4-annotated.json +0 -343
  139. package/dist/solution/VenueBooking/types.d.ts +0 -154
  140. package/dist/solution/VenueBooking/types.js +0 -21
  141. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +0 -11
  142. package/dist/solution/VenueBooking/utils/dateSummary.js +0 -104
  143. package/dist/solution/VenueBooking/utils/resource.d.ts +0 -14
  144. package/dist/solution/VenueBooking/utils/resource.js +0 -131
  145. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +0 -38
  146. package/dist/solution/VenueBooking/utils/slotMerge.js +0 -239
  147. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +0 -32
  148. package/dist/solution/VenueBooking/utils/timeSlot.js +0 -453
  149. package/dist/solution/VenueBooking/utils.d.ts +0 -1
  150. package/dist/solution/VenueBooking/utils.js +0 -1
  151. package/lib/apis/picoding.d.ts +0 -0
  152. package/lib/apis/picoding.js +0 -0
  153. package/lib/modules/OpenData/index.d.ts +0 -24
  154. package/lib/modules/OpenData/index.js +0 -119
  155. package/lib/modules/OpenData/types.d.ts +0 -73
  156. package/lib/modules/OpenData/types.js +0 -17
  157. package/lib/modules/OpenData/utils.d.ts +0 -2
  158. package/lib/modules/OpenData/utils.js +0 -111
  159. package/lib/modules/Quotation/index.d.ts +0 -48
  160. package/lib/modules/Quotation/index.js +0 -152
  161. package/lib/modules/Quotation/types.d.ts +0 -42
  162. package/lib/modules/Quotation/types.js +0 -17
  163. package/lib/modules/SalesSummary/index.d.ts +0 -63
  164. package/lib/modules/SalesSummary/index.js +0 -105
  165. package/lib/modules/SalesSummary/types.d.ts +0 -60
  166. package/lib/modules/SalesSummary/types.js +0 -17
  167. package/lib/modules/SalesSummary/utils.d.ts +0 -30
  168. package/lib/modules/SalesSummary/utils.js +0 -420
  169. package/lib/modules/ScanOrderLogger/index.d.ts +0 -23
  170. package/lib/modules/ScanOrderLogger/index.js +0 -147
  171. package/lib/modules/ScanOrderLogger/providers/feishu.d.ts +0 -2
  172. package/lib/modules/ScanOrderLogger/providers/feishu.js +0 -157
  173. package/lib/modules/ScanOrderLogger/providers/grafana.d.ts +0 -2
  174. package/lib/modules/ScanOrderLogger/providers/grafana.js +0 -52
  175. package/lib/modules/ScanOrderLogger/types.d.ts +0 -53
  176. package/lib/modules/ScanOrderLogger/types.js +0 -17
  177. package/lib/solution/ScanOrder/index.d.ts +0 -152
  178. package/lib/solution/ScanOrder/index.js +0 -1901
  179. package/lib/solution/ScanOrder/types.d.ts +0 -287
  180. package/lib/solution/ScanOrder/types.js +0 -36
  181. package/lib/solution/ScanOrder/utils.d.ts +0 -167
  182. package/lib/solution/ScanOrder/utils.js +0 -635
  183. package/lib/solution/VenueBooking/index.d.ts +0 -199
  184. package/lib/solution/VenueBooking/index.js +0 -1926
  185. package/lib/solution/VenueBooking/sales-section-4-annotated.json +0 -343
  186. package/lib/solution/VenueBooking/types.d.ts +0 -154
  187. package/lib/solution/VenueBooking/types.js +0 -44
  188. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +0 -11
  189. package/lib/solution/VenueBooking/utils/dateSummary.js +0 -110
  190. package/lib/solution/VenueBooking/utils/resource.d.ts +0 -14
  191. package/lib/solution/VenueBooking/utils/resource.js +0 -92
  192. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +0 -38
  193. package/lib/solution/VenueBooking/utils/slotMerge.js +0 -237
  194. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +0 -32
  195. package/lib/solution/VenueBooking/utils/timeSlot.js +0 -339
  196. package/lib/solution/VenueBooking/utils.d.ts +0 -1
  197. package/lib/solution/VenueBooking/utils.js +0 -69
@@ -36,54 +36,17 @@ var import_BaseModule = require("../BaseModule");
36
36
  var import_utils = require("./utils");
37
37
  var import_utils2 = require("../Product/utils");
38
38
  var import_dayjs = __toESM(require("dayjs"));
39
- var import_utils3 = require("../../solution/ScanOrder/utils");
40
- var import_Discount = require("../Discount");
41
- var import_Rules = require("../Rules");
42
- var import_types = require("../Rules/types");
43
- var import_decimal = __toESM(require("decimal.js"));
44
39
  var OrderModule = class extends import_BaseModule.BaseModule {
40
+ // LoggerManager 实例
45
41
  constructor(name, version) {
46
42
  super(name || "order", version);
47
43
  this.defaultName = "order";
48
44
  this.defaultVersion = "1.0.0";
49
45
  }
50
- /**
51
- * Populate `savedAmount` on each discount based on product-level discount details.
52
- * Only selected discounts get a non-zero value.
53
- */
54
- static populateSavedAmounts(productList, discountList) {
55
- var _a, _b;
56
- const savedMap = /* @__PURE__ */ new Map();
57
- for (const product of productList) {
58
- const qty = product.num || 1;
59
- for (const pd of product.discount_list || []) {
60
- const discountKey = ((_a = pd.discount) == null ? void 0 : _a.resource_id) || pd.id;
61
- if (discountKey == null)
62
- continue;
63
- const amount = new import_decimal.default(pd.amount || 0).times(qty).plus(((_b = pd.metadata) == null ? void 0 : _b.product_discount_difference) || 0);
64
- savedMap.set(discountKey, (savedMap.get(discountKey) || new import_decimal.default(0)).plus(amount));
65
- }
66
- }
67
- for (const d of discountList) {
68
- const key = d.id;
69
- d.savedAmount = d.isSelected && key != null && savedMap.has(key) ? savedMap.get(key).toNumber() : 0;
70
- }
71
- }
72
46
  async initialize(core, options) {
73
- var _a;
74
47
  this.core = core;
75
48
  this.store = options.store;
76
- if (!this.store.tempOrder) {
77
- this.store.tempOrder = null;
78
- }
79
49
  this.request = this.core.getPlugin("request");
80
- this.window = this.core.getPlugin("window");
81
- const otherParams = options.otherParams || {};
82
- this.cacheId = otherParams.cacheId;
83
- this.salesSummaryModuleName = otherParams.salesSummaryModuleName;
84
- this.rulesHooksOverride = (_a = otherParams.rules) == null ? void 0 : _a.hooks;
85
- this.registerDiscountModules(options);
86
- this.restoreTempOrderFromStorage();
87
50
  const appPlugin = this.core.getPlugin("app");
88
51
  if (!appPlugin) {
89
52
  throw new Error("Order 模块需要 app 插件支持");
@@ -128,451 +91,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
128
91
  });
129
92
  }
130
93
  }
131
- // ─── Discount: 子模块注册 ───
132
- registerDiscountModules(options) {
133
- let targetCacheData = {};
134
- if (this.cacheId && this.window) {
135
- const sessionData = this.window.sessionStorage.getItem(this.name);
136
- if (sessionData) {
137
- try {
138
- const data = JSON.parse(sessionData);
139
- targetCacheData = (data == null ? void 0 : data[this.cacheId]) || {};
140
- } catch {
141
- }
142
- }
143
- }
144
- const discount = new import_Discount.DiscountModule(`${this.name}_discount`);
145
- this.core.registerModule(discount, {
146
- initialState: targetCacheData == null ? void 0 : targetCacheData[discount.name],
147
- otherParams: {
148
- fatherModule: this.name,
149
- openCache: !!this.cacheId,
150
- cacheId: this.cacheId
151
- }
152
- });
153
- this.store.discount = discount;
154
- const rules = new import_Rules.RulesModule(`${this.name}_rules`);
155
- this.core.registerModule(rules, {
156
- hooks: this.rulesHooksOverride || this.createDefaultRulesHooks()
157
- });
158
- this.store.rules = rules;
159
- }
160
- createDefaultRulesHooks() {
161
- return (0, import_utils.createDefaultOrderRulesHooks)();
162
- }
163
- // ─── Discount: 公共 API ───
164
- async loadDiscountConfig(params) {
165
- var _a, _b, _c, _d;
166
- const discountList = await ((_a = this.store.discount) == null ? void 0 : _a.loadPrepareConfig({
167
- customer_id: params.customerId,
168
- action: params.action || "create",
169
- with_good_pass: 1,
170
- with_discount_card: 1,
171
- with_wallet_pass_holder: 1,
172
- request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
173
- }));
174
- if (discountList) {
175
- (_b = this.store.discount) == null ? void 0 : _b.setDiscountList(discountList);
176
- }
177
- if ((_d = (_c = this.store.tempOrder) == null ? void 0 : _c.products) == null ? void 0 : _d.length) {
178
- this.applyDiscount();
179
- }
180
- }
181
- getDiscountList() {
182
- var _a;
183
- return ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList()) || [];
184
- }
185
- async scanCode(code, customerId) {
186
- var _a, _b, _c, _d;
187
- const resultDiscountList = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, customerId)) || [];
188
- const rulesModule = this.store.rules;
189
- if (!rulesModule) {
190
- return {
191
- type: "clientCalc",
192
- isAvailable: false,
193
- discountList: this.getDiscountList(),
194
- unavailableReason: import_types.UnavailableReason.Unknown
195
- };
196
- }
197
- if (!resultDiscountList.length) {
198
- return {
199
- type: "server",
200
- isAvailable: false,
201
- discountList: this.getDiscountList()
202
- };
203
- }
204
- const withScanList = resultDiscountList.map((item) => ({ ...item, isScan: true }));
205
- const currentSelected = this.getDiscountList().filter((n) => n.isSelected);
206
- if (currentSelected.length && currentSelected.some((n) => withScanList.some((m) => m.id === n.id))) {
207
- return {
208
- type: "clientCalc",
209
- isAvailable: true,
210
- discountList: this.getDiscountList()
211
- };
212
- }
213
- const tempOrder = this.store.tempOrder;
214
- const holders = ((_b = tempOrder == null ? void 0 : tempOrder.holder) == null ? void 0 : _b.form_record_id) ? [{ form_record_id: tempOrder.holder.form_record_id }] : [];
215
- const { isAvailable, discountList: newDiscountList, unavailableReason } = rulesModule.isDiscountListAvailable({
216
- productList: (tempOrder == null ? void 0 : tempOrder.products) || [],
217
- oldDiscountList: this.getDiscountList(),
218
- newDiscountList: withScanList,
219
- holders,
220
- isFormSubject: !!((_c = tempOrder == null ? void 0 : tempOrder.holder) == null ? void 0 : _c.type) && tempOrder.holder.type === "form"
221
- }) || { isAvailable: false, discountList: this.getDiscountList() };
222
- if (isAvailable && newDiscountList) {
223
- (_d = this.store.discount) == null ? void 0 : _d.setDiscountList(newDiscountList);
224
- this.applyDiscount();
225
- }
226
- return {
227
- type: "clientCalc",
228
- isAvailable: isAvailable || false,
229
- discountList: newDiscountList || this.getDiscountList(),
230
- unavailableReason
231
- };
232
- }
233
- applyDiscount() {
234
- var _a, _b, _c, _d;
235
- const tempOrder = this.store.tempOrder;
236
- if (!tempOrder)
237
- return;
238
- const rulesModule = this.store.rules;
239
- if (!rulesModule)
240
- return;
241
- const discountList = ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList()) || [];
242
- const holders = ((_b = tempOrder.holder) == null ? void 0 : _b.form_record_id) ? [{ form_record_id: tempOrder.holder.form_record_id }] : [];
243
- const result = rulesModule.calcDiscount({
244
- productList: tempOrder.products,
245
- discountList,
246
- holders,
247
- isFormSubject: !!((_c = tempOrder.holder) == null ? void 0 : _c.type) && tempOrder.holder.type === "form"
248
- });
249
- if (result == null ? void 0 : result.productList) {
250
- tempOrder.products = result.productList;
251
- }
252
- if (result == null ? void 0 : result.discountList) {
253
- OrderModule.populateSavedAmounts(result.productList || tempOrder.products, result.discountList);
254
- (_d = this.store.discount) == null ? void 0 : _d.setDiscountList(result.discountList);
255
- tempOrder.discount_list = result.discountList.filter((d) => d.isSelected);
256
- }
257
- }
258
- // ─── TempOrder: 初始化入口 ───
259
- initTempOrder(params) {
260
- if (params.cacheId !== void 0)
261
- this.cacheId = params.cacheId;
262
- if (params.salesSummaryModuleName !== void 0)
263
- this.salesSummaryModuleName = params.salesSummaryModuleName;
264
- this.restoreTempOrderFromStorage();
265
- }
266
- // ─── TempOrder: localStorage 持久化 ───
267
- getTempOrderStorageKey() {
268
- if (!this.cacheId)
269
- return null;
270
- return `scanOrder:tempOrder:${this.cacheId}`;
271
- }
272
- restoreTempOrderFromStorage() {
273
- var _a, _b;
274
- const key = this.getTempOrderStorageKey();
275
- if (!key)
276
- return;
277
- if (!this.window)
278
- return;
279
- const cachedData = this.window.localStorage.getItem(key);
280
- if (!cachedData)
281
- return;
282
- try {
283
- const parsedData = JSON.parse(cachedData);
284
- if (!(0, import_utils.isTempOrder)(parsedData)) {
285
- this.window.localStorage.removeItem(key);
286
- return;
287
- }
288
- if (Array.isArray(parsedData.products)) {
289
- for (let i = 0; i < parsedData.products.length; i++) {
290
- const p = parsedData.products[i];
291
- if (!p || typeof p !== "object")
292
- continue;
293
- if (!Array.isArray(p.product_option_item)) {
294
- p.product_option_item = [];
295
- }
296
- if (!Array.isArray(p.product_bundle)) {
297
- p.product_bundle = [];
298
- }
299
- const row = p;
300
- if (typeof row.identity_key !== "string" || row.identity_key.length === 0) {
301
- const newKey = (0, import_utils.createUuidV4)();
302
- row.identity_key = newKey;
303
- if (!row.metadata || typeof row.metadata !== "object") {
304
- row.metadata = {};
305
- }
306
- if (!row.metadata.unique_identification_number) {
307
- row.metadata.unique_identification_number = newKey;
308
- }
309
- }
310
- parsedData.products[i] = (0, import_utils3.normalizeOrderProduct)(row);
311
- }
312
- }
313
- this.store.tempOrder = parsedData;
314
- } catch {
315
- (_b = (_a = this.window) == null ? void 0 : _a.localStorage) == null ? void 0 : _b.removeItem(key);
316
- }
317
- }
318
- persistTempOrder() {
319
- const key = this.getTempOrderStorageKey();
320
- if (!key || !this.store.tempOrder)
321
- return;
322
- if (!this.window)
323
- return;
324
- this.window.localStorage.setItem(key, JSON.stringify(this.store.tempOrder));
325
- }
326
- // ─── TempOrder: 创建 & 获取 ───
327
- createDefaultTempOrderInstance() {
328
- return (0, import_utils.createDefaultTempOrder)({
329
- now: (0, import_utils.formatDateTime)(/* @__PURE__ */ new Date()),
330
- summary: (0, import_utils.createEmptySummary)()
331
- });
332
- }
333
- ensureTempOrder() {
334
- if (this.store.tempOrder)
335
- return this.store.tempOrder;
336
- const newOrder = this.createDefaultTempOrderInstance();
337
- this.store.tempOrder = newOrder;
338
- this.persistTempOrder();
339
- return newOrder;
340
- }
341
- restoreOrder() {
342
- const freshTempOrder = this.createDefaultTempOrderInstance();
343
- this.store.tempOrder = freshTempOrder;
344
- this.persistTempOrder();
345
- return freshTempOrder;
346
- }
347
- getTempOrder() {
348
- return this.store.tempOrder;
349
- }
350
- async addNewOrder() {
351
- const tempOrder = this.ensureTempOrder();
352
- await this.recalculateSummary({ createIfMissing: true });
353
- this.persistTempOrder();
354
- return tempOrder;
355
- }
356
- getOrderProducts() {
357
- const tempOrder = this.ensureTempOrder();
358
- return tempOrder.products;
359
- }
360
- // ─── TempOrder: 金额汇总 ───
361
- getSalesSummary() {
362
- if (!this.salesSummaryModuleName)
363
- return null;
364
- return this.core.getModule(this.salesSummaryModuleName);
365
- }
366
- async recalculateSummary(options) {
367
- const tempOrder = (options == null ? void 0 : options.createIfMissing) ? this.ensureTempOrder() : this.store.tempOrder;
368
- if (!tempOrder)
369
- return null;
370
- const salesSummary = this.getSalesSummary();
371
- if (!salesSummary) {
372
- tempOrder.summary = (0, import_utils.createEmptySummary)();
373
- tempOrder.surcharge_fee = tempOrder.summary.surcharge_fee;
374
- return tempOrder.summary;
375
- }
376
- const summary = await salesSummary.getSummary({
377
- products: tempOrder.products
378
- });
379
- tempOrder.summary = summary;
380
- if (summary.is_price_include_tax !== void 0) {
381
- tempOrder.is_price_include_tax = summary.is_price_include_tax;
382
- }
383
- if (typeof summary.tax_title === "string") {
384
- tempOrder.tax_title = summary.tax_title;
385
- }
386
- tempOrder.surcharge_fee = summary.surcharge_fee;
387
- tempOrder.surcharges = summary.surcharges || [];
388
- tempOrder.deposit_amount = summary.deposit_amount || "0.00";
389
- tempOrder.is_deposit = summary.deposit_amount !== "0.00" ? 1 : 0;
390
- tempOrder.shop_discount = summary.discount_amount || "0.00";
391
- return tempOrder.summary;
392
- }
393
- async getScanOrderSummary() {
394
- const summary = await this.recalculateSummary({ createIfMissing: true });
395
- if (!summary)
396
- return (0, import_utils.createEmptySummary)();
397
- this.persistTempOrder();
398
- return summary;
399
- }
400
- // ─── TempOrder: 备注 ───
401
- updateTempOrderNote(note) {
402
- const tempOrder = this.ensureTempOrder();
403
- tempOrder.note = String(note || "");
404
- this.persistTempOrder();
405
- return tempOrder.note;
406
- }
407
- updateTempOrderBuzzer(buzzer) {
408
- const tempOrder = this.ensureTempOrder();
409
- tempOrder.buzzer = String(buzzer || "");
410
- this.persistTempOrder();
411
- return tempOrder.buzzer;
412
- }
413
- updateTempOrderContactsInfo(contactsInfo) {
414
- const tempOrder = this.ensureTempOrder();
415
- tempOrder.contacts_info = Array.isArray(contactsInfo) ? contactsInfo : [];
416
- this.persistTempOrder();
417
- return tempOrder.contacts_info;
418
- }
419
- // ─── TempOrder: 商品 CRUD ───
420
- async addProductToOrder(product) {
421
- const tempOrder = this.ensureTempOrder();
422
- const hasExplicitIdentityKey = typeof product.identity_key === "string" && product.identity_key.length > 0;
423
- if (hasExplicitIdentityKey) {
424
- const normalizedProduct = (0, import_utils3.normalizeOrderProduct)(product);
425
- const productIndex = (0, import_utils3.getProductIdentityIndex)(
426
- tempOrder.products,
427
- normalizedProduct
428
- );
429
- if (productIndex === -1) {
430
- tempOrder.products.push(normalizedProduct);
431
- } else {
432
- const targetProduct = tempOrder.products[productIndex];
433
- tempOrder.products[productIndex] = {
434
- ...targetProduct,
435
- ...normalizedProduct,
436
- num: (0, import_utils3.getSafeProductNum)(targetProduct.num + normalizedProduct.num),
437
- _origin: normalizedProduct._origin || targetProduct._origin
438
- };
439
- }
440
- } else {
441
- const incomingFingerprint = (0, import_utils3.buildProductLineFingerprint)(
442
- product.product_option_item,
443
- product.product_bundle
444
- );
445
- const matchedIndex = tempOrder.products.findIndex((item) => {
446
- if (item.product_id !== product.product_id)
447
- return false;
448
- if (item.product_variant_id !== product.product_variant_id)
449
- return false;
450
- const existedFingerprint = (0, import_utils3.buildProductLineFingerprint)(
451
- item.product_option_item,
452
- item.product_bundle
453
- );
454
- return existedFingerprint === incomingFingerprint;
455
- });
456
- if (matchedIndex === -1) {
457
- const normalizedProduct = (0, import_utils3.normalizeOrderProduct)(product);
458
- tempOrder.products.push(normalizedProduct);
459
- } else {
460
- const targetProduct = tempOrder.products[matchedIndex];
461
- const normalizedProduct = (0, import_utils3.normalizeOrderProduct)({
462
- ...product,
463
- identity_key: targetProduct.identity_key
464
- });
465
- tempOrder.products[matchedIndex] = {
466
- ...targetProduct,
467
- ...normalizedProduct,
468
- identity_key: targetProduct.identity_key,
469
- num: (0, import_utils3.getSafeProductNum)(targetProduct.num + normalizedProduct.num),
470
- _origin: normalizedProduct._origin || targetProduct._origin
471
- };
472
- }
473
- }
474
- this.applyDiscount();
475
- await this.recalculateSummary({ createIfMissing: true });
476
- this.persistTempOrder();
477
- return tempOrder.products;
478
- }
479
- async updateProductInOrder(params) {
480
- var _a, _b, _c;
481
- const {
482
- product_id,
483
- product_variant_id,
484
- updates,
485
- identity_key,
486
- product_option_item,
487
- product_bundle
488
- } = params;
489
- const tempOrder = this.ensureTempOrder();
490
- const identityLookup = {
491
- product_id,
492
- product_variant_id
493
- };
494
- if (identity_key !== void 0)
495
- identityLookup.identity_key = identity_key;
496
- if (product_option_item !== void 0)
497
- identityLookup.product_option_item = product_option_item;
498
- if (product_bundle !== void 0)
499
- identityLookup.product_bundle = product_bundle;
500
- const productIndex = (0, import_utils3.getProductIdentityIndex)(tempOrder.products, identityLookup);
501
- if (productIndex === -1) {
502
- throw new Error("[Order] 目标商品不存在,无法更新");
503
- }
504
- const targetProduct = tempOrder.products[productIndex];
505
- const nextProduct = {
506
- ...targetProduct,
507
- ...updates,
508
- product_id,
509
- product_variant_id
510
- };
511
- nextProduct.num = (0, import_utils3.getSafeProductNum)(nextProduct.num);
512
- const callerUpdatesTopPrice = Object.prototype.hasOwnProperty.call(updates || {}, "selling_price") || Object.prototype.hasOwnProperty.call(updates || {}, "original_price");
513
- const callerUpdatesMainMeta = ((_a = updates == null ? void 0 : updates.metadata) == null ? void 0 : _a.main_product_selling_price) !== void 0 || ((_b = updates == null ? void 0 : updates.metadata) == null ? void 0 : _b.main_product_original_price) !== void 0 || ((_c = updates == null ? void 0 : updates.metadata) == null ? void 0 : _c.source_product_price) !== void 0;
514
- if (callerUpdatesTopPrice && !callerUpdatesMainMeta) {
515
- const existedMeta = nextProduct.metadata || {};
516
- nextProduct.metadata = { ...existedMeta };
517
- delete nextProduct.metadata.source_product_price;
518
- delete nextProduct.metadata.main_product_selling_price;
519
- delete nextProduct.metadata.main_product_original_price;
520
- delete nextProduct.metadata.price_schema_version;
521
- }
522
- tempOrder.products[productIndex] = (0, import_utils3.normalizeOrderProduct)(nextProduct);
523
- this.applyDiscount();
524
- await this.recalculateSummary({ createIfMissing: true });
525
- this.persistTempOrder();
526
- return tempOrder.products;
527
- }
528
- async removeProductFromOrder(identity) {
529
- const tempOrder = this.ensureTempOrder();
530
- tempOrder.products = tempOrder.products.filter(
531
- (item) => !(0, import_utils3.isIdentityMatch)(item, identity)
532
- );
533
- this.applyDiscount();
534
- await this.recalculateSummary({ createIfMissing: true });
535
- this.persistTempOrder();
536
- return tempOrder.products;
537
- }
538
- // ─── TempOrder: 提交 ───
539
- async submitTempOrder(params) {
540
- const tempOrder = this.ensureTempOrder();
541
- this.persistTempOrder();
542
- const effectiveCacheId = (params == null ? void 0 : params.cacheId) ?? this.cacheId;
543
- const payload = (0, import_utils.buildSubmitPayload)({
544
- tempOrder,
545
- cacheId: effectiveCacheId,
546
- platform: params == null ? void 0 : params.platform,
547
- businessCode: params == null ? void 0 : params.businessCode,
548
- channel: params == null ? void 0 : params.channel,
549
- type: params == null ? void 0 : params.type,
550
- enhance: params == null ? void 0 : params.enhancePayload
551
- });
552
- let result;
553
- if (tempOrder.order_id) {
554
- const products = (0, import_utils.filterProductsForScanOrderMore)(payload.products);
555
- const moreResult = await this.scanOrderMore({
556
- query: {
557
- order_id: tempOrder.order_id,
558
- products,
559
- request_unique_idempotency_token: payload.request_unique_idempotency_token
560
- }
561
- });
562
- if (moreResult.code === 200) {
563
- result = {
564
- data: {
565
- order_id: tempOrder.order_id
566
- }
567
- };
568
- }
569
- } else {
570
- result = await this.submitScanOrder({
571
- query: payload
572
- });
573
- }
574
- return result;
575
- }
576
94
  createOrder(params) {
577
95
  var _a;
578
96
  const order = {
@@ -774,36 +292,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
774
292
  throw error;
775
293
  }
776
294
  }
777
- async submitScanOrder(params) {
778
- const { url, query } = params;
779
- const fetchUrl = url || "/order/sales/checkout";
780
- return this.request.post(fetchUrl, query, { customToast: () => {
781
- } });
782
- }
783
- async scanOrderMore(params) {
784
- const { url, query } = params;
785
- const fetchUrl = url || `/order/order/product/${query.order_id}`;
786
- const requestBody = {
787
- products: query.products,
788
- request_unique_idempotency_token: query.request_unique_idempotency_token
789
- };
790
- return this.request.put(fetchUrl, requestBody, { customToast: () => {
791
- } });
792
- }
793
- // TODO 获取详情的接口
794
- async getOrderInfoByRemote(order_id) {
795
- const res = await this.request.get(`/order/sales/${order_id}`, {
796
- with: ["products", "scheduleEvents"]
797
- });
798
- if (res.code === 200 && this.store.tempOrder) {
799
- this.store.tempOrder.lastOrderInfo = res.data;
800
- }
801
- return res;
802
- }
803
- getLastOrderInfo() {
804
- var _a, _b;
805
- return (_b = (_a = this.store) == null ? void 0 : _a.tempOrder) == null ? void 0 : _b.lastOrderInfo;
806
- }
807
295
  };
808
296
  // Annotate the CommonJS export names for ESM import in node:
809
297
  0 && (module.exports = {