KMLightMemberUserInfo.swift 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. //
  2. // KMLightMemberUserInfo.swift
  3. // PDF Reader Pro
  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 subscriptionInfoList: [KMLightMemberUserSubscriptionInfo] = []
  19. var existOrderInfo: Bool?
  20. // accountSource = 0;
  21. // accountType = "<null>";
  22. // appId = 16;
  23. // area = "<null>";
  24. // companyId = "<null>";
  25. // createdAt = "2023-07-04 16:52:47";
  26. // digestPassword = "<null>";
  27. // email = "wahek23894@dotvilla.com";
  28. // freeDate = "2023-06-22 08:00:00";
  29. // fullName = "<null>";
  30. // id = "6d9bf147-177b-408c-aeac-4116a30805a8";
  31. // industry = "<null>";
  32. // isInFreeUseTime = 1;
  33. // job = "<null>";
  34. // lastPopularizeAt = "<null>";
  35. // lastPresentedCouponAt = "<null>";
  36. // mailable = "<null>";
  37. // phone = "<null>";
  38. // platformType = 0;
  39. // remark = "<null>";
  40. // resetToken = "<null>";
  41. // role = "<null>";
  42. // subscribed = "<null>";
  43. // subscriberType = "<null>";
  44. //
  45. // var companyId: String = ""
  46. // var fullName: String = ""
  47. // var subscriberType: String = ""
  48. // var subscribed: String = ""
  49. // var digestPassword: String = ""
  50. // var phone: String = ""
  51. // var industry: String = ""
  52. // var lastPopularizeAt: String = ""
  53. // var lastPresentedCouponAt: String = ""
  54. // var mailable: String = ""
  55. // var resetToken: String = ""
  56. // var role: String = ""
  57. // var job: String = ""
  58. // var area: String = ""
  59. // var accountSource: String = ""
  60. // var updatedAt: String = ""
  61. // var remark: String = ""
  62. // var validFlag: String = ""
  63. // var subscriptionInfoList: Any
  64. }
  65. class KMLightMemberUserSubscriptionInfo: NSObject, Codable {
  66. var endDate: String?
  67. var id: String?
  68. var payType: Int? //0:未自动续订 1:自动续订
  69. var platform: Int?
  70. var status: Int?
  71. var userId: String?
  72. }
  73. extension KMLightMemberUserInfo {
  74. //MARK: data
  75. /**
  76. @abstract 解析数据
  77. @param data 传入参数 NSDictionary
  78. @return KMAdvertisementModel
  79. */
  80. static public func parseData(data: NSDictionary, needSave: Bool = true, completion:(_ result: KMLightMemberUserInfo) -> Void) -> Void {
  81. var result: KMLightMemberUserInfo = KMLightMemberUserInfo()
  82. if data.count > 0 {
  83. if (data.count != 0 && needSave) {
  84. KMLightMemberCache.cache.saveData(data: data)
  85. }
  86. var resultData = KMLightMemberCache.cache.removeNullValuesFromDictionary(data as! [String : Any])
  87. //兼容旧数据
  88. if resultData["subscriptionInfoList"] == nil {
  89. resultData.updateValue([], forKey: "subscriptionInfoList")
  90. }
  91. let jsonString: String = DictionaryToJson.dictionary(toJson: resultData as? AnyObject)!
  92. let jsonData: Data = jsonString.data(using: .utf8)!
  93. let decoder = JSONDecoder()
  94. // decoder.dataDecodingStrategy = .base64
  95. // decoder.keyDecodingStrategy = .convertFromSnakeCase //带下划线命名
  96. decoder.nonConformingFloatDecodingStrategy = .convertFromString(positiveInfinity: "+∞", negativeInfinity: "-∞", nan: "NaN")
  97. #if DEBUG
  98. //MARK: 测试使用
  99. var lightMemberUserInfo = try! decoder.decode(KMLightMemberUserInfo.self, from: jsonData)
  100. if (lightMemberUserInfo != nil) {
  101. result = KMLightMemberUserInfo.allowLoadItemData(lightMemberUserInfo)
  102. }
  103. #else
  104. // MARK: 此处try 使用 ? ,如果数据出问题 advertisementModel将无参数, 测试时使用!
  105. var lightMemberUserInfo = try? decoder.decode(KMLightMemberUserInfo.self, from: jsonData)
  106. if (lightMemberUserInfo != nil) {
  107. result = KMLightMemberUserInfo.allowLoadItemData(lightMemberUserInfo!)
  108. }
  109. #endif
  110. }
  111. completion(result)
  112. }
  113. func allowLoadData(data: NSDictionary) -> Bool {
  114. var result = false
  115. // let status = (data["status"] as? Int) ?? 0
  116. // let app_name: String = data["app_name"] as? String ?? ""
  117. //
  118. // if (status == 1 &&
  119. // app_name == configuration.appName.string()) {
  120. // result = true
  121. // }
  122. return result
  123. }
  124. func allowLoadContentData(data: KMLightMemberUserInfo) -> Bool {
  125. var result = false
  126. // let time: NSInteger = NSInteger(KMAdvertisementTimeStampConversion.getCurrentTimeInterval())!
  127. // let startTime: NSInteger = NSInteger(data.startTime!)!
  128. // let endTime: NSInteger = NSInteger(data.endTime!)!
  129. // let platform = configuration.platform
  130. // let subscribeType = configuration.subscribeType
  131. // let version = data.version ?? "1.0"
  132. // let localVersion = self.getLocalVersion()
  133. // let hidden = data.hidden ?? false
  134. //
  135. // if (time >= startTime &&
  136. // time <= endTime &&
  137. // platform == data.platform &&
  138. // self.compareVersion(nowVersion:localVersion, newVersion: version) &&
  139. // (subscribeType == data.subscribeType || data.subscribeType == .all) &&
  140. // !hidden) {
  141. // result = true
  142. // }
  143. return result
  144. }
  145. //过滤item是否显示
  146. static func allowLoadItemData(_ data: KMLightMemberUserInfo) -> KMLightMemberUserInfo {
  147. var result = data
  148. var array: [KMLightMemberUserSubscriptionInfo] = []
  149. let subscriptionList = data.subscriptionInfoList
  150. for item in subscriptionList {
  151. if item.platform == 1 {
  152. array.append(item)
  153. }
  154. }
  155. // if subscriptionList.count > 1 {
  156. result.existOrderInfo = true
  157. // } else {
  158. // result.existOrderInfo = false
  159. // }
  160. result.subscriptionInfoList = array
  161. return result
  162. }
  163. //获取本地版本号
  164. func getLocalVersion() -> String {
  165. var localVersion = ""
  166. if let v: String = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String {
  167. localVersion = v
  168. }
  169. return localVersion
  170. }
  171. func compareVersion(nowVersion: String, newVersion: String) -> Bool {
  172. let nowArray = nowVersion.split(separator: ".")
  173. let newArray = newVersion.split(separator: ".")
  174. let big = nowArray.count > newArray.count ? newArray.count : nowArray.count
  175. if big != 0 {
  176. for index in 0...big - 1 {
  177. let first = nowArray[index]
  178. let second = newArray[index]
  179. if Int(first)! < Int(second)! {
  180. return true
  181. }
  182. if index == big - 1 {
  183. if Int(first)! <= Int(second)! {
  184. return true
  185. }
  186. }
  187. }
  188. } else {
  189. return true
  190. }
  191. return false
  192. }
  193. }