正在显示
4 个修改的文件
包含
166 行增加
和
85 行删除
| @@ -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 |
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 | +} |
| 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 | +} |
| @@ -240,11 +240,12 @@ Route::middleware(['bloginauth'])->group(function () { | @@ -240,11 +240,12 @@ Route::middleware(['bloginauth'])->group(function () { | ||
| 240 | // 自定义页面,专题页 | 240 | // 自定义页面,专题页 |
| 241 | Route::prefix('custom')->group(function () { | 241 | Route::prefix('custom')->group(function () { |
| 242 | Route::get('/', [\App\Http\Controllers\Bside\CustomController::class, 'index'])->name('bside_custom'); | 242 | Route::get('/', [\App\Http\Controllers\Bside\CustomController::class, 'index'])->name('bside_custom'); |
| 243 | - Route::post('/create', [\App\Http\Controllers\Bside\CustomController::class, 'create'])->name('bside_custom_create'); | ||
| 244 | - Route::post('/update', [\App\Http\Controllers\Bside\CustomController::class, 'update'])->name('bside_custom_update'); | 243 | + Route::post('/create', [\App\Http\Controllers\Bside\CustomController::class, 'save'])->name('bside_custom_create'); |
| 244 | + Route::post('/update', [\App\Http\Controllers\Bside\CustomController::class, 'save'])->name('bside_custom_update'); | ||
| 245 | Route::delete('/delete', [\App\Http\Controllers\Bside\CustomController::class, 'delete'])->name('bside_custom_delete'); | 245 | Route::delete('/delete', [\App\Http\Controllers\Bside\CustomController::class, 'delete'])->name('bside_custom_delete'); |
| 246 | Route::any('/html/{id}', [\App\Http\Controllers\Bside\CustomController::class, 'html'])->where('id','\d+')->name('bside_custom_delete'); | 246 | Route::any('/html/{id}', [\App\Http\Controllers\Bside\CustomController::class, 'html'])->where('id','\d+')->name('bside_custom_delete'); |
| 247 | }); | 247 | }); |
| 248 | + | ||
| 248 | // 导航栏编辑 | 249 | // 导航栏编辑 |
| 249 | Route::prefix('nav')->group(function () { | 250 | Route::prefix('nav')->group(function () { |
| 250 | Route::get('/', [\App\Http\Controllers\Bside\NavController::class, 'index'])->name('bside_nav'); | 251 | Route::get('/', [\App\Http\Controllers\Bside\NavController::class, 'index'])->name('bside_nav'); |
-
请 注册 或 登录 后发表评论