getKey(); $remark = $request->input('remark', '管理员手动完成'); 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->isFinalStatus()) { $errors[] = "订单 {$orderId} 已处于最终状态"; $failCount++; continue; } // 只允许转出订单手动完成 if (!$order->isTransferOut()) { $errors[] = "订单 {$orderId} 不是转出订单,不允许手动完成"; $failCount++; continue; } $result = TransferLogic::manualComplete($orderId, $remark); 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 form() { $this->textarea('remark', '备注说明') ->default('管理员手动完成') ->required() ->help('请输入手动完成的原因'); } /** * 确认对话框 */ public function confirm() { return [ '确认手动完成选中的订单吗?', '手动完成操作将直接将订单状态设置为已完成,请谨慎操作。', ]; } /** * 设置按钮样式 */ public function html() { return << {$this->title} HTML; } }