Bläddra i källkod

支付流程完成

南鑫林 6 år sedan
förälder
incheckning
068023acb1
13 ändrade filer med 716 tillägg och 76 borttagningar
  1. 1 2
      RainbowPlanet/.gitignore
  2. 1 1
      RainbowPlanet/Podfile.lock
  3. 4 4
      RainbowPlanet/RainbowPlanet.xcodeproj/project.pbxproj
  4. 18 6
      RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCartPayOrder/View/ShoppingCartOrderPayView.swift
  5. 1 1
      RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCartPayOrder/View/ShoppingCartPayOrderItemCell.swift
  6. 39 33
      RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCartPayOrder/ViewController/ShoppingCartPayOrderController.swift
  7. 7 0
      RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductDetail/View/Cell/ProductDetailProductLabel/ProductDetailProductLabelIconCollectionViewCell.swift
  8. 41 18
      RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductDetail/View/Cell/ProductDetailProductLabel/ProductDetailProductLabelTableViewCell.swift
  9. 485 0
      RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductDetail/View/ProductDetailView.swift
  10. 36 0
      RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductDetail/ViewController/ProductDetailViewController.swift
  11. 3 10
      RainbowPlanet/RainbowPlanet/Service/SwiftMoyaService/SwiftMoyaServiceApi/SwiftMoyaServicePay/SwiftMoyaNetWorkServicePay.swift
  12. 1 1
      RainbowPlanet/RainbowPlanet/Service/SwiftMoyaService/SwiftMoyaServiceApi/SwiftMoyaServiceProduct/SwiftMoyaNetWorkServiceProduct.swift
  13. 79 0
      RainbowPlanet/RainbowPlanet/Service/SwiftMoyaService/SwiftMoyaServiceManger/SwiftMoyaNetWorkManager/SwiftMoyaNetWorkManager.swift

+ 1 - 2
RainbowPlanet/.gitignore

@@ -21,5 +21,4 @@ DerivedData
 
 #CocoaPods
 Pods
-!Podfile
-!Podfile.lock
+!Podfile

+ 1 - 1
RainbowPlanet/Podfile.lock

@@ -169,4 +169,4 @@ SPEC CHECKSUMS:
 
 PODFILE CHECKSUM: 8367a381fb27c958a744db1b81ae93efe4c465ee
 
-COCOAPODS: 1.6.1
+COCOAPODS: 1.6.2

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

@@ -41,7 +41,7 @@
 		A70B2C75228920BA00B2449F /* ProductDetailSkuSectionHeaerCollectionReusableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A70B2C74228920BA00B2449F /* ProductDetailSkuSectionHeaerCollectionReusableView.swift */; };
 		A70B842E228F97EC00882BC5 /* ProcuctDetailSelectSkuTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A70B842D228F97EC00882BC5 /* ProcuctDetailSelectSkuTableViewCell.swift */; };
 		A70B8430228FF6D400882BC5 /* ProductCartCountModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A70B842F228FF6D400882BC5 /* ProductCartCountModel.swift */; };
-		A70B84322290046D00882BC5 /* ProductDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A70B84312290046D00882BC5 /* ProductDetailView.swift */; };
+		A70B843422911AF600882BC5 /* ProductDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A70B843322911AF600882BC5 /* ProductDetailView.swift */; };
 		A70EBBC022561179000AD74F /* Extension+UITableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A70EBBBF22561179000AD74F /* Extension+UITableView.swift */; };
 		A7146349228EFCE20066099B /* ORSKUDataFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = A7146347228EFCE20066099B /* ORSKUDataFilter.m */; };
 		A714634E228F020A0066099B /* ORSKUDataFilterSwift.swift in Sources */ = {isa = PBXBuildFile; fileRef = A714634D228F020A0066099B /* ORSKUDataFilterSwift.swift */; };
@@ -421,7 +421,7 @@
 		A70B2C74228920BA00B2449F /* ProductDetailSkuSectionHeaerCollectionReusableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductDetailSkuSectionHeaerCollectionReusableView.swift; sourceTree = "<group>"; };
 		A70B842D228F97EC00882BC5 /* ProcuctDetailSelectSkuTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProcuctDetailSelectSkuTableViewCell.swift; sourceTree = "<group>"; };
 		A70B842F228FF6D400882BC5 /* ProductCartCountModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductCartCountModel.swift; sourceTree = "<group>"; };
-		A70B84312290046D00882BC5 /* ProductDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductDetailView.swift; sourceTree = "<group>"; };
+		A70B843322911AF600882BC5 /* ProductDetailView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProductDetailView.swift; sourceTree = "<group>"; };
 		A70EBBBF22561179000AD74F /* Extension+UITableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Extension+UITableView.swift"; sourceTree = "<group>"; };
 		A7146347228EFCE20066099B /* ORSKUDataFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ORSKUDataFilter.m; sourceTree = "<group>"; };
 		A7146348228EFCE20066099B /* ORSKUDataFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ORSKUDataFilter.h; sourceTree = "<group>"; };
@@ -897,6 +897,7 @@
 		A70B2C192286B4ED00B2449F /* View */ = {
 			isa = PBXGroup;
 			children = (
+				A70B843322911AF600882BC5 /* ProductDetailView.swift */,
 				A70B2C702289016600B2449F /* ProductDetailSkuView */,
 				A70B2C39228819CA00B2449F /* Cell */,
 			);
@@ -939,7 +940,6 @@
 				A70B2C442288408E00B2449F /* ProductDetailHotSell */,
 				A70B2C4A228845B200B2449F /* ProductDetailParameter */,
 				A70B2C4F22884EF100B2449F /* ProductDetailDescription */,
-				A70B84312290046D00882BC5 /* ProductDetailView.swift */,
 			);
 			path = Cell;
 			sourceTree = "<group>";
