only(['employee_id'=>0,'keyname'=>'','org_id'=>0,'page'=>1,'limit'=>21]); if (!request()->isAjax()){ //部门 $org = OrgLogic::struc($request->employee->root_id); View::assign('org', $org); $orgids = orgSubIds(request()->employee->root_id); View::assign('orgids', json_encode($orgids)); View::assign('empid', $request->employee->id); $group_count = VrGroup::where([['root_id','=',request()->employee->root_id],['status','=',2]])->count(); View::assign('group_count',$group_count); //审核开关 $switch = AppSetting::where([['code','=','auditSwitch'],['root_id','=',$request->employee->root_id],['content','=',1]])->findOrEmpty(); View::assign('switch',$switch->isEmpty() ? 0 : 1); return View::fetch(); } //直接作品列表 $topid = VrFloder::where([['root_id','=',$request->employee->root_id],['fld_type','=',2],['depth','=',0],['fld_name','=','全部']])->value('id'); //文件夹条件 $where[] = ['root_id','=',$request->employee->root_id]; $where[] = ['depth','=',1]; $where[] = ['fld_type','=',2]; //作品列表条件 $where1[] = ['status','=',2]; $where1[] = ['root_id','=',$request->employee->root_id]; $where1[] = ['team_floder_id','NULL',null]; //团队文件夹没有部门 只搜索作品 if ($param['org_id']) { $eids = Employee::where([['org_id','=',$param['org_id']],['state','=','在职'],['uid','>',0]])->column('id'); $where1[] = ['emp_id','in',$eids]; } //上传人搜索条件 if ($param['employee_id']) $where1[] = ['emp_id','=',$param['employee_id']]; //名称搜索条件 if($param['keyname']){ $where1[] = ['title','like','%'.$param['keyname'].'%']; $where[] = ['fld_name','like','%'.$param['keyname'].'%']; } //分页开始位置 $start = ($param['page']-1)*$param['limit']; $count1 = VrFloder::where($where)->count(); $count2 = VrGroup::where($where1)->count(); $count = $count1 + $count2; //文件夹列表在上面 文件夹长度 if($start==0 || $start <= $count1){ //第一页直接查询文件夹列表 $floder_list = VrFloder::where($where)->order('id desc')->limit($start,$param['limit'])->select()->toArray(); $group_list = []; if(count($floder_list)<$param['limit']){ //文件夹没有查够一页数据 $diff = $param['limit'] - count($floder_list); $group_list = VrGroup::where($where1)->order('id desc')->limit($diff)->select()->toArray(); } }else{ $floder_list = []; //从作品开始查询 $start = $start-$count1; $group_list = VrGroup::where($where1)->order('id desc')->limit($start,$param['limit'])->select()->toArray(); } //头像 if ($group_list) { $eids = array_column($group_list,'emp_id'); $uids = Employee::where([['id','in',$eids]])->column('uid','id'); $head = User::where([['id','in',$uids]])->column('headimgurl','id'); } $host = config('app.vr_show_domain'); foreach ($group_list as $key => $value) { $uid = isset($uids[$value['emp_id']]) ? $uids[$value['emp_id']] : 0; $group_list[$key]['title'] = $value['title'] ?: '未命名作品'; $group_list[$key]['show_url'] = $host.$value['sid']; $group_list[$key]['headimgurl'] = $uid&&isset($head[$uid]) ? $head[$uid] : ''; } $list = ['floder_list'=>$floder_list,'group_list'=>$group_list]; return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']); } /** * 创建文件夹 */ public function make_floder() { $request = request(); $param = $request->only(['name','pid'=>0]); if(!empty($param['pid'])){ $pdata = VrFloder::find($param['pid']); if($pdata->depth == 2) return json(['code'=>1,'msg'=>'最多支持创建两级文件夹']); } $add=[ 'fld_name'=>$param['name'], 'createtime'=>time(), 'create_user'=>$request->employee->id, 'root_id'=>$request->employee->root_id, 'fld_type'=>2, 'pid'=>$param['pid'] ]; $ms = VrFloder::create($add); if($ms){ return json(['code' => 0, 'msg' => '添加成功']); }else{ return json(['code' => 1, 'msg' => '添加失败']); } } /** * 浏览下级文件夹 */ public function floder_child() { $request = request(); $param = $request->only(['id'=>0,'employee_id'=>0,'keyname'=>0,'org_id'=>0,'page'=>1,'limit'=>21]); $fdata = VrFloder::find($param['id']); if (!request()->isAjax()){ // $data = VrFloder::where('id',$param['id'])->find(); //部门 $org = OrgLogic::struc($request->employee->root_id); View::assign('org', $org); $orgids = orgSubIds(request()->employee->root_id); View::assign('orgids', json_encode($orgids)); View::assign('empid', $request->employee->id); View::assign('data',$fdata); $group_count = VrGroup::where([['root_id','=',request()->employee->root_id],['team_floder_id','=',$fdata['id']],['status','=',2]])->count(); View::assign('group_count',$group_count); View::assign('id',$param['id']); return View::fetch(); } //文件夹条件 $where[] = ['root_id','=',$request->employee->root_id]; $where[] = ['lft','>',$fdata['lft']]; $where[] = ['fld_type','=',2]; $where[] = ['rgt','<',$fdata['rgt']]; $where[] = ['depth','=',$fdata['depth']+1]; //作品条件 $where1[] = ['status','=',2]; $where1[] = ['root_id','=',$request->employee->root_id]; $where1[] = ['team_floder_id','=',$fdata->id]; //团队文件夹没有部门 只搜索作品 if ($param['org_id']) { $eids = Employee::where([['org_id','=',$param['org_id']],['state','=','在职'],['uid','>',0]])->column('id'); $where1[] = ['emp_id','in',$eids]; } //上传人搜索条件 if ($param['employee_id']) $where1[] = ['emp_id','=',$param['employee_id']]; //名称搜索条件 if($param['keyname']){ $where1[] = ['title','like','%'.$param['keyname'].'%']; $where[] = ['fld_name','like','%'.$param['keyname'].'%']; } //分页开始位置 $start = ($param['page']-1)*$param['limit']; $count1 = VrFloder::where($where)->count(); $count2 = VrGroup::where($where1)->count(); $count = $count1 + $count2; //文件夹列表在上面 文件夹长度 if($start==0 || $start <= $count1){ //第一页直接查询文件夹列表 $floder_list = VrFloder::where($where)->order('id desc')->limit($start,$param['limit'])->select()->toArray(); $group_list = []; if(count($floder_list)<$param['limit']){ //文件夹没有查够一页数据 $diff = $param['limit'] - count($floder_list); $group_list = VrGroup::where($where1)->order('id desc')->limit($diff)->select()->toArray(); } }else{ $floder_list = []; //从作品开始查询 $start = $start-$count1; $group_list = VrGroup::where($where1)->order('id desc')->limit($start,$param['limit'])->select()->toArray(); } $host = config('app.vr_show_domain'); //头像 if ($group_list) { $eids = array_column($group_list,'emp_id'); $uids = Employee::where([['id','in',$eids]])->column('uid','id'); $head = User::where([['id','in',$uids]])->column('headimgurl','id'); } foreach ($group_list as $key => $value) { $uid = isset($uids[$value['emp_id']]) ? $uids[$value['emp_id']] : 0; $group_list[$key]['title'] = $value['title'] ?: '未命名作品'; $group_list[$key]['show_url'] = $host.$value['sid']; $group_list[$key]['headimgurl'] = $uid&&isset($head[$uid]) ? $head[$uid] : ''; } $list = ['floder_list'=>$floder_list,'group_list'=>$group_list]; return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']); } /** * 文件夹的修改 */ public function edit_floder() { $request = request(); $param = $request->only(['id','name']); $data = VrFloder::find($param['id']); $data->fld_name = $param['name']; $data->save(); return json(['code' => 0, 'msg' => '修改成功']); } /** * 文件夹的删除 */ public function del_floder($id) { $request = request(); //$param = $request->only(['id','name']); $data = VrFloder::find($id); if(empty($data)) return json(['code' => 1, 'msg' => '数据不存在']); $count = VrGroup::where('floder_id',$data->id)->count(); if(!empty($count)) return json(['code' => 1, 'msg' => '文件夹下有VR作品,暂不能删除']); $where[] = ['root_id','=',$request->employee->root_id]; $where[] = ['lft','>',$data['lft']]; $where[] = ['rgt','<',$data['rgt']]; $where[] = ['depth','=',$data['depth']+1]; $child_floder_count = VrFloder::where($where)->count(); if(!empty($child_floder_count)) return json(['code' => 1, 'msg' => '文件夹下有子文件夹,请先删除子文件夹']); $data->delete(); return json(['code' => 0, 'msg' => '删除成功']); } /** * VR作品待审核列表 * 排序 待审核,审核通过,驳回 * 1 2 -1 */ public function group_check_list() { $request = request(); $param = $request->only(['page'=>1,'limit'=>10]); $where[] = ['root_id','=',$request->employee->root_id]; $where[] = ['status','in',[1,2,-1]]; $list = VrGroup::with(['employee'=>function($query){ $query->field('id,name,uid')->bind(['name'=>'name','uid'=>'uid']); }])->where($where)->page($param['page'],$param['limit'])->field('*,IF(status=1,0,IF(status=2,1,2)) as orders')->order('orders asc')->select()->toArray(); $count = VrGroup::where($where)->count(); $uids = array_column($list,'uid'); $imgs = User::where([['id','in',$uids]])->column('headimgurl','id'); $host = config('app.vr_show_domain'); foreach ($list as $key => $value) { $list[$key]['headimgurl'] = isset($imgs[$value['uid']]) ? $imgs[$value['uid']] : ''; $list[$key]['show_url'] = $host.$value['sid']; } return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']); } /** * 审核Vr作品 * 审核切图 */ public function checking() { $request = request(); $param = $request->only(['id','status']); $where[] = ['root_id','=',$request->employee->root_id]; $where[] = ['id','=',$param['id']]; $data = VrGroup::where($where)->findOrEmpty(); $msg = $data->isEmpty() ? '审核失败' : ($data->status != 1 ? '无法审核' : true); if($msg !== true) return json(['code' => 1, 'msg' => $msg]); //修改作品默认放入到团队的顶级文件夹 每个店面只有一个团队文件夹 if($param['status']==2 && empty($data->team_floder_id)){ $top_floder = VrFloder::where([['root_id','=',$request->employee->root_id],['fld_type','=',2],['depth','=',0]])->value('id'); if(!$top_floder){ $top_floder = VrFloder::insertGetId([ 'fld_name' => '全部', 'createtime' => time(), 'vr_num' => 0, 'fld_type' => 2, 'create_user' => $request->employee->id, 'lft' => 1, 'rgt' => 2, 'depth' => 0, 'root_id' => $request->employee->root_id ]); } $data->team_floder_id = $top_floder; VrFloder::where([['root_id','=',$request->employee->root_id],['fld_type','=',2],['depth','=',0]])->inc('vr_num')->update(); } $data->status = $param['status']; $data->review_time = time(); // if($param['status'] == -1) $data->floder_id = 0;//驳回作品直接进草稿箱 $data->save(); if($param['status']==2) dataStatistics(request()->employee->root_id,'group_count',1,'inc');//manage应用首页统计数据 return json(['code' => 0, 'msg' => '审核通过,作品制作中']); } // //切图操作 // public function cut_img(){ // $id = input('id',0); // $request = request(); // $group_info = VrGroup::where([['id','=',$id],['root_id','=',$request->employee->root_id]])->findOrEmpty(); // if($group_info->isEmpty()) return json(['code' => 1, 'msg' => '切图失败']); // // $ing_count = 16;//同时最大切图数量 // // $ing = VrView::where([['cut_img_status','=',1]])->count(); // // if($ing > $ing_count) return true;//正在切图的场景大于5个,进入等待中 // // $limit = $ing_count-$ing; // $where = [['vr_group_id','=',$id],['cut_img_status','=',0]]; // $list = VrView::where($where)->order('id asc')->select(); // if ($list) { // $arr = ['image_b','image_d','image_f','image_l','image_r','image_u','preview','thumb']; // //遍历场景切图 // foreach ($list as $key => $value) { // //下载原图 // $url = $value->pic_path;//vr图片保存域名 // $floder = $value->getData('vr_path'); // // 原图保存地址 // $inputfile = './upload/wzh/'.$floder.'.jpg'; // $this->dlfile($url,$inputfile); // //切图保存地址 // $outputfilepath = './upload/wzh/'.$floder.'/'; // $krpano = new Krpano(); // $i = false; // try { // // 生成六面体的6张图 // $krpano->spheretocubeCube($inputfile, $outputfilepath); // // 生成封面图 // $krpano->makepreview($inputfile, $outputfilepath); // // 生成竖版预览图 // $krpano->spheretocubeVcube($inputfile, $outputfilepath); // } catch (Exception $e) { // // VrView::where($where)->update(['cut_img_time'=>0,'cut_img_status'=>0]); // trace($e->getMessage(), 'error'); // $i = true; // } // //检测切图 // $i = false; // foreach ($arr as $item) { // //切图保存地址 // $img = $outputfilepath.$item.'.jpg'; // if(!file_exists($img)){ // //验证切图是否成功 // $i = true; // break; // } // } // //切图失败 // if ($i) { // VrView::where('id',$value->id)->update(['cut_img_time'=>time(),'cut_img_status'=>3]); // foreach ($arr as $v1) { // //切图保存地址 // $img = $outputfilepath.$item.'.jpg'; // if(file_exists($img)){ // //删除已经生成的切图 // @unlink($img);//删除本地文件 // } // } // }else{ // //切图成功 // //删除本地原图 // @unlink($inputfile);//删除本地文件 // foreach ($arr as $v2) { // //切图保存地址 // $img = $outputfilepath.$v2.'.jpg'; // $file = $value->structure.$v2.'.jpg'; // $res = $this->ossUpload($file,$img); // @unlink($img);//删除本地文件 // } // //删除服务器空文件夹 // @rmdir('./upload/wzh/'.$floder); // VrView::where('id',$value->id)->update(['cut_img_time'=>time(),'cut_img_status'=>4]); // } // VrGroup::where('id',$id)->update(['status'=>2,'cut_status'=>2]); // } // }else{ // //没有要切图的直接审核通过 // } // VrGroup::where('id',$id)->update(['status'=>2]); // //生成预览二维码 // // $this->viewQrcode($group_info->sid,$group_info->pic_path); // return true; // } /* * 审核通过创建预览二维码 */ // private function viewQrcode($sid,$pic) // { // if(empty($sid) || empty($pic)) return false; // $name = uniqid() . '.jpg'; // $host = request()->domain(); // $content = '/index.html#/viewvr?id=' . $sid; // $url = $host.$content; // // $url = 'https://saasdev.zhuangqixiaoguan.com/index.html#/viewvr?id=61861954062ab44ad4ef494040617385'; // qrcode($url, 'upload/'.$name); // $arr = explode('/',$pic); // array_pop($arr); // $path = implode('/',$arr).'/'.$name; // //二维码图片上传到oss // $res = $this->ossUpload($path, './upload/'.$name); // if($res) VrGroup::where('sid',$sid)->update(['qrcode'=>$path,'view_url'=>$content]); // @unlink('./upload/'.$name); // return true; // } /* * oss文件上传 */ // private function ossUpload($path, $file) // { // $accessKeyId = config('app.vr_ali_oss_access_key_id'); // $accessKeySecret = config('app.vr_ali_oss_access_key_secret'); // $endpoint = config('app.vr_ali_oss_end_point'); // $bucket = config('app.vr_ali_oss_bucket'); // $oss = new OssClient($accessKeyId, $accessKeySecret, $endpoint); // try { // $oss->uploadFile($bucket, $path, $file); // } catch (OssException $e) { // return false; // } // return true; // } // private function dlfile($file_url, $save_to) // { // $in= fopen($file_url, "rb"); // $out= fopen($save_to, "wb"); // while ($chunk = fread($in,8192)) // { // fwrite($out, $chunk, 8192); // } // fclose($in); // fclose($out); // } /** * 移动作品到文件夹 */ public function moveto_floder() { $request = request(); $param = $request->only(['group_ids', 'floder_id']); // var_dump($param); // exit; if(!empty($param['group_ids'])) $group_ids = explode(',',$param['group_ids']); Db::startTrans(); try { //减去原文件夹的vr数量 // $yfid = VrGroup::where([['id', 'in', $group_ids], ['root_id', '=', $request->employee->root_id]])->value('team_floder_id'); // VrFloder::where([['id', '=', $yfid], ['root_id', '=', $request->employee->root_id]])->update(['vr_num' => Db::raw('vr_num -' . count($group_ids))]); // //修改增加新文件夹的vr数量 // VrGroup::where([['id', 'in', $group_ids], ['root_id', '=', $request->employee->root_id]])->update(['team_floder_id' => $param['floder_id']]); // VrFloder::where([['id', '=', $param['floder_id']], ['root_id', '=', $request->employee->root_id]])->update(['vr_num' => Db::raw('vr_num +' . count($group_ids))]); $gdata = VrGroup::where([['id', 'in', $group_ids], ['root_id', '=', $request->employee->root_id]])->column('team_floder_id,id'); foreach($gdata as $key=>$val){ VrFloder::where([['id', '=', $val['team_floder_id']], ['root_id', '=', $request->employee->root_id]])->update(['vr_num' => Db::raw('vr_num - 1')]); } //修改增加新文件夹的vr数量 VrGroup::where([['id', 'in', $group_ids], ['root_id', '=', $request->employee->root_id]])->update(['team_floder_id' => $param['floder_id']]); VrFloder::where([['id', '=', $param['floder_id']], ['root_id', '=', $request->employee->root_id]])->update(['vr_num' => Db::raw('vr_num +' . count($group_ids))]); Db::commit(); } catch (\Exception $e) { Db::rollback(); //var_dump($e->getMessage()); return json(['code' => 1, 'msg' => '移动失败.']); } return json(['code' => 0, 'msg' => '移动成功']); } /** * 移动页面 */ public function batch_mobile() { $request = request(); $list = VrFloder::where([['root_id','=',$request->employee->root_id],['fld_type','=',2]])->order('lft asc')->select()->toArray(); View::assign('list',$list); return View::fetch(); //return json(['code' => 0, 'data' => $list, 'count' => 0, 'msg' => '获取成功']); } /** * 删除VR作品 */ public function del_group() { $request = request(); $param = $request->only(['id'=>0, 'fid'=>0]); $where = [['id','in',explode(',',$param['id'])],['root_id','=',$request->employee->root_id]]; $info = VrGroup::where($where)->column('id,size,title'); if(empty($info)) return json(['code' => 1, 'msg' => '删除失败']); //关联楼盘户型之后不让删除 $del_arr = ['app\model\Building'=>'营销楼盘','app\model\BuildingHousetype'=>'楼盘户型','app\model\BuildingProgress'=>'楼盘进度','app\model\ConstructionRecord'=>'在施工地']; $error = []; $ids = []; foreach ($info as $val) { $check_res = false; foreach ($del_arr as $key => $value) { $obj = new $key(); $del_where = [['vr_group_ids','=',$val['id']]]; $check = $obj->where($del_where)->value('id'); if($check){ $check_res = $value; break; } } if ($check_res !== false) { $title = $val['title'] ?: '未命名作品'; $error[] = '《'.$title.'》关联了【'.$check_res.'】无法删除'; }else{ $ids[] = $val; } } if (empty($ids)) return json(['code' => 1, 'msg' => implode(',',$error)]); $info = array_column($ids,'id'); $size = array_sum(array_column($ids,'size')); //所有场景 $where1 = [['vr_group_id','in',$info]]; $views = VrView::where($where1)->column('id,cut_img_size,size,vr_path,structure'); //所有热点 $vids = array_column($views,'id'); $where2 = [['view_id','in',$vids]]; VrGroup::where($where)->delete(); VrView::where($where1)->delete(); VrHotspot::where($where2)->delete(); //删除oss文件 foreach ($views as $val) { $file = $val['structure']; $this->delOss($val['structure'],$val['vr_path']); } dataStatistics(request()->employee->root_id,'group_count',1,'dec');//manage应用首页统计数据 dataStatistics(request()->employee->root_id,'use_count',$size,'dec');//manage应用首页统计数据 if($error) return json(['code'=>1,'data'=>'','msg'=>implode(',',$error)]); return json(['code'=>0,'data'=>'删除完成','msg'=>'删除完成']); } /** * 删除oss */ public function delOss($str,$name) { $arr = ['image_b','image_d','image_f','image_l','image_r','image_u','preview','thumb',$name]; $objects = []; foreach ($arr as $v) { $objects[] = $str.$v.'.jpg'; } $accessKeyId = config('app.vr_ali_oss_access_key_id'); $accessKeySecret = config('app.vr_ali_oss_access_key_secret'); $endpoint = config('app.vr_ali_oss_end_point'); $bucket = config('app.vr_ali_oss_bucket'); $oss = new OssClient($accessKeyId, $accessKeySecret, $endpoint); try { $exist = $oss->deleteObjects($bucket, $objects); //删除空文件夹 oss自动删除空文件夹 // $res = $oss->deleteBucket($bucket, $str); return true; } catch (OssException $e) { return false; } } /** * 审核开关 */ public function switch() { $request = request(); $where = [['code','=','auditSwitch'],['root_id','=',$request->employee->root_id]]; $info = AppSetting::where($where)->findOrEmpty(); if ($info->isEmpty()) { AppSetting::insertGetId([ 'code'=>'auditSwitch', 'root_id'=>$request->employee->root_id, 'type'=>'string', 'content'=>1, 'remark'=>'vr作品审核开关,1需要审核,0不审核' ]); }else{ $info->content = $info->content ? 0 : 1; $info->save(); } return json(['code'=>0,'data'=>'设置完成','msg'=>'设置完成']); } }