航海的逻辑的修改

This commit is contained in:
fengshuo
2022-08-15 15:14:38 +08:00
parent d46b04b6bf
commit d2bbdc7e65
14 changed files with 253 additions and 24 deletions

View File

@@ -21,6 +21,14 @@ NS_ASSUME_NONNULL_BEGIN
/// @param completion 完成
/// @param uid 用户的uid
+ (void)getSailingInfo:(HttpRequestHelperCompletion)completion uid:(NSString *)uid;
/// 开始航海
/// @param completion 完成
/// @param uid 用户的uid
/// @param keyNum 燃料数
/// @param sendMessage 是否发消息
/// @param roomUid 房间的uid
+ (void)openSailing:(HttpRequestHelperCompletion)completion uid:(NSString *)uid keyNum:(NSString *)keyNum sendMessage:(NSString *)sendMessage roomUid:(NSString *)roomUid;
@end
NS_ASSUME_NONNULL_END

View File

@@ -27,4 +27,15 @@
[self makeRequest:@"linearlyPool/userkey" method:HttpRequestHelperMethodGET completion:completion, uid, nil];
}
///
/// @param completion
/// @param uid uid
/// @param keyNum
/// @param sendMessage
/// @param roomUid uid
+ (void)openSailing:(HttpRequestHelperCompletion)completion uid:(NSString *)uid keyNum:(NSString *)keyNum sendMessage:(NSString *)sendMessage roomUid:(NSString *)roomUid {
[self makeRequest:@"" method:HttpRequestHelperMethodPOST completion:completion,__FUNCTION__, uid, keyNum, sendMessage, roomUid, nil];
}
@end

View File

@@ -11,7 +11,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface RoomSailingInfoModel : NSObject
///燃料的个数
@property (nonatomic, assign) int keyNum;
@property (nonatomic, assign) NSInteger keyNum;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,19 @@
//
// RoomSailingPrizeListModel.h
// xplan-ios
//
// Created by 冯硕 on 2022/8/15.
//
#import <Foundation/Foundation.h>
#import "RoomSailingPrizeModel.h"
NS_ASSUME_NONNULL_BEGIN
@interface RoomSailingPrizeListModel : NSObject
///奖品的数组
@property (nonatomic,strong) NSArray<RoomSailingPrizeModel *> *prizeItemList;
///剩余钥匙数
@property (nonatomic,assign) NSInteger remainKeyNum;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,15 @@
//
// RoomSailingPrizeListModel.m
// xplan-ios
//
// Created by on 2022/8/15.
//
#import "RoomSailingPrizeListModel.h"
@implementation RoomSailingPrizeListModel
+ (NSDictionary *)objectClassInArray {
return @{@"prizeItemList": RoomSailingPrizeModel.class};
}
@end

View File

@@ -0,0 +1,45 @@
//
// RoomSailingPrizeModel.h
// xplan-ios
//
// Created by 冯硕 on 2022/8/15.
//
#import <Foundation/Foundation.h>
typedef enum : NSUInteger {
SailingPrizeLevelOne=1,
SailingPrizeLevelTwo,
SailingPrizeLevelThree,
SailingPrizeLevelFour,
} SailingPrizeLevel;
//奖品类型。1-萌币2-礼物3-座驾4-头饰5-背景6-实物7-靓号8-全麦礼物
typedef NS_ENUM(NSUInteger, SailingPrizeType) {
SailingPrizeType_Gold = 1,
SailingPrizeType_Gift,
SailingPrizeType_Car,
SailingPrizeType_Headwear,
SailingPrizeType_Background,
SailingPrizeType_Matter,
SailingPrizeType_Beautif,
SailingPrizeType_WholeServer
};
NS_ASSUME_NONNULL_BEGIN
@interface RoomSailingPrizeModel : NSObject
@property (nonatomic, copy) NSString *prizeName;//奖品名称
@property (nonatomic, copy) NSString *prizeImgUrl;//奖品icon
@property (nonatomic, assign) SailingPrizeType prizeType;//奖品类型
@property (nonatomic, copy) NSString *prizeTypeDesc;//奖品类型描述
@property (nonatomic, assign) int prizeNum;//奖品数量
@property (nonatomic, assign) CGFloat platformValue;//价格
@property (nonatomic, assign) SailingPrizeLevel prizeLevel;//奖品等级
@property (nonatomic, assign) NSInteger referenceId;//相关实体id
@property (nonatomic, assign) NSInteger prizeId;//奖品id
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,12 @@
//
// RoomSailingPrizeModel.m
// xplan-ios
//
// Created by on 2022/8/15.
//
#import "RoomSailingPrizeModel.h"
@implementation RoomSailingPrizeModel
@end

