Procházet zdrojové kódy

【综合】登陆逻辑调整

tangchao před 3 měsíci
rodič
revize
f21c5aa7ec

+ 34 - 0
PDF Office/PDF Master/MemberCenter/Model/KMMemberInfo.swift

@@ -1214,4 +1214,38 @@ import Cocoa
         isHaveAIDiscount = ""
         canTrail = false
     }
+    
+    /**
+     @abstract 用户支持的平台
+     */
+    
+    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
+    }
 }

+ 24 - 3
PDF Office/PDF Master/MemberCenter/WindowsController/KMLoginWindowsController.swift

@@ -23,6 +23,7 @@ class KMLoginWindowsController: NSWindowController {
     var memberInfo: KMMemberInfo = KMMemberInfo.shared
     
     var signUpView: KMSignUpView?
+    var signUpViewNew: KMSignUpView?
     
     var loginResult: LoginResultComplete?
     
@@ -32,6 +33,8 @@ class KMLoginWindowsController: NSWindowController {
             return subscribeType_
         }
     }
+    private var product_: IAPProduct?
+    private var needDiscount_: Bool = false
     
     private var viewModel = KMSignUpViewModel()
     private var cancellables = Set<AnyCancellable>()
@@ -68,6 +71,8 @@ class KMLoginWindowsController: NSWindowController {
         
         subscribeType_ = nil
         signUpView?.type = nil
+        product_ = nil
+        needDiscount_ = false
         _trackSignInEvent(params: ["Exposure" : "Exposure_Signin"])
         
         loginResult = nil
@@ -96,6 +101,7 @@ class KMLoginWindowsController: NSWindowController {
             signUpView.frame = rightBox.frame
             rightBox.contentView = signUpView
             rightBox.fillColor = NSColor(named: "membercentercolor") ?? NSColor.white
+            signUpViewNew = signUpView
             
             signUpView.sendCodeBlock = { [weak self] _ in
                 self?._trackSignInEvent(params: ["Btn" : "Btn_SendCode"])
@@ -125,8 +131,18 @@ class KMLoginWindowsController: NSWindowController {
                     }
                 }
             }
-            signUpView.buyBlock = { _ in
-                KMPrint("Buy ...")
+            signUpView.buyBlock = { [weak self] _ in
+                guard let theProduct = self?.product_ else {
+                    NSSound.beep()
+                    return
+                }
+                
+                if theProduct.isEqual(to: IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite) || theProduct.isEqual(to: IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite) {
+                    IAPProductsManager.default().makeSubProduct(theProduct, discount: self?.needDiscount_ ?? false)
+                    return
+                } else {
+                    IAPProductsManager.default().makeSubProduct(theProduct, discount: self?.needDiscount_ ?? false)
+                }
             }
         }
     }
@@ -199,13 +215,18 @@ class KMLoginWindowsController: NSWindowController {
         loginResult = complete
     }
     