@@ -3457,6 +3457,7 @@
 				A72A72B422321DE000B21995 /* Extension+UIImage.swift in Sources */,
 				A7BB68552268DE8600AB07A2 /* SelfRecommendationView.swift in Sources */,
 				A72A72AF22321DE000B21995 /* AppInfo.swift in Sources */,
+				A70B843422911AF600882BC5 /* ProductDetailView.swift in Sources */,
 				A7D460942276854500A5A54E /* BaiduToCity2Model.swift in Sources */,
 				A72A72D422321E2700B21995 /* EnumMacro.swift in Sources */,
 				A7FF1598228D092A00A85748 /* OrderListModel.swift in Sources */,
@@ -3600,7 +3601,6 @@
 				BD7AB8452284398A0030646A /* OrderPaySelfPickAddInfoCell.swift in Sources */,
 				A72A72D222321E2700B21995 /* Common.swift in Sources */,
 				A70B2C64228875DE00B2449F /* ShopViewShopInfoTableViewCell.swift in Sources */,
-				A70B84322290046D00882BC5 /* ProductDetailView.swift in Sources */,
 				BDEF7791228571DC00ED0AC0 /* CommonPayView.swift in Sources */,
 				A71AF0A6226EDDC8001730FE /* SearchViewController.swift in Sources */,
 				BD20F1CF2283CE2300677D8E /* ShoppingCartFinishPayView.swift in Sources */,

+ 18 - 6
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCartPayOrder/View/ShoppingCartOrderPayView.swift

