فهرست منبع

Merge branch 'develop_PDFReaderPro_V4.7.0' of git.kdan.cc:Mac_PDF/PDF_Office into develop_PDFReaderPro_V4.7.0

niehaoyu 1 هفته پیش
والد
کامیت
45aef70628

+ 103 - 53
PDF Office/PDF Master/Class/Purchase/DMG/KMPurchaseEmbeddedWindowController.swift

@@ -1626,7 +1626,54 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
                              discountFlag: getOneTimePurchaseDiscountFlag(),
                              couponCode: couponCode,
                              num: pdfCount) { success, result in
-                //写定时器查询结果
+                if success {
+                    if let dataInfo = result {
+                        self.orderID = result?.createOrder?.orderId ?? ""
+                        let page_pay_url = result?.createOrder?.payHref ?? ""
+                        let qrCode = result?.createOrder?.qrCode ?? ""
+                        if self.paymentMethod == .paddle || self.paymentMethod == .paypal {
+                            if self.orderID == "" || page_pay_url == "" {
+                                DispatchQueue.main.async {
+                                    let alert = NSAlert()
+                                    alert.alertStyle = .critical
+                                    alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
+                                    alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
+                                    alert.runModal()
+                                }
+                            } else {
+                                self.openWebView(page_pay_url)
+                            }
+                        } else if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
+                            if self.orderID == "" || qrCode == "" {
+                                DispatchQueue.main.async {
+                                    let alert = NSAlert()
+                                    alert.alertStyle = .critical
+                                    alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
+                                    alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
+                                    alert.runModal()
+                                }
+                            } else {
+                                self.scanCode(qrCode)
+                            }
+                        }
+                    } else {
+                        DispatchQueue.main.async {
+                            let alert = NSAlert()
+                            alert.alertStyle = .critical
+                            alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
+                            alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
+                            alert.runModal()
+                        }
+                    }
+                } else {
+                    DispatchQueue.main.async {
+                        let alert = NSAlert()
+                        alert.alertStyle = .critical
+                        alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
+                        alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
+                        alert.runModal()
+                    }
+                }
             }
         } else {
             var price = _product_Info.price
@@ -1666,44 +1713,43 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
                                    discountFlag: getPurchaseDiscountFlag(),
                                    couponCode: couponCode,
                                    num: pdfCount) { success, result in
-                //写定时器查询结果
+                if success {
+                    if let dataInfo = result {
+                        self.orderID = result?.createOrder?.orderId ?? ""
+                        let page_pay_url = result?.createOrder?.payHref ?? ""
+                        if self.orderID == "" || page_pay_url == "" {
+                            DispatchQueue.main.async {
+                                let alert = NSAlert()
+                                alert.alertStyle = .critical
+                                alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
+                                alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
+                                alert.runModal()
+                            }
+                        } else {
+                            if self.paymentMethod == .paddle || self.paymentMethod == .paypal {
+                                self.openWebView(page_pay_url)
+                            }
+                        }
+                    } else {
+                        DispatchQueue.main.async {
+                            let alert = NSAlert()
+                            alert.alertStyle = .critical
+                            alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
+                            alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
+                            alert.runModal()
+                        }
+                    }
+                } else {
+                    DispatchQueue.main.async {
+                        let alert = NSAlert()
+                        alert.alertStyle = .critical
+                        alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
+                        alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
+                        alert.runModal()
+                    }
+                }
             }
         }
