getKey(); if (empty($orderIds)) { return $this->response()->error('请选择要重试的订单'); } $successCount = 0; $failCount = 0; $errors = []; foreach ($orderIds as $orderId) { try { $order = TransferOrder::find($orderId); if (!$order) { $errors[] = "订单 {$orderId} 不存在"; $failCount++; continue; } if (!$order->canRetry()) { $errors[] = "订单 {$orderId} 状态不允许重试"; $failCount++; continue; } $result = TransferLogic::retryOrder($orderId); if ($result) { $successCount++; } else { $errors[] = "订单 {$orderId} 重试失败"; $failCount++; } } catch (\Exception $e) { $errors[] = "订单 {$orderId} 重试异常: " . $e->getMessage(); $failCount++; } } // 构建响应消息 $message = "重试完成:成功 {$successCount} 个,失败 {$failCount} 个"; if (!empty($errors)) { $message .= "\n错误详情:\n" . implode("\n", array_slice($errors, 0, 5)); if (count($errors) > 5) { $message .= "\n...还有 " . (count($errors) - 5) . " 个错误"; } } if ($failCount > 0) { return $this->response()->warning($message); } else { return $this->response()->success($message); } } /** * 确认对话框 */ public function confirm() { return [ '确认重试选中的订单吗?', '重试操作将重新处理失败的订单,请确认操作。', ]; } /** * 设置按钮样式 */ public function html() { return << {$this->title} HTML; } }