@pisell/pisellos 2.1.172 → 2.1.174

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 (238) 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/promotion/index.js +9 -0
  7. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -2
  8. package/dist/model/strategy/adapter/walletPass/evaluator.js +12 -63
  9. package/dist/model/strategy/adapter/walletPass/locales.js +3 -12
  10. package/dist/model/strategy/engine.d.ts +5 -18
  11. package/dist/model/strategy/engine.js +45 -145
  12. package/dist/model/strategy/type.d.ts +0 -17
  13. package/dist/model/strategy/type.js +0 -4
  14. package/dist/modules/Cart/types.d.ts +0 -2
  15. package/dist/modules/Cart/utils/cartProduct.js +25 -56
  16. package/dist/modules/Cart/utils/changePrice.js +16 -9
  17. package/dist/modules/Discount/availability.d.ts +7 -0
  18. package/dist/modules/Discount/availability.js +52 -0
  19. package/dist/modules/Discount/entitlementPass.d.ts +34 -0
  20. package/dist/modules/Discount/entitlementPass.js +147 -0
  21. package/dist/modules/Discount/entitlementState.d.ts +8 -0
  22. package/dist/modules/Discount/entitlementState.js +205 -0
  23. package/dist/modules/Discount/index.d.ts +12 -3
  24. package/dist/modules/Discount/index.js +211 -17
  25. package/dist/modules/Discount/types.d.ts +42 -22
  26. package/dist/modules/Holder/index.d.ts +48 -0
  27. package/dist/modules/Holder/index.js +640 -0
  28. package/dist/modules/Holder/types.d.ts +123 -0
  29. package/dist/modules/Holder/types.js +1 -0
  30. package/dist/modules/Holder/utils.d.ts +13 -0
  31. package/dist/modules/Holder/utils.js +34 -0
  32. package/dist/modules/OpenData/index.d.ts +24 -0
  33. package/dist/modules/OpenData/index.js +173 -0
  34. package/dist/modules/OpenData/types.d.ts +73 -0
  35. package/dist/modules/OpenData/types.js +1 -0
  36. package/dist/modules/OpenData/utils.d.ts +2 -0
  37. package/dist/modules/OpenData/utils.js +75 -0
  38. package/dist/modules/Order/index.d.ts +67 -1
  39. package/dist/modules/Order/index.js +923 -30
  40. package/dist/modules/Order/types.d.ts +176 -12
  41. package/dist/modules/Order/types.js +2 -0
  42. package/dist/modules/Order/utils.d.ts +128 -0
  43. package/dist/modules/Order/utils.js +621 -5
  44. package/dist/modules/Payment/index.d.ts +1 -2
  45. package/dist/modules/Payment/index.js +7 -10
  46. package/dist/modules/Payment/utils.js +0 -3
  47. package/dist/modules/Payment/walletpass.d.ts +0 -23
  48. package/dist/modules/Payment/walletpass.js +95 -191
  49. package/dist/modules/Product/types.d.ts +7 -0
  50. package/dist/modules/Product/utils.js +2 -2
  51. package/dist/modules/ProductList/index.d.ts +1 -1
  52. package/dist/modules/ProductList/index.js +4 -3
  53. package/dist/modules/Quotation/index.d.ts +48 -0
  54. package/dist/modules/Quotation/index.js +248 -0
  55. package/dist/modules/Quotation/types.d.ts +42 -0
  56. package/dist/modules/Quotation/types.js +1 -0
  57. package/dist/modules/Rules/entitlementLines.d.ts +8 -0
  58. package/dist/modules/Rules/entitlementLines.js +157 -0
  59. package/dist/modules/Rules/index.d.ts +17 -11
  60. package/dist/modules/Rules/index.js +495 -726
  61. package/dist/modules/Rules/types.d.ts +2 -4
  62. package/dist/modules/SalesSummary/index.d.ts +63 -0
  63. package/dist/modules/SalesSummary/index.js +174 -0
  64. package/dist/modules/SalesSummary/types.d.ts +60 -0
  65. package/dist/modules/SalesSummary/types.js +1 -0
  66. package/dist/modules/SalesSummary/utils.d.ts +30 -0
  67. package/dist/modules/SalesSummary/utils.js +480 -0
  68. package/dist/modules/ScanOrderLogger/index.d.ts +23 -0
  69. package/dist/modules/ScanOrderLogger/index.js +174 -0
  70. package/dist/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
  71. package/dist/modules/ScanOrderLogger/providers/feishu.js +221 -0
  72. package/dist/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
  73. package/dist/modules/ScanOrderLogger/providers/grafana.js +50 -0
  74. package/dist/modules/ScanOrderLogger/types.d.ts +53 -0
  75. package/dist/modules/ScanOrderLogger/types.js +1 -0
  76. package/dist/modules/Schedule/getDateIsInSchedule.js +11 -18
  77. package/dist/modules/Schedule/utils.d.ts +1 -1
  78. package/dist/modules/Summary/types.d.ts +0 -2
  79. package/dist/modules/Summary/utils.d.ts +3 -9
  80. package/dist/modules/Summary/utils.js +67 -57
  81. package/dist/modules/index.d.ts +5 -0
  82. package/dist/modules/index.js +6 -1
  83. package/dist/plugins/window.d.ts +3 -2
  84. package/dist/solution/BookingByStep/index.d.ts +17 -3
  85. package/dist/solution/BookingByStep/index.js +322 -247
  86. package/dist/solution/BookingByStep/types.d.ts +4 -1
  87. package/dist/solution/BookingByStep/types.js +7 -1
  88. package/dist/solution/BookingByStep/utils/timeslots.d.ts +3 -1
  89. package/dist/solution/BookingByStep/utils/timeslots.js +19 -12
  90. package/dist/solution/Checkout/index.js +0 -2
  91. package/dist/solution/ScanOrder/index.d.ts +158 -0
  92. package/dist/solution/ScanOrder/index.js +3474 -0
  93. package/dist/solution/ScanOrder/types.d.ts +307 -0
  94. package/dist/solution/ScanOrder/types.js +35 -0
  95. package/dist/solution/ScanOrder/utils.d.ts +172 -0
  96. package/dist/solution/ScanOrder/utils.js +796 -0
  97. package/dist/solution/ShopDiscount/index.d.ts +6 -2
  98. package/dist/solution/ShopDiscount/index.js +194 -110
  99. package/dist/solution/ShopDiscount/types.d.ts +1 -1
  100. package/dist/solution/ShopDiscount/types.js +1 -2
  101. package/dist/solution/ShopDiscount/utils.d.ts +1 -0
  102. package/dist/solution/ShopDiscount/utils.js +52 -27
  103. package/dist/solution/VenueBooking/index.d.ts +225 -0
  104. package/dist/solution/VenueBooking/index.js +3749 -0
  105. package/dist/solution/VenueBooking/sales-section-4-annotated.json +343 -0
  106. package/dist/solution/VenueBooking/types.d.ts +156 -0
  107. package/dist/solution/VenueBooking/types.js +21 -0
  108. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +11 -0
  109. package/dist/solution/VenueBooking/utils/dateSummary.js +104 -0
  110. package/dist/solution/VenueBooking/utils/resource.d.ts +14 -0
  111. package/dist/solution/VenueBooking/utils/resource.js +131 -0
  112. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +38 -0
  113. package/dist/solution/VenueBooking/utils/slotMerge.js +239 -0
  114. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
  115. package/dist/solution/VenueBooking/utils/timeSlot.js +453 -0
  116. package/dist/solution/VenueBooking/utils.d.ts +1 -0
  117. package/dist/solution/VenueBooking/utils.js +1 -0
  118. package/dist/solution/index.d.ts +2 -0
  119. package/dist/solution/index.js +3 -1
  120. package/dist/types/index.d.ts +1 -0
  121. package/lib/apis/picoding.d.ts +0 -0
  122. package/lib/apis/picoding.js +0 -0
  123. package/lib/index.d.ts +0 -1
  124. package/lib/index.js +1 -3
  125. package/lib/model/strategy/adapter/promotion/evaluator.js +8 -57
  126. package/lib/model/strategy/adapter/promotion/index.js +49 -0
  127. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -2
  128. package/lib/model/strategy/adapter/walletPass/evaluator.js +7 -36
  129. package/lib/model/strategy/adapter/walletPass/locales.js +3 -12
  130. package/lib/model/strategy/engine.d.ts +5 -18
  131. package/lib/model/strategy/engine.js +21 -85
  132. package/lib/model/strategy/type.d.ts +0 -17
  133. package/lib/modules/Cart/types.d.ts +0 -2
  134. package/lib/modules/Cart/utils/cartProduct.js +12 -39
  135. package/lib/modules/Cart/utils/changePrice.js +13 -9
  136. package/lib/modules/Discount/availability.d.ts +7 -0
  137. package/lib/modules/Discount/availability.js +91 -0
  138. package/lib/modules/Discount/entitlementPass.d.ts +34 -0
  139. package/lib/modules/Discount/entitlementPass.js +184 -0
  140. package/lib/modules/Discount/entitlementState.d.ts +8 -0
  141. package/lib/modules/Discount/entitlementState.js +206 -0
  142. package/lib/modules/Discount/index.d.ts +12 -3
  143. package/lib/modules/Discount/index.js +123 -12
  144. package/lib/modules/Discount/types.d.ts +42 -22
  145. package/lib/modules/Holder/index.d.ts +48 -0
  146. package/lib/modules/Holder/index.js +402 -0
  147. package/lib/modules/Holder/types.d.ts +123 -0
  148. package/lib/modules/Holder/types.js +17 -0
  149. package/lib/modules/Holder/utils.d.ts +13 -0
  150. package/lib/modules/Holder/utils.js +71 -0
  151. package/lib/modules/OpenData/index.d.ts +24 -0
  152. package/lib/modules/OpenData/index.js +119 -0
  153. package/lib/modules/OpenData/types.d.ts +73 -0
  154. package/lib/modules/OpenData/types.js +17 -0
  155. package/lib/modules/OpenData/utils.d.ts +2 -0
  156. package/lib/modules/OpenData/utils.js +111 -0
  157. package/lib/modules/Order/index.d.ts +67 -1
  158. package/lib/modules/Order/index.js +529 -1
  159. package/lib/modules/Order/types.d.ts +176 -12
  160. package/lib/modules/Order/utils.d.ts +128 -0
  161. package/lib/modules/Order/utils.js +514 -2
  162. package/lib/modules/Payment/index.d.ts +1 -2
  163. package/lib/modules/Payment/index.js +0 -1
  164. package/lib/modules/Payment/utils.js +0 -3
  165. package/lib/modules/Payment/walletpass.d.ts +0 -23
  166. package/lib/modules/Payment/walletpass.js +17 -94
  167. package/lib/modules/Product/types.d.ts +7 -0
  168. package/lib/modules/Product/utils.js +2 -2
  169. package/lib/modules/ProductList/index.d.ts +1 -1
  170. package/lib/modules/ProductList/index.js +5 -4
  171. package/lib/modules/Quotation/index.d.ts +48 -0
  172. package/lib/modules/Quotation/index.js +152 -0
  173. package/lib/modules/Quotation/types.d.ts +42 -0
  174. package/lib/modules/Quotation/types.js +17 -0
  175. package/lib/modules/Rules/entitlementLines.d.ts +8 -0
  176. package/lib/modules/Rules/entitlementLines.js +158 -0
  177. package/lib/modules/Rules/index.d.ts +17 -11
  178. package/lib/modules/Rules/index.js +548 -798
  179. package/lib/modules/Rules/types.d.ts +2 -4
  180. package/lib/modules/SalesSummary/index.d.ts +63 -0
  181. package/lib/modules/SalesSummary/index.js +105 -0
  182. package/lib/modules/SalesSummary/types.d.ts +60 -0
  183. package/lib/modules/SalesSummary/types.js +17 -0
  184. package/lib/modules/SalesSummary/utils.d.ts +30 -0
  185. package/lib/modules/SalesSummary/utils.js +420 -0
  186. package/lib/modules/ScanOrderLogger/index.d.ts +23 -0
  187. package/lib/modules/ScanOrderLogger/index.js +147 -0
  188. package/lib/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
  189. package/lib/modules/ScanOrderLogger/providers/feishu.js +157 -0
  190. package/lib/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
  191. package/lib/modules/ScanOrderLogger/providers/grafana.js +52 -0
  192. package/lib/modules/ScanOrderLogger/types.d.ts +53 -0
  193. package/lib/modules/ScanOrderLogger/types.js +17 -0
  194. package/lib/modules/Schedule/getDateIsInSchedule.js +9 -11
  195. package/lib/modules/Schedule/utils.d.ts +1 -1
  196. package/lib/modules/Summary/types.d.ts +0 -2
  197. package/lib/modules/Summary/utils.d.ts +3 -9
  198. package/lib/modules/Summary/utils.js +45 -34
  199. package/lib/modules/index.d.ts +5 -0
  200. package/lib/modules/index.js +11 -1
  201. package/lib/plugins/window.d.ts +3 -2
  202. package/lib/solution/BookingByStep/index.d.ts +17 -3
  203. package/lib/solution/BookingByStep/index.js +45 -4
  204. package/lib/solution/BookingByStep/types.d.ts +4 -1
  205. package/lib/solution/BookingByStep/types.js +15 -0
  206. package/lib/solution/BookingByStep/utils/timeslots.d.ts +3 -1
  207. package/lib/solution/BookingByStep/utils/timeslots.js +19 -11
  208. package/lib/solution/Checkout/index.js +0 -2
  209. package/lib/solution/ScanOrder/index.d.ts +158 -0
  210. package/lib/solution/ScanOrder/index.js +2135 -0
  211. package/lib/solution/ScanOrder/types.d.ts +307 -0
  212. package/lib/solution/ScanOrder/types.js +36 -0
  213. package/lib/solution/ScanOrder/utils.d.ts +172 -0
  214. package/lib/solution/ScanOrder/utils.js +658 -0
  215. package/lib/solution/ShopDiscount/index.d.ts +6 -2
  216. package/lib/solution/ShopDiscount/index.js +94 -50
  217. package/lib/solution/ShopDiscount/types.d.ts +1 -1
  218. package/lib/solution/ShopDiscount/utils.d.ts +1 -0
  219. package/lib/solution/ShopDiscount/utils.js +48 -11
  220. package/lib/solution/VenueBooking/index.d.ts +225 -0
  221. package/lib/solution/VenueBooking/index.js +2073 -0
  222. package/lib/solution/VenueBooking/sales-section-4-annotated.json +343 -0
  223. package/lib/solution/VenueBooking/types.d.ts +156 -0
  224. package/lib/solution/VenueBooking/types.js +44 -0
  225. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +11 -0
  226. package/lib/solution/VenueBooking/utils/dateSummary.js +110 -0
  227. package/lib/solution/VenueBooking/utils/resource.d.ts +14 -0
  228. package/lib/solution/VenueBooking/utils/resource.js +92 -0
  229. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +38 -0
  230. package/lib/solution/VenueBooking/utils/slotMerge.js +237 -0
  231. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
  232. package/lib/solution/VenueBooking/utils/timeSlot.js +339 -0
  233. package/lib/solution/VenueBooking/utils.d.ts +1 -0
  234. package/lib/solution/VenueBooking/utils.js +69 -0
  235. package/lib/solution/index.d.ts +2 -0
  236. package/lib/solution/index.js +5 -1
  237. package/lib/types/index.d.ts +1 -0
  238. 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,463 @@ 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
