Quellcode durchsuchen

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

niehaoyu vor 1 Woche
Ursprung
Commit
18d092284f

+ 111 - 9
PDF Office/PDF Master/MemberCenter/Model/KMMemberCenterManager.swift

@@ -52,6 +52,7 @@ enum KMMemberCenterErrorCodeType: Int, CaseIterable {
 
 typealias KMMemberCenterComplete = (_ success: Bool, _ result: KMMemberCenterResult?) -> Void
 typealias KMMemberProductComplete = (_ success: Bool, _ result: KMMemberProductResult?) -> Void
+typealias KMMemberRequestInfoComplete = (_ success: Bool, _ info: NSDictionary?) -> Void
 
 class KMMemberCenterManager: NSObject {
     static let manager = KMMemberCenterManager()
@@ -466,6 +467,7 @@ class KMMemberCenterManager: NSObject {
     func getInviteNum(_ complete: @escaping KMMemberCenterComplete) {
         let token: String = KMMemberInfo.shared.access_token
         if token == "" {
+            complete(false, nil)
             return
         }
         
@@ -506,6 +508,7 @@ class KMMemberCenterManager: NSObject {
     func userInfo(_ complete: @escaping KMMemberCenterComplete) {
         let token: String = KMMemberInfo.shared.access_token
         if token == "" {
+            complete(false, nil)
             return
         }
         
@@ -624,6 +627,7 @@ class KMMemberCenterManager: NSObject {
     func userLogout(_ complete: @escaping KMMemberCenterComplete) {
         let token: String = KMMemberInfo.shared.access_token
         if token == "" {
+            complete(false, nil)
             return
         }
         let uuid: String = GetHardwareUUID() ?? ""
@@ -663,6 +667,7 @@ class KMMemberCenterManager: NSObject {
     func userRightList(_ complete: @escaping KMMemberCenterComplete) {
         let token: String = KMMemberInfo.shared.access_token
         if token == "" {
+            complete(false, nil)
             return
         }
         
@@ -733,6 +738,7 @@ class KMMemberCenterManager: NSObject {
     func userLogOffForUser(code: String, _ complete: @escaping KMMemberCenterComplete) {
         let token: String = KMMemberInfo.shared.access_token
         if token == "" {
+            complete(false, nil)
             return
         }
         
@@ -778,6 +784,7 @@ class KMMemberCenterManager: NSObject {
     func userRevokeCancel(_ complete: @escaping KMMemberCenterComplete) {
         let token: String = KMMemberInfo.shared.access_token
         if token == "" {
+            complete(false, nil)
             return
         }
         
@@ -964,7 +971,7 @@ class KMMemberCenterManager: NSObject {
     /**
      @abstract              获取批量阶段购买价格
      @param productId 购买的产品id
-     @param isEducation 是否教育优惠
+     @param num 批量个数
      @param complete 回调
      */
     func getBatchProductPrice(productId: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
@@ -1019,12 +1026,14 @@ class KMMemberCenterManager: NSObject {
     /**
      @abstract              验证商品优惠券,返回商品优惠后价格
      @param productId 购买的产品id
-     @param isEducation 是否教育优惠
+     @param userId 用户ID
+     @param code 优惠券
      @param complete 回调
      */
     func checkCoupon(productId: String, userId: String, code: String, _ complete: @escaping KMMemberProductComplete) {
         let token: String = KMMemberInfo.shared.access_token
         if token == "" {
+            complete(false, nil)
             return
         }
         let urlString = configuration.activityBaseURL() + "/pdf-office-website/web/checkCoupon"
@@ -1148,14 +1157,62 @@ class KMMemberCenterManager: NSObject {
      @param orderId 订单id
      @param complete 回调
      */
-    func getStateByOrderId(orderId: String, _ complete: @escaping KMMemberProductComplete) {
+    func getStateByOrderId(orderId: String, _ complete: @escaping KMMemberRequestInfoComplete) {
         let token: String = KMMemberInfo.shared.access_token
         if token == "" {
+            complete(false, nil)
             return
         }
         let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/getStateByOrderId"
         KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: nil) { requestSerializer in
             requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
+        } completion: { [weak self] (task, responseObject, error) in
+            var dic: NSDictionary = [:]
+            if error == nil, let responseObject = responseObject as? NSDictionary {
+                dic = responseObject
+            } else {
+                var info = responseObject
+                if let error = error {
+                    if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
+                        info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
+                    }
+                }
+                dic = (info as? NSDictionary) ?? [:]
+            }
+            let code: Int = dic["code"] as? Int ?? 0
+            if code == 200 {
+                complete(true, dic)
+            } else {
+                complete(false, dic)
+            }
+        }
+    }
+    
+    /**
+     @abstract              创建订单(买断)
+     @param productId               产品id
+     @param paymentMethod   支付方式 PAYPAL(0),ALIPAY(1),WXPAY(2),PADDLE(3)
+     @param price                      价格
+     @param discountFlag        0原价,1优惠券,2升级,3教育优惠,4批量购买,5黑五折扣
+     @param couponCode        优惠卷
+     @param num                      批量购买数量
+     @param complete 回调
+     */
+    func createOrder(productId: String, paymentMethod: Int, price: String, discountFlag: Int, couponCode: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
+        let token: String = KMMemberInfo.shared.access_token
+        if token == "" {
+            complete(false, nil)
+            return
+        }
+        let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/createOrder"
+        let params: [String: Any] = ["productId": productId,
+                                     "paymentMethod": paymentMethod,
+                                     "price": price,
+                                     "discountFlag": discountFlag,
+                                     "couponCode": couponCode,
+                                     "num": num]
+        KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
+            requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
         } completion: { [weak self] (task, responseObject, error) in
             var dic: NSDictionary = [:]
             if error == nil, let responseObject = responseObject as? NSDictionary {
@@ -1173,20 +1230,25 @@ class KMMemberCenterManager: NSObject {
             let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
             let message: String = dic["msg"] as? String ?? ""
             
-            var status = ""
-            if let token = result["status"] { status = token as! String }
-
-            let result1 = KMMemberProductResult(code: code, msg: message, result: status)
+            var thirdOrderNo = ""
+            var orderId = ""
+            var payHref = ""
             if code == 200 {
+                if let token = result["thirdOrderNo"] { thirdOrderNo = token as! String }
+                if let token = result["orderId"] { orderId = token as! String }
+                if let token = result["payHref"] { payHref = token as! String }
+                let products = KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref)
+                let result1 = KMMemberProductResult(code: code, msg: message, createOrder: products)
                 complete(true, result1)
             } else {
+                let result1 = KMMemberProductResult(code: code, msg: message, createOrder: KMCreateOrderModel(thirdOrderNo: thirdOrderNo, orderId: orderId, payHref: payHref))
                 complete(false, result1)
             }
         }
     }
     
     /**
-     @abstract              创建订单(买断、订阅)
+     @abstract              创建订单(订阅)
      @param productId               产品id
      @param paymentMethod   支付方式 PAYPAL(0),ALIPAY(1),WXPAY(2),PADDLE(3)
      @param price                      价格
@@ -1195,9 +1257,10 @@ class KMMemberCenterManager: NSObject {
      @param num                      批量购买数量
      @param complete 回调
      */
-    func createOrder(productId: String, paymentMethod: Int, price: String, discountFlag: Int, couponCode: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
+    func createSubscriber(productId: String, paymentMethod: Int, price: String, discountFlag: Int, couponCode: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
         let token: String = KMMemberInfo.shared.access_token
         if token == "" {
+            complete(false, nil)
             return
         }
         let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/createOrder"
@@ -1251,6 +1314,7 @@ class KMMemberCenterManager: NSObject {
     func getOrderListByStatus(orderStatus: Int, _ complete: @escaping KMMemberProductComplete) {
         let token: String = KMMemberInfo.shared.access_token
         if token == "" {
+            complete(false, nil)
             return
         }
         let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/getOrderListByStatus"
@@ -1291,6 +1355,43 @@ class KMMemberCenterManager: NSObject {
         }
     }
     
+    /**
+     @abstract              关闭订单
+     @param orderId 订单id
+     @param complete 回调
+     */
+    func closeByOrderId(orderId: String, _ complete: @escaping KMMemberRequestInfoComplete) {
+        let token: String = KMMemberInfo.shared.access_token
+        if token == "" {
+            complete(false, nil)
+            return
+        }
+        let urlString = configuration.activityBaseURL() + "/pdf-office-website/order/closeOrder"
+        KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: nil) { requestSerializer in
+            requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
+        } completion: { [weak self] (task, responseObject, error) in
+            var dic: NSDictionary = [:]
+            if error == nil, let responseObject = responseObject as? NSDictionary {
+                dic = responseObject
+            } else {
+                var info = responseObject
+                if let error = error {
+                    if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
+                        info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
+                    }
+                }
+                dic = (info as? NSDictionary) ?? [:]
+            }
+            let code: Int = dic["code"] as? Int ?? 0
+
+            if code == 200 {
+                complete(true, dic)
+            } else {
+                complete(false, dic)
+            }
+        }
+    }
+    
     // MARK: 苹果支付
     
     /**
@@ -1301,6 +1402,7 @@ class KMMemberCenterManager: NSObject {
     func appStoreEquityVerification(orderStatus: Int, _ complete: @escaping KMMemberProductComplete) {
         let token: String = KMMemberInfo.shared.access_token
         if token == "" {
+            complete(false, nil)
             return
         }
         let urlString = configuration.activityBaseURL() + "/member-system-website/applePay/appStoreEquityVerification"

+ 118 - 4
PDF Office/PDF Master/MemberCenter/ViewModel/KMProductModel.swift

@@ -68,15 +68,30 @@ class KMProductModel: ObservableObject {
     var dmgProductDatas: KMMemberProductResult?
     
     /**
-     DMG 版本 已经登录用户 最后一次价格价格获取
+     DMG 版本 已经登录用户 最后一次价格获取
      */
     var dmgLastGetProductPriceInfos: KMMemberProductResult?
     
     /**
-     DMG 版本 已经登录用户 最后一次价格价格获取
+     DMG 版本 已经登录用户 最后一次批量价格获取
      */
     var dmgLastGetBatchProductPriceInfos: KMMemberProductResult?
     
+    /**
+     DMG 版本 已经登录用户 最后一次验证商品优惠券价格获取
+     */
+    var dmgLastCheckCouponProductPriceInfos: KMMemberProductResult?
+    
+    /**
+     DMG 版本 已经登录用户 最后一次创建的买断订单返回信息
+     */
+    var dmgLastCreatOrderProductInfos: KMMemberProductResult?
+    
+    /**
+     DMG 版本 已经登录用户 最后一次创建的买断订单返回信息
+     */
+    var dmgLastCreatSubscriberProductInfos: KMMemberProductResult?
+    
     // MARK: DMG Public Method
     
     func checkConnectionAvailable() -> Void {
@@ -112,7 +127,9 @@ class KMProductModel: ObservableObject {
     
     /**
      @abstract 获取登录用户价格(建立订单时需要用到)
-     @param
+     @param productId 购买的产品id
+     @param isEducation 是否教育优惠
+     @param complete 回调
      */
     func getDMGProductPriceInfosForMember(productId: String, isEducation: Int, _ complete: @escaping KMMemberProductComplete) {
         checkConnectionAvailable()
@@ -133,7 +150,9 @@ class KMProductModel: ObservableObject {
     
     /**
      @abstract 获取批量阶段购买价格(建立订单时需要用到)
-     @param
+     @param productId 购买的产品id
+     @param num 批量个数
+     @param complete 回调
      */
     func getDMGBatchProductPriceInfosForMember(productId: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
         checkConnectionAvailable()
@@ -151,6 +170,101 @@ class KMProductModel: ObservableObject {
         }
     }
     
+    /**
+     @abstract 验证商品优惠券(建立订单时需要用到)
+     @param productId 购买的产品id
+     @param code 优惠券
+     @param complete 回调
+     */
+    func getDMGCheckCouponProductPriceInfosForMember(productId: String, code: String, _ complete: @escaping KMMemberProductComplete) {
+        checkConnectionAvailable()
+        KMMemberCenterManager.manager.checkCoupon(productId: productId, userId: KMMemberInfo.shared.userID, code: code) { [weak self] success, result in
+            if success {
+                guard let productsArrays : KMMemberProductResult = result else {
+                    complete(false, result)
+                    return
+                }
+                self?.dmgLastCheckCouponProductPriceInfos = productsArrays
+                complete(true, productsArrays)
+            } else {
+                complete(false, result)
+            }
+        }
+    }
+    
+    /**
+     @abstract 获取订单列表
+     @param orderStatus               0全部1待支付
+     @param complete 回调
+     */
+    func getDMGProductListInfosForMember(orderStatus: Int, _ complete: @escaping KMMemberProductComplete) {
+        checkConnectionAvailable()
+        KMMemberCenterManager.manager.getOrderListByStatus(orderStatus: orderStatus) { [weak self] success, result in
+            if success {
+                guard let productsArrays : KMMemberProductResult = result else {
+                    complete(false, result)
+                    return
+                }
+                complete(true, productsArrays)
+            } else {
+                complete(false, result)
+            }
+        }
+    }
+    
+    /**
+     @abstract              创建订单(买断)
+     @param productId               产品id
+     @param paymentMethod   支付方式 PAYPAL(0),ALIPAY(1),WXPAY(2),PADDLE(3)
+     @param price                      价格
+     @param discountFlag        0原价,1优惠券,2升级,3教育优惠,4批量购买,5黑五折扣
+     @param couponCode        优惠卷
+     @param num                      批量购买数量
+     @param complete 回调
+     */
+    func creatOrder(productId: String, paymentMethod: Int, price: String, discountFlag: Int, couponCode: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
+        checkConnectionAvailable()
+        KMMemberCenterManager.manager.createOrder(productId: productId, paymentMethod: paymentMethod, price: price, discountFlag: discountFlag, couponCode: couponCode, num: num) { [weak self] success, result in
+            if success {
+                guard let productsArrays : KMMemberProductResult = result else {
+                    complete(false, result)
+                    return
+                }
+                self?.dmgLastCreatOrderProductInfos = productsArrays
+                complete(true, productsArrays)
+            } else {
+                complete(false, result)
+            }
+        }
+    }
+    
+    /**
+     @abstract              创建订单(订阅)
+     @param productId               产品id
+     @param paymentMethod   支付方式 PAYPAL(0),ALIPAY(1),WXPAY(2),PADDLE(3)
+     @param price                      价格
+     @param discountFlag        0原价,1优惠券,2升级,3教育优惠,4批量购买,5黑五折扣
+     @param couponCode        优惠卷
+     @param num                      批量购买数量
+     @param complete 回调
+     */
+    func createSubscriber(productId: String, paymentMethod: Int, price: String, discountFlag: Int, couponCode: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
+        checkConnectionAvailable()
+        KMMemberCenterManager.manager.createSubscriber(productId: productId, paymentMethod: paymentMethod, price: price, discountFlag: discountFlag, couponCode: couponCode, num: num) { [weak self] success, result in
+            if success {
+                guard let productsArrays : KMMemberProductResult = result else {
+                    complete(false, result)
+                    return
+                }
+                self?.dmgLastCreatSubscriberProductInfos = productsArrays
+                complete(true, productsArrays)
+            } else {
+                complete(false, result)
+            }
+        }
+    }
+    
+    
     // MARK: Public Method
     
     /**