@pisell/pisellos 0.0.230 → 0.0.232
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.
- package/dist/modules/Order/index.d.ts +13 -2
- package/dist/modules/Order/index.js +93 -1
- package/dist/modules/Order/types.d.ts +45 -0
- package/dist/modules/Order/types.js +8 -0
- package/dist/modules/Payment/cash.d.ts +8 -0
- package/dist/modules/Payment/cash.js +20 -1
- package/dist/modules/Payment/cashRecommendationAlgorithm.d.ts +22 -0
- package/dist/modules/Payment/cashRecommendationAlgorithm.js +423 -0
- package/dist/modules/Payment/eftpos.js +1 -1
- package/dist/modules/Payment/index.d.ts +34 -124
- package/dist/modules/Payment/index.js +662 -1280
- package/dist/modules/Payment/mx51.d.ts +0 -0
- package/dist/modules/Payment/mx51.js +0 -0
- package/dist/modules/Payment/types.d.ts +323 -45
- package/dist/modules/Payment/types.js +101 -2
- package/dist/modules/Payment/utils.d.ts +17 -0
- package/dist/modules/Payment/utils.js +62 -0
- package/dist/modules/Payment/walletpass.d.ts +96 -0
- package/dist/modules/Payment/walletpass.js +492 -0
- package/dist/modules/Schedule/index.d.ts +9 -0
- package/dist/modules/Schedule/index.js +60 -0
- package/dist/solution/Checkout/index.d.ts +254 -2
- package/dist/solution/Checkout/index.js +2472 -320
- package/dist/solution/Checkout/types.d.ts +207 -6
- package/dist/solution/Checkout/types.js +5 -0
- package/lib/modules/Order/index.d.ts +13 -2
- package/lib/modules/Order/index.js +65 -1
- package/lib/modules/Order/types.d.ts +45 -0
- package/lib/modules/Payment/cash.d.ts +8 -0
- package/lib/modules/Payment/cash.js +14 -1
- package/lib/modules/Payment/cashRecommendationAlgorithm.d.ts +22 -0
- package/lib/modules/Payment/cashRecommendationAlgorithm.js +342 -0
- package/lib/modules/Payment/eftpos.js +1 -1
- package/lib/modules/Payment/index.d.ts +34 -124
- package/lib/modules/Payment/index.js +232 -533
- package/lib/modules/Payment/mx51.d.ts +0 -0
- package/lib/modules/Payment/mx51.js +0 -0
- package/lib/modules/Payment/types.d.ts +323 -45
- package/lib/modules/Payment/types.js +37 -2
- package/lib/modules/Payment/utils.d.ts +17 -0
- package/lib/modules/Payment/utils.js +67 -0
- package/lib/modules/Payment/walletpass.d.ts +96 -0
- package/lib/modules/Payment/walletpass.js +304 -0
- package/lib/modules/Schedule/index.d.ts +9 -0
- package/lib/modules/Schedule/index.js +36 -0
- package/lib/solution/Checkout/index.d.ts +254 -2
- package/lib/solution/Checkout/index.js +1361 -39
- package/lib/solution/Checkout/types.d.ts +207 -6
- package/lib/solution/Checkout/types.js +5 -0
- package/package.json +1 -1
- package/dist/modules/Payment/wallet.d.ts +0 -11
- package/dist/modules/Payment/wallet.js +0 -78
- package/lib/modules/Payment/wallet.d.ts +0 -11
- package/lib/modules/Payment/wallet.js +0 -51
|
@@ -21,11 +21,11 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
21
21
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
22
22
|
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); }
|
|
23
23
|
import { BaseModule } from "../BaseModule";
|
|
24
|
-
import { PaymentStatus, PaymentHooks, PaymentMethodType } from "./types";
|
|
24
|
+
import { PaymentStatus, PaymentHooks, PaymentMethodType, RoundingRule } from "./types";
|
|
25
25
|
import { getUniqueId } from "../Cart/utils";
|
|
26
26
|
import { CashPaymentImpl } from "./cash";
|
|
27
27
|
import { EftposPaymentImpl } from "./eftpos";
|
|
28
|
-
import {
|
|
28
|
+
import { WalletPassPaymentImpl } from "./walletpass";
|
|
29
29
|
import { Decimal } from 'decimal.js';
|
|
30
30
|
export * from "./types";
|
|
31
31
|
export { generateRequestUniqueId };
|
|
@@ -65,28 +65,7 @@ function generateRequestUniqueId() {
|
|
|
65
65
|
/**
|
|
66
66
|
* 支付模块实现
|
|
67
67
|
*
|
|
68
|
-
*
|
|
69
|
-
* 1. 用户操作 → 调用支付API (pushPaymentAsync, submitPayAsync等)
|
|
70
|
-
* 2. 数据处理 → 更新本地IndexDB中的订单和支付项数据
|
|
71
|
-
* 3. 立即完成 → 本地订单状态立即更新为PaymentStatus.Finished(isSynced保持false)
|
|
72
|
-
* 4. 后台同步 → 网络请求推送到TasksManager异步同步到服务器
|
|
73
|
-
* 5. 同步成功 → 网络请求成功后,isSynced设为true
|
|
74
|
-
* 6. 自动重试 → TasksManager自动重试失败的网络请求,直到isSynced为true
|
|
75
|
-
*
|
|
76
|
-
* 数据状态说明:
|
|
77
|
-
* - PaymentStatus.Processing: 订单正在进行支付操作
|
|
78
|
-
* - PaymentStatus.PartiallyPaid + isSynced=false: 部分支付完成,等待服务器同步
|
|
79
|
-
* - PaymentStatus.PartiallyPaid + isSynced=true: 部分支付且已同步到服务器
|
|
80
|
-
* - PaymentStatus.Finished + isSynced=false: 本地支付完成,等待服务器同步
|
|
81
|
-
* - PaymentStatus.Finished + isSynced=true: 支付完成且已同步到服务器
|
|
82
|
-
*
|
|
83
|
-
* 这种设计的优势:
|
|
84
|
-
* - 即时反馈:支付操作后立即显示完成状态,用户体验更佳
|
|
85
|
-
* - 离线支持:即使网络断开也能正常操作,数据保存在本地
|
|
86
|
-
* - 同步追踪:通过isSynced清楚知道哪些数据还未同步到服务器
|
|
87
|
-
* - 自动重试:TasksManager会自动重试失败的网络请求
|
|
88
|
-
* - 异步处理:不阻塞用户界面,网络同步在后台进行
|
|
89
|
-
* - 数据一致性:通过事件系统确保数据状态同步
|
|
68
|
+
* 负责处理支付相关的数据管理和本地存储
|
|
90
69
|
*/
|
|
91
70
|
export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
92
71
|
_inherits(PaymentModule, _BaseModule);
|
|
@@ -112,7 +91,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
112
91
|
_defineProperty(_assertThisInitialized(_this), "wallet", void 0);
|
|
113
92
|
_this.cash = new CashPaymentImpl(_assertThisInitialized(_this));
|
|
114
93
|
_this.eftpos = new EftposPaymentImpl(_assertThisInitialized(_this));
|
|
115
|
-
_this.wallet = new
|
|
94
|
+
_this.wallet = new WalletPassPaymentImpl(_assertThisInitialized(_this));
|
|
116
95
|
return _this;
|
|
117
96
|
}
|
|
118
97
|
_createClass(PaymentModule, [{
|
|
@@ -149,12 +128,10 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
149
128
|
_context.next = 13;
|
|
150
129
|
return this.ensurePaymentTables();
|
|
151
130
|
case 13:
|
|
152
|
-
// 注册任务处理函数
|
|
153
|
-
this.registerTaskHandlers();
|
|
154
131
|
this.registerNetworkHandlers();
|
|
155
132
|
console.log('[PaymentModule] 初始化完成');
|
|
156
133
|
this.logInfo('PaymentModule initialized successfully');
|
|
157
|
-
case
|
|
134
|
+
case 16:
|
|
158
135
|
case "end":
|
|
159
136
|
return _context.stop();
|
|
160
137
|
}
|
|
@@ -243,7 +220,6 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
243
220
|
this.logInfo('Registering network status listener');
|
|
244
221
|
network === null || network === void 0 || network.addListener('networkStatusChange', /*#__PURE__*/function () {
|
|
245
222
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(status) {
|
|
246
|
-
var requeuedCount;
|
|
247
223
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
248
224
|
while (1) switch (_context2.prev = _context2.next) {
|
|
249
225
|
case 0:
|
|
@@ -252,24 +228,11 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
252
228
|
connected: status.connected,
|
|
253
229
|
previousStatus: status.previousStatus
|
|
254
230
|
});
|
|
255
|
-
if (
|
|
256
|
-
|
|
257
|
-
|
|
231
|
+
if (status.connected) {
|
|
232
|
+
_this2.logInfo('Network reconnected');
|
|
233
|
+
// 网络恢复时的处理逻辑可以在这里添加
|
|
258
234
|
}
|
|
259
|
-
|
|
260
|
-
// this.runPaymentSyncQueue();
|
|
261
|
-
// 1. 先检查并重新排队未同步订单,然后执行队列
|
|
262
|
-
_context2.next = 6;
|
|
263
|
-
return _this2.recheckAndRequeueUnsyncedOrders();
|
|
264
|
-
case 6:
|
|
265
|
-
requeuedCount = _context2.sent;
|
|
266
|
-
if (!(requeuedCount > 0)) {
|
|
267
|
-
_context2.next = 10;
|
|
268
|
-
break;
|
|
269
|
-
}
|
|
270
|
-
_context2.next = 10;
|
|
271
|
-
return _this2.runPaymentSyncQueue();
|
|
272
|
-
case 10:
|
|
235
|
+
case 3:
|
|
273
236
|
case "end":
|
|
274
237
|
return _context2.stop();
|
|
275
238
|
}
|
|
@@ -319,7 +282,9 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
319
282
|
return _context3.abrupt("return", cachedMethods);
|
|
320
283
|
case 16:
|
|
321
284
|
_context3.next = 18;
|
|
322
|
-
return this.request.get('/pay/custom-payment/available'
|
|
285
|
+
return this.request.get('/pay/custom-payment/available', {
|
|
286
|
+
channel: 'pos'
|
|
287
|
+
});
|
|
323
288
|
case 18:
|
|
324
289
|
response = _context3.sent;
|
|
325
290
|
payMethods = response.data || []; // 尝试缓存到 IndexDB
|
|
@@ -403,7 +368,9 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
403
368
|
|
|
404
369
|
// 从服务器获取最新数据
|
|
405
370
|
_context4.next = 5;
|
|
406
|
-
return this.request.get('/pay/custom-payment/available'
|
|
371
|
+
return this.request.get('/pay/custom-payment/available', {
|
|
372
|
+
channel: 'pos'
|
|
373
|
+
});
|
|
407
374
|
case 5:
|
|
408
375
|
response = _context4.sent;
|
|
409
376
|
newPayMethods = response.data || []; // 检查是否有变化
|
|
@@ -710,31 +677,6 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
710
677
|
}
|
|
711
678
|
return createPaymentOrderAsync;
|
|
712
679
|
}()
|
|
713
|
-
/**
|
|
714
|
-
* 往交易组中添加订单(兼容性方法)
|
|
715
|
-
* @deprecated 使用 createPaymentOrderAsync 替代
|
|
716
|
-
*/
|
|
717
|
-
)
|
|
718
|
-
}, {
|
|
719
|
-
key: "pushOrderAsync",
|
|
720
|
-
value: (function () {
|
|
721
|
-
var _pushOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
|
|
722
|
-
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
723
|
-
while (1) switch (_context8.prev = _context8.next) {
|
|
724
|
-
case 0:
|
|
725
|
-
console.warn('[PaymentModule] pushOrderAsync 已废弃,请使用 createPaymentOrderAsync 替代');
|
|
726
|
-
return _context8.abrupt("return", this.createPaymentOrderAsync(params));
|
|
727
|
-
case 2:
|
|
728
|
-
case "end":
|
|
729
|
-
return _context8.stop();
|
|
730
|
-
}
|
|
731
|
-
}, _callee8, this);
|
|
732
|
-
}));
|
|
733
|
-
function pushOrderAsync(_x7) {
|
|
734
|
-
return _pushOrderAsync.apply(this, arguments);
|
|
735
|
-
}
|
|
736
|
-
return pushOrderAsync;
|
|
737
|
-
}()
|
|
738
680
|
/**
|
|
739
681
|
* 删除支付订单(新方法)
|
|
740
682
|
*/
|
|
@@ -742,71 +684,46 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
742
684
|
}, {
|
|
743
685
|
key: "deletePaymentOrderAsync",
|
|
744
686
|
value: (function () {
|
|
745
|
-
var _deletePaymentOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
687
|
+
var _deletePaymentOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(orderUuid) {
|
|
746
688
|
var order;
|
|
747
|
-
return _regeneratorRuntime().wrap(function
|
|
748
|
-
while (1) switch (
|
|
689
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
690
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
749
691
|
case 0:
|
|
750
|
-
|
|
751
|
-
|
|
692
|
+
_context8.prev = 0;
|
|
693
|
+
_context8.next = 3;
|
|
752
694
|
return this.dbManager.get('order', orderUuid);
|
|
753
695
|
case 3:
|
|
754
|
-
order =
|
|
696
|
+
order = _context8.sent;
|
|
755
697
|
if (!order) {
|
|
756
|
-
|
|
698
|
+
_context8.next = 10;
|
|
757
699
|
break;
|
|
758
700
|
}
|
|
759
|
-
|
|
701
|
+
_context8.next = 7;
|
|
760
702
|
return this.dbManager.delete('order', orderUuid);
|
|
761
703
|
case 7:
|
|
762
|
-
|
|
704
|
+
_context8.next = 9;
|
|
763
705
|
return this.core.effects.emit(PaymentHooks.OnOrderDeleted, order);
|
|
764
706
|
case 9:
|
|
765
707
|
console.log('[PaymentModule] 支付订单删除成功:', orderUuid);
|
|
766
708
|
case 10:
|
|
767
|
-
|
|
709
|
+
_context8.next = 16;
|
|
768
710
|
break;
|
|
769
711
|
case 12:
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
console.error('[PaymentModule] 删除支付订单失败',
|
|
773
|
-
throw
|
|
712
|
+
_context8.prev = 12;
|
|
713
|
+
_context8.t0 = _context8["catch"](0);
|
|
714
|
+
console.error('[PaymentModule] 删除支付订单失败', _context8.t0);
|
|
715
|
+
throw _context8.t0;
|
|
774
716
|
case 16:
|
|
775
717
|
case "end":
|
|
776
|
-
return
|
|
718
|
+
return _context8.stop();
|
|
777
719
|
}
|
|
778
|
-
},
|
|
720
|
+
}, _callee8, this, [[0, 12]]);
|
|
779
721
|
}));
|
|
780
|
-
function deletePaymentOrderAsync(
|
|
722
|
+
function deletePaymentOrderAsync(_x7) {
|
|
781
723
|
return _deletePaymentOrderAsync.apply(this, arguments);
|
|
782
724
|
}
|
|
783
725
|
return deletePaymentOrderAsync;
|
|
784
726
|
}()
|
|
785
|
-
/**
|
|
786
|
-
* 删除订单(兼容性方法)
|
|
787
|
-
* @deprecated 使用 deletePaymentOrderAsync 替代
|
|
788
|
-
*/
|
|
789
|
-
)
|
|
790
|
-
}, {
|
|
791
|
-
key: "deleteOrderAsync",
|
|
792
|
-
value: (function () {
|
|
793
|
-
var _deleteOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(orderUuid) {
|
|
794
|
-
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
795
|
-
while (1) switch (_context10.prev = _context10.next) {
|
|
796
|
-
case 0:
|
|
797
|
-
console.warn('[PaymentModule] deleteOrderAsync 已废弃,请使用 deletePaymentOrderAsync 替代');
|
|
798
|
-
return _context10.abrupt("return", this.deletePaymentOrderAsync(orderUuid));
|
|
799
|
-
case 2:
|
|
800
|
-
case "end":
|
|
801
|
-
return _context10.stop();
|
|
802
|
-
}
|
|
803
|
-
}, _callee10, this);
|
|
804
|
-
}));
|
|
805
|
-
function deleteOrderAsync(_x9) {
|
|
806
|
-
return _deleteOrderAsync.apply(this, arguments);
|
|
807
|
-
}
|
|
808
|
-
return deleteOrderAsync;
|
|
809
|
-
}()
|
|
810
727
|
/**
|
|
811
728
|
* 更新订单
|
|
812
729
|
*/
|
|
@@ -814,48 +731,48 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
814
731
|
}, {
|
|
815
732
|
key: "updateOrderAsync",
|
|
816
733
|
value: (function () {
|
|
817
|
-
var _updateOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
734
|
+
var _updateOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(orderUuid, params) {
|
|
818
735
|
var order, updatedOrder;
|
|
819
|
-
return _regeneratorRuntime().wrap(function
|
|
820
|
-
while (1) switch (
|
|
736
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
737
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
821
738
|
case 0:
|
|
822
|
-
|
|
823
|
-
|
|
739
|
+
_context9.prev = 0;
|
|
740
|
+
_context9.next = 3;
|
|
824
741
|
return this.dbManager.get('order', orderUuid);
|
|
825
742
|
case 3:
|
|
826
|
-
order =
|
|
743
|
+
order = _context9.sent;
|
|
827
744
|
if (!order) {
|
|
828
|
-
|
|
745
|
+
_context9.next = 12;
|
|
829
746
|
break;
|
|
830
747
|
}
|
|
831
748
|
updatedOrder = _objectSpread(_objectSpread({}, order), params);
|
|
832
|
-
|
|
749
|
+
_context9.next = 8;
|
|
833
750
|
return this.dbManager.update('order', updatedOrder);
|
|
834
751
|
case 8:
|
|
835
|
-
|
|
752
|
+
_context9.next = 10;
|
|
836
753
|
return this.core.effects.emit(PaymentHooks.OnOrderUpdated, updatedOrder);
|
|
837
754
|
case 10:
|
|
838
|
-
|
|
755
|
+
_context9.next = 12;
|
|
839
756
|
return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
|
|
840
757
|
action: 'update',
|
|
841
758
|
order: updatedOrder,
|
|
842
759
|
originalOrder: order
|
|
843
760
|
});
|
|
844
761
|
case 12:
|
|
845
|
-
|
|
762
|
+
_context9.next = 18;
|
|
846
763
|
break;
|
|
847
764
|
case 14:
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
console.error('[PaymentModule] 更新订单失败',
|
|
851
|
-
throw
|
|
765
|
+
_context9.prev = 14;
|
|
766
|
+
_context9.t0 = _context9["catch"](0);
|
|
767
|
+
console.error('[PaymentModule] 更新订单失败', _context9.t0);
|
|
768
|
+
throw _context9.t0;
|
|
852
769
|
case 18:
|
|
853
770
|
case "end":
|
|
854
|
-
return
|
|
771
|
+
return _context9.stop();
|
|
855
772
|
}
|
|
856
|
-
},
|
|
773
|
+
}, _callee9, this, [[0, 14]]);
|
|
857
774
|
}));
|
|
858
|
-
function updateOrderAsync(
|
|
775
|
+
function updateOrderAsync(_x8, _x9) {
|
|
859
776
|
return _updateOrderAsync.apply(this, arguments);
|
|
860
777
|
}
|
|
861
778
|
return updateOrderAsync;
|
|
@@ -874,38 +791,38 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
874
791
|
}, {
|
|
875
792
|
key: "replaceOrderIdByUuidAsync",
|
|
876
793
|
value: (function () {
|
|
877
|
-
var _replaceOrderIdByUuidAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
794
|
+
var _replaceOrderIdByUuidAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(orderUuid, newOrderId) {
|
|
878
795
|
var existingOrder, allOrders, duplicateOrder, originalOrderId, updatedOrder;
|
|
879
|
-
return _regeneratorRuntime().wrap(function
|
|
880
|
-
while (1) switch (
|
|
796
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
797
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
881
798
|
case 0:
|
|
882
799
|
this.logInfo('Starting replaceOrderIdByUuidAsync', {
|
|
883
800
|
orderUuid: orderUuid,
|
|
884
801
|
newOrderId: newOrderId
|
|
885
802
|
});
|
|
886
|
-
|
|
887
|
-
|
|
803
|
+
_context10.prev = 1;
|
|
804
|
+
_context10.next = 4;
|
|
888
805
|
return this.dbManager.get('order', orderUuid);
|
|
889
806
|
case 4:
|
|
890
|
-
existingOrder =
|
|
807
|
+
existingOrder = _context10.sent;
|
|
891
808
|
if (existingOrder) {
|
|
892
|
-
|
|
809
|
+
_context10.next = 8;
|
|
893
810
|
break;
|
|
894
811
|
}
|
|
895
812
|
this.logWarning('Order not found for UUID replacement', {
|
|
896
813
|
orderUuid: orderUuid
|
|
897
814
|
});
|
|
898
|
-
return
|
|
815
|
+
return _context10.abrupt("return", null);
|
|
899
816
|
case 8:
|
|
900
|
-
|
|
817
|
+
_context10.next = 10;
|
|
901
818
|
return this.dbManager.getAll('order');
|
|
902
819
|
case 10:
|
|
903
|
-
allOrders =
|
|
820
|
+
allOrders = _context10.sent;
|
|
904
821
|
duplicateOrder = allOrders.find(function (order) {
|
|
905
822
|
return String(order.order_id) === String(newOrderId) && order.uuid !== orderUuid;
|
|
906
823
|
});
|
|
907
824
|
if (!duplicateOrder) {
|
|
908
|
-
|
|
825
|
+
_context10.next = 15;
|
|
909
826
|
break;
|
|
910
827
|
}
|
|
911
828
|
this.logWarning('New order ID already exists', {
|
|
@@ -918,6 +835,8 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
918
835
|
originalOrderId = existingOrder.id; // 更新订单ID
|
|
919
836
|
updatedOrder = _objectSpread(_objectSpread({}, existingOrder), {}, {
|
|
920
837
|
id: newOrderId,
|
|
838
|
+
order_id: newOrderId,
|
|
839
|
+
// 🔧 修复:同时更新根级的 order_id 字段
|
|
921
840
|
order_info: _objectSpread(_objectSpread({}, existingOrder.order_info), {}, {
|
|
922
841
|
order_id: newOrderId,
|
|
923
842
|
// 保留原始本地订单ID作为参考
|
|
@@ -925,13 +844,13 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
925
844
|
updated_at: new Date().toISOString()
|
|
926
845
|
})
|
|
927
846
|
}); // 更新到数据库
|
|
928
|
-
|
|
847
|
+
_context10.next = 19;
|
|
929
848
|
return this.dbManager.update('order', updatedOrder);
|
|
930
849
|
case 19:
|
|
931
|
-
|
|
850
|
+
_context10.next = 21;
|
|
932
851
|
return this.core.effects.emit(PaymentHooks.OnOrderUpdated, updatedOrder);
|
|
933
852
|
case 21:
|
|
934
|
-
|
|
853
|
+
_context10.next = 23;
|
|
935
854
|
return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
|
|
936
855
|
action: 'order_id_replaced',
|
|
937
856
|
order: updatedOrder,
|
|
@@ -948,85 +867,103 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
948
867
|
newOrderId: newOrderId
|
|
949
868
|
});
|
|
950
869
|
console.log("[PaymentModule] \u8BA2\u5355ID\u66FF\u6362\u6210\u529F: ".concat(originalOrderId, " \u2192 ").concat(newOrderId));
|
|
951
|
-
return
|
|
870
|
+
return _context10.abrupt("return", updatedOrder);
|
|
952
871
|
case 28:
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
console.error('[PaymentModule] 替换订单ID失败',
|
|
956
|
-
this.logError('replaceOrderIdByUuidAsync failed',
|
|
872
|
+
_context10.prev = 28;
|
|
873
|
+
_context10.t0 = _context10["catch"](1);
|
|
874
|
+
console.error('[PaymentModule] 替换订单ID失败', _context10.t0);
|
|
875
|
+
this.logError('replaceOrderIdByUuidAsync failed', _context10.t0, {
|
|
957
876
|
orderUuid: orderUuid,
|
|
958
877
|
newOrderId: newOrderId
|
|
959
878
|
});
|
|
960
|
-
throw
|
|
879
|
+
throw _context10.t0;
|
|
961
880
|
case 33:
|
|
962
881
|
case "end":
|
|
963
|
-
return
|
|
882
|
+
return _context10.stop();
|
|
964
883
|
}
|
|
965
|
-
},
|
|
884
|
+
}, _callee10, this, [[1, 28]]);
|
|
966
885
|
}));
|
|
967
|
-
function replaceOrderIdByUuidAsync(
|
|
886
|
+
function replaceOrderIdByUuidAsync(_x10, _x11) {
|
|
968
887
|
return _replaceOrderIdByUuidAsync.apply(this, arguments);
|
|
969
888
|
}
|
|
970
889
|
return replaceOrderIdByUuidAsync;
|
|
971
890
|
}()
|
|
972
891
|
/**
|
|
973
892
|
* 获取支付项(新方法)
|
|
893
|
+
*
|
|
894
|
+
* @param orderUuid 订单UUID
|
|
895
|
+
* @param includeVoided 是否包含已撤销的支付项,默认为false
|
|
896
|
+
* @returns 支付项数组
|
|
974
897
|
*/
|
|
975
898
|
)
|
|
976
899
|
}, {
|
|
977
900
|
key: "getPaymentItemsAsync",
|
|
978
901
|
value: (function () {
|
|
979
|
-
var _getPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
980
|
-
var
|
|
981
|
-
|
|
982
|
-
|
|
902
|
+
var _getPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(orderUuid) {
|
|
903
|
+
var includeVoided,
|
|
904
|
+
order,
|
|
905
|
+
allPayments,
|
|
906
|
+
_args11 = arguments;
|
|
907
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
908
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
983
909
|
case 0:
|
|
910
|
+
includeVoided = _args11.length > 1 && _args11[1] !== undefined ? _args11[1] : false;
|
|
984
911
|
if (orderUuid) {
|
|
985
|
-
|
|
912
|
+
_context11.next = 3;
|
|
986
913
|
break;
|
|
987
914
|
}
|
|
988
915
|
throw new Error('orderUuid is required');
|
|
989
|
-
case
|
|
990
|
-
|
|
916
|
+
case 3:
|
|
917
|
+
_context11.next = 5;
|
|
991
918
|
return this.getPaymentOrderByUuidAsync(orderUuid);
|
|
992
|
-
case
|
|
993
|
-
order =
|
|
994
|
-
|
|
995
|
-
|
|
919
|
+
case 5:
|
|
920
|
+
order = _context11.sent;
|
|
921
|
+
allPayments = (order === null || order === void 0 ? void 0 : order.payment) || [];
|
|
922
|
+
if (!includeVoided) {
|
|
923
|
+
_context11.next = 9;
|
|
924
|
+
break;
|
|
925
|
+
}
|
|
926
|
+
return _context11.abrupt("return", allPayments);
|
|
927
|
+
case 9:
|
|
928
|
+
return _context11.abrupt("return", allPayments.filter(function (payment) {
|
|
929
|
+
return payment.status !== 'voided';
|
|
930
|
+
}));
|
|
931
|
+
case 10:
|
|
996
932
|
case "end":
|
|
997
|
-
return
|
|
933
|
+
return _context11.stop();
|
|
998
934
|
}
|
|
999
|
-
},
|
|
935
|
+
}, _callee11, this);
|
|
1000
936
|
}));
|
|
1001
|
-
function getPaymentItemsAsync(
|
|
937
|
+
function getPaymentItemsAsync(_x12) {
|
|
1002
938
|
return _getPaymentItemsAsync.apply(this, arguments);
|
|
1003
939
|
}
|
|
1004
940
|
return getPaymentItemsAsync;
|
|
1005
941
|
}()
|
|
1006
942
|
/**
|
|
1007
|
-
*
|
|
1008
|
-
*
|
|
943
|
+
* 获取所有支付项(包括已撤销的)
|
|
944
|
+
*
|
|
945
|
+
* @param orderUuid 订单UUID
|
|
946
|
+
* @returns 所有支付项数组(包括撤销的)
|
|
1009
947
|
*/
|
|
1010
948
|
)
|
|
1011
949
|
}, {
|
|
1012
|
-
key: "
|
|
950
|
+
key: "getAllPaymentItemsAsync",
|
|
1013
951
|
value: (function () {
|
|
1014
|
-
var
|
|
1015
|
-
return _regeneratorRuntime().wrap(function
|
|
1016
|
-
while (1) switch (
|
|
952
|
+
var _getAllPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(orderUuid) {
|
|
953
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
954
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
1017
955
|
case 0:
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
case 2:
|
|
956
|
+
return _context12.abrupt("return", this.getPaymentItemsAsync(orderUuid, true));
|
|
957
|
+
case 1:
|
|
1021
958
|
case "end":
|
|
1022
|
-
return
|
|
959
|
+
return _context12.stop();
|
|
1023
960
|
}
|
|
1024
|
-
},
|
|
961
|
+
}, _callee12, this);
|
|
1025
962
|
}));
|
|
1026
|
-
function
|
|
1027
|
-
return
|
|
963
|
+
function getAllPaymentItemsAsync(_x13) {
|
|
964
|
+
return _getAllPaymentItemsAsync.apply(this, arguments);
|
|
1028
965
|
}
|
|
1029
|
-
return
|
|
966
|
+
return getAllPaymentItemsAsync;
|
|
1030
967
|
}()
|
|
1031
968
|
/**
|
|
1032
969
|
* 为某个订单添加支付项(新方法)
|
|
@@ -1035,29 +972,30 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1035
972
|
}, {
|
|
1036
973
|
key: "addPaymentItemAsync",
|
|
1037
974
|
value: (function () {
|
|
1038
|
-
var _addPaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1039
|
-
var order, newPaymentItem;
|
|
1040
|
-
return _regeneratorRuntime().wrap(function
|
|
1041
|
-
while (1) switch (
|
|
975
|
+
var _addPaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(orderUuid, paymentItem) {
|
|
976
|
+
var _newPaymentItem$metad, order, paymentUuid, newPaymentItem;
|
|
977
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
978
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
1042
979
|
case 0:
|
|
1043
980
|
this.logInfo('Starting addPaymentItemAsync', {
|
|
1044
981
|
orderUuid: orderUuid,
|
|
1045
982
|
paymentAmount: paymentItem.amount,
|
|
1046
983
|
paymentCode: paymentItem.code
|
|
1047
984
|
});
|
|
1048
|
-
|
|
1049
|
-
|
|
985
|
+
_context13.prev = 1;
|
|
986
|
+
_context13.next = 4;
|
|
1050
987
|
return this.getPaymentOrderByUuidAsync(orderUuid);
|
|
1051
988
|
case 4:
|
|
1052
|
-
order =
|
|
989
|
+
order = _context13.sent;
|
|
1053
990
|
if (order) {
|
|
1054
|
-
|
|
991
|
+
_context13.next = 7;
|
|
1055
992
|
break;
|
|
1056
993
|
}
|
|
1057
994
|
throw new Error("Order not found: ".concat(orderUuid));
|
|
1058
995
|
case 7:
|
|
996
|
+
paymentUuid = getUniqueId('payment_');
|
|
1059
997
|
newPaymentItem = {
|
|
1060
|
-
uuid:
|
|
998
|
+
uuid: paymentUuid,
|
|
1061
999
|
id: paymentItem.id || 0,
|
|
1062
1000
|
name: paymentItem.name,
|
|
1063
1001
|
code: paymentItem.code,
|
|
@@ -1065,147 +1003,317 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1065
1003
|
amount: formatAmount(paymentItem.amount),
|
|
1066
1004
|
voucher_id: paymentItem.voucher_id || '',
|
|
1067
1005
|
rounding_amount: '0.00',
|
|
1068
|
-
service_charge:
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1006
|
+
service_charge: paymentItem.service_charge,
|
|
1007
|
+
status: 'active',
|
|
1008
|
+
// 新支付项默认为活跃状态
|
|
1009
|
+
metadata: {
|
|
1010
|
+
unique_payment_number: paymentUuid // 设置唯一支付号为支付项的 uuid
|
|
1011
|
+
}
|
|
1073
1012
|
};
|
|
1074
1013
|
order.payment.push(newPaymentItem);
|
|
1075
1014
|
this.recalculateOrderAmount(order);
|
|
1076
|
-
|
|
1015
|
+
_context13.next = 13;
|
|
1077
1016
|
return this.dbManager.update('order', order);
|
|
1078
|
-
case
|
|
1079
|
-
|
|
1017
|
+
case 13:
|
|
1018
|
+
_context13.next = 15;
|
|
1080
1019
|
return this.core.effects.emit(PaymentHooks.OnPaymentAdded, {
|
|
1081
1020
|
orderUuid: orderUuid,
|
|
1082
1021
|
payment: newPaymentItem
|
|
1083
1022
|
});
|
|
1084
|
-
case
|
|
1023
|
+
case 15:
|
|
1085
1024
|
this.logInfo('addPaymentItemAsync completed successfully', {
|
|
1086
1025
|
orderUuid: orderUuid,
|
|
1087
1026
|
paymentUuid: newPaymentItem.uuid,
|
|
1027
|
+
uniquePaymentNumber: (_newPaymentItem$metad = newPaymentItem.metadata) === null || _newPaymentItem$metad === void 0 ? void 0 : _newPaymentItem$metad.unique_payment_number,
|
|
1088
1028
|
newExpectAmount: order.expect_amount
|
|
1089
1029
|
});
|
|
1090
|
-
|
|
1030
|
+
_context13.next = 23;
|
|
1091
1031
|
break;
|
|
1092
|
-
case
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
console.error('[PaymentModule] 添加支付项失败',
|
|
1096
|
-
this.logError('addPaymentItemAsync failed',
|
|
1032
|
+
case 18:
|
|
1033
|
+
_context13.prev = 18;
|
|
1034
|
+
_context13.t0 = _context13["catch"](1);
|
|
1035
|
+
console.error('[PaymentModule] 添加支付项失败', _context13.t0);
|
|
1036
|
+
this.logError('addPaymentItemAsync failed', _context13.t0, {
|
|
1097
1037
|
orderUuid: orderUuid,
|
|
1098
1038
|
paymentItem: paymentItem
|
|
1099
1039
|
});
|
|
1100
|
-
throw
|
|
1101
|
-
case
|
|
1040
|
+
throw _context13.t0;
|
|
1041
|
+
case 23:
|
|
1102
1042
|
case "end":
|
|
1103
|
-
return
|
|
1043
|
+
return _context13.stop();
|
|
1104
1044
|
}
|
|
1105
|
-
},
|
|
1045
|
+
}, _callee13, this, [[1, 18]]);
|
|
1106
1046
|
}));
|
|
1107
|
-
function addPaymentItemAsync(
|
|
1047
|
+
function addPaymentItemAsync(_x14, _x15) {
|
|
1108
1048
|
return _addPaymentItemAsync.apply(this, arguments);
|
|
1109
1049
|
}
|
|
1110
1050
|
return addPaymentItemAsync;
|
|
1111
1051
|
}()
|
|
1112
1052
|
/**
|
|
1113
|
-
*
|
|
1114
|
-
* @deprecated 使用 addPaymentItemAsync 替代
|
|
1115
|
-
*/
|
|
1116
|
-
)
|
|
1117
|
-
}, {
|
|
1118
|
-
key: "pushPaymentAsync",
|
|
1119
|
-
value: (function () {
|
|
1120
|
-
var _pushPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(orderUuid, paymentItem) {
|
|
1121
|
-
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
1122
|
-
while (1) switch (_context16.prev = _context16.next) {
|
|
1123
|
-
case 0:
|
|
1124
|
-
console.warn('[PaymentModule] pushPaymentAsync 已废弃,请使用 addPaymentItemAsync 替代');
|
|
1125
|
-
return _context16.abrupt("return", this.addPaymentItemAsync(orderUuid, paymentItem));
|
|
1126
|
-
case 2:
|
|
1127
|
-
case "end":
|
|
1128
|
-
return _context16.stop();
|
|
1129
|
-
}
|
|
1130
|
-
}, _callee16, this);
|
|
1131
|
-
}));
|
|
1132
|
-
function pushPaymentAsync(_x18, _x19) {
|
|
1133
|
-
return _pushPaymentAsync.apply(this, arguments);
|
|
1134
|
-
}
|
|
1135
|
-
return pushPaymentAsync;
|
|
1136
|
-
}()
|
|
1137
|
-
/**
|
|
1138
|
-
* 删除一个支付项
|
|
1053
|
+
* 删除一个支付项 - 标记删除而非物理删除
|
|
1139
1054
|
*/
|
|
1140
1055
|
)
|
|
1141
1056
|
}, {
|
|
1142
1057
|
key: "deletePaymentAsync",
|
|
1143
1058
|
value: (function () {
|
|
1144
|
-
var _deletePaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1145
|
-
var order,
|
|
1146
|
-
return _regeneratorRuntime().wrap(function
|
|
1147
|
-
while (1) switch (
|
|
1059
|
+
var _deletePaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(orderUuid, paymentUuid) {
|
|
1060
|
+
var order, paymentItem;
|
|
1061
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
1062
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
1148
1063
|
case 0:
|
|
1149
|
-
this.logInfo('Starting deletePaymentAsync', {
|
|
1064
|
+
this.logInfo('Starting deletePaymentAsync (mark as voided)', {
|
|
1150
1065
|
orderUuid: orderUuid,
|
|
1151
1066
|
paymentUuid: paymentUuid
|
|
1152
1067
|
});
|
|
1153
|
-
|
|
1154
|
-
|
|
1068
|
+
_context14.prev = 1;
|
|
1069
|
+
_context14.next = 4;
|
|
1155
1070
|
return this.dbManager.get('order', orderUuid);
|
|
1156
1071
|
case 4:
|
|
1157
|
-
order =
|
|
1072
|
+
order = _context14.sent;
|
|
1158
1073
|
if (order) {
|
|
1159
|
-
|
|
1074
|
+
_context14.next = 7;
|
|
1160
1075
|
break;
|
|
1161
1076
|
}
|
|
1162
1077
|
throw new Error('订单不存在');
|
|
1163
1078
|
case 7:
|
|
1164
|
-
|
|
1079
|
+
paymentItem = order.payment.find(function (payment) {
|
|
1165
1080
|
return payment.uuid === paymentUuid;
|
|
1166
1081
|
});
|
|
1167
|
-
if (
|
|
1168
|
-
|
|
1082
|
+
if (paymentItem) {
|
|
1083
|
+
_context14.next = 10;
|
|
1084
|
+
break;
|
|
1085
|
+
}
|
|
1086
|
+
throw new Error("\u652F\u4ED8\u9879\u4E0D\u5B58\u5728: ".concat(paymentUuid));
|
|
1087
|
+
case 10:
|
|
1088
|
+
if (!(paymentItem.status === 'voided')) {
|
|
1089
|
+
_context14.next = 13;
|
|
1169
1090
|
break;
|
|
1170
1091
|
}
|
|
1171
|
-
|
|
1092
|
+
console.warn("[PaymentModule] \u652F\u4ED8\u9879 ".concat(paymentUuid, " \u5DF2\u7ECF\u88AB\u5220\u9664\uFF0C\u8DF3\u8FC7\u64CD\u4F5C"));
|
|
1093
|
+
return _context14.abrupt("return");
|
|
1094
|
+
case 13:
|
|
1095
|
+
// 标记删除而不是物理删除
|
|
1096
|
+
paymentItem.status = 'voided';
|
|
1097
|
+
paymentItem.origin_amount = paymentItem.amount; // 保存原始金额
|
|
1098
|
+
paymentItem.amount = '0.00'; // 将金额设为0,不参与订单金额计算
|
|
1099
|
+
|
|
1100
|
+
console.log("[PaymentModule] \u652F\u4ED8\u9879\u6807\u8BB0\u4E3A\u5220\u9664:", {
|
|
1101
|
+
uuid: paymentItem.uuid,
|
|
1102
|
+
originalAmount: paymentItem.origin_amount,
|
|
1103
|
+
status: paymentItem.status
|
|
1104
|
+
});
|
|
1105
|
+
|
|
1106
|
+
// 重新计算待付金额
|
|
1172
1107
|
this.recalculateOrderAmount(order);
|
|
1173
1108
|
|
|
1174
1109
|
// 更新到 IndexDB
|
|
1175
|
-
|
|
1110
|
+
_context14.next = 20;
|
|
1176
1111
|
return this.dbManager.update('order', order);
|
|
1177
|
-
case
|
|
1178
|
-
|
|
1112
|
+
case 20:
|
|
1113
|
+
_context14.next = 22;
|
|
1179
1114
|
return this.core.effects.emit(PaymentHooks.OnPaymentDeleted, {
|
|
1180
1115
|
order: order,
|
|
1181
|
-
paymentItem:
|
|
1116
|
+
paymentItem: paymentItem
|
|
1182
1117
|
});
|
|
1183
|
-
case
|
|
1184
|
-
|
|
1118
|
+
case 22:
|
|
1119
|
+
_context14.next = 24;
|
|
1185
1120
|
return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
|
|
1186
1121
|
action: 'payment_delete',
|
|
1187
1122
|
order: order,
|
|
1188
|
-
paymentItem:
|
|
1123
|
+
paymentItem: paymentItem
|
|
1189
1124
|
});
|
|
1190
|
-
case
|
|
1191
|
-
|
|
1125
|
+
case 24:
|
|
1126
|
+
this.logInfo('deletePaymentAsync completed successfully (marked as voided)', {
|
|
1127
|
+
orderUuid: orderUuid,
|
|
1128
|
+
paymentUuid: paymentUuid,
|
|
1129
|
+
originalAmount: paymentItem.origin_amount,
|
|
1130
|
+
newExpectAmount: order.expect_amount
|
|
1131
|
+
});
|
|
1132
|
+
_context14.next = 32;
|
|
1192
1133
|
break;
|
|
1193
|
-
case
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
console.error('[PaymentModule] 删除支付项失败',
|
|
1197
|
-
|
|
1198
|
-
|
|
1134
|
+
case 27:
|
|
1135
|
+
_context14.prev = 27;
|
|
1136
|
+
_context14.t0 = _context14["catch"](1);
|
|
1137
|
+
console.error('[PaymentModule] 删除支付项失败', _context14.t0);
|
|
1138
|
+
this.logError('deletePaymentAsync failed', _context14.t0, {
|
|
1139
|
+
orderUuid: orderUuid,
|
|
1140
|
+
paymentUuid: paymentUuid
|
|
1141
|
+
});
|
|
1142
|
+
throw _context14.t0;
|
|
1143
|
+
case 32:
|
|
1199
1144
|
case "end":
|
|
1200
|
-
return
|
|
1145
|
+
return _context14.stop();
|
|
1201
1146
|
}
|
|
1202
|
-
},
|
|
1147
|
+
}, _callee14, this, [[1, 27]]);
|
|
1203
1148
|
}));
|
|
1204
|
-
function deletePaymentAsync(
|
|
1149
|
+
function deletePaymentAsync(_x16, _x17) {
|
|
1205
1150
|
return _deletePaymentAsync.apply(this, arguments);
|
|
1206
1151
|
}
|
|
1207
1152
|
return deletePaymentAsync;
|
|
1208
1153
|
}()
|
|
1154
|
+
/**
|
|
1155
|
+
* 批量更新代金券类支付项(覆盖更新)
|
|
1156
|
+
*
|
|
1157
|
+
* 删除所有现有的带 voucher_id 的支付项,然后添加新的代金券支付项
|
|
1158
|
+
* 这是一个覆盖式更新,确保代金券支付项的一致性
|
|
1159
|
+
*/
|
|
1160
|
+
)
|
|
1161
|
+
}, {
|
|
1162
|
+
key: "updateVoucherPaymentItemsAsync",
|
|
1163
|
+
value: (function () {
|
|
1164
|
+
var _updateVoucherPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(orderUuid, voucherPaymentItems) {
|
|
1165
|
+
var order, existingVoucherItems, _iterator5, _step5, voucherItem, _iterator6, _step6, _voucherItem, updatedOrder;
|
|
1166
|
+
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
1167
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
1168
|
+
case 0:
|
|
1169
|
+
this.logInfo('Starting updateVoucherPaymentItemsAsync', {
|
|
1170
|
+
orderUuid: orderUuid,
|
|
1171
|
+
newVoucherCount: voucherPaymentItems.length,
|
|
1172
|
+
voucherItems: voucherPaymentItems.map(function (item) {
|
|
1173
|
+
return {
|
|
1174
|
+
code: item.code,
|
|
1175
|
+
amount: item.amount,
|
|
1176
|
+
voucher_id: item.voucher_id
|
|
1177
|
+
};
|
|
1178
|
+
})
|
|
1179
|
+
});
|
|
1180
|
+
_context15.prev = 1;
|
|
1181
|
+
_context15.next = 4;
|
|
1182
|
+
return this.getPaymentOrderByUuidAsync(orderUuid);
|
|
1183
|
+
case 4:
|
|
1184
|
+
order = _context15.sent;
|
|
1185
|
+
if (order) {
|
|
1186
|
+
_context15.next = 7;
|
|
1187
|
+
break;
|
|
1188
|
+
}
|
|
1189
|
+
throw new Error("\u8BA2\u5355\u4E0D\u5B58\u5728: ".concat(orderUuid));
|
|
1190
|
+
case 7:
|
|
1191
|
+
// 1. 查找所有现有的代金券类支付项(带 voucher_id 且状态不是 voided)
|
|
1192
|
+
existingVoucherItems = order.payment.filter(function (payment) {
|
|
1193
|
+
return payment.voucher_id && payment.status !== 'voided';
|
|
1194
|
+
});
|
|
1195
|
+
console.log('[PaymentModule] 发现现有代金券支付项:', {
|
|
1196
|
+
orderUuid: orderUuid,
|
|
1197
|
+
existingVoucherCount: existingVoucherItems.length,
|
|
1198
|
+
existingItems: existingVoucherItems.map(function (item) {
|
|
1199
|
+
return {
|
|
1200
|
+
uuid: item.uuid,
|
|
1201
|
+
code: item.code,
|
|
1202
|
+
amount: item.amount,
|
|
1203
|
+
voucher_id: item.voucher_id
|
|
1204
|
+
};
|
|
1205
|
+
})
|
|
1206
|
+
});
|
|
1207
|
+
|
|
1208
|
+
// 2. 删除所有现有的代金券支付项
|
|
1209
|
+
_iterator5 = _createForOfIteratorHelper(existingVoucherItems);
|
|
1210
|
+
_context15.prev = 10;
|
|
1211
|
+
_iterator5.s();
|
|
1212
|
+
case 12:
|
|
1213
|
+
if ((_step5 = _iterator5.n()).done) {
|
|
1214
|
+
_context15.next = 19;
|
|
1215
|
+
break;
|
|
1216
|
+
}
|
|
1217
|
+
voucherItem = _step5.value;
|
|
1218
|
+
console.log("[PaymentModule] \u5220\u9664\u73B0\u6709\u4EE3\u91D1\u5238\u652F\u4ED8\u9879: ".concat(voucherItem.uuid));
|
|
1219
|
+
_context15.next = 17;
|
|
1220
|
+
return this.deletePaymentAsync(orderUuid, voucherItem.uuid);
|
|
1221
|
+
case 17:
|
|
1222
|
+
_context15.next = 12;
|
|
1223
|
+
break;
|
|
1224
|
+
case 19:
|
|
1225
|
+
_context15.next = 24;
|
|
1226
|
+
break;
|
|
1227
|
+
case 21:
|
|
1228
|
+
_context15.prev = 21;
|
|
1229
|
+
_context15.t0 = _context15["catch"](10);
|
|
1230
|
+
_iterator5.e(_context15.t0);
|
|
1231
|
+
case 24:
|
|
1232
|
+
_context15.prev = 24;
|
|
1233
|
+
_iterator5.f();
|
|
1234
|
+
return _context15.finish(24);
|
|
1235
|
+
case 27:
|
|
1236
|
+
// 3. 添加新的代金券支付项
|
|
1237
|
+
console.log('[PaymentModule] 添加新的代金券支付项:', {
|
|
1238
|
+
orderUuid: orderUuid,
|
|
1239
|
+
newItemCount: voucherPaymentItems.length
|
|
1240
|
+
});
|
|
1241
|
+
_iterator6 = _createForOfIteratorHelper(voucherPaymentItems);
|
|
1242
|
+
_context15.prev = 29;
|
|
1243
|
+
_iterator6.s();
|
|
1244
|
+
case 31:
|
|
1245
|
+
if ((_step6 = _iterator6.n()).done) {
|
|
1246
|
+
_context15.next = 40;
|
|
1247
|
+
break;
|
|
1248
|
+
}
|
|
1249
|
+
_voucherItem = _step6.value;
|
|
1250
|
+
if (_voucherItem.voucher_id) {
|
|
1251
|
+
_context15.next = 35;
|
|
1252
|
+
break;
|
|
1253
|
+
}
|
|
1254
|
+
throw new Error("\u4EE3\u91D1\u5238\u652F\u4ED8\u9879\u7F3A\u5C11 voucher_id: ".concat(JSON.stringify(_voucherItem)));
|
|
1255
|
+
case 35:
|
|
1256
|
+
console.log("[PaymentModule] \u6DFB\u52A0\u4EE3\u91D1\u5238\u652F\u4ED8\u9879:", {
|
|
1257
|
+
code: _voucherItem.code,
|
|
1258
|
+
amount: _voucherItem.amount,
|
|
1259
|
+
voucher_id: _voucherItem.voucher_id
|
|
1260
|
+
});
|
|
1261
|
+
_context15.next = 38;
|
|
1262
|
+
return this.addPaymentItemAsync(orderUuid, _voucherItem);
|
|
1263
|
+
case 38:
|
|
1264
|
+
_context15.next = 31;
|
|
1265
|
+
break;
|
|
1266
|
+
case 40:
|
|
1267
|
+
_context15.next = 45;
|
|
1268
|
+
break;
|
|
1269
|
+
case 42:
|
|
1270
|
+
_context15.prev = 42;
|
|
1271
|
+
_context15.t1 = _context15["catch"](29);
|
|
1272
|
+
_iterator6.e(_context15.t1);
|
|
1273
|
+
case 45:
|
|
1274
|
+
_context15.prev = 45;
|
|
1275
|
+
_iterator6.f();
|
|
1276
|
+
return _context15.finish(45);
|
|
1277
|
+
case 48:
|
|
1278
|
+
_context15.next = 50;
|
|
1279
|
+
return this.getPaymentOrderByUuidAsync(orderUuid);
|
|
1280
|
+
case 50:
|
|
1281
|
+
updatedOrder = _context15.sent;
|
|
1282
|
+
_context15.next = 53;
|
|
1283
|
+
return this.core.effects.emit(PaymentHooks.OnPaymentAdded, {
|
|
1284
|
+
orderUuid: orderUuid,
|
|
1285
|
+
order: updatedOrder,
|
|
1286
|
+
payment: null // 批量操作不提供单个支付项
|
|
1287
|
+
});
|
|
1288
|
+
case 53:
|
|
1289
|
+
this.logInfo('updateVoucherPaymentItemsAsync completed successfully', {
|
|
1290
|
+
orderUuid: orderUuid,
|
|
1291
|
+
removedVoucherCount: existingVoucherItems.length,
|
|
1292
|
+
addedVoucherCount: voucherPaymentItems.length,
|
|
1293
|
+
finalExpectAmount: updatedOrder === null || updatedOrder === void 0 ? void 0 : updatedOrder.expect_amount
|
|
1294
|
+
});
|
|
1295
|
+
_context15.next = 61;
|
|
1296
|
+
break;
|
|
1297
|
+
case 56:
|
|
1298
|
+
_context15.prev = 56;
|
|
1299
|
+
_context15.t2 = _context15["catch"](1);
|
|
1300
|
+
console.error('[PaymentModule] 批量更新代金券支付项失败:', _context15.t2);
|
|
1301
|
+
this.logError('updateVoucherPaymentItemsAsync failed', _context15.t2, {
|
|
1302
|
+
orderUuid: orderUuid,
|
|
1303
|
+
voucherPaymentItems: voucherPaymentItems
|
|
1304
|
+
});
|
|
1305
|
+
throw _context15.t2;
|
|
1306
|
+
case 61:
|
|
1307
|
+
case "end":
|
|
1308
|
+
return _context15.stop();
|
|
1309
|
+
}
|
|
1310
|
+
}, _callee15, this, [[1, 56], [10, 21, 24, 27], [29, 42, 45, 48]]);
|
|
1311
|
+
}));
|
|
1312
|
+
function updateVoucherPaymentItemsAsync(_x18, _x19) {
|
|
1313
|
+
return _updateVoucherPaymentItemsAsync.apply(this, arguments);
|
|
1314
|
+
}
|
|
1315
|
+
return updateVoucherPaymentItemsAsync;
|
|
1316
|
+
}()
|
|
1209
1317
|
/**
|
|
1210
1318
|
* 更新一个支付项
|
|
1211
1319
|
*/
|
|
@@ -1213,18 +1321,18 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1213
1321
|
}, {
|
|
1214
1322
|
key: "updatePaymentAsync",
|
|
1215
1323
|
value: (function () {
|
|
1216
|
-
var _updatePaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1324
|
+
var _updatePaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(orderUuid, paymentUuid, params) {
|
|
1217
1325
|
var order, paymentItem, formattedParams;
|
|
1218
|
-
return _regeneratorRuntime().wrap(function
|
|
1219
|
-
while (1) switch (
|
|
1326
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
1327
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
1220
1328
|
case 0:
|
|
1221
|
-
|
|
1222
|
-
|
|
1329
|
+
_context16.prev = 0;
|
|
1330
|
+
_context16.next = 3;
|
|
1223
1331
|
return this.dbManager.get('order', orderUuid);
|
|
1224
1332
|
case 3:
|
|
1225
|
-
order =
|
|
1333
|
+
order = _context16.sent;
|
|
1226
1334
|
if (order) {
|
|
1227
|
-
|
|
1335
|
+
_context16.next = 6;
|
|
1228
1336
|
break;
|
|
1229
1337
|
}
|
|
1230
1338
|
throw new Error('订单不存在');
|
|
@@ -1233,7 +1341,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1233
1341
|
return payment.uuid === paymentUuid;
|
|
1234
1342
|
});
|
|
1235
1343
|
if (!paymentItem) {
|
|
1236
|
-
|
|
1344
|
+
_context16.next = 18;
|
|
1237
1345
|
break;
|
|
1238
1346
|
}
|
|
1239
1347
|
// 如果更新参数中包含 amount,先格式化
|
|
@@ -1247,36 +1355,36 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1247
1355
|
this.recalculateOrderAmount(order);
|
|
1248
1356
|
|
|
1249
1357
|
// 更新到 IndexDB
|
|
1250
|
-
|
|
1358
|
+
_context16.next = 14;
|
|
1251
1359
|
return this.dbManager.update('order', order);
|
|
1252
1360
|
case 14:
|
|
1253
|
-
|
|
1361
|
+
_context16.next = 16;
|
|
1254
1362
|
return this.core.effects.emit(PaymentHooks.OnPaymentUpdated, {
|
|
1255
1363
|
order: order,
|
|
1256
1364
|
paymentItem: paymentItem
|
|
1257
1365
|
});
|
|
1258
1366
|
case 16:
|
|
1259
|
-
|
|
1367
|
+
_context16.next = 18;
|
|
1260
1368
|
return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
|
|
1261
1369
|
action: 'payment_update',
|
|
1262
1370
|
order: order,
|
|
1263
1371
|
paymentItem: paymentItem
|
|
1264
1372
|
});
|
|
1265
1373
|
case 18:
|
|
1266
|
-
|
|
1374
|
+
_context16.next = 24;
|
|
1267
1375
|
break;
|
|
1268
1376
|
case 20:
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
console.error('[PaymentModule] 更新支付项失败',
|
|
1272
|
-
throw
|
|
1377
|
+
_context16.prev = 20;
|
|
1378
|
+
_context16.t0 = _context16["catch"](0);
|
|
1379
|
+
console.error('[PaymentModule] 更新支付项失败', _context16.t0);
|
|
1380
|
+
throw _context16.t0;
|
|
1273
1381
|
case 24:
|
|
1274
1382
|
case "end":
|
|
1275
|
-
return
|
|
1383
|
+
return _context16.stop();
|
|
1276
1384
|
}
|
|
1277
|
-
},
|
|
1385
|
+
}, _callee16, this, [[0, 20]]);
|
|
1278
1386
|
}));
|
|
1279
|
-
function updatePaymentAsync(
|
|
1387
|
+
function updatePaymentAsync(_x20, _x21, _x22) {
|
|
1280
1388
|
return _updatePaymentAsync.apply(this, arguments);
|
|
1281
1389
|
}
|
|
1282
1390
|
return updatePaymentAsync;
|
|
@@ -1288,113 +1396,87 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1288
1396
|
}, {
|
|
1289
1397
|
key: "submitPayAsync",
|
|
1290
1398
|
value: (function () {
|
|
1291
|
-
var _submitPayAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1292
|
-
var orderToSubmit, order,
|
|
1293
|
-
return _regeneratorRuntime().wrap(function
|
|
1294
|
-
while (1) switch (
|
|
1399
|
+
var _submitPayAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(orderUuid) {
|
|
1400
|
+
var orderToSubmit, order, allOrders, _iterator7, _step7, _order, result;
|
|
1401
|
+
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
1402
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
1295
1403
|
case 0:
|
|
1296
1404
|
this.logInfo('Starting submitPayAsync', {
|
|
1297
1405
|
orderUuid: orderUuid
|
|
1298
1406
|
});
|
|
1299
|
-
|
|
1407
|
+
_context17.prev = 1;
|
|
1300
1408
|
if (!orderUuid) {
|
|
1301
|
-
|
|
1409
|
+
_context17.next = 9;
|
|
1302
1410
|
break;
|
|
1303
1411
|
}
|
|
1304
|
-
|
|
1412
|
+
_context17.next = 5;
|
|
1305
1413
|
return this.dbManager.get('order', orderUuid);
|
|
1306
1414
|
case 5:
|
|
1307
|
-
order =
|
|
1415
|
+
order = _context17.sent;
|
|
1308
1416
|
orderToSubmit = order ? [order] : [];
|
|
1309
|
-
|
|
1417
|
+
_context17.next = 13;
|
|
1310
1418
|
break;
|
|
1311
1419
|
case 9:
|
|
1312
|
-
|
|
1420
|
+
_context17.next = 11;
|
|
1313
1421
|
return this.dbManager.getAll('order');
|
|
1314
1422
|
case 11:
|
|
1315
|
-
|
|
1423
|
+
allOrders = _context17.sent;
|
|
1316
1424
|
// 包括正在处理中的订单和部分支付的订单(可能添加了新的支付项)
|
|
1317
|
-
orderToSubmit =
|
|
1425
|
+
orderToSubmit = allOrders.filter(function (order) {
|
|
1318
1426
|
return order.payment_status === PaymentStatus.Processing || order.payment_status === PaymentStatus.PartiallyPaid;
|
|
1319
1427
|
});
|
|
1320
1428
|
case 13:
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1429
|
+
_iterator7 = _createForOfIteratorHelper(orderToSubmit);
|
|
1430
|
+
_context17.prev = 14;
|
|
1431
|
+
_iterator7.s();
|
|
1324
1432
|
case 16:
|
|
1325
|
-
if ((
|
|
1326
|
-
|
|
1433
|
+
if ((_step7 = _iterator7.n()).done) {
|
|
1434
|
+
_context17.next = 22;
|
|
1327
1435
|
break;
|
|
1328
1436
|
}
|
|
1329
|
-
_order =
|
|
1330
|
-
|
|
1437
|
+
_order = _step7.value;
|
|
1438
|
+
_context17.next = 20;
|
|
1331
1439
|
return this.submitSingleOrderPayment(_order);
|
|
1332
1440
|
case 20:
|
|
1333
|
-
|
|
1441
|
+
_context17.next = 16;
|
|
1334
1442
|
break;
|
|
1335
1443
|
case 22:
|
|
1336
|
-
|
|
1444
|
+
_context17.next = 27;
|
|
1337
1445
|
break;
|
|
1338
1446
|
case 24:
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1447
|
+
_context17.prev = 24;
|
|
1448
|
+
_context17.t0 = _context17["catch"](14);
|
|
1449
|
+
_iterator7.e(_context17.t0);
|
|
1342
1450
|
case 27:
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
return
|
|
1451
|
+
_context17.prev = 27;
|
|
1452
|
+
_iterator7.f();
|
|
1453
|
+
return _context17.finish(27);
|
|
1346
1454
|
case 30:
|
|
1347
|
-
_context19.next = 32;
|
|
1348
|
-
return this.runPaymentSyncQueue();
|
|
1349
|
-
case 32:
|
|
1350
|
-
_context19.next = 34;
|
|
1351
|
-
return this.dbManager.getAll('order');
|
|
1352
|
-
case 34:
|
|
1353
|
-
allOrders = _context19.sent;
|
|
1354
|
-
allOrdersProcessed = allOrders.every(function (order) {
|
|
1355
|
-
return order.payment.every(function (payment) {
|
|
1356
|
-
return payment.isSynced === true;
|
|
1357
|
-
});
|
|
1358
|
-
});
|
|
1359
|
-
if (!allOrdersProcessed) {
|
|
1360
|
-
_context19.next = 42;
|
|
1361
|
-
break;
|
|
1362
|
-
}
|
|
1363
1455
|
result = {
|
|
1364
1456
|
status: 'success'
|
|
1365
1457
|
};
|
|
1366
1458
|
this.logInfo('submitPayAsync completed', {
|
|
1367
1459
|
result: result.status,
|
|
1368
|
-
processedOrdersCount:
|
|
1460
|
+
processedOrdersCount: orderToSubmit.length
|
|
1369
1461
|
});
|
|
1370
|
-
return
|
|
1371
|
-
case
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
status: 'failed'
|
|
1377
|
-
});
|
|
1378
|
-
case 44:
|
|
1379
|
-
_context19.next = 51;
|
|
1380
|
-
break;
|
|
1381
|
-
case 46:
|
|
1382
|
-
_context19.prev = 46;
|
|
1383
|
-
_context19.t1 = _context19["catch"](1);
|
|
1384
|
-
console.error('[PaymentModule] 提交支付失败', _context19.t1);
|
|
1385
|
-
this.logError('submitPayAsync failed', _context19.t1, {
|
|
1462
|
+
return _context17.abrupt("return", result);
|
|
1463
|
+
case 35:
|
|
1464
|
+
_context17.prev = 35;
|
|
1465
|
+
_context17.t1 = _context17["catch"](1);
|
|
1466
|
+
console.error('[PaymentModule] 提交支付失败', _context17.t1);
|
|
1467
|
+
this.logError('submitPayAsync failed', _context17.t1, {
|
|
1386
1468
|
orderUuid: orderUuid
|
|
1387
1469
|
});
|
|
1388
|
-
return
|
|
1470
|
+
return _context17.abrupt("return", {
|
|
1389
1471
|
status: 'failed'
|
|
1390
1472
|
});
|
|
1391
|
-
case
|
|
1473
|
+
case 40:
|
|
1392
1474
|
case "end":
|
|
1393
|
-
return
|
|
1475
|
+
return _context17.stop();
|
|
1394
1476
|
}
|
|
1395
|
-
},
|
|
1477
|
+
}, _callee17, this, [[1, 35], [14, 24, 27, 30]]);
|
|
1396
1478
|
}));
|
|
1397
|
-
function submitPayAsync(
|
|
1479
|
+
function submitPayAsync(_x23) {
|
|
1398
1480
|
return _submitPayAsync.apply(this, arguments);
|
|
1399
1481
|
}
|
|
1400
1482
|
return submitPayAsync;
|
|
@@ -1406,12 +1488,12 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1406
1488
|
}, {
|
|
1407
1489
|
key: "submitSingleOrderPayment",
|
|
1408
1490
|
value: (function () {
|
|
1409
|
-
var _submitSingleOrderPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1491
|
+
var _submitSingleOrderPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(order) {
|
|
1410
1492
|
var paymentData, totalPaidAmount, orderTotalAmount;
|
|
1411
|
-
return _regeneratorRuntime().wrap(function
|
|
1412
|
-
while (1) switch (
|
|
1493
|
+
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
1494
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
1413
1495
|
case 0:
|
|
1414
|
-
|
|
1496
|
+
_context18.prev = 0;
|
|
1415
1497
|
paymentData = {
|
|
1416
1498
|
payments: order.payment.map(function (payment) {
|
|
1417
1499
|
return {
|
|
@@ -1447,101 +1529,47 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1447
1529
|
paymentData.payment_status = order.payment_status === PaymentStatus.Finished ? 'paid' : 'partially_paid';
|
|
1448
1530
|
|
|
1449
1531
|
// 更新订单状态到数据库
|
|
1450
|
-
|
|
1451
|
-
_context20.next = 8;
|
|
1532
|
+
_context18.next = 8;
|
|
1452
1533
|
return this.dbManager.update('order', order);
|
|
1453
1534
|
case 8:
|
|
1454
1535
|
if (!(paymentData.payments.length === 0)) {
|
|
1455
|
-
|
|
1536
|
+
_context18.next = 12;
|
|
1456
1537
|
break;
|
|
1457
1538
|
}
|
|
1458
|
-
console.log("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u652F\u4ED8\u5217\u8868\u4E3A\u7A7A\uFF0C\u8DF3\u8FC7\
|
|
1459
|
-
this.logWarning('Empty payment
|
|
1539
|
+
console.log("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u652F\u4ED8\u5217\u8868\u4E3A\u7A7A\uFF0C\u8DF3\u8FC7\u652F\u4ED8\u5904\u7406"));
|
|
1540
|
+
this.logWarning('Empty payment list', {
|
|
1460
1541
|
orderUuid: order.uuid,
|
|
1461
1542
|
orderId: order.order_id
|
|
1462
1543
|
});
|
|
1463
|
-
return
|
|
1544
|
+
return _context18.abrupt("return");
|
|
1464
1545
|
case 12:
|
|
1465
|
-
|
|
1466
|
-
return this.addToSyncQueue(order, paymentData);
|
|
1467
|
-
case 14:
|
|
1468
|
-
_context20.next = 16;
|
|
1546
|
+
_context18.next = 14;
|
|
1469
1547
|
return this.core.effects.emit(PaymentHooks.OnPaymentSubmitted, order);
|
|
1470
|
-
case
|
|
1471
|
-
|
|
1548
|
+
case 14:
|
|
1549
|
+
_context18.next = 16;
|
|
1472
1550
|
return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
|
|
1473
1551
|
action: 'submit',
|
|
1474
1552
|
order: order
|
|
1475
1553
|
});
|
|
1476
|
-
case
|
|
1477
|
-
|
|
1554
|
+
case 16:
|
|
1555
|
+
_context18.next = 22;
|
|
1478
1556
|
break;
|
|
1479
|
-
case
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
console.error("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u652F\u4ED8\u63D0\u4EA4\u5931\u8D25"),
|
|
1483
|
-
throw
|
|
1484
|
-
case
|
|
1557
|
+
case 18:
|
|
1558
|
+
_context18.prev = 18;
|
|
1559
|
+
_context18.t0 = _context18["catch"](0);
|
|
1560
|
+
console.error("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u652F\u4ED8\u63D0\u4EA4\u5931\u8D25"), _context18.t0);
|
|
1561
|
+
throw _context18.t0;
|
|
1562
|
+
case 22:
|
|
1485
1563
|
case "end":
|
|
1486
|
-
return
|
|
1564
|
+
return _context18.stop();
|
|
1487
1565
|
}
|
|
1488
|
-
},
|
|
1566
|
+
}, _callee18, this, [[0, 18]]);
|
|
1489
1567
|
}));
|
|
1490
|
-
function submitSingleOrderPayment(
|
|
1568
|
+
function submitSingleOrderPayment(_x24) {
|
|
1491
1569
|
return _submitSingleOrderPayment.apply(this, arguments);
|
|
1492
1570
|
}
|
|
1493
1571
|
return submitSingleOrderPayment;
|
|
1494
1572
|
}()
|
|
1495
|
-
/**
|
|
1496
|
-
* 添加到同步任务队列
|
|
1497
|
-
*/
|
|
1498
|
-
)
|
|
1499
|
-
}, {
|
|
1500
|
-
key: "addToSyncQueue",
|
|
1501
|
-
value: (function () {
|
|
1502
|
-
var _addToSyncQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(order, paymentData) {
|
|
1503
|
-
return _regeneratorRuntime().wrap(function _callee21$(_context21) {
|
|
1504
|
-
while (1) switch (_context21.prev = _context21.next) {
|
|
1505
|
-
case 0:
|
|
1506
|
-
try {
|
|
1507
|
-
console.log("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u5DF2\u6DFB\u52A0\u5230\u540C\u6B65\u961F\u5217"));
|
|
1508
|
-
|
|
1509
|
-
// 集成TasksManager
|
|
1510
|
-
if (this.app.tasksManager) {
|
|
1511
|
-
this.app.tasksManager.addTask({
|
|
1512
|
-
module: 'payment',
|
|
1513
|
-
queueId: 'payment_sync',
|
|
1514
|
-
tasks: [{
|
|
1515
|
-
id: "payment_".concat(order.uuid),
|
|
1516
|
-
action: 'syncPayment',
|
|
1517
|
-
payload: {
|
|
1518
|
-
orderUuid: order.uuid,
|
|
1519
|
-
orderId: order.order_id,
|
|
1520
|
-
paymentData: paymentData,
|
|
1521
|
-
core: this.core
|
|
1522
|
-
},
|
|
1523
|
-
maxRetries: 3,
|
|
1524
|
-
type: 'cloud'
|
|
1525
|
-
}]
|
|
1526
|
-
});
|
|
1527
|
-
console.log("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u540C\u6B65\u4EFB\u52A1\u5DF2\u6DFB\u52A0\u5230\u961F\u5217"));
|
|
1528
|
-
} else {
|
|
1529
|
-
console.warn('[PaymentModule] TasksManager 未初始化,无法添加同步任务');
|
|
1530
|
-
}
|
|
1531
|
-
} catch (error) {
|
|
1532
|
-
console.error('[PaymentModule] 添加同步任务失败', error);
|
|
1533
|
-
}
|
|
1534
|
-
case 1:
|
|
1535
|
-
case "end":
|
|
1536
|
-
return _context21.stop();
|
|
1537
|
-
}
|
|
1538
|
-
}, _callee21, this);
|
|
1539
|
-
}));
|
|
1540
|
-
function addToSyncQueue(_x27, _x28) {
|
|
1541
|
-
return _addToSyncQueue.apply(this, arguments);
|
|
1542
|
-
}
|
|
1543
|
-
return addToSyncQueue;
|
|
1544
|
-
}()
|
|
1545
1573
|
/**
|
|
1546
1574
|
* 获取订单剩余待付金额
|
|
1547
1575
|
*/
|
|
@@ -1549,29 +1577,29 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1549
1577
|
}, {
|
|
1550
1578
|
key: "getRemainingOrderAmountAsync",
|
|
1551
1579
|
value: (function () {
|
|
1552
|
-
var _getRemainingOrderAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1580
|
+
var _getRemainingOrderAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(orderUuid) {
|
|
1553
1581
|
var order;
|
|
1554
|
-
return _regeneratorRuntime().wrap(function
|
|
1555
|
-
while (1) switch (
|
|
1582
|
+
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
|
1583
|
+
while (1) switch (_context19.prev = _context19.next) {
|
|
1556
1584
|
case 0:
|
|
1557
|
-
|
|
1585
|
+
_context19.next = 2;
|
|
1558
1586
|
return this.getPaymentOrderByUuidAsync(orderUuid);
|
|
1559
1587
|
case 2:
|
|
1560
|
-
order =
|
|
1588
|
+
order = _context19.sent;
|
|
1561
1589
|
if (order) {
|
|
1562
|
-
|
|
1590
|
+
_context19.next = 5;
|
|
1563
1591
|
break;
|
|
1564
1592
|
}
|
|
1565
1593
|
throw new Error('订单不存在');
|
|
1566
1594
|
case 5:
|
|
1567
|
-
return
|
|
1595
|
+
return _context19.abrupt("return", new Decimal(order.expect_amount).toNumber());
|
|
1568
1596
|
case 6:
|
|
1569
1597
|
case "end":
|
|
1570
|
-
return
|
|
1598
|
+
return _context19.stop();
|
|
1571
1599
|
}
|
|
1572
|
-
},
|
|
1600
|
+
}, _callee19, this);
|
|
1573
1601
|
}));
|
|
1574
|
-
function getRemainingOrderAmountAsync(
|
|
1602
|
+
function getRemainingOrderAmountAsync(_x25) {
|
|
1575
1603
|
return _getRemainingOrderAmountAsync.apply(this, arguments);
|
|
1576
1604
|
}
|
|
1577
1605
|
return getRemainingOrderAmountAsync;
|
|
@@ -1583,65 +1611,65 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1583
1611
|
}, {
|
|
1584
1612
|
key: "getRemainingOrderAmountWithInputAsync",
|
|
1585
1613
|
value: (function () {
|
|
1586
|
-
var _getRemainingOrderAmountWithInputAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1614
|
+
var _getRemainingOrderAmountWithInputAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(inputAmount, orderUuid) {
|
|
1587
1615
|
var order, inputDecimal;
|
|
1588
|
-
return _regeneratorRuntime().wrap(function
|
|
1589
|
-
while (1) switch (
|
|
1616
|
+
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
|
1617
|
+
while (1) switch (_context20.prev = _context20.next) {
|
|
1590
1618
|
case 0:
|
|
1591
|
-
|
|
1619
|
+
_context20.next = 2;
|
|
1592
1620
|
return this.getPaymentOrderByUuidAsync(orderUuid);
|
|
1593
1621
|
case 2:
|
|
1594
|
-
order =
|
|
1622
|
+
order = _context20.sent;
|
|
1595
1623
|
if (order) {
|
|
1596
|
-
|
|
1624
|
+
_context20.next = 5;
|
|
1597
1625
|
break;
|
|
1598
1626
|
}
|
|
1599
1627
|
throw new Error('订单不存在');
|
|
1600
1628
|
case 5:
|
|
1601
1629
|
if (!(inputAmount === null || inputAmount === undefined)) {
|
|
1602
|
-
|
|
1630
|
+
_context20.next = 7;
|
|
1603
1631
|
break;
|
|
1604
1632
|
}
|
|
1605
|
-
return
|
|
1633
|
+
return _context20.abrupt("return", new Decimal(order.expect_amount).toNumber());
|
|
1606
1634
|
case 7:
|
|
1607
1635
|
if (!(typeof inputAmount === 'string')) {
|
|
1608
|
-
|
|
1636
|
+
_context20.next = 10;
|
|
1609
1637
|
break;
|
|
1610
1638
|
}
|
|
1611
1639
|
if (!(inputAmount.trim() === '')) {
|
|
1612
|
-
|
|
1640
|
+
_context20.next = 10;
|
|
1613
1641
|
break;
|
|
1614
1642
|
}
|
|
1615
|
-
return
|
|
1643
|
+
return _context20.abrupt("return", new Decimal(order.expect_amount).toNumber());
|
|
1616
1644
|
case 10:
|
|
1617
1645
|
if (!(typeof inputAmount === 'number')) {
|
|
1618
|
-
|
|
1646
|
+
_context20.next = 14;
|
|
1619
1647
|
break;
|
|
1620
1648
|
}
|
|
1621
1649
|
if (!(isNaN(inputAmount) || !isFinite(inputAmount))) {
|
|
1622
|
-
|
|
1650
|
+
_context20.next = 14;
|
|
1623
1651
|
break;
|
|
1624
1652
|
}
|
|
1625
1653
|
// 如果输入是 NaN 或无穷大,返回原始的待付金额
|
|
1626
1654
|
console.warn("[PaymentModule] \u8F93\u5165\u91D1\u989D\u4E0D\u662F\u6709\u6548\u6570\u5B57: ".concat(inputAmount, "\uFF0C\u8FD4\u56DE\u539F\u59CB\u5F85\u4ED8\u91D1\u989D"));
|
|
1627
|
-
return
|
|
1655
|
+
return _context20.abrupt("return", new Decimal(order.expect_amount).toNumber());
|
|
1628
1656
|
case 14:
|
|
1629
|
-
|
|
1657
|
+
_context20.prev = 14;
|
|
1630
1658
|
inputDecimal = new Decimal(inputAmount);
|
|
1631
|
-
return
|
|
1659
|
+
return _context20.abrupt("return", new Decimal(order.expect_amount).minus(inputDecimal).toNumber());
|
|
1632
1660
|
case 19:
|
|
1633
|
-
|
|
1634
|
-
|
|
1661
|
+
_context20.prev = 19;
|
|
1662
|
+
_context20.t0 = _context20["catch"](14);
|
|
1635
1663
|
// 如果输入不是有效的数字,返回原始的待付金额
|
|
1636
1664
|
console.warn("[PaymentModule] \u8F93\u5165\u91D1\u989D\u683C\u5F0F\u65E0\u6548: ".concat(inputAmount, "\uFF0C\u8FD4\u56DE\u539F\u59CB\u5F85\u4ED8\u91D1\u989D"));
|
|
1637
|
-
return
|
|
1665
|
+
return _context20.abrupt("return", new Decimal(order.expect_amount).toNumber());
|
|
1638
1666
|
case 23:
|
|
1639
1667
|
case "end":
|
|
1640
|
-
return
|
|
1668
|
+
return _context20.stop();
|
|
1641
1669
|
}
|
|
1642
|
-
},
|
|
1670
|
+
}, _callee20, this, [[14, 19]]);
|
|
1643
1671
|
}));
|
|
1644
|
-
function getRemainingOrderAmountWithInputAsync(
|
|
1672
|
+
function getRemainingOrderAmountWithInputAsync(_x26, _x27) {
|
|
1645
1673
|
return _getRemainingOrderAmountWithInputAsync.apply(this, arguments);
|
|
1646
1674
|
}
|
|
1647
1675
|
return getRemainingOrderAmountWithInputAsync;
|
|
@@ -1656,6 +1684,10 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1656
1684
|
var totalAmount = new Decimal(order.total_amount);
|
|
1657
1685
|
var paidAmount = order.payment.reduce(function (sum, payment) {
|
|
1658
1686
|
try {
|
|
1687
|
+
// 忽略已撤销的支付项
|
|
1688
|
+
if (payment.status === 'voided') {
|
|
1689
|
+
return sum;
|
|
1690
|
+
}
|
|
1659
1691
|
return sum.plus(payment.amount);
|
|
1660
1692
|
} catch (error) {
|
|
1661
1693
|
console.warn("[PaymentModule] \u65E0\u6548\u7684\u652F\u4ED8\u91D1\u989D: ".concat(payment.amount, "\uFF0C\u8DF3\u8FC7\u8BA1\u7B97"));
|
|
@@ -1664,6 +1696,18 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1664
1696
|
}, new Decimal(0));
|
|
1665
1697
|
var remainingAmount = totalAmount.minus(paidAmount);
|
|
1666
1698
|
order.expect_amount = Decimal.max(0, remainingAmount).toFixed(2);
|
|
1699
|
+
console.log("[PaymentModule] \u91CD\u65B0\u8BA1\u7B97\u8BA2\u5355\u91D1\u989D:", {
|
|
1700
|
+
orderUuid: order.uuid,
|
|
1701
|
+
totalAmount: order.total_amount,
|
|
1702
|
+
paidAmount: paidAmount.toFixed(2),
|
|
1703
|
+
remainingAmount: order.expect_amount,
|
|
1704
|
+
activePayments: order.payment.filter(function (p) {
|
|
1705
|
+
return p.status !== 'voided';
|
|
1706
|
+
}).length,
|
|
1707
|
+
voidedPayments: order.payment.filter(function (p) {
|
|
1708
|
+
return p.status === 'voided';
|
|
1709
|
+
}).length
|
|
1710
|
+
});
|
|
1667
1711
|
}
|
|
1668
1712
|
|
|
1669
1713
|
/**
|
|
@@ -1672,29 +1716,29 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1672
1716
|
}, {
|
|
1673
1717
|
key: "getCashPaymentMethod",
|
|
1674
1718
|
value: (function () {
|
|
1675
|
-
var _getCashPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1719
|
+
var _getCashPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
|
|
1676
1720
|
var payMethods;
|
|
1677
|
-
return _regeneratorRuntime().wrap(function
|
|
1678
|
-
while (1) switch (
|
|
1721
|
+
return _regeneratorRuntime().wrap(function _callee21$(_context21) {
|
|
1722
|
+
while (1) switch (_context21.prev = _context21.next) {
|
|
1679
1723
|
case 0:
|
|
1680
|
-
|
|
1681
|
-
|
|
1724
|
+
_context21.prev = 0;
|
|
1725
|
+
_context21.next = 3;
|
|
1682
1726
|
return this.dbManager.getAll('pay_method');
|
|
1683
1727
|
case 3:
|
|
1684
|
-
payMethods =
|
|
1685
|
-
return
|
|
1728
|
+
payMethods = _context21.sent;
|
|
1729
|
+
return _context21.abrupt("return", payMethods.find(function (method) {
|
|
1686
1730
|
return method.code === PaymentMethodType.Cash;
|
|
1687
1731
|
}) || null);
|
|
1688
1732
|
case 7:
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
console.error('[PaymentModule] 获取现金支付方式失败',
|
|
1692
|
-
return
|
|
1733
|
+
_context21.prev = 7;
|
|
1734
|
+
_context21.t0 = _context21["catch"](0);
|
|
1735
|
+
console.error('[PaymentModule] 获取现金支付方式失败', _context21.t0);
|
|
1736
|
+
return _context21.abrupt("return", null);
|
|
1693
1737
|
case 11:
|
|
1694
1738
|
case "end":
|
|
1695
|
-
return
|
|
1739
|
+
return _context21.stop();
|
|
1696
1740
|
}
|
|
1697
|
-
},
|
|
1741
|
+
}, _callee21, this, [[0, 7]]);
|
|
1698
1742
|
}));
|
|
1699
1743
|
function getCashPaymentMethod() {
|
|
1700
1744
|
return _getCashPaymentMethod.apply(this, arguments);
|
|
@@ -1708,29 +1752,29 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1708
1752
|
}, {
|
|
1709
1753
|
key: "getEftposPaymentMethod",
|
|
1710
1754
|
value: (function () {
|
|
1711
|
-
var _getEftposPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1755
|
+
var _getEftposPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
|
|
1712
1756
|
var payMethods;
|
|
1713
|
-
return _regeneratorRuntime().wrap(function
|
|
1714
|
-
while (1) switch (
|
|
1757
|
+
return _regeneratorRuntime().wrap(function _callee22$(_context22) {
|
|
1758
|
+
while (1) switch (_context22.prev = _context22.next) {
|
|
1715
1759
|
case 0:
|
|
1716
|
-
|
|
1717
|
-
|
|
1760
|
+
_context22.prev = 0;
|
|
1761
|
+
_context22.next = 3;
|
|
1718
1762
|
return this.dbManager.getAll('pay_method');
|
|
1719
1763
|
case 3:
|
|
1720
|
-
payMethods =
|
|
1721
|
-
return
|
|
1764
|
+
payMethods = _context22.sent;
|
|
1765
|
+
return _context22.abrupt("return", payMethods.find(function (method) {
|
|
1722
1766
|
return method.code === PaymentMethodType.Eftpos;
|
|
1723
1767
|
}) || null);
|
|
1724
1768
|
case 7:
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
console.error('[PaymentModule] 获取Eftpos支付方式失败',
|
|
1728
|
-
return
|
|
1769
|
+
_context22.prev = 7;
|
|
1770
|
+
_context22.t0 = _context22["catch"](0);
|
|
1771
|
+
console.error('[PaymentModule] 获取Eftpos支付方式失败', _context22.t0);
|
|
1772
|
+
return _context22.abrupt("return", null);
|
|
1729
1773
|
case 11:
|
|
1730
1774
|
case "end":
|
|
1731
|
-
return
|
|
1775
|
+
return _context22.stop();
|
|
1732
1776
|
}
|
|
1733
|
-
},
|
|
1777
|
+
}, _callee22, this, [[0, 7]]);
|
|
1734
1778
|
}));
|
|
1735
1779
|
function getEftposPaymentMethod() {
|
|
1736
1780
|
return _getEftposPaymentMethod.apply(this, arguments);
|
|
@@ -1744,29 +1788,29 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1744
1788
|
}, {
|
|
1745
1789
|
key: "getWalletPaymentMethod",
|
|
1746
1790
|
value: (function () {
|
|
1747
|
-
var _getWalletPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1791
|
+
var _getWalletPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
|
|
1748
1792
|
var payMethods;
|
|
1749
|
-
return _regeneratorRuntime().wrap(function
|
|
1750
|
-
while (1) switch (
|
|
1793
|
+
return _regeneratorRuntime().wrap(function _callee23$(_context23) {
|
|
1794
|
+
while (1) switch (_context23.prev = _context23.next) {
|
|
1751
1795
|
case 0:
|
|
1752
|
-
|
|
1753
|
-
|
|
1796
|
+
_context23.prev = 0;
|
|
1797
|
+
_context23.next = 3;
|
|
1754
1798
|
return this.dbManager.getAll('pay_method');
|
|
1755
1799
|
case 3:
|
|
1756
|
-
payMethods =
|
|
1757
|
-
return
|
|
1800
|
+
payMethods = _context23.sent;
|
|
1801
|
+
return _context23.abrupt("return", payMethods.find(function (method) {
|
|
1758
1802
|
return method.code === PaymentMethodType.Wallet;
|
|
1759
1803
|
}) || null);
|
|
1760
1804
|
case 7:
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
console.error('[PaymentModule] 获取钱包支付方式失败',
|
|
1764
|
-
return
|
|
1805
|
+
_context23.prev = 7;
|
|
1806
|
+
_context23.t0 = _context23["catch"](0);
|
|
1807
|
+
console.error('[PaymentModule] 获取钱包支付方式失败', _context23.t0);
|
|
1808
|
+
return _context23.abrupt("return", null);
|
|
1765
1809
|
case 11:
|
|
1766
1810
|
case "end":
|
|
1767
|
-
return
|
|
1811
|
+
return _context23.stop();
|
|
1768
1812
|
}
|
|
1769
|
-
},
|
|
1813
|
+
}, _callee23, this, [[0, 7]]);
|
|
1770
1814
|
}));
|
|
1771
1815
|
function getWalletPaymentMethod() {
|
|
1772
1816
|
return _getWalletPaymentMethod.apply(this, arguments);
|
|
@@ -1774,64 +1818,44 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1774
1818
|
return getWalletPaymentMethod;
|
|
1775
1819
|
}()
|
|
1776
1820
|
/**
|
|
1777
|
-
*
|
|
1821
|
+
* 确保支付模块所需的数据库表已创建
|
|
1778
1822
|
*/
|
|
1779
1823
|
)
|
|
1780
|
-
}, {
|
|
1781
|
-
key: "registerTaskHandlers",
|
|
1782
|
-
value: function registerTaskHandlers() {
|
|
1783
|
-
if (this.app.tasksManager) {
|
|
1784
|
-
// 注册支付同步任务处理函数
|
|
1785
|
-
this.app.tasksManager.addTaskFunction('syncPayment', PaymentModule.syncPaymentTask);
|
|
1786
|
-
console.log('[PaymentModule] 任务处理函数已注册');
|
|
1787
|
-
} else {
|
|
1788
|
-
console.warn('[PaymentModule] TasksManager 未初始化,无法注册任务处理函数');
|
|
1789
|
-
}
|
|
1790
|
-
}
|
|
1791
|
-
|
|
1792
|
-
/**
|
|
1793
|
-
* 静态方法:处理支付同步任务(后台网络同步)
|
|
1794
|
-
* 这个方法里不允许用 this,因为需要作为静态方法注入到任务队列里
|
|
1795
|
-
*/
|
|
1796
1824
|
}, {
|
|
1797
1825
|
key: "ensurePaymentTables",
|
|
1798
|
-
value: (
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
function () {
|
|
1803
|
-
var _ensurePaymentTables = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
|
|
1804
|
-
return _regeneratorRuntime().wrap(function _callee27$(_context27) {
|
|
1805
|
-
while (1) switch (_context27.prev = _context27.next) {
|
|
1826
|
+
value: (function () {
|
|
1827
|
+
var _ensurePaymentTables = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
|
|
1828
|
+
return _regeneratorRuntime().wrap(function _callee24$(_context24) {
|
|
1829
|
+
while (1) switch (_context24.prev = _context24.next) {
|
|
1806
1830
|
case 0:
|
|
1807
|
-
|
|
1808
|
-
|
|
1831
|
+
_context24.prev = 0;
|
|
1832
|
+
_context24.next = 3;
|
|
1809
1833
|
return this.dbManager.getAll('pay_method');
|
|
1810
1834
|
case 3:
|
|
1811
|
-
|
|
1835
|
+
_context24.next = 9;
|
|
1812
1836
|
break;
|
|
1813
1837
|
case 5:
|
|
1814
|
-
|
|
1815
|
-
|
|
1838
|
+
_context24.prev = 5;
|
|
1839
|
+
_context24.t0 = _context24["catch"](0);
|
|
1816
1840
|
console.warn('[PaymentModule] pay_method 表不存在,请在数据库配置中添加以下配置:');
|
|
1817
1841
|
console.warn('{ name: "pay_method", keyPath: "id" }');
|
|
1818
1842
|
case 9:
|
|
1819
|
-
|
|
1820
|
-
|
|
1843
|
+
_context24.prev = 9;
|
|
1844
|
+
_context24.next = 12;
|
|
1821
1845
|
return this.dbManager.getAll('order');
|
|
1822
1846
|
case 12:
|
|
1823
|
-
|
|
1847
|
+
_context24.next = 18;
|
|
1824
1848
|
break;
|
|
1825
1849
|
case 14:
|
|
1826
|
-
|
|
1827
|
-
|
|
1850
|
+
_context24.prev = 14;
|
|
1851
|
+
_context24.t1 = _context24["catch"](9);
|
|
1828
1852
|
console.warn('[PaymentModule] order 表不存在,请在数据库配置中添加以下配置:');
|
|
1829
1853
|
console.warn('{ name: "order", keyPath: "uuid" }');
|
|
1830
1854
|
case 18:
|
|
1831
1855
|
case "end":
|
|
1832
|
-
return
|
|
1856
|
+
return _context24.stop();
|
|
1833
1857
|
}
|
|
1834
|
-
},
|
|
1858
|
+
}, _callee24, this, [[0, 5], [9, 14]]);
|
|
1835
1859
|
}));
|
|
1836
1860
|
function ensurePaymentTables() {
|
|
1837
1861
|
return _ensurePaymentTables.apply(this, arguments);
|
|
@@ -1845,784 +1869,142 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1845
1869
|
}, {
|
|
1846
1870
|
key: "getPartiallyPaidOrdersAsync",
|
|
1847
1871
|
value: (function () {
|
|
1848
|
-
var _getPartiallyPaidOrdersAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1872
|
+
var _getPartiallyPaidOrdersAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
|
|
1849
1873
|
var allOrders;
|
|
1850
|
-
return _regeneratorRuntime().wrap(function
|
|
1851
|
-
while (1) switch (
|
|
1874
|
+
return _regeneratorRuntime().wrap(function _callee25$(_context25) {
|
|
1875
|
+
while (1) switch (_context25.prev = _context25.next) {
|
|
1852
1876
|
case 0:
|
|
1853
|
-
|
|
1854
|
-
|
|
1877
|
+
_context25.prev = 0;
|
|
1878
|
+
_context25.next = 3;
|
|
1855
1879
|
return this.dbManager.getAll('order');
|
|
1856
1880
|
case 3:
|
|
1857
|
-
allOrders =
|
|
1858
|
-
return
|
|
1881
|
+
allOrders = _context25.sent;
|
|
1882
|
+
return _context25.abrupt("return", allOrders.filter(function (order) {
|
|
1859
1883
|
return order.payment_status === PaymentStatus.PartiallyPaid;
|
|
1860
1884
|
}));
|
|
1861
1885
|
case 7:
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
console.error('[PaymentModule] 获取部分支付订单失败',
|
|
1865
|
-
return
|
|
1886
|
+
_context25.prev = 7;
|
|
1887
|
+
_context25.t0 = _context25["catch"](0);
|
|
1888
|
+
console.error('[PaymentModule] 获取部分支付订单失败', _context25.t0);
|
|
1889
|
+
return _context25.abrupt("return", []);
|
|
1866
1890
|
case 11:
|
|
1867
1891
|
case "end":
|
|
1868
|
-
return
|
|
1892
|
+
return _context25.stop();
|
|
1869
1893
|
}
|
|
1870
|
-
},
|
|
1894
|
+
}, _callee25, this, [[0, 7]]);
|
|
1871
1895
|
}));
|
|
1872
1896
|
function getPartiallyPaidOrdersAsync() {
|
|
1873
1897
|
return _getPartiallyPaidOrdersAsync.apply(this, arguments);
|
|
1874
1898
|
}
|
|
1875
1899
|
return getPartiallyPaidOrdersAsync;
|
|
1876
|
-
}()
|
|
1877
|
-
/**
|
|
1878
|
-
* 获取未同步到服务器的订单
|
|
1879
|
-
*/
|
|
1880
|
-
)
|
|
1881
|
-
}, {
|
|
1882
|
-
key: "getUnsyncedOrdersAsync",
|
|
1883
|
-
value: (function () {
|
|
1884
|
-
var _getUnsyncedOrdersAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
|
|
1885
|
-
var allOrders;
|
|
1886
|
-
return _regeneratorRuntime().wrap(function _callee29$(_context29) {
|
|
1887
|
-
while (1) switch (_context29.prev = _context29.next) {
|
|
1888
|
-
case 0:
|
|
1889
|
-
_context29.prev = 0;
|
|
1890
|
-
_context29.next = 3;
|
|
1891
|
-
return this.dbManager.getAll('order');
|
|
1892
|
-
case 3:
|
|
1893
|
-
allOrders = _context29.sent;
|
|
1894
|
-
return _context29.abrupt("return", allOrders.filter(function (order) {
|
|
1895
|
-
// 订单已完成或部分支付,但支付项还未同步
|
|
1896
|
-
return (order.payment_status === PaymentStatus.Finished || order.payment_status === PaymentStatus.PartiallyPaid) && order.payment.some(function (payment) {
|
|
1897
|
-
return !payment.isSynced;
|
|
1898
|
-
});
|
|
1899
|
-
}));
|
|
1900
|
-
case 7:
|
|
1901
|
-
_context29.prev = 7;
|
|
1902
|
-
_context29.t0 = _context29["catch"](0);
|
|
1903
|
-
console.error('[PaymentModule] 获取未同步订单失败', _context29.t0);
|
|
1904
|
-
return _context29.abrupt("return", []);
|
|
1905
|
-
case 11:
|
|
1906
|
-
case "end":
|
|
1907
|
-
return _context29.stop();
|
|
1908
|
-
}
|
|
1909
|
-
}, _callee29, this, [[0, 7]]);
|
|
1910
|
-
}));
|
|
1911
|
-
function getUnsyncedOrdersAsync() {
|
|
1912
|
-
return _getUnsyncedOrdersAsync.apply(this, arguments);
|
|
1913
|
-
}
|
|
1914
|
-
return getUnsyncedOrdersAsync;
|
|
1915
|
-
}()
|
|
1900
|
+
}() // === 新的 API 方法实现 ===
|
|
1916
1901
|
/**
|
|
1917
|
-
*
|
|
1918
|
-
*
|
|
1902
|
+
* 智能金额舍入
|
|
1903
|
+
*
|
|
1904
|
+
* 根据指定的舍入间隔和规则对金额进行舍入处理
|
|
1905
|
+
*
|
|
1906
|
+
* @param originalAmount 原始金额
|
|
1907
|
+
* @param interval 舍入间隔 (0.05, 0.1, 0.5, 1)
|
|
1908
|
+
* @param rule 舍入规则 (standard, standard_down, always_up, always_down)
|
|
1909
|
+
* @returns 舍入后的金额(保留两位小数的字符串)
|
|
1919
1910
|
*/
|
|
1920
1911
|
)
|
|
1921
1912
|
}, {
|
|
1922
|
-
key: "
|
|
1923
|
-
value:
|
|
1924
|
-
var
|
|
1925
|
-
var
|
|
1926
|
-
return _regeneratorRuntime().wrap(function
|
|
1927
|
-
while (1) switch (
|
|
1913
|
+
key: "roundAmountAsync",
|
|
1914
|
+
value: function () {
|
|
1915
|
+
var _roundAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(originalAmount, interval, rule) {
|
|
1916
|
+
var amount, roundingInterval, supportedIntervals, intervalValue, baseValue, roundedValue, finalAmount, result;
|
|
1917
|
+
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
1918
|
+
while (1) switch (_context26.prev = _context26.next) {
|
|
1928
1919
|
case 0:
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
return order.payment_status === PaymentStatus.Finished && order.payment.every(function (payment) {
|
|
1936
|
-
return payment.isSynced;
|
|
1937
|
-
});
|
|
1938
|
-
});
|
|
1939
|
-
_iterator6 = _createForOfIteratorHelper(finishedAndSyncedOrders);
|
|
1940
|
-
_context30.prev = 6;
|
|
1941
|
-
_iterator6.s();
|
|
1942
|
-
case 8:
|
|
1943
|
-
if ((_step6 = _iterator6.n()).done) {
|
|
1944
|
-
_context30.next = 14;
|
|
1920
|
+
_context26.prev = 0;
|
|
1921
|
+
// 参数验证
|
|
1922
|
+
amount = new Decimal(originalAmount);
|
|
1923
|
+
roundingInterval = new Decimal(interval);
|
|
1924
|
+
if (!roundingInterval.lte(0)) {
|
|
1925
|
+
_context26.next = 5;
|
|
1945
1926
|
break;
|
|
1946
1927
|
}
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1928
|
+
throw new Error('舍入间隔必须大于 0');
|
|
1929
|
+
case 5:
|
|
1930
|
+
// 支持的舍入间隔
|
|
1931
|
+
supportedIntervals = [0.05, 0.1, 0.5, 1];
|
|
1932
|
+
intervalValue = roundingInterval.toNumber();
|
|
1933
|
+
if (!supportedIntervals.includes(intervalValue)) {
|
|
1934
|
+
console.warn("[PaymentModule] \u4E0D\u652F\u6301\u7684\u820D\u5165\u95F4\u9694: ".concat(intervalValue, ", \u652F\u6301\u7684\u95F4\u9694: ").concat(supportedIntervals.join(', ')));
|
|
1935
|
+
}
|
|
1936
|
+
|
|
1937
|
+
// 计算基础值:x / interval
|
|
1938
|
+
baseValue = amount.div(roundingInterval);
|
|
1939
|
+
console.log("[PaymentModule] \u820D\u5165\u8BA1\u7B97 - \u539F\u59CB\u91D1\u989D: ".concat(amount.toString(), ", \u95F4\u9694: ").concat(intervalValue, ", \u57FA\u7840\u503C: ").concat(baseValue.toString(), ", \u89C4\u5219: ").concat(rule));
|
|
1940
|
+
_context26.t0 = rule;
|
|
1941
|
+
_context26.next = _context26.t0 === RoundingRule.Standard ? 13 : _context26.t0 === 'standard' ? 13 : _context26.t0 === RoundingRule.StandardDown ? 15 : _context26.t0 === 'standard_down' ? 15 : _context26.t0 === RoundingRule.AlwaysUp ? 17 : _context26.t0 === 'always_up' ? 17 : _context26.t0 === RoundingRule.AlwaysDown ? 19 : _context26.t0 === 'always_down' ? 19 : 21;
|
|
1955
1942
|
break;
|
|
1956
|
-
case
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1943
|
+
case 13:
|
|
1944
|
+
// 标准舍入(中点向上)
|
|
1945
|
+
roundedValue = this.standardRound(baseValue, true);
|
|
1946
|
+
return _context26.abrupt("break", 22);
|
|
1947
|
+
case 15:
|
|
1948
|
+
// 标准舍入(中点向下)
|
|
1949
|
+
roundedValue = this.standardRound(baseValue, false);
|
|
1950
|
+
return _context26.abrupt("break", 22);
|
|
1951
|
+
case 17:
|
|
1952
|
+
// 总是向上舍入
|
|
1953
|
+
roundedValue = baseValue.ceil();
|
|
1954
|
+
return _context26.abrupt("break", 22);
|
|
1960
1955
|
case 19:
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
return
|
|
1956
|
+
// 总是向下舍入
|
|
1957
|
+
roundedValue = baseValue.floor();
|
|
1958
|
+
return _context26.abrupt("break", 22);
|
|
1959
|
+
case 21:
|
|
1960
|
+
throw new Error("\u4E0D\u652F\u6301\u7684\u820D\u5165\u89C4\u5219: ".concat(rule));
|
|
1964
1961
|
case 22:
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
_context30.t1 = _context30["catch"](0);
|
|
1971
|
-
console.error('[PaymentModule] 清理已完成订单失败', _context30.t1);
|
|
1962
|
+
// 计算最终金额:roundedValue * interval
|
|
1963
|
+
finalAmount = roundedValue.mul(roundingInterval);
|
|
1964
|
+
result = finalAmount.toFixed(2);
|
|
1965
|
+
console.log("[PaymentModule] \u820D\u5165\u7ED3\u679C - \u820D\u5165\u503C: ".concat(roundedValue.toString(), ", \u6700\u7EC8\u91D1\u989D: ").concat(result));
|
|
1966
|
+
return _context26.abrupt("return", result);
|
|
1972
1967
|
case 28:
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
}));
|
|
1978
|
-
function cleanupFinishedOrders() {
|
|
1979
|
-
return _cleanupFinishedOrders.apply(this, arguments);
|
|
1980
|
-
}
|
|
1981
|
-
return cleanupFinishedOrders;
|
|
1982
|
-
}()
|
|
1983
|
-
/**
|
|
1984
|
-
* 检测未同步的订单并重新加入任务队列
|
|
1985
|
-
*
|
|
1986
|
-
* 此方法专门用于处理因网络问题导致任务队列执行失败但队列被清空的情况。
|
|
1987
|
-
* 它会检查本地 IndexDB 中所有未同步的订单(isSynced: false),
|
|
1988
|
-
* 并将这些订单重新添加到任务队列中。
|
|
1989
|
-
*
|
|
1990
|
-
* 使用场景:
|
|
1991
|
-
* - 网络恢复后重新检查未同步的订单
|
|
1992
|
-
* - 应用启动时检查并重新排队未完成的支付
|
|
1993
|
-
* - 用户手动重试前的预检查
|
|
1994
|
-
*
|
|
1995
|
-
* @returns Promise<number> 返回重新加入队列的订单数量
|
|
1996
|
-
*/
|
|
1997
|
-
)
|
|
1998
|
-
}, {
|
|
1999
|
-
key: "recheckAndRequeueUnsyncedOrders",
|
|
2000
|
-
value: (function () {
|
|
2001
|
-
var _recheckAndRequeueUnsyncedOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
|
|
2002
|
-
var unsyncedOrders, requeuedCount, _iterator7, _step7, order, success;
|
|
2003
|
-
return _regeneratorRuntime().wrap(function _callee31$(_context31) {
|
|
2004
|
-
while (1) switch (_context31.prev = _context31.next) {
|
|
2005
|
-
case 0:
|
|
2006
|
-
this.logInfo('Starting recheckAndRequeueUnsyncedOrders');
|
|
2007
|
-
_context31.prev = 1;
|
|
2008
|
-
if (this.app.tasksManager) {
|
|
2009
|
-
_context31.next = 6;
|
|
2010
|
-
break;
|
|
2011
|
-
}
|
|
2012
|
-
console.warn('[PaymentModule] TasksManager 未初始化,无法重新排队未同步订单');
|
|
2013
|
-
this.logWarning('TasksManager not initialized, cannot requeue unsynced orders');
|
|
2014
|
-
return _context31.abrupt("return", 0);
|
|
2015
|
-
case 6:
|
|
2016
|
-
_context31.next = 8;
|
|
2017
|
-
return this.getUnsyncedOrdersAsync();
|
|
2018
|
-
case 8:
|
|
2019
|
-
unsyncedOrders = _context31.sent;
|
|
2020
|
-
if (!(unsyncedOrders.length === 0)) {
|
|
2021
|
-
_context31.next = 13;
|
|
2022
|
-
break;
|
|
2023
|
-
}
|
|
2024
|
-
console.log('[PaymentModule] 没有发现未同步的订单');
|
|
2025
|
-
this.logInfo('No unsynced orders found');
|
|
2026
|
-
return _context31.abrupt("return", 0);
|
|
2027
|
-
case 13:
|
|
2028
|
-
console.log("[PaymentModule] \u53D1\u73B0 ".concat(unsyncedOrders.length, " \u4E2A\u672A\u540C\u6B65\u7684\u8BA2\u5355\uFF0C\u5F00\u59CB\u91CD\u65B0\u52A0\u5165\u4EFB\u52A1\u961F\u5217"));
|
|
2029
|
-
this.logInfo('Found unsynced orders, adding to sync queue', {
|
|
2030
|
-
unsyncedCount: unsyncedOrders.length,
|
|
2031
|
-
orderUuids: unsyncedOrders.map(function (o) {
|
|
2032
|
-
return o.uuid;
|
|
2033
|
-
})
|
|
2034
|
-
});
|
|
2035
|
-
requeuedCount = 0; // 将未同步的订单重新添加到任务队列
|
|
2036
|
-
_iterator7 = _createForOfIteratorHelper(unsyncedOrders);
|
|
2037
|
-
_context31.prev = 17;
|
|
2038
|
-
_iterator7.s();
|
|
2039
|
-
case 19:
|
|
2040
|
-
if ((_step7 = _iterator7.n()).done) {
|
|
2041
|
-
_context31.next = 27;
|
|
2042
|
-
break;
|
|
2043
|
-
}
|
|
2044
|
-
order = _step7.value;
|
|
2045
|
-
_context31.next = 23;
|
|
2046
|
-
return this.reAddOrderToSyncQueue(order);
|
|
2047
|
-
case 23:
|
|
2048
|
-
success = _context31.sent;
|
|
2049
|
-
if (success) {
|
|
2050
|
-
requeuedCount++;
|
|
2051
|
-
}
|
|
2052
|
-
case 25:
|
|
2053
|
-
_context31.next = 19;
|
|
2054
|
-
break;
|
|
2055
|
-
case 27:
|
|
2056
|
-
_context31.next = 32;
|
|
2057
|
-
break;
|
|
2058
|
-
case 29:
|
|
2059
|
-
_context31.prev = 29;
|
|
2060
|
-
_context31.t0 = _context31["catch"](17);
|
|
2061
|
-
_iterator7.e(_context31.t0);
|
|
1968
|
+
_context26.prev = 28;
|
|
1969
|
+
_context26.t1 = _context26["catch"](0);
|
|
1970
|
+
console.error('[PaymentModule] 金额舍入失败:', _context26.t1);
|
|
1971
|
+
throw new Error("\u91D1\u989D\u820D\u5165\u5931\u8D25: ".concat(_context26.t1 instanceof Error ? _context26.t1.message : String(_context26.t1)));
|
|
2062
1972
|
case 32:
|
|
2063
|
-
_context31.prev = 32;
|
|
2064
|
-
_iterator7.f();
|
|
2065
|
-
return _context31.finish(32);
|
|
2066
|
-
case 35:
|
|
2067
|
-
console.log("[PaymentModule] \u6210\u529F\u91CD\u65B0\u52A0\u5165 ".concat(requeuedCount, " \u4E2A\u8BA2\u5355\u5230\u4EFB\u52A1\u961F\u5217"));
|
|
2068
|
-
this.logInfo('Successfully requeued unsynced orders', {
|
|
2069
|
-
requeuedCount: requeuedCount,
|
|
2070
|
-
totalFound: unsyncedOrders.length
|
|
2071
|
-
});
|
|
2072
|
-
return _context31.abrupt("return", requeuedCount);
|
|
2073
|
-
case 40:
|
|
2074
|
-
_context31.prev = 40;
|
|
2075
|
-
_context31.t1 = _context31["catch"](1);
|
|
2076
|
-
console.error('[PaymentModule] 重新排队未同步订单失败', _context31.t1);
|
|
2077
|
-
this.logError('recheckAndRequeueUnsyncedOrders failed', _context31.t1);
|
|
2078
|
-
return _context31.abrupt("return", 0);
|
|
2079
|
-
case 45:
|
|
2080
|
-
case "end":
|
|
2081
|
-
return _context31.stop();
|
|
2082
|
-
}
|
|
2083
|
-
}, _callee31, this, [[1, 40], [17, 29, 32, 35]]);
|
|
2084
|
-
}));
|
|
2085
|
-
function recheckAndRequeueUnsyncedOrders() {
|
|
2086
|
-
return _recheckAndRequeueUnsyncedOrders.apply(this, arguments);
|
|
2087
|
-
}
|
|
2088
|
-
return recheckAndRequeueUnsyncedOrders;
|
|
2089
|
-
}()
|
|
2090
|
-
/**
|
|
2091
|
-
* 手动执行支付同步队列
|
|
2092
|
-
* 外部可以调用此方法来触发支付同步任务的执行
|
|
2093
|
-
*
|
|
2094
|
-
* 注意:此方法只执行现有队列中的任务,不会检查未同步的订单。
|
|
2095
|
-
* 如果需要检查未同步订单,请先调用 recheckAndRequeueUnsyncedOrders()
|
|
2096
|
-
*
|
|
2097
|
-
* 使用示例:
|
|
2098
|
-
* ```typescript
|
|
2099
|
-
* // 1. 先检查并重新排队未同步订单,然后执行队列
|
|
2100
|
-
* const requeuedCount = await paymentModule.recheckAndRequeueUnsyncedOrders();
|
|
2101
|
-
* if (requeuedCount > 0) {
|
|
2102
|
-
* await paymentModule.runPaymentSyncQueue();
|
|
2103
|
-
* }
|
|
2104
|
-
*
|
|
2105
|
-
* // 2. 或者直接执行现有队列(不检查未同步订单)
|
|
2106
|
-
* await paymentModule.runPaymentSyncQueue();
|
|
2107
|
-
* ```
|
|
2108
|
-
*/
|
|
2109
|
-
)
|
|
2110
|
-
}, {
|
|
2111
|
-
key: "runPaymentSyncQueue",
|
|
2112
|
-
value: (function () {
|
|
2113
|
-
var _runPaymentSyncQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
|
|
2114
|
-
var _this3 = this;
|
|
2115
|
-
var queue;
|
|
2116
|
-
return _regeneratorRuntime().wrap(function _callee32$(_context32) {
|
|
2117
|
-
while (1) switch (_context32.prev = _context32.next) {
|
|
2118
|
-
case 0:
|
|
2119
|
-
this.logInfo('Starting runPaymentSyncQueue');
|
|
2120
|
-
_context32.prev = 1;
|
|
2121
|
-
if (this.app.tasksManager) {
|
|
2122
|
-
_context32.next = 6;
|
|
2123
|
-
break;
|
|
2124
|
-
}
|
|
2125
|
-
console.warn('[PaymentModule] TasksManager 未初始化,无法执行同步队列');
|
|
2126
|
-
this.logWarning('TasksManager not initialized, cannot run sync queue');
|
|
2127
|
-
return _context32.abrupt("return");
|
|
2128
|
-
case 6:
|
|
2129
|
-
// 检查队列里有没有要跑的东西,没有就不 run 了
|
|
2130
|
-
queue = this.app.tasksManager.getTaskQueue({
|
|
2131
|
-
module: 'payment',
|
|
2132
|
-
queueId: 'payment_sync'
|
|
2133
|
-
});
|
|
2134
|
-
if (queue !== null && queue !== void 0 && queue.length) {
|
|
2135
|
-
_context32.next = 10;
|
|
2136
|
-
break;
|
|
2137
|
-
}
|
|
2138
|
-
console.log('[PaymentModule] 支付同步队列无内容,不执行');
|
|
2139
|
-
return _context32.abrupt("return");
|
|
2140
|
-
case 10:
|
|
2141
|
-
console.log('[PaymentModule] 开始执行支付同步队列');
|
|
2142
|
-
_context32.next = 13;
|
|
2143
|
-
return this.app.tasksManager.run({
|
|
2144
|
-
module: 'payment',
|
|
2145
|
-
queueId: 'payment_sync',
|
|
2146
|
-
callback: function callback() {
|
|
2147
|
-
console.log('[PaymentModule] 支付同步队列执行完成');
|
|
2148
|
-
if (_this3.logger) {
|
|
2149
|
-
_this3.logger.addLog({
|
|
2150
|
-
type: 'info',
|
|
2151
|
-
title: '[PaymentModule] Payment sync queue completed',
|
|
2152
|
-
metadata: {}
|
|
2153
|
-
});
|
|
2154
|
-
}
|
|
2155
|
-
}
|
|
2156
|
-
});
|
|
2157
|
-
case 13:
|
|
2158
|
-
this.logInfo('runPaymentSyncQueue completed successfully');
|
|
2159
|
-
_context32.next = 20;
|
|
2160
|
-
break;
|
|
2161
|
-
case 16:
|
|
2162
|
-
_context32.prev = 16;
|
|
2163
|
-
_context32.t0 = _context32["catch"](1);
|
|
2164
|
-
console.error('[PaymentModule] 执行支付同步队列失败', _context32.t0);
|
|
2165
|
-
this.logError('runPaymentSyncQueue failed', _context32.t0);
|
|
2166
|
-
// 不抛出错误,避免影响主流程
|
|
2167
|
-
case 20:
|
|
2168
|
-
case "end":
|
|
2169
|
-
return _context32.stop();
|
|
2170
|
-
}
|
|
2171
|
-
}, _callee32, this, [[1, 16]]);
|
|
2172
|
-
}));
|
|
2173
|
-
function runPaymentSyncQueue() {
|
|
2174
|
-
return _runPaymentSyncQueue.apply(this, arguments);
|
|
2175
|
-
}
|
|
2176
|
-
return runPaymentSyncQueue;
|
|
2177
|
-
}()
|
|
2178
|
-
/**
|
|
2179
|
-
* 重新将订单添加到同步队列
|
|
2180
|
-
* 用于处理因网络问题导致任务队列清空但订单未同步的情况
|
|
2181
|
-
*
|
|
2182
|
-
* @param order 要重新添加的订单
|
|
2183
|
-
* @returns Promise<boolean> 是否成功添加到队列
|
|
2184
|
-
*/
|
|
2185
|
-
)
|
|
2186
|
-
}, {
|
|
2187
|
-
key: "reAddOrderToSyncQueue",
|
|
2188
|
-
value: (function () {
|
|
2189
|
-
var _reAddOrderToSyncQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(order) {
|
|
2190
|
-
var paymentData, existingQueue, taskId, taskExists;
|
|
2191
|
-
return _regeneratorRuntime().wrap(function _callee33$(_context33) {
|
|
2192
|
-
while (1) switch (_context33.prev = _context33.next) {
|
|
2193
|
-
case 0:
|
|
2194
|
-
_context33.prev = 0;
|
|
2195
|
-
// 构造支付数据
|
|
2196
|
-
paymentData = {
|
|
2197
|
-
payments: order.payment.map(function (payment) {
|
|
2198
|
-
return {
|
|
2199
|
-
uuid: payment.uuid,
|
|
2200
|
-
amount: payment.amount,
|
|
2201
|
-
code: payment.code,
|
|
2202
|
-
id: payment.id,
|
|
2203
|
-
name: payment.name,
|
|
2204
|
-
type: payment.type,
|
|
2205
|
-
voucher_id: payment.voucher_id,
|
|
2206
|
-
metadata: payment.metadata,
|
|
2207
|
-
rounding_amount: payment.rounding_amount,
|
|
2208
|
-
service_charge: payment.service_charge
|
|
2209
|
-
};
|
|
2210
|
-
}),
|
|
2211
|
-
payment_status: order.payment_status === PaymentStatus.Finished ? 'paid' : 'partially_paid'
|
|
2212
|
-
}; // 检查是否已经在队列中,避免重复添加
|
|
2213
|
-
existingQueue = this.app.tasksManager.getTaskQueue({
|
|
2214
|
-
module: 'payment',
|
|
2215
|
-
queueId: 'payment_sync'
|
|
2216
|
-
});
|
|
2217
|
-
taskId = "payment_".concat(order.uuid);
|
|
2218
|
-
taskExists = existingQueue === null || existingQueue === void 0 ? void 0 : existingQueue.some(function (task) {
|
|
2219
|
-
return task.id === taskId;
|
|
2220
|
-
});
|
|
2221
|
-
if (!taskExists) {
|
|
2222
|
-
_context33.next = 8;
|
|
2223
|
-
break;
|
|
2224
|
-
}
|
|
2225
|
-
console.log("[PaymentModule] \u4EFB\u52A1 ".concat(taskId, " \u5DF2\u5B58\u5728\u4E8E\u961F\u5217\u4E2D\uFF0C\u8DF3\u8FC7\u91CD\u590D\u6DFB\u52A0"));
|
|
2226
|
-
return _context33.abrupt("return", false);
|
|
2227
|
-
case 8:
|
|
2228
|
-
_context33.next = 10;
|
|
2229
|
-
return this.addToSyncQueue(order, paymentData);
|
|
2230
|
-
case 10:
|
|
2231
|
-
console.log("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u5DF2\u91CD\u65B0\u6DFB\u52A0\u5230\u540C\u6B65\u961F\u5217"));
|
|
2232
|
-
this.logInfo('Order re-added to sync queue', {
|
|
2233
|
-
orderUuid: order.uuid,
|
|
2234
|
-
orderId: order.order_id,
|
|
2235
|
-
paymentStatus: order.payment_status,
|
|
2236
|
-
unsyncedPayments: order.payment.filter(function (p) {
|
|
2237
|
-
return !p.isSynced;
|
|
2238
|
-
}).length
|
|
2239
|
-
});
|
|
2240
|
-
return _context33.abrupt("return", true);
|
|
2241
|
-
case 15:
|
|
2242
|
-
_context33.prev = 15;
|
|
2243
|
-
_context33.t0 = _context33["catch"](0);
|
|
2244
|
-
console.error("[PaymentModule] \u91CD\u65B0\u6DFB\u52A0\u8BA2\u5355 ".concat(order.uuid, " \u5230\u540C\u6B65\u961F\u5217\u5931\u8D25"), _context33.t0);
|
|
2245
|
-
this.logError('Failed to re-add order to sync queue', _context33.t0, {
|
|
2246
|
-
orderUuid: order.uuid,
|
|
2247
|
-
orderId: order.order_id
|
|
2248
|
-
});
|
|
2249
|
-
return _context33.abrupt("return", false);
|
|
2250
|
-
case 20:
|
|
2251
|
-
case "end":
|
|
2252
|
-
return _context33.stop();
|
|
2253
|
-
}
|
|
2254
|
-
}, _callee33, this, [[0, 15]]);
|
|
2255
|
-
}));
|
|
2256
|
-
function reAddOrderToSyncQueue(_x32) {
|
|
2257
|
-
return _reAddOrderToSyncQueue.apply(this, arguments);
|
|
2258
|
-
}
|
|
2259
|
-
return reAddOrderToSyncQueue;
|
|
2260
|
-
}() // === 新的 API 方法实现 ===
|
|
2261
|
-
/**
|
|
2262
|
-
* 删除支付项(新方法)
|
|
2263
|
-
*/
|
|
2264
|
-
)
|
|
2265
|
-
}, {
|
|
2266
|
-
key: "deletePaymentItemAsync",
|
|
2267
|
-
value: function () {
|
|
2268
|
-
var _deletePaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(orderUuid, paymentUuid) {
|
|
2269
|
-
return _regeneratorRuntime().wrap(function _callee34$(_context34) {
|
|
2270
|
-
while (1) switch (_context34.prev = _context34.next) {
|
|
2271
|
-
case 0:
|
|
2272
|
-
console.warn('[PaymentModule] deletePaymentItemAsync 暂时使用 deletePaymentAsync 实现');
|
|
2273
|
-
return _context34.abrupt("return", this.deletePaymentAsync(orderUuid, paymentUuid));
|
|
2274
|
-
case 2:
|
|
2275
|
-
case "end":
|
|
2276
|
-
return _context34.stop();
|
|
2277
|
-
}
|
|
2278
|
-
}, _callee34, this);
|
|
2279
|
-
}));
|
|
2280
|
-
function deletePaymentItemAsync(_x33, _x34) {
|
|
2281
|
-
return _deletePaymentItemAsync.apply(this, arguments);
|
|
2282
|
-
}
|
|
2283
|
-
return deletePaymentItemAsync;
|
|
2284
|
-
}()
|
|
2285
|
-
/**
|
|
2286
|
-
* 更新支付项(新方法)
|
|
2287
|
-
*/
|
|
2288
|
-
}, {
|
|
2289
|
-
key: "updatePaymentItemAsync",
|
|
2290
|
-
value: (function () {
|
|
2291
|
-
var _updatePaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(orderUuid, paymentUuid, params) {
|
|
2292
|
-
return _regeneratorRuntime().wrap(function _callee35$(_context35) {
|
|
2293
|
-
while (1) switch (_context35.prev = _context35.next) {
|
|
2294
|
-
case 0:
|
|
2295
|
-
console.warn('[PaymentModule] updatePaymentItemAsync 暂时使用 updatePaymentAsync 实现');
|
|
2296
|
-
return _context35.abrupt("return", this.updatePaymentAsync(orderUuid, paymentUuid, params));
|
|
2297
|
-
case 2:
|
|
2298
|
-
case "end":
|
|
2299
|
-
return _context35.stop();
|
|
2300
|
-
}
|
|
2301
|
-
}, _callee35, this);
|
|
2302
|
-
}));
|
|
2303
|
-
function updatePaymentItemAsync(_x35, _x36, _x37) {
|
|
2304
|
-
return _updatePaymentItemAsync.apply(this, arguments);
|
|
2305
|
-
}
|
|
2306
|
-
return updatePaymentItemAsync;
|
|
2307
|
-
}()
|
|
2308
|
-
/**
|
|
2309
|
-
* 获取订单剩余待付金额(新方法)
|
|
2310
|
-
*/
|
|
2311
|
-
)
|
|
2312
|
-
}, {
|
|
2313
|
-
key: "getRemainingAmountAsync",
|
|
2314
|
-
value: (function () {
|
|
2315
|
-
var _getRemainingAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(orderUuid) {
|
|
2316
|
-
return _regeneratorRuntime().wrap(function _callee36$(_context36) {
|
|
2317
|
-
while (1) switch (_context36.prev = _context36.next) {
|
|
2318
|
-
case 0:
|
|
2319
|
-
console.warn('[PaymentModule] getRemainingAmountAsync 暂时使用 getRemainingOrderAmountAsync 实现');
|
|
2320
|
-
return _context36.abrupt("return", this.getRemainingOrderAmountAsync(orderUuid));
|
|
2321
|
-
case 2:
|
|
2322
|
-
case "end":
|
|
2323
|
-
return _context36.stop();
|
|
2324
|
-
}
|
|
2325
|
-
}, _callee36, this);
|
|
2326
|
-
}));
|
|
2327
|
-
function getRemainingAmountAsync(_x38) {
|
|
2328
|
-
return _getRemainingAmountAsync.apply(this, arguments);
|
|
2329
|
-
}
|
|
2330
|
-
return getRemainingAmountAsync;
|
|
2331
|
-
}()
|
|
2332
|
-
/**
|
|
2333
|
-
* 获取订单剩余待付金额(基于用户输入的金额)(新方法)
|
|
2334
|
-
*/
|
|
2335
|
-
)
|
|
2336
|
-
}, {
|
|
2337
|
-
key: "getRemainingAmountWithInputAsync",
|
|
2338
|
-
value: (function () {
|
|
2339
|
-
var _getRemainingAmountWithInputAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(inputAmount, orderUuid) {
|
|
2340
|
-
return _regeneratorRuntime().wrap(function _callee37$(_context37) {
|
|
2341
|
-
while (1) switch (_context37.prev = _context37.next) {
|
|
2342
|
-
case 0:
|
|
2343
|
-
console.warn('[PaymentModule] getRemainingAmountWithInputAsync 暂时使用 getRemainingOrderAmountWithInputAsync 实现');
|
|
2344
|
-
return _context37.abrupt("return", this.getRemainingOrderAmountWithInputAsync(inputAmount, orderUuid));
|
|
2345
|
-
case 2:
|
|
2346
1973
|
case "end":
|
|
2347
|
-
return
|
|
1974
|
+
return _context26.stop();
|
|
2348
1975
|
}
|
|
2349
|
-
},
|
|
1976
|
+
}, _callee26, this, [[0, 28]]);
|
|
2350
1977
|
}));
|
|
2351
|
-
function
|
|
2352
|
-
return
|
|
1978
|
+
function roundAmountAsync(_x28, _x29, _x30) {
|
|
1979
|
+
return _roundAmountAsync.apply(this, arguments);
|
|
2353
1980
|
}
|
|
2354
|
-
return
|
|
1981
|
+
return roundAmountAsync;
|
|
2355
1982
|
}()
|
|
2356
1983
|
/**
|
|
2357
|
-
*
|
|
1984
|
+
* 标准舍入处理(处理中点情况)
|
|
1985
|
+
*
|
|
1986
|
+
* @param value 要舍入的值
|
|
1987
|
+
* @param midpointUp 中点是否向上舍入
|
|
1988
|
+
* @returns 舍入后的值
|
|
2358
1989
|
*/
|
|
2359
|
-
)
|
|
2360
1990
|
}, {
|
|
2361
|
-
key: "
|
|
2362
|
-
value:
|
|
2363
|
-
var
|
|
2364
|
-
|
|
2365
|
-
while (1) switch (_context38.prev = _context38.next) {
|
|
2366
|
-
case 0:
|
|
2367
|
-
console.warn('[PaymentModule] submitPaymentAsync 暂时使用 submitPayAsync 实现');
|
|
2368
|
-
return _context38.abrupt("return", this.submitPayAsync(orderUuid));
|
|
2369
|
-
case 2:
|
|
2370
|
-
case "end":
|
|
2371
|
-
return _context38.stop();
|
|
2372
|
-
}
|
|
2373
|
-
}, _callee38, this);
|
|
2374
|
-
}));
|
|
2375
|
-
function submitPaymentAsync(_x41) {
|
|
2376
|
-
return _submitPaymentAsync.apply(this, arguments);
|
|
2377
|
-
}
|
|
2378
|
-
return submitPaymentAsync;
|
|
2379
|
-
}())
|
|
2380
|
-
}], [{
|
|
2381
|
-
key: "syncPaymentTask",
|
|
2382
|
-
value: (function () {
|
|
2383
|
-
var _syncPaymentTask = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(payload) {
|
|
2384
|
-
var _payload$task$payload, orderUuid, orderId, paymentData, core, app, logger, request, dbManager, requestRes, order, businessError, _error$message, _error$message2, _error$message3, isNetworkError, _error$response3, _error$response, errorData, _error$response2, _order2;
|
|
2385
|
-
return _regeneratorRuntime().wrap(function _callee39$(_context39) {
|
|
2386
|
-
while (1) switch (_context39.prev = _context39.next) {
|
|
2387
|
-
case 0:
|
|
2388
|
-
_payload$task$payload = payload.task.payload, orderUuid = _payload$task$payload.orderUuid, orderId = _payload$task$payload.orderId, paymentData = _payload$task$payload.paymentData, core = _payload$task$payload.core;
|
|
2389
|
-
console.log("[PaymentModule] \u5F00\u59CB\u540E\u53F0\u540C\u6B65\u652F\u4ED8\uFF0C\u8BA2\u5355ID: ".concat(orderId));
|
|
2390
|
-
|
|
2391
|
-
// 生成request_unique: 年月日时分秒毫秒+4位随机数
|
|
2392
|
-
paymentData.request_unique = generateRequestUniqueId();
|
|
2393
|
-
|
|
2394
|
-
// 从全局获取必要的实例
|
|
2395
|
-
app = window.app;
|
|
2396
|
-
logger = app === null || app === void 0 ? void 0 : app.logger; // 记录开始日志
|
|
2397
|
-
if (logger) {
|
|
2398
|
-
logger.addLog({
|
|
2399
|
-
type: 'info',
|
|
2400
|
-
title: '[PaymentModule] Starting syncPaymentTask',
|
|
2401
|
-
metadata: {
|
|
2402
|
-
orderUuid: orderUuid,
|
|
2403
|
-
orderId: orderId,
|
|
2404
|
-
paymentDataKeys: Object.keys(paymentData)
|
|
2405
|
-
}
|
|
2406
|
-
});
|
|
2407
|
-
}
|
|
2408
|
-
if (app) {
|
|
2409
|
-
_context39.next = 8;
|
|
2410
|
-
break;
|
|
2411
|
-
}
|
|
2412
|
-
throw new Error('App 实例未找到');
|
|
2413
|
-
case 8:
|
|
2414
|
-
request = app.request;
|
|
2415
|
-
if (request) {
|
|
2416
|
-
_context39.next = 11;
|
|
2417
|
-
break;
|
|
2418
|
-
}
|
|
2419
|
-
throw new Error('Request 插件未找到');
|
|
2420
|
-
case 11:
|
|
2421
|
-
dbManager = app.dbManager;
|
|
2422
|
-
if (dbManager) {
|
|
2423
|
-
_context39.next = 14;
|
|
2424
|
-
break;
|
|
2425
|
-
}
|
|
2426
|
-
throw new Error('DBManager 未找到');
|
|
2427
|
-
case 14:
|
|
2428
|
-
_context39.prev = 14;
|
|
2429
|
-
_context39.next = 17;
|
|
2430
|
-
return request.post("/shop/order/".concat(orderId, "/order-payment"), paymentData, {
|
|
2431
|
-
noToast: true
|
|
2432
|
-
});
|
|
2433
|
-
case 17:
|
|
2434
|
-
requestRes = _context39.sent;
|
|
2435
|
-
if (!(requestRes.status === true)) {
|
|
2436
|
-
_context39.next = 35;
|
|
2437
|
-
break;
|
|
2438
|
-
}
|
|
2439
|
-
_context39.next = 21;
|
|
2440
|
-
return dbManager.get('order', orderUuid);
|
|
2441
|
-
case 21:
|
|
2442
|
-
order = _context39.sent;
|
|
2443
|
-
if (!order) {
|
|
2444
|
-
_context39.next = 27;
|
|
2445
|
-
break;
|
|
2446
|
-
}
|
|
2447
|
-
order.payment.forEach(function (payment) {
|
|
2448
|
-
payment.isSynced = true;
|
|
2449
|
-
// 清除之前的错误状态
|
|
2450
|
-
delete payment.syncError;
|
|
2451
|
-
});
|
|
2452
|
-
_context39.next = 26;
|
|
2453
|
-
return dbManager.update('order', order);
|
|
2454
|
-
case 26:
|
|
2455
|
-
console.log("[PaymentModule] \u8BA2\u5355 ".concat(orderUuid, " \u540C\u6B65\u72B6\u6001\u5DF2\u66F4\u65B0"));
|
|
2456
|
-
case 27:
|
|
2457
|
-
console.log("[PaymentModule] \u8BA2\u5355 ".concat(orderUuid, " \u540E\u53F0\u540C\u6B65\u6210\u529F"));
|
|
2458
|
-
_context39.next = 30;
|
|
2459
|
-
return core.effects.emit('payment:onPaymentSyncSuccess', {
|
|
2460
|
-
orderUuid: orderUuid,
|
|
2461
|
-
orderId: orderId,
|
|
2462
|
-
timestamp: Date.now()
|
|
2463
|
-
});
|
|
2464
|
-
case 30:
|
|
2465
|
-
console.log("[PaymentModule] \u5DF2\u901A\u8FC7 effects \u901A\u77E5\u524D\u7AEF\u8BA2\u5355 ".concat(orderUuid, " \u540C\u6B65\u6210\u529F"));
|
|
2466
|
-
|
|
2467
|
-
// 记录成功日志
|
|
2468
|
-
if (logger) {
|
|
2469
|
-
logger.addLog({
|
|
2470
|
-
type: 'info',
|
|
2471
|
-
title: '[PaymentModule] syncPaymentTask completed successfully',
|
|
2472
|
-
metadata: {
|
|
2473
|
-
orderUuid: orderUuid,
|
|
2474
|
-
orderId: orderId
|
|
2475
|
-
}
|
|
2476
|
-
});
|
|
2477
|
-
}
|
|
2478
|
-
return _context39.abrupt("return", {
|
|
2479
|
-
status: 'success',
|
|
2480
|
-
orderUuid: orderUuid,
|
|
2481
|
-
orderId: orderId
|
|
2482
|
-
});
|
|
2483
|
-
case 35:
|
|
2484
|
-
// 接口返回失败,视为业务错误处理
|
|
2485
|
-
console.log("[PaymentModule] \u63A5\u53E3\u8FD4\u56DE\u5931\u8D25\uFF0C\u8BA2\u5355 ".concat(orderUuid, " \u540C\u6B65\u5931\u8D25"));
|
|
2486
|
-
|
|
2487
|
-
// 模拟业务错误,抛出一个包含响应信息的错误
|
|
2488
|
-
businessError = new Error(requestRes.message || '接口返回失败');
|
|
2489
|
-
businessError.response = {
|
|
2490
|
-
status: 200
|
|
2491
|
-
}; // HTTP 状态码是 200,但业务失败
|
|
2492
|
-
businessError.isBusinessError = true;
|
|
2493
|
-
businessError.responseData = requestRes;
|
|
2494
|
-
throw businessError;
|
|
2495
|
-
case 41:
|
|
2496
|
-
_context39.next = 80;
|
|
2497
|
-
break;
|
|
2498
|
-
case 43:
|
|
2499
|
-
_context39.prev = 43;
|
|
2500
|
-
_context39.t0 = _context39["catch"](14);
|
|
2501
|
-
console.error('[PaymentModule] 后台同步失败:', _context39.t0);
|
|
2502
|
-
|
|
2503
|
-
// 检查是否是网络错误(没有响应码)还是业务错误(有响应码)
|
|
2504
|
-
isNetworkError = !_context39.t0.response && !_context39.t0.status && (_context39.t0.code === 'NETWORK_ERROR' || _context39.t0.code === 'ERR_NETWORK' || _context39.t0.code === 'ECONNREFUSED' || _context39.t0.code === 'ENOTFOUND' || _context39.t0.code === 'ETIMEDOUT' || ((_error$message = _context39.t0.message) === null || _error$message === void 0 ? void 0 : _error$message.includes('网络')) || ((_error$message2 = _context39.t0.message) === null || _error$message2 === void 0 ? void 0 : _error$message2.includes('network')) || ((_error$message3 = _context39.t0.message) === null || _error$message3 === void 0 ? void 0 : _error$message3.includes('fetch')));
|
|
2505
|
-
if (!isNetworkError) {
|
|
2506
|
-
_context39.next = 53;
|
|
2507
|
-
break;
|
|
2508
|
-
}
|
|
2509
|
-
// 网络错误:重试
|
|
2510
|
-
console.log("[PaymentModule] \u7F51\u7EDC\u9519\u8BEF\uFF0C\u8BA2\u5355 ".concat(orderUuid, " \u5C06\u91CD\u8BD5\u540C\u6B65"));
|
|
2511
|
-
|
|
2512
|
-
// 记录网络错误日志
|
|
2513
|
-
if (logger) {
|
|
2514
|
-
logger.addLog({
|
|
2515
|
-
type: 'warning',
|
|
2516
|
-
title: '[PaymentModule] syncPaymentTask network error - will retry',
|
|
2517
|
-
metadata: {
|
|
2518
|
-
orderUuid: orderUuid,
|
|
2519
|
-
orderId: orderId,
|
|
2520
|
-
errorCode: _context39.t0.code,
|
|
2521
|
-
errorMessage: _context39.t0.message
|
|
2522
|
-
}
|
|
2523
|
-
});
|
|
2524
|
-
}
|
|
2525
|
-
throw _context39.t0;
|
|
2526
|
-
case 53:
|
|
2527
|
-
// 业务错误(有响应码):不标记为已同步,通过 effects 通知前端,但不重试
|
|
2528
|
-
console.log("[PaymentModule] \u4E1A\u52A1\u9519\u8BEF\uFF0C\u8BA2\u5355 ".concat(orderUuid, " \u540C\u6B65\u5931\u8D25\uFF0C\u901A\u77E5\u524D\u7AEF"));
|
|
2529
|
-
_context39.prev = 54;
|
|
2530
|
-
if (!(core && core.effects)) {
|
|
2531
|
-
_context39.next = 63;
|
|
2532
|
-
break;
|
|
2533
|
-
}
|
|
2534
|
-
// 通过 effects 通知前端同步错误
|
|
2535
|
-
errorData = {
|
|
2536
|
-
orderUuid: orderUuid,
|
|
2537
|
-
orderId: orderId,
|
|
2538
|
-
error: _context39.t0.message || '业务错误',
|
|
2539
|
-
errorCode: _context39.t0.code,
|
|
2540
|
-
statusCode: ((_error$response = _context39.t0.response) === null || _error$response === void 0 ? void 0 : _error$response.status) || _context39.t0.status,
|
|
2541
|
-
timestamp: Date.now()
|
|
2542
|
-
}; // 如果是业务错误,添加响应数据
|
|
2543
|
-
if (_context39.t0.isBusinessError && _context39.t0.responseData) {
|
|
2544
|
-
errorData.error = _context39.t0.responseData.message || _context39.t0.message || '接口返回失败';
|
|
2545
|
-
// 可以添加更多响应数据
|
|
2546
|
-
errorData.responseData = _context39.t0.responseData;
|
|
2547
|
-
}
|
|
2548
|
-
_context39.next = 60;
|
|
2549
|
-
return core.effects.emit('payment:onPaymentSyncError', errorData);
|
|
2550
|
-
case 60:
|
|
2551
|
-
console.log("[PaymentModule] \u5DF2\u901A\u8FC7 effects \u901A\u77E5\u524D\u7AEF\u8BA2\u5355 ".concat(orderUuid, " \u540C\u6B65\u9519\u8BEF"));
|
|
2552
|
-
_context39.next = 64;
|
|
2553
|
-
break;
|
|
2554
|
-
case 63:
|
|
2555
|
-
console.warn("[PaymentModule] \u65E0\u6CD5\u83B7\u53D6 core \u5B9E\u4F8B\uFF0C\u65E0\u6CD5\u901A\u77E5\u524D\u7AEF\u9519\u8BEF");
|
|
2556
|
-
case 64:
|
|
2557
|
-
// 记录业务错误日志
|
|
2558
|
-
if (logger) {
|
|
2559
|
-
logger.addLog({
|
|
2560
|
-
type: 'error',
|
|
2561
|
-
title: '[PaymentModule] syncPaymentTask business error',
|
|
2562
|
-
metadata: {
|
|
2563
|
-
orderUuid: orderUuid,
|
|
2564
|
-
orderId: orderId,
|
|
2565
|
-
errorCode: _context39.t0.code,
|
|
2566
|
-
errorMessage: _context39.t0.message,
|
|
2567
|
-
statusCode: ((_error$response2 = _context39.t0.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.status) || _context39.t0.status,
|
|
2568
|
-
isBusinessError: _context39.t0.isBusinessError
|
|
2569
|
-
}
|
|
2570
|
-
});
|
|
2571
|
-
}
|
|
2572
|
-
_context39.next = 71;
|
|
2573
|
-
break;
|
|
2574
|
-
case 67:
|
|
2575
|
-
_context39.prev = 67;
|
|
2576
|
-
_context39.t1 = _context39["catch"](54);
|
|
2577
|
-
console.error("[PaymentModule] \u901A\u77E5\u524D\u7AEF\u540C\u6B65\u9519\u8BEF\u5931\u8D25:", _context39.t1);
|
|
1991
|
+
key: "standardRound",
|
|
1992
|
+
value: function standardRound(value, midpointUp) {
|
|
1993
|
+
var floorValue = value.floor();
|
|
1994
|
+
var fractionalPart = value.minus(floorValue);
|
|
2578
1995
|
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
});
|
|
2590
|
-
}
|
|
2591
|
-
case 71:
|
|
2592
|
-
_context39.next = 73;
|
|
2593
|
-
return dbManager.get('order', orderUuid);
|
|
2594
|
-
case 73:
|
|
2595
|
-
_order2 = _context39.sent;
|
|
2596
|
-
if (!_order2) {
|
|
2597
|
-
_context39.next = 79;
|
|
2598
|
-
break;
|
|
2599
|
-
}
|
|
2600
|
-
_order2.payment.forEach(function (payment) {
|
|
2601
|
-
payment.isSynced = true;
|
|
2602
|
-
});
|
|
2603
|
-
_context39.next = 78;
|
|
2604
|
-
return dbManager.update('order', _order2);
|
|
2605
|
-
case 78:
|
|
2606
|
-
console.log("[PaymentModule] \u8BA2\u5355 ".concat(orderUuid, " \u4E1A\u52A1\u9519\u8BEF\uFF0C\u5DF2\u6807\u8BB0\u4E3A\u5DF2\u540C\u6B65"));
|
|
2607
|
-
case 79:
|
|
2608
|
-
return _context39.abrupt("return", {
|
|
2609
|
-
status: 'completed_with_error',
|
|
2610
|
-
orderUuid: orderUuid,
|
|
2611
|
-
orderId: orderId,
|
|
2612
|
-
error: _context39.t0.message || '业务错误',
|
|
2613
|
-
statusCode: ((_error$response3 = _context39.t0.response) === null || _error$response3 === void 0 ? void 0 : _error$response3.status) || _context39.t0.status
|
|
2614
|
-
});
|
|
2615
|
-
case 80:
|
|
2616
|
-
case "end":
|
|
2617
|
-
return _context39.stop();
|
|
2618
|
-
}
|
|
2619
|
-
}, _callee39, null, [[14, 43], [54, 67]]);
|
|
2620
|
-
}));
|
|
2621
|
-
function syncPaymentTask(_x42) {
|
|
2622
|
-
return _syncPaymentTask.apply(this, arguments);
|
|
1996
|
+
// 检查是否是中点(小数部分 = 0.5)
|
|
1997
|
+
if (fractionalPart.eq(0.5)) {
|
|
1998
|
+
// 中点情况,根据规则决定
|
|
1999
|
+
return midpointUp ? floorValue.plus(1) : floorValue;
|
|
2000
|
+
} else if (fractionalPart.gt(0.5)) {
|
|
2001
|
+
// 大于中点,向上舍入
|
|
2002
|
+
return floorValue.plus(1);
|
|
2003
|
+
} else {
|
|
2004
|
+
// 小于中点,向下舍入
|
|
2005
|
+
return floorValue;
|
|
2623
2006
|
}
|
|
2624
|
-
|
|
2625
|
-
}())
|
|
2007
|
+
}
|
|
2626
2008
|
}]);
|
|
2627
2009
|
return PaymentModule;
|
|
2628
2010
|
}(BaseModule);
|