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

购物车 -- NetRequest (to be continued)

Chris 6 роки тому
батько
коміт
e05258491d

+ 4 - 0
RainbowPlanet/RainbowPlanet.xcodeproj/project.pbxproj

@@ -263,6 +263,7 @@
 		BDD4FB1422840954006FE833 /* ShoppingCartOrderPayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDD4FB1322840954006FE833 /* ShoppingCartOrderPayView.swift */; };
 		BDD4FB1722840DD3006FE833 /* OrderPayAcountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDD4FB1622840DD3006FE833 /* OrderPayAcountView.swift */; };
 		BDE3045D22851E4F001D050F /* ProductCartListModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDE3045C22851E4F001D050F /* ProductCartListModel.swift */; };
+		BDE3045F228554CA001D050F /* ProductCartAmountModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDE3045E228554CA001D050F /* ProductCartAmountModel.swift */; };
 		BDF47D7A228271F600941AB9 /* ShoppingCartView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDF47D79228271F600941AB9 /* ShoppingCartView.swift */; };
 		BDF47D7E22827C3F00941AB9 /* ProductSlidingTopBottomCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDF47D7D22827C3F00941AB9 /* ProductSlidingTopBottomCollectionViewCell.swift */; };
 		BDF47D80228288F900941AB9 /* ShoppingCartAccountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDF47D7F228288F900941AB9 /* ShoppingCartAccountView.swift */; };
@@ -561,6 +562,7 @@
 		BDD4FB1322840954006FE833 /* ShoppingCartOrderPayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoppingCartOrderPayView.swift; sourceTree = "<group>"; };
 		BDD4FB1622840DD3006FE833 /* OrderPayAcountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderPayAcountView.swift; sourceTree = "<group>"; };
 		BDE3045C22851E4F001D050F /* ProductCartListModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductCartListModel.swift; sourceTree = "<group>"; };
+		BDE3045E228554CA001D050F /* ProductCartAmountModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductCartAmountModel.swift; sourceTree = "<group>"; };
 		BDF47D79228271F600941AB9 /* ShoppingCartView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoppingCartView.swift; sourceTree = "<group>"; };
 		BDF47D7D22827C3F00941AB9 /* ProductSlidingTopBottomCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductSlidingTopBottomCollectionViewCell.swift; sourceTree = "<group>"; };
 		BDF47D7F228288F900941AB9 /* ShoppingCartAccountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoppingCartAccountView.swift; sourceTree = "<group>"; };
@@ -1730,6 +1732,7 @@
 				A7A98E11227ECA11005306E9 /* ProductSearchModel.swift */,
 				A70B2C062284305400B2449F /* ProductModel.swift */,
 				BDE3045C22851E4F001D050F /* ProductCartListModel.swift */,
+				BDE3045E228554CA001D050F /* ProductCartAmountModel.swift */,
 			);
 			path = ProductModel;
 			sourceTree = "<group>";
@@ -2570,6 +2573,7 @@
 				A71AA5152272160A008FF1A5 /* ExpressAddressListTableViewCell.swift in Sources */,
 				A72A72B722321DE000B21995 /* Extension+NSMutableAttributedString.swift in Sources */,
 				A7BB6857226965C100AB07A2 /* SelfRecommendationHeaderCollectionReusableView.swift in Sources */,
+				BDE3045F228554CA001D050F /* ProductCartAmountModel.swift in Sources */,
 				A7BB68672269B1DD00AB07A2 /* AddressPOIViewController.swift in Sources */,
 				A7284A7322546460000BAEC4 /* SwiftMoyaServicePayApi.swift in Sources */,
 				BDE3045D22851E4F001D050F /* ProductCartListModel.swift in Sources */,

+ 29 - 0
RainbowPlanet/RainbowPlanet/Service/Model/ProductModel/ProductCartAmountModel.swift

