123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867 |
- <?php
- namespace app\sys\controller;
- use think\facade\View;
- use app\model\Setting;
- use app\model\SmartScreen as SmartScreenModel;
- use think\facade\Request;
- use app\model\SmartScreenCate;
- use app\model\SmartScreenData;
- use app\model\Org;
- use app\model\Employee;
- use xiaohongwu\Vr;
- use app\model\Decostyle;
- use app\model\Community;
- use app\model\Housetype;
- use app\model\Permission;
- use app\model\Company;
- use think\facade\Db;
- use toolkits\Aec;
- class SmartScreen
- {
- private $modular;
- public function __construct()
- {
- $this->modular = ['introduce' => '公司简介', 'pattern' => '模式优势', 'boutique' => '精品设计', 'science' => '材料', 'major' => '大牌软装', 'customized' => '定制家具', 'realistic' => '实景样板房', 'praise' => '口碑及服务', 'platinum' => '铂金工程'];
- }
- /**
- * 面板
- */
- public function index()
- {
- $root_id = request()->employee->root_id;
- //录音开关
- $where = [
- ['name', '=', 'recordingSwitch'],
- ['root_id', '=', $root_id]
- ];
- $info = Setting::where($where)->findOrEmpty();
- $data['switch'] = $info->isEmpty() ? 0 : ($info->content ? 1 : 0);
- // 谈单有效时长
- $where1 = [
- ['name', '=', 'smartScreenValidMinutes'],
- ['root_id', '=', $root_id]
- ];
- $smartScreenValidMinutes = Setting::where($where1)->findOrEmpty();
- $data['smartScreenValidMinutes'] = $smartScreenValidMinutes->isEmpty() ? 0 : $smartScreenValidMinutes['content'];
- //9个模块
- $modular = array_keys($this->modular);
- $where = [
- ['root_id', '=', $root_id],
- ['code', 'in', $modular]
- ];
- $res = SmartScreenModel::where($where)->column('*', 'code');
- $ali_oss_bindurl = config('app.ali_oss_bindurl');
- foreach ($res as $k2 => $v2) {
- $res[$k2]['background_img'] = $v2['background_img'] ? 'https://' . $ali_oss_bindurl . '/' . $v2['background_img'] : '';
- $res[$k2]['lcon_img'] = $v2['lcon_img'] ? 'https://' . $ali_oss_bindurl . '/' . $v2['lcon_img'] : '';
- }
- $diff = array_diff($modular, array_keys($res));
- $row = [];
- foreach ($diff as $v) {
- $row[$v] = [
- 'title' => $this->modular[$v],
- 'code' => $v,
- 'background_img' => '',
- 'lcon_img' => ''
- ];
- }
- $data['row'] = array_merge($res, $row);
- View::assign('data', $data);
- //排序后的数据
- $where = [
- ['name', '=', 'wisdomMenuOrder'],
- ['root_id', '=', $root_id]
- ];
- $order = Setting::where($where)->value('content');
- $menus = Permission::where([['uri','like','smartScreen/content?type=%']])->order('sort asc,id asc')->column('id,auth_name as name,uri');
- $new_title = array_column($data['row'],'title','code');
- if ($order) {
- $ids = array_flip(explode(',',$order));
- foreach ($menus as $key => $val) {
- $code = trim(str_replace('smartScreen/content?type=','',$val['uri']));
- $menus[$key]['order'] = $ids[$val['id']];
- $menus[$key]['name'] = $new_title[$code];
- }
- array_multisort(array_column($menus,'order'),SORT_ASC, $menus);
- }else{
- foreach ($menus as $key => $val) {
- $code = trim(str_replace('smartScreen/content?type=','',$val['uri']));
- $menus[$key]['name'] = $new_title[$code];
- }
- }
- View::assign('menus', $menus);
- //智慧屏演示地址
- $domain = request()->domain();
- $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
- View::assign('url', $domain.'/smartscreen.html#/home?token='.$aec->encrypt($root_id.'#0#0'));
- return View::fetch();
- }
- /**
- * 保存排序
- */
- public function saveOrder()
- {
- $root_id = request()->employee->root_id;
- $ids = input('ids','');
- $arr = explode(',',$ids);
- sort($arr);
- $menu = Permission::where([['uri','like','smartScreen/content?type=%']])->order('id asc')->column('id');
- if(empty($ids) || $arr != $menu) return json(['code' => 1, 'data' => 'ids错误', 'msg' => 'ids错误']);
- //排序后的数据
- $where = [
- ['name', '=', 'wisdomMenuOrder'],
- ['root_id', '=', $root_id]
- ];
- $info = Setting::where($where)->findOrEmpty();
- if ($info->isEmpty()) {
- Setting::insert([
- 'name'=>'wisdomMenuOrder',
- 'root_id'=>$root_id,
- 'content'=>$ids
- ]);
- }else{
- $info->content = $ids;
- $info->save();
- }
- return json(['code' => 0, 'data' => '保存成功', 'msg' => '保存成功']);
- }
- /**
- * 智慧屏录音开关设置
- */
- public function recordingSwitch()
- {
- $root_id = request()->employee->root_id;
- $res = 1; //默认开启
- $where = [
- ['name', '=', 'recordingSwitch'],
- ['root_id', '=', $root_id]
- ];
- $info = Setting::where($where)->findOrEmpty();
- if ($info->isEmpty()) {
- Setting::insert([
- 'name' => 'recordingSwitch',
- 'root_id' => $root_id,
- 'content' => 1
- ]);
- } else {
- $res = $info->content ? 0 : 1;
- $info->content = $res;
- $info->save();
- }
- return json(['code' => 0, 'data' => '保存成功', 'msg' => '保存成功']);
- }
- /**
- * 获取单个模块详情
- */
- public function getModularRead()
- {
- $param = Request::only(['type' => '']);
- if (empty($param['type']) || !isset($this->modular[$param['type']])) return json(['code' => 1, 'data' => '参数错误', 'msg' => '参数错误']);
- $root_id = request()->employee->root_id;
- $where = [
- ['code', '=', $param['type']],
- ['root_id', '=', $root_id]
- ];
- $res = SmartScreenModel::where($where)->findOrEmpty();
- $ali_oss_bindurl = config('app.ali_oss_bindurl');
- if ($res->isEmpty()) {
- $res = [
- 'title' => $this->modular[$param['type']],
- 'code' => $param['type'],
- 'background_img' => '',
- 'lcon_img' => ''
- ];
- }
- return json(['code' => 0, 'data' => $res, 'msg' => '保存成功']);
- }
- /**
- * 保存模块信息
- */
- public function saveModularRead()
- {
- $param = Request::only(['type' => '', 'title' => '', 'background_img' => '', 'lcon_img' => '']);
- if (empty($param['type']) || !isset($this->modular[$param['type']])) return json(['code' => 1, 'data' => '参数错误', 'msg' => '参数错误']);
- $root_id = request()->employee->root_id;
- $where = [
- ['code', '=', $param['type']],
- ['root_id', '=', $root_id]
- ];
- $res = SmartScreenModel::where($where)->findOrEmpty();
- if ($res->isEmpty()) {
- SmartScreenModel::insert([
- 'title' => $param['title'],
- 'code' => $param['type'],
- 'background_img' => $param['background_img'],
- 'lcon_img' => $param['lcon_img'],
- 'root_id' => $root_id
- ]);
- } else {
- $res->title = $param['title'];
- $res->background_img = $param['background_img'];
- $res->lcon_img = $param['lcon_img'];
- $res->save();
- }
- return json(['code' => 0, 'data' => '保存成功', 'msg' => '保存成功']);
- }
- /**
- * 公司介绍introduce ,
- *
- */
- public function content()
- {
- $type = input('type', '');
- $cate = $this->modular;
- $title = $cate[$type];
- $root_id = request()->employee->root_id;
- //获取一级分类
- $where = [
- ['root_id', '=', $root_id],
- ['pid', '=', 0],
- ['code', '=', $type],
- ['del', '=', 0],
- ];
- $types = SmartScreenCate::where($where)->order('id asc')->select()->toArray();
- //默认展示第一个标签
- $default_type = $types ? $types[0]['id'] : 0;
- //
- View::assign('default_type', $default_type);
- View::assign('types', $types);
- View::assign('title', $title);
- //类型
- View::assign('type', $type);
- return View::fetch();
- }
- /**
- * 一级分类页面
- *
- */
- public function cate1()
- {
- $param = Request::only(['type' => '']);
- View::assign('type', $param['type']);
- return View::fetch();
- }
- /**
- * 添加分类
- */
- public function saveCate()
- {
- $root_id = request()->employee->root_id;
- $param = Request::only(['type' => '', 'title' => '', 'pid' => 0,'level' => 1,'is_case'=>0]);
- if ($param['pid']) {
- $info = SmartScreenCate::where([['id','=',$param['pid']],['root_id','=',$root_id]])->findOrEmpty();
- if($info->isEmpty()) return json(['code' => 1, 'data' => '参数错误', 'msg' => '参数错误']);
- $param['is_case'] = $info->is_case;
- }
-
- View::assign('type', $param['type']);
- $where = [
- ['root_id', '=', $root_id],
- ['title', '=', $param['title']],
- ['pid', '=', $param['pid']],
- ['code', '=', $param['type']],
- ['level', '=', $param['level']],
- ['del','=',0]
- ];
- $find = SmartScreenCate::where($where)->findOrEmpty();
- if (!$find->isEmpty()) return json(['code' => 1, 'data' => '名称重复', 'msg' => '名称重复']);
- $pid = SmartScreenCate::insertGetId([
- 'root_id' => $root_id,
- 'title' => $param['title'],
- 'pid' => $param['pid'],
- 'is_case' => $param['is_case'],
- 'code' => $param['type'],
- 'level' => $param['level']
- ]);
- if ($param['is_case']==1 && $param['pid']==0) {
- $decostyle = Decostyle::where([['root_id','=',$root_id],['type','=',0]])->column('name');
- $community = Community::where([['root_id','=',$root_id],['type','=',0]])->column('name');
- $housetype = Housetype::where([['root_id','=',$root_id]])->column('name');
- $decostyle = $decostyle ?: ['新中式','轻奢','北欧','简欧','日式','田园'];
- $community = $community ?: ['碧桂园天悦','恒大城'];
- $housetype = $housetype ?: ['一室一厅','两室一厅','三室一厅','三室两厅','复式'];
- $p1 = SmartScreenCate::insertGetId([
- 'root_id'=>$root_id,
- 'title'=>'风格',
- 'code'=>$param['type'],
- 'pid'=>$pid,
- 'is_case'=>1,
- 'level'=>2
- ]);
- foreach ($decostyle as $k1 => $v1) {
- SmartScreenCate::insertGetId([
- 'root_id'=>$root_id,
- 'title'=>$v1,
- 'code'=>$param['type'],
- 'pid'=>$p1,
- 'is_case'=>1,
- 'level'=>3
- ]);
- }
- $p2 = SmartScreenCate::insertGetId([
- 'root_id'=>$root_id,
- 'title'=>'小区',
- 'code'=>$param['type'],
- 'pid'=>$pid,
- 'is_case'=>1,
- 'level'=>2
- ]);
- foreach ($community as $k2 => $v2) {
- SmartScreenCate::insertGetId([
- 'root_id'=>$root_id,
- 'title'=>$v2,
- 'code'=>$param['type'],
- 'pid'=>$p2,
- 'is_case'=>1,
- 'level'=>3
- ]);
- }
- $p3 = SmartScreenCate::insertGetId([
- 'root_id'=>$root_id,
- 'title'=>'户型',
- 'code'=>$param['type'],
- 'pid'=>$pid,
- 'is_case'=>1,
- 'level'=>2
- ]);
- foreach ($housetype as $k3 => $v3) {
- SmartScreenCate::insertGetId([
- 'root_id'=>$root_id,
- 'title'=>$v3,
- 'code'=>$param['type'],
- 'pid'=>$p3,
- 'is_case'=>1,
- 'level'=>3
- ]);
- }
- }
- return json(['code' => 0, 'data' => '保存成功', 'msg' => '保存成功']);
- }
- /**
- * 编辑分类
- */
- public function editCate()
- {
- $root_id = request()->employee->root_id;
- $param = Request::only([ 'title' => '', 'id' => 0]);
- $info = SmartScreenCate::where([['root_id','=',$root_id],['id','=',$param['id']]])->findOrEmpty();
- if($info->isEmpty()) return json(['code' => 1, 'data' => '参数错误', 'msg' => '参数错误']);
- $where = [
- ['root_id','=',$root_id],
- ['title','=',$param['title']],
- ['id','<>',$param['id']],
- ['code','=',$info->code],
- ['level','=',$info->level]
- ];
-
- $check = SmartScreenCate::where($where)->findOrEmpty();
- if(!$check->isEmpty()) return json(['code' => 1, 'data' => '名称重复', 'msg' => '名称重复']);
- $info->title = $param['title'];
- $info->save();
- return json(['code' => 0, 'data' => '保存成功', 'msg' => '保存成功']);
- }
- /**
- * 删除分类
- */
- public function delCate()
- {
- $root_id = request()->employee->root_id;
- $param = Request::only([ 'id' => 0]);
- $info = SmartScreenCate::where([['root_id','=',$root_id],['id','=',$param['id']]])->findOrEmpty();
- if($info->isEmpty()) return json(['code' => 1, 'data' => '参数错误', 'msg' => '参数错误']);
- $info->del = 1;
- $info->save();
- return json(['code' => 0, 'data' => '删除成功', 'msg' => '删除成功']);
- }
- /**
- * 二级分类页面
- *
- */
- public function cate2()
- {
- $param = Request::only(['type' => '', 'pid' => 0]);
- $info = SmartScreenCate::where('id', $param['pid'])->findOrEmpty();
- View::assign('type', $param['type']);
- $root_id = request()->employee->root_id;
- //一级分类
- $where = [
- ['pid', '=', 0],
- ['root_id', '=', $root_id],
- ['level', '=', 1],
- ['del', '=', 0],
- ['code','=',$param['type']]
- ];
- $cate1 = SmartScreenCate::where($where)->select()->toArray();
- //二级
- $where = [
- ['pid', 'in', array_column($cate1,'id')],
- ['root_id', '=', $root_id],
- ['level', '=', 2],
- ['del', '=', 0],
- ['code','=',$param['type']]
- ];
- $level2 = SmartScreenCate::where($where)->select()->toArray();
- //三级
- $where = [
- ['pid', 'in', array_column($level2, 'id')],
- ['root_id', '=', $root_id],
- ['level', '=', 3],
- ['del', '=', 0],
- ['code','=',$param['type']]
- ];
- $level3 = SmartScreenCate::where($where)->select()->toArray();
- //合并二级三级
- foreach ($level2 as $k => $v) {
- $level2[$k]['child'] = [];
- foreach ($level3 as $k3 => $v3) {
- if ($v3['pid'] == $v['id']) $level2[$k]['child'][] = $v3;
- }
- }
- //合并一级二级
- foreach ($cate1 as $k1 => $v1) {
- $cate1[$k1]['child'] = [];
- foreach ($level2 as $k4 => $v4) {
- if($v4['pid']==$v1['id']) $cate1[$k1]['child'][] = $v4;
- }
- }
- View::assign('cate', $cate1);
- // View::assign('row', $level2);
- // View::assign('is_case', $info->is_case);
- View::assign('pid', $param['pid']);
- return View::fetch();
- }
- /**
- * 添加素材
- */
- public function addMaterial()
- {
- $root_id = request()->employee->root_id;
- $param = Request::only(['type' => '', 'pid' => 0]);
- $info = SmartScreenCate::where('id',$param['pid'])->find();
- $view = $info->is_case ? 'add1' : 'add2';
- //设计师
- $orgs = Org::where([['path','like',$root_id.'-%'],['org_type','=',2]])->column('id');
- $designer = Employee::where([['state','=','在职'],['uid','>',0],['org_id','in',$orgs]])->column('id,name');
- View::assign('designer',$designer);
- //获取二级分类
- // $query = ['title','not in',['小区','户型','风格']];
- $cates = SmartScreenCate::where([['pid','=',$param['pid'],['root_id','=',$root_id]],['del','=',0]])->select()->toArray();
- $community = $decostyle = $housetype = [];
- $community_id = $decostyle_id = $housetype_id = 0;
- foreach ($cates as $key => $value) {
- if($value['title']=='小区') $community_id=$value['id'];
- if($value['title']=='风格') $decostyle_id=$value['id'];
- if($value['title']=='户型') $housetype_id=$value['id'];
- }
- //三级
- $label = SmartScreenCate::where([['code','=',$info->code],['level','=',3],['del','=',0]])->select()->toArray();
- $joinlabel = [];
- foreach ($label as $val) {
- $joinlabel[$val['pid']][$val['id']] = $val['title'];
- if($val['pid']==$community_id) $community[] = $val;
- if($val['pid']==$decostyle_id) $decostyle[] = $val;
- if($val['pid']==$housetype_id) $housetype[] = $val;
- }
- View::assign('community',$community);
- View::assign('decostyle',$decostyle);
- View::assign('housetype',$housetype);
- View::assign('label', json_encode($joinlabel));
- View::assign('type',$cates);
- View::assign('cate1',$param['pid']);
- return View::fetch($view);
- }
- /*
- * 素材添加
- */
- public function add()
- {
- $root_id = request()->employee->root_id;
- $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]);
- $data['employee_id'] = request()->employee->id;
- $data['root_id'] = $root_id;
- $data['desc'] = input('desc2','') ? input('desc2','') : $data['desc'];
- SmartScreenData::create($data);
- return json(['code' => 0, 'msg' => '保存成功']);
- }
- /**
- * 文件上传
- */
- public function fileupload()
- {
- $ali_oss_bindurl = config('app.ali_oss_bindurl');
- $url = 'https://' . $ali_oss_bindurl . '/' . Request::param('file');
- return json(['code' => 0, 'data' => ['src' => $url]]);
- }
- /*
- * 列表
- */
- public function list()
- {
- $root_id = request()->employee->root_id;
- $param = Request::only(['pid'=>0,'limit'=>10,'page'=>1,'keyword'=>'','label'=>0]);
- $val = $param['label'] ?: $param['pid'];
- $where[] = ['cate1','find in set',$val];
- $where[] = ['del','=',0];
- $where[] = ['root_id','=',$root_id];
- if($param['keyword']) $where[] = ['title','like','%'.$param['keyword'].'%'];
- $list = SmartScreenData::with(['cate1'=>function($query){
- $query->field('id,title')->bind(['cate1_name'=>'title','is_case'=>'is_case']);
- },'cate2'=>function($query){
- $query->field('id,title')->bind(['cate2_name'=>'title']);
- },'cate3'=>function($query){
- $query->field('id,title')->bind(['cate3_name'=>'title']);
- },'employee'=>function($query){
- $query->field('id,name,opt_name')->bind(['e_name'=>'name','opt_name'=>'opt_name']);
- }])->where($where)->page($param['page'],$param['limit'])->order('id desc')->select();
- $count = SmartScreenData::where($where)->count();
- //讲解次数
- $vrObj = new Vr();
- foreach ($list as $k => $v) {
- $list[$k]['type'] = $v['type'] ? '必看' : '推荐';
- //封面图
- if ($v['is_case']==0 && $v['difference']==3) {
- $list[$k]['leixing'] = 'VR';
- $list[$k]['covers'] = $v['vr_case'] ? $vrObj->getFirstImg($v['vr_case']) : '';
- }elseif ($v['is_case']==0 && $v['difference']==1){
- $list[$k]['leixing'] = '视频';
- $list[$k]['covers'] = $v['cover'] ? $v['cover'].'?x-oss-process=image/resize,w_50' : '';
- // $list[$k]['covers'] = $v['covers'] ? $v['video_case'].'?x-oss-process=video/snapshot,t_100,f_jpg,w_200,m_fast' : '';
- }elseif ($v['is_case']==0 && $v['difference']==2){
- $list[$k]['leixing'] = '图文';
- $list[$k]['covers'] = $v['cover'] ? $v['cover'].'?x-oss-process=image/resize,w_50' : '';
- }elseif($v['is_case']==0 && $v['difference']==4){
- $list[$k]['leixing'] = 'PDF';
- $list[$k]['covers'] = $v['cover'] ? $v['cover'].'?x-oss-process=image/resize,w_50' : '';
- }else{
- $list[$k]['leixing'] = '案例';
- $list[$k]['covers'] = $v['cover'] ? $v['cover'].'?x-oss-process=image/resize,w_50' : '';
- }
- //
- if(empty($v['e_name']) && $v['opt_name']) $list[$k]['e_name'] = $v['opt_name'];
- }
- //分类
- // $cate1 = array_column($list,'cate1');
- // $cate2 = array_column($list,'cate2');
- // $cate3 = array_column($list,'cate3');
- // $cate = implode(',',array_merge($cate1,$cate2,$cate3));
- // $cate = array_filter(explode(',',$cate));
- // $cate =
- return json(['code' => 0, 'data'=>$list,'count'=>$count, 'msg' => '保存成功']);
- }
- /**
- * 删除
- */
- public function del()
- {
- $root_id = request()->employee->root_id;
- $param = Request::only(['id'=>0]);
- $where = [
- ['root_id','=',$root_id],
- ['id','=',$param['id']]
- ];
- SmartScreenData::where($where)->update(['del'=>1]);
- return json(['code' => 0, 'data'=>'删除成功','msg' => '删除成功']);
- }
- /*
- * 素材编辑
- */
- public function edit()
- {
- $root_id = request()->employee->root_id;
- $param = Request::only(['id'=>0,'pid'=>0]);
- $where = [
- ['root_id','=',$root_id],
- ['id','=',$param['id']]
- ];
- $infos = SmartScreenData::where($where)->find();
- View::assign('data',$infos);
- //设计师
- $orgs = Org::where([['path','like',$root_id.'-%'],['org_type','=',2]])->column('id');
- $designer = Employee::where([['state','=','在职'],['uid','>',0],['org_id','in',$orgs]])->column('id,name');
- View::assign('designer',$designer);
- //获取二级分类
- // $query = ['title','not in',['小区','户型','风格']];
- $cates = SmartScreenCate::where([['pid','=',$param['pid'],['root_id','=',$root_id]],['del','=',0]])->select()->toArray();
- $community = $decostyle = $housetype = [];
- $community_id = $decostyle_id = $housetype_id = 0;
- foreach ($cates as $key => $value) {
- if($value['title']=='小区') $community_id=$value['id'];
- if($value['title']=='风格') $decostyle_id=$value['id'];
- if($value['title']=='户型') $housetype_id=$value['id'];
- }
- $info = SmartScreenCate::where('id',$param['pid'])->find();
- $view = $info->is_case ? 'edit1' : 'edit2';
- //三级
- $label = SmartScreenCate::where([['code','=',$info->code],['level','=',3],['del','=',0]])->select()->toArray();
- $joinlabel = [];
- foreach ($label as $val) {
- $joinlabel[$val['pid']][$val['id']] = $val['title'];
- if($val['pid']==$community_id) $community[] = $val;
- if($val['pid']==$decostyle_id) $decostyle[] = $val;
- if($val['pid']==$housetype_id) $housetype[] = $val;
- }
- View::assign('community',$community);
- View::assign('decostyle',$decostyle);
- View::assign('housetype',$housetype);
- View::assign('label', json_encode($joinlabel));
- View::assign('type',$cates);
- View::assign('cate1',$param['pid']);
- View::assign('id',$param['id']);
- //默认三级
- $cate3 = SmartScreenCate::where('id',$infos->cate3)->value('title');
- View::assign('cate3',['id'=>$infos->cate3,'title'=>$cate3]);
- return View::fetch($view);
- }
- /*
- * 编辑
- */
- public function edits()
- {
- $root_id = request()->employee->root_id;
- $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]);
- $id = $data['id'];
- unset($data['id']);
- $where = [
- ['root_id','=',$root_id],
- ['id','=',$id]
- ];
- $data['desc'] = input('desc2','') ? input('desc2','') : $data['desc'];
- $domain = config('app.ali_oss_bindurl');
- $search = 'https://'.$domain.'/';
- if($data['cover']) $data['cover'] = str_replace($search, '', $data['cover']);
-
- if($data['video_case']){
- $data['video_case'] = str_replace($search, '', $data['video_case']);
- $arr = explode(',',$data['video_case']);
- $data['video_case'] = end($arr);
- }
- SmartScreenData::where($where)->update($data);
- return json(['code' => 0,'data'=>'保存成功', 'msg' => '保存成功']);
- }
- /**
- * 删除一级标签
- */
- public function delCate1()
- {
- $root_id = request()->employee->root_id;
- $param = Request::only([ 'id' => 0]);
- $info = SmartScreenCate::where([['root_id','=',$root_id],['id','=',$param['id']]])->findOrEmpty();
- if($info->isEmpty()) return json(['code' => 1, 'data' => '参数错误', 'msg' => '参数错误']);
- $info->del = 1;
- $info->save();
- //
- $cate2 = SmartScreenCate::where('pid',$info->id)->select()->toArray();
- SmartScreenCate::where([['id|pid','in',array_column($cate2,'id')]])->update(['del'=>1]);
- return json(['code' => 0, 'data' => '删除成功', 'msg' => '删除成功']);
- }
- /**
- * 删除二级标签
- */
- public function delCate2()
- {
- $root_id = request()->employee->root_id;
- $param = Request::only([ 'id' => 0]);
- $info = SmartScreenCate::where([['root_id','=',$root_id],['id','=',$param['id']]])->findOrEmpty();
- if($info->isEmpty()) return json(['code' => 1, 'data' => '参数错误', 'msg' => '参数错误']);
- $info->del = 1;
- $info->save();
- //
- $cate2 = SmartScreenCate::where('pid',$info->id)->select()->toArray();
- return json(['code' => 0, 'data' => '删除成功', 'msg' => '删除成功']);
- }
- /**
- * 恢复默认
- */
- public function recovery()
- {
- $root_id = request()->employee->root_id;
- $param = Request::only([ 'type' => '']);
- $where = [
- ['root_id','=',$root_id],
- ['code','=',$param['type']]
- ];
- $title = $this->modular[$param['type']];
- $info = SmartScreenModel::where($where)->update(['background_img'=>'','lcon_img'=>'','title'=>$title]);
- return json(['code' => 0, 'data' => '恢复成功', 'msg' => '恢复成功']);
- }
-
- /**
- * 此方法用于从某个企业复制<谈单智慧屏>内容至另一个企业
- */
- public function copy_smart_screen($from_root_id = 0 , $new_root_id = 0)
- {
- if (!$from_root_id || !$new_root_id) return '错误';
- if ($from_root_id == $new_root_id) return '错误';
- $company = Company::where([['root_id','in',[$from_root_id,$new_root_id]]])->count();
- if($company != 2) return '错误';
-
- Db::startTrans();
- try {
- $cateArray = [];
- //一级
- $cate1 = SmartScreenCate::where(['root_id'=>$from_root_id , 'del'=>0 , 'pid'=>0 , 'level'=>1])->order('addtime')->select();
- foreach($cate1 as $item1){
- $new_cate1 = SmartScreenCate::insertGetId([
- 'root_id' => $new_root_id,
- 'title' => $item1['title'],
- 'code' => $item1['code'],
- 'pid' => 0,
- 'is_case' => $item1['is_case'],
- 'level' => 1,
- ]);
- $cateArray[$item1['id']] = $new_cate1;
- //二级
- $cate2 = SmartScreenCate::where(['root_id'=>$from_root_id , 'del'=>0 , 'pid'=>$item1['id'] , 'level'=>2])->order('addtime')->select();
- foreach($cate2 as $item2){
- $new_cate2 = SmartScreenCate::insertGetId([
- 'root_id' => $new_root_id,
- 'title' => $item2['title'],
- 'code' => $item2['code'],
- 'pid' => $new_cate1,
- 'is_case' => $item2['is_case'],
- 'level' => 2,
- ]);
- $cateArray[$item2['id']] = $new_cate2;
- //三级
- $cate3 = SmartScreenCate::where(['root_id'=>$from_root_id , 'del'=>0 , 'pid'=>$item2['id'] , 'level'=>3])->order('addtime')->select();
- foreach($cate3 as $item3){
- $new_cate3 = SmartScreenCate::insertGetId([
- 'root_id' => $new_root_id,
- 'title' => $item3['title'],
- 'code' => $item3['code'],
- 'pid' => $new_cate2,
- 'is_case' => $item3['is_case'],
- 'level' => 3,
- ]);
- $cateArray[$item3['id']] = $new_cate3;
- }
- }
- }
- //内容
- $data = SmartScreenData::where(['root_id'=>$from_root_id , 'del'=>0 ])->order('addtime')->column('*','id');
- $newData = [];
- foreach($data as $val){
- $arr['root_id'] = $new_root_id;
- $arr['cate1'] = isset($cateArray[$val['cate1']]) ? $cateArray[$val['cate1']] : '';
- $arr['cate2'] = isset($cateArray[$val['cate2']]) ? $cateArray[$val['cate2']] : '';
- $arr['cate3'] = isset($cateArray[$val['cate3']]) ? $cateArray[$val['cate3']] : '';
- $arr['title'] = $val['title'];
- $arr['pics'] = $val['pics'];
- $arr['cover'] = $val['cover'];
- $arr['desc'] = $val['desc'];
- $arr['real_case'] = $val['real_case'];
- $arr['vr_case'] = $val['vr_case'];
- $arr['video_case'] = $val['video_case'];
- $arr['video_format'] = $val['video_format'];
- $arr['difference'] = $val['difference'];
- $arr['type'] = $val['type'];
- $arr['square'] = $val['square'];
- $arr['money'] = $val['money'];
- $arr['square'] = $val['square'];
- $arr['square'] = $val['square'];
- $newData[] = $arr;
- }
- $screendata = new SmartScreenData;
- $screendata->saveAll($newData);
- //模块设置
- $screen = SmartScreenModel::where(['root_id'=>$from_root_id , 'del'=>0 ])->order('addtime')->column('*','id');
- $screenData = [];
- foreach($screen as $sc){
- $scArr['root_id'] = $new_root_id;
- $scArr['title'] = $sc['title'];
- $scArr['code'] = $sc['code'];
- $scArr['background_img'] = $sc['background_img'];
- $scArr['lcon_img'] = $sc['lcon_img'];
- $screenData[] = $scArr;
- }
- $screens = new SmartScreenModel;
- $screens->saveAll($screenData);
- Db::commit();
- return '复制成功';
- } catch (\Exception $e) {
- // 回滚事务
- Db::rollback();
- return '复制失败';
- }
- }
- /**
- * 智慧屏设置谈单有效时长
- */
- public function setValidMinutes(){
- $root_id = request()->employee->root_id;
- $minutes = input('minutes', 0, 'intval');
- $where = [
- ['name', '=', 'smartScreenValidMinutes'],
- ['root_id', '=', $root_id]
- ];
- $info = Setting::where($where)->findOrEmpty();
- if ($info->isEmpty()) {
- Setting::insert([
- 'name' => 'smartScreenValidMinutes',
- 'root_id' => $root_id,
- 'content' => $minutes
- ]);
- } else {
- $info->content = $minutes;
- $info->save();
- }
- return json(['code' => 0, 'data' => '保存成功', 'msg' => '保存成功']);
- }
- }
|