feat: 品牌化那拉提景区收款页
This commit is contained in:
@ -5,6 +5,83 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
/// 收款页展示配置接口响应。
|
||||
struct PayPageConfigResponse: Decodable, Sendable, Equatable {
|
||||
let background: String
|
||||
let logo: String
|
||||
let title: String
|
||||
let subtitle: String
|
||||
|
||||
init(background: String, logo: String, title: String, subtitle: String) {
|
||||
self.background = background
|
||||
self.logo = logo
|
||||
self.title = title
|
||||
self.subtitle = subtitle
|
||||
}
|
||||
}
|
||||
|
||||
/// 收款页最终可展示并可持久化的品牌配置。
|
||||
struct PayPageConfig: Codable, Sendable, Equatable {
|
||||
let background: String
|
||||
let logo: String
|
||||
let title: String
|
||||
let subtitle: String
|
||||
|
||||
/// 那拉提景区随包默认配置。
|
||||
static let nalatiDefault = PayPageConfig(
|
||||
background: "",
|
||||
logo: "",
|
||||
title: "那拉提旅拍管理收费平台",
|
||||
subtitle: "那拉提景区"
|
||||
)
|
||||
|
||||
/// 将服务端非空有效字段合并到当前可用配置。
|
||||
func merging(_ response: PayPageConfigResponse) -> PayPageConfig {
|
||||
PayPageConfig(
|
||||
background: Self.validRemoteImageURL(response.background) ?? background,
|
||||
logo: Self.validRemoteImageURL(response.logo) ?? logo,
|
||||
title: response.title.trimmedNonEmpty ?? title,
|
||||
subtitle: response.subtitle.trimmedNonEmpty ?? subtitle
|
||||
)
|
||||
}
|
||||
|
||||
private static func validRemoteImageURL(_ value: String) -> String? {
|
||||
let trimmed = value.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard let url = URL(string: trimmed),
|
||||
url.scheme?.lowercased() == "https",
|
||||
url.host != nil else {
|
||||
return nil
|
||||
}
|
||||
return trimmed
|
||||
}
|
||||
}
|
||||
|
||||
/// 收款页品牌化景区判定策略。
|
||||
enum PayPageBrandingPolicy {
|
||||
/// 那拉提景区正式 ID。
|
||||
static let nalatiScenicId = 128
|
||||
|
||||
/// 判断当前景区是否启用品牌收款页。
|
||||
static func isNalati(scenicId: Int) -> Bool {
|
||||
scenicId == nalatiScenicId
|
||||
}
|
||||
}
|
||||
|
||||
/// 收款页当前账号信息的展示文本格式化规则。
|
||||
enum PaymentAccountDisplayFormatter {
|
||||
/// 解析当前登录摄影师名称,昵称为空时使用实名,仍为空时显示占位符。
|
||||
static func photographerName(userName: String, realName: String) -> String {
|
||||
userName.trimmedNonEmpty ?? realName.trimmedNonEmpty ?? "-"
|
||||
}
|
||||
|
||||
/// 去除空值与重复项后,合并当前账号的全部店铺名称。
|
||||
static func storeNames(_ names: [String]) -> String {
|
||||
var seen = Set<String>()
|
||||
let resolved = names.compactMap(\.trimmedNonEmpty).filter { seen.insert($0).inserted }
|
||||
return resolved.isEmpty ? "-" : resolved.joined(separator: "、")
|
||||
}
|
||||
}
|
||||
|
||||
/// 摄影师收款码响应,包含静态与动态支付 URL。
|
||||
struct PayCodeResponse: Decodable, Sendable, Equatable {
|
||||
let staticPayURL: String
|
||||
@ -101,3 +178,10 @@ struct PaymentMerchantInfo: Sendable, Equatable {
|
||||
company: "扬州元智享网络科技有限公司"
|
||||
)
|
||||
}
|
||||
|
||||
private extension String {
|
||||
var trimmedNonEmpty: String? {
|
||||
let value = trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
return value.isEmpty ? nil : value
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user