CNLiveCommuntViewModel.m 38.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
//
//  CNLiveCommuntViewModel.m
//  CNLiveCommunitModule-CNLiveCommunitModule
//
//  Created by open on 2022/2/1.
//

#import "CNLiveCommuntViewModel.h"
#import <CommonCrypto/CommonDigest.h>

//自动选择微信OR支付宝
#define CNCCommuntHomePayApiContentURL   cn_API_OpenApi2(@"/unifypay/pay")

//获取首页数据
#define CNCCommuntHomeListContentURL   cn_API_CommuntyApi(@"/user/nbhdAppIndex")
//获取小区列表数据
#define CNCCommuntNBhdListContentURL   cn_API_CommuntyApi(@"/user/nbhdList")
//提交报修
#define CNCCommuntAddMaintainContentURL   cn_API_CommuntyApi(@"/repairApi/add")
//活动报名
#define CNCCommuntPayMentSignUpOrderContentURL   cn_API_CommuntyApi(@"/signupApi/signup")
//获取活动列表数据
#define CNCCommuntListHandContentURL   cn_API_CommuntyApi(@"/handworkApi/listHandwork")
//获取活动记录列表数据
#define CNCCommuntListOrderContentURL   cn_API_CommuntyApi(@"/signupApi/userOrders")
//获取保修记录列表数据
#define CNCCommuntListRepairContentURL   cn_API_CommuntyApi(@"/repairApi/getUserOrders")
//获取获取维修项目数据
#define CNCCommuntListMaintainContentURL   cn_API_CommuntyApi(@"/repairApi/getMaintains")
//获取报修详情
#define CNCCommuntMaintainDetailContentURL   cn_API_CommuntyApi(@"/repairApi/getOrder")
//获取现金线下交费
#define CNCCommuntPayMentDetailContentURL   cn_API_CommuntyApi(@"/repairApi/cashPayment")
//抢单
#define CNCCommuntPayMentGrabOrderContentURL   cn_API_CommuntyApi(@"/repairApi/grabOrder")
//用户取消订单
#define CNCCommuntPayMentCancleOrderContentURL   cn_API_CommuntyApi(@"/repairApi/cancleOrder")
//设置维修金额
#define CNCCommuntPayMentTotalFeeOrderContentURL   cn_API_CommuntyApi(@"/repairApi/setTotalFee")
//报修缴费
#define CNCCommuntPayMentRepairOrderContentURL   cn_API_CommuntyApi(@"/repairApi/repairOrderNotify")
//用户评价
#define CNCCommuntPayMentActivityCommentsOrderContentURL   cn_API_CommuntyApi(@"/feedbackApi/add")
//活动详情
#define CNCCommuntPayMentActivityDetailOrderContentURL   cn_API_CommuntyApi(@"/handworkApi/handworkById")
//查看详情
#define CNCCommuntPayMentActivityResultOrderContentURL   cn_API_CommuntyApi(@"/signupApi/userSignupInfo")
@implementation CNLiveCommuntViewModel

