vipBuyView.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. //
  2. // vipBuyView.m
  3. // live1v1
  4. //
  5. // Created by IOS1 on 2019/5/9.
  6. // Copyright © 2019 IOS1. All rights reserved.
  7. //
  8. #import "vipBuyView.h"
  9. #import "UIImage+RKImgCategory.h"
  10. #import "YBRechargeType.h"
  11. @interface vipBuyView(){
  12. NSMutableArray *paylist;
  13. NSArray *rules;
  14. UIActivityIndicatorView *testActivityIndicator;//菊花
  15. UIView *rulesView;
  16. UIView *payListView;
  17. NSMutableArray *payTypeArray;
  18. NSMutableArray *coinArray;
  19. UIButton *gopaybtn;
  20. UIView *payListBackView;
  21. NSString *payType;
  22. NSString *payHref;
  23. UILabel *getCoinL;
  24. UILabel *needMoneyL;
  25. }
  26. @property(nonatomic,strong)NSDictionary *seleDic;//选中的钻石字典
  27. //支付宝
  28. @property(nonatomic,copy)NSString *aliapp_key_ios;
  29. @property(nonatomic,copy)NSString *aliapp_partner;
  30. @property(nonatomic,copy)NSString *aliapp_seller_id;
  31. //微信
  32. @property(nonatomic,copy)NSString *wx_appid;
  33. @end
  34. @implementation vipBuyView
  35. - (instancetype)initWithMsg:(NSDictionary *)msg{
  36. if (self = [super init]) {
  37. self.frame = CGRectMake(0, 0, _window_width, _window_height);
  38. self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
  39. _aliapp_key_ios = [msg valueForKey:@"aliapp_key"];
  40. _aliapp_partner = [msg valueForKey:@"aliapp_partner"];
  41. _aliapp_seller_id = [msg valueForKey:@"aliapp_seller_id"];
  42. //微信的信息
  43. _wx_appid = [msg valueForKey:@"wx_appid"];
  44. paylist = [NSMutableArray array];
  45. // [paylist addObject:@{@"id":@"coin",@"name":@"余额支付"}];
  46. [paylist addObjectsFromArray:[msg valueForKey:@"paylist"]] ;
  47. rules = [msg valueForKey:@"vip_rules"];
  48. payTypeArray = [NSMutableArray array];
  49. coinArray = [NSMutableArray array];
  50. [self creatUI];
  51. }
  52. return self;
  53. }
  54. - (void)closebtnClick{
  55. [UIView animateWithDuration:0.2 animations:^{
  56. rulesView.y = _window_height;
  57. }completion:^(BOOL finished) {
  58. self.hidden = YES;
  59. }];
  60. }
  61. - (void)show{
  62. self.hidden = NO;
  63. [UIView animateWithDuration:0.2 animations:^{
  64. rulesView.y = _window_height-rulesView.height;
  65. }];
  66. }
  67. - (void)creatUI{
  68. CGFloat btnWidth;
  69. CGFloat btnSH = 0.0;
  70. btnWidth = 110;
  71. btnSH = 40;
  72. CGFloat speace = (_window_width-btnWidth*2)/3;
  73. NSInteger count = 0;
  74. if (rules.count % 2 == 0) {
  75. count = rules.count/2;
  76. }else{
  77. count = rules.count/2+1;
  78. }
  79. rulesView = [[UIView alloc]initWithFrame:CGRectMake(0, _window_height, _window_width, 140+(btnSH + 20)*count+ShowDiff)];
  80. rulesView.backgroundColor = [UIColor whiteColor];
  81. rulesView.layer.mask = [PublicObj setViewLeftTop:20 andRightTop:20 andView:rulesView];
  82. [self addSubview:rulesView];
  83. UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(rulesView.width/2-50, 20, 100, 20)];
  84. label.text = YZMsg(@"开通会员");
  85. label.font = [UIFont boldSystemFontOfSize:14];
  86. label.textColor = RGB_COLOR(@"#323232", 1);
  87. label.textAlignment = NSTextAlignmentCenter;
  88. [rulesView addSubview:label];
  89. UIButton *closeBtn = [UIButton buttonWithType:0];
  90. closeBtn.frame = CGRectMake(rulesView.width-52, 10, 40, 40);
  91. [closeBtn setImage:[UIImage imageNamed:@"screen_close"] forState:0];
  92. closeBtn.imageEdgeInsets = UIEdgeInsetsMake(12, 12, 12, 12);
  93. [closeBtn addTarget:self action:@selector(closebtnClick) forControlEvents:UIControlEventTouchUpInside];
  94. [rulesView addSubview:closeBtn];
  95. for (int j = 0; j < rules.count; j++) {
  96. UIButton *btn = [UIButton buttonWithType:0];
  97. btn.frame = CGRectMake(speace+j%2 * (btnWidth+speace), 60+(j/2)*(btnSH + 20), btnWidth, btnSH);
  98. [btn addTarget:self action:@selector(coinBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  99. btn.clipsToBounds = YES;
  100. btn.layer.cornerRadius = 5;
  101. btn.layer.masksToBounds = YES;
  102. btn.tag = 2000+j;
  103. btn.titleLabel.font = SYS_Font(13);
  104. [btn setTitle:minstr([rules[j] valueForKey:@"name"]) forState:0];
  105. if (![lagType isEqual:ZH_CN]) {
  106. [btn setTitle:minstr([rules[j] valueForKey:@"name_en"]) forState:0];
  107. }
  108. [rulesView addSubview:btn];
  109. if (j == 0) {
  110. [btn setBackgroundColor:RGB_COLOR(@"#e5c79b", 1)];
  111. [btn setTitleColor:RGB_COLOR(@"#8c6936", 1) forState:0];
  112. }else{
  113. [btn setBackgroundColor:RGB_COLOR(@"#fafafa", 1)];
  114. [btn setTitleColor:RGB_COLOR(@"#969696", 1) forState:0];
  115. }
  116. [coinArray addObject:btn];
  117. }
  118. _seleDic = rules[0];
  119. gopaybtn = [UIButton buttonWithType:0];
  120. gopaybtn.frame = CGRectMake(_window_width *0.1, rulesView.height-ShowDiff-50, _window_width*0.8, 40);
  121. gopaybtn.userInteractionEnabled = YES;
  122. [gopaybtn setBackgroundImage:[UIImage rk_gradientColorImageFromColors:@[RGB_COLOR(@"#f1d7b2", 1),RGB_COLOR(@"#e0b77a", 1)] gradientType:RKGradientTypeLeftToRight imgSize:gopaybtn.size]];
  123. gopaybtn.titleLabel.font = SYS_Font(15);
  124. [gopaybtn setTitle:YZMsg(@"立即开通") forState:0];
  125. [gopaybtn setTitleColor:RGB_COLOR(@"#8c6936", 1) forState:0];
  126. [gopaybtn addTarget:self action:@selector(gopaybtnClick) forControlEvents:UIControlEventTouchUpInside];
  127. gopaybtn.layer.cornerRadius = 20.0;
  128. gopaybtn.layer.masksToBounds = YES;
  129. [rulesView addSubview:gopaybtn];
  130. needMoneyL = [[UILabel alloc]initWithFrame:CGRectMake(speace, gopaybtn.top-40, 260, 40)];
  131. needMoneyL.font = SYS_Font(13);
  132. needMoneyL.textColor = RGB_COLOR(@"#323232", 1);//money_ios
  133. [needMoneyL setAttributedText:[self getAttstr:[NSString stringWithFormat:@"%@:%@%@ / ¥%@",YZMsg(@"金额"),minstr([_seleDic valueForKey:@"coin"]),[common name_coin],minstr([_seleDic valueForKey:@"money"])] andMoney:minstr([_seleDic valueForKey:@"money"])]];
  134. [rulesView addSubview:needMoneyL];
  135. }
  136. - (NSAttributedString *)getAttstr:(NSString *)str andMoney:(NSString *)money{
  137. NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:str];
  138. NSString *formatStr = YZMsg(@"金额");
  139. [string addAttributes:@{NSForegroundColorAttributeName:RGB_COLOR(@"#969696", 1)} range:NSMakeRange(0, formatStr.length)];
  140. [string addAttributes:@{NSForegroundColorAttributeName: [UIColor colorWithRed:255/255.0 green:0/255.0 blue:0/255.0 alpha:1.0]} range:NSMakeRange((str.length - money.length)-1, money.length+1)];
  141. return string;
  142. }
  143. - (void)coinBtnClick:(UIButton *)sender{
  144. for (UIButton *btn in coinArray) {
  145. if (btn == sender) {
  146. [btn setBackgroundColor:RGB_COLOR(@"#e5c79b", 1)];
  147. [btn setTitleColor:RGB_COLOR(@"#8c6936", 1) forState:0];
  148. }else{
  149. [btn setBackgroundColor:RGB_COLOR(@"#fafafa", 1)];
  150. [btn setTitleColor:RGB_COLOR(@"#969696", 1) forState:0];
  151. }
  152. }
  153. _seleDic = rules[sender.tag - 2000];
  154. [needMoneyL setAttributedText:[self getAttstr:[NSString stringWithFormat:@"%@:%@%@ / ¥%@",YZMsg(@"金额"),minstr([_seleDic valueForKey:@"coin"]),[common name_coin],minstr([_seleDic valueForKey:@"money"])] andMoney:minstr([_seleDic valueForKey:@"money"])]];
  155. }
  156. - (void)gopaybtnClick{
  157. if (paylist.count <= 0) {
  158. [MBProgressHUD showError:YZMsg(@"支付未开启")];
  159. return;
  160. }
  161. if (payListBackView) {
  162. [payListBackView removeFromSuperview];
  163. payListBackView = nil;
  164. }
  165. if (!payListBackView) {
  166. payType = minstr([paylist[0] valueForKey:@"id"]);
  167. payHref = minstr([paylist[0] valueForKey:@"href"]);
  168. payListBackView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _window_width, _window_height)];
  169. payListBackView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
  170. [self addSubview:payListBackView];
  171. payListView = [[UIView alloc]initWithFrame:CGRectMake(_window_width*0.1, _window_height, _window_width*0.8, 150+paylist.count * 50)];
  172. payListView.backgroundColor = [UIColor whiteColor];
  173. payListView.layer.cornerRadius = 20;
  174. payListView.layer.masksToBounds = YES;
  175. [payListBackView addSubview:payListView];
  176. UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(payListView.width/2-80, 10, 160, 20)];
  177. label.text = YZMsg(@"支付方式");
  178. label.font = [UIFont boldSystemFontOfSize:14];
  179. label.textColor = RGB_COLOR(@"#323232", 1);
  180. label.textAlignment = NSTextAlignmentCenter;
  181. [payListView addSubview:label];
  182. UIButton *closeBtn = [UIButton buttonWithType:0];
  183. closeBtn.frame = CGRectMake(payListView.width-52, 0, 40, 40);
  184. [closeBtn setImage:[UIImage imageNamed:@"screen_close"] forState:0];
  185. closeBtn.imageEdgeInsets = UIEdgeInsetsMake(12, 12, 12, 12);
  186. [closeBtn addTarget:self action:@selector(listClosebtnClick) forControlEvents:UIControlEventTouchUpInside];
  187. [payListView addSubview:closeBtn];
  188. UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(payListView.width/2-80, 40, 160, 20)];
  189. label2.text = [NSString stringWithFormat:@"%@%@%@",YZMsg(@"购买"),minstr([_seleDic valueForKey:@"name"]),YZMsg(@"会员")];
  190. if (![lagType isEqual:ZH_CN]) {
  191. label2.text = [NSString stringWithFormat:@"%@%@%@",YZMsg(@"购买"),minstr([_seleDic valueForKey:@"name_en"]),YZMsg(@"会员")];
  192. }
  193. label2.font = SYS_Font(11);
  194. label2.textColor = RGB_COLOR(@"#969696", 1);
  195. label2.textAlignment = NSTextAlignmentCenter;
  196. [payListView addSubview:label2];
  197. getCoinL = [[UILabel alloc]initWithFrame:CGRectMake(0, 65, payListView.width, 25)];
  198. getCoinL.attributedText = [self getAtt];
  199. getCoinL.textAlignment = NSTextAlignmentCenter;
  200. [payListView addSubview:getCoinL];
  201. for (int i = 0; i < paylist.count; i ++) {
  202. UIButton *btn = [UIButton buttonWithType:0];
  203. btn.frame = CGRectMake(40, i * 50 + 90, payListView.width-80, 50);
  204. btn.tag = 4000+i;
  205. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  206. [payListView addSubview:btn];
  207. UIImageView *imgV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 17, 16, 16)];
  208. // if (i == 0) {
  209. // imgV.image = [UIImage imageNamed:@"coin_Icon"];
  210. // }else{
  211. [imgV sd_setImageWithURL:[NSURL URLWithString:minstr([paylist[i] valueForKey:@"thumb"])]];
  212. // }
  213. [btn addSubview:imgV];
  214. UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(imgV.right+5, imgV.top, 160, 16)];
  215. lable.text = minstr([paylist[i] valueForKey:@"name"]);
  216. lable.textColor = RGB_COLOR(@"#404040", 1);
  217. lable.font = SYS_Font(14);
  218. [btn addSubview:lable];
  219. UIImageView *rightImgV = [[UIImageView alloc]initWithFrame:CGRectMake(btn.width-20, 17.5, 20, 15)];
  220. [btn addSubview:rightImgV];
  221. rightImgV.tag = btn.tag+1000;
  222. if (i == 0) {
  223. rightImgV.image = [UIImage imageNamed:@"支付选中"];
  224. }
  225. [payTypeArray addObject:rightImgV];
  226. [PublicObj lineViewWithFrame:CGRectMake(0, 49, btn.width, 1) andColor:RGB_COLOR(@"#f0f0f0", 1) andView:btn];
  227. }
  228. UIButton *btn = [UIButton buttonWithType:0];
  229. btn.frame = CGRectMake(0, 90+paylist.count*50+10, payListView.width, 40);
  230. [btn setTitle:YZMsg(@"立即支付") forState:0];
  231. [btn setTitleColor:RGB_COLOR(@"#9d8055", 1) forState:0];
  232. btn.titleLabel.font = [UIFont boldSystemFontOfSize:15];
  233. [btn addTarget:self action:@selector(goPayMoney) forControlEvents:UIControlEventTouchUpInside];
  234. [payListView addSubview:btn];
  235. }
  236. payListBackView.hidden = NO;
  237. [UIView animateWithDuration:0.2 animations:^{
  238. payListView.center = payListBackView.center;
  239. }];
  240. }
  241. - (NSAttributedString *)getAtt{
  242. NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@",minstr([_seleDic valueForKey:@"coin"]),[common name_coin]] attributes:@{NSFontAttributeName:SYS_Font(20),NSForegroundColorAttributeName: RGB_COLOR(@"#323232", 1)}];
  243. [string addAttributes:@{NSFontAttributeName:SYS_Font(15)} range:NSMakeRange(minstr([_seleDic valueForKey:@"coin"]).length, [common name_coin].length)];
  244. //money_ios
  245. NSMutableAttributedString *string2 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" / ¥%@",minstr([_seleDic valueForKey:@"money"])] attributes:@{NSFontAttributeName:SYS_Font(20),NSForegroundColorAttributeName: RGB_COLOR(@"#323232", 1)}];
  246. [string2 addAttributes:@{NSForegroundColorAttributeName: [UIColor colorWithRed:255/255.0 green:0/255.0 blue:0/255.0 alpha:1.0]} range:NSMakeRange(3, minstr([_seleDic valueForKey:@"money"]).length+1)];
  247. [string appendAttributedString:string2];
  248. return string;
  249. }
  250. - (void)listClosebtnClick{
  251. [UIView animateWithDuration:0.2 animations:^{
  252. payListView.y = _window_height;
  253. }completion:^(BOOL finished) {
  254. payListBackView.hidden = YES;
  255. }];
  256. }
  257. - (void)btnClick:(UIButton *)sender{
  258. payType = minstr([paylist[sender.tag-4000] valueForKey:@"id"]);
  259. payHref = minstr([paylist[sender.tag-4000] valueForKey:@"href"]);
  260. UIImageView *imageView = (UIImageView *)[sender viewWithTag:sender.tag + 1000];
  261. for (UIImageView *img in payTypeArray) {
  262. if (imageView == img) {
  263. img.image = [UIImage imageNamed:@"支付选中"];
  264. }else{
  265. img.image = [UIImage new];
  266. }
  267. }
  268. }
  269. - (void)goPayMoney{
  270. if (payHref.length>6) {
  271. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:minstr(payHref)]];
  272. }else {
  273. NSDictionary *payPostDic = @{ @"chargeid":[_seleDic valueForKey:@"id"],
  274. @"days":[_seleDic valueForKey:@"days"],
  275. @"money":[_seleDic valueForKey:@"money"],//money_ios
  276. @"coin":[_seleDic valueForKey:@"coin"],
  277. };
  278. YBWeakSelf;
  279. if ([payType isEqual:@"ali"]) {
  280. //支付宝
  281. [YBRechargeType chargeManeger].aliPayKey = _aliapp_key_ios;
  282. [YBRechargeType chargeManeger].aliPayPartner = _aliapp_partner;
  283. [YBRechargeType chargeManeger].aliPaySellerID = _aliapp_seller_id;
  284. [YBRechargeType chargeManeger].aliCallBackUrl = [h5url stringByAppendingString:@"/appapi/vipback/notify_ali"];
  285. [[YBRechargeType chargeManeger]selAliPayUrl:@"Vipcharge.getAliOrder" andParameter:payPostDic complete:^(int stateCode, int payType, NSString *msg) {
  286. dispatch_async(dispatch_get_main_queue(), ^{
  287. if (stateCode == 0) {
  288. [weakSelf paySuc];
  289. }else{
  290. [weakSelf payFail];
  291. }
  292. });
  293. }];
  294. }
  295. if ([payType isEqual:@"wx"]) {
  296. //微信
  297. [YBRechargeType chargeManeger].wechatAppID = _wx_appid;
  298. [[YBRechargeType chargeManeger]selWechatPayUrl:@"Vipcharge.getWxOrder" andParameter:payPostDic complete:^(int stateCode, int payType, NSString *msg) {
  299. dispatch_async(dispatch_get_main_queue(), ^{
  300. if (stateCode == 0) {
  301. [weakSelf paySuc];
  302. }else{
  303. [weakSelf payFail];
  304. }
  305. });
  306. }];
  307. }
  308. /*rk_20-6-23充值vip不能使用苹果
  309. if ([payType isEqual:@"apple"]) {
  310. //苹果
  311. [YBRechargeType chargeManeger].productID = minstr([_seleDic valueForKey:@"product_id"]);
  312. [YBRechargeType chargeManeger].appleCallBackUrl = [h5url stringByAppendingFormat:@"/Appapi/Vipback/notify_ios"];
  313. [[YBRechargeType chargeManeger]selApplePayUrl:@"Vipcharge.getIosOrder" andParameter:payPostDic complete:^(int stateCode, int payType, NSString *msg) {
  314. dispatch_async(dispatch_get_main_queue(), ^{
  315. if (stateCode == 0) {
  316. [weakSelf paySuc];
  317. }else{
  318. [weakSelf payFail];
  319. }
  320. });
  321. }];
  322. }
  323. */
  324. if ([payType isEqual:@"balance"]) {
  325. //余额支付
  326. [self doCoinPay];
  327. }
  328. if ([payType isEqual:@"paypal"]) {
  329. [[YBRechargeType chargeManeger]selPayPalAndPatameter:payPostDic rechargeType:rechargeType_Vip complete:^(int stateCode, int payType, NSString *msg) {
  330. dispatch_async(dispatch_get_main_queue(), ^{
  331. if (stateCode == 0) {
  332. [weakSelf paySuc];
  333. }else{
  334. [weakSelf payFail];
  335. }
  336. });
  337. }];
  338. }
  339. }
  340. }
  341. -(void)paySuc {
  342. if (self.block) {
  343. self.block();
  344. }
  345. [self listClosebtnClick];
  346. [self closebtnClick];
  347. }
  348. -(void)payFail{
  349. [self listClosebtnClick];
  350. [self closebtnClick];
  351. }
  352. - (void)doCoinPay{
  353. [MBProgressHUD showMessage:@""];
  354. NSDictionary *subdic = @{
  355. @"chargeid":[_seleDic valueForKey:@"id"],
  356. @"days":[_seleDic valueForKey:@"days"],
  357. @"coin":[_seleDic valueForKey:@"coin"]
  358. };
  359. YBWeakSelf;
  360. [YBNetworking postWithUrl:@"Vipcharge.balancePay" Dic:subdic Suc:^(int code, id info, NSString *msg) {
  361. [MBProgressHUD hideHUD];
  362. if (code == 0) {
  363. [MBProgressHUD showError:YZMsg(@"支付成功")];
  364. [weakSelf paySuc];
  365. }else{
  366. [MBProgressHUD showError:msg];
  367. [weakSelf payFail];
  368. }
  369. } Fail:^(id fail) {
  370. [MBProgressHUD hideHUD];
  371. }];
  372. }
  373. /*
  374. // Only override drawRect: if you perform custom drawing.
  375. // An empty implementation adversely affects performance during animation.
  376. - (void)drawRect:(CGRect)rect {
  377. // Drawing code
  378. }
  379. */
  380. @end