JXSignViewController.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. //
  2. // JXSignViewController.m
  3. // shiku_im
  4. //
  5. // Created by qiudezheng on 2020/4/29.
  6. // Copyright © 2020 Reese. All rights reserved.
  7. //
  8. #import "JXSignViewController.h"
  9. #import "JXApplyViewController.h"
  10. @interface JXSignViewController ()<UIAlertViewDelegate>
  11. @property(strong,nonatomic)UIView * navigationView;
  12. @property(strong,nonatomic)UIScrollView * scrollView;
  13. @property(strong,nonatomic)UIButton * backButton;
  14. @property(strong,nonatomic)NSArray * awardArray;
  15. @property(strong,nonatomic)NSArray * historyArray;
  16. @property(strong,nonatomic)NSDictionary * awardDic;
  17. @end
  18. @implementation JXSignViewController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. self.view.backgroundColor = [UIColor colorWithRed:126/255.0f green:23/255.0f blue:21/255.0f alpha:1.0f];
  22. self.tableView.alpha = 0.0f;
  23. [self initNavigationView];
  24. long time = (long)[[NSDate date] timeIntervalSince1970];
  25. time = (time *1000 + g_server.timeDifference);
  26. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  27. [SVProgressHUD show];
  28. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(compareHistory) name:@"history" object:nil];
  29. [g_server getContinutyAwardBySalt:salt andToView:self];
  30. }
  31. -(void)getContinuelyAwardButtonClicked:(UIButton *)sender
  32. {
  33. NSString * nowDay = [NSString stringWithFormat:@"%@",[self.awardDic objectForKey:@"nowDays"]];
  34. BOOL check = NO;
  35. int count = 0;
  36. for(int i=0;i<=(self.awardArray.count - 1);i++)
  37. {
  38. NSDictionary * dict = [self.awardArray objectAtIndex:i];
  39. NSString * realNowDay = [NSString stringWithFormat:@"%@",[dict objectForKey:@"nowDays"]];
  40. if(realNowDay.intValue == nowDay.intValue)
  41. {
  42. count = i;
  43. check = YES;
  44. break;
  45. }
  46. }
  47. NSString * continuString = [NSString stringWithFormat:@"%@",[self.awardDic objectForKey:@"isGetContinuesTask"]];
  48. if(check && continuString.boolValue)
  49. {
  50. [SVProgressHUD show];
  51. long time = (long)[[NSDate date] timeIntervalSince1970];
  52. time = (time *1000 + g_server.timeDifference);
  53. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  54. [g_server getAwardBy:salt andToView:self];
  55. UIImageView * image = (UIImageView *)[self.view viewWithTag:100+count];
  56. image.image = [UIImage imageNamed:@"getSigned"];
  57. }
  58. else
  59. {
  60. [SVProgressHUD setMinimumDismissTimeInterval:2.0f];
  61. [SVProgressHUD showErrorWithStatus:@"没有可以领取的任务奖励"];
  62. }
  63. }
  64. -(void)compareHistory
  65. {
  66. for(NSDictionary * dict in self.historyArray)
  67. {
  68. NSString * signData = [NSString stringWithFormat:@"%@",[dict objectForKey:@"date"]];
  69. NSArray * dataArray = [signData componentsSeparatedByString:@"-"];
  70. NSString * signDay = [NSString stringWithFormat:@"%@",[dataArray objectAtIndex:2]];
  71. UILabel * label = (UILabel *)[self.view viewWithTag:(1000 + signDay.intValue)];
  72. label.text = @"已完成";
  73. UIImageView * image = (UIImageView *)[self.view viewWithTag:(10000 + signDay.intValue)];
  74. image.image = [UIImage imageNamed:@"getSigned"];
  75. }
  76. }
  77. -(void)initComponents
  78. {
  79. 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))];
  80. self.scrollView.backgroundColor = self.view.backgroundColor;
  81. self.scrollView.contentSize = CGSizeMake(JX_SCREEN_WIDTH, self.scrollView.frame.size.height);
  82. [self.view addSubview:self.scrollView];
  83. UIImageView * bannerImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 0.71*JX_SCREEN_WIDTH)];
  84. bannerImage.image = [UIImage imageNamed:@"signBackImage"];
  85. bannerImage.userInteractionEnabled = YES;
  86. [self.scrollView addSubview:bannerImage];
  87. UIButton * postButton = [UIButton buttonWithType:UIButtonTypeCustom];
  88. postButton.frame = CGRectMake(JX_SCREEN_WIDTH - 70 - 15, bannerImage.frame.size.height - 40, 70, 30);
  89. [postButton setBackgroundColor:[UIColor colorWithRed:253/255.0f green:219/255.0f blue:173/255.0f alpha:1.0f]];
  90. [postButton setTitle:@"签到" forState:UIControlStateNormal];
  91. [postButton setTitleColor:self.view.backgroundColor forState:UIControlStateNormal];
  92. [postButton.titleLabel setFont:[UIFont systemFontOfSize:13.0f]];
  93. [postButton.layer setCornerRadius:5.0f];
  94. [postButton.layer setMasksToBounds:YES];
  95. [postButton addTarget:self action:@selector(signButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  96. [bannerImage addSubview:postButton];
  97. 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))];
  98. signView.backgroundColor = [UIColor colorWithRed:210/255.0f green:17/255.0f blue:24/255.0f alpha:1.0f];
  99. [signView.layer setCornerRadius:20.0f];
  100. [signView.layer setBorderColor:[[UIColor colorWithRed:254/255.0f green:238/255.0f blue:101/255.0f alpha:1.0f]CGColor]];
  101. [signView.layer setBorderWidth:2.0f];
  102. [signView.layer setMasksToBounds:YES];
  103. signView.userInteractionEnabled = YES;
  104. [self.scrollView addSubview:signView];
  105. UILabel * signLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, signView.frame.size.width, 40)];
  106. signLabel.text = @"连续完成任务有礼";
  107. signLabel.textColor = [UIColor colorWithRed:254/255.0f green:238/255.0f blue:101/255.0f alpha:1.0f];
  108. signLabel.font = [UIFont systemFontOfSize:17.0f];
  109. signLabel.textAlignment = NSTextAlignmentCenter;
  110. [signView addSubview:signLabel];
  111. float widths = (signView.frame.size.width - 7 * 20) / 6;
  112. for(int i=0;i<=(self.awardArray.count - 1);i++)
  113. {
  114. NSDictionary * dict = [self.awardArray objectAtIndex:i];
  115. UIImageView * image = [[UIImageView alloc]initWithFrame:CGRectMake(20 + i * (20 + widths), signLabel.frame.size.height, widths, widths)];
  116. image.image = [UIImage imageNamed:@"unGetSigned"];
  117. image.tag = i + 100;
  118. [signView addSubview:image];
  119. 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)];
  120. label.text = [NSString stringWithFormat:@"%@天",[dict objectForKey:@"days"]];
  121. label.textColor = [UIColor colorWithRed:241/255.0f green:207/255.0f blue:141/255.0f alpha:1.0f];
  122. label.textAlignment = NSTextAlignmentCenter;
  123. label.font = [UIFont systemFontOfSize:13.0f];
  124. [signView addSubview:label];
  125. }
  126. UIButton * getButton = [UIButton buttonWithType:UIButtonTypeCustom];
  127. getButton.frame = CGRectMake(signView.frame.size.width / 2 - 70, signLabel.frame.size.height + widths + 30, 140, 30);
  128. [getButton setBackgroundColor:[UIColor colorWithRed:253/255.0f green:219/255.0f blue:173/255.0f alpha:1.0f]];
  129. [getButton setTitle:@"领取连续完成任务奖励" forState:UIControlStateNormal];
  130. [getButton setTitleColor:self.view.backgroundColor forState:UIControlStateNormal];
  131. [getButton.titleLabel setFont:[UIFont systemFontOfSize:13.0f]];
  132. [getButton.layer setCornerRadius:5.0f];
  133. [getButton.layer setMasksToBounds:YES];
  134. [getButton addTarget:self action:@selector(getContinuelyAwardButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  135. [signView addSubview:getButton];
  136. UILabel * awardLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, getButton.frame.origin.y + getButton.frame.size.height + 10, signView.frame.size.width, 40)];
  137. awardLabel.text = @"每日签到";
  138. awardLabel.textColor = [UIColor colorWithRed:254/255.0f green:238/255.0f blue:101/255.0f alpha:1.0f];
  139. awardLabel.font = [UIFont systemFontOfSize:17.0f];
  140. awardLabel.textAlignment = NSTextAlignmentCenter;
  141. [signView addSubview:awardLabel];
  142. int perform = 0;
  143. NSCalendar *gregorian = [[NSCalendar alloc]
  144. initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
  145. NSDate* dt = [NSDate date];
  146. unsigned unitFlags = NSCalendarUnitYear |
  147. NSCalendarUnitMonth | NSCalendarUnitDay |
  148. NSCalendarUnitHour | NSCalendarUnitMinute |
  149. NSCalendarUnitSecond | NSCalendarUnitWeekday;
  150. NSDateComponents* comp = [gregorian components: unitFlags
  151. fromDate:dt];
  152. NSLog(@"现在是%ld年" , comp.year);
  153. NSLog(@"现在是%ld月 " , comp.month);
  154. NSLog(@"现在是%ld日" , comp.day);
  155. // if(comp.month == 2)
  156. // {
  157. // if(comp.year % 4 == 0 || comp.year % 400 ==0)
  158. // {
  159. //
  160. // }
  161. // }
  162. if(comp.month == 1 || comp.month == 3 || comp.month == 5 || comp.month == 7 || comp.month == 8 || comp.month == 10 || comp.month == 12)
  163. {
  164. perform = 6;
  165. }
  166. else
  167. {
  168. perform = 5;
  169. }
  170. for(int i=0;i<=(perform-1);i++)
  171. {
  172. for(int j=0;j<=5;j++)
  173. {
  174. 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)];
  175. image.tag = i * 6 + (j+1) + 10000;
  176. image.image = [UIImage imageNamed:@"unGetSigned"];
  177. [signView addSubview:image];
  178. 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)];
  179. label.tag = i * 6 + (j+1) + 1000;
  180. if((label.tag-1000) < comp.day)
  181. {
  182. label.text = @"未完成";
  183. }
  184. else
  185. {
  186. label.text = @"待完成";
  187. }
  188. label.textColor = [UIColor colorWithRed:241/255.0f green:207/255.0f blue:141/255.0f alpha:1.0f];
  189. label.textAlignment = NSTextAlignmentCenter;
  190. label.font = [UIFont systemFontOfSize:13.0f];
  191. [signView addSubview:label];
  192. if(perform == 6 && i == 5)
  193. {
  194. break;
  195. }
  196. }
  197. }
  198. signView.frame = CGRectMake(signView.frame.origin.x, signView.frame.origin.y, signView.frame.size.width,widths * perform * 1.4 + signView.frame.origin.y);
  199. self.scrollView.contentSize = CGSizeMake(JX_SCREEN_WIDTH, signView.frame.origin.y + signView.frame.size.height + 5);
  200. }
  201. -(void)viewWillDisappear:(BOOL)animated
  202. {
  203. [SVProgressHUD dismiss];
  204. }
  205. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  206. // [_wait hide];
  207. [SVProgressHUD dismiss];
  208. if([aDownload.action isEqualToString:act_UserSign])
  209. {
  210. UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"恭喜你签到成功,获得%@即信币",[dict objectForKey:@"signinCoin"]] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
  211. alertView.tag = 100000;
  212. [alertView show];
  213. long time = (long)[[NSDate date] timeIntervalSince1970];
  214. time = (time *1000 + g_server.timeDifference);
  215. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  216. [g_server getUserSignHistory:salt andToView:self];
  217. [[NSNotificationCenter defaultCenter]postNotificationName:@"refreshes" object:nil];
  218. }
  219. if([aDownload.action isEqualToString:act_GetContinu])
  220. {
  221. self.awardDic = dict;
  222. self.awardArray = [dict objectForKey:@"configs"];
  223. [self initComponents];
  224. long time = (long)[[NSDate date] timeIntervalSince1970];
  225. time = (time *1000 + g_server.timeDifference);
  226. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  227. [g_server getUserSignHistory:salt andToView:self];
  228. }
  229. if([aDownload.action isEqualToString:act_SignHistory])
  230. {
  231. self.historyArray = [dict objectForKey:@"historys"];
  232. [[NSNotificationCenter defaultCenter]postNotificationName:@"history" object:nil];
  233. }
  234. if([aDownload.action isEqualToString:act_GainContinueAward])
  235. {
  236. [SVProgressHUD setMinimumDismissTimeInterval:2.0f];
  237. [SVProgressHUD showSuccessWithStatus:@"恭喜你获得连续完成任务奖励"];
  238. }
  239. }
  240. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  241. {
  242. if(alertView.tag == 100000)
  243. {
  244. [g_navigation popToViewController:[JXApplyViewController class] animated:YES];
  245. }
  246. }
  247. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  248. NSString * errorCode = [NSString stringWithFormat:@"%@",[dict objectForKey:@"resultMsg"]];
  249. if([errorCode isEqualToString:@"权限验证失败"])
  250. {
  251. if([aDownload.action isEqualToString:act_UserSign])
  252. {
  253. long time = (long)[[NSDate date] timeIntervalSince1970];
  254. time = (time *1000 + g_server.timeDifference);
  255. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  256. [g_server userSignBySalt:salt andToView:self];
  257. }
  258. if([aDownload.action isEqualToString:act_GetContinu])
  259. {
  260. long time = (long)[[NSDate date] timeIntervalSince1970];
  261. time = (time *1000 + g_server.timeDifference);
  262. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  263. [g_server getContinutyAwardBySalt:salt andToView:self];
  264. }
  265. if([aDownload.action isEqualToString:act_SignHistory])
  266. {
  267. long time = (long)[[NSDate date] timeIntervalSince1970];
  268. time = (time *1000 + g_server.timeDifference);
  269. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  270. [g_server getUserSignHistory:salt andToView:self];
  271. }
  272. if([aDownload.action isEqualToString:act_GainContinueAward])
  273. {
  274. long time = (long)[[NSDate date] timeIntervalSince1970];
  275. time = (time *1000 + g_server.timeDifference);
  276. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  277. [g_server getAwardBy:salt andToView:self];
  278. }
  279. }
  280. else
  281. {
  282. [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"%@",[dict objectForKey:@"resultMsg"]]];
  283. }
  284. if( [aDownload.action isEqualToString:act_UserLogout] ){
  285. [self performSelector:@selector(doSwitch) withObject:nil afterDelay:1];
  286. }
  287. return hide_error;
  288. }
  289. -(void)signButtonClicked:(UIButton *)sender
  290. {
  291. long time = (long)[[NSDate date] timeIntervalSince1970];
  292. time = (time *1000 + g_server.timeDifference);
  293. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  294. [SVProgressHUD show];
  295. [g_server userSignBySalt:salt andToView:self];
  296. }
  297. -(void)initNavigationView
  298. {
  299. self.navigationView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT>=812?88:64)];
  300. self.navigationView.backgroundColor = [UIColor whiteColor];
  301. [self.view addSubview:self.navigationView];
  302. UILabel * titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, JX_SCREEN_TOP - 40, JX_SCREEN_WIDTH, 40)];
  303. titleLabel.text = @"每日签到";
  304. titleLabel.textColor = [UIColor blackColor];
  305. titleLabel.font = [UIFont systemFontOfSize:18.0f];
  306. titleLabel.textAlignment = NSTextAlignmentCenter;
  307. [self.navigationView addSubview:titleLabel];
  308. self.backButton = [UIButton buttonWithType:UIButtonTypeCustom];
  309. self.backButton.frame = CGRectMake(15, 30, 30, 30);
  310. if(JX_SCREEN_HEIGHT >= 812)
  311. {
  312. self.backButton.frame = CGRectMake(15, 45, 30, 30);
  313. }
  314. [self.backButton setImage:[UIImage imageNamed:@"title_back_black"] forState:UIControlStateNormal];
  315. [self.backButton addTarget:self action:@selector(backButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  316. [self.navigationView addSubview:self.backButton];
  317. }
  318. -(void)backButtonClicked:(UIButton *)sender
  319. {
  320. [g_navigation dismissViewController:self animated:YES];
  321. }
  322. @end