优惠券swift版马甲包

YMMainGoodModel.swift 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // YMMainGoodModel.swift
  3. // MvpGoods
  4. //
  5. // Created by 小花 on 2019/4/9.
  6. // Copyright © 2019 MVP. All rights reserved.
  7. //
  8. import UIKit
  9. import ObjectMapper
  10. class YMMainGoodModel: Mappable {
  11. var goods_id: Int?
  12. var title: String?
  13. var img: String?
  14. var price: String? //原价
  15. var discount_price: String? //折扣价
  16. var coupon_price: Int? //优惠券价格
  17. var volume: Int? //月销量
  18. var coupon_start_time: String?
  19. var coupon_end_time: String?
  20. func coverWith(good_ID: String?,pri: String?, discount_pri: String?,coupon_pri: String?, start_time: String?, end_time:String?) {
  21. goods_id = Int(good_ID ?? "0")
  22. price = pri
  23. discount_price = discount_pri
  24. coupon_price = Int(coupon_pri ?? "0")
  25. coupon_start_time = start_time
  26. coupon_end_time = end_time
  27. }
  28. init(){
  29. }
  30. required init?(map: Map) {
  31. }
  32. func mapping(map: Map) {
  33. goods_id <- (map["goods_id"],transform)
  34. title <- map["title"]
  35. img <- map["img"]
  36. price <- map["price"]
  37. discount_price <- map["discount_price"]
  38. coupon_price <- (map["coupon_price"],transform)
  39. volume <- map["volume"]
  40. coupon_start_time <- map["coupon_start_time"]
  41. coupon_end_time <- map["coupon_end_time"]
  42. }
  43. let transform = TransformOf<Int, Any>(fromJSON: { (value: Any) -> Int? in
  44. // 将值从 String? 变换为 Int?
  45. if value is String {
  46. return Int(value as! String)
  47. }else {
  48. return value as? Int
  49. }
  50. }, toJSON: { (value: Int?) -> String? in
  51. // 将值从 Int? 变换为 String?
  52. if let value = value {
  53. return String(value)
  54. }
  55. return nil
  56. })
  57. }