@pisell/pisellos 2.1.16 → 2.1.18

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.
@@ -267,6 +267,10 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
267
267
  if (!resource.times || !Array.isArray(resource.times) || !resource.start_time) {
268
268
  return resource;
269
269
  }
270
+ // 如果resource.advanced 为 null 或者 resource.advanced.unit 为 0,则不进行修正
271
+ if (!resource.advanced || resource.advanced.unit === 0) {
272
+ return resource;
273
+ }
270
274
  var resourceStartTime = dayjs(resource.start_time);
271
275
 
272
276
  // 过滤和修正时间段
@@ -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 = 13;
1110
+ _context13.next = 19;
1090
1111
  return this.dbManager.update('order', order);
1091
- case 13:
1092
- _context13.next = 15;
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 15:
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 = 23;
1132
+ _context13.next = 29;
1112
1133
  break;
1113
- case 18:
1114
- _context13.prev = 18;
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 23:
1143
+ case 29:
1123
1144
  case "end":
1124
1145
  return _context13.stop();
1125
1146
  }
1126
- }, _callee13, this, [[1, 18]]);
1147
+ }, _callee13, this, [[1, 24]]);
1127
1148
  }));
1128
1149
  function addPaymentItemAsync(_x14, _x15) {
1129
1150
  return _addPaymentItemAsync.apply(this, arguments);
@@ -1049,7 +1049,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1049
1049
  key: "addPaymentItemAsync",
1050
1050
  value: (function () {
1051
1051
  var _addPaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(paymentItem) {
1052
- var orderPaymentType, processedPaymentItem, metadata, paymentItemWithType, remainingAmount, _paymentItem$type, _paymentItem$code, isEftposPayment, syncResult;
1052
+ var orderPaymentType, processedPaymentItem, metadata, paymentItemWithType, remainingAmount, _paymentItem$type, _paymentItem$code, isEftposPayment, _isCashPayment, isCustomePayment, syncResult;
1053
1053
  return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1054
1054
  while (1) switch (_context15.prev = _context15.next) {
1055
1055
  case 0:
@@ -1090,44 +1090,46 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1090
1090
  case 17:
1091
1091
  remainingAmount = _context15.sent;
1092
1092
  if (!(Number(remainingAmount) > 0)) {
1093
- _context15.next = 36;
1093
+ _context15.next = 38;
1094
1094
  break;
1095
1095
  }
1096
1096
  this.logInfo('订单金额还有待付的,同步 EFTPOS 支付');
1097
1097
  // 检查是否是 EFTPOS 支付,如果是则立即同步订单
1098
1098
  isEftposPayment = ((_paymentItem$type = paymentItem.type) === null || _paymentItem$type === void 0 ? void 0 : _paymentItem$type.toLowerCase()) === 'eftpos' || ((_paymentItem$code = paymentItem.code) === null || _paymentItem$code === void 0 ? void 0 : _paymentItem$code.toUpperCase().includes('EFTPOS'));
1099
+ _isCashPayment = paymentItem.code === 'CASHMANUAL';
1100
+ isCustomePayment = paymentItem.type === 'custom';
1099
1101
  this.logInfo('EFTPOS 支付检查:', {
1100
1102
  paymentCode: paymentItem.code,
1101
1103
  paymentType: paymentItem.type,
1102
1104
  isEftposPayment: isEftposPayment,
1103
1105
  currentOrderSynced: this.store.isOrderSynced
1104
1106
  });
1105
- if (!isEftposPayment) {
1106
- _context15.next = 36;
1107
+ if (!(isEftposPayment || _isCashPayment || isCustomePayment)) {
1108
+ _context15.next = 38;
1107
1109
  break;
1108
1110
  }
1109
1111
  this.logInfo('检测到 EFTPOS 支付,立即同步订单到后端...');
1110
- _context15.prev = 24;
1111
- _context15.next = 27;
1112
+ _context15.prev = 26;
1113
+ _context15.next = 29;
1112
1114
  return this.syncOrderToBackendWithReturn(true);
1113
- case 27:
1115
+ case 29:
1114
1116
  syncResult = _context15.sent;
1115
1117
  this.logInfo('EFTPOS 支付后订单同步完成 (已标记为手动同步):', {
1116
1118
  orderId: syncResult.orderId,
1117
1119
  isOrderSynced: this.store.isOrderSynced,
1118
1120
  backendResponse: syncResult.response
1119
1121
  });
1120
- _context15.next = 36;
1122
+ _context15.next = 38;
1121
1123
  break;
1122
- case 31:
1123
- _context15.prev = 31;
1124
- _context15.t0 = _context15["catch"](24);
1124
+ case 33:
1125
+ _context15.prev = 33;
1126
+ _context15.t0 = _context15["catch"](26);
1125
1127
  this.logError('EFTPOS 支付后订单同步失败:', _context15.t0);
1126
1128
  // 不抛出错误,避免影响支付流程,但记录错误
1127
- _context15.next = 36;
1128
- return this.handleError(new Error("EFTPOS \u652F\u4ED8\u540E\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(_context15.t0 instanceof Error ? _context15.t0.message : String(_context15.t0))), CheckoutErrorType.OrderCreationFailed);
1129
- case 36:
1130
1129
  _context15.next = 38;
1130
+ return this.handleError(new Error("EFTPOS \u652F\u4ED8\u540E\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(_context15.t0 instanceof Error ? _context15.t0.message : String(_context15.t0))), CheckoutErrorType.OrderCreationFailed);
1131
+ case 38:
1132
+ _context15.next = 40;
1131
1133
  return this.core.effects.emit(CheckoutHooks.OnPaymentItemAdded, {
1132
1134
  orderUuid: this.store.currentOrder.uuid,
1133
1135
  paymentMethodCode: paymentItem.code,
@@ -1135,22 +1137,22 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1135
1137
  amount: String(paymentItem.amount),
1136
1138
  timestamp: Date.now()
1137
1139
  });
1138
- case 38:
1139
- _context15.next = 46;
1140
- break;
1141
1140
  case 40:
1142
- _context15.prev = 40;
1141
+ _context15.next = 48;
1142
+ break;
1143
+ case 42:
1144
+ _context15.prev = 42;
1143
1145
  _context15.t1 = _context15["catch"](1);
1144
1146
  this.logError('添加支付项失败:', _context15.t1);
1145
- _context15.next = 45;
1147
+ _context15.next = 47;
1146
1148
  return this.handleError(_context15.t1, CheckoutErrorType.PaymentFailed);
1147
- case 45:
1149
+ case 47:
1148
1150
  throw _context15.t1;
1149
- case 46:
1151
+ case 48:
1150
1152
  case "end":
1151
1153
  return _context15.stop();
1152
1154
  }
1153
- }, _callee15, this, [[1, 40], [24, 31]]);
1155
+ }, _callee15, this, [[1, 42], [26, 33]]);
1154
1156
  }));
1155
1157
  function addPaymentItemAsync(_x14) {
1156
1158
  return _addPaymentItemAsync.apply(this, arguments);
@@ -1284,7 +1286,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1284
1286
  value: (function () {
1285
1287
  var _updateVoucherPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(voucherPaymentItems) {
1286
1288
  var _this3 = this;
1287
- var orderPaymentType, voucherPaymentItemsWithType, currentOrderId, isCurrentOrderReal, updatedOrder;
1289
+ var remainingAmount, remainingValue, isOrderSynced, orderPaymentType, voucherPaymentItemsWithType, currentOrderId, isCurrentOrderReal, updatedOrder;
1288
1290
  return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1289
1291
  while (1) switch (_context17.prev = _context17.next) {
1290
1292
  case 0:
@@ -1295,6 +1297,26 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1295
1297
  }
1296
1298
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '当前没有活跃订单,无法更新代金券支付项');
1297
1299
  case 3:
1300
+ _context17.next = 5;
1301
+ return this.calculateRemainingAmountAsync();
1302
+ case 5:
1303
+ remainingAmount = _context17.sent;
1304
+ remainingValue = new Decimal(remainingAmount);
1305
+ isOrderSynced = this.store.isOrderSynced;
1306
+ if (!(remainingValue.lte(0) && isOrderSynced && voucherPaymentItems.length === 0)) {
1307
+ _context17.next = 11;
1308
+ break;
1309
+ }
1310
+ this.logInfo('订单已同步且支付完成,跳过清空代金券操作避免重复同步:', {
1311
+ orderUuid: this.store.currentOrder.uuid,
1312
+ orderId: this.store.currentOrder.order_id,
1313
+ remainingAmount: remainingAmount,
1314
+ isOrderSynced: isOrderSynced,
1315
+ voucherPaymentItemsCount: voucherPaymentItems.length,
1316
+ reason: 'Order synced and payment completed, skip clear vouchers to avoid duplicate sync'
1317
+ });
1318
+ return _context17.abrupt("return");
1319
+ case 11:
1298
1320
  this.logInfo('开始批量更新代金券支付项:', {
1299
1321
  voucherPaymentItems: voucherPaymentItems
1300
1322
  });
@@ -1316,15 +1338,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1316
1338
  metadata: metadata
1317
1339
  });
1318
1340
  }); // 调用 Payment 模块的批量更新方法
1319
- _context17.next = 8;
1341
+ _context17.next = 16;
1320
1342
  return this.payment.updateVoucherPaymentItemsAsync(this.store.currentOrder.uuid, voucherPaymentItemsWithType);
1321
- case 8:
1343
+ case 16:
1322
1344
  // 重新从Payment模块获取最新的订单数据,确保支付项同步
1323
1345
  currentOrderId = this.store.currentOrder.order_id; // 保存当前的订单ID
1324
1346
  isCurrentOrderReal = currentOrderId && !isVirtualOrderId(currentOrderId);
1325
- _context17.next = 12;
1347
+ _context17.next = 20;
1326
1348
  return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
1327
- case 12:
1349
+ case 20:
1328
1350
  updatedOrder = _context17.sent;
1329
1351
  if (updatedOrder) {
1330
1352
  // 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
@@ -1339,10 +1361,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1339
1361
  }
1340
1362
 
1341
1363
  // 更新 stateAmount 为剩余未支付金额
1342
- _context17.next = 16;
1364
+ _context17.next = 24;
1343
1365
  return this.updateStateAmountToRemaining();
1344
- case 16:
1345
- _context17.next = 18;
1366
+ case 24:
1367
+ _context17.next = 26;
1346
1368
  return this.core.effects.emit(CheckoutHooks.OnPaymentStarted, {
1347
1369
  orderUuid: this.store.currentOrder.uuid,
1348
1370
  paymentMethodCode: 'VOUCHER_BATCH',
@@ -1351,23 +1373,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1351
1373
  }, 0).toFixed(2),
1352
1374
  timestamp: Date.now()
1353
1375
  });
