fix(drone-dock): 适配小程序收款码图片展示与重试

This commit is contained in:
2026-10-27 17:24:53 +08:00
parent 570b951280
commit 2db4ad8e69
9 changed files with 526 additions and 74 deletions
@@ -1,16 +1,16 @@
import Foundation
/// 张工的机巢套餐收款数据源;付款链接与收款记录不提供单笔支付状态查询。
/// 张工的机巢套餐收款数据源;小程序收款码与收款记录不提供单笔支付状态查询。
protocol DroneDockPaymentServing: Sendable {
/// 获取当前景区可售套餐,无分页。
@MainActor func projects(scenicID: Int) async throws -> [DroneDockProject]
/// 获取指定套餐的付款链接;省略 price 时使用后端当前售价。
/// 获取指定套餐的小程序收款码;省略 price 时使用后端当前售价。
@MainActor func payCode(scenicID: Int, projectID: Int, price: String?) async throws -> DroneDockPayCode
/// 获取本人当前景区的收款记录,默认日期与每页数量由后端决定。
@MainActor func receipts(scenicID: Int, projectID: Int?, page: Int) async throws -> DroneDockReceiptsResponse
}
/// 机巢套餐、付款链接及真实收款记录接口,复用统一登录凭证和业务错误处理。
/// 机巢套餐、小程序收款码及真实收款记录接口,复用统一登录凭证和业务错误处理。
@MainActor
final class DroneDockPaymentAPI: DroneDockPaymentServing {
private let client: APIClient
@@ -32,7 +32,7 @@ final class DroneDockPaymentAPI: DroneDockPaymentServing {
return projects
}
/// 由后端生成完整付款链接;客户端不自行拼接金额、备注或身份参数。
/// 由后端生成完整小程序收款码;客户端不自行拼接金额、备注或身份参数。
func payCode(scenicID: Int, projectID: Int, price: String? = nil) async throws -> DroneDockPayCode {
try validateScenic(scenicID)
guard projectID > 0 else { throw APIError.networkFailed("请选择航拍套餐") }
@@ -30,7 +30,7 @@ struct DroneDockProject: Decodable, Hashable, Sendable {
}
}
/// 后端生成的可重复购买付款链接;不代表单笔交易或到账结果。
/// 后端生成的小程序收款码及报价;同一码可重复购买,不代表单笔交易或到账结果。
struct DroneDockPayCode: Decodable, Equatable, Sendable {
/// 报价所属套餐 ID。
let projectID: Int
@@ -44,17 +44,17 @@ struct DroneDockPayCode: Decodable, Equatable, Sendable {
let storeUserID: Int
/// 收款归属的店铺 ID。
let storeID: Int
/// 用于绘制普通二维码的 HTTP(S) 付款链接。
/// 后端小程序码的 HTTP(S) 图片地址,直接加载原图,不再编码成普通二维码。
let payURL: String
/// 付款链接接口字段。
/// 小程序收款码接口字段;pay_url 沿用字段名,内容为图片地址。
private enum CodingKeys: String, CodingKey {
case price
case projectID = "project_id", projectName = "project_name", shootCount = "shoot_count"
case storeUserID = "store_user_id", storeID = "store_id", payURL = "pay_url"
}
/// 验证身份、报价和链接格式;不接受缺失或不可扫码的付款地址。
/// 验证身份、报价和图片地址格式;图片内容与加载结果由视图处理。
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
projectID = try container.paymentInteger(.projectID, minimum: 1)
@@ -72,7 +72,7 @@ struct DroneDockPayCode: Decodable, Equatable, Sendable {
let scheme = components.scheme?.lowercased(), ["https", "http"].contains(scheme),
let host = components.host, !host.isEmpty, components.url != nil,
components.user == nil, components.password == nil else {
throw DecodingError.dataCorruptedError(forKey: .payURL, in: container, debugDescription: "付款链接必须是有效 HTTP(S) 地址")
throw DecodingError.dataCorruptedError(forKey: .payURL, in: container, debugDescription: "收款码图片必须是有效 HTTP(S) 地址")
}
}
}
@@ -6,11 +6,11 @@ final class DroneDockPaymentViewModel {
private(set) var context: DroneDockHomeContext
/// 服务端当前可售套餐。
private(set) var projects: [DroneDockProject] = []
/// 当前已确认报价的付款链接;改价、换套餐或失败时立即清除。
/// 当前已确认报价的小程序收款码;改价、换套餐或失败时立即清除。
private(set) var payCode: DroneDockPayCode?
/// 是否正在加载套餐列表。
private(set) var isLoadingProjects = false
/// 是否正在向后端生成付款链接。
/// 是否正在向后端生成小程序收款码。
private(set) var isGenerating = false
/// 套餐读取错误,与成功的空列表分开表达。
private(set) var projectError: String?
@@ -38,7 +38,7 @@ final class DroneDockPaymentViewModel {
self.currentContext = currentContext
}
/// 加载可售套餐;切换登录、景区或门店时清除之前的套餐和付款链接。
/// 加载可售套餐;切换登录、景区或门店时清除之前的套餐和小程序收款码。
func loadProjects() async {
let scope = scopeGeneration
let requested = await currentContext()