@pisell/pisellos 0.0.270 → 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.
@@ -1264,7 +1264,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1264
1264
  key: "updateVoucherPaymentItemsAsync",
1265
1265
  value: (function () {
1266
1266
  var _updateVoucherPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(orderUuid, voucherPaymentItems) {
1267
- var order, expectAmount, warningMessage, existingVoucherItems, _iterator5, _step5, voucherItem, _iterator6, _step6, _voucherItem, updatedOrder;
1267
+ var order, existingVoucherItems, _iterator5, _step5, voucherItem, _iterator6, _step6, _voucherItem, updatedOrder;
1268
1268
  return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1269
1269
  while (1) switch (_context15.prev = _context15.next) {
1270
1270
  case 0:
@@ -1291,43 +1291,6 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1291
1291
  }
1292
1292
  throw new Error("\u8BA2\u5355\u4E0D\u5B58\u5728: ".concat(orderUuid));
1293
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:
1331
1294
  // 1. 查找所有现有的代金券类支付项(带 voucher_id 且状态不是 voided)
1332
1295
  existingVoucherItems = order.payment.filter(function (payment) {
1333
1296
  return payment.voucher_id && payment.status !== 'voided';
@@ -1347,96 +1310,96 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1347
1310
 
1348
1311
  // 2. 删除所有现有的代金券支付项
1349
1312
  _iterator5 = _createForOfIteratorHelper(existingVoucherItems);
1350
- _context15.prev = 20;
1313
+ _context15.prev = 10;
1351
1314
  _iterator5.s();
1352
- case 22:
1315
+ case 12:
1353
1316
  if ((_step5 = _iterator5.n()).done) {
1354
- _context15.next = 29;
1317
+ _context15.next = 19;
1355
1318
  break;
1356
1319
  }
1357
1320
  voucherItem = _step5.value;
1358
1321
  console.log("[PaymentModule] \u5220\u9664\u73B0\u6709\u4EE3\u91D1\u5238\u652F\u4ED8\u9879: ".concat(voucherItem.uuid));
1359
- _context15.next = 27;
1322
+ _context15.next = 17;
1360
1323
  return this.deletePaymentAsync(orderUuid, voucherItem.uuid);
1361
- case 27:
1362
- _context15.next = 22;
1324
+ case 17:
1325
+ _context15.next = 12;
1363
1326
  break;
1364
- case 29:
1365
- _context15.next = 34;
1327
+ case 19:
1328
+ _context15.next = 24;
1366
1329
  break;
1367
- case 31:
1368
- _context15.prev = 31;
1369
- _context15.t0 = _context15["catch"](20);
1330
+ case 21:
1331
+ _context15.prev = 21;
1332
+ _context15.t0 = _context15["catch"](10);
1370
1333
  _iterator5.e(_context15.t0);
1371
- case 34:
1372
- _context15.prev = 34;
1334
+ case 24:
1335
+ _context15.prev = 24;
1373
1336
  _iterator5.f();
1374
- return _context15.finish(34);
1375
- case 37:
1337
+ return _context15.finish(24);
1338
+ case 27:
1376
1339
  // 3. 添加新的代金券支付项
1377
1340
  console.log('[PaymentModule] 添加新的代金券支付项:', {
1378
1341
  orderUuid: orderUuid,
1379
1342
  newItemCount: voucherPaymentItems.length
1380
1343
  });
1381
1344
  _iterator6 = _createForOfIteratorHelper(voucherPaymentItems);
1382
- _context15.prev = 39;
1345
+ _context15.prev = 29;
1383
1346
  _iterator6.s();
1384
- case 41:
1347
+ case 31:
1385
1348
  if ((_step6 = _iterator6.n()).done) {
1386
- _context15.next = 50;
1349
+ _context15.next = 40;
1387
1350
  break;
1388
1351
  }
1389
1352
  _voucherItem = _step6.value;
1390
1353
  if (_voucherItem.voucher_id) {
1391
- _context15.next = 45;
1354
+ _context15.next = 35;
1392
1355
  break;
1393
1356
  }
1394
1357
  throw new Error("\u4EE3\u91D1\u5238\u652F\u4ED8\u9879\u7F3A\u5C11 voucher_id: ".concat(JSON.stringify(_voucherItem)));
1395
- case 45:
1358
+ case 35:
1396
1359
  console.log("[PaymentModule] \u6DFB\u52A0\u4EE3\u91D1\u5238\u652F\u4ED8\u9879:", {
1397
1360
  code: _voucherItem.code,
1398
1361
  amount: _voucherItem.amount,
1399
1362
  voucher_id: _voucherItem.voucher_id,
1400
1363
  order_payment_type: _voucherItem.order_payment_type
1401
1364
  });
1402
- _context15.next = 48;
1365
+ _context15.next = 38;
1403
1366
  return this.addPaymentItemAsync(orderUuid, _voucherItem);
1404
- case 48:
1405
- _context15.next = 41;
1367
+ case 38:
1368
+ _context15.next = 31;
1406
1369
  break;
1407
- case 50:
1408
- _context15.next = 55;
1370
+ case 40:
1371
+ _context15.next = 45;
1409
1372
  break;
1410
- case 52:
1411
- _context15.prev = 52;
1412
- _context15.t1 = _context15["catch"](39);
1373
+ case 42:
1374
+ _context15.prev = 42;
1375
+ _context15.t1 = _context15["catch"](29);
1413
1376
  _iterator6.e(_context15.t1);
1414
- case 55:
1415
- _context15.prev = 55;
1377
+ case 45:
1378
+ _context15.prev = 45;
1416
1379
  _iterator6.f();
1417
- return _context15.finish(55);
1418
- case 58:
1419
- _context15.next = 60;
1380
+ return _context15.finish(45);
1381
+ case 48:
1382
+ _context15.next = 50;
1420
1383
  return this.getPaymentOrderByUuidAsync(orderUuid);
1421
- case 60:
1384
+ case 50:
1422
1385
  updatedOrder = _context15.sent;
1423
- _context15.next = 63;
1386
+ _context15.next = 53;
1424
1387
  return this.core.effects.emit(PaymentHooks.OnPaymentAdded, {
1425
1388
  orderUuid: orderUuid,
1426
1389
  order: updatedOrder,
1427
1390
  payment: null // 批量操作不提供单个支付项
1428
1391
  });
1429
- case 63:
1392
+ case 53:
1430
1393
  this.logInfo('updateVoucherPaymentItemsAsync completed successfully', {
1431
1394
  orderUuid: orderUuid,
1432
1395
  removedVoucherCount: existingVoucherItems.length,
1433
1396
  addedVoucherCount: voucherPaymentItems.length,
1434
1397
  finalExpectAmount: updatedOrder === null || updatedOrder === void 0 ? void 0 : updatedOrder.expect_amount
1435
1398
  });
1436
- _context15.next = 71;
1399
+ _context15.next = 61;
1437
1400
  break;
1438
- case 66:
1439
- _context15.prev = 66;
1401
+ case 56:
1402
+ _context15.prev = 56;
1440
1403
  _context15.t2 = _context15["catch"](1);
1441
1404
  console.error('[PaymentModule] 批量更新代金券支付项失败:', _context15.t2);
1442
1405
  this.logError('updateVoucherPaymentItemsAsync failed', _context15.t2, {
@@ -1444,11 +1407,11 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1444
1407
  voucherPaymentItems: voucherPaymentItems
1445
1408
  });
1446
1409
  throw _context15.t2;
1447
- case 71:
1410
+ case 61:
1448
1411
  case "end":
1449
1412
  return _context15.stop();
1450
1413
  }
1451
- }, _callee15, this, [[1, 66], [20, 31, 34, 37], [39, 52, 55, 58]]);
1414
+ }, _callee15, this, [[1, 56], [10, 21, 24, 27], [29, 42, 45, 48]]);
1452
1415
  }));
