@pisell/pisellos 2.1.151 → 2.1.152

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