@@ -26,7 +26,14 @@ class ShoppingCartOrderPayView: BaseView {
     // 已选商品ModelArr
     var proListModelArr : Array<CartProductListModel>? {
         didSet {
-            tableView.reloadData()
+            if proListModelArr != nil {
+                tableView.reloadData()
+                accountView.isHidden = false
+
+            }else {
+                accountView.isHidden = true
+            }
+            
         }
     }
     
@@ -36,14 +43,18 @@ class ShoppingCartOrderPayView: BaseView {
     // 快递地址信息Mdl
     var expressAddressMdl: ExpressAddresModel? {
         didSet {
-            self.tableView.reloadSections([0], with: UITableView.RowAnimation.none)
+            if expressAddressMdl != nil {
+                tableView.reloadData()
+            }
         }
     }
     
     // 自提地址信息Mdl
     var selfAddressInfoMdl: DefaultContactInfoModel? {
         didSet {
-            self.tableView.reloadSections([0], with: UITableView.RowAnimation.none)
+            if selfAddressInfoMdl != nil {
+                tableView.reloadData()
+            }
         }
     }
     
@@ -121,7 +132,8 @@ class ShoppingCartOrderPayView: BaseView {
 // MARK: - tableView dataSource && delegate
 extension ShoppingCartOrderPayView : UITableViewDelegate, UITableViewDataSource {
     func numberOfSections(in tableView: UITableView) -> Int {
-        return proListModelArr!.count + 1
+        
+        return proListModelArr?.isEmpty ?? true ? 0 : (proListModelArr?.count ?? 0) + 1
     }
     
     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
@@ -137,7 +149,7 @@ extension ShoppingCartOrderPayView : UITableViewDelegate, UITableViewDataSource
                 return 1
             }
         } else {
-            return proListModelArr![section-1].productList!.count
+            return proListModelArr![section-1].productList?.isEmpty ?? true ? 0 : proListModelArr![section-1].productList?.count ?? 0
         }
     }
     
@@ -300,7 +312,7 @@ extension ShoppingCartOrderPayView {
         
         let cartProListMdl: CartProductListModel = proListModelArr![section]
         for productMdl in cartProListMdl.productList! {
-            totalPrice += productMdl.skuPrice! * productMdl.amount!
+            totalPrice += ((productMdl.skuPrice ?? 0) * (productMdl.amount ?? 0))
         }
         return totalPrice
     }

+ 1 - 1
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCartPayOrder/View/ShoppingCartPayOrderItemCell.swift

@@ -17,7 +17,7 @@ class ShoppingCartPayOrderItemCell: UITableViewCell {
             // 商品名称
             titleLabel.text = productMdl?.productName
             // 预计配送时间
-            deliveryTime.text = "预计配送时间:次日达"
+            deliveryTime.text = "预计配送时间:\(productMdl?.receiveTime ?? "")"
             // 规格
             sellScaleLabel.text = "规格:\(productMdl?.skuName ?? "")"
             // 数量

+ 39 - 33
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCartPayOrder/ViewController/ShoppingCartPayOrderController.swift

@@ -22,6 +22,7 @@ class ShoppingCartPayOrderController: BaseViewController {
     
     // 已选商品ModelArr
     var selListModelArr : Array<CartProductListModel>?
+
     // 全部已选总价
     var totalProductPrice: Int?
     
@@ -37,11 +38,14 @@ class ShoppingCartPayOrderController: BaseViewController {
     
     override func setupViews() {
         navigationBar.title = "订单支付"
-        self.setOrderPayView()
+        view.addSubview(orderPayView)
     }
     
     override func setupLayouts() {
-        
+        orderPayView.snp.makeConstraints { (make) in
+            make.bottom.left.right.equalToSuperview()
+            make.top.equalTo(kNavBarTotalHeight)
+        }
     }
     
     override func setupData() {
@@ -57,25 +61,7 @@ class ShoppingCartPayOrderController: BaseViewController {
         default:
             break
         }
-    }
-    
-    /// 添加view
-    func setOrderPayView() {
-        view.addSubview(orderPayView)
-        orderPayView.snp.makeConstraints { (make) in
-            make.bottom.left.right.equalToSuperview()
-            make.top.equalTo(kNavBarTotalHeight)
-        }
-    }
-    
-    private lazy var orderPayView: ShoppingCartOrderPayView = {
-        let orderPayView = ShoppingCartOrderPayView()
-        orderPayView.proListModelArr = self.selListModelArr
-        orderPayView.totalProductPrice = self.totalProductPrice!
-        orderPayView.commitOrderTransBlock = {
-            [weak self] (paraMdl) in
-            self?.orderCreateApi(paraMdl: paraMdl)
-        }
+        
         orderPayView.jumpNavBlock = {
             [weak self] (jumpType) in
             switch jumpType {
@@ -91,12 +77,24 @@ class ShoppingCartPayOrderController: BaseViewController {
             case WillJumpType.selfPersonalInfo:
                 let vc = SelfMentionContactsListViewController()
                 self?.navigationController?.pushViewController(vc, animated: true)
-            case WillJumpType.selfAddressInfo:                
+            case WillJumpType.selfAddressInfo:
                 let vc = SelfRecommendationViewController()
                 self?.navigationController?.pushViewController(vc, animated: true)
             }
         }
         
+        orderPayView.commitOrderTransBlock = {
+            [weak self] (paraMdl) in
+            if self?.selListModelArr != nil {
+                self?.orderCreateApi(paraMdl: paraMdl)
+            }
+        }
+    }
+    
+    private lazy var orderPayView: ShoppingCartOrderPayView = {
+        let orderPayView = ShoppingCartOrderPayView()
+        orderPayView.proListModelArr = self.selListModelArr
+        orderPayView.totalProductPrice = self.totalProductPrice ?? 0
         return orderPayView
     }()
     
@@ -121,9 +119,7 @@ class ShoppingCartPayOrderController: BaseViewController {
             // 弹出支付方式View
             AlertSheetView.payAlertSheetView(cancelClosure: {
                 [weak self] in
-                let vc = ShoppingCartFinishPayController()
-                vc.payStatus = false
-                self?.navigationController?.pushViewController(vc, animated: true)
+                self?.pushVC(payStatus: false)
             }, sureClosure: { [weak self] (payType) in
                 switch payType {
                 case .wechatPay:
@@ -137,19 +133,29 @@ class ShoppingCartPayOrderController: BaseViewController {
     
     // 微信支付
     func payWeixinpayApi(orderPayModel: OrderCreateBackModel) {
-        SwiftMoyaNetWorkServicePay.shared().payWeixinpayApi(paraMdl: orderPayModel) { [weak self] (data) -> (Void) in            
-            let vc = ShoppingCartFinishPayController()
-            vc.payStatus = true
-            self?.navigationController?.pushViewController(vc, animated: true)
+        SwiftMoyaNetWorkServicePay.shared().payWeixinpayApi(paraMdl: orderPayModel) { [weak self] (weChatpayOrderModel) -> (Void) in
+            PayManager.shared().weixinpay(wechatpayOrderModel: weChatpayOrderModel as! WeChatpayOrderModel, successPayBlock: {
+                self?.pushVC(payStatus: true)
+            }, failPayBlock: {
+                self?.pushVC(payStatus: false)
+            })
         }
     }
     
+    func pushVC(payStatus: Bool){
+        let vc = ShoppingCartFinishPayController()
+        vc.payStatus = true
+        self.navigationController?.pushViewController(vc, animated: true)
+    }
+    
     // 支付宝支付
     func payAlipayApi(orderPayModel: OrderCreateBackModel) {
-        SwiftMoyaNetWorkServicePay.shared().payAlipayApi(paraMdl: orderPayModel) { [weak self] (data) -> (Void) in
-            let vc = ShoppingCartFinishPayController()
-            vc.payStatus = true
-            self?.navigationController?.pushViewController(vc, animated: true)
+        SwiftMoyaNetWorkServicePay.shared().payAlipayApi(paraMdl: orderPayModel) { [weak self] (orderString) -> (Void) in
+            PayManager.shared().alipay(orderString: orderString as? String ?? "" , successPayBlock: {
+                 self?.pushVC(payStatus: true)
+            }, failPayBlock: {
+                self?.pushVC(payStatus: false)
+            })
         }
     }
     

+ 7 - 0
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductDetail/View/Cell/ProductDetailProductLabel/ProductDetailProductLabelIconCollectionViewCell.swift

@@ -63,4 +63,11 @@ class ProductDetailProductLabelIconCollectionViewCell: UICollectionViewCell {
         titleLabel.font = kRegularFont13
         return titleLabel
     }()
+    
+    var label : ProductDetailLabelModel? {
+        didSet {
+            iconImageView.kf.setImage(with: kURLImage(name: label?.img ?? "pic_preload"), placeholder: kImage(name: "pic_preload"))
+            titleLabel.text = label?.name
+        }
+    }
 }

+ 41 - 18
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductDetail/View/Cell/ProductDetailProductLabel/ProductDetailProductLabelTableViewCell.swift

@@ -113,13 +113,7 @@ class ProductDetailProductLabelTableViewCell: UITableViewCell {
     
     var productDetailModel : ProductDetailModel? {
         didSet {
-            if productDetailModel?.report?.isEmpty ?? true {
-                iconImageView.isHidden = true
-                titleLabel.isHidden = true
-            }else {
-                iconImageView.isHidden = false
-                titleLabel.isHidden = false
-            }
+
         }
     }
     
@@ -131,13 +125,42 @@ class ProductDetailProductLabelTableViewCell: UITableViewCell {
         self.iconCollectionView.reloadData()
         //更新collectionView的高度约束
         let contentSize1 = self.iconCollectionView.collectionViewLayout.collectionViewContentSize
-        iconCollectionView.snp.remakeConstraints { (make) in
-            make.top.equalToSuperview()
-            make.height.equalTo(contentSize1.height)
-            make.left.equalTo(0)
-            make.width.equalTo(4*(kScreenWidth/5))
-            make.bottom.equalToSuperview()
+        if productDetailModel?.report?.isEmpty ?? true {
+            bgView.isHidden = true
+            iconImageView.isHidden = true
+            titleLabel.isHidden = true
+            bgView.snp.remakeConstraints { (make) in
+                make.top.equalTo(10)
+                make.bottom.equalTo(-10)
+                make.right.equalToSuperview()
+                make.width.equalTo(0)
+            }
+            iconCollectionView.snp.remakeConstraints { (make) in
+                make.top.equalToSuperview()
+                make.height.equalTo(contentSize1.height)
+                make.left.equalTo(0)
+                make.width.equalTo(kScreenWidth)
+                make.bottom.equalToSuperview()
+            }
+        }else {
+            bgView.isHidden = false
+            iconImageView.isHidden = false
+            titleLabel.isHidden = false
+            bgView.snp.makeConstraints { (make) in
+                make.top.equalTo(10)
+                make.bottom.equalTo(-10)
+                make.right.equalToSuperview()
+                make.width.equalTo(kScreenWidth/5)
+            }
+            iconCollectionView.snp.remakeConstraints { (make) in
+                make.top.equalToSuperview()
+                make.height.equalTo(contentSize1.height)
+                make.left.equalTo(0)
+                make.width.equalTo(4*(kScreenWidth/5))
+                make.bottom.equalToSuperview()
+            }
         }
+       
         self.iconCollectionView.collectionViewLayout.invalidateLayout()
     }
 
@@ -145,17 +168,17 @@ class ProductDetailProductLabelTableViewCell: UITableViewCell {
 
 extension ProductDetailProductLabelTableViewCell: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
     func numberOfSections(in collectionView: UICollectionView) -> Int {
-        return 1
+        return  self.productDetailModel?.label?.isEmpty ?? true ? 0 :1
     }
     
     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
-        return 4
+        return self.productDetailModel?.label?.count ?? 0
     }
     
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
-            let cell = ProductDetailProductLabelIconCollectionViewCell.cellWith(collectionView: collectionView, indexPath: indexPath)
-            return cell
-       
+        let cell = ProductDetailProductLabelIconCollectionViewCell.cellWith(collectionView: collectionView, indexPath: indexPath)
+        cell.label = self.productDetailModel?.label?[indexPath.row]
+        return cell
     }
     
     func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {

+ 485 - 0
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductDetail/View/ProductDetailView.swift

@@ -0,0 +1,485 @@
+
+//  ProductDetailView.swift
+//  RainbowPlanet
+//
+//  Created by 南鑫林 on 2019/5/11.
+//  Copyright © 2019 RainbowPlanet. All rights reserved.
+//
+
+import UIKit
+import PPBadgeViewSwift
+import FWPopupView
+
+class ProductDetailView: BaseView {
+    
+    typealias LookAllCommentClosure = () -> Void
+    var lookAllCommentClosure : LookAllCommentClosure?
+    
+    typealias AddCartClosure = (ProductDetailSkuModel) -> Void
+    var addCartClosure : AddCartClosure?
+    
+    typealias BuyNowClosure = (ProductDetailSkuModel) -> Void
+    var buyNowClosure : BuyNowClosure?
+    
+    var productDetailSkuModel : ProductDetailSkuModel?
+    
+    var titles = ["","","商品评价","","热销排行","商品参数","商品详情"]
+    
+    var index : Int? {
+        didSet {
+            if index == 0 {
+                tableView.scrollToTop()
+            }else {
+                let reloadSection = 2 * index!
+                let rect = tableView.rect(forSection: reloadSection)
+                tableView.setContentOffset(CGPoint(x: 0, y: rect.origin.y - kNavBarTotalHeight), animated: true)
+            }
+            
+        }
+    }
+    
+    var productDetailModel : ProductDetailModel? {
+        didSet {
+            tableView.ly_startLoading()
+            tableView.reloadData()
+            if productDetailModel != nil {
+                
+                if productDetailModel?.commentNumber != 0 && productDetailModel?.commentNumber != nil {
+                    titles[2] = "商品评价" + "(" + "\(productDetailModel?.commentNumber ?? 0)" + ")"
+                    
+                }
+                if productDetailModel?.imgs?.isEmpty ?? true {
+                    tableView.tableHeaderView = nil
+                }else {
+                    tableView.ly_hideEmpty()
+                    tableView.tableHeaderView = productDetailTableViewHeaderView
+                    productDetailTableViewHeaderView.productDetailModel = productDetailModel
+                }
+            }
+        }
+    }
+    
+    var productSearchListModel: ProductSearchListModel? {
+        didSet {
+            tableView.reloadData()
+        }
+    }
+    
+    var productCommentListModel :ProductCommentListModel? {
+        didSet {
+            tableView.reloadData()
+        }
+    }
+    
+    
+    override func setupViews() {
+        addSubview(bottomBgView)
+        bottomBgView.addSubview(cartButton)
+        cartButton.addSubview(cartImageView)
+        bottomBgView.addSubview(addCartButton)
+        bottomBgView.addSubview(buyButton)
+        addSubview(tableView)
+        addSubview(topButton)
+        if #available(iOS 11.0, *) {
+            tableView.contentInsetAdjustmentBehavior = .never
+        }
+        let emptyView =  EmptyView.shared.diyCustomEmptyViewStyle2(iconStr: "page04", titleStr: "当前暂无数据")
+        emptyView.contentViewY = kScaleValue(value: 182)
+        tableView.ly_emptyView = emptyView
+    }
+    
+    override func setupLayouts() {
+        bottomBgView.snp.makeConstraints { (make) in
+            make.left.bottom.right.equalToSuperview()
+            make.height.equalTo(50 + kSafeTabBarHeight)
+        }
+        cartButton.snp.makeConstraints { (make) in
+            make.top.left.equalToSuperview()
+            make.width.equalTo(71 * kScaleWidth)
+            make.bottom.equalTo(-kSafeTabBarHeight)
+        }
+        cartImageView.snp.makeConstraints { (make) in
+            make.center.equalToSuperview()
+        }
+        addCartButton.snp.makeConstraints { (make) in
+            make.left.equalTo(cartButton.snp.right)
+            make.top.bottom.equalTo(cartButton)
+            make.width.equalTo(152 * kScaleWidth)
+        }
+        buyButton.snp.makeConstraints { (make) in
+            make.left.equalTo(addCartButton.snp.right)
+            make.top.bottom.equalTo(cartButton)
+            make.width.equalTo(152 * kScaleWidth)
+        }
+        tableView.snp.makeConstraints { (make) in
+            make.top.left.right.equalToSuperview()
+            make.bottom.equalTo(bottomBgView.snp.top)
+        }
+        topButton.snp.makeConstraints { (make) in
+            make.right.equalTo(-10)
+            make.size.equalTo(44)
+            make.bottom.equalTo(-70-kSafeTabBarHeight)
+        }
+    }
+    
+    lazy var tableView: UITableView = {
+        let tableView = UITableView(frame: CGRect.zero, style: UITableView.Style.grouped)
+        tableView.separatorStyle = .none
+        tableView.backgroundColor = kf7f8faColor
+        tableView.dataSource = self
+        tableView.delegate = self
+        tableView.estimatedRowHeight = 0.000001
+        tableView.estimatedSectionFooterHeight = 0.000001
+        tableView.estimatedSectionHeaderHeight = 0.000001
+        return tableView
+    }()
+    
+    lazy var productDetailTableViewHeaderView: ProductDetailTableViewHeaderView = {
+        let productDetailTableViewHeaderView = ProductDetailTableViewHeaderView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 251+kSafeTabBarHeight))
+        return productDetailTableViewHeaderView
+    }()
+    
+    private lazy var bottomBgView: UIView = {
+        let bottomBgView = UIView()
+        return bottomBgView
+    }()
+    
+    private lazy var cartButton : UIButton = {
+        let cartButton = UIButton()
+        return cartButton
+    }()
+    
+    private lazy var cartImageView: UIImageView = {
+        let cartImageView = UIImageView()
+        cartImageView.image = kImage(name: "tabbar_shopping")
+        cartImageView.pp.badgeView.backgroundColor = kfe352bColor
+        cartImageView.pp.moveBadge(x: -2, y: 2)
+        return cartImageView
+    }()
+    
+    private lazy var addCartButton : UIButton = {
+        let addCartButton = UIButton(type: UIButton.ButtonType.custom)
+        addCartButton.setTitle("加入购物车", for: UIControl.State.normal)
+        addCartButton.setTitleColor(UIColor.white, for: UIControl.State.normal)
+        addCartButton.backgroundColor = k404040Color
+        addCartButton.titleLabel?.font = kRegularFont16
+        addCartButton.rx.tap.subscribe(onNext: {
+            [weak self] (data) in
+            self?.view.productDetailSkuViewType = ProductDetailSkuViewType.addCart
+            self?.view.productDetailModel = self?.productDetailModel
+            self?.view.show()
+        }).disposed(by: disposeBag)
+        return addCartButton
+    }()
+    
+    private lazy var buyButton : UIButton = {
+        let buyButton = UIButton(type: UIButton.ButtonType.custom)
+        buyButton.setTitle("立即购买", for: UIControl.State.normal)
+        buyButton.setTitleColor(UIColor.white, for: UIControl.State.normal)
+        buyButton.backgroundColor = kFFA42FColor
+        buyButton.titleLabel?.font = kRegularFont16
+        buyButton.rx.tap.subscribe(onNext: {
+            [weak self] (data) in
+            self?.view.productDetailSkuViewType = ProductDetailSkuViewType.buyNow
+            self?.view.productDetailModel = self?.productDetailModel
+            self?.view.show()
+        }).disposed(by: disposeBag)
+        return buyButton
+    }()
+    
+    private lazy var topButton : UIButton = {
+        let topButton = UIButton(type: UIButton.ButtonType.custom)
+        topButton.setImage(kImage(name: "product_detail_top"), for: UIControl.State.normal)
+        topButton.rx.tap.subscribe(onNext: { [weak self] (data) in
+            self?.tableView.scrollToTop()
+        }).disposed(by: disposeBag)
+        return topButton
+    }()
+    
+    
+    lazy var view: ProductDetailSkuView = {
+        let view = ProductDetailSkuView(frame: CGRect(x: 0, y: 0, width: kScreenWidth , height: kScreenHeight - 76 - kNavBarTotalHeight))
+        let vProperty1 = FWPopupViewProperty()
+        vProperty1.popupCustomAlignment = .bottomCenter
+        vProperty1.popupAnimationType = .frame
+        vProperty1.maskViewColor = UIColor(white: 0, alpha: 0.5)
+        vProperty1.touchWildToHide = "0"
+        vProperty1.popupViewEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
+        vProperty1.animationDuration = 0.1
+        view.vProperty = vProperty1
+        view.sureClosure = {
+            [weak self] (productDetailSkuViewType,productDetailSkuModel) in
+            self?.productDetailSkuModel = productDetailSkuModel
+            switch productDetailSkuViewType {
+            case .selectSku:
+                self?.tableView.reloadData()
+                view.hide()
+                break
+            case .buyNow:
+                view.hide(popupDidDisappearBlock: { (FWPopupView) in
+                    self?.tableView.reloadData()
+                    if let buyNowClosure = self?.buyNowClosure {
+                        buyNowClosure((self?.productDetailSkuModel)!)
+                    }
+                })
+                break
+            case .addCart:
+
+                if let addCartClosure = self?.addCartClosure {
+                    addCartClosure((self?.productDetailSkuModel)!)
+                }
+                break
+            }
+        }
+        return view
+    }()
+    
+    var productCartCount : Int = 0 {
+        didSet {
+            if productCartCount == 0 {
+                cartImageView.pp.hiddenBadge()
+            }else {
+                cartImageView.pp.addBadge(number: productCartCount)
+            }
+            self.tableView.reloadData()
+            self.view.hide()
+        }
+    }
+    var productCartCountModel : ProductCartCountModel? {
+        didSet {
+            if productCartCountModel != nil {
+                if productCartCountModel?.count == 0 {
+                    cartImageView.pp.hiddenBadge()
+                }else {
+                    cartImageView.pp.addBadge(number: productCartCountModel?.count ?? 0)
+                }
+            }
+            
+        }
+    }
+    
+}
+
+extension ProductDetailView : UITableViewDelegate, UITableViewDataSource {
+    func numberOfSections(in tableView: UITableView) -> Int {
+        if productDetailModel != nil {
+            return 7
+        }
+        return 0
+    }
+    
+    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
+        switch section {
+        case 1:
+            
+            if !(productDetailModel?.spec?.isEmpty ?? true) && !(productDetailModel?.label?.isEmpty ?? true) {
+                return 2
+            }
+            
+            if (productDetailModel?.spec?.isEmpty ?? true) && !(productDetailModel?.label?.isEmpty ?? true) {
+                return 1
+            }
+            
+            if !(productDetailModel?.spec?.isEmpty ?? true) && (productDetailModel?.label?.isEmpty ?? true) {
+                return 1
+            }
+            return 0
+            
+        case 2:
+            if productCommentListModel != nil {
+                return productCommentListModel?.data?.isEmpty ?? true ? 0 :  1
+            }
+            return 0
+            
+        case 5:
+            return productDetailModel?.parameter?.isEmpty ?? true ? 0 :  productDetailModel?.parameter?.count ?? 0
+        default:
+            return 1
+        }
+    }
+    
+    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
+        
+        
+        switch indexPath.section {
+        case 0:
+            let cell = ProductDetailProductInfoTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
+            cell.productDetailModel = productDetailModel
+            return cell
+        case 1:
+            if !(productDetailModel?.spec?.isEmpty ?? true) && !(productDetailModel?.label?.isEmpty ?? true) {
+                if indexPath.row == 0 {
+                    let cell = ProcuctDetailSelectSkuTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
+                    if self.productDetailSkuModel != nil {
+                        cell.productDetailSkuModel = self.productDetailSkuModel
+                    }
+                    return cell
+                }else {
+                    let cell = ProductDetailProductLabelTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
+                    cell.productDetailModel = productDetailModel
+                    cell.frame = tableView.bounds
+                    cell.layoutIfNeeded()
+                    cell.reloadData()
+                    return cell
+                }
+            }
+            
+            if (productDetailModel?.spec?.isEmpty ?? true) && !(productDetailModel?.label?.isEmpty ?? true) {
+                let cell = ProductDetailProductLabelTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
+                cell.productDetailModel = productDetailModel
+                cell.frame = tableView.bounds
+                cell.layoutIfNeeded()
+                cell.reloadData()
+                return cell
+            }
+            
+            if !(productDetailModel?.spec?.isEmpty ?? true) && (productDetailModel?.label?.isEmpty ?? true) {
+                let cell = ProcuctDetailSelectSkuTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
+                if self.productDetailSkuModel != nil {
+                    cell.productDetailSkuModel = self.productDetailSkuModel
+                }
+                return cell
+            }
+            return UITableViewCell()
+        case 2:
+            let cell = ProductDetailEvaluationTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
+            cell.productCommentModel = productCommentListModel?.data?[indexPath.row]
+            return cell
+        case 3:
+            let cell = ProductDetailShopTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
+            cell.productDetailModel = productDetailModel
+            return cell
+        case 4:
+            let cell = ProductDetailHotSellTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
+            cell.productSearchListModel = productSearchListModel
+            return cell
+        case 5:
+            let cell = ProductDetailParameterTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
+            cell.productDetailModel = productDetailModel
+            return cell
+        case 6:
+            let cell = ProductDetailDescriptionTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
+            cell.productDetailModel = productDetailModel
+            return cell
+            
+        default:
+            
+            return UITableViewCell()
+        }
+        
+    }
+    
+    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
+        if indexPath.section == 1 {
+            if !(productDetailModel?.spec?.isEmpty ?? true) && !(productDetailModel?.label?.isEmpty ?? true) {
+                if indexPath.row == 0 {
+                    self.view.productDetailSkuViewType = ProductDetailSkuViewType.selectSku
+                    self.view.productDetailModel = self.productDetailModel
+                    self.view.show()
+                }
+            }
+            if !(productDetailModel?.spec?.isEmpty ?? true) && (productDetailModel?.label?.isEmpty ?? true) {
+                self.view.productDetailSkuViewType = ProductDetailSkuViewType.selectSku
+                self.view.productDetailModel = self.productDetailModel
+                self.view.show()
+            }
+        }
+    }
+    
+    
+    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
+        switch indexPath.section {
+        case 1:
+            if !(productDetailModel?.spec?.isEmpty ?? true) && !(productDetailModel?.label?.isEmpty ?? true) {
+                if indexPath.row == 0 {
+                    return UITableView.automaticDimension
+                }else {
+                    return 65 * kScaleWidth
+                }
+            }
+            
+            if (productDetailModel?.spec?.isEmpty ?? true) && !(productDetailModel?.label?.isEmpty ?? true) {
+                return 65 * kScaleWidth
+            }
+            
+            if !(productDetailModel?.spec?.isEmpty ?? true) && (productDetailModel?.label?.isEmpty ?? true) {
+                return UITableView.automaticDimension
+            }
+            return 0
+        case 4:
+            return 173
+        default:
+            return UITableView.automaticDimension
+        }
+        
+    }
+    
+    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
+        switch section {
+        case 2,4,5,6:
+            return UITableView.automaticDimension
+        default:
+            return 0
+        }
+        
+    }
+    
+    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
+        switch section {
+        case 2,4,5,6:
+            let view = ProductDetailSectionHeader(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 44))
+            view.section = section
+            view.titles = titles
+            view.lookAllCommentClosure = {
+                [weak self] in
+                if let lookAllCommentClosure = self?.lookAllCommentClosure {
+                    lookAllCommentClosure()
+                }
+            }
+            
+            return view
+        default:
+            return nil
+        }
+    }
+    
+    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
+        return 10
+    }
+    
+    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
+        return nil
+    }
+    
+    func scrollViewDidScroll(_ scrollView: UIScrollView) {
+        var offset = scrollView.contentOffset
+        NotificationCenter.default.post(name: NSNotification.Name(rawValue: "ProductDetailView"), object: offset)
+        
+        if (!(scrollView.isTracking || scrollView.isDecelerating)) {
+            //不是用户滚动的,比如setContentOffset等方法,引起的滚动不需要处理。
+            return;
+        }
+        offset.y =  offset.y + kNavBarTotalHeight
+        
+        if  offset.y > 251 + kSafeTabBarHeight {
+            
+            let indexPath = tableView.indexPathForRow(at: offset)
+            if indexPath != nil {
+                var rect = tableView.rect(forSection: (indexPath?.section)!)
+                
+                if rect.size.height + kNavBarTotalHeight - tableView.frame.size.height < 0 {
+                    
+                    rect.size.height = tableView.frame.size.height - kNavBarTotalHeight - rect.size.height
+                    
+                    tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: rect.size.height, right: 0)
+                }
+                
+                if indexPath!.section % 2 == 0  {
+                    NotificationCenter.default.post(name: NSNotification.Name(rawValue: "ProductDetailViewSection"), object: indexPath!.section)
+                    
+                }
+            }
+        }
+    }
+    
+}

