VrManage.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. <?php
  2. namespace app\sys\controller;
  3. use think\facade\View;
  4. use app\logics\OrgLogic;
  5. use think\facade\Db;
  6. use think\facade\Request;
  7. use app\model\VrFloder;
  8. use app\model\VrGroup;
  9. use app\model\VrView;
  10. use app\model\User;
  11. use app\model\Employee;
  12. use app\model\VrHotspot;
  13. use vr\Krpano;
  14. use OSS\OssClient;
  15. use app\model\AppSetting;
  16. class VrManage
  17. {
  18. /**
  19. * vr作品列表
  20. */
  21. public function floder_list()
  22. {
  23. $request = request();
  24. $param = $request->only(['employee_id'=>0,'keyname'=>'','org_id'=>0,'page'=>1,'limit'=>21]);
  25. if (!request()->isAjax()){
  26. //部门
  27. $org = OrgLogic::struc($request->employee->root_id);
  28. View::assign('org', $org);
  29. $orgids = orgSubIds(request()->employee->root_id);
  30. View::assign('orgids', json_encode($orgids));
  31. View::assign('empid', $request->employee->id);
  32. $group_count = VrGroup::where([['root_id','=',request()->employee->root_id],['status','=',2]])->count();
  33. View::assign('group_count',$group_count);
  34. //审核开关
  35. $switch = AppSetting::where([['code','=','auditSwitch'],['root_id','=',$request->employee->root_id],['content','=',1]])->findOrEmpty();
  36. View::assign('switch',$switch->isEmpty() ? 0 : 1);
  37. return View::fetch();
  38. }
  39. //直接作品列表
  40. $topid = VrFloder::where([['root_id','=',$request->employee->root_id],['fld_type','=',2],['depth','=',0],['fld_name','=','全部']])->value('id');
  41. //文件夹条件
  42. $where[] = ['root_id','=',$request->employee->root_id];
  43. $where[] = ['depth','=',1];
  44. $where[] = ['fld_type','=',2];
  45. //作品列表条件
  46. $where1[] = ['status','=',2];
  47. $where1[] = ['root_id','=',$request->employee->root_id];
  48. $where1[] = ['team_floder_id','NULL',null];
  49. //团队文件夹没有部门 只搜索作品
  50. if ($param['org_id']) {
  51. $eids = Employee::where([['org_id','=',$param['org_id']],['state','=','在职'],['uid','>',0]])->column('id');
  52. $where1[] = ['emp_id','in',$eids];
  53. }
  54. //上传人搜索条件
  55. if ($param['employee_id']) $where1[] = ['emp_id','=',$param['employee_id']];
  56. //名称搜索条件
  57. if($param['keyname']){
  58. $where1[] = ['title','like','%'.$param['keyname'].'%'];
  59. $where[] = ['fld_name','like','%'.$param['keyname'].'%'];
  60. }
  61. //分页开始位置
  62. $start = ($param['page']-1)*$param['limit'];
  63. $count1 = VrFloder::where($where)->count();
  64. $count2 = VrGroup::where($where1)->count();
  65. $count = $count1 + $count2;
  66. //文件夹列表在上面 文件夹长度
  67. if($start==0 || $start <= $count1){
  68. //第一页直接查询文件夹列表
  69. $floder_list = VrFloder::where($where)->order('id desc')->limit($start,$param['limit'])->select()->toArray();
  70. $group_list = [];
  71. if(count($floder_list)<$param['limit']){
  72. //文件夹没有查够一页数据
  73. $diff = $param['limit'] - count($floder_list);
  74. $group_list = VrGroup::where($where1)->order('id desc')->limit($diff)->select()->toArray();
  75. }
  76. }else{
  77. $floder_list = [];
  78. //从作品开始查询
  79. $start = $start-$count1;
  80. $group_list = VrGroup::where($where1)->order('id desc')->limit($start,$param['limit'])->select()->toArray();
  81. }
  82. //头像
  83. if ($group_list) {
  84. $eids = array_column($group_list,'emp_id');
  85. $uids = Employee::where([['id','in',$eids]])->column('uid','id');
  86. $head = User::where([['id','in',$uids]])->column('headimgurl','id');
  87. }
  88. $host = config('app.vr_show_domain');
  89. foreach ($group_list as $key => $value) {
  90. $uid = isset($uids[$value['emp_id']]) ? $uids[$value['emp_id']] : 0;
  91. $group_list[$key]['title'] = $value['title'] ?: '未命名作品';
  92. $group_list[$key]['show_url'] = $host.$value['sid'];
  93. $group_list[$key]['headimgurl'] = $uid&&isset($head[$uid]) ? $head[$uid] : '';
  94. }
  95. $list = ['floder_list'=>$floder_list,'group_list'=>$group_list];
  96. return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
  97. }
  98. /**
  99. * 创建文件夹
  100. */
  101. public function make_floder()
  102. {
  103. $request = request();
  104. $param = $request->only(['name','pid'=>0]);
  105. if(!empty($param['pid'])){
  106. $pdata = VrFloder::find($param['pid']);
  107. if($pdata->depth == 2) return json(['code'=>1,'msg'=>'最多支持创建两级文件夹']);
  108. }
  109. $add=[
  110. 'fld_name'=>$param['name'],
  111. 'createtime'=>time(),
  112. 'create_user'=>$request->employee->id,
  113. 'root_id'=>$request->employee->root_id,
  114. 'fld_type'=>2,
  115. 'pid'=>$param['pid']
  116. ];
  117. $ms = VrFloder::create($add);
  118. if($ms){
  119. return json(['code' => 0, 'msg' => '添加成功']);
  120. }else{
  121. return json(['code' => 1, 'msg' => '添加失败']);
  122. }
  123. }
  124. /**
  125. * 浏览下级文件夹
  126. */
  127. public function floder_child()
  128. {
  129. $request = request();
  130. $param = $request->only(['id'=>0,'employee_id'=>0,'keyname'=>0,'org_id'=>0,'page'=>1,'limit'=>21]);
  131. $fdata = VrFloder::find($param['id']);
  132. if (!request()->isAjax()){
  133. // $data = VrFloder::where('id',$param['id'])->find();
  134. //部门
  135. $org = OrgLogic::struc($request->employee->root_id);
  136. View::assign('org', $org);
  137. $orgids = orgSubIds(request()->employee->root_id);
  138. View::assign('orgids', json_encode($orgids));
  139. View::assign('empid', $request->employee->id);
  140. View::assign('data',$fdata);
  141. $group_count = VrGroup::where([['root_id','=',request()->employee->root_id],['team_floder_id','=',$fdata['id']],['status','=',2]])->count();
  142. View::assign('group_count',$group_count);
  143. View::assign('id',$param['id']);
  144. return View::fetch();
  145. }
  146. //文件夹条件
  147. $where[] = ['root_id','=',$request->employee->root_id];
  148. $where[] = ['lft','>',$fdata['lft']];
  149. $where[] = ['fld_type','=',2];
  150. $where[] = ['rgt','<',$fdata['rgt']];
  151. $where[] = ['depth','=',$fdata['depth']+1];
  152. //作品条件
  153. $where1[] = ['status','=',2];
  154. $where1[] = ['root_id','=',$request->employee->root_id];
  155. $where1[] = ['team_floder_id','=',$fdata->id];
  156. //团队文件夹没有部门 只搜索作品
  157. if ($param['org_id']) {
  158. $eids = Employee::where([['org_id','=',$param['org_id']],['state','=','在职'],['uid','>',0]])->column('id');
  159. $where1[] = ['emp_id','in',$eids];
  160. }
  161. //上传人搜索条件
  162. if ($param['employee_id']) $where1[] = ['emp_id','=',$param['employee_id']];
  163. //名称搜索条件
  164. if($param['keyname']){
  165. $where1[] = ['title','like','%'.$param['keyname'].'%'];
  166. $where[] = ['fld_name','like','%'.$param['keyname'].'%'];
  167. }
  168. //分页开始位置
  169. $start = ($param['page']-1)*$param['limit'];
  170. $count1 = VrFloder::where($where)->count();
  171. $count2 = VrGroup::where($where1)->count();
  172. $count = $count1 + $count2;
  173. //文件夹列表在上面 文件夹长度
  174. if($start==0 || $start <= $count1){
  175. //第一页直接查询文件夹列表
  176. $floder_list = VrFloder::where($where)->order('id desc')->limit($start,$param['limit'])->select()->toArray();
  177. $group_list = [];
  178. if(count($floder_list)<$param['limit']){
  179. //文件夹没有查够一页数据
  180. $diff = $param['limit'] - count($floder_list);
  181. $group_list = VrGroup::where($where1)->order('id desc')->limit($diff)->select()->toArray();
  182. }
  183. }else{
  184. $floder_list = [];
  185. //从作品开始查询
  186. $start = $start-$count1;
  187. $group_list = VrGroup::where($where1)->order('id desc')->limit($start,$param['limit'])->select()->toArray();
  188. }
  189. $host = config('app.vr_show_domain');
  190. //头像
  191. if ($group_list) {
  192. $eids = array_column($group_list,'emp_id');
  193. $uids = Employee::where([['id','in',$eids]])->column('uid','id');
  194. $head = User::where([['id','in',$uids]])->column('headimgurl','id');
  195. }
  196. foreach ($group_list as $key => $value) {
  197. $uid = isset($uids[$value['emp_id']]) ? $uids[$value['emp_id']] : 0;
  198. $group_list[$key]['title'] = $value['title'] ?: '未命名作品';
  199. $group_list[$key]['show_url'] = $host.$value['sid'];
  200. $group_list[$key]['headimgurl'] = $uid&&isset($head[$uid]) ? $head[$uid] : '';
  201. }
  202. $list = ['floder_list'=>$floder_list,'group_list'=>$group_list];
  203. return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
  204. }
  205. /**
  206. * 文件夹的修改
  207. */
  208. public function edit_floder()
  209. {
  210. $request = request();
  211. $param = $request->only(['id','name']);
  212. $data = VrFloder::find($param['id']);
  213. $data->fld_name = $param['name'];
  214. $data->save();
  215. return json(['code' => 0, 'msg' => '修改成功']);
  216. }
  217. /**
  218. * 文件夹的删除
  219. */
  220. public function del_floder($id)
  221. {
  222. $request = request();
  223. //$param = $request->only(['id','name']);
  224. $data = VrFloder::find($id);
  225. if(empty($data)) return json(['code' => 1, 'msg' => '数据不存在']);
  226. $count = VrGroup::where('floder_id',$data->id)->count();
  227. if(!empty($count)) return json(['code' => 1, 'msg' => '文件夹下有VR作品,暂不能删除']);
  228. $where[] = ['root_id','=',$request->employee->root_id];
  229. $where[] = ['lft','>',$data['lft']];
  230. $where[] = ['rgt','<',$data['rgt']];
  231. $where[] = ['depth','=',$data['depth']+1];
  232. $child_floder_count = VrFloder::where($where)->count();
  233. if(!empty($child_floder_count)) return json(['code' => 1, 'msg' => '文件夹下有子文件夹,请先删除子文件夹']);
  234. $data->delete();
  235. return json(['code' => 0, 'msg' => '删除成功']);
  236. }
  237. /**
  238. * VR作品待审核列表
  239. * 排序 待审核,审核通过,驳回
  240. * 1 2 -1
  241. */
  242. public function group_check_list()
  243. {
  244. $request = request();
  245. $param = $request->only(['page'=>1,'limit'=>10]);
  246. $where[] = ['root_id','=',$request->employee->root_id];
  247. $where[] = ['status','in',[1,2,-1]];
  248. $list = VrGroup::with(['employee'=>function($query){
  249. $query->field('id,name,uid')->bind(['name'=>'name','uid'=>'uid']);
  250. }])->where($where)->page($param['page'],$param['limit'])->field('*,IF(status=1,0,IF(status=2,1,2)) as orders')->order('orders asc')->select()->toArray();
  251. $count = VrGroup::where($where)->count();
  252. $uids = array_column($list,'uid');
  253. $imgs = User::where([['id','in',$uids]])->column('headimgurl','id');
  254. $host = config('app.vr_show_domain');
  255. foreach ($list as $key => $value) {
  256. $list[$key]['headimgurl'] = isset($imgs[$value['uid']]) ? $imgs[$value['uid']] : '';
  257. $list[$key]['show_url'] = $host.$value['sid'];
  258. }
  259. return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
  260. }
  261. /**
  262. * 审核Vr作品
  263. * 审核切图
  264. */
  265. public function checking()
  266. {
  267. $request = request();
  268. $param = $request->only(['id','status']);
  269. $where[] = ['root_id','=',$request->employee->root_id];
  270. $where[] = ['id','=',$param['id']];
  271. $data = VrGroup::where($where)->findOrEmpty();
  272. $msg = $data->isEmpty() ? '审核失败' : ($data->status != 1 ? '无法审核' : true);
  273. if($msg !== true) return json(['code' => 1, 'msg' => $msg]);
  274. //修改作品默认放入到团队的顶级文件夹 每个店面只有一个团队文件夹
  275. if($param['status']==2 && empty($data->team_floder_id)){
  276. $top_floder = VrFloder::where([['root_id','=',$request->employee->root_id],['fld_type','=',2],['depth','=',0]])->value('id');
  277. if(!$top_floder){
  278. $top_floder = VrFloder::insertGetId([
  279. 'fld_name' => '全部',
  280. 'createtime' => time(),
  281. 'vr_num' => 0,
  282. 'fld_type' => 2,
  283. 'create_user' => $request->employee->id,
  284. 'lft' => 1,
  285. 'rgt' => 2,
  286. 'depth' => 0,
  287. 'root_id' => $request->employee->root_id
  288. ]);
  289. }
  290. $data->team_floder_id = $top_floder;
  291. VrFloder::where([['root_id','=',$request->employee->root_id],['fld_type','=',2],['depth','=',0]])->inc('vr_num')->update();
  292. }
  293. $data->status = $param['status'];
  294. $data->review_time = time();
  295. // if($param['status'] == -1) $data->floder_id = 0;//驳回作品直接进草稿箱
  296. $data->save();
  297. if($param['status']==2) dataStatistics(request()->employee->root_id,'group_count',1,'inc');//manage应用首页统计数据
  298. return json(['code' => 0, 'msg' => '审核通过,作品制作中']);
  299. }
  300. // //切图操作
  301. // public function cut_img(){
  302. // $id = input('id',0);
  303. // $request = request();
  304. // $group_info = VrGroup::where([['id','=',$id],['root_id','=',$request->employee->root_id]])->findOrEmpty();
  305. // if($group_info->isEmpty()) return json(['code' => 1, 'msg' => '切图失败']);
  306. // // $ing_count = 16;//同时最大切图数量
  307. // // $ing = VrView::where([['cut_img_status','=',1]])->count();
  308. // // if($ing > $ing_count) return true;//正在切图的场景大于5个,进入等待中
  309. // // $limit = $ing_count-$ing;
  310. // $where = [['vr_group_id','=',$id],['cut_img_status','=',0]];
  311. // $list = VrView::where($where)->order('id asc')->select();
  312. // if ($list) {
  313. // $arr = ['image_b','image_d','image_f','image_l','image_r','image_u','preview','thumb'];
  314. // //遍历场景切图
  315. // foreach ($list as $key => $value) {
  316. // //下载原图
  317. // $url = $value->pic_path;//vr图片保存域名
  318. // $floder = $value->getData('vr_path');
  319. // // 原图保存地址
  320. // $inputfile = './upload/wzh/'.$floder.'.jpg';
  321. // $this->dlfile($url,$inputfile);
  322. // //切图保存地址
  323. // $outputfilepath = './upload/wzh/'.$floder.'/';
  324. // $krpano = new Krpano();
  325. // $i = false;
  326. // try {
  327. // // 生成六面体的6张图
  328. // $krpano->spheretocubeCube($inputfile, $outputfilepath);
  329. // // 生成封面图
  330. // $krpano->makepreview($inputfile, $outputfilepath);
  331. // // 生成竖版预览图
  332. // $krpano->spheretocubeVcube($inputfile, $outputfilepath);
  333. // } catch (Exception $e) {
  334. // // VrView::where($where)->update(['cut_img_time'=>0,'cut_img_status'=>0]);
  335. // trace($e->getMessage(), 'error');
  336. // $i = true;
  337. // }
  338. // //检测切图
  339. // $i = false;
  340. // foreach ($arr as $item) {
  341. // //切图保存地址
  342. // $img = $outputfilepath.$item.'.jpg';
  343. // if(!file_exists($img)){
  344. // //验证切图是否成功
  345. // $i = true;
  346. // break;
  347. // }
  348. // }
  349. // //切图失败
  350. // if ($i) {
  351. // VrView::where('id',$value->id)->update(['cut_img_time'=>time(),'cut_img_status'=>3]);
  352. // foreach ($arr as $v1) {
  353. // //切图保存地址
  354. // $img = $outputfilepath.$item.'.jpg';
  355. // if(file_exists($img)){
  356. // //删除已经生成的切图
  357. // @unlink($img);//删除本地文件
  358. // }
  359. // }
  360. // }else{
  361. // //切图成功
  362. // //删除本地原图
  363. // @unlink($inputfile);//删除本地文件
  364. // foreach ($arr as $v2) {
  365. // //切图保存地址
  366. // $img = $outputfilepath.$v2.'.jpg';
  367. // $file = $value->structure.$v2.'.jpg';
  368. // $res = $this->ossUpload($file,$img);
  369. // @unlink($img);//删除本地文件
  370. // }
  371. // //删除服务器空文件夹
  372. // @rmdir('./upload/wzh/'.$floder);
  373. // VrView::where('id',$value->id)->update(['cut_img_time'=>time(),'cut_img_status'=>4]);
  374. // }
  375. // VrGroup::where('id',$id)->update(['status'=>2,'cut_status'=>2]);
  376. // }
  377. // }else{
  378. // //没有要切图的直接审核通过
  379. // }
  380. // VrGroup::where('id',$id)->update(['status'=>2]);
  381. // //生成预览二维码
  382. // // $this->viewQrcode($group_info->sid,$group_info->pic_path);
  383. // return true;
  384. // }
  385. /*
  386. * 审核通过创建预览二维码
  387. */
  388. // private function viewQrcode($sid,$pic)
  389. // {
  390. // if(empty($sid) || empty($pic)) return false;
  391. // $name = uniqid() . '.jpg';
  392. // $host = request()->domain();
  393. // $content = '/index.html#/viewvr?id=' . $sid;
  394. // $url = $host.$content;
  395. // // $url = 'https://saasdev.zhuangqixiaoguan.com/index.html#/viewvr?id=61861954062ab44ad4ef494040617385';
  396. // qrcode($url, 'upload/'.$name);
  397. // $arr = explode('/',$pic);
  398. // array_pop($arr);
  399. // $path = implode('/',$arr).'/'.$name;
  400. // //二维码图片上传到oss
  401. // $res = $this->ossUpload($path, './upload/'.$name);
  402. // if($res) VrGroup::where('sid',$sid)->update(['qrcode'=>$path,'view_url'=>$content]);
  403. // @unlink('./upload/'.$name);
  404. // return true;
  405. // }
  406. /*
  407. * oss文件上传
  408. */
  409. // private function ossUpload($path, $file)
  410. // {
  411. // $accessKeyId = config('app.vr_ali_oss_access_key_id');
  412. // $accessKeySecret = config('app.vr_ali_oss_access_key_secret');
  413. // $endpoint = config('app.vr_ali_oss_end_point');
  414. // $bucket = config('app.vr_ali_oss_bucket');
  415. // $oss = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
  416. // try {
  417. // $oss->uploadFile($bucket, $path, $file);
  418. // } catch (OssException $e) {
  419. // return false;
  420. // }
  421. // return true;
  422. // }
  423. // private function dlfile($file_url, $save_to)
  424. // {
  425. // $in= fopen($file_url, "rb");
  426. // $out= fopen($save_to, "wb");
  427. // while ($chunk = fread($in,8192))
  428. // {
  429. // fwrite($out, $chunk, 8192);
  430. // }
  431. // fclose($in);
  432. // fclose($out);
  433. // }
  434. /**
  435. * 移动作品到文件夹
  436. */
  437. public function moveto_floder()
  438. {
  439. $request = request();
  440. $param = $request->only(['group_ids', 'floder_id']);
  441. // var_dump($param);
  442. // exit;
  443. if(!empty($param['group_ids'])) $group_ids = explode(',',$param['group_ids']);
  444. Db::startTrans();
  445. try {
  446. //减去原文件夹的vr数量
  447. // $yfid = VrGroup::where([['id', 'in', $group_ids], ['root_id', '=', $request->employee->root_id]])->value('team_floder_id');
  448. // VrFloder::where([['id', '=', $yfid], ['root_id', '=', $request->employee->root_id]])->update(['vr_num' => Db::raw('vr_num -' . count($group_ids))]);
  449. // //修改增加新文件夹的vr数量
  450. // VrGroup::where([['id', 'in', $group_ids], ['root_id', '=', $request->employee->root_id]])->update(['team_floder_id' => $param['floder_id']]);
  451. // VrFloder::where([['id', '=', $param['floder_id']], ['root_id', '=', $request->employee->root_id]])->update(['vr_num' => Db::raw('vr_num +' . count($group_ids))]);
  452. $gdata = VrGroup::where([['id', 'in', $group_ids], ['root_id', '=', $request->employee->root_id]])->column('team_floder_id,id');
  453. foreach($gdata as $key=>$val){
  454. VrFloder::where([['id', '=', $val['team_floder_id']], ['root_id', '=', $request->employee->root_id]])->update(['vr_num' => Db::raw('vr_num - 1')]);
  455. }
  456. //修改增加新文件夹的vr数量
  457. VrGroup::where([['id', 'in', $group_ids], ['root_id', '=', $request->employee->root_id]])->update(['team_floder_id' => $param['floder_id']]);
  458. VrFloder::where([['id', '=', $param['floder_id']], ['root_id', '=', $request->employee->root_id]])->update(['vr_num' => Db::raw('vr_num +' . count($group_ids))]);
  459. Db::commit();
  460. } catch (\Exception $e) {
  461. Db::rollback();
  462. //var_dump($e->getMessage());
  463. return json(['code' => 1, 'msg' => '移动失败.']);
  464. }
  465. return json(['code' => 0, 'msg' => '移动成功']);
  466. }
  467. /**
  468. * 移动页面
  469. */
  470. public function batch_mobile()
  471. {
  472. $request = request();
  473. $list = VrFloder::where([['root_id','=',$request->employee->root_id],['fld_type','=',2]])->order('lft asc')->select()->toArray();
  474. View::assign('list',$list);
  475. return View::fetch();
  476. //return json(['code' => 0, 'data' => $list, 'count' => 0, 'msg' => '获取成功']);
  477. }
  478. /**
  479. * 删除VR作品
  480. */
  481. public function del_group()
  482. {
  483. $request = request();
  484. $param = $request->only(['id'=>0, 'fid'=>0]);
  485. $where = [['id','in',explode(',',$param['id'])],['root_id','=',$request->employee->root_id]];
  486. $info = VrGroup::where($where)->column('id,size,title');
  487. if(empty($info)) return json(['code' => 1, 'msg' => '删除失败']);
  488. //关联楼盘户型之后不让删除
  489. $del_arr = ['app\model\Building'=>'营销楼盘','app\model\BuildingHousetype'=>'楼盘户型','app\model\BuildingProgress'=>'楼盘进度','app\model\ConstructionRecord'=>'在施工地'];
  490. $error = [];
  491. $ids = [];
  492. foreach ($info as $val) {
  493. $check_res = false;
  494. foreach ($del_arr as $key => $value) {
  495. $obj = new $key();
  496. $del_where = [['vr_group_ids','=',$val['id']]];
  497. $check = $obj->where($del_where)->value('id');
  498. if($check){
  499. $check_res = $value;
  500. break;
  501. }
  502. }
  503. if ($check_res !== false) {
  504. $title = $val['title'] ?: '未命名作品';
  505. $error[] = '《'.$title.'》关联了【'.$check_res.'】无法删除';
  506. }else{
  507. $ids[] = $val;
  508. }
  509. }
  510. if (empty($ids)) return json(['code' => 1, 'msg' => implode(',',$error)]);
  511. $info = array_column($ids,'id');
  512. $size = array_sum(array_column($ids,'size'));
  513. //所有场景
  514. $where1 = [['vr_group_id','in',$info]];
  515. $views = VrView::where($where1)->column('id,cut_img_size,size,vr_path,structure');
  516. //所有热点
  517. $vids = array_column($views,'id');
  518. $where2 = [['view_id','in',$vids]];
  519. VrGroup::where($where)->delete();
  520. VrView::where($where1)->delete();
  521. VrHotspot::where($where2)->delete();
  522. //删除oss文件
  523. foreach ($views as $val) {
  524. $file = $val['structure'];
  525. $this->delOss($val['structure'],$val['vr_path']);
  526. }
  527. dataStatistics(request()->employee->root_id,'group_count',1,'dec');//manage应用首页统计数据
  528. dataStatistics(request()->employee->root_id,'use_count',$size,'dec');//manage应用首页统计数据
  529. if($error) return json(['code'=>1,'data'=>'','msg'=>implode(',',$error)]);
  530. return json(['code'=>0,'data'=>'删除完成','msg'=>'删除完成']);
  531. }
  532. /**
  533. * 删除oss
  534. */
  535. public function delOss($str,$name)
  536. {
  537. $arr = ['image_b','image_d','image_f','image_l','image_r','image_u','preview','thumb',$name];
  538. $objects = [];
  539. foreach ($arr as $v) {
  540. $objects[] = $str.$v.'.jpg';
  541. }
  542. $accessKeyId = config('app.vr_ali_oss_access_key_id');
  543. $accessKeySecret = config('app.vr_ali_oss_access_key_secret');
  544. $endpoint = config('app.vr_ali_oss_end_point');
  545. $bucket = config('app.vr_ali_oss_bucket');
  546. $oss = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
  547. try {
  548. $exist = $oss->deleteObjects($bucket, $objects);
  549. //删除空文件夹 oss自动删除空文件夹
  550. // $res = $oss->deleteBucket($bucket, $str);
  551. return true;
  552. } catch (OssException $e) {
  553. return false;
  554. }
  555. }
  556. /**
  557. * 审核开关
  558. */
  559. public function switch()
  560. {
  561. $request = request();
  562. $where = [['code','=','auditSwitch'],['root_id','=',$request->employee->root_id]];
  563. $info = AppSetting::where($where)->findOrEmpty();
  564. if ($info->isEmpty()) {
  565. AppSetting::insertGetId([
  566. 'code'=>'auditSwitch',
  567. 'root_id'=>$request->employee->root_id,
  568. 'type'=>'string',
  569. 'content'=>1,
  570. 'remark'=>'vr作品审核开关,1需要审核,0不审核'
  571. ]);
  572. }else{
  573. $info->content = $info->content ? 0 : 1;
  574. $info->save();
  575. }
  576. return json(['code'=>0,'data'=>'设置完成','msg'=>'设置完成']);
  577. }
  578. }