XYWalletListViewModel.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // XYWalletListViewModel.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2020/1/13.
  6. // Copyright © 2020 翟玉磊. All rights reserved.
  7. //
  8. #import "XYWalletListViewModel.h"
  9. #import "XYWalletListCellModel.h"
  10. @implementation XYWalletListViewModel
  11. - (instancetype)init {
  12. if (self = [super init]) {
  13. self.shouldPullDownToRefresh = YES;
  14. self.shouldBeginRefreshing = NO;
  15. }
  16. return self;
  17. }
  18. - (void)loadData:(SuccessHandler)success failure:(FailureHandler)failure {
  19. [[XYUserAPIManager new] getUserWalletSuccessHandler:^(ZYLResponseModel *responseModel) {
  20. if (responseModel.codeState) {
  21. [self.dataSource removeAllObjects];
  22. if (StringIsNotEmpty([XYAppConfigModel getUrlVirtualCoin])) {
  23. XYWalletListCellModel *model = [XYWalletListCellModel new];
  24. model.walletType = Wallet_Type_Star_Virtual;
  25. model.bgImageName = @"icon_wallet_virtual_bg";
  26. model.title = [NSString stringWithFormat:@"查看%@", App_CoinName(Wallet_Type_Star_Virtual)];
  27. model.cellHeight = SCREEN_WIDTH * (72.0f/375.0f);
  28. [self.dataSource addObject:model];
  29. }
  30. NSMutableArray *tempArray = [NSMutableArray array];
  31. for (NSDictionary *dict in responseModel.data[@"walletItems"]) {
  32. XYWalletListCellModel *model = [XYWalletListCellModel new];
  33. model.walletType = [dict[@"walletType"] integerValue];
  34. switch (model.walletType) {
  35. case Wallet_Type_Star_Diamond:
  36. {
  37. model.bgImageName = @"icon_wallet_pink_bg";
  38. model.coin = [BaseMethod toString:dict[@"balance"]];
  39. model.title = App_CoinName(Wallet_Type_Star_Diamond);
  40. model.operationStr = kLocalizedString(@"充值");
  41. model.introduceTitle = App_CoinName(Wallet_Type_Star_Diamond);
  42. model.introduce = kLocalizedString(@"可用来购买虚拟礼物等本平台上的产品或服务。");
  43. self.coinBalance = responseModel.data[@"coinBalance"];
  44. [tempArray addObject:model];
  45. }
  46. break;
  47. case Wallet_Type_Star_Yuan:
  48. {
  49. model.bgImageName = @"icon_wallet_blue_bg";
  50. model.coin = [BaseMethod toString:dict[@"balance"]];
  51. model.title = App_CoinName(Wallet_Type_Star_Yuan);
  52. if (StringIsNotEmpty([XYAppConfigModel getUrlCoinShop])) {
  53. model.operationStr = kLocalizedString(@"兑换");
  54. }
  55. model.introduceTitle = App_CoinName(Wallet_Type_Star_Yuan);
  56. model.introduce = [NSString stringWithFormat:kLocalizedString(@"%@:每充值100%@可获得1%@,可用来兑换【贵族】或在【%@商城】中兑换您喜欢的其他商品。"), App_CoinName(Wallet_Type_Star_Yuan), App_CoinName(Wallet_Type_Star_Diamond), App_CoinName(Wallet_Type_Star_Yuan), App_CoinName(Wallet_Type_Star_Yuan)];
  57. // [tempArray addObject:model];
  58. }
  59. break;
  60. case Wallet_Type_Star_Coin:
  61. {
  62. model.bgImageName = @"icon_wallet_yellow_bg";
  63. model.coin = [BaseMethod toString:dict[@"balance"]];
  64. model.title = App_CoinName(Wallet_Type_Star_Coin);
  65. model.operationStr = kLocalizedString(@"转出");
  66. // [tempArray addObject:model];
  67. }
  68. break;
  69. case Wallet_Type_Star_Dust:
  70. {
  71. model.bgImageName = @"icon_wallet_purple_bg";
  72. model.coin = [BaseMethod toString:dict[@"balance"]];
  73. model.title = App_CoinName(Wallet_Type_Star_Dust);
  74. model.operationStr = kLocalizedString(@"提现");
  75. model.introduceTitle = App_CoinName(Wallet_Type_Star_Dust);
  76. model.introduce = kLocalizedString(@"用户在平台上的收益,可以兑换钻石或提现。");
  77. if (!ApplicationDelegate.isVersionStatus) {
  78. [tempArray addObject:model];
  79. }
  80. }
  81. break;
  82. case Wallet_Type_Gold_Coin:
  83. {
  84. model.bgImageName = @"icon_wallet_gold_bg";
  85. model.coin = [BaseMethod toString:dict[@"balance"]];
  86. model.title = App_CoinName(Wallet_Type_Gold_Coin);
  87. model.operationStr = kLocalizedString(@"商城兑换");
  88. model.introduceTitle = App_CoinName(Wallet_Type_Gold_Coin);
  89. model.introduce = kLocalizedString(@"签到获得金币,金币可用于商城兑换");
  90. [tempArray addObject:model];
  91. }
  92. break;
  93. default:
  94. break;
  95. }
  96. }
  97. // 排序
  98. NSArray *sortedArray = [tempArray sortedArrayUsingComparator:^NSComparisonResult(XYWalletListCellModel *obj1, XYWalletListCellModel *obj2) {
  99. if (obj1.walletType < obj2.walletType) {
  100. return NSOrderedAscending;
  101. }else {
  102. return NSOrderedDescending;
  103. }
  104. }];
  105. [self.dataSource addObjectsFromArray:sortedArray];
  106. }
  107. !success?:success(responseModel);
  108. } failureHandler:^(NSError *error) {
  109. !failure?:failure(error);
  110. }];
  111. }
  112. @end