+ 36 - 0
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductDetail/ViewController/ProductDetailViewController.swift

@@ -93,6 +93,33 @@ class ProductDetailViewController: BaseViewController {
             [weak self] (productDetailSkuModel) in
             self?.productDetailAddCartApi(productDetailSkuModel: productDetailSkuModel)
         }
+        productDetailView.buyNowClosure = {
+            [weak self] (productDetailSkuModel) in
+            let vc = ShoppingCartPayOrderController()
+            
+            var cartProductListModels = Array<CartProductListModel>()
+            let cartProductListModel = CartProductListModel()
+            cartProductListModel.shopId = self?.productDetailModel?.shopId
+            cartProductListModel.shopName = self?.productDetailModel?.shopName
+            
+            var productList = Array<ProductModel>()
+            let productModel = ProductModel()
+            productModel.productImg = self?.productDetailModel?.img
+            productModel.productName = self?.productDetailModel?.name
+            productModel.skuId = productDetailSkuModel.id
+            productModel.skuName = productDetailSkuModel.skuName
+            productModel.amount = productDetailSkuModel.productCount
+            productModel.skuPrice = productDetailSkuModel.price
+            productModel.receiveTime = self?.productDetailModel?.receiveTime
+            productList.append(productModel)
+            
+            cartProductListModel.productList = productList
+            cartProductListModels.append(cartProductListModel)
+            
+            vc.selListModelArr = cartProductListModels
+            vc.totalProductPrice = (productDetailSkuModel.price ?? 0) * (productDetailSkuModel.productCount ?? 0)
+            self?.navigationController?.pushViewController(vc, animated: true)
+        }
     }
     
     
