123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- //
- // 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(_ complete: @escaping UserInfoComplete) -> 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.userInfo { success, result in
- guard let result = result else { return }
- let resultDict = result as KMMemberCenterResult
- let msg = resultDict.msg
- if success {
- let userInfo = resultDict.userInfo
- guard let userInfo = resultDict.userInfo else { return }
- KMMemberInfo.shared.memberUserInfo(model: userInfo)
- complete(true, "")
- } else {
- complete(false, "")
- }
- }
- }
-
- /**
- @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_type1 ||
- KMMemberInfo.shared.userScenarioType == .pro_type2 ||
- KMMemberInfo.shared.userScenarioType == .pro_type3 {
- 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_status == 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.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) -> 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.userLogOffForUser(code: code) { success, result in
- guard let result = result else { return }
- let resultDict = result as KMMemberCenterResult
- let msg = resultDict.msg
- if success {
- let logOff: KMMemberLogOff = resultDict.logOff!
- if let token = logOff.currentTime { KMCloseApplyWC.shared.currentTime = token }
- if let token = logOff.logOffTime { KMCloseApplyWC.shared.logOffTime = token }
- KMCloseApplyWC.shared.showWindow(nil)
- } else {
- print(msg as Any)
- }
- }
- }
-
- /**
- @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) }
- return platformsArray
- }
- }
|