Kaynağa Gözat

网络请求底层修改

南鑫林 6 yıl önce
ebeveyn
işleme
7138c598a1

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

@@ -162,6 +162,7 @@
 		A757C92E22744ACE00226355 /* AddressManagerListModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A757C92D22744ACE00226355 /* AddressManagerListModel.swift */; };
 		A757C9302274839900226355 /* SelfMentionAddressListModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A757C92F2274839900226355 /* SelfMentionAddressListModel.swift */; };
 		A757C9342274882E00226355 /* UIScrollView+MJRefreshEX.m in Sources */ = {isa = PBXBuildFile; fileRef = A757C9322274882E00226355 /* UIScrollView+MJRefreshEX.m */; };
+		A75C474E22938B3900139C0C /* OrderFreightTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A75C474D22938B3900139C0C /* OrderFreightTableViewCell.swift */; };
 		A7636AC52268139C00374F9E /* LocationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7636AC42268139C00374F9E /* LocationViewController.swift */; };
 		A7636AC822682BAF00374F9E /* LocationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7636AC722682BAF00374F9E /* LocationView.swift */; };
 		A76390EB2248E27A0067EEE0 /* UserNotifications.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A76390EA2248E27A0067EEE0 /* UserNotifications.framework */; };
@@ -547,6 +548,7 @@
 		A757C92F2274839900226355 /* SelfMentionAddressListModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelfMentionAddressListModel.swift; sourceTree = "<group>"; };
 		A757C9322274882E00226355 /* UIScrollView+MJRefreshEX.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIScrollView+MJRefreshEX.m"; sourceTree = "<group>"; };
 		A757C9332274882E00226355 /* UIScrollView+MJRefreshEX.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIScrollView+MJRefreshEX.h"; sourceTree = "<group>"; };
+		A75C474D22938B3900139C0C /* OrderFreightTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderFreightTableViewCell.swift; sourceTree = "<group>"; };
 		A7636AC42268139C00374F9E /* LocationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationViewController.swift; sourceTree = "<group>"; };
 		A7636AC722682BAF00374F9E /* LocationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationView.swift; sourceTree = "<group>"; };
 		A76390EA2248E27A0067EEE0 /* UserNotifications.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UserNotifications.framework; path = System/Library/Frameworks/UserNotifications.framework; sourceTree = SDKROOT; };
@@ -2762,6 +2764,7 @@
 				A7FF156D228C6EAE00A85748 /* OrderDeliveryModeTableViewCell.swift */,
 				A7FF156F228C6EF200A85748 /* OrderDeliveryModeAndButtonTableViewCell.swift */,
 				A7FF1571228C7D4600A85748 /* OrderButtonTableViewCell.swift */,
+				A75C474D22938B3900139C0C /* OrderFreightTableViewCell.swift */,
 			);
 			path = View;
 			sourceTree = "<group>";
@@ -3407,6 +3410,7 @@
 				A70B2C042283D06B00B2449F /* ProductFloorFullLeftHeaderCollectionReusableView.swift in Sources */,
 				A7B4E721228151F40012914A /* ProductFloorTitleView.swift in Sources */,
 				A729B5AD2266FF45004AE098 /* BindPhoneNumberView.swift in Sources */,
+				A75C474E22938B3900139C0C /* OrderFreightTableViewCell.swift in Sources */,
 				A7FF1592228C918100A85748 /* OrderRefunddetailsStatusTableViewCell.swift in Sources */,
 				A7CC74E62270628B003C4F38 /* DeliveryMethodTypeModel.swift in Sources */,
 				BDAA40FD228E9CD600CF841D /* OrderApplyRefundPhoneCell.swift in Sources */,

+ 10 - 1
RainbowPlanet/RainbowPlanet/Macro/Common.swift

@@ -168,5 +168,14 @@ func isMobileVerification(mobile:String) -> Bool {
     }
     
     return true
-    
+}
+
+
+/// 价格转换
+///
+/// - Parameter price: 价格分
+/// - Returns: string
+func priceConversion(price:Int) -> String {
+    let price = Float(price/100)
+    return String(format: "¥%2.f", price)
 }

+ 87 - 0
RainbowPlanet/RainbowPlanet/Modules/OrderModule/Order/View/OrderFreightTableViewCell.swift

