正在显示
13 个修改的文件
包含
392 行增加
和
127 行删除
| @@ -144,3 +144,68 @@ if (!function_exists('checkDomain')) { | @@ -144,3 +144,68 @@ if (!function_exists('checkDomain')) { | ||
| 144 | } | 144 | } |
| 145 | } | 145 | } |
| 146 | } | 146 | } |
| 147 | + | ||
| 148 | + | ||
| 149 | + | ||
| 150 | +/** | ||
| 151 | + * 把返回的数据集转换成Tree | ||
| 152 | + * @param $list array 数据列表 | ||
| 153 | + * @param string|int $pk 主键|root | ||
| 154 | + * @param string $pid 父id | ||
| 155 | + * @param string $child 子键 | ||
| 156 | + * @param int $root 获取哪个id下面 | ||
| 157 | + * @param bool $empty_child 当子数据不存在,是否要返回空子数据 | ||
| 158 | + * @return array | ||
| 159 | + */ | ||
| 160 | +function list_to_tree($list, $pk='id',$pid = 'pid',$child = '_child',$root=0,$empty_child=true) { | ||
| 161 | + // 如果是数字,则是root | ||
| 162 | + if(is_numeric($pk)){ | ||
| 163 | + $root = $pk; | ||
| 164 | + $pk = 'id'; | ||
| 165 | + } | ||
| 166 | + // 创建Tree | ||
| 167 | + $tree = array(); | ||
| 168 | + if(is_array($list)) { | ||
| 169 | + // 创建基于主键的数组引用 | ||
| 170 | + $refer = array(); | ||
| 171 | + foreach ($list as $key => $data) { | ||
| 172 | + if($empty_child){ | ||
| 173 | + $list[$key][$child] = []; | ||
| 174 | + } | ||
| 175 | + $refer[$data[$pk]] =& $list[$key]; | ||
| 176 | + } | ||
| 177 | + foreach ($list as $key => $data) { | ||
| 178 | + // 判断是否存在parent | ||
| 179 | + $parentId = $data[$pid]; | ||
| 180 | + if ($root == $parentId) { | ||
| 181 | + $tree[] =& $list[$key]; | ||
| 182 | + }else{ | ||
| 183 | + if (isset($refer[$parentId])) { | ||
| 184 | + $refer[$parentId][$child][] = & $list[$key]; | ||
| 185 | + } | ||
| 186 | + } | ||
| 187 | + } | ||
| 188 | + } | ||
| 189 | + return $tree; | ||
| 190 | +} | ||
| 191 | + | ||
| 192 | +/** | ||
| 193 | + * tree数据转list | ||
| 194 | + * @param $tree | ||
| 195 | + * @param string $child | ||
| 196 | + * @return array | ||
| 197 | + * @author:dc | ||
| 198 | + * @time 2022/1/11 10:13 | ||
| 199 | + */ | ||
| 200 | +function tree_to_list($tree, $child='_child'){ | ||
| 201 | + $lists = []; | ||
| 202 | + foreach ($tree as $item){ | ||
| 203 | + $c = $item[$child]??[]; | ||
| 204 | + unset($item[$child]); | ||
| 205 | + $lists[] = $item; | ||
| 206 | + if ($c){ | ||
| 207 | + $lists = array_merge($lists,tree_to_list($c, $child)); | ||
| 208 | + } | ||
| 209 | + } | ||
| 210 | + return $lists; | ||
| 211 | +} |
| @@ -4,6 +4,8 @@ namespace App\Http\Controllers\Aside; | @@ -4,6 +4,8 @@ namespace App\Http\Controllers\Aside; | ||
| 4 | 4 | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | use App\Http\Controllers\Controller; | 6 | use App\Http\Controllers\Controller; |
| 7 | +use App\Http\Requests\Aside\Template\TemplateRequest; | ||
| 8 | +use App\Http\Requests\Scene; | ||
| 7 | use Illuminate\Http\JsonResponse; | 9 | use Illuminate\Http\JsonResponse; |
| 8 | use Illuminate\Http\Request; | 10 | use Illuminate\Http\Request; |
| 9 | use Illuminate\Http\Exceptions\HttpResponseException; | 11 | use Illuminate\Http\Exceptions\HttpResponseException; |
| @@ -155,4 +157,21 @@ class BaseController extends Controller | @@ -155,4 +157,21 @@ class BaseController extends Controller | ||
| 155 | } | 157 | } |
| 156 | return $data; | 158 | return $data; |
| 157 | } | 159 | } |
| 160 | + | ||
| 161 | + | ||
| 162 | + /** | ||
| 163 | + * 验证 | ||
| 164 | + * @param $c | ||
| 165 | + * @param $scene | ||
| 166 | + * @return array | ||
| 167 | + * @author:dc | ||
| 168 | + * @time 2023/5/11 14:56 | ||
| 169 | + */ | ||
| 170 | + protected final function verify($c,$scene=null){ | ||
| 171 | + return (new $c())->setScene($scene?:Scene::$CREATE)->validated(); | ||
| 172 | + } | ||
| 173 | + | ||
| 174 | + | ||
| 175 | + | ||
| 176 | + | ||
| 158 | } | 177 | } |
| @@ -3,6 +3,9 @@ | @@ -3,6 +3,9 @@ | ||
| 3 | namespace App\Http\Controllers\Aside; | 3 | namespace App\Http\Controllers\Aside; |
| 4 | 4 | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | +use App\Http\Logic\Aside\Template\TemplateLogic; | ||
| 7 | +use App\Http\Requests\Aside\Template\TemplateRequest; | ||
| 8 | +use App\Http\Requests\Scene; | ||
| 6 | use App\Models\Template\ATemplate; | 9 | use App\Models\Template\ATemplate; |
| 7 | use App\Models\Template\ATemplateHtml; | 10 | use App\Models\Template\ATemplateHtml; |
| 8 | use Illuminate\Validation\Rule; | 11 | use Illuminate\Validation\Rule; |
| @@ -25,22 +28,9 @@ class TemplateController extends BaseController | @@ -25,22 +28,9 @@ class TemplateController extends BaseController | ||
| 25 | */ | 28 | */ |
| 26 | public function index(){ | 29 | public function index(){ |
| 27 | 30 | ||
| 28 | - $limit = $this->param['limit']??20; | 31 | + $lists = (new ATemplate)->lists($this->map,$this->page,$this->row,$this->order,['id','name','status','is_default','sort','thumb','url','created_at','updated_at']); |
| 32 | + $this->response('success',Code::SUCCESS,$lists); | ||
| 29 | 33 | ||
| 30 | - | ||
| 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()); | ||
| 44 | } | 34 | } |
| 45 | 35 | ||
| 46 | 36 | ||
| @@ -50,7 +40,7 @@ class TemplateController extends BaseController | @@ -50,7 +40,7 @@ class TemplateController extends BaseController | ||
| 50 | * @time 2023/5/4 16:19 | 40 | * @time 2023/5/4 16:19 |
| 51 | */ | 41 | */ |
| 52 | public function edit(){ | 42 | public function edit(){ |
| 53 | - $this->save(true); | 43 | + $this->save(Scene::$UPDATE); |
| 54 | } | 44 | } |
| 55 | 45 | ||
| 56 | /** | 46 | /** |
| @@ -59,7 +49,7 @@ class TemplateController extends BaseController | @@ -59,7 +49,7 @@ class TemplateController extends BaseController | ||
| 59 | * @time 2023/5/5 9:30 | 49 | * @time 2023/5/5 9:30 |
| 60 | */ | 50 | */ |
| 61 | public function insert(){ | 51 | public function insert(){ |
| 62 | - $this->save(); | 52 | + $this->save(Scene::$CREATE); |
| 63 | } | 53 | } |
| 64 | 54 | ||
| 65 | 55 | ||
| @@ -72,47 +62,15 @@ class TemplateController extends BaseController | @@ -72,47 +62,15 @@ class TemplateController extends BaseController | ||
| 72 | * @author:dc | 62 | * @author:dc |
| 73 | * @time 2023/5/11 10:13 | 63 | * @time 2023/5/11 10:13 |
| 74 | */ | 64 | */ |
| 75 | - private function save($is_edit=false){ | 65 | + private function save($scene){ |
| 76 | 66 | ||
| 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 | 67 | ||
| 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']); | 68 | + $data = $this->verify(TemplateRequest::class,$scene); |
| 105 | 69 | ||
| 106 | 70 | ||
| 71 | + TemplateLogic::instance()->save($data); | ||
| 107 | 72 | ||
| 108 | - // 保存 | ||
| 109 | - $id = ATemplate::_save($data,$data['id']??0); | ||
| 110 | 73 | ||
| 111 | - if(!$id){ | ||
| 112 | - return $this->response('保存失败',Code::SYSTEM_ERROR); | ||
| 113 | - } | ||
| 114 | - | ||
| 115 | - return $this->success(ATemplate::_find($id)); | ||
| 116 | } | 74 | } |
| 117 | 75 | ||
| 118 | 76 | ||
| @@ -142,11 +100,9 @@ class TemplateController extends BaseController | @@ -142,11 +100,9 @@ class TemplateController extends BaseController | ||
| 142 | */ | 100 | */ |
| 143 | public function html_index($template_id){ | 101 | public function html_index($template_id){ |
| 144 | 102 | ||
| 103 | + $lists = (new ATemplate)->list($this->map,$this->order,['id','name','status','is_default','sort','thumb','url','created_at','updated_at']); | ||
| 104 | + $this->response('success',Code::SUCCESS,$lists); | ||
| 145 | 105 | ||
| 146 | - $lists = ATemplateHtml::where('template_id',$template_id)->get(); | ||
| 147 | - | ||
| 148 | - | ||
| 149 | - return $this->success($lists->toArray()); | ||
| 150 | } | 106 | } |
| 151 | 107 | ||
| 152 | 108 |
| @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Bside; | @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Bside; | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | use App\Helper\Common; | 6 | use App\Helper\Common; |
| 7 | use App\Http\Controllers\Controller; | 7 | use App\Http\Controllers\Controller; |
| 8 | +use App\Http\Requests\Scene; | ||
| 8 | use App\Models\User\User as UserModel; | 9 | use App\Models\User\User as UserModel; |
| 9 | use Illuminate\Http\JsonResponse; | 10 | use Illuminate\Http\JsonResponse; |
| 10 | use Illuminate\Http\Request; | 11 | use Illuminate\Http\Request; |
| @@ -216,4 +217,18 @@ class BaseController extends Controller | @@ -216,4 +217,18 @@ class BaseController extends Controller | ||
| 216 | } | 217 | } |
| 217 | 218 | ||
| 218 | 219 | ||
| 220 | + /** | ||
| 221 | + * 验证 | ||
| 222 | + * @param $c | ||
| 223 | + * @param $scene | ||
| 224 | + * @return array | ||
| 225 | + * @author:dc | ||
| 226 | + * @time 2023/5/11 14:56 | ||
| 227 | + */ | ||
| 228 | + protected final function verify($c,$scene=null){ | ||
| 229 | + return (new $c())->setScene($scene?:Scene::$CREATE)->validated(); | ||
| 230 | + } | ||
| 231 | + | ||
| 232 | + | ||
| 233 | + | ||
| 219 | } | 234 | } |
| @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Bside; | @@ -4,6 +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; | ||
| 7 | use App\Models\BNav; | 8 | use App\Models\BNav; |
| 8 | 9 | ||
| 9 | /** | 10 | /** |
| @@ -16,42 +17,6 @@ use App\Models\BNav; | @@ -16,42 +17,6 @@ use App\Models\BNav; | ||
| 16 | class NavController extends BaseController | 17 | class NavController extends BaseController |
| 17 | { | 18 | { |
| 18 | 19 | ||
| 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 | - ]; | ||
| 55 | 20 | ||
| 56 | /** | 21 | /** |
| 57 | * 列表数据 | 22 | * 列表数据 |
| @@ -98,9 +63,7 @@ class NavController extends BaseController | @@ -98,9 +63,7 @@ class NavController extends BaseController | ||
| 98 | * @time 2023/5/8 17:06 | 63 | * @time 2023/5/8 17:06 |
| 99 | */ | 64 | */ |
| 100 | public function update(){ | 65 | public function update(){ |
| 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(); | 66 | + return $this->save(true); |
| 104 | } | 67 | } |
| 105 | 68 | ||
| 106 | /** | 69 | /** |
| @@ -112,8 +75,9 @@ class NavController extends BaseController | @@ -112,8 +75,9 @@ class NavController extends BaseController | ||
| 112 | * @author:dc | 75 | * @author:dc |
| 113 | * @time 2023/5/8 17:06 | 76 | * @time 2023/5/8 17:06 |
| 114 | */ | 77 | */ |
| 115 | - private function save(){ | ||
| 116 | - $data = $this->validate(request() ,$this->verify['role'],$this->verify['message']); | 78 | + private function save($edit=false){ |
| 79 | + | ||
| 80 | + $data = $this->verify(NavRequest::class,$edit?NavRequest::$UPDATE:null); | ||
| 117 | 81 | ||
| 118 | if($data['pid']){ | 82 | if($data['pid']){ |
| 119 | // 验证是否存在上级 | 83 | // 验证是否存在上级 |
| @@ -26,4 +26,15 @@ class BaseLogic extends Logic | @@ -26,4 +26,15 @@ class BaseLogic extends Logic | ||
| 26 | $this->user = Session::get('manage'); | 26 | $this->user = Session::get('manage'); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 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 | + } | ||
| 29 | } | 40 | } |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Http\Logic\Aside\Template; | ||
| 4 | + | ||
| 5 | + | ||
| 6 | +use App\Http\Logic\Aside\BaseLogic; | ||
| 7 | +use App\Models\Template\ATemplate; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * @author:dc | ||
| 11 | + * @time 2023/5/11 14:35 | ||
| 12 | + * Class TemplateLogic | ||
| 13 | + * @package App\Http\Logic\Aside\Template | ||
| 14 | + */ | ||
| 15 | +class TemplateLogic extends BaseLogic { | ||
| 16 | + | ||
| 17 | + public function __construct() | ||
| 18 | + { | ||
| 19 | + parent::__construct(); | ||
| 20 | + | ||
| 21 | + $this->model = new ATemplate(); | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + | ||
| 28 | +} |
| @@ -109,6 +109,9 @@ class BaseLogic extends Logic | @@ -109,6 +109,9 @@ class BaseLogic extends Logic | ||
| 109 | if($image_hash !== false){ | 109 | if($image_hash !== false){ |
| 110 | return $hash; | 110 | return $hash; |
| 111 | } | 111 | } |
| 112 | + $this->config = config('filesystems.disks.upload'); | ||
| 113 | + $this->uploads = config('upload.default_image'); | ||
| 114 | + $this->path = $this->config['root'].$this->uploads['path'].'/'; | ||
| 112 | $url = $this->path; | 115 | $url = $this->path; |
| 113 | $fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension(); | 116 | $fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension(); |
| 114 | $res = $files->move($url,$fileName); | 117 | $res = $files->move($url,$fileName); |
| @@ -59,19 +59,19 @@ class NewsLogic extends BaseLogic | @@ -59,19 +59,19 @@ class NewsLogic extends BaseLogic | ||
| 59 | $this->param['project_id'] = $this->user['project_id']; | 59 | $this->param['project_id'] = $this->user['project_id']; |
| 60 | $this->param['created_at'] = date('Y-m-d H:i:s',time()); | 60 | $this->param['created_at'] = date('Y-m-d H:i:s',time()); |
| 61 | $this->param['updated_at'] = date('Y-m-d H:i:s',time()); | 61 | $this->param['updated_at'] = date('Y-m-d H:i:s',time()); |
| 62 | - DB::beginTransaction(); | ||
| 63 | - try { | 62 | +// DB::beginTransaction(); |
| 63 | +// try { | ||
| 64 | if(isset($this->param['image'])){ | 64 | if(isset($this->param['image'])){ |
| 65 | $data = $this->upload(); | 65 | $data = $this->upload(); |
| 66 | $this->param['image'] = $data; | 66 | $this->param['image'] = $data; |
| 67 | } | 67 | } |
| 68 | $rs = $this->model->insertGetId($this->param); | 68 | $rs = $this->model->insertGetId($this->param); |
| 69 | RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']); | 69 | RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']); |
| 70 | - DB::commit(); | ||
| 71 | - }catch (\Exception $e){ | ||
| 72 | - DB::rollBack(); | ||
| 73 | - $this->fail('添加失败'); | ||
| 74 | - } | 70 | +// DB::commit(); |
| 71 | +// }catch (\Exception $e){ | ||
| 72 | +// DB::rollBack(); | ||
| 73 | +// $this->fail('添加失败'); | ||
| 74 | +// } | ||
| 75 | return $this->success(); | 75 | return $this->success(); |
| 76 | } | 76 | } |
| 77 | 77 |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Http\Requests\Aside\Template; | ||
| 4 | + | ||
| 5 | +use App\Http\Requests\Scene; | ||
| 6 | +use Illuminate\Foundation\Http\FormRequest; | ||
| 7 | +use Illuminate\Validation\Rule; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * @author:dc | ||
| 11 | + * @time 2023/5/11 14:38 | ||
| 12 | + * Class TemplateRequest | ||
| 13 | + * @package App\Http\Requests\Aside\Template | ||
| 14 | + */ | ||
| 15 | +class TemplateRequest extends FormRequest | ||
| 16 | +{ | ||
| 17 | + use Scene; | ||
| 18 | + | ||
| 19 | + /** | ||
| 20 | + * Determine if the user is authorized to make this request. | ||
| 21 | + * | ||
| 22 | + * @return bool | ||
| 23 | + */ | ||
| 24 | + public function authorize() | ||
| 25 | + { | ||
| 26 | + return true; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * Get the validation rules that apply to the request. | ||
| 31 | + * | ||
| 32 | + * @return array | ||
| 33 | + */ | ||
| 34 | + public function rules() | ||
| 35 | + { | ||
| 36 | + $rule = [ | ||
| 37 | + 'id' => ['required','integer'], | ||
| 38 | + 'name' => ['required'], | ||
| 39 | + 'status' => ['required',Rule::in(0,1)], | ||
| 40 | + 'is_default' => ['required',Rule::in(0,1)], | ||
| 41 | + 'sort' => ['required','integer'], | ||
| 42 | + 'thumb' => ['required'], | ||
| 43 | + 'url' => ['required'], | ||
| 44 | + ]; | ||
| 45 | + | ||
| 46 | + // 更新场景 | ||
| 47 | + if(!$this->isScene(Scene::$CREATE)){ | ||
| 48 | + unset($rule['id']); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + return $rule; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + | ||
| 55 | + | ||
| 56 | + public function messages() | ||
| 57 | + { | ||
| 58 | + return [ | ||
| 59 | + 'id.required' => 'id必须', | ||
| 60 | + 'id.integer' => 'id必须', | ||
| 61 | + | ||
| 62 | + 'name.required' => '名称必须', | ||
| 63 | + 'status.integer' => '状态错误', | ||
| 64 | + 'status.in' => '状态错误', | ||
| 65 | + 'is_default.integer' => '是否默认', | ||
| 66 | + 'is_default.in' => '是否默认', | ||
| 67 | + 'sort.required' => '排序必须', | ||
| 68 | + 'sort.integer' => '排序必须', | ||
| 69 | + 'thumb.required' => '缩略图必须', | ||
| 70 | + 'url.required' => '预览链接必须', | ||
| 71 | + ]; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | +} |
app/Http/Requests/Bside/Nav/NavRequest.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Http\Requests\Bside\Nav; | ||
| 4 | + | ||
| 5 | +use App\Http\Requests\Scene; | ||
| 6 | +use Illuminate\Foundation\Http\FormRequest; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * 导航 c端的 nav | ||
| 10 | + * @author:dc | ||
| 11 | + * @time 2023/5/11 15:20 | ||
| 12 | + * Class NavRequest | ||
| 13 | + * @package App\Http\Requests\Bside\Nav | ||
| 14 | + */ | ||
| 15 | +class NavRequest extends FormRequest | ||
| 16 | +{ | ||
| 17 | + use Scene; | ||
| 18 | + | ||
| 19 | + /** | ||
| 20 | + * Determine if the user is authorized to make this request. | ||
| 21 | + * | ||
| 22 | + * @return bool | ||
| 23 | + */ | ||
| 24 | + public function authorize() | ||
| 25 | + { | ||
| 26 | + return true; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * Get the validation rules that apply to the request. | ||
| 31 | + * | ||
| 32 | + * @return array | ||
| 33 | + */ | ||
| 34 | + public function rules() | ||
| 35 | + { | ||
| 36 | + $rule = [ | ||
| 37 | + 'pid' => ['required','integer','gte:0'], | ||
| 38 | + 'name' => ['required','max:100'], | ||
| 39 | + 'location' => ['required','in:header,footer'], | ||
| 40 | + 'url' => ['required','max:200'], | ||
| 41 | + 'status' => ['required','in:0,1'], | ||
| 42 | + 'target' => ['required','in:0,1'], | ||
| 43 | + 'sort' => ['required','integer','gte:0'] | ||
| 44 | + ]; | ||
| 45 | + | ||
| 46 | + if($this->isScene(static::$UPDATE)){ | ||
| 47 | + $rule['id'] = ['required','integer']; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + return $rule; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + public function messages() | ||
| 54 | + { | ||
| 55 | + return [ | ||
| 56 | + 'id.required' => '编辑导航数据不存在', | ||
| 57 | + 'id.integer' => '编辑导航数据不存在', | ||
| 58 | + 'pid.required' => '上级选择错误', | ||
| 59 | + 'pid.gte' => '上级选择错误', | ||
| 60 | + 'pid.integer' => '上级选择错误', | ||
| 61 | + 'name.required' => '名称必须', | ||
| 62 | + 'name.max' => '名称不能超过100个字符', | ||
| 63 | + 'location.required' => '位置选择错误', | ||
| 64 | + 'location.in' => '位置选择错误', | ||
| 65 | + 'url.required' => '链接必须', | ||
| 66 | + 'url.max' => '链接不能超过200个字符', | ||
| 67 | + 'status.required' => '状态选择错误', | ||
| 68 | + 'status.in' => '状态必须是显示/隐藏', | ||
| 69 | + 'target.required' => '打开方式必须', | ||
| 70 | + 'target.in' => '打开方式选择错误', | ||
| 71 | + 'sort.required' => '排序必须', | ||
| 72 | + 'sort.integer' => '排序必须是一个数字', | ||
| 73 | + 'sort.gte' => '排序必须大于等于0', | ||
| 74 | + ]; | ||
| 75 | + } | ||
| 76 | +} |
app/Http/Requests/Scene.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Http\Requests; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * @author:dc | ||
| 7 | + * @time 2023/5/11 14:49 | ||
| 8 | + * Class Scene | ||
| 9 | + * @package App\Http\Requests | ||
| 10 | + */ | ||
| 11 | +trait Scene { | ||
| 12 | + | ||
| 13 | + /** | ||
| 14 | + * 更新场景 | ||
| 15 | + */ | ||
| 16 | + static $UPDATE = 1; | ||
| 17 | + | ||
| 18 | + /** | ||
| 19 | + * 创建场景 | ||
| 20 | + */ | ||
| 21 | + static $CREATE = 0; | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * 删除场景 | ||
| 25 | + */ | ||
| 26 | + static $DELETE = -1; | ||
| 27 | + | ||
| 28 | + | ||
| 29 | + private $scene; | ||
| 30 | + | ||
| 31 | + | ||
| 32 | + public function setScene($scene){ | ||
| 33 | + | ||
| 34 | + $this->scene = $scene; | ||
| 35 | + | ||
| 36 | + return $this; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * @return mixed | ||
| 42 | + */ | ||
| 43 | + public function getScene() | ||
| 44 | + { | ||
| 45 | + return $this->scene; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + | ||
| 49 | + | ||
| 50 | + public function isScene($scene){ | ||
| 51 | + return $this->scene === $scene; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | +} |
| @@ -94,29 +94,29 @@ class ATemplate extends \App\Models\Base{ | @@ -94,29 +94,29 @@ 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 | - } | 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 | 120 | ||
| 121 | 121 | ||
| 122 | 122 |
-
请 注册 或 登录 后发表评论