1
0

SmartScreen.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  1. <?php
  2. namespace app\sys\controller;
  3. use think\facade\View;
  4. use app\model\Setting;
  5. use app\model\SmartScreen as SmartScreenModel;
  6. use think\facade\Request;
  7. use app\model\SmartScreenCate;
  8. use app\model\SmartScreenData;
  9. use app\model\Org;
  10. use app\model\Employee;
  11. use xiaohongwu\Vr;
  12. use app\model\Decostyle;
  13. use app\model\Community;
  14. use app\model\Housetype;
  15. use app\model\Permission;
  16. use app\model\Company;
  17. use think\facade\Db;
  18. use toolkits\Aec;
  19. class SmartScreen
  20. {
  21. private $modular;
  22. public function __construct()
  23. {
  24. $this->modular = ['introduce' => '公司简介', 'pattern' => '模式优势', 'boutique' => '精品设计', 'science' => '材料', 'major' => '大牌软装', 'customized' => '定制家具', 'realistic' => '实景样板房', 'praise' => '口碑及服务', 'platinum' => '铂金工程'];
  25. }
  26. /**
  27. * 面板
  28. */
  29. public function index()
  30. {
  31. $root_id = request()->employee->root_id;
  32. //录音开关
  33. $where = [
  34. ['name', '=', 'recordingSwitch'],
  35. ['root_id', '=', $root_id]
  36. ];
  37. $info = Setting::where($where)->findOrEmpty();
  38. $data['switch'] = $info->isEmpty() ? 0 : ($info->content ? 1 : 0);
  39. // 谈单有效时长
  40. $where1 = [
  41. ['name', '=', 'smartScreenValidMinutes'],
  42. ['root_id', '=', $root_id]
  43. ];
  44. $smartScreenValidMinutes = Setting::where($where1)->findOrEmpty();
  45. $data['smartScreenValidMinutes'] = $smartScreenValidMinutes->isEmpty() ? 0 : $smartScreenValidMinutes['content'];
  46. //9个模块
  47. $modular = array_keys($this->modular);
  48. $where = [
  49. ['root_id', '=', $root_id],
  50. ['code', 'in', $modular]
  51. ];
  52. $res = SmartScreenModel::where($where)->column('*', 'code');
  53. $ali_oss_bindurl = config('app.ali_oss_bindurl');
  54. foreach ($res as $k2 => $v2) {
  55. $res[$k2]['background_img'] = $v2['background_img'] ? 'https://' . $ali_oss_bindurl . '/' . $v2['background_img'] : '';
  56. $res[$k2]['lcon_img'] = $v2['lcon_img'] ? 'https://' . $ali_oss_bindurl . '/' . $v2['lcon_img'] : '';
  57. }
  58. $diff = array_diff($modular, array_keys($res));
  59. $row = [];
  60. foreach ($diff as $v) {
  61. $row[$v] = [
  62. 'title' => $this->modular[$v],
  63. 'code' => $v,
  64. 'background_img' => '',
  65. 'lcon_img' => ''
  66. ];
  67. }
  68. $data['row'] = array_merge($res, $row);
  69. View::assign('data', $data);
  70. //排序后的数据
  71. $where = [
  72. ['name', '=', 'wisdomMenuOrder'],
  73. ['root_id', '=', $root_id]
  74. ];
  75. $order = Setting::where($where)->value('content');
  76. $menus = Permission::where([['uri','like','smartScreen/content?type=%']])->order('sort asc,id asc')->column('id,auth_name as name,uri');
  77. $new_title = array_column($data['row'],'title','code');
  78. if ($order) {
  79. $ids = array_flip(explode(',',$order));
  80. foreach ($menus as $key => $val) {
  81. $code = trim(str_replace('smartScreen/content?type=','',$val['uri']));
  82. $menus[$key]['order'] = $ids[$val['id']];
  83. $menus[$key]['name'] = $new_title[$code];
  84. }
  85. array_multisort(array_column($menus,'order'),SORT_ASC, $menus);
  86. }else{
  87. foreach ($menus as $key => $val) {
  88. $code = trim(str_replace('smartScreen/content?type=','',$val['uri']));
  89. $menus[$key]['name'] = $new_title[$code];
  90. }
  91. }
  92. View::assign('menus', $menus);
  93. //智慧屏演示地址
  94. $domain = request()->domain();
  95. $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
  96. View::assign('url', $domain.'/smartscreen.html#/home?token='.$aec->encrypt($root_id.'#0#0'));
  97. return View::fetch();
  98. }
  99. /**
  100. * 保存排序
  101. */
  102. public function saveOrder()
  103. {
  104. $root_id = request()->employee->root_id;
  105. $ids = input('ids','');
  106. $arr = explode(',',$ids);
  107. sort($arr);
  108. $menu = Permission::where([['uri','like','smartScreen/content?type=%']])->order('id asc')->column('id');
  109. if(empty($ids) || $arr != $menu) return json(['code' => 1, 'data' => 'ids错误', 'msg' => 'ids错误']);
  110. //排序后的数据
  111. $where = [
  112. ['name', '=', 'wisdomMenuOrder'],
  113. ['root_id', '=', $root_id]
  114. ];
  115. $info = Setting::where($where)->findOrEmpty();
  116. if ($info->isEmpty()) {
  117. Setting::insert([
  118. 'name'=>'wisdomMenuOrder',
  119. 'root_id'=>$root_id,
  120. 'content'=>$ids
  121. ]);
  122. }else{
  123. $info->content = $ids;
  124. $info->save();
  125. }
  126. return json(['code' => 0, 'data' => '保存成功', 'msg' => '保存成功']);
  127. }
  128. /**
  129. * 智慧屏录音开关设置
  130. */
  131. public function recordingSwitch()
  132. {
  133. $root_id = request()->employee->root_id;
  134. $res = 1; //默认开启
  135. $where = [
  136. ['name', '=', 'recordingSwitch'],
  137. ['root_id', '=', $root_id]
  138. ];
  139. $info = Setting::where($where)->findOrEmpty();
  140. if ($info->isEmpty()) {
  141. Setting::insert([
  142. 'name' => 'recordingSwitch',
  143. 'root_id' => $root_id,
  144. 'content' => 1
  145. ]);
  146. } else {
  147. $res = $info->content ? 0 : 1;
  148. $info->content = $res;
  149. $info->save();
  150. }
  151. return json(['code' => 0, 'data' => '保存成功', 'msg' => '保存成功']);
  152. }
  153. /**
  154. * 获取单个模块详情
  155. */
  156. public function getModularRead()
  157. {
  158. $param = Request::only(['type' => '']);
  159. if (empty($param['type']) || !isset($this->modular[$param['type']])) return json(['code' => 1, 'data' => '参数错误', 'msg' => '参数错误']);
  160. $root_id = request()->employee->root_id;
  161. $where = [
  162. ['code', '=', $param['type']],
  163. ['root_id', '=', $root_id]
  164. ];
  165. $res = SmartScreenModel::where($where)->findOrEmpty();
  166. $ali_oss_bindurl = config('app.ali_oss_bindurl');
  167. if ($res->isEmpty()) {
  168. $res = [
  169. 'title' => $this->modular[$param['type']],
  170. 'code' => $param['type'],
  171. 'background_img' => '',
  172. 'lcon_img' => ''
  173. ];
  174. }
  175. return json(['code' => 0, 'data' => $res, 'msg' => '保存成功']);
  176. }
  177. /**
  178. * 保存模块信息
  179. */
  180. public function saveModularRead()
  181. {
  182. $param = Request::only(['type' => '', 'title' => '', 'background_img' => '', 'lcon_img' => '']);
  183. if (empty($param['type']) || !isset($this->modular[$param['type']])) return json(['code' => 1, 'data' => '参数错误', 'msg' => '参数错误']);
  184. $root_id = request()->employee->root_id;
  185. $where = [
  186. ['code', '=', $param['type']],
  187. ['root_id', '=', $root_id]
  188. ];
  189. $res = SmartScreenModel::where($where)->findOrEmpty();
  190. if ($res->isEmpty()) {
  191. SmartScreenModel::insert([
  192. 'title' => $param['title'],
  193. 'code' => $param['type'],
  194. 'background_img' => $param['background_img'],
  195. 'lcon_img' => $param['lcon_img'],
  196. 'root_id' => $root_id
  197. ]);
  198. } else {
  199. $res->title = $param['title'];
  200. $res->background_img = $param['background_img'];
  201. $res->lcon_img = $param['lcon_img'];
  202. $res->save();
  203. }
  204. return json(['code' => 0, 'data' => '保存成功', 'msg' => '保存成功']);
  205. }
  206. /**
  207. * 公司介绍introduce ,
  208. *
  209. */
  210. public function content()
  211. {
  212. $type = input('type', '');
  213. $cate = $this->modular;
  214. $title = $cate[$type];
  215. $root_id = request()->employee->root_id;
  216. //获取一级分类
  217. $where = [
  218. ['root_id', '=', $root_id],
  219. ['pid', '=', 0],
  220. ['code', '=', $type],
  221. ['del', '=', 0],
  222. ];
  223. $types = SmartScreenCate::where($where)->order('id asc')->select()->toArray();
  224. //默认展示第一个标签
  225. $default_type = $types ? $types[0]['id'] : 0;
  226. //
  227. View::assign('default_type', $default_type);
  228. View::assign('types', $types);
  229. View::assign('title', $title);
  230. //类型
  231. View::assign('type', $type);
  232. return View::fetch();
  233. }
  234. /**
  235. * 一级分类页面
  236. *
  237. */
  238. public function cate1()
  239. {
  240. $param = Request::only(['type' => '']);
  241. View::assign('type', $param['type']);
  242. return View::fetch();
  243. }
  244. /**
  245. * 添加分类
  246. */
  247. public function saveCate()
  248. {
  249. $root_id = request()->employee->root_id;
  250. $param = Request::only(['type' => '', 'title' => '', 'pid' => 0,'level' => 1,'is_case'=>0]);
  251. if ($param['pid']) {
  252. $info = SmartScreenCate::where([['id','=',$param['pid']],['root_id','=',$root_id]])->findOrEmpty();
  253. if($info->isEmpty()) return json(['code' => 1, 'data' => '参数错误', 'msg' => '参数错误']);
  254. $param['is_case'] = $info->is_case;
  255. }
  256. View::assign('type', $param['type']);
  257. $where = [
  258. ['root_id', '=', $root_id],
  259. ['title', '=', $param['title']],
  260. ['pid', '=', $param['pid']],
  261. ['code', '=', $param['type']],
  262. ['level', '=', $param['level']],
  263. ['del','=',0]
  264. ];
  265. $find = SmartScreenCate::where($where)->findOrEmpty();
  266. if (!$find->isEmpty()) return json(['code' => 1, 'data' => '名称重复', 'msg' => '名称重复']);
  267. $pid = SmartScreenCate::insertGetId([
  268. 'root_id' => $root_id,
  269. 'title' => $param['title'],
  270. 'pid' => $param['pid'],
  271. 'is_case' => $param['is_case'],
  272. 'code' => $param['type'],
  273. 'level' => $param['level']
  274. ]);
  275. if ($param['is_case']==1 && $param['pid']==0) {
  276. $decostyle = Decostyle::where([['root_id','=',$root_id],['type','=',0]])->column('name');
  277. $community = Community::where([['root_id','=',$root_id],['type','=',0]])->column('name');
  278. $housetype = Housetype::where([['root_id','=',$root_id]])->column('name');
  279. $decostyle = $decostyle ?: ['新中式','轻奢','北欧','简欧','日式','田园'];
  280. $community = $community ?: ['碧桂园天悦','恒大城'];
  281. $housetype = $housetype ?: ['一室一厅','两室一厅','三室一厅','三室两厅','复式'];
  282. $p1 = SmartScreenCate::insertGetId([
  283. 'root_id'=>$root_id,
  284. 'title'=>'风格',
  285. 'code'=>$param['type'],
  286. 'pid'=>$pid,
  287. 'is_case'=>1,
  288. 'level'=>2
  289. ]);
  290. foreach ($decostyle as $k1 => $v1) {
  291. SmartScreenCate::insertGetId([
  292. 'root_id'=>$root_id,
  293. 'title'=>$v1,
  294. 'code'=>$param['type'],
  295. 'pid'=>$p1,
  296. 'is_case'=>1,
  297. 'level'=>3
  298. ]);
  299. }
  300. $p2 = SmartScreenCate::insertGetId([
  301. 'root_id'=>$root_id,
  302. 'title'=>'小区',
  303. 'code'=>$param['type'],
  304. 'pid'=>$pid,
  305. 'is_case'=>1,
  306. 'level'=>2
  307. ]);
  308. foreach ($community as $k2 => $v2) {
  309. SmartScreenCate::insertGetId([
  310. 'root_id'=>$root_id,
  311. 'title'=>$v2,
  312. 'code'=>$param['type'],
  313. 'pid'=>$p2,
  314. 'is_case'=>1,
  315. 'level'=>3
  316. ]);
  317. }
  318. $p3 = SmartScreenCate::insertGetId([
  319. 'root_id'=>$root_id,
  320. 'title'=>'户型',
  321. 'code'=>$param['type'],
  322. 'pid'=>$pid,
  323. 'is_case'=>1,
  324. 'level'=>2
  325. ]);
  326. foreach ($housetype as $k3 => $v3) {
  327. SmartScreenCate::insertGetId([
  328. 'root_id'=>$root_id,
  329. 'title'=>$v3,
  330. 'code'=>$param['type'],
  331. 'pid'=>$p3,
  332. 'is_case'=>1,
  333. 'level'=>3
  334. ]);
  335. }
  336. }
  337. return json(['code' => 0, 'data' => '保存成功', 'msg' => '保存成功']);
  338. }
  339. /**
  340. * 编辑分类
  341. */
  342. public function editCate()
  343. {
  344. $root_id = request()->employee->root_id;
  345. $param = Request::only([ 'title' => '', 'id' => 0]);
  346. $info = SmartScreenCate::where([['root_id','=',$root_id],['id','=',$param['id']]])->findOrEmpty();
  347. if($info->isEmpty()) return json(['code' => 1, 'data' => '参数错误', 'msg' => '参数错误']);
  348. $where = [
  349. ['root_id','=',$root_id],
  350. ['title','=',$param['title']],
  351. ['id','<>',$param['id']],
  352. ['code','=',$info->code],
  353. ['level','=',$info->level]
  354. ];
  355. $check = SmartScreenCate::where($where)->findOrEmpty();
  356. if(!$check->isEmpty()) return json(['code' => 1, 'data' => '名称重复', 'msg' => '名称重复']);
  357. $info->title = $param['title'];
  358. $info->save();
  359. return json(['code' => 0, 'data' => '保存成功', 'msg' => '保存成功']);
  360. }
  361. /**
  362. * 删除分类
  363. */
  364. public function delCate()
  365. {
  366. $root_id = request()->employee->root_id;
  367. $param = Request::only([ 'id' => 0]);
  368. $info = SmartScreenCate::where([['root_id','=',$root_id],['id','=',$param['id']]])->findOrEmpty();
  369. if($info->isEmpty()) return json(['code' => 1, 'data' => '参数错误', 'msg' => '参数错误']);
  370. $info->del = 1;
  371. $info->save();
  372. return json(['code' => 0, 'data' => '删除成功', 'msg' => '删除成功']);
  373. }
  374. /**
  375. * 二级分类页面
  376. *
  377. */
  378. public function cate2()
  379. {
  380. $param = Request::only(['type' => '', 'pid' => 0]);
  381. $info = SmartScreenCate::where('id', $param['pid'])->findOrEmpty();
  382. View::assign('type', $param['type']);
  383. $root_id = request()->employee->root_id;
  384. //一级分类
  385. $where = [
  386. ['pid', '=', 0],
  387. ['root_id', '=', $root_id],
  388. ['level', '=', 1],
  389. ['del', '=', 0],
  390. ['code','=',$param['type']]
  391. ];
  392. $cate1 = SmartScreenCate::where($where)->select()->toArray();
  393. //二级
  394. $where = [
  395. ['pid', 'in', array_column($cate1,'id')],
  396. ['root_id', '=', $root_id],
  397. ['level', '=', 2],
  398. ['del', '=', 0],
  399. ['code','=',$param['type']]
  400. ];
  401. $level2 = SmartScreenCate::where($where)->select()->toArray();
  402. //三级
  403. $where = [
  404. ['pid', 'in', array_column($level2, 'id')],
  405. ['root_id', '=', $root_id],
  406. ['level', '=', 3],
  407. ['del', '=', 0],
  408. ['code','=',$param['type']]
  409. ];
  410. $level3 = SmartScreenCate::where($where)->select()->toArray();
  411. //合并二级三级
  412. foreach ($level2 as $k => $v) {
  413. $level2[$k]['child'] = [];
  414. foreach ($level3 as $k3 => $v3) {
  415. if ($v3['pid'] == $v['id']) $level2[$k]['child'][] = $v3;
  416. }
  417. }
  418. //合并一级二级
  419. foreach ($cate1 as $k1 => $v1) {
  420. $cate1[$k1]['child'] = [];
  421. foreach ($level2 as $k4 => $v4) {
  422. if($v4['pid']==$v1['id']) $cate1[$k1]['child'][] = $v4;
  423. }
  424. }
  425. View::assign('cate', $cate1);
  426. // View::assign('row', $level2);
  427. // View::assign('is_case', $info->is_case);
  428. View::assign('pid', $param['pid']);
  429. return View::fetch();
  430. }
  431. /**
  432. * 添加素材
  433. */
  434. public function addMaterial()
  435. {
  436. $root_id = request()->employee->root_id;
  437. $param = Request::only(['type' => '', 'pid' => 0]);
  438. $info = SmartScreenCate::where('id',$param['pid'])->find();
  439. $view = $info->is_case ? 'add1' : 'add2';
  440. //设计师
  441. $orgs = Org::where([['path','like',$root_id.'-%'],['org_type','=',2]])->column('id');
  442. $designer = Employee::where([['state','=','在职'],['uid','>',0],['org_id','in',$orgs]])->column('id,name');
  443. View::assign('designer',$designer);
  444. //获取二级分类
  445. // $query = ['title','not in',['小区','户型','风格']];
  446. $cates = SmartScreenCate::where([['pid','=',$param['pid'],['root_id','=',$root_id]],['del','=',0]])->select()->toArray();
  447. $community = $decostyle = $housetype = [];
  448. $community_id = $decostyle_id = $housetype_id = 0;
  449. foreach ($cates as $key => $value) {
  450. if($value['title']=='小区') $community_id=$value['id'];
  451. if($value['title']=='风格') $decostyle_id=$value['id'];
  452. if($value['title']=='户型') $housetype_id=$value['id'];
  453. }
  454. //三级
  455. $label = SmartScreenCate::where([['code','=',$info->code],['level','=',3],['del','=',0]])->select()->toArray();
  456. $joinlabel = [];
  457. foreach ($label as $val) {
  458. $joinlabel[$val['pid']][$val['id']] = $val['title'];
  459. if($val['pid']==$community_id) $community[] = $val;
  460. if($val['pid']==$decostyle_id) $decostyle[] = $val;
  461. if($val['pid']==$housetype_id) $housetype[] = $val;
  462. }
  463. View::assign('community',$community);
  464. View::assign('decostyle',$decostyle);
  465. View::assign('housetype',$housetype);
  466. View::assign('label', json_encode($joinlabel));
  467. View::assign('type',$cates);
  468. View::assign('cate1',$param['pid']);
  469. return View::fetch($view);
  470. }
  471. /*
  472. * 素材添加
  473. */
  474. public function add()
  475. {
  476. $root_id = request()->employee->root_id;
  477. $data = Request::only(['file'=>'','title'=>'','cate1'=>'','cate2'=>'','cate3'=>'','desc'=>'', 'cover'=>'', 'real_case'=>'', 'video_case'=>'', 'vr_case'=>'','video_format'=>0,'difference'=>0,'type'=>0,'square'=>0,'designer_id'=>0,'community_id'=>0,'decostyle_id'=>0,'housetype_id'=>0,'money'=>0]);
  478. $data['employee_id'] = request()->employee->id;
  479. $data['root_id'] = $root_id;
  480. $data['desc'] = input('desc2','') ? input('desc2','') : $data['desc'];
  481. SmartScreenData::create($data);
  482. return json(['code' => 0, 'msg' => '保存成功']);
  483. }
  484. /**
  485. * 文件上传
  486. */
  487. public function fileupload()
  488. {
  489. $ali_oss_bindurl = config('app.ali_oss_bindurl');
  490. $url = 'https://' . $ali_oss_bindurl . '/' . Request::param('file');
  491. return json(['code' => 0, 'data' => ['src' => $url]]);
  492. }
  493. /*
  494. * 列表
  495. */
  496. public function list()
  497. {
  498. $root_id = request()->employee->root_id;
  499. $param = Request::only(['pid'=>0,'limit'=>10,'page'=>1,'keyword'=>'','label'=>0]);
  500. $val = $param['label'] ?: $param['pid'];
  501. $where[] = ['cate1','find in set',$val];
  502. $where[] = ['del','=',0];
  503. $where[] = ['root_id','=',$root_id];
  504. if($param['keyword']) $where[] = ['title','like','%'.$param['keyword'].'%'];
  505. $list = SmartScreenData::with(['cate1'=>function($query){
  506. $query->field('id,title')->bind(['cate1_name'=>'title','is_case'=>'is_case']);
  507. },'cate2'=>function($query){
  508. $query->field('id,title')->bind(['cate2_name'=>'title']);
  509. },'cate3'=>function($query){
  510. $query->field('id,title')->bind(['cate3_name'=>'title']);
  511. },'employee'=>function($query){
  512. $query->field('id,name,opt_name')->bind(['e_name'=>'name','opt_name'=>'opt_name']);
  513. }])->where($where)->page($param['page'],$param['limit'])->order('id desc')->select();
  514. $count = SmartScreenData::where($where)->count();
  515. //讲解次数
  516. $vrObj = new Vr();
  517. foreach ($list as $k => $v) {
  518. $list[$k]['type'] = $v['type'] ? '必看' : '推荐';
  519. //封面图
  520. if ($v['is_case']==0 && $v['difference']==3) {
  521. $list[$k]['leixing'] = 'VR';
  522. $list[$k]['covers'] = $v['vr_case'] ? $vrObj->getFirstImg($v['vr_case']) : '';
  523. }elseif ($v['is_case']==0 && $v['difference']==1){
  524. $list[$k]['leixing'] = '视频';
  525. $list[$k]['covers'] = $v['cover'] ? $v['cover'].'?x-oss-process=image/resize,w_50' : '';
  526. // $list[$k]['covers'] = $v['covers'] ? $v['video_case'].'?x-oss-process=video/snapshot,t_100,f_jpg,w_200,m_fast' : '';
  527. }elseif ($v['is_case']==0 && $v['difference']==2){
  528. $list[$k]['leixing'] = '图文';
  529. $list[$k]['covers'] = $v['cover'] ? $v['cover'].'?x-oss-process=image/resize,w_50' : '';
  530. }elseif($v['is_case']==0 && $v['difference']==4){
  531. $list[$k]['leixing'] = 'PDF';
  532. $list[$k]['covers'] = $v['cover'] ? $v['cover'].'?x-oss-process=image/resize,w_50' : '';
  533. }else{
  534. $list[$k]['leixing'] = '案例';
  535. $list[$k]['covers'] = $v['cover'] ? $v['cover'].'?x-oss-process=image/resize,w_50' : '';
  536. }
  537. //
  538. if(empty($v['e_name']) && $v['opt_name']) $list[$k]['e_name'] = $v['opt_name'];
  539. }
  540. //分类
  541. // $cate1 = array_column($list,'cate1');
  542. // $cate2 = array_column($list,'cate2');
  543. // $cate3 = array_column($list,'cate3');
  544. // $cate = implode(',',array_merge($cate1,$cate2,$cate3));
  545. // $cate = array_filter(explode(',',$cate));
  546. // $cate =
  547. return json(['code' => 0, 'data'=>$list,'count'=>$count, 'msg' => '保存成功']);
  548. }
  549. /**
  550. * 删除
  551. */
  552. public function del()
  553. {
  554. $root_id = request()->employee->root_id;
  555. $param = Request::only(['id'=>0]);
  556. $where = [
  557. ['root_id','=',$root_id],
  558. ['id','=',$param['id']]
  559. ];
  560. SmartScreenData::where($where)->update(['del'=>1]);
  561. return json(['code' => 0, 'data'=>'删除成功','msg' => '删除成功']);
  562. }
  563. /*
  564. * 素材编辑
  565. */
  566. public function edit()
  567. {
  568. $root_id = request()->employee->root_id;
  569. $param = Request::only(['id'=>0,'pid'=>0]);
  570. $where = [
  571. ['root_id','=',$root_id],
  572. ['id','=',$param['id']]
  573. ];
  574. $infos = SmartScreenData::where($where)->find();
  575. View::assign('data',$infos);
  576. //设计师
  577. $orgs = Org::where([['path','like',$root_id.'-%'],['org_type','=',2]])->column('id');
  578. $designer = Employee::where([['state','=','在职'],['uid','>',0],['org_id','in',$orgs]])->column('id,name');
  579. View::assign('designer',$designer);
  580. //获取二级分类
  581. // $query = ['title','not in',['小区','户型','风格']];
  582. $cates = SmartScreenCate::where([['pid','=',$param['pid'],['root_id','=',$root_id]],['del','=',0]])->select()->toArray();
  583. $community = $decostyle = $housetype = [];
  584. $community_id = $decostyle_id = $housetype_id = 0;
  585. foreach ($cates as $key => $value) {
  586. if($value['title']=='小区') $community_id=$value['id'];
  587. if($value['title']=='风格') $decostyle_id=$value['id'];
  588. if($value['title']=='户型') $housetype_id=$value['id'];
  589. }
  590. $info = SmartScreenCate::where('id',$param['pid'])->find();
  591. $view = $info->is_case ? 'edit1' : 'edit2';
  592. //三级
  593. $label = SmartScreenCate::where([['code','=',$info->code],['level','=',3],['del','=',0]])->select()->toArray();
  594. $joinlabel = [];
  595. foreach ($label as $val) {
  596. $joinlabel[$val['pid']][$val['id']] = $val['title'];
  597. if($val['pid']==$community_id) $community[] = $val;
  598. if($val['pid']==$decostyle_id) $decostyle[] = $val;
  599. if($val['pid']==$housetype_id) $housetype[] = $val;
  600. }
  601. View::assign('community',$community);
  602. View::assign('decostyle',$decostyle);
  603. View::assign('housetype',$housetype);
  604. View::assign('label', json_encode($joinlabel));
  605. View::assign('type',$cates);
  606. View::assign('cate1',$param['pid']);
  607. View::assign('id',$param['id']);
  608. //默认三级
  609. $cate3 = SmartScreenCate::where('id',$infos->cate3)->value('title');
  610. View::assign('cate3',['id'=>$infos->cate3,'title'=>$cate3]);
  611. return View::fetch($view);
  612. }
  613. /*
  614. * 编辑
  615. */
  616. public function edits()
  617. {
  618. $root_id = request()->employee->root_id;
  619. $data = Request::only(['id'=>0,'title'=>'','cate1'=>'','cate2'=>'','cate3'=>'','desc'=>'', 'cover'=>'', 'real_case'=>'', 'video_case'=>'', 'vr_case'=>'','video_format'=>0,'difference'=>0,'type'=>0,'square'=>0,'designer_id'=>0,'community_id'=>0,'decostyle_id'=>0,'housetype_id'=>0,'money'=>0]);
  620. $id = $data['id'];
  621. unset($data['id']);
  622. $where = [
  623. ['root_id','=',$root_id],
  624. ['id','=',$id]
  625. ];
  626. $data['desc'] = input('desc2','') ? input('desc2','') : $data['desc'];
  627. $domain = config('app.ali_oss_bindurl');
  628. $search = 'https://'.$domain.'/';
  629. if($data['cover']) $data['cover'] = str_replace($search, '', $data['cover']);
  630. if($data['video_case']){
  631. $data['video_case'] = str_replace($search, '', $data['video_case']);
  632. $arr = explode(',',$data['video_case']);
  633. $data['video_case'] = end($arr);
  634. }
  635. SmartScreenData::where($where)->update($data);
  636. return json(['code' => 0,'data'=>'保存成功', 'msg' => '保存成功']);
  637. }
  638. /**
  639. * 删除一级标签
  640. */
  641. public function delCate1()
  642. {
  643. $root_id = request()->employee->root_id;
  644. $param = Request::only([ 'id' => 0]);
  645. $info = SmartScreenCate::where([['root_id','=',$root_id],['id','=',$param['id']]])->findOrEmpty();
  646. if($info->isEmpty()) return json(['code' => 1, 'data' => '参数错误', 'msg' => '参数错误']);
  647. $info->del = 1;
  648. $info->save();
  649. //
  650. $cate2 = SmartScreenCate::where('pid',$info->id)->select()->toArray();
  651. SmartScreenCate::where([['id|pid','in',array_column($cate2,'id')]])->update(['del'=>1]);
  652. return json(['code' => 0, 'data' => '删除成功', 'msg' => '删除成功']);
  653. }
  654. /**
  655. * 删除二级标签
  656. */
  657. public function delCate2()
  658. {
  659. $root_id = request()->employee->root_id;
  660. $param = Request::only([ 'id' => 0]);
  661. $info = SmartScreenCate::where([['root_id','=',$root_id],['id','=',$param['id']]])->findOrEmpty();
  662. if($info->isEmpty()) return json(['code' => 1, 'data' => '参数错误', 'msg' => '参数错误']);
  663. $info->del = 1;
  664. $info->save();
  665. //
  666. $cate2 = SmartScreenCate::where('pid',$info->id)->select()->toArray();
  667. return json(['code' => 0, 'data' => '删除成功', 'msg' => '删除成功']);
  668. }
  669. /**
  670. * 恢复默认
  671. */
  672. public function recovery()
  673. {
  674. $root_id = request()->employee->root_id;
  675. $param = Request::only([ 'type' => '']);
  676. $where = [
  677. ['root_id','=',$root_id],
  678. ['code','=',$param['type']]
  679. ];
  680. $title = $this->modular[$param['type']];
  681. $info = SmartScreenModel::where($where)->update(['background_img'=>'','lcon_img'=>'','title'=>$title]);
  682. return json(['code' => 0, 'data' => '恢复成功', 'msg' => '恢复成功']);
  683. }
  684. /**
  685. * 此方法用于从某个企业复制<谈单智慧屏>内容至另一个企业
  686. */
  687. public function copy_smart_screen($from_root_id = 0 , $new_root_id = 0)
  688. {
  689. if (!$from_root_id || !$new_root_id) return '错误';
  690. if ($from_root_id == $new_root_id) return '错误';
  691. $company = Company::where([['root_id','in',[$from_root_id,$new_root_id]]])->count();
  692. if($company != 2) return '错误';
  693. Db::startTrans();
  694. try {
  695. $cateArray = [];
  696. //一级
  697. $cate1 = SmartScreenCate::where(['root_id'=>$from_root_id , 'del'=>0 , 'pid'=>0 , 'level'=>1])->order('addtime')->select();
  698. foreach($cate1 as $item1){
  699. $new_cate1 = SmartScreenCate::insertGetId([
  700. 'root_id' => $new_root_id,
  701. 'title' => $item1['title'],
  702. 'code' => $item1['code'],
  703. 'pid' => 0,
  704. 'is_case' => $item1['is_case'],
  705. 'level' => 1,
  706. ]);
  707. $cateArray[$item1['id']] = $new_cate1;
  708. //二级
  709. $cate2 = SmartScreenCate::where(['root_id'=>$from_root_id , 'del'=>0 , 'pid'=>$item1['id'] , 'level'=>2])->order('addtime')->select();
  710. foreach($cate2 as $item2){
  711. $new_cate2 = SmartScreenCate::insertGetId([
  712. 'root_id' => $new_root_id,
  713. 'title' => $item2['title'],
  714. 'code' => $item2['code'],
  715. 'pid' => $new_cate1,
  716. 'is_case' => $item2['is_case'],
  717. 'level' => 2,
  718. ]);
  719. $cateArray[$item2['id']] = $new_cate2;
  720. //三级
  721. $cate3 = SmartScreenCate::where(['root_id'=>$from_root_id , 'del'=>0 , 'pid'=>$item2['id'] , 'level'=>3])->order('addtime')->select();
  722. foreach($cate3 as $item3){
  723. $new_cate3 = SmartScreenCate::insertGetId([
  724. 'root_id' => $new_root_id,
  725. 'title' => $item3['title'],
  726. 'code' => $item3['code'],
  727. 'pid' => $new_cate2,
  728. 'is_case' => $item3['is_case'],
  729. 'level' => 3,
  730. ]);
  731. $cateArray[$item3['id']] = $new_cate3;
  732. }
  733. }
  734. }
  735. //内容
  736. $data = SmartScreenData::where(['root_id'=>$from_root_id , 'del'=>0 ])->order('addtime')->column('*','id');
  737. $newData = [];
  738. foreach($data as $val){
  739. $arr['root_id'] = $new_root_id;
  740. $arr['cate1'] = isset($cateArray[$val['cate1']]) ? $cateArray[$val['cate1']] : '';
  741. $arr['cate2'] = isset($cateArray[$val['cate2']]) ? $cateArray[$val['cate2']] : '';
  742. $arr['cate3'] = isset($cateArray[$val['cate3']]) ? $cateArray[$val['cate3']] : '';
  743. $arr['title'] = $val['title'];
  744. $arr['pics'] = $val['pics'];
  745. $arr['cover'] = $val['cover'];
  746. $arr['desc'] = $val['desc'];
  747. $arr['real_case'] = $val['real_case'];
  748. $arr['vr_case'] = $val['vr_case'];
  749. $arr['video_case'] = $val['video_case'];
  750. $arr['video_format'] = $val['video_format'];
  751. $arr['difference'] = $val['difference'];
  752. $arr['type'] = $val['type'];
  753. $arr['square'] = $val['square'];
  754. $arr['money'] = $val['money'];
  755. $arr['square'] = $val['square'];
  756. $arr['square'] = $val['square'];
  757. $newData[] = $arr;
  758. }
  759. $screendata = new SmartScreenData;
  760. $screendata->saveAll($newData);
  761. //模块设置
  762. $screen = SmartScreenModel::where(['root_id'=>$from_root_id , 'del'=>0 ])->order('addtime')->column('*','id');
  763. $screenData = [];
  764. foreach($screen as $sc){
  765. $scArr['root_id'] = $new_root_id;
  766. $scArr['title'] = $sc['title'];
  767. $scArr['code'] = $sc['code'];
  768. $scArr['background_img'] = $sc['background_img'];
  769. $scArr['lcon_img'] = $sc['lcon_img'];
  770. $screenData[] = $scArr;
  771. }
  772. $screens = new SmartScreenModel;
  773. $screens->saveAll($screenData);
  774. Db::commit();
  775. return '复制成功';
  776. } catch (\Exception $e) {
  777. // 回滚事务
  778. Db::rollback();
  779. return '复制失败';
  780. }
  781. }
  782. /**
  783. * 智慧屏设置谈单有效时长
  784. */
  785. public function setValidMinutes(){
  786. $root_id = request()->employee->root_id;
  787. $minutes = input('minutes', 0, 'intval');
  788. $where = [
  789. ['name', '=', 'smartScreenValidMinutes'],
  790. ['root_id', '=', $root_id]
  791. ];
  792. $info = Setting::where($where)->findOrEmpty();
  793. if ($info->isEmpty()) {
  794. Setting::insert([
  795. 'name' => 'smartScreenValidMinutes',
  796. 'root_id' => $root_id,
  797. 'content' => $minutes
  798. ]);
  799. } else {
  800. $info->content = $minutes;
  801. $info->save();
  802. }
  803. return json(['code' => 0, 'data' => '保存成功', 'msg' => '保存成功']);
  804. }
  805. }