// // KMMemberInfo.swift // PDF Reader Pro // // Created by wanjun on 2024/10/22. // import Cocoa // 用户场景类型 @objc enum KMUserScenarioType : Int { case lite_type1 = 0 // 免费版 无旧买断 免费未试用 (右上角导航栏按钮 - “登录领福利” + “试用”) case lite_type2 // 免费版 无旧买断 免费试用中 (右上角导航栏按钮 - “登录领福利”) case lite_type3 // 免费版 无旧买断 试用过期或取消 (右上角导航栏按钮 - “登录领福利” + 开通会员) case lite_type4 // 免费版 无旧买断 可升级订阅 (右上角导航栏按钮 - “登录领福利” + 升级) case lite_type5 // 免费版 无旧买断 多平台永久 (右上角导航栏按钮 - “登录领福利” + 升级全平台) case lite_type6 // 免费版 无旧买断 全平台高级年订阅 (右上角导航栏按钮 - “登录领福利”) case lite_type7 // 免费版 无旧买断 会员到期 (右上角导航栏按钮 - “登录领福利” + 续费) case lite_type8 // 免费版 无旧买断 订阅中取消 (右上角导航栏按钮 - “登录领福利” + 续费) case lite_type9 // 免费版 有旧买断 免费未试用 (右上角导航栏按钮 - “登录领福利” + “升级至Pro” + 立即试用) case lite_type10 // 免费版 有旧买断 免费试用中 (右上角导航栏按钮 - “登录领福利”) case lite_type11 // 免费版 有旧买断 试用过期或取消 (右上角导航栏按钮 - “登录领福利” + 开通会员) case lite_type12 // 免费版 有旧买断 全平台高级版年订阅 (右上角导航栏按钮 - “登录领福利”) case lite_type13 // 免费版 有旧买断 订阅中取消 (右上角导航栏按钮 - “登录领福利” + 续费) case pro_type1 // 付费版 有旧PDF To Office (右上角导航栏按钮 - “登录领福利” + 升级(全平台)) case pro_type2 // 付费版 有旧PDF To Office 全平台高级年订阅 (右上角导航栏按钮 - “登录领福利”) case pro_type3 // 付费版 无旧PDF To Office (右上角导航栏按钮 - “登录领福利” + 升级(全平台/高级版永久)) case pro_type4 // 付费版 无旧PDF To Office 高级版永久 (右上角导航栏按钮 - Info + 升级(全平台)) case pro_type5 // 付费版 无旧PDF To Office 全平台高级年订阅 (右上角导航栏按钮 - Info) } // 当前权益类型 @objc enum KMCurrentUserEquityType : Int { case lite_free = 0 // 免费版 免费 case lite_old } @objcMembers class KMMemberInfo: NSObject { static let shared = KMMemberInfo() var isLogin: Bool = false /** 登录 */ private var _refresh_token: String = "" // 刷新Token private var _access_token: String = "" // 访问Token private var _token_type: String = "" // Token 类型 private var _expires_in: String = "" private var _scope: String = "" /** 登录 */ var userID: String = "" // 用户ID var userEmail: String = "" // 用户邮箱 var fullName: String = "" // 用户名称 var _activeVips: [KMMemberUserInfoActiveVIP] = [] // 活跃的会员 var _activeAis: [KMMemberUserInfoActiveVIP] = [] // 活跃的AI var vip_id: String = "" // id var vip_userId: String = "" // 用户id var vip_status: Int = 0 // 状态 0注册1订阅中2订阅过期3试用中4试用过期 var vip_endDate: String = "" // 到期时间 var vip_payType: Int = 0 // 0未开启自动续订 1自动续订 var vip_productName: String = "" // 产品名字 var vip_levels: String = "" // 会员等级 1是免费 2是标准 3是高级 var vip_platforms: String = "" // 支持的平台 var vip_point: Int = 0 // 剩余ai点数(svip才有) var vip_maxDeviceNum: Int = 0 // 最大登录设备限制数 var vip_paymentModel: String = "" // 支付方式 付费模式(1自动续订(vip svip) 2单次付费(永久会员)) var vip_isAi: String = "" // 是否是ai产品(0否1是) var vip_cycle: Int = 0 // 订阅周期:1、月(30天);2、季(90天);3、半年(183天);4、年(365天) var ai_id: String = "" // id var ai_userId: String = "" // 用户id var ai_status: Int = 0 // 状态 0注册1订阅中2订阅过期3试用中4试用过期 var ai_endDate: String = "" // 到期时间 var ai_payType: Int = 0 // 0未开启自动续订 1自动续订 var ai_productName: String = "" // 产品名字 var ai_levels: String = "" // 会员等级 1是免费 2是标准 3是高级 var ai_platforms: String = "" // 支持的平台 var ai_point: Int = 0 // 剩余ai点数(svip才有) var ai_maxDeviceNum: Int = 0 // 最大登录设备限制数 var ai_paymentModel: String = "" // 支付方式 付费模式(1自动续订(vip svip) 2单次付费(永久会员)) var ai_isAi: String = "" // 是否是ai产品(0否1是) var ai_cycle: Int = 0 // 订阅周期:1、月(30天);2、季(90天);3、半年(183天);4、年(365天) var aiPoint: Int = 0 // AI 点数 var validFlag: String = "" // 注销(0), * 正常(1), * 停用(2), * 注销中(5); var isHaveAIDiscount: String = "" // 是否有ai折扣 var canTrail: Bool = false // 是否能试用 // var currentTime: String = "" // 当前注销时间 // var logOffTime: String = "" // 注销时间 // MARK: Get & Set var refresh_token: String { get { let token = UserDefaults.standard.value(forKey: "MemberRefreshToken") if token is String { return token as! String } return _refresh_token } set { _refresh_token = newValue UserDefaults.standard.setValue(newValue, forKey: "MemberRefreshToken") UserDefaults.standard.synchronize() } } var access_token: String { get { let token = UserDefaults.standard.value(forKey: "MemberAccessToken") if token is String { return token as! String } return _access_token } set { _access_token = newValue UserDefaults.standard.setValue(newValue, forKey: "MemberAccessToken") UserDefaults.standard.synchronize() } } var token_type: String { get { return _token_type } set { _token_type = newValue } } var activeVips: [KMMemberUserInfoActiveVIP] { get { return _activeVips } set { _activeVips = newValue for index in 0..<_activeVips.count { let vip = _activeVips[index] if index == 0 { vip_id = vip.id vip_userId = vip.userId vip_status = vip.status vip_endDate = vip.endDate vip_payType = vip.payType vip_productName = vip.productName vip_levels = vip.levels vip_platforms = vip.platforms vip_point = vip.point vip_maxDeviceNum = vip.maxDeviceNum vip_paymentModel = vip.paymentModel vip_isAi = vip.isAi vip_cycle = vip.cycle } else { if let vipLevelsInt = Int(vip_levels), let vipOtherLevelsInt = Int(vip.levels), vipLevelsInt < vipOtherLevelsInt { vip_id = vip.id vip_userId = vip.userId vip_status = vip.status vip_endDate = vip.endDate vip_payType = vip.payType vip_productName = vip.productName vip_levels = vip.levels vip_platforms = vip.platforms vip_point = vip.point vip_maxDeviceNum = vip.maxDeviceNum vip_paymentModel = vip.paymentModel vip_isAi = vip.isAi vip_cycle = vip.cycle } } } } } var activeAis: [KMMemberUserInfoActiveVIP] { get { return _activeAis } set { _activeAis = newValue for index in 0..<_activeAis.count { let vip = _activeAis[index] if index == 0 { ai_id = vip.id ai_userId = vip.userId ai_status = vip.status ai_endDate = vip.endDate ai_payType = vip.payType ai_productName = vip.productName ai_levels = vip.levels ai_platforms = vip.platforms ai_point = vip.point ai_maxDeviceNum = vip.maxDeviceNum ai_paymentModel = vip.paymentModel ai_isAi = vip.isAi ai_cycle = vip.cycle } else { if let vipLevelsInt = Int(ai_levels), let vipOtherLevelsInt = Int(vip.levels), vipLevelsInt < vipOtherLevelsInt { ai_id = vip.id ai_userId = vip.userId ai_status = vip.status ai_endDate = vip.endDate ai_payType = vip.payType ai_productName = vip.productName ai_levels = vip.levels ai_platforms = vip.platforms ai_point = vip.point ai_maxDeviceNum = vip.maxDeviceNum ai_paymentModel = vip.paymentModel ai_isAi = vip.isAi ai_cycle = vip.cycle } } } } } // 用户当前的状态 var userScenarioType: KMUserScenarioType { get { let oldAIPoints = AIInfoManager.default().aiInfo.totalToken - AIInfoManager.default().aiInfo.usedTimes // 旧版AI点数 let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" var startTime = Date() if KMMemberInfo.shared.vip_endDate.count > 0 { startTime = dateFormatter.date(from: KMMemberInfo.shared.vip_endDate)! } let currentTime = Date() let platforms = KMMemberInfo.shared.vip_platforms let platformsArray = platforms .components(separatedBy: ",") .map { $0.trimmingCharacters(in: .whitespaces) } #if VERSION_FREE #if VERSION_DMG // DMG if KMMemberInfo.shared.isLogin { } else { } #else // AppStore 免费版本 if IAPProductsManager.default().allAccessPackPermanent_lite.isSubscribed == true || IAPProductsManager.default().isAvailableAllFunction() == true { // 有旧买断 if KMMemberInfo.shared.canTrail { return .lite_type9 } if KMMemberInfo.shared.vip_status == 3 { return .lite_type10 } else if KMMemberInfo.shared.vip_status == 4 { return .lite_type11 } if KMMemberInfo.shared.vip_paymentModel == "1" && KMMemberInfo.shared.vip_cycle == 4 && platformsArray.count == 4 { return .lite_type12 } if KMMemberInfo.shared.vip_paymentModel == "1" && KMMemberInfo.shared.vip_payType == 0 { return .lite_type13 } } else { // 无旧买断 if KMMemberInfo.shared.canTrail && KMMemberInfo.shared.vip_levels == "1" { return .lite_type1 } if KMMemberInfo.shared.vip_status == 3 { return .lite_type2 } else if KMMemberInfo.shared.vip_status == 4 { return .lite_type3 } else if KMMemberInfo.shared.vip_status == 2 { return .lite_type7 } else if KMMemberInfo.shared.vip_paymentModel == "1" && KMMemberInfo.shared.vip_payType == 0 { return .lite_type8 } if KMMemberInfo.shared.vip_paymentModel == "2" { return .lite_type5 } else { if KMMemberInfo.shared.vip_cycle == 4 && platformsArray.count == 4 { return .lite_type6 } else { return .lite_type4 } } } #endif #else // AppStore 付费版 if IAPProductsManager.default().pdfToOfficeProduct.isSubscribed == true { if KMMemberInfo.shared.vip_cycle == 4 && platformsArray.count == 4 { return .pro_type2 } else { return .pro_type1 } } else { if KMMemberInfo.shared.vip_paymentModel == "2" { return .pro_type4 } else { if KMMemberInfo.shared.vip_cycle == 4 && platformsArray.count == 4 { return .pro_type2 } else { return .pro_type3 } } } #endif return .lite_type1 } } // 是否允许全部功能 var isMemberAllFunction: Bool { get { #if VERSION_FREE #if VERSION_DMG // DMG #else // AppStore 免费版本 if KMMemberInfo.shared.isLogin { if IAPProductsManager.default().allAccessPackPermanent_lite.isSubscribed == true || IAPProductsManager.default().isAvailableAllFunction() == true { return true } else { if userScenarioType == .lite_type2 || userScenarioType == .lite_type4 || userScenarioType == .lite_type5 || userScenarioType == .lite_type6 { return true } return false } } else { if IAPProductsManager.default().allAccessPackPermanent_lite.isSubscribed == true || IAPProductsManager.default().isAvailableAllFunction() == true { return true } return false } #endif #else // AppStore 付费版 return true #endif return false } } // 是否允许使用转档 var isPermitConvert: Bool { if KMMemberInfo.shared.isLogin { if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() { return true } else { if userScenarioType == .lite_type4 || userScenarioType == .lite_type5 || userScenarioType == .lite_type6 || userScenarioType == .lite_type12 { return true } else { return false } } } else { if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() { return true } return false } } // 是否允许使用AI var isPermitAI: Bool { // let oldAIPoints = AIInfoManager.default().aiInfo.totalToken - AIInfoManager.default().aiInfo.usedTimes // 旧版AI点数 // if KMMemberInfo.shared.isLogin { // if oldAIPoints > 0 { // return true // } else { // if userScenarioType == .lite_type4 || userScenarioType == .lite_type5 || userScenarioType == .lite_type6 || userScenarioType == .lite_type12 { // if KMMemberInfo.shared.aiPoint > 0 { // return true // } else { // return false // } // } // return false // } // } else { // if AIInfoManager.default().aiInfoValid && oldAIPoints > 0 { // return true // } // return false // } if KMMemberInfo.shared.isLogin { if KMMemberInfo.shared.ai_productName != "" || AIInfoManager.default().aiInfoValid { return true } return false } else { if AIInfoManager.default().aiInfoValid { return true } return false } } // MARK: Public Method func memberUserInfo(model: KMMemberUserInfo) -> Void { userID = model.id userEmail = model.email fullName = model.fullName aiPoint = model.aiPoint validFlag = model.validFlag isHaveAIDiscount = model.isHaveAIDiscount if model.canTrail == "1" { canTrail = true } else { canTrail = false } activeVips = model.activeVIP activeAis = model.activeAI } func advancedFunctionUsage() -> Void { let platforms = KMMemberInfo.shared.vip_platforms let platformsArray = platforms .components(separatedBy: ",") .map { $0.trimmingCharacters(in: .whitespaces) } if KMMemberInfo.shared.isLogin { if userScenarioType == .lite_type1 { KMProductCompareWC.shared.orientation = true KMProductCompareWC.shared.orientationType = .trial KMProductCompareWC.shared.showWindow(nil) } else if userScenarioType == .lite_type2 || userScenarioType == .lite_type6 || userScenarioType == .lite_type10 || userScenarioType == .lite_type12 { } else if userScenarioType == .lite_type3 || userScenarioType == .lite_type11 { KMProductCompareWC.shared.orientation = true KMProductCompareWC.shared.orientationType = .lite_Base KMProductCompareWC.shared.showWindow(nil) } else if userScenarioType == .lite_type4 || userScenarioType == .lite_type5 || userScenarioType == .lite_type9 || userScenarioType == .lite_type13 { KMProductCompareWC.shared.orientation = true KMProductCompareWC.shared.orientationType = .lite_MacWindows KMProductCompareWC.shared.showWindow(nil) } else if userScenarioType == .lite_type7 || userScenarioType == .lite_type8 { KMProductCompareWC.shared.orientation = true if KMMemberInfo.shared.vip_paymentModel == "1" && KMMemberInfo.shared.vip_cycle == 4 && platformsArray.count == 4 { KMProductCompareWC.shared.orientationType = .lite_MacWindows } else { KMProductCompareWC.shared.orientationType = .lite_Base } KMProductCompareWC.shared.showWindow(nil) } } else { KMLoginWindowsController.shared.openWindow() { [weak self] success in guard let self = self else { return } if success { if self.userScenarioType == .lite_type1 { KMProductCompareWC.shared.orientation = true KMProductCompareWC.shared.orientationType = .trial KMProductCompareWC.shared.showWindow(nil) } else if self.userScenarioType == .lite_type2 || self.userScenarioType == .lite_type6 || self.userScenarioType == .lite_type10 || self.userScenarioType == .lite_type12 { } else if self.userScenarioType == .lite_type3 || self.userScenarioType == .lite_type11 { KMProductCompareWC.shared.orientation = true KMProductCompareWC.shared.orientationType = .lite_Base KMProductCompareWC.shared.showWindow(nil) } else if self.userScenarioType == .lite_type4 || self.userScenarioType == .lite_type5 || self.userScenarioType == .lite_type9 || self.userScenarioType == .lite_type13 { KMProductCompareWC.shared.orientation = true KMProductCompareWC.shared.orientationType = .lite_MacWindows KMProductCompareWC.shared.showWindow(nil) } else if self.userScenarioType == .lite_type7 || self.userScenarioType == .lite_type8 { KMProductCompareWC.shared.orientation = true if KMMemberInfo.shared.vip_paymentModel == "1" && KMMemberInfo.shared.vip_cycle == 4 && platformsArray.count == 4 { KMProductCompareWC.shared.orientationType = .lite_MacWindows } else { KMProductCompareWC.shared.orientationType = .lite_Base } KMProductCompareWC.shared.showWindow(nil) } } } } } func aiSubscription() -> Bool { let oldAIPoints = AIInfoManager.default().aiInfo.totalToken - AIInfoManager.default().aiInfo.usedTimes // 旧版AI点数 if oldAIPoints > 0 { return true } else { if KMMemberInfo.shared.isLogin { if KMMemberInfo.shared.aiPoint > 0 { return true } else { AIPurchaseWindowController.currentWC().showWindow(nil) return false } } else { KMLoginWindowsController.shared.openWindow() { success in if success { AIPurchaseWindowController.currentWC().showWindow(nil) } } return false } } } }