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

【会员系统】DMG 购买结算界面 批量购买 商品价格串接

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

+ 88 - 2
PDF Office/PDF Master/Class/Purchase/DMG/KMPurchaseEmbeddedWindowController.swift

@@ -240,6 +240,7 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
     private var isApplyCoupon: Bool = false
     
     private var isWindowDidLoad: Bool = false
+    private var isBatchProductPriceGetFinsed: Bool = false
 
     @objc static func currentWC(_ productInfo: KMListingProductsModel) -> KMPurchaseEmbeddedWindowController {
         if currentWindowController != nil {
@@ -697,6 +698,9 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
     }
     
     private func priceRefresh(productsModel: KMListingProductsModel) -> Void {
+        if productsModel.code == "" {
+            return
+        }
         var listPrice: Float = 0.0
         var discount: Float = 0.0
         var paySum: Float = 0.0
@@ -756,7 +760,6 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
         
         if _dmgProductType == .advanced_annual_subscription  ||
            _dmgProductType == .standard_annual_subscription  ||
-           _dmgProductType == .advanced_permanent  ||
            _dmgProductType == .ai_subscription_month {
             // 全平台高级版年订阅             99.9 美金,无试用
             // 全平台标准版年订阅             79.9 美金
@@ -801,6 +804,56 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
             discount = listPrice - paySum
         }
         
+        if _dmgProductType == .advanced_permanent {
+            // 全平台高级版年订阅             99.9 美金,无试用
+            // 全平台标准版年订阅             79.9 美金
+            // Mac & Win 双平台高级永久      119.99 美金
+            // AI 月订阅                    14.99 美金
+            aiAddOnView.isHidden = true
+            extendedView.isHidden = true
+            
+            var tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
+            if product_Info.cycle == 4 {
+                tipsString = NSLocalizedString("%.2@/year, auto-renewal", comment: "")
+            }
+            if product_Info.cycle == 3 {
+                tipsString = NSLocalizedString("%.2@/half a year, auto-renewal", comment: "")
+            }
+            if product_Info.cycle == 2 {
+                tipsString = NSLocalizedString("%.2@/quarter, auto-renewal", comment: "")
+            }
+            if product_Info.cycle == 1 {
+                tipsString = NSLocalizedString("%.2@/monthly, auto-renewal", comment: "")
+            }
+            if product_Info.cycle == 0 {
+                tipsString = NSLocalizedString("%.2@, One time purchase.", 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)
+            }
+            
+            prmiumLabel.stringValue = String(format: "%@ %@", abbreviation, fullString)
+            
+            discount1 = product_Info.price.floatValue //优惠价格拿原价
+            if pdfCount > 1 , isBatchProductPriceGetFinsed {
+                discount1 = product_Info.displayPrice.floatValue //优惠价格拿更新后的批量价格
+            }
+            original1 = product_Info.price.floatValue
+            if preferredLanguage.hasPrefix("zh-Hans") || preferredLanguage.hasPrefix("zh-Hant") {
+                discount1 = product_Info.cnyPrice.floatValue  //优惠价格拿原价
+                if pdfCount > 1 , isBatchProductPriceGetFinsed {
+                    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
@@ -1149,7 +1202,40 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
         }
         
         // 价格刷新
-        priceRefresh()
+        priceRefresh(productsModel: _product_Info)
+        
+        let model = KMProductModel.shared
+        isBatchProductPriceGetFinsed = false
+        model.getDMGBatchProductPriceInfosForMember(productId: _product_Info.id, num: pdfCount) { [weak self] success, result in
+            guard let pricesArrays : KMMemberProductResult = result else {
+                return
+            }
+            guard let batchProductPrice : KMBatchProductPriceModel = pricesArrays.batchProductPrice else {
+                return
+            }
+            //原价更新
+            let priceString = batchProductPrice.price
+            if let priceDouble = Double(priceString) {
+                self?.product_Info.price = NSNumber(value: priceDouble)
+            }
+            
+            let cnyPriceString = batchProductPrice.cnyPrice
+            if let cnyPriceDouble = Double(cnyPriceString) {
+                self?.product_Info.cnyPrice = NSNumber(value: cnyPriceDouble)
+            }
+            
+            let batchPriceString = batchProductPrice.batchPrice
+            if let batchPriceDouble = Double(batchPriceString) {
+                self?.product_Info.displayPrice = NSNumber(value: batchPriceDouble)
+            }
+            
+            let cnyBatchPriceString = batchProductPrice.cnyBatchPrice
+            if let cnyBatchPriceDouble = Double(cnyBatchPriceString) {
+                self?.product_Info.displayCnyPrice = NSNumber(value: cnyBatchPriceDouble)
+            }
+            self?.isBatchProductPriceGetFinsed = true
+            self?.priceRefresh(productsModel: self?.product_Info ?? KMListingProductsModel())
+        }
     }
     
     @IBAction func aiAddOnButtonAction(_ sender: NSButton) {