// // YMMainGoodModel.swift // MvpGoods // // Created by 小花 on 2019/4/9. // Copyright © 2019 MVP. All rights reserved. // import UIKit import ObjectMapper class YMMainGoodModel: Mappable { var goods_id: Int? var title: String? var img: String? var price: String? //原价 var discount_price: String? //折扣价 var coupon_price: Int? //优惠券价格 var volume: Int? //月销量 var coupon_start_time: String? var coupon_end_time: String? func coverWith(good_ID: String?,pri: String?, discount_pri: String?,coupon_pri: String?, start_time: String?, end_time:String?) { goods_id = Int(good_ID ?? "0") price = pri discount_price = discount_pri coupon_price = Int(coupon_pri ?? "0") coupon_start_time = start_time coupon_end_time = end_time } init(){ } required init?(map: Map) { } func mapping(map: Map) { goods_id <- (map["goods_id"],transform) title <- map["title"] img <- map["img"] price <- map["price"] discount_price <- map["discount_price"] coupon_price <- (map["coupon_price"],transform) volume <- map["volume"] coupon_start_time <- map["coupon_start_time"] coupon_end_time <- map["coupon_end_time"] } let transform = TransformOf(fromJSON: { (value: Any) -> Int? in // 将值从 String? 变换为 Int? if value is String { return Int(value as! String) }else { return value as? Int } }, toJSON: { (value: Int?) -> String? in // 将值从 Int? 变换为 String? if let value = value { return String(value) } return nil }) }