1453
1416
  function updateVoucherPaymentItemsAsync(_x18, _x19) {
1454
1417
  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, 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 = 8;
1339
+ _context17.next = 16;
1320
1340
  return this.payment.updateVoucherPaymentItemsAsync(this.store.currentOrder.uuid, voucherPaymentItemsWithType);
1321
- case 8:
1341
+ case 16:
1322
1342
  // 重新从Payment模块获取最新的订单数据,确保支付项同步
1323
1343
  currentOrderId = this.store.currentOrder.order_id; // 保存当前的订单ID
1324
1344
  isCurrentOrderReal = currentOrderId && !isVirtualOrderId(currentOrderId);
1325
- _context17.next = 12;
1345
+ _context17.next = 20;
1326
1346
  return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
1327
- case 12:
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 = 16;
1362
+ _context17.next = 24;
1343
1363
  return this.updateStateAmountToRemaining();
1344
- case 16:
1345
- _context17.next = 18;
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 18:
1374
+ case 26:
1355
1375
  this.logInfo('代金券支付项批量更新成功');
1356
- _context17.next = 27;
1376
+ _context17.next = 35;
1357
1377
  break;
1358
- case 21:
1359
- _context17.prev = 21;
1378
+ case 29:
1379
+ _context17.prev = 29;
1360
1380
  _context17.t0 = _context17["catch"](0);
1361
1381
  this.logError('[Checkout] 批量更新代金券支付项失败:', _context17.t0);
1362
- _context17.next = 26;
1382
+ _context17.next = 34;
1363
1383
  return this.handleError(_context17.t0, CheckoutErrorType.PaymentFailed);
1364
- case 26:
1384
+ case 34:
1365
1385
  throw _context17.t0;
1366
- case 27:
1386
+ case 35:
1367
1387
  case "end":
1368
1388
  return _context17.stop();
1369
1389
  }
1370
- }, _callee17, this, [[0, 21]]);
1390
+ }, _callee17, this, [[0, 29]]);
1371
1391
  }));
1372
1392
  function updateVoucherPaymentItemsAsync(_x16) {
1373
1393
  return _updateVoucherPaymentItemsAsync.apply(this, arguments);
@@ -670,36 +670,6 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
670
670
  if (!order) {
671
671
  throw new Error(`订单不存在: ${orderUuid}`);
672
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
- }
703
673
  const existingVoucherItems = order.payment.filter(
704
674
  (payment) => payment.voucher_id && payment.status !== "voided"
705
675
  );
@@ -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
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.270",
4
+ "version": "0.0.271",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",