Browse Source

【会员系统】DMG 批量价格API

zenghong 1 week ago
parent
commit
852ed42c87
1 changed files with 52 additions and 17 deletions
  1. 52 17
      PDF Office/PDF Master/MemberCenter/ViewModel/KMProductModel.swift

+ 52 - 17
PDF Office/PDF Master/MemberCenter/ViewModel/KMProductModel.swift

@@ -72,13 +72,14 @@ class KMProductModel: ObservableObject {
      */
     var dmgLastGetProductPriceInfos: KMMemberProductResult?
     
-    // MARK: DMG Public Method
-    
     /**
-     @abstract 获取服务器架上所有商品 (得到的价格是原始价格)
-     @param
+     DMG 版本 已经登录用户 最后一次价格价格获取
      */
-    func getDMGProductDatas() -> Void {
+    var dmgLastGetBatchProductPriceInfos: KMMemberProductResult?
+    
+    // MARK: DMG Public Method
+    
+    func checkConnectionAvailable() -> Void {
         if KMMemberCenterManager.manager.isConnectionAvailable() == false {
             let alert = NSAlert()
             alert.alertStyle = .critical
@@ -88,12 +89,26 @@ class KMProductModel: ObservableObject {
             alert.runModal()
             return
         }
+    }
+    
+    /**
+     @abstract 获取服务器架上所有商品 (得到的价格是原始价格)
+     @param
+     */
+    func getDMGProductDatas() -> Void {
+        checkConnectionAvailable()
 
         KMMemberCenterManager.manager.getListingProducts(isEducation: 0) { [weak self] success, result in
             guard let productsArrays : KMMemberProductResult = result else { return }
             self?.dmgProductDatas = productsArrays
         }
         
+        if KMMemberInfo.shared.isLogin {
+            getDMGProductPriceInfosForMember(productId: "SP2024102100002", isEducation: 0) { [weak self] success, result in
+                
+            }
+        }
+        
     }
     
     /**
@@ -101,20 +116,40 @@ class KMProductModel: ObservableObject {
      @param
      */
     func getDMGProductPriceInfosForMember(productId: String, isEducation: Int, _ complete: @escaping KMMemberProductComplete) {
-        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
-        }
+        checkConnectionAvailable()
         //暂时无教育优惠,先固定传 0
         KMMemberCenterManager.manager.getProductPriceForBuy(productId: productId, isEducation: 0, userId:KMMemberInfo.shared.userID) { [weak self] success, result in
-            guard let productsArrays : KMMemberProductResult = result else { return }
-            self?.dmgLastGetProductPriceInfos = productsArrays
-            complete(true, productsArrays)
+            if success {
+                guard let productsArrays : KMMemberProductResult = result else {
+                    complete(false, result)
+                    return
+                }
+                self?.dmgLastGetProductPriceInfos = productsArrays
+                complete(true, productsArrays)
+            } else {
+                complete(false, result)
+            }
+        }
+    }
+    
+    /**
+     @abstract 获取批量阶段购买价格(建立订单时需要用到)
+     @param
+     */
+    func getDMGBatchProductPriceInfosForMember(productId: String, num: Int, _ complete: @escaping KMMemberProductComplete) {
+        checkConnectionAvailable()
+        //暂时无教育优惠,先固定传 0
+        KMMemberCenterManager.manager.getBatchProductPrice(productId: productId, num: 0) { [weak self] success, result in
+            if success {
+                guard let productsArrays : KMMemberProductResult = result else {
+                    complete(false, result)
+                    return
+                }
+                self?.dmgLastGetBatchProductPriceInfos = productsArrays
+                complete(true, productsArrays)
+            } else {
+                complete(false, result)
+            }
         }
     }