49 lines
1.9 KiB
Swift
49 lines
1.9 KiB
Swift
import Foundation
|
|
|
|
/// 线下收款接口抽象,供生产 API 与测试替身共用。
|
|
@MainActor
|
|
protocol OfflineCollectionServing: AnyObject {
|
|
func statistics(scenicId: Int) async throws -> OfflineCollectionStatisticsResponse
|
|
func details(scenicId: Int, date: String) async throws -> OfflineCollectionDetailsResponse
|
|
func register(_ request: OfflineCollectionRegisterRequest) async throws -> OfflineCollectionRegisterResponse
|
|
func supplement(_ request: OfflineSettlementRequest) async throws -> OfflineSettlementResult
|
|
}
|
|
|
|
/// 线下收款真实网络 API。
|
|
@MainActor
|
|
final class OfflineCollectionAPI: OfflineCollectionServing {
|
|
private let client: APIClient
|
|
private let prefix = "/api/yf-handset-app/photog/offline-pay-collect"
|
|
|
|
init(client: APIClient) {
|
|
self.client = client
|
|
}
|
|
|
|
func statistics(scenicId: Int) async throws -> OfflineCollectionStatisticsResponse {
|
|
try await client.send(APIRequest(
|
|
method: .get,
|
|
path: "\(prefix)/statistics",
|
|
queryItems: [URLQueryItem(name: "scenic_id", value: String(scenicId))]
|
|
))
|
|
}
|
|
|
|
func details(scenicId: Int, date: String) async throws -> OfflineCollectionDetailsResponse {
|
|
try await client.send(APIRequest(
|
|
method: .get,
|
|
path: "\(prefix)/details",
|
|
queryItems: [
|
|
URLQueryItem(name: "scenic_id", value: String(scenicId)),
|
|
URLQueryItem(name: "date", value: date),
|
|
]
|
|
))
|
|
}
|
|
|
|
func register(_ request: OfflineCollectionRegisterRequest) async throws -> OfflineCollectionRegisterResponse {
|
|
try await client.send(APIRequest(method: .post, path: "\(prefix)/register", body: request))
|
|
}
|
|
|
|
func supplement(_ request: OfflineSettlementRequest) async throws -> OfflineSettlementResult {
|
|
try await client.send(APIRequest(method: .post, path: "\(prefix)/supplement", body: request))
|
|
}
|
|
}
|