NYBasetjTimeVC.m 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  1. //
  2. // NYBasetjTimeVC.m
  3. // jiaPei
  4. //
  5. // Created by Ning.ge on 2023/6/8.
  6. // Copyright © 2023 JCZ. All rights reserved.
  7. // 从之前的PeriodVC复制计时逻辑,不做修改。
  8. #import "NYBasetjTimeVC.h"
  9. typedef enum {
  10. AlertTypeStopTiming = 1,
  11. AlertTypeGotoLogin
  12. }AlertType;
  13. @interface NYBasetjTimeVC ()
  14. /// 跑马灯
  15. @property (strong, readwrite, nonatomic) QMUIMarqueeLabel *marqueeLabel;
  16. @property (strong, readwrite, nonatomic) NSString *classIdStr;
  17. @property (assign, readwrite, nonatomic) LoginFlagType loginFlagType;
  18. @property (strong, readwrite, nonatomic) UIView *adView;
  19. //@property (nonatomic, readwrite, strong) QMUIPopupMenuView *popupAtBarButtonItem;
  20. //@property (nonatomic, readwrite, strong) UIBarButtonItem *rightBarButtonItem;
  21. @property (assign, readwrite, nonatomic) CGFloat varY;
  22. @property (strong, readwrite, nonatomic) NSTimer *timer;
  23. @property (strong, readwrite, nonatomic) NSDateFormatter *formatter;
  24. @property (assign, readwrite, nonatomic) NSInteger seconds;
  25. @end
  26. @implementation NYBasetjTimeVC
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. // Do any additional setup after loading the view.
  30. [self.navigationItem setLeftBarButtonItems:@[[UIBarButtonItem rq_backItemWithTitle:@"" imageName:@"back_white" target:self action:@selector(rq_back)]]];
  31. // 初始化 CTCallCenter 并设置监听
  32. self.callCenter = [[CTCallCenter alloc] init];
  33. __weak typeof(self) weakSelf = self;
  34. self.callCenter.callEventHandler = ^(CTCall *call) {
  35. [weakSelf phoneCallForHandler:call.callState];
  36. };
  37. }
  38. /// rq_back事件处理
  39. - (void)rq_back {
  40. [self.navigationController popViewControllerAnimated:YES];
  41. }
  42. // 计算两个时间的差
  43. - (NSTimeInterval)timeDifferenceExceedingSecondsBetween:(NSString *)thisTime and:(NSString *)nowTime {
  44. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  45. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  46. NSDate *thisDate = [dateFormatter dateFromString:thisTime];
  47. NSDate *nowDate = [dateFormatter dateFromString:nowTime];
  48. if (thisDate && nowDate) {
  49. NSTimeInterval timeDifference = [nowDate timeIntervalSinceDate:thisDate];
  50. return timeDifference;
  51. }
  52. return 0.0;
  53. }
  54. #pragma mark 以下内容为-从之前的PeriodVC复制计时逻辑,不做修改。
  55. #pragma mark 理论计时
  56. - (void)myInitTheory {
  57. NSString *str = @"根据运管部门要求,为了防止学员在打理论学时的时候挂学时,设定以下规则:\n1、开启理论计时后不允许最小化且不能切换到别的软件,否则计时暂停\n2、每天计时最大有效时间为4学时,单条学时不得超过4学时,否则视为无效学时\n3、计时完成后,请点击结束计时并立即上传,服务器要与运管系统同步,约30分后才会反馈回手机\n4、福州培训时间 \n 课堂时间:07:00---22:00 \n 模拟时间:05:00---23:00 \n 实操:05:00---23:00 \n 远程:05:00--23:59:59 \n 请学员注意!避免非培训时间导致学时无效。";
  58. UILabel *remindLabel = [[UILabel alloc] initWithFrame:CGRectMake(25, self.varY, kSize.width - 50, [str heightForWid:kSize.width - 50 Font:Font17])];
  59. remindLabel.numberOfLines = 0;
  60. [remindLabel setText:str Font:Font17 TextColor:[UIColor orangeColor] Alignment:NSTextAlignmentLeft];
  61. [self.view addSubview:remindLabel];
  62. }
  63. - (void)startTimingWithResultBlock:(void (^)(BOOL isSuccess))resultBlock {
  64. @weakify(self)
  65. // if (RQ_USER_MANAGER.isCykh) {
  66. // if (![self checkCykhChooseStr]) {
  67. // !resultBlock? : resultBlock(NO);
  68. // return;
  69. // }
  70. // }
  71. [self getCurrentPXKWithComplete:^(BOOL isSuccess, NSString *pxkm) {
  72. @strongify(self)
  73. if (!isSuccess) {
  74. !resultBlock? : resultBlock(NO);
  75. return;
  76. }
  77. if(self.vcType == TimeVCTypeTheory){//普通理论
  78. [RQ_USER_MANAGER.currentUser updatePxjdWithPxjd:pxkm.intValue >1 ?@"4": pxkm];
  79. }else {
  80. [RQ_USER_MANAGER.currentUser updatePxjdWithPxjd:pxkm];
  81. }
  82. /// 理论计时类型二地市编号:null (暂无地市;在科目二可以进行科目四的理论计时,科目三暂无理论计时)
  83. if ([RQ_SHARE_FUNCTION.theoryOfTimingTypeTwoCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && [pxkm isEqualToString:@"3"]) {
  84. ShowMsg(@"科目三暂无理论计时!");
  85. !resultBlock? : resultBlock(NO);
  86. return;
  87. }
  88. /// 理论计时类型三地市编号:3502 (厦门;在科目三可以进行科目四的理论计时,科目二暂无理论计时)
  89. else if ([RQ_SHARE_FUNCTION.theoryOfTimingTypeThreeCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && [pxkm isEqualToString:@"2"]) {
  90. ShowMsg(@"科目二暂无理论计时!");
  91. !resultBlock? : resultBlock(NO);
  92. return;
  93. } else {
  94. NSLog(@"-------------------%@-------------------",[RQ_SHARE_FUNCTION.theoryOfTimingTypeThreeCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city]? @"包含" : @"不包含");
  95. if (RQ_USER_MANAGER.isycbd == 1) {
  96. [RQ_RemoteTheory_MANAGER getTheoryStatusWithResultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull statusDict) {
  97. @strongify(self)
  98. if (isSuccess) {
  99. NSString *statusStr = statusDict[@"body"];
  100. if (!statusStr && [statusStr isEqualToString:@""]) {
  101. ShowMsg(@"获取学员状态异常!");
  102. !resultBlock? : resultBlock(NO);
  103. return;
  104. }
  105. BOOL statusIsSignIn = [statusStr isEqualToString:@"1"];
  106. NSString *pxkm = RQ_USER_MANAGER.currentUser.pxjd;
  107. if (pxkm.length < 1) {
  108. pxkm = @"1";
  109. }
  110. if (([pxkm isEqualToString:@"2"] || [pxkm isEqualToString:@"3"])) {
  111. pxkm = @"4";
  112. }
  113. if (self.vcType == TimeVCTypeAJob) { //从业
  114. pxkm = RQ_USER_MANAGER.cykhPxkmStr;
  115. }
  116. NSArray* array = [DB_Helper quearyTrain:RQStringIsNotEmpty(RQ_USER_MANAGER.currentUser.outId)? RQ_USER_MANAGER.currentUser.outId : @"" Subject:pxkm];
  117. __block NSInteger trainTime = 0;
  118. [array.rac_sequence.signal subscribeNext:^(TrainRecord *record) {
  119. trainTime = trainTime + record.trainTime.integerValue;
  120. } completed:^{
  121. dispatch_async(dispatch_get_main_queue(), ^{
  122. @strongify(self)
  123. if (trainTime >= 30) {
  124. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:statusIsSignIn? @"检测到上次未正常签退,请签退后再开始理论计时" : @"检测到学员已签退!本地存在异常学时,是否删除异常学时?" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"取消" otherButtonTitles:@[statusIsSignIn? @"签退" : @"删除"] otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  125. @strongify(self)
  126. !resultBlock? : resultBlock(NO);
  127. if (selectedOtherButtonIndex == 0) {
  128. if (statusIsSignIn) {
  129. TrainRecord *lastRecord = [array lastObject];
  130. /// 1.本地活体检测
  131. [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:RQ_USER_MANAGER.ycbdFaceCount completeBlock:^(BOOL success, NSDictionary * _Nullable dic) {
  132. @strongify(self)
  133. if (success) {
  134. /// 2.线上活体检测
  135. [RQ_RemoteTheory_MANAGER edufaceTofaceWithPhotoStr:dic[@"normalImg"] loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess) {
  136. @strongify(self)
  137. if (isSuccess) {
  138. /// 2.5 温州(3303)上传照片的时间是实时取服务器时间 其他地市采取从开始计时时间+累计计时时长的时间
  139. if ([RQ_USER_MANAGER.currentUser.city isEqualToString:@"3303"]) {
  140. [RQ_RemoteTheory_MANAGER getCurrentTimeWithResultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull timeDict) {
  141. @strongify(self)
  142. if (isSuccess) {
  143. /// 3.签退
  144. [RQ_RemoteTheory_MANAGER uploadEduSignOutWithArray:array resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signOutDict) {
  145. @strongify(self)
  146. if (success) {
  147. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:nil];
  148. NSString *timeStr = timeDict[@"body"];
  149. /// 4.1上传签退照片
  150. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:lastRecord.classid timeStr:timeStr actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  151. @strongify(self)
  152. if (isSuccess) {
  153. NSLog(@"上传签退照片成功!");
  154. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:YES completion:nil];
  155. } else {
  156. NSLog(@"上传签退照片失败!");
  157. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:^{
  158. @strongify(self)
  159. [self reUploadPhotoWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_SignOut];
  160. }];
  161. }
  162. }];
  163. }
  164. !resultBlock? : resultBlock(NO);
  165. }];
  166. } else {
  167. !resultBlock? : resultBlock(NO);
  168. }
  169. }];
  170. } else {
  171. /// 3.签退
  172. [RQ_RemoteTheory_MANAGER uploadEduSignOutWithArray:array resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signOutDict) {
  173. @strongify(self)
  174. if (success) {
  175. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:nil];
  176. /// 4.2上传签退照片
  177. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:lastRecord.classid timeStr:lastRecord.endTime actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  178. @strongify(self)
  179. if (isSuccess) {
  180. NSLog(@"上传签退照片成功!");
  181. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:YES completion:nil];
  182. } else {
  183. NSLog(@"上传签退照片失败!");
  184. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:^{
  185. @strongify(self)
  186. [self reUploadPhotoWithClassidStr:self.classIdStr timeStr:lastRecord.endTime actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_SignOut];
  187. }];
  188. }
  189. }];
  190. }
  191. !resultBlock? : resultBlock(NO);
  192. }];
  193. }
  194. } else {
  195. !resultBlock? : resultBlock(NO);
  196. }
  197. }];
  198. } else {
  199. !resultBlock? : resultBlock(NO);
  200. }
  201. }];
  202. } else {
  203. for (TrainRecord *record in array) {
  204. [DB_Helper deleteTrainRecord:record];
  205. }
  206. }
  207. }
  208. }];
  209. } else {
  210. if (statusIsSignIn) {
  211. [RQ_RemoteTheory_MANAGER uploadEduSignOutWithArray:@[] resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signOutDict) {
  212. @strongify(self)
  213. if (isSuccess) {
  214. [self signOutSuccessWithTrainArray:@[] signOutSuccess:YES uploadImageSuccess:NO completion:nil];
  215. }
  216. !resultBlock? : resultBlock(isSuccess);
  217. }];
  218. } else {
  219. /// 1.本地活体检测
  220. [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:RQ_USER_MANAGER.ycbdFaceCount completeBlock:^(BOOL success, NSDictionary * _Nullable dic) {
  221. @strongify(self)
  222. if (success) {
  223. /// 2.线上活体检测
  224. [RQ_RemoteTheory_MANAGER edufaceTofaceWithPhotoStr:dic[@"normalImg"] loginFlagType:LoginFlagType_SignIn resultBlock:^(BOOL isSuccess) {
  225. @strongify(self)
  226. //#warning 测试阶段-绕开人脸
  227. // isSuccess = true;
  228. if (isSuccess) {
  229. /// 3.获取线上时间
  230. [RQ_RemoteTheory_MANAGER getCurrentTimeWithResultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull timeDict) {
  231. @strongify(self)
  232. if (isSuccess) {
  233. // NSString *timeStr = @"2022-03-13 22:46:59";
  234. NSDate *date = [NSDate rq_dateWithTimestamp:timeDict[@"body"]];
  235. // NSDate *date = [NSDate rq_dateWithTimestamp:timeStr];
  236. NSInteger timeStamp = [RQ_SHARE_FUNCTION getTimeStampWithDate:date];
  237. NSString *timeStampStr = [NSString stringWithFormat:@"%@",[NSNumber numberWithInteger:timeStamp]];
  238. self.classIdStr = timeStampStr;
  239. if (self.classIdStr.length < 10) {
  240. /// 如果生成时间戳错误 用一个随机十位数代替
  241. self.classIdStr = [NSString stringWithFormat:@"%@",[NSNumber numberWithInteger:[NSString rq_randomNumberWithFrom:1647311377 to:9999999999]]];
  242. }
  243. NSInteger todayEndTimestamp = [RQ_SHARE_FUNCTION getTimeStampWithHour:23 andMinute:59 andDate:[NSDate rq_dateWithTimestamp:timeDict[@"body"]]];
  244. BOOL isShow = (todayEndTimestamp - timeStamp) < 3 * RQ_D_HOUR;
  245. self.marqueeLabel.hidden = !isShow;
  246. /// 4.签到
  247. [RQ_RemoteTheory_MANAGER uploadEduSignInWithClassidStr:self.classIdStr resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signInDict) {
  248. if (isSuccess) {
  249. @strongify(self)
  250. NSString *timeStr = signInDict[@"body"];
  251. [self signInSuccessWithBeginTime:timeStr];
  252. /// 5.上传照片
  253. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_SignIn resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  254. // @strongify(self)
  255. }];
  256. }
  257. !resultBlock? : resultBlock(isSuccess);
  258. }];
  259. } else {
  260. !resultBlock? : resultBlock(NO);
  261. }
  262. }];
  263. } else {
  264. !resultBlock? : resultBlock(NO);
  265. }
  266. }];
  267. } else {
  268. !resultBlock? : resultBlock(NO);
  269. }
  270. }];
  271. }
  272. }
  273. });
  274. }];
  275. } else {
  276. !resultBlock? : resultBlock(NO);
  277. }
  278. }];
  279. } else {
  280. !resultBlock? : resultBlock(YES);
  281. [self getWebTime];
  282. }
  283. }
  284. }];
  285. }
  286. - (void)getCurrentPXKWithComplete:(void(^)(BOOL isSuccess,NSString *pxkm))complete {
  287. // @weakify(self)
  288. ShowHUD();
  289. if (![Util connectedToNetWork]) {
  290. ShowMsg(@"请检查网络连接。");
  291. RemoveHUD();
  292. !complete? : complete(NO, nil);
  293. return;
  294. }
  295. NSMutableArray *arr = [NSMutableArray array];
  296. [arr property:RQ_USER_MANAGER.currentUser.outId forKey:@"stuOutId"];
  297. [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"];
  298. NSString* method = @"getStudentStatusByStuOutId";
  299. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  300. // @strongify(self)
  301. RemoveHUD();
  302. if (!dict) {
  303. ShowMsgFailed();
  304. !complete? : complete(NO, nil);
  305. return;
  306. }
  307. if ([dict[@"code"] isEqualToString:@"0"]) {
  308. !complete? : complete(YES, dict[@"body"]);
  309. } else {
  310. ShowMsg(dict[@"body"]);
  311. !complete? : complete(NO, nil);
  312. }
  313. }];
  314. }
  315. - (void)getWebTime {
  316. @weakify(self)
  317. ShowHUD();
  318. if (![Util connectedToNetWork])
  319. {
  320. ShowMsg(@"请检查网络连接。");
  321. RemoveHUD();
  322. return;
  323. }
  324. NSMutableArray *arr=[NSMutableArray array];
  325. if([@"3310" isEqualToString:RQ_USER_MANAGER.currentUser.city]){
  326. [arr property:RQ_USER_MANAGER.currentUser.outId forKey:@"outId"];
  327. }
  328. [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"];
  329. NSString* method = @"isUsePhone";
  330. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  331. @strongify(self)
  332. RemoveHUD();
  333. //NSLog(@"获取服务器时间--%@---->%@",arr,dict);
  334. if (!dict) {
  335. ShowMsgFailed();
  336. return;
  337. }
  338. if ( [dict[@"code"] isEqualToString:@"0"]) {
  339. myDelegate.begin_Time = dict[@"body"];
  340. [Tools playAudioWithString:@"操作成功,开始计时"];
  341. self.seconds = 0;
  342. [self.on_offBtn setTitle:@"结束计时" forState:UIControlStateNormal];
  343. myDelegate.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES];
  344. myDelegate.isUseriPhone = YES;
  345. self.timer = myDelegate.timer;
  346. myDelegate.tPeriodVC = self;
  347. ShowMsgSuc();
  348. }
  349. else
  350. {
  351. ShowMsg(dict[@"body"]);
  352. [Tools playAudioWithString:dict[@"body"]];
  353. }
  354. }];
  355. }
  356. - (void)setSecondString:(NSString *)secondString {
  357. _secondString = secondString;
  358. }
  359. - (void)timeFireMethod {
  360. @weakify(self)
  361. self.seconds++;
  362. [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]];
  363. int hour = 0;
  364. int min = 0;
  365. int second = 0;
  366. if (RQ_USER_MANAGER.isycbd == 1) {
  367. NSString *pxkm = RQ_USER_MANAGER.currentUser.pxjd;
  368. if (pxkm.length < 1) {
  369. pxkm = @"1";
  370. }
  371. if (([pxkm isEqualToString:@"2"] || [pxkm isEqualToString:@"3"])) {
  372. pxkm = @"4";
  373. }
  374. int remainder1 = [RQ_USER_MANAGER.currentUser.city isEqualToString:@"3303"]? (int)(self.seconds)%1200 : (int)(self.seconds)%780;
  375. // int remainder1 = (int)(self.seconds)%120;
  376. if (remainder1 == 0) {
  377. NSLog(@"在视频的时候-切换成竖屏%zd",RQ_Video_Module.playerController.player.isFullScreen);
  378. if(RQ_Video_Module.playerController.player.isFullScreen){//在视频的时候-切换成竖屏
  379. [RQ_Video_Module backBtnClickActiondo];
  380. }
  381. UIViewController *current_VC = RQControllerHelper.currentViewController;
  382. if([current_VC isKindOfClass:[NYExaminationViewController class]]||
  383. [current_VC isKindOfClass:[NYExaminationRoomViewController class]]){
  384. return ;//在考试模式下不显示人脸拍照
  385. }
  386. [self.timer setFireDate:[NSDate distantFuture]];
  387. SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindow];
  388. alert.backgroundViewColor = backGroundColor;
  389. alert.customViewColor = RQ_MAIN_COLOR;
  390. [alert addButton:@"立即开始 " actionBlock:^(void) {
  391. dispatch_async(dispatch_get_main_queue(), ^{
  392. @strongify(self)
  393. /// 1.本地活体检测
  394. [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:RQ_USER_MANAGER.ycbdFaceCount completeBlock:^(BOOL success, NSDictionary * _Nullable dic) {
  395. @strongify(self)
  396. if (success) {
  397. /// 2.线上活体检测
  398. [RQ_RemoteTheory_MANAGER edufaceTofaceWithPhotoStr:dic[@"normalImg"] loginFlagType:LoginFlagType_Process resultBlock:^(BOOL isSuccess) {
  399. @strongify(self)
  400. if (isSuccess) {
  401. /// 2.5 温州(3303)上传照片的时间是实时取服务器时间 其他地市采取从开始计时时间+累计计时时长的时间
  402. if ([RQ_USER_MANAGER.currentUser.city isEqualToString:@"3303"]) {
  403. [RQ_RemoteTheory_MANAGER getCurrentTimeWithResultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull timeDict) {
  404. @strongify(self)
  405. if (isSuccess) {
  406. /// 3.1上传过程照片
  407. NSString *timeStr = timeDict[@"body"];
  408. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_Process resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  409. @strongify(self)
  410. if (isSuccess) {
  411. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"过程验证成功" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  412. @strongify(self)
  413. [self.timer setFireDate:[NSDate distantPast]];
  414. }];
  415. } else {
  416. self.seconds--;
  417. [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]];
  418. [self.timer setFireDate:[NSDate distantPast]];
  419. }
  420. }];
  421. } else {
  422. self.seconds--;
  423. [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]];
  424. [self.timer setFireDate:[NSDate distantPast]];
  425. }
  426. }];
  427. } else {
  428. NSString *timeStr = [self getTimes:self.seconds];
  429. /// 3.2上传过程照片
  430. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_Process resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  431. @strongify(self)
  432. if (isSuccess) {
  433. [self lnShowTimeHandler];
  434. } else {
  435. self.seconds--;
  436. [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]];
  437. [self.timer setFireDate:[NSDate distantPast]];
  438. }
  439. }];
  440. }
  441. } else {
  442. self.seconds--;
  443. [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]];
  444. [self.timer setFireDate:[NSDate distantPast]];
  445. }
  446. }];
  447. } else {
  448. self.seconds--;
  449. [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]];
  450. [self.timer setFireDate:[NSDate distantPast]];
  451. }
  452. }];
  453. });
  454. }];
  455. [alert addTimerToButtonIndex:0 reverse:YES];
  456. [alert showNotice:@"温馨提示" subTitle:@"即将开始活体检测,请做好准备" closeButtonTitle:nil duration:5.0f];
  457. }
  458. } else {
  459. }
  460. int remainder;
  461. if (RQ_USER_MANAGER.isycbd == 1) {
  462. remainder = (int)self.seconds%1800;
  463. } else {
  464. remainder = (int)self.seconds%300;
  465. }
  466. if (remainder == 0) {
  467. //每5分钟保存一次,温州每30分钟保存一次
  468. [self saveTrain];
  469. }
  470. //判断-辽宁-晚上23:55分
  471. if((int)self.seconds%30==0){
  472. NSLog(@"判断-辽宁-晚上23:55分");
  473. [self lnShowTime2399Handler];
  474. }
  475. hour = (int)self.seconds / 3600;
  476. min = (int)self.seconds % 3600 / 60;
  477. second = (int)self.seconds % 3600 % 60;
  478. NSString *min_s;
  479. NSString *second_s;
  480. if (min<10) {
  481. min_s=[NSString stringWithFormat:@"0%d",min];
  482. }else{
  483. min_s=[NSString stringWithFormat:@"%d",min];
  484. }
  485. if (second<10) {
  486. second_s=[NSString stringWithFormat:@"0%d",second];
  487. }else{
  488. second_s=[NSString stringWithFormat:@"%d",second];
  489. }
  490. //凌晨重新计时 只是为了防止夜里挂学时 导致一天挂学时超过4小时做的处理 但是这样的话 学员就可以一夜挂8个小时 这样反而不好 应该取消这个 如果连续超过四个小时 判定无效 dansonmark
  491. /*
  492. NSString *time=[myDelegate.begin_Time substringWithRange:NSMakeRange(0, 10)];
  493. time=[NSString stringWithFormat:@"%@ 23:59:59",time];
  494. if ([[self getTimes:self.seconds] isEqualToString:time]) {
  495. [self saveTrain];
  496. //加2就不会连在一起了
  497. self.seconds = self.seconds+2;
  498. //重置开始时间
  499. myDelegate.begin_Time = [self getTimes:self.seconds];
  500. self.seconds = 0;
  501. }
  502. */
  503. //更新UI上的时间
  504. self.timeLabel.text = [NSString stringWithFormat:@"0%d:%@:%@",hour,min_s,second_s];
  505. }
  506. //call电话 - 进来处理
  507. - (void)phoneCallForHandler:(NSString *)callState{
  508. // 电话状态发生变化
  509. if ([callState isEqualToString:CTCallStateDialing]) {
  510. NSLog(@"拨号中");
  511. [self calllongTimeHandler];
  512. } else if ([callState isEqualToString:CTCallStateConnected]) {
  513. NSLog(@"已接通-不处理");
  514. } else if ([callState isEqualToString:CTCallStateDisconnected]) {
  515. NSLog(@"已挂断-不处理");
  516. } else if ([callState isEqualToString:CTCallStateIncoming]) {
  517. NSLog(@"来电中");
  518. [self calllongTimeHandler];
  519. }
  520. }
  521. //超过15分钟-提示暂停-签退
  522. - (void)calllongTimeHandler{
  523. @weakify(self)
  524. if(self.seconds>=900){
  525. [self.timer setFireDate:[NSDate distantFuture]];
  526. //暂停计时
  527. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"为了您的学时有效性,请优先选择签退" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"签退" otherButtonTitles:@[@"取消"] otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  528. NSLog(@"%zd",selectedOtherButtonIndex);
  529. if(selectedOtherButtonIndex==0){//取消
  530. [self.timer setFireDate:[NSDate distantPast]];//恢复计时
  531. }else{//签退
  532. //走-签退-结束计时流程
  533. @strongify(self)
  534. [self btnClick:self.on_offBtn];
  535. }
  536. }];
  537. }
  538. }
  539. //2.4 辽宁-特殊判断 - 拍照上传-超时处理
  540. - (void)lnShowTimeHandler {
  541. @weakify(self)
  542. if ([[RQ_USER_MANAGER getParamsKey:@"APP_LN_DQBH"] rangeOfString:RQ_USER_MANAGER.currentUser.city].location != NSNotFound) {//是否辽宁
  543. NSString *this_timeStr = [self getTimes:self.seconds];//当前计时器时间
  544. //提示: 本次训练暂停学时较多. 请先签退, 再重新签到)
  545. [RQ_RemoteTheory_MANAGER getCurrentTimeWithResultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull timeDict) {
  546. @strongify(self)
  547. if (isSuccess) {
  548. NSString *now_timeStr = timeDict[@"body"];
  549. //如果-暂停超过15分钟-提示-签退
  550. double timecount = fabs([self timeDifferenceExceedingSecondsBetween:this_timeStr and:now_timeStr]);
  551. NSLog(@"辽宁timecount=%f",timecount);
  552. if(timecount>900){
  553. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"本次训练暂停学时较多. 请先签退, 再重新签到" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"签退" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  554. //走-签退-结束计时流程
  555. @strongify(self)
  556. [self btnClick:self.on_offBtn];
  557. }];
  558. }else{
  559. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"过程验证成功" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  560. @strongify(self)
  561. [self.timer setFireDate:[NSDate distantPast]];
  562. }];
  563. }
  564. }
  565. }];
  566. return;
  567. }else{//非辽宁-直接提示成功
  568. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"过程验证成功" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  569. @strongify(self)
  570. [self.timer setFireDate:[NSDate distantPast]];
  571. }];
  572. }
  573. }
  574. //2.5 辽宁-特殊判断 - 凌晨提醒签退
  575. - (void)lnShowTime2399Handler {
  576. @weakify(self)
  577. if ([[RQ_USER_MANAGER getParamsKey:@"APP_LN_DQBH"] rangeOfString:RQ_USER_MANAGER.currentUser.city].location != NSNotFound) {//是否辽宁
  578. NSString *time=[myDelegate.begin_Time substringWithRange:NSMakeRange(0, 10)];
  579. NSString *time50=[NSString stringWithFormat:@"%@ 23:50:00",time];
  580. NSString *time55=[NSString stringWithFormat:@"%@ 23:55:00",time];
  581. NSString *this_timeStr = [self getTimes:self.seconds];
  582. //如果-暂停超过15分钟-提示-签退
  583. double timecount = [self timeDifferenceExceedingSecondsBetween:this_timeStr and:time50];
  584. if(timecount<0){
  585. double timecount55 = [self timeDifferenceExceedingSecondsBetween:this_timeStr and:time55];
  586. if(timecount55<0){
  587. [self.timer setFireDate:[NSDate distantFuture]];
  588. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"本次培训即将隔日无效. 请先签退. 0点过后再重新签到" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"签退" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  589. //走-签退-结束计时流程
  590. @strongify(self)
  591. [self btnClick:self.on_offBtn];
  592. }];
  593. return;
  594. }else{
  595. ShowMsg(@"本次培训即将隔日无效. 请先签退. 0点过后再重新签到");
  596. return;
  597. }
  598. }
  599. //23:55:00 强制签退
  600. NSLog(@"this_timeStr=%@ time50=%@ time55=%@ %f",this_timeStr,time50,time55,timecount);
  601. }
  602. }
  603. - (void)stopTimingWithResultBlock:(void (^)(BOOL isSuccessed))resultBlock {
  604. @weakify(self)
  605. [self.timer setFireDate:[NSDate distantFuture]];
  606. [self saveTrain];
  607. if (RQ_USER_MANAGER.isycbd == 1) {
  608. /// 1.本地活体检测
  609. [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:RQ_USER_MANAGER.ycbdFaceCount completeBlock:^(BOOL success, NSDictionary * _Nullable dic) {
  610. @strongify(self)
  611. if (success) {
  612. /// 2.线上活体检测
  613. [RQ_RemoteTheory_MANAGER edufaceTofaceWithPhotoStr:dic[@"normalImg"] loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess) {
  614. @strongify(self)
  615. if (isSuccess) {
  616. /// 2.5 温州(3303)上传照片的时间是实时取服务器时间 其他地市采取从开始计时时间+累计计时时长的时间
  617. if ([RQ_USER_MANAGER.currentUser.city isEqualToString:@"3303"]) {
  618. [RQ_RemoteTheory_MANAGER getCurrentTimeWithResultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull timeDict) {
  619. @strongify(self)
  620. if (isSuccess) {
  621. /// 4.签退
  622. NSString *pxkm = RQ_USER_MANAGER.currentUser.pxjd;
  623. if (pxkm.length < 1) {
  624. pxkm = @"1";
  625. }
  626. if (([pxkm isEqualToString:@"2"] || [pxkm isEqualToString:@"3"])) {
  627. pxkm = @"4";
  628. }
  629. NSArray* array = [DB_Helper quearyTrain:RQStringIsNotEmpty(RQ_USER_MANAGER.currentUser.outId)? RQ_USER_MANAGER.currentUser.outId : @"" Subject:pxkm];
  630. if (array.count < 1) {
  631. !resultBlock? : resultBlock(YES);
  632. ShowMsg(@"本地无学时明细!");
  633. return;
  634. }
  635. [RQ_RemoteTheory_MANAGER uploadEduSignOutWithArray:array resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signOutDict) {
  636. @strongify(self)
  637. if (isSuccess) {
  638. !resultBlock? : resultBlock(YES);
  639. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:nil];
  640. /// 4.1上传签退照片
  641. NSString *timeStr = timeDict[@"body"];
  642. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  643. @strongify(self)
  644. if (isSuccess) {
  645. NSLog(@"上传签退照片成功!");
  646. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:YES completion:nil];
  647. } else {
  648. NSLog(@"上传签退照片失败!");
  649. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:^{
  650. @strongify(self)
  651. [self reUploadPhotoWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_SignOut];
  652. }];
  653. }
  654. }];
  655. } else {
  656. !resultBlock? : resultBlock(NO);
  657. [self.timer setFireDate:[NSDate distantPast]];
  658. }
  659. }];
  660. } else {
  661. !resultBlock? : resultBlock(NO);
  662. [self.timer setFireDate:[NSDate distantPast]];
  663. }
  664. }];
  665. } else {
  666. /// 3.签退
  667. NSString *pxkm = RQ_USER_MANAGER.currentUser.pxjd;
  668. if (pxkm.length < 1) {
  669. pxkm = @"1";
  670. }
  671. if (([pxkm isEqualToString:@"2"] || [pxkm isEqualToString:@"3"])) {
  672. pxkm = @"4";
  673. }
  674. if(self.vcType == TimeVCTypeAJob){//从业
  675. pxkm = RQ_USER_MANAGER.cykhPxkmStr;
  676. }
  677. // if (RQ_USER_MANAGER.isCykh) {
  678. // if (![self checkCykhChooseStr]) {
  679. // !resultBlock? : resultBlock(YES);
  680. // return;
  681. // } else {
  682. // pxkm = RQ_USER_MANAGER.cykhPxkmStr;
  683. // }
  684. // }
  685. NSArray* array = [DB_Helper quearyTrain:RQStringIsNotEmpty(RQ_USER_MANAGER.currentUser.outId)? RQ_USER_MANAGER.currentUser.outId : @"" Subject:pxkm];
  686. if (array.count < 1) {
  687. !resultBlock? : resultBlock(YES);
  688. ShowMsg(@"本地无学时明细!");
  689. return;
  690. }
  691. [RQ_RemoteTheory_MANAGER uploadEduSignOutWithArray:array resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signOutDict) {
  692. @strongify(self)
  693. if (isSuccess) {
  694. !resultBlock? : resultBlock(YES);
  695. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:nil];
  696. /// 4.2上传签退照片
  697. NSString *timeStr = [self getTimes:self.seconds];
  698. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  699. @strongify(self)
  700. if (isSuccess) {
  701. NSLog(@"上传签退照片成功!");
  702. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:YES completion:nil];
  703. } else {
  704. NSLog(@"上传签退照片失败!");
  705. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:^{
  706. [self reUploadPhotoWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_SignOut];
  707. }];
  708. }
  709. }];
  710. } else {
  711. !resultBlock? : resultBlock(NO);
  712. [self.timer setFireDate:[NSDate distantPast]];
  713. }
  714. }];
  715. }
  716. } else {
  717. !resultBlock? : resultBlock(NO);
  718. [self.timer setFireDate:[NSDate distantPast]];
  719. }
  720. }];
  721. } else {
  722. !resultBlock? : resultBlock(NO);
  723. [self.timer setFireDate:[NSDate distantPast]];
  724. }
  725. }];
  726. } else {
  727. !resultBlock? : resultBlock(YES);
  728. [self setSecondString:@"0"];
  729. [self.timer setFireDate:[NSDate distantFuture]];
  730. [self.timer invalidate];
  731. self.timer = nil;
  732. myDelegate.timer = nil;
  733. myDelegate.tPeriodVC = nil;
  734. myDelegate.isTrain = NO;
  735. self.timeLabel.text = @"00:00:00";
  736. // if (self.seconds < 60) {
  737. // ShowMsg(@"学时未满一分钟不统计");
  738. // return;
  739. // }
  740. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"结束计时,是否上传学时?" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"暂不上传" otherButtonTitles:@[@"确定"] otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  741. @strongify(self)
  742. if (selectedOtherButtonIndex == 0) {
  743. [self upLoadTrainRecord];
  744. }else if (selectedOtherButtonIndex == NSNotFound){
  745. ShowMsg(@"学时已保存在本地");
  746. }
  747. }];
  748. }
  749. }
  750. -(void)saveTrain {
  751. if (!self.formatter) {
  752. self.formatter = [NSDateFormatter rq_defaultDateFormatter];
  753. }
  754. TrainRecord *train = [[TrainRecord alloc]init];
  755. train.studentId = RQStringIsNotEmpty(RQ_USER_MANAGER.currentUser.outId)? RQ_USER_MANAGER.currentUser.outId : @"";
  756. train.beginTime = myDelegate.begin_Time;
  757. NSDate *date = [self.formatter dateFromString:myDelegate.begin_Time];
  758. date = [date dateByAddingTimeInterval:self.seconds];
  759. train.state = @"0";
  760. train.endTime=[self.formatter stringFromDate:date];
  761. NSInteger mins = self.seconds / 60;
  762. train.trainTime = [NSString stringWithFormat:@"%d",(int)mins];
  763. train.classid = (self.classIdStr && ![self.classIdStr isEqualToString:@""])? self.classIdStr : @"0";
  764. [DB_Helper saveTrain:train];
  765. }
  766. - (NSString *)getTimes:(int)second {
  767. if (!self.formatter) {
  768. self.formatter=[[NSDateFormatter alloc]init];
  769. [self.formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  770. }
  771. NSString *beginTimeStr = myDelegate.begin_Time;
  772. [self.formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
  773. NSDate *beginDate = [self.formatter dateFromString:beginTimeStr];
  774. NSDate *newDate = [NSDate dateWithTimeInterval:second sinceDate:beginDate];
  775. NSString *nowString = [self.formatter stringFromDate:newDate];
  776. return nowString;
  777. }
  778. - (void)upLoadTrainRecord{
  779. NSString *pxkm = RQ_USER_MANAGER.currentUser.pxjd;
  780. // NSString *crDate = RQ_USER_MANAGER.currentUser.crDate;
  781. // if (crDate.length > 10) {
  782. // crDate = [crDate substringToIndex:7];
  783. // }
  784. // NSArray *dateArray = [crDate componentsSeparatedByString:@"-"];
  785. // if ([[dateArray firstObject] integerValue] < 2016) {
  786. // pxkm = @"1";
  787. // }
  788. // if ([[dateArray firstObject] integerValue] == 2016) {
  789. //
  790. // if ([[dateArray lastObject] integerValue] < 11) {
  791. // pxkm = @"1";
  792. // }
  793. // }
  794. if (pxkm.length < 1) {
  795. pxkm = @"1";
  796. }
  797. /// 理论计时类型一地市编号:3501,3503 (福州,莆田;在科目二,科目三可以进行科目四的理论计时)
  798. if ([RQ_SHARE_FUNCTION.theoryOfTimingTypeOneCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && ([pxkm isEqualToString:@"2"] || [pxkm isEqualToString:@"3"])) {
  799. pxkm = @"4";
  800. }
  801. /// 理论计时类型二地市编号:null (暂无地市;在科目二可以进行科目四的理论计时)
  802. else if ([RQ_SHARE_FUNCTION.theoryOfTimingTypeTwoCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && [pxkm isEqualToString:@"2"]) {
  803. pxkm = @"4";
  804. }
  805. /// 理论计时类型三地市编号:3502 (厦门;在科目三可以进行科目四的理论计时)
  806. else if ([RQ_SHARE_FUNCTION.theoryOfTimingTypeThreeCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && [pxkm isEqualToString:@"3"]) {
  807. pxkm = @"4";
  808. }
  809. /// 新增地市 (新增地市;默认在科目二,科目三可以进行科目四的理论计时)
  810. else if (![RQ_SHARE_FUNCTION.theoryOfTimingTypeOneCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && ![RQ_SHARE_FUNCTION.theoryOfTimingTypeTwoCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && ![RQ_SHARE_FUNCTION.theoryOfTimingTypeThreeCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && ([pxkm isEqualToString:@"2"] || [pxkm isEqualToString:@"3"])) {
  811. pxkm = @"4";
  812. }
  813. if(self.vcType == TimeVCTypeAJob){//从业
  814. pxkm = RQ_USER_MANAGER.cykhPxkmStr;
  815. }
  816. // if (RQ_USER_MANAGER.isCykh) {
  817. // if (![self checkCykhChooseStr]) {
  818. // return;
  819. // } else {
  820. // pxkm = RQ_USER_MANAGER.cykhPxkmStr;
  821. // }
  822. // }
  823. NSArray* array = [DB_Helper quearyTrain:RQStringIsNotEmpty(RQ_USER_MANAGER.currentUser.outId)? RQ_USER_MANAGER.currentUser.outId : @"" Subject:pxkm];
  824. if (array.count < 1) {
  825. ShowMsg(@"本地无学时明细!");
  826. return;
  827. }
  828. //这里是对分段上传学时做的处理 如果学时上传有问题 查看这里
  829. [self uploadMoreTrainRecordWithArray:array];
  830. }
  831. - (void)uploadMoreTrainRecordWithArray:(NSArray *)trainArray
  832. {
  833. ShowHUD();
  834. if (![Util connectedToNetWork]) {
  835. showMsgUnconnect();
  836. return;
  837. }
  838. NSString* str = @"";
  839. for (TrainRecord *record in trainArray) {
  840. str = [str stringByAppendingString:[NSString stringWithFormat:@"%@,%@,%@,%@;",record.studentId,record.beginTime,record.endTime,record.trainTime]];
  841. }
  842. TrainRecord *record = [trainArray firstObject];
  843. /// 理论计时类型一地市编号:3501,3503 (福州,莆田;在科目二,科目三可以进行科目四的理论计时)
  844. if ([RQ_SHARE_FUNCTION.theoryOfTimingTypeOneCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && ([record.subject isEqualToString:@"2"] || [record.subject isEqualToString:@"3"])) {
  845. record.subject = @"4";
  846. }
  847. /// 理论计时类型二地市编号:null (暂无地市;在科目二可以进行科目四的理论计时)
  848. else if ([RQ_SHARE_FUNCTION.theoryOfTimingTypeTwoCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && [record.subject isEqualToString:@"2"]) {
  849. record.subject = @"4";
  850. }
  851. /// 理论计时类型三地市编号:3502 (厦门;在科目三可以进行科目四的理论计时)
  852. else if ([RQ_SHARE_FUNCTION.theoryOfTimingTypeThreeCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && [record.subject isEqualToString:@"3"]) {
  853. record.subject = @"4";
  854. }
  855. /// 新增地市 (新增地市;默认在科目二,科目三可以进行科目四的理论计时)
  856. else if (![RQ_SHARE_FUNCTION.theoryOfTimingTypeOneCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && ![RQ_SHARE_FUNCTION.theoryOfTimingTypeTwoCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && ![RQ_SHARE_FUNCTION.theoryOfTimingTypeThreeCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && ([record.subject isEqualToString:@"2"] || [record.subject isEqualToString:@"3"])) {
  857. record.subject = @"4";
  858. }
  859. NSMutableArray *arr = [NSMutableArray array];
  860. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"ios",@"trainType", nil]];
  861. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:[DES3Util encrypt:str ],@"trainRecord", nil]];
  862. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:record.subject,@"pxkm", nil]];
  863. NSString* method = @"uploadMoreTrainRecord";
  864. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  865. RemoveHUD();
  866. //NSLog(@"---------><>%@----><>%@",arr,dict);
  867. if (!dict) {
  868. ShowMsg(@"操作失败");
  869. return;
  870. }
  871. if ( [dict[@"code"] isEqualToString:@"1"]) {
  872. ShowMsg(dict[@"body"]);
  873. return;
  874. }
  875. if ( [dict[@"code"] isEqualToString:@"0"]) {
  876. for (TrainRecord *record in trainArray) {
  877. [DB_Helper updateTrainState:record];
  878. }
  879. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"上传学时成功!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:nil];
  880. }
  881. }];
  882. }
  883. #pragma mark btn
  884. - (void)btnClick:(UIButton *)sender {
  885. if(RQ_USER_MANAGER.currentUser.stuNum == nil ||
  886. [RQ_USER_MANAGER.currentUser.stuNum isEqualToString:@""]){
  887. ShowMsg(@"数据正在同步至监管平台,请先进行理论练习。");
  888. return;
  889. }
  890. UIButton *btn = sender;
  891. @weakify(self, btn)
  892. if (btn.enabled) {
  893. btn.enabled = NO;
  894. }
  895. if (myDelegate.isUseriPhone) {
  896. //点击事件 如果已经开始计时 调用里边的内容
  897. [self stopTimingWithResultBlock:^(BOOL isSuccessed) {
  898. @strongify(self, btn)
  899. btn.enabled = YES;
  900. if (isSuccessed) {
  901. [btn setTitle:@"开始计时" forState:UIControlStateNormal];
  902. myDelegate.isUseriPhone = NO;
  903. }
  904. }];
  905. }else{
  906. if (myDelegate.timer) {
  907. ShowMsg(@"请先关闭其他计时");
  908. return;
  909. }
  910. [self startTimingWithResultBlock:^(BOOL isSuccess) {
  911. @strongify(btn)
  912. btn.enabled = YES;
  913. }];
  914. }
  915. }
  916. #pragma mark - 温州远程理论
  917. //远程理论签到成功
  918. - (void)signInSuccessWithBeginTime:(NSString *)beginTime {
  919. myDelegate.begin_Time = beginTime;
  920. [Tools playAudioWithString:@"操作成功,开始计时"];
  921. self.seconds = 0;
  922. [self.on_offBtn setTitle:@"结束计时" forState:UIControlStateNormal];
  923. myDelegate.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES];
  924. myDelegate.isUseriPhone = YES;
  925. self.timer = myDelegate.timer;
  926. myDelegate.tPeriodVC = self;
  927. ShowMsgSuc();
  928. [RQ_COMMON_MANAGER keepIdleTimerDisabledisOpen:YES];
  929. [MBProgressHUD hideHUDForView:[RQ_SHARE_FUNCTION topViewController].view animated:YES];
  930. if ([RQ_USER_MANAGER.currentUser.city isEqualToString:@"3501"]) {
  931. WeakSelf(weakSelf)
  932. [RQ_ALERTVIEW_MANAGER showAlertWithTitle:@"温馨提示" message: @"福州培训时间 \n 课堂时间:07:00---22:00 \n 模拟时间:05:00---23:00 \n 实操:05:00---23:00 \n 远程:05:00--23:59:59 \n 请学员注意!避免非培训时间导致学时无效。" confirmTitle:@"确认" confirmAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
  933. RemoveHUD();
  934. [MBProgressHUD hideHUDForView:weakSelf.view animated:YES];
  935. }];
  936. }
  937. }
  938. //远程理论签退成功
  939. - (void)signOutSuccessWithTrainArray:(NSArray *)trainArray signOutSuccess:(BOOL)signOutSuccess uploadImageSuccess:(BOOL)uploadImageSuccess completion:(void (^)(void))completion {
  940. for (TrainRecord *record in trainArray) {
  941. [DB_Helper updateTrainState:record];
  942. }
  943. if (trainArray.count > 0) {
  944. if (signOutSuccess) {
  945. if (![_secondString isEqualToString:@"0"]) {
  946. [self setSecondString:@"0"];
  947. }
  948. if (self.timer.isValid) {
  949. [self.timer invalidate];
  950. }
  951. if (self.timer) {
  952. self.timer = nil;
  953. }
  954. if (myDelegate.timer) {
  955. myDelegate.timer = nil;
  956. }
  957. if (myDelegate.tPeriodVC) {
  958. myDelegate.tPeriodVC = nil;
  959. }
  960. if (myDelegate.isTrain) {
  961. myDelegate.isTrain = NO;
  962. }
  963. if (![self.timeLabel.text isEqualToString:@"00:00:00"]) {
  964. self.timeLabel.text = @"00:00:00";
  965. }
  966. }
  967. if (signOutSuccess && uploadImageSuccess) {
  968. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"签退成功!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:nil];
  969. } else if (signOutSuccess && !uploadImageSuccess && completion) {
  970. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"上传照片失败!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"重新上传" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  971. completion();
  972. }];
  973. }
  974. } else {
  975. // 强制签退后再去调签到
  976. [self startTimingWithResultBlock:nil];
  977. }
  978. [RQ_COMMON_MANAGER keepIdleTimerDisabledisOpen:NO];
  979. }
  980. - (void)reUploadPhotoWithClassidStr:(NSString *)classidStr timeStr:(NSString *)timeStr actionPhotoStr:(NSString *)actionPhotoStr loginFlagType:(LoginFlagType)loginFlagType {
  981. __block BOOL reUploadSuccess = YES;
  982. __block BOOL isUploading = NO;
  983. int i = 0;
  984. do {
  985. if (i == 0) {
  986. if (!isUploading) {
  987. isUploading = YES;
  988. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:classidStr timeStr:timeStr actionPhotoStr:actionPhotoStr loginFlagType:loginFlagType resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  989. if (isSuccess) {
  990. ShowMsg(@"重新上传照片成功!");
  991. reUploadSuccess = YES;
  992. } else {
  993. reUploadSuccess = NO;
  994. }
  995. isUploading = NO;
  996. }];
  997. }
  998. } else {
  999. if (!isUploading) {
  1000. isUploading = YES;
  1001. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"上传照片失败!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"重新上传" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  1002. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:classidStr timeStr:timeStr actionPhotoStr:actionPhotoStr loginFlagType:loginFlagType resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  1003. if (isSuccess) {
  1004. ShowMsg(@"重新上传照片成功!");
  1005. reUploadSuccess = YES;
  1006. } else {
  1007. reUploadSuccess = NO;
  1008. }
  1009. isUploading = NO;
  1010. }];
  1011. }];
  1012. }
  1013. }
  1014. i ++;
  1015. } while (reUploadSuccess == NO);
  1016. }
  1017. #pragma mark - LazyLoad
  1018. - (QMUIMarqueeLabel *)marqueeLabel {
  1019. if (!_marqueeLabel) {
  1020. _marqueeLabel = [[QMUIMarqueeLabel alloc] qmui_initWithFont:[UIFont qmui_systemFontOfSize:17 weight:QMUIFontWeightBold italic:YES] textColor:UIColor.redColor];
  1021. @weakify(_marqueeLabel)
  1022. _marqueeLabel.text = @"在深夜时间,进行理论计时,记得在十二点前签退!否则,会丢失部分学时!!!";
  1023. _marqueeLabel.hidden = YES;
  1024. [RACObserve(_marqueeLabel, hidden) subscribeNext:^(id _Nullable x) {
  1025. @strongify(_marqueeLabel)
  1026. if (_marqueeLabel.hidden) {
  1027. [_marqueeLabel requestToStopAnimation];
  1028. } else {
  1029. [_marqueeLabel requestToStartAnimation];
  1030. }
  1031. }];
  1032. }
  1033. return _marqueeLabel;
  1034. }
  1035. - (UIView *)adView {
  1036. if (!_adView) {
  1037. _adView = [[UIView alloc] initWithFrame:CGRectMake(25, (kSize.height - kNavOffSet - kSafeAreaBottomHeight) - 60, kSize.width - 50, (kSize.width - 50) / (640/100.0))];
  1038. _adView.layer.cornerRadius = 5;
  1039. _adView.clipsToBounds = YES;
  1040. }
  1041. return _adView;
  1042. }
  1043. //- (QMUIPopupMenuView *)popupAtBarButtonItem {
  1044. // if (!_popupAtBarButtonItem) {
  1045. // @weakify(self)
  1046. // _popupAtBarButtonItem = [[QMUIPopupMenuView alloc] init];
  1047. // _popupAtBarButtonItem.automaticallyHidesWhenUserTap = YES;// 点击空白地方消失浮层
  1048. // _popupAtBarButtonItem.maximumWidth = RQ_SCREEN_WIDTH / 2.f;
  1049. // _popupAtBarButtonItem.shouldShowItemSeparator = YES;
  1050. // _popupAtBarButtonItem.tintColor = RQ_MAIN_COLOR;
  1051. // _popupAtBarButtonItem.items = @[[QMUIPopupMenuButtonItem itemWithImage:nil title:@"从业科目一" handler:^(QMUIPopupMenuButtonItem * _Nonnull aItem) {
  1052. // @strongify(self)
  1053. // self.rightBarButtonItem.title = aItem.title;
  1054. // RQ_USER_MANAGER.cykhPxkmStr = @"5";
  1055. // [aItem.menuView hideWithAnimated:YES];
  1056. // }],
  1057. // [QMUIPopupMenuButtonItem itemWithImage:nil title:@"从业科目二" handler:^(QMUIPopupMenuButtonItem * _Nonnull aItem) {
  1058. // @strongify(self)
  1059. // self.rightBarButtonItem.title = aItem.title;
  1060. // RQ_USER_MANAGER.cykhPxkmStr = @"6";
  1061. // [aItem.menuView hideWithAnimated:YES];
  1062. // }],
  1063. // [QMUIPopupMenuButtonItem itemWithImage:nil title:@"从业科目四" handler:^(QMUIPopupMenuButtonItem * _Nonnull aItem) {
  1064. // @strongify(self)
  1065. // self.rightBarButtonItem.title = aItem.title;
  1066. // RQ_USER_MANAGER.cykhPxkmStr = @"7";
  1067. // [aItem.menuView hideWithAnimated:YES];
  1068. // }],
  1069. // [QMUIPopupMenuButtonItem itemWithImage:nil title:@"从业考核" handler:^(QMUIPopupMenuButtonItem * _Nonnull aItem) {
  1070. // @strongify(self)
  1071. // self.rightBarButtonItem.title = aItem.title;
  1072. // RQ_USER_MANAGER.cykhPxkmStr = @"8";
  1073. // [aItem.menuView hideWithAnimated:YES];
  1074. // }]];
  1075. // }
  1076. // return _popupAtBarButtonItem;
  1077. //}
  1078. //- (UIBarButtonItem *)rightBarButtonItem {
  1079. // if (!_rightBarButtonItem) {
  1080. // _rightBarButtonItem = [UIBarButtonItem rq_systemItemWithTitle:RQStringIsEmpty(RQ_USER_MANAGER.cykhPxkmStr)? @"从业培训" : RQ_USER_MANAGER.cykhPxkmStr titleColor:RQ_MAIN_COLOR imageName:nil target:self selector:@selector(handleRightBarButtonItemEvent) textType:YES];
  1081. // @weakify(_rightBarButtonItem)
  1082. // [RACObserve(myDelegate, isUseriPhone) subscribeNext:^(id _Nullable x) {
  1083. // @strongify(_rightBarButtonItem)
  1084. // if (myDelegate.isUseriPhone) {
  1085. // _rightBarButtonItem.action = nil;
  1086. // } else {
  1087. // _rightBarButtonItem.action = @selector(handleRightBarButtonItemEvent);
  1088. // }
  1089. // }];
  1090. // }
  1091. // return _rightBarButtonItem;
  1092. //}
  1093. //- (void)handleRightBarButtonItemEvent {
  1094. // if (self.popupAtBarButtonItem.isShowing) {
  1095. // [self.popupAtBarButtonItem hideWithAnimated:YES];
  1096. // } else {
  1097. // // 相对于右上角的按钮布局
  1098. // self.popupAtBarButtonItem.sourceBarItem = self.navigationItem.rightBarButtonItem;
  1099. // [self.popupAtBarButtonItem showWithAnimated:YES];
  1100. // }
  1101. //}
  1102. //从业计时-切换弹窗
  1103. - (BOOL)checkCykhChooseStr {
  1104. @weakify(self)
  1105. if (RQStringIsNotEmpty(RQ_USER_MANAGER.cykhPxkmStr)) {
  1106. return YES;
  1107. } else {
  1108. [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"请选择从业计时类型" confirmTitle:@"确定" cancelTitle:@"取消" confirmAction:^{
  1109. @strongify(self)
  1110. // [self handleRightBarButtonItemEvent];
  1111. } cancelAction:nil];
  1112. return NO;
  1113. }
  1114. }
  1115. @end