NYClassRoomPeiCell.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. //
  2. // NYClassRoomPeiCell.m
  3. // jiaPei
  4. //
  5. // Created by Ning.ge on 2024/2/4.
  6. // Copyright © 2024 JCZ. All rights reserved.
  7. //
  8. #import "NYClassRoomPeiCell.h"
  9. #import "NYClassRoomPeiViewModel.h"
  10. #import "MapManager.h"
  11. #import "TZImagePickerController.h"//第三方相册
  12. #import "NYClassRoomPeiPhotoCell.h"
  13. @interface NYClassRoomPeiCell ()<TZImagePickerControllerDelegate,UICollectionViewDelegate,UICollectionViewDataSource>{
  14. CGFloat _itemWH;
  15. CGFloat _margin;
  16. NSInteger _index;
  17. }
  18. @property (nonatomic, readwrite, strong) NYClassRoomPeiViewModel *viewModel;
  19. @property (nonatomic, readwrite, assign) CLLocationCoordinate2D myLocation;
  20. @property (nonatomic ,strong) NSMutableArray *photosArray;
  21. @property (nonatomic ,strong) CultivateInfoModel *cultivateInfo;
  22. @end
  23. @implementation NYClassRoomPeiCell
  24. #pragma mark - PublicMethods
  25. + (instancetype)cellWithCollectionView:(UICollectionView *)collectionView forIndexPath:(NSIndexPath *)indexPath {
  26. static NSString *ID = @"NYClassRoomPeiCell";
  27. [collectionView registerNib:[UINib nibWithNibName:ID bundle:nil] forCellWithReuseIdentifier:ID];
  28. NYClassRoomPeiCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
  29. if (!cell) cell = [self rq_viewFromXib];
  30. [cell setup_UI];
  31. return cell;
  32. }
  33. -(void)setup_UI{
  34. [self.collectionView registerClass:[NYClassRoomPeiPhotoCell class] forCellWithReuseIdentifier:@"cell"];
  35. [self.imageArrayView addSubview:self.collectionView];
  36. [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.edges.mas_equalTo(self.imageArrayView);
  38. }];
  39. self.collectionView.backgroundColor = [UIColor colorWithHexString:@"#F2F3F5" alpha:1.0];
  40. }
  41. //详细
  42. - (void)setCultivateInfoModel:(CultivateInfoModel *)cultInfoModel{
  43. self.viewModel.cultivateInfoModel = cultInfoModel;
  44. RAC(self.coach_name_label, text) = [[RACObserve(cultInfoModel, coachName) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread];
  45. RAC(self.stu_name_label, text) = [[RACObserve(cultInfoModel, stuName) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread];
  46. // RAC(self.cat_type_label, text) = [[RACObserve(cultInfoModel, stuCx) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread];
  47. RAC(self.cat_num_label, text) = [[RACObserve(cultInfoModel, licnum) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread];
  48. RAC(self.room_name_label, text) = [[RACObserve(cultInfoModel, roomName) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread];
  49. RAC(self.course_ptime_label, text) = [[RACObserve(cultInfoModel, timeAll) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread];
  50. RAC(self.sign_time_label, text) = [[RACObserve(cultInfoModel, signTime) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread];
  51. RAC(self.exit_ptime_label, text) = [[RACObserve(cultInfoModel, nextDate) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread];
  52. }
  53. - (void)bindViewModel:(NYClassRoomPeiViewModel *)viewModel {
  54. self.viewModel = viewModel;
  55. [self getClassRoomInfo];
  56. //定位功能
  57. [MBProgressHUD rq_showProgressHUD:@"正在获取当前位置..."];
  58. [[MapManager sharedManager] updateLocationWithCompleteBlock:^(BOOL success, CLLocation * _Nonnull location, BMKLocation * _Nullable bmkLocation) {
  59. [MBProgressHUD rq_hideHUD];
  60. if (success) {
  61. _myLocation = location.coordinate;
  62. }
  63. }];
  64. }
  65. //获取 课堂 信息
  66. - (void)getClassRoomInfo{
  67. NSMutableArray *arr = [NSMutableArray array];
  68. [arr property:RQ_USER_MANAGER.currentUser.outId forKey:@"outid"];
  69. [arr property:@"1" forKey:@"type"];//1课堂 2模拟
  70. [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"];
  71. NSString* method = @"getStunocarSignInfo";
  72. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
  73. if (dict==nil||[dict[@"code"] intValue]!=0) {
  74. self.not_data_view.hidden = NO;
  75. return;
  76. }
  77. CultivateInfoModel *cultInfoModel = [CultivateInfoModel modelWithDictionary:[NSMutableDictionary dictionaryWithDictionary:dict[@"body"]]];
  78. self.cultivateInfo = cultInfoModel;
  79. [self getPhotoArray];
  80. }];
  81. }
  82. //获取课堂 照片
  83. - (void)getPhotoArray{
  84. NSString *classid = self.cultivateInfo.classid;
  85. NSMutableArray *arr = [NSMutableArray array];
  86. [arr property:RQ_USER_MANAGER.currentUser.outId forKey:@"outid"];
  87. [arr property:@"1" forKey:@"type"];//1课堂 2模拟
  88. [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"];
  89. [arr property:classid forKey:@"classid"];
  90. [self.photosArray removeAllObjects];
  91. NSString* method = @"getStunocarPhoto";
  92. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
  93. if (dict==nil||[dict[@"code"] intValue]!=0) {
  94. self.not_data_view.hidden = NO;
  95. return;
  96. }
  97. self.cultivateInfo.timeAll = dict[@"body"][@"timeAll"];
  98. self.cultivateInfo.nextDate = dict[@"body"][@"nextDate"];
  99. [self setCultivateInfoModel:self.cultivateInfo];
  100. NSArray<CultivatePhotoModel*> *photo_array = [CultivatePhotoModel modelArrayWithJSON:dict[@"body"][@"photos"]];
  101. [self.photosArray addObjectsFromArray:photo_array];
  102. [self.collectionView reloadData];
  103. }];
  104. }
  105. - (IBAction)submit_clickdo:(UIButton *)sender {
  106. if(_myLocation.latitude<=0){
  107. ShowMsg(@"定位失败!请重新定位!");
  108. return;
  109. }
  110. CultivateInfoModel *cultInfoModel = self.viewModel.cultivateInfoModel;
  111. // roomLat roomLng maxDistance
  112. //NSString *title = [NSString stringWithFormat:@"您距离课堂超过了%@m",cultInfoModel.maxDistance];
  113. //计算距离
  114. double this_distance = 0.0;
  115. double lat1 = cultInfoModel.roomLat.doubleValue;
  116. double lng1 = cultInfoModel.roomLng.doubleValue;
  117. // 26.122397, 119.251203
  118. if(_myLocation.latitude >0){
  119. double lat2 = _myLocation.latitude;//[[NSString stringWithFormat:@"%.6f",] doubleValue];
  120. double lng2 = _myLocation.longitude;//[[NSString stringWithFormat:@"%.6f",] doubleValue];
  121. this_distance = [MapManager getDistance:lat1 lng1:lng1 lat2:lat2 lng2:lng2]; // [self distanceBetweenOrderBy:lat1 :lat2 :lng1 :lng2];
  122. }
  123. if(this_distance>cultInfoModel.maxDistance.doubleValue){//超出范围
  124. if(cultInfoModel.isDistance){//是否强制 判断-范围
  125. [RQ_SHARE_FUNCTION showAlertWithTitle:@"提示" message:@"当前位置超出理论教室规定最大距离, 不能继续拍照" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"取消" otherButtonTitles:@[@"确定"] otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  126. if (selectedOtherButtonIndex == 0) {
  127. }
  128. }];
  129. }else{
  130. //友好提示一下
  131. [RQ_SHARE_FUNCTION showAlertWithTitle:@"提示" message:@"当前位置已超出理论教室规定最大距离, 是否继续拍照?" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"取消" otherButtonTitles:@[@"确定"] otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  132. if (selectedOtherButtonIndex == 0) {
  133. [self beginCheckBodyHumanface];
  134. }
  135. }];
  136. }
  137. }else{//未超出范围
  138. //直接-进入人脸-签到流程
  139. [self beginCheckBodyHumanface];
  140. }
  141. }
  142. //人脸比对流程
  143. -(void)beginCheckBodyHumanface{
  144. @weakify(self)
  145. /// 1.本地活体检测
  146. [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:RQ_USER_MANAGER.ycbdFaceCount completeBlock:^(BOOL success, NSDictionary * _Nullable dic) {
  147. if (success) {
  148. //上传-课堂照片
  149. __block NSMutableArray *arr = [NSMutableArray array];
  150. NSData *imageData = [[NSData alloc] initWithBase64EncodedString:dic[@"normalImg"] options:NSDataBase64DecodingIgnoreUnknownCharacters];
  151. NSString *method = [NSString stringWithFormat:@"education/imageup/%@/1/%@/nocar",RQ_USER_MANAGER.currentUser.city,RQ_USER_MANAGER.currentUser.outId];
  152. [jiaPeiManager requestAnythingImageWithURL:method array:arr data:imageData completion:^(NSDictionary *dict) {
  153. NSLog(@"%@",dict);
  154. int code = [dict[@"code"] intValue];
  155. if(code == 0 ){
  156. NSString *paths = dict[@"data"][@"paths"];
  157. NSString *photoid = dict[@"data"][@"id"];
  158. /// 2.线上活体检测
  159. [self stunocarfaceTofacedo:photoid];
  160. }else{
  161. if (dict[@"msg"]) {
  162. ShowMsg(dict[@"msg"]);
  163. return;
  164. }
  165. if (dict[@"body"]) {
  166. ShowMsg(dict[@"body"]);
  167. return;
  168. }
  169. }
  170. }];
  171. }else{
  172. ShowMsg(@"活体检测失败");
  173. }
  174. }];
  175. }
  176. // 人脸线上比对
  177. -(void)stunocarfaceTofacedo:(NSString *)photoid {
  178. NSMutableArray *arr = [NSMutableArray array];
  179. [arr property:RQ_USER_MANAGER.currentUser.outId forKey:@"stuId"];
  180. [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"];
  181. [arr property:photoid forKey:@"photo"];
  182. NSString* method = @"stunocarfaceToface";
  183. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
  184. if ([dict[@"code"] intValue] == 0)
  185. {
  186. [self updateStunocarPhoto:photoid];
  187. }
  188. else
  189. {
  190. if (dict[@"msg"]) {
  191. ShowMsg(dict[@"msg"]);
  192. return;
  193. }
  194. if (dict[@"body"]) {
  195. ShowMsg(dict[@"body"]);
  196. return;
  197. }
  198. }
  199. }];
  200. }
  201. // 过程上传
  202. -(void)updateStunocarPhoto:(NSString *)photoid{
  203. NSString *classid = self.cultivateInfo.classid;
  204. NSString *lat = [NSString stringWithFormat:@"%.6f",_myLocation.latitude];
  205. NSString *lng = [NSString stringWithFormat:@"%.6f",_myLocation.longitude];
  206. NSMutableArray *arr = [NSMutableArray array];
  207. [arr property:RQ_USER_MANAGER.currentUser.outId forKey:@"stuId"];
  208. [arr property:@"1" forKey:@"type"];//1课堂 2模拟
  209. [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"];
  210. [arr property:classid forKey:@"classid"];
  211. [arr property:photoid forKey:@"photo"];
  212. [arr property:lng forKey:@"lng"];
  213. [arr property:lat forKey:@"lat"];
  214. NSString* method = @"updateStunocarPhoto";
  215. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
  216. if ([dict[@"code"] intValue] == 0) {
  217. ShowMsg(@"上传照片成功!");
  218. [self getClassRoomInfo];
  219. }
  220. else
  221. {
  222. if (dict[@"msg"]) {
  223. ShowMsg(dict[@"msg"]);
  224. return;
  225. }
  226. if (dict[@"body"]) {
  227. ShowMsg(dict[@"body"]);
  228. return;
  229. }
  230. }
  231. }];
  232. }
  233. -(double)distanceBetweenOrderBy:(double) latitude1 :(double) latitude2 :(double) longitude1 :(double) longitude2{
  234. CLLocation *curLocation = [[CLLocation alloc] initWithLatitude:latitude1 longitude:longitude1];
  235. CLLocation *otherLocation = [[CLLocation alloc] initWithLatitude:latitude2 longitude:longitude2];
  236. // 计算两个坐标之间的距离
  237. //CLLocationDistance distance = [curLocation distanceFromLocation:otherLocation];
  238. double distance = [curLocation distanceFromLocation:otherLocation];
  239. return distance;
  240. }
  241. -(UICollectionView *)collectionView{
  242. if (!_collectionView) {
  243. UICollectionViewFlowLayout *flowLayOut = [[UICollectionViewFlowLayout alloc] init];
  244. flowLayOut.itemSize = CGSizeMake(80, 150);
  245. flowLayOut.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
  246. flowLayOut.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  247. self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayOut];
  248. self.collectionView.showsHorizontalScrollIndicator = NO;
  249. self.collectionView.delegate = self;
  250. self.collectionView.dataSource = self;
  251. // self.collectionView.scrollEnabled = NO;
  252. }
  253. return _collectionView;
  254. }
  255. - (NSMutableArray *)photosArray{
  256. if (!_photosArray) {
  257. self.photosArray = [NSMutableArray array];
  258. }
  259. return _photosArray;
  260. }
  261. #pragma mark - SystemMethods
  262. - (void)awakeFromNib {
  263. [super awakeFromNib];
  264. self.contentView.backgroundColor = UIColor.clearColor;
  265. _px00_view.layer.shadowColor = RGBA_COLOR(124, 129, 136, 0.2).CGColor;
  266. _px01_view.layer.shadowColor = RGBA_COLOR(124, 129, 136, 0.2).CGColor;
  267. }
  268. - (void)checkLocalPhoto{
  269. int currentIndex = _index;
  270. NSMutableArray *images = [NSMutableArray array];
  271. for (CultivatePhotoModel *photoModel in self.photosArray) {
  272. [images addObject:photoModel.filepath];
  273. }
  274. [RQ_SHARE_FUNCTION showPhotoBrowserWithDataSource:images currentIndex:currentIndex isCanSave:NO];
  275. }
  276. #pragma mark UICollectionViewDelegate
  277. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  278. _index = indexPath.row;
  279. [self checkLocalPhoto];
  280. }
  281. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  282. return _photosArray.count;
  283. }
  284. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  285. NYClassRoomPeiPhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
  286. CultivatePhotoModel *photoModel = self.photosArray[indexPath.row];
  287. cell.cultivatePhotoModel = photoModel;
  288. return cell;
  289. }
  290. @end