View File

@@ -0,0 +1,21 @@
//
// XPSailingProtocol.h
// xplan-ios
//
// Created by 冯硕 on 2022/8/12.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class RoomSailingInfoModel, RoomSailingPrizeListModel;
@protocol XPSailingProtocol <NSObject>
///获取航海的信息成功
- (void)getSailingInfoSuccess:(RoomSailingInfoModel *)info;
///开启一个探索成功
- (void)openSailingSuccess:(RoomSailingPrizeListModel *)model;
///探索一次失败
- (void)openSailingFail:(NSString *)message;
@end
NS_ASSUME_NONNULL_END

View File

@@ -10,7 +10,11 @@
NS_ASSUME_NONNULL_BEGIN
@interface XPSailingPresenter : BaseMvpPresenter
/// 获取航海信息
- (void)getSailingInfo;
///开始探索
- (void)openSailing:(NSString *)roomUid sendMessage:(BOOL)sendMessage keyNum:(NSInteger)keyNum;
@end
NS_ASSUME_NONNULL_END

View File

@@ -6,7 +6,34 @@
//
#import "XPSailingPresenter.h"
#import "Api+Sailing.h"
#import "AccountInfoStorage.h"
#import "RoomSailingInfoModel.h"
#import "RoomSailingPrizeListModel.h"
#import "XPSailingProtocol.h"
@implementation XPSailingPresenter
///
- (void)getSailingInfo {
NSString * uid = [AccountInfoStorage instance].getUid;
[Api getSailingInfo:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
RoomSailingInfoModel * info = [RoomSailingInfoModel modelWithDictionary:data.data];
[[self getView] getSailingInfoSuccess:info];
}] uid:uid];
}
///
- (void)openSailing:(NSString *)roomUid sendMessage:(BOOL)sendMessage keyNum:(NSInteger)keyNum {
NSString * keyNumStr = [NSString stringWithFormat:@"%ld", keyNum];
NSString * uid = [AccountInfoStorage instance].getUid;
NSString * sendMessageStr = [NSString stringWithFormat:@"%d", sendMessage];
[Api openSailing:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
RoomSailingPrizeListModel * listModel = [RoomSailingPrizeListModel modelWithDictionary:data.data];
[[self getView] openSailingSuccess:listModel];
} fail:^(NSInteger code, NSString * _Nullable msg) {
[[self getView] openSailingFail:msg];
} showLoading:YES] uid:uid keyNum:keyNumStr sendMessage:sendMessageStr roomUid:roomUid];
}
@end

View File

@@ -1,16 +0,0 @@
//
// XPSailingProtocol.h
// xplan-ios
//
// Created by 冯硕 on 2022/8/12.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@protocol XPSailingProtocol <NSObject>
@end
NS_ASSUME_NONNULL_END

View File

@@ -5,12 +5,11 @@
// Created by 冯硕 on 2022/8/12.
//
#import "BaseViewController.h"
#import "MvpViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface XPSailingViewController : BaseViewController
@interface XPSailingViewController : MvpViewController
- (instancetype)initWithRoomUid:(NSString *)roomUid;
@end
NS_ASSUME_NONNULL_END

View File

