MineNewViewController.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. //
  2. // MineViewController.m
  3. // 千模
  4. //
  5. // Created by Drew on 2018/10/24.
  6. // Copyright © 2018 MUMEI. All rights reserved.
  7. //
  8. #import "MineNewViewController.h"
  9. #import "MyWalletController.h"
  10. #import "MySkillsController.h"
  11. #import "MyOrderController.h"
  12. #import "ModelDataController.h"
  13. #import "PlatformActivityController.h"
  14. #import "AboutUsViewController.h"
  15. #import "ModelCodeController.h"
  16. #import "PromoteController.h"
  17. #import "SettingsViewController.h"
  18. #import "ShareViewController.h"
  19. #import "IntroView.h"
  20. #import "ModelCardController.h"
  21. #import "RankController.h"
  22. #import "ApplyRecommendView.h"
  23. #import "WZLBadgeImport.h"
  24. #import "AppDelegate.h"
  25. #import "LoginViewController.h"
  26. #import "SwitchClientAlertController.h"
  27. #import "SwitchClientPresentationController.h"
  28. @interface MineNewViewController () <UIViewControllerTransitioningDelegate> {
  29. BOOL online;
  30. }
  31. @property(weak, nonatomic) IBOutlet UIView *headView;
  32. @property(weak, nonatomic) IBOutlet UIView *bgView;
  33. @property(weak, nonatomic) IBOutlet UILabel *nameLabel;
  34. @property(weak, nonatomic) IBOutlet UIView *avatarBg;
  35. @property(weak, nonatomic) IBOutlet UIImageView *avatarView;
  36. @property(weak, nonatomic) IBOutlet UIView *container1;
  37. @property(weak, nonatomic) IBOutlet UIView *container2;
  38. @property(weak, nonatomic) IBOutlet UIView *incomeView;
  39. @property(weak, nonatomic) IBOutlet UILabel *incomeLabel;
  40. @property(weak, nonatomic) IBOutlet UISwitch *onlineSwitch;
  41. @property(weak, nonatomic) IBOutlet UIView *modelCardView;
  42. @property(weak, nonatomic) IBOutlet UIView *skillView;
  43. @property(weak, nonatomic) IBOutlet UIView *switchView;
  44. @property(weak, nonatomic) IBOutlet UIView *switchIndicatorView;
  45. @property(weak, nonatomic) IBOutlet UIView *transformView;
  46. @property(weak, nonatomic) IBOutlet UIImageView *orderIcon;
  47. @end
  48. @implementation MineNewViewController
  49. - (void)viewDidLoad {
  50. [super viewDidLoad];
  51. NSArray *constrains = self.headView.constraints;
  52. for (NSLayoutConstraint *constraint in constrains) {
  53. if (constraint.firstAttribute == NSLayoutAttributeHeight) {
  54. constraint.constant = 104 + [[UIApplication sharedApplication] statusBarFrame].size.height;
  55. }
  56. }
  57. [self.headView updateConstraints];
  58. self.nameLabel.userInteractionEnabled = YES;
  59. self.avatarBg.layer.cornerRadius = 43;
  60. self.avatarView.layer.cornerRadius = 35;
  61. self.avatarView.layer.masksToBounds = YES;
  62. self.avatarView.userInteractionEnabled = YES;
  63. online = YES;
  64. }
  65. - (void)viewWillAppear:(BOOL)animated {
  66. [self.navigationController setNavigationBarHidden:YES animated:NO];
  67. [self getDataFromNetworking];
  68. }
  69. - (void)viewDidLayoutSubviews {
  70. [super viewDidLayoutSubviews];
  71. CAGradientLayer *gl = [CAGradientLayer layer];
  72. gl.frame = CGRectMake(0, 0, self.headView.frame.size.width, 104 + [[UIApplication sharedApplication] statusBarFrame].size.height);
  73. gl.startPoint = CGPointMake(0, 0);
  74. gl.endPoint = CGPointMake(0, 1);
  75. gl.colors = @[(__bridge id) [UIColor colorWithRed:251 / 255.0 green:92 / 255.0 blue:163 / 255.0 alpha:1].CGColor, (__bridge id) [UIColor colorWithRed:253 / 255.0 green:127 / 255.0 blue:141 / 255.0 alpha:1].CGColor];
  76. gl.locations = @[@(0), @(1.0f)];
  77. [self.headView.layer addSublayer:gl];
  78. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bgView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(30, 30)];
  79. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  80. maskLayer.frame = self.bgView.bounds;
  81. maskLayer.path = maskPath.CGPath;
  82. self.bgView.layer.mask = maskLayer;
  83. self.container1.layer.cornerRadius = 12;
  84. self.container1.layer.shadowColor = [UIColor colorWithRed:0 / 255.0 green:0 / 255.0 blue:0 / 255.0 alpha:0.08].CGColor;
  85. self.container1.layer.shadowOffset = CGSizeMake(0, 6);
  86. self.container1.layer.shadowOpacity = 1;
  87. self.container1.layer.shadowRadius = 12;
  88. self.container2.layer.cornerRadius = 12;
  89. self.container2.layer.shadowColor = [UIColor colorWithRed:0 / 255.0 green:0 / 255.0 blue:0 / 255.0 alpha:0.08].CGColor;
  90. self.container2.layer.shadowOffset = CGSizeMake(0, 6);
  91. self.container2.layer.shadowOpacity = 1;
  92. self.container2.layer.shadowRadius = 12;
  93. self.incomeView.layer.cornerRadius = 17;
  94. self.incomeView.layer.shadowColor = [UIColor colorWithRed:255 / 255.0 green:64 / 255.0 blue:149 / 255.0 alpha:0.36].CGColor;
  95. self.incomeView.layer.shadowOffset = CGSizeMake(0, 8);
  96. self.incomeView.layer.shadowOpacity = 1;
  97. self.incomeView.layer.shadowRadius = 10;
  98. }
  99. - (void)viewDidAppear:(BOOL)animated {
  100. [super viewDidAppear:animated];
  101. AppDelegate *app = [[UIApplication sharedApplication] delegate];
  102. if (app.firstLogin) {
  103. __weak MineNewViewController *this = self;
  104. IntroView *introView = [[IntroView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)
  105. confirm:^{
  106. ModelCardController *modelCardVC = [[ModelCardController alloc] init];
  107. modelCardVC.type = @"init";
  108. modelCardVC.hidesBottomBarWhenPushed = YES;
  109. [this.navigationController pushViewController:modelCardVC animated:YES];
  110. }
  111. cancel:^{
  112. }];
  113. UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
  114. CGRect rect1 = [self.modelCardView convertRect:self.modelCardView.bounds toView:window];
  115. introView.icon1left.constant = rect1.origin.x + rect1.size.width / 2 - 43;
  116. introView.icon1top.constant = rect1.origin.y + rect1.size.height / 2 - 43 - [[UIApplication sharedApplication] statusBarFrame].size.height;
  117. CGRect rect2 = [self.skillView convertRect:self.skillView.bounds toView:window];
  118. introView.icon2left.constant = rect2.origin.x + rect2.size.width / 2 - 43;
  119. [window addSubview:introView];
  120. [introView updateConstraints];
  121. [introView layoutIfNeeded];
  122. app.firstLogin = false;
  123. }
  124. }
  125. - (void)viewWillDisappear:(BOOL)animated {
  126. [self.navigationController setNavigationBarHidden:NO animated:YES];
  127. }
  128. - (void)getDataFromNetworking {
  129. // [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  130. NSDictionary *dic = @{@"modelpk": [ModelUser user].modelpk};
  131. [YanCNetWorkManager
  132. requestPostWithURLStr:Url_refreshLogin(PublicUrl)
  133. parameters:dic
  134. finish:^(id dataDic) {
  135. [MBProgressHUD hideHUDForView:self.view animated:YES];
  136. NSString *issuccess = dataDic[@"msg"];
  137. if ([issuccess isEqualToString:@"success"]) {
  138. ModelUser *user = [ModelUser modelUser];
  139. [user setValuesForKeysWithDictionary:dataDic[@"data"]];
  140. user.modelpk = dataDic[@"data"][@"modelpk"];
  141. user.coin_a = dataDic[@"data"][@"coin_a"];
  142. user.coin_ir = dataDic[@"data"][@"coin_ir"];
  143. user.pk = dataDic[@"data"][@"pk"];
  144. user.qrcode = dataDic[@"data"][@"qrcode"];
  145. [ModelUser save:user];
  146. self.nameLabel.text = [NSString stringWithFormat:@"%@", dataDic[@"data"][@"pet"]];
  147. [self.avatarView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", PublicUrl, dataDic[@"data"][@"hphoto"]]] placeholderImage:[UIImage imageNamed:@"morentouxiang"]];
  148. online = user.is_a;
  149. [self setSwitchState:user.is_a];
  150. if ([dataDic[@"data"][@"hasred"] isEqualToString:@"1"]) {
  151. [self.orderIcon showBadge];
  152. } else {
  153. [self.orderIcon clearBadge];
  154. }
  155. [self getIncomeFromNetworking];
  156. } else {
  157. [MBProgressHUD showInfo:@"请重新登录"];
  158. [self logout];
  159. }
  160. }
  161. enError:^(NSError *error) {
  162. [MBProgressHUD hideHUDForView:self.view animated:YES];
  163. }];
  164. }
  165. - (void)logout {
  166. [[[NIMSDK sharedSDK] loginManager] logout:^(NSError *error) {
  167. }];
  168. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"token"];
  169. [[NSUserDefaults standardUserDefaults] synchronize];
  170. [self.view.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
  171. LoginViewController *loginController = [[LoginViewController alloc] init];
  172. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:loginController];
  173. self.view.window.rootViewController = nav;
  174. }
  175. - (void)getIncomeFromNetworking {
  176. NSDictionary *dic = @{@"memberpk": [ModelUser modelUser].pk};
  177. [YanCNetWorkManager requestPostWithURLStr:Url_getIncomeToday(PublicUrl) parameters:dic finish:^(id dataDic) {
  178. NSString *issuccess = dataDic[@"msg"];
  179. if ([issuccess isEqualToString:@"success"]) {
  180. self.incomeLabel.text = [NSString stringWithFormat:@"今日收入 %@元", dataDic[@"count"]];
  181. } else {
  182. [MBProgressHUD showInfo:@"请求失败!"];
  183. }
  184. } enError:^(NSError *error) {
  185. [MBProgressHUD hideHUDForView:self.view animated:YES];
  186. }];
  187. }
  188. - (IBAction)handelTap:(id)sender {
  189. switch (((UITapGestureRecognizer *) sender).view.tag) {
  190. case 1: {
  191. ModelCardController *modelCardVC = [[ModelCardController alloc] init];
  192. modelCardVC.hidesBottomBarWhenPushed = YES;
  193. [self.navigationController pushViewController:modelCardVC animated:YES];
  194. break;
  195. }
  196. case 2: {
  197. MySkillsController *mySkillsVC = [[MySkillsController alloc] init];
  198. mySkillsVC.hidesBottomBarWhenPushed = YES;
  199. [self.navigationController pushViewController:mySkillsVC animated:YES];
  200. break;
  201. }
  202. case 3: {
  203. [ApplyRecommendView showIntoView:[UIApplication sharedApplication].keyWindow confirm:^{
  204. NSDictionary *dic = @{@"modelpk": [ModelUser modelUser].modelpk};
  205. [YanCNetWorkManager requestPostWithURLStr:Url_applyRecommend(PublicUrl)
  206. parameters:dic
  207. finish:^(id res) {
  208. BOOL success = [res[@"success"] intValue] == 1;
  209. if (success) {
  210. [MBProgressHUD showInfo:@"申请已提交"];
  211. } else {
  212. [MBProgressHUD showInfo:@"请求失败!"];
  213. }
  214. }
  215. enError:^(NSError *error) {
  216. [MBProgressHUD hideHUDForView:self.view animated:YES];
  217. }];
  218. }];
  219. break;
  220. // UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确定申请首页推荐展示?" preferredStyle:UIAlertControllerStyleAlert];
  221. // [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
  222. // [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *_Nonnull action) {
  223. // NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:[ModelUser modelUser].modelpk, @"modelpk", nil];
  224. // [YanCNetWorkManager requestPostWithURLStr:Url_applyRecommend(PublicUrl)
  225. // parameters:dic
  226. // finish:^(id res) {
  227. // BOOL success = [res[@"success"] intValue] == 1;
  228. // if (success) {
  229. // [MBProgressHUD showInfo:@"申请已提交"];
  230. // } else {
  231. // [MBProgressHUD showInfo:@"请求失败!"];
  232. // }
  233. // }
  234. // enError:^(NSError *error) {
  235. // [MBProgressHUD hideHUDForView:self.view animated:YES];
  236. // }];
  237. // }]];
  238. // [self presentViewController:alert animated:YES completion:nil];
  239. }
  240. case 4: {
  241. PromoteController *vc = [[PromoteController alloc] init];
  242. vc.hidesBottomBarWhenPushed = YES;
  243. [self.navigationController pushViewController:vc animated:YES];
  244. break;
  245. }
  246. case 5: {
  247. MyOrderController *vc = [[MyOrderController alloc] init];
  248. vc.hidesBottomBarWhenPushed = YES;
  249. [self.navigationController pushViewController:vc animated:YES];
  250. break;
  251. }
  252. case 6: {
  253. MyWalletController *myWalletVC = [[MyWalletController alloc] init];
  254. myWalletVC.hidesBottomBarWhenPushed = YES;
  255. myWalletVC.amount = [ModelUser modelUser].coin_a;
  256. [self.navigationController pushViewController:myWalletVC animated:YES];
  257. break;
  258. }
  259. case 7: {
  260. PlatformActivityController *activityVC = [[PlatformActivityController alloc] init];
  261. activityVC.hidesBottomBarWhenPushed = YES;
  262. [self.navigationController pushViewController:activityVC animated:YES];
  263. break;
  264. }
  265. case 8: {
  266. AboutUsViewController *aboutUsVC = [[AboutUsViewController alloc] init];
  267. aboutUsVC.hidesBottomBarWhenPushed = YES;
  268. [self.navigationController pushViewController:aboutUsVC animated:YES];
  269. break;
  270. }
  271. case 9: {
  272. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  273. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  274. [MBProgressHUD hideHUDForView:self.view];
  275. [MBProgressHUD showInfo:@"清理完成"];
  276. });
  277. break;
  278. }
  279. default:
  280. break;
  281. }
  282. }
  283. - (IBAction)tapSettings:(id)sender {
  284. SettingsViewController *settingsVC = [[SettingsViewController alloc] init];
  285. settingsVC.hidesBottomBarWhenPushed = YES;
  286. [self.navigationController pushViewController:settingsVC animated:YES];
  287. }
  288. - (IBAction)tapSwitch:(id)sender {
  289. [self updateOnline:!online];
  290. }
  291. - (IBAction)jumpToMemberClient:(id)sender {
  292. SwitchClientAlertController *vc = [[SwitchClientAlertController alloc] init];
  293. vc.modalPresentationStyle = UIModalPresentationCustom;
  294. vc.transitioningDelegate = self;
  295. [self presentViewController:vc animated:YES completion:nil];
  296. }
  297. - (void)updateOnline:(BOOL)state {
  298. __weak MineNewViewController *this = self;
  299. NSDictionary *dic = @{@"modelpk": [ModelUser modelUser].modelpk, @"state": @(state)};
  300. [YanCNetWorkManager requestPostWithURLStr:Url_setOnline(PublicUrl)
  301. parameters:dic
  302. finish:^(id res) {
  303. BOOL success = [@"success" isEqualToString:res[@"msg"]];
  304. if (success) {
  305. online = state;
  306. [this setSwitchState:state];
  307. if (online) {
  308. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
  309. hud.mode = MBProgressHUDModeText;
  310. hud.detailsLabel.text = @"您已开启在线状态\n将优先排序获得更多商业订单";
  311. hud.detailsLabel.font = [UIFont boldSystemFontOfSize:16];
  312. hud.margin = 15.f;
  313. hud.removeFromSuperViewOnHide = YES;
  314. [hud.bezelView setBackgroundColor:[UIColor colorWithRed:0 / 255.0 green:0 / 255.0 blue:0 / 255.0 alpha:0.8]];
  315. hud.contentColor = [UIColor whiteColor];
  316. [hud hideAnimated:YES afterDelay:2];
  317. } else {
  318. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
  319. hud.mode = MBProgressHUDModeText;
  320. hud.detailsLabel.text = @"您已开启离线状态\n客户无法及时联系您将造成经济损失";
  321. hud.detailsLabel.font = [UIFont boldSystemFontOfSize:16];
  322. hud.margin = 15.f;
  323. hud.removeFromSuperViewOnHide = YES;
  324. [hud.bezelView setBackgroundColor:[UIColor colorWithRed:0 / 255.0 green:0 / 255.0 blue:0 / 255.0 alpha:0.8]];
  325. hud.contentColor = [UIColor whiteColor];
  326. [hud hideAnimated:YES afterDelay:2];
  327. }
  328. } else {
  329. [MBProgressHUD showInfo:@"请求失败!"];
  330. }
  331. }
  332. enError:^(NSError *error) {
  333. [MBProgressHUD hideHUDForView:self.view animated:YES];
  334. }];
  335. }
  336. - (void)setSwitchState:(BOOL)state {
  337. if (state) {
  338. [UIView animateWithDuration:0.25
  339. delay:0
  340. options:UIViewAnimationOptionCurveEaseOut
  341. animations:^{
  342. self.switchView.backgroundColor = [UIColor whiteColor];
  343. self.switchIndicatorView.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:64 / 255.0 blue:149 / 255.0 alpha:1];
  344. self.transformView.transform = CGAffineTransformMakeTranslation(0, 0);
  345. }
  346. completion:nil];
  347. } else {
  348. [UIView animateWithDuration:0.25
  349. delay:0
  350. options:UIViewAnimationOptionCurveEaseOut
  351. animations:^{
  352. self.switchView.backgroundColor = [UIColor colorWithRed:0 / 255.0 green:0 / 255.0 blue:0 / 255.0 alpha:0.3];
  353. self.switchIndicatorView.backgroundColor = [UIColor whiteColor];
  354. self.transformView.transform = CGAffineTransformMakeTranslation(-32, 0);
  355. }
  356. completion:nil];
  357. }
  358. }
  359. - (IBAction)tapRank:(id)sender {
  360. RankController *rankVC = [[RankController alloc] init];
  361. rankVC.hidesBottomBarWhenPushed = YES;
  362. [self.navigationController pushViewController:rankVC animated:YES];
  363. }
  364. - (UIStatusBarStyle)preferredStatusBarStyle {
  365. return UIStatusBarStyleLightContent;
  366. }
  367. #pragma mark - UIViewControllerTransitioningDelegate
  368. - (UIPresentationController* )presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source {
  369. if ([presented isKindOfClass:[SwitchClientAlertController class]]) {
  370. return [[SwitchClientPresentationController alloc] initWithPresentedViewController:presented presentingViewController:self];
  371. }
  372. return [[UIPresentationController alloc] initWithPresentedViewController:presented presentingViewController:self];
  373. }
  374. @end