NYBasetjTimeVC.m 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227
  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.isTrain = YES;
  347. myDelegate.tPeriodVC = self;
  348. ShowMsgSuc();
  349. }
  350. else
  351. {
  352. ShowMsg(dict[@"body"]);
  353. [Tools playAudioWithString:dict[@"body"]];
  354. }
  355. }];
  356. }
  357. - (void)setSecondString:(NSString *)secondString {
  358. _secondString = secondString;
  359. }
  360. - (void)timeFireMethod {
  361. @weakify(self)
  362. self.seconds++;
  363. [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]];
  364. int hour = 0;
  365. int min = 0;
  366. int second = 0;
  367. if (RQ_USER_MANAGER.isycbd == 1) {
  368. NSString *pxkm = RQ_USER_MANAGER.currentUser.pxjd;
  369. if (pxkm.length < 1) {
  370. pxkm = @"1";
  371. }
  372. if (([pxkm isEqualToString:@"2"] || [pxkm isEqualToString:@"3"])) {
  373. pxkm = @"4";
  374. }
  375. // NSLog(@"isNotGcbd=%d",RQ_USER_MANAGER.currentUser.isNotGcbd);
  376. int remainder1 = [RQ_USER_MANAGER.currentUser.city isEqualToString:@"3303"]? (int)(self.seconds)%1200 : (int)(self.seconds)%780;
  377. // int remainder1 = (int)(self.seconds)%120;
  378. if (remainder1 == 0 && RQ_USER_MANAGER.currentUser.isNotGcbd) { //过程照片isNotGcbd
  379. NSLog(@"在视频的时候-切换成竖屏%zd",RQ_Video_Module.playerController.player.isFullScreen);
  380. if(RQ_Video_Module.playerController.player.isFullScreen){//在视频的时候-切换成竖屏
  381. [RQ_Video_Module backBtnClickActiondo];
  382. }
  383. UIViewController *current_VC = RQControllerHelper.currentViewController;
  384. if([current_VC isKindOfClass:[NYExaminationViewController class]]||
  385. [current_VC isKindOfClass:[NYExaminationRoomViewController class]]){
  386. return ;//在考试模式下不显示人脸拍照
  387. }
  388. [self.timer setFireDate:[NSDate distantFuture]];
  389. SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindow];
  390. alert.backgroundViewColor = backGroundColor;
  391. alert.customViewColor = RQ_MAIN_COLOR;
  392. [alert addButton:@"立即开始 " actionBlock:^(void) {
  393. dispatch_async(dispatch_get_main_queue(), ^{
  394. @strongify(self)
  395. /// 1.本地活体检测
  396. [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:RQ_USER_MANAGER.ycbdFaceCount completeBlock:^(BOOL success, NSDictionary * _Nullable dic) {
  397. @strongify(self)
  398. if (success) {
  399. /// 2.线上活体检测
  400. [RQ_RemoteTheory_MANAGER edufaceTofaceWithPhotoStr:dic[@"normalImg"] loginFlagType:LoginFlagType_Process resultBlock:^(BOOL isSuccess) {
  401. @strongify(self)
  402. if (isSuccess) {
  403. /// 2.5 温州(3303)上传照片的时间是实时取服务器时间 其他地市采取从开始计时时间+累计计时时长的时间
  404. if ([RQ_USER_MANAGER.currentUser.city isEqualToString:@"3303"]) {
  405. [RQ_RemoteTheory_MANAGER getCurrentTimeWithResultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull timeDict) {
  406. @strongify(self)
  407. if (isSuccess) {
  408. /// 3.1上传过程照片
  409. NSString *timeStr = timeDict[@"body"];
  410. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_Process resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  411. @strongify(self)
  412. if (isSuccess) {
  413. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"过程验证成功" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  414. @strongify(self)
  415. [self.timer setFireDate:[NSDate distantPast]];
  416. }];
  417. } else {
  418. self.seconds--;
  419. [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]];
  420. [self.timer setFireDate:[NSDate distantPast]];
  421. }
  422. }];
  423. } else {
  424. self.seconds--;
  425. [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]];
  426. [self.timer setFireDate:[NSDate distantPast]];
  427. }
  428. }];
  429. } else {
  430. NSString *timeStr = [self getTimes:self.seconds];
  431. /// 3.2上传过程照片
  432. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_Process resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  433. @strongify(self)
  434. if (isSuccess) {
  435. [self lnShowTimeHandler];
  436. } else {
  437. self.seconds--;
  438. [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]];
  439. [self.timer setFireDate:[NSDate distantPast]];
  440. }
  441. }];
  442. }
  443. } else {
  444. self.seconds--;
  445. [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]];
  446. [self.timer setFireDate:[NSDate distantPast]];
  447. }
  448. }];
  449. } else {
  450. self.seconds--;
  451. [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]];
  452. [self.timer setFireDate:[NSDate distantPast]];
  453. }
  454. }];
  455. });
  456. }];
  457. [alert addTimerToButtonIndex:0 reverse:YES];
  458. [alert showNotice:@"温馨提示" subTitle:@"即将开始活体检测,请做好准备" closeButtonTitle:nil duration:5.0f];
  459. }
  460. } else {
  461. }
  462. int remainder;
  463. if (RQ_USER_MANAGER.isycbd == 1) {
  464. remainder = (int)self.seconds%1800;
  465. } else {
  466. remainder = (int)self.seconds%300;
  467. }
  468. if (remainder == 0) {
  469. //每5分钟保存一次,温州每30分钟保存一次
  470. [self saveTrain];
  471. }
  472. //判断-辽宁-晚上23:55分
  473. if((int)self.seconds%30==0){
  474. NSLog(@"判断-辽宁-晚上23:55分");
  475. [self lnShowTime2399Handler];
  476. }
  477. hour = (int)self.seconds / 3600;
  478. min = (int)self.seconds % 3600 / 60;
  479. second = (int)self.seconds % 3600 % 60;
  480. NSString *min_s;
  481. NSString *second_s;
  482. if (min<10) {
  483. min_s=[NSString stringWithFormat:@"0%d",min];
  484. }else{
  485. min_s=[NSString stringWithFormat:@"%d",min];
  486. }
  487. if (second<10) {
  488. second_s=[NSString stringWithFormat:@"0%d",second];
  489. }else{
  490. second_s=[NSString stringWithFormat:@"%d",second];
  491. }
  492. //凌晨重新计时 只是为了防止夜里挂学时 导致一天挂学时超过4小时做的处理 但是这样的话 学员就可以一夜挂8个小时 这样反而不好 应该取消这个 如果连续超过四个小时 判定无效 dansonmark
  493. /*
  494. NSString *time=[myDelegate.begin_Time substringWithRange:NSMakeRange(0, 10)];
  495. time=[NSString stringWithFormat:@"%@ 23:59:59",time];
  496. if ([[self getTimes:self.seconds] isEqualToString:time]) {
  497. [self saveTrain];
  498. //加2就不会连在一起了
  499. self.seconds = self.seconds+2;
  500. //重置开始时间
  501. myDelegate.begin_Time = [self getTimes:self.seconds];
  502. self.seconds = 0;
  503. }
  504. */
  505. //更新UI上的时间
  506. self.timeLabel.text = [NSString stringWithFormat:@"0%d:%@:%@",hour,min_s,second_s];
  507. }
  508. //call电话 - 进来处理
  509. - (void)phoneCallForHandler:(NSString *)callState{
  510. // 电话状态发生变化
  511. if ([callState isEqualToString:CTCallStateDialing]) {
  512. NSLog(@"拨号中");
  513. [self calllongTimeHandler];
  514. } else if ([callState isEqualToString:CTCallStateConnected]) {
  515. NSLog(@"已接通-不处理");
  516. } else if ([callState isEqualToString:CTCallStateDisconnected]) {
  517. NSLog(@"已挂断-不处理");
  518. } else if ([callState isEqualToString:CTCallStateIncoming]) {
  519. NSLog(@"来电中");
  520. [self calllongTimeHandler];
  521. }
  522. }
  523. //超过15分钟-提示暂停-签退
  524. - (void)calllongTimeHandler{
  525. @weakify(self)
  526. if(self.seconds>=900){
  527. [self.timer setFireDate:[NSDate distantFuture]];
  528. //暂停计时
  529. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"为了您的学时有效性,请优先选择签退" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"签退" otherButtonTitles:@[@"取消"] otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  530. NSLog(@"%zd",selectedOtherButtonIndex);
  531. if(selectedOtherButtonIndex==0){//取消
  532. [self.timer setFireDate:[NSDate distantPast]];//恢复计时
  533. }else{//签退
  534. //走-签退-结束计时流程
  535. @strongify(self)
  536. [self btnClick:self.on_offBtn];
  537. }
  538. }];
  539. }
  540. }
  541. //2.4 辽宁-特殊判断 - 拍照上传-超时处理
  542. - (void)lnShowTimeHandler {
  543. @weakify(self)
  544. if ([[RQ_USER_MANAGER getParamsKey:@"APP_LN_DQBH"] rangeOfString:RQ_USER_MANAGER.currentUser.city].location != NSNotFound) {//是否辽宁
  545. NSString *this_timeStr = [self getTimes:self.seconds];//当前计时器时间
  546. //提示: 本次训练暂停学时较多. 请先签退, 再重新签到)
  547. [RQ_RemoteTheory_MANAGER getCurrentTimeWithResultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull timeDict) {
  548. @strongify(self)
  549. if (isSuccess) {
  550. NSString *now_timeStr = timeDict[@"body"];
  551. //如果-暂停超过15分钟-提示-签退
  552. double timecount = fabs([self timeDifferenceExceedingSecondsBetween:this_timeStr and:now_timeStr]);
  553. NSLog(@"辽宁timecount=%f",timecount);
  554. if(timecount>900){
  555. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"本次训练暂停学时较多. 请先签退, 再重新签到" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"签退" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  556. //走-签退-结束计时流程
  557. @strongify(self)
  558. [self btnClick:self.on_offBtn];
  559. }];
  560. }else{
  561. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"过程验证成功" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  562. @strongify(self)
  563. [self.timer setFireDate:[NSDate distantPast]];
  564. }];
  565. }
  566. }
  567. }];
  568. return;
  569. }else{//非辽宁-直接提示成功
  570. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"过程验证成功" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  571. @strongify(self)
  572. [self.timer setFireDate:[NSDate distantPast]];
  573. }];
  574. }
  575. }
  576. //2.5 辽宁-特殊判断 - 凌晨提醒签退
  577. - (void)lnShowTime2399Handler {
  578. @weakify(self)
  579. if ([[RQ_USER_MANAGER getParamsKey:@"APP_LN_DQBH"] rangeOfString:RQ_USER_MANAGER.currentUser.city].location != NSNotFound) {//是否辽宁
  580. NSString *time=[myDelegate.begin_Time substringWithRange:NSMakeRange(0, 10)];
  581. NSString *time50=[NSString stringWithFormat:@"%@ 23:50:00",time];
  582. NSString *time55=[NSString stringWithFormat:@"%@ 23:55:00",time];
  583. NSString *this_timeStr = [self getTimes:self.seconds];
  584. //如果-暂停超过15分钟-提示-签退
  585. double timecount = [self timeDifferenceExceedingSecondsBetween:this_timeStr and:time50];
  586. if(timecount<0){
  587. double timecount55 = [self timeDifferenceExceedingSecondsBetween:this_timeStr and:time55];
  588. if(timecount55<0){
  589. [self.timer setFireDate:[NSDate distantFuture]];
  590. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"本次培训即将隔日无效. 请先签退. 0点过后再重新签到" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"签退" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  591. //走-签退-结束计时流程
  592. @strongify(self)
  593. [self btnClick:self.on_offBtn];
  594. }];
  595. return;
  596. }else{
  597. ShowMsg(@"本次培训即将隔日无效. 请先签退. 0点过后再重新签到");
  598. return;
  599. }
  600. }
  601. //23:55:00 强制签退
  602. NSLog(@"this_timeStr=%@ time50=%@ time55=%@ %f",this_timeStr,time50,time55,timecount);
  603. }
  604. }
  605. - (void)stopTimingWithResultBlock:(void (^)(BOOL isSuccessed))resultBlock {
  606. @weakify(self)
  607. [self.timer setFireDate:[NSDate distantFuture]];
  608. [self saveTrain];
  609. if (RQ_USER_MANAGER.isycbd == 1) {
  610. /// 1.本地活体检测
  611. [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:RQ_USER_MANAGER.ycbdFaceCount completeBlock:^(BOOL success, NSDictionary * _Nullable dic) {
  612. @strongify(self)
  613. if (success) {
  614. /// 2.线上活体检测
  615. [RQ_RemoteTheory_MANAGER edufaceTofaceWithPhotoStr:dic[@"normalImg"] loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess) {
  616. @strongify(self)
  617. if (isSuccess) {
  618. /// 2.5 温州(3303)上传照片的时间是实时取服务器时间 其他地市采取从开始计时时间+累计计时时长的时间
  619. if ([RQ_USER_MANAGER.currentUser.city isEqualToString:@"3303"]) {
  620. [RQ_RemoteTheory_MANAGER getCurrentTimeWithResultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull timeDict) {
  621. @strongify(self)
  622. if (isSuccess) {
  623. /// 4.签退
  624. NSString *pxkm = RQ_USER_MANAGER.currentUser.pxjd;
  625. if (pxkm.length < 1) {
  626. pxkm = @"1";
  627. }
  628. if (([pxkm isEqualToString:@"2"] || [pxkm isEqualToString:@"3"])) {
  629. pxkm = @"4";
  630. }
  631. if(self.vcType == TimeVCTypeAJob){//从业
  632. pxkm = RQ_USER_MANAGER.cykhPxkmStr;
  633. }
  634. NSArray* array = [DB_Helper quearyTrain:RQStringIsNotEmpty(RQ_USER_MANAGER.currentUser.outId)? RQ_USER_MANAGER.currentUser.outId : @"" Subject:pxkm];
  635. if (array.count < 1) {
  636. !resultBlock? : resultBlock(YES);
  637. ShowMsg(@"本地无学时明细!");
  638. return;
  639. }
  640. [RQ_RemoteTheory_MANAGER uploadEduSignOutWithArray:array resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signOutDict) {
  641. @strongify(self)
  642. if (isSuccess) {
  643. !resultBlock? : resultBlock(YES);
  644. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:nil];
  645. /// 4.1上传签退照片
  646. NSString *timeStr = timeDict[@"body"];
  647. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  648. @strongify(self)
  649. if (isSuccess) {
  650. NSLog(@"上传签退照片成功!");
  651. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:YES completion:nil];
  652. } else {
  653. NSLog(@"上传签退照片失败!");
  654. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:^{
  655. @strongify(self)
  656. [self reUploadPhotoWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_SignOut];
  657. }];
  658. }
  659. }];
  660. } else {
  661. !resultBlock? : resultBlock(NO);
  662. [self.timer setFireDate:[NSDate distantPast]];
  663. }
  664. }];
  665. } else {
  666. !resultBlock? : resultBlock(NO);
  667. [self.timer setFireDate:[NSDate distantPast]];
  668. }
  669. }];
  670. } else {
  671. /// 3.签退
  672. NSString *pxkm = RQ_USER_MANAGER.currentUser.pxjd;
  673. if (pxkm.length < 1) {
  674. pxkm = @"1";
  675. }
  676. if (([pxkm isEqualToString:@"2"] || [pxkm isEqualToString:@"3"])) {
  677. pxkm = @"4";
  678. }
  679. if(self.vcType == TimeVCTypeAJob){//从业
  680. pxkm = RQ_USER_MANAGER.cykhPxkmStr;
  681. }
  682. // if (RQ_USER_MANAGER.isCykh) {
  683. // if (![self checkCykhChooseStr]) {
  684. // !resultBlock? : resultBlock(YES);
  685. // return;
  686. // } else {
  687. // pxkm = RQ_USER_MANAGER.cykhPxkmStr;
  688. // }
  689. // }
  690. NSArray* array = [DB_Helper quearyTrain:RQStringIsNotEmpty(RQ_USER_MANAGER.currentUser.outId)? RQ_USER_MANAGER.currentUser.outId : @"" Subject:pxkm];
  691. if (array.count < 1) {
  692. !resultBlock? : resultBlock(YES);
  693. ShowMsg(@"本地无学时明细!");
  694. //[self.timer setFireDate:[NSDate distantPast]];
  695. return;
  696. }
  697. [RQ_RemoteTheory_MANAGER uploadEduSignOutWithArray:array resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signOutDict) {
  698. @strongify(self)
  699. if (isSuccess) {
  700. !resultBlock? : resultBlock(YES);
  701. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:nil];
  702. /// 4.2上传签退照片
  703. NSString *timeStr = [self getTimes:self.seconds];
  704. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  705. @strongify(self)
  706. if (isSuccess) {
  707. NSLog(@"上传签退照片成功!");
  708. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:YES completion:nil];
  709. } else {
  710. NSLog(@"上传签退照片失败!");
  711. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:^{
  712. [self reUploadPhotoWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:dic[@"actionImg"] loginFlagType:LoginFlagType_SignOut];
  713. }];
  714. }
  715. }];
  716. } else {
  717. !resultBlock? : resultBlock(NO);
  718. [self.timer setFireDate:[NSDate distantPast]];
  719. }
  720. }];
  721. }
  722. } else {
  723. !resultBlock? : resultBlock(NO);
  724. [self.timer setFireDate:[NSDate distantPast]];
  725. }
  726. }];
  727. } else {
  728. !resultBlock? : resultBlock(NO);
  729. [self.timer setFireDate:[NSDate distantPast]];
  730. }
  731. }];
  732. } else {
  733. !resultBlock? : resultBlock(YES);
  734. [self setSecondString:@"0"];
  735. [self.timer setFireDate:[NSDate distantFuture]];
  736. [self.timer invalidate];
  737. self.timer = nil;
  738. myDelegate.timer = nil;
  739. myDelegate.tPeriodVC = nil;
  740. myDelegate.isTrain = NO;
  741. self.timeLabel.text = @"00:00:00";
  742. // if (self.seconds < 60) {
  743. // ShowMsg(@"学时未满一分钟不统计");
  744. // return;
  745. // }
  746. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"结束计时,是否上传学时?" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"暂不上传" otherButtonTitles:@[@"确定"] otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  747. @strongify(self)
  748. if (selectedOtherButtonIndex == 0) {
  749. [self upLoadTrainRecord];
  750. }else if (selectedOtherButtonIndex == NSNotFound){
  751. ShowMsg(@"学时已保存在本地");
  752. }
  753. }];
  754. }
  755. }
  756. -(void)saveTrain {
  757. if (!self.formatter) {
  758. self.formatter = [NSDateFormatter rq_defaultDateFormatter];
  759. }
  760. TrainRecord *train = [[TrainRecord alloc]init];
  761. train.studentId = RQStringIsNotEmpty(RQ_USER_MANAGER.currentUser.outId)? RQ_USER_MANAGER.currentUser.outId : @"";
  762. train.beginTime = myDelegate.begin_Time;
  763. NSDate *date = [self.formatter dateFromString:myDelegate.begin_Time];
  764. date = [date dateByAddingTimeInterval:self.seconds];
  765. train.state = @"0";
  766. train.endTime=[self.formatter stringFromDate:date];
  767. NSInteger mins = self.seconds / 60;
  768. train.trainTime = [NSString stringWithFormat:@"%d",(int)mins];
  769. train.classid = (self.classIdStr && ![self.classIdStr isEqualToString:@""])? self.classIdStr : @"0";
  770. [DB_Helper saveTrain:train];
  771. }
  772. - (NSString *)getTimes:(int)second {
  773. if (!self.formatter) {
  774. self.formatter=[[NSDateFormatter alloc]init];
  775. [self.formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  776. }
  777. NSString *beginTimeStr = myDelegate.begin_Time;
  778. [self.formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
  779. NSDate *beginDate = [self.formatter dateFromString:beginTimeStr];
  780. NSDate *newDate = [NSDate dateWithTimeInterval:second sinceDate:beginDate];
  781. NSString *nowString = [self.formatter stringFromDate:newDate];
  782. return nowString;
  783. }
  784. - (void)upLoadTrainRecord{
  785. NSString *pxkm = RQ_USER_MANAGER.currentUser.pxjd;
  786. // NSString *crDate = RQ_USER_MANAGER.currentUser.crDate;
  787. // if (crDate.length > 10) {
  788. // crDate = [crDate substringToIndex:7];
  789. // }
  790. // NSArray *dateArray = [crDate componentsSeparatedByString:@"-"];
  791. // if ([[dateArray firstObject] integerValue] < 2016) {
  792. // pxkm = @"1";
  793. // }
  794. // if ([[dateArray firstObject] integerValue] == 2016) {
  795. //
  796. // if ([[dateArray lastObject] integerValue] < 11) {
  797. // pxkm = @"1";
  798. // }
  799. // }
  800. if (pxkm.length < 1) {
  801. pxkm = @"1";
  802. }
  803. /// 理论计时类型一地市编号:3501,3503 (福州,莆田;在科目二,科目三可以进行科目四的理论计时)
  804. if ([RQ_SHARE_FUNCTION.theoryOfTimingTypeOneCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && ([pxkm isEqualToString:@"2"] || [pxkm isEqualToString:@"3"])) {
  805. pxkm = @"4";
  806. }
  807. /// 理论计时类型二地市编号:null (暂无地市;在科目二可以进行科目四的理论计时)
  808. else if ([RQ_SHARE_FUNCTION.theoryOfTimingTypeTwoCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && [pxkm isEqualToString:@"2"]) {
  809. pxkm = @"4";
  810. }
  811. /// 理论计时类型三地市编号:3502 (厦门;在科目三可以进行科目四的理论计时)
  812. else if ([RQ_SHARE_FUNCTION.theoryOfTimingTypeThreeCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && [pxkm isEqualToString:@"3"]) {
  813. pxkm = @"4";
  814. }
  815. /// 新增地市 (新增地市;默认在科目二,科目三可以进行科目四的理论计时)
  816. 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"])) {
  817. pxkm = @"4";
  818. }
  819. if(self.vcType == TimeVCTypeAJob){//从业
  820. pxkm = RQ_USER_MANAGER.cykhPxkmStr;
  821. }
  822. // if (RQ_USER_MANAGER.isCykh) {
  823. // if (![self checkCykhChooseStr]) {
  824. // return;
  825. // } else {
  826. // pxkm = RQ_USER_MANAGER.cykhPxkmStr;
  827. // }
  828. // }
  829. NSArray* array = [DB_Helper quearyTrain:RQStringIsNotEmpty(RQ_USER_MANAGER.currentUser.outId)? RQ_USER_MANAGER.currentUser.outId : @"" Subject:pxkm];
  830. if (array.count < 1) {
  831. ShowMsg(@"本地无学时明细!");
  832. return;
  833. }
  834. //这里是对分段上传学时做的处理 如果学时上传有问题 查看这里
  835. [self uploadMoreTrainRecordWithArray:array];
  836. }
  837. - (void)uploadMoreTrainRecordWithArray:(NSArray *)trainArray
  838. {
  839. ShowHUD();
  840. if (![Util connectedToNetWork]) {
  841. showMsgUnconnect();
  842. return;
  843. }
  844. NSString* str = @"";
  845. for (TrainRecord *record in trainArray) {
  846. str = [str stringByAppendingString:[NSString stringWithFormat:@"%@,%@,%@,%@;",record.studentId,record.beginTime,record.endTime,record.trainTime]];
  847. }
  848. TrainRecord *record = [trainArray firstObject];
  849. /// 理论计时类型一地市编号:3501,3503 (福州,莆田;在科目二,科目三可以进行科目四的理论计时)
  850. if ([RQ_SHARE_FUNCTION.theoryOfTimingTypeOneCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && ([record.subject isEqualToString:@"2"] || [record.subject isEqualToString:@"3"])) {
  851. record.subject = @"4";
  852. }
  853. /// 理论计时类型二地市编号:null (暂无地市;在科目二可以进行科目四的理论计时)
  854. else if ([RQ_SHARE_FUNCTION.theoryOfTimingTypeTwoCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && [record.subject isEqualToString:@"2"]) {
  855. record.subject = @"4";
  856. }
  857. /// 理论计时类型三地市编号:3502 (厦门;在科目三可以进行科目四的理论计时)
  858. else if ([RQ_SHARE_FUNCTION.theoryOfTimingTypeThreeCityCodeArr containsObject:RQ_USER_MANAGER.currentUser.city] && [record.subject isEqualToString:@"3"]) {
  859. record.subject = @"4";
  860. }
  861. /// 新增地市 (新增地市;默认在科目二,科目三可以进行科目四的理论计时)
  862. 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"])) {
  863. record.subject = @"4";
  864. }
  865. NSMutableArray *arr = [NSMutableArray array];
  866. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"ios",@"trainType", nil]];
  867. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:[DES3Util encrypt:str ],@"trainRecord", nil]];
  868. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:record.subject,@"pxkm", nil]];
  869. NSString* method = @"uploadMoreTrainRecord";
  870. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  871. RemoveHUD();
  872. //NSLog(@"---------><>%@----><>%@",arr,dict);
  873. if (!dict) {
  874. ShowMsg(@"操作失败");
  875. return;
  876. }
  877. if ( [dict[@"code"] isEqualToString:@"1"]) {
  878. ShowMsg(dict[@"body"]);
  879. return;
  880. }
  881. if ( [dict[@"code"] isEqualToString:@"0"]) {
  882. for (TrainRecord *record in trainArray) {
  883. [DB_Helper updateTrainState:record];
  884. }
  885. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"上传学时成功!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:nil];
  886. }
  887. }];
  888. }
  889. #pragma mark btn
  890. - (void)btnClick:(UIButton *)sender {
  891. if(RQ_USER_MANAGER.currentUser.stuNum == nil ||
  892. [RQ_USER_MANAGER.currentUser.stuNum isEqualToString:@""]){
  893. ShowMsg(@"数据正在同步至监管平台,请先进行理论练习。");
  894. return;
  895. }
  896. UIButton *btn = sender;
  897. @weakify(self, btn)
  898. if (btn.enabled) {
  899. btn.enabled = NO;
  900. }
  901. if (myDelegate.isUseriPhone) {
  902. //点击事件 如果已经开始计时 调用里边的内容
  903. [self stopTimingWithResultBlock:^(BOOL isSuccessed) {
  904. @strongify(self, btn)
  905. btn.enabled = YES;
  906. if (isSuccessed) {
  907. [btn setTitle:@"开始计时" forState:UIControlStateNormal];
  908. myDelegate.isUseriPhone = NO;
  909. }
  910. }];
  911. }else{
  912. if (myDelegate.timer) {
  913. ShowMsg(@"请先关闭其他计时");
  914. return;
  915. }
  916. [self startTimingWithResultBlock:^(BOOL isSuccess) {
  917. @strongify(btn)
  918. btn.enabled = YES;
  919. }];
  920. }
  921. }
  922. #pragma mark - 温州远程理论
  923. //远程理论签到成功
  924. - (void)signInSuccessWithBeginTime:(NSString *)beginTime {
  925. myDelegate.begin_Time = beginTime;
  926. [Tools playAudioWithString:@"操作成功,开始计时"];
  927. self.seconds = 0;
  928. [self.on_offBtn setTitle:@"结束计时" forState:UIControlStateNormal];
  929. myDelegate.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES];
  930. myDelegate.isUseriPhone = YES;
  931. self.timer = myDelegate.timer;
  932. myDelegate.isTrain = YES;
  933. myDelegate.tPeriodVC = self;
  934. ShowMsgSuc();
  935. [RQ_COMMON_MANAGER keepIdleTimerDisabledisOpen:YES];
  936. [MBProgressHUD hideHUDForView:[RQ_SHARE_FUNCTION topViewController].view animated:YES];
  937. if ([RQ_USER_MANAGER.currentUser.city isEqualToString:@"3501"]) {
  938. WeakSelf(weakSelf)
  939. [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) {
  940. RemoveHUD();
  941. [MBProgressHUD hideHUDForView:weakSelf.view animated:YES];
  942. }];
  943. }
  944. }
  945. //远程理论签退成功
  946. - (void)signOutSuccessWithTrainArray:(NSArray *)trainArray signOutSuccess:(BOOL)signOutSuccess uploadImageSuccess:(BOOL)uploadImageSuccess completion:(void (^)(void))completion {
  947. for (TrainRecord *record in trainArray) {
  948. [DB_Helper updateTrainState:record];
  949. }
  950. if (trainArray.count > 0) {
  951. if (signOutSuccess) {
  952. if (![_secondString isEqualToString:@"0"]) {
  953. [self setSecondString:@"0"];
  954. }
  955. if (self.timer.isValid) {
  956. [self.timer invalidate];
  957. }
  958. if (self.timer) {
  959. self.timer = nil;
  960. }
  961. if (myDelegate.timer) {
  962. myDelegate.timer = nil;
  963. }
  964. if (myDelegate.tPeriodVC) {
  965. myDelegate.tPeriodVC = nil;
  966. }
  967. if (myDelegate.isTrain) {
  968. myDelegate.isTrain = NO;
  969. }
  970. if (![self.timeLabel.text isEqualToString:@"00:00:00"]) {
  971. self.timeLabel.text = @"00:00:00";
  972. }
  973. }
  974. if (signOutSuccess && uploadImageSuccess) {
  975. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"签退成功!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:nil];
  976. } else if (signOutSuccess && !uploadImageSuccess && completion) {
  977. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"上传照片失败!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"重新上传" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  978. completion();
  979. }];
  980. }
  981. } else {
  982. // 强制签退后再去调签到
  983. [self startTimingWithResultBlock:nil];
  984. }
  985. [RQ_COMMON_MANAGER keepIdleTimerDisabledisOpen:NO];
  986. }
  987. - (void)reUploadPhotoWithClassidStr:(NSString *)classidStr timeStr:(NSString *)timeStr actionPhotoStr:(NSString *)actionPhotoStr loginFlagType:(LoginFlagType)loginFlagType {
  988. __block BOOL reUploadSuccess = YES;
  989. __block BOOL isUploading = NO;
  990. int i = 0;
  991. do {
  992. if (i == 0) {
  993. if (!isUploading) {
  994. isUploading = YES;
  995. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:classidStr timeStr:timeStr actionPhotoStr:actionPhotoStr loginFlagType:loginFlagType resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  996. if (isSuccess) {
  997. ShowMsg(@"重新上传照片成功!");
  998. reUploadSuccess = YES;
  999. } else {
  1000. reUploadSuccess = NO;
  1001. }
  1002. isUploading = NO;
  1003. }];
  1004. }
  1005. } else {
  1006. if (!isUploading) {
  1007. isUploading = YES;
  1008. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"上传照片失败!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"重新上传" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  1009. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:classidStr timeStr:timeStr actionPhotoStr:actionPhotoStr loginFlagType:loginFlagType resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  1010. if (isSuccess) {
  1011. ShowMsg(@"重新上传照片成功!");
  1012. reUploadSuccess = YES;
  1013. } else {
  1014. reUploadSuccess = NO;
  1015. }
  1016. isUploading = NO;
  1017. }];
  1018. }];
  1019. }
  1020. }
  1021. i ++;
  1022. } while (reUploadSuccess == NO);
  1023. }
  1024. #pragma mark - LazyLoad
  1025. - (QMUIMarqueeLabel *)marqueeLabel {
  1026. if (!_marqueeLabel) {
  1027. _marqueeLabel = [[QMUIMarqueeLabel alloc] qmui_initWithFont:[UIFont qmui_systemFontOfSize:17 weight:QMUIFontWeightBold italic:YES] textColor:UIColor.redColor];
  1028. @weakify(_marqueeLabel)
  1029. _marqueeLabel.text = @"在深夜时间,进行理论计时,记得在十二点前签退!否则,会丢失部分学时!!!";
  1030. _marqueeLabel.hidden = YES;
  1031. [RACObserve(_marqueeLabel, hidden) subscribeNext:^(id _Nullable x) {
  1032. @strongify(_marqueeLabel)
  1033. if (_marqueeLabel.hidden) {
  1034. [_marqueeLabel requestToStopAnimation];
  1035. } else {
  1036. [_marqueeLabel requestToStartAnimation];
  1037. }
  1038. }];
  1039. }
  1040. return _marqueeLabel;
  1041. }
  1042. - (UIView *)adView {
  1043. if (!_adView) {
  1044. _adView = [[UIView alloc] initWithFrame:CGRectMake(25, (kSize.height - kNavOffSet - kSafeAreaBottomHeight) - 60, kSize.width - 50, (kSize.width - 50) / (640/100.0))];
  1045. _adView.layer.cornerRadius = 5;
  1046. _adView.clipsToBounds = YES;
  1047. }
  1048. return _adView;
  1049. }
  1050. //- (QMUIPopupMenuView *)popupAtBarButtonItem {
  1051. // if (!_popupAtBarButtonItem) {
  1052. // @weakify(self)
  1053. // _popupAtBarButtonItem = [[QMUIPopupMenuView alloc] init];
  1054. // _popupAtBarButtonItem.automaticallyHidesWhenUserTap = YES;// 点击空白地方消失浮层
  1055. // _popupAtBarButtonItem.maximumWidth = RQ_SCREEN_WIDTH / 2.f;
  1056. // _popupAtBarButtonItem.shouldShowItemSeparator = YES;
  1057. // _popupAtBarButtonItem.tintColor = RQ_MAIN_COLOR;
  1058. // _popupAtBarButtonItem.items = @[[QMUIPopupMenuButtonItem itemWithImage:nil title:@"从业科目一" handler:^(QMUIPopupMenuButtonItem * _Nonnull aItem) {
  1059. // @strongify(self)
  1060. // self.rightBarButtonItem.title = aItem.title;
  1061. // RQ_USER_MANAGER.cykhPxkmStr = @"5";
  1062. // [aItem.menuView hideWithAnimated:YES];
  1063. // }],
  1064. // [QMUIPopupMenuButtonItem itemWithImage:nil title:@"从业科目二" handler:^(QMUIPopupMenuButtonItem * _Nonnull aItem) {
  1065. // @strongify(self)
  1066. // self.rightBarButtonItem.title = aItem.title;
  1067. // RQ_USER_MANAGER.cykhPxkmStr = @"6";
  1068. // [aItem.menuView hideWithAnimated:YES];
  1069. // }],
  1070. // [QMUIPopupMenuButtonItem itemWithImage:nil title:@"从业科目四" handler:^(QMUIPopupMenuButtonItem * _Nonnull aItem) {
  1071. // @strongify(self)
  1072. // self.rightBarButtonItem.title = aItem.title;
  1073. // RQ_USER_MANAGER.cykhPxkmStr = @"7";
  1074. // [aItem.menuView hideWithAnimated:YES];
  1075. // }],
  1076. // [QMUIPopupMenuButtonItem itemWithImage:nil title:@"从业考核" handler:^(QMUIPopupMenuButtonItem * _Nonnull aItem) {
  1077. // @strongify(self)
  1078. // self.rightBarButtonItem.title = aItem.title;
  1079. // RQ_USER_MANAGER.cykhPxkmStr = @"8";
  1080. // [aItem.menuView hideWithAnimated:YES];
  1081. // }]];
  1082. // }
  1083. // return _popupAtBarButtonItem;
  1084. //}
  1085. //- (UIBarButtonItem *)rightBarButtonItem {
  1086. // if (!_rightBarButtonItem) {
  1087. // _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];
  1088. // @weakify(_rightBarButtonItem)
  1089. // [RACObserve(myDelegate, isUseriPhone) subscribeNext:^(id _Nullable x) {
  1090. // @strongify(_rightBarButtonItem)
  1091. // if (myDelegate.isUseriPhone) {
  1092. // _rightBarButtonItem.action = nil;
  1093. // } else {
  1094. // _rightBarButtonItem.action = @selector(handleRightBarButtonItemEvent);
  1095. // }
  1096. // }];
  1097. // }
  1098. // return _rightBarButtonItem;
  1099. //}
  1100. //- (void)handleRightBarButtonItemEvent {
  1101. // if (self.popupAtBarButtonItem.isShowing) {
  1102. // [self.popupAtBarButtonItem hideWithAnimated:YES];
  1103. // } else {
  1104. // // 相对于右上角的按钮布局
  1105. // self.popupAtBarButtonItem.sourceBarItem = self.navigationItem.rightBarButtonItem;
  1106. // [self.popupAtBarButtonItem showWithAnimated:YES];
  1107. // }
  1108. //}
  1109. //从业计时-切换弹窗
  1110. - (BOOL)checkCykhChooseStr {
  1111. @weakify(self)
  1112. if (RQStringIsNotEmpty(RQ_USER_MANAGER.cykhPxkmStr)) {
  1113. return YES;
  1114. } else {
  1115. [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"请选择从业计时类型" confirmTitle:@"确定" cancelTitle:@"取消" confirmAction:^{
  1116. @strongify(self)
  1117. // [self handleRightBarButtonItemEvent];
  1118. } cancelAction:nil];
  1119. return NO;
  1120. }
  1121. }
  1122. @end