WithdrawalController.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. //
  2. // WithdrawalController.m
  3. // model
  4. //
  5. // Created by zuxiukuan on 2018/7/15.
  6. // Copyright © 2018年 Mine. All rights reserved.
  7. // 提现界面
  8. #import "WithdrawalController.h"
  9. #import "BindPhoneController.h"
  10. @interface WithdrawalController ()<UITextFieldDelegate>
  11. {
  12. NSString *amount;
  13. NSString *useAmount;
  14. NSString *name;
  15. NSString *account;
  16. }
  17. @property (nonatomic, strong) UILabel *moneyLabel;
  18. @property (nonatomic, strong) UILabel *totalMoneyLabel;
  19. @property (nonatomic, strong) UILabel *withdrawalLabel;
  20. @property (nonatomic, strong) UILabel *accountNameLabel;
  21. @property (nonatomic, strong) UILabel *phoneLabel;
  22. @property (nonatomic, strong) UITextField *priceTF; //提现金额
  23. @end
  24. @implementation WithdrawalController
  25. - (void)viewWillAppear:(BOOL)animated {
  26. [super viewWillAppear:animated];
  27. self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
  28. [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
  29. [self.navigationController.navigationBar setShadowImage:[UIImage new]];
  30. [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
  31. [self getDataFromNetworking];
  32. }
  33. - (void)viewWillDisappear:(BOOL)animated {
  34. [super viewWillDisappear:animated];
  35. self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
  36. [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
  37. [self.navigationController.navigationBar setShadowImage:nil];
  38. [self.navigationController.navigationBar setTitleTextAttributes:nil];
  39. }
  40. - (void)viewDidLoad {
  41. [super viewDidLoad];
  42. self.view.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
  43. //设置导航条
  44. [self creatNavBar];
  45. //设置子试图
  46. [self creatSubViews];
  47. }
  48. - (void)didReceiveMemoryWarning {
  49. [super didReceiveMemoryWarning];
  50. // Dispose of any resources that can be recreated.
  51. }
  52. - (void)creatNavBar {
  53. self.title = @"提现";
  54. //返回
  55. UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
  56. btn.frame = CGRectMake(0, 0, 40, 40);
  57. [btn setImage:[UIImage imageNamed:@"fanhui1"] forState:UIControlStateNormal];
  58. btn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
  59. [btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
  60. UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
  61. UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  62. // nagetiveSpacer.width = -12;//这个值可以根据自己需要自己调整
  63. self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftItem];
  64. }
  65. - (void)backClick {
  66. if (self.passBackAmount) {
  67. self.passBackAmount(amount);
  68. }
  69. [self.navigationController popViewControllerAnimated:YES];
  70. }
  71. - (void)creatSubViews {
  72. CGFloat headerHeight = (HeightStatusBar == 44) ? 277 : 233;
  73. UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, headerHeight)];
  74. UIImageView *bgView = [[UIImageView alloc] initWithFrame:headerView.bounds];
  75. [bgView setImage:[UIImage imageNamed:@"jianbianbeijing"]];
  76. [headerView addSubview:bgView];
  77. //
  78. UIImageView *verticalImageView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth / 2, headerHeight - 125, 1, 75)];
  79. verticalImageView.image = [UIImage imageNamed:@"shufenge"];
  80. [headerView addSubview:verticalImageView];
  81. //
  82. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, Height_NaviBar + 50, ScreenWidth/2, 14)];
  83. titleLabel.text = @"资产总额";
  84. titleLabel.textAlignment = NSTextAlignmentCenter;
  85. titleLabel.font = [UIFont systemFontOfSize:14];
  86. titleLabel.textColor = RGBValueColor(0xffffff, 1.0);
  87. [headerView addSubview:titleLabel];
  88. //
  89. self.moneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(titleLabel.frame) + 25, ScreenWidth/2, 30)];
  90. self.moneyLabel.textAlignment = NSTextAlignmentCenter;
  91. self.moneyLabel.textColor = RGBValueColor(0xffffff, 1.0);
  92. NSString *str = @"0元";
  93. NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:str];
  94. [attrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:NSMakeRange(0,str.length - 1)];
  95. [attrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(str.length - 1,1)];
  96. self.moneyLabel.attributedText = attrString;
  97. [headerView addSubview:self.moneyLabel];
  98. //
  99. UILabel *moneyTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(verticalImageView.frame), Height_NaviBar + 50, ScreenWidth/2, 14)];
  100. moneyTitleLabel.text = @"可提现";
  101. moneyTitleLabel.textAlignment = NSTextAlignmentCenter;
  102. moneyTitleLabel.font = [UIFont systemFontOfSize:14];
  103. moneyTitleLabel.textColor = RGBValueColor(0xffffff, 1.0);
  104. [headerView addSubview:moneyTitleLabel];
  105. //
  106. self.totalMoneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(verticalImageView.frame), CGRectGetMaxY(moneyTitleLabel.frame) + 25, ScreenWidth/2, 30)];
  107. self.totalMoneyLabel.textAlignment = NSTextAlignmentCenter;
  108. self.totalMoneyLabel.textColor = RGBValueColor(0xffffff, 1.0);
  109. NSString *str1 = @"0元";
  110. NSMutableAttributedString *attrString1 = [[NSMutableAttributedString alloc] initWithString:str1];
  111. [attrString1 addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:NSMakeRange(0,str1.length - 1)];
  112. [attrString1 addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(str1.length - 1,1)];
  113. self.totalMoneyLabel.attributedText = attrString1;
  114. [headerView addSubview:self.totalMoneyLabel];
  115. [self.view addSubview:headerView];
  116. // 白色背景 views
  117. UIImageView *whiteImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(headerView.frame) + 10, ScreenWidth, 163)];
  118. whiteImageView.userInteractionEnabled = YES;
  119. whiteImageView.image = [UIImage imageNamed:@"beisebeijing"];
  120. [self.view addSubview:whiteImageView];
  121. //我的提现账户
  122. UILabel *accountlabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, ScreenWidth / 2 - 20, 56)];
  123. accountlabel.textAlignment = NSTextAlignmentLeft;
  124. accountlabel.textColor = RGBValueColor(0x333333, 1.0);
  125. accountlabel.text = @"我的提现账户";
  126. accountlabel.font = [UIFont systemFontOfSize:16];
  127. [whiteImageView addSubview:accountlabel];
  128. //管理提现账户
  129. UILabel *managerAccountlabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth / 2, 0, ScreenWidth / 2 - 40, 56)];
  130. managerAccountlabel.textAlignment = NSTextAlignmentRight;
  131. managerAccountlabel.textColor = RGBValueColor(0x333333, 1.0);
  132. managerAccountlabel.text = @"管理提现账户";
  133. managerAccountlabel.font = [UIFont systemFontOfSize:16];
  134. [whiteImageView addSubview:managerAccountlabel];
  135. //右箭头
  136. UIImageView *arrowView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth - 28, 22.5, 8, 14)];
  137. arrowView.image = [UIImage imageNamed:@"youjiantou"];
  138. [whiteImageView addSubview:arrowView];
  139. UIButton *clickBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  140. clickBtn.frame = CGRectMake(ScreenWidth / 2, 0, ScreenWidth / 2, 56);
  141. [clickBtn addTarget:self action:@selector(clickBtn) forControlEvents:UIControlEventTouchUpInside];
  142. [whiteImageView addSubview:clickBtn];
  143. //分割线
  144. UIImageView *lineView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 56, ScreenWidth, 1)];
  145. lineView.image = [UIImage imageNamed:@"fengexian"];
  146. [whiteImageView addSubview:lineView];
  147. //提现账户(支付宝
  148. self.withdrawalLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(lineView.frame) + 17, ScreenWidth, 14)];
  149. self.withdrawalLabel.textAlignment = NSTextAlignmentLeft;
  150. self.withdrawalLabel.textColor = RGBValueColor(0x333333, 1.0);
  151. self.withdrawalLabel.font = [UIFont systemFontOfSize:14.0];
  152. self.withdrawalLabel.text = @"提现账户(支付宝)";
  153. [whiteImageView addSubview:self.withdrawalLabel];
  154. //账户姓名(支付宝)
  155. self.accountNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(self.withdrawalLabel.frame) + 17, ScreenWidth, 14)];
  156. self.accountNameLabel.textAlignment = NSTextAlignmentLeft;
  157. self.accountNameLabel.textColor = RGBValueColor(0x333333, 1.0);
  158. self.accountNameLabel.font = [UIFont systemFontOfSize:14.0];
  159. self.accountNameLabel.text = @"账户姓名(支付宝)";
  160. [whiteImageView addSubview:self.accountNameLabel];
  161. //未绑定手机
  162. self.phoneLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(self.accountNameLabel.frame) + 17, ScreenWidth, 14)];
  163. self.phoneLabel.textAlignment = NSTextAlignmentLeft;
  164. self.phoneLabel.textColor = RGBValueColor(0x999999, 1.0);
  165. self.phoneLabel.font = [UIFont systemFontOfSize:14.0];
  166. self.phoneLabel.text = @"未绑定支付宝";
  167. [whiteImageView addSubview:self.phoneLabel];
  168. //金额输入框背景
  169. UIImageView *amtBg = [[UIImageView alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(whiteImageView.frame) + 55, ScreenWidth - 40, 45)];
  170. amtBg.image = [UIImage imageNamed:@"chakan"];
  171. [self.view addSubview:amtBg];
  172. //金额输入框
  173. UITextField *priceTF = [[UITextField alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(whiteImageView.frame) + 64, ScreenWidth - 40, 30)];
  174. priceTF.textAlignment = NSTextAlignmentCenter;
  175. priceTF.keyboardType = UIKeyboardTypeDecimalPad;
  176. priceTF.font = [UIFont systemFontOfSize:16];
  177. priceTF.textColor = RGBValueColor(0x333333, 1.0);
  178. priceTF.placeholder = @"请输入提现金额";
  179. priceTF.tag = 1000;
  180. priceTF.delegate = self;
  181. [self.view addSubview:priceTF];
  182. self.priceTF = priceTF;
  183. //提现按钮
  184. UIButton *withdrawalBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  185. withdrawalBtn.frame = CGRectMake(20, CGRectGetMaxY(priceTF.frame) + 20, ScreenWidth - 40, 45);
  186. [withdrawalBtn setBackgroundImage:[UIImage imageNamed:@"tixian-1"] forState:UIControlStateNormal];
  187. [withdrawalBtn setTitle:@"提现" forState:UIControlStateNormal];
  188. [withdrawalBtn setTitleColor:RGBValueColor(0xffffff, 1.0) forState:UIControlStateNormal];
  189. [withdrawalBtn addTarget:self action:@selector(withdrawalBtnAction) forControlEvents:UIControlEventTouchUpInside];
  190. [self.view addSubview:withdrawalBtn];
  191. }
  192. #pragma mark -- 网络请求
  193. - (void)getDataFromNetworking {
  194. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  195. ModelUser *modelUser = [ModelUser user];
  196. NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:modelUser.modelpk,@"modelpk", nil];
  197. [YanCNetWorkManager requestPostWithURLStr:Url_alipayoutcashload(PublicUrl) parameters:dic finish:^(id dataDic) {
  198. [MBProgressHUD hideHUDForView:self.view animated:YES];
  199. NSString *issuccess = dataDic[@"msg"];
  200. if ([issuccess isEqualToString:@"success"]) {
  201. NSDictionary *dic = dataDic[@"data"];
  202. amount = dic[@"coin_a"];
  203. useAmount = dic[@"coin_use"];
  204. name = dic[@"name"];
  205. account = dic[@"alipayid"];
  206. [self updateUI];
  207. } else {
  208. [MBProgressHUD showInfo:@"请求失败!"];
  209. }
  210. } enError:^(NSError *error) {
  211. [MBProgressHUD hideHUDForView:self.view animated:YES];
  212. }];
  213. }
  214. #pragma mark -- 刷新界面
  215. -(void)updateUI{
  216. NSString *str = [NSString stringWithFormat:@"%@元",amount];
  217. NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:str];
  218. [attrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:NSMakeRange(0,str.length - 1)];
  219. [attrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(str.length - 1,1)];
  220. self.moneyLabel.attributedText = attrString;
  221. NSString *str1 = [NSString stringWithFormat:@"%@元",useAmount];
  222. NSMutableAttributedString *attrString1 = [[NSMutableAttributedString alloc] initWithString:str1];
  223. [attrString1 addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:NSMakeRange(0,str1.length - 1)];
  224. [attrString1 addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(str1.length - 1,1)];
  225. self.totalMoneyLabel.attributedText = attrString1;
  226. self.withdrawalLabel.text = [NSString stringWithFormat:@"提现账户(支付宝):%@",account];
  227. self.accountNameLabel.text = [NSString stringWithFormat:@"账户姓名(支付宝):%@",name];
  228. if (account.length>0 && name.length>0) {
  229. self.phoneLabel.hidden = YES;
  230. }else{
  231. self.phoneLabel.hidden = NO;
  232. }
  233. }
  234. #pragma mark -- 管理我的账户
  235. - (void)clickBtn {
  236. NSLog(@"管理我的账户");
  237. BindPhoneController *bindPhoneVC = [[BindPhoneController alloc] init];
  238. [self.navigationController pushViewController:bindPhoneVC animated:YES];
  239. }
  240. #pragma mark -- 提现
  241. - (void)withdrawalBtnAction {
  242. if (account.length == 0 || name.length == 0) {
  243. [MBProgressHUD showInfo:@"请先去绑定支付宝"];
  244. return;
  245. }
  246. if (self.priceTF.text.length == 0) {
  247. [MBProgressHUD showInfo:@"请输入提现金额"];
  248. return;
  249. }
  250. if ([self.priceTF.text doubleValue] > [useAmount doubleValue]) {
  251. [MBProgressHUD showInfo:@"提现金额不能大于可提现总额"];
  252. return;
  253. }
  254. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  255. ModelUser *modelUser = [ModelUser user];
  256. NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:modelUser.modelpk,@"modelpk",self.priceTF.text,@"fee", nil];
  257. [YanCNetWorkManager requestPostWithURLStr:Url_alipayoutcash(PublicUrl) parameters:dic finish:^(id dataDic) {
  258. [MBProgressHUD hideHUDForView:self.view animated:YES];
  259. NSString *issuccess = dataDic[@"msg"];
  260. if ([issuccess isEqualToString:@"success"]) {
  261. NSDictionary *dic = dataDic[@"data"];
  262. amount = dic[@"coin_a"];
  263. useAmount = dic[@"coin_use"];
  264. name = dic[@"name"];
  265. account = dic[@"alipayid"];
  266. [self updateUI];
  267. self.priceTF.text = @"";
  268. [MBProgressHUD showInfo:@"提现成功"];
  269. } else {
  270. [MBProgressHUD showInfo:@"提现失败!"];
  271. }
  272. } enError:^(NSError *error) {
  273. [MBProgressHUD hideHUDForView:self.view animated:YES];
  274. }];
  275. }
  276. #pragma mark ----- UITextFieldDelegate
  277. - (void)textFieldDidEndEditing:(UITextField *)textField {
  278. NSLog(@"textField.text = %@", textField.text);
  279. }
  280. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  281. if (textField.tag == 1000) {
  282. if(![self isValidAboutInputText:textField shouldChangeCharactersInRange:range replacementString:string decimalNumber:2]) {
  283. return NO;
  284. }
  285. }
  286. return YES;
  287. }
  288. //输入框中只能输入数字和小数点,且小数点只能输入一位,参数number 可以设置小数的位数,该函数在-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string调用;
  289. - (BOOL)isValidAboutInputText:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string decimalNumber:(NSInteger)number {
  290. NSScanner *scanner = [NSScanner scannerWithString:string];
  291. NSCharacterSet *numbers;
  292. NSRange pointRange = [textField.text rangeOfString:@"."];
  293. if ( (pointRange.length > 0) && (pointRange.location < range.location || pointRange.location > range.location + range.length) ){
  294. numbers = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
  295. }else{
  296. numbers = [NSCharacterSet characterSetWithCharactersInString:@"0123456789."];
  297. }
  298. if ( [textField.text isEqualToString:@""] && [string isEqualToString:@"."] ){
  299. return NO;
  300. }
  301. short remain = number; //保留 number位小数
  302. NSString *tempStr = [textField.text stringByAppendingString:string];
  303. NSUInteger strlen = [tempStr length];
  304. if(pointRange.length > 0 && pointRange.location > 0){ //判断输入框内是否含有“.”。
  305. if([string isEqualToString:@"."]){ //当输入框内已经含有“.”时,如果再输入“.”则被视为无效。
  306. return NO;
  307. }
  308. if(strlen > 0 && (strlen - pointRange.location) > remain+1){ //当输入框内已经含有“.”,当字符串长度减去小数点前面的字符串长度大于需要要保留的小数点位数,则视当次输入无效。
  309. return NO;
  310. }
  311. }
  312. NSRange zeroRange = [textField.text rangeOfString:@"0"];
  313. if(zeroRange.length == 1 && zeroRange.location == 0){ //判断输入框第一个字符是否为“0”
  314. if(![string isEqualToString:@"0"] && ![string isEqualToString:@"."] && [textField.text length] == 1){ //当输入框只有一个字符并且字符为“0”时,再输入不为“0”或者“.”的字符时,则将此输入替换输入框的这唯一字符。
  315. textField.text = string;
  316. return NO;
  317. }else{
  318. if(pointRange.length == 0 && pointRange.location > 0){ //当输入框第一个字符为“0”时,并且没有“.”字符时,如果当此输入的字符为“0”,则视当此输入无效。
  319. if([string isEqualToString:@"0"]){
  320. return NO;
  321. }
  322. }
  323. }
  324. }
  325. NSString *buffer;
  326. if ( ![scanner scanCharactersFromSet:numbers intoString:&buffer] && ([string length] != 0) ){
  327. return NO;
  328. }else{
  329. return YES;
  330. }
  331. }
  332. @end