-//        self._buyProduct(productID, count: pdfCount, discountId: couponCode, payment: paymentMethod, license: licenseCode, email: emailTextField.stringValue) { [weak self] info, err in
-//            guard let self = self else { return }
-//            if err != nil {
-//                DispatchQueue.main.async {
-//                    let alert = NSAlert()
-//                    alert.alertStyle = .critical
-//                    alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
-//                    alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
-//                    alert.runModal()
-//                }
-//                return
-//            }
-//            if let dataInfo = info {
-//                self.orderID = dataInfo["trade_no"] as! String
-//                let page_pay_url = dataInfo["page_pay_url"] as! String
-//                if self.paymentMethod == .paddle || self.paymentMethod == .paypal {
-//                    if page_pay_url != "" {
-//                        self.openWebView(page_pay_url)
-//                    }
-//                } else if self.paymentMethod == .wxpay || self.paymentMethod == .alipay {
-//                    if page_pay_url != "" {
-//                        self.scanCode(page_pay_url)
-//                    }
-//                }
-//            } else {
-//                // 数据错误
-//                DispatchQueue.main.async {
-//                    let alert = NSAlert()
-//                    alert.alertStyle = .critical
-//                    alert.messageText = NSLocalizedString("Please check if the information is wrong or the network is error.", comment: "")
-//                    alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
-//                    alert.runModal()
-//                }
-//            }
-//        }
     }
     
     func getPurchasePaymentMethod() -> Int {
@@ -2178,6 +2224,11 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
         startPolling()
     }
     
+    private func convertBase64StringToNSImage(base64String: String) -> NSImage? {
+        // 待补充base64转NSImage方法
+        return nil
+    }
+    
     private func scanCode(_ urlPath: String) -> Void {
         DispatchQueue.main.async { [weak self] in
             guard let self = self else { return }
@@ -2190,21 +2241,7 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
                 self.scanLabel.stringValue = NSLocalizedString("Scan QR Code with Alipay", comment: "")
                 self.payTypeImageView.image = NSImage(named: "EmbeddedPayment28")
             }
-
-            if let url = URL(string: urlPath) {
-                URLSession.shared.dataTask(with: url) { data, response, error in
-                    if let data = data, let image = NSImage(data: data) {
-                        DispatchQueue.main.async {
-                            self.qrCodeImageView.image = image
-                            self.startPolling()
-                        }
-                    } else {
-                        print("Failed to load image or there was an error: \(error?.localizedDescription ?? "Unknown error")")
-                    }
-                }.resume()
-            } else {
-                print("Invalid URL.")
-            }
+            self.payTypeImageView.image = convertBase64StringToNSImage(base64String: urlPath)
         }
     }
     
@@ -2290,6 +2327,19 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
         }
     }
     
+    private func pollingResultNew() -> Void {
+        DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
+            guard let self = self else { return }
+            if self.orderID == "" { return }
+            KMMemberCenterManager.manager.getStateByOrderId(orderId: self.orderID) { success, info in
+                if (success) {
+                    NotificationCenter.default.post(name: NSNotification.Name(rawValue: "KMIAPSubscriptionLoadedNotification"), object: nil)
+                    self.stopPolling();
+                }
+            }
+        }
+    }
+    
     private func startPolling() {
         timer = Timer(timeInterval: interval, repeats: false) { [weak self] _ in
             guard let self = self else { return }
@@ -2309,7 +2359,7 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
         print("Performing polling task \(pollCount + 1)/\(maxPolls)")
         
         pollCount += 1
-        pollingResult()
+        pollingResultNew()
     }
     
     private func stopPolling() {

+ 7 - 1
PDF Office/PDF Master/Class/Purchase/DMG/Verification/KMVerificationMessageViewController.m

@@ -178,7 +178,7 @@ NSPopoverDelegate>
     self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade to Pro", nil)];
     [self.button setTitleColor:[NSColor whiteColor]];
     self.officeButton.layer.backgroundColor = [NSColor clearColor].CGColor;
-    self.officeButton.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"PDF To Office", nil)];
+    self.officeButton.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"PDF to Office", nil)];
     [self.officeButton setTitleColor:[NSColor whiteColor]];
 
     self.aiLabel.stringValue = NSLocalizedStringFromTable(@"Free Use 1-Year AI Tools", @"MemberCenterLocalizable", nil);
@@ -368,6 +368,12 @@ NSPopoverDelegate>
             }
         } else if (type == KMUserScenarioTypeLite_type11) {
             self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
+        } else if (type == KMUserScenarioTypePro_type3) {
+            if([KMMemberInfo shared].vip_status == 2) {
+                self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedStringFromTable(@"Renew now",@"MemberCenterLocalizable", nil)];
+            } else {
+                self.button.title = [NSString stringWithFormat:@" %@ ",NSLocalizedString(@"Upgrade", nil)];
+            }
         }
 #if !VERSION_FREE
         BOOL isNoSupportMemberUpgrade = YES;

