// // ASVipCouponsViewModel.m // Asteria // // Created by iOS on 2023/12/9. // #import "ASVipCouponsViewModel.h" @implementation ASVipCouponsViewModel - (void)postGetCoupon:(NSString *)ID com:(void(^)(BOOL isSuccess, NSString *msg))com { [ASNetTools.shared postWithPath:postAddVipCoupon param:@{@"id":ID} success:^(id _Nonnull json) { com(true, @""); } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) { com(false, msg); }]; } - (void)getVipCouponList:(NSString *)v com:(void(^)(BOOL isSuccess, NSString *msg))com { [ASNetTools.shared getWithPath:getVipCouponUrl param:@{@"v":v} success:^(id _Nonnull json) { NSDictionary *coupsData = json; if (![coupsData.allKeys containsObject:@"coupons"]) { com(false, @"DATA ERROR!"); return; } NSDictionary *coups = [coupsData valueForKey:@"coupons"]; NSMutableArray *arr = [NSMutableArray array]; if (coups != nil && coups.count != 0) { NSArray *keys = coups.allKeys; NSMutableArray *sortedArr = [NSMutableArray array]; for (NSString *key in keys) { if (sortedArr.count == 0) { [sortedArr addObject:key]; continue; } for (int i=0; i i+1) { NSString *nx = sortedArr[i+1]; if (key.intValue >= this.intValue && key.intValue < nx.intValue) { [sortedArr insertObject:key atIndex:i+1]; break; } } else { if (sortedArr.count == 1 && key.intValue <= this.intValue) { [sortedArr insertObject:key atIndex:i]; } else { [sortedArr addObject:key]; } break; } } } for (int i=0; i