Переглянути джерело

【会员系统】DMG 购买结算界面商品展示串接

zenghong 1 тиждень тому
батько
коміт
404bcbc750

+ 90 - 25
PDF Office/PDF Master/Class/Purchase/DMG/KMPurchaseEmbeddedWindowController.swift

@@ -275,10 +275,33 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
         
         xibInitialization()
         paymentMethod = .paypal
-        priceRefresh()
+        priceRefresh(productsModel: product_Info)
         
         confirmPayment(isConfirm: false)
         self.window?.delegate = self;
+        
+        if KMMemberInfo.shared.isLogin {
+            let model = KMProductModel()
+            model.getDMGProductPriceInfosForMember(productId: product_Info.id, isEducation: 0) { [weak self] success, result in
+                if success {
+                    guard let productResults : KMMemberProductResult = result else {
+                        return
+                    }
+                    guard let products : [KMListingProductsModel] = productResults.listingProducts else {
+                        return
+                    }
+                    guard let product : KMListingProductsModel = products.first else {
+                        return
+                    }
+                    self?.product_Info = product;
+                    for tProduct in products {
+                        if tProduct.id == self?.product_Info.id {
+                            self?.product_Info = tProduct;
+                        }
+                    }
+                }
+            }
+        }
     }
     
     override func close() {
@@ -316,33 +339,31 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
         refreshLicenseCodeView(isReveal: false)
         usualAddCountView.isHidden = isMoreCountViewShouldHidden(product_Info)
         
+        oneLicenseLabel.stringValue = NSLocalizedString("and more offline. It's one time purchase.", comment: "")
+        oneLicenseLabel.isHidden = true
+        
+        licenseCodeLabel.stringValue = NSLocalizedString("License Code", comment: "")
+        licenseCodeLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
+        licenseCodeLabel.font = NSFont.SFProTextRegularFont(14.0)
+        licenseCodeTextField.placeholderString = NSLocalizedString("Input license code previously activated the app", comment: "")
+        licenseCodeTextField.delegate = self
+        licenseCodeBox.borderColor = NSColor(named: "KMPurchase_DADBDE")!
+        licenseCodeBox.fillColor = NSColor(named: "KMPurchase_FFFFFF")!
+        notFoundButton.title = NSLocalizedString("Not Found?", comment: "")
+        notFoundButton.setTitleColor(color: NSColor(named: "KMPurchaseCouponColor")!, font: NSFont(name: "body-s-regular", size: 14))
+        licenseCodeTextField.stringValue = VerificationManager.default().originLicenseCode ?? ""
+        refreshLicenseCodeView(isReveal: true)
+        licenseCodeErrorLabel.stringValue = NSLocalizedString("Please enter right license code. How to Retrieve License.", comment: "")
+        licenseCodeErrorLabel.textColor = NSColor(named: "KMPurchaseErrorColor")
+        licenseCodeErrorLabel.font = NSFont.SFProTextRegularFont(11.0)
+        refreshLicenseCodeErrorView(isReveal: false)
+        
         if _dmgProductType == .advanced_annual_subscription_trail {
             aiAddOnView.isHidden = true
             extendedView.isHidden = true
             
-            pdfReaderProLabel.stringValue = NSLocalizedString("PDF Reader Pro Standard - Annual Plan", comment: "")
-            
-            let tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
-            let fullString = String(format: tipsString, product_Info.price)
-            prmiumLabel.stringValue = fullString
-            
-            
-//            oneLicenseLabel.stringValue = NSLocalizedString("and more offline. It's one time purchase.", comment: "")
-            licenseCodeLabel.stringValue = NSLocalizedString("License Code", comment: "")
-            licenseCodeLabel.textColor = NSColor(named: "KMPurchaseTitleColor1")
-            licenseCodeLabel.font = NSFont.SFProTextRegularFont(14.0)
-            licenseCodeTextField.placeholderString = NSLocalizedString("Input license code previously activated the app", comment: "")
-            licenseCodeTextField.delegate = self
-            licenseCodeBox.borderColor = NSColor(named: "KMPurchase_DADBDE")!
-            licenseCodeBox.fillColor = NSColor(named: "KMPurchase_FFFFFF")!
-            notFoundButton.title = NSLocalizedString("Not Found?", comment: "")
-            notFoundButton.setTitleColor(color: NSColor(named: "KMPurchaseCouponColor")!, font: NSFont(name: "body-s-regular", size: 14))
-            licenseCodeTextField.stringValue = VerificationManager.default().originLicenseCode ?? ""
-            refreshLicenseCodeView(isReveal: true)
-            licenseCodeErrorLabel.stringValue = NSLocalizedString("Please enter right license code. How to Retrieve License.", comment: "")
-            licenseCodeErrorLabel.textColor = NSColor(named: "KMPurchaseErrorColor")
-            licenseCodeErrorLabel.font = NSFont.SFProTextRegularFont(11.0)
-            refreshLicenseCodeErrorView(isReveal: false)
+            let productName = product_Info.productName
+            pdfReaderProLabel.stringValue = productName
         }
         
         
@@ -588,6 +609,50 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
         emailErrorLabel(isReveal: false)
     }
     
+    private func priceRefresh(productsModel: KMListingProductsModel) -> Void {
+        if _dmgProductType == .advanced_annual_subscription_trail {
+            aiAddOnView.isHidden = true
+            extendedView.isHidden = true
+            
+            let tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
+            var fullString = String(format: tipsString, product_Info.price)
+            let preferredLanguage = Locale.preferredLanguages.first ?? "en"
+            if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
+                fullString = String(format: tipsString, product_Info.cnyPrice)
+            }
+            var abbreviation = "USD"
+            if NSLocalizedString("USD", comment: "") == "CNY" {
+                abbreviation = "CNY"
+            }
+            
+            prmiumLabel.stringValue = String(format: "%@ %@", abbreviation, fullString)
+            
+            var listPrice: Float = 0.0
+            var discount: Float = 0.0
+            var paySum: Float = 0.0
+            var discount1: Float = product_Info.displayPrice.floatValue
+            var original1: Float = product_Info.price.floatValue
+            if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
+                discount1 = product_Info.displayCnyPrice.floatValue
+                original1 = product_Info.cnyPrice.floatValue
+            }
+            listPrice = original1 * Float(amountTextField1.stringValue)!
+            paySum = discount1 * Float(amountTextField1.stringValue)!
+            discount = listPrice - paySum
+            
+            originalPriceLabel1.stringValue = String(format: "%@ %@", abbreviation, String(format: "%.2f", discount1))
+            if String(format: "%.2f", original1) == String(format: "%.2f", discount1) {
+                discountPriceLabel1.isHidden = true
+            } else {
+                discountPriceLabel1.isHidden = false
+                let attributedString = NSMutableAttributedString(string: String(format: "%.2f", original1))
+                attributedString.addAttribute(.strikethroughStyle, value: NSNumber(value: NSUnderlineStyle.single.rawValue), range: NSMakeRange(0, attributedString.length))
+                attributedString.addAttribute(.strikethroughColor, value: NSColor(named: "KMPurchaseDiscountColor") as Any, range: NSMakeRange(0, attributedString.length))
+                discountPriceLabel1.attributedStringValue = attributedString
+            }
+        }
+    }
+    
     private func priceRefresh() -> Void {
         if KMDMGProductsManager.shareInstance.productDatas == nil {
             let alert = NSAlert()
@@ -1247,7 +1312,7 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
         set {
             _product_Info = newValue
             xibInitialization()
-            priceRefresh()
+            priceRefresh(productsModel: _product_Info)
             
             confirmPayment(isConfirm: false)
         }