@pisell/pisellos 2.3.59 → 2.3.61

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 (46) hide show
  1. package/dist/core/index.d.ts +0 -7
  2. package/dist/core/index.js +66 -109
  3. package/dist/model/strategy/adapter/walletPass/evaluator.js +0 -1
  4. package/dist/model/strategy/adapter/walletPass/type.d.ts +5 -0
  5. package/dist/model/strategy/adapter/walletPass/utils.js +57 -24
  6. package/dist/modules/Payment/types.d.ts +2 -0
  7. package/dist/modules/Payment/utils.js +4 -1
  8. package/dist/modules/Payment/walletpass.d.ts +11 -0
  9. package/dist/modules/Payment/walletpass.js +204 -49
  10. package/dist/modules/ProductList/index.js +2 -1
  11. package/dist/modules/Quotation/index.d.ts +0 -6
  12. package/dist/modules/Quotation/index.js +19 -75
  13. package/dist/plugins/request.d.ts +0 -1
  14. package/dist/server/index.js +62 -74
  15. package/dist/server/modules/floor-plan/index.d.ts +0 -4
  16. package/dist/server/modules/floor-plan/index.js +98 -240
  17. package/dist/server/modules/order/index.d.ts +5 -6
  18. package/dist/server/modules/order/index.js +78 -176
  19. package/dist/server/modules/products/index.d.ts +0 -2
  20. package/dist/server/modules/products/index.js +3 -17
  21. package/dist/server/modules/resource/index.js +13 -21
  22. package/dist/solution/BaseSales/index.d.ts +5 -0
  23. package/dist/solution/BaseSales/index.js +311 -281
  24. package/lib/core/index.d.ts +0 -7
  25. package/lib/core/index.js +3 -20
  26. package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -1
  27. package/lib/model/strategy/adapter/walletPass/type.d.ts +5 -0
  28. package/lib/model/strategy/adapter/walletPass/utils.js +62 -10
  29. package/lib/modules/Payment/types.d.ts +2 -0
  30. package/lib/modules/Payment/utils.js +5 -1
  31. package/lib/modules/Payment/walletpass.d.ts +11 -0
  32. package/lib/modules/Payment/walletpass.js +183 -15
  33. package/lib/modules/ProductList/index.js +2 -1
  34. package/lib/modules/Quotation/index.d.ts +0 -6
  35. package/lib/modules/Quotation/index.js +5 -49
  36. package/lib/plugins/request.d.ts +0 -1
  37. package/lib/server/modules/floor-plan/index.d.ts +0 -4
  38. package/lib/server/modules/floor-plan/index.js +6 -54
  39. package/lib/server/modules/order/index.d.ts +5 -6
  40. package/lib/server/modules/order/index.js +23 -105
  41. package/lib/server/modules/products/index.d.ts +0 -2
  42. package/lib/server/modules/products/index.js +4 -15
  43. package/lib/server/modules/resource/index.js +2 -7
  44. package/lib/solution/BaseSales/index.d.ts +5 -0
  45. package/lib/solution/BaseSales/index.js +11 -0
  46. package/package.json +1 -1
