create
This commit is contained in:
206
ShenQi/WithdrawViewController.m
Normal file
206
ShenQi/WithdrawViewController.m
Normal file
@@ -0,0 +1,206 @@
|
||||
//
|
||||
// WithdrawViewController.m
|
||||
// ShenQi
|
||||
//
|
||||
// Created by Yao on 2024/11/9.
|
||||
//
|
||||
|
||||
#import "WithdrawViewController.h"
|
||||
|
||||
#import "DataModels.h"
|
||||
#import "MacroDefine.h"
|
||||
#import "InviteRecordsTableViewCell.h"
|
||||
#import "AppDelegate.h"
|
||||
|
||||
#import "DSTextField.h"
|
||||
#import <MJRefresh.h>
|
||||
#import <SVProgressHUD.h>
|
||||
#import <AdSupport/AdSupport.h>
|
||||
#import <AppTrackingTransparency/AppTrackingTransparency.h>
|
||||
|
||||
#import "WithdrawRecordsViewController.h"
|
||||
|
||||
@interface WithdrawViewController () <UITextFieldDelegate>
|
||||
|
||||
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
|
||||
@property (weak, nonatomic) IBOutlet UILabel *balanceLabel;
|
||||
@property (weak, nonatomic) IBOutlet UILabel *inputWithdrawLabel;
|
||||
@property (weak, nonatomic) IBOutlet DSTextField *withdrawTextField;
|
||||
@property (weak, nonatomic) IBOutlet UIButton *withdrawBtn;
|
||||
@property (weak, nonatomic) IBOutlet UIButton *withdrawRecordBtn;
|
||||
|
||||
@property (nonatomic, strong) NSString *inviteCode;
|
||||
@property (nonatomic, assign) CGFloat balance;
|
||||
|
||||
@end
|
||||
|
||||
@implementation WithdrawViewController
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
||||
self.titleLabel.text = NSLocalizedString(@"Withdraw", nil);
|
||||
|
||||
self.balanceLabel.text = [NSString stringWithFormat:@"%@:",NSLocalizedString(@"Balance", nil)];
|
||||
self.inputWithdrawLabel.text = [NSString stringWithFormat:@"%@%@%@%@",NSLocalizedString(@"PLS", nil),NSLocalizedString(@"InputEdit", nil),NSLocalizedString(@"Withdraw", nil),NSLocalizedString(@"Amount", nil)];
|
||||
|
||||
self.withdrawTextField.delegate = self;
|
||||
self.withdrawTextField.placeHolderString = [NSString stringWithFormat:@"%@%@%@%@",NSLocalizedString(@"PLS", nil),NSLocalizedString(@"InputEdit", nil),NSLocalizedString(@"Withdraw", nil),NSLocalizedString(@"Amount", nil)];
|
||||
|
||||
self.withdrawBtn.layer.cornerRadius = 20.f;
|
||||
self.withdrawBtn.layer.masksToBounds = YES;
|
||||
[self.withdrawBtn setTitle:NSLocalizedString(@"OK", nil) forState:(UIControlStateNormal)];
|
||||
[self.withdrawBtn addTarget:self action:@selector(withdrawAction) forControlEvents:(UIControlEventTouchUpInside)];
|
||||
|
||||
[self.withdrawRecordBtn setTitle:NSLocalizedString(@"WithdrawRecord", nil) forState:(UIControlStateNormal)];
|
||||
[self.withdrawRecordBtn addTarget:self action:@selector(withdrawRecordAction) forControlEvents:(UIControlEventTouchUpInside)];
|
||||
|
||||
[self setupInviteCode];
|
||||
}
|
||||
|
||||
- (IBAction)dismissAction:(id)sender
|
||||
{
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
}
|
||||
|
||||
-(void)withdrawAction
|
||||
{
|
||||
NSString *amout = self.withdrawTextField.text;
|
||||
if ([amout floatValue] > 0) {
|
||||
if ([amout floatValue] > self.balance) {
|
||||
[SVProgressHUD showInfoWithStatus:[NSString stringWithFormat:@"%@%@",NSLocalizedString(@"OverCanWithdraw", nil),NSLocalizedString(@"Amount", nil)]];
|
||||
}else{
|
||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:WithdrawApplyURL]];
|
||||
request.HTTPMethod = @"POST";
|
||||
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
|
||||
|
||||
NSDictionary *parmas = @{@"amount":[NSNumber numberWithFloat:[amout floatValue]],@"inviteCode":self.inviteCode};
|
||||
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:parmas options:NSJSONWritingPrettyPrinted error:nil];
|
||||
request.HTTPBody = jsonData;
|
||||
|
||||
[SVProgressHUD show];
|
||||
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) {
|
||||
[SVProgressHUD showSuccessWithStatus:nil];
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
[self dismissAction:nil];
|
||||
});
|
||||
}else{
|
||||
[SVProgressHUD showInfoWithStatus:error.localizedDescription];
|
||||
}
|
||||
}else{
|
||||
NSString *errmsg = [responseObject objectForKey:@"error"];
|
||||
[SVProgressHUD showInfoWithStatus:errmsg];
|
||||
}
|
||||
}else{
|
||||
[SVProgressHUD showInfoWithStatus:error.localizedDescription];
|
||||
}
|
||||
});
|
||||
}];
|
||||
[dataTask resume];
|
||||
}
|
||||
}else{
|
||||
[SVProgressHUD showInfoWithStatus:[NSString stringWithFormat:@"%@%@%@%@",NSLocalizedString(@"PLS", nil),NSLocalizedString(@"InputEdit", nil),NSLocalizedString(@"Withdraw", nil),NSLocalizedString(@"Amount", nil)]];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)withdrawRecordAction
|
||||
{
|
||||
WithdrawRecordsViewController *withdrawRecordsViewController = [[WithdrawRecordsViewController alloc] initWithNibName:@"WithdrawRecordsViewController" bundle:nil];
|
||||
[self presentViewController:withdrawRecordsViewController animated:YES completion:nil];
|
||||
}
|
||||
|
||||
-(void)setupInviteCode
|
||||
{
|
||||
// 我的邀请码
|
||||
__block NSString *advertisingId = nil;
|
||||
AppDelegate *appdelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
-(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;
|
||||
AppDelegate *appdelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
||||
appdelegate.inviteCode = self.inviteCode;
|
||||
self.balance = model.data.balance;
|
||||
self.balanceLabel.text = [NSString stringWithFormat:@"%@:%.1f",NSLocalizedString(@"Balance", nil),self.balance];
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}];
|
||||
[dataTask resume];
|
||||
}
|
||||
|
||||
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
|
||||
{
|
||||
[self.view endEditing:YES];
|
||||
}
|
||||
|
||||
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
|
||||
{
|
||||
NSString *text = nil;
|
||||
if (range.location >= textField.text.length) {
|
||||
text = [textField.text stringByAppendingString:string];
|
||||
} else {
|
||||
text = [textField.text stringByReplacingCharactersInRange:range withString:string];
|
||||
}
|
||||
if ([string containsString:@"."]) {
|
||||
if ([textField.text containsString:@"."]) {
|
||||
return NO;
|
||||
}
|
||||
}else{
|
||||
if ([textField.text containsString:@"."] && ![string isEqualToString:@""]) {
|
||||
NSString *floatAmout = [textField.text componentsSeparatedByString:@"."].lastObject;
|
||||
if (floatAmout.length >= 2) {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
|
||||
{
|
||||
textField.clearButtonMode = UITextFieldViewModeAlways;
|
||||
return YES;
|
||||
}
|
||||
|
||||
-(void)textFieldDidEndEditing:(UITextField *)textField
|
||||
{
|
||||
textField.clearButtonMode = UITextFieldViewModeNever;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user