410 lines
15 KiB
Objective-C
410 lines
15 KiB
Objective-C
//
|
|
// YMIAPRechargeViewController.m
|
|
// YUMI
|
|
//
|
|
// Created by XY on 2023/2/21.
|
|
//
|
|
|
|
#import "XPIAPRechargeViewController.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import <Base64/MF_Base64Additions.h>
|
|
///Tool
|
|
#import "DJDKMIMOMColor.h"
|
|
#import "YUMIMacroUitls.h"
|
|
#import "YUMIHtmlUrl.h"
|
|
#import "RechargeStorage.h"
|
|
#import "AccountInfoStorage.h"
|
|
#import "NSObject+MJExtension.h"
|
|
#import "NSArray+Safe.h"
|
|
#import "UIImage+Utils.h"
|
|
///Model
|
|
#import "RechargeListModel.h"
|
|
///View
|
|
#import "XPIAPRechargeHeaderView.h"
|
|
#import "XPIAPRechargeCollectionViewCell.h"
|
|
#import "XPMineRechargeNavView.h"
|
|
///P
|
|
#import "XPMineRechargePresenter.h"
|
|
#import "XPMineRechargeProtocol.h"
|
|
///VC
|
|
#import "XPWebViewController.h"
|
|
#import "XPIAPRechargeHeadCell.h"
|
|
#import "SessionViewController.h"
|
|
#import "ClientConfig.h"
|
|
#import "Api+Main.h"
|
|
#import "YuMi-swift.h"
|
|
|
|
#import "IAPManager.h"
|
|
#import "FirstRechargeManager.h"
|
|
|
|
#define kHeaderViewHeight 220.0/375.0*KScreenWidth
|
|
|
|
@interface XPIAPRechargeViewController ()<
|
|
UICollectionViewDelegate,
|
|
UICollectionViewDataSource,
|
|
UICollectionViewDelegateFlowLayout,
|
|
XPMineRechargeProtocol,
|
|
XPMineRechargeNavViewDelegate,
|
|
XPIAPRechargeHeadCellDelegate>
|
|
|
|
@property (nonatomic, strong) UICollectionView *collectionView;
|
|
/// 头部
|
|
@property (nonatomic, strong) XPIAPRechargeHeaderView *headerView;
|
|
/// 充值按钮
|
|
@property (nonatomic, strong) UIButton *rechargeBtn;
|
|
///
|
|
@property (nonatomic,strong) UIStackView *stackView;
|
|
///同意
|
|
@property (nonatomic,strong) UILabel *agreeLabel;
|
|
///充值协议
|
|
@property (nonatomic,strong) UIButton *protcoloButton;
|
|
/// 返回
|
|
@property (nonatomic,strong) UIButton *backBtn;
|
|
/// 标题
|
|
@property (nonatomic,strong) UILabel *titleLabel;
|
|
|
|
/// 数据源
|
|
@property (nonatomic, strong) NSArray<RechargeListModel *> *dataSource;
|
|
/// 选中下标
|
|
@property (nonatomic, strong) NSIndexPath *selectedIndex;
|
|
|
|
@end
|
|
|
|
@implementation XPIAPRechargeViewController
|
|
|
|
- (void)dealloc {
|
|
|
|
}
|
|
|
|
- (BOOL)isHiddenNavBar {
|
|
return YES;
|
|
}
|
|
|
|
- (UIStatusBarStyle)preferredStatusBarStyle {
|
|
return UIStatusBarStyleLightContent;
|
|
}
|
|
|
|
- (XPMineRechargePresenter *)createPresenter {
|
|
return [[XPMineRechargePresenter alloc] init];
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self createUI];
|
|
[self initHttpData];
|
|
}
|
|
|
|
- (void)createUI {
|
|
self.view.backgroundColor = UIColorFromRGB(0xF4F5FA);
|
|
|
|
[self.view addSubview:self.headerView];
|
|
[self.view addSubview:self.collectionView];
|
|
[self.view addSubview:self.rechargeBtn];
|
|
[self.view addSubview:self.stackView];
|
|
[self.view addSubview:self.titleLabel];
|
|
[self.view addSubview:self.backBtn];
|
|
|
|
[self.stackView addArrangedSubview:self.agreeLabel];
|
|
[self.stackView addArrangedSubview:self.protcoloButton];
|
|
CGFloat height = kGetScaleWidth(236);
|
|
[self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.trailing.top.mas_equalTo(0);
|
|
make.height.mas_equalTo(height);
|
|
}];
|
|
|
|
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.mas_equalTo(self.view);
|
|
make.bottom.mas_equalTo(-34);
|
|
make.height.mas_equalTo(kGetScaleWidth(14));
|
|
}];
|
|
|
|
[self.rechargeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.width.mas_equalTo(kGetScaleWidth(343));
|
|
make.height.mas_equalTo(kGetScaleWidth(56));
|
|
make.centerX.equalTo(self.view);
|
|
make.bottom.equalTo(self.stackView.mas_top).mas_offset(-kGetScaleWidth(10));
|
|
}];
|
|
|
|
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.headerView.mas_bottom).mas_offset(kGetScaleWidth(21));
|
|
make.leading.trailing.mas_equalTo(0);
|
|
make.bottom.equalTo(self.rechargeBtn.mas_top).mas_offset(-kGetScaleWidth(10));
|
|
}];
|
|
|
|
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(kStatusBarHeight);
|
|
make.height.mas_equalTo(44);
|
|
make.centerX.mas_equalTo(self.view);
|
|
}];
|
|
[self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(0);
|
|
make.top.mas_equalTo(kStatusBarHeight);
|
|
make.width.height.mas_equalTo(44);
|
|
}];
|
|
}
|
|
|
|
- (void)initHttpData {
|
|
[self getRechargeList];
|
|
[self.presenter getBannerList];
|
|
[self getUserWalletBalanceInfo];
|
|
|
|
// @kWeakify(self);
|
|
// [[IAPManager sharedManager] retryCheckAllReceipt:^{
|
|
// @kStrongify(self);
|
|
// [self getUserWalletBalanceInfo];
|
|
// if(self.delegate && [self.delegate respondsToSelector:@selector(paySuccess)]){
|
|
// [self.delegate paySuccess];
|
|
// }
|
|
// }];
|
|
}
|
|
|
|
/// 返回
|
|
- (void)backBtnAction {
|
|
if(self.isFairyPay){
|
|
[UIView animateWithDuration:0.5 animations:^{
|
|
self.view.frame = CGRectMake(0, KScreenHeight, KScreenWidth, KScreenHeight);
|
|
}completion:^(BOOL finished) {
|
|
[self willMoveToParentViewController:nil]; //1
|
|
[self.view removeFromSuperview]; //2
|
|
[self removeFromParentViewController]; //3
|
|
}];
|
|
return;
|
|
}
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
}
|
|
|
|
/// 点击充值按钮
|
|
- (void)rechargeBtnAction {
|
|
self.rechargeBtn.userInteractionEnabled = NO;
|
|
|
|
if(self.selectedIndex == nil){
|
|
[self showSuccessToast:YMLocalizedString(@"XPIAPRechargeViewController11")];
|
|
return;
|
|
}
|
|
|
|
NSInteger index = self.selectedIndex.row;
|
|
if(index < self.dataSource.count){
|
|
RechargeListModel *model = [self.dataSource xpSafeObjectAtIndex:index];
|
|
if (model.chargeProdId) {
|
|
[self showLoading];
|
|
|
|
@kWeakify(self);
|
|
[[IAPManager sharedManager] purchase:model.chargeProdId
|
|
success:^(NSString *transactionID, NSString *orderID) {
|
|
@kStrongify(self);
|
|
[self hideHUD];
|
|
[self getUserWalletBalanceInfo];
|
|
|
|
// 更新首充状态
|
|
FirstRechargeManager *manager = [FirstRechargeManager sharedManager];
|
|
// 使用新添加的方法更新首充状态
|
|
[manager updateChargeStatusToCompleted];
|
|
[self.collectionView reloadData];
|
|
|
|
// 由于服务器可能会返回不同的状态,我们在延迟后再次确认状态已更新
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
[[FirstRechargeManager sharedManager] updateChargeStatusToCompleted];
|
|
});
|
|
|
|
if(self.delegate && [self.delegate respondsToSelector:@selector(paySuccess)]){
|
|
[self.delegate paySuccess];
|
|
}
|
|
self.rechargeBtn.userInteractionEnabled = YES;
|
|
|
|
} failure:^(NSError * _Nonnull error) {
|
|
@kStrongify(self);
|
|
[self hideHUD];
|
|
if (error) {
|
|
[self showErrorToast:error.domain];
|
|
}
|
|
self.rechargeBtn.userInteractionEnabled = YES;
|
|
} contactCS:^(NSString * _Nonnull uid) {
|
|
@kStrongify(self);
|
|
[self hideHUD];
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
NIMSession * session = [NIMSession session:uid type:NIMSessionTypeP2P];
|
|
SessionViewController * sessionVC = [[SessionViewController alloc] initWithSession:session];
|
|
[self.navigationController pushViewController:sessionVC animated:YES];
|
|
});
|
|
}];
|
|
}
|
|
}
|
|
}
|
|
|
|
- (void)protcoloButtonAction:(UIButton *)sender {
|
|
if(self.isFairyPay){
|
|
XPWebViewController * webVC= [[XPWebViewController alloc] initWithCustomizeNav:YES];
|
|
webVC.url = URLWithType(kRechargePrivacyURL);
|
|
webVC.is_Pi_FairyPay = YES;
|
|
webVC.view.backgroundColor = [UIColor whiteColor];
|
|
[self addChildViewController:webVC];
|
|
[self.view addSubview:webVC.view];
|
|
webVC.view.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
|
|
return;
|
|
}
|
|
|
|
XPWebViewController * webVC= [[XPWebViewController alloc] initWithRoomUID:nil];
|
|
webVC.url = URLWithType(kRechargePrivacyURL);
|
|
[self.navigationController pushViewController:webVC animated:YES];
|
|
}
|
|
|
|
- (void)getRechargeList {
|
|
[self.presenter requestRechargeListWithChannel:@"8"];
|
|
}
|
|
|
|
- (void)getUserWalletBalanceInfo {
|
|
[self.presenter getUserWalletInfo];
|
|
}
|
|
- (void)getBannerListSuccessWithList:(NSArray *)list{
|
|
|
|
self.selectedIndex = [NSIndexPath indexPathForRow:0 inSection:0];
|
|
|
|
[self.collectionView reloadData];
|
|
}
|
|
|
|
- (void)requestRechargeListSucccess:(NSArray *)list {
|
|
self.dataSource = list;
|
|
[self.collectionView reloadData];
|
|
}
|
|
|
|
#pragma mark - XPMineRechargeNavViewDelegate
|
|
- (void)xPMineRechargeNavView:(XPMineRechargeNavView *)view didClickBackButton:(UIButton *)sender {
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
}
|
|
|
|
- (void)getUserWalletInfo:(WalletInfoModel *)balanceInfo {
|
|
self.headerView.walletInfo = balanceInfo;
|
|
}
|
|
|
|
// MARK: 。。。没有用到?
|
|
//- (void)checkTranscationIdsSuccess {
|
|
// NSString * uid = [AccountInfoStorage instance].getUid;
|
|
// [RechargeStorage delegateAllTranscationIdsWithUid:uid];
|
|
//}
|
|
|
|
#pragma mark - UICollectionViewDelegate
|
|
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
|
|
|
return self.dataSource.count;
|
|
}
|
|
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
return CGSizeMake(kGetScaleWidth(108), kGetScaleWidth(121));
|
|
}
|
|
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
XPIAPRechargeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass(XPIAPRechargeCollectionViewCell.self) forIndexPath:indexPath];
|
|
NSInteger count = indexPath.item;
|
|
cell.rechargeModel = [self.dataSource xpSafeObjectAtIndex:count];
|
|
cell.selectedStyle = self.selectedIndex.item == indexPath.item;
|
|
return cell;
|
|
}
|
|
|
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
self.selectedIndex = indexPath;
|
|
[collectionView reloadData];
|
|
}
|
|
#pragma mark - XPIAPRechargeHeadCellDelegate
|
|
- (void)xpIAPRechargeHeadCell:(XPIAPRechargeHeadCell *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
|
|
|
|
}
|
|
#pragma mark - 懒加载
|
|
- (UICollectionView *)collectionView {
|
|
if (!_collectionView) {
|
|
MSBaseRTLFlowLayout *layout = [[MSBaseRTLFlowLayout alloc] init];
|
|
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
|
|
layout.minimumLineSpacing = kGetScaleWidth(8);
|
|
layout.minimumInteritemSpacing = kGetScaleWidth(8);
|
|
layout.sectionInset = UIEdgeInsetsMake(0, kGetScaleWidth(17), 0, kGetScaleWidth(17));
|
|
|
|
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
|
|
_collectionView.backgroundColor = UIColor.clearColor;
|
|
_collectionView.alwaysBounceVertical = YES;
|
|
[_collectionView registerClass:[XPIAPRechargeCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass(XPIAPRechargeCollectionViewCell.self)];
|
|
[_collectionView registerClass:[XPIAPRechargeHeadCell class] forCellWithReuseIdentifier:NSStringFromClass(XPIAPRechargeHeadCell.self)];
|
|
|
|
_collectionView.delegate = self;
|
|
_collectionView.dataSource = self;
|
|
_collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
|
}
|
|
return _collectionView;
|
|
}
|
|
|
|
- (XPIAPRechargeHeaderView *)headerView {
|
|
if (!_headerView) {
|
|
_headerView = [[XPIAPRechargeHeaderView alloc] init];
|
|
}
|
|
return _headerView;
|
|
}
|
|
|
|
- (UIButton *)rechargeBtn {
|
|
if (!_rechargeBtn) {
|
|
_rechargeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_rechargeBtn setTitle:YMLocalizedString(@"XPIAPRechargeViewController2") forState:UIControlStateNormal];
|
|
[_rechargeBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
|
|
_rechargeBtn.titleLabel.font = kFontMedium(16);
|
|
[_rechargeBtn setBackgroundImage:[UIImage gradientColorImageFromColors:@[[DJDKMIMOMColor confirmButtonGradientStartColor], [DJDKMIMOMColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)] forState:UIControlStateNormal];
|
|
_rechargeBtn.layer.cornerRadius = kGetScaleWidth(56)/2;
|
|
_rechargeBtn.clipsToBounds = YES;
|
|
[_rechargeBtn addTarget:self action:@selector(rechargeBtnAction) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _rechargeBtn;
|
|
}
|
|
|
|
- (UIStackView *)stackView {
|
|
if (!_stackView) {
|
|
_stackView = [[UIStackView alloc] init];
|
|
_stackView.axis = UILayoutConstraintAxisHorizontal;
|
|
_stackView.distribution = UIStackViewDistributionFill;
|
|
_stackView.alignment = UIStackViewAlignmentFill;
|
|
_stackView.spacing = 2;
|
|
}
|
|
return _stackView;
|
|
}
|
|
|
|
- (UIButton *)protcoloButton {
|
|
if (!_protcoloButton) {
|
|
_protcoloButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_protcoloButton setTitle:YMLocalizedString(@"XPIAPRechargeViewController3") forState:UIControlStateNormal];
|
|
[_protcoloButton setTitleColor:[DJDKMIMOMColor appMainColor] forState:UIControlStateNormal];
|
|
_protcoloButton.titleLabel.font = [UIFont systemFontOfSize:12];
|
|
[_protcoloButton addTarget:self action:@selector(protcoloButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _protcoloButton;
|
|
}
|
|
- (UILabel *)agreeLabel {
|
|
if (!_agreeLabel) {
|
|
_agreeLabel = [[UILabel alloc] init];
|
|
_agreeLabel.text = YMLocalizedString(@"XPIAPRechargeViewController4");
|
|
_agreeLabel.font = [UIFont systemFontOfSize:12];
|
|
_agreeLabel.textColor = [DJDKMIMOMColor textThirdColor];
|
|
}
|
|
return _agreeLabel;
|
|
}
|
|
|
|
|
|
|
|
|
|
- (UIButton *)backBtn {
|
|
if (!_backBtn) {
|
|
_backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_backBtn setImage:[[UIImage imageNamed:@"room_info_back"]ms_SetImageForRTL] forState:UIControlStateNormal];
|
|
[_backBtn addTarget:self action:@selector(backBtnAction) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _backBtn;
|
|
}
|
|
|
|
- (UILabel *)titleLabel {
|
|
if (!_titleLabel) {
|
|
_titleLabel = [[UILabel alloc] init];
|
|
_titleLabel.text = YMLocalizedString(@"XPIAPRechargeViewController6");
|
|
_titleLabel.textColor = UIColor.blackColor;
|
|
_titleLabel.font = kFontBold(16);
|
|
}
|
|
return _titleLabel;
|
|
}
|
|
|
|
|
|
@end
|