@@ -8,17 +8,24 @@
#import "XPSailingViewController.h"
///Third
#import <Masonry/Masonry.h>
#import <NIMSDK/NIMSDK.h>
///Tool
#import "ThemeColor.h"
#import "XPMacro.h"
#import "TTPopup.h"
#import "XPHtmlUrl.h"
///Model
#import "RoomSailingInfoModel.h"
#import "RoomSailingPrizeListModel.h"
#import "AttachmentModel.h"
///View
#import "XPSailingRankView.h"
#import "XPRoomHalfWebView.h"
///P
#import "XPSailingPresenter.h"
#import "XPSailingProtocol.h"
@interface XPSailingViewController ()
@interface XPSailingViewController ()<XPSailingProtocol, NIMSystemNotificationManagerDelegate>
///View
@property (nonatomic,strong) UIView * topView;
///
@@ -48,10 +55,30 @@
///
@property (nonatomic,strong) UILabel *consumLabel;
@property (nonatomic,assign) NSInteger exploreCount;
///
@property (nonatomic,strong) RoomSailingInfoModel *sailingInfo;
///uid
@property (nonatomic,strong) NSString *roomUid;
@end
@implementation XPSailingViewController
- (void)dealloc {
[[NIMSDK sharedSDK].systemNotificationManager removeDelegate:self];
}
- (instancetype)initWithRoomUid:(NSString *)roomUid {
if (self = [super init]) {
self.roomUid = roomUid;
[[NIMSDK sharedSDK].systemNotificationManager addDelegate:self];
}
return self;
}
- (__kindof id)createPresenter {
return [[XPSailingPresenter alloc] init];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initSubViews];
@@ -158,6 +185,24 @@
}];
}
#pragma mark - XPSailingProtocol
- (void)getSailingInfoSuccess:(RoomSailingInfoModel *)info {
self.sailingInfo = info;
NSString * fuleStr = [NSString stringWithFormat:@"%ld", info.keyNum];
[self.fuleButton setTitle:fuleStr forState:UIControlStateNormal];
}
- (void)openSailingSuccess:(RoomSailingPrizeListModel *)model {
self.sailingInfo.keyNum = model.remainKeyNum;
NSString * fuleStr = [NSString stringWithFormat:@"%ld", self.sailingInfo.keyNum];
[self.fuleButton setTitle:fuleStr forState:UIControlStateNormal];
self.exploreButton.userInteractionEnabled = YES;
}
- (void)openSailingFail:(NSString *)message {
self.exploreButton.userInteractionEnabled = YES;
}
#pragma mark - Event Response
- (void)dismissView {
[self dismissViewControllerAnimated:YES completion:nil];
@@ -197,7 +242,22 @@
}
- (void)exploreButtonAction:(UIButton *)sender {
if (self.exploreCount > self.sailingInfo.keyNum) {
TTAlertConfig * config = [[TTAlertConfig alloc] init];
config.title = @"";
config.message = @"参与活动获得燃料";
config.confirmButtonConfig.title = @"去参与";
config.cancelButtonConfig.title = @"取消";
[TTPopup alertWithConfig:config confirmHandler:^{
[self getFuleButtonAction:self.getFuleButton];
} cancelHandler:^{
}];
} else {
NSString * roomUid = [NSString stringWithFormat:@""];
[self.presenter openSailing:roomUid sendMessage:YES keyNum:self.exploreCount];
self.exploreButton.userInteractionEnabled = NO;
}
}
- (void)textFiledDidChange:(UITextField *)textFiled {
@@ -214,6 +274,18 @@
self.exploreCount = textFiled.text.integerValue;
}
#pragma mark - NIMSystemNotificationManagerDelegate
- (void)onReceiveCustomSystemNotification:(NIMCustomSystemNotification *)notification {
if (notification.receiverType == NIMSessionTypeP2P) {
AttachmentModel *attachment = [AttachmentModel modelWithJSON:notification.content];
if (attachment.first == CustomMessageType_Account && attachment.second == Custom_Message_Sub_Account_Changed){
if (attachment.second == Custom_Message_Sub_Account_Changed) {
[self.presenter getSailingInfo];
}
}
}
}
#pragma mark - Getters And Setters
- (void)setExploreCount:(NSInteger)exploreCount {
_exploreCount = exploreCount;