123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- <?php
- namespace app\sys\controller;
- use think\facade\View;
- use think\facade\Request;
- use app\logics\ToolLogic;
- use app\logics\ToolDecohelperLogic;
- use app\logics\ToolSettingsLogic;
- use app\model\ToolDecohelper;
- use app\model\ToolSettings;
- use app\model\Setting;
- class Tool extends Base
- {
- /**
- * 页面展示
- */
- public function __call($method, $argv)
- {
- return View::fetch($method);
- }
- /*
- * 装修风格测一测列表
- */
- public function styleTest()
- {
- if (!Request::isAjax()) {
- $type = (new ToolSettings())->getStyleTypeAttr();
- View::assign('type', $type);
- return View::fetch();
- }
- // $tool = ToolSettings::where(['tool_type' => 'styleTest', 'root_id' => request()->employee->root_id])->find();
- // $data = empty($tool) ? [] : (array)$tool->value;
- $type = '';
- $param = request()->param('type');
- if(!empty($param)) $type = $param;
- $data = ToolLogic::list($type);
- $data = array_reverse($data);
- return json(['code' => 0, 'data' => $data, 'count' => count($data)]);
- }
- /*
- * 装修风格测一测添加视图
- */
- public function styleTestAdd()
- {
- $type = (new ToolSettings())->getStyleTypeAttr();
- View::assign('type', $type);
- return View::fetch();
- }
- /*
- * 装修风格测一测保存
- */
- public function styleTestAddSave()
- {
- $data = Request::only(['type', 'img']);
- if (empty($data['img'])) return json(['code' => 1, 'msg' => '请选择图片']);
- $data['root_id'] = request()->employee->root_id;
- ToolLogic::styleTestAddSave($data);
- return json(['code' => 0, 'msg' => '添加成功']);
- }
- /**
- * 装修风格测一测修改
- */
- public function styleTestEdit($key)
- {
- $type = (new ToolSettings())->getStyleTypeAttr();
- $tool = ToolLogic::list();
- $data = empty($tool) ? [] : (array)$tool;
- View::assign('data', $data[$key]);
- View::assign('type', $type);
- return View::fetch();
- }
- /**
- * 装修风格测一测修改保存
- */
- public function styleTestEditSave()
- {
- $data = Request::only(['type', 'key', 'img']);
- $tool = ToolSettings::where(['tool_type' => 'styleTest', 'root_id' => request()->employee->root_id])->find();
- $setting = empty($tool) ? [] : json_decode($tool->getData('value'), true);
- if (empty($setting)) return json(['code' => 1, 'msg' => '修改失败']);
- $setting[$data['key']] = ['type' => $data['type'], 'img' => isset($data['img']) ? $data['img'] : $setting[$data['key']]['img']];
- $tool->value = json_encode($setting);
- $tool->save();
- return json(['code' => 0, 'msg' => '修改成功']);
- }
- /*
- * 删除测一测图
- */
- public function del($key)
- {
- $tool = ToolSettings::where(['tool_type' => 'styleTest', 'root_id' => request()->employee->root_id])->find();
- $setting = empty($tool) ? [] : json_decode($tool->getData('value'), true);
- if (empty($setting)) return json(['code' => 1, 'msg' => '删除失败']);
- unset($setting[$key]);
- $tool->value = json_encode($setting);
- $tool->save();
- return json(['code' => 0, 'msg' => '删除成功']);
- }
- /**
- * 装修助手
- */
- public function decohelper()
- {
- $tool = ToolSettings::where(['tool_type' => 'decoHelper', 'root_id' => request()->employee->root_id])->find();
- $datastr = empty($tool) ? [] : (array)$tool->getData('value');
- View::assign('datastr', json_encode($datastr));
- return View::fetch();
- }
- /**
- * 装修助手
- */
- public function decohelperlist()
- {
- $param = input();
- $condition = [];
- if (!empty($param['label'])) $condition[] = ['label', 'like', '%' . $param['label'] . '%'];
- if (!empty($param['title'])) $condition[] = ['title', 'like', '%' . $param['title'] . '%'];
- $data = ToolDecohelper::where($condition)->order('type,id')->select();
- return json(['code' => 0, 'data' => $data, 'count' => count($data)]);
- }
- /**
- * 装修助手结构及节点保存
- */
- public function decoStrucSave()
- {
- $param = input();
- $tool = ToolSettings::where(['tool_type' => 'decoHelper', 'root_id' => request()->employee->root_id])->find();
- if (empty($tool)) {
- $tool = new ToolSettings();
- $tool->root_id = request()->employee->root_id;
- $tool->tool_type = 'decoHelper';
- }
- $tool->value = $param['data'];
- $tool->save();
- return json(['code' => 0, 'msg' => '保存成功']);
- }
- /**
- * 装修助手添加页面
- */
- public function decoPostAdd()
- {
- $tool = ToolSettings::where(['tool_type' => 'decoHelper', 'root_id' => request()->employee->root_id])->find();
- View::assign('finalArr', $tool->value);
- View::assign('finalStr', json_encode($tool->value));
- return View::fetch();
- }
- /**
- * 装修助手修改保存
- */
- public function decoPostSave()
- {
- $param = input();
- $titleArr = explode('_', $param['endpoint']);
- $title = $titleArr[0];
- $savedata = [
- 'desc' => $param['desc'],
- 'content' => $param['content'],
- 'title' => $title,
- 'typepath' => $param['endpoint'],
- ];
- if (isset($param['img'])) $data['cover'] = $param['img'];
- if (isset($param['id'])) $data['id'] = $param['id'];
- $tdor = new ToolDecohelperLogic();
- if ($tdor->save($savedata)) {
- return json(['code' => 0, 'msg' => '保存成功']);
- } else {
- return json(['code' => 1, 'msg' => '保存失败']);
- }
- }
- /**
- * 装修助手编辑页面
- */
- public function decoPostEdit()
- {
- $title = input('key');
- $thepost = (new ToolDecohelperLogic())->getpost($title);
- View::assign('thepost', $thepost->toArray());
- $selectStr = $thepost->typepath;
- $selectArr = explode('_', $selectStr);
- $select_endor = $selectStr;
- $select_child = $selectArr[1] . '_' . $selectArr[2];
- $select_top = $selectArr[2];
- $select_middle = $selectArr[1];
- View::assign('select_middle', $select_middle);
- View::assign('select_top', $select_top);
- View::assign('select_child', $select_child);
- View::assign('select_endor', $select_endor);
- $datastr = (new ToolSettingsLogic())->decovalue();
- $dataArr = json_decode($datastr, true);
- $finalArr = [];
- foreach ($dataArr as $firstnode) {
- $finalArr[$firstnode['title']] = [];
- if (isset($firstnode['children'])) {
- foreach ($firstnode['children'] as $childnode) {
- $finalArr[$firstnode['title']][$childnode['title']] = [];
- if (isset($childnode['children'])) {
- foreach ($childnode['children'] as $endnode) {
- $finalArr[$firstnode['title']][$childnode['title']][] = $endnode['title'];
- }
- }
- }
- }
- }
- $finalStr = json_encode($finalArr);
- View::assign('finalArr', $finalArr);
- View::assign('finalStr', $finalStr);
- return View::fetch();
- }
- /*
- * 删除分类图
- */
- public function deco_del($id)
- {
- if ((new ToolDecohelperLogic())->delete($id)) {
- return json(['code' => 0, 'msg' => '删除成功']);
- } else {
- return json(['code' => 1, 'msg' => '删除失败']);
- }
- }
- /**
- * 装修报价页面
- */
- public function renovate_quotation()
- {
- $data = Request::only(['content'=>'', 'cover'=>'']);
- $domain = 'https://'.config('app.ali_oss_bindurl').'/';
- $check = Setting::where([['root_id','=',request()->employee->root_id],['name','=','renovate_quotation']])->find();
- if (!Request::isAjax()) {
- $content = $cover = '';
- if(!empty($check)){
- $set = json_decode($check['content'],true);
- $content = $set['content'];
- $cover = $domain.$set['cover'];
- }
- View::assign('content',$content);
- View::assign('cover',$cover);
- return View::fetch();
- }
- if(empty($check)){
- $add = [
- 'name'=>'renovate_quotation',
- 'content'=>json_encode(['cover'=>$data['cover'],'content'=>$data['content']]),
- 'root_id'=>request()->employee->root_id
- ];
- (new Setting())->create($add);
- }else{
- $check->content = json_encode(['cover'=>str_replace($domain,'',$data['cover']),'content'=>$data['content']]);
- $check->save();
- }
- return json(['code'=>0,'msg'=>'设置成功']);
- }
- }
|