@@ -169,11 +196,20 @@ class ProductDetailViewController: BaseViewController {
         }
     }
     
+    var productCartCountModel :ProductCartCountModel?
+    
+    var isOnlyOne : Bool = false
+    
     /// 获取购物车数量
     func productGetCartCountApi() {
         SwiftMoyaNetWorkServiceProduct.shared().productGetCartCountApi {
             [weak self] (productCartCountModel) -> (Void) in
             self?.productDetailView.productCartCountModel = productCartCountModel as? ProductCartCountModel
+            if self?.isOnlyOne ?? false {
+                self?.productDetailView.productCartCount = (productCartCountModel as? ProductCartCountModel)?.count ?? 0
+            }else {
+                self?.isOnlyOne = true
+            }
         }
     }
     

+ 3 - 10
RainbowPlanet/RainbowPlanet/Service/SwiftMoyaService/SwiftMoyaServiceApi/SwiftMoyaServicePay/SwiftMoyaNetWorkServicePay.swift

@@ -33,16 +33,9 @@ public class SwiftMoyaNetWorkServicePay: NSObject {
         parameters.updateValue(paraMdl.money ?? 0, forKey: "money")
         
         SwiftProgressHUD.shared().showWait()
-        SwiftMoyaNetWorkManager.shared().request(target: MultiTarget(SwiftMoyaServicePayApi.alipay(parameters: parameters))) { (rootModel) in
-            let rootModel = rootModel as! RootModel
-            if rootModel.code == 0 {
-                completion(rootModel.data as Any)
-                SwiftProgressHUD.shared().hide()
-            }else if rootModel.code == 1 {
-                SwiftProgressHUD.shared().showWarning(rootModel.msg ?? "")
-            }else {
-                SwiftProgressHUD.shared().showWarning(rootModel.msg ?? "")
-            }
+        SwiftMoyaNetWorkManager.shared().requestValue(target: MultiTarget(SwiftMoyaServicePayApi.alipay(parameters: parameters))) { (orderString) in
+            SwiftProgressHUD.shared().hide()
+            completion(orderString as Any)
         }
     }
 

+ 1 - 1
RainbowPlanet/RainbowPlanet/Service/SwiftMoyaService/SwiftMoyaServiceApi/SwiftMoyaServiceProduct/SwiftMoyaNetWorkServiceProduct.swift

@@ -282,7 +282,7 @@ class SwiftMoyaNetWorkServiceProduct: NSObject {
         parameters.updateValue(productDetailModel.id ?? "", forKey: "product_id")
         parameters.updateValue(productDetailSkuModel.price ?? "", forKey: "product_price")
         parameters.updateValue(productDetailSkuModel.id ?? "", forKey: "sku_id")
-        parameters.updateValue(productDetailModel.totalCount ?? "", forKey: "amount")
+        parameters.updateValue(productDetailSkuModel.productCount ?? 1, forKey: "amount")
         parameters.updateValue(1, forKey: "is_select")
         parameters.updateValue(productDetailModel.name ?? "", forKey: "product_name")
         parameters.updateValue(productDetailModel.img  ?? "", forKey: "product_img")

+ 79 - 0
RainbowPlanet/RainbowPlanet/Service/SwiftMoyaService/SwiftMoyaServiceManger/SwiftMoyaNetWorkManager/SwiftMoyaNetWorkManager.swift

@@ -275,6 +275,36 @@ public class SwiftMoyaNetWorkManager: NSObject {
             .disposed(by: disposeBag)
     }
     
+    // MARK: 网络请求返回Value
+    /// 网络请求返回Value
+    ///
+    /// - Parameters:
+    ///   - target: 请求地址加参数
+    ///   - completion: 请求成功回调
+    func requestValue(target: MultiTarget,isCustomAlert:Bool = false,completion: @escaping successCallback) -> Void {
+        //判断是否链接网络
+        if !isNetworkConnect{
+            SwiftProgressHUD.shared().showText("网络链接失败,请检查网络")
+            
+            return
+        }
+        
+        provider.rx
+            .request(target)
+            .subscribeOn(ConcurrentDispatchQueueScheduler(qos: .userInitiated))
+            .observeOn(MainScheduler.instance)
+            .subscribe(onSuccess: { [weak self] response in
+                self?.getResponseValueStatusCode(response: response, isCustomAlert: isCustomAlert, completion: completion)
+            }) {
+                [weak self] (error) in
+                SwiftProgressHUD.shared().showText(error.localizedDescription)
+                if let falseCallback = self?.falseCallback  {
+                    falseCallback()
+                }
+            }
+            .disposed(by: disposeBag)
+    }
+    
     // MARK: 网络请求返回数组
     /// 网络请求返回数组
     ///
@@ -431,6 +461,55 @@ extension SwiftMoyaNetWorkManager {
         }
     }
     
+    // MARK: 返回Vaule
+    /// 获取状态码返回Vaule
+    ///
+    /// - Parameters:
+    ///   - response: 响应结果
+    ///   - completion: 回调
+    private func getResponseValueStatusCode(response:Response, isCustomAlert:Bool , completion: @escaping successCallback) -> Void {
+        let json = try? JSON(response.mapJSON())
+        if response.statusCode == 200 {
+            NXLLog("\nstatusCode=\(response.statusCode)\njson=\n\(json!.description)");
+            let json = JSON(parseJSON: json!.description)
+            let rootModel = RootModel(JSONString: json.description)
+            let data = JSON(json["data"]).description
+            rootModel?.data = data
+            if rootModel!.code == 0 {
+                completion(rootModel?.data as Any)
+            }else if rootModel!.code  == 1 {
+                if !isCustomAlert {
+                    SwiftProgressHUD.shared().showText(rootModel!.msg ?? "信息有误!!!", textAlignment: .left)
+                }
+                if let falseCallback = self.falseCallback  {
+                    falseCallback()
+                }
+                
+            }else {
+                SwiftProgressHUD.shared().showError(rootModel!.msg ?? "信息有误!!!")
+                if let falseCallback = self.falseCallback  {
+                    falseCallback()
+                }
+            }
+        }else if response.statusCode == 401 {
+            NXLLog("\nstatusCode=\(response.statusCode)\njson=\n\(json!.description)");
+            let infoModel = InfoModel(JSONString: json?.description ?? "")
+            kAppDelegate.setLoginController()
+            SwiftProgressHUD.shared().showText(infoModel!.message ?? "登录过期,请重新登录")
+            
+            if let falseCallback = self.falseCallback  {
+                falseCallback()
+            }
+        } else {
+            NXLLog("\nstatusCode=\(response.statusCode)\nerror=\n\(response.description)");
+            SwiftProgressHUD.shared().showText(response.description)
+            
+            if let falseCallback = self.falseCallback  {
+                falseCallback()
+            }
+        }
+    }
+    
     // MARK: 返回数组
     /// 获取状态码返回数组
     ///