184 lines
8.1 KiB
Objective-C
184 lines
8.1 KiB
Objective-C
//
|
||
// InviteRecordsViewController.m
|
||
// ShenQi
|
||
//
|
||
// Created by Yao on 2024/11/12.
|
||
//
|
||
|
||
#import "InviteRecordsViewController.h"
|
||
|
||
#import "MacroDefine.h"
|
||
#import "InviteRecordsTableViewCell.h"
|
||
#import "AppDelegate.h"
|
||
#import "DataModels.h"
|
||
|
||
#import <MJRefresh.h>
|
||
#import <SVProgressHUD.h>
|
||
#import <AdSupport/AdSupport.h>
|
||
#import <AppTrackingTransparency/AppTrackingTransparency.h>
|
||
|
||
@interface InviteRecordsViewController () <UITableViewDelegate,UITableViewDataSource>
|
||
|
||
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
|
||
@property (weak, nonatomic) IBOutlet UILabel *balanceLabel;
|
||
@property (weak, nonatomic) IBOutlet UILabel *incomeLabel;
|
||
@property (weak, nonatomic) IBOutlet UITableView *recordsTableView;
|
||
@property (weak, nonatomic) IBOutlet UILabel *emptyLabel;
|
||
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator;
|
||
|
||
@property (nonatomic, strong) NSMutableArray *recordsArray;
|
||
@property (nonatomic, assign) NSInteger page;
|
||
|
||
@end
|
||
|
||
static NSString *identifier = @"InviteRecordsTableViewCell";
|
||
|
||
@implementation InviteRecordsViewController
|
||
|
||
- (void)viewDidLoad {
|
||
[super viewDidLoad];
|
||
|
||
self.titleLabel.text = NSLocalizedString(@"RECORDS", nil);
|
||
|
||
self.recordsTableView.delegate = self;
|
||
self.recordsTableView.dataSource = self;
|
||
self.recordsTableView.rowHeight = 50;
|
||
self.recordsTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
|
||
self.page = 1;
|
||
self.recordsArray = @[].mutableCopy;
|
||
[self setupInviteCode];
|
||
}];
|
||
[self.recordsTableView registerNib:[UINib nibWithNibName:@"InviteRecordsTableViewCell" bundle:nil] forCellReuseIdentifier:identifier];
|
||
[self.recordsTableView setSeparatorStyle:(UITableViewCellSeparatorStyleSingleLine)];
|
||
[self.recordsTableView setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
|
||
self.recordsTableView.tableFooterView = [UIView new];
|
||
|
||
self.page = 1;
|
||
self.recordsArray = @[].mutableCopy;
|
||
[self setupInviteCode];
|
||
}
|
||
|
||
- (IBAction)dismissAction:(id)sender
|
||
{
|
||
[self dismissViewControllerAnimated:YES completion:nil];
|
||
}
|
||
|
||
-(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{
|
||
advertisingId = appdelegate.inviteCode;
|
||
[self refreshInviteRecordsDataWithAdvertisingId:advertisingId];
|
||
}
|
||
}
|
||
|
||
-(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];
|
||
if (!ISNULLSTR(model.data.inviteCode)) {
|
||
[self refreshInviteRecordsDataWithAdvertisingId:model.data.inviteCode];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
});
|
||
}];
|
||
[dataTask resume];
|
||
}
|
||
|
||
-(void)refreshInviteRecordsDataWithAdvertisingId:(NSString *)advertisingId
|
||
{
|
||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?code=%@&page=%@&size=%@",InviteRecordsURL,advertisingId,[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) {
|
||
NSDictionary *datadic = [responseObject objectForKey:@"data"];
|
||
NSDictionary *inviteCodedic = [datadic objectForKey:@"inviteCode"];
|
||
CGFloat balance = [[inviteCodedic objectForKey:@"balance"] floatValue];
|
||
CGFloat income = [[inviteCodedic objectForKey:@"income"] floatValue];
|
||
// NSInteger inviteNum = [[inviteCodedic objectForKey:@"inviteNum"] integerValue];
|
||
self.balanceLabel.text = [NSString stringWithFormat:@"%@:%.1f",NSLocalizedString(@"Balance", nil),balance];
|
||
self.incomeLabel.text = [NSString stringWithFormat:@"%@:%.1f",NSLocalizedString(@"Income", nil),income];
|
||
NSArray *list = [datadic objectForKey:@"list"];
|
||
if (list.count < 20) {
|
||
self.recordsTableView.mj_footer = nil;
|
||
}else if (list.count == 20) {
|
||
self.recordsTableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
|
||
self.page++;
|
||
[self setupInviteCode];
|
||
}];
|
||
}
|
||
if (!ISNULLARRAY(list)) {
|
||
[self.recordsArray addObjectsFromArray:list];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (ISNULLARRAY(self.recordsArray)) {
|
||
self.emptyLabel.hidden = NO;
|
||
}else{
|
||
self.emptyLabel.hidden = YES;
|
||
}
|
||
[self.activityIndicator stopAnimating];
|
||
[self.recordsTableView reloadData];
|
||
[self.recordsTableView.mj_header endRefreshing];
|
||
[self.recordsTableView.mj_footer endRefreshing];
|
||
});
|
||
}];
|
||
[dataTask resume];
|
||
}
|
||
|
||
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
||
{
|
||
return self.recordsArray.count;
|
||
}
|
||
|
||
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
||
{
|
||
InviteRecordsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
|
||
cell.titleLabel.text = [self.recordsArray objectAtIndex:indexPath.row];
|
||
return cell;
|
||
}
|
||
|
||
@end
|