is_open; $is_customize = request()->is_customize; $customize_url = request()->customize_url; if ($data) { $set['is_open'] = $data; $set['is_customize'] = $is_customize; $set['customize_url'] = $customize_url; \Setting::set('official_website.theme_set',$set); } return $this->successJson('',$set); } public function createTheme() { $data = request()->data; if (empty($data)) { return $this->errorJson("数据为空"); } $validate = $this->validate($this->rules(), $data, $this->message()); if ($validate) { return $validate; } $official = new OfficialWebsiteTheme(); $official->title = $data['title']; $official->is_default = $data['is_default']; if ($data['is_default'] == 1) { OfficialWebsiteTheme::where("is_default",1)->update(["is_default"=>0]); } if ($official->save()) { return $this->successJson('成功'); } else { return $this->errorJson('失败'); } } public function themeList() { $list = OfficialWebsiteTheme::orderBy('id','desc')->paginate(10); return $this->successJson("",$list); } public function editTheme() { $data = request()->data; $status = request()->status; $id = request()->id; if (empty($id) || empty($status)) { return $this->errorJson('参数不存在'); } if (empty($data)) { $theme = OfficialWebsiteTheme::where("id",$id)->first(); $theme = empty($theme) ? [] : $theme->toArray(); //解压数据 $theme_data = $this->processData($status,$theme); $theme_data['identification'] = $theme['identification']; $theme_data['uniAccount'] = UniAccount::select("uniacid","name")->get(); } else { //保存 $rel = $this->saveData($status,$data,$id); if ($rel == true) { return $this->successJson('成功'); } else { return $this->errorJson('失败'); } } return $this->successJson('',$theme_data); } public function processData($status,$data) { $result = []; if (empty($data)) { return $result; } if ($status == 1) { $result = !empty($data['basic']) ? json_decode($data['basic'],true) : []; if (isset($result['cus_url'])) { $result['cus_url'] = $result['cus_url']; } } elseif ($status == 2) { $result = !empty($data['top']) ? json_decode($data['top'],true) : []; if ($result['logo']) { $result['logo'] = $result['logo']; } } elseif ($status == 3) { if ($data['tail']) { $result['bottom'] = htmlspecialchars_decode($data['tail']); } } return $result; } public function saveData($status,$data,$id=0) { if (empty($id)) { $official = new OfficialWebsiteTheme(); } else { $official = OfficialWebsiteTheme::where("id",$id)->first(); } if ($status == 1) { $data = json_encode($data); $official->basic = $data; } elseif ($status == 2) { $data = json_encode($data); $official->top = $data; } elseif ($status == 3) { $data = htmlspecialchars($data['bottom']); $official->tail = $data; } elseif ($status == 4) { if ($data['is_default'] == 1) { OfficialWebsiteTheme::where("id",">",0)->update(["is_default"=>0]); } $official->is_default = $data['is_default']; } if ($official->save()) { return true; } else { return false; } } public function dentList() { $theme = request()->theme_id; $theme = empty($theme) ? "" : $theme; $all_multiple = OfficialWebsiteMultiple::where("theme_id",$theme)->select("id","theme_id","name","identification")->get(); $all_multiple = empty($all_multiple) ? [] : $all_multiple->toArray(); return $this->successJson("",$all_multiple); } public function multipleList() { $data = request()->data; $theme_id = request()->theme_id; $theme_id = empty($theme_id) ? 0 : $theme_id; if (empty($theme_id) || !is_numeric($theme_id)) { return $this->errorJson("主题ID不能为空且必须为数字"); } $theme_set = OfficialWebsiteTheme::where("id",$theme_id)->first(); $identification = request()->identification; $identification = empty($identification) ? "" : $identification; if (!preg_match("/[a-zA-Z0-9_]{1,15}/",$identification)) { return $this->errorJson("路径名称只能是字母、数字、下划线且长度不超过15"); } $multiple = []; if ($identification) { $multiple = OfficialWebsiteMultiple::where("theme_id",$theme_id)->where("identification",$identification)->first(); $multiple = empty($multiple) ? [] : $multiple->toArray(); if (isset($multiple['detail'])) { $multiple['detail'] = htmlspecialchars_decode($multiple['detail']); } $all_multiple = OfficialWebsiteMultiple::where("theme_id",$theme_id)->select("id","theme_id","name","identification")->get(); $all_multiple = empty($all_multiple) ? [] : $all_multiple->toArray(); $multiple['all_multiple'] = $all_multiple; } if ($data) { $repeat = OfficialWebsiteMultiple::where("identification",$identification)->where("theme_id",$theme_id)->first(); if ($repeat) { $official = $repeat; } else { $official = new OfficialWebsiteMultiple(); } $data['url'] = "https://".$_SERVER['HTTP_HOST']."/officialwebsite.php?page_name=".$identification; $validate = $this->validate($this->rules(), $data, $this->message()); if ($validate) { return $validate; } $article = ""; $help = ""; if ($identification == "resource_page") { $basic = empty($theme_set) ? [] : json_decode($theme_set['basic'],true); $cus_uniacid = empty($basic['cus_uniacid']) ? 0 : $basic['cus_uniacid']; if (app('plugins')->isEnabled('article')) { $article = Category::where("uniacid",$cus_uniacid)->with(["hasManyArticle"=>function ($query){ $query->select("id","category_id","title","desc","thumb","author","created_at","content")->where('state', 1)->where('type', '!=', 1)->orderBy("id","DESC")->offset(0)->limit(15); }])->get(); $article = empty($article) ? "" : json_encode($article->toArray()); } if (app('plugins')->isEnabled('help-center')) { $help = HelpCenterAddModel::where("uniacid",$cus_uniacid)->select('title', 'content')->orderBy('sort')->offset(0)->limit(25)->get(); $help = empty($help) ? "" : json_encode($help->toArray()); } } $official->theme_id = $theme_id; $official->name = $data['name']; $official->identification = $identification; $official->mul_title = $data['mul_title']; $official->url = $data['url']; $official->keyword = $data['keyword']; $official->describe = $data['describe']; $official->detail = htmlspecialchars($data['detail']); $official->article = $article; $official->helper = $help; if ($official->save()) { if ($theme_set['identification'] == "common") { if (!file_exists(base_path("/official/".$theme_set['identification']."/" . $identification . ".html"))) { $room = '