ASGiftCardListViewModel.m 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // ASGiftCardListViewModel.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/12/2.
  6. //
  7. #import "ASGiftCardListViewModel.h"
  8. @implementation ASGiftCardListViewModel
  9. - (instancetype)init
  10. {
  11. self = [super init];
  12. if (self) {
  13. self.unUseCardList = [NSMutableArray array];
  14. self.cantUseCardList = [NSMutableArray array];
  15. }
  16. return self;
  17. }
  18. - (void)getUnuseCardList:(NSInteger)page com:(void(^)(BOOL hasNext, NSString *msg))com {
  19. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  20. dic[@"page"] = [NSString stringWithFormat:@"%ld", page];
  21. dic[@"status"] = @"1";
  22. [ASNetTools.shared getWithPath:getUserGiftCardUrl param:dic success:^(id _Nonnull json) {
  23. NSInteger pagesize = [NSString stringWithFormat:@"%@", json[@"pageSize"]].integerValue;
  24. NSArray *list = json[@"list"];
  25. NSMutableArray *arr = [ASGiftCardModel mj_objectArrayWithKeyValuesArray:list];
  26. if (page == 1) {
  27. self.unUseCardList = arr;
  28. } else {
  29. [self.unUseCardList addObjectsFromArray:arr];
  30. }
  31. if (arr.count >= pagesize){
  32. com(true, @"");
  33. } else {
  34. com(false, @"");
  35. }
  36. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  37. com(false, msg);
  38. }];
  39. }
  40. - (void)getCantUseCardList:(NSInteger)page com:(void(^)(BOOL hasNext, NSString *msg))com {
  41. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  42. dic[@"page"] = [NSString stringWithFormat:@"%ld", page];
  43. dic[@"status"] = @"2";
  44. [ASNetTools.shared getWithPath:getUserGiftCardUrl param:dic success:^(id _Nonnull json) {
  45. NSInteger pagesize = [NSString stringWithFormat:@"%@", json[@"pageSize"]].integerValue;
  46. NSArray *list = json[@"list"];
  47. NSMutableArray *arr = [ASGiftCardModel mj_objectArrayWithKeyValuesArray:list];
  48. if (page == 1) {
  49. self.unUseCardList = arr;
  50. } else {
  51. [self.unUseCardList addObjectsFromArray:arr];
  52. }
  53. if (arr.count >= pagesize){
  54. com(true, @"");
  55. } else {
  56. com(false, @"");
  57. }
  58. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  59. com(false, msg);
  60. }];
  61. }
  62. @end