@@ -12,15 +12,8 @@ declare class PisellOSCore implements PisellCore {
12
12
  context: BusinessContext;
13
13
  server: any;
14
14
  serverOptions?: ServerOptions;
15
- private serverModulePromise?;
16
15
  constructor(options?: PisellOSOptions);
17
16
  private initialize;
18
- /**
19
- * 仅预加载 Server 模块代码,不创建实例、不注册模块、不请求业务数据。
20
- * 导入失败会清空 Promise,正式 initializeServer 时仍可重新尝试。
21
- */
22
- preloadServerModule(): Promise<void>;
23
- private loadServerModule;
24
17
  /**
25
18
  * 初始化 Server(公开方法,需要外部显式调用并等待)
26
19
  * Server 配置从构造函数传入的 options.server 中获取
@@ -24,6 +24,8 @@ import { EffectsManager } from "../effects";
24
24
  * pisell OS 核心实现
25
25
  */
26
26
  var PisellOSCore = /*#__PURE__*/function () {
27
+ // 保存 Server 配置
28
+
27
29
  function PisellOSCore(options) {
28
30
  _classCallCheck(this, PisellOSCore);
29
31
  _defineProperty(this, "plugins", new Map());
@@ -35,8 +37,6 @@ var PisellOSCore = /*#__PURE__*/function () {
35
37
  _defineProperty(this, "server", void 0);
36
38
  // Server 实例
37
39
  _defineProperty(this, "serverOptions", void 0);
38
- // 保存 Server 配置
39
- _defineProperty(this, "serverModulePromise", void 0);
40
40
  this.debug = (options === null || options === void 0 ? void 0 : options.debug) || false;
41
41
  this.context = (options === null || options === void 0 ? void 0 : options.context) || {};
42
42
 
@@ -45,7 +45,7 @@ var PisellOSCore = /*#__PURE__*/function () {
45
45
  this.serverOptions = options.server;
46
46
  }
47
47
  this.initialize(options);
48
- console.log('constructor123456');
48
+ console.log('constructor1234');
49
49
  }
50
50
  _createClass(PisellOSCore, [{
51
51
  key: "initialize",
@@ -64,49 +64,6 @@ var PisellOSCore = /*#__PURE__*/function () {
64
64
  this.log('[PisellOS] 核心初始化完成');
65
65
  }
66
66
 
67
- /**
68
- * 仅预加载 Server 模块代码,不创建实例、不注册模块、不请求业务数据。
69
- * 导入失败会清空 Promise,正式 initializeServer 时仍可重新尝试。
70
- */
71
- }, {
72
- key: "preloadServerModule",
73
- value: (function () {
74
- var _preloadServerModule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
75
- return _regeneratorRuntime().wrap(function _callee$(_context) {
76
- while (1) switch (_context.prev = _context.next) {
77
- case 0:
78
- if (!(this.server || !this.serverOptions)) {
79
- _context.next = 2;
80
- break;
81
- }
82
- return _context.abrupt("return");
83
- case 2:
84
- _context.next = 4;
85
- return this.loadServerModule();
86
- case 4:
87
- case "end":
88
- return _context.stop();
89
- }
90
- }, _callee, this);
91
- }));
92
- function preloadServerModule() {
93
- return _preloadServerModule.apply(this, arguments);
94
- }
95
- return preloadServerModule;
96
- }())
97
- }, {
98
- key: "loadServerModule",
99
- value: function loadServerModule() {
100
- var _this2 = this;
101
- if (!this.serverModulePromise) {
102
- this.serverModulePromise = import("../server").catch(function (error) {
103
- _this2.serverModulePromise = undefined;
104
- throw error;
105
- });
106
- }
107
- return this.serverModulePromise;
108
- }
109
-
110
67
  /**
111
68
  * 初始化 Server(公开方法,需要外部显式调用并等待)
112
69
  * Server 配置从构造函数传入的 options.server 中获取
@@ -114,57 +71,57 @@ var PisellOSCore = /*#__PURE__*/function () {
114
71
  }, {
115
72
  key: "initializeServer",
116
73
  value: (function () {
117
- var _initializeServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
74
+ var _initializeServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
118
75
  var ServerModule, Server;
119
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
120
- while (1) switch (_context2.prev = _context2.next) {
76
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
77
+ while (1) switch (_context.prev = _context.next) {
121
78
  case 0:
122
79
  if (!this.server) {
123
- _context2.next = 3;
80
+ _context.next = 3;
124
81
  break;
125
82
  }
126
83
  this.log('Server 已经初始化,跳过重复初始化', 'warn');
127
- return _context2.abrupt("return");
84
+ return _context.abrupt("return");
128
85
  case 3:
129
86
  if (this.serverOptions) {
130
- _context2.next = 6;
87
+ _context.next = 6;
131
88
  break;
132
89
  }
133
90
  this.log('未提供 Server 配置,无法初始化', 'warn');
134
- return _context2.abrupt("return");
91
+ return _context.abrupt("return");
135
92
  case 6:
136
- _context2.prev = 6;
137
- _context2.next = 9;
138
- return this.loadServerModule();
93
+ _context.prev = 6;
94
+ _context.next = 9;
95
+ return import("../server");
139
96
  case 9:
140
- ServerModule = _context2.sent;
97
+ ServerModule = _context.sent;
141
98
  Server = ServerModule.default; // 创建 Server 实例
142
99
  this.server = new Server(this);
143
100
  this.log('Server 实例已创建');
144
101
 
145
102
  // 初始化模块并预加载数据
146
103
  if (!this.serverOptions.modules) {
147
- _context2.next = 16;
104
+ _context.next = 16;
148
105
  break;
149
106
  }
150
- _context2.next = 16;
107
+ _context.next = 16;
151
108
  return this.server.initialize(this.serverOptions.modules, this.serverOptions.autoInitData !== false, options);
152
109
  case 16:
153
110
  console.log('[PisellOS] ✅ Server 初始化完成,所有数据已预加载');
154
111
  this.log('[PisellOS] Server 初始化完成');
155
- _context2.next = 25;
112
+ _context.next = 25;
156
113
  break;
157
114
  case 20:
158
- _context2.prev = 20;
159
- _context2.t0 = _context2["catch"](6);
160
- console.error('[PisellOS] ❌ Server 初始化失败:', _context2.t0);
161
- this.log("Server \u521D\u59CB\u5316\u5931\u8D25: ".concat(_context2.t0), 'error');
162
- throw _context2.t0;
115
+ _context.prev = 20;
116
+ _context.t0 = _context["catch"](6);
117
+ console.error('[PisellOS] ❌ Server 初始化失败:', _context.t0);
118
+ this.log("Server \u521D\u59CB\u5316\u5931\u8D25: ".concat(_context.t0), 'error');
119
+ throw _context.t0;
163
120
  case 25:
164
121
  case "end":
165
- return _context2.stop();
122
+ return _context.stop();
166
123
  }
167
- }, _callee2, this, [[6, 20]]);
124
+ }, _callee, this, [[6, 20]]);
168
125
  }));
