Parcourir la source

【综合】试用召回逻辑完善

niehaoyu il y a 9 mois
Parent
commit
e261893c69

+ 16 - 3
PDF Office/PDF Master/Class/GuideInfo/KMCouponDueWindowController.swift

@@ -24,6 +24,10 @@ class KMCouponDueWindowController: NSWindowController {
     @IBOutlet var buyButton: KMButton!
     @IBOutlet var laterInfoLabel: NSTextField!
     
+    var disCount: Int = 20
+    var couponCode: String = ""
+    var endUpAt: String = ""
+    
     deinit {
         print("KMCouponDueWindowController deInit")
     }
@@ -72,9 +76,18 @@ class KMCouponDueWindowController: NSWindowController {
     
     func reloadData() {
         self.titleLabel.stringValue = KMAdsInfoManager.shareInstance.couponInfo?.title ?? ""
-        self.subTitleLabel.stringValue = KMAdsInfoManager.shareInstance.couponInfo?.subTitle ?? ""
-        self.laterInfoLabel.stringValue = KMAdsInfoManager.shareInstance.couponInfo?.laterInfoString ?? ""
-        self.buyButton.title = KMAdsInfoManager.shareInstance.couponInfo?.buyBtnTitle ?? ""
+        
+        if KMAdsInfo().languageKey == "zh_CN" {
+            self.subTitleLabel.stringValue = String(format: KMAdsInfoManager.shareInstance.couponInfo?.subTitle ?? "", self.endUpAt)
+            self.buyButton.title = String(format: KMAdsInfoManager.shareInstance.couponInfo?.buyBtnTitle ?? "", String(format: "%ld", 10-self.disCount/10))
+        } else {
+            self.subTitleLabel.stringValue = String(format: KMAdsInfoManager.shareInstance.couponInfo?.subTitle ?? "", self.endUpAt, String(format: "%ld", self.disCount))
+            self.buyButton.title = String(format: KMAdsInfoManager.shareInstance.couponInfo?.buyBtnTitle ?? "", String(format: "%ld", self.disCount)+"%")
+        }
+        self.laterInfoLabel.stringValue = String(format: KMAdsInfoManager.shareInstance.couponInfo?.laterInfoString ?? "", self.couponCode)
+        
+        self.contendImage.image = KMAdsInfoManager.shareInstance.couponInfo?.adsImage
+        self.tipInfoImage.image = KMAdsInfoManager.shareInstance.couponInfo?.adsDetailImage
         
         self.refreshUI()
     }

+ 8 - 7
PDF Office/PDF Master/Class/GuideInfo/KMCouponDueWindowController.xib

@@ -45,7 +45,7 @@
                                     <subviews>
                                         <imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="x8W-tS-Xhe">
                                             <rect key="frame" x="0.0" y="0.0" width="300" height="380"/>
-                                            <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="cnLight" id="UDr-qh-Sdk"/>
+                                            <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="UDr-qh-Sdk"/>
                                         </imageView>
                                     </subviews>
                                     <constraints>
@@ -85,7 +85,7 @@
                                                 <imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="GkG-tR-cLY">
                                                     <rect key="frame" x="0.0" y="0.0" width="266" height="100"/>
                                                     <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
-                                                    <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="detailCnDark" id="erh-zg-aUs"/>
+                                                    <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="erh-zg-aUs"/>
                                                 </imageView>
                                             </subviews>
                                             <constraints>
@@ -119,9 +119,12 @@
                                             <color key="fillColor" red="1" green="0.61799015410958902" blue="0.16566780821917809" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                                         </box>
                                         <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="VRY-Yk-fAD">
-                                            <rect key="frame" x="17" y="20" width="232" height="14"/>
-                                            <textFieldCell key="cell" alignment="left" title="Buy later? Save the coupon code: XXX-XXX" id="Ukb-Yc-wec">
-                                                <font key="font" metaFont="system" size="11"/>
+                                            <rect key="frame" x="-2" y="20" width="270" height="14"/>
+                                            <constraints>
+                                                <constraint firstAttribute="width" constant="266" id="5bJ-Fv-1Zy"/>
+                                            </constraints>
+                                            <textFieldCell key="cell" selectable="YES" alignment="center" title="--" id="Ukb-Yc-wec">
+                                                <font key="font" metaFont="smallSystem"/>
                                                 <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
                                                 <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
                                             </textFieldCell>
@@ -169,8 +172,6 @@
         </window>
     </objects>
     <resources>
-        <image name="cnLight" width="300" height="380"/>
-        <image name="detailCnDark" width="266" height="100"/>
         <namedColor name="Color">
             <color red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
         </namedColor>

+ 32 - 11
PDF Office/PDF Master/Class/Home/ViewController/KMHomeViewController.swift

@@ -985,14 +985,39 @@ extension KMHomeViewController {
     //MARK: 试用到期优惠券弹窗
     func checkTrialEndCouponInfo() {
         
-//        if self.showCoupon {
-//            self.showCouponInfoWindow()
-//            self.showCoupon = false
-//        }
+        KMRequestServerManager.manager.getDeviceRetensionCoupon {[weak self] success, result in
+            if success == true {
+                if result != nil {
+                    let dataDict = result!["data"] as? NSDictionary
+                    //                        if dataDict!["pop_up"] as? Bool == true {
+                    let discount = dataDict!["discount"] as? Int
+                    let coupon_code = dataDict!["coupon_code"] as? String
+                    let end_up_at = dataDict!["end_up_at"] as? String
+                    
+                    self?.showCouponInfoWindow(discount: discount, couponCode: coupon_code, endUpAt: end_up_at)
+
+                }
+            } else {
+#if VERSION_DMG
+                if KMVerificationWindowController.allowsShowExpired() {
+                    self?.checkRepeatTrialExpiredController()
+                } else if KMVerificationWindowController.allowRepeatTrialAlertShow() {
+                    self?.checkRepeatTrialAlertController()
+                }
+#endif
+                
+            }
+        }
     }
     
-    func showCouponInfoWindow() {
-        self.couponDueWindowVC = KMCouponDueWindowController(windowNibName: "KMCouponDueWindowController")
+    func showCouponInfoWindow(discount: Int?, couponCode: String?, endUpAt: String?) {
+        if self.couponDueWindowVC == nil {
+            self.couponDueWindowVC = KMCouponDueWindowController(windowNibName: "KMCouponDueWindowController")
+        }
+        self.couponDueWindowVC.disCount = discount ?? 20
+        self.couponDueWindowVC.couponCode = couponCode ?? ""
+        self.couponDueWindowVC.endUpAt = endUpAt ?? ""
+        
         self.couponDueWindowVC.showWindow(nil)
         self.couponDueWindowVC.reloadData()
         
@@ -1001,11 +1026,7 @@ extension KMHomeViewController {
     // MARK: - Noti Actions
     func deviceVerifyFinishNotification(_ sender: Notification) {
 #if VERSION_DMG
-        if KMVerificationWindowController.allowsShowExpired() {
-            self.checkRepeatTrialExpiredController()
-        } else if KMVerificationWindowController.allowRepeatTrialAlertShow() {
-            self.checkRepeatTrialAlertController()
-        }
+         
 #endif
     }
     

+ 25 - 0
PDF Office/PDF Master/Class/KMLightMember/Manager/KMRequestServerManager.swift

@@ -173,6 +173,7 @@ struct Result {
 }
 
 typealias KMRequestServerComplete = (_ success: Bool, _ result: Result?) -> Void
+typealias KMRequestServerDateComplete = (_ success: Bool, _ result: NSDictionary?) -> Void
 
 
 class KMRequestServerManager: NSObject {
@@ -478,6 +479,30 @@ extension KMRequestServerManager {
             }
         }
     }
+    
+    func getDeviceRetensionCoupon(complete: @escaping KMRequestServerDateComplete) {
+
+        let urlString = AIInfoConfig().aiActionURL + "api/devices/getRetensionCoupon"
+        let params: [String:Any] = ["unique_sn": self.uuid(),
+                                    "platform": "DMG"]
+
+        KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
+            requestSerializer.setValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
+        } completion: { [unowned self] (task, responseObject, error) in
+            let result = self.dealData(responseObject: responseObject as? NSDictionary, error: error)
+            if result.code == 200 {
+                complete(true, responseObject as? NSDictionary)
+            } else {
+                complete(false, responseObject as? NSDictionary)
+            }
+        }
+    }
+    
+    
+    //MARK: Private Method
+    private func uuid() -> String {
+        return GetHardwareUUID()!
+    }
 }
 
 //MARK: - 订阅

+ 15 - 23
PDF Office/PDF Master/Class/Purchase/DMG/Verification/VerificationManager/KMAdsInfo.swift

@@ -119,9 +119,11 @@ import Cocoa
     
     var languageKey: String {
         let language = Bundle.main.preferredLocalizations[0]
-        if language == "zh_CN" {
+        if language == "zh_CN" ||
+            language == "zh-Hans" {
             return "zh_CN"
-        } else if language == "zh_TW" {
+        } else if language == "zh_TW" ||
+                    language == "zh-Hant" {
             return "zh_TW"
         }
         return "en"
@@ -144,10 +146,10 @@ import Cocoa
         get {
             
             let imageDict: [String: Any] = self.infoDict["image"] as! [String : Any]
-            let imageURLString = imageDict[self.languageKey] as! NSString
+            let imageURLString = imageDict[KMAdsInfo().languageKey] as! NSString
             
             var imageName = self.versionKey
-            imageName.append(String(format: "_%@.%@", self.languageKey, imageURLString.lastPathComponent))
+            imageName.append(String(format: "_%@.%@", KMAdsInfo().languageKey, imageURLString.lastPathComponent))
  
             let kImageCacheFilePath: String = NSTemporaryDirectory() + "Advertisement/ImageCache"
             let imgSavePath = kImageCacheFilePath + "/" + imageName
@@ -167,7 +169,7 @@ import Cocoa
                 }
             }
              
-            return NSImage(named: "ComPDFKit_EN")!
+            return NSImage(named: "cnLight")!
         }
     }
     
@@ -175,10 +177,10 @@ import Cocoa
         get {
             
             let imageDict: [String: Any] = self.infoDict["detailImage"] as! [String : Any]
-            let imageURLString = imageDict[self.languageKey] as! NSString
+            let imageURLString = imageDict[KMAdsInfo().languageKey] as! NSString
             
             var imageName = self.versionKey
-            imageName.append(String(format: "_%@.%@", self.languageKey, imageURLString.lastPathComponent))
+            imageName.append(String(format: "_%@.%@", KMAdsInfo().languageKey, imageURLString.lastPathComponent))
  
             let kImageCacheFilePath: String = NSTemporaryDirectory() + "Advertisement/ImageCache"
             let imgSavePath = kImageCacheFilePath + "/" + imageName
@@ -198,48 +200,38 @@ import Cocoa
                 }
             }
              
-            return NSImage(named: "ComPDFKit_EN")!
+            return NSImage(named: "detailCnDark")!
         }
     }
     
     var adsURLLink: String {
         get {
             let linkDict: [String: Any] = self.infoDict["linkURL"] as! [String : Any]
-            return linkDict[self.languageKey] as! String
+            return linkDict[KMAdsInfo().languageKey] as! String
         }
     }
     