-    func newOpenWindow(type: KMSubscribeWaterMarkType?, _ complete: @escaping LoginResultComplete) -> Void {
+    func newOpenWindow(type: KMSubscribeWaterMarkType?, product: IAPProduct?, needDiscount: Bool, _ complete: @escaping LoginResultComplete) -> Void {
         openWindow(complete)
         
         subscribeType_ = type
         signUpView?.type = type
+        signUpViewNew?.type = type
+        product_ = product
+        needDiscount_ = needDiscount
+        
         DispatchQueue.main.async {
             self.signUpView?.updateUI()
+            self.signUpViewNew?.updateUI()
         }
     }
     

+ 127 - 3
PDF Office/PDF Master/MemberCenter/WindowsController/KMProductCompareWC.swift

@@ -1212,12 +1212,77 @@ class KMProductCompareWC: NSWindowController {
 #endif
     }
     
+    private func _loginAfterAction() {
+        let info = KMMemberInfo.shared
+        var expired = info.vip_status == 2 || info.vip_status == 4
+        let state = info.userScenarioType
+        let platforms = info.userPlatforms()
+        let vip_levels = info.vip_levels
+        let vip_paymentModel = info.vip_paymentModel
+        
+        if platforms.count == 1 && platforms.first == "ios" && info.vip_levels == "3" && vip_paymentModel == "2" { // ios单平台高级版永久账户
+            KMMemberInfo.shared.productCompareShow()
+            return
+        } else if platforms.count == 1 && platforms.first == "mac" { // Mac 单平台高级版永久账户
+            // 关闭比较表,可以直接使用高级功能
+            window?.close()
+            return
+        } else if platforms.count == 2 && platforms.contains("windows") && platforms.contains("mac") && vip_paymentModel == "2" { // Mac & Windows 双平台高级永久账户
+            // 关闭比较表,可以直接使用高级功能
+            window?.close()
+            return
+        } else if platforms.count == 1 && platforms.first == "android" && info.vip_levels == "3" && vip_paymentModel == "1" { // Android单平台高级版月订阅账户
+            // 关闭比较表,可以直接使用高级功能
+            let alert = NSAlert()
+            alert.alertStyle = .critical
+            alert.informativeText = NSLocalizedString("Sorry, you do not have the rights to this paid feature and cannot use it. If you have any questions, please contact customer service at support@pdfreaderpro.com", comment: "")
+            alert.addButton(withTitle: NSLocalizedString("Got it", comment: ""))
+            alert.runModal()
+            
+            window?.close()
+            return
+            
+        } else if platforms.count == 4 && vip_levels == "2" && vip_paymentModel == "1" { // 全平台标准版年订阅账户 不支持升级,关闭比较表,可以直接使用非转档的高级功能
+            let alert = NSAlert()
+            alert.alertStyle = .critical
+            alert.informativeText = NSLocalizedString("Sorry, you do not have the rights to this paid feature and cannot use it. If you have any questions, please contact customer service at support@pdfreaderpro.com", comment: "")
+            alert.addButton(withTitle: NSLocalizedString("Got it", comment: ""))
+            alert.runModal()
+            
+            window?.close()
+            return
+        }
+    }
+    
     // MARK: Button Actions
     
     @IBAction func buttonItemClicked_Subscribe(_ sender: Any) {
         if KMIsAppStoreFreeVersion() && subscribeType != nil && KMMemberInfo.shared.isLogin == false { // AppStore 免费版 + 付费功能进入 + 未登陆,跳转登陆
-            KMLoginWindowsController.shared.newOpenWindow(type: subscribeType) { success in
+            var product = IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite
+            if model.isPurchaseSwitch {
+                product = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite
+            }
+            KMLoginWindowsController.shared.newOpenWindow(type: subscribeType, product: product, needDiscount: model.isCancelAutoRenew) { success in
+                if KMMemberInfo.shared.isLogin == false {
+                    return
+                }
                 
+                let info = KMMemberInfo.shared
+                var expired = info.vip_status == 2 || info.vip_status == 4
+                let state = info.userScenarioType
+                let platforms = info.userPlatforms()
+                let vip_levels = info.vip_levels
+                let vip_paymentModel = info.vip_paymentModel
+                if info.vip_levels == "1" || expired {
+                    if self.model.isPurchaseSwitch { // 免费账户/订阅过期账户
+                        IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite, discount: self.model.isCancelAutoRenew)
+                    } else {
+                        IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite, discount: self.model.isCancelAutoRenew)
+                    }
+                    return
+                } else {
+                    self._loginAfterAction()
+                }
             }
             return
         }
@@ -1338,14 +1403,73 @@ class KMProductCompareWC: NSWindowController {
             KMMemberPromptWC.shared.tipType = .signouting
         } else {
 #if !VERSION_DMG
-        addWaitingView(to: window?.contentView ?? NSView())
+//        addWaitingView(to: window?.contentView ?? NSView())
 #endif
             if KMIsAppStoreFreeVersion() && subscribeType != nil && KMMemberInfo.shared.isLogin == false { // AppStore 免费版 + 付费功能进入 + 未登陆,跳转登陆
-                KMLoginWindowsController.shared.newOpenWindow(type: subscribeType) { success in
+                let state = model.state
+                let tag = sender.tag
+                var product: IAPProduct?
+                let isPurchaseSwitch = model.isPurchaseSwitch
+                if state == .lite_Base {
+                    if tag == 0 {
+                        if isPurchaseSwitch {
+                            product = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite
+                        } else {
+                            product = IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite
+                        }
+                    } else if tag == 3 {
+                        product = IAPProductsManager.default().allAccessPackPermanent_lite
+                    } else {
+                        product = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite
+                    }
+                } else if state == .lite_MacWindows {
+                    if tag == 2 {
+                        let platforms = KMMemberInfo.shared.vip_platforms
+                        let platformsArray = platforms
+                            .components(separatedBy: ",")
+                            .map { $0.trimmingCharacters(in: .whitespaces) }
+                        if KMMemberInfo.shared.userScenarioType == .lite_type5 {
+                            if platformsArray.count == 1 {
+                                product = IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_lite
+                            } else if platformsArray.count == 2 {
+                                product = IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite
+                            }
+                        } else {
+                            if platformsArray.count == 1 {
+                                product = IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_lite
+                            } else if platformsArray.count == 2 {
+                                product = IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite
+                            } else {
+                                product = IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite
+                            }
+                        }
+                    }
+                }
+                
+                KMLoginWindowsController.shared.newOpenWindow(type: subscribeType, product: product, needDiscount: model.isCancelAutoRenew) { success in
+                    if KMMemberInfo.shared.isLogin == false {
+                        return
+                    }
                     
+                    let info = KMMemberInfo.shared
+                    var expired = info.vip_status == 2 || info.vip_status == 4
+                    let state = info.userScenarioType
+                    let platforms = info.userPlatforms()
+                    let vip_levels = info.vip_levels
+                    let vip_paymentModel = info.vip_paymentModel
+                    if info.vip_levels == "1" || expired {
+                        self.model.appstorePurchaseAction(sender.tag) { [weak self] success, msg in
+                            
+                        }
+                        return
+                    } else {
+                        self._loginAfterAction()
+                        return
+                    }
                 }
                 return
             }
+            addWaitingView(to: window?.contentView ?? NSView())
             model.appstorePurchaseAction(sender.tag) { [weak self] success, msg in
                 guard let self = self else { return }
             }