Tool.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <?php
  2. namespace app\sys\controller;
  3. use think\facade\View;
  4. use think\facade\Request;
  5. use app\logics\ToolLogic;
  6. use app\logics\ToolDecohelperLogic;
  7. use app\logics\ToolSettingsLogic;
  8. use app\model\ToolDecohelper;
  9. use app\model\ToolSettings;
  10. use app\model\Setting;
  11. class Tool extends Base
  12. {
  13. /**
  14. * 页面展示
  15. */
  16. public function __call($method, $argv)
  17. {
  18. return View::fetch($method);
  19. }
  20. /*
  21. * 装修风格测一测列表
  22. */
  23. public function styleTest()
  24. {
  25. if (!Request::isAjax()) {
  26. $type = (new ToolSettings())->getStyleTypeAttr();
  27. View::assign('type', $type);
  28. return View::fetch();
  29. }
  30. // $tool = ToolSettings::where(['tool_type' => 'styleTest', 'root_id' => request()->employee->root_id])->find();
  31. // $data = empty($tool) ? [] : (array)$tool->value;
  32. $type = '';
  33. $param = request()->param('type');
  34. if(!empty($param)) $type = $param;
  35. $data = ToolLogic::list($type);
  36. $data = array_reverse($data);
  37. return json(['code' => 0, 'data' => $data, 'count' => count($data)]);
  38. }
  39. /*
  40. * 装修风格测一测添加视图
  41. */
  42. public function styleTestAdd()
  43. {
  44. $type = (new ToolSettings())->getStyleTypeAttr();
  45. View::assign('type', $type);
  46. return View::fetch();
  47. }
  48. /*
  49. * 装修风格测一测保存
  50. */
  51. public function styleTestAddSave()
  52. {
  53. $data = Request::only(['type', 'img']);
  54. if (empty($data['img'])) return json(['code' => 1, 'msg' => '请选择图片']);
  55. $data['root_id'] = request()->employee->root_id;
  56. ToolLogic::styleTestAddSave($data);
  57. return json(['code' => 0, 'msg' => '添加成功']);
  58. }
  59. /**
  60. * 装修风格测一测修改
  61. */
  62. public function styleTestEdit($key)
  63. {
  64. $type = (new ToolSettings())->getStyleTypeAttr();
  65. $tool = ToolLogic::list();
  66. $data = empty($tool) ? [] : (array)$tool;
  67. View::assign('data', $data[$key]);
  68. View::assign('type', $type);
  69. return View::fetch();
  70. }
  71. /**
  72. * 装修风格测一测修改保存
  73. */
  74. public function styleTestEditSave()
  75. {
  76. $data = Request::only(['type', 'key', 'img']);
  77. $tool = ToolSettings::where(['tool_type' => 'styleTest', 'root_id' => request()->employee->root_id])->find();
  78. $setting = empty($tool) ? [] : json_decode($tool->getData('value'), true);
  79. if (empty($setting)) return json(['code' => 1, 'msg' => '修改失败']);
  80. $setting[$data['key']] = ['type' => $data['type'], 'img' => isset($data['img']) ? $data['img'] : $setting[$data['key']]['img']];
  81. $tool->value = json_encode($setting);
  82. $tool->save();
  83. return json(['code' => 0, 'msg' => '修改成功']);
  84. }
  85. /*
  86. * 删除测一测图
  87. */
  88. public function del($key)
  89. {
  90. $tool = ToolSettings::where(['tool_type' => 'styleTest', 'root_id' => request()->employee->root_id])->find();
  91. $setting = empty($tool) ? [] : json_decode($tool->getData('value'), true);
  92. if (empty($setting)) return json(['code' => 1, 'msg' => '删除失败']);
  93. unset($setting[$key]);
  94. $tool->value = json_encode($setting);
  95. $tool->save();
  96. return json(['code' => 0, 'msg' => '删除成功']);
  97. }
  98. /**
  99. * 装修助手
  100. */
  101. public function decohelper()
  102. {
  103. $tool = ToolSettings::where(['tool_type' => 'decoHelper', 'root_id' => request()->employee->root_id])->find();
  104. $datastr = empty($tool) ? [] : (array)$tool->getData('value');
  105. View::assign('datastr', json_encode($datastr));
  106. return View::fetch();
  107. }
  108. /**
  109. * 装修助手
  110. */
  111. public function decohelperlist()
  112. {
  113. $param = input();
  114. $condition = [];
  115. if (!empty($param['label'])) $condition[] = ['label', 'like', '%' . $param['label'] . '%'];
  116. if (!empty($param['title'])) $condition[] = ['title', 'like', '%' . $param['title'] . '%'];
  117. $data = ToolDecohelper::where($condition)->order('type,id')->select();
  118. return json(['code' => 0, 'data' => $data, 'count' => count($data)]);
  119. }
  120. /**
  121. * 装修助手结构及节点保存
  122. */
  123. public function decoStrucSave()
  124. {
  125. $param = input();
  126. $tool = ToolSettings::where(['tool_type' => 'decoHelper', 'root_id' => request()->employee->root_id])->find();
  127. if (empty($tool)) {
  128. $tool = new ToolSettings();
  129. $tool->root_id = request()->employee->root_id;
  130. $tool->tool_type = 'decoHelper';
  131. }
  132. $tool->value = $param['data'];
  133. $tool->save();
  134. return json(['code' => 0, 'msg' => '保存成功']);
  135. }
  136. /**
  137. * 装修助手添加页面
  138. */
  139. public function decoPostAdd()
  140. {
  141. $tool = ToolSettings::where(['tool_type' => 'decoHelper', 'root_id' => request()->employee->root_id])->find();
  142. View::assign('finalArr', $tool->value);
  143. View::assign('finalStr', json_encode($tool->value));
  144. return View::fetch();
  145. }
  146. /**
  147. * 装修助手修改保存
  148. */
  149. public function decoPostSave()
  150. {
  151. $param = input();
  152. $titleArr = explode('_', $param['endpoint']);
  153. $title = $titleArr[0];
  154. $savedata = [
  155. 'desc' => $param['desc'],
  156. 'content' => $param['content'],
  157. 'title' => $title,
  158. 'typepath' => $param['endpoint'],
  159. ];
  160. if (isset($param['img'])) $data['cover'] = $param['img'];
  161. if (isset($param['id'])) $data['id'] = $param['id'];
  162. $tdor = new ToolDecohelperLogic();
  163. if ($tdor->save($savedata)) {
  164. return json(['code' => 0, 'msg' => '保存成功']);
  165. } else {
  166. return json(['code' => 1, 'msg' => '保存失败']);
  167. }
  168. }
  169. /**
  170. * 装修助手编辑页面
  171. */
  172. public function decoPostEdit()
  173. {
  174. $title = input('key');
  175. $thepost = (new ToolDecohelperLogic())->getpost($title);
  176. View::assign('thepost', $thepost->toArray());
  177. $selectStr = $thepost->typepath;
  178. $selectArr = explode('_', $selectStr);
  179. $select_endor = $selectStr;
  180. $select_child = $selectArr[1] . '_' . $selectArr[2];
  181. $select_top = $selectArr[2];
  182. $select_middle = $selectArr[1];
  183. View::assign('select_middle', $select_middle);
  184. View::assign('select_top', $select_top);
  185. View::assign('select_child', $select_child);
  186. View::assign('select_endor', $select_endor);
  187. $datastr = (new ToolSettingsLogic())->decovalue();
  188. $dataArr = json_decode($datastr, true);
  189. $finalArr = [];
  190. foreach ($dataArr as $firstnode) {
  191. $finalArr[$firstnode['title']] = [];
  192. if (isset($firstnode['children'])) {
  193. foreach ($firstnode['children'] as $childnode) {
  194. $finalArr[$firstnode['title']][$childnode['title']] = [];
  195. if (isset($childnode['children'])) {
  196. foreach ($childnode['children'] as $endnode) {
  197. $finalArr[$firstnode['title']][$childnode['title']][] = $endnode['title'];
  198. }
  199. }
  200. }
  201. }
  202. }
  203. $finalStr = json_encode($finalArr);
  204. View::assign('finalArr', $finalArr);
  205. View::assign('finalStr', $finalStr);
  206. return View::fetch();
  207. }
  208. /*
  209. * 删除分类图
  210. */
  211. public function deco_del($id)
  212. {
  213. if ((new ToolDecohelperLogic())->delete($id)) {
  214. return json(['code' => 0, 'msg' => '删除成功']);
  215. } else {
  216. return json(['code' => 1, 'msg' => '删除失败']);
  217. }
  218. }
  219. /**
  220. * 装修报价页面
  221. */
  222. public function renovate_quotation()
  223. {
  224. $data = Request::only(['content'=>'', 'cover'=>'']);
  225. $domain = 'https://'.config('app.ali_oss_bindurl').'/';
  226. $check = Setting::where([['root_id','=',request()->employee->root_id],['name','=','renovate_quotation']])->find();
  227. if (!Request::isAjax()) {
  228. $content = $cover = '';
  229. if(!empty($check)){
  230. $set = json_decode($check['content'],true);
  231. $content = $set['content'];
  232. $cover = $domain.$set['cover'];
  233. }
  234. View::assign('content',$content);
  235. View::assign('cover',$cover);
  236. return View::fetch();
  237. }
  238. if(empty($check)){
  239. $add = [
  240. 'name'=>'renovate_quotation',
  241. 'content'=>json_encode(['cover'=>$data['cover'],'content'=>$data['content']]),
  242. 'root_id'=>request()->employee->root_id
  243. ];
  244. (new Setting())->create($add);
  245. }else{
  246. $check->content = json_encode(['cover'=>str_replace($domain,'',$data['cover']),'content'=>$data['content']]);
  247. $check->save();
  248. }
  249. return json(['code'=>0,'msg'=>'设置成功']);
  250. }
  251. }