Commit 86cb2b7d84e1a0b55c3d435a7886e266b59546bd

Authored by zhangxiaowen
1 parent 8d4c92e9

no message

CNLiveBalanceModule/Classes/Controller/CNLiveBalanceController.m
... ... @@ -28,7 +28,6 @@
28 28 @end
29 29  
30 30 @implementation CNLiveBalanceController
31   -static const NSInteger timeValue = 1.5;
32 31 #pragma mark - 加载数据
33 32 - (void)loadData {
34 33 [CNLiveBalanceRequest getBalance:self.type ID:self.ID block:^(BOOL isSuccess, NSString * _Nonnull number) {
... ...
CNLiveBalanceModule/Classes/Controller/CNLiveMonthBillController.m
... ... @@ -19,12 +19,13 @@
19 19 #import "CNLiveCategory.h"
20 20 #import "CNLiveRefreshHeader.h"
21 21  
22   -#import "CNLiveTradingRecordModel.h"
23   -#import "CNLiveTradingRecordCell.h"
24 22 #import "CNLiveServices.h"
  23 +#import "CNLiveBalanceRequest.h"
25 24  
26 25 #import "CNLiveBalanceNavigationBar.h"
27 26 #import "CNLiveMonthBillView.h"
  27 +#import "CNLiveTradingRecordModel.h"
  28 +#import "CNLiveTradingRecordCell.h"
28 29  
29 30 @interface CNLiveMonthBillController ()<UITableViewDelegate, UITableViewDataSource,CNLiveBalanceNavigationBarDelegate,CNLiveMonthBillViewDelegate>
30 31 @property (nonatomic, strong) CNLiveBalanceNavigationBar *navigationBar;
... ... @@ -52,17 +53,7 @@ static const CGFloat height = 60;
52 53 }
53 54 #pragma mark - 加载数据
54 55 - (void)loadData {
55   - NSDictionary *params = @{@"appId":AppId,
56   - @"targetId":CNUserShareModel.uid?CNUserShareModel.uid:@"",
57   - //@"10504050"
58   - @"type":self.type,//0全部(默认) 1收入 2支出
59   - @"startTime":self.startTime?self.startTime:@"1575129600000",
60   - @"endTime":self.endTime?self.endTime:@"1577807999000",
61   - @"pageSize":[NSString stringWithFormat:@"%d",INT_MAX],
62   - @"pageNo":[NSString stringWithFormat:@"%ld", self.pageNo]
63   - };
64   - [CNLiveNetworking setAllowRequestDefaultArgument:YES];
65   - [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:CNGetTradingRecordUrl Param:params CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
  56 + [CNLiveBalanceRequest getTradingRecordWithType:self.type startTime:self.startTime endTime:self.endTime block:^(BOOL isSuccess, NSDictionary * _Nonnull data, NSError *error) {
66 57 [self.tableView.mj_header endRefreshing];
67 58 [self.tableView.mj_footer endRefreshing];
68 59  
... ... @@ -75,20 +66,14 @@ static const CGFloat height = 60;
75 66 return;
76 67 }
77 68  
78   - if (responseObject && [responseObject isKindOfClass:[NSDictionary class]] && responseObject[@"data"] && [responseObject[@"data"] isKindOfClass:[NSDictionary class]]) {
79   - NSString *errorCode = [NSString stringWithFormat:@"%@", responseObject[@"errorCode"]];
80   - NSDictionary *data = responseObject[@"data"];
  69 + if (isSuccess) {
81 70 CNLiveTradingRecordModel *model = [CNLiveTradingRecordModel mj_objectWithKeyValues:data];
82 71 if(self.pageNo == 1&&self.data.count > 0){
83 72 [self.data removeAllObjects];
84 73 }
85 74 [self.data addObjectsFromArray:model.list];
86 75 [self.tableView reloadData];
87   -
88   - }else{
89   -
90 76 }
91   -
92 77 }];
93 78  
94 79 }
... ...
CNLiveBalanceModule/Classes/Controller/CNLiveTradingRecordController.m
... ... @@ -18,13 +18,14 @@
18 18 #import "CNLiveCategory.h"
19 19 #import "CNLiveRefreshHeader.h"
20 20  
21   -#import "CNLiveTradingRecordModel.h"
22   -#import "CNLiveTradingRecordCell.h"
23 21 #import "CNLiveServices.h"
  22 +#import "CNLiveBalanceRequest.h"
24 23  
25 24 #import "CNLiveBalanceNavigationBar.h"
26 25 #import "CNLiveTradingRecordView.h"
27 26 #import "CNLiveMonthBillController.h" //月账单
  27 +#import "CNLiveTradingRecordModel.h"
  28 +#import "CNLiveTradingRecordCell.h"
28 29  
29 30 @interface CNLiveTradingRecordController ()<UITableViewDelegate, UITableViewDataSource,CNLiveBalanceNavigationBarDelegate,CNLiveTradingRecordViewDelegate>
30 31 @property (nonatomic, strong) CNLiveBalanceNavigationBar *navigationBar;
... ... @@ -45,16 +46,7 @@ static const CGFloat height = 80;
45 46  
46 47 #pragma mark - 加载数据
47 48 - (void)loadData {
48   - NSDictionary *params = @{@"appId":AppId,
49   - @"targetId":CNUserShareModel.uid?CNUserShareModel.uid:@"",
50   - @"type":@"0",//0全部(默认) 1收入 2支出
51   - @"startTime":self.startTime?self.startTime:@"1575129600000",
52   - @"endTime":self.endTime?self.endTime:@"1577807999000",
53   - @"pageSize":[NSString stringWithFormat:@"%d",INT_MAX],
54   - @"pageNo":[NSString stringWithFormat:@"%ld", self.pageNo]
55   - };
56   - [CNLiveNetworking setAllowRequestDefaultArgument:YES];
57   - [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:CNGetTradingRecordUrl Param:params CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
  49 + [CNLiveBalanceRequest getTradingRecordWithType:@"0" startTime:self.startTime endTime:self.endTime block:^(BOOL isSuccess, NSDictionary * _Nonnull data, NSError *error) {
58 50 [self.tableView.mj_header endRefreshing];
59 51 [self.tableView.mj_footer endRefreshing];
60 52  
... ... @@ -67,9 +59,7 @@ static const CGFloat height = 80;
67 59 return;
68 60 }
69 61  
70   - if (responseObject && [responseObject isKindOfClass:[NSDictionary class]] && responseObject[@"data"] && [responseObject[@"data"] isKindOfClass:[NSDictionary class]]) {
71   - NSString *errorCode = [NSString stringWithFormat:@"%@", responseObject[@"errorCode"]];
72   - NSDictionary *data = responseObject[@"data"];
  62 + if (isSuccess) {
73 63 CNLiveTradingRecordModel *model = [CNLiveTradingRecordModel mj_objectWithKeyValues:data];
74 64 if(self.pageNo == 1&&self.data.count > 0){
75 65 [self.data removeAllObjects];
... ... @@ -78,54 +68,8 @@ static const CGFloat height = 80;
78 68  
79 69 self.tradingRecordView.model = model;
80 70 [self.tableView reloadData];
81   -
82   - }else{
83   -
84 71 }
85   -
86 72 }];
87   -
88   -// [[HttpService service]sendRequestWithHttpMethod:E_HTTP_REQUEST_METHOD_POST URLPath:CNGetTradingRecordUrl parameters:params isCache:NO CheckParam:nil completionHandler:^(id data, NSError *error) {
89   -// if (error) {
90   -// NSLog(@"error:%@",error.localizedDescription);
91   -// [self.tableView.mj_header endRefreshing];
92   -// [self.tableView.mj_footer endRefreshing];
93   -// [self.dataArray removeAllObjects];
94   -// [self.tableView reloadData];
95   -// // [self showEmptyViewWithFrame:CGRectMake(0, kNavigationBarHeight+80, KScreenWidth, KScreenHeight-kNavigationBarHeight-80) image:[UIImage imageNamed:@"wufalianjie"] text:error.localizedDescription detailText:@"别紧张,试试看刷新页面~" buttonTitle:@" 重试 " buttonAction:@selector(refreshList)];
96   -// [self showEmptyViewWithImage:[UIImage imageNamed:@"wufalianjie"] text:error.localizedDescription detailText:@"别紧张,试试看刷新页面~" buttonTitle:@" 重试 " buttonAction:@selector(refreshList)];
97   -// [self setCNAPIErrorEmptyView];
98   -// self.emptyView.verticalOffset = -(kNavigationBarHeight+80);
99   -// // [QMUITips showError:error.localizedDescription inView:self.view hideAfterDelay:1.5];
100   -// return;
101   -// }
102   -// NSLog(@"data:%@",data);
103   -// if (refresh) {
104   -// _page = 1;
105   -// [self.dataArray removeAllObjects];
106   -// [self.tableView.mj_header endRefreshing];
107   -// } else {
108   -// [self.tableView.mj_footer endRefreshing];
109   -// }
110   -// _lastPage = [data[@"lastPage"] boolValue];
111   -// double defray = [data[@"defray"] doubleValue];
112   -// double income = [data[@"income"] doubleValue];
113   -// self.payLab.text = [NSString stringWithFormat:@"支出 ¥%.2f",defray];
114   -// self.incomeLab.text = [NSString stringWithFormat:@"收入 ¥%.2f",income];
115   -// if (data[@"list"] && [data[@"list"] isKindOfClass:[NSArray class]] && [NSArray arrayWithArray:data[@"list"]].count>0) {
116   -//
117   -// NSMutableArray *arrayM = [NSMutableArray array];
118   -// for (NSDictionary *dic in data[@"list"]) {
119   -// CNTradingRecordModel *model = [CNTradingRecordModel mj_objectWithKeyValues:dic];
120   -// [arrayM addObject:model];
121   -// }
122   -// self.dataArray = [self.dataArray arrayByAddingObjectsFromArray:arrayM].mutableCopy;
123   -// } else {
124   -// [self.dataArray removeAllObjects];
125   -// [self.tableView addSubview:self.noDataView];
126   -// }
127   -// [self.tableView reloadData];
128   -// }];
129 73  
130 74 }
131 75  
... ... @@ -144,9 +88,14 @@ static const CGFloat height = 80;
144 88 else {
145 89 self.automaticallyAdjustsScrollViewInsets = NO;
146 90 }
  91 + [self createSubViews];
  92 +
  93 + NSArray *times = [CNLiveBalanceRequest getMonthFirstAndLastDayWithDate:[NSDate date]];
  94 +
  95 + self.startTime = times.firstObject;
  96 + self.endTime = times.lastObject;
147 97 self.pageNo = 1;
148 98  
149   - [self createSubViews];
150 99 [self loadData];
151 100  
152 101 }
... ...
CNLiveBalanceModule/Classes/Model/CNLiveBalanceRequest.h
... ... @@ -10,12 +10,19 @@
10 10  
11 11 NS_ASSUME_NONNULL_BEGIN
12 12 typedef void(^GetBalanceBlock)(BOOL isSuccess, NSString *number);
  13 +typedef void(^GetTradingRecordBlock)(BOOL isSuccess, NSDictionary *data, NSError *error);
13 14  
14 15 @interface CNLiveBalanceRequest : NSObject
15 16  
16 17 // 获取余额
17 18 + (void)getBalance:(NSString *)type ID:(NSString *)ID block:(GetBalanceBlock)block;
18 19  
  20 +//
  21 ++ (void)getTradingRecordWithType:(NSString *)type startTime:(NSString *)startTime endTime:(NSString *)endTime block:(GetTradingRecordBlock)block;
  22 +
  23 ++ (NSArray *)getMonthFirstAndLastDayWithDate:(NSDate *)date;
  24 +
  25 +
19 26 @end
20 27  
21 28 NS_ASSUME_NONNULL_END
... ...
CNLiveBalanceModule/Classes/Model/CNLiveBalanceRequest.m
... ... @@ -9,6 +9,7 @@
9 9 #import "CNLiveBalanceRequest.h"
10 10 #import "CNLiveNetworking.h"
11 11 #import "CNLiveEnvironment.h"
  12 +#import "CNUserInfoManager.h"
12 13  
13 14 @implementation CNLiveBalanceRequest
14 15 #pragma mark - 获取余额
... ... @@ -34,4 +35,46 @@
34 35 }];
35 36 }
36 37  
  38 ++ (void)getTradingRecordWithType:(NSString *)type startTime:(NSString *)startTime endTime:(NSString *)endTime block:(GetTradingRecordBlock)block{
  39 + NSDictionary *params = @{@"appId":AppId,
  40 + @"targetId":CNUserShareModel.uid?CNUserShareModel.uid:@"",
  41 + @"type":type?type:@"0",//0全部(默认) 1收入 2支出
  42 + @"startTime":startTime?startTime:@"",
  43 + @"endTime":endTime?endTime:@"",
  44 + @"pageSize":[NSString stringWithFormat:@"%d",INT_MAX],
  45 + @"pageNo":[NSString stringWithFormat:@"%d", 1]
  46 + };
  47 + [CNLiveNetworking setAllowRequestDefaultArgument:YES];
  48 + [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:CNGetTradingRecordUrl Param:params CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
  49 + if (responseObject && [responseObject isKindOfClass:[NSDictionary class]] && responseObject[@"data"] && [responseObject[@"data"] isKindOfClass:[NSDictionary class]]) {
  50 + NSString *errorCode = [NSString stringWithFormat:@"%@", responseObject[@"errorCode"]];
  51 + NSDictionary *data = responseObject[@"data"];
  52 + block?block([errorCode isEqualToString:@"0"], data, error):@"";
  53 +
  54 + }else{
  55 + block?block(NO, nil, error):@"";
  56 +
  57 + }
  58 +
  59 + }];
  60 +
  61 +}
  62 +
  63 ++ (NSArray *)getMonthFirstAndLastDayWithDate:(NSDate *)date{
  64 + double interval = 0;
  65 + NSDate *firstDateOut = nil;
  66 + NSDate *lastDateOut = nil;
  67 + NSCalendar *calendar = [NSCalendar currentCalendar];
  68 + BOOL OK = [calendar rangeOfUnit:NSCalendarUnitMonth startDate:&firstDateOut interval:&interval forDate:date];
  69 + if (OK) {
  70 + lastDateOut = [firstDateOut dateByAddingTimeInterval:interval-1];
  71 + }else {
  72 + return @[@"",@""];
  73 + }
  74 + NSString *firstOutString = [NSString stringWithFormat:@"%ld", (long)[firstDateOut timeIntervalSince1970]*1000];
  75 + NSString *lastOutString = [NSString stringWithFormat:@"%ld", (long)[lastDateOut timeIntervalSince1970]*1000];
  76 + return @[firstOutString, lastOutString];
  77 +
  78 +}
  79 +
