CNLiveMineViewModel.swift 39.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855
//
//  CNLiveMineViewModel.swift
//  metaCode
//
//  Created by open on 2023/6/14.
//

import Foundation
import CNLiveRequestBastKit
import HandyJSON
import AFNetworking

enum CNLiveMineRequestType {
    case icon
    case nickName
    case gender
    case email
    case location
    case birthday
    case other
}
enum CNLiveMineResponseType {
    case success
    case failed
    case noNetwork
    case unkonw
}
enum CNLiveMineGetWriteType {
    case nodate //未填写
    case havedate //已填写
    case effect //效验接口
}
typealias resultBlock = (_ type: CNLiveMineRequestType,_ result: Bool) -> Void
typealias resultNewsBlock = (_ result: Any,_ respStatue :CNLiveMineResponseType) -> Void
class CNLiveMineViewModel: NSObject {
    
    /// 提交更新用户单项数据
    /// - Parameters:
    ///   - type: nickName-昵称,gender-性别,email-邮箱, location-联系方式,birthday-生日yyyy-MM-dd
    ///   - value: 对应的信息,性别,m:男、f:女、n:未知
    static func requestUpdateUserInfoAction(type: CNLiveMineRequestType,value: String, resultBlock: @escaping resultBlock) {
        
        let param = NSMutableDictionary.init()
        if type == .nickName {
            param.setValue("nickName", forKey: "type")
            param.setValue(value, forKey: "value")
        }
        if type == .gender {
            param.setValue("gender", forKey: "type")
            
            param.setValue(value, forKey: "value")
        }
        if type == .email {
            param.setValue("email", forKey: "type")
            param.setValue(value, forKey: "value")
        }
        if type == .location {
            param.setValue("location", forKey: "type")
            param.setValue(value, forKey: "value")
        }
        if type == .birthday {
            param.setValue("birthday", forKey: "type")
            param.setValue(value, forKey: "value")
        }
        param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "uid")
        param.setValue(UserInfoManager.shared.userInfo.token, forKey: "token")
        showLoading(message: "")
        CNLiveNetworking.setAllowRequestDefaultArgument(true)
        CNLiveNetworking.setupShowDataResult(false)
        CNLiveNetworking.requestNetwork(with: .POST, urlString: "/open/api2/user/updateUserById", param: param as! [String : Any], cacheType: .networkOnly) { task, result, error in
            hiddenLoading()
            if (error == nil) {
                let resp = result as! NSDictionary
                let errorCode = resp["errorCode"]
                if (errorCode as! String == "0") {
                    showMessage(message: "更改成功")
                    resultBlock(type,true)
                } else {
                    showMessage(message: resp["errorMessage"] as! String)
                    resultBlock(type,false)
                }
            } else {
                showMessage(message: "修改信息失败")
                resultBlock(type,false)
            }
        }
    }
    
    
    /// 上传并修改头像
    /// - Parameters:
    ///   - image: 头像
    ///   - resultBlock: 返回
    static func requestUploadIconAction(_ image: UIImage,resultBlock: @escaping resultBlock) {
             
        CNLiveMineViewModel.requestAccessTokenAction() {  type, result in
            if result {
                let param = NSMutableDictionary.init()
                param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "uid")
                param.setValue(UserInfoManager.shared.userInfo.token, forKey: "token")
                param.setValue(UserInfoManager.shared.userInfo.access_token, forKey: "access_token")
                showLoading(message: "修改头像中...")
                CNLiveNetworking.setAllowRequestDefaultArgument(true)
                CNLiveNetworking.setupShowDataResult(false)
                CNLiveNetworking.setupShowResult(true)
                CNLiveNetworking.uploadNetwork(withURLString: "/open/api2/user/updateUserFaceById", param: param as? [AnyHashable : Any]) { formData in
                    let imageData = image.imageWithZip()
                    formData?.appendPart(withFileData: imageData as Data, name: "face", fileName: ".jpg", mimeType: "image/jpg")
                } progressBlock: { progress in
                    print("已上传==>\(progress!.fractionCompleted*100)")
                } completionBlock: { task, result, error in
                    hiddenLoading()
                    if (error == nil) {
                        let resp = result as! NSDictionary
                        let errorCode = resp["errorCode"]
                        if (errorCode as! String == "0") {
                            showMessage(message: "头像更改成功")
                            let data = resp["data"] as! Dictionary<String, Any>
                            let userInfo = UserInfoManager.shared.userInfo
                            userInfo.faceUrl = data["faceUrl"] as! String
                            userInfo.bigFaceUrl = data["bigFaceUrl"] as! String
                            UserInfoManager.cacheUserInfo(userInfo: userInfo)
                            resultBlock(.icon,true)
                        } else {
                            showMessage(message: resp["errorMessage"] as! String)
                            resultBlock(.icon,false)
                        }
                    } else {
                        showMessage(message: "头像更改失败")
                        resultBlock(.icon,false)
                    }
                }
            } else {
                resultBlock(.icon,false)
            }
        }
    }
    
    /// 获取access_token
    /// - Parameter resultBlock: 结果返回
    static func requestAccessTokenAction(resultBlock: @escaping resultBlock) {
        //当前时间大于最大允许时间则表明当前access_token已经过期需要重新请求
        let param = NSMutableDictionary.init()
        param.setValue(APPId, forKey: "appId")
        param.setValue(APPSecret, forKey: "secret")
        showLoading(message: "")
        CNLiveNetworking.setAllowRequestDefaultArgument(false)
        CNLiveNetworking.setupShowDataResult(false)
        CNLiveNetworking.requestNetwork(with: .POST, urlString: "/open/api2/token", param: (param as! [AnyHashable : Any]), cacheType: .networkOnly) { task, result, error in
            hiddenLoading()
            if (error == nil) {
                let resp = result as! NSDictionary
                let errorCode = "\(resp["errorCode"] ?? 0)"
                if (errorCode == "0") {
                    let data = resp["data"] as! Dictionary<String, Any>
                    let userInfo = UserInfoManager.shared.userInfo
                    userInfo.access_token = data["access_token"] as! String
                    let expires_in = data["expires_in"] as! NSNumber
                    userInfo.expires_in = "\(expires_in.intValue+CNLiveMineViewModel.timeStamp)"
                    UserInfoManager.cacheUserInfo(userInfo: userInfo)
                    resultBlock(.other,true)
                } else {
                    showMessage(message: resp["errorMessage"] as! String)
                    resultBlock(.other,false)
                }
            } else {
                showMessage(message: "修改头像失败")
                resultBlock(.other,false)
            }
        }
    }
    
    /// 上传反馈意见接口
    /// - Parameter resultBlock: 成功回调
    static func requestFeedBack(text: String,contactWay: String,images: NSMutableArray,resultBlock: @escaping resultBlock) {
        if (text.count == 0) {
            showMessage(message: "反馈内容不能为空")
            resultBlock(.other,false)
            return
        }
        images.remove("")
        let imageUrl = NSMutableString()
        if images.count > 0 {
            images.forEach { image_url in
                imageUrl.append(image_url as! String)
                imageUrl.append(",")
            }
            imageUrl.deleteCharacters(in: NSRange(location: imageUrl.length - 1, length: 1))
        }
        let param = NSMutableDictionary()
        param.setValue(imageUrl, forKey: "images")
        param.setValue(text, forKey: "text")
        param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "sid")
        param.setValue(contactWay, forKey: "contactWay")
        param.setValue(UserInfoManager.shared.userInfo.nickName, forKey: "contactName")
        param.setValue("", forKey: "category")
        param.setValue("ios", forKey: "plat")
        param.setValue(Bundle.main.infoDictionary?["CFBundleVersion"] as! String, forKey: "version")
        param.setValue(UIDevice.current.identifierForVendor?.uuidString.replacingOccurrences(of: "-", with: "") ?? "", forKey: "deviceId")
        showLoading(message: "")
        CNLiveNetworking.setAllowRequestDefaultArgument(true)
        CNLiveNetworking.setupShowDataResult(false)
        CNLiveNetworking.requestNetwork(with: .POST, urlString: APPBaseMCUrl+"/commonApi/collectFeedback", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
            hiddenLoading()
            if (error == nil) {
                let resp = result as! NSDictionary
                let errorCode = "\(resp["errorCode"] ?? "0")"
                if (errorCode == "0") {
                    resultBlock(.other,true)
                } else {
                    showMessage(message: resp["errorMessage"] as! String)
                    resultBlock(.other,false)
                }
            } else {
                showMessage(message: "提交失败")
                resultBlock(.other,false)
            }
        }
    }
    
    /// 获取系统消息
    /// - Parameter resultBlock: 结果返回
    static func requestMessage(resultBlock: @escaping resultNewsBlock) {
        showLoading(message: "")
        CNLiveNetworking.setAllowRequestDefaultArgument(true)
        CNLiveNetworking.setupShowDataResult(false)
        CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseMCUrl+"/newsApi/getNews", param: ["sid":UserInfoManager.shared.userInfo.uid], cacheType: .networkOnly) { task, result, error in
            hiddenLoading()
            if (error == nil) {
                let resp = result as! NSDictionary
                let errorCode = "\(resp["errorCode"] ?? "0")"
                if (errorCode == "0") {
                    let newsModel = dictionaryToModel(resp as! [String : Any], NewsModel.self,"data") as! NewsModel
                    resultBlock(newsModel,.success)
                } else {
                    showMessage(message: resp["errorMessage"] as! String)
                    resultBlock(NSNull(),.failed)
                }
            } else {
                if CNLiveNetworking.isNetworking() {
                    showMessage(message: "获取失败")
                    resultBlock(NSNull(),.failed)
                } else {
                    showMessage(message: "似乎与网络断开链接")
                    resultBlock(NSNull(),.noNetwork)
                }
            }
        }
    }
    
    /// 获取身份信息列表数据
    /// - Parameters:
    ///   - page: 页数
    ///   - resultBlock: 返回
    static func requestAuthStandList(page: NSInteger, resultBlock: @escaping resultNewsBlock) {
        let param = NSMutableDictionary()
        param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "sid")
        param.setValue("30", forKey: "pageSize")
        param.setValue("\(page)", forKey: "page")
        CNLiveNetworking.setAllowRequestDefaultArgument(true)
        CNLiveNetworking.setupShowDataResult(false)
        CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseMCUrl+"/identityApi/allList", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
            hiddenLoading()
            if (error == nil) {
                let resp = result as! NSDictionary
                let errorCode = "\(resp["errorCode"] ?? "0")"
                if (errorCode == "0") {
                    let listModel = dictionaryToModel(resp as! [String : Any], StandListBaseModel.self,"data") as! StandListBaseModel
                    if page == 1 && listModel.list.count > 0 {
                        CNLiveSaveStandDB.shared.insertObjects(objects: listModel.list)
                    }
                    listModel.list = StandSortManager.sortAllListData(stands: listModel.list as NSArray) as! [StandListModel]
                    resultBlock(listModel,.success)
                } else {
                    let tempArray = CNLiveSaveStandDB.shared.searchAllObject()
                    if tempArray.count > 0 {
                        let listModel = StandListBaseModel.init()
                        listModel.pageNum = page
                        listModel.total = page
                        listModel.list = StandSortManager.sortAllListData(stands: tempArray as NSArray) as! [StandListModel]
                        resultBlock(listModel,.success)
                    }else{
                        showMessage(message: resp["errorMessage"] as! String)
                        resultBlock(NSNull(),.failed)
                    }
                }
            } else {
                let tempArray = CNLiveSaveStandDB.shared.searchAllObject()
                if tempArray.count > 0 {
                    let listModel = StandListBaseModel.init()
                    listModel.pageNum = page
                    listModel.total = page
                    listModel.list = StandSortManager.sortAllListData(stands: tempArray as NSArray) as! [StandListModel]
                    resultBlock(listModel,.success)
                }else{
                    if CNLiveNetworking.isNetworking() {
                        showMessage(message: "获取失败")
                        resultBlock(NSNull(),.failed)
                    } else {
                        showMessage(message: "似乎与网络断开链接")
                        resultBlock(NSNull(),.noNetwork)
                    }
                }
            }
        }
    }
    
    /// 获取已认证身份列表
    /// - Parameters:
    ///   - page: 页数
    ///   - resultBlock: 数据返回
    static func requestsGETAuthInfoList(page: NSInteger, resultBlock: @escaping resultNewsBlock) {
        let param = NSMutableDictionary()
        param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "sid")
        param.setValue("1", forKey: "type") //0正在审核  1已认证  -1审核失败
        param.setValue("\(page)", forKey: "page")
        param.setValue("30", forKey: "pageSize")
        CNLiveNetworking.setAllowRequestDefaultArgument(true)
        CNLiveNetworking.setupShowDataResult(false)
        CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseMCUrl+"/identityApi/myList", param: param as! [String: String], cacheType: .networkOnly) { task, result, error in
            hiddenLoading()
            if (error == nil) {
                let resp = result as! NSDictionary
                let errorCode = "\(resp["errorCode"] ?? "0")"
                if (errorCode == "0" && resp["data"] is NSNull) {
                    let listModel = dictionaryToModel(resp as! [String : Any], MineAuthListBaseModel.self,"data") as! MineAuthListBaseModel
                    if page == 1 && listModel.list.count > 0 {
                        CNLiveSaveAuthDB.shared.insertObjects(objects: listModel.list)
                    }
                    listModel.list = StandSortManager.sortMyListData(auths: listModel.list as NSArray) as! [MineAuthListModel]
                    resultBlock(listModel,.success)
                } else {
                    let tempArray = CNLiveSaveAuthDB.shared.searchAllObject()
                    if tempArray.count > 0 {
                        let listModel = MineAuthListBaseModel.init()
                        listModel.pageNum = page
                        listModel.total = page
                        listModel.list = StandSortManager.sortMyListData(auths: tempArray as NSArray) as! [MineAuthListModel]
                        resultBlock(listModel,.success)
                    }else{
                        showMessage(message: resp["errorMessage"] as! String)
                        resultBlock(NSNull(),.failed)
                    }
                }
            } else {
                let tempArray = CNLiveSaveAuthDB.shared.searchAllObject()
                if tempArray.count > 0 {
                    let listModel = MineAuthListBaseModel.init()
                    listModel.pageNum = page
                    listModel.total = page
                    listModel.list = StandSortManager.sortMyListData(auths: tempArray as NSArray) as! [MineAuthListModel]
                    resultBlock(listModel,.success)
                }else{
                    if CNLiveNetworking.isNetworking() {
                        showMessage(message: "获取失败")
                        resultBlock(NSNull(),.failed)
                    } else {
                        showMessage(message: "似乎与网络断开链接")
                        resultBlock(NSNull(),.noNetwork)
                    }
                }
            }
        }
    }
    
    /// 上传用户认证信息接口
    /// - Parameters:
    ///   - infos: 认证信息数据
    ///   - resultBlock: 返回
    static func requestsPOSTAuthInfo(identityId: String,infos: NSArray, resultBlock: @escaping resultNewsBlock) {
        
        let values = NSMutableDictionary()
        values.addEntries(from: ["sid":UserInfoManager.shared.userInfo.uid])
        values.addEntries(from: ["identityId":identityId])
        let temp_array = NSMutableArray()
        for info in infos {
            let value = (info as! MineStandInfoModel).value ?? ""
            let key = (info as! MineStandInfoModel).name ?? ""
            let authInfoId = (info as! MineStandInfoModel).authInfoId
            let inputType = (info as! MineStandInfoModel).inputType
            let nonEmpty = (info as! MineStandInfoModel).nonEmpty
            if value.count == 0 && nonEmpty {
                if inputType == 3 {
                    showMessage(message: "请选择\(key)")
                    return
                } else {
                    showMessage(message: "请填写\(key)")
                    return
                }
            }
            temp_array.add(["authInfoId":authInfoId,"msg":value] as [String : Any])
        }
        values.addEntries(from: ["authInfo":temp_array])
        do {
            let request = URLRequest.init(url: URL.init(string: APPBaseMCUrl+"/identityApi/saveUserMsg")!) as! NSMutableURLRequest
            request.httpMethod = "POST"
            request.timeoutInterval = 10
            request.setValue("application/json", forHTTPHeaderField: "Content-Type")
            let data = try JSONSerialization.data(withJSONObject: values, options: .prettyPrinted)
            request.httpBody = data
            showLoading(message: "")
            CNLiveNetworking.setAllowRequestDefaultArgument(false)
            CNLiveNetworking.setupShowDataResult(false)
            CNLiveNetworking.setBuildCustomUrlRequest(request as URLRequest) { task, result, error in
                hiddenLoading()
                if (error == nil) {
                    let resp = result as! NSDictionary
                    let errorCode = "\(resp["errorCode"] ?? "0")"
                    if (errorCode == "0") {
                        resultBlock(NSNull(),.success)
                    } else {
                        showMessage(message: resp["errorMessage"] as! String)
                        resultBlock(NSNull(),.failed)
                    }
                } else {
                    if CNLiveNetworking.isNetworking() {
                        showMessage(message: "上传失败")
                        resultBlock(NSNull(),.failed)
                    } else {
                        showMessage(message: "似乎与网络断开链接")
                        resultBlock(NSNull(),.noNetwork)
                    }
                }
            }
        } catch {
            showMessage(message: "上传失败")
            resultBlock(NSNull(),.failed)
        }
    }
    
    /// 获取身份信息数据
    /// - Parameters:
    ///   - identityId: 身份id
    ///   - resultBlock: 返回
    static func requestsStandInfo(identityId: String, type: CNLiveMineGetWriteType, resultBlock: @escaping resultNewsBlock) {
        let param = NSMutableDictionary()
        param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "sid")
        param.setValue(identityId, forKey: "identityId")
        CNLiveNetworking.setAllowRequestDefaultArgument(true)
        CNLiveNetworking.setupShowDataResult(false)
        CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseMCUrl+"/identityApi/getIdentity", param: param as! [String: String], cacheType: .networkOnly) { task, result, error in
            hiddenLoading()
            if (error == nil) {
                let resp = result as! NSDictionary
                let errorCode = "\(resp["errorCode"] ?? "0")"
                if (errorCode == "0") {
                    if resp["data"] is NSNull {
                        resultBlock(NSNull(),.failed)
                    } else {
                        let newsModel = dictionaryToModel(resp as! [String : Any], MineStandInfoBaseModel.self,"data") as! MineStandInfoBaseModel
                        if type == .nodate {
                            let tempArray = NSMutableArray()
                            for authinfo in newsModel.authInfos {
                                if authinfo.input {
                                    tempArray.add(authinfo)
                                }
                            }
                            resultBlock(tempArray,.success)
                        }else if (type == .effect) {
                            resultBlock(newsModel,.success)
                        }else {
                            let tempArray = NSMutableArray.init(array: newsModel.authInfos)
                            resultBlock(tempArray,.success)
                        }
                    }
                } else {
                    showMessage(message: resp["errorMessage"] as! String)
                    resultBlock(NSNull(),.failed)
                }
            } else {
                if CNLiveNetworking.isNetworking() {
                    showMessage(message: "获取失败")
                    resultBlock(NSNull(),.failed)
                } else {
                    showMessage(message: "似乎与网络断开链接")
                    resultBlock(NSNull(),.noNetwork)
                }                
            }
        }
    }
    
    /// 获取最新app版本
    /// - Parameter resultBlock: 结果回调
    static func requestSystemNews(resultBlock: @escaping resultNewsBlock) {
        let param = NSMutableDictionary()
        param.setValue("2", forKey: "appType")
        CNLiveNetworking.setAllowRequestDefaultArgument(true)
        CNLiveNetworking.setupShowDataResult(false)
        CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseMCUrl+"/commonApi/getVersion", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
            if (error == nil) {
                let resp = result as! NSDictionary
                let errorCode = "\(resp["errorCode"] ?? "0")"
                if (errorCode == "0" && (resp["data"] != nil)) {
                    if resp["data"] is NSNull {
                        resultBlock(NSNull(),.failed)
                    } else {
                        let userInfoModel = dictionaryToModel(resp as! [String : Any], UpdateInfoModel.self,"data") as! UpdateInfoModel
                        let ver1 = "\(userInfoModel.version.split(separator: "_").last ?? "0")"
                        let ver2 = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String
                        print("获取的新版本号=>\(ver1),原来的版本号=>\(ver2)")
                        if CNLiveMineViewModel.compare(v1: ver1, v2: ver2) {
                            resultBlock(userInfoModel,.success)
                        } else {
                           print("没有新版本")
                        }
                    }
                } else {
                    resultBlock(NSNull(),.failed)
                }
            } else {
                if CNLiveNetworking.isNetworking() {
                    resultBlock(NSNull(),.failed)
                } else {
                    resultBlock(NSNull(),.noNetwork)
                }
            }
        }
    }
    
    /// 获取身份列表
    /// - Parameters:
    ///   - page: 页数
    ///   - resultBlock: 返回
    static func requestIdenList(page: Int,resultBlock: @escaping resultNewsBlock) {
        showLoading(message: "")
        let param = NSMutableDictionary()
        param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "sid")
        param.setValue("\(page)", forKey: "page")
        param.setValue("10", forKey: "pageSize")
        CNLiveNetworking.setAllowRequestDefaultArgument(true)
        CNLiveNetworking.setupShowDataResult(false)
        CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseMCUrl+"/identityApi/list", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
            hiddenLoading()
            if (error == nil) {
                let resp = result as! NSDictionary
                let errorCode = "\(resp["errorCode"] ?? "0")"
                if (errorCode == "0") {
                    let userInfoModel = dictionaryToModel(resp as! [String : Any], UpdateInfoModel.self,"data") as! UpdateInfoModel
                    resultBlock(userInfoModel,.success)
                    
                } else {
                    resultBlock(NSNull(),.failed)
                }
            } else {
                if CNLiveNetworking.isNetworking() {
                    resultBlock(NSNull(),.failed)
                } else {
                    resultBlock(NSNull(),.noNetwork)
                }
            }
        }
    }
    
    /// 结果检查逻辑
    /// - Parameter id: 当前身份
    static func startKeepTimeWithStand(id: String, resultBlock: @escaping resultNewsBlock) {
        // 定义需要计时的时间
        var timeCount = 20
        // 在global线程里创建一个时间源
        let codeTimer = DispatchSource.makeTimerSource(queue: DispatchQueue.global())
        // 设定这个时间源是每秒循环一次,立即开始
        codeTimer.schedule(deadline: .now(), repeating: .seconds(1))
        // 设定时间源的触发事件
        codeTimer.setEventHandler {
            // 每秒计时一次
            timeCount = timeCount - 1
            // 时间到了取消时间源
            if timeCount <= 0 {
                codeTimer.cancel()
                // 返回主线程处理一些事件,更新UI等等
                DispatchQueue.main.async {
                    showLoading(message: "")
                    CNLiveMineViewModel.requestsStandInfo(identityId: id, type: .effect) { result, respStatue in
                        if respStatue == .success {
                            let listBaseModel = result as! MineStandInfoBaseModel
                            if listBaseModel.authTime > 0 || listBaseModel.code!.count > 0 {
                                showMessage(message: listBaseModel.name!.count > 0 ? "恭喜您通过认证,您已是\(listBaseModel.name ?? "")" : "恭喜您通过认证")
                                resultBlock(listBaseModel, .success)
                                NotificationCenter.default.post(name: Notification.Name.StandAuth.StandAuthNotificationSuccess, object: nil)
                            } else {
                                showMessage(message: "审核失败,请您修改后重新提交")
                                resultBlock(listBaseModel, .failed)
                                NotificationCenter.default.post(name: Notification.Name.StandAuth.StandAuthNotificationUnSuccess, object: nil)
                            }
                        }
                    }
                }
            }
        }
        // 启动时间源
        codeTimer.resume()
    }
    