/// 读取小区APP首页
/// @param nbhdId 小区id
/// @param completerBlock 返回数据
+(void)requestWithCommuntyHomeNBhdAppIndexWithNBhdId:(NSString *)nbhdId CompleterBlock:(void(^)(NSArray *))completerBlock
{
    if ([CNLiveNetworking isNetworking]) {
        [QMUITips showLoadingInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
        [CNLiveNetworking setAllowRequestDefaultArgument:YES];
        [CNLiveNetworking setupShowDataResult:NO];
        [CNLiveNetworking setupShowResult:YES];
        [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodGET URLString:CNCCommuntHomeListContentURL Param:@{@"nbhdId":[nbhdId isNotBlank]?nbhdId:@""} CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
            [QMUITips hideAllTipsInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
            [CNLiveCommuntViewModel communty_chooseRequestWithResponseObject:responseObject Error:error isData:NO CompleterBlock:^(id responseObject) {
                if (responseObject && [[responseObject numberValueForKey:@"errorCode" default:@1] isEqualToNumber:@0]) {
                    NSMutableArray * tempArray = [CNLiveCommuntyHomeModel mj_objectArrayWithKeyValuesArray:[responseObject objectForKey:@"data"]];
                    [CNLiveRespCacheManager cachePathWithObject:responseObject FileName:CNCCommuntHomeListContentURL];
                    if (tempArray.count > 0 && completerBlock) completerBlock(tempArray);
                }else{
                    if (![[responseObject numberValueForKey:@"errorCode" default:@1] isEqualToNumber:@100062]) {
                        id resp = [CNLiveRespCacheManager objectCacheWithFileName:CNCCommuntHomeListContentURL];
                        NSMutableArray * tempArray = [CNLiveCommuntyHomeModel mj_objectArrayWithKeyValuesArray:resp];
                        if (tempArray.count > 0) {
                            if (completerBlock) completerBlock(tempArray);
                        }else{
                            if (completerBlock) completerBlock(nil);
                        }
                    }else{
                        [QMUITips showError:[responseObject stringValueForKey:@"errorMessage" default:@""] inView:[CNLiveCommuntTools cCommunt_currentViewController].view hideAfterDelay:2];
                        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                            [[self displayViewController] dsPopViewControllerAnimated:YES];
                        });
                    }
                }
            }];
        }];
    }else{
        id resp = [CNLiveRespCacheManager objectCacheWithFileName:CNCCommuntHomeListContentURL];
        NSMutableArray * tempArray = [CNLiveCommuntyHomeModel mj_objectArrayWithKeyValuesArray:resp];
        if (tempArray.count > 0) {
            if (completerBlock) completerBlock(tempArray);
        }else{
            [QMUITips showError:@"您似乎与互联网断开连接" inView:[CNLiveCommuntTools cCommunt_currentViewController].view hideAfterDelay:1.5];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                if (completerBlock) completerBlock(nil);
            });
        }
    }
}
/// 获取小区列表
/// @param completerBlock 返回数据
+(void)requestWithCommuntyHomeListIndexWithCompleterBlock:(void(^)(NSArray * listArray))completerBlock
{
    [QMUITips showLoadingInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
    [CNLiveNetworking setAllowRequestDefaultArgument:YES];
    [CNLiveNetworking setupShowDataResult:NO];
    [CNLiveNetworking setupShowResult:YES];
    [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodGET URLString:CNCCommuntNBhdListContentURL Param:@{} CacheType:CNLiveNetworkCacheTypeCacheNetwork CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
        [QMUITips hideAllTipsInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
        [CNLiveCommuntViewModel communty_chooseRequestWithResponseObject:responseObject Error:error isData:YES CompleterBlock:^(id responseObject) {
            if (responseObject) {
                NSMutableArray * tempArray = [CNLiveCommuntyHomeListModel mj_objectArrayWithKeyValuesArray:responseObject];
                if (completerBlock) completerBlock(tempArray);
            }else{
                if (completerBlock) completerBlock(@[]);
            }
        }];
    }];
}
/// 请求获取活动列表数据
/// @param nbhdId 小区id
/// @param page 页数
/// @param completerBlock 返回数据
+(void)requestWithCommuntyHomeActivityForNBHdId:(NSString *)nbhdId ShowType:(CNLiveCommuntListShowType)showType Index:(NSInteger)index Page:(NSInteger)page completerBlock:(void (^)(NSArray * _Nonnull, BOOL))completerBlock
{
    [QMUITips showLoadingInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
    if (showType == CNLiveCommuntListShowTypeHome) {
        NSDictionary * paramDict = @{
            @"neighborhoodId":nbhdId,
            @"page":[NSString stringWithFormat:@"%ld",page],
            @"pageSize":@"10"
        };
        [CNLiveNetworking setAllowRequestDefaultArgument:YES];
        [CNLiveNetworking setupShowDataResult:NO];
        [CNLiveNetworking setupShowResult:YES];
        [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodGET URLString:CNCCommuntListHandContentURL Param:paramDict CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
            [QMUITips hideAllTipsInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
            [CNLiveCommuntViewModel communty_chooseRequestWithResponseObject:responseObject Error:error isData:YES CompleterBlock:^(id responseObject) {
                if (responseObject && [[responseObject allKeys] containsObject:@"list"]) {
                    NSMutableArray * tempArray = [CNLiveCommuntyActivityHomeListModel mj_objectArrayWithKeyValuesArray:[responseObject arrayForKey:@"list"]];
                    if (completerBlock) completerBlock(tempArray,[responseObject boolValueForKey:@"isLastPage" default:YES]);
                }else{
                    if (completerBlock) completerBlock(@[],YES);
                }
            }];
        }];
    }
    if (showType == CNLiveCommuntListShowTypeRecord) {
        NSDictionary * paramDict = @{
            @"neighborhoodId":nbhdId,
            @"userId":[CNUserInfoManager manager].userInfoModel.uid,
            @"status":[NSString stringWithFormat:@"%ld",index],
            @"page":[NSString stringWithFormat:@"%ld",page],
            @"pageSize":@"10"
        };
        [CNLiveNetworking setAllowRequestDefaultArgument:YES];
        [CNLiveNetworking setupShowDataResult:NO];
        [CNLiveNetworking setupShowResult:YES];
        [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodGET URLString:CNCCommuntListOrderContentURL Param:paramDict CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
            [QMUITips hideAllTipsInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
            [CNLiveCommuntViewModel communty_chooseRequestWithResponseObject:responseObject Error:error isData:YES CompleterBlock:^(id responseObject) {
                if (responseObject && [[responseObject allKeys] containsObject:@"list"]) {
                    NSMutableArray * tempArray = [CNLiveCommuntyActivityRecordListModel mj_objectArrayWithKeyValuesArray:[responseObject arrayForKey:@"list"]];
                    if (completerBlock) completerBlock(tempArray,[responseObject boolValueForKey:@"isLastPage" default:YES]);
                }else{
                    if (completerBlock) completerBlock(@[],YES);
                }
            }];
        }];
    }
    if (showType == CNLiveCommuntListShowTypeRepair) {
        NSDictionary * paramDict = @{
            @"userId":[CNUserInfoManager manager].userInfoModel.uid,
            @"status":[NSString stringWithFormat:@"%ld",index],
            @"page":[NSString stringWithFormat:@"%ld",page],
            @"pageSize":@"10"
        };
        [CNLiveNetworking setAllowRequestDefaultArgument:YES];
        [CNLiveNetworking setupShowDataResult:NO];
        [CNLiveNetworking setupShowResult:YES];
        [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:CNCCommuntListRepairContentURL Param:paramDict CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
            [QMUITips hideAllTipsInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
            [CNLiveCommuntViewModel communty_chooseRequestWithResponseObject:responseObject Error:error isData:YES CompleterBlock:^(id responseObject) {
                if (responseObject && [[responseObject allKeys] containsObject:@"list"]) {
                    NSMutableArray * tempArray = [CNLiveCommuntyActivityRepairListModel mj_objectArrayWithKeyValuesArray:[responseObject arrayForKey:@"list"]];
                    if (completerBlock) completerBlock(tempArray,[responseObject boolValueForKey:@"isLastPage" default:YES]);
                }else{
                    if (completerBlock) completerBlock(@[],YES);
                }
            }];
        }];
    }
}
/// 获取维修项目
/// @param nbhdId 小区id
/// @param completerBlock 返回数据
+(void)requestWithCommuntyHomeMaintenForNBHdId:(NSString *)nbhdId
                                CompleterBlock:(void(^)(NSArray * dataArray))completerBlock
{
    NSDictionary * paramDict = @{
        @"oId":nbhdId,
        @"page":@"1",
        @"pageSize":@"100"
    };
    [QMUITips showLoadingInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
    [CNLiveNetworking setAllowRequestDefaultArgument:YES];
    [CNLiveNetworking setupShowDataResult:NO];
    [CNLiveNetworking setupShowResult:YES];
    [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodGET URLString:CNCCommuntListMaintainContentURL Param:paramDict CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
        [QMUITips hideAllTipsInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
        [CNLiveCommuntViewModel communty_chooseRequestWithResponseObject:responseObject Error:error isData:YES CompleterBlock:^(id responseObject) {
            if (responseObject) {
                NSMutableArray * tempArray = [CNLiveCommuntyActivityMaintainsListModel mj_objectArrayWithKeyValuesArray:responseObject];
                if (completerBlock) completerBlock(tempArray);
            }else{
                if (completerBlock) completerBlock(@[]);
            }
        }];
    }];
}
/// 提交报修
/// @param param 参数
/// @param nbhdId 小区id
/// @param completerBlock 返回数据
+(void)requestWithCommuntyHomeMaintenPushWithParamDict:(NSDictionary *)param nbhdId:(NSString *)nbhdId CompleterBlock:(nonnull void (^)(CNLiveCommuntyActivityMaintainsCreateModel *))completerBlock
{
    [QMUITips showLoadingInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
    NSMutableDictionary * paramDict = [[NSMutableDictionary alloc] initWithDictionary:param];
    [paramDict addString:nbhdId forKey:@"neighboorHoodId"];
    [paramDict addString:[CNUserInfoManager manager].userInfoModel.uid forKey:@"userId"];
    [CNLiveNetworking setAllowRequestDefaultArgument:YES];
    [CNLiveNetworking setupShowDataResult:NO];
    [CNLiveNetworking setupShowResult:YES];
    [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:CNCCommuntAddMaintainContentURL Param:paramDict CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
        [QMUITips hideAllTipsInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
        [CNLiveCommuntViewModel communty_chooseRequestWithResponseObject:responseObject Error:error isData:YES CompleterBlock:^(id responseObject) {
            if (responseObject) {
                CNLiveCommuntyActivityMaintainsCreateModel * createModel = [CNLiveCommuntyActivityMaintainsCreateModel mj_objectWithKeyValues:responseObject];
                if (completerBlock) completerBlock(createModel);
            }else{
                if (completerBlock) completerBlock(nil);
            }
        }];
    }];
}
/// 获取维修上面时间
/// @param interval 当前时间之后的时间
/// @param completerBlock 返回数据
+(void)requestWithCommuntyHomeMaintenForTimeInterval:(NSInteger)interval CompleterBlock:(void(^)(NSArray * dataArray))completerBlock
{
    NSMutableArray *dayArray = [[NSMutableArray alloc] init];
    //计算从当前日期开始的七天日期
    for (int i = 0; i < interval; i ++) {
        CNLiveCommuntyActivityMaintainsTimeModel * timeModel = [[CNLiveCommuntyActivityMaintainsTimeModel alloc] init];
        NSDateComponents *components_h = [[NSCalendar currentCalendar] components:NSCalendarUnitHour fromDate:[NSDate date]];
        NSMutableArray * tArray = [[NSMutableArray alloc] init];
        NSInteger start = i == 0 ? (components_h.hour-(components_h.hour%2)) : 0;
        for (int i = 0; i < 12; i++) {
            [tArray addObject:[NSString stringWithFormat:@"%02ld~%02ld",start,start+2]];
            start += 2;
        }
        if (i == 0) [tArray removeObjectsInRange:NSMakeRange([tArray indexOfObject:@"22~24"]+1, tArray.count - [tArray indexOfObject:@"22~24"] - 1)];

        NSTimeInterval secondsPerDay = i * 24*60*60;
        NSDate *curDate = [NSDate dateWithTimeInterval:secondsPerDay sinceDate:[NSDate date]];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy-MM-dd"];
        NSString *dateStr = [dateFormatter stringFromDate:curDate];
        timeModel.time = tArray;
        timeModel.day = dateStr;
        [dayArray addObject:timeModel];
    }
    if (completerBlock) completerBlock(dayArray);
}

/// 获取维修订单详情
/// @param maintenId 报修id
/// @param isChat 是不是聊天进来的
/// @param completerBlock 返回数据
+(void)requestWithCommuntyMaintenDetailForMaintenId:(NSString *)maintenId isChat:(BOOL)isChat CompleterBlock:(nonnull void (^)(CNLiveCommuntyActivityMaintainsCreateModel *))completerBlock
{
    [QMUITips showLoadingInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
    [CNLiveNetworking setAllowRequestDefaultArgument:YES];
    [CNLiveNetworking setupShowDataResult:NO];
    [CNLiveNetworking setupShowResult:YES];
    [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:CNCCommuntMaintainDetailContentURL Param:@{@"id":maintenId} CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
        [QMUITips hideAllTipsInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
        [CNLiveCommuntViewModel communty_chooseRequestWithResponseObject:responseObject Error:error isData:YES CompleterBlock:^(id responseObject) {
            if (responseObject) {
                CNLiveCommuntyActivityMaintainsCreateModel * createModel = [CNLiveCommuntyActivityMaintainsCreateModel mj_objectWithKeyValues:responseObject];
                if (isChat && createModel.showType == 0) createModel.showType = 4;
                if (isChat && createModel.showType == 1) createModel.showType = 5;
                if (isChat && createModel.showType == 2) createModel.showType = 6;
                if (isChat && createModel.showType == 3) createModel.showType = 6;
                if (completerBlock) completerBlock(createModel);
            }else{
                if (completerBlock) completerBlock(nil);
            }
        }];
    }];
}

/// 设置线下已经支付
/// @param orderId 订单id
/// @param completerBlock 回去结果
+(void)requestWithCommuntyMaintenPayMentOrderId:(NSString *)orderId CompleterBlock:(void(^)(void))completerBlock
{
    NSDictionary * paramDict = @{
        @"id":orderId,
        @"repairId":[CNUserInfoManager manager].userInfoModel.uid
    };
    [QMUITips showLoadingInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
    [CNLiveNetworking setAllowRequestDefaultArgument:YES];
    [CNLiveNetworking setupShowDataResult:NO];
    [CNLiveNetworking setupShowResult:YES];
    [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:CNCCommuntPayMentDetailContentURL Param:paramDict CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
        [QMUITips hideAllTipsInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
        [CNLiveCommuntViewModel communty_chooseRequestWithResponseObject:responseObject Error:error isData:NO CompleterBlock:^(id responseObject) {
            if (responseObject && completerBlock) completerBlock();
        }];
    }];
}

/// 抢单
/// @param orderId 订单id
/// @param type 类型 1:接单 0:取消接单
/// @param completerBlock 结果返回
+(void)requestWithCommuntyGrabOrderMentOrderId:(NSString *)orderId type:(BOOL)type CompleterBlock:(void(^)(void))completerBlock
{
    NSDictionary * paramDict = @{
        @"id":orderId,
        @"repairId":[CNUserInfoManager manager].userInfoModel.uid,
        @"type": type?@"1":@"0"
    };
    [QMUITips showLoadingInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
    [CNLiveNetworking setAllowRequestDefaultArgument:YES];
    [CNLiveNetworking setupShowDataResult:NO];
    [CNLiveNetworking setupShowResult:YES];
    [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:CNCCommuntPayMentGrabOrderContentURL Param:paramDict CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
        [QMUITips hideAllTipsInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
        [CNLiveCommuntViewModel communty_chooseRequestWithResponseObject:responseObject Error:error isData:NO CompleterBlock:^(id responseObject) {
            if (responseObject && completerBlock) completerBlock();
        }];
    }];
}
/// 用户取消订单
/// @param orderId 订单id
/// @param completerBlock 结果返回
+(void)requestWithCommuntyCancleOrderMentOrderId:(NSString *)orderId CompleterBlock:(void(^)(void))completerBlock
{
    NSDictionary * paramDict = @{
        @"id":orderId,
        @"userId":[CNUserInfoManager manager].userInfoModel.uid,
    };
    [QMUITips showLoadingInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
    [CNLiveNetworking setAllowRequestDefaultArgument:YES];
    [CNLiveNetworking setupShowDataResult:NO];
    [CNLiveNetworking setupShowResult:YES];
    [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:CNCCommuntPayMentCancleOrderContentURL Param:paramDict CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
        [QMUITips hideAllTipsInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
        [CNLiveCommuntViewModel communty_chooseRequestWithResponseObject:responseObject Error:error isData:NO CompleterBlock:^(id responseObject) {
            if (responseObject && completerBlock) completerBlock();
        }];
    }];
}

/// 设置维修费用
/// @param orderId 订单id
/// @param totalFee 价格,以分为单位
/// @param completerBlock 结果返回
+(void)requestWithCommuntyTotalFeeOrderMentOrderId:(NSString *)orderId totalFee:(NSString *)totalFee CompleterBlock:(void(^)(NSString * payUrl))completerBlock
{
    NSDictionary * paramDict = @{
        @"id":orderId,
        @"totalFee":totalFee//[NSString stringWithFormat:@"%.0f",[totalFee floatValue] * 100],
    };
    [QMUITips showLoadingInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
    [CNLiveNetworking setAllowRequestDefaultArgument:YES];
    [CNLiveNetworking setupShowDataResult:NO];
    [CNLiveNetworking setupShowResult:YES];
    [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:CNCCommuntPayMentTotalFeeOrderContentURL Param:paramDict CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
        [QMUITips hideAllTipsInView:[CNLiveCommuntTools cCommunt_currentViewController].view.viewController.view];
        [CNLiveCommuntViewModel communty_chooseRequestWithResponseObject:responseObject Error:error isData:YES CompleterBlock:^(id responseObject) {
            if (responseObject) {
                NSString * timestamp = [CNLiveCommuntViewModel getNowTimestamp];
                NSDictionary * param = [[NSMutableDictionary alloc] initWithDictionary:@{
                    @"appId":AppId,
                    @"sp_id":AppId,
                    @"out_trade_no":orderId,
                    @"body":[responseObject stringValueForKey:@"repairName" default:@"服务"],
                    @"total_fee":totalFee,//[NSString stringWithFormat:@"%.0f",[totalFee floatValue] * 100],
                    @"user_id":[CNUserInfoManager manager].userInfoModel.uid,
                    @"notify_url":CNCCommuntPayMentRepairOrderContentURL,
                    @"ver":[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"],
                    @"timestamp":timestamp,
                }];
                NSString *string = [NSString stringWithFormat:@"%@&key=%@",[CNLiveCommuntViewModel signvalue:param URLString:nil],APPKey];
                NSString *signString = [[CNLiveCommuntViewModel sha1:string] uppercaseString];
                NSString * url = [NSString stringWithFormat:@"%@?%@&sign=%@",CNCCommuntHomePayApiContentURL,[CNLiveCommuntViewModel signvalue:param URLString:nil],signString];
                if (completerBlock) completerBlock(url);
            }
        }];
    }];
}

/// 活动报名
/// @param handworkId 手工活动id
/// @param users 参与人
/// @param completerBlock 结果返回
+(void)requestWithCommuntySingUpOrderMentHandworkId:(NSString *)handworkId Ussers:(NSArray *)users CompleterBlock:(nonnull void (^)(CNLiveCommuntyActivitySignUpModel * ))completerBlock
{
    NSDictionary * paramDict = @{
        @"handworkId":handworkId,
        @"signupVosJson":[users mj_JSONString],
        @"createUserId":[CNUserInfoManager manager].userInfoModel.uid,
        @"type":@"1"
    };
    [QMUITips showLoadingInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
    [CNLiveNetworking setAllowRequestDefaultArgument:YES];
    [CNLiveNetworking setupShowDataResult:NO];
    [CNLiveNetworking setupShowResult:YES];
    [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:CNCCommuntPayMentSignUpOrderContentURL Param:paramDict CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
        [QMUITips hideAllTipsInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
        [CNLiveCommuntViewModel communty_chooseRequestWithResponseObject:responseObject Error:error isData:YES CompleterBlock:^(id responseObject) {
            if (responseObject) {
                CNLiveCommuntyActivitySignUpModel * signUpModel = [CNLiveCommuntyActivitySignUpModel mj_objectWithKeyValues:responseObject];
                if (completerBlock) completerBlock(signUpModel);
            }else{
                if (completerBlock) completerBlock(nil);
            }
        }];
    }];
}

/// 对用户信息进行存读取操作
/// @param userDict 用户信息
/// @param isSave 读&存
/// @param isNew 是不是新数据
/// @param completerBlock 返回结果
+(void)requestWithCommuntySaveInfoUsersMentUserDict:(NSDictionary *)userDict isSave:(BOOL)isSave isNew:(BOOL)isNew CompleterBlock:(void(^)(NSArray * userArray, BOOL isSave))completerBlock
{
    NSString * cacheKey = [NSString stringWithFormat:@"%@/kCNLiveCommuntySaveInfoUsersMentKey04",[CNUserInfoManager manager].userInfoModel.uid];
    if (isSave) {
        if ([userDict allKeys].count > 0 && [userDict allValues].count > 0) {
            NSString * save_string = [NSString stringWithFormat:@"%@",[CNLiveRespCacheManager objectCacheWithFileName:cacheKey]];
            NSMutableArray * tempArray = [[NSMutableArray alloc] initWithArray:[save_string mj_JSONObject]];
            if (!isNew) {
                BOOL isReplace = YES;
                NSString * i_nameString = [userDict stringValueForKey:@"name" default:@""];
                NSString * i_sexString = [userDict stringValueForKey:@"gender" default:@""];
                NSString * i_ageString = [userDict stringValueForKey:@"age" default:@""];
                NSString * i_mobileString = [userDict stringValueForKey:@"mobile" default:@""];
                for (NSDictionary * subDict in tempArray) {
                    NSString * o_nameString = [subDict stringValueForKey:@"name" default:@""];
                    NSString * o_sexString = [subDict stringValueForKey:@"gender" default:@""];
                    NSString * o_ageString = [subDict stringValueForKey:@"age" default:@""];
                    NSString * o_mobileString = [subDict stringValueForKey:@"mobile" default:@""];
                    if (![i_nameString isEqualToString:o_nameString]
                        || ![i_sexString isEqualToString:o_sexString]
                        || ![i_ageString isEqualToString:o_ageString]
                        || ![i_mobileString isEqualToString:o_mobileString]) {
                        [tempArray replaceObjectAtIndex:[tempArray indexOfObject:subDict] withObject:userDict];
                        isReplace = NO;
                        break;
                    }
                }
                if (isReplace) [tempArray addObject:userDict];
            }else{
                [tempArray addObject:userDict];
            }
            NSString * user_info = [tempArray mj_JSONString];
            [CNLiveRespCacheManager cachePathWithObject:user_info FileName:cacheKey];
            if (completerBlock) completerBlock(@[],isSave);
        }
    }else{
        NSString * save_string = [NSString stringWithFormat:@"%@",[CNLiveRespCacheManager objectCacheWithFileName:cacheKey]];
        NSMutableArray * tempArray = [[NSMutableArray alloc] initWithArray:[save_string mj_JSONObject]];
        if (completerBlock) completerBlock(tempArray,isSave);
    }
}


/// 对活动进行评论id
/// @param contentId 订单Id
/// @param handworkId 活动Id
/// @param comment 用户id
/// @param imgs 评价内容
/// @param isAnonymity 评价图片
/// @param completerBlock 是否匿名 true:匿名
+(void)requestWithCommuntyCommentsInfoWithContentId:(NSString *)contentId handworkId:(NSString *)handworkId comment:(NSString *)comment imgs:(NSString *)imgs isAnonymity:(BOOL)isAnonymity CompleterBlock:(void(^)(void))completerBlock
{
    NSDictionary * paramDict = @{
        @"signupId":contentId,
        @"handworkId":handworkId,
        @"userId":[CNUserInfoManager manager].userInfoModel.uid,
        @"comment":comment,
        @"imgs":imgs,
        @"isAnonymity":isAnonymity?@"true":@"false",
    };
    [QMUITips showLoadingInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
    [CNLiveNetworking setAllowRequestDefaultArgument:YES];
    [CNLiveNetworking setupShowDataResult:NO];
    [CNLiveNetworking setupShowResult:YES];
    [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:CNCCommuntPayMentActivityCommentsOrderContentURL Param:paramDict CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
        [QMUITips hideAllTipsInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
        [CNLiveCommuntViewModel communty_chooseRequestWithResponseObject:responseObject Error:error isData:NO CompleterBlock:^(id responseObject) {
            if ([responseObject[@"errorMessage"] isEqualToString:@"success"] && completerBlock) completerBlock();
        }];
    }];
}
/// 获取活动详情界面接口
/// @param activityId 活动id
/// @param completerBlock 返回结果
+(void)requestWithCommuntyActivityDetailMentActivityId:(NSString *)activityId CompleterBlock:(void(^)(CNLiveCommuntyActivityDetailModel * detailModel))completerBlock
{
    NSDictionary * paramDict = @{
        @"orderId":@"",
        @"handworkId":activityId,
    };
    [QMUITips showLoadingInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
    [CNLiveNetworking setAllowRequestDefaultArgument:YES];
    [CNLiveNetworking setupShowDataResult:NO];
    [CNLiveNetworking setupShowResult:YES];
    [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodGET URLString:CNCCommuntPayMentActivityDetailOrderContentURL Param:paramDict CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
        [QMUITips hideAllTipsInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
        [CNLiveCommuntViewModel communty_chooseRequestWithResponseObject:responseObject Error:error isData:YES CompleterBlock:^(id responseObject) {
            if (responseObject) {
                CNLiveCommuntyActivityDetailModel * detailModel = [CNLiveCommuntyActivityDetailModel mj_objectWithKeyValues:responseObject];
                if (completerBlock) completerBlock(detailModel);
            }else{
                if (completerBlock) completerBlock(nil);
            }
        }];
    }];
}
/// 获取成功界面查看详情界面
/// @param orderId 订单id
/// @param signId 报名id
/// @param completerBlock 返回结果
+(void)requestWithCommuntyActivityResultDetailMentOrderId:(NSString *)orderId SignId:(NSString *)signId handworkId:(NSString *)handworkId CompleterBlock:(void(^)(CNLiveCommuntyActivityResultDetailModel * detailModel))completerBlock
{
    NSDictionary * paramDict = @{
        @"orderId":[orderId isNotBlank]?orderId:@"",
        @"handworkId":[handworkId isNotBlank]?handworkId:@"",
        @"signupIds":[signId isNotBlank]?signId:@""
    };
    [QMUITips showLoadingInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
    [CNLiveNetworking setAllowRequestDefaultArgument:YES];
    [CNLiveNetworking setupShowDataResult:NO];
    [CNLiveNetworking setupShowResult:YES];
    [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodGET URLString:CNCCommuntPayMentActivityResultOrderContentURL Param:paramDict CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
        [QMUITips hideAllTipsInView:[CNLiveCommuntTools cCommunt_currentViewController].view];
        [CNLiveCommuntViewModel communty_chooseRequestWithResponseObject:responseObject Error:error isData:YES CompleterBlock:^(id responseObject) {
            if (responseObject) {
                CNLiveCommuntyActivityResultDetailModel * detailModel = [CNLiveCommuntyActivityResultDetailModel mj_objectWithKeyValues:responseObject];
                if (completerBlock) completerBlock(detailModel);
            }else{
                if (completerBlock) completerBlock(nil);
            }
        }];
    }];
}
#pragma mark =========== 对放回的结果进行提醒判断 ===========

/// 获取时间戳
+ (NSString *)getNowTimestamp
{
    NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Beijing"];
    [formatter setTimeZone:timeZone];
    NSDate *datenow = [NSDate date];//现在时间
    NSInteger timeSp = [[NSNumber numberWithDouble:[datenow timeIntervalSince1970]] integerValue];
    return [NSString stringWithFormat:@"%ld",(long)timeSp];
}
+ (NSString *)signvalue:(NSDictionary*)parameter URLString:(NSString *)urlString
{
    //对所有传入参数按照字段名的 ASCII 码从小到大排序
    NSArray *keyArr=[parameter allKeys];
    NSArray *arr = [keyArr sortedArrayUsingSelector:@selector(compare:)];
    NSMutableString *string1 = [[NSMutableString alloc]init];
    if (urlString != nil) [string1 appendFormat:@"%@?",urlString];
    for (int i=0; i<arr.count; i++) {
        NSString *parameterString = [NSString stringWithFormat:@"%@",parameter[[arr objectAtIndex:i]]];
        if (parameterString.length > 0) {
            [string1 appendString:[NSString stringWithFormat:@"%@=%@&",[arr objectAtIndex:i],parameter[[arr objectAtIndex:i]]]];
        }
    }
    if (string1.length > 0) [string1 deleteCharactersInRange:NSMakeRange(string1.length-1, 1)];
    return string1;
}
+ (NSString*)sha1:(NSString *)string
{
    NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
    uint8_t digest[CC_SHA1_DIGEST_LENGTH];
    CC_SHA1(data.bytes, (unsigned int)data.length, digest);
    NSMutableString* output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2];
    for(int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++)
        [output appendFormat:@"%02x", digest[i]];
    
    while ([[output substringToIndex:1] isEqualToString:@"0"]) {
        output = [[NSMutableString alloc] initWithString:[output substringFromIndex:1]];
    }
    return output;
}
/// 对放回的结果进行提醒判断
/// @param responseObject 返回数据
/// @param error 错误
/// @param isData 是否取data
/// @param completerBlock 成功
+(void)communty_chooseRequestWithResponseObject:(id)responseObject Error:(NSError *)error isData:(BOOL)isData CompleterBlock:(void(^)(id responseObject))completerBlock
{
    if (error) {
        
        if (error.code == -1009) {
            [QMUITips showError:@"您似乎与互联网断开连接" inView:[CNLiveCommuntTools cCommunt_currentViewController].view hideAfterDelay:1.5];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                if (completerBlock) completerBlock(nil);
            });
        }else if (error.code == 500 || error.code == 404) {
            [QMUITips showError:@"服务器异常" inView:[CNLiveCommuntTools cCommunt_currentViewController].view hideAfterDelay:1.5];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                if (completerBlock) completerBlock(nil);
            });
        }else{
            [QMUITips showError:@"请求失败" inView:[CNLiveCommuntTools cCommunt_currentViewController].view hideAfterDelay:1.5];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                if (completerBlock) completerBlock(nil);
            });
        }
    }else{
        if (responseObject == nil) {
            [QMUITips showError:@"请求失败" inView:[CNLiveCommuntTools cCommunt_currentViewController].view hideAfterDelay:1.5];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                if (completerBlock) completerBlock(nil);
            });
        }else if ([responseObject isKindOfClass:[NSDictionary class]] && ((NSDictionary *)responseObject).allKeys.count == 0) {
            [QMUITips showError:@"请求失败" inView:[CNLiveCommuntTools cCommunt_currentViewController].view hideAfterDelay:1.5];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                if (completerBlock) completerBlock(nil);
            });
        }else if ([responseObject isKindOfClass:[NSDictionary class]] && ((NSDictionary *)responseObject).allKeys.count > 0 && [responseObject[@"errorCode"] integerValue] != 0) {
            [QMUITips showError:responseObject[@"errorMessage"] inView:[CNLiveCommuntTools cCommunt_currentViewController].view hideAfterDelay:1.5];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                if (completerBlock) completerBlock(nil);
            });
        }else{
            if (isData) {
                if ([[responseObject allKeys] containsObject:@"data"]
                    && responseObject[@"data"]
                    && responseObject[@"data"] != NULL
                    && ![responseObject[@"data"] isKindOfClass:[NSNull class]]) {
                    if (completerBlock) completerBlock(responseObject[@"data"]);
                }else{
                    [QMUITips showError:@"请求失败" inView:[CNLiveCommuntTools cCommunt_currentViewController].view hideAfterDelay:1.5];
                    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                        if (completerBlock) completerBlock(nil);
                    });
                }
            }else{
                if (completerBlock) completerBlock(responseObject);
            }
        }
    }
}
@end