validatePermissions($context['app']->scopes ?? [], $context)) { return $this->errorResponse('权限不足', null, 403); } // 获取查询参数 $businessId = $data['business_id'] ?? null; $orderId = $data['order_id'] ?? null; $appId = $context['app']->id ?? null; if (!$businessId && !$orderId) { return $this->errorResponse('缺少查询参数', [ 'message' => '必须提供 business_id 或 order_id 其中之一' ], 400); } if (!$appId) { return $this->errorResponse('应用ID缺失', null, 400); } // 根据不同参数查询订单 $order = null; if ($businessId) { // 根据业务ID查询 $order = TransferService::getOrderByOutId($businessId, $appId); } elseif ($orderId) { // 根据订单ID查询 $orderDto = TransferService::getOrderInfo($orderId); // 验证订单是否属于当前应用 if ($orderDto && $orderDto->out_id == $appId) { $order = $orderDto; } } if (!$order) { return $this->errorResponse('订单不存在', null, 404); } // 记录操作日志 $this->logAction('transfer.query', [ 'order_id' => $order->id, 'business_id' => $order->out_order_id, 'query_type' => $businessId ? 'business_id' : 'order_id' ], $context); // 返回订单信息 return $this->successResponse('查询成功', [ 'order_id' => $order->id, 'business_id' => $order->out_order_id, 'type' => $order->type->value, 'type_text' => $order->type->getDescription(), 'status' => $order->status->value, 'status_text' => $order->status->getDescription(), 'amount' => $order->amount, 'out_amount' => $order->out_amount, 'exchange_rate' => $order->exchange_rate, 'user_id' => $order->user_id, 'out_user_id' => $order->out_user_id, 'remark' => $order->remark, 'callback_data' => $order->callback_data, 'error_message' => $order->error_message, 'created_at' => $order->created_at->toISOString(), 'processed_at' => $order->processed_at?->toISOString(), 'completed_at' => $order->completed_at?->toISOString(), ]); } catch (\Exception $e) { // 记录错误日志 $this->logError('transfer.query.error', $e, $context); return $this->errorResponse('查询失败', [ 'error' => $e->getMessage() ], 500); } } /** * 获取Handler描述 * * @return string */ public function getDescription(): string { return '查询划转订单状态和详细信息'; } /** * 获取请求参数说明 * * @return array */ public function getRequestParameters(): array { return [ 'business_id' => [ 'type' => 'string', 'required' => false, 'description' => '外部业务订单ID(与order_id二选一)' ], 'order_id' => [ 'type' => 'integer', 'required' => false, 'description' => '内部订单ID(与business_id二选一)' ] ]; } /** * 获取响应参数说明 * * @return array */ public function getResponseParameters(): array { return [ 'order_id' => [ 'type' => 'integer', 'description' => '内部订单ID' ], 'business_id' => [ 'type' => 'string', 'description' => '外部业务订单ID' ], 'type' => [ 'type' => 'integer', 'description' => '订单类型(1=转入,2=转出)' ], 'type_text' => [ 'type' => 'string', 'description' => '订单类型描述' ], 'status' => [ 'type' => 'integer', 'description' => '订单状态值' ], 'status_text' => [ 'type' => 'string', 'description' => '订单状态描述' ], 'amount' => [ 'type' => 'string', 'description' => '内部金额' ], 'out_amount' => [ 'type' => 'string', 'description' => '外部金额' ], 'exchange_rate' => [ 'type' => 'string', 'description' => '汇率' ], 'user_id' => [ 'type' => 'integer', 'description' => '用户ID' ], 'out_user_id' => [ 'type' => 'string', 'description' => '外部用户ID' ], 'remark' => [ 'type' => 'string', 'description' => '备注信息' ], 'callback_data' => [ 'type' => 'object', 'description' => '回调数据' ], 'error_message' => [ 'type' => 'string', 'description' => '错误信息(如有)' ], 'created_at' => [ 'type' => 'string', 'description' => '创建时间' ], 'processed_at' => [ 'type' => 'string', 'description' => '处理时间' ], 'completed_at' => [ 'type' => 'string', 'description' => '完成时间' ] ]; } }