WithdrawalController.m 18 KB

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