暂无描述

FKBasketReform.m 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // FKBasketReform.m
  3. // FirstLink
  4. //
  5. // Created by jack on 16/2/20.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKBasketReform.h"
  9. #import "FKBasketUnitItem.h"
  10. #import "FKPromotionActivityItem.h"
  11. @implementation FKBasketReform
  12. + (NSArray *)parserBasketDetailWithDict:(NSDictionary *)dict{
  13. if (![dict isKindOfClass:[NSDictionary class]]) return nil;
  14. NSArray *dataArray = dict[@"data"][@"list"];
  15. if ([dataArray isKindOfClass:[NSArray class]] && dataArray.count > 0){
  16. NSMutableArray *arrayM = [NSMutableArray arrayWithCapacity:dataArray.count];
  17. for (NSDictionary *itemDict in dataArray) {
  18. FKBasketUnitItem *item = [[FKBasketUnitItem alloc]init];
  19. [item mts_setValuesForKeysWithDictionary:itemDict];
  20. [arrayM addObject:item];
  21. }
  22. return arrayM;
  23. }
  24. return nil;
  25. }
  26. + (kUserLevel)parserUserLevelWithDict:(NSDictionary *)dict{
  27. if (![dict isKindOfClass:[NSDictionary class]]) return kUserLevelNone;
  28. kUserLevel userLevel = kUserLevelNone;
  29. NSDictionary *userDict = dict[@"data"][@"current_user"];
  30. if ([userDict isKindOfClass:[NSDictionary class]]) {
  31. NSInteger levelIndex = [userDict[@"level"] integerValue];
  32. if (levelIndex >= 2){
  33. userLevel = kUserLevelVIP;
  34. }else if (levelIndex == 1){
  35. userLevel = kUserLevelNoraml;
  36. }
  37. }
  38. return userLevel;
  39. }
  40. + (NSArray *)deleteArrayForGoodIdArray:(NSArray *)goodIdArray{
  41. if (goodIdArray.count == 0) return nil;
  42. NSMutableArray *arrayM = [NSMutableArray arrayWithCapacity:goodIdArray.count];
  43. for (NSString *goodID in goodIdArray) {
  44. [arrayM addObject:@{@"goods_id" : goodID, @"quantity" : @(0)}];
  45. }
  46. return arrayM;
  47. }
  48. + (NSString *)parserMessageWithDict:(NSDictionary *)dict{
  49. if ([dict[@"data"][@"message"] isKindOfClass:[NSString class]]){
  50. return dict[@"data"][@"message"];
  51. }
  52. return nil;
  53. }
  54. + (NSMutableDictionary *)parserPromotionActivity:(NSDictionary *)dict {
  55. NSMutableDictionary *mutDict = [NSMutableDictionary dictionary];
  56. NSString *key;
  57. NSNumber *number;
  58. FKPromotionActivityItem *activity;
  59. NSMutableArray *array;
  60. for (NSDictionary *subDict in dict[@"data"][@"list"]) {
  61. if (subDict[@"id"] != [NSNull null]) {
  62. number = subDict[@"id"];
  63. key = [NSString stringWithFormat:@"%d", number.intValue];
  64. }
  65. array = [NSMutableArray array];
  66. for (NSDictionary *proActDict in subDict[@"list"]) {
  67. activity = [FKPromotionActivityItem new];
  68. [activity mts_setValuesForKeysWithDictionary:proActDict];
  69. [array addObject:activity];
  70. }
  71. if (key.length > 0 && array.count > 0) {
  72. [mutDict setValue:array forKey:key];
  73. }
  74. }
  75. return mutDict;
  76. }
  77. @end