@@ -0,0 +1,29 @@
+//
+//  ProductCartAmountModel.swift
+//  RainbowPlanet
+//
+//  Created by Christopher on 2019/5/10.
+//  Copyright © 2019 RainbowPlanet. All rights reserved.
+//
+
+import Foundation
+import ObjectMapper
+
+
+class CartAmountModel : NSObject, Mappable{
+    
+    var amount : Int?
+    
+    
+    class func newInstance(map: Map) -> Mappable?{
+        return CartAmountModel()
+    }
+    required init?(map: Map){}
+    private override init(){}
+    
+    func mapping(map: Map)
+    {
+        amount <- map["amount"]
+    }
+    
+}

+ 118 - 3
RainbowPlanet/RainbowPlanet/Service/SwiftMoyaService/SwiftMoyaServiceApi/SwiftMoyaServiceProduct/SwiftMoyaNetWorkServiceProduct.swift

@@ -21,6 +21,7 @@ class SwiftMoyaNetWorkServiceProduct: NSObject {
     /// 数据回调
     typealias apiCallBack = (Any) -> (Void)
     
+    // MARK: - 搜索、列表、热销
     /// 搜索、列表、热销
     ///
     /// - Parameters:
@@ -46,6 +47,7 @@ class SwiftMoyaNetWorkServiceProduct: NSObject {
         }
     }
     
+    // MARK: - 商品分类
     /// 商品分类
     ///
     /// - Parameters:
@@ -64,6 +66,7 @@ class SwiftMoyaNetWorkServiceProduct: NSObject {
         }
     }
     
+    // MARK: - 首页商品
     /// 首页商品
     ///
     /// - Parameters:
@@ -85,12 +88,10 @@ class SwiftMoyaNetWorkServiceProduct: NSObject {
         }
     }
     
+    // MARK: - 购物车列表
     /// 购物车列表
     ///
     /// - Parameters:
-    ///   - uid: 用户id
-    ///   - city_id: 城市id
-    ///   - deliver_type: 配送方式
     ///   - completion: 回调
     func productCartListApi(completion: @escaping apiCallBack) {
         var parameters = Dictionary<String,Any>()
@@ -109,4 +110,118 @@ class SwiftMoyaNetWorkServiceProduct: NSObject {
             completion(productCartListData)
         }
     }
