Files
yuyin_ios/SweetParty/主类/RCMic/Room/Box/第二个转盘/Second_ZhuanPanView.m
2025-08-08 11:05:33 +08:00

283 lines
10 KiB
Objective-C
Executable File

//
// Second_ZhuanPanView.m
// QiaoYuYueWan
//
// Created by 翟三美 on 2020/10/19.
// Copyright © 2020 QiaoYuYueWan. All rights reserved.
//
#import "Second_ZhuanPanView.h"
#import "BJBoxPoolAlert.h"
#import "BJBoxRankAlert.h"
#import "BJBoxRuleAlert.h"
#import "BJBoxRecordAlert.h"
#import "BJBoxResultAlert.h"
#import "BJBoxAwardModel.h"
#import "SPOpenConfirmAlert.h"
@interface Second_ZhuanPanView ()<SecondTurntableViewDelegate>
@property (strong, nonatomic) IBOutlet UILabel *moneyLab;
@property (weak, nonatomic) IBOutlet UILabel *oneBtnLab;
@property (weak, nonatomic) IBOutlet UILabel *tenBtnLab;
@property (weak, nonatomic) IBOutlet UILabel *baiBtnLab;
@property (weak, nonatomic) IBOutlet UILabel *singlePriceLab;
@property (weak, nonatomic) IBOutlet UIButton *startBtn;
@property (nonatomic, strong) RCMicRoomViewModel *viewModel;
@property(nonatomic, assign) NSInteger boxType;
@property(nonatomic, assign) NSInteger currentTimes; //当前要抽的次数
@property (nonatomic, strong) BJBoxResultAlert *resultView;
@property(nonatomic, strong) NSArray *listModel; /*结果数据源*/
@property(nonatomic, assign) NSInteger coin_value_1;
@property(nonatomic, strong) NSDictionary *resultDic;
@property(nonatomic, strong) NSDictionary *paramsDic;
@end
@implementation Second_ZhuanPanView
+ (Second_ZhuanPanView *)initBoxWith:(RCMicRoomViewModel *)model {
Second_ZhuanPanView *view = LoadNib(NSStringFromClass(Second_ZhuanPanView.class));
view.frame = UIScreen.mainScreen.bounds;
view.backgroundColor = HEXCOLORA(0x000000, 0.6);
view.viewModel = model;
[view initSubView];
return view;
}
- (void)initSubView {
self.boxType = 21;
self.currentTimes = 1;
_coin_value_1 = BJPassData.sharedBJPassData.boxValue_6;
[self onChangePriceLab];
//获取宝箱信息,余额情况
[self loadData];
//转盘
[self.whiteView addSubview:self.turntable];
self.turntable.delegate = self;
[self.turntable loadPoolDataWithType:self.boxType];
__weak __typeof(self)weakSelf = self;
//抽一次
[self.oneBtn buttonAddTaget:^(UIButton *btn) {
weakSelf.currentTimes = 1;
[weakSelf.oneBtn setImage:ImageNamed(@"sec_zhuan_1_s") forState:UIControlStateNormal];
[weakSelf.tenBtn setImage:ImageNamed(@"sec_zhuan_10") forState:UIControlStateNormal];
[weakSelf.baiBtn setImage:ImageNamed(@"sec_zhuan_100") forState:UIControlStateNormal];
} forControlEvents:UIControlEventTouchUpInside];
//抽十次
[self.tenBtn buttonAddTaget:^(UIButton *btn) {
weakSelf.currentTimes = 10;
[weakSelf.oneBtn setImage:ImageNamed(@"sec_zhuan_1") forState:UIControlStateNormal];
[weakSelf.tenBtn setImage:ImageNamed(@"sec_zhuan_10_s") forState:UIControlStateNormal];
[weakSelf.baiBtn setImage:ImageNamed(@"sec_zhuan_100") forState:UIControlStateNormal];
} forControlEvents:UIControlEventTouchUpInside];
//抽百次
[self.baiBtn buttonAddTaget:^(UIButton *btn) {
weakSelf.currentTimes = 100;
[weakSelf.oneBtn setImage:ImageNamed(@"sec_zhuan_1") forState:UIControlStateNormal];
[weakSelf.tenBtn setImage:ImageNamed(@"sec_zhuan_10") forState:UIControlStateNormal];
[weakSelf.baiBtn setImage:ImageNamed(@"sec_zhuan_100_s") forState:UIControlStateNormal];
} forControlEvents:UIControlEventTouchUpInside];
}
- (void)loadData
{
[RCMicHTTP postWithURLString:@"/api/user/get_user_money" parameters:@{} response:^(RCMicHTTPResult *result) {
[SVProgressHUD dismiss];
if (result.success) {
if (result.errorCode == 200 && [result.content isKindOfClass:NSDictionary.class]) {
NSString *moneyText = [result.content safeStringForKey:@"integral"];
self.moneyLab.text = NSStringFormat(@"%@",moneyText);
}else {
[SVProgressHUD showInfoWithStatus:result.message];
}
}else {
[SVProgressHUD showInfoWithStatus:@"网络错误"];
}
}];
}
-(void)onChangePriceLab {
NSInteger singlePrice = 0;
if (self.boxType == 21) {
singlePrice = _coin_value_1;
}
NSString *priceText = [NSString stringWithFormat:@"%ld金币/次,连开几率更高", singlePrice];
self.singlePriceLab.text = priceText;
self.oneBtnLab.text = [NSString stringWithFormat:@"%ld", singlePrice];
self.tenBtnLab.text = [NSString stringWithFormat:@"%ld", singlePrice*10];
self.baiBtnLab.text = [NSString stringWithFormat:@"%ld", singlePrice*100];
}
#pragma mark - public
- (void)showOnView:(nullable UIView *)parent {
if (parent) {
[parent addSubview:self];
}else {
[MainWindow() addSubview:self];
}
}
#pragma mark - 4个按钮
- (void)buttonClickMethod:(NSInteger)tag {
switch (tag) {
case 600:{
//说明
BJBoxRuleAlert *view = [[BJBoxRuleAlert alloc] initWithFrame:UIScreen.mainScreen.bounds];
[view showOnView:UIViewController.currentViewController.view WithType:_boxType];
}break;
case 601:{
BJBoxPoolAlert *view = [[BJBoxPoolAlert alloc] initWithFrame:CGRectZero];
[view showOnView:UIViewController.currentViewController.view WithType:_boxType];
}break;
case 602:{
//中奖记录
BJBoxRecordAlert *view = [[BJBoxRecordAlert alloc] initWithFrame:CGRectZero];
view.frame = UIScreen.mainScreen.bounds;
[view showOnView:UIViewController.currentViewController.view WithType:_boxType];
}break;
case 603:{
BJBoxRankAlert *view = [[BJBoxRankAlert alloc] initWithFrame:CGRectZero];
[view showOnView:UIViewController.currentViewController.view roomId:_viewModel.roomInfo.roomId WithType:_boxType];
}break;
default:
break;
}
}
- (void)openBoxWithTimes:(NSInteger )keysNum {
self.resultView.hidden = YES;
NSDictionary *dict = @{@"open_num":@(keysNum),
@"bs":@(0), //没啥用
@"tid":@(_boxType).stringValue,
@"rid":C_string(_viewModel.roomInfo.roomId)};
NSMutableDictionary *paras = [NSMutableDictionary dictionary];
[paras addEntriesFromDictionary:dict];
[RCMicHTTP postWithURLString:@"/api/box/open_box" parameters:paras response:^(RCMicHTTPResult *result) {
[SVProgressHUD dismiss];
if (result.success) {
if (result.errorCode == 200 && [result.content isKindOfClass:NSDictionary.class]) {
//奖品、价值、余额
NSString *leftMoney = [result.content safeStringForKey:@"user_money"];
self.moneyLab.text = NSStringFormat(@"%@", leftMoney);
self.resultDic = result.content;
self.paramsDic = paras;
NSArray *winGiftArr = [result.content safeArrayForKey:@"win_gift_list"];
NSArray *giftArr = [BJBoxAwardModel mj_objectArrayWithKeyValuesArray:winGiftArr];
if (giftArr.count > 0) {
BJBoxAwardModel *bigestObj = giftArr.firstObject;
for (BJBoxAwardModel *obj in giftArr) {
if ([obj.gift_price doubleValue] > [bigestObj.gift_price doubleValue]) {
bigestObj = obj;
}
}
[self.turntable startAnimationWithResultGid:bigestObj.gid];
}
}else {
[SVProgressHUD showInfoWithStatus:result.message];
self.startBtn.userInteractionEnabled = YES;
}
}else {
[SVProgressHUD showInfoWithStatus:@"网络错误"];
self.startBtn.userInteractionEnabled = YES;
}
}];
}
- (IBAction)startZhuanPan:(id)sender {
[self openBoxWithTimes:self.currentTimes];
self.startBtn.userInteractionEnabled = NO;
// NSString *keyStr = [NSString stringWithFormat:@"close_open_tips_%ld", self.boxType];
// if ([[NSUserDefaults standardUserDefaults] boolForKey:keyStr]) {
// [self openBoxWithTimes:self.currentTimes];
// self.startBtn.userInteractionEnabled = NO;
// }else {
// NSInteger onePrice = _coin_value_1;
// SPOpenConfirmAlert *alert = [[NSBundle mainBundle] loadNibNamed:@"SPOpenConfirmAlert" owner:self options:nil].firstObject;
// alert.frame = [UIScreen mainScreen].bounds;
// [alert onShowWithType:self.boxType price:(onePrice*self.currentTimes)];
// WEAK_SELF
// alert.onConfirmBlock = ^{
// [weakSelf openBoxWithTimes:weakSelf.currentTimes];
// weakSelf.startBtn.userInteractionEnabled = NO;
// };
// }
}
//转盘停止转动代理方法
- (void)turnTableViewDidFinish {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.resultView.hidden = NO;
self.startBtn.userInteractionEnabled = YES;
//为了转盘转完再出震动和大礼物
[self.resultView showOnView:self WithResult:self.resultDic withPara:self.paramsDic withType:self.boxType];
});
}
//关闭
- (IBAction)closeMethod:(id)sender {
[self removeFromSuperview];
}
//规则说明
- (IBAction)shuomingMethod:(id)sender {
[self buttonClickMethod:600];
}
//中奖纪录
- (IBAction)zhongJiangJiLuMethod:(id)sender {
[self buttonClickMethod:602];
}
//手气榜
- (IBAction)shouqiBangMethod:(id)sender {
[self buttonClickMethod:603];
}
//本期奖池
- (IBAction)benQiJiangChiMethod:(id)sender {
[self buttonClickMethod:601];
}
#pragma mark ====================== 懒加载 ======================
- (BJBoxResultAlert *)resultView{
if (!_resultView) {
_resultView = [[BJBoxResultAlert alloc] initWithFrame:CGRectZero];
WEAK_SELF
_resultView.refreshCoinBlock = ^(NSString * _Nonnull leftMoney) {
weakSelf.moneyLab.text = NSStringFormat(@"%@", leftMoney);
};
_resultView.tryAgainBlock = ^{
[weakSelf openBoxWithTimes:weakSelf.currentTimes];
};
}
return _resultView;
}
- (SecondTurntableView *)turntable{
if (!_turntable) {
_turntable = [[SecondTurntableView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
}
return _turntable;
}
@end