123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358 |
- //
- // JXSignViewController.m
- // shiku_im
- //
- // Created by qiudezheng on 2020/4/29.
- // Copyright © 2020 Reese. All rights reserved.
- //
- #import "JXSignViewController.h"
- #import "JXApplyViewController.h"
- @interface JXSignViewController ()<UIAlertViewDelegate>
- @property(strong,nonatomic)UIView * navigationView;
- @property(strong,nonatomic)UIScrollView * scrollView;
- @property(strong,nonatomic)UIButton * backButton;
- @property(strong,nonatomic)NSArray * awardArray;
- @property(strong,nonatomic)NSArray * historyArray;
- @property(strong,nonatomic)NSDictionary * awardDic;
- @end
- @implementation JXSignViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.view.backgroundColor = [UIColor colorWithRed:126/255.0f green:23/255.0f blue:21/255.0f alpha:1.0f];
- self.tableView.alpha = 0.0f;
-
- [self initNavigationView];
-
- long time = (long)[[NSDate date] timeIntervalSince1970];
- time = (time *1000 + g_server.timeDifference);
- NSString *salt = [NSString stringWithFormat:@"%ld", time];
- [SVProgressHUD show];
- [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(compareHistory) name:@"history" object:nil];
- [g_server getContinutyAwardBySalt:salt andToView:self];
- }
- -(void)getContinuelyAwardButtonClicked:(UIButton *)sender
- {
- NSString * nowDay = [NSString stringWithFormat:@"%@",[self.awardDic objectForKey:@"nowDays"]];
- BOOL check = NO;
- int count = 0;
- for(int i=0;i<=(self.awardArray.count - 1);i++)
- {
- NSDictionary * dict = [self.awardArray objectAtIndex:i];
- NSString * realNowDay = [NSString stringWithFormat:@"%@",[dict objectForKey:@"nowDays"]];
- if(realNowDay.intValue == nowDay.intValue)
- {
- count = i;
- check = YES;
- break;
- }
- }
- NSString * continuString = [NSString stringWithFormat:@"%@",[self.awardDic objectForKey:@"isGetContinuesTask"]];
- if(check && continuString.boolValue)
- {
- [SVProgressHUD show];
- long time = (long)[[NSDate date] timeIntervalSince1970];
- time = (time *1000 + g_server.timeDifference);
- NSString *salt = [NSString stringWithFormat:@"%ld", time];
- [g_server getAwardBy:salt andToView:self];
- UIImageView * image = (UIImageView *)[self.view viewWithTag:100+count];
- image.image = [UIImage imageNamed:@"getSigned"];
- }
- else
- {
- [SVProgressHUD setMinimumDismissTimeInterval:2.0f];
- [SVProgressHUD showErrorWithStatus:@"没有可以领取的任务奖励"];
- }
- }
- -(void)compareHistory
- {
- for(NSDictionary * dict in self.historyArray)
- {
- NSString * signData = [NSString stringWithFormat:@"%@",[dict objectForKey:@"date"]];
- NSArray * dataArray = [signData componentsSeparatedByString:@"-"];
- NSString * signDay = [NSString stringWithFormat:@"%@",[dataArray objectAtIndex:2]];
- UILabel * label = (UILabel *)[self.view viewWithTag:(1000 + signDay.intValue)];
- label.text = @"已完成";
- UIImageView * image = (UIImageView *)[self.view viewWithTag:(10000 + signDay.intValue)];
- image.image = [UIImage imageNamed:@"getSigned"];
- }
- }
- -(void)initComponents
- {
- self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, self.navigationView.frame.origin.y + self.navigationView.frame.size.height, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT - (self.navigationView.frame.origin.y + self.navigationView.frame.size.height))];
- self.scrollView.backgroundColor = self.view.backgroundColor;
- self.scrollView.contentSize = CGSizeMake(JX_SCREEN_WIDTH, self.scrollView.frame.size.height);
- [self.view addSubview:self.scrollView];
-
- UIImageView * bannerImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 0.71*JX_SCREEN_WIDTH)];
- bannerImage.image = [UIImage imageNamed:@"signBackImage"];
- bannerImage.userInteractionEnabled = YES;
- [self.scrollView addSubview:bannerImage];
-
- UIButton * postButton = [UIButton buttonWithType:UIButtonTypeCustom];
- postButton.frame = CGRectMake(JX_SCREEN_WIDTH - 70 - 15, bannerImage.frame.size.height - 40, 70, 30);
- [postButton setBackgroundColor:[UIColor colorWithRed:253/255.0f green:219/255.0f blue:173/255.0f alpha:1.0f]];
- [postButton setTitle:@"签到" forState:UIControlStateNormal];
- [postButton setTitleColor:self.view.backgroundColor forState:UIControlStateNormal];
- [postButton.titleLabel setFont:[UIFont systemFontOfSize:13.0f]];
- [postButton.layer setCornerRadius:5.0f];
- [postButton.layer setMasksToBounds:YES];
- [postButton addTarget:self action:@selector(signButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
- [bannerImage addSubview:postButton];
-
- UIImageView * signView = [[UIImageView alloc]initWithFrame:CGRectMake(15, bannerImage.frame.origin.y + bannerImage.frame.size.height + 10, JX_SCREEN_WIDTH - 30, JX_SCREEN_HEIGHT - ( bannerImage.frame.origin.y + bannerImage.frame.size.height + 10))];
- signView.backgroundColor = [UIColor colorWithRed:210/255.0f green:17/255.0f blue:24/255.0f alpha:1.0f];
- [signView.layer setCornerRadius:20.0f];
- [signView.layer setBorderColor:[[UIColor colorWithRed:254/255.0f green:238/255.0f blue:101/255.0f alpha:1.0f]CGColor]];
- [signView.layer setBorderWidth:2.0f];
- [signView.layer setMasksToBounds:YES];
- signView.userInteractionEnabled = YES;
- [self.scrollView addSubview:signView];
-
- UILabel * signLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, signView.frame.size.width, 40)];
- signLabel.text = @"连续完成任务有礼";
- signLabel.textColor = [UIColor colorWithRed:254/255.0f green:238/255.0f blue:101/255.0f alpha:1.0f];
- signLabel.font = [UIFont systemFontOfSize:17.0f];
- signLabel.textAlignment = NSTextAlignmentCenter;
- [signView addSubview:signLabel];
-
- float widths = (signView.frame.size.width - 7 * 20) / 6;
- for(int i=0;i<=(self.awardArray.count - 1);i++)
- {
- NSDictionary * dict = [self.awardArray objectAtIndex:i];
- UIImageView * image = [[UIImageView alloc]initWithFrame:CGRectMake(20 + i * (20 + widths), signLabel.frame.size.height, widths, widths)];
- image.image = [UIImage imageNamed:@"unGetSigned"];
- image.tag = i + 100;
- [signView addSubview:image];
-
- UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(image.frame.origin.x, image.frame.origin.y + image.frame.size.height, image.frame.size.width, image.frame.size.height / 2)];
- label.text = [NSString stringWithFormat:@"%@天",[dict objectForKey:@"days"]];
- label.textColor = [UIColor colorWithRed:241/255.0f green:207/255.0f blue:141/255.0f alpha:1.0f];
- label.textAlignment = NSTextAlignmentCenter;
- label.font = [UIFont systemFontOfSize:13.0f];
- [signView addSubview:label];
- }
-
- UIButton * getButton = [UIButton buttonWithType:UIButtonTypeCustom];
- getButton.frame = CGRectMake(signView.frame.size.width / 2 - 70, signLabel.frame.size.height + widths + 30, 140, 30);
- [getButton setBackgroundColor:[UIColor colorWithRed:253/255.0f green:219/255.0f blue:173/255.0f alpha:1.0f]];
- [getButton setTitle:@"领取连续完成任务奖励" forState:UIControlStateNormal];
- [getButton setTitleColor:self.view.backgroundColor forState:UIControlStateNormal];
- [getButton.titleLabel setFont:[UIFont systemFontOfSize:13.0f]];
- [getButton.layer setCornerRadius:5.0f];
- [getButton.layer setMasksToBounds:YES];
- [getButton addTarget:self action:@selector(getContinuelyAwardButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
- [signView addSubview:getButton];
-
- UILabel * awardLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, getButton.frame.origin.y + getButton.frame.size.height + 10, signView.frame.size.width, 40)];
- awardLabel.text = @"每日签到";
- awardLabel.textColor = [UIColor colorWithRed:254/255.0f green:238/255.0f blue:101/255.0f alpha:1.0f];
- awardLabel.font = [UIFont systemFontOfSize:17.0f];
- awardLabel.textAlignment = NSTextAlignmentCenter;
- [signView addSubview:awardLabel];
-
- int perform = 0;
-
- NSCalendar *gregorian = [[NSCalendar alloc]
- initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
- NSDate* dt = [NSDate date];
- unsigned unitFlags = NSCalendarUnitYear |
- NSCalendarUnitMonth | NSCalendarUnitDay |
- NSCalendarUnitHour | NSCalendarUnitMinute |
- NSCalendarUnitSecond | NSCalendarUnitWeekday;
- NSDateComponents* comp = [gregorian components: unitFlags
- fromDate:dt];
- NSLog(@"现在是%ld年" , comp.year);
- NSLog(@"现在是%ld月 " , comp.month);
- NSLog(@"现在是%ld日" , comp.day);
- // if(comp.month == 2)
- // {
- // if(comp.year % 4 == 0 || comp.year % 400 ==0)
- // {
- //
- // }
- // }
- if(comp.month == 1 || comp.month == 3 || comp.month == 5 || comp.month == 7 || comp.month == 8 || comp.month == 10 || comp.month == 12)
- {
- perform = 6;
- }
- else
- {
- perform = 5;
- }
- for(int i=0;i<=(perform-1);i++)
- {
- for(int j=0;j<=5;j++)
- {
- UIImageView * image = [[UIImageView alloc]initWithFrame:CGRectMake(20 + j * (20 + widths), awardLabel.frame.size.height + awardLabel.frame.origin.y + 15 + i * widths * 1.5, widths, widths)];
- image.tag = i * 6 + (j+1) + 10000;
- image.image = [UIImage imageNamed:@"unGetSigned"];
- [signView addSubview:image];
-
- UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(image.frame.origin.x, image.frame.origin.y + image.frame.size.height, image.frame.size.width, image.frame.size.height / 2)];
- label.tag = i * 6 + (j+1) + 1000;
- if((label.tag-1000) < comp.day)
- {
- label.text = @"未完成";
- }
- else
- {
- label.text = @"待完成";
- }
- label.textColor = [UIColor colorWithRed:241/255.0f green:207/255.0f blue:141/255.0f alpha:1.0f];
- label.textAlignment = NSTextAlignmentCenter;
- label.font = [UIFont systemFontOfSize:13.0f];
- [signView addSubview:label];
-
- if(perform == 6 && i == 5)
- {
- break;
- }
- }
-
- }
-
- signView.frame = CGRectMake(signView.frame.origin.x, signView.frame.origin.y, signView.frame.size.width,widths * perform * 1.4 + signView.frame.origin.y);
- self.scrollView.contentSize = CGSizeMake(JX_SCREEN_WIDTH, signView.frame.origin.y + signView.frame.size.height + 5);
- }
- -(void)viewWillDisappear:(BOOL)animated
- {
- [SVProgressHUD dismiss];
- }
- -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
- // [_wait hide];
-
- [SVProgressHUD dismiss];
- if([aDownload.action isEqualToString:act_UserSign])
- {
- UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"恭喜你签到成功,获得%@即信币",[dict objectForKey:@"signinCoin"]] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
- alertView.tag = 100000;
- [alertView show];
- long time = (long)[[NSDate date] timeIntervalSince1970];
- time = (time *1000 + g_server.timeDifference);
- NSString *salt = [NSString stringWithFormat:@"%ld", time];
- [g_server getUserSignHistory:salt andToView:self];
- [[NSNotificationCenter defaultCenter]postNotificationName:@"refreshes" object:nil];
- }
- if([aDownload.action isEqualToString:act_GetContinu])
- {
- self.awardDic = dict;
- self.awardArray = [dict objectForKey:@"configs"];
- [self initComponents];
- long time = (long)[[NSDate date] timeIntervalSince1970];
- time = (time *1000 + g_server.timeDifference);
- NSString *salt = [NSString stringWithFormat:@"%ld", time];
- [g_server getUserSignHistory:salt andToView:self];
- }
- if([aDownload.action isEqualToString:act_SignHistory])
- {
- self.historyArray = [dict objectForKey:@"historys"];
- [[NSNotificationCenter defaultCenter]postNotificationName:@"history" object:nil];
- }
- if([aDownload.action isEqualToString:act_GainContinueAward])
- {
- [SVProgressHUD setMinimumDismissTimeInterval:2.0f];
- [SVProgressHUD showSuccessWithStatus:@"恭喜你获得连续完成任务奖励"];
- }
- }
- -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
- {
- if(alertView.tag == 100000)
- {
- [g_navigation popToViewController:[JXApplyViewController class] animated:YES];
- }
- }
- -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
-
- NSString * errorCode = [NSString stringWithFormat:@"%@",[dict objectForKey:@"resultMsg"]];
- if([errorCode isEqualToString:@"权限验证失败"])
- {
- if([aDownload.action isEqualToString:act_UserSign])
- {
- long time = (long)[[NSDate date] timeIntervalSince1970];
- time = (time *1000 + g_server.timeDifference);
- NSString *salt = [NSString stringWithFormat:@"%ld", time];
- [g_server userSignBySalt:salt andToView:self];
- }
- if([aDownload.action isEqualToString:act_GetContinu])
- {
- long time = (long)[[NSDate date] timeIntervalSince1970];
- time = (time *1000 + g_server.timeDifference);
- NSString *salt = [NSString stringWithFormat:@"%ld", time];
- [g_server getContinutyAwardBySalt:salt andToView:self];
- }
- if([aDownload.action isEqualToString:act_SignHistory])
- {
- long time = (long)[[NSDate date] timeIntervalSince1970];
- time = (time *1000 + g_server.timeDifference);
- NSString *salt = [NSString stringWithFormat:@"%ld", time];
- [g_server getUserSignHistory:salt andToView:self];
- }
- if([aDownload.action isEqualToString:act_GainContinueAward])
- {
- long time = (long)[[NSDate date] timeIntervalSince1970];
- time = (time *1000 + g_server.timeDifference);
- NSString *salt = [NSString stringWithFormat:@"%ld", time];
- [g_server getAwardBy:salt andToView:self];
- }
- }
- else
- {
- [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"%@",[dict objectForKey:@"resultMsg"]]];
- }
-
- if( [aDownload.action isEqualToString:act_UserLogout] ){
- [self performSelector:@selector(doSwitch) withObject:nil afterDelay:1];
- }
- return hide_error;
- }
- -(void)signButtonClicked:(UIButton *)sender
- {
- long time = (long)[[NSDate date] timeIntervalSince1970];
- time = (time *1000 + g_server.timeDifference);
- NSString *salt = [NSString stringWithFormat:@"%ld", time];
- [SVProgressHUD show];
- [g_server userSignBySalt:salt andToView:self];
- }
- -(void)initNavigationView
- {
- self.navigationView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT>=812?88:64)];
- self.navigationView.backgroundColor = [UIColor whiteColor];
- [self.view addSubview:self.navigationView];
-
- UILabel * titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, JX_SCREEN_TOP - 40, JX_SCREEN_WIDTH, 40)];
- titleLabel.text = @"每日签到";
- titleLabel.textColor = [UIColor blackColor];
- titleLabel.font = [UIFont systemFontOfSize:18.0f];
- titleLabel.textAlignment = NSTextAlignmentCenter;
- [self.navigationView addSubview:titleLabel];
-
- self.backButton = [UIButton buttonWithType:UIButtonTypeCustom];
- self.backButton.frame = CGRectMake(15, 30, 30, 30);
- if(JX_SCREEN_HEIGHT >= 812)
- {
- self.backButton.frame = CGRectMake(15, 45, 30, 30);
- }
- [self.backButton setImage:[UIImage imageNamed:@"title_back_black"] forState:UIControlStateNormal];
- [self.backButton addTarget:self action:@selector(backButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
- [self.navigationView addSubview:self.backButton];
- }
- -(void)backButtonClicked:(UIButton *)sender
- {
- [g_navigation dismissViewController:self animated:YES];
- }
- @end
|