@pisell/pisellos 0.0.269 → 0.0.271
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/Payment/index.js +31 -10
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/solution/Checkout/index.js +36 -16
- package/lib/modules/Payment/index.js +17 -0
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/solution/Checkout/index.js +14 -0
- package/package.json +1 -1
|
@@ -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);
|
|
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
|
|
|
49
49
|
getCategories(): ProductCategory[];
|
|
50
50
|
setOtherParams(key: string, value: any): void;
|
|
51
51
|
getOtherParams(): any;
|
|
52
|
-
getProductType(): "
|
|
52
|
+
getProductType(): "duration" | "session" | "normal";
|
|
53
53
|
}
|
|
@@ -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, isOrderSynced, 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,26 @@ 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
|
+
isOrderSynced = this.store.isOrderSynced;
|
|
1304
|
+
if (!(remainingValue.lte(0) && isOrderSynced && voucherPaymentItems.length === 0)) {
|
|
1305
|
+
_context17.next = 11;
|
|
1306
|
+
break;
|
|
1307
|
+
}
|
|
1308
|
+
this.logInfo('订单已同步且支付完成,跳过清空代金券操作避免重复同步:', {
|
|
1309
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
1310
|
+
orderId: this.store.currentOrder.order_id,
|
|
1311
|
+
remainingAmount: remainingAmount,
|
|
1312
|
+
isOrderSynced: isOrderSynced,
|
|
1313
|
+
voucherPaymentItemsCount: voucherPaymentItems.length,
|
|
1314
|
+
reason: 'Order synced and payment completed, skip clear vouchers to avoid duplicate sync'
|
|
1315
|
+
});
|
|
1316
|
+
return _context17.abrupt("return");
|
|
1317
|
+
case 11:
|
|
1298
1318
|
this.logInfo('开始批量更新代金券支付项:', {
|
|
1299
1319
|
voucherPaymentItems: voucherPaymentItems
|
|
1300
1320
|
});
|
|
@@ -1316,15 +1336,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1316
1336
|
metadata: metadata
|
|
1317
1337
|
});
|
|
1318
1338
|
}); // 调用 Payment 模块的批量更新方法
|
|
1319
|
-
_context17.next =
|
|
1339
|
+
_context17.next = 16;
|
|
1320
1340
|
return this.payment.updateVoucherPaymentItemsAsync(this.store.currentOrder.uuid, voucherPaymentItemsWithType);
|
|
1321
|
-
case
|
|
1341
|
+
case 16:
|
|
1322
1342
|
// 重新从Payment模块获取最新的订单数据,确保支付项同步
|
|
1323
1343
|
currentOrderId = this.store.currentOrder.order_id; // 保存当前的订单ID
|
|
1324
1344
|
isCurrentOrderReal = currentOrderId && !isVirtualOrderId(currentOrderId);
|
|
1325
|
-
_context17.next =
|
|
1345
|
+
_context17.next = 20;
|
|
1326
1346
|
return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
|
|
1327
|
-
case
|
|
1347
|
+
case 20:
|
|
1328
1348
|
updatedOrder = _context17.sent;
|
|
1329
1349
|
if (updatedOrder) {
|
|
1330
1350
|
// 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
|
|
@@ -1339,10 +1359,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1339
1359
|
}
|
|
1340
1360
|
|
|
1341
1361
|
// 更新 stateAmount 为剩余未支付金额
|
|
1342
|
-
_context17.next =
|
|
1362
|
+
_context17.next = 24;
|
|
1343
1363
|
return this.updateStateAmountToRemaining();
|
|
1344
|
-
case
|
|
1345
|
-
_context17.next =
|
|
1364
|
+
case 24:
|
|
1365
|
+
_context17.next = 26;
|
|
1346
1366
|
return this.core.effects.emit(CheckoutHooks.OnPaymentStarted, {
|
|
1347
1367
|
orderUuid: this.store.currentOrder.uuid,
|
|
1348
1368
|
paymentMethodCode: 'VOUCHER_BATCH',
|
|
@@ -1351,23 +1371,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1351
1371
|
}, 0).toFixed(2),
|
|
1352
1372
|
timestamp: Date.now()
|
|
1353
1373
|
});
|
|
1354
|
-
case
|
|
1374
|
+
case 26:
|
|
1355
1375
|
this.logInfo('代金券支付项批量更新成功');
|
|
1356
|
-
_context17.next =
|
|
1376
|
+
_context17.next = 35;
|
|
1357
1377
|
break;
|
|
1358
|
-
case
|
|
1359
|
-
_context17.prev =
|
|
1378
|
+
case 29:
|
|
1379
|
+
_context17.prev = 29;
|
|
1360
1380
|
_context17.t0 = _context17["catch"](0);
|
|
1361
1381
|
this.logError('[Checkout] 批量更新代金券支付项失败:', _context17.t0);
|
|
1362
|
-
_context17.next =
|
|
1382
|
+
_context17.next = 34;
|
|
1363
1383
|
return this.handleError(_context17.t0, CheckoutErrorType.PaymentFailed);
|
|
1364
|
-
case
|
|
1384
|
+
case 34:
|
|
1365
1385
|
throw _context17.t0;
|
|
1366
|
-
case
|
|
1386
|
+
case 35:
|
|
1367
1387
|
case "end":
|
|
1368
1388
|
return _context17.stop();
|
|
1369
1389
|
}
|
|
1370
|
-
}, _callee17, this, [[0,
|
|
1390
|
+
}, _callee17, this, [[0, 29]]);
|
|
1371
1391
|
}));
|
|
1372
1392
|
function updateVoucherPaymentItemsAsync(_x16) {
|
|
1373
1393
|
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,
|
|
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
|
|
|
49
49
|
getCategories(): ProductCategory[];
|
|
50
50
|
setOtherParams(key: string, value: any): void;
|
|
51
51
|
getOtherParams(): any;
|
|
52
|
-
getProductType(): "
|
|
52
|
+
getProductType(): "duration" | "session" | "normal";
|
|
53
53
|
}
|
|
@@ -792,6 +792,20 @@ 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
|
+
const isOrderSynced = this.store.isOrderSynced;
|
|
798
|
+
if (remainingValue.lte(0) && isOrderSynced && voucherPaymentItems.length === 0) {
|
|
799
|
+
this.logInfo("订单已同步且支付完成,跳过清空代金券操作避免重复同步:", {
|
|
800
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
801
|
+
orderId: this.store.currentOrder.order_id,
|
|
802
|
+
remainingAmount,
|
|
803
|
+
isOrderSynced,
|
|
804
|
+
voucherPaymentItemsCount: voucherPaymentItems.length,
|
|
805
|
+
reason: "Order synced and payment completed, skip clear vouchers to avoid duplicate sync"
|
|
806
|
+
});
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
795
809
|
this.logInfo("开始批量更新代金券支付项:", {
|
|
796
810
|
voucherPaymentItems
|
|
797
811
|
});
|