themeService = new ThemeService(); } /** * 获取模板列表(后台管理) * @return \think\response\Json */ public function index() { $tid = $this->getTenantId(); $themes = $this->themeService->getThemeList(); $currentTheme = $this->themeService->getCurrentTheme($tid); $theme_useing = TemplateSiteConfig::where('tid', $tid) ->where('key', 'current_theme') ->value('value'); return json([ 'code' => 200, 'msg' => 'success', 'data' => [ 'list' => $themes, 'currentTheme' => $currentTheme ] ]); } /** * 切换模板 * @return \think\response\Json */ public function switch() { $tid = Request::post('tid', 0, 'int'); $themeKey = Request::post('theme_key', ''); if (empty($tid) || $tid == 0) { return json([ 'code' => 401, 'msg' => '未获取到租户ID,请先选择租户' ]); } if (empty($themeKey)) { return json([ 'code' => 400, 'msg' => '模板标识不能为空' ]); } $result = $this->themeService->switchTheme($tid, $themeKey); if ($result) { return json([ 'code' => 200, 'msg' => '切换成功' ]); } return json([ 'code' => 400, 'msg' => '切换失败,模板不存在' ]); } /** * 获取模板字段数据 * @return \think\response\Json */ public function getData() { $tid = Request::get('tid', 0, 'int'); $themeKey = Request::get('theme_key', ''); $themeData = $this->themeService->getThemeData($tid, $themeKey ?: null); return json([ 'code' => 200, 'msg' => 'success', 'data' => $themeData ]); } /** * 保存模板字段数据 * @return \think\response\Json */ public function saveData() { $tid = Request::post('tid', 0, 'int'); $themeKey = Request::post('theme_key', ''); $fieldKey = Request::post('field_key', ''); $fieldValue = Request::post('field_value', ''); if (empty($themeKey) || empty($fieldKey)) { return json([ 'code' => 400, 'msg' => '参数不完整' ]); } $result = $this->themeService->saveThemeField($tid, $themeKey, $fieldKey, $fieldValue); if ($result) { return json([ 'code' => 200, 'msg' => '保存成功' ]); } return json([ 'code' => 400, 'msg' => '保存失败' ]); } }