123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- //
- // KMLightMemberUserInfo.swift
- // PDF Reader Pro
- //
- // 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 subscriptionInfoList: [KMLightMemberUserSubscriptionInfo] = []
- var existOrderInfo: Bool?
-
- // accountSource = 0;
- // accountType = "<null>";
- // appId = 16;
- // area = "<null>";
- // companyId = "<null>";
- // createdAt = "2023-07-04 16:52:47";
- // digestPassword = "<null>";
- // email = "wahek23894@dotvilla.com";
- // freeDate = "2023-06-22 08:00:00";
- // fullName = "<null>";
- // id = "6d9bf147-177b-408c-aeac-4116a30805a8";
- // industry = "<null>";
- // isInFreeUseTime = 1;
- // job = "<null>";
- // lastPopularizeAt = "<null>";
- // lastPresentedCouponAt = "<null>";
- // mailable = "<null>";
- // phone = "<null>";
- // platformType = 0;
- // remark = "<null>";
- // resetToken = "<null>";
- // role = "<null>";
- // subscribed = "<null>";
- // subscriberType = "<null>";
- //
- // 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: Any
- }
- class KMLightMemberUserSubscriptionInfo: NSObject, Codable {
- var endDate: String?
- var id: String?
- var payType: Int? //0:未自动续订 1:自动续订
- var platform: Int?
- var status: Int?
- var userId: 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 {
- 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.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 = KMLightMemberUserInfo.allowLoadItemData(lightMemberUserInfo)
- }
- #else
- // MARK: 此处try 使用 ? ,如果数据出问题 advertisementModel将无参数, 测试时使用!
- 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
-
- // 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是否显示
- 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)
- }
- }
- // if subscriptionList.count > 1 {
- result.existOrderInfo = true
- // } else {
- // result.existOrderInfo = false
- // }
- 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
- }
- }
|