1
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
|
||||
@interface KBShopVM ()
|
||||
@property (nonatomic, copy, readwrite, nullable) NSArray<KBShopStyleModel *> *styles;
|
||||
- (id)kb_themeIdParamFromString:(NSString *)themeId;
|
||||
@end
|
||||
|
||||
|
||||
@@ -99,17 +100,17 @@
|
||||
if (completion) completion(nil, [self kb_invalidResponseError]);
|
||||
return;
|
||||
}
|
||||
NSString *balanceValue = dataObj[@"balanceDisplay"];
|
||||
// NSNumber *balanceNumber = nil;
|
||||
// if ([balanceValue isKindOfClass:[NSNumber class]]) {
|
||||
// balanceNumber = balanceValue;
|
||||
// } else if ([balanceValue isKindOfClass:[NSString class]]) {
|
||||
// balanceNumber = @([(NSString *)balanceValue doubleValue]);
|
||||
// }
|
||||
// if (!balanceNumber) {
|
||||
// balanceNumber = @(0);
|
||||
// }
|
||||
if (completion) completion(balanceValue, nil);
|
||||
id balanceValue = dataObj[@"balance"];
|
||||
NSNumber *balanceNumber = nil;
|
||||
if ([balanceValue isKindOfClass:[NSNumber class]]) {
|
||||
balanceNumber = balanceValue;
|
||||
} else if ([balanceValue isKindOfClass:[NSString class]]) {
|
||||
balanceNumber = @([(NSString *)balanceValue doubleValue]);
|
||||
}
|
||||
if (!balanceNumber) {
|
||||
balanceNumber = @(0);
|
||||
}
|
||||
if (completion) completion(balanceNumber, nil);
|
||||
}];
|
||||
}
|
||||
|
||||
@@ -119,7 +120,7 @@
|
||||
if (completion) completion(nil, [self kb_invalidParameterError]);
|
||||
return;
|
||||
}
|
||||
NSDictionary *params = @{@"themeId": themeId};
|
||||
NSDictionary *params = @{@"themeId": [self kb_themeIdParamFromString:themeId]};
|
||||
[[KBNetworkManager shared] GET:API_THEME_DETAIL
|
||||
parameters:params
|
||||
headers:nil
|
||||
@@ -141,4 +142,56 @@
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)purchaseThemeWithId:(nullable NSString *)themeId
|
||||
completion:(KBShopPurchaseCompletion)completion {
|
||||
if (themeId.length == 0) {
|
||||
if (completion) completion(NO, [self kb_invalidParameterError]);
|
||||
return;
|
||||
}
|
||||
NSDictionary *body = @{@"themeId": [self kb_themeIdParamFromString:themeId]};
|
||||
[[KBNetworkManager shared] POST:API_THEME_PURCHASE
|
||||
jsonBody:body
|
||||
headers:nil
|
||||
autoShowBusinessError:NO
|
||||
completion:^(NSDictionary * _Nullable json,
|
||||
NSURLResponse * _Nullable response,
|
||||
NSError * _Nullable error) {
|
||||
if (completion) completion(error == nil, error);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)fetchThemeDownloadInfoWithId:(nullable NSString *)themeId
|
||||
completion:(KBShopDownloadInfoCompletion)completion {
|
||||
if (themeId.length == 0) {
|
||||
if (completion) completion(nil, [self kb_invalidParameterError]);
|
||||
return;
|
||||
}
|
||||
NSDictionary *params = @{@"themeId": [self kb_themeIdParamFromString:themeId]};
|
||||
[[KBNetworkManager shared] GET:API_THEME_DOWNLOAD
|
||||
parameters:params
|
||||
headers:nil
|
||||
autoShowBusinessError:NO
|
||||
completion:^(NSDictionary * _Nullable json,
|
||||
NSURLResponse * _Nullable response,
|
||||
NSError * _Nullable error) {
|
||||
if (error) {
|
||||
if (completion) completion(nil, error);
|
||||
return;
|
||||
}
|
||||
id dataObj = json[KBData] ?: json[@"data"];
|
||||
if (![dataObj isKindOfClass:[NSDictionary class]]) {
|
||||
if (completion) completion(nil, [self kb_invalidResponseError]);
|
||||
return;
|
||||
}
|
||||
if (completion) completion((NSDictionary *)dataObj, nil);
|
||||
}];
|
||||
}
|
||||
|
||||
- (id)kb_themeIdParamFromString:(NSString *)themeId {
|
||||
if (themeId.length == 0) { return @""; }
|
||||
NSNumberFormatter *formatter = [NSNumberFormatter new];
|
||||
NSNumber *number = [formatter numberFromString:themeId];
|
||||
return number ?: themeId;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user