// // KMLightMemberUserInfo.swift // PDF Master // // Created by lizhe on 2023/2/22. // 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 accountType: Int = 0 var createdAt: String = "" var validFlag: String = "" // 0是已注销 5是注销中 // var companyId: String = "" // var fullName: String = "" // var subscriberType: String = "" // var subscribed: String = "" // var digestPassword: String = "" // var phone: String = "" // var industry: String = "" // var lastPopularizeAt: String = "" // var lastPresentedCouponAt: String = "" // var mailable: String = "" // var resetToken: String = "" // var role: String = "" // var job: String = "" // var area: String = "" // var accountSource: String = "" // var updatedAt: String = "" // var remark: String = "" // var validFlag: String = "" // var subscriptionInfoList: String = "" } extension KMLightMemberUserInfo { //MARK: data /** @abstract 解析数据 @param data 传入参数 NSDictionary @return KMAdvertisementModel */ static public func parseData(data: NSDictionary, needSave: Bool = true, completion:(_ result: KMLightMemberUserInfo) -> Void) -> Void { if (data.count != 0 && needSave) { KMLightMemberCache.cache.saveData(data: data) } var result: KMLightMemberUserInfo = KMLightMemberUserInfo() let jsonString: String = DictionaryToJson.dictionary(toJson: data)! let jsonData: Data = jsonString.data(using: .utf8)! let decoder = JSONDecoder() // decoder.dataDecodingStrategy = .base64 // decoder.keyDecodingStrategy = .convertFromSnakeCase //带下划线命名 decoder.nonConformingFloatDecodingStrategy = .convertFromString(positiveInfinity: "+∞", negativeInfinity: "-∞", nan: "NaN") #if DEBUG //MARK: 测试使用 var lightMemberUserInfo = try! decoder.decode(KMLightMemberUserInfo.self, from: jsonData) if (lightMemberUserInfo != nil) { result = lightMemberUserInfo } #else // MARK: 此处try 使用 ? ,如果数据出问题 advertisementModel将无参数, 测试时使用! var lightMemberUserInfo = try? decoder.decode(KMLightMemberUserInfo.self, from: jsonData) if (lightMemberUserInfo != nil) { result = lightMemberUserInfo! } #endif completion(result) } func allowLoadData(data: NSDictionary) -> Bool { var result = false // let status = (data["status"] as? Int) ?? 0 // let app_name: String = data["app_name"] as? String ?? "" // // if (status == 1 && // app_name == configuration.appName.string()) { // result = true // } return result } func allowLoadContentData(data: KMLightMemberUserInfo) -> Bool { var result = false // let time: NSInteger = NSInteger(KMAdvertisementTimeStampConversion.getCurrentTimeInterval())! // let startTime: NSInteger = NSInteger(data.startTime!)! // let endTime: NSInteger = NSInteger(data.endTime!)! // let platform = configuration.platform // let subscribeType = configuration.subscribeType // let version = data.version ?? "1.0" // let localVersion = self.getLocalVersion() // let hidden = data.hidden ?? false // // if (time >= startTime && // time <= endTime && // platform == data.platform && // self.compareVersion(nowVersion:localVersion, newVersion: version) && // (subscribeType == data.subscribeType || data.subscribeType == .all) && // !hidden) { // result = true // } return result } //过滤item是否显示 func allowLoadItemData(_ data: KMLightMemberUserInfo) -> KMLightMemberUserInfo { // //获取缓存数据 // if (UserDefaults.standard.object(forKey: "KMAdvertisementShowScroll_iOS") == nil) { // UserDefaults.standard.set([], forKey: "KMAdvertisementShowScroll_iOS") // } // let cacheArray: [String] = UserDefaults.standard.object(forKey: "KMAdvertisementShowScroll_iOS") as! [String] let model = data // var sections: [KMAdvertisementModelSection] = [] // for section in data.content! { // var items: [KMAdvertisementModelItem] = [] // for item in section.content! { // let timeString = KMAdvertisementTimeStampConversion.getCurrentTimeInterval() // let time: NSInteger = NSInteger(timeString)! // let startTime: NSInteger = NSInteger(item.startTime ?? timeString)! // let endTime: NSInteger = NSInteger(item.endTime ?? timeString)! // let hidden = item.hidden ?? false // // print(hidden ? "隐藏" : "显示") // if (!hidden && // time >= startTime && // time <= endTime && // !cacheArray.contains(item.productID ?? "")) { // items.append(item) // } // } // section.content = items // sections.append(section) // } // model.content = sections return model } //获取本地版本号 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 } }