Files
suixinkan_uikit/suixinkan/Features/Payment/Models/PaymentModels.swift

188 lines
5.6 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// PaymentModels.swift
// suixinkan
//
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
let dynamicPayURL: String
enum CodingKeys: String, CodingKey {
case staticPayURL = "static_pay_url"
case dynamicPayURL = "dynamic_pay_url"
}
init(staticPayURL: String, dynamicPayURL: String) {
self.staticPayURL = staticPayURL
self.dynamicPayURL = dynamicPayURL
}
}
///
struct RepaymentCollectionRecordResponse: Decodable, Sendable, Equatable {
let analyse: [RepaymentCollectionRecordAnalyseItem]
let list: [RepaymentCollectionRecordItem]
init(
analyse: [RepaymentCollectionRecordAnalyseItem] = [],
list: [RepaymentCollectionRecordItem] = []
) {
self.analyse = analyse
self.list = list
}
}
///
struct RepaymentCollectionRecordAnalyseItem: Decodable, Sendable, Equatable, Hashable {
let date: String
let orderCount: Int
let orderAmountSum: String
enum CodingKeys: String, CodingKey {
case date
case orderCount = "order_count"
case orderAmountSum = "order_amount_sum"
}
init(date: String, orderCount: Int, orderAmountSum: String) {
self.date = date
self.orderCount = orderCount
self.orderAmountSum = orderAmountSum
}
}
///
struct RepaymentCollectionRecordItem: Decodable, Sendable, Equatable, Hashable {
let orderNumber: String
let userPhone: String
let orderAmount: String
let createDate: String
let createTime: String
enum CodingKeys: String, CodingKey {
case orderNumber = "order_number"
case userPhone = "user_phone"
case orderAmount = "order_amount"
case createDate = "create_date"
case createTime = "create_time"
}
init(
orderNumber: String,
userPhone: String,
orderAmount: String,
createDate: String,
createTime: String
) {
self.orderNumber = orderNumber
self.userPhone = userPhone
self.orderAmount = orderAmount
self.createDate = createDate
self.createTime = createTime
}
}
/// Android `RepaymentCollectionRecordGroup`
struct RepaymentCollectionRecordGroup: Sendable, Equatable, Hashable {
let analyse: RepaymentCollectionRecordAnalyseItem
let items: [RepaymentCollectionRecordItem]
}
///
struct PaymentMerchantInfo: Sendable, Equatable {
let name: String
let company: String
static let defaultInfo = PaymentMerchantInfo(
name: "元智享",
company: "扬州元智享网络科技有限公司"
)
}
private extension String {
var trimmedNonEmpty: String? {
let value = trimmingCharacters(in: .whitespacesAndNewlines)
return value.isEmpty ? nil : value
}
}