wake-ios/wake/Models/OrderInfo.swift
2025-09-02 20:25:35 +08:00

102 lines
2.6 KiB
Swift

import Foundation
///
struct OrderInfo: Codable, Identifiable {
let id: String
let userId: String
let totalAmount: Amount
let status: String
let items: [OrderItem]
let paymentInfo: PaymentInfo?
let createdAt: String
let updatedAt: String
let expiredAt: String
enum CodingKeys: String, CodingKey {
case id
case userId = "user_id"
case totalAmount = "total_amount"
case status
case items
case paymentInfo = "payment_info"
case createdAt = "created_at"
case updatedAt = "updated_at"
case expiredAt = "expired_at"
}
}
///
struct PaymentInfo: Codable {
let id: String
let paymentMethod: String
let paymentStatus: String
let paymentAmount: Amount
let transactionId: String?
let thirdPartyTransactionId: String?
let paidAt: String?
let createdAt: String
let updatedAt: String
enum CodingKeys: String, CodingKey {
case id
case paymentMethod = "payment_method"
case paymentStatus = "payment_status"
case paymentAmount = "payment_amount"
case transactionId = "transaction_id"
case thirdPartyTransactionId = "third_party_transaction_id"
case paidAt = "paid_at"
case createdAt = "created_at"
case updatedAt = "updated_at"
}
}
///
struct Amount: Codable {
let amount: String
let currency: String
}
///
struct OrderItem: Codable, Identifiable {
let id: String
let productId: Int
let productType: String
let productCode: String
let productName: String
let unitPrice: Amount
let discountAmount: Amount
let quantity: Int
let totalPrice: Amount
enum CodingKeys: String, CodingKey {
case id
case productId = "product_id"
case productType = "product_type"
case productCode = "product_code"
case productName = "product_name"
case unitPrice = "unit_price"
case discountAmount = "discount_amount"
case quantity
case totalPrice = "total_price"
}
}
///
enum OrderStatus: Int, Codable {
case pending = 0 //
case paid = 1 //
case completed = 2 //
case cancelled = 3 //
case refunded = 4 // 退
var description: String {
switch self {
case .pending: return "待支付"
case .paid: return "已支付"
case .completed: return "已完成"
case .cancelled: return "已取消"
case .refunded: return "已退款"
}
}
}