+ 8 - 4
PDF Office/PDF Master/MemberCenter/Model/KMMemberCenterManager.swift

@@ -1374,15 +1374,17 @@ class KMMemberCenterManager: NSObject {
             var thirdOrderNo = ""
             var orderId = ""
             var payHref = ""
+            var qrCode = ""
             if requestCode == 200 {
                 if let token = result["thirdOrderNo"] { thirdOrderNo = token as? String ?? thirdOrderNo}
                 if let token = result["orderId"] { orderId = token as? String ?? orderId}
                 if let token = result["payHref"] { payHref = token as? String ?? payHref}
-                let products = KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref)
+                if let token = result["qrcode"] { qrCode = token as? String ?? qrCode}
+                let products = KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref, qrCode: qrCode)
                 let result1 = KMMemberProductResult(code: requestCode, msg: message, createOrder: products)
                 complete(true, result1)
             } else {
-                let result1 = KMMemberProductResult(code: requestCode, msg: message, createOrder: KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref))
+                let result1 = KMMemberProductResult(code: requestCode, msg: message, createOrder: KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref, qrCode: qrCode))
                 complete(false, result1)
             }
         }
@@ -1433,15 +1435,17 @@ class KMMemberCenterManager: NSObject {
             var thirdOrderNo = ""
             var orderId = ""
             var payHref = ""
+            var qrCode = ""
             if requestCode == 200 {
                 if let token = result["thirdOrderNo"] { thirdOrderNo = token as? String ?? thirdOrderNo}
                 if let token = result["orderId"] { orderId = token as? String ?? orderId}
                 if let token = result["payHref"] { payHref = token as? String ?? payHref}
-                let products = KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref)
+                if let token = result["qrcode"] { qrCode = token as? String ?? qrCode}
+                let products = KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref, qrCode: qrCode)
                 let result1 = KMMemberProductResult(code: requestCode, msg: message, createOrder: products)
                 complete(true, result1)
             } else {
-                let result1 = KMMemberProductResult(code: requestCode, msg: message, createOrder: KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref))
+                let result1 = KMMemberProductResult(code: requestCode, msg: message, createOrder: KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref, qrCode: qrCode))
                 complete(false, result1)
             }
         }

+ 3 - 1
PDF Office/PDF Master/MemberCenter/Model/KMMemberProductResult.swift