+    
+    // MARK: - 购物车-添加
+    /// 购物车-添加
+    ///
+    /// - Parameters:
+    ///   -
+    ///   - completion: 回调
+    func productCartAddApi(completion: @escaping apiCallBack) {
+        var parameters = Dictionary<String,Any>()
+        parameters.updateValue(0, forKey: "shop_id")
+        parameters.updateValue("", forKey: "shop_name")
+        parameters.updateValue(0, forKey: "product_id")
+        parameters.updateValue("", forKey: "product_name")
+        parameters.updateValue("", forKey: "product_img")
+        parameters.updateValue(0, forKey: "product_price")
+        parameters.updateValue(0, forKey: "sku_id")
+        parameters.updateValue("", forKey: "sku_name")
+        parameters.updateValue(0, forKey: "amount")
+        parameters.updateValue(0, forKey: "is_select")
+        
+        
+        parameters.updateValue(0, forKey: "city_id")
+        parameters.updateValue(0, forKey: "city_name")
+        parameters.updateValue(0, forKey: "deliver_type")
+        
+        SwiftProgressHUD.shared().showWait()
+        SwiftMoyaNetWorkManager.shared().request(target: MultiTarget(SwiftMoyaServiceProductApi.productCartAdd(parameters: parameters))) { (rootModel) in
+            let rootModel = rootModel as! RootModel
+            SwiftProgressHUD.shared().showText(rootModel.msg!)
+            completion("")
+        }
+    }
+    
+    // MARK: - 购物车-删除
+    /// 购物车-删除
+    ///
+    /// - Parameters:
+    ///   - id: 购物车id
+    ///   - completion: 回调
+    func productCartDeleteApi(id:Int = 0, completion: @escaping apiCallBack) {
+        var parameters = Dictionary<String,Any>()
+        parameters.updateValue(id, forKey: "id")
+        
+        SwiftProgressHUD.shared().showWait()
+        SwiftMoyaNetWorkManager.shared().request(target: MultiTarget(SwiftMoyaServiceProductApi.productCartDelete(parameters: parameters))) { (rootModel) in
+            let rootModel = rootModel as! RootModel
+            SwiftProgressHUD.shared().showText(rootModel.msg!)
+            completion("")
+        }
+    }
+    
+    // MARK: - 购物车-数量
+    /// 购物车-数量
+    ///
+    /// - Parameters:
+    ///   - id: 购物车id
+    ///   - type: 1-增加,2-减少
+    ///   - completion: 回调
+    func productCartAmountApi(id:Int = 0, type:Int = 0, completion: @escaping apiCallBack) {
+        var parameters = Dictionary<String,Any>()
+        parameters.updateValue(id, forKey: "id")
+        parameters.updateValue(type, forKey: "type")
+        
+        SwiftProgressHUD.shared().showWait()
+        SwiftMoyaNetWorkManager.shared().request(CartAmountModel.self, target: MultiTarget(SwiftMoyaServiceProductApi.productCartAmount(parameters: parameters))) { (cartAmountModel) in
+            SwiftProgressHUD.shared().hide()
+            completion(cartAmountModel)
+        }
+    }
+    
+    // MARK: - 购物车-选中
+    /// 购物车-选中
+    ///
+    /// - Parameters:
+    ///   - id: 表id
+    ///   - shop_id: 商户id
+    ///   - isSelect: 1-选中,0-未选中
+    ///   - completion: 回调
+    func productCartIsSelApi(id:Int = 0, shop_id:Int = 0, isSelect:Int = 0, completion: @escaping apiCallBack) {
+        var parameters = Dictionary<String,Any>()
+        parameters.updateValue(id, forKey: "id")
+        parameters.updateValue(shop_id, forKey: "shop_id")
+        parameters.updateValue(isSelect, forKey: "isSelect")
+        
+        SwiftProgressHUD.shared().showWait()
+        SwiftMoyaNetWorkManager.shared().request(target: MultiTarget(SwiftMoyaServiceProductApi.productCartIsSel(parameters: parameters))) { (rootModel) in
+            let rootModel = rootModel as! RootModel
+            SwiftProgressHUD.shared().showText(rootModel.msg!)
+            completion("")
+        }
+    }
+    
+    // MARK: - 购物车-全选
+    /// 购物车-全选
+    ///
+    /// - Parameters:
+    ///   - isSelect: 1-选中,0-未选中
+    ///   - completion: 回调
+    func productCartAllSelApi(isSelect:Int = 0, completion: @escaping apiCallBack) {
+        var parameters = Dictionary<String,Any>()
+        parameters.updateValue(isSelect, forKey: "isSelect")
+        // 本地获取city_id
+        let loacationModel = LocationModel.shared().getLocationModel()
+        let baiduToCityModel = BaiduToCityFactory.shared.query(bjcityId: loacationModel!.cityCode)
+        parameters.updateValue(baiduToCityModel.areaCode, forKey: "city_id")
+        
+        SwiftProgressHUD.shared().showWait()
+        SwiftMoyaNetWorkManager.shared().request(target: MultiTarget(SwiftMoyaServiceProductApi.productCartAllSel(parameters: parameters))) { (rootModel) in
+            let rootModel = rootModel as! RootModel
+            SwiftProgressHUD.shared().showText(rootModel.msg!)
+            completion("")
+        }
+    }
+    
 }

+ 69 - 3
RainbowPlanet/RainbowPlanet/Service/SwiftMoyaService/SwiftMoyaServiceApi/SwiftMoyaServiceProduct/SwiftMoyaServiceProductApi.swift

@@ -25,6 +25,26 @@ public let kProductHomeProductApi = "/product/honmeProduct"
 /// 购物车列表
 public let kProductCartListApi = "/product/cartList"
 
