getMessage(); } } /** * 创建转入订单 * * @param array $data 订单数据 * @return TransferOrderDto|string 成功返回DTO,失败返回错误信息 */ public static function createTransferIn(array $data): TransferOrderDto|string { try { $order = TransferLogic::createTransferIn($data); return TransferOrderDto::fromModel($order); } catch (\Exception $e) { return $e->getMessage(); } } /** * 查询订单信息 * * @param int $orderId 订单ID * @param int|null $userId 用户ID(可选,用于权限验证) * @return TransferOrderDto|null */ public static function getOrderInfo(int $orderId, ?int $userId = null): ?TransferOrderDto { $query = TransferOrder::where('id', $orderId); if ($userId !== null) { $query->where('user_id', $userId); } $order = $query->first(); return $order ? TransferOrderDto::fromModel($order) : null; } /** * 根据外部订单ID查询订单信息 * * @param string $outOrderId 外部订单ID * @param int $outId 开放接口ID * @return TransferOrderDto|null */ public static function getOrderByOutId(string $outOrderId, int $outId): ?TransferOrderDto { $order = TransferOrder::where('out_order_id', $outOrderId) ->where('out_id', $outId) ->first(); return $order ? TransferOrderDto::fromModel($order) : null; } /** * 获取用户可用的划转应用列表 * * @param int $userId 用户ID * @return TransferAppDto[] */ public static function getAvailableApps(int $userId): array { $apps = TransferApp::where('is_enabled', true)->get(); return $apps->map(function ($app) { return TransferAppDto::fromModel($app); })->toArray(); } /** * 获取用户订单列表 * * @param int $userId 用户ID * @param array $filters 筛选条件 * @return array */ public static function getUserOrders(int $userId, array $filters = []): array { $query = TransferOrder::where('user_id', $userId); // 应用筛选条件 if (isset($filters['type'])) { $query->where('type', $filters['type']); } if (isset($filters['status'])) { $query->where('status', $filters['status']); } if (isset($filters['transfer_app_id'])) { $query->where('transfer_app_id', $filters['transfer_app_id']); } if (isset($filters['start_date'])) { $query->where('created_at', '>=', $filters['start_date']); } if (isset($filters['end_date'])) { $query->where('created_at', '<=', $filters['end_date']); } // 分页参数 $page = $filters['page'] ?? 1; $perPage = $filters['per_page'] ?? 20; $orders = $query->orderBy('created_at', 'desc') ->paginate($perPage, ['*'], 'page', $page); return [ 'data' => $orders->items(), 'current_page' => $orders->currentPage(), 'per_page' => $orders->perPage(), 'total' => $orders->total(), 'last_page' => $orders->lastPage(), ]; } /** * 获取应用配置信息 * * @param int $appId 应用ID * @return TransferAppDto|null */ public static function getAppConfig(int $appId): ?TransferAppDto { $app = TransferApp::find($appId); return $app ? TransferAppDto::fromModel($app) : null; } /** * 根据应用标识获取配置信息 * * @param string $keyname 应用标识 * @return TransferAppDto|null */ public static function getAppByKeyname(string $keyname): ?TransferAppDto { $app = TransferApp::where('keyname', $keyname) ->where('is_enabled', true) ->first(); return $app ? TransferAppDto::fromModel($app) : null; } /** * 处理回调结果 * * @param array $callbackData 回调数据 * @return bool */ public static function processCallback(array $callbackData): bool { try { return TransferLogic::processCallback($callbackData); } catch (\Exception $e) { \Log::error('Transfer callback processing failed', [ 'error' => $e->getMessage(), 'data' => $callbackData ]); return false; } } }