//!!!: 积分相关接口请求
    
    /// 获取积分余额相关数据接口
    /// - Parameter resultBlock: 返回
    static func requestWithCheckIn(resultBlock: @escaping resultNewsBlock) {
        let param = NSMutableDictionary()
        param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "uid")
        let custom_param = NSMutableDictionary()
        custom_param.setValue(APPId_wjj, forKey: "appId")
        custom_param.setValue(APPKey_wjj, forKey: "appKey")
        CNLiveNetworking.setAllowRequestDefaultArgument(true)
        CNLiveNetworking.setupShowDataResult(false)
        CNLiveNetworking.setupDSRequest(true)
        CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
        CNLiveNetworking.requestNetwork(with: .POST, urlString: APPBaseWjjShopUrl+"/Api/Index3/myOrderCount", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
            hiddenLoading()
            if (error == nil) {
                let resp = result as! NSDictionary
                let errorCode = "\(resp["code"] ?? "0")"
                if (errorCode == "200") {
                    let listModel = dictionaryToModel(resp as! [String : Any], MinePointCheckInModel.self,"data") as! MinePointCheckInModel
                    resultBlock(listModel,.success)
                } else {
                    showMessage(message: resp["message"] as! String)
                    resultBlock(NSNull(),.failed)
                }
            } else {
                if CNLiveNetworking.isNetworking() {
                    showMessage(message: "获取失败")
                    resultBlock(NSNull(),.failed)
                } else {
                    showMessage(message: "似乎与网络断开链接")
                    resultBlock(NSNull(),.noNetwork)
                }
            }
        }
    }
    
    /// 获取任务列表接口
    /// - Parameter resultBlock: 返回
    static func requestWithTaskList(resultBlock: @escaping resultNewsBlock) {
        let param = NSMutableDictionary()
        param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "sid")
        let custom_param = NSMutableDictionary()
        custom_param.setValue(APPId_wjj, forKey: "appId")
        custom_param.setValue(APPKey_wjj, forKey: "appKey")
        CNLiveNetworking.setAllowRequestDefaultArgument(true)
        CNLiveNetworking.setupShowDataResult(false)
        CNLiveNetworking.setupSignRequestKey(APPKey_wjj)
        CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
        CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseWjjUrl+"/Daren/integral/getTasks.action", param: (param as! [AnyHashable : Any]), cacheType: .networkOnly) { task, result, error in
            hiddenLoading()
            if (error == nil) {
                let resp = result as! NSDictionary
                let errorCode = "\(resp["errorCode"] ?? "0")"
                if (errorCode == "0") {
                    let dict = resp["data"] as! NSDictionary
                    let array = dict["dailyTask"] as! NSArray
                    let tempArray = NSMutableArray()
                    for item in array {
                        let listModel = dictionaryToModel(item as! [String : Any], MineTaskCheckListModel.self,"") as! MineTaskCheckListModel
                        if listModel.taskId!.contains("check_in") {
                            tempArray.add(listModel)
                        }
                    }
                    resultBlock(tempArray,.success)
                } else {
                    showMessage(message: resp["errorMessage"] as! String)
                    resultBlock(NSNull(),.failed)
                }
            } else {
                if CNLiveNetworking.isNetworking() {
                    showMessage(message: "获取失败")
                    resultBlock(NSNull(),.failed)
                } else {
                    showMessage(message: "似乎与网络断开链接")
                    resultBlock(NSNull(),.noNetwork)
                }
            }
        }
    }
    
    /// 获取网家家余额数据
    /// - Parameters:
    ///   - page: 页数
    ///   - resultBlock: 返回
    static func requestWithTradRecord(page: NSInteger, resultBlock: @escaping resultNewsBlock) {
        let param = NSMutableDictionary()
        param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "targetId")
        param.setValue("0", forKey: "type")//0全部(默认) 1收入 2支出
        param.setValue("\((timeStamp * 1000) - 30*24*60*60)", forKey: "startTime")//"1600569015000"
        param.setValue("\((timeStamp * 1000))", forKey: "endTime")//"1603074615000"