@@ -0,0 +1,87 @@
+//
+//  OrderFreightTableViewCell.swift
+//  RainbowPlanet
+//
+//  Created by 南鑫林 on 2019/5/21.
+//  Copyright © 2019 RainbowPlanet. All rights reserved.
+//
+
+import UIKit
+
+class OrderFreightTableViewCell: UITableViewCell {
+    
+    class func cellWith(tableView:UITableView,indexPath:IndexPath) -> OrderFreightTableViewCell {
+        let ID = "OrderFreightTableViewCell"
+        tableView.register(OrderFreightTableViewCell.self, forCellReuseIdentifier: ID)
+        let cell : OrderFreightTableViewCell = tableView.dequeueReusableCell(withIdentifier: ID, for: indexPath) as! OrderFreightTableViewCell
+        cell.indexPath = indexPath
+        return cell
+    }
+    
+    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
+        super.init(style: style, reuseIdentifier: reuseIdentifier)
+        setupViews()
+        setupLayouts()
+    }
+    
+    required init?(coder aDecoder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+    
+    var indexPath: IndexPath? {
+        didSet {
+            
+        }
+    }
+    //MRAK: - 设置View
+    private func setupViews() {
+        self.selectionStyle = .none
+        addSubview(titleLabel)
+        addSubview(freightLabel)
+        addSubview(lineLabel)
+    }
+    
+    private func setupLayouts() {
+        titleLabel.snp.makeConstraints { (make) in
+            make.left.equalTo(14)
+            make.top.bottom.equalToSuperview()
+        }
+        freightLabel.snp.makeConstraints { (make) in
+            make.right.equalTo(-14)
+            make.top.bottom.equalToSuperview()
+        }
+        lineLabel.snp.makeConstraints { (make) in
+            make.bottom.equalToSuperview()
+            make.left.equalTo(titleLabel)
+            make.right.equalTo(freightLabel)
+            make.height.equalTo(1)
+        }
+    }
+    
+    private lazy var titleLabel: UILabel = {
+        let titleLabel = UILabel()
+        titleLabel.text = "运费"
+        titleLabel.textColor = k333333Color
+        titleLabel.font = kRegularFont14
+        return titleLabel
+    }()
+    
+    private lazy var freightLabel: UILabel = {
+        let freightLabel = UILabel()
+        freightLabel.textColor = k333333Color
+        freightLabel.font = kRegularFont14
+        return freightLabel
+    }()
+    private lazy var lineLabel: UILabel = {
+        let lineLabel = UILabel()
+        lineLabel.backgroundColor = kf5f5f5Color
+        return lineLabel
+    }()
+    
+    var orderModel: OrderModel? {
+        didSet {
+            freightLabel.text = priceConversion(price: orderModel?.transPrice ?? 0)
+        }
+    }
+
+}

+ 31 - 23
RainbowPlanet/RainbowPlanet/Modules/OrderModule/Order/ViewController/OrderListViewController.swift