37 80 @end
... ...
CNLiveBalanceModule/Classes/View/CNLiveMonthBillView.m
... ... @@ -12,6 +12,7 @@
12 12 #import "CNLiveCategory.h"
13 13 #import "CNLiveBaseKit.h"
14 14 #import "PGDatePickManager.h"
  15 +#import "CNLiveBalanceRequest.h"
15 16  
16 17 @interface CNLiveMonthBillView ()<PGDatePickerDelegate>
17 18 @property (nonatomic, strong) QMUIButton *switchTime;
... ... @@ -95,31 +96,14 @@ static const NSInteger margin = 20;
95 96 NSString *value = [dateFormatter stringFromDate:date];
96 97 [_switchTime setTitle:value forState:UIControlStateNormal];
97 98  
98   - NSArray *timeArr = [self getMonthFirstAndLastDayWith:date];
99   - NSLog(@"%@",timeArr);
  99 + NSArray *times = [CNLiveBalanceRequest getMonthFirstAndLastDayWithDate:date];
  100 + NSLog(@"%@",times);
100 101 if (self.delegate && [self.delegate respondsToSelector:@selector(monthBillView:startTime:endTime:)]) {
101   - [self.delegate monthBillView:self startTime:timeArr.firstObject endTime:timeArr.lastObject];
  102 + [self.delegate monthBillView:self startTime:times.firstObject endTime:times.lastObject];
102 103 }
103 104  
104 105 }
105 106  
106   -- (NSArray *)getMonthFirstAndLastDayWith:(NSDate *)date{
107   - double interval = 0;
108   - NSDate *firstDateOut = nil;
109   - NSDate *lastDateOut = nil;
110   - NSCalendar *calendar = [NSCalendar currentCalendar];
111   - BOOL OK = [calendar rangeOfUnit:NSCalendarUnitMonth startDate:&firstDateOut interval:&interval forDate:date];
112   - if (OK) {
113   - lastDateOut = [firstDateOut dateByAddingTimeInterval:interval-1];
114   - }else {
115   - return @[@"",@""];
116   - }
117   - NSString *firstOutString = [NSString stringWithFormat:@"%ld", (long)[firstDateOut timeIntervalSince1970]*1000];
118   - NSString *lastOutString = [NSString stringWithFormat:@"%ld", (long)[lastDateOut timeIntervalSince1970]*1000];
119   - return @[firstOutString, lastOutString];
120   -
121   -}
122   -
123 107 /*
124 108 // Only override drawRect: if you perform custom drawing.
125 109 // An empty implementation adversely affects performance during animation.
... ...
CNLiveBalanceModule/Classes/View/CNLiveTradingRecordView.m
... ... @@ -12,6 +12,8 @@
12 12 #import "CNLiveCategory.h"
13 13 #import "CNLiveBaseKit.h"
14 14 #import "PGDatePickManager.h"
  15 +#import "CNLiveBalanceRequest.h"
  16 +
15 17 #import "CNLiveTradingRecordModel.h"
16 18  
17 19 @interface CNLiveTradingRecordView ()<PGDatePickerDelegate>
... ... @@ -71,7 +73,7 @@ static const NSInteger height = 30;
71 73 #pragma mark - PGDatePickerDelegate
72 74 - (void)datePicker:(PGDatePicker *)datePicker didSelectDate:(NSDateComponents *)dateComponents{
73 75 dateComponents.day = 1;
74   - NSCalendar * calendar = [NSCalendar currentCalendar];
  76 + NSCalendar *calendar = [NSCalendar currentCalendar];
75 77 NSDate *date = [calendar dateFromComponents:dateComponents];
76 78 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
77 79 [dateFormatter setLocale:[NSLocale currentLocale]];
... ... @@ -79,28 +81,11 @@ static const NSInteger height = 30;
79 81 NSString *value = [dateFormatter stringFromDate:date];
80 82 [_switchTime setTitle:value forState:UIControlStateNormal];
81 83  
82   - NSArray *timeArr = [self getMonthFirstAndLastDayWith:date];
83   - NSLog(@"%@",timeArr);
  84 + NSArray *times = [CNLiveBalanceRequest getMonthFirstAndLastDayWithDate:date];
  85 + NSLog(@"%@",times);
84 86 if (self.delegate && [self.delegate respondsToSelector:@selector(tradingRecordView:date:startTime:endTime:)]) {
85   - [self.delegate tradingRecordView:self date:value startTime:timeArr.firstObject endTime:timeArr.lastObject];
86   - }
87   -
88   -}
89   -
90   -- (NSArray *)getMonthFirstAndLastDayWith:(NSDate *)date{
91   - double interval = 0;
92   - NSDate *firstDateOut = nil;
93   - NSDate *lastDateOut = nil;
94   - NSCalendar *calendar = [NSCalendar currentCalendar];
95   - BOOL OK = [calendar rangeOfUnit:NSCalendarUnitMonth startDate:&firstDateOut interval:&interval forDate:date];
96   - if (OK) {
97   - lastDateOut = [firstDateOut dateByAddingTimeInterval:interval-1];
98   - }else {
99   - return @[@"",@""];
  87 + [self.delegate tradingRecordView:self date:value startTime:times.firstObject endTime:times.lastObject];
100 88 }
101   - NSString *firstOutString = [NSString stringWithFormat:@"%ld", (long)[firstDateOut timeIntervalSince1970]*1000];
102   - NSString *lastOutString = [NSString stringWithFormat:@"%ld", (long)[lastDateOut timeIntervalSince1970]*1000];
103   - return @[firstOutString, lastOutString];
104 89  
105 90 }
106 91  
... ...