123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- //
- // KMUserInfoVCModel.swift
- // PDF Reader Pro
- //
- // Created by wanjun on 2024/10/31.
- //
- import Foundation
- import Combine
- @objc enum memberEquityType : Int {
- case advancedSixMonthPlan = 0 // 高级版半年订阅
- case advancedYearMonthPlan // 高级版年订阅
- }
- typealias UserInfoComplete = (_ success: Bool,_ msg: String) -> Void
- @objcMembers
- class KMUserInfoVCModel: ObservableObject {
-
- /**
- @abstract 刷新个人权益
- @param
- */
- func refreshUserInfo(networkAlert: Bool = true ,_ complete: @escaping UserInfoComplete) -> Void {
- if KMMemberCenterManager.manager.isConnectionAvailable() == false && networkAlert {
- let alert = NSAlert()
- alert.alertStyle = .critical
- alert.messageText = NSLocalizedString("Error Information", comment: "")
- alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
- alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
- alert.runModal()
- return
- }
- KMMemberCenterManager.manager.userInfo { success, result in
- guard let result = result else { return }
- let resultDict = result as KMMemberCenterResult
- let msg = resultDict.msg
- let code = resultDict.code
- if success {
- let userInfo = resultDict.userInfo
- guard let userInfo = resultDict.userInfo else { return }
- KMMemberInfo.shared.memberUserInfo(model: userInfo)
- complete(true, "")
- } else {
- complete(false, "")
- if(code == 304) {
- KMMemberInfo.shared.clearMemberInfoCache()
- KMMemberInfo.shared.isLogin = false
- KMMemberInfo.shared.access_token = ""
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "MemberCenterLogoutSuccess"), object: nil)
- }
- }
- }
- }
-
- /**
- @abstract 根据用户支持的平台返回外部视图需要的平台图片数组
- @param
- */
- func getPlatformsImages() -> [NSImage] {
- var images: [NSImage] = []
- for platform in userPlatforms() {
- if KMMemberInfo.shared.userScenarioType == .lite_type4 ||
- KMMemberInfo.shared.userScenarioType == .lite_type5 ||
- KMMemberInfo.shared.userScenarioType == .lite_type6 ||
- KMMemberInfo.shared.userScenarioType == .lite_type8 ||
- KMMemberInfo.shared.userScenarioType == .lite_type12 ||
- KMMemberInfo.shared.userScenarioType == .lite_type13 ||
- KMMemberInfo.shared.userScenarioType == .pro_type2 ||
- KMMemberInfo.shared.userScenarioType == .pro_type4 ||
- (KMMemberInfo.shared.userScenarioType == .lite_type9 &&
- (KMMemberInfo.shared.vip_paymentModel == "2" && KMMemberInfo.shared.vip_levels != "1")) ||
- (KMMemberInfo.shared.userScenarioType == .pro_type1 &&
- (KMMemberInfo.shared.vip_paymentModel == "2" && KMMemberInfo.shared.vip_levels != "1")) ||
- KMMemberInfo.shared.userScenarioType == .pro_type5 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type5 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type6 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type7 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type28 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type29 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type30 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type43 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type44 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type45 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type8 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type9 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type10 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type12 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type13 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type14 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type15 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type16 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type17 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type20 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type21 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type23 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type24 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type25 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type26 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type27 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type31 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type32 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type35 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type36 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type38 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type39 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type40 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type41 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type42 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type46 ||
- KMMemberInfo.shared.userScenarioType == .dmg_type47 {
- if platform == "mac" {
- images.append(NSImage(named: "MacOSPlatformImage2")!)
- } else if platform == "ios" {
- images.append(NSImage(named: "iOSPlatformImage2")!)
- } else if platform == "windows" {
- images.append(NSImage(named: "WindowsPlatformImage2")!)
- } else if platform == "android" {
- images.append(NSImage(named: "AndroidPlatformImage2")!)
- }
- } else {
- if platform == "mac" {
- images.append(NSImage(named: "MacOSPlatformImage3")!)
- } else if platform == "ios" {
- images.append(NSImage(named: "iOSPlatformImage3")!)
- } else if platform == "windows" {
- images.append(NSImage(named: "WindowsPlatformImage3")!)
- } else if platform == "android" {
- images.append(NSImage(named: "AndroidPlatformImage3")!)
- }
- }
- }
- return images
- }
-
- /**
- @abstract 跳转官网用户中心;1、官网未登录,则跳转到登录页面;2、官网已登录,则跳转到官网-个人中心;
- */
- func skipAccountCenter() -> Void {
- var urlPath = ""
- #if DEBUG
- if kTestMode == 1{
- urlPath = "http://test-pdf-pro.kdan.cn:3021/user-center/account-benefits"
- } else {
- urlPath = "https://pdfreaderpro.com/user-center/account-benefits"
- }
- #else
- urlPath = "https://pdfreaderpro.com/user-center/account-benefits"
- #endif
- NSWorkspace.shared.open(URL(string: urlPath)!)
- }
-
- /**
- @abstract 退出登录;
- */
- func signOutAction() -> Void {
- NotificationCenter.default.post(name: NSNotification.Name("CloseMenuNotification"), object: nil)
- KMMemberPromptWC.shared.showWindow(nil)
- KMMemberPromptWC.shared.tipType = .logout
- }
-
- /**
- @abstract 注销账户;
- */
- func closeAccountAction() -> Void {
- if KMMemberCenterManager.manager.isConnectionAvailable() == false {
- let alert = NSAlert()
- alert.alertStyle = .critical
- alert.messageText = NSLocalizedString("Error Information", comment: "")
- alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
- alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
- alert.runModal()
- return
- }
- if KMMemberInfo.shared.validFlag == "5" {
- // 撤销注销申请
- KMMemberCenterManager.manager.userRevokeCancel { success, result in
- guard let result = result else { return }
- let resultDict = result as KMMemberCenterResult
- let msg = resultDict.msg
- if success {
- self.refreshUserInfo { success, msg in
- KMMemberPromptWC.shared.showWindow(nil)
- KMMemberPromptWC.shared.tipType = .cancelSignout
- }
- } else {
- print(msg as Any)
- }
- }
- } else {
- if (KMMemberInfo.shared.vip_paymentModel == "1" && KMMemberInfo.shared.vip_status == 1) || (KMMemberInfo.shared.ai_status == 1 && KMMemberInfo.shared.ai_paymentModel == "1") {
- // 订阅用户提示退订
- NotificationCenter.default.post(name: NSNotification.Name("CloseMenuNotification"), object: nil)
- KMMemberPromptWC.shared.showWindow(nil)
- KMMemberPromptWC.shared.tipType = .unsubscribe
- } else {
- // 手动注销
- NotificationCenter.default.post(name: NSNotification.Name("CloseMenuNotification"), object: nil)
- KMMemberPromptWC.shared.showWindow(nil)
- KMMemberPromptWC.shared.tipType = .signout
- }
- }
- }
-
- /**
- @abstract 展开个人中心;
- */
- func expandPersonalCenter() -> Void {
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "ExpandPersonalCenter"), object: nil)
- }
-
- /**
- @abstract 确认退出;
- */
- func confirmExitAction() -> Void {
- if KMMemberCenterManager.manager.isConnectionAvailable() == false {
- let alert = NSAlert()
- alert.alertStyle = .critical
- alert.messageText = NSLocalizedString("Error Information", comment: "")
- alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
- alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
- alert.runModal()
- return
- }
- KMMemberCenterManager.manager.userLogout { success, result in
- guard let result = result else { return }
- let resultDict = result as KMMemberCenterResult
- let msg = resultDict.msg
- if success {
- let islogout: Bool = resultDict.result!
- if islogout {
- KMMemberInfo.shared.clearMemberInfoCache()
- KMMemberInfo.shared.isLogin = false
- KMMemberInfo.shared.access_token = ""
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "MemberCenterLogoutSuccess"), object: nil)
- }
- } else {
- print(msg as Any)
- }
- }
- }
-
- /**
- @abstract 注销账户 警告弹窗;
- */
- func closeAccountWarningWC() -> Void {
- KMCloseAccountWC.shared.showWindow(nil)
- }
-
- /**
- @abstract 删除我的账户 弹窗;
- */
- func deleteAccountWC() -> Void {
- KMCloseVerificationWC.shared.showWindow(nil)
- }
-
- /**
- @abstract 注销账户申请 弹窗;
- */
- func closeAccountApplyWC(code: String,callback: ((Bool?, KMMemberCenterResult?)->Void)?) -> Void {
- if KMMemberCenterManager.manager.isConnectionAvailable() == false {
- let alert = NSAlert()
- alert.alertStyle = .critical
- alert.messageText = NSLocalizedString("Error Information", comment: "")
- alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
- alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
- alert.runModal()
-
- callback?(false,nil)
- return
- }
- KMMemberCenterManager.manager.userLogOffForUser(code: code) { success, result in
- guard let result = result else { return }
- let resultDict = result as KMMemberCenterResult
- callback?(success,resultDict)
- }
- }
-
- /**
- @abstract 跳转比较表;
- */
- func skipCompare(_ type: KMCompareTableType) -> Void {
- KMProductCompareWC.shared.orientation = true
- KMProductCompareWC.shared.orientationType = type
- KMProductCompareWC.shared.showWindow(nil)
- }
-
- /**
- @abstract 购买全平台年订阅;
- */
- func buyFullPlatformSubscription(_ type: memberEquityType) -> Void {
- if type == .advancedSixMonthPlan {
- IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite, discount: IAPProductsManager.default().isCancelAutoRenew())
- } else if type == .advancedYearMonthPlan {
- IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite, discount: IAPProductsManager.default().isCancelAutoRenew())
- }
- }
-
- // MARK: Private Method
-
- /**
- @abstract 获取用户支持的最大设备数
- @param
- */
- private func maxDeviceNum() -> Int {
- return KMMemberInfo.shared.vip_maxDeviceNum
- }
-
- /**
- @abstract 用户支持的平台
- @param
- */
- private func userPlatforms() -> [String] {
- let platforms = KMMemberInfo.shared.vip_platforms
- let platformsArray = platforms
- .components(separatedBy: ",")
- .map { $0.trimmingCharacters(in: .whitespaces) }
-
-
- let containsMac = platforms.contains("mac")
- let containsiOS = platforms.contains("ios")
- let containsWin = platforms.contains("windows")
- let containsAn = platforms.contains("android")
- var newPlatforms:[String] = []
- if(containsMac == true){
- newPlatforms.append("mac")
- }
-
- if(containsWin == true){
- newPlatforms.append("windows")
- }
-
- if(containsiOS == true){
- newPlatforms.append("ios")
- }
-
- if(containsAn == true){
- newPlatforms.append("android")
- }
- return newPlatforms
- }
- }
|