@pisell/pisellos 2.1.16 → 2.1.17
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.
|
@@ -1043,7 +1043,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1043
1043
|
key: "addPaymentItemAsync",
|
|
1044
1044
|
value: (function () {
|
|
1045
1045
|
var _addPaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(orderUuid, paymentItem) {
|
|
1046
|
-
var _newPaymentItem$metad, _newPaymentItem$metad2, _newPaymentItem$metad3, order, paymentUuid, newPaymentItem;
|
|
1046
|
+
var _newPaymentItem$metad, _newPaymentItem$metad2, _newPaymentItem$metad3, order, expectAmount, warningMessage, paymentUuid, newPaymentItem;
|
|
1047
1047
|
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
1048
1048
|
while (1) switch (_context13.prev = _context13.next) {
|
|
1049
1049
|
case 0:
|
|
@@ -1064,6 +1064,27 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1064
1064
|
}
|
|
1065
1065
|
throw new Error("Order not found: ".concat(orderUuid));
|
|
1066
1066
|
case 7:
|
|
1067
|
+
// 🔒 支付锁检查:如果订单待付金额已经为0,不允许继续添加支付项
|
|
1068
|
+
expectAmount = new Decimal(order.expect_amount);
|
|
1069
|
+
if (!expectAmount.lte(0)) {
|
|
1070
|
+
_context13.next = 13;
|
|
1071
|
+
break;
|
|
1072
|
+
}
|
|
1073
|
+
warningMessage = "\u8BA2\u5355 ".concat(orderUuid, " \u5F85\u4ED8\u91D1\u989D\u5DF2\u4E3A0\uFF0C\u4E0D\u5141\u8BB8\u6DFB\u52A0\u65B0\u7684\u652F\u4ED8\u9879");
|
|
1074
|
+
console.warn('[PaymentModule] Payment lock triggered:', {
|
|
1075
|
+
orderUuid: orderUuid,
|
|
1076
|
+
expectAmount: order.expect_amount,
|
|
1077
|
+
attemptedPaymentAmount: paymentItem.amount,
|
|
1078
|
+
attemptedPaymentCode: paymentItem.code,
|
|
1079
|
+
reason: 'Order already fully paid'
|
|
1080
|
+
});
|
|
1081
|
+
this.logError('addPaymentItemAsync blocked by payment lock', new Error(warningMessage), {
|
|
1082
|
+
orderUuid: orderUuid,
|
|
1083
|
+
expectAmount: order.expect_amount,
|
|
1084
|
+
paymentItem: paymentItem
|
|
1085
|
+
});
|
|
1086
|
+
throw new Error(warningMessage);
|
|
1087
|
+
case 13:
|
|
1067
1088
|
paymentUuid = getUniqueId('payment_');
|
|
1068
1089
|
newPaymentItem = {
|
|
1069
1090
|
uuid: paymentUuid,
|
|
@@ -1086,15 +1107,15 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1086
1107
|
};
|
|
1087
1108
|
order.payment.push(newPaymentItem);
|
|
1088
1109
|
this.recalculateOrderAmount(order);
|
|
1089
|
-
_context13.next =
|
|
1110
|
+
_context13.next = 19;
|
|
1090
1111
|
return this.dbManager.update('order', order);
|
|
1091
|
-
case
|
|
1092
|
-
_context13.next =
|
|
1112
|
+
case 19:
|
|
1113
|
+
_context13.next = 21;
|
|
1093
1114
|
return this.core.effects.emit(PaymentHooks.OnPaymentAdded, {
|
|
1094
1115
|
orderUuid: orderUuid,
|
|
1095
1116
|
payment: newPaymentItem
|
|
1096
1117
|
});
|
|
1097
|
-
case
|
|
1118
|
+
case 21:
|
|
1098
1119
|
this.logInfo('addPaymentItemAsync completed successfully', {
|
|
1099
1120
|
orderUuid: orderUuid,
|
|
1100
1121
|
paymentUuid: newPaymentItem.uuid,
|
|
@@ -1108,10 +1129,10 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1108
1129
|
actualPaidAmount: (_newPaymentItem$metad2 = newPaymentItem.metadata) === null || _newPaymentItem$metad2 === void 0 ? void 0 : _newPaymentItem$metad2.actual_paid_amount,
|
|
1109
1130
|
changeGivenAmount: (_newPaymentItem$metad3 = newPaymentItem.metadata) === null || _newPaymentItem$metad3 === void 0 ? void 0 : _newPaymentItem$metad3.change_given_amount
|
|
1110
1131
|
});
|
|
1111
|
-
_context13.next =
|
|
1132
|
+
_context13.next = 29;
|
|
1112
1133
|
break;
|
|
1113
|
-
case
|
|
1114
|
-
_context13.prev =
|
|
1134
|
+
case 24:
|
|
1135
|
+
_context13.prev = 24;
|
|
1115
1136
|
_context13.t0 = _context13["catch"](1);
|
|
1116
1137
|
console.error('[PaymentModule] 添加支付项失败', _context13.t0);
|
|
1117
1138
|
this.logError('addPaymentItemAsync failed', _context13.t0, {
|
|
@@ -1119,11 +1140,11 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1119
1140
|
paymentItem: paymentItem
|
|
1120
1141
|
});
|
|
1121
1142
|
throw _context13.t0;
|
|
1122
|
-
case
|
|
1143
|
+
case 29:
|
|
1123
1144
|
case "end":
|
|
1124
1145
|
return _context13.stop();
|
|
1125
1146
|
}
|
|
1126
|
-
}, _callee13, this, [[1,
|
|
1147
|
+
}, _callee13, this, [[1, 24]]);
|
|
1127
1148
|
}));
|
|
1128
1149
|
function addPaymentItemAsync(_x14, _x15) {
|
|
1129
1150
|
return _addPaymentItemAsync.apply(this, arguments);
|
|
@@ -1243,7 +1264,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1243
1264
|
key: "updateVoucherPaymentItemsAsync",
|
|
1244
1265
|
value: (function () {
|
|
1245
1266
|
var _updateVoucherPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(orderUuid, voucherPaymentItems) {
|
|
1246
|
-
var order, existingVoucherItems, _iterator5, _step5, voucherItem, _iterator6, _step6, _voucherItem, updatedOrder;
|
|
1267
|
+
var order, expectAmount, warningMessage, existingVoucherItems, _iterator5, _step5, voucherItem, _iterator6, _step6, _voucherItem, updatedOrder;
|
|
1247
1268
|
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
1248
1269
|
while (1) switch (_context15.prev = _context15.next) {
|
|
1249
1270
|
case 0:
|
|
@@ -1270,6 +1291,43 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1270
1291
|
}
|
|
1271
1292
|
throw new Error("\u8BA2\u5355\u4E0D\u5B58\u5728: ".concat(orderUuid));
|
|
1272
1293
|
case 7:
|
|
1294
|
+
// 🔒 订单状态检查:如果订单待付金额已经为0且尝试清空代金券(空数组),跳过操作
|
|
1295
|
+
expectAmount = new Decimal(order.expect_amount);
|
|
1296
|
+
if (!(expectAmount.lte(0) && voucherPaymentItems.length === 0)) {
|
|
1297
|
+
_context15.next = 12;
|
|
1298
|
+
break;
|
|
1299
|
+
}
|
|
1300
|
+
console.warn('[PaymentModule] Skipping voucher update - order already fully paid:', {
|
|
1301
|
+
orderUuid: orderUuid,
|
|
1302
|
+
expectAmount: order.expect_amount,
|
|
1303
|
+
attemptedOperation: 'clear_vouchers',
|
|
1304
|
+
reason: 'Order payment completed, no need to clear vouchers'
|
|
1305
|
+
});
|
|
1306
|
+
this.logInfo('updateVoucherPaymentItemsAsync skipped - order already paid', {
|
|
1307
|
+
orderUuid: orderUuid,
|
|
1308
|
+
expectAmount: order.expect_amount,
|
|
1309
|
+
voucherCount: voucherPaymentItems.length
|
|
1310
|
+
});
|
|
1311
|
+
return _context15.abrupt("return");
|
|
1312
|
+
case 12:
|
|
1313
|
+
if (!(expectAmount.lte(0) && voucherPaymentItems.length > 0)) {
|
|
1314
|
+
_context15.next = 17;
|
|
1315
|
+
break;
|
|
1316
|
+
}
|
|
1317
|
+
warningMessage = "\u8BA2\u5355 ".concat(orderUuid, " \u5DF2\u5B8C\u6210\u652F\u4ED8\uFF0C\u4E0D\u5141\u8BB8\u6DFB\u52A0\u4EE3\u91D1\u5238\u652F\u4ED8\u9879");
|
|
1318
|
+
console.warn('[PaymentModule] Voucher update blocked - order already fully paid:', {
|
|
1319
|
+
orderUuid: orderUuid,
|
|
1320
|
+
expectAmount: order.expect_amount,
|
|
1321
|
+
attemptedVoucherCount: voucherPaymentItems.length,
|
|
1322
|
+
reason: 'Order already fully paid'
|
|
1323
|
+
});
|
|
1324
|
+
this.logError('updateVoucherPaymentItemsAsync blocked', new Error(warningMessage), {
|
|
1325
|
+
orderUuid: orderUuid,
|
|
1326
|
+
expectAmount: order.expect_amount,
|
|
1327
|
+
voucherPaymentItems: voucherPaymentItems
|
|
1328
|
+
});
|
|
1329
|
+
throw new Error(warningMessage);
|
|
1330
|
+
case 17:
|
|
1273
1331
|
// 1. 查找所有现有的代金券类支付项(带 voucher_id 且状态不是 voided)
|
|
1274
1332
|
existingVoucherItems = order.payment.filter(function (payment) {
|
|
1275
1333
|
return payment.voucher_id && payment.status !== 'voided';
|
|
@@ -1289,96 +1347,96 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1289
1347
|
|
|
1290
1348
|
// 2. 删除所有现有的代金券支付项
|
|
1291
1349
|
_iterator5 = _createForOfIteratorHelper(existingVoucherItems);
|
|
1292
|
-
_context15.prev =
|
|
1350
|
+
_context15.prev = 20;
|
|
1293
1351
|
_iterator5.s();
|
|
1294
|
-
case
|
|
1352
|
+
case 22:
|
|
1295
1353
|
if ((_step5 = _iterator5.n()).done) {
|
|
1296
|
-
_context15.next =
|
|
1354
|
+
_context15.next = 29;
|
|
1297
1355
|
break;
|
|
1298
1356
|
}
|
|
1299
1357
|
voucherItem = _step5.value;
|
|
1300
1358
|
console.log("[PaymentModule] \u5220\u9664\u73B0\u6709\u4EE3\u91D1\u5238\u652F\u4ED8\u9879: ".concat(voucherItem.uuid));
|
|
1301
|
-
_context15.next =
|
|
1359
|
+
_context15.next = 27;
|
|
1302
1360
|
return this.deletePaymentAsync(orderUuid, voucherItem.uuid);
|
|
1303
|
-
case
|
|
1304
|
-
_context15.next =
|
|
1361
|
+
case 27:
|
|
1362
|
+
_context15.next = 22;
|
|
1305
1363
|
break;
|
|
1306
|
-
case
|
|
1307
|
-
_context15.next =
|
|
1364
|
+
case 29:
|
|
1365
|
+
_context15.next = 34;
|
|
1308
1366
|
break;
|
|
1309
|
-
case
|
|
1310
|
-
_context15.prev =
|
|
1311
|
-
_context15.t0 = _context15["catch"](
|
|
1367
|
+
case 31:
|
|
1368
|
+
_context15.prev = 31;
|
|
1369
|
+
_context15.t0 = _context15["catch"](20);
|
|
1312
1370
|
_iterator5.e(_context15.t0);
|
|
1313
|
-
case
|
|
1314
|
-
_context15.prev =
|
|
1371
|
+
case 34:
|
|
1372
|
+
_context15.prev = 34;
|
|
1315
1373
|
_iterator5.f();
|
|
1316
|
-
return _context15.finish(
|
|
1317
|
-
case
|
|
1374
|
+
return _context15.finish(34);
|
|
1375
|
+
case 37:
|
|
1318
1376
|
// 3. 添加新的代金券支付项
|
|
1319
1377
|
console.log('[PaymentModule] 添加新的代金券支付项:', {
|
|
1320
1378
|
orderUuid: orderUuid,
|
|
1321
1379
|
newItemCount: voucherPaymentItems.length
|
|
1322
1380
|
});
|
|
1323
1381
|
_iterator6 = _createForOfIteratorHelper(voucherPaymentItems);
|
|
1324
|
-
_context15.prev =
|
|
1382
|
+
_context15.prev = 39;
|
|
1325
1383
|
_iterator6.s();
|
|
1326
|
-
case
|
|
1384
|
+
case 41:
|
|
1327
1385
|
if ((_step6 = _iterator6.n()).done) {
|
|
1328
|
-
_context15.next =
|
|
1386
|
+
_context15.next = 50;
|
|
1329
1387
|
break;
|
|
1330
1388
|
}
|
|
1331
1389
|
_voucherItem = _step6.value;
|
|
1332
1390
|
if (_voucherItem.voucher_id) {
|
|
1333
|
-
_context15.next =
|
|
1391
|
+
_context15.next = 45;
|
|
1334
1392
|
break;
|
|
1335
1393
|
}
|
|
1336
1394
|
throw new Error("\u4EE3\u91D1\u5238\u652F\u4ED8\u9879\u7F3A\u5C11 voucher_id: ".concat(JSON.stringify(_voucherItem)));
|
|
1337
|
-
case
|
|
1395
|
+
case 45:
|
|
1338
1396
|
console.log("[PaymentModule] \u6DFB\u52A0\u4EE3\u91D1\u5238\u652F\u4ED8\u9879:", {
|
|
1339
1397
|
code: _voucherItem.code,
|
|
1340
1398
|
amount: _voucherItem.amount,
|
|
1341
1399
|
voucher_id: _voucherItem.voucher_id,
|
|
1342
1400
|
order_payment_type: _voucherItem.order_payment_type
|
|
1343
1401
|
});
|
|
1344
|
-
_context15.next =
|
|
1402
|
+
_context15.next = 48;
|
|
1345
1403
|
return this.addPaymentItemAsync(orderUuid, _voucherItem);
|
|
1346
|
-
case
|
|
1347
|
-
_context15.next =
|
|
1404
|
+
case 48:
|
|
1405
|
+
_context15.next = 41;
|
|
1348
1406
|
break;
|
|
1349
|
-
case
|
|
1350
|
-
_context15.next =
|
|
1407
|
+
case 50:
|
|
1408
|
+
_context15.next = 55;
|
|
1351
1409
|
break;
|
|
1352
|
-
case
|
|
1353
|
-
_context15.prev =
|
|
1354
|
-
_context15.t1 = _context15["catch"](
|
|
1410
|
+
case 52:
|
|
1411
|
+
_context15.prev = 52;
|
|
1412
|
+
_context15.t1 = _context15["catch"](39);
|
|
1355
1413
|
_iterator6.e(_context15.t1);
|
|
1356
|
-
case
|
|
1357
|
-
_context15.prev =
|
|
1414
|
+
case 55:
|
|
1415
|
+
_context15.prev = 55;
|
|
1358
1416
|
_iterator6.f();
|
|
1359
|
-
return _context15.finish(
|
|
1360
|
-
case
|
|
1361
|
-
_context15.next =
|
|
1417
|
+
return _context15.finish(55);
|
|
1418
|
+
case 58:
|
|
1419
|
+
_context15.next = 60;
|
|
1362
1420
|
return this.getPaymentOrderByUuidAsync(orderUuid);
|
|
1363
|
-
case
|
|
1421
|
+
case 60:
|
|
1364
1422
|
updatedOrder = _context15.sent;
|
|
1365
|
-
_context15.next =
|
|
1423
|
+
_context15.next = 63;
|
|
1366
1424
|
return this.core.effects.emit(PaymentHooks.OnPaymentAdded, {
|
|
1367
1425
|
orderUuid: orderUuid,
|
|
1368
1426
|
order: updatedOrder,
|
|
1369
1427
|
payment: null // 批量操作不提供单个支付项
|
|
1370
1428
|
});
|
|
1371
|
-
case
|
|
1429
|
+
case 63:
|
|
1372
1430
|
this.logInfo('updateVoucherPaymentItemsAsync completed successfully', {
|
|
1373
1431
|
orderUuid: orderUuid,
|
|
1374
1432
|
removedVoucherCount: existingVoucherItems.length,
|
|
1375
1433
|
addedVoucherCount: voucherPaymentItems.length,
|
|
1376
1434
|
finalExpectAmount: updatedOrder === null || updatedOrder === void 0 ? void 0 : updatedOrder.expect_amount
|
|
1377
1435
|
});
|
|
1378
|
-
_context15.next =
|
|
1436
|
+
_context15.next = 71;
|
|
1379
1437
|
break;
|
|
1380
|
-
case
|
|
1381
|
-
_context15.prev =
|
|
1438
|
+
case 66:
|
|
1439
|
+
_context15.prev = 66;
|
|
1382
1440
|
_context15.t2 = _context15["catch"](1);
|
|
1383
1441
|
console.error('[PaymentModule] 批量更新代金券支付项失败:', _context15.t2);
|
|
1384
1442
|
this.logError('updateVoucherPaymentItemsAsync failed', _context15.t2, {
|
|
@@ -1386,11 +1444,11 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1386
1444
|
voucherPaymentItems: voucherPaymentItems
|
|
1387
1445
|
});
|
|
1388
1446
|
throw _context15.t2;
|
|
1389
|
-
case
|
|
1447
|
+
case 71:
|
|
1390
1448
|
case "end":
|
|
1391
1449
|
return _context15.stop();
|
|
1392
1450
|
}
|
|
1393
|
-
}, _callee15, this, [[1,
|
|
1451
|
+
}, _callee15, this, [[1, 66], [20, 31, 34, 37], [39, 52, 55, 58]]);
|
|
1394
1452
|
}));
|
|
1395
1453
|
function updateVoucherPaymentItemsAsync(_x18, _x19) {
|
|
1396
1454
|
return _updateVoucherPaymentItemsAsync.apply(this, arguments);
|
|
@@ -1284,7 +1284,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1284
1284
|
value: (function () {
|
|
1285
1285
|
var _updateVoucherPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(voucherPaymentItems) {
|
|
1286
1286
|
var _this3 = this;
|
|
1287
|
-
var orderPaymentType, voucherPaymentItemsWithType, currentOrderId, isCurrentOrderReal, updatedOrder;
|
|
1287
|
+
var remainingAmount, remainingValue, orderPaymentType, voucherPaymentItemsWithType, currentOrderId, isCurrentOrderReal, updatedOrder;
|
|
1288
1288
|
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
1289
1289
|
while (1) switch (_context17.prev = _context17.next) {
|
|
1290
1290
|
case 0:
|
|
@@ -1295,6 +1295,24 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1295
1295
|
}
|
|
1296
1296
|
throw createCheckoutError(CheckoutErrorType.ValidationFailed, '当前没有活跃订单,无法更新代金券支付项');
|
|
1297
1297
|
case 3:
|
|
1298
|
+
_context17.next = 5;
|
|
1299
|
+
return this.calculateRemainingAmountAsync();
|
|
1300
|
+
case 5:
|
|
1301
|
+
remainingAmount = _context17.sent;
|
|
1302
|
+
remainingValue = new Decimal(remainingAmount);
|
|
1303
|
+
if (!remainingValue.lte(0)) {
|
|
1304
|
+
_context17.next = 10;
|
|
1305
|
+
break;
|
|
1306
|
+
}
|
|
1307
|
+
this.logInfo('订单已完成支付且修改代金券,跳过操作避免重复同步:', {
|
|
1308
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
1309
|
+
orderId: this.store.currentOrder.order_id,
|
|
1310
|
+
remainingAmount: remainingAmount,
|
|
1311
|
+
voucherPaymentItemsCount: voucherPaymentItems.length,
|
|
1312
|
+
reason: 'Order payment completed, skip clear vouchers'
|
|
1313
|
+
});
|
|
1314
|
+
return _context17.abrupt("return");
|
|
1315
|
+
case 10:
|
|
1298
1316
|
this.logInfo('开始批量更新代金券支付项:', {
|
|
1299
1317
|
voucherPaymentItems: voucherPaymentItems
|
|
1300
1318
|
});
|
|
@@ -1316,15 +1334,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1316
1334
|
metadata: metadata
|
|
1317
1335
|
});
|
|
1318
1336
|
}); // 调用 Payment 模块的批量更新方法
|
|
1319
|
-
_context17.next =
|
|
1337
|
+
_context17.next = 15;
|
|
1320
1338
|
return this.payment.updateVoucherPaymentItemsAsync(this.store.currentOrder.uuid, voucherPaymentItemsWithType);
|
|
1321
|
-
case
|
|
1339
|
+
case 15:
|
|
1322
1340
|
// 重新从Payment模块获取最新的订单数据,确保支付项同步
|
|
1323
1341
|
currentOrderId = this.store.currentOrder.order_id; // 保存当前的订单ID
|
|
1324
1342
|
isCurrentOrderReal = currentOrderId && !isVirtualOrderId(currentOrderId);
|
|
1325
|
-
_context17.next =
|
|
1343
|
+
_context17.next = 19;
|
|
1326
1344
|
return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
|
|
1327
|
-
case
|
|
1345
|
+
case 19:
|
|
1328
1346
|
updatedOrder = _context17.sent;
|
|
1329
1347
|
if (updatedOrder) {
|
|
1330
1348
|
// 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
|
|
@@ -1339,10 +1357,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1339
1357
|
}
|
|
1340
1358
|
|
|
1341
1359
|
// 更新 stateAmount 为剩余未支付金额
|
|
1342
|
-
_context17.next =
|
|
1360
|
+
_context17.next = 23;
|
|
1343
1361
|
return this.updateStateAmountToRemaining();
|
|
1344
|
-
case
|
|
1345
|
-
_context17.next =
|
|
1362
|
+
case 23:
|
|
1363
|
+
_context17.next = 25;
|
|
1346
1364
|
return this.core.effects.emit(CheckoutHooks.OnPaymentStarted, {
|
|
1347
1365
|
orderUuid: this.store.currentOrder.uuid,
|
|
1348
1366
|
paymentMethodCode: 'VOUCHER_BATCH',
|
|
@@ -1351,23 +1369,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1351
1369
|
}, 0).toFixed(2),
|
|
1352
1370
|
timestamp: Date.now()
|
|
1353
1371
|
});
|
|
1354
|
-
case
|
|
1372
|
+
case 25:
|
|
1355
1373
|
this.logInfo('代金券支付项批量更新成功');
|
|
1356
|
-
_context17.next =
|
|
1374
|
+
_context17.next = 34;
|
|
1357
1375
|
break;
|
|
1358
|
-
case
|
|
1359
|
-
_context17.prev =
|
|
1376
|
+
case 28:
|
|
1377
|
+
_context17.prev = 28;
|
|
1360
1378
|
_context17.t0 = _context17["catch"](0);
|
|
1361
1379
|
this.logError('[Checkout] 批量更新代金券支付项失败:', _context17.t0);
|
|
1362
|
-
_context17.next =
|
|
1380
|
+
_context17.next = 33;
|
|
1363
1381
|
return this.handleError(_context17.t0, CheckoutErrorType.PaymentFailed);
|
|
1364
|
-
case
|
|
1382
|
+
case 33:
|
|
1365
1383
|
throw _context17.t0;
|
|
1366
|
-
case
|
|
1384
|
+
case 34:
|
|
1367
1385
|
case "end":
|
|
1368
1386
|
return _context17.stop();
|
|
1369
1387
|
}
|
|
1370
|
-
}, _callee17, this, [[0,
|
|
1388
|
+
}, _callee17, this, [[0, 28]]);
|
|
1371
1389
|
}));
|
|
1372
1390
|
function updateVoucherPaymentItemsAsync(_x16) {
|
|
1373
1391
|
return _updateVoucherPaymentItemsAsync.apply(this, arguments);
|
|
@@ -526,6 +526,23 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
526
526
|
if (!order) {
|
|
527
527
|
throw new Error(`Order not found: ${orderUuid}`);
|
|
528
528
|
}
|
|
529
|
+
const expectAmount = new import_decimal.Decimal(order.expect_amount);
|
|
530
|
+
if (expectAmount.lte(0)) {
|
|
531
|
+
const warningMessage = `订单 ${orderUuid} 待付金额已为0,不允许添加新的支付项`;
|
|
532
|
+
console.warn("[PaymentModule] Payment lock triggered:", {
|
|
533
|
+
orderUuid,
|
|
534
|
+
expectAmount: order.expect_amount,
|
|
535
|
+
attemptedPaymentAmount: paymentItem.amount,
|
|
536
|
+
attemptedPaymentCode: paymentItem.code,
|
|
537
|
+
reason: "Order already fully paid"
|
|
538
|
+
});
|
|
539
|
+
this.logError("addPaymentItemAsync blocked by payment lock", new Error(warningMessage), {
|
|
540
|
+
orderUuid,
|
|
541
|
+
expectAmount: order.expect_amount,
|
|
542
|
+
paymentItem
|
|
543
|
+
});
|
|
544
|
+
throw new Error(warningMessage);
|
|
545
|
+
}
|
|
529
546
|
const paymentUuid = (0, import_utils.getUniqueId)("payment_");
|
|
530
547
|
const newPaymentItem = {
|
|
531
548
|
uuid: paymentUuid,
|
|
@@ -653,6 +670,36 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
|
|
|
653
670
|
if (!order) {
|
|
654
671
|
throw new Error(`订单不存在: ${orderUuid}`);
|
|
655
672
|
}
|
|
673
|
+
const expectAmount = new import_decimal.Decimal(order.expect_amount);
|
|
674
|
+
if (expectAmount.lte(0) && voucherPaymentItems.length === 0) {
|
|
675
|
+
console.warn("[PaymentModule] Skipping voucher update - order already fully paid:", {
|
|
676
|
+
orderUuid,
|
|
677
|
+
expectAmount: order.expect_amount,
|
|
678
|
+
attemptedOperation: "clear_vouchers",
|
|
679
|
+
reason: "Order payment completed, no need to clear vouchers"
|
|
680
|
+
});
|
|
681
|
+
this.logInfo("updateVoucherPaymentItemsAsync skipped - order already paid", {
|
|
682
|
+
orderUuid,
|
|
683
|
+
expectAmount: order.expect_amount,
|
|
684
|
+
voucherCount: voucherPaymentItems.length
|
|
685
|
+
});
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
if (expectAmount.lte(0) && voucherPaymentItems.length > 0) {
|
|
689
|
+
const warningMessage = `订单 ${orderUuid} 已完成支付,不允许添加代金券支付项`;
|
|
690
|
+
console.warn("[PaymentModule] Voucher update blocked - order already fully paid:", {
|
|
691
|
+
orderUuid,
|
|
692
|
+
expectAmount: order.expect_amount,
|
|
693
|
+
attemptedVoucherCount: voucherPaymentItems.length,
|
|
694
|
+
reason: "Order already fully paid"
|
|
695
|
+
});
|
|
696
|
+
this.logError("updateVoucherPaymentItemsAsync blocked", new Error(warningMessage), {
|
|
697
|
+
orderUuid,
|
|
698
|
+
expectAmount: order.expect_amount,
|
|
699
|
+
voucherPaymentItems
|
|
700
|
+
});
|
|
701
|
+
throw new Error(warningMessage);
|
|
702
|
+
}
|
|
656
703
|
const existingVoucherItems = order.payment.filter(
|
|
657
704
|
(payment) => payment.voucher_id && payment.status !== "voided"
|
|
658
705
|
);
|
|
@@ -792,6 +792,18 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
|
|
|
792
792
|
"当前没有活跃订单,无法更新代金券支付项"
|
|
793
793
|
);
|
|
794
794
|
}
|
|
795
|
+
const remainingAmount = await this.calculateRemainingAmountAsync();
|
|
796
|
+
const remainingValue = new import_decimal.default(remainingAmount);
|
|
797
|
+
if (remainingValue.lte(0)) {
|
|
798
|
+
this.logInfo("订单已完成支付且修改代金券,跳过操作避免重复同步:", {
|
|
799
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
800
|
+
orderId: this.store.currentOrder.order_id,
|
|
801
|
+
remainingAmount,
|
|
802
|
+
voucherPaymentItemsCount: voucherPaymentItems.length,
|
|
803
|
+
reason: "Order payment completed, skip clear vouchers"
|
|
804
|
+
});
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
795
807
|
this.logInfo("开始批量更新代金券支付项:", {
|
|
796
808
|
voucherPaymentItems
|
|
797
809
|
});
|