123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433 |
- import Cocoa
- @objc enum KMUserScenarioType : Int {
- case null = 0
- case lite_type1
- case lite_type2
- case lite_type3
- case lite_type4
- case lite_type5
- case lite_type6
- case lite_type7
- case lite_type8
- case lite_type9
- case lite_type10
- case lite_type11
- }
- @objcMembers class KMMemberInfo: NSObject {
-
- static let shared = KMMemberInfo()
-
- var isLogin: Bool = false
-
-
- private var _refresh_token: String = ""
- private var _access_token: String = ""
- private var _token_type: String = ""
- private var _expires_in: String = ""
- private var _scope: String = ""
-
- var userID: String = ""
- var userEmail: String = ""
- var fullName: String = ""
- var _activeVips: [KMMemberUserInfoActiveVIP] = []
- var _activeAis: [KMMemberUserInfoActiveVIP] = []
- var vip_id: String = ""
- var vip_userId: String = ""
- var vip_status: Int = 0
- var vip_endDate: String = ""
- var vip_payType: Int = 0
- var vip_productName: String = ""
- var vip_levels: String = ""
- var vip_platforms: String = ""
- var vip_point: Int = 0
- var vip_maxDeviceNum: Int = 0
- var vip_paymentModel: String = ""
- var vip_isAi: String = ""
- var vip_cycle: Int = 0
- var ai_id: String = ""
- var ai_userId: String = ""
- var ai_status: Int = 0
- var ai_endDate: String = ""
- var ai_payType: Int = 0
- var ai_productName: String = ""
- var ai_levels: String = ""
- var ai_platforms: String = ""
- var ai_point: Int = 0
- var ai_maxDeviceNum: Int = 0
- var ai_paymentModel: String = ""
- var ai_isAi: String = ""
- var ai_cycle: Int = 0
- var aiPoint: Int = 0
- var validFlag: String = ""
- var isHaveAIDiscount: String = ""
- var canTrail: Bool = false
-
-
-
-
- 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 vip in _activeVips {
- if vip_levels == "" {
- 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 vip in _activeAis {
- if ai_levels == "" {
- 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
-
- 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()
- #if VERSION_FREE
- #if VERSION_DMG
-
- if KMMemberInfo.shared.isLogin {
-
- } else {
-
- }
- #else
-
- if KMMemberInfo.shared.isLogin {
- if KMMemberInfo.shared.canTrail &&
- KMMemberInfo.shared.vip_levels == "1" &&
- KMMemberInfo.shared.ai_productName == "" &&
- !IAPProductsManager.default().isAvailableAllFunction() &&
- !AIInfoManager.default().aiInfoValid {
-
- return .lite_type5
- } else if KMMemberInfo.shared.vip_status == 4 &&
- KMMemberInfo.shared.vip_levels == "1" &&
- KMMemberInfo.shared.ai_productName == "" &&
- !IAPProductsManager.default().isAvailableAllFunction() &&
- oldAIPoints > 0 {
-
- return .lite_type6
- } else if KMMemberInfo.shared.vip_paymentModel == "2" &&
- KMMemberInfo.shared.ai_productName != "" {
-
- return .lite_type7
- } else if KMMemberInfo.shared.vip_status == 1 &&
- KMMemberInfo.shared.vip_payType == 1 {
-
- return .lite_type8
- } else if KMMemberInfo.shared.vip_status == 1 &&
- KMMemberInfo.shared.vip_paymentModel == "1" &&
- KMMemberInfo.shared.vip_payType == 0 {
-
- return .lite_type9
- } else if KMMemberInfo.shared.vip_status == 2 {
-
- return .lite_type10
- } else if KMMemberInfo.shared.vip_status == 4 {
-
- return .lite_type11
- }
- } else {
- if IAPProductsManager.default().isAvailableAllFunction() {
- if AIInfoManager.default().aiInfoValid {
- return .lite_type3
- } else {
- return .lite_type4
- }
- } else {
- if AIInfoManager.default().aiInfoValid {
- return .lite_type2
- } else {
- return .lite_type1
- }
- }
- }
- #endif
- #else
-
-
-
-
-
-
-
-
- if KMMemberInfo.shared.isLogin {
-
- } else {
-
- }
- #endif
- return .null
- }
- }
-
-
- var isMemberAllFunction: Bool {
- get {
- if KMMemberInfo.shared.isLogin {
- if userScenarioType == .lite_type7 || userScenarioType == .lite_type8 || userScenarioType == .lite_type9 {
- return true
- }
- return false
- } else {
- if IAPProductsManager.default().isAvailableAllFunction() {
- return true
- }
- return false
- }
- }
- }
-
-
- var isPermitConvert: Bool {
- if KMMemberInfo.shared.isLogin {
- if userScenarioType == .lite_type7 || userScenarioType == .lite_type8 {
- return true
- }
- return false
- } else {
- if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
- return true
- }
- return false
- }
- }
-
-
- var isPermitAI: Bool {
- let oldAIPoints = AIInfoManager.default().aiInfo.totalToken - AIInfoManager.default().aiInfo.usedTimes
- if KMMemberInfo.shared.isLogin {
- if oldAIPoints > 0 {
- return true
- } else {
- if userScenarioType == .lite_type6 || userScenarioType == .lite_type7 || userScenarioType == .lite_type8 {
- if KMMemberInfo.shared.aiPoint > 0 {
- return true
- } else {
- return false
- }
- }
- return false
- }
- } else {
- if AIInfoManager.default().aiInfoValid && oldAIPoints > 0 {
- return true
- }
- return false
- }
- }
-
-
-
- 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 {
- if userScenarioType == .lite_type1 || userScenarioType == .lite_type2 {
- if KMMemberInfo.shared.isLogin {
- KMProductCompareWC.shared.orientation = true
- KMProductCompareWC.shared.orientationType = .trial
- KMProductCompareWC.shared.showWindow(nil)
- } else {
- KMLoginWindowsController.shared.openWindow() { success in
- if success {
- KMProductCompareWC.shared.orientation = true
- KMProductCompareWC.shared.orientationType = .trial
- KMProductCompareWC.shared.showWindow(nil)
- }
- }
- }
- } else if userScenarioType == .lite_type3 || userScenarioType == .lite_type4 {
-
- } else if userScenarioType == .lite_type5 {
- KMProductCompareWC.shared.orientation = true
- KMProductCompareWC.shared.orientationType = .trial
- KMProductCompareWC.shared.showWindow(nil)
- } else if userScenarioType == .lite_type6 {
- KMProductCompareWC.shared.orientation = true
- KMProductCompareWC.shared.orientationType = .lite_Base
- KMProductCompareWC.shared.showWindow(nil)
- } else if userScenarioType == .lite_type7 || userScenarioType == .lite_type8 || userScenarioType == .lite_type9 {
-
- } else if userScenarioType == .lite_type10 || userScenarioType == .lite_type11 {
- KMProductCompareWC.shared.orientation = true
- KMProductCompareWC.shared.orientationType = .lite_Base
- KMProductCompareWC.shared.showWindow(nil)
- }
- }
-
- func aiSubscription() -> Bool {
- let oldAIPoints = AIInfoManager.default().aiInfo.totalToken - AIInfoManager.default().aiInfo.usedTimes
- 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
- }
- }
- }
- }
|