123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- import Cocoa
- class KMLightMemberUserInfo: NSObject, Codable {
- var id: String = ""
- var appId: String = ""
- var freeDate: String = ""
- var isInFreeUseTime: Bool = false
- var email: String = ""
- var platformType: Int = 0
- var createdAt: String = ""
- var validFlag: String = ""
- var subscriptionInfoList: [KMLightMemberUserSubscriptionInfo] = []
- var existOrderInfo: Bool?
-
- }
- class KMLightMemberUserSubscriptionInfo: NSObject, Codable {
- var endDate: String?
- var id: String?
- var payType: Int?
- var platform: Int?
- var status: Int?
- var userId: String?
- }
- extension KMLightMemberUserInfo {
-
-
- static public func parseData(data: NSDictionary, needSave: Bool = true, completion:(_ result: KMLightMemberUserInfo) -> Void) -> Void {
- var result: KMLightMemberUserInfo = KMLightMemberUserInfo()
- if data.count > 0 {
- if (data.count != 0 && needSave) {
- KMLightMemberCache.cache.saveData(data: data)
- }
- var resultData = KMLightMemberCache.cache.removeNullValuesFromDictionary(data as! [String : Any])
-
- if resultData["subscriptionInfoList"] == nil {
- resultData.updateValue([], forKey: "subscriptionInfoList")
- }
-
- let jsonString: String = DictionaryToJson.dictionary(toJson: resultData as? AnyObject)!
- let jsonData: Data = jsonString.data(using: .utf8)!
-
- let decoder = JSONDecoder()
-
-
- decoder.nonConformingFloatDecodingStrategy = .convertFromString(positiveInfinity: "+∞", negativeInfinity: "-∞", nan: "NaN")
- #if DEBUG
-
- var lightMemberUserInfo = try! decoder.decode(KMLightMemberUserInfo.self, from: jsonData)
- if (lightMemberUserInfo != nil) {
- result = KMLightMemberUserInfo.allowLoadItemData(lightMemberUserInfo)
- }
- #else
-
- var lightMemberUserInfo = try? decoder.decode(KMLightMemberUserInfo.self, from: jsonData)
- if (lightMemberUserInfo != nil) {
- result = KMLightMemberUserInfo.allowLoadItemData(lightMemberUserInfo!)
- }
- #endif
- }
- completion(result)
- }
-
- func allowLoadData(data: NSDictionary) -> Bool {
- var result = false
-
- return result
-
- }
-
- func allowLoadContentData(data: KMLightMemberUserInfo) -> Bool {
- var result = false
-
- return result
- }
-
-
- static func allowLoadItemData(_ data: KMLightMemberUserInfo) -> KMLightMemberUserInfo {
- var result = data
- var array: [KMLightMemberUserSubscriptionInfo] = []
-
- let subscriptionList = data.subscriptionInfoList
- for item in subscriptionList {
- if item.platform == 1 {
- array.append(item)
- }
- }
- result.existOrderInfo = true
- result.subscriptionInfoList = array
- return result
- }
-
-
- func getLocalVersion() -> String {
- var localVersion = ""
- if let v: String = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String {
- localVersion = v
- }
- return localVersion
- }
-
- func compareVersion(nowVersion: String, newVersion: String) -> Bool {
- let nowArray = nowVersion.split(separator: ".")
- let newArray = newVersion.split(separator: ".")
- let big = nowArray.count > newArray.count ? newArray.count : nowArray.count
- if big != 0 {
- for index in 0...big - 1 {
- let first = nowArray[index]
- let second = newArray[index]
- if Int(first)! < Int(second)! {
- return true
- }
- if index == big - 1 {
- if Int(first)! <= Int(second)! {
- return true
- }
- }
- }
- } else {
- return true
- }
- return false
- }
- }
|