CNLiveCMineInteViewModel.m
11.6 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
//
// CNLiveCMineInteViewModel.m
// CNLiveCMineModule
//
// Created by open on 2021/12/27.
//
#import "CNLiveCMineInteViewModel.h"
#import "CNLiveCMineInteHeaderCustomView.h"
@implementation CNLiveCMineInteViewModel
+(void)requestWithIntegraTaskWithSignMedthodForCompleterBlock:(void (^)(NSMutableArray * , NSString *))completerBlock
{
if (![CNLiveNetworking isNetworking]) {
NSMutableArray * tempArray01 = [[NSMutableArray alloc] initWithArray:@[@"",@"",@"",@""]];
CNLiveCMineInteTaskListModel * listModel = (CNLiveCMineInteTaskListModel *)[CNLiveRespCacheManager objectCacheWithFileName:NSStringFromClass(CNLiveCMineInteTaskListModel.class)];
if (listModel) {
[tempArray01 replaceObjectAtIndex:1 withObject:listModel];
}
CNLiveCMineInteListModel * spListModel = (CNLiveCMineInteListModel *)[CNLiveRespCacheManager objectCacheWithFileName:NSStringFromClass(CNLiveCMineInteListModel.class)];
if (!spListModel) {
spListModel = [[CNLiveCMineInteListModel alloc] init];
NSMutableArray * tempArray = [[NSMutableArray alloc] init];
CNLiveCMineInteListSubModel * subModel = [[CNLiveCMineInteListSubModel alloc] init];
subModel.contentId = @"21";
subModel.poster = @"c_mine_content_item_task";
subModel.title = @"做任务";
subModel.subTitle = @"赚取更多积分";
subModel.isEmpty = @"1";
[tempArray addObject:subModel];
spListModel.list = tempArray;
}
if (spListModel) {
[tempArray01 replaceObjectAtIndex:3 withObject:spListModel];
}
completerBlock(tempArray01,@"请求失败");
[QMUITips showWithText:@"无法连接网络" inView:AppKeyWindow hideAfterDelay:1.5];
return;
}
[[CNLiveCMineService shareMineProtocol] pushCMineInteContentForCMainUMengStatisticaMedthod];
NSDictionary * param = @{
@"sid":[CNUserInfoManager manager].userInfoModel.uid
};
NSDictionary * param01 = @{
@"channelId":@"21",
@"modelId":@"",
@"page":@"1",
@"pageSize":@"10"
};
NSDictionary * param02 = @{
@"blockId":@"21",
@"userId":[CNUserInfoManager manager].userInfoModel.uid,
@"type":@"",
@"page":@"1",
@"pageSize":@"10"
};
__block CNLiveNetworking * signInNetworking = [CNLiveNetworking createBatchOrChainNetworkWithMethod:CNLiveRequestMethodPOST URLString:cn_API_Host(@"/Daren/integral/checkIn.action") Param:param];
signInNetworking.tag = 1000;
signInNetworking.isShowDataResult = YES;
signInNetworking.allowRequestDefaultArgument = YES;
signInNetworking.resultResponseAsynchronously = NO;
__block CNLiveNetworking * inteGetNetworking = [CNLiveNetworking createBatchOrChainNetworkWithMethod:CNLiveRequestMethodGET URLString:cn_API_Host(@"/Daren/integral/getTasks.action") Param:param];
inteGetNetworking.tag = 1001;
inteGetNetworking.isShowDataResult = YES;
inteGetNetworking.allowRequestDefaultArgument = YES;
inteGetNetworking.resultResponseAsynchronously = NO;
__block CNLiveNetworking * spListNetworking = [CNLiveNetworking createBatchOrChainNetworkWithMethod:CNLiveRequestMethodGET URLString:cn_API_Classify(@"/contentApi/getList") Param:param01];
spListNetworking.tag = 1002;
spListNetworking.isShowDataResult = YES;
spListNetworking.allowRequestDefaultArgument = YES;
spListNetworking.resultResponseAsynchronously = NO;
__block CNLiveNetworking * blockNetworking = [CNLiveNetworking createBatchOrChainNetworkWithMethod:CNLiveRequestMethodGET URLString:cn_API_Classify(@"/contentApi/getBlockContents") Param:param02];
blockNetworking.tag = 1003;
blockNetworking.isShowDataResult = YES;
blockNetworking.allowRequestDefaultArgument = YES;
blockNetworking.resultResponseAsynchronously = NO;
[CNLiveNetworkManager requestBatchWithArray:@[signInNetworking,inteGetNetworking,spListNetworking,blockNetworking] CompletionBlock:^(NSArray *resultArray) {
@try {
NSMutableArray * tempArray = [[NSMutableArray alloc] init];
for (CNLiveNetworking * networking in resultArray) {
if (networking.tag == 1000 && ![tempArray containsObject:signInNetworking]) {
[tempArray addObject:networking];
}
if (networking.tag == 1001 && ![tempArray containsObject:inteGetNetworking]) {
[tempArray addObject:networking];
}
if (networking.tag == 1002 && ![tempArray containsObject:spListNetworking]) {
[tempArray addObject:networking];
}
if (networking.tag == 1003 && ![tempArray containsObject:blockNetworking]) {
[tempArray addObject:networking];
}
}
NSMutableArray * tempArray01 = [[NSMutableArray alloc] initWithArray:@[@"",@"",@"",@""]];
for (CNLiveNetworking * networking in tempArray) {
if (networking.tag == 1000) {
if (!networking.error) {
CNLiveCMineInteScoreModel * scoreModel = [CNLiveCMineInteScoreModel mj_objectWithKeyValues:networking.responseObject];
[tempArray01 replaceObjectAtIndex:0 withObject:scoreModel];
if ([scoreModel.status isEqualToString:@"1"]) [CNLiveCMineInteHeaderCustomView showWithScoreViewForScoreIntergal:scoreModel.score Statue:YES];
}
}
if (networking.tag == 1001) {
if (!networking.error) {
CNLiveCMineInteTaskListModel * listModel = [CNLiveCMineInteTaskListModel mj_objectWithKeyValues:networking.responseObject];
[tempArray01 replaceObjectAtIndex:1 withObject:listModel];
[CNLiveRespCacheManager cachePathWithObject:listModel FileName:NSStringFromClass(CNLiveCMineInteTaskListModel.class)];
}else{
[QMUITips showWithText:@"接口请求错误" inView:AppKeyWindow hideAfterDelay:1.5];
CNLiveCMineInteTaskListModel * listModel = (CNLiveCMineInteTaskListModel *)[CNLiveRespCacheManager objectCacheWithFileName:NSStringFromClass(CNLiveCMineInteTaskListModel.class)];
if (listModel) {
[tempArray01 replaceObjectAtIndex:1 withObject:listModel];
}
}
}
if (networking.tag == 1002) {
if (!networking.error) {
CNLiveCMineInteListModel * spListModel = [CNLiveCMineInteListModel mj_objectWithKeyValues:networking.responseObject];
[tempArray01 replaceObjectAtIndex:2 withObject:spListModel];
}
}
if (networking.tag == 1003) {
if (!networking.error) {
CNLiveCMineInteListModel * spListModel = [CNLiveCMineInteListModel mj_objectWithKeyValues:networking.responseObject];
if (spListModel.list.count == 0) {
NSMutableArray * tempArray = [[NSMutableArray alloc] init];
CNLiveCMineInteListSubModel * subModel = [[CNLiveCMineInteListSubModel alloc] init];
subModel.contentId = @"21";
subModel.poster = @"c_mine_content_item_task";
subModel.title = @"做任务";
subModel.subTitle = @"赚取更多积分";
subModel.isEmpty = @"1";
spListModel.list = tempArray;
}
[tempArray01 replaceObjectAtIndex:3 withObject:spListModel];
[CNLiveRespCacheManager cachePathWithObject:spListModel FileName:NSStringFromClass(CNLiveCMineInteListModel.class)];
}else{
CNLiveCMineInteListModel * spListModel = (CNLiveCMineInteListModel *)[CNLiveRespCacheManager objectCacheWithFileName:NSStringFromClass(CNLiveCMineInteListModel.class)];
if (!spListModel) {
spListModel = [[CNLiveCMineInteListModel alloc] init];
NSMutableArray * tempArray = [[NSMutableArray alloc] init];
CNLiveCMineInteListSubModel * subModel = [[CNLiveCMineInteListSubModel alloc] init];
subModel.contentId = @"21";
subModel.poster = @"c_mine_content_item_task";
subModel.title = @"做任务";
subModel.subTitle = @"赚取更多积分";
subModel.isEmpty = @"1";
[tempArray addObject:subModel];
spListModel.list = tempArray;
}
if (spListModel) {
[tempArray01 replaceObjectAtIndex:3 withObject:spListModel];
}
}
}
}
if (completerBlock) completerBlock(tempArray01,nil);
} @catch (NSException *exception) {
NSLog(@"异常了");
if (completerBlock) completerBlock(nil,@"获取失败");
}
}];
}
/// 获取积分明细(新)
/// @param currentMonth 时间格式 2021-12
/// @param currentType 1-全部 2-获取 3-支出
/// @param pageNo 页码(默认1)
/// @param completerBlock 结果返回
+(void)requestWithIntegraDetailWithCurrentMonth:(NSString *)currentMonth currentType:(NSInteger)currentType pageNo:(NSInteger)pageNo integralBlock:(nonnull void (^)(CNLiveCMineInteTaskListModel * _Nonnull, NSError * _Nonnull))integralBlock CompleterBlock:(void(^)(CNLiveCMineInteDetailModel *, NSArray *,NSError *))completerBlock
{
NSDictionary * param = @{
@"sid":[CNUserInfoManager manager].userInfoModel.uid
};
NSDictionary * paramDict = @{
@"sid":[CNUserInfoManager manager].userInfoModel.uid,
@"currentMonth":currentMonth,
@"type":[NSString stringWithFormat:@"%ld",currentType],
@"pageNo":[NSString stringWithFormat:@"%ld",pageNo],
@"pageSize":@"10"
};
[CNLiveNetworking setAllowRequestDefaultArgument:YES];
[CNLiveNetworking setupShowDataResult:YES];
[CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:cn_API_Host(@"/Daren/integral/integralRecordNew.action") Param:paramDict CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
CNLiveCMineInteDetailModel * listModel = [CNLiveCMineInteDetailModel mj_objectWithKeyValues:responseObject];
listModel.date_string = currentMonth;
NSMutableArray * tempArray = listModel.integralList.mutableCopy;
if (completerBlock) completerBlock(listModel,tempArray,error);
}];
[CNLiveNetworking setAllowRequestDefaultArgument:YES];
[CNLiveNetworking setupShowDataResult:YES];
[CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodGET URLString:cn_API_Host(@"/Daren/integral/getTasks.action") Param:param CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
if (!error) {
CNLiveCMineInteTaskListModel * listModel = [CNLiveCMineInteTaskListModel mj_objectWithKeyValues:responseObject];
if (integralBlock) {
integralBlock(listModel,error);
}
}
}];
}
@end