修改了礼物面板请求失败的话可以重试
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
//
|
||||
|
||||
#import "GiftInfoModel.h"
|
||||
|
||||
#import "MJExtension.h"
|
||||
@implementation GiftInfoModel
|
||||
|
||||
MJCodingImplementation
|
||||
@end
|
||||
|
@@ -6,7 +6,7 @@
|
||||
//
|
||||
|
||||
#import "GiftNobleInfoModel.h"
|
||||
|
||||
#import "MJExtension.h"
|
||||
@implementation GiftNobleInfoModel
|
||||
|
||||
MJCodingImplementation
|
||||
@end
|
||||
|
@@ -51,15 +51,25 @@
|
||||
NSArray * arrary = [[XPGiftStorage shareStorage] getGiftDatasource:roomUid];
|
||||
if (arrary.count > 0) {
|
||||
[[self getView] getNormalGiftListSuccess:arrary];
|
||||
return;
|
||||
}
|
||||
|
||||
[Api requestNormalGiftList:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
||||
NSArray * info = [GiftInfoModel modelsWithArray:data.data[@"gift"]];
|
||||
[Api requestNormalGiftList:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
||||
NSArray *luckyBagGift = [GiftInfoModel modelsWithArray:data.data[@"luckyBagGift"]]; // 福袋礼物
|
||||
NSArray *vipGift = [GiftInfoModel modelsWithArray:data.data[@"vipGift"]]; // 贵族礼物
|
||||
NSArray *luckyPoolGift = [GiftInfoModel modelsWithArray:data.data[@"luckyPoolGift"]];// 福袋奖池礼物
|
||||
NSArray *normalGift = [GiftInfoModel modelsWithArray:data.data[@"normalGift"]]; // 普通面板礼物
|
||||
NSMutableArray *info = [NSMutableArray array];
|
||||
[info addObjectsFromArray:luckyBagGift];
|
||||
[info addObjectsFromArray:vipGift];
|
||||
[info addObjectsFromArray:luckyPoolGift];
|
||||
[info addObjectsFromArray:normalGift];
|
||||
///把礼物信息保存一下
|
||||
[[XPGiftStorage shareStorage] saveGiftDatasource:info roomUid:roomUid];
|
||||
[[XPGiftStorage shareStorage] writeGiftToDirectory:info];
|
||||
[[self getView] getNormalGiftListSuccess:info];
|
||||
} roomUid:roomUid];
|
||||
}fail:^(NSInteger code, NSString * _Nullable msg) {
|
||||
[[self getView] getNormalGiftListFail:msg];
|
||||
}] roomUid:roomUid];
|
||||
}
|
||||
|
||||
|
||||
@@ -67,10 +77,12 @@
|
||||
- (void)getPackGiftList {
|
||||
NSString * uid = [AccountInfoStorage instance].getUid;
|
||||
NSString * ticket = [AccountInfoStorage instance].getTicket;
|
||||
[Api requestPackGiftList:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
||||
[Api requestPackGiftList:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
||||
NSArray * info = [GiftInfoModel modelsWithArray:data.data];
|
||||
[[self getView] getPacketGiftListSuccess:info];
|
||||
} uid:uid ticket:ticket];
|
||||
}fail:^(NSInteger code, NSString * _Nullable msg) {
|
||||
[[self getView] getPacketGiftListFail:msg];
|
||||
}] uid:uid ticket:ticket];
|
||||
}
|
||||
|
||||
|
||||
|
@@ -26,6 +26,10 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
/// 获取当前房间的数据中的礼物
|
||||
/// @param giftId 礼物的id
|
||||
- (GiftInfoModel *)findGiftInfo:(NSString *)giftId;
|
||||
|
||||
///礼物数据写入本地
|
||||
- (void)writeGiftToDirectory:(NSArray *)array;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
@@ -7,12 +7,15 @@
|
||||
|
||||
#import "XPGiftStorage.h"
|
||||
#import "GiftInfoModel.h"
|
||||
#import "NSObject+MJExtension.h"
|
||||
|
||||
@interface XPGiftStorage ()
|
||||
///key:房间id value:房间对应的礼物列表
|
||||
@property (nonatomic, strong) NSCache<NSString *, NSArray<GiftInfoModel *> *> *roomGiftCache;
|
||||
///当前房间的uid
|
||||
@property (nonatomic,copy) NSString *currentRoomUid;
|
||||
///
|
||||
@property (nonatomic,assign) BOOL isWriteToFile;
|
||||
@end
|
||||
|
||||
@implementation XPGiftStorage
|
||||
@@ -47,6 +50,11 @@
|
||||
/// 获取当前房间的数据中的礼物
|
||||
/// @param giftId 礼物的id
|
||||
- (GiftInfoModel *)findGiftInfo:(NSString *)giftId {
|
||||
GiftInfoModel * giftInfo = [self getGiftInfoFromDirectory:giftId];
|
||||
if (giftInfo) {
|
||||
return giftInfo;
|
||||
}
|
||||
|
||||
if (self.currentRoomUid) {
|
||||
NSArray<GiftInfoModel *> *giftLists = [self.roomGiftCache objectForKey:self.currentRoomUid];
|
||||
if (giftLists.count > 0) {
|
||||
@@ -73,4 +81,44 @@
|
||||
return _roomGiftCache;
|
||||
}
|
||||
|
||||
- (void)writeGiftToDirectory:(NSArray *)array {
|
||||
///因为不想每次都要大量的IO操作 就保存一份吧
|
||||
if (self.isWriteToFile) {
|
||||
return;
|
||||
}
|
||||
NSString * path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
|
||||
NSString * giftDirPath = [path stringByAppendingPathComponent:@"Gift"];
|
||||
//判断有没有文件夹
|
||||
BOOL isDir =NO;
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
BOOL existed = [fileManager fileExistsAtPath:giftDirPath isDirectory:&isDir];
|
||||
if ( !(isDir ==YES && existed == YES) ){
|
||||
//如果没有文件夹则创建
|
||||
[fileManager createDirectoryAtPath:giftDirPath withIntermediateDirectories:YES attributes:nil error:nil];
|
||||
}
|
||||
for (int i = 0; i< array.count; i++) {
|
||||
GiftInfoModel * giftInfoModel = [array objectAtIndex:i];
|
||||
NSString *giftPath = [giftDirPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%ld", giftInfoModel.giftId]];
|
||||
[NSKeyedArchiver archiveRootObject:giftInfoModel.model2dictionary toFile:giftPath];
|
||||
}
|
||||
self.isWriteToFile = YES;
|
||||
}
|
||||
|
||||
- (GiftInfoModel *)getGiftInfoFromDirectory:(NSString *)giftId {
|
||||
//找到相应的目录
|
||||
NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
|
||||
NSString *pathFile = [path stringByAppendingPathComponent:@"Gift"];
|
||||
//判断有没有文件夹
|
||||
BOOL isDir =NO;
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
BOOL existed = [fileManager fileExistsAtPath:pathFile isDirectory:&isDir];
|
||||
GiftInfoModel * giftInfo;
|
||||
if (existed) {
|
||||
NSString *aPath = [pathFile stringByAppendingPathComponent:giftId];
|
||||
NSDictionary * dic = [NSKeyedUnarchiver unarchiveObjectWithFile:aPath];
|
||||
giftInfo = [GiftInfoModel modelWithDictionary:dic];
|
||||
}
|
||||
return giftInfo;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@@ -13,8 +13,12 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
- (void)getUserWalletInfo:(WalletInfoModel *)balanceInfo;
|
||||
///获取普通礼物列表
|
||||
- (void)getNormalGiftListSuccess:(NSArray<GiftInfoModel *> *)giftList;
|
||||
///获取普通礼物列表失败
|
||||
- (void)getNormalGiftListFail:(NSString *)message;
|
||||
///获取背包礼物列表
|
||||
- (void)getPacketGiftListSuccess:(NSArray<GiftInfoModel *> *)giftList;
|
||||
///获取背包礼物列表失败
|
||||
- (void)getPacketGiftListFail:(NSString *)message;
|
||||
///送礼物成功
|
||||
- (void)sendGiftSuccess:(GiftReceiveInfoModel *)receiveInfo originDic:(NSDictionary *)originDic uidCount:(NSInteger)uidCount;
|
||||
///送礼物失败
|
||||
|
@@ -141,12 +141,6 @@
|
||||
make.height.mas_equalTo(108 * 2 + 20);
|
||||
}];
|
||||
|
||||
|
||||
[self.giftcollectionView
|
||||
mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.height.mas_equalTo(108 * 2 + 10);
|
||||
}];
|
||||
|
||||
[self.pageController mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.height.mas_equalTo(10);
|
||||
}];
|
||||
|
@@ -5,7 +5,7 @@
|
||||
// Created by 冯硕 on 2021/11/9.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "MvpViewController.h"
|
||||
#import "RoomHostDelegate.h"
|
||||
#import "XPGiftUserInfoModel.h"
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
@@ -14,7 +14,7 @@ typedef NS_ENUM(NSInteger, SendGiftType) {
|
||||
SendGiftType_User, ///送给某一个人
|
||||
};
|
||||
|
||||
@interface XPSendGiftView : UIView
|
||||
@interface XPSendGiftView : MvpViewController
|
||||
///房间内才需要
|
||||
@property (nonatomic,weak) id<RoomHostDelegate> delegate;
|
||||
/// 送礼物的
|
||||
|
@@ -14,7 +14,6 @@
|
||||
#import "XPGiftPresenter.h"
|
||||
#import "TTPopup.h"
|
||||
#import "ThemeColor+SendGift.h"
|
||||
#import "XCHUDTool.h"
|
||||
#import "StatisticsServiceHelper.h"
|
||||
///Model
|
||||
#import "GiftInfoModel.h"
|
||||
@@ -36,6 +35,10 @@
|
||||
#import "XPNobleCenterViewController.h"
|
||||
|
||||
@interface XPSendGiftView ()< XPGiftBarViewDelegate, XPGiftProtocol, XPGiftInfoViewDelegate>
|
||||
///顶部的区域
|
||||
@property (nonatomic,strong) UIView * topView;
|
||||
///内容区域
|
||||
@property (nonatomic,strong) UIView *contentView;
|
||||
///
|
||||
@property (nonatomic,strong) UIStackView *stackView;
|
||||
///送礼物的人
|
||||
@@ -50,7 +53,10 @@
|
||||
@property (nonatomic,copy) NSString *roomUid;
|
||||
///使用的地方
|
||||
@property (nonatomic,assign) SendGiftType usingplaceType;
|
||||
|
||||
///普通礼物的重试次数
|
||||
@property (nonatomic,assign) int normalGiftRetryCount;
|
||||
///背包礼物的重试次数
|
||||
@property (nonatomic,assign) int packGiftRetryCount;
|
||||
@end
|
||||
|
||||
@implementation XPSendGiftView
|
||||
@@ -60,32 +66,42 @@
|
||||
|
||||
- (instancetype)initWithType:(SendGiftType)type uid:(NSString *)uid{
|
||||
if (self = [super init]) {
|
||||
self.modalPresentationStyle = UIModalPresentationOverFullScreen;
|
||||
self.roomUid = uid;
|
||||
self.usingplaceType = type;
|
||||
[self initSubViews];
|
||||
[self initSubViewConstraints];
|
||||
[self initHttpRequest];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[self initSubViews];
|
||||
[self initSubViewConstraints];
|
||||
[self initHttpRequest];
|
||||
}
|
||||
|
||||
#pragma mark - Private Method
|
||||
- (void)initSubViews {
|
||||
self.backgroundColor = [ThemeColor giftBackGroundColor];
|
||||
[self addSubview:self.stackView];
|
||||
[self.view addSubview:self.topView];
|
||||
[self.view addSubview:self.contentView];
|
||||
[self.contentView addSubview:self.stackView];
|
||||
[self.stackView addArrangedSubview:self.userView];
|
||||
[self.stackView addArrangedSubview:self.giftInfoView];
|
||||
[self.stackView addArrangedSubview:self.giftBarView];
|
||||
}
|
||||
|
||||
- (void)initSubViewConstraints {
|
||||
[self mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo(KScreenWidth);
|
||||
make.bottom.mas_equalTo(self.stackView.mas_bottom);
|
||||
[self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.right.top.mas_equalTo(self.view);
|
||||
make.bottom.mas_equalTo(self.contentView.mas_top);;
|
||||
}];
|
||||
|
||||
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self.stackView.mas_top);
|
||||
make.left.right.bottom.mas_equalTo(self.view);
|
||||
}];
|
||||
|
||||
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.right.top.mas_equalTo(self);
|
||||
make.left.right.bottom.mas_equalTo(self.contentView);
|
||||
}];
|
||||
}
|
||||
|
||||
@@ -236,13 +252,13 @@
|
||||
RoomSendGiftType roomSendGiftType;
|
||||
if (self.userView.isSelectAll) {
|
||||
if (giftInfo.sourceType == GiftSourceType_Pack && giftCount.isTotal && giftInfo && uids.count > 1) {
|
||||
[XCHUDTool showErrorWithMessage:@"只能全部赠送给一人"];
|
||||
[self showErrorToast:@"只能全部赠送给一人"];
|
||||
return -1;
|
||||
}
|
||||
roomSendGiftType = RoomSendGiftType_AllMic;
|
||||
} else if(self.userView.selectUserArray.count > 1) {
|
||||
if (giftInfo.sourceType == GiftSourceType_Pack && giftCount.isTotal) {
|
||||
[XCHUDTool showErrorWithMessage:@"只能全部赠送给一人"];
|
||||
[self showErrorToast:@"只能全部赠送给一人"];
|
||||
return -1;
|
||||
}
|
||||
roomSendGiftType = RoomSendGiftType_MutableOnMic;
|
||||
@@ -283,7 +299,7 @@
|
||||
///发送消息
|
||||
[self.giftPresenter sendGift:uidString giftNum:giftNumber sendType:sendType giftId:giftId giftSource:sourceType giftType:giftInfo.giftType roomSendType:roomSendType roomUid:self.roomUid msg:@""];
|
||||
} else {
|
||||
[XCHUDTool showErrorWithMessage:@"请选择至少一个人"];
|
||||
[self showErrorToast:@"请选择至少一个人"];
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -292,20 +308,20 @@
|
||||
|
||||
///充值
|
||||
- (void)xPGiftBarViewDidClickRecharge:(XPGiftBarView *)view {
|
||||
[TTPopup dismiss];
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
XPMineRechargeViewController * rechargeVC = [[XPMineRechargeViewController alloc] init];
|
||||
[self.delegate.getCurrentNav pushViewController:rechargeVC animated:YES];
|
||||
}
|
||||
|
||||
- (void)xPGiftBarViewDidClickFirstRecharge:(XPGiftBarView *)view {
|
||||
[TTPopup dismiss];
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
XPFirstRechargeViewController * firstRechargeVC = [[XPFirstRechargeViewController alloc] initWithNavigation:self.delegate.getCurrentNav];
|
||||
[self.delegate.getCurrentNav presentViewController:firstRechargeVC animated:YES completion:nil];
|
||||
}
|
||||
|
||||
#pragma mark - XPGiftInfoViewDelegate
|
||||
- (void)xPGiftInfoView:(XPGiftInfoView *)view didClickPlayRule:(NSString *)ruleUrl {
|
||||
[TTPopup dismiss];
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
XPWebViewController * webVC = [[XPWebViewController alloc] init];
|
||||
webVC.url = ruleUrl;
|
||||
[self.delegate.getCurrentNav pushViewController:webVC animated:YES];
|
||||
@@ -316,7 +332,7 @@
|
||||
}
|
||||
|
||||
- (void)xPGiftInfoViewDidClickNobleEntrance:(XPGiftInfoView *)view {
|
||||
[TTPopup dismiss];
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
[StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventvipEntranceGiftClick];
|
||||
XPNobleCenterViewController * nobleVC = [[XPNobleCenterViewController alloc] initWithRoomUid:self.delegate.getRoomInfo.uid];
|
||||
[self.delegate.getCurrentNav pushViewController:nobleVC animated:YES];
|
||||
@@ -331,11 +347,29 @@
|
||||
self.giftInfoView.packOriginArray = giftList;
|
||||
}
|
||||
|
||||
- (void)getPacketGiftListFail:(NSString *)message {
|
||||
self.packGiftRetryCount ++;
|
||||
if (self.packGiftRetryCount <= 10) {
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
[self.giftPresenter getPackGiftList];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
///普通礼物 /幸运礼物
|
||||
- (void)getNormalGiftListSuccess:(NSArray<GiftInfoModel *> *)giftList {
|
||||
self.giftInfoView.normalOriginArray = giftList;
|
||||
}
|
||||
|
||||
- (void)getNormalGiftListFail:(NSString *)message {
|
||||
self.normalGiftRetryCount ++;
|
||||
if (self.normalGiftRetryCount <= 10) {
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
[self.giftPresenter getNormalGiftList:self.roomUid];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
- (void)sendGiftSuccess:(GiftReceiveInfoModel *)receiveInfo originDic:(NSDictionary *)originDic uidCount:(NSInteger)uidCount{
|
||||
if (receiveInfo.sourceType == GiftSourceType_Pack) {
|
||||
///更新个数
|
||||
@@ -351,7 +385,6 @@
|
||||
if (code == 31005) {// 余额不足
|
||||
[self showNotSufficientFundsWithToast:msg];
|
||||
} else if (code == 8535) {//贵族等级未达到礼物等级
|
||||
[TTPopup dismiss];
|
||||
GiftInfoModel * giftInfo = self.giftInfoView.lastSelectGift;
|
||||
TTAlertConfig *config = [[TTAlertConfig alloc] init];
|
||||
config.actionStyle = TTAlertActionConfirmStyle;
|
||||
@@ -362,20 +395,24 @@
|
||||
|
||||
}];
|
||||
} else {
|
||||
[XCHUDTool showErrorWithMessage:msg];
|
||||
[self showErrorToast:msg];
|
||||
}
|
||||
}
|
||||
|
||||
/// 余额不足,是否弹首充弹窗
|
||||
- (void)showNotSufficientFundsWithToast:(NSString *)msg {
|
||||
if (self.delegate.getUserInfo.isFirstCharge) {
|
||||
[TTPopup dismiss];
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
XPFirstRechargeViewController * firstRechargeVC = [[XPFirstRechargeViewController alloc] initWithNavigation:self.delegate.getCurrentNav];
|
||||
[self.delegate.getCurrentNav presentViewController:firstRechargeVC animated:YES completion:nil];
|
||||
} else {
|
||||
[XCHUDTool showErrorWithMessage:msg];
|
||||
[self showErrorToast:msg];
|
||||
}
|
||||
}
|
||||
#pragma mark - Event Response
|
||||
- (void)disMissViewRecognizer:(UITapGestureRecognizer *)tap {
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
}
|
||||
|
||||
#pragma mark - Getters And Setters
|
||||
- (void)setDelegate:(id<RoomHostDelegate>)delegate {
|
||||
@@ -384,6 +421,25 @@
|
||||
self.giftInfoView.curUserNobleLevel = self.delegate.getUserInfo.userVipInfoVO.vipLevel;
|
||||
}
|
||||
|
||||
- (UIView *)topView {
|
||||
if (!_topView) {
|
||||
_topView = [[UIView alloc] init];
|
||||
_topView.backgroundColor = [UIColor clearColor];
|
||||
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(disMissViewRecognizer:)];
|
||||
[_topView addGestureRecognizer:tap];
|
||||
}
|
||||
return _topView;
|
||||
}
|
||||
|
||||
|
||||
- (UIView *)contentView {
|
||||
if (!_contentView) {
|
||||
_contentView = [[UIView alloc] init];
|
||||
_contentView.backgroundColor = [ThemeColor giftBackGroundColor];
|
||||
}
|
||||
return _contentView;
|
||||
}
|
||||
|
||||
- (XPGiftUsersView *)userView {
|
||||
if (!_userView) {
|
||||
_userView = [[XPGiftUsersView alloc] init];
|
||||
|
@@ -145,6 +145,7 @@
|
||||
[info addObjectsFromArray:normalGift];
|
||||
///把礼物信息保存一下
|
||||
[[XPGiftStorage shareStorage] saveGiftDatasource:info roomUid:roomUid];
|
||||
[[XPGiftStorage shareStorage] writeGiftToDirectory:info];
|
||||
} roomUid:roomUid];
|
||||
}
|
||||
|
||||
|
@@ -107,7 +107,7 @@
|
||||
giftView.delegate = self.delegate;
|
||||
NSArray * giftUses = [self configGiftUsers:[self.delegate getMicroQueue]];
|
||||
[giftView configGiftUsers:giftUses];
|
||||
[TTPopup popupView:giftView style:TTPopupStyleActionSheet];
|
||||
[self.delegate.getCurrentNav presentViewController:giftView animated:YES completion:nil];
|
||||
}
|
||||
break;
|
||||
case XPRoomMenuItemType_Message: {
|
||||
|
@@ -674,7 +674,7 @@
|
||||
giftView.delegate = self.cardInfo.delegate;
|
||||
NSArray *users = [self configGiftUsers:self.cardInfo.delegate.getMicroQueue];
|
||||
[giftView configGiftUsers:users];
|
||||
[TTPopup popupView:giftView style:TTPopupStyleActionSheet];
|
||||
[self.presentingViewController presentViewController:giftView animated:YES completion:nil];
|
||||
}
|
||||
break;
|
||||
case UserCardItemType_Attention:
|
||||
|
Reference in New Issue
Block a user