// // WithdrawRecordsViewController.m // ShenQi // // Created by Yao on 2024/11/9. // #import "WithdrawRecordsViewController.h" #import "WithdrawRecordTableViewCell.h" #import "DataModels.h" #import "MacroDefine.h" #import "InviteRecordsTableViewCell.h" #import "AppDelegate.h" #import #import #import #import @interface WithdrawRecordsViewController () @property (weak, nonatomic) IBOutlet UILabel *titleLabel; @property (weak, nonatomic) IBOutlet UITableView *recordTableView; @property (weak, nonatomic) IBOutlet UILabel *emptyLabel; @property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator; @property (nonatomic, assign) NSInteger page; @property (nonatomic, strong) NSMutableArray *recordsArray; @property (nonatomic, strong) NSString *inviteCode; @end static NSString *identifier = @"WithdrawRecordTableViewCell"; @implementation WithdrawRecordsViewController - (void)viewDidLoad { [super viewDidLoad]; self.titleLabel.text = NSLocalizedString(@"WithdrawRecord", nil); self.recordTableView.delegate = self; self.recordTableView.dataSource = self; self.recordTableView.rowHeight = 70; self.recordTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ self.page = 1; self.recordsArray = @[].mutableCopy; [self refreshWithdrawRecords]; }]; [self.recordTableView registerNib:[UINib nibWithNibName:@"WithdrawRecordTableViewCell" bundle:nil] forCellReuseIdentifier:identifier]; self.recordTableView.tableFooterView = [UIView new]; self.page = 1; self.recordsArray = @[].mutableCopy; [self setupInviteCode]; } - (IBAction)dismissAction:(id)sender { [self dismissViewControllerAnimated:YES completion:nil]; } -(void)refreshWithdrawRecords { NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?inviteCode=%@&page=%@&size=%@",WithdrawURL,self.inviteCode,[NSNumber numberWithInteger:self.page],[NSNumber numberWithInteger:20]]]]; request.HTTPMethod = @"GET"; [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; NSURLSession *session = [NSURLSession sharedSession]; NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { dispatch_async(dispatch_get_main_queue(), ^{ if (error) { [SVProgressHUD showInfoWithStatus:error.localizedDescription]; }else{ NSError *error; NSMutableDictionary *responseObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error]; if (error) { [SVProgressHUD showInfoWithStatus:error.localizedDescription]; }else{ if (ISNULL(error) && !ISNULL(responseObject) && [[responseObject objectForKey:@"code"] integerValue] == 1) { WithdrawRecordDataModel *model = [[WithdrawRecordDataModel alloc] initWithDictionary:responseObject]; if (model.data.list.count < 20) { self.recordTableView.mj_footer = nil; }else if (model.data.list.count == 20) { self.recordTableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{ self.page++; [self refreshWithdrawRecords]; }]; } if (!ISNULLARRAY(model.data.list)) { [self.recordsArray addObjectsFromArray:model.data.list]; } } } } if (ISNULLARRAY(self.recordsArray)) { self.emptyLabel.hidden = NO; }else{ self.emptyLabel.hidden = YES; } [self.activityIndicator stopAnimating]; [self.recordTableView reloadData]; [self.recordTableView.mj_header endRefreshing]; [self.recordTableView.mj_footer endRefreshing]; }); }]; [dataTask resume]; } -(void)setupInviteCode { // 我的邀请码 __block NSString *advertisingId = nil; AppDelegate *appdelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; if (ISNULLSTR(appdelegate.inviteCode)) { if (@available(iOS 14, *)) { [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) { advertisingId = [[ASIdentifierManager sharedManager] advertisingIdentifier].UUIDString; [self getCodeWithAdvertisingId:advertisingId]; }]; } else { advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]; [self getCodeWithAdvertisingId:advertisingId]; } }else{ self.inviteCode = appdelegate.inviteCode; [self refreshWithdrawRecords]; } } -(void)getCodeWithAdvertisingId:(NSString *)advertisingId { NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:InviteCodeURL]]; request.HTTPMethod = @"POST"; [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; NSDictionary *parmas = @{@"userId":[NSNumber numberWithInteger:[VV88AUUserID integerValue]],@"deviceCode":advertisingId}; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:parmas options:NSJSONWritingPrettyPrinted error:nil]; request.HTTPBody = jsonData; NSURLSession *session = [NSURLSession sharedSession]; NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { dispatch_async(dispatch_get_main_queue(), ^{ if (error == nil) { NSError *error; NSMutableDictionary *responseObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error]; if (error == nil) { if (ISNULL(error) && !ISNULL(responseObject) && [[responseObject objectForKey:@"code"] integerValue] == 1) { InviteCodeModelDataModel *model = [[InviteCodeModelDataModel alloc] initWithDictionary:responseObject]; self.inviteCode = model.data.inviteCode; [self refreshWithdrawRecords]; } } } }); }]; [dataTask resume]; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.recordsArray.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { WithdrawRecordTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; WithdrawRecordList *list = [self.recordsArray objectAtIndex:indexPath.row]; cell.list = list; return cell; } @end