+// MARK: - 购物车-添加
+/// 购物车-添加
+public let kProductCartAddApi = "/product/cartAdd"
+
+// MARK: - 购物车-删除
+/// 购物车-删除
+public let kProductCartDeleteApi = "/product/deleteCart"
+
+// MARK: - 购物车-数量
+/// 购物车-数量
+public let kProductCartAmountApi = "/product/setProductAmount"
+
+// MARK: - 购物车-选中
+/// 购物车-选中
+public let kProductCartIsSelApi = "/cart/isSelect"
+
+// MARK: - 购物车-全选
+/// 购物车-全选
+public let kProductCartAllSelApi = "/cart/isSelectAll"
+
 
 /// 商品
 ///
@@ -32,11 +52,21 @@ public let kProductCartListApi = "/product/cartList"
 /// - productCategory: 商品分类
 /// - productHomeProduct: 首页商品
 /// - productCartList: 购物车列表
+/// - productCartAdd: 购物车-添加
+/// - productCartDelete: 购物车-删除
+/// - productCartAmount: 购物车-数量
+/// - productCartIsSel: 购物车-选中
+/// - productCartAllSel: 购物车-全选
 public enum SwiftMoyaServiceProductApi {
     case productSearch(parameters:Dictionary<String, Any>)
     case productCategory(parameters:Dictionary<String, Any>)
     case productHomeProduct(parameters:Dictionary<String, Any>)
     case productCartList(parameters:Dictionary<String, Any>)
+    case productCartAdd(parameters:Dictionary<String, Any>)
+    case productCartDelete(parameters:Dictionary<String, Any>)
+    case productCartAmount(parameters:Dictionary<String, Any>)
+    case productCartIsSel(parameters:Dictionary<String, Any>)
+    case productCartAllSel(parameters:Dictionary<String, Any>)
 }
 
 extension SwiftMoyaServiceProductApi: TargetType {
@@ -46,7 +76,12 @@ extension SwiftMoyaServiceProductApi: TargetType {
         case .productSearch,
              .productCategory,
              .productHomeProduct,
-             .productCartList
+             .productCartList,
+             .productCartAdd,
+             .productCartDelete,
+             .productCartAmount,
+             .productCartIsSel,
+             .productCartAllSel
             :
             return URL(string: kApiDataPrefix())!
         }
@@ -62,6 +97,16 @@ extension SwiftMoyaServiceProductApi: TargetType {
             return kProductHomeProductApi
         case .productCartList:
             return kProductCartListApi
+        case .productCartAdd:
+            return kProductCartAddApi
+        case .productCartDelete:
+            return kProductCartDeleteApi
+        case .productCartAmount:
+            return kProductCartAmountApi
+        case .productCartIsSel:
+            return kProductCartIsSelApi
+        case .productCartAllSel:
+            return kProductCartAllSelApi
         }
     }
     
@@ -73,6 +118,17 @@ extension SwiftMoyaServiceProductApi: TargetType {
              .productCartList
             :
             return .post
+        case .productCartAdd,
+             .productCartAmount,
+             .productCartIsSel,
+             .productCartAllSel
+            :
+//            return .put
+            return .post
+        case .productCartDelete
+            :
+//            return .delete
+            return .post
         }
     }
     
@@ -82,7 +138,12 @@ extension SwiftMoyaServiceProductApi: TargetType {
         case .productSearch(var parameters),
              .productCategory(var parameters),
              .productHomeProduct(var parameters),
-             .productCartList(var parameters)
+             .productCartList(var parameters),
+             .productCartAdd(var parameters),
+             .productCartDelete(var parameters),
+             .productCartAmount(var parameters),
+             .productCartIsSel(var parameters),
+             .productCartAllSel(var parameters)
             :
             let sign = SwiftSign.shared().sign(signType:.AccessToken, parameters: parameters)
             parameters.updateValue(sign, forKey: "sign")
@@ -108,7 +169,12 @@ extension SwiftMoyaServiceProductApi: TargetType {
         case .productSearch,
              .productCategory,
              .productHomeProduct,
-             .productCartList
+             .productCartList,
+             .productCartAdd,
+             .productCartDelete,
+             .productCartAmount,
+             .productCartIsSel,
+             .productCartAllSel
             :
             return (headerParameters(headerType: .tokenHeader) as! [String : String])
         }