169
126
  function initializeServer(_x) {
170
127
  return _initializeServer.apply(this, arguments);
@@ -197,7 +154,7 @@ var PisellOSCore = /*#__PURE__*/function () {
197
154
  }, {
198
155
  key: "registerPlugin",
199
156
  value: function registerPlugin(plugin, options) {
200
- var _this3 = this;
157
+ var _this2 = this;
201
158
  if (this.plugins.has(plugin.name)) {
202
159
  this.log("\u63D2\u4EF6 ".concat(plugin.name, " \u5DF2\u7ECF\u6CE8\u518C\u8FC7\uFF0C\u5C06\u88AB\u8986\u76D6"), 'warn');
203
160
  }
@@ -225,7 +182,7 @@ var PisellOSCore = /*#__PURE__*/function () {
225
182
  var result = plugin.initialize();
226
183
  if (result instanceof Promise) {
227
184
  result.catch(function (err) {
228
- _this3.log("\u63D2\u4EF6 ".concat(plugin.name, " \u521D\u59CB\u5316\u5931\u8D25: ").concat(err.message), 'error');
185
+ _this2.log("\u63D2\u4EF6 ".concat(plugin.name, " \u521D\u59CB\u5316\u5931\u8D25: ").concat(err.message), 'error');
229
186
  throw err;
230
187
  });
231
188
  }
@@ -251,7 +208,7 @@ var PisellOSCore = /*#__PURE__*/function () {
251
208
  }, {
252
209
  key: "registerModule",
253
210
  value: function registerModule(module, options) {
254
- var _this4 = this;
211
+ var _this3 = this;
255
212
  if (this.modules.has(module.name)) {
256
213
  this.log("\u6A21\u5757 ".concat(module.name, " \u5DF2\u7ECF\u6CE8\u518C\u8FC7\uFF0C\u5C06\u88AB\u8986\u76D6"), 'warn');
257
214
  }
@@ -294,7 +251,7 @@ var PisellOSCore = /*#__PURE__*/function () {
294
251
  // 预先给模块初始化值系统
295
252
  var _createStore = createStore((options === null || options === void 0 ? void 0 : options.initialState) || {}, module.name, function (path, value) {
296
253
  console.log('core 检测到模块值更新', module.name, path, value);
297
- _this4.effects.emit("".concat(module.name, ":changed"), {
254
+ _this3.effects.emit("".concat(module.name, ":changed"), {
298
255
  path: path,
299
256
  value: value
300
257
  });
@@ -309,7 +266,7 @@ var PisellOSCore = /*#__PURE__*/function () {
309
266
  }, options));
310
267
  if (result instanceof Promise) {
311
268
  result.catch(function (err) {
312
- _this4.log("\u6A21\u5757 ".concat(module.name, " \u521D\u59CB\u5316\u5931\u8D25: ").concat(err.message), 'error');
269
+ _this3.log("\u6A21\u5757 ".concat(module.name, " \u521D\u59CB\u5316\u5931\u8D25: ").concat(err.message), 'error');
313
270
  throw err;
314
271
  });
315
272
  }
@@ -354,100 +311,100 @@ var PisellOSCore = /*#__PURE__*/function () {
354
311
  }, {
355
312
  key: "destroy",
356
313
  value: function () {
357
- var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
314
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
358
315
  var _iterator4, _step4, _step4$value, name, module, _iterator5, _step5, _step5$value, _name, plugin;
359
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
360
- while (1) switch (_context3.prev = _context3.next) {
316
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
317
+ while (1) switch (_context2.prev = _context2.next) {
361
318
  case 0:
362
319
  // 先销毁模块
363
320
  _iterator4 = _createForOfIteratorHelper(this.modules.entries());
364
- _context3.prev = 1;
321
+ _context2.prev = 1;
365
322
  _iterator4.s();
366
323
  case 3:
367
324
  if ((_step4 = _iterator4.n()).done) {
368
- _context3.next = 17;
325
+ _context2.next = 17;
369
326
  break;
370
327
  }
371
328
  _step4$value = _slicedToArray(_step4.value, 2), name = _step4$value[0], module = _step4$value[1];
372
329
  if (!module.destroy) {
373
- _context3.next = 15;
330
+ _context2.next = 15;
374
331
  break;
375
332
  }
376
- _context3.prev = 6;
377
- _context3.next = 9;
333
+ _context2.prev = 6;
334
+ _context2.next = 9;
378
335
  return Promise.resolve(module.destroy());
379
336
  case 9:
380
337
  this.log("\u6A21\u5757 ".concat(name, " \u5DF2\u9500\u6BC1"));
381
- _context3.next = 15;
338
+ _context2.next = 15;
382
339
  break;
383
340
  case 12:
384
- _context3.prev = 12;
385
- _context3.t0 = _context3["catch"](6);
386
- this.log("\u9500\u6BC1\u6A21\u5757 ".concat(name, " \u65F6\u51FA\u9519: ").concat(_context3.t0), 'error');
341
+ _context2.prev = 12;
342
+ _context2.t0 = _context2["catch"](6);
343
+ this.log("\u9500\u6BC1\u6A21\u5757 ".concat(name, " \u65F6\u51FA\u9519: ").concat(_context2.t0), 'error');
387
344
  case 15:
388
- _context3.next = 3;
345
+ _context2.next = 3;
389
346
  break;
390
347
  case 17:
391
- _context3.next = 22;
348
+ _context2.next = 22;
392
349
  break;
393
350
  case 19:
394
- _context3.prev = 19;
395
- _context3.t1 = _context3["catch"](1);
396
- _iterator4.e(_context3.t1);
351
+ _context2.prev = 19;
352
+ _context2.t1 = _context2["catch"](1);
353
+ _iterator4.e(_context2.t1);
397
354
  case 22:
398
- _context3.prev = 22;
355
+ _context2.prev = 22;
399
356
  _iterator4.f();
400
- return _context3.finish(22);
357
+ return _context2.finish(22);
401
358
  case 25:
402
359
  this.modules.clear();
403
360
 
404
361
  // 再销毁插件
405
362
  _iterator5 = _createForOfIteratorHelper(this.plugins.entries());
406
- _context3.prev = 27;
363
+ _context2.prev = 27;
407
364
  _iterator5.s();
408
365
  case 29:
409
366
  if ((_step5 = _iterator5.n()).done) {
410
- _context3.next = 43;
367
+ _context2.next = 43;
411
368
  break;
412
369
  }
413
370
  _step5$value = _slicedToArray(_step5.value, 2), _name = _step5$value[0], plugin = _step5$value[1];
414
371
  if (!plugin.destroy) {
415
- _context3.next = 41;
372
+ _context2.next = 41;
416
373
  break;
417
374
  }
418
- _context3.prev = 32;
419
- _context3.next = 35;
375
+ _context2.prev = 32;
376
+ _context2.next = 35;
420
377
  return Promise.resolve(plugin.destroy());
421
378
  case 35:
422
379
  this.log("\u63D2\u4EF6 ".concat(_name, " \u5DF2\u9500\u6BC1"));
423
- _context3.next = 41;
380
+ _context2.next = 41;
424
381
  break;
425
382
  case 38:
426
- _context3.prev = 38;
427
- _context3.t2 = _context3["catch"](32);
428
- this.log("\u9500\u6BC1\u63D2\u4EF6 ".concat(_name, " \u65F6\u51FA\u9519: ").concat(_context3.t2), 'error');
383
+ _context2.prev = 38;
384
+ _context2.t2 = _context2["catch"](32);
385
+ this.log("\u9500\u6BC1\u63D2\u4EF6 ".concat(_name, " \u65F6\u51FA\u9519: ").concat(_context2.t2), 'error');
429
386
  case 41:
430
- _context3.next = 29;
387
+ _context2.next = 29;
431
388
  break;
432
389
  case 43:
433
- _context3.next = 48;
390
+ _context2.next = 48;
434
391
  break;
435
392
  case 45:
436
- _context3.prev = 45;
437
- _context3.t3 = _context3["catch"](27);
438
- _iterator5.e(_context3.t3);
393
+ _context2.prev = 45;
394
+ _context2.t3 = _context2["catch"](27);
395
+ _iterator5.e(_context2.t3);
439
396
  case 48:
440
- _context3.prev = 48;
397
+ _context2.prev = 48;
441
398
  _iterator5.f();
442
- return _context3.finish(48);
399
+ return _context2.finish(48);
443
400
  case 51:
444
401
  this.plugins.clear();
445
402
  this.log('PisellOS 核心已销毁');
446
403
  case 53:
447
404
  case "end":
448
- return _context3.stop();
405
+ return _context2.stop();
449
406
  }
450
- }, _callee3, this, [[1, 19, 22, 25], [6, 12], [27, 45, 48, 51], [32, 38]]);
407
+ }, _callee2, this, [[1, 19, 22, 25], [6, 12], [27, 45, 48, 51], [32, 38]]);
451
408
  }));
452
409
  function destroy() {
453
410
  return _destroy.apply(this, arguments);
@@ -257,7 +257,6 @@ export var WalletPassEvaluator = /*#__PURE__*/function () {
257
257
  var rawText = this.getText(reasonCode);
258
258
  // 金额类型字段:从 otherParams.getData 取货币符号;非金额或取不到则留空
259
259
  var currency = failedField && AMOUNT_FIELDS.has(failedField) ? ((_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 || (_this$otherParams$get = (_this$otherParams2 = _this$otherParams).getData) === null || _this$otherParams$get === void 0 ? void 0 : _this$otherParams$get.call(_this$otherParams2, 'shop_symbol')) || '' : '';
260
- console.log(currency, 'currency12345');
261
260
  var reason = thresholdValue !== undefined ? formatReason(rawText, thresholdValue, currency) : rawText;
262
261
  results.push({
263
262
  voucher: voucher,
@@ -26,6 +26,11 @@ export interface Voucher {
26
26
  recommended_usage_amount: number;
27
27
  /** 后端计算推荐使用金额(仅商品) 不包含税费附加费 */
28
28
  recommended_pure_product_usage_amount: number;
29
+ /**
30
+ * 扫码资产自身可供前端重新计算的金额基准。
31
+ * 后端 recommended_usage_amount 会包含当前已选券上下文,取消勾选后不能继续把它当作资产永久上限。
32
+ */
33
+ _wallet_asset_recalculation_base_amount?: number;
29
34
  /** 实际抵扣金额 */
30
35
  actualDeduction: number;
31
36
  /** 抵扣详情 */
@@ -1,9 +1,4 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
2
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
8
3
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
9
4
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -11,7 +6,25 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
11
6
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
12
7
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
13
8
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
9
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
10
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
11
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
13
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
14
14
  import Decimal from 'decimal.js';
15
+ var DEFAULT_WALLET_PASS_CALCULATION_CONFIG = {
16
+ maxDeductionAmount: 99999,
17
+ maxUsagePerOrder: 0,
18
+ allowCrossProduct: true,
19
+ applicableProductLimit: 0,
20
+ deductTaxAndFee: true,
21
+ maxPassesPerItem: 0,
22
+ deductOptionPrice: false
23
+ };
24
+ function getWalletPassCalculationConfig(voucher) {
25
+ return _objectSpread(_objectSpread({}, DEFAULT_WALLET_PASS_CALCULATION_CONFIG), (voucher === null || voucher === void 0 ? void 0 : voucher.config) || {});
26
+ }
27
+
15
28
  /** 订单商品数量 */
16
29
  export var getProductQuantity = function getProductQuantity(product) {
17
30
  return product.quantity || product.product_quantity || 1;
@@ -72,12 +85,22 @@ function applyMaxPassUsageIncrements(usageMap, walletPassProductId, maxPassesPer
72
85
  // 辅助函数:根据 deductTaxAndFee 配置获取推荐使用金额
73
86
  var getRecommendedAmount = function getRecommendedAmount(voucher) {
74
87
  var _config$deductTaxAndF;
75
- console.log('voucher312', voucher);
76
88
  var config = voucher.config,
77
89
  recommended_usage_amount = voucher.recommended_usage_amount,
78
90
  recommended_pure_product_usage_amount = voucher.recommended_pure_product_usage_amount;
79
91
  var deductTaxAndFee = (_config$deductTaxAndF = config === null || config === void 0 ? void 0 : config.deductTaxAndFee) !== null && _config$deductTaxAndF !== void 0 ? _config$deductTaxAndF : true; // 默认开启抵扣税费
80
92
 
93
+ // 扫码接口的 recommended_* 金额包含搜索时已选券的上下文,可能只是当时的
94
+ // 剩余可抵扣额。取消其他券后,前端重算需要回到资产自身金额基准,再由
95
+ // 剩余订单金额、适用商品金额和策略上限重新裁剪。
96
+ var rawRecalculationBaseAmount = voucher._wallet_asset_recalculation_base_amount;
97
+ if (rawRecalculationBaseAmount !== undefined && rawRecalculationBaseAmount !== null) {
98
+ var recalculationBaseAmount = Number(rawRecalculationBaseAmount);
99
+ if (Number.isFinite(recalculationBaseAmount) && recalculationBaseAmount >= 0) {
100
+ return recalculationBaseAmount;
101
+ }
102
+ }
103
+
81
104
  // 如果开启抵扣税费,使用 recommended_usage_amount(包含税费)
82
105
  // 如果关闭抵扣税费,使用 recommended_pure_product_usage_amount(仅商品金额)
83
106
  return deductTaxAndFee ? recommended_usage_amount : recommended_pure_product_usage_amount !== null && recommended_pure_product_usage_amount !== void 0 ? recommended_pure_product_usage_amount : recommended_usage_amount;
@@ -285,7 +308,6 @@ export function processVouchers(applicableVouchers, orderTotalAmount, products)
285
308
  // 辅助函数:判断券是否可用,返回可用性和原因代码
286
309
  var isVoucherAvailable = function isVoucherAvailable(voucher, productsData, usedVoucherCounts, itemPassUsage) {
287
310
  var config = voucher.config,
288
- id = voucher.id,
289
311
  product_id = voucher.product_id;
290
312
 
291
313
  // 根据 deductTaxAndFee 配置获取推荐金额
@@ -659,6 +681,7 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
659
681
  var productsForCalc = expandProductsWithBundleItems(products, true);
660
682
  var remainingOrderAmount = new Decimal(orderTotalAmount);
661
683
  var selectedWithDetails = [];
684
+ var usedVoucherCounts = new Map();
662
685
 
663
686
  // 追踪每个 Wallet Pass 商品对每个订单商品行的已使用卡券次数(按行唯一键)
664
687
  var itemPassUsageMap = new Map();
@@ -678,15 +701,26 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
678
701
  // 第一步:按顺序应用已选中的券,计算实际抵扣
679
702
  selectedVouchers.forEach(function (selectedVoucher) {
680
703
  var _selectedVoucher$_ava;
681
- var config = selectedVoucher.config,
682
- id = selectedVoucher.id;
704
+ var product_id = selectedVoucher.product_id;
705
+ var config = getWalletPassCalculationConfig(selectedVoucher);
683
706
  var maxDeductionAmount = config.maxDeductionAmount,
707
+ maxUsagePerOrder = config.maxUsagePerOrder,
684
708
  allowCrossProduct = config.allowCrossProduct,
685
709
  applicableProductLimit = config.applicableProductLimit,
686
- _config$deductTaxAndF4 = config.deductTaxAndFee,
687
- deductTaxAndFee = _config$deductTaxAndF4 === void 0 ? true : _config$deductTaxAndF4,
688
- _config$maxPassesPerI = config.maxPassesPerItem,
689
- maxPassesPerItem = _config$maxPassesPerI === void 0 ? 0 : _config$maxPassesPerI;
710
+ deductTaxAndFee = config.deductTaxAndFee,
711
+ maxPassesPerItem = config.maxPassesPerItem;
712
+ var usedCount = usedVoucherCounts.get(product_id) || 0;
713
+ if (maxUsagePerOrder > 0 && usedCount >= maxUsagePerOrder) {
714
+ selectedWithDetails.push(_objectSpread(_objectSpread({}, selectedVoucher), {}, {
715
+ config: config,
716
+ actualDeduction: 0,
717
+ deductionDetails: [],
718
+ _available_max_amount: 0,
719
+ _unified_available_status: 0,
720
+ reasonCode: 'usage_limit_reached'
721
+ }));
722
+ return;
723
+ }
690
724
 
691
725
  // 根据券的配置选择使用哪个单价字段和金额字段
692
726
  var unitPriceField = deductTaxAndFee ? 'unitPriceWithTax' : 'unitPricePure';
@@ -702,6 +736,7 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
702
736
  if (applicableProducts.length === 0) {
703
737
  // 无适用商品,跳过
704
738
  selectedWithDetails.push(_objectSpread(_objectSpread({}, selectedVoucher), {}, {
739
+ config: config,
705
740
  actualDeduction: 0,
706
741
  deductionDetails: [],
707
742
  _available_max_amount: 0,
@@ -798,6 +833,7 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
798
833
  remainingOrderAmount = remainingOrderAmount.minus(totalDeducted);
799
834
  applyMaxPassUsageIncrements(itemPassUsageMap, selectedVoucher.product_id, maxPassesPerItem, deductionDetails);
800
835
  selectedWithDetails.push(_objectSpread(_objectSpread({}, selectedVoucher), {}, {
836
+ config: config,
801
837
  actualDeduction: totalDeducted.toNumber(),
802
838
  // 转换为数字
803
839
  deductionDetails: deductionDetails,
@@ -805,16 +841,15 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
805
841
  // 转换为数字
806
842
  _unified_available_status: totalDeducted.greaterThan(0) ? 1 : 0
807
843
  }));
844
+ if (totalDeducted.greaterThan(0)) {
845
+ usedVoucherCounts.set(product_id, usedCount + 1);
846
+ }
808
847
  });
809
848
 
810
849
  // 第二步:为所有券重新计算 _available_max_amount 和 _unified_available_status
811
850
  var selectedIds = new Set(selectedVouchers.map(function (v) {
812
851
  return v.id;
813
852
  }));
814
- var usedVoucherCounts = new Map();
815
- selectedVouchers.forEach(function (v) {
816
- usedVoucherCounts.set(v.product_id, (usedVoucherCounts.get(v.product_id) || 0) + 1);
817
- });
818
853
  var allWithUpdatedStatus = allVouchers.map(function (voucher) {
819
854
  // 如果是已选中的券,使用详细计算结果
820
855
  if (selectedIds.has(voucher.id)) {
@@ -825,16 +860,13 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
825
860
  }
826
861
 
827
862
  // 未选中的券,重新计算其可用状态
828
- var config = voucher.config,
829
- id = voucher.id,
830
- product_id = voucher.product_id;
863
+ var product_id = voucher.product_id;
864
+ var config = getWalletPassCalculationConfig(voucher);
831
865
  var maxDeductionAmount = config.maxDeductionAmount,
832
866
  allowCrossProduct = config.allowCrossProduct,
833
867
  applicableProductLimit = config.applicableProductLimit,
834
- _config$deductTaxAndF5 = config.deductTaxAndFee,
835
- deductTaxAndFee = _config$deductTaxAndF5 === void 0 ? true : _config$deductTaxAndF5,
836
- _config$maxPassesPerI2 = config.maxPassesPerItem,
837
- maxPassesPerItem = _config$maxPassesPerI2 === void 0 ? 0 : _config$maxPassesPerI2;
868
+ deductTaxAndFee = config.deductTaxAndFee,
869
+ maxPassesPerItem = config.maxPassesPerItem;
838
870
 
839
871
  // 根据券的配置选择使用哪个单价字段和金额字段
840
872
  var unitPriceField = deductTaxAndFee ? 'unitPriceWithTax' : 'unitPricePure';
@@ -929,6 +961,7 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
929
961
  }
930
962
  }
931
963
  return _objectSpread(_objectSpread({}, voucher), {}, {
964
+ config: config,
932
965
  _available_max_amount: calculatedMaxAmount.toNumber(),
933
966
  // 转换为数字
934
967
  _unified_available_status: isAvailable ? 1 : 0
@@ -486,6 +486,8 @@ export interface WalletPassPayment {
486
486
  importWalletAssetsSnapshot: (snapshot: WalletAssetsSnapshot) => WalletAssetsState;
487
487
  /** 设置单张钱包资产的选择状态并重新计算其实际抵扣额。 */
488
488
  selectWalletAsset: (assetId: WalletAssetId, options: SelectWalletAssetOptions) => WalletAssetsState;
489
+ /** 更新已选钱包资产的手动使用金额,并保持原有选择顺序重新计算。 */
490
+ updateWalletAssetAmount: (assetId: WalletAssetId, amount: number) => WalletAssetsState;
489
491
  /** 精确搜索钱包资产;仅当前券可用时自动选择。 */
490
492
  scanWalletAssetAsync: (code: string) => Promise<ScanWalletAssetResult>;
491
493
  /** 清空未确认的钱包资产选择。 */
@@ -12,9 +12,12 @@ export var getAvailableMaxAmount = function getAvailableMaxAmount(data) {
12
12
  */
13
13
  export var formatWalletPassList2PreparePayments = function formatWalletPassList2PreparePayments(list) {
14
14
  var formatted = (list || []).map(function (item) {
15
+ var _ref, _item$actualDeduction;
15
16
  return {
16
17
  voucher_id: item.id || 0,
17
- amount: Number(item.edit_current_amount || getAvailableMaxAmount(item)) || 0,
18
+ // 前端策略重算后的 actualDeduction 才是最终可同步金额;
19
+ // edit_current_amount 只是用户请求值,仍可能被策略和订单剩余金额裁剪。
20
+ amount: Number((_ref = (_item$actualDeduction = item.actualDeduction) !== null && _item$actualDeduction !== void 0 ? _item$actualDeduction : item.edit_current_amount) !== null && _ref !== void 0 ? _ref : getAvailableMaxAmount(item)) || 0,
18
21
  tag: item.tag || '',
19
22
  wallet_pass_usage_unit: item.wallet_pass_usage_unit || {},
20
23
  wallet_pass_use_value: item.wallet_pass_use_value || undefined
@@ -24,6 +24,11 @@ export declare class WalletPassPaymentImpl implements WalletPassPayment {
24
24
  private emitEvent;
25
25
  private publishWalletAssetsState;
26
26
  private recalculateWalletAssets;
27
+ /**
28
+ * 搜索接口只返回后端 Wallet Pass 数据,不包含前端策略 config。
29
+ * 在资产进入共享选择状态前补齐策略结果,避免增量重算回退到接口状态。
30
+ */
31
+ private formatSearchedWalletPaymentAssets;
27
32
  /** 获取当前缓存中所有支付类 Wallet 资产的扫码 code。 */
28
33
  private getSearchedWalletAssetCodes;
29
34
  /**
@@ -106,7 +111,13 @@ export declare class WalletPassPaymentImpl implements WalletPassPayment {
106
111
  getWalletAssetsState(): WalletAssetsState;
107
112
  exportWalletAssetsSnapshot(): WalletAssetsSnapshot;
108
113
  importWalletAssetsSnapshot(snapshot: WalletAssetsSnapshot): WalletAssetsState;
114
+ private updateWalletAssetEditAmountInCaches;
109
115
  selectWalletAsset(assetId: WalletAssetId, options: SelectWalletAssetOptions): WalletAssetsState;
116
+ /**
117
+ * 更新已选资产的手动金额。只允许在当前实际抵扣额内向下调整,
118
+ * 金额为 0 时沿用 legacy 行为取消选择。
119
+ */
120
+ updateWalletAssetAmount(assetId: WalletAssetId, amount: number): WalletAssetsState;
110
121
  scanWalletAssetAsync(code: string): Promise<ScanWalletAssetResult>;
111
122
  clearWalletAssetSelection(): WalletAssetsState;
112
123
  setCommittedWalletAssets(committedIds: WalletAssetId[], committedAssets?: any[]): WalletAssetsState;