@@ -187,10 +187,12 @@ class KMCreateOrderModel: NSObject {
     var thirdOrderNo    : String = ""   // 【必需】
     var orderId         : String = ""   // 【必需】
     var payHref         : String = ""   // 【必需】
-    init(thirdOrderNo: String, orderId: String, payHref: String) {
+    var qrCode          : String = ""   // 【必需】
+    init(thirdOrderNo: String, orderId: String, payHref: String, qrCode: String) {
         self.thirdOrderNo = thirdOrderNo
         self.orderId = orderId
         self.payHref = payHref
+        self.qrCode = qrCode
     }
 }
 

+ 7 - 2
PDF Office/PDF Master/MemberCenter/ViewController/KMUserInfoViewController.swift

@@ -244,10 +244,15 @@ class KMUserInfoViewController: NSViewController {
             buyNow1Label.stringValue = NSLocalizedString("Upgrade Now", tableName: "MemberCenterLocalizable", comment: "")
         }  else if KMMemberInfo.shared.userScenarioType == .lite_type5 ||
                     KMMemberInfo.shared.userScenarioType == .pro_type1 ||
-                    KMMemberInfo.shared.userScenarioType == .pro_type3 ||
                     KMMemberInfo.shared.userScenarioType == .pro_type4 {
             buyNow1Label.stringValue = NSLocalizedString("Upgrade Now", tableName: "MemberCenterLocalizable", comment: "")
-        } else if KMMemberInfo.shared.userScenarioType == .lite_type7 ||
+        }  else if KMMemberInfo.shared.userScenarioType == .pro_type3 {
+            if(KMMemberInfo.shared.vip_status == 2) {
+                buyNow1Label.stringValue = NSLocalizedString("Renew now", tableName: "MemberCenterLocalizable", comment: "")
+            } else {
+                buyNow1Label.stringValue = NSLocalizedString("Upgrade Now", tableName: "MemberCenterLocalizable", comment: "")
+            }
+        }  else if KMMemberInfo.shared.userScenarioType == .lite_type7 ||
                     KMMemberInfo.shared.userScenarioType == .lite_type8 ||
                     KMMemberInfo.shared.userScenarioType == .lite_type13 {
             buyNow1Label.stringValue = NSLocalizedString("Renew now", tableName: "MemberCenterLocalizable", comment: "")

+ 38 - 12
PDF Office/PDF Master/MemberCenter/ViewModel/KMProductModel.swift

@@ -173,7 +173,7 @@ class KMProductModel: ObservableObject {
         guard let productModels = dmgProductDatas?.listingProducts else { return "" }
         for model in productModels {
             if model.code == productCode {
-                return model.price.stringValue
+                return String(format: "%.2f", model.price.doubleValue)
             }
         }
         return ""
@@ -185,7 +185,7 @@ class KMProductModel: ObservableObject {
         guard let productModels = dmgProductDatas?.listingProducts else { return "" }
         for model in productModels {
             if model.code == productCode {
-                return model.cnyPrice.stringValue
+                return String(format: "%.2f", model.cnyPrice.doubleValue)
             }
         }
         return ""
@@ -197,7 +197,7 @@ class KMProductModel: ObservableObject {
         guard let productModels = dmgProductDatas?.listingProducts else { return "" }
         for model in productModels {
             if model.code == productCode {
-                return model.displayPrice.stringValue
+                return String(format: "%.2f", model.displayPrice.doubleValue)
             }
         }
         return ""
@@ -209,7 +209,7 @@ class KMProductModel: ObservableObject {
         guard let productModels = dmgProductDatas?.listingProducts else { return "" }
         for model in productModels {
             if model.code == productCode {
-                return model.displayCnyPrice.stringValue
+                return String(format: "%.2f", model.displayCnyPrice.doubleValue)
             }
         }
         return ""
@@ -431,9 +431,17 @@ class KMProductModel: ObservableObject {
             if type == .pdfReaderProStandard_dmg {
                 return getDMGPrice(productCode: "standard-annual-subscription")
             } else if type == .pdfReaderProAdvanced_dmg {
-                return getDMGPrice(productCode: "advanced-annual-subscription")
+                if isBlackFive {
+                    return getDMGPrice(productCode: "advanced-annual-subscription-blackFive")
+                } else {
+                    return getDMGPrice(productCode: "advanced-annual-subscription")
+                }
             } else if type == .pdfReaderProPermanent_dmg {
-                return getDMGPrice(productCode: "advanced-permanent")
+                if isBlackFive {
+                    return getDMGPrice(productCode: "advanced-permanent-blackFive")
+                } else {
+                    return getDMGPrice(productCode: "advanced-permanent")
+                }
             } else if type == .pdfReaderProAIAnnual_dmg {
                 return getDMGPrice(productCode: "ai-subscription-year-trail")
             } else if type == .pdfReaderProAIMonthly_dmg {
@@ -441,9 +449,7 @@ class KMProductModel: ObservableObject {
             } else if type == .pdfToOffice_dmg {
                 return getDMGPrice(productCode: "PDF to Office")
             } else if type == .add2Device_dmg {
-                return getDMGPrice(productCode: "Add 2-Device · Advanced Annual")
             } else if type == .add3Device_dmg {
-                return getDMGPrice(productCode: "Add 3-Device · Advanced Annual")
             }
 #else
     // AppStore 免费版本
@@ -546,9 +552,17 @@ class KMProductModel: ObservableObject {
             if tag == 1 {
                 code = "standard-annual-subscription"
             } else if tag == 3 {
-                code = "advanced-permanent"
+                if isBlackFive {
+                    code = "advanced-permanent-blackFive"
+                } else {
+                    code = "advanced-permanent"
+                }
             } else {
-                code = "advanced-annual-subscription"
+                if isBlackFive {
+                    code = "advanced-annual-subscription-blackFive"
+                } else {
+                    code = "advanced-annual-subscription"
+                }
             }
             #if VERSION_DMG
             let embeddedWC = KMPurchaseEmbeddedWindowController.currentCode(code)
@@ -557,13 +571,13 @@ class KMProductModel: ObservableObject {
             #endif
         } else if state == .dmg_Upgrades1 {
             #if VERSION_DMG
-            let embeddedWC = KMPurchaseEmbeddedWindowController.currentCode("Add 2-Device · Advanced Annual")
+            let embeddedWC = KMPurchaseEmbeddedWindowController.currentCode("advanced-annual-subscription")
             embeddedWC.showWindow(nil)
             embeddedWC.window?.center()
             #endif
         } else if state == .dmg_Upgrades2 {
             #if VERSION_DMG
-            let embeddedWC = KMPurchaseEmbeddedWindowController.currentCode("Add 3-Device · Advanced Annual")
+            let embeddedWC = KMPurchaseEmbeddedWindowController.currentCode("advanced-annual-subscription")
             embeddedWC.showWindow(nil)
             embeddedWC.window?.center()
             #endif
@@ -986,4 +1000,16 @@ class KMProductModel: ObservableObject {
             ]
         }
     }
+    
+    /**
+     是否黑五活动期
+     */
+    var isBlackFive: Bool {
+        if let loginContent = KMAdvertisementManager.manager.info.topRightInfoContent {
+            if loginContent.content?.isEmpty == false {
+                return true
+            }
+        }
+        return false
+    }
 }

+ 24 - 7
PDF Office/PDF Master/MemberCenter/WindowsController/KMProductCompareWC.swift

@@ -363,10 +363,28 @@ class KMProductCompareWC: NSWindowController {
             standardPlanPurchaseLabel.stringValue = model.getProductPrice(.pdfReaderProStandard_dmg)
             advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.pdfReaderProAdvanced_dmg)
             permanentPurchaseLabel.stringValue = model.getProductPrice(.pdfReaderProPermanent_dmg)
-        } else if model.state == .dmg_Upgrades1 {
-            advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.add2Device_dmg)
-        } else if model.state == .dmg_Upgrades2 {
-            advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.add3Device_dmg)
+        } else if model.state == .dmg_Upgrades1 || model.state == .dmg_Upgrades2 {
+            guard let productModels = model.dmgProductDatas?.listingProducts else { return }
+            for productModel in productModels {
+                if productModel.code == "advanced-annual-subscription" {
+                    model.getDMGProductPriceInfosForMember(productId: productModel.id, isEducation: 0) { [weak self] success, result in
+                        guard let self = self else { return }
+                        guard let results: KMMemberProductResult = result else { return }
+                        guard let productModels2 = results.listingProducts else { return }
+                        for productModel2 in productModels2 {
+                            if self.model.isBlackFive == true {
+                                if productModel2.code == "advanced-annual-subscription-blackFive" {
+                                    self.permanentPurchaseLabel.stringValue = String(format: "%.2f", productModel2.upgradePrice.doubleValue)
+                                }
+                            } else {
+                                if productModel2.code == "advanced-annual-subscription" {
+                                    self.permanentPurchaseLabel.stringValue = String(format: "%.2f", productModel2.upgradePrice.doubleValue)
+                                }
+                            }
+                        }
+                    }
+                }
+            }
         } else {
             advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.pdfReaderProAdvanced_dmg)
         }
@@ -1060,6 +1078,7 @@ class KMProductCompareWC: NSWindowController {
     }
     
     @IBAction func appstorePurchaseAction(_ sender: NSButton) {
+        addWaitingView(to: window?.contentView ?? NSView())
         model.appstorePurchaseAction(sender.tag) { [weak self] success, msg in
             guard let self = self else { return }
 
@@ -1116,9 +1135,7 @@ class KMProductCompareWC: NSWindowController {
             model.appStoreEquityVerification(notification) { success, msg in
                 KMUserInfoVCModel().refreshUserInfo { success, msg,dic  in
                 }
-                DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
-                    self.window?.close()
-                }
+                self.window?.close()
             }
         }
     }