//        param.setValue("1600569015000", forKey: "startTime")
//        param.setValue("1603074615000", forKey: "endTime")
        param.setValue("10", forKey: "pageSize")
        param.setValue("\(page)", forKey: "pageNo")
        let custom_param = NSMutableDictionary()
        custom_param.setValue(APPId_wjj, forKey: "appId")
        custom_param.setValue(APPKey_wjj, forKey: "appKey")
        CNLiveNetworking.setAllowRequestDefaultArgument(true)
        CNLiveNetworking.setupShowDataResult(false)
        CNLiveNetworking.setupSignRequestKey(APPKey_wjj)
        CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
        CNLiveNetworking.requestNetwork(with: .POST, urlString: APPBaseWjjUrl+"/Daren/transaction/getTransactionRecord.action", param: (param as! [AnyHashable : Any]), cacheType: .networkOnly) { task, result, error in
            hiddenLoading()
            if (error == nil) {
                let resp = result as! NSDictionary
                let errorCode = "\(resp["errorCode"] ?? "0")"
                if (errorCode == "0") {
                    let listModel = dictionaryToModel(resp as! [String : Any], MineTradingRecordBaseModel.self,"data") as! MineTradingRecordBaseModel
                    resultBlock(listModel,.success)
                } else {
                    showMessage(message: resp["errorMessage"] as! String)
                    resultBlock(NSNull(),.failed)
                }
            } else {
                if CNLiveNetworking.isNetworking() {
                    showMessage(message: "获取失败")
                    resultBlock(NSNull(),.failed)
                } else {
                    showMessage(message: "似乎与网络断开链接")
                    resultBlock(NSNull(),.noNetwork)
                }
            }
        }
    }
    
    /// 获取积分明细
    /// - Parameters:
    ///   - page: 页数
    ///   - resultBlock: 返回
    static func requestWithIntegralRecord(page: NSInteger, resultBlock: @escaping resultNewsBlock) {
        let startTime = NSDate.timeIntervalChangeToTimeStr(timeInterval: Double((timeStamp * 1000) - 30*24*60*60))
        let endTime = NSDate.timeIntervalChangeToTimeStr(timeInterval: Double(timeStamp * 1000))
        let param = NSMutableDictionary()
        param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "sid")
        param.setValue(startTime, forKey: "startTime")//开始时间  "2022-08-21"
        param.setValue(endTime, forKey: "endTime")//开始时间 "2022-09-20"
        param.setValue("0", forKey: "type")//0全部(默认) 1收入 2支出
        param.setValue("10", forKey: "pageSize")
        param.setValue("\(page)", forKey: "pageNo")
        let custom_param = NSMutableDictionary()
        custom_param.setValue(APPId_wjj, forKey: "appId")
        custom_param.setValue(APPKey_wjj, forKey: "appKey")
        CNLiveNetworking.setAllowRequestDefaultArgument(true)
        CNLiveNetworking.setupShowDataResult(false)
        CNLiveNetworking.setupSignRequestKey(APPKey_wjj)
        CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
        CNLiveNetworking.requestNetwork(with: .POST, urlString: APPBaseWjjUrl+"/Daren/integral/myIntegralRecord.action", param: (param as! [AnyHashable : Any]), cacheType: .networkOnly) { task, result, error in
            hiddenLoading()
            if (error == nil) {
                let resp = result as! NSDictionary
                let errorCode = "\(resp["errorCode"] ?? "0")"
                if (errorCode == "0") {
                    let listModel = dictionaryToModel(resp as! [String : Any], MineIntegralRecordModel.self,"data") as! MineIntegralRecordModel
                    resultBlock(listModel,.success)
                } else {
                    showMessage(message: resp["errorMessage"] as! String)
                    resultBlock(NSNull(),.failed)
                }
            } else {
                if CNLiveNetworking.isNetworking() {
                    showMessage(message: "获取失败")
                    resultBlock(NSNull(),.failed)
                } else {
                    showMessage(message: "似乎与网络断开链接")
                    resultBlock(NSNull(),.noNetwork)
                }
            }
        }
    }
    
    /// 签到功能
    /// - Parameters:
    ///   - resultBlock: 返回
    static func requestWithCheckInAction(resultBlock: @escaping resultNewsBlock) {
        let param = NSMutableDictionary()
        param.setValue(UserInfoManager.shared.userInfo.uid, forKey: "sid")
        let custom_param = NSMutableDictionary()
        custom_param.setValue(APPId_wjj, forKey: "appId")
        custom_param.setValue(APPKey_wjj, forKey: "appKey")
        CNLiveNetworking.setAllowRequestDefaultArgument(true)
        CNLiveNetworking.setupShowDataResult(false)
        CNLiveNetworking.setupSignRequestKey(APPKey_wjj)
        CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
        CNLiveNetworking.requestNetwork(with: .POST, urlString: APPBaseWjjUrl+"/Daren/integral/checkIn.action", param: (param as! [AnyHashable : Any]), cacheType: .networkOnly) { task, result, error in
            hiddenLoading()
            if (error == nil) {
                let resp = result as! NSDictionary
                let errorCode = "\(resp["errorCode"] ?? "0")"
                if (errorCode == "0") {
                    resultBlock(resp,.success)
                } else {
                    showMessage(message: resp["errorMessage"] as! String)
                    resultBlock(NSNull(),.failed)
                }
            } else {
                if CNLiveNetworking.isNetworking() {
                    showMessage(message: "签到失败")
                    resultBlock(NSNull(),.failed)
                } else {
                    showMessage(message: "似乎与网络断开链接")
                    resultBlock(NSNull(),.noNetwork)
                }
            }
        }
    }
    
    /// 获取十位时间戳
    static var timeStamp: Int {
        let timeInterval: TimeInterval = NSDate().timeIntervalSince1970
        let timeStamp = Int(timeInterval)
        return timeStamp
    }
    
    /// 比较版本大小,返回是否需要更新
    /// - Parameters:
    ///   - v1: 版本1-新版本
    ///   - v2: 版本2-当前版本
    /// - Returns: true:v1>v2  false: v1<=v2
    static fileprivate func compare(v1: String, v2: String) -> Bool {
        
        if v1.isEmpty && v2.isEmpty || v1.isEmpty {
            return false
        }
        
        if v2.isEmpty {
            return true
        }
        
        let array1 = v1.components(separatedBy: ".")
        let array2 = v2.components(separatedBy: ".")
        let mineCount = array1.count > array2.count ? (array2.count - 1) : (array1.count - 1)
        
        var value1: Int = 0
        var value2: Int = 0
        
        for i in 0...mineCount {
            
            if !(array1[i]).isPurnInt() || !(array2[i]).isPurnInt() {
                return false
            }
            value1 = Int(array1[i])!
            value2 = Int(array2[i])!
            
            //v1版本字段大于v2版本字段
            if value1 > value2 {
                return true
            } else if (value1 < value2) {
                return false
            }
            //v1版本==v2版本字段 继续循环
        }
        if array1.count > array2.count {
            return true
        } else if (array1.count <= array2.count) {
            return false
        }
        return false
    }
    
}