// // NYClassRoomPeiCell.m // jiaPei // // Created by Ning.ge on 2024/2/4. // Copyright © 2024 JCZ. All rights reserved. // #import "NYClassRoomPeiCell.h" #import "NYClassRoomPeiViewModel.h" #import "MapManager.h" #import "TZImagePickerController.h"//第三方相册 #import "NYClassRoomPeiPhotoCell.h" @interface NYClassRoomPeiCell (){ CGFloat _itemWH; CGFloat _margin; NSInteger _index; } @property (nonatomic, readwrite, strong) NYClassRoomPeiViewModel *viewModel; @property (nonatomic, readwrite, assign) CLLocationCoordinate2D myLocation; @property (nonatomic ,strong) NSMutableArray *photosArray; @property (nonatomic ,strong) CultivateInfoModel *cultivateInfo; @end @implementation NYClassRoomPeiCell #pragma mark - PublicMethods + (instancetype)cellWithCollectionView:(UICollectionView *)collectionView forIndexPath:(NSIndexPath *)indexPath { static NSString *ID = @"NYClassRoomPeiCell"; [collectionView registerNib:[UINib nibWithNibName:ID bundle:nil] forCellWithReuseIdentifier:ID]; NYClassRoomPeiCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath]; if (!cell) cell = [self rq_viewFromXib]; [cell setup_UI]; return cell; } -(void)setup_UI{ [self.collectionView registerClass:[NYClassRoomPeiPhotoCell class] forCellWithReuseIdentifier:@"cell"]; [self.imageArrayView addSubview:self.collectionView]; [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.mas_equalTo(self.imageArrayView); }]; self.collectionView.backgroundColor = [UIColor colorWithHexString:@"#F2F3F5" alpha:1.0]; } //详细 - (void)setCultivateInfoModel:(CultivateInfoModel *)cultInfoModel{ self.viewModel.cultivateInfoModel = cultInfoModel; RAC(self.coach_name_label, text) = [[RACObserve(cultInfoModel, coachName) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread]; RAC(self.stu_name_label, text) = [[RACObserve(cultInfoModel, stuName) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread]; // RAC(self.cat_type_label, text) = [[RACObserve(cultInfoModel, stuCx) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread]; RAC(self.cat_num_label, text) = [[RACObserve(cultInfoModel, licnum) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread]; RAC(self.room_name_label, text) = [[RACObserve(cultInfoModel, roomName) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread]; RAC(self.course_ptime_label, text) = [[RACObserve(cultInfoModel, timeAll) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread]; RAC(self.sign_time_label, text) = [[RACObserve(cultInfoModel, signTime) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread]; RAC(self.exit_ptime_label, text) = [[RACObserve(cultInfoModel, nextDate) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread]; } - (void)bindViewModel:(NYClassRoomPeiViewModel *)viewModel { self.viewModel = viewModel; [self getClassRoomInfo]; //定位功能 [MBProgressHUD rq_showProgressHUD:@"正在获取当前位置..."]; [[MapManager sharedManager] updateLocationWithCompleteBlock:^(BOOL success, CLLocation * _Nonnull location, BMKLocation * _Nullable bmkLocation) { [MBProgressHUD rq_hideHUD]; if (success) { _myLocation = location.coordinate; } }]; } //获取 课堂 信息 - (void)getClassRoomInfo{ NSMutableArray *arr = [NSMutableArray array]; [arr property:RQ_USER_MANAGER.currentUser.outId forKey:@"outid"]; [arr property:@"1" forKey:@"type"];//1课堂 2模拟 [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"]; NSString* method = @"getStunocarSignInfo"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) { if (dict==nil||[dict[@"code"] intValue]!=0) { self.not_data_view.hidden = NO; return; } CultivateInfoModel *cultInfoModel = [CultivateInfoModel modelWithDictionary:[NSMutableDictionary dictionaryWithDictionary:dict[@"body"]]]; self.cultivateInfo = cultInfoModel; [self getPhotoArray]; }]; } //获取课堂 照片 - (void)getPhotoArray{ NSString *classid = self.cultivateInfo.classid; NSMutableArray *arr = [NSMutableArray array]; [arr property:RQ_USER_MANAGER.currentUser.outId forKey:@"outid"]; [arr property:@"1" forKey:@"type"];//1课堂 2模拟 [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"]; [arr property:classid forKey:@"classid"]; [self.photosArray removeAllObjects]; NSString* method = @"getStunocarPhoto"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) { if (dict==nil||[dict[@"code"] intValue]!=0) { self.not_data_view.hidden = NO; return; } self.cultivateInfo.timeAll = dict[@"body"][@"timeAll"]; self.cultivateInfo.nextDate = dict[@"body"][@"nextDate"]; [self setCultivateInfoModel:self.cultivateInfo]; NSArray *photo_array = [CultivatePhotoModel modelArrayWithJSON:dict[@"body"][@"photos"]]; [self.photosArray addObjectsFromArray:photo_array]; [self.collectionView reloadData]; }]; } - (IBAction)submit_clickdo:(UIButton *)sender { if(_myLocation.latitude<=0){ ShowMsg(@"定位失败!请重新定位!"); return; } CultivateInfoModel *cultInfoModel = self.viewModel.cultivateInfoModel; // roomLat roomLng maxDistance //NSString *title = [NSString stringWithFormat:@"您距离课堂超过了%@m",cultInfoModel.maxDistance]; //计算距离 double this_distance = 0.0; double lat1 = cultInfoModel.roomLat.doubleValue; double lng1 = cultInfoModel.roomLng.doubleValue; // 26.122397, 119.251203 if(_myLocation.latitude >0){ double lat2 = _myLocation.latitude;//[[NSString stringWithFormat:@"%.6f",] doubleValue]; double lng2 = _myLocation.longitude;//[[NSString stringWithFormat:@"%.6f",] doubleValue]; this_distance = [MapManager getDistance:lat1 lng1:lng1 lat2:lat2 lng2:lng2]; // [self distanceBetweenOrderBy:lat1 :lat2 :lng1 :lng2]; } if(this_distance>cultInfoModel.maxDistance.doubleValue){//超出范围 if(cultInfoModel.isDistance){//是否强制 判断-范围 [RQ_SHARE_FUNCTION showAlertWithTitle:@"提示" message:@"当前位置超出理论教室规定最大距离, 不能继续拍照" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"取消" otherButtonTitles:@[@"确定"] otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) { if (selectedOtherButtonIndex == 0) { } }]; }else{ //友好提示一下 [RQ_SHARE_FUNCTION showAlertWithTitle:@"提示" message:@"当前位置已超出理论教室规定最大距离, 是否继续拍照?" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"取消" otherButtonTitles:@[@"确定"] otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) { if (selectedOtherButtonIndex == 0) { [self beginCheckBodyHumanface]; } }]; } }else{//未超出范围 //直接-进入人脸-签到流程 [self beginCheckBodyHumanface]; } } //人脸比对流程 -(void)beginCheckBodyHumanface{ @weakify(self) /// 1.本地活体检测 [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:RQ_USER_MANAGER.ycbdFaceCount completeBlock:^(BOOL success, NSDictionary * _Nullable dic) { if (success) { //上传-课堂照片 __block NSMutableArray *arr = [NSMutableArray array]; NSData *imageData = [[NSData alloc] initWithBase64EncodedString:dic[@"normalImg"] options:NSDataBase64DecodingIgnoreUnknownCharacters]; NSString *method = [NSString stringWithFormat:@"education/imageup/%@/1/%@/nocar",RQ_USER_MANAGER.currentUser.city,RQ_USER_MANAGER.currentUser.outId]; [jiaPeiManager requestAnythingImageWithURL:method array:arr data:imageData completion:^(NSDictionary *dict) { NSLog(@"%@",dict); int code = [dict[@"code"] intValue]; if(code == 0 ){ NSString *paths = dict[@"data"][@"paths"]; NSString *photoid = dict[@"data"][@"id"]; /// 2.线上活体检测 [self stunocarfaceTofacedo:photoid]; }else{ if (dict[@"msg"]) { ShowMsg(dict[@"msg"]); return; } if (dict[@"body"]) { ShowMsg(dict[@"body"]); return; } } }]; }else{ ShowMsg(@"活体检测失败"); } }]; } // 人脸线上比对 -(void)stunocarfaceTofacedo:(NSString *)photoid { NSMutableArray *arr = [NSMutableArray array]; [arr property:RQ_USER_MANAGER.currentUser.outId forKey:@"stuId"]; [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"]; [arr property:photoid forKey:@"photo"]; NSString* method = @"stunocarfaceToface"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) { if ([dict[@"code"] intValue] == 0) { [self updateStunocarPhoto:photoid]; } else { if (dict[@"msg"]) { ShowMsg(dict[@"msg"]); return; } if (dict[@"body"]) { ShowMsg(dict[@"body"]); return; } } }]; } // 过程上传 -(void)updateStunocarPhoto:(NSString *)photoid{ NSString *classid = self.cultivateInfo.classid; NSString *lat = [NSString stringWithFormat:@"%.6f",_myLocation.latitude]; NSString *lng = [NSString stringWithFormat:@"%.6f",_myLocation.longitude]; NSMutableArray *arr = [NSMutableArray array]; [arr property:RQ_USER_MANAGER.currentUser.outId forKey:@"stuId"]; [arr property:@"1" forKey:@"type"];//1课堂 2模拟 [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"]; [arr property:classid forKey:@"classid"]; [arr property:photoid forKey:@"photo"]; [arr property:lng forKey:@"lng"]; [arr property:lat forKey:@"lat"]; NSString* method = @"updateStunocarPhoto"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) { if ([dict[@"code"] intValue] == 0) { ShowMsg(@"上传照片成功!"); [self getClassRoomInfo]; } else { if (dict[@"msg"]) { ShowMsg(dict[@"msg"]); return; } if (dict[@"body"]) { ShowMsg(dict[@"body"]); return; } } }]; } -(double)distanceBetweenOrderBy:(double) latitude1 :(double) latitude2 :(double) longitude1 :(double) longitude2{ CLLocation *curLocation = [[CLLocation alloc] initWithLatitude:latitude1 longitude:longitude1]; CLLocation *otherLocation = [[CLLocation alloc] initWithLatitude:latitude2 longitude:longitude2]; // 计算两个坐标之间的距离 //CLLocationDistance distance = [curLocation distanceFromLocation:otherLocation]; double distance = [curLocation distanceFromLocation:otherLocation]; return distance; } -(UICollectionView *)collectionView{ if (!_collectionView) { UICollectionViewFlowLayout *flowLayOut = [[UICollectionViewFlowLayout alloc] init]; flowLayOut.itemSize = CGSizeMake(80, 150); flowLayOut.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5); flowLayOut.scrollDirection = UICollectionViewScrollDirectionHorizontal; self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayOut]; self.collectionView.showsHorizontalScrollIndicator = NO; self.collectionView.delegate = self; self.collectionView.dataSource = self; // self.collectionView.scrollEnabled = NO; } return _collectionView; } - (NSMutableArray *)photosArray{ if (!_photosArray) { self.photosArray = [NSMutableArray array]; } return _photosArray; } #pragma mark - SystemMethods - (void)awakeFromNib { [super awakeFromNib]; self.contentView.backgroundColor = UIColor.clearColor; _px00_view.layer.shadowColor = RGBA_COLOR(124, 129, 136, 0.2).CGColor; _px01_view.layer.shadowColor = RGBA_COLOR(124, 129, 136, 0.2).CGColor; } - (void)checkLocalPhoto{ int currentIndex = _index; NSMutableArray *images = [NSMutableArray array]; for (CultivatePhotoModel *photoModel in self.photosArray) { [images addObject:photoModel.filepath]; } [RQ_SHARE_FUNCTION showPhotoBrowserWithDataSource:images currentIndex:currentIndex isCanSave:NO]; } #pragma mark UICollectionViewDelegate - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ _index = indexPath.row; [self checkLocalPhoto]; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return _photosArray.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ NYClassRoomPeiPhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath]; CultivatePhotoModel *photoModel = self.photosArray[indexPath.row]; cell.cultivatePhotoModel = photoModel; return cell; } @end