@pisell/pisellos 3.0.90 → 3.0.91

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