1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- //
- // FKBasketReform.m
- // FirstLink
- //
- // Created by jack on 16/2/20.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKBasketReform.h"
- #import "FKBasketUnitItem.h"
- #import "FKPromotionActivityItem.h"
- @implementation FKBasketReform
- + (NSArray *)parserBasketDetailWithDict:(NSDictionary *)dict{
- if (![dict isKindOfClass:[NSDictionary class]]) return nil;
-
- NSArray *dataArray = dict[@"data"][@"list"];
-
- if ([dataArray isKindOfClass:[NSArray class]] && dataArray.count > 0){
- NSMutableArray *arrayM = [NSMutableArray arrayWithCapacity:dataArray.count];
- for (NSDictionary *itemDict in dataArray) {
- FKBasketUnitItem *item = [[FKBasketUnitItem alloc]init];
- [item mts_setValuesForKeysWithDictionary:itemDict];
- [arrayM addObject:item];
- }
- return arrayM;
- }
- return nil;
- }
- + (kUserLevel)parserUserLevelWithDict:(NSDictionary *)dict{
- if (![dict isKindOfClass:[NSDictionary class]]) return kUserLevelNone;
-
- kUserLevel userLevel = kUserLevelNone;
- NSDictionary *userDict = dict[@"data"][@"current_user"];
- if ([userDict isKindOfClass:[NSDictionary class]]) {
- NSInteger levelIndex = [userDict[@"level"] integerValue];
- if (levelIndex >= 2){
- userLevel = kUserLevelVIP;
- }else if (levelIndex == 1){
- userLevel = kUserLevelNoraml;
- }
- }
- return userLevel;
- }
- + (NSArray *)deleteArrayForGoodIdArray:(NSArray *)goodIdArray{
-
- if (goodIdArray.count == 0) return nil;
-
- NSMutableArray *arrayM = [NSMutableArray arrayWithCapacity:goodIdArray.count];
- for (NSString *goodID in goodIdArray) {
- [arrayM addObject:@{@"goods_id" : goodID, @"quantity" : @(0)}];
- }
- return arrayM;
- }
- + (NSString *)parserMessageWithDict:(NSDictionary *)dict{
- if ([dict[@"data"][@"message"] isKindOfClass:[NSString class]]){
- return dict[@"data"][@"message"];
- }
- return nil;
- }
- + (NSMutableDictionary *)parserPromotionActivity:(NSDictionary *)dict {
- NSMutableDictionary *mutDict = [NSMutableDictionary dictionary];
-
- NSString *key;
- NSNumber *number;
- FKPromotionActivityItem *activity;
- NSMutableArray *array;
- for (NSDictionary *subDict in dict[@"data"][@"list"]) {
- if (subDict[@"id"] != [NSNull null]) {
- number = subDict[@"id"];
- key = [NSString stringWithFormat:@"%d", number.intValue];
- }
-
- array = [NSMutableArray array];
- for (NSDictionary *proActDict in subDict[@"list"]) {
- activity = [FKPromotionActivityItem new];
- [activity mts_setValuesForKeysWithDictionary:proActDict];
-
- [array addObject:activity];
- }
-
- if (key.length > 0 && array.count > 0) {
- [mutDict setValue:array forKey:key];
- }
- }
- return mutDict;
- }
- @end
|