YOUPAILZVipCoinRechargeVC.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. //
  2. // YOUPAILZVipCoinRechargeVC.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/8/26.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZVipCoinRechargeVC.h"
  9. #import "YOUPAILZVipCoinRechargeCell.h"
  10. #import "YOUPAILCIMSessionVC.h"
  11. #import "YOUPAILZVipCoinRechargeModel.h"
  12. #import "UIViewController+TFPresent.h"
  13. #import "YOUPAILZPaySuccessVC.h"
  14. #import "IPAManager.h"
  15. @interface YOUPAILZVipCoinRechargeVC () <UICollectionViewDelegate,UICollectionViewDataSource>
  16. @property (nonatomic,weak) UILabel *youpaipbalanceL;
  17. @property (nonatomic,weak) UICollectionView *youpaipcollectionView;
  18. @property (nonatomic,strong) NSArray <YOUPAILZVipCoinRechargeModel *>*youpaipdataSource;
  19. @property (nonatomic,strong) YOUPAILZVipCoinRechargeModel *youpaipcurrentModel;
  20. @property (nonatomic,strong) UIButton *youpaiprechargeBtn;
  21. @end
  22. @implementation YOUPAILZVipCoinRechargeVC
  23. - (void)dealloc{
  24. [[NSNotificationCenter defaultCenter] removeObserver:self];
  25. }
  26. - (void)viewWillAppear:(BOOL)animated{
  27. [super viewWillAppear:animated];
  28. [self.navigationController.navigationBar setBlackBar];
  29. }
  30. - (void)viewWillDisappear:(BOOL)animated{
  31. [super viewWillDisappear:animated];
  32. [self.navigationController.navigationBar setDefaultBar];
  33. }
  34. - (UIStatusBarStyle)preferredStatusBarStyle{
  35. return UIStatusBarStyleLightContent;
  36. }
  37. - (void)youpaifback{
  38. [self.navigationController popViewControllerAnimated:YES];
  39. }
  40. - (void)viewDidLoad {
  41. [super viewDidLoad];
  42. self.title = @"贵族币充值";
  43. [self youpaifinitUI];
  44. self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(youpaifback) image:[UIImage imageNamed:@"vqu_images_nav_return_white"]];
  45. [self youpaifrequestVipCoinRechargeList];
  46. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(youpaifApplePaySuccess:) name:@"yqApplePaySuccess" object:nil];
  47. }
  48. - (void)youpaifApplePaySuccess:(NSNotification*)noti{
  49. [self youpaifrequestVipCoinRechargeList];
  50. [self youpaifgoPaySuccessVC];
  51. }
  52. - (void)youpaifgoPaySuccessVC{
  53. YOUPAILZPaySuccessVC *vc = [[YOUPAILZPaySuccessVC alloc] init];
  54. vc.youpaipcontent = @"恭喜你,充值成功";
  55. [self.navigationController pushViewController:vc animated:YES];
  56. }
  57. - (void)youpaifinitUI{
  58. [self.view addLineWithColor:HexColorFromRGB(0x1C1D23) lineRect:CGRectMake(0, NavBarHeight, KScreenWidth, ScaleSize(92.0f))];
  59. UIImageView *balanceBgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vqu_images_ic_vip_coin_recharge_bg"]];
  60. balanceBgV.userInteractionEnabled = YES;
  61. [self.view addSubview:balanceBgV];
  62. [balanceBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.left.offset(ScaleSize(14.0f));
  64. make.top.offset(NavBarHeight + ScaleSize(10.0f));
  65. make.right.offset(ScaleSize(-14.0f));
  66. make.height.offset(ScaleSize(82.0f));
  67. }];
  68. UILabel *coinDescL = [[UILabel alloc] init];
  69. coinDescL.text = @"贵族币余额";
  70. coinDescL.textColor = HexColorFromRGB(0xFDCC88);
  71. coinDescL.font = LCFont(ScaleSize(14.0f));
  72. [balanceBgV addSubview:coinDescL];
  73. [coinDescL mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.left.top.offset(ScaleSize(14.0f));
  75. }];
  76. UILabel *balanceL = [[UILabel alloc] init];
  77. balanceL.text = @"0";
  78. balanceL.textColor = HexColorFromRGB(0xFDCC88);
  79. balanceL.font = LCFont(ScaleSize(36.0f));
  80. [balanceBgV addSubview:balanceL];
  81. self.youpaipbalanceL = balanceL;
  82. [balanceL mas_makeConstraints:^(MASConstraintMaker *make) {
  83. make.left.offset(ScaleSize(14.0f));
  84. make.top.equalTo(coinDescL.mas_bottom).offset(ScaleSize(6.0f));
  85. }];
  86. UIButton *serviceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  87. serviceBtn.layer.cornerRadius = ScaleSize(27.0f) / 2.0f;
  88. serviceBtn.clipsToBounds = YES;
  89. [serviceBtn setTitle:LCStr(word34) forState:UIControlStateNormal];//@"人工通道"
  90. [serviceBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  91. serviceBtn.titleLabel.font = LCFont12;
  92. serviceBtn.backgroundColor = HexColorFromRGB(0x4F4B5B);
  93. [serviceBtn addTarget:self action:@selector(youpaifserviceBtnClick) forControlEvents:UIControlEventTouchUpInside];
  94. [balanceBgV addSubview:serviceBtn];
  95. [serviceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.centerY.equalTo(balanceBgV);
  97. make.right.offset(ScaleSize(-12.0f));
  98. make.size.mas_offset(CGSizeMake(ScaleSize(76.0f), ScaleSize(27.0f)));
  99. }];
  100. if ([LCSaveData getWhiteVersion]) {
  101. serviceBtn.hidden = YES;
  102. }
  103. UIView *footerBgV = [[UIView alloc] init];
  104. footerBgV.backgroundColor = [UIColor whiteColor];
  105. [self.view addSubview:footerBgV];
  106. [footerBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  107. make.left.bottom.right.offset(0.0f);
  108. make.height.offset(30.0f+SafeHeight+48.0f+10.0f);
  109. }];
  110. UIButton *rechargeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  111. rechargeBtn.layer.cornerRadius = 24.0f;
  112. rechargeBtn.clipsToBounds = YES;
  113. [rechargeBtn setTitle:@"立即充值" forState:UIControlStateNormal];
  114. [rechargeBtn setTitleColor:HexColorFromRGB(0x75170A) forState:UIControlStateNormal];
  115. rechargeBtn.titleLabel.font = LCFont16;
  116. [rechargeBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 80.0f, 48.0f) FromColors:@[HexColorFromRGB(0xFBD893),HexColorFromRGB(0xD66F47)] ByGradientType:GradientTopToBottom] forState:UIControlStateNormal];
  117. [rechargeBtn addTarget:self action:@selector(youpaifrechargeBtnClick) forControlEvents:UIControlEventTouchUpInside];
  118. [footerBgV addSubview:rechargeBtn];
  119. self.youpaiprechargeBtn = rechargeBtn;
  120. [rechargeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  121. make.top.offset(10.0f);
  122. make.centerX.equalTo(footerBgV);
  123. make.size.mas_offset(CGSizeMake(KScreenWidth - 80.0f, 48.0f));
  124. }];
  125. UIView *centerBgV = [[UIView alloc] init];
  126. centerBgV.backgroundColor = [UIColor whiteColor];
  127. [self.view addSubview:centerBgV];
  128. [centerBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  129. make.left.right.offset(0.0f);
  130. make.top.equalTo(balanceBgV.mas_bottom).offset(0.0f);
  131. make.bottom.equalTo(footerBgV.mas_top).offset(0.0f);
  132. }];
  133. UILabel *rechargeDescL = [[UILabel alloc] init];
  134. rechargeDescL.text = @"请选择充值金额:";
  135. rechargeDescL.textColor = LZA3AABEColor;
  136. rechargeDescL.font = LCFont(ScaleSize(12.0f));
  137. [centerBgV addSubview:rechargeDescL];
  138. [rechargeDescL mas_makeConstraints:^(MASConstraintMaker *make) {
  139. make.left.offset(ScaleSize(14.0f));
  140. make.top.offset(ScaleSize(38.0f));
  141. }];
  142. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  143. flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
  144. flowLayout.itemSize = CGSizeMake((KScreenWidth - ScaleSize(33.0f)) / 2.0f, ScaleSize(74.0f));
  145. flowLayout.minimumLineSpacing = ScaleSize(5.0f);
  146. flowLayout.minimumInteritemSpacing = ScaleSize(5.0f);
  147. flowLayout.sectionInset = UIEdgeInsetsMake(0.0f, ScaleSize(14.0f), 0.0f, ScaleSize(14.0f));
  148. UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
  149. collectionView.backgroundColor = [UIColor clearColor];
  150. collectionView.alwaysBounceVertical = YES;
  151. collectionView.delegate = self;
  152. collectionView.dataSource = self;
  153. [collectionView registerClass:YOUPAILZVipCoinRechargeCell.class forCellWithReuseIdentifier:@"cell"];
  154. [collectionView registerClass:UICollectionReusableView.class forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer"];
  155. collectionView.showsVerticalScrollIndicator = NO;
  156. collectionView.showsHorizontalScrollIndicator = NO;
  157. [centerBgV addSubview:collectionView];
  158. self.youpaipcollectionView = collectionView;
  159. [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  160. make.left.bottom.right.offset(0.0f);
  161. make.top.equalTo(rechargeDescL.mas_bottom).offset(ScaleSize(12.0f));
  162. }];
  163. }
  164. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  165. return 1;
  166. }
  167. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  168. return self.youpaipdataSource.count;
  169. }
  170. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  171. YOUPAILZVipCoinRechargeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
  172. [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.item]];
  173. return cell;
  174. }
  175. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
  176. UICollectionReusableView *reusableview = nil;
  177. if (kind == UICollectionElementKindSectionFooter){
  178. reusableview = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer" forIndexPath:indexPath];
  179. for (UIView *subV in reusableview.subviews) {
  180. [subV removeFromSuperview];
  181. }
  182. UILabel *lab = [[UILabel alloc] init];
  183. lab.numberOfLines = 0;
  184. lab.textColor = LZ273145Color;
  185. lab.font = LCFont(ScaleSize(12.0f));
  186. lab.text =LCStr(word35);// @"为方便大额用户,贵族币与人民币比例为1:1\n可以用于购买贵族、兑换钻石";
  187. [reusableview addSubview:lab];
  188. [lab mas_makeConstraints:^(MASConstraintMaker *make) {
  189. make.top.offset(ScaleSize(16.0f));
  190. make.left.offset(ScaleSize(26.0f));
  191. make.right.offset(ScaleSize(-26.0f));
  192. }];
  193. if ([LCSaveData getWhiteVersion]) {
  194. lab.hidden = YES;
  195. }
  196. }
  197. return reusableview;
  198. }
  199. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
  200. return CGSizeMake(KScreenWidth,ScaleSize(66.0f)); //查看跟多群成员
  201. }
  202. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  203. self.youpaipcurrentModel.youpaipisSelected = NO;
  204. self.youpaipcurrentModel = self.youpaipdataSource[indexPath.item];
  205. self.youpaipcurrentModel.youpaipisSelected = YES;
  206. [self.youpaipcollectionView reloadData];
  207. }
  208. - (void)youpaifrequestVipCoinRechargeList{
  209. @weakify(self);
  210. [LCHttpHelper requestWithURLString:GetNobleCoin parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  211. @strongify(self);
  212. NSDictionary* dict = (NSDictionary*)responseObject;
  213. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  214. if (code == 0) {
  215. NSInteger user_noble_coin = [[[dict objectForKey:@"data"]objectForKey:@"user_noble_coin"] integerValue];
  216. NSArray *recharge_coin = [[dict objectForKey:@"data"]objectForKey:@"recharge_coin"];
  217. self.youpaipbalanceL.text = [NSString stringWithFormat:@"%@",@(user_noble_coin)];
  218. self.youpaipdataSource = [YOUPAILZVipCoinRechargeModel mj_objectArrayWithKeyValuesArray:recharge_coin];
  219. if (self.youpaipdataSource.count != 0) {
  220. self.youpaipcurrentModel = self.youpaipdataSource[0];
  221. self.youpaipcurrentModel.youpaipisSelected = YES;
  222. }
  223. [self.youpaipcollectionView reloadData];
  224. }
  225. } failure:^(NSError *error) {
  226. }];
  227. }
  228. - (void)youpaifserviceBtnClick{
  229. NIMSession *session = [NIMSession session:@"4" type:NIMSessionTypeP2P];
  230. @weakify(self);
  231. [ZCHUDHelper show];
  232. [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[session.sessionId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
  233. @strongify(self);
  234. [ZCHUDHelper dismiss];
  235. YOUPAILCIMSessionVC *vc = [[YOUPAILCIMSessionVC alloc] initWithSession:session];
  236. [self.navigationController pushViewController:vc animated:YES];
  237. }];
  238. }
  239. - (void)youpaifrechargeBtnClick{
  240. if (self.youpaipcurrentModel != nil) {
  241. [self applePay];
  242. }
  243. }
  244. - (void)applePay{
  245. self.youpaiprechargeBtn.userInteractionEnabled = NO;
  246. /// 内购
  247. [ZCHUDHelper showWithStatus:@"支付中..."];
  248. NSLog(@"%@",self.youpaipcurrentModel.ios_product_id);
  249. [[IPAManager shareIAPManager] startPurchWithID:self.youpaipcurrentModel.ios_product_id completeHandle:^(IAPPurchType type, NSString *data) {
  250. if (type == IAPPurchSuccess) {
  251. [LCSaveData saveReceiptData:data];
  252. [self requestApplePayBack:data];
  253. }else{
  254. dispatch_async(dispatch_get_main_queue(), ^{
  255. self.youpaiprechargeBtn.userInteractionEnabled = YES;
  256. });
  257. NSString *title = @"";
  258. switch (type) {
  259. case IAPPurchFailed:
  260. title = @"购买失败";
  261. break;
  262. case IAPPurchCancle:
  263. title = @"已取消购买";
  264. break;
  265. case IAPPurchVerFailed:
  266. title = @"订单校验失败";
  267. break;
  268. // case IAPPurchVerSuccess:
  269. // NSLog(@"订单校验成功");
  270. // break;
  271. case IAPPurchNotArrow:
  272. title = @"不允许程序内付费";
  273. break;
  274. default:
  275. break;
  276. }
  277. if (title.length == 0) {
  278. [ZCHUDHelper dismiss];
  279. }else{
  280. [ZCHUDHelper showTitle:title];
  281. }
  282. }
  283. }];
  284. }
  285. - (void)requestApplePayBack:(NSString *)receipt_data{
  286. NSLog(@"receipt_data == %@",receipt_data);
  287. [LCHttpHelper requestWithURLString:ApplePayBack parameters:@{@"receipt_data":receipt_data} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  288. NSDictionary* dict = (NSDictionary*)responseObject;
  289. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  290. dispatch_async(dispatch_get_main_queue(), ^{
  291. self.youpaiprechargeBtn.userInteractionEnabled = YES;
  292. });
  293. if (code == 0) {
  294. [LCSaveData removeReceiptData:receipt_data];
  295. NSInteger type = 2;
  296. if (![LCSaveData getOnlineVersion]) {
  297. type = 4;
  298. }
  299. [self youpaifrequestVipCoinRechargeList];
  300. }
  301. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  302. } failure:^(NSError *error) {
  303. dispatch_async(dispatch_get_main_queue(), ^{
  304. self.youpaiprechargeBtn.userInteractionEnabled = YES;
  305. });
  306. [ZCHUDHelper showTitle:error.localizedDescription];
  307. }];
  308. }
  309. @end