KMLightMemberUserInfo.swift 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. //
  2. // KMLightMemberUserInfo.swift
  3. // PDF Master
  4. //
  5. // Created by lizhe on 2023/2/22.
  6. //
  7. import Cocoa
  8. class KMLightMemberUserInfo: NSObject, Codable {
  9. var id: String = ""
  10. var appId: String = ""
  11. var freeDate: String = ""
  12. var isInFreeUseTime: Bool = false //是否免费使用
  13. var email: String = ""
  14. var platformType: Int = 0
  15. var accountType: Int = 0
  16. var createdAt: String = ""
  17. var validFlag: String = "" // 0是已注销 5是注销中
  18. // var companyId: String = ""
  19. // var fullName: String = ""
  20. // var subscriberType: String = ""
  21. // var subscribed: String = ""
  22. // var digestPassword: String = ""
  23. // var phone: String = ""
  24. // var industry: String = ""
  25. // var lastPopularizeAt: String = ""
  26. // var lastPresentedCouponAt: String = ""
  27. // var mailable: String = ""
  28. // var resetToken: String = ""
  29. // var role: String = ""
  30. // var job: String = ""
  31. // var area: String = ""
  32. // var accountSource: String = ""
  33. // var updatedAt: String = ""
  34. // var remark: String = ""
  35. // var validFlag: String = ""
  36. // var subscriptionInfoList: String = ""
  37. }
  38. extension KMLightMemberUserInfo {
  39. //MARK: data
  40. /**
  41. @abstract 解析数据
  42. @param data 传入参数 NSDictionary
  43. @return KMAdvertisementModel
  44. */
  45. static public func parseData(data: NSDictionary, needSave: Bool = true, completion:(_ result: KMLightMemberUserInfo) -> Void) -> Void {
  46. if (data.count != 0 && needSave) {
  47. KMLightMemberCache.cache.saveData(data: data)
  48. }
  49. var result: KMLightMemberUserInfo = KMLightMemberUserInfo()
  50. let jsonString: String = DictionaryToJson.dictionary(toJson: data)!
  51. let jsonData: Data = jsonString.data(using: .utf8)!
  52. let decoder = JSONDecoder()
  53. // decoder.dataDecodingStrategy = .base64
  54. // decoder.keyDecodingStrategy = .convertFromSnakeCase //带下划线命名
  55. decoder.nonConformingFloatDecodingStrategy = .convertFromString(positiveInfinity: "+∞", negativeInfinity: "-∞", nan: "NaN")
  56. #if DEBUG
  57. //MARK: 测试使用
  58. var lightMemberUserInfo = try! decoder.decode(KMLightMemberUserInfo.self, from: jsonData)
  59. if (lightMemberUserInfo != nil) {
  60. result = lightMemberUserInfo
  61. }
  62. #else
  63. // MARK: 此处try 使用 ? ,如果数据出问题 advertisementModel将无参数, 测试时使用!
  64. var lightMemberUserInfo = try? decoder.decode(KMLightMemberUserInfo.self, from: jsonData)
  65. if (lightMemberUserInfo != nil) {
  66. result = lightMemberUserInfo!
  67. }
  68. #endif
  69. completion(result)
  70. }
  71. func allowLoadData(data: NSDictionary) -> Bool {
  72. var result = false
  73. // let status = (data["status"] as? Int) ?? 0
  74. // let app_name: String = data["app_name"] as? String ?? ""
  75. //
  76. // if (status == 1 &&
  77. // app_name == configuration.appName.string()) {
  78. // result = true
  79. // }
  80. return result
  81. }
  82. func allowLoadContentData(data: KMLightMemberUserInfo) -> Bool {
  83. var result = false
  84. // let time: NSInteger = NSInteger(KMAdvertisementTimeStampConversion.getCurrentTimeInterval())!
  85. // let startTime: NSInteger = NSInteger(data.startTime!)!
  86. // let endTime: NSInteger = NSInteger(data.endTime!)!
  87. // let platform = configuration.platform
  88. // let subscribeType = configuration.subscribeType
  89. // let version = data.version ?? "1.0"
  90. // let localVersion = self.getLocalVersion()
  91. // let hidden = data.hidden ?? false
  92. //
  93. // if (time >= startTime &&
  94. // time <= endTime &&
  95. // platform == data.platform &&
  96. // self.compareVersion(nowVersion:localVersion, newVersion: version) &&
  97. // (subscribeType == data.subscribeType || data.subscribeType == .all) &&
  98. // !hidden) {
  99. // result = true
  100. // }
  101. return result
  102. }
  103. //过滤item是否显示
  104. func allowLoadItemData(_ data: KMLightMemberUserInfo) -> KMLightMemberUserInfo {
  105. // //获取缓存数据
  106. // if (UserDefaults.standard.object(forKey: "KMAdvertisementShowScroll_iOS") == nil) {
  107. // UserDefaults.standard.set([], forKey: "KMAdvertisementShowScroll_iOS")
  108. // }
  109. // let cacheArray: [String] = UserDefaults.standard.object(forKey: "KMAdvertisementShowScroll_iOS") as! [String]
  110. let model = data
  111. // var sections: [KMAdvertisementModelSection] = []
  112. // for section in data.content! {
  113. // var items: [KMAdvertisementModelItem] = []
  114. // for item in section.content! {
  115. // let timeString = KMAdvertisementTimeStampConversion.getCurrentTimeInterval()
  116. // let time: NSInteger = NSInteger(timeString)!
  117. // let startTime: NSInteger = NSInteger(item.startTime ?? timeString)!
  118. // let endTime: NSInteger = NSInteger(item.endTime ?? timeString)!
  119. // let hidden = item.hidden ?? false
  120. //
  121. // print(hidden ? "隐藏" : "显示")
  122. // if (!hidden &&
  123. // time >= startTime &&
  124. // time <= endTime &&
  125. // !cacheArray.contains(item.productID ?? "")) {
  126. // items.append(item)
  127. // }
  128. // }
  129. // section.content = items
  130. // sections.append(section)
  131. // }
  132. // model.content = sections
  133. return model
  134. }
  135. //获取本地版本号
  136. func getLocalVersion() -> String {
  137. var localVersion = ""
  138. if let v: String = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String {
  139. localVersion = v
  140. }
  141. return localVersion
  142. }
  143. func compareVersion(nowVersion: String, newVersion: String) -> Bool {
  144. let nowArray = nowVersion.split(separator: ".")
  145. let newArray = newVersion.split(separator: ".")
  146. let big = nowArray.count > newArray.count ? newArray.count : nowArray.count
  147. if big != 0 {
  148. for index in 0...big - 1 {
  149. let first = nowArray[index]
  150. let second = newArray[index]
  151. if Int(first)! < Int(second)! {
  152. return true
  153. }
  154. if index == big - 1 {
  155. if Int(first)! <= Int(second)! {
  156. return true
  157. }
  158. }
  159. }
  160. } else {
  161. return true
  162. }
  163. return false
  164. }
  165. }