+ notifyTempOrderChanged() {
329
+ if (!this.store.tempOrder)
330
+ return;
331
+ this.store.tempOrder = {
332
+ ...this.store.tempOrder,
333
+ products: [...this.store.tempOrder.products],
334
+ bookings: this.store.tempOrder.bookings ? [...this.store.tempOrder.bookings] : []
335
+ };
336
+ this.persistTempOrder();
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
+ }
94
588
  createOrder(params) {
95
589
  var _a;
96
590
  const order = {
@@ -111,6 +605,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
111
605
  let is_deposit = 0;
112
606
  if (params.cartItems.length > 0) {
113
607
  params.cartItems.forEach((item) => {
608
+ var _a2;
114
609
  if (!item._origin.duration) {
115
610
  const { duration, durationType } = (0, import_utils.generateDuration)(item);
116
611
  item._origin.duration = duration;
@@ -118,6 +613,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
118
613
  }
119
614
  const discountList = (0, import_utils.getAllDiscountList)(item);
120
615
  item._origin.product.discount_list = discountList;
616
+ if ((_a2 = params == null ? void 0 : params.extraData) == null ? void 0 : _a2.is_add_holder_info) {
617
+ (0, import_utils.ensureCartItemOriginHolder)(item, this.window);
618
+ }
121
619
  if ((0, import_utils2.isNormalProduct)(item._origin)) {
122
620
  order.relation_products.push(item._origin.product);
123
621
  const relationForms = item._origin.relation_forms || [];
@@ -292,6 +790,36 @@ var OrderModule = class extends import_BaseModule.BaseModule {
292
790
  throw error;
293
791
  }
294
792
  }
793
+ async submitScanOrder(params) {
794
+ const { url, query } = params;
795
+ const fetchUrl = url || "/order/sales/checkout";
796
+ return this.request.post(fetchUrl, query, { customToast: () => {
797
+ } });
798
+ }
799
+ async scanOrderMore(params) {
800
+ const { url, query } = params;
801
+ const fetchUrl = url || `/order/order/product/${query.order_id}`;
802
+ const requestBody = {
803
+ products: query.products,
804
+ request_unique_idempotency_token: query.request_unique_idempotency_token
805
+ };
806
+ return this.request.put(fetchUrl, requestBody, { customToast: () => {
807
+ } });
808
+ }
809
+ // TODO 获取详情的接口
810
+ async getOrderInfoByRemote(order_id) {
811
+ const res = await this.request.get(`/order/sales/${order_id}`, {
812
+ with: ["products", "scheduleEvents"]
813
+ });
814
+ if (res.code === 200 && this.store.tempOrder) {
815
+ this.store.tempOrder.lastOrderInfo = res.data;
816
+ }
817
+ return res;
818
+ }
819
+ getLastOrderInfo() {
820
+ var _a, _b;
821
+ return (_b = (_a = this.store) == null ? void 0 : _a.tempOrder) == null ? void 0 : _b.lastOrderInfo;
822
+ }
295
823
  };
296
824
  // Annotate the CommonJS export names for ESM import in node:
297
825
  0 && (module.exports = {