Merge branch 'develop' of http://47.244.231.31:8099/zhl/globalso-v6 into develop
正在显示
10 个修改的文件
包含
147 行增加
和
62 行删除
| @@ -210,18 +210,5 @@ class BaseController extends Controller | @@ -210,18 +210,5 @@ class BaseController extends Controller | ||
| 210 | } | 210 | } |
| 211 | 211 | ||
| 212 | 212 | ||
| 213 | - /** | ||
| 214 | - * 验证 | ||
| 215 | - * @param $c | ||
| 216 | - * @param $scene | ||
| 217 | - * @return array | ||
| 218 | - * @author:dc | ||
| 219 | - * @time 2023/5/11 14:56 | ||
| 220 | - */ | ||
| 221 | - protected final function verify($c,$scene=null){ | ||
| 222 | - return app($c)->setScene($scene?:Scene::$CREATE)->validated(); | ||
| 223 | - } | ||
| 224 | - | ||
| 225 | - | ||
| 226 | 213 | ||
| 227 | } | 214 | } |
| @@ -114,7 +114,7 @@ class CustomController extends BaseController | @@ -114,7 +114,7 @@ class CustomController extends BaseController | ||
| 114 | $id = BCustom::_save($this->user['project_id'],$data,$data['id']??0); | 114 | $id = BCustom::_save($this->user['project_id'],$data,$data['id']??0); |
| 115 | 115 | ||
| 116 | if($id===-1){ | 116 | if($id===-1){ |
| 117 | - return $this->response('数据不存在','B_CUSTOM_NOTFOUND'); | 117 | + return $this->response('数据不存在',Code::SYSTEM_ERROR); |
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | return $this->success(BCustom::_find($this->user['project_id'],$id,true)); | 120 | return $this->success(BCustom::_find($this->user['project_id'],$id,true)); |
| @@ -132,7 +132,7 @@ class CustomController extends BaseController | @@ -132,7 +132,7 @@ class CustomController extends BaseController | ||
| 132 | $data = BCustom::_find($this->user['project_id'],$id); | 132 | $data = BCustom::_find($this->user['project_id'],$id); |
| 133 | 133 | ||
| 134 | if(empty($data)){ | 134 | if(empty($data)){ |
| 135 | - return $this->response('数据不存在','B_CUSTOM_NOTFOUND'); | 135 | + return $this->response('数据不存在',Code::SYSTEM_ERROR); |
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | 138 | ||
| @@ -154,7 +154,7 @@ class CustomController extends BaseController | @@ -154,7 +154,7 @@ class CustomController extends BaseController | ||
| 154 | { | 154 | { |
| 155 | $data = BCustom::_find($this->user['project_id'],$id); | 155 | $data = BCustom::_find($this->user['project_id'],$id); |
| 156 | if(!$data){ | 156 | if(!$data){ |
| 157 | - return $this->response('数据不存在','B_CUSTOM_NOTFOUND'); | 157 | + return $this->response('数据不存在',Code::SYSTEM_ERROR); |
| 158 | } | 158 | } |
| 159 | if($this->isPost()){ | 159 | if($this->isPost()){ |
| 160 | $html = $this->param['html']??''; | 160 | $html = $this->param['html']??''; |
| @@ -4,9 +4,7 @@ namespace App\Http\Controllers\Bside; | @@ -4,9 +4,7 @@ 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\Requests\Bside\Nav\NavRequest; | ||
| 8 | use App\Models\BNav; | 7 | use App\Models\BNav; |
| 9 | -use Illuminate\Validation\Validator; | ||
| 10 | 8 | ||
| 11 | /** | 9 | /** |
| 12 | * 导航栏目 b端编辑 c端显示 | 10 | * 导航栏目 b端编辑 c端显示 |
| @@ -18,6 +16,42 @@ use Illuminate\Validation\Validator; | @@ -18,6 +16,42 @@ use Illuminate\Validation\Validator; | ||
| 18 | class NavController extends BaseController | 16 | class NavController extends BaseController |
| 19 | { | 17 | { |
| 20 | 18 | ||
| 19 | + /** | ||
| 20 | + * 验证规则 | ||
| 21 | + * @var array[] | ||
| 22 | + */ | ||
| 23 | + private $verify = [ | ||
| 24 | + 'role' => [ | ||
| 25 | + 'pid' => ['required','integer','gte:0'], | ||
| 26 | + 'name' => ['required','max:100'], | ||
| 27 | + 'location' => ['required','in:header,footer'], | ||
| 28 | + 'url' => ['required','max:200'], | ||
| 29 | + 'status' => ['required','in:0,1'], | ||
| 30 | + 'target' => ['required','in:0,1'], | ||
| 31 | + 'sort' => ['required','integer','gte:0'] | ||
| 32 | + ], | ||
| 33 | + 'message' => [ | ||
| 34 | + 'pid.required' => '上级选择错误', | ||
| 35 | + 'pid.gte' => '上级选择错误', | ||
| 36 | + 'pid.integer' => '上级选择错误', | ||
| 37 | + 'name.required' => '名称必须', | ||
| 38 | + 'name.max' => '名称不能超过100个字符', | ||
| 39 | + 'location.required' => '位置选择错误', | ||
| 40 | + 'location.in' => '位置选择错误', | ||
| 41 | + 'url.required' => '链接必须', | ||
| 42 | + 'url.max' => '链接不能超过200个字符', | ||
| 43 | + 'status.required' => '状态选择错误', | ||
| 44 | + 'status.in' => '状态必须是显示/隐藏', | ||
| 45 | + 'target.required' => '打开方式必须', | ||
| 46 | + 'target.in' => '打开方式选择错误', | ||
| 47 | + 'sort.required' => '排序必须', | ||
| 48 | + 'sort.integer' => '排序必须是一个数字', | ||
| 49 | + 'sort.gte' => '排序必须大于等于0', | ||
| 50 | + ], | ||
| 51 | + 'attr' => [ | ||
| 52 | + | ||
| 53 | + ] | ||
| 54 | + ]; | ||
| 21 | 55 | ||
| 22 | /** | 56 | /** |
| 23 | * 列表数据 | 57 | * 列表数据 |
| @@ -64,7 +98,9 @@ class NavController extends BaseController | @@ -64,7 +98,9 @@ class NavController extends BaseController | ||
| 64 | * @time 2023/5/8 17:06 | 98 | * @time 2023/5/8 17:06 |
| 65 | */ | 99 | */ |
| 66 | public function update(){ | 100 | public function update(){ |
| 67 | - return $this->save(true); | 101 | + $this->verify['role']['id'] = ['required','integer','gt:0']; |
| 102 | + $this->verify['message']['id.gt'] = $this->verify['message']['id.integer'] = $this->verify['message']['id.required'] = '编辑导航数据不存在'; | ||
| 103 | + return $this->save(); | ||
| 68 | } | 104 | } |
| 69 | 105 | ||
| 70 | /** | 106 | /** |
| @@ -76,22 +112,21 @@ class NavController extends BaseController | @@ -76,22 +112,21 @@ class NavController extends BaseController | ||
| 76 | * @author:dc | 112 | * @author:dc |
| 77 | * @time 2023/5/8 17:06 | 113 | * @time 2023/5/8 17:06 |
| 78 | */ | 114 | */ |
| 79 | - private function save($edit=false){ | ||
| 80 | - | ||
| 81 | - $data = $this->verify(NavRequest::class,$edit?NavRequest::$UPDATE:null); | 115 | + private function save(){ |
| 116 | + $data = $this->validate(request() ,$this->verify['role'],$this->verify['message']); | ||
| 82 | 117 | ||
| 83 | if($data['pid']){ | 118 | if($data['pid']){ |
| 84 | // 验证是否存在上级 | 119 | // 验证是否存在上级 |
| 85 | $all = BNav::_all($this->user['project_id'],$data['location']); | 120 | $all = BNav::_all($this->user['project_id'],$data['location']); |
| 86 | if(!$all->where('id',$data['pid'])->count()){ | 121 | if(!$all->where('id',$data['pid'])->count()){ |
| 87 | - return $this->response('上级栏目不存在','B_NAV_PID_NOTFOUND'); | 122 | + return $this->response('上级栏目不存在',Code::SYSTEM_ERROR); |
| 88 | } | 123 | } |
| 89 | // 上级不允许是自己的下级 | 124 | // 上级不允许是自己的下级 |
| 90 | if(!empty($data['id'])){ | 125 | if(!empty($data['id'])){ |
| 91 | $all = list_to_tree($all->toArray(),$data['id']); | 126 | $all = list_to_tree($all->toArray(),$data['id']); |
| 92 | $all = tree_to_list($all); | 127 | $all = tree_to_list($all); |
| 93 | if(in_array($data['pid'],array_column($all,'id'))){ | 128 | if(in_array($data['pid'],array_column($all,'id'))){ |
| 94 | - return $this->response('上级栏目不允许为本身的下级','B_NAV_PID_IS_CHILD'); | 129 | + return $this->response('上级栏目不允许为本身的下级',Code::SYSTEM_ERROR); |
| 95 | } | 130 | } |
| 96 | } | 131 | } |
| 97 | } | 132 | } |
| @@ -100,7 +135,7 @@ class NavController extends BaseController | @@ -100,7 +135,7 @@ class NavController extends BaseController | ||
| 100 | $id = BNav::_save($this->user['project_id'],$data,$data['id']??0); | 135 | $id = BNav::_save($this->user['project_id'],$data,$data['id']??0); |
| 101 | 136 | ||
| 102 | if($id===-1){ | 137 | if($id===-1){ |
| 103 | - return $this->response('导航菜单不存在','B_NAV_NOTFOUND'); | 138 | + return $this->response('导航菜单不存在',Code::SYSTEM_ERROR); |
| 104 | } | 139 | } |
| 105 | 140 | ||
| 106 | return $this->success(BNav::_find($this->user['project_id'],$id,true)); | 141 | return $this->success(BNav::_find($this->user['project_id'],$id,true)); |
| @@ -118,12 +153,12 @@ class NavController extends BaseController | @@ -118,12 +153,12 @@ class NavController extends BaseController | ||
| 118 | $data = BNav::_find($this->user['project_id'],$id); | 153 | $data = BNav::_find($this->user['project_id'],$id); |
| 119 | 154 | ||
| 120 | if(empty($data)){ | 155 | if(empty($data)){ |
| 121 | - return $this->response('导航菜单不存在','B_NAV_NOTFOUND'); | 156 | + return $this->response('导航菜单不存在',Code::SYSTEM_ERROR); |
| 122 | } | 157 | } |
| 123 | 158 | ||
| 124 | 159 | ||
| 125 | if(BNav::isChild($data['id'],$this->user['project_id'])){ | 160 | if(BNav::isChild($data['id'],$this->user['project_id'])){ |
| 126 | - return $this->response('存在下级无法删除','B_NAV_DELETE_CHILD'); | 161 | + return $this->response('存在下级无法删除',Code::SYSTEM_ERROR); |
| 127 | } | 162 | } |
| 128 | 163 | ||
| 129 | 164 | ||
| @@ -141,22 +176,22 @@ class NavController extends BaseController | @@ -141,22 +176,22 @@ class NavController extends BaseController | ||
| 141 | public function urls(){ | 176 | public function urls(){ |
| 142 | // todo::需要配合 c端来 | 177 | // todo::需要配合 c端来 |
| 143 | return $this->success([ | 178 | return $this->success([ |
| 144 | - [ | ||
| 145 | - 'url' => '/', | ||
| 146 | - 'name' => '首页' | ||
| 147 | - ], | ||
| 148 | - [ | ||
| 149 | - 'url' => '/list', | ||
| 150 | - 'name' => '列表' | ||
| 151 | - ], | ||
| 152 | - [ | ||
| 153 | - 'url' => '/page', | ||
| 154 | - 'name' => '单页' | ||
| 155 | - ], | ||
| 156 | - [ | ||
| 157 | - 'url' => '/goods', | ||
| 158 | - 'name' => '商品' | ||
| 159 | - ], | 179 | + [ |
| 180 | + 'url' => '/', | ||
| 181 | + 'name' => '首页' | ||
| 182 | + ], | ||
| 183 | + [ | ||
| 184 | + 'url' => '/list', | ||
| 185 | + 'name' => '列表' | ||
| 186 | + ], | ||
| 187 | + [ | ||
| 188 | + 'url' => '/page', | ||
| 189 | + 'name' => '单页' | ||
| 190 | + ], | ||
| 191 | + [ | ||
| 192 | + 'url' => '/goods', | ||
| 193 | + 'name' => '商品' | ||
| 194 | + ], | ||
| 160 | ]); | 195 | ]); |
| 161 | } | 196 | } |
| 162 | 197 |
| @@ -57,7 +57,7 @@ class TemplateController extends BaseController | @@ -57,7 +57,7 @@ class TemplateController extends BaseController | ||
| 57 | if($template_id && ATemplate::_bFind($template_id)){ | 57 | if($template_id && ATemplate::_bFind($template_id)){ |
| 58 | BSetting::_save($this->user['project_id'],$template_id); | 58 | BSetting::_save($this->user['project_id'],$template_id); |
| 59 | }else{ | 59 | }else{ |
| 60 | - return $this->response('无法使用不存在的模板','B_TEMPLATE_NOTFOUND'); | 60 | + return $this->response('无法使用不存在的模板',Code::SYSTEM_ERROR); |
| 61 | } | 61 | } |
| 62 | } | 62 | } |
| 63 | 63 | ||
| @@ -151,7 +151,7 @@ class TemplateController extends BaseController | @@ -151,7 +151,7 @@ class TemplateController extends BaseController | ||
| 151 | $type = $this->param['type']??''; | 151 | $type = $this->param['type']??''; |
| 152 | 152 | ||
| 153 | if(!is_array($html)){ | 153 | if(!is_array($html)){ |
| 154 | - return $this->response('参数异常','B_CUSTOM_CHUNK_PARAMS'); | 154 | + return $this->response('参数异常',Code::SYSTEM_ERROR); |
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | // 项目id | 157 | // 项目id |
| @@ -161,7 +161,7 @@ class TemplateController extends BaseController | @@ -161,7 +161,7 @@ class TemplateController extends BaseController | ||
| 161 | 161 | ||
| 162 | // 验证这个模板是否存在 | 162 | // 验证这个模板是否存在 |
| 163 | if(!$type || !ATemplateHtml::_typeExist($template_id,$type)){ | 163 | if(!$type || !ATemplateHtml::_typeExist($template_id,$type)){ |
| 164 | - return $this->response('页面类型错误','B_CUSTOM_CHUNK_PARAMS_TYPE'); | 164 | + return $this->response('页面类型错误',Code::SYSTEM_ERROR); |
| 165 | } | 165 | } |
| 166 | 166 | ||
| 167 | 167 |
| @@ -27,14 +27,4 @@ class BaseLogic extends Logic | @@ -27,14 +27,4 @@ class BaseLogic extends Logic | ||
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | - /** | ||
| 31 | - * 获取实例 | ||
| 32 | - * @param mixed ...$params | ||
| 33 | - * @return static | ||
| 34 | - * @author:dc | ||
| 35 | - * @time 2023/5/11 15:23 | ||
| 36 | - */ | ||
| 37 | - public static function instance(...$params){ | ||
| 38 | - return new static(...$params); | ||
| 39 | - } | ||
| 40 | } | 30 | } |
app/Http/Logic/Bside/Nav/NavLogic.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Http\Logic\Bside; | ||
| 4 | + | ||
| 5 | +use App\Helper\Arr; | ||
| 6 | +use App\Models\BNav; | ||
| 7 | +use App\Models\Inquiry; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * @author:dc | ||
| 11 | + * @time 2023/5/11 16:51 | ||
| 12 | + * Class NavLogic | ||
| 13 | + * @package App\Http\Logic\Bside | ||
| 14 | + */ | ||
| 15 | +class NavLogic extends BaseLogic | ||
| 16 | +{ | ||
| 17 | + public function __construct() | ||
| 18 | + { | ||
| 19 | + parent::__construct(); | ||
| 20 | + | ||
| 21 | + $this->model = new BNav(); | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * @param $ids | ||
| 27 | + * @return array | ||
| 28 | + * @throws \App\Exceptions\AsideGlobalException | ||
| 29 | + * @throws \App\Exceptions\BsideGlobalException | ||
| 30 | + * @author:dc | ||
| 31 | + * @time 2023/5/11 16:59 | ||
| 32 | + */ | ||
| 33 | + public function delete($ids,$map = []) | ||
| 34 | + { | ||
| 35 | + if(BNav::isChild($ids,$this->user['project_id'])){ | ||
| 36 | + $this->fail('存在下级无法删除','B_NAV_DELETE_CHILD'); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + return parent::delete($ids,$map); // TODO: Change the autogenerated stub | ||
| 40 | + | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | +} |
| @@ -384,4 +384,17 @@ class Logic | @@ -384,4 +384,17 @@ class Logic | ||
| 384 | } | 384 | } |
| 385 | return $this->success($info); | 385 | return $this->success($info); |
| 386 | } | 386 | } |
| 387 | + | ||
| 388 | + | ||
| 389 | + | ||
| 390 | + /** | ||
| 391 | + * 获取实例 | ||
| 392 | + * @param mixed ...$params | ||
| 393 | + * @return static | ||
| 394 | + * @author:dc | ||
| 395 | + * @time 2023/5/11 15:23 | ||
| 396 | + */ | ||
| 397 | + public static function instance(...$params){ | ||
| 398 | + return new static(...$params); | ||
| 399 | + } | ||
| 387 | } | 400 | } |
| @@ -14,7 +14,7 @@ use Illuminate\Validation\Rule; | @@ -14,7 +14,7 @@ use Illuminate\Validation\Rule; | ||
| 14 | */ | 14 | */ |
| 15 | class TemplateRequest extends FormRequest | 15 | class TemplateRequest extends FormRequest |
| 16 | { | 16 | { |
| 17 | - use Scene; | 17 | +// use Scene; |
| 18 | 18 | ||
| 19 | /** | 19 | /** |
| 20 | * Determine if the user is authorized to make this request. | 20 | * Determine if the user is authorized to make this request. |
| @@ -44,9 +44,9 @@ class TemplateRequest extends FormRequest | @@ -44,9 +44,9 @@ class TemplateRequest extends FormRequest | ||
| 44 | ]; | 44 | ]; |
| 45 | 45 | ||
| 46 | // 更新场景 | 46 | // 更新场景 |
| 47 | - if(!$this->isScene(Scene::$CREATE)){ | ||
| 48 | - unset($rule['id']); | ||
| 49 | - } | 47 | +// if(!$this->isScene(Scene::$CREATE)){ |
| 48 | +// unset($rule['id']); | ||
| 49 | +// } | ||
| 50 | 50 | ||
| 51 | return $rule; | 51 | return $rule; |
| 52 | } | 52 | } |
| @@ -43,10 +43,16 @@ class NavRequest extends FormRequest | @@ -43,10 +43,16 @@ class NavRequest extends FormRequest | ||
| 43 | 'sort' => ['required','integer','gte:0'] | 43 | 'sort' => ['required','integer','gte:0'] |
| 44 | ]; | 44 | ]; |
| 45 | 45 | ||
| 46 | + // 修改 | ||
| 46 | if($this->isScene(static::$UPDATE)){ | 47 | if($this->isScene(static::$UPDATE)){ |
| 47 | $rule['id'] = ['required','integer']; | 48 | $rule['id'] = ['required','integer']; |
| 48 | } | 49 | } |
| 49 | 50 | ||
| 51 | + // 删除 | ||
| 52 | + if($this->isScene(static::$DELETE)){ | ||
| 53 | + $rule = ['id' => ['required','integer']]; | ||
| 54 | + } | ||
| 55 | + | ||
| 50 | return $rule; | 56 | return $rule; |
| 51 | } | 57 | } |
| 52 | 58 |
| @@ -29,8 +29,14 @@ trait Scene { | @@ -29,8 +29,14 @@ trait Scene { | ||
| 29 | private $scene; | 29 | private $scene; |
| 30 | 30 | ||
| 31 | 31 | ||
| 32 | + /** | ||
| 33 | + * @param $scene | ||
| 34 | + * @return $this | ||
| 35 | + * @author:dc | ||
| 36 | + * @time 2023/5/11 17:14 | ||
| 37 | + */ | ||
| 32 | public function setScene($scene){ | 38 | public function setScene($scene){ |
| 33 | - | 39 | + var_dump($scene); |
| 34 | $this->scene = $scene; | 40 | $this->scene = $scene; |
| 35 | 41 | ||
| 36 | return $this; | 42 | return $this; |
| @@ -46,7 +52,12 @@ trait Scene { | @@ -46,7 +52,12 @@ trait Scene { | ||
| 46 | } | 52 | } |
| 47 | 53 | ||
| 48 | 54 | ||
| 49 | - | 55 | + /** |
| 56 | + * @param $scene | ||
| 57 | + * @return bool | ||
| 58 | + * @author:dc | ||
| 59 | + * @time 2023/5/11 17:14 | ||
| 60 | + */ | ||
| 50 | public function isScene($scene){ | 61 | public function isScene($scene){ |
| 51 | return $this->scene === $scene; | 62 | return $this->scene === $scene; |
| 52 | } | 63 | } |
-
请 注册 或 登录 后发表评论