1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- //
- // 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<NSString*, NSDictionary*> *coupsData = json;
- if (![coupsData.allKeys containsObject:@"coupons"]) {
- com(false, @"DATA ERROR!");
- return;
- }
- NSDictionary<NSString*, NSDictionary*> *coups = [coupsData valueForKey:@"coupons"];
-
- NSMutableArray<ASVipCouponModel *> *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<sortedArr.count; i++) {
- NSString *this = sortedArr[i];
- if (sortedArr.count > 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<sortedArr.count; i++) {
- ASVipCouponModel *coupM = [ASVipCouponModel mj_objectWithKeyValues: coups[sortedArr[i]]];
- if (i+1<sortedArr.count) {
- ASVipCouponModel *tempNext = [ASVipCouponModel mj_objectWithKeyValues: coups[sortedArr[i+1]]];
- }
-
- [arr addObject:coupM];
- }
- }
- self.couponArr = arr;
- com(true, @"");
- } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
- com(false, msg);
- }];
- }
- @end
|