BogoRechargeScrollView.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. //
  2. // BogoRechargeScrollView.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2021/4/8.
  6. // Copyright © 2021 xfg. All rights reserved.
  7. //
  8. #import "BogoRechargeScrollView.h"
  9. #import "BogoRechargeTopView.h"
  10. #import "BogoRechargePayMoneyCollection.h"
  11. #import "BogoRechargePayTypeCollection.h"
  12. @interface BogoRechargeScrollView ()
  13. @property(nonatomic, strong) BogoRechargeTopView *topView;
  14. @property(nonatomic, strong) BogoRechargePayMoneyCollection *payMoneyView;
  15. @property(nonatomic, strong) BogoRechargePayTypeCollection *payTypeView;
  16. @property(nonatomic, strong) NSMutableArray *listArr;
  17. @property(nonatomic, strong) NSMutableArray *rule_list;//支付金额列表
  18. @property(nonatomic, strong) UIButton *selectAgreeBtn;
  19. @property(nonatomic, strong) UIButton *agreeBtn;
  20. @property(nonatomic, strong) UIButton *payBtn;
  21. //弹窗需要
  22. @property(nonatomic, strong) UILabel *titleLabel;
  23. @property(nonatomic, strong) UIButton *closeBtn;
  24. @end
  25. @implementation BogoRechargeScrollView
  26. - (instancetype)initWithFrame:(CGRect)frame
  27. {
  28. self = [super initWithFrame:frame];
  29. if (self) {
  30. [self setUpView];
  31. [self loadRechargeData];
  32. }
  33. return self;
  34. }
  35. -(void)setUpView{
  36. self.backgroundColor = UIColor.clearColor;
  37. self.topView.frame = CGRectMake(0, 0, kScreenW, 145);
  38. [self addSubview:self.topView];
  39. [self addSubview:self.payMoneyView];
  40. [self addSubview:self.payTypeView];
  41. self.selectAgreeBtn.frame = CGRectMake(30, self.height - kRealValue(40) - 20, kRealValue(40), kRealValue(40));
  42. self.agreeBtn.frame = CGRectMake(self.selectAgreeBtn.right, self.selectAgreeBtn.top, kScreenW * 0.5, kRealValue(40));
  43. self.payBtn.frame = CGRectMake(62, self.agreeBtn.bottom, SCREEN_WIDTH - 124, kRealValue(45));
  44. [self addSubview:self.selectAgreeBtn];
  45. [self addSubview:self.agreeBtn];
  46. [self addSubview:self.payBtn];
  47. }
  48. -(void)resetViewFrame{
  49. if (self.isRecharge) {
  50. self.contentSize = CGSizeMake(0, kScreenH * 1.2);
  51. }else{
  52. self.topView.frame = CGRectMake(0, 0, kScreenW, kRealValue(60));
  53. self.topView.hidden = YES;
  54. [self addSubview:self.titleLabel];
  55. [self addSubview:self.closeBtn];
  56. self.contentSize = CGSizeMake(0, self.payBtn.bottom + kRealValue(20));
  57. }
  58. NSLog(@"ntSize.heig%f",self.contentSize.height);
  59. self.payMoneyView.top = self.topView.bottom;
  60. NSInteger count = 0;
  61. if (self.model.rule_list.count%3 > 0) {
  62. count = self.model.rule_list.count/3 + 1;
  63. } else {
  64. count = self.model.rule_list.count/3;
  65. }
  66. self.payMoneyView.height = kRealValue(40) + count * 90;
  67. self.payTypeView.top = self.payMoneyView.bottom;
  68. self.payTypeView.height = self.model.pay_list.count * kRealValue(60) + kRealValue(30);
  69. self.payBtn.top = self.payTypeView.bottom + kRealValue(20);
  70. self.selectAgreeBtn.top = self.payBtn.bottom + 30;
  71. self.agreeBtn.top = self.selectAgreeBtn.top;
  72. // if (!self.isRecharge) {
  73. self.contentSize = CGSizeMake(0, self.agreeBtn.bottom + kRealValue(20));
  74. // }
  75. }
  76. - (void)loadRechargeData
  77. {
  78. self.listArr = [NSMutableArray array];
  79. self.rule_list = [NSMutableArray array];
  80. NSMutableDictionary * parmDict = [NSMutableDictionary dictionary];
  81. [parmDict setObject:@"pay" forKey:@"ctl"];
  82. [parmDict setObject:@"recharge" forKey:@"act"];
  83. FWWeakify(self)
  84. [[NetHttpsManager manager] POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  85. FWStrongify(self)
  86. [self.listArr removeAllObjects];
  87. [self.rule_list removeAllObjects];
  88. self.model = [AccountRechargeModel mj_objectWithKeyValues:responseJson];
  89. self.rule_list = [NSMutableArray arrayWithArray:self.model.rule_list];
  90. self.topView.numerLabel.text = [NSString stringWithFormat:@"%ld",self.model.diamonds];
  91. [self resetViewFrame];
  92. self.payMoneyView.model = self.model;
  93. self.payTypeView.model = self.model;
  94. //如果有其它金额充值方式,要在除苹果支付外的其它支付方式里面的每个支付方式列表里添加一个对应的model,添加的model用于表示其它金额支付
  95. if ([self.model.show_other integerValue] == 1)
  96. {
  97. for (int i=0; i<self.model.pay_list.count; ++i)
  98. {
  99. PayTypeModel * model = self.model.pay_list[i];
  100. if (![model.class_name isEqual:@"Iappay"])
  101. {
  102. PayMoneyModel * otherModel = [[PayMoneyModel alloc] init];
  103. otherModel.hasOtherPay = YES;
  104. if (model.rule_list.count>0)
  105. {
  106. [model.rule_list addObject:otherModel];
  107. self.model.pay_list[i] = model;
  108. }
  109. else
  110. {
  111. NSMutableArray * otherArray = [NSMutableArray arrayWithArray:self.model.rule_list];
  112. [otherArray addObject:otherModel];
  113. // self.otherPayArr = otherArray;
  114. break;
  115. }
  116. }
  117. }
  118. }
  119. // PayTypeModel * model = self.model.pay_list.firstObject;
  120. // if ([model.class_name isEqual:@"Iappay"] && self.model.pay_list.count == 1)
  121. // {
  122. // self.rechargeWayView.frame = CGRectMake(0, CGRectGetMaxY(self.rechargeBtn.frame), self.width, 0);
  123. // self.rechargeWayView.hidden = YES;
  124. // self.separateView.frame = CGRectMake(10, CGRectGetMaxY(self.rechargeWayView.frame)+20, self.width-20, 0.5);
  125. // }
  126. // else
  127. // {
  128. // self.rechargeWayView.frame = CGRectMake(0, CGRectGetMaxY(_selectLineView.frame) - kRealValue(5), self.width, 40);
  129. //
  130. // self.selectAgreeBtn.frame = CGRectMake(kRealValue(15), self.rechargeWayView.bottom + kRealValue(15), kRealValue(20), kRealValue(20));
  131. // self.agreeBtn.centerY = self.selectAgreeBtn.centerY;
  132. // self.agreeBtn.left = self.selectAgreeBtn.right;
  133. // self.rechargeWayView.hidden = NO;
  134. // self.separateView.frame = CGRectMake(10, _rechargeWayView.bottom + 35, self.width-20, 0.5);
  135. // }
  136. // self.listCollectionView.frame = CGRectMake(0, CGRectGetMaxY(self.separateView.frame), self.width, self.height-CGRectGetMaxY(_separateView.frame)-45);
  137. // if (self.model.pay_list.count>0)
  138. // {
  139. // PayTypeModel *model = [self.model.pay_list firstObject];
  140. // if ([self.model.show_other integerValue] == 1)
  141. // {
  142. // if (![model.class_name isEqual:@"Iappay"])
  143. // {
  144. // if (model.rule_list.count>0)
  145. // {
  146. // self.listArray = model.rule_list;
  147. // }
  148. // else
  149. // {
  150. // self.listArray = self.otherPayArr;
  151. // }
  152. // }
  153. // else
  154. // {
  155. // self.listArray = model.rule_list.count>0 ? model.rule_list: self.model.rule_list;
  156. // }
  157. // }
  158. // else
  159. // {
  160. // self.listArray = model.rule_list.count>0 ? model.rule_list: self.model.rule_list;
  161. // }
  162. // }
  163. // self.rechargeWayView.rechargeWayArr =self.model.pay_list;
  164. // [self.listCollectionView reloadData];
  165. // [self reloadView];
  166. } FailureBlock:^(NSError *error) {
  167. }];
  168. }
  169. - (void)updateDiamonds:(NSInteger)diamonds {
  170. self.topView.numerLabel.text = [NSString stringWithFormat:@"%ld",diamonds];
  171. }
  172. #pragma mark - 点击事件
  173. -(void)clickAgreenBtn:(UIButton *)sender{
  174. NSString *tmpUrlStr = [GlobalVariables sharedInstance].appModel.h5_url.url_recharge_agreement;
  175. BGMainWebViewController *tmpController = [BGMainWebViewController webControlerWithUrlStr:tmpUrlStr isShowIndicator:YES isShowNavBar:YES isShowBackBtn:YES isShowCloseBtn:NO];
  176. [[AppDelegate sharedAppDelegate] pushViewController:tmpController animated:YES];
  177. }
  178. -(void)clickSelectAgreenBtn:(UIButton *)sender{
  179. sender.selected = !sender.selected;
  180. }
  181. #pragma mark - 点击充值按钮
  182. -(void)clickPayBtn:(UIButton *)sender{
  183. if (!self.selectAgreeBtn.selected) {
  184. [FanweMessage alertHUD:ASLocalizedString(@"请先勾选是否同意用户充值免责协议")];
  185. return;
  186. }
  187. if (!self.payTypeView.selectModel) {
  188. [FanweMessage alertHUD:ASLocalizedString(@"请选择支付方式")];
  189. return;
  190. }
  191. if ([self.payTypeView.selectModel.class_name isEqualToString:@"Iappay"]) {
  192. [self payRequestNet:1];
  193. }else{
  194. [self payRequestNet:0];
  195. }
  196. }
  197. #pragma mark 支付请求
  198. //内购传rule_id,money
  199. //支付宝、微信传 pay_id 支付id,rule_id 充值规则id,money 价格
  200. - (void)payRequestNet:(int)indicate
  201. // wxPayNet:(int)wxIndicate
  202. {
  203. NSString *payID = [NSString stringWithFormat:@"%ld",self.payTypeView.selectModel.payWayID];
  204. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  205. [parmDict setObject:@"pay" forKey:@"ctl"];
  206. [parmDict setObject:@"pay" forKey:@"act"];
  207. [parmDict setObject:payID forKey:@"pay_id"];
  208. // if (wxIndicate == 1 && indicate < self.ruleListArr.count)
  209. // {
  210. if (indicate) {
  211. PayMoneyModel *model = self.payMoneyView.selectModel;
  212. // self.ruleListArr[indicate];
  213. [parmDict setObject:[NSString stringWithFormat:@"%ld",(long)model.payID] forKey:@"rule_id"];
  214. [parmDict setObject:[NSString stringWithFormat:@"%@",model.money] forKey:@"money"];
  215. }else{
  216. PayMoneyModel *model = self.payMoneyView.selectModel;
  217. // self.ruleListArr[indicate];
  218. [parmDict setObject:[NSString stringWithFormat:@"%ld",(long)model.payID] forKey:@"rule_id"];
  219. [parmDict setObject:[NSString stringWithFormat:@"%@",model.money] forKey:@"money"];
  220. }
  221. [SVProgressHUD show];
  222. [[NetHttpsManager manager] POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson){
  223. [SVProgressHUD dismiss];
  224. if ([responseJson toInt:@"status"]==1)
  225. {
  226. NSDictionary *payDic =[responseJson objectForKey:@"pay"];
  227. NSDictionary *sdkDic =[payDic objectForKey:@"sdk_code"];
  228. NSString *sdkType =[sdkDic objectForKey:@"pay_sdk_type"];
  229. if ([sdkType isEqualToString:@"alipay"])
  230. {
  231. //支付宝支付
  232. NSDictionary *configDic =[sdkDic objectForKey:@"config"];
  233. Pay_Model * model2 =[Pay_Model mj_objectWithKeyValues: configDic];
  234. NSString *orderString = [NSString stringWithFormat:@"%@&sign=\"%@\"&sign_type=\"%@\"",model2.order_spec, model2.sign, model2.sign_type];
  235. if (self.reDelegate && [self.reDelegate respondsToSelector:@selector(alipay:)]) {
  236. [self.reDelegate alipay:orderString];
  237. }
  238. // [self alipay:orderString block:nil];
  239. }
  240. // else if ([sdkType isEqualToString:@"wxpay"])
  241. // {
  242. // //微信支付
  243. // NSDictionary *configDic =[payDic objectForKey:@"config"];
  244. // NSDictionary *iosDic =[configDic objectForKey:@"ios"];
  245. // Mwxpay * wxmodel =[Mwxpay mj_objectWithKeyValues: iosDic];
  246. // PayReq* req = [[PayReq alloc] init];
  247. // req.openID = wxmodel.appid;
  248. // req.partnerId = wxmodel.partnerid;
  249. // req.prepayId = wxmodel.prepayid;
  250. // req.nonceStr = wxmodel.noncestr;
  251. // req.timeStamp = [wxmodel.timestamp intValue];
  252. // req.package = wxmodel.package;
  253. // req.sign = wxmodel.sign;
  254. //
  255. // [WXApi sendReq:req completion:^(BOOL success) {
  256. //
  257. // }];
  258. //
  259. // }
  260. else if ([sdkType isEqualToString:@"JubaoWxsdk"] || [sdkType isEqualToString:@"JubaoAlisdk"])
  261. {
  262. // NSDictionary *configDic =[sdkDic objectForKey:@"config"];
  263. // _juBaoModel = [JuBaoModel mj_objectWithKeyValues: configDic];
  264. // BGParam *param = [[BGParam alloc] init];
  265. // // playerid:用户在第三方平台上的用户名
  266. // param.playerid = _juBaoModel.playerid;
  267. // // goodsname:购买商品名称
  268. // param.goodsname = _juBaoModel.goodsname;
  269. // // amount:购买商品价格,单位是元
  270. // param.amount = _juBaoModel.amount;
  271. // // payid:第三方平台上的订单号,请传真实订单号,方便后续对账,例子里采用随机数,
  272. // param.payid = _juBaoModel.payid;
  273. //
  274. // [BGInterface start:self withParams:param withDelegate:self];
  275. //[BGInterface start:self withParams:param withType:model.withType withDelegate:self];
  276. // 凡伟支付 end
  277. }
  278. else if ([sdkType isEqualToString:@"iappay"])
  279. {
  280. // [SVProgressHUD showWithStatus:ASLocalizedString(@"正在提交iTunes Store,请等待...")];
  281. // NSMutableDictionary *configDic = [NSMutableDictionary new];
  282. // configDic = sdkDic[@"config"];
  283. // self.pro_id = configDic[@"product_id"];
  284. NSString *productId = sdkDic[@"config"][@"product_id"];
  285. if (productId.length && self.reDelegate && [self.reDelegate respondsToSelector:@selector(checkProid:)]) {
  286. [self.reDelegate checkProid:productId];
  287. }
  288. }
  289. else if ([payDic toInt:@"is_wap"] == 1)
  290. {
  291. if ([payDic toInt:@"is_without"] == 1) // 跳转外部浏览器
  292. {
  293. NSURL *url=[NSURL URLWithString:[payDic stringForKey:@"url"]];
  294. [[UIApplication sharedApplication] openURL:url];
  295. }
  296. else
  297. {
  298. BGMainWebViewController *vc = [BGMainWebViewController webControlerWithUrlStr:[payDic stringForKey:@"url"] isShowIndicator:YES isShowNavBar:YES isShowBackBtn:YES];
  299. [[AppDelegate sharedAppDelegate] pushViewController:vc animated:YES];
  300. }
  301. }
  302. else
  303. {
  304. NSLog(ASLocalizedString(@"错误"));
  305. }
  306. }
  307. else
  308. {
  309. NSLog(ASLocalizedString(@"请求失败"));
  310. }
  311. }FailureBlock:^(NSError *error){
  312. [SVProgressHUD dismiss];
  313. }];
  314. }
  315. -(BogoRechargeTopView *)topView{
  316. if (!_topView) {
  317. _topView = [[NSBundle mainBundle]loadNibNamed:@"BogoRechargeTopView" owner:nil options:nil].lastObject;
  318. }
  319. return _topView;
  320. }
  321. -(BogoRechargePayMoneyCollection *)payMoneyView{
  322. if (!_payMoneyView) {
  323. _payMoneyView = [[BogoRechargePayMoneyCollection alloc]initWithFrame:CGRectMake(0, self.topView.bottom, kScreenW, kRealValue(240))];
  324. if (kIsCheckingVersion()) {
  325. _payMoneyView.hidden = YES;
  326. }
  327. }
  328. return _payMoneyView;
  329. }
  330. -(BogoRechargePayTypeCollection *)payTypeView{
  331. if (!_payTypeView) {
  332. _payTypeView = [[BogoRechargePayTypeCollection alloc]initWithFrame:CGRectMake(0, self.payMoneyView.bottom, kScreenW, kRealValue(380))];
  333. if (kIsCheckingVersion()) {
  334. _payTypeView.hidden = YES;
  335. }
  336. }
  337. return _payTypeView;;
  338. }
  339. -(UIButton *)selectAgreeBtn{
  340. if (!_selectAgreeBtn) {
  341. _selectAgreeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  342. [_selectAgreeBtn setImage:[UIImage imageNamed:@"bogo_recharge_normalAgree"] forState:UIControlStateNormal];
  343. [_selectAgreeBtn setImage:[UIImage imageNamed:@"bogo_recharge_selectAgree"] forState:UIControlStateSelected];
  344. [_selectAgreeBtn addTarget:self action:@selector(clickSelectAgreenBtn:) forControlEvents:UIControlEventTouchUpInside];
  345. if (kIsCheckingVersion()) {
  346. _selectAgreeBtn.hidden = YES;
  347. }
  348. }
  349. return _selectAgreeBtn;
  350. }
  351. -(UIButton *)agreeBtn{
  352. if (!_agreeBtn) {
  353. NSString *firstStr = ASLocalizedString(@"同意");
  354. NSString *secondStr = ASLocalizedString(@" 用户充值免责协议");
  355. NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@%@",firstStr,secondStr]];
  356. [attributeString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#333333"] range:NSMakeRange(0, firstStr.length)];
  357. [attributeString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#00AEFF"] range:NSMakeRange(firstStr.length, secondStr.length)];
  358. _agreeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  359. _agreeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  360. [_agreeBtn setAttributedTitle:attributeString forState:UIControlStateNormal];
  361. [_agreeBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
  362. _agreeBtn.titleLabel.font = [UIFont systemFontOfSize:12];
  363. [_agreeBtn addTarget:self action:@selector(clickAgreenBtn:) forControlEvents:UIControlEventTouchUpInside];
  364. if (kIsCheckingVersion()) {
  365. _agreeBtn.hidden = YES;
  366. }
  367. }
  368. return _agreeBtn;
  369. }
  370. -(UIButton *)payBtn{
  371. if (!_payBtn) {
  372. _payBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  373. [_payBtn setBackgroundImage:[UIImage imageNamed:@"widthBtnBg"] forState:UIControlStateNormal];
  374. [_payBtn setTitle:ASLocalizedString(@"立即支付") forState:UIControlStateNormal];
  375. _payBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  376. [_payBtn addTarget:self action:@selector(clickPayBtn:) forControlEvents:UIControlEventTouchUpInside];
  377. if (kIsCheckingVersion()) {
  378. _payBtn.hidden = YES;
  379. }
  380. }
  381. return _payBtn;
  382. }
  383. - (void)closeBtnAction{
  384. if (self.reDelegate && [self.reDelegate respondsToSelector:@selector(rechargeScrollView:didClickCloseBtn:)]) {
  385. [self.reDelegate rechargeScrollView:self didClickCloseBtn:self.closeBtn];
  386. }
  387. }
  388. - (UILabel *)titleLabel{
  389. if (!_titleLabel) {
  390. _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, kScreenW, 20)];
  391. _titleLabel.textColor = [UIColor colorWithHexString:@"333333"];
  392. _titleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
  393. _titleLabel.textAlignment = NSTextAlignmentCenter;
  394. _titleLabel.text = ASLocalizedString(@"充值");
  395. }
  396. return _titleLabel;
  397. }
  398. - (UIButton *)closeBtn{
  399. if (!_closeBtn) {
  400. _closeBtn = [[UIButton alloc]initWithFrame:CGRectMake(kScreenW - 40, 0, 40, 40)];
  401. [_closeBtn setImage:[UIImage imageNamed:@"lr_btn_ward_close"] forState:UIControlStateNormal];
  402. [_closeBtn addTarget:self action:@selector(closeBtnAction) forControlEvents:UIControlEventTouchUpInside];
  403. }
  404. return _closeBtn;
  405. }
  406. @end