@@ -117,21 +117,21 @@ extension OrderListViewController : UITableViewDelegate, UITableViewDataSource {
                 if orderModel.feedbackStatus == 0 { //未维权
                     switch orderModel.status {
                     case 0: //待付款
-                        return 4 + (orderModel.detail?.count ?? 0)
+                        return 5 + (orderModel.detail?.count ?? 0)
                     case 1: //待发货
-                        return 4 + (orderModel.detail?.count ?? 0)
+                        return 5 + (orderModel.detail?.count ?? 0)
                     case 2: //已发货/待收货
-                        return 4 + (orderModel.detail?.count ?? 0)
+                        return 5 + (orderModel.detail?.count ?? 0)
                     case 3: //配送中
-                        return 4 + (orderModel.detail?.count ?? 0)
+                        return 5 + (orderModel.detail?.count ?? 0)
                     case 4: //待自提
-                        return 4 + (orderModel.detail?.count ?? 0)
+                        return 5 + (orderModel.detail?.count ?? 0)
                     case 5: //已自提
-                        return 4 + (orderModel.detail?.count ?? 0)
+                        return 5 + (orderModel.detail?.count ?? 0)
                     case 6: //已完成
-                        return 4 + (orderModel.detail?.count ?? 0)
+                        return 5 + (orderModel.detail?.count ?? 0)
                     case 7: //已关闭
-                        return 4 + (orderModel.detail?.count ?? 0)
+                        return 5 + (orderModel.detail?.count ?? 0)
                         
                     default:
                         return 0
@@ -139,11 +139,11 @@ extension OrderListViewController : UITableViewDelegate, UITableViewDataSource {
                 }else {
                     switch orderModel.feedbackStatus {
                     case 1: //1-退款处理中
-                        return 4 + (orderModel.detail?.count ?? 0)
+                        return 5 + (orderModel.detail?.count ?? 0)
                     case 2: //2-退款完成
-                        return 4 + (orderModel.detail?.count ?? 0)
+                        return 5 + (orderModel.detail?.count ?? 0)
                     case 3: //3-拒绝退款
-                        return 4 + (orderModel.detail?.count ?? 0)
+                        return 5 + (orderModel.detail?.count ?? 0)
                     default:
                         return 0
                     }
@@ -153,32 +153,32 @@ extension OrderListViewController : UITableViewDelegate, UITableViewDataSource {
                 if orderModel.feedbackStatus == 0 { //未维权
                     switch orderModel.status {
                     case 0: //待付款
-                        return 4 + (orderModel.detail?.count ?? 0)
+                        return 5 + (orderModel.detail?.count ?? 0)
                     case 1: //待发货
-                        return 3 + (orderModel.detail?.count ?? 0)
-                    case 2: //已发货/待收货
                         return 4 + (orderModel.detail?.count ?? 0)
+                    case 2: //已发货/待收货
+                        return 5 + (orderModel.detail?.count ?? 0)
                     case 3: //配送中
-                        return 4 + (orderModel.detail?.count ?? 0)
+                        return 5 + (orderModel.detail?.count ?? 0)
                     case 4: //待自提
-                        return 4 + (orderModel.detail?.count ?? 0)
+                        return 5 + (orderModel.detail?.count ?? 0)
                     case 5: //已自提
-                        return 4 + (orderModel.detail?.count ?? 0)
+                        return 5 + (orderModel.detail?.count ?? 0)
                     case 6: //已完成
-                        return 4 + (orderModel.detail?.count ?? 0)
+                        return 5 + (orderModel.detail?.count ?? 0)
                     case 7: //已关闭
-                         return 3 + (orderModel.detail?.count ?? 0)
+                         return 4 + (orderModel.detail?.count ?? 0)
                     default:
                         return 0
                     }
                 }else {
                     switch orderModel.feedbackStatus {
                     case 1: //1-退款处理中
-                        return 4 + (orderModel.detail?.count ?? 0)
+                        return 5 + (orderModel.detail?.count ?? 0)
                     case 2: //2-退款完成
-                        return 4 + (orderModel.detail?.count ?? 0)
+                        return 5 + (orderModel.detail?.count ?? 0)
                     case 3: //3-拒绝退款
-                        return 4 + (orderModel.detail?.count ?? 0)
+                        return 5 + (orderModel.detail?.count ?? 0)
                     default:
                         return 0
                     }
@@ -204,10 +204,14 @@ extension OrderListViewController : UITableViewDelegate, UITableViewDataSource {
             cell.orderModel = orderModel
             return cell
         case details!.count + 2:
-            let cell = OrderTotalAmountTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
+            let cell = OrderFreightTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
             cell.orderModel = orderModel
             return cell
         case details!.count + 3:
+            let cell = OrderTotalAmountTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
+            cell.orderModel = orderModel
+            return cell
+        case details!.count + 4:
             let orderModel = orderModel
             switch orderModel.deliverType {
             case 1: //自提
@@ -312,6 +316,8 @@ extension OrderListViewController : UITableViewDelegate, UITableViewDataSource {
         case details!.count + 2:
             return 40
         case details!.count + 3:
+            return 40
+        case details!.count + 4:
             return UITableView.automaticDimension
         default:
             return 108
@@ -333,6 +339,8 @@ extension OrderListViewController : UITableViewDelegate, UITableViewDataSource {
             break
         case details!.count + 3:
             break
+        case details!.count + 4:
+            break
         default:
             if let productDidSelectBlock = productDidSelectBlock {
                 productDidSelectBlock(orderModel,(orderModel.detail?[indexPath.row-2])!)

+ 20 - 18
RainbowPlanet/RainbowPlanet/Service/SwiftMoyaService/SwiftMoyaServiceManger/SwiftMoyaNetWorkManager/SwiftMoyaNetWorkManager.swift

@@ -264,7 +264,7 @@ public class SwiftMoyaNetWorkManager: NSObject {
             .subscribeOn(ConcurrentDispatchQueueScheduler(qos: .userInitiated))
             .observeOn(MainScheduler.instance)
             .subscribe(onSuccess: { [weak self] response in
-                self?.getResponseStatusCode(response: response, isCustomAlert: isCustomAlert, completion: completion)
+                self?.getResponseStatusCode(response: response, completion: completion)
             }) {
                 [weak self] (error) in
                 SwiftProgressHUD.shared().showText(error.localizedDescription)
@@ -281,7 +281,7 @@ public class SwiftMoyaNetWorkManager: NSObject {
     /// - Parameters:
     ///   - target: 请求地址加参数
     ///   - completion: 请求成功回调
-    func requestValue(target: MultiTarget,isCustomAlert:Bool = false,completion: @escaping successCallback) -> Void {
+    func requestValue(target: MultiTarget,completion: @escaping successCallback) -> Void {
         //判断是否链接网络
         if !isNetworkConnect{
             SwiftProgressHUD.shared().showText("网络链接失败,请检查网络")
@@ -294,7 +294,7 @@ public class SwiftMoyaNetWorkManager: NSObject {
             .subscribeOn(ConcurrentDispatchQueueScheduler(qos: .userInitiated))
             .observeOn(MainScheduler.instance)
             .subscribe(onSuccess: { [weak self] response in
-                self?.getResponseValueStatusCode(response: response, isCustomAlert: isCustomAlert, completion: completion)
+                self?.getResponseValueStatusCode(response: response, completion: completion)
             }) {
                 [weak self] (error) in
                 SwiftProgressHUD.shared().showText(error.localizedDescription)
@@ -311,7 +311,7 @@ public class SwiftMoyaNetWorkManager: NSObject {
     /// - Parameters:
     ///   - target: 请求地址加参数
     ///   - completion: 请求成功回调
-    func requestArray(target: MultiTarget,isCustomAlert:Bool = false,completion: @escaping successCallArrayback) -> Void {
+    func requestArray(target: MultiTarget,completion: @escaping successCallArrayback) -> Void {
         //判断是否链接网络
         if !isNetworkConnect{
             SwiftProgressHUD.shared().showText("网络链接失败,请检查网络")
@@ -325,7 +325,7 @@ public class SwiftMoyaNetWorkManager: NSObject {
             .observeOn(MainScheduler.instance)
             .subscribe(onSuccess: { [weak self] response in
                 
-                self?.getResponseArrayStatusCode(response: response, isCustomAlert: isCustomAlert, completion: completion)
+                self?.getResponseArrayStatusCode(response: response, completion: completion)
             }) {
                 [weak self] (error) in
                 SwiftProgressHUD.shared().showText(error.localizedDescription)
@@ -418,7 +418,7 @@ extension SwiftMoyaNetWorkManager {
     /// - Parameters:
     ///   - response: 响应结果
     ///   - completion: 回调
-    private func getResponseStatusCode(response:Response, isCustomAlert:Bool , completion: @escaping successCallback) -> Void {
+    private func getResponseStatusCode(response:Response, completion: @escaping successCallback) -> Void {
         let json = try? JSON(response.mapJSON())
         if response.statusCode == 200 {
             let url = String(describing: response.request!.url!)
@@ -431,9 +431,8 @@ extension SwiftMoyaNetWorkManager {
             if rootModel!.code == 0 {
                 completion(rootModel as Any)
             }else if rootModel!.code  == 1 {
-                if !isCustomAlert {
-                    SwiftProgressHUD.shared().showText(rootModel!.msg ?? "信息有误!!!", textAlignment: .left)
-                }
+                SwiftProgressHUD.shared().showText(rootModel!.msg ?? "信息有误!!!", textAlignment: .left)
+
                 if let falseCallback = self.falseCallback  {
                     falseCallback()
                 }
@@ -470,7 +469,7 @@ extension SwiftMoyaNetWorkManager {
     /// - Parameters:
     ///   - response: 响应结果
     ///   - completion: 回调
-    private func getResponseValueStatusCode(response:Response, isCustomAlert:Bool , completion: @escaping successCallback) -> Void {
+    private func getResponseValueStatusCode(response:Response, completion: @escaping successCallback) -> Void {
         let json = try? JSON(response.mapJSON())
         if response.statusCode == 200 {
             let url = String(describing: response.request!.url!)
@@ -482,9 +481,8 @@ extension SwiftMoyaNetWorkManager {
             if rootModel!.code == 0 {
                 completion(rootModel?.data as Any)
             }else if rootModel!.code  == 1 {
-                if !isCustomAlert {
-                    SwiftProgressHUD.shared().showText(rootModel!.msg ?? "信息有误!!!", textAlignment: .left)
-                }
+                SwiftProgressHUD.shared().showText(rootModel!.msg ?? "信息有误!!!", textAlignment: .left)
+
                 if let falseCallback = self.falseCallback  {
                     falseCallback()
                 }
@@ -522,7 +520,7 @@ extension SwiftMoyaNetWorkManager {
     /// - Parameters:
     ///   - response: 响应结果 数组
     ///   - completion: 回调
-    private func getResponseArrayStatusCode(response:Response, isCustomAlert:Bool , completion: @escaping successCallArrayback) -> Void {
+    private func getResponseArrayStatusCode(response:Response, completion: @escaping successCallArrayback) -> Void {
         let json = try? JSON(response.mapJSON())
         if response.statusCode == 200 {
             let url = String(describing: response.request!.url!)
@@ -535,9 +533,7 @@ extension SwiftMoyaNetWorkManager {
                 let array = JSON(parseJSON: rootModel?.data ?? "").arrayObject ?? Array<Any>()
                 completion(array)
             }else if rootModel!.code  == 1 {
-                if !isCustomAlert {
-                    SwiftProgressHUD.shared().showText(rootModel!.msg ?? "信息有误!!!", textAlignment: .left)
-                }
+                SwiftProgressHUD.shared().showText(rootModel!.msg ?? "信息有误!!!", textAlignment: .left)
                 if let falseCallback = self.falseCallback  {
                     falseCallback()
                 }
@@ -590,8 +586,10 @@ extension PrimitiveSequence where TraitType == SingleTrait, ElementType == Respo
                         let mapper = T(JSONString:  rootModel!.data ?? "")
                         return Single<T?>.just(mapper)
                     }else if rootModel!.code  == 1 {
+                        SwiftProgressHUD.shared().showError(rootModel!.msg ?? "信息有误!!!")
                         return Single<T?>.just(nil)
                     }else {
+                        SwiftProgressHUD.shared().showError(rootModel!.msg ?? "信息有误!!!")
                         return Single<T?>.just(nil)
                     }
                 }else if response.statusCode == 401 {
@@ -604,6 +602,8 @@ extension PrimitiveSequence where TraitType == SingleTrait, ElementType == Respo
                 }else {
                     let url = String(describing: response.request!.url!)
                     NXLLog("\nurl=\(url)\nstatusCode=\(response.statusCode)\nerror=\n\(response.description)");
+                    SwiftProgressHUD.shared().showText(response.description)
+
                     return Single<T?>.just(nil)
                 }
 
@@ -637,7 +637,8 @@ extension PrimitiveSequence where TraitType == SingleTrait, ElementType == Respo
                     }else if rootModel!.code  == 1 {
                         SwiftProgressHUD.shared().showText(rootModel!.msg ?? "信息有误!!!", textAlignment: .left)
                         return Single<[T]?>.just(nil)
-                    }else {                        SwiftProgressHUD.shared().showText(response.description)
+                    }else {
+                        SwiftProgressHUD.shared().showText(rootModel!.msg ?? "信息有误!!!", textAlignment: .left)
                         return Single<[T]?>.just(nil)
                     }
                 }else if response.statusCode == 401 {
@@ -650,6 +651,7 @@ extension PrimitiveSequence where TraitType == SingleTrait, ElementType == Respo
                 }else {
                     let url = String(describing: response.request!.url!)
                     NXLLog("\nurl=\(url)\nstatusCode=\(response.statusCode)\nerror=\n\(response.description)");
+                    SwiftProgressHUD.shared().showText(response.description)
                     return Single<[T]?>.just(nil)
                 }
                 

BIN
彩虹星球1期遗留问题.xmind