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 "已退款" } } }