Files
peko-ios/YuMi/Modules/YMMine/View/Noble/View/XPNobleCenterViewController.m
2023-11-02 11:26:02 +08:00

478 lines
17 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// XPNobleCenterViewController.m
// xplan-ios
//
// Created by GreenLand on 2021/12/28.
//
#import "XPNobleCenterViewController.h"
///Third
#import <Masonry/Masonry.h>
#import <JXCategoryView/JXCategoryView.h>
#import <JXCategoryView/JXCategoryListContainerView.h>
#import <SDCycleScrollView/SDCycleScrollView.h>
#import <Base64/MF_Base64Additions.h>
#import <NIMSDK/NIMSDK.h>
///Tool
#import "DJDKMIMOMColor.h"
#import "ThemeColor+NobleCenter.h"
#import "Api+NobleCenter.h"
#import "XPIAPHelper.h"
#import "RechargeStorage.h"
#import "AccountInfoStorage.h"
#import "UIImage+Utils.h"
#import "TTPopup.h"
#import "StatisticsServiceHelper.h"
///View
#import "XPNobleCenterListViewController.h"
#import "XPNobleCenterNavView.h"
#import "XPNobleCenterMyNobleView.h"
#import "XPWebViewController.h"
#import "XPNobleSettingViewController.h"
#import "XPSkillCardPlayerManager.h"
///P
#import "XPNobleCenterPresenter.h"
#import "Api+Gift.h"
///model
#import "NobleCenterModel.h"
#import "UserInfoModel.h"
#import "NobleRechargeModel.h"
#import "AttachmentModel.h"
#import "WalletInfoModel.h"
#import "XPNobleCenterPayView.h"
#import "XPNobleCenterProtocol.h"
@interface XPNobleCenterViewController ()<XPNobleCenterProtocol,XPNobleCenterPayViewDelegate,JXCategoryViewDelegate, JXCategoryListContainerViewDelegate,XPNobleCenterNavViewDelegate, NIMSystemNotificationManagerDelegate>
///分页标题
@property (nonatomic, strong) NSArray<NSString *> *titles;
///分页控件
@property (nonatomic, strong) JXCategoryTitleView *titleView;
///分页lineView
@property (nonatomic, strong) JXCategoryListContainerView *lineView;
///头饰
@property (nonatomic,strong) XPNobleCenterListViewController *nobleListView;
///头部背景图
@property (nonatomic, strong) UIImageView *headBGImgeView;
@property (nonatomic, strong) XPNobleCenterNavView *navView;
///总数据
@property (nonatomic, strong) NobleCenterModel *model;
///用户信息
@property (nonatomic, strong) UserInfoModel *userInfo;
///开通贵族
@property (nonatomic, strong) UILabel *openNobleButton;
///
@property (nonatomic,strong) UIImageView *openNobleView;
@property (nonatomic,strong) UIImageView *openNobleIconView;
///当前用户贵族信息-开通了贵族才显示
@property (nonatomic, strong) XPNobleCenterMyNobleView *myNobleView;
///更新用户信息
@property (nonatomic, assign) BOOL needUpdateUserInfo;
///充值-----
@property (nonatomic, strong) NobleRechargeModel *rechargeModel;
///订单编号
@property (nonatomic,copy) NSString *orderId;
///房间UID
@property (nonatomic, assign) NSInteger roomUid;
@property (nonatomic,strong) WalletInfoModel * infoModel;
@property(nonatomic,strong) UIButton *rankBtn;
@end
@implementation XPNobleCenterViewController
///通过roomUid初始化从房间进入)
- (instancetype)initWithRoomUid:(NSInteger)roomUid {
if (self = [super init]) {
self.roomUid = roomUid;
}
return self;;
}
- (void)dealloc {
[XPIAPHelper shareHelper].delegate = nil;
}
- (void)viewDidLoad {
[super viewDidLoad];
[XPIAPHelper shareHelper].delegate = self;
[[NIMSDK sharedSDK].systemNotificationManager addDelegate:self];
[self requestHttp];
[self initSubViews];
[self initSubViewConstraints];
}
- (BOOL)isHiddenNavBar {
return YES;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self hideNavigationBar];
if (self.needUpdateUserInfo) {
[self.presenter getUserInfo];
}
if([XPSkillCardPlayerManager shareInstance].isInRoom == YES && [XPSkillCardPlayerManager shareInstance].isInRoomFirstRecharge == NO){
[XPSkillCardPlayerManager shareInstance].isInRoomFirstRecharge = YES;
}
}
- (XPNobleCenterPresenter *)createPresenter {
return [[XPNobleCenterPresenter alloc] init];
}
#pragma mark - Private Method
- (void)initSubViews {
self.view.backgroundColor = UIColorFromRGB(0x221E13);
[self.view addSubview:self.headBGImgeView];
[self.view addSubview:self.navView];
[self.view addSubview:self.titleView];
[self.view addSubview:self.lineView];
[self.view addSubview:self.openNobleView];
[self.view addSubview:self.myNobleView];
[self.openNobleView addSubview:self.openNobleIconView];
[self.openNobleView addSubview:self.openNobleButton];
[self.view addSubview:self.rankBtn];
}
- (void)initSubViewConstraints {
CGFloat height = KScreenWidth * 410 / 375.0;
[self.headBGImgeView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.top.trailing.mas_equalTo(self.view);
make.height.mas_equalTo(height);
}];
[self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.top.mas_equalTo(self.view);
make.height.mas_equalTo(kNavigationHeight);
}];
[self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.mas_equalTo(self.view);
make.height.mas_equalTo(40);
make.top.mas_equalTo(self.navView.mas_bottom);
}];
[self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.bottom.mas_equalTo(self.view);
make.top.mas_equalTo(self.titleView.mas_bottom);
}];
[self.openNobleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.view);
make.bottom.mas_equalTo(-kSafeAreaBottomHeight - 5);
make.width.mas_equalTo(300);
make.height.mas_equalTo(44);
}];
[self.openNobleButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_lessThanOrEqualTo(258);
make.centerX.equalTo(self.openNobleView);
make.top.bottom.equalTo(self.openNobleView);
}];
[self.myNobleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(91+kSafeAreaBottomHeight);
make.leading.bottom.trailing.mas_equalTo(0);
}];
[self.openNobleIconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(20);
make.centerY.equalTo(self.openNobleView);
make.trailing.equalTo(self.openNobleButton.mas_leading).mas_offset(-2);
}];
[self.rankBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(57);
make.height.mas_equalTo(24);
make.trailing.mas_equalTo(-24);
make.top.mas_equalTo(139);
}];
}
#pragma mark - XPNobleCenterPayViewDelegate
- (void)payWithType:(NobleCenterPayType)type{
if(type == NobleCenterPayType_diamond){
if(self.infoModel.diamonds.integerValue < 2990){
TTAlertConfig *config = [[TTAlertConfig alloc]init];
config.message = YMLocalizedString(@"XPNobleCenterViewController3");
config.actionStyle = TTAlertActionBothStyle;
[TTPopup alertWithConfig:config showBorder:NO confirmHandler:^{
XPWebViewController * webVC =[[XPWebViewController alloc] init];
webVC.url = [NSString stringWithFormat:URLWithType(kThirdPartyPay),@"5",[YYUtility deviceID]];
webVC.isPush = YES;
[self.navigationController pushViewController:webVC animated:YES];
} cancelHandler:^{
}];
return;
}
NSString *roomUid = self.roomUid > 0 ? @(self.roomUid).stringValue : @(self.userInfo.uid).stringValue;
[self.presenter openVipWithDiamondRoomUid:roomUid];
return;
}
XPWebViewController * webVC =[[XPWebViewController alloc] init];
webVC.url = [NSString stringWithFormat:URLWithType(kThirdPartyPay),@"5",[YYUtility deviceID]];
webVC.isPush = YES;
[self.navigationController pushViewController:webVC animated:YES];
}
-(void)openVipWithDiamondSuccess{
[self requestHttp];
}
-(void)openVipWithDiamondFail{
}
///请求贵族中心数据
- (void)requestHttp {
[self.presenter getUserInfo];
[self checkTranscationIds];
[self.presenter getNobleChargeProductListWithChannelType:@"9"];
NSString * uid = [AccountInfoStorage instance].getUid;
NSString * ticket = [AccountInfoStorage instance].getTicket;
[Api getUserWalletInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if(code == 200){
WalletInfoModel * model = [WalletInfoModel modelWithDictionary:data.data];
self.infoModel = model;
}
} uid:uid ticket:ticket];
}
///批量验证
- (void)checkTranscationIds {
NSString * uid = [AccountInfoStorage instance].getUid;
NSArray * array = [RechargeStorage getAllReciptsWithUid:uid];
if (array.count > 0) {
[self.presenter checkTranscationIds:array];
}
}
#pragma mark - XPNobleCenterProtocol
///获取用户信息成功
- (void)onGetUserInfoSuccess:(UserInfoModel *)userInfo {
self.userInfo = userInfo;
self.needUpdateUserInfo = NO;
[self.presenter getNobleCenterInfo];
}
- (void)getNobleCenterInfoSuccess:(NobleCenterModel *)model {
self.model = model;
__block NSMutableArray<NSString *> *names = [NSMutableArray array];
NSInteger defaultSelectIndex = 0;
for (int index = 0; index < model.vipInfos.count; index++) {
NobleInfo *tagInfo = [model.vipInfos safeObjectAtIndex1:index];
[names addObject:tagInfo.vipName];
if (tagInfo.vipLevel == model.currLevel) {
defaultSelectIndex = index;
}
}
self.titles = names.copy;
self.titleView.titles = self.titles;
self.openNobleView.hidden = self.userInfo.userVipInfoVO.vipLevel;
self.myNobleView.hidden = !self.userInfo.userVipInfoVO.vipLevel;
if (self.userInfo.userVipInfoVO) {
self.myNobleView.model = model;
}
self.titleView.defaultSelectedIndex = defaultSelectIndex;
[self.titleView reloadData];
[self.lineView reloadData];
self.navView.hideSettingBtn = self.model.currLevel < 9;
}
///获取贵族充值信息成功
- (void)onGetNobleRechargeDataSuccess:(NobleRechargeModel *)rechargeInfo {
self.rechargeModel = rechargeInfo;
if (self.rechargeModel.list.count == 0)return;
RechargeListModel *rechargeModel = [self.rechargeModel.list safeObjectAtIndex1:0];
NSString *title = [NSString stringWithFormat:YMLocalizedString(@"XPNobleCenterViewController0"), rechargeModel.money];
self.openNobleButton.text = title;
}
-(void)rankAction{
XPWebViewController * webVC =[[XPWebViewController alloc] init];
webVC.url = URLWithType(kNobleRankURL);
[self.navigationController pushViewController:webVC animated:YES];
}
#pragma mark - JXCategoryViewDelegate
- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
return self.titles.count;
}
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
XPNobleCenterListViewController *VC = [[XPNobleCenterListViewController alloc] init];
VC.isOpenNoble = self.userInfo.userVipInfoVO.vipLevel;
NobleInfo *vipInfo = [self.model.vipInfos safeObjectAtIndex1:index];
VC.vipInfo = vipInfo;
if (vipInfo.comingSoon != 2) {
VC.vipAuthInfos = [[NSMutableArray alloc]initWithArray:self.model.vipAuthInfos];
VC.isCurrentLevel = self.userInfo.userVipInfoVO.vipLevel == vipInfo.vipLevel;
VC.currentScore = self.model.currScore;
}
return VC;
}
// 点击选中或者滚动选中都会调用该方法。适用于只关心选中事件,不关心具体是点击还是滚动选中的。
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
// 侧滑手势处理
self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
}
#pragma mark -NIMSystemNotificationManagerDelegate
- (void)onReceiveCustomSystemNotification:(NIMCustomSystemNotification *)notification {
if (notification.receiverType == NIMSessionTypeP2P) {
if (notification.content != nil) {
NSData *jsonData = [notification.content dataUsingEncoding:NSUTF8StringEncoding];
NSError *err;
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
if(err) {
NSLog(@"json解析失败%@",err);
return;
}
if ([dic[@"first"] intValue] == CustomMessageType_Noble_VIP && [dic[@"second"] intValue] == Custom_Message_Sub_Open_Noble_Success) { // 开通贵族成功
[self.presenter getUserInfo];
}
}
}
}
#pragma mark - XPNobleCenterNavViewDelegate
- (void)xPNobleCenterNavView:(XPNobleCenterNavView *)view didClickBackButton:(UIButton *)sender {
[self.navigationController popViewControllerAnimated:YES];
}
- (void)xPNobleCenterNavView:(XPNobleCenterNavView *)view didClickHelpButton:(UIButton *)sender {
XPWebViewController * webVC =[[XPWebViewController alloc] init];
webVC.url = URLWithType(kNobleRuleURL);
[self.navigationController pushViewController:webVC animated:YES];
}
- (void)xPNobleCenterNavView:(XPNobleCenterNavView *)view didClickSettingButton:(UIButton *)sender {
XPNobleSettingViewController * settingVC =[[XPNobleSettingViewController alloc] init];
settingVC.enterHide = self.userInfo.userVipInfoVO.enterHide;
settingVC.didUpdateEnterHideBlock = ^{
self.needUpdateUserInfo = YES;
};
[self.navigationController pushViewController:settingVC animated:YES];
}
#pragma mark - events
- (void)onOpenNobleButtonClick {
XPNobleCenterPayView *payView = [[XPNobleCenterPayView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
payView.diamonds = self.infoModel.diamonds;
payView.delegate = self;
[self.view addSubview:payView];
}
#pragma mark - Getters And Setters
- (JXCategoryTitleView *)titleView {
if (!_titleView) {
_titleView = [[JXCategoryTitleView alloc] init];
_titleView.delegate = self;
_titleView.titles = self.titles;
_titleView.titleColor = [DJDKMIMOMColor normalNobleTextColor];
_titleView.titleSelectedColor = [DJDKMIMOMColor hightNobleLightTextColor];
_titleView.titleFont = [UIFont systemFontOfSize:14];
_titleView.titleSelectedFont = [UIFont systemFontOfSize:14 weight:UIFontWeightSemibold];
_titleView.titleLabelAnchorPointStyle = JXCategoryTitleLabelAnchorPointStyleCenter;
_titleView.contentScrollViewClickTransitionAnimationEnabled = NO;
_titleView.defaultSelectedIndex = 0;
_titleView.listContainer = self.lineView;
JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
lineView.indicatorWidth = 26;
lineView.indicatorHeight = 3;
lineView.indicatorColor = UIColorFromRGB(0xFFD3A8);
lineView.verticalMargin = 0;
_titleView.indicators = @[lineView];
}
return _titleView;
}
- (JXCategoryListContainerView *)lineView {
if (!_lineView) {
_lineView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
_lineView.scrollView.backgroundColor = [UIColor clearColor];
_lineView.defaultSelectedIndex = 0;
_lineView.scrollView.scrollEnabled = NO;
}
return _lineView;
}
- (NSArray<NSString *> *)titles {
if (!_titles) {
_titles = @[];
}
return _titles;
}
- (XPNobleCenterListViewController *)nobleListView {
if (!_nobleListView) {
_nobleListView = [[XPNobleCenterListViewController alloc] init];
}
return _nobleListView;
}
- (UIImageView *)headBGImgeView {
if (!_headBGImgeView) {
_headBGImgeView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"nobleCenter_head_bg"]];
_headBGImgeView.contentMode = UIViewContentModeScaleAspectFit;
}
return _headBGImgeView;
}
- (XPNobleCenterNavView *)navView {
if (!_navView) {
_navView = [[XPNobleCenterNavView alloc] init];
_navView.delegate = self;
}
return _navView;
}
- (UILabel *)openNobleButton {
if (!_openNobleButton) {
NSString *title = [NSString stringWithFormat:YMLocalizedString(@"XPNobleCenterViewController0"), @"2.99"];
_openNobleButton = [UILabel new];
_openNobleButton.text = title;
_openNobleButton.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
_openNobleButton.textColor = [DJDKMIMOMColor mainTextColor];
_openNobleButton.numberOfLines = 0;
_openNobleButton.textAlignment = NSTextAlignmentCenter;
}
return _openNobleButton;
}
- (UIImageView *)openNobleView{
if (!_openNobleView){
_openNobleView = [UIImageView new];
_openNobleView.image = kImage(@"noble_open_btn_bg");
_openNobleView.userInteractionEnabled = YES;
_openNobleView.hidden = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onOpenNobleButtonClick)];
[_openNobleView addGestureRecognizer:tap];
}
return _openNobleView;
}
-(UIImageView *)openNobleIconView{
if (!_openNobleIconView){
_openNobleIconView = [UIImageView new];
_openNobleIconView.image = kImage(@"noble_open_btn");
}
return _openNobleIconView;
}
- (XPNobleCenterMyNobleView *)myNobleView {
if (!_myNobleView) {
_myNobleView = [[XPNobleCenterMyNobleView alloc] init];
_myNobleView.hidden = YES;
}
return _myNobleView;
}
- (UIButton *)rankBtn{
if(!_rankBtn){
_rankBtn = [UIButton new];
[_rankBtn setBackgroundImage:kImage(@"mine_noble_center_rank") forState:UIControlStateNormal];
[_rankBtn addTarget:self action:@selector(rankAction) forControlEvents:UIControlEventTouchUpInside];
}
return _rankBtn;
}
@end