修改了礼物面板请求失败的话可以重试

This commit is contained in:
fengshuo
2022-03-22 20:53:20 +08:00
parent 3b792698f0
commit 1f3ba5bac3
12 changed files with 161 additions and 42 deletions

View File

@@ -6,7 +6,7 @@
//
#import "GiftInfoModel.h"
#import "MJExtension.h"
@implementation GiftInfoModel
MJCodingImplementation
@end

View File

@@ -6,7 +6,7 @@
//
#import "GiftNobleInfoModel.h"
#import "MJExtension.h"
@implementation GiftNobleInfoModel
MJCodingImplementation
@end

View File

@@ -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];
}

View File

@@ -26,6 +26,10 @@ NS_ASSUME_NONNULL_BEGIN
/// 获取当前房间的数据中的礼物
/// @param giftId 礼物的id
- (GiftInfoModel *)findGiftInfo:(NSString *)giftId;
///礼物数据写入本地
- (void)writeGiftToDirectory:(NSArray *)array;
@end
NS_ASSUME_NONNULL_END

View File

@@ -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

View File

@@ -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;
///送礼物失败

View File

@@ -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);
}];

View File

@@ -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;
/// 送礼物的

View File

@@ -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];