cdts/xdts-ios 3/TreeHole/Code/Features/Bottle/BottleService.m
2023-07-27 09:20:00 +08:00

211 lines
7.9 KiB
Objective-C

//
// BottleService.m
// TreeHole
//
// Created by mambaxie on 2022/4/28.
//
#import "BottleService.h"
@implementation BottleService
///获取首页推荐瓶子信息
+ (void)getHomeBottleInfoWithCompletion:(void(^)(HomeBottleInfo *info))completion {
[PYHTTPManager postWithPath:@"getwinecabinet" params:nil callback:^(id _Nullable rsp, NSError * _Nullable error) {
if (!completion) {
return;
}
if (error) {
completion(nil);
return;
}
NSLog(@"首页瓶子是的%@",rsp);
HomeBottleInfo *info = [[HomeBottleInfo alloc] init];
info.left_bottle_num = [rsp[@"left_bottle_num"] intValue];
NSDictionary *bottle_imgs = rsp[@"bottle_imgs"];
NSArray *cabinet_row_ids = rsp[@"cabinet_row_ids"];
NSArray *row_bottle_types = rsp[@"row_bottle_types"];
info.cabinet_list_num = [rsp[@"cabinet_list_num"] intValue] ?: 100;
info.toast_msg = rsp[@"toast_msg"];
NSMutableArray *bottleInfosM = [NSMutableArray array];
#pragma mark--加判断 防崩
if ([cabinet_row_ids isKindOfClass:[NSArray class]]&&cabinet_row_ids.count>0) {
for (int i = 0; i < cabinet_row_ids.count; i++) {
NSDictionary *rowInfo = cabinet_row_ids[i];
BottleInfo *bottleInfo = [[BottleInfo alloc] init];
bottleInfo.ID = [rowInfo[@"b_id"] intValue];
bottleInfo.bottle_id = [rowInfo[@"bottle_id"] integerValue];
bottleInfo.cover = [bottle_imgs objectForKey:@(bottleInfo.ID).stringValue];
int row = i / info.cabinet_list_num;
bottleInfo.rowIndex = row;
bottleInfo.columnIndex = i % info.cabinet_list_num;
if (row < row_bottle_types.count) {
bottleInfo.typeInfo = [BottleTypeInfo mj_objectWithKeyValues:row_bottle_types[row]];
}
[bottleInfosM addObject:bottleInfo];
}
}
info.bottleInfos = bottleInfosM;
completion(info);
}];
}
///// 获取首页推荐瓶子信息
//+ (void)getHomereCommendBottleInfoWithCompletion:(void(^)(HomeBottleInfo *info))completion {
// [PYHTTPManager postWithPath:@"getwinecabinet" params:nil callback:^(id _Nullable rsp, NSError * _Nullable error) {
// if (!completion) {
// return;
// }
// if (error) {
// completion(nil);
// return;
// }
//
// NSLog(@"首页推荐瓶子%@",rsp);
// HomeBottleInfo *info = [[HomeBottleInfo alloc] init];
// info.left_bottle_num = [rsp[@"left_bottle_num"] intValue];
// NSDictionary *bottle_imgs = rsp[@"bottle_imgs"];
// NSArray *cabinet_row_ids = rsp[@"cabinet_row_ids"];
// NSArray *row_bottle_types = rsp[@"row_bottle_types"];
// info.cabinet_list_num = [rsp[@"cabinet_list_num"] intValue] ?: 100;
// info.toast_msg = rsp[@"toast_msg"];
// NSMutableArray *bottleInfosM = [NSMutableArray array];
// for (int i = 0; i < cabinet_row_ids.count; i++) {
// NSDictionary *rowInfo = cabinet_row_ids[i];
// BottleInfo *bottleInfo = [[BottleInfo alloc] init];
// bottleInfo.ID = [rowInfo[@"b_id"] intValue];
// bottleInfo.cover = [bottle_imgs objectForKey:@(bottleInfo.ID).stringValue];
// int row = i / info.cabinet_list_num;
// bottleInfo.rowIndex = row;
// bottleInfo.columnIndex = i % info.cabinet_list_num;
// if (row < row_bottle_types.count) {
// bottleInfo.typeInfo = [BottleTypeInfo mj_objectWithKeyValues:row_bottle_types[row]];
// }
// [bottleInfosM addObject:bottleInfo];
// }
// info.bottleInfos = bottleInfosM;
//
// completion(info);
// }];
//}
+ (void)getBottleTypeGroupInfosWithCompletion:(void(^)(NSArray<BottleTypeGroupInfo *> * _Nullable infos, NSString *navSubTitle, NSString *sendBottleNotice))completion {
if (!completion) {
return;
}
[PYHTTPManager getWithPath:@"getbottleconfig" params:nil callback:^(id _Nullable rsp, NSError * _Nullable error) {
if (error) {
completion(nil, nil, nil);
return;
}
NSArray<BottleTypeGroupInfo *> *groupInfos = nil;
NSString *navSubTitle = nil;
NSString *sendBottleNotice = nil;
groupInfos = [BottleTypeGroupInfo mj_objectArrayWithKeyValuesArray:rsp[@"bottle_groups"]];
//防崩
if ([groupInfos isKindOfClass:[NSArray class]] && groupInfos.count>0) {
for (BottleTypeGroupInfo *groupInfo in groupInfos) {
for (BottleTypeInfo *info in groupInfo.bottle_types) {
info.bottle_group_type = groupInfo.group_type;
}
}
}
navSubTitle = rsp[@"nav_sub_title"];
sendBottleNotice = rsp[@"send_bottle_notice"];
completion(groupInfos, navSubTitle, sendBottleNotice);
}];
}
/// 发布瓶子内容
+ (void)publishBottleWithGroupType:(NSString *)groupType
type:(NSString *)type
content:(NSString *)content
images:(NSArray<NSString *> *)images
voice:(NSString *)voice
voiceSec:(int)voiceSec
price:(int)price
weChat:(NSString *)weChat
completion:(PYHTTPManagerCallback)completion {
[PYHTTPManager postWithPath:@"sendbottle" params:@{
@"bottle_group_type" : groupType ?: @"",
@"bottle_type": type ?: @"",
@"content": content ?: @"",
@"images": images ?: @[],
@"voice": voice ?: @"",
@"voice_sec": @(voiceSec),
@"price": @(price),
@"wx_num": weChat ?: @""
} callback:completion];
}
+ (void)getBottleDetailInfoWithBID:(int)bid bottleType:(NSString *)bottleType isHome:(BOOL)ishome isNext:(int)isNext isAttach:(int)isAttach bottleID:(int)bottleID completion:(void (^)(BottleDetailInfo * _Nullable))completion {
int waitTime = 0.1;
if (isNext > 0) {
waitTime = 0.6;
}
NSString *url;
if (ishome) {
url = @"recommend/bottle1";
}else{
url = @"getbottle";
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(waitTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[PYHTTPManager postWithPath:url params:@{
@"b_id": @(bid),
@"bottle_type": bottleType ?: @"",
@"is_next": @(isNext),
@"is_attach": @(isAttach),
@"bottle_id": @(bottleID),
} callback:^(id _Nullable rsp, NSError * _Nullable error) {
if (!error) {
NSLog(@"%@数据==%@",url, rsp);
completion([BottleDetailInfo mj_objectWithKeyValues:rsp]);
} else {
completion(nil);
}
}];
});
}
/// 回复上报
+ (void)recordReplyBottleWithBID:(int)bid replyContent:content imageURL:(NSString *)imageURL voiceURL:(nonnull NSString *)voiceURL voiceSec:(int)voiceSec completion:(nonnull PYHTTPManagerCallback)completion {
[PYHTTPManager postWithPath:@"recordreplybottle" params:@{
@"bottle_id": @(bid),
@"reply_content":content ?: @"",
@"image_url": imageURL ?: @"",
@"voice_url": voiceURL ?: @"",
@"voice_sec": @(voiceSec)
} callback:completion];
}
/// 举报
+ (void)reportBottleWithBID:(int)bid completion:(PYHTTPManagerCallback)completion {
[PYHTTPManager postWithPath:@"reportbottle" params:@{
@"bottle_id": @(bid)
} callback:completion];
}
/// 处理该瓶子(仅限管理员账户操作)
+ (void)dealBottleWithBID:(int)bid operation:(NSString *)operation completion:(PYHTTPManagerCallback)completion {
[PYHTTPManager postWithPath:@"dealbottle" params:@{
@"bottle_id": @(bid),
@"deal_des": operation
} callback:completion];
}
@end