فهرست منبع

【dmg】价格购买逻辑

wangshuai 3 روز پیش
والد
کامیت
2c75400e6d
1فایلهای تغییر یافته به همراه87 افزوده شده و 44 حذف شده
  1. 87 44
      PDF Office/PDF Master/Class/Purchase/DMG/KMPurchaseEmbeddedWindowController.swift

+ 87 - 44
PDF Office/PDF Master/Class/Purchase/DMG/KMPurchaseEmbeddedWindowController.swift

@@ -527,13 +527,17 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
             if NSLocalizedString("USD", comment: "") == "CNY" {
                 abbreviation = "CNY"
             }
-        }
-        if self.paymentMethod == .alipay {
+        } else if self.paymentMethod == .alipay {
+            if NSLocalizedString("USD", comment: "") == "CNY" {
+                abbreviation = "CNY"
+            }
+        }  else if self.paymentMethod == .paddle ||  self.paymentMethod == .paypal {
             if NSLocalizedString("USD", comment: "") == "CNY" {
                 abbreviation = "CNY"
             }
         }
-        let insting = Float(_product_Info.individualPriceString ?? "0") ?? 0
+        
+        let insting = Float(showSinglePriceString() ?? "0") ?? 0
         
         listPrice = Float(String(format: "%.2f", insting)) ?? 0  //单价*购买个数
         
@@ -757,45 +761,64 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
             return
         }
         
+        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
+        }
+        
         self.refreshCouponError(isReveal: false)
         applyButton.isEnabled = false
         coupomTextField.isEnabled = false
         
+        window?.showWaitingView()
         KMMemberCenterManager.manager.checkCoupon(productId: product_Info.id, userId: KMMemberInfo.shared.userID, code: coupomTextField.stringValue) {[weak self] success, result in
-            if(success == true) {
-                
-                guard let productResult : KMMemberProductResult = result else {
-                    return
-                }
-                guard let couponModel : KMCheckCouponModel = productResult.checkCoupon else {
-                    return
-                }
-
-                let priceString = couponModel.priceString
-                self?.product_Info.priceString = priceString
-                
-                let cnyPriceString = couponModel.cnyPriceString
-                self?.product_Info.cnyPriceString = cnyPriceString //批量时将总价赋给priceString,只显示priceString价格了,其他的置空
-                
-                self?.product_Info.upgradePriceString = couponModel.upgradePriceString
-                self?.product_Info.displayPriceString = couponModel.displayPriceString
-                self?.product_Info.displayCnyPriceString = couponModel.displayCnyPriceString
-                
-                self?.product_Info.individualPriceString = couponModel.priceString
-                self?.product_Info.individualCnyPriceString = couponModel.cnyPriceString
-                self?.product_Info.verifyofferCode = self?.coupomTextField.stringValue ?? ""
-
-                self?.priceRefresh(productsModel: self?._product_Info ?? KMListingProductsModel())
-            }else {
-                let alert = NSAlert()
-                alert.alertStyle = .critical
-                alert.messageText = NSLocalizedString("Error Information", comment: "")
-                alert.informativeText = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
-                alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
-                alert.addButton(withTitle: NSLocalizedString("Cancel", comment: ""))
-                let result = alert.runModal()
-                if (result == .alertFirstButtonReturn) {
-                    self?.applyButtonAction(sender)
+            self?.window?.hideWaitingView()
+            
+            KMMainThreadExecute {
+                if(success == true) {
+                    let alert = NSAlert()
+                    alert.alertStyle = .critical
+                    alert.messageText = NSLocalizedString("Successfully", comment: "")
+                    _ = alert.runModal()
+                    
+                    guard let productResult : KMMemberProductResult = result else {
+                        return
+                    }
+                    guard let couponModel : KMCheckCouponModel = productResult.checkCoupon else {
+                        return
+                    }
+                    
+                    let priceString = couponModel.priceString
+                    self?.product_Info.priceString = priceString
+                    
+                    let cnyPriceString = couponModel.cnyPriceString
+                    self?.product_Info.cnyPriceString = cnyPriceString //批量时将总价赋给priceString,只显示priceString价格了,其他的置空
+                    
+                    self?.product_Info.upgradePriceString = couponModel.upgradePriceString
+                    self?.product_Info.displayPriceString = couponModel.displayPriceString
+                    self?.product_Info.displayCnyPriceString = couponModel.displayCnyPriceString
+                    
+                    self?.product_Info.individualPriceString = couponModel.priceString
+                    self?.product_Info.individualCnyPriceString = couponModel.cnyPriceString
+                    self?.product_Info.verifyofferCode = self?.coupomTextField.stringValue ?? ""
+                    
+                    self?.priceRefresh(productsModel: self?._product_Info ?? KMListingProductsModel())
+                }else {
+                    let alert = NSAlert()
+                    alert.alertStyle = .critical
+                    alert.messageText = NSLocalizedString("Error Information", comment: "")
+                    alert.informativeText = NSLocalizedString("The coupon code is invalid. Please try again.", comment: "")
+                    alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
+                    alert.addButton(withTitle: NSLocalizedString("Cancel", comment: ""))
+                    let result = alert.runModal()
+                    if (result == .alertFirstButtonReturn) {
+                        self?.applyButtonAction(sender)
+                    }
                 }
             }
             
@@ -1202,27 +1225,47 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
         let preferredLanguage = Locale.preferredLanguages.first ?? "en"
         var priceString = product_Info.priceString ?? ""
         if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
-            priceString = product_Info.priceString ?? ""
-        } else {
             priceString = product_Info.cnyPriceString ?? ""
+        } else {
+            priceString = product_Info.priceString ?? ""
         }
 
         return priceString
     }
     
-    func showsinglePriceString()->String { //单价
+    func showOrgShowPriceString()->String { //实际购买显示的价格
         let preferredLanguage = Locale.preferredLanguages.first ?? "en"
         var priceString = product_Info.priceString ?? ""
+        if(product_Info.upgradePriceString?.isEmpty == false) {
+            priceString = product_Info.upgradePriceString ?? ""
+        } else if(product_Info.displayPriceString?.isEmpty == false) {
+            if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
+                priceString = product_Info.displayCnyPriceString ?? ""
+            } else {
+                priceString = product_Info.displayPriceString ?? ""
+            }
+        } else if(product_Info.priceString?.isEmpty == false) {
+            if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
+                priceString = product_Info.cnyPriceString ?? ""
+            } else {
+                priceString = product_Info.priceString ?? ""
+
+            }
+        }
+        return priceString
+    }
+    
+    func showSinglePriceString()->String { //单价
+        let preferredLanguage = Locale.preferredLanguages.first ?? "en"
+        var priceString = product_Info.individualPriceString ?? ""
         if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
-            priceString = product_Info.individualPriceString ?? ""
-        } else {
             priceString = product_Info.individualCnyPriceString ?? ""
+        } else {
+            priceString = product_Info.individualPriceString ?? ""
         }
 
         return priceString
     }
-
-
     
     func showPayPriceString()->String { //实际支付的价格
         let iswechatOrAlipayPay = (self.paymentMethod == .wxpay || self.paymentMethod == .alipay)