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