1354
- case 18:
1376
+ case 26:
1355
1377
  this.logInfo('代金券支付项批量更新成功');
1356
- _context17.next = 27;
1378
+ _context17.next = 35;
1357
1379
  break;
1358
- case 21:
1359
- _context17.prev = 21;
1380
+ case 29:
1381
+ _context17.prev = 29;
1360
1382
  _context17.t0 = _context17["catch"](0);
1361
1383
  this.logError('[Checkout] 批量更新代金券支付项失败:', _context17.t0);
1362
- _context17.next = 26;
1384
+ _context17.next = 34;
1363
1385
  return this.handleError(_context17.t0, CheckoutErrorType.PaymentFailed);
1364
- case 26:
1386
+ case 34:
1365
1387
  throw _context17.t0;
1366
- case 27:
1388
+ case 35:
1367
1389
  case "end":
1368
1390
  return _context17.stop();
1369
1391
  }
1370
- }, _callee17, this, [[0, 21]]);
1392
+ }, _callee17, this, [[0, 29]]);
1371
1393
  }));
1372
1394
  function updateVoucherPaymentItemsAsync(_x16) {
1373
1395
  return _updateVoucherPaymentItemsAsync.apply(this, arguments);
@@ -178,6 +178,9 @@ var DateModule = class extends import_BaseModule.BaseModule {
178
178
  if (!resource.times || !Array.isArray(resource.times) || !resource.start_time) {
179
179
  return resource;
180
180
  }
181
+ if (!resource.advanced || resource.advanced.unit === 0) {
182
+ return resource;
183
+ }
181
184
  const resourceStartTime = (0, import_dayjs.default)(resource.start_time);
182
185
  const correctedTimes = resource.times.map((timeSlot) => {
183
186
  if (!timeSlot.start_at || !timeSlot.end_at) {
@@ -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,
@@ -659,13 +659,15 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
659
659
  if (Number(remainingAmount) > 0) {
660
660
  this.logInfo("订单金额还有待付的,同步 EFTPOS 支付");
661
661
  const isEftposPayment = ((_a = paymentItem.type) == null ? void 0 : _a.toLowerCase()) === "eftpos" || ((_b = paymentItem.code) == null ? void 0 : _b.toUpperCase().includes("EFTPOS"));
662
+ const isCashPayment2 = paymentItem.code === "CASHMANUAL";
663
+ const isCustomePayment = paymentItem.type === "custom";
662
664
  this.logInfo("EFTPOS 支付检查:", {
663
665
  paymentCode: paymentItem.code,
664
666
  paymentType: paymentItem.type,
665
667
  isEftposPayment,
666
668
  currentOrderSynced: this.store.isOrderSynced
667
669
  });
668
- if (isEftposPayment) {
670
+ if (isEftposPayment || isCashPayment2 || isCustomePayment) {
669
671
  this.logInfo("检测到 EFTPOS 支付,立即同步订单到后端...");
670
672
  try {
671
673
  const syncResult = await this.syncOrderToBackendWithReturn(true);
@@ -792,6 +794,20 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
792
794
  "当前没有活跃订单,无法更新代金券支付项"
793
795
  );
794
796
  }
797
+ const remainingAmount = await this.calculateRemainingAmountAsync();
798
+ const remainingValue = new import_decimal.default(remainingAmount);
799
+ const isOrderSynced = this.store.isOrderSynced;
800
+ if (remainingValue.lte(0) && isOrderSynced && voucherPaymentItems.length === 0) {
801
+ this.logInfo("订单已同步且支付完成,跳过清空代金券操作避免重复同步:", {
802
+ orderUuid: this.store.currentOrder.uuid,
803
+ orderId: this.store.currentOrder.order_id,
804
+ remainingAmount,
805
+ isOrderSynced,
806
+ voucherPaymentItemsCount: voucherPaymentItems.length,
807
+ reason: "Order synced and payment completed, skip clear vouchers to avoid duplicate sync"
808
+ });
809
+ return;
810
+ }
795
811
  this.logInfo("开始批量更新代金券支付项:", {
796
812
  voucherPaymentItems
797
813
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.1.16",
4
+ "version": "2.1.18",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",