正在显示
12 个修改的文件
包含
399 行增加
和
47 行删除
| @@ -44,19 +44,11 @@ class Demo extends Command | @@ -44,19 +44,11 @@ class Demo extends Command | ||
| 44 | */ | 44 | */ |
| 45 | public function handle() | 45 | public function handle() |
| 46 | { | 46 | { |
| 47 | - //切换数据库配置 | ||
| 48 | - $project = ProjectServer::useProject(1); | ||
| 49 | - //创建数据库 | ||
| 50 | - ProjectServer::createDatabase($project); | ||
| 51 | - //创建表 | ||
| 52 | - ProjectServer::initTable($project); | 47 | + preg_match_all("/\@include\(\"([a-z0-9_]+)\"\)/i",' |
| 48 | +@include("asdf")@include("")@include("asdtrw2erf") | ||
| 49 | + ',$include); | ||
| 53 | 50 | ||
| 54 | - dd(1); | ||
| 55 | - | ||
| 56 | - $sql = 'CREATE DATABASE database_name;'; | ||
| 57 | - $results = DB::select($sql); | ||
| 58 | - dd($results); | ||
| 59 | - return true; | 51 | + print_r($include); |
| 60 | } | 52 | } |
| 61 | 53 | ||
| 62 | public function printMessage() | 54 | public function printMessage() |
| @@ -97,4 +89,4 @@ class Demo extends Command | @@ -97,4 +89,4 @@ class Demo extends Command | ||
| 97 | } | 89 | } |
| 98 | dd(1); | 90 | dd(1); |
| 99 | } | 91 | } |
| 100 | -} | ||
| 92 | +} |
| @@ -2,7 +2,10 @@ | @@ -2,7 +2,10 @@ | ||
| 2 | 2 | ||
| 3 | namespace App\Http\Controllers\Aside; | 3 | namespace App\Http\Controllers\Aside; |
| 4 | 4 | ||
| 5 | +use App\Enums\Common\Code; | ||
| 6 | +use App\Models\Template\ATemplate; | ||
| 5 | use App\Models\Template\ATemplateHtml; | 7 | use App\Models\Template\ATemplateHtml; |
| 8 | +use Illuminate\Validation\Rule; | ||
| 6 | 9 | ||
| 7 | /** | 10 | /** |
| 8 | * 模板 | 11 | * 模板 |
| @@ -22,9 +25,22 @@ class TemplateController extends BaseController | @@ -22,9 +25,22 @@ class TemplateController extends BaseController | ||
| 22 | */ | 25 | */ |
| 23 | public function index(){ | 26 | public function index(){ |
| 24 | 27 | ||
| 28 | + $limit = $this->param['limit']??20; | ||
| 25 | 29 | ||
| 26 | 30 | ||
| 27 | - return view('a'); | 31 | + $lists = ATemplate::where(function ($query){ |
| 32 | + | ||
| 33 | + !empty($this->param['status']) && $query->where('status',$this->param['status']); | ||
| 34 | + !empty($this->param['name']) && $query->where('status',$this->param['name']); | ||
| 35 | + | ||
| 36 | + | ||
| 37 | + }) | ||
| 38 | + ->select(['id','name','status','is_default','sort','thumb','url','created_at','updated_at']) | ||
| 39 | + ->orderBy('sort') | ||
| 40 | + ->paginate($limit); | ||
| 41 | + | ||
| 42 | + | ||
| 43 | + return $this->success($lists->toArray()); | ||
| 28 | } | 44 | } |
| 29 | 45 | ||
| 30 | 46 | ||
| @@ -34,7 +50,7 @@ class TemplateController extends BaseController | @@ -34,7 +50,7 @@ class TemplateController extends BaseController | ||
| 34 | * @time 2023/5/4 16:19 | 50 | * @time 2023/5/4 16:19 |
| 35 | */ | 51 | */ |
| 36 | public function edit(){ | 52 | public function edit(){ |
| 37 | - | 53 | + $this->save(true); |
| 38 | } | 54 | } |
| 39 | 55 | ||
| 40 | /** | 56 | /** |
| @@ -43,12 +59,168 @@ class TemplateController extends BaseController | @@ -43,12 +59,168 @@ class TemplateController extends BaseController | ||
| 43 | * @time 2023/5/5 9:30 | 59 | * @time 2023/5/5 9:30 |
| 44 | */ | 60 | */ |
| 45 | public function insert(){ | 61 | public function insert(){ |
| 62 | + $this->save(); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + | ||
| 66 | + /** | ||
| 67 | + * @param false $is_edit | ||
| 68 | + * @return \Illuminate\Http\JsonResponse | ||
| 69 | + * @throws \Illuminate\Validation\ValidationException | ||
| 70 | + * @throws \Psr\Container\ContainerExceptionInterface | ||
| 71 | + * @throws \Psr\Container\NotFoundExceptionInterface | ||
| 72 | + * @author:dc | ||
| 73 | + * @time 2023/5/11 10:13 | ||
| 74 | + */ | ||
| 75 | + private function save($is_edit=false){ | ||
| 76 | + | ||
| 77 | + $verify = [ | ||
| 78 | + 'role' => [ | ||
| 79 | + 'id' => ['required','integer'], | ||
| 80 | + 'name' => ['required'], | ||
| 81 | + 'status' => ['required',Rule::in(0,1)], | ||
| 82 | + 'is_default' => ['required',Rule::in(0,1)], | ||
| 83 | + 'sort' => ['required','integer'], | ||
| 84 | + 'thumb' => ['required'], | ||
| 85 | + 'url' => ['required'], | ||
| 86 | + ], | ||
| 87 | + 'message' => [ | ||
| 88 | + 'id.required' => 'id必须', | ||
| 89 | + 'id.integer' => 'id必须', | ||
| 90 | + | ||
| 91 | + 'name.required' => '名称必须', | ||
| 92 | + 'status.integer' => '状态错误', | ||
| 93 | + 'status.in' => '状态错误', | ||
| 94 | + 'is_default.integer' => '是否默认', | ||
| 95 | + 'is_default.in' => '是否默认', | ||
| 96 | + 'sort.required' => '排序必须', | ||
| 97 | + 'sort.integer' => '排序必须', | ||
| 98 | + 'thumb.required' => '缩略图必须', | ||
| 99 | + 'url.required' => '预览链接必须', | ||
| 100 | + ] | ||
| 101 | + ]; | ||
| 102 | + if(!$is_edit) unset($verify['role']['id']); | ||
| 103 | + | ||
| 104 | + $data = $this->validate(request() ,$verify['role'],$verify['message']); | ||
| 105 | + | ||
| 106 | + | ||
| 107 | + | ||
| 108 | + // 保存 | ||
| 109 | + $id = ATemplate::_save($data,$data['id']??0); | ||
| 110 | + | ||
| 111 | + if(!$id){ | ||
| 112 | + return $this->response('保存失败',Code::SYSTEM_ERROR); | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + return $this->success(ATemplate::_find($id)); | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + | ||
| 119 | + /** | ||
| 120 | + * 删除 | ||
| 121 | + * @author:dc | ||
| 122 | + * @time 2023/5/4 17:10 | ||
| 123 | + */ | ||
| 124 | + public function delete($id){ | ||
| 125 | + | ||
| 126 | + if(ATemplate::destroy($id)){ | ||
| 127 | + return $this->response('删除成功'); | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + return $this->response('删除失败',Code::SYSTEM_ERROR); | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + | ||
| 134 | + | ||
| 135 | + | ||
| 136 | + | ||
| 137 | + | ||
| 138 | + /** | ||
| 139 | + * 列表 | ||
| 140 | + * @author:dc | ||
| 141 | + * @time 2023/5/4 17:10 | ||
| 142 | + */ | ||
| 143 | + public function html_index($template_id){ | ||
| 144 | + | ||
| 145 | + | ||
| 146 | + $lists = ATemplateHtml::where('template_id',$template_id)->get(); | ||
| 147 | + | ||
| 148 | + | ||
| 149 | + return $this->success($lists->toArray()); | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + | ||
| 153 | + /** | ||
| 154 | + * 编辑 | ||
| 155 | + * @author:dc | ||
| 156 | + * @time 2023/5/4 16:19 | ||
| 157 | + */ | ||
| 158 | + public function html_edit($template_id){ | ||
| 159 | + $this->html_save($template_id,true); | ||
| 160 | + } | ||
| 46 | 161 | ||
| 162 | + /** | ||
| 163 | + * 新增 | ||
| 164 | + * @author:dc | ||
| 165 | + * @time 2023/5/5 9:30 | ||
| 166 | + */ | ||
| 167 | + public function html_insert($template_id){ | ||
| 168 | + $this->html_save($template_id); | ||
| 47 | } | 169 | } |
| 48 | 170 | ||
| 49 | 171 | ||
| 50 | - private function save($name = ''){ | 172 | + /** |
| 173 | + * @param false $is_edit | ||
| 174 | + * @return \Illuminate\Http\JsonResponse | ||
| 175 | + * @throws \Illuminate\Validation\ValidationException | ||
| 176 | + * @throws \Psr\Container\ContainerExceptionInterface | ||
| 177 | + * @throws \Psr\Container\NotFoundExceptionInterface | ||
| 178 | + * @author:dc | ||
| 179 | + * @time 2023/5/11 10:13 | ||
| 180 | + */ | ||
| 181 | + private function html_save($template_id,$is_edit=false){ | ||
| 182 | + | ||
| 183 | + $verify = [ | ||
| 184 | + 'role' => [ | ||
| 185 | + 'id' => ['required','integer'], | ||
| 186 | +// 'template_id' => ['required','integer'], | ||
| 187 | + 'name' => ['required'], | ||
| 188 | + 'type' => ['required',Rule::in(ATemplateHtml::$typeMap)], | ||
| 189 | + 'css' => [], | ||
| 190 | + 'script' => [], | ||
| 191 | + 'html' => ['required'], | ||
| 192 | + ], | ||
| 193 | + 'message' => [ | ||
| 194 | + 'id.required' => 'id必须', | ||
| 195 | + 'id.integer' => 'id必须', | ||
| 196 | + | ||
| 197 | +// 'template_id.required' => '模板选择错误', | ||
| 198 | +// 'template_id.integer' => '模板选择错误', | ||
| 199 | + | ||
| 200 | + 'name.required' => '名称必须', | ||
| 201 | + | ||
| 202 | + 'type.required' => '页面类型选择错误', | ||
| 203 | + 'type.in' => '页面类型选择错误', | ||
| 204 | + | ||
| 205 | + | ||
| 206 | + 'html.required' => 'html 代码必须', | ||
| 207 | + | ||
| 208 | + ] | ||
| 209 | + ]; | ||
| 210 | + if(!$is_edit) unset($verify['role']['id']); | ||
| 51 | 211 | ||
| 212 | + $data = $this->validate(request() ,$verify['role'],$verify['message']); | ||
| 213 | + | ||
| 214 | + | ||
| 215 | + | ||
| 216 | + // 保存 | ||
| 217 | + $id = ATemplateHtml::_save($template_id,$data,$data['id']??0); | ||
| 218 | + | ||
| 219 | + if(!$id){ | ||
| 220 | + return $this->response('保存失败',Code::SYSTEM_ERROR); | ||
| 221 | + } | ||
| 222 | + | ||
| 223 | + return $this->success(ATemplateHtml::_find($id)); | ||
| 52 | } | 224 | } |
| 53 | 225 | ||
| 54 | 226 | ||
| @@ -57,12 +229,28 @@ class TemplateController extends BaseController | @@ -57,12 +229,28 @@ class TemplateController extends BaseController | ||
| 57 | * @author:dc | 229 | * @author:dc |
| 58 | * @time 2023/5/4 17:10 | 230 | * @time 2023/5/4 17:10 |
| 59 | */ | 231 | */ |
| 60 | - public function delete(){ | 232 | + public function html_delete($template_id, $id){ |
| 61 | 233 | ||
| 234 | + if(ATemplateHtml::where('template_id',$template_id)->where('id',$id)->delete()){ | ||
| 235 | + return $this->response('删除成功'); | ||
| 236 | + } | ||
| 62 | 237 | ||
| 238 | + return $this->response('删除失败',Code::SYSTEM_ERROR); | ||
| 63 | } | 239 | } |
| 64 | 240 | ||
| 65 | 241 | ||
| 242 | + /** | ||
| 243 | + * 页面类型 | ||
| 244 | + * @return \Illuminate\Http\JsonResponse | ||
| 245 | + * @throws \Psr\Container\ContainerExceptionInterface | ||
| 246 | + * @throws \Psr\Container\NotFoundExceptionInterface | ||
| 247 | + * @author:dc | ||
| 248 | + * @time 2023/5/11 10:29 | ||
| 249 | + */ | ||
| 250 | + public function html_type(){ | ||
| 251 | + return $this->success(ATemplateHtml::$typeMap); | ||
| 252 | + } | ||
| 253 | + | ||
| 66 | 254 | ||
| 67 | 255 | ||
| 68 | 256 |
| @@ -101,12 +101,21 @@ class BaseController extends Controller | @@ -101,12 +101,21 @@ class BaseController extends Controller | ||
| 101 | */ | 101 | */ |
| 102 | public function response($msg = null,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'): JsonResponse | 102 | public function response($msg = null,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'): JsonResponse |
| 103 | { | 103 | { |
| 104 | - $code = Code::fromValue($code); | ||
| 105 | - $result = [ | ||
| 106 | - 'msg' => $msg == ' ' ? $code->description : $msg, | ||
| 107 | - 'code' => $code->value, | ||
| 108 | - 'data' => $this->_extents($data), | ||
| 109 | - ]; | 104 | + try { |
| 105 | + $code = Code::fromValue($code); | ||
| 106 | + $result = [ | ||
| 107 | + 'msg' => $msg == ' ' ? $code->description : $msg, | ||
| 108 | + 'code' => $code->value, | ||
| 109 | + 'data' => $this->_extents($data), | ||
| 110 | + ]; | ||
| 111 | + }catch (\Throwable $e){ | ||
| 112 | + $result = [ | ||
| 113 | + 'msg' => $msg, | ||
| 114 | + 'code' => $code, | ||
| 115 | + 'data' => $this->_extents($data), | ||
| 116 | + ]; | ||
| 117 | + } | ||
| 118 | + | ||
| 110 | $this->header['Content-Type'] = $type; | 119 | $this->header['Content-Type'] = $type; |
| 111 | $this->header['token'] = $this->token; | 120 | $this->header['token'] = $this->token; |
| 112 | $response = response($result,$result_code,$this->header);; | 121 | $response = response($result,$result_code,$this->header);; |
| @@ -189,7 +189,7 @@ class NavController extends BaseController | @@ -189,7 +189,7 @@ class NavController extends BaseController | ||
| 189 | 'name' => '单页' | 189 | 'name' => '单页' |
| 190 | ], | 190 | ], |
| 191 | [ | 191 | [ |
| 192 | - 'url' => 'goods', | 192 | + 'url' => '/goods', |
| 193 | 'name' => '商品' | 193 | 'name' => '商品' |
| 194 | ], | 194 | ], |
| 195 | ]); | 195 | ]); |
| @@ -3,9 +3,12 @@ | @@ -3,9 +3,12 @@ | ||
| 3 | namespace App\Http\Controllers\Bside; | 3 | namespace App\Http\Controllers\Bside; |
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | +use App\Enums\Common\Code; | ||
| 6 | use App\Models\Template\ATemplate; | 7 | use App\Models\Template\ATemplate; |
| 8 | +use App\Models\Template\ATemplateHtml; | ||
| 7 | use App\Models\Template\BSetting; | 9 | use App\Models\Template\BSetting; |
| 8 | use App\Models\Template\BTemplateData; | 10 | use App\Models\Template\BTemplateData; |
| 11 | +use Illuminate\Validation\Rule; | ||
| 9 | 12 | ||
| 10 | 13 | ||
| 11 | /** | 14 | /** |
| @@ -93,6 +96,29 @@ class TemplateController extends BaseController | @@ -93,6 +96,29 @@ class TemplateController extends BaseController | ||
| 93 | 96 | ||
| 94 | } | 97 | } |
| 95 | 98 | ||
| 99 | + /** | ||
| 100 | + * 获取 编辑html | ||
| 101 | + * @author:dc | ||
| 102 | + * @time 2023/5/11 9:33 | ||
| 103 | + */ | ||
| 104 | + public function get_html(){ | ||
| 105 | + $source = $this->param['source']??''; | ||
| 106 | + $source_id = $this->param['source_id']??0; | ||
| 107 | + | ||
| 108 | + $sourceMap = [ | ||
| 109 | + // 数据表/数据类型 =》 模板类型/模板名称 | ||
| 110 | + 'index' => 'index', | ||
| 111 | + 'product' => 'product', | ||
| 112 | + 'product_info' => 'product_info', | ||
| 113 | + 'blogs' => 'blogs', | ||
| 114 | + 'blogs_info' => 'blogs_info', | ||
| 115 | + 'page' => 'page', | ||
| 116 | + ]; | ||
| 117 | + | ||
| 118 | + return $this->success(); | ||
| 119 | + | ||
| 120 | + } | ||
| 121 | + | ||
| 96 | 122 | ||
| 97 | /** | 123 | /** |
| 98 | * 自定义块 | 124 | * 自定义块 |
| @@ -102,14 +128,33 @@ class TemplateController extends BaseController | @@ -102,14 +128,33 @@ class TemplateController extends BaseController | ||
| 102 | public function customChunk(){ | 128 | public function customChunk(){ |
| 103 | 129 | ||
| 104 | $html = $this->param['html']??[]; | 130 | $html = $this->param['html']??[]; |
| 131 | + // 那个页面 的 | ||
| 132 | + $type = $this->param['type']??''; | ||
| 133 | + | ||
| 105 | if(!is_array($html)){ | 134 | if(!is_array($html)){ |
| 106 | return $this->response('参数异常','B_CUSTOM_CHUNK_PARAMS'); | 135 | return $this->response('参数异常','B_CUSTOM_CHUNK_PARAMS'); |
| 107 | } | 136 | } |
| 108 | 137 | ||
| 138 | + // 项目id | ||
| 139 | + $project_id = $this->user['project_id']; | ||
| 140 | + // 当前模板 | ||
| 141 | + $template_id = BSetting::_get($project_id)['template_id']; | ||
| 142 | + | ||
| 143 | + // 验证这个模板是否存在 | ||
| 144 | + if(!$type || !ATemplateHtml::_typeExist($template_id,$type)){ | ||
| 145 | + return $this->response('页面类型错误','B_CUSTOM_CHUNK_PARAMS_TYPE'); | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + | ||
| 149 | + $html = view("template.{$template_id}.{$type}")->render(); | ||
| 150 | + | ||
| 151 | + | ||
| 152 | + return $this->response('',Code::SUCCESS,$html); | ||
| 153 | +// $data = BTemplateData::_insert(); | ||
| 154 | + | ||
| 109 | 155 | ||
| 110 | 156 | ||
| 111 | 157 | ||
| 112 | - $data = BTemplateData::_insert(); | ||
| 113 | } | 158 | } |
| 114 | 159 | ||
| 115 | 160 |
| @@ -94,6 +94,30 @@ class ATemplate extends \App\Models\Base{ | @@ -94,6 +94,30 @@ class ATemplate extends \App\Models\Base{ | ||
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | 96 | ||
| 97 | + /** | ||
| 98 | + * @param array $data | ||
| 99 | + * @param int $id | ||
| 100 | + * @author:dc | ||
| 101 | + * @time 2023/5/11 10:08 | ||
| 102 | + */ | ||
| 103 | + public static function _save(array $data,int $id=0){ | ||
| 104 | + if($id){ | ||
| 105 | + $model = static::where('id',$id)->first(); | ||
| 106 | + } | ||
| 107 | + if(empty($model)) $model = new static(); | ||
| 108 | + | ||
| 109 | + $model->name = $data['name']; | ||
| 110 | + $model->status = $data['status']; | ||
| 111 | + $model->is_default = $data['is_default']; | ||
| 112 | + $model->sort = $data['sort']; | ||
| 113 | + $model->thumb = $data['thumb']; | ||
| 114 | + $model->url = $data['url']; | ||
| 115 | + | ||
| 116 | + $model->save(); | ||
| 117 | + | ||
| 118 | + return $model->id; | ||
| 119 | + } | ||
| 120 | + | ||
| 97 | 121 | ||
| 98 | 122 | ||
| 99 | } | 123 | } |
| @@ -24,6 +24,28 @@ class ATemplateHtml extends \App\Models\Base{ | @@ -24,6 +24,28 @@ class ATemplateHtml extends \App\Models\Base{ | ||
| 24 | use SoftDeletes; | 24 | use SoftDeletes; |
| 25 | 25 | ||
| 26 | 26 | ||
| 27 | + public static $sourceMap = [ | ||
| 28 | + // 数据表/数据类型 =》 模板类型/模板名称 | ||
| 29 | + 'index' => 'index', | ||
| 30 | + 'product' => 'product', | ||
| 31 | + 'product_info' => 'product_info', | ||
| 32 | + 'blogs' => 'blogs', | ||
| 33 | + 'blogs_info' => 'blogs_info', | ||
| 34 | + 'page' => 'page', | ||
| 35 | + ]; | ||
| 36 | + | ||
| 37 | + public static $typeMap = [ | ||
| 38 | + 'index' => '首页', | ||
| 39 | + 'product' => '商品列表', | ||
| 40 | + 'product_info' => '商品详情', | ||
| 41 | + 'blogs' => '博客', | ||
| 42 | + 'blogs_info' => '博客详情', | ||
| 43 | + 'page' => '单页', | ||
| 44 | + 'news' => '新闻列表', | ||
| 45 | + 'news_info' => '新闻详情', | ||
| 46 | + ]; | ||
| 47 | + | ||
| 48 | + | ||
| 27 | /** | 49 | /** |
| 28 | * 模板中的数据 | 50 | * 模板中的数据 |
| 29 | * @param $template_id | 51 | * @param $template_id |
| @@ -36,4 +58,57 @@ class ATemplateHtml extends \App\Models\Base{ | @@ -36,4 +58,57 @@ class ATemplateHtml extends \App\Models\Base{ | ||
| 36 | } | 58 | } |
| 37 | 59 | ||
| 38 | 60 | ||
| 61 | + /** | ||
| 62 | + * 是否存在type | ||
| 63 | + * @param int $template_id | ||
| 64 | + * @param $type | ||
| 65 | + * @return mixed | ||
| 66 | + * @author:dc | ||
| 67 | + * @time 2023/5/10 16:03 | ||
| 68 | + */ | ||
| 69 | + public static function _typeExist(int $template_id,$type){ | ||
| 70 | + return static::where(['template_id'=>$template_id,'type'=>$type])->limit(1)->count(); | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + | ||
| 74 | + public static function _bAll($template_id){ | ||
| 75 | + return static::where(['template_id'=>$template_id,'status'=>1])->get(); | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + | ||
| 79 | + public static function _find($id){ | ||
| 80 | + return static::where('id',$id)->first(); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + /** | ||
| 84 | + * @param array $data | ||
| 85 | + * @param int $id | ||
| 86 | + * @return mixed | ||
| 87 | + * @author:dc | ||
| 88 | + * @time 2023/5/11 10:20 | ||
| 89 | + */ | ||
| 90 | + public static function _save(int $template_id, array $data,int $id = 0){ | ||
| 91 | + if($id){ | ||
| 92 | + $model = static::where('id',$id)->first(); | ||
| 93 | + } | ||
| 94 | + if(empty($model)) $model = new static(); | ||
| 95 | + | ||
| 96 | + $model->template_id = $template_id; | ||
| 97 | + | ||
| 98 | + $model->name = $data['name']; | ||
| 99 | + $model->status = $data['status']; | ||
| 100 | + $model->is_default = $data['is_default']; | ||
| 101 | + $model->sort = $data['sort']; | ||
| 102 | + $model->thumb = $data['thumb']; | ||
| 103 | + $model->url = $data['url']; | ||
| 104 | + | ||
| 105 | + $model->save(); | ||
| 106 | + | ||
| 107 | + return $model->id; | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + | ||
| 111 | + | ||
| 112 | + | ||
| 113 | + | ||
| 39 | } | 114 | } |
| @@ -21,29 +21,37 @@ class BTemplateData extends \App\Models\Base{ | @@ -21,29 +21,37 @@ class BTemplateData extends \App\Models\Base{ | ||
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | /** | 23 | /** |
| 24 | - * 插入 | ||
| 25 | - * @param $project_id | ||
| 26 | - * @param $data | 24 | + * 插入/修改 |
| 25 | + * @param int $project_id | ||
| 26 | + * @param array $data | ||
| 27 | * @return mixed | 27 | * @return mixed |
| 28 | * @author:dc | 28 | * @author:dc |
| 29 | * @time 2023/5/10 10:23 | 29 | * @time 2023/5/10 10:23 |
| 30 | */ | 30 | */ |
| 31 | - public static function _insert($project_id,$data) | 31 | + public static function _save(int $project_id, array $data) |
| 32 | { | 32 | { |
| 33 | 33 | ||
| 34 | - $model = new static(); | ||
| 35 | - | ||
| 36 | - $model->project_id = $project_id; | ||
| 37 | - | ||
| 38 | - $model->template_id = $data['template_id']; | ||
| 39 | - | ||
| 40 | - $model->name = $data['name']; | ||
| 41 | - $model->type = $data['type']; | ||
| 42 | - $model->is_edit = $data['is_edit']; | ||
| 43 | - $model->css = $data['css']; | ||
| 44 | - $model->script = $data['script']; | ||
| 45 | - $model->html = $data['html']; | ||
| 46 | - $model->data_ext = $data['data_ext']; | 34 | + $model = static::where([ |
| 35 | + 'project_id'=>$project_id, | ||
| 36 | + 'template_id'=>$data['template_id'], | ||
| 37 | + 'type' => $data['type'], | ||
| 38 | + 'tag' => $data['tag'], | ||
| 39 | + ])->first(); | ||
| 40 | + | ||
| 41 | + if(!$model){ | ||
| 42 | + $model = new static(); | ||
| 43 | + $model->project_id = $project_id; | ||
| 44 | + $model->template_id = $data['template_id']; | ||
| 45 | + $model->type = $data['type']; | ||
| 46 | + $model->tag = $data['tag']; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + $model->css = $data['css']??''; | ||
| 50 | + $model->script = $data['script']??''; | ||
| 51 | + $model->html = $data['html']??''; | ||
| 52 | + $model->data_ext = $data['data_ext']??''; | ||
| 53 | + $model->data_source = $data['data_source']??'all'; | ||
| 54 | + $model->data_source_id = $data['data_source_id']??0; | ||
| 47 | 55 | ||
| 48 | $model->save(); | 56 | $model->save(); |
| 49 | 57 |
resources/views/template/.gitignore
0 → 100644
resources/views/template/readme.md
0 → 100644
| @@ -126,10 +126,16 @@ Route::middleware(['web'])->group(function (){ //admin用渲染默认要加上w | @@ -126,10 +126,16 @@ Route::middleware(['web'])->group(function (){ //admin用渲染默认要加上w | ||
| 126 | 126 | ||
| 127 | // 自定义页面 模板,头部底部 | 127 | // 自定义页面 模板,头部底部 |
| 128 | Route::prefix('template')->group(function () { | 128 | Route::prefix('template')->group(function () { |
| 129 | - Route::get('/', [\App\Http\Controllers\Aside\TemplateController::class, 'index'])->name('admin.template_header_footer'); | ||
| 130 | - Route::get('/edit', [\App\Http\Controllers\Aside\TemplateController::class, 'edit'])->name('admin.template_header_footer_edit'); | ||
| 131 | - Route::get('/insert', [\App\Http\Controllers\Aside\TemplateController::class, 'insert'])->name('admin.template_header_footer_insert'); | ||
| 132 | - Route::get('/delete', [\App\Http\Controllers\Aside\TemplateController::class, 'delete'])->name('admin.template_header_footer_system'); | 129 | + Route::get('/', [\App\Http\Controllers\Aside\TemplateController::class, 'index'])->name('admin.template'); |
| 130 | + Route::post('/edit', [\App\Http\Controllers\Aside\TemplateController::class, 'edit'])->name('admin.template_edit'); | ||
| 131 | + Route::post('/insert', [\App\Http\Controllers\Aside\TemplateController::class, 'insert'])->name('admin.template_insert'); | ||
| 132 | + Route::delete('/delete/{id}', [\App\Http\Controllers\Aside\TemplateController::class, 'delete'])->where('id','\d+')->name('admin.template_delete'); | ||
| 133 | + | ||
| 134 | + Route::get('/html/{template_id}', [\App\Http\Controllers\Aside\TemplateController::class, 'html_index'])->where('template_id','\d+')->name('admin.template.html'); | ||
| 135 | + Route::post('/html/{template_id}/edit', [\App\Http\Controllers\Aside\TemplateController::class, 'html_edit'])->where('template_id','\d+')->name('admin.template_edit.html'); | ||
| 136 | + Route::post('/html/{template_id}/insert', [\App\Http\Controllers\Aside\TemplateController::class, 'html_insert'])->where('template_id','\d+')->name('admin.template_insert.html'); | ||
| 137 | + Route::delete('/html/{template_id}/delete/{id}', [\App\Http\Controllers\Aside\TemplateController::class, 'html_delete'])->where('template_id','\d+')->where('id','\d+')->name('admin.template_delete.html'); | ||
| 138 | + Route::get('/html/type', [\App\Http\Controllers\Aside\TemplateController::class, 'html_type'])->name('admin.template_type.html'); | ||
| 133 | }); | 139 | }); |
| 134 | 140 | ||
| 135 | 141 |
| @@ -225,7 +225,7 @@ Route::middleware(['bloginauth'])->group(function () { | @@ -225,7 +225,7 @@ Route::middleware(['bloginauth'])->group(function () { | ||
| 225 | Route::prefix('template')->group(function () { | 225 | Route::prefix('template')->group(function () { |
| 226 | Route::get('/', [\App\Http\Controllers\Bside\TemplateController::class, 'index'])->name('bside_template'); | 226 | Route::get('/', [\App\Http\Controllers\Bside\TemplateController::class, 'index'])->name('bside_template'); |
| 227 | Route::any('/use-template', [\App\Http\Controllers\Bside\TemplateController::class, 'info'])->name('bside_template_use'); | 227 | Route::any('/use-template', [\App\Http\Controllers\Bside\TemplateController::class, 'info'])->name('bside_template_use'); |
| 228 | - Route::post('/edit', [\App\Http\Controllers\Bside\TemplateController::class, 'edit_save'])->name('template_header_footer_edit_save'); | 228 | + Route::get('/custom-chunk', [\App\Http\Controllers\Bside\TemplateController::class, 'customChunk'])->name('bside_template_custom_chunk'); |
| 229 | Route::get('/system', [\App\Http\Controllers\Bside\TemplateController::class, 'system_all_html'])->name('template_header_footer_system'); | 229 | Route::get('/system', [\App\Http\Controllers\Bside\TemplateController::class, 'system_all_html'])->name('template_header_footer_system'); |
| 230 | }); | 230 | }); |
| 231 | 231 |
-
请 注册 或 登录 后发表评论