-    var languageKey: String {
-        let language = Bundle.main.preferredLocalizations[0]
-        if language == "zh_CN" {
-            return "zh_CN"
-        } else if language == "zh_TW" {
-            return "zh_TW"
-        }
-        return "en"
-    }
-    
     var versionKey: String {
         return self.infoDict["version"] as! String
     }
     
     var title: String {
         let titleDict: [String: Any] = self.infoDict["title"] as! [String : Any]
-        return titleDict[self.languageKey] as! String
+        return titleDict[KMAdsInfo().languageKey] as! String
     }
     
     var subTitle: String {
         let titleDict: [String: Any] = self.infoDict["subTitle"] as! [String : Any]
-        return titleDict[self.languageKey] as! String
+        return titleDict[KMAdsInfo().languageKey] as! String
     }
     
     var buyBtnTitle: String {
         let titleDict: [String: Any] = self.infoDict["buyBtnTitle"] as! [String : Any]
-        return titleDict[self.languageKey] as! String
+        return titleDict[KMAdsInfo().languageKey] as! String
     }
     
     var laterInfoString: String {
         let titleDict: [String: Any] = self.infoDict["laterInfoString"] as! [String : Any]
-        return titleDict[self.languageKey] as! String
+        return titleDict[KMAdsInfo().languageKey] as! String
     }
 }