Merge branch 'develop' of http://47.244.231.31:8099/zhl/globalso-v6 into develop
正在显示
11 个修改的文件
包含
379 行增加
和
258 行删除
| @@ -27,29 +27,19 @@ class TemplateController extends BaseController | @@ -27,29 +27,19 @@ class TemplateController extends BaseController | ||
| 27 | */ | 27 | */ |
| 28 | public function index(){ | 28 | public function index(){ |
| 29 | 29 | ||
| 30 | - $lists = (new ATemplate)->lists($this->map,$this->page,$this->row,$this->order,['id','name','status','is_default','sort','thumb','url','created_at','updated_at']); | 30 | + $lists = (new ATemplate)->lists( |
| 31 | + $this->map, | ||
| 32 | + $this->page, | ||
| 33 | + $this->row, | ||
| 34 | + $this->order, | ||
| 35 | + ['id','name','status','is_default','sort','thumb','url','created_at','updated_at'] | ||
| 36 | + ); | ||
| 37 | + | ||
| 31 | $this->response('success',Code::SUCCESS,$lists); | 38 | $this->response('success',Code::SUCCESS,$lists); |
| 32 | 39 | ||
| 33 | } | 40 | } |
| 34 | 41 | ||
| 35 | 42 | ||
| 36 | - /** | ||
| 37 | - * 编辑 | ||
| 38 | - * @author:dc | ||
| 39 | - * @time 2023/5/4 16:19 | ||
| 40 | - */ | ||
| 41 | - public function edit(TemplateRequest $request){ | ||
| 42 | - $this->save($request->validated()); | ||
| 43 | - } | ||
| 44 | - | ||
| 45 | - /** | ||
| 46 | - * 新增 | ||
| 47 | - * @author:dc | ||
| 48 | - * @time 2023/5/5 9:30 | ||
| 49 | - */ | ||
| 50 | - public function insert(TemplateRequest $request){ | ||
| 51 | - $this->save($request->validated()); | ||
| 52 | - } | ||
| 53 | 43 | ||
| 54 | 44 | ||
| 55 | /** | 45 | /** |
| @@ -61,9 +51,9 @@ class TemplateController extends BaseController | @@ -61,9 +51,9 @@ class TemplateController extends BaseController | ||
| 61 | * @author:dc | 51 | * @author:dc |
| 62 | * @time 2023/5/11 10:13 | 52 | * @time 2023/5/11 10:13 |
| 63 | */ | 53 | */ |
| 64 | - private function save($data){ | 54 | + public function save(TemplateRequest $request){ |
| 65 | 55 | ||
| 66 | - TemplateLogic::instance()->save($data); | 56 | + TemplateLogic::instance()->save($request->validated()); |
| 67 | 57 | ||
| 68 | 58 | ||
| 69 | } | 59 | } |
| @@ -95,7 +85,7 @@ class TemplateController extends BaseController | @@ -95,7 +85,7 @@ class TemplateController extends BaseController | ||
| 95 | */ | 85 | */ |
| 96 | public function html_index($template_id){ | 86 | public function html_index($template_id){ |
| 97 | 87 | ||
| 98 | - $lists = (new ATemplate)->list($this->map,$this->order,['id','name','status','is_default','sort','thumb','url','created_at','updated_at']); | 88 | + $lists = (new ATemplateHtml)->list([['template_id','=',$template_id]],$this->order,['id','name','status','is_default','sort','thumb','url','created_at','updated_at']); |
| 99 | $this->response('success',Code::SUCCESS,$lists); | 89 | $this->response('success',Code::SUCCESS,$lists); |
| 100 | 90 | ||
| 101 | } | 91 | } |
| @@ -4,6 +4,8 @@ namespace App\Http\Controllers\Bside; | @@ -4,6 +4,8 @@ namespace App\Http\Controllers\Bside; | ||
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | use App\Enums\Common\Code; | 6 | use App\Enums\Common\Code; |
| 7 | +use App\Http\Logic\Bside\CustomLogic; | ||
| 8 | +use App\Http\Requests\Bside\Custom\CustomRequest; | ||
| 7 | use App\Models\BCustom; | 9 | use App\Models\BCustom; |
| 8 | 10 | ||
| 9 | /** | 11 | /** |
| @@ -17,41 +19,6 @@ class CustomController extends BaseController | @@ -17,41 +19,6 @@ class CustomController extends BaseController | ||
| 17 | { | 19 | { |
| 18 | 20 | ||
| 19 | /** | 21 | /** |
| 20 | - * 验证规则 | ||
| 21 | - * @var array[] | ||
| 22 | - */ | ||
| 23 | - private $verify = [ | ||
| 24 | - 'role' => [ | ||
| 25 | - 'name' => ['required','max:100'], | ||
| 26 | - 'title' => ['required','max:200'], | ||
| 27 | - 'keywords' => ['required','max:200'], | ||
| 28 | - 'description' => ['required','max:250'], | ||
| 29 | -// 'html' => ['required'], | ||
| 30 | - 'url' => ['required','max:200'], | ||
| 31 | - 'status' => ['required','in:0,1'], | ||
| 32 | - ], | ||
| 33 | - 'message' => [ | ||
| 34 | - 'name.required' => '名称必须', | ||
| 35 | - 'name.max' => '名称不能超过100个字符', | ||
| 36 | - 'title.required' => '网页标题必须', | ||
| 37 | - 'title.max' => '网页标题不能超过200个字符', | ||
| 38 | - 'keywords.required' => '网页关键字必须', | ||
| 39 | - 'keywords.max' => '网页关键字不能超过200个字符', | ||
| 40 | - 'description.required' => '网页描述必须', | ||
| 41 | - 'description.max' => '网页描述不能超过250个字符', | ||
| 42 | - | ||
| 43 | - 'url.required' => '链接必须', | ||
| 44 | - 'url.max' => '链接不能超过200个字符', | ||
| 45 | - | ||
| 46 | - 'status.required' => '状态选择错误', | ||
| 47 | - 'status.in' => '状态必须是显示/隐藏' | ||
| 48 | - ], | ||
| 49 | - 'attr' => [ | ||
| 50 | - | ||
| 51 | - ] | ||
| 52 | - ]; | ||
| 53 | - | ||
| 54 | - /** | ||
| 55 | * 列表数据 | 22 | * 列表数据 |
| 56 | * @throws \Psr\Container\ContainerExceptionInterface | 23 | * @throws \Psr\Container\ContainerExceptionInterface |
| 57 | * @throws \Psr\Container\NotFoundExceptionInterface | 24 | * @throws \Psr\Container\NotFoundExceptionInterface |
| @@ -64,40 +31,18 @@ class CustomController extends BaseController | @@ -64,40 +31,18 @@ class CustomController extends BaseController | ||
| 64 | $limit = intval($this->param['limit']??20); | 31 | $limit = intval($this->param['limit']??20); |
| 65 | 32 | ||
| 66 | 33 | ||
| 67 | - $lists = BCustom::_all($this->user['project_id'],$limit)->toArray(); | ||
| 68 | - | 34 | + $lists = CustomLogic::instance()->getList( |
| 35 | + [], | ||
| 36 | + [], | ||
| 37 | + ['id','name','title','status','url','keywords','description','created_at','updated_at'], | ||
| 38 | + $limit | ||
| 39 | + ); | ||
| 69 | 40 | ||
| 70 | return $this->success($lists); | 41 | return $this->success($lists); |
| 71 | 42 | ||
| 72 | } | 43 | } |
| 73 | 44 | ||
| 74 | 45 | ||
| 75 | - | ||
| 76 | - /** | ||
| 77 | - * 创建数据 | ||
| 78 | - * @author:dc | ||
| 79 | - * @time 2023/5/8 16:39 | ||
| 80 | - */ | ||
| 81 | - public function create(){ | ||
| 82 | - return $this->save(); | ||
| 83 | - } | ||
| 84 | - | ||
| 85 | - | ||
| 86 | - /** | ||
| 87 | - * 修改 | ||
| 88 | - * @return \Illuminate\Http\JsonResponse | ||
| 89 | - * @throws \Illuminate\Validation\ValidationException | ||
| 90 | - * @throws \Psr\Container\ContainerExceptionInterface | ||
| 91 | - * @throws \Psr\Container\NotFoundExceptionInterface | ||
| 92 | - * @author:dc | ||
| 93 | - * @time 2023/5/8 17:06 | ||
| 94 | - */ | ||
| 95 | - public function update(){ | ||
| 96 | - $this->verify['role']['id'] = ['required','integer','gt:0']; | ||
| 97 | - $this->verify['message']['id.gt'] = $this->verify['message']['id.integer'] = $this->verify['message']['id.required'] = '编辑导航数据不存在'; | ||
| 98 | - return $this->save(); | ||
| 99 | - } | ||
| 100 | - | ||
| 101 | /** | 46 | /** |
| 102 | * 新增修改 | 47 | * 新增修改 |
| 103 | * @return \Illuminate\Http\JsonResponse | 48 | * @return \Illuminate\Http\JsonResponse |
| @@ -107,17 +52,9 @@ class CustomController extends BaseController | @@ -107,17 +52,9 @@ class CustomController extends BaseController | ||
| 107 | * @author:dc | 52 | * @author:dc |
| 108 | * @time 2023/5/8 17:06 | 53 | * @time 2023/5/8 17:06 |
| 109 | */ | 54 | */ |
| 110 | - private function save(){ | ||
| 111 | - $data = $this->validate(request() ,$this->verify['role'],$this->verify['message']); | ||
| 112 | - | ||
| 113 | - // 保存 | ||
| 114 | - $id = BCustom::_save($this->user['project_id'],$data,$data['id']??0); | 55 | + public function save(CustomRequest $request){ |
| 115 | 56 | ||
| 116 | - if($id===-1){ | ||
| 117 | - return $this->response('数据不存在',Code::SYSTEM_ERROR); | ||
| 118 | - } | ||
| 119 | - | ||
| 120 | - return $this->success(BCustom::_find($this->user['project_id'],$id,true)); | 57 | + return $this->success(CustomLogic::instance()->save($request->validated())); |
| 121 | } | 58 | } |
| 122 | 59 | ||
| 123 | 60 | ||
| @@ -127,18 +64,11 @@ class CustomController extends BaseController | @@ -127,18 +64,11 @@ class CustomController extends BaseController | ||
| 127 | * @author:dc | 64 | * @author:dc |
| 128 | * @time 2023/5/9 9:20 | 65 | * @time 2023/5/9 9:20 |
| 129 | */ | 66 | */ |
| 130 | - public function delete(){ | ||
| 131 | - $id = $this->param['id']??0; | ||
| 132 | - $data = BCustom::_find($this->user['project_id'],$id); | ||
| 133 | - | ||
| 134 | - if(empty($data)){ | ||
| 135 | - return $this->response('数据不存在',Code::SYSTEM_ERROR); | ||
| 136 | - } | 67 | + public function delete(CustomRequest $request){ |
| 137 | 68 | ||
| 69 | + CustomLogic::instance()->delete($request->validated()['id']); | ||
| 138 | 70 | ||
| 139 | - if($data->delete()){ | ||
| 140 | - return $this->response('删除成功',Code::SUCCESS); | ||
| 141 | - } | 71 | + return $this->response('删除成功'); |
| 142 | 72 | ||
| 143 | } | 73 | } |
| 144 | 74 |
| @@ -4,9 +4,12 @@ namespace App\Http\Controllers\Bside; | @@ -4,9 +4,12 @@ namespace App\Http\Controllers\Bside; | ||
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | use App\Enums\Common\Code; | 6 | use App\Enums\Common\Code; |
| 7 | +use App\Http\Logic\Bside\TemplateLogic; | ||
| 8 | +use App\Http\Requests\Bside\TemplateRequest; | ||
| 7 | use App\Models\Template\ATemplate; | 9 | use App\Models\Template\ATemplate; |
| 8 | use App\Models\Template\ATemplateHtml; | 10 | use App\Models\Template\ATemplateHtml; |
| 9 | use App\Models\Template\BSetting; | 11 | use App\Models\Template\BSetting; |
| 12 | +use App\Models\Template\BTemplate; | ||
| 10 | use App\Models\Template\BTemplateData; | 13 | use App\Models\Template\BTemplateData; |
| 11 | use Illuminate\Validation\Rule; | 14 | use Illuminate\Validation\Rule; |
| 12 | 15 | ||
| @@ -117,9 +120,10 @@ class TemplateController extends BaseController | @@ -117,9 +120,10 @@ class TemplateController extends BaseController | ||
| 117 | $source = $this->param['source']??''; | 120 | $source = $this->param['source']??''; |
| 118 | $source_id = $this->param['source_id']??0; | 121 | $source_id = $this->param['source_id']??0; |
| 119 | 122 | ||
| 123 | + $data = TemplateLogic::instance()->first($source,$source_id); | ||
| 120 | 124 | ||
| 121 | 125 | ||
| 122 | - return $this->success(); | 126 | + return $this->response('',Code::SUCCESS,$data['html']); |
| 123 | 127 | ||
| 124 | } | 128 | } |
| 125 | 129 | ||
| @@ -128,13 +132,38 @@ class TemplateController extends BaseController | @@ -128,13 +132,38 @@ class TemplateController extends BaseController | ||
| 128 | * @author:dc | 132 | * @author:dc |
| 129 | * @time 2023/5/11 11:00 | 133 | * @time 2023/5/11 11:00 |
| 130 | */ | 134 | */ |
| 131 | - public function save_html(){ | 135 | + public function save_html(TemplateRequest $request){ |
| 132 | 136 | ||
| 133 | - $source = $this->param['source']??''; | ||
| 134 | - $source_id = $this->param['source_id']??0; | 137 | + $data = $request->validated(); |
| 138 | + | ||
| 139 | + $data['data_source'] = $data['source']; | ||
| 140 | + $data['data_source_id'] = $data['source_id']; | ||
| 141 | + | ||
| 142 | + unset($data['source']); | ||
| 143 | + unset($data['source_id']); | ||
| 144 | + | ||
| 145 | + TemplateLogic::instance()->save($data); | ||
| 146 | + | ||
| 147 | + return $this->response('保存成功'); | ||
| 148 | + | ||
| 149 | + } | ||
| 150 | + | ||
| 151 | + /** | ||
| 152 | + * 状态修改 | ||
| 153 | + * @param TemplateRequest $request | ||
| 154 | + * @return \Illuminate\Http\JsonResponse | ||
| 155 | + * @throws \App\Exceptions\AsideGlobalException | ||
| 156 | + * @throws \App\Exceptions\BsideGlobalException | ||
| 157 | + * @author:dc | ||
| 158 | + * @time 2023/5/15 14:43 | ||
| 159 | + */ | ||
| 160 | + public function status(TemplateRequest $request){ | ||
| 161 | + | ||
| 162 | + $data = $request->validated(); | ||
| 135 | 163 | ||
| 136 | - $html = $this->param['html']??''; | 164 | + TemplateLogic::instance()->status($data['source'],$data['source_id'],$data['status']); |
| 137 | 165 | ||
| 166 | + return $this->response('保存成功'); | ||
| 138 | 167 | ||
| 139 | } | 168 | } |
| 140 | 169 |
app/Http/Logic/Bside/CustomLogic.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Http\Logic\Bside; | ||
| 4 | + | ||
| 5 | +use App\Helper\Arr; | ||
| 6 | +use App\Models\BCustom; | ||
| 7 | +use App\Models\Inquiry; | ||
| 8 | +use App\Models\RouteMap; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * 自定义页面 | ||
| 12 | + * @author:dc | ||
| 13 | + * @time 2023/5/12 9:47 | ||
| 14 | + * Class CustomLogic | ||
| 15 | + * @package App\Http\Logic\Bside | ||
| 16 | + */ | ||
| 17 | +class CustomLogic extends BaseLogic | ||
| 18 | +{ | ||
| 19 | + public function __construct() | ||
| 20 | + { | ||
| 21 | + parent::__construct(); | ||
| 22 | + | ||
| 23 | + $this->model = new BCustom(); | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * @param $param | ||
| 29 | + * @return array | ||
| 30 | + * @throws \App\Exceptions\AsideGlobalException | ||
| 31 | + * @throws \App\Exceptions\BsideGlobalException | ||
| 32 | + * @author:dc | ||
| 33 | + * @time 2023/5/12 9:54 | ||
| 34 | + */ | ||
| 35 | + public function save($param) | ||
| 36 | + { | ||
| 37 | + $id = parent::save($param); | ||
| 38 | + | ||
| 39 | + $data = $this->getInfo($id['id']); | ||
| 40 | + | ||
| 41 | + try { | ||
| 42 | + RouteMap::setRoute($data['url'],RouteMap::SOURCE_CUSTOM,$data['id'],$this->user['project_id']); | ||
| 43 | + }catch (\Throwable $e){ | ||
| 44 | + | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + return $data; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + | ||
| 51 | + /** | ||
| 52 | + * 删除 | ||
| 53 | + * @param $ids | ||
| 54 | + * @param array $map | ||
| 55 | + * @return array|void | ||
| 56 | + * @author:dc | ||
| 57 | + * @time 2023/5/12 9:58 | ||
| 58 | + */ | ||
| 59 | + public function delete($ids, $map = []) | ||
| 60 | + { | ||
| 61 | + | ||
| 62 | + parent::delete($ids, $map); // TODO: Change the autogenerated stub | ||
| 63 | + | ||
| 64 | + // 删除路由 | ||
| 65 | + RouteMap::delRoute(RouteMap::SOURCE_CUSTOM,$ids,$this->user['project_id']); | ||
| 66 | + | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + | ||
| 70 | + | ||
| 71 | + | ||
| 72 | +} |
app/Http/Logic/Bside/TemplateLogic.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Http\Logic\Bside; | ||
| 4 | + | ||
| 5 | +use App\Models\RouteMap; | ||
| 6 | +use App\Models\Template\BTemplate; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * @author:dc | ||
| 10 | + * @time 2023/5/15 13:57 | ||
| 11 | + * Class TemplateLogic | ||
| 12 | + * @package App\Http\Logic\Bside | ||
| 13 | + */ | ||
| 14 | +class TemplateLogic extends BaseLogic | ||
| 15 | +{ | ||
| 16 | + public function __construct() | ||
| 17 | + { | ||
| 18 | + parent::__construct(); | ||
| 19 | + | ||
| 20 | + $this->model = new BTemplate(); | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * @param $param | ||
| 26 | + * @return array | ||
| 27 | + * @throws \App\Exceptions\AsideGlobalException | ||
| 28 | + * @throws \App\Exceptions\BsideGlobalException | ||
| 29 | + * @author:dc | ||
| 30 | + * @time 2023/5/12 9:54 | ||
| 31 | + */ | ||
| 32 | + public function save($param) | ||
| 33 | + { | ||
| 34 | + | ||
| 35 | + // 查询 | ||
| 36 | + $data = $this->first($param['data_source'],$param['data_source_id']); | ||
| 37 | + if($data){ | ||
| 38 | + $param['id'] = $data['id']; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + parent::save($param); | ||
| 42 | + | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * 状态修改 | ||
| 48 | + * @param $source | ||
| 49 | + * @param $source_id | ||
| 50 | + * @param $status | ||
| 51 | + * @return mixed | ||
| 52 | + * @throws \App\Exceptions\AsideGlobalException | ||
| 53 | + * @throws \App\Exceptions\BsideGlobalException | ||
| 54 | + * @author:dc | ||
| 55 | + * @time 2023/5/15 14:41 | ||
| 56 | + */ | ||
| 57 | + public function status($source,$source_id,$status){ | ||
| 58 | + | ||
| 59 | + $data = $this->first($source,$source_id); | ||
| 60 | + | ||
| 61 | + if(!$data){ | ||
| 62 | + $this->fail('数据不存在'); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + $data->status = $status; | ||
| 66 | + | ||
| 67 | + return $data->save(); | ||
| 68 | + | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + | ||
| 72 | + /** | ||
| 73 | + * @param $source | ||
| 74 | + * @param $source_id | ||
| 75 | + * @return mixed | ||
| 76 | + * @author:dc | ||
| 77 | + * @time 2023/5/15 14:49 | ||
| 78 | + */ | ||
| 79 | + public function first($source,$source_id) | ||
| 80 | + { | ||
| 81 | + return $data = BTemplate::where([ | ||
| 82 | + 'project_id'=>$this->user['project_id'], | ||
| 83 | + 'data_source' => $source, | ||
| 84 | + 'data_source_id' => $source_id, | ||
| 85 | + ])->first(); | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + | ||
| 89 | +} |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Http\Requests\Bside\Custom; | ||
| 4 | + | ||
| 5 | +use Illuminate\Foundation\Http\FormRequest; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * @author:dc | ||
| 9 | + * @time 2023/5/12 9:45 | ||
| 10 | + * Class CustomRequest | ||
| 11 | + * @package App\Http\Requests\Bside\Custom | ||
| 12 | + */ | ||
| 13 | +class CustomRequest extends FormRequest | ||
| 14 | +{ | ||
| 15 | + | ||
| 16 | + /** | ||
| 17 | + * Determine if the user is authorized to make this request. | ||
| 18 | + * | ||
| 19 | + * @return bool | ||
| 20 | + */ | ||
| 21 | + public function authorize() | ||
| 22 | + { | ||
| 23 | + return true; | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * Get the validation rules that apply to the request. | ||
| 28 | + * | ||
| 29 | + * @return array | ||
| 30 | + */ | ||
| 31 | + public function rules() | ||
| 32 | + { | ||
| 33 | + $rule = [ | ||
| 34 | + 'name' => ['required','max:100'], | ||
| 35 | + 'title' => ['required','max:200'], | ||
| 36 | + 'keywords' => ['required','max:200'], | ||
| 37 | + 'description' => ['required','max:250'], | ||
| 38 | +// 'html' => ['required'], | ||
| 39 | + 'url' => ['required','max:200'], | ||
| 40 | + 'status' => ['required','in:0,1'], | ||
| 41 | + ]; | ||
| 42 | + | ||
| 43 | + // 修改 | ||
| 44 | + if($this->is('b/custom/update')){ | ||
| 45 | + $rule['id'] = ['required','integer']; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + // 删除 | ||
| 49 | + if($this->is('b/custom/delete')){ | ||
| 50 | + $rule = ['id' => ['required','integer']]; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + return $rule; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public function messages() | ||
| 57 | + { | ||
| 58 | + return [ | ||
| 59 | + 'id.required' => '数据不存在', | ||
| 60 | + 'id.integer' => '数据不存在', | ||
| 61 | + | ||
| 62 | + 'name.required' => '名称必须', | ||
| 63 | + 'name.max' => '名称不能超过100个字符', | ||
| 64 | + 'title.required' => '网页标题必须', | ||
| 65 | + 'title.max' => '网页标题不能超过200个字符', | ||
| 66 | + 'keywords.required' => '网页关键字必须', | ||
| 67 | + 'keywords.max' => '网页关键字不能超过200个字符', | ||
| 68 | + 'description.required' => '网页描述必须', | ||
| 69 | + 'description.max' => '网页描述不能超过250个字符', | ||
| 70 | + | ||
| 71 | + 'url.required' => '链接必须', | ||
| 72 | + 'url.max' => '链接不能超过200个字符', | ||
| 73 | + | ||
| 74 | + 'status.required' => '状态选择错误', | ||
| 75 | + 'status.in' => '状态必须是显示/隐藏' | ||
| 76 | + ]; | ||
| 77 | + } | ||
| 78 | +} |
app/Http/Requests/Bside/TemplateRequest.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Http\Requests\Bside; | ||
| 4 | + | ||
| 5 | +use App\Models\Template\ATemplateHtml; | ||
| 6 | +use Illuminate\Foundation\Http\FormRequest; | ||
| 7 | +use Illuminate\Validation\Rule; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * @author:dc | ||
| 11 | + * @time 2023/5/15 14:04 | ||
| 12 | + * Class TemplateRequest | ||
| 13 | + * @package App\Http\Requests\Bside\Nav | ||
| 14 | + */ | ||
| 15 | +class TemplateRequest extends FormRequest | ||
| 16 | +{ | ||
| 17 | + | ||
| 18 | + /** | ||
| 19 | + * Determine if the user is authorized to make this request. | ||
| 20 | + * | ||
| 21 | + * @return bool | ||
| 22 | + */ | ||
| 23 | + public function authorize() | ||
| 24 | + { | ||
| 25 | + return true; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * Get the validation rules that apply to the request. | ||
| 30 | + * | ||
| 31 | + * @return array | ||
| 32 | + */ | ||
| 33 | + public function rules() | ||
| 34 | + { | ||
| 35 | + $rule = [ | ||
| 36 | + 'css' => [], | ||
| 37 | + 'script' => [], | ||
| 38 | + 'html' => ['required'], | ||
| 39 | + 'source' => ['required',Rule::in(array_column(ATemplateHtml::$sourceMap,'template'))], | ||
| 40 | + 'source_id' => ['required','integer','gte:0'], | ||
| 41 | + 'status' => ['required',Rule::in([0,1])] | ||
| 42 | + ]; | ||
| 43 | + | ||
| 44 | + | ||
| 45 | + // 删除 | ||
| 46 | + if(!$this->is('b/template/status')){ | ||
| 47 | + unset($rule['css']); | ||
| 48 | + unset($rule['script']); | ||
| 49 | + unset($rule['html']); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + return $rule; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + | ||
| 56 | + public function messages() | ||
| 57 | + { | ||
| 58 | + return [ | ||
| 59 | + | ||
| 60 | + 'html.required' => '自定义内容必须', | ||
| 61 | + | ||
| 62 | + 'source.required' => '数据错误', | ||
| 63 | + 'source.in' => '数据错误', | ||
| 64 | + | ||
| 65 | + 'source_id.required' => '数据错误', | ||
| 66 | + 'source_id.integer' => '数据错误', | ||
| 67 | + 'source_id.gte' => '数据错误', | ||
| 68 | + | ||
| 69 | + 'status.required' => '状态错误', | ||
| 70 | + 'status.in' => '状态错误', | ||
| 71 | + | ||
| 72 | + ]; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + | ||
| 76 | +} |
| @@ -32,78 +32,7 @@ class BCustom extends Base | @@ -32,78 +32,7 @@ class BCustom extends Base | ||
| 32 | const STATUS_DISABLED = 0; | 32 | const STATUS_DISABLED = 0; |
| 33 | 33 | ||
| 34 | 34 | ||
| 35 | - /** | ||
| 36 | - * 创建或者新增导航栏 | ||
| 37 | - * @param int $project_id | ||
| 38 | - * @param array $data | ||
| 39 | - * @param int $id | ||
| 40 | - * @return int | ||
| 41 | - * @author:dc | ||
| 42 | - * @time 2023/5/8 16:24 | ||
| 43 | - */ | ||
| 44 | - public static function _save(int $project_id, array $data, int $id = 0):int { | ||
| 45 | - if($id){ | ||
| 46 | - $model = static::where('id',$id)->where('project_id', $project_id)->first(); | ||
| 47 | - if(!$model){ | ||
| 48 | - return -1; | ||
| 49 | - } | ||
| 50 | - }else{ | ||
| 51 | - $model = new static(); | ||
| 52 | - $model->project_id = $project_id; | ||
| 53 | - | ||
| 54 | - } | ||
| 55 | - | ||
| 56 | - $model->name = $data['name']; | ||
| 57 | - $model->title = $data['title']; | ||
| 58 | - $model->keywords = $data['keywords']; | ||
| 59 | - $model->description = $data['description']; | ||
| 60 | - $model->url = $data['url']; | ||
| 61 | - $model->status = $data['status']; | ||
| 62 | - $model->html = $data['html']??''; | ||
| 63 | - | ||
| 64 | - $model->save(); | ||
| 65 | - | ||
| 66 | - // 创建路由标识 | ||
| 67 | - try { | ||
| 68 | - RouteMap::setRoute($model->url,RouteMap::SOURCE_CUSTOM,$model->id,$project_id); | ||
| 69 | - }catch (\Throwable $e){ | ||
| 70 | - | ||
| 71 | - } | ||
| 72 | - | ||
| 73 | - | ||
| 74 | - return $model->id; | ||
| 75 | - } | ||
| 76 | - | ||
| 77 | 35 | ||
| 78 | - /** | ||
| 79 | - * 删除 | ||
| 80 | - * @param int $project_id | ||
| 81 | - * @param int $id | ||
| 82 | - * @return mixed | ||
| 83 | - * @author:dc | ||
| 84 | - * @time 2023/5/8 16:27 | ||
| 85 | - */ | ||
| 86 | - public static function _del(int $project_id, int $id){ | ||
| 87 | - return static::where(['project_id'=>$project_id,'id'=>$id])->delete(); | ||
| 88 | - } | ||
| 89 | - | ||
| 90 | - | ||
| 91 | - /** | ||
| 92 | - * 查询当前项目下的所有信息 | ||
| 93 | - * @param int $project_id | ||
| 94 | - * @return mixed | ||
| 95 | - * @author:dc | ||
| 96 | - * @time 2023/5/8 16:29 | ||
| 97 | - */ | ||
| 98 | - public static function _all(int $project_id, int $limit = 20) | ||
| 99 | - { | ||
| 100 | - return static::where(function ($query) use ($project_id){ | ||
| 101 | - // 那个公司 | ||
| 102 | - $query->where('project_id',$project_id); | ||
| 103 | - }) | ||
| 104 | - ->select(['id','name','title','status','url','keywords','description','created_at','updated_at']) | ||
| 105 | - ->paginate($limit); | ||
| 106 | - } | ||
| 107 | 36 | ||
| 108 | /** | 37 | /** |
| 109 | * 查询一条数据 | 38 | * 查询一条数据 |
| @@ -32,52 +32,6 @@ class BNav extends Base | @@ -32,52 +32,6 @@ class BNav extends Base | ||
| 32 | const STATUS_DISABLED = 0; | 32 | const STATUS_DISABLED = 0; |
| 33 | 33 | ||
| 34 | 34 | ||
| 35 | - /** | ||
| 36 | - * 创建或者新增导航栏 | ||
| 37 | - * @param int $project_id | ||
| 38 | - * @param array $data | ||
| 39 | - * @param int $id | ||
| 40 | - * @return int | ||
| 41 | - * @author:dc | ||
| 42 | - * @time 2023/5/8 16:24 | ||
| 43 | - */ | ||
| 44 | - public static function _save(int $project_id, array $data, int $id = 0):int { | ||
| 45 | - if($id){ | ||
| 46 | - $model = static::where('id',$id)->where('project_id', $project_id)->first(); | ||
| 47 | - if(!$model){ | ||
| 48 | - return -1; | ||
| 49 | - } | ||
| 50 | - }else{ | ||
| 51 | - $model = new static(); | ||
| 52 | - $model->project_id = $project_id; | ||
| 53 | - | ||
| 54 | - } | ||
| 55 | - | ||
| 56 | - $model->pid = $data['pid']; | ||
| 57 | - $model->name = $data['name']; | ||
| 58 | - $model->location = $data['location']; | ||
| 59 | - $model->url = $data['url']; | ||
| 60 | - $model->status = $data['status']; | ||
| 61 | - $model->target = $data['target']; | ||
| 62 | - $model->sort = $data['sort']; | ||
| 63 | - $model->save(); | ||
| 64 | - | ||
| 65 | - return $model->id; | ||
| 66 | - } | ||
| 67 | - | ||
| 68 | - | ||
| 69 | - /** | ||
| 70 | - * 删除 | ||
| 71 | - * @param int $project_id | ||
| 72 | - * @param int $id | ||
| 73 | - * @return mixed | ||
| 74 | - * @author:dc | ||
| 75 | - * @time 2023/5/8 16:27 | ||
| 76 | - */ | ||
| 77 | - public static function _del(int $project_id, int $id){ | ||
| 78 | - return static::where(['project_id'=>$project_id,'id'=>$id])->delete(); | ||
| 79 | - } | ||
| 80 | - | ||
| 81 | 35 | ||
| 82 | /** | 36 | /** |
| 83 | * 查询当前项目下的所有栏目信息 | 37 | * 查询当前项目下的所有栏目信息 |
| @@ -98,36 +52,8 @@ class BNav extends Base | @@ -98,36 +52,8 @@ class BNav extends Base | ||
| 98 | ->get(); | 52 | ->get(); |
| 99 | } | 53 | } |
| 100 | 54 | ||
| 101 | - /** | ||
| 102 | - * 查询一条数据 | ||
| 103 | - * @param int $project_id | ||
| 104 | - * @param int $id | ||
| 105 | - * @return mixed | ||
| 106 | - * @author:dc | ||
| 107 | - * @time 2023/5/8 17:04 | ||
| 108 | - */ | ||
| 109 | - public static function _find(int $project_id, int $id, $array = false) | ||
| 110 | - { | ||
| 111 | - $data = static::where(['id'=>$id,'project_id'=>$project_id])->first(); | ||
| 112 | - if($data){ | ||
| 113 | - return $array ? $data->toArray() : $data; | ||
| 114 | - } | ||
| 115 | - return []; | ||
| 116 | - } | ||
| 117 | 55 | ||
| 118 | 56 | ||
| 119 | - /** | ||
| 120 | - * 是否存在 | ||
| 121 | - * @param int $project_id | ||
| 122 | - * @param int $id | ||
| 123 | - * @return mixed | ||
| 124 | - * @author:dc | ||
| 125 | - * @time 2023/5/8 17:24 | ||
| 126 | - */ | ||
| 127 | - public static function _check(int $project_id, int $id) | ||
| 128 | - { | ||
| 129 | - return static::where(['id'=>$id,'project_id'=>$project_id])->count(); | ||
| 130 | - } | ||
| 131 | 57 | ||
| 132 | /** | 58 | /** |
| 133 | * 是否有下级 | 59 | * 是否有下级 |
| @@ -127,8 +127,8 @@ Route::middleware(['web'])->group(function (){ //admin用渲染默认要加上w | @@ -127,8 +127,8 @@ Route::middleware(['web'])->group(function (){ //admin用渲染默认要加上w | ||
| 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'); | 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'); | 130 | + Route::post('/edit', [\App\Http\Controllers\Aside\TemplateController::class, 'save'])->name('admin.template_edit'); |
| 131 | + Route::post('/insert', [\App\Http\Controllers\Aside\TemplateController::class, 'save'])->name('admin.template_insert'); | ||
| 132 | Route::delete('/delete/{id}', [\App\Http\Controllers\Aside\TemplateController::class, 'delete'])->where('id','\d+')->name('admin.template_delete'); | 132 | Route::delete('/delete/{id}', [\App\Http\Controllers\Aside\TemplateController::class, 'delete'])->where('id','\d+')->name('admin.template_delete'); |
| 133 | 133 | ||
| 134 | Route::get('/html/{template_id}', [\App\Http\Controllers\Aside\TemplateController::class, 'html_index'])->where('template_id','\d+')->name('admin.template.html'); | 134 | Route::get('/html/{template_id}', [\App\Http\Controllers\Aside\TemplateController::class, 'html_index'])->where('template_id','\d+')->name('admin.template.html'); |
| @@ -233,15 +233,17 @@ Route::middleware(['bloginauth'])->group(function () { | @@ -233,15 +233,17 @@ Route::middleware(['bloginauth'])->group(function () { | ||
| 233 | Route::get('/get_type', [\App\Http\Controllers\Bside\TemplateController::class, 'get_type'])->name('bside_template_type'); | 233 | Route::get('/get_type', [\App\Http\Controllers\Bside\TemplateController::class, 'get_type'])->name('bside_template_type'); |
| 234 | Route::get('/get_html', [\App\Http\Controllers\Bside\TemplateController::class, 'get_html'])->name('bside_template_get_html'); | 234 | Route::get('/get_html', [\App\Http\Controllers\Bside\TemplateController::class, 'get_html'])->name('bside_template_get_html'); |
| 235 | Route::get('/save_html', [\App\Http\Controllers\Bside\TemplateController::class, 'save_html'])->name('bside_template_save_html'); | 235 | Route::get('/save_html', [\App\Http\Controllers\Bside\TemplateController::class, 'save_html'])->name('bside_template_save_html'); |
| 236 | + Route::get('/status', [\App\Http\Controllers\Bside\TemplateController::class, 'status'])->name('bside_template_status'); | ||
| 236 | }); | 237 | }); |
| 237 | // 自定义页面,专题页 | 238 | // 自定义页面,专题页 |
| 238 | Route::prefix('custom')->group(function () { | 239 | Route::prefix('custom')->group(function () { |
| 239 | Route::get('/', [\App\Http\Controllers\Bside\CustomController::class, 'index'])->name('bside_custom'); | 240 | Route::get('/', [\App\Http\Controllers\Bside\CustomController::class, 'index'])->name('bside_custom'); |
| 240 | - Route::post('/create', [\App\Http\Controllers\Bside\CustomController::class, 'create'])->name('bside_custom_create'); | ||
| 241 | - Route::post('/update', [\App\Http\Controllers\Bside\CustomController::class, 'update'])->name('bside_custom_update'); | 241 | + Route::post('/create', [\App\Http\Controllers\Bside\CustomController::class, 'save'])->name('bside_custom_create'); |
| 242 | + Route::post('/update', [\App\Http\Controllers\Bside\CustomController::class, 'save'])->name('bside_custom_update'); | ||
| 242 | Route::delete('/delete', [\App\Http\Controllers\Bside\CustomController::class, 'delete'])->name('bside_custom_delete'); | 243 | Route::delete('/delete', [\App\Http\Controllers\Bside\CustomController::class, 'delete'])->name('bside_custom_delete'); |
| 243 | Route::any('/html/{id}', [\App\Http\Controllers\Bside\CustomController::class, 'html'])->where('id','\d+')->name('bside_custom_delete'); | 244 | Route::any('/html/{id}', [\App\Http\Controllers\Bside\CustomController::class, 'html'])->where('id','\d+')->name('bside_custom_delete'); |
| 244 | }); | 245 | }); |
| 246 | + | ||
| 245 | // 导航栏编辑 | 247 | // 导航栏编辑 |
| 246 | Route::prefix('nav')->group(function () { | 248 | Route::prefix('nav')->group(function () { |
| 247 | Route::get('/', [\App\Http\Controllers\Bside\NavController::class, 'index'])->name('bside_nav'); | 249 | Route::get('/', [\App\Http\Controllers\Bside\NavController::class, 'index'])->name('bside_nav'); |
-
请 注册 或 登录 后发表评论