正在显示
8 个修改的文件
包含
175 行增加
和
4 行删除
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Http\Controllers\Bside\Product; | ||
| 4 | + | ||
| 5 | +use App\Helper\Arr; | ||
| 6 | +use App\Http\Controllers\Bside\BaseController; | ||
| 7 | +use App\Http\Logic\Bside\Product\DescribeLogic; | ||
| 8 | +use App\Http\Requests\Bside\product\DescribeRequest; | ||
| 9 | +use App\Rules\Ids; | ||
| 10 | +use Illuminate\Http\Request; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * Class DescribeController | ||
| 14 | + * @package App\Http\Controllers\Bside | ||
| 15 | + * @author zbj | ||
| 16 | + * @date 2023/4/15 | ||
| 17 | + */ | ||
| 18 | +class DescribeController extends BaseController | ||
| 19 | +{ | ||
| 20 | + | ||
| 21 | + public function index(DescribeLogic $logic) | ||
| 22 | + { | ||
| 23 | + $map = []; | ||
| 24 | + if(!empty($this->param['search'])){ | ||
| 25 | + $map[] = ['title', 'like', "%{$this->param['search']}%"]; | ||
| 26 | + } | ||
| 27 | + $sort = ['id' => 'desc']; | ||
| 28 | + $data = $logic->getList($map, $sort, ['id', 'title', 'describe', 'status', 'created_at']); | ||
| 29 | + return $this->success($data); | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + public function info(Request $request, DescribeLogic $logic){ | ||
| 33 | + $request->validate([ | ||
| 34 | + 'id'=>'required' | ||
| 35 | + ],[ | ||
| 36 | + 'id.required' => 'ID不能为空' | ||
| 37 | + ]); | ||
| 38 | + $data = $logic->getInfo($this->param['id']); | ||
| 39 | + return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'describe', 'created_at'])); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + public function save(DescribeRequest $request, DescribeLogic $logic) | ||
| 43 | + { | ||
| 44 | + $data = $logic->save($this->param); | ||
| 45 | + return $this->success($data); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + public function delete(Request $request, DescribeLogic $logic) | ||
| 49 | + { | ||
| 50 | + $request->validate([ | ||
| 51 | + 'ids'=>['required', new Ids()] | ||
| 52 | + ],[ | ||
| 53 | + 'ids.required' => 'ID不能为空' | ||
| 54 | + ]); | ||
| 55 | + | ||
| 56 | + $data = $logic->delete($this->param['ids']); | ||
| 57 | + return $this->success($data); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | +} |
| @@ -88,6 +88,9 @@ class BaseLogic | @@ -88,6 +88,9 @@ class BaseLogic | ||
| 88 | public function getInfo($id) | 88 | public function getInfo($id) |
| 89 | { | 89 | { |
| 90 | $info = $this->getCacheInfo($id); | 90 | $info = $this->getCacheInfo($id); |
| 91 | + if(!$info){ | ||
| 92 | + $this->fail('数据不存在或者已经删除'); | ||
| 93 | + } | ||
| 91 | return $this->success($info->toArray()); | 94 | return $this->success($info->toArray()); |
| 92 | } | 95 | } |
| 93 | 96 | ||
| @@ -161,8 +164,11 @@ class BaseLogic | @@ -161,8 +164,11 @@ class BaseLogic | ||
| 161 | $map[] = ['id', 'in', $ids]; | 164 | $map[] = ['id', 'in', $ids]; |
| 162 | $res = $this->formatQuery($map)->delete(); | 165 | $res = $this->formatQuery($map)->delete(); |
| 163 | if($res){ | 166 | if($res){ |
| 164 | - if($this->is_cache && !empty($param['id'])){ | ||
| 165 | - Cache::forget($this->getInfoCacheKey($param['id'])); | 167 | + |
| 168 | + if($this->is_cache){ | ||
| 169 | + foreach ($ids as $id){ | ||
| 170 | + Cache::forget($this->getInfoCacheKey($id)); | ||
| 171 | + } | ||
| 166 | } | 172 | } |
| 167 | return $this->success(); | 173 | return $this->success(); |
| 168 | }else{ | 174 | }else{ |
| @@ -37,7 +37,7 @@ class CategoryLogic extends BaseLogic | @@ -37,7 +37,7 @@ class CategoryLogic extends BaseLogic | ||
| 37 | public function delete($ids){ | 37 | public function delete($ids){ |
| 38 | $ids= array_filter(Arr::splitFilterToArray($ids), 'intval'); | 38 | $ids= array_filter(Arr::splitFilterToArray($ids), 'intval'); |
| 39 | foreach ($ids as $id){ | 39 | foreach ($ids as $id){ |
| 40 | - $info = $this->getInfo($id); | 40 | + $info = $this->getCacheInfo($id); |
| 41 | if(!$info){ | 41 | if(!$info){ |
| 42 | continue; | 42 | continue; |
| 43 | } | 43 | } |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Http\Logic\Bside\Product; | ||
| 4 | + | ||
| 5 | +use App\Helper\Arr; | ||
| 6 | +use App\Http\Logic\Bside\BaseLogic; | ||
| 7 | +use App\Models\Product\Describe; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * Class DescribeLogic | ||
| 11 | + * @package App\Http\Logic\Bside\Product | ||
| 12 | + * @author zbj | ||
| 13 | + * @date 2023/4/15 | ||
| 14 | + */ | ||
| 15 | +class DescribeLogic extends BaseLogic | ||
| 16 | +{ | ||
| 17 | + public function __construct() | ||
| 18 | + { | ||
| 19 | + parent::__construct(); | ||
| 20 | + | ||
| 21 | + $this->model = new Describe(); | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + public function delete($ids){ | ||
| 25 | + $ids= array_filter(Arr::splitFilterToArray($ids), 'intval'); | ||
| 26 | + foreach ($ids as $id){ | ||
| 27 | + $info = $this->getCacheInfo($id); | ||
| 28 | + if(!$info){ | ||
| 29 | + continue; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + //todo 是否有关联商品 | ||
| 33 | + | ||
| 34 | + } | ||
| 35 | + return parent::delete($ids); | ||
| 36 | + } | ||
| 37 | +} |
| @@ -24,7 +24,7 @@ class KeywordLogic extends BaseLogic | @@ -24,7 +24,7 @@ class KeywordLogic extends BaseLogic | ||
| 24 | public function delete($ids){ | 24 | public function delete($ids){ |
| 25 | $ids= array_filter(Arr::splitFilterToArray($ids), 'intval'); | 25 | $ids= array_filter(Arr::splitFilterToArray($ids), 'intval'); |
| 26 | foreach ($ids as $id){ | 26 | foreach ($ids as $id){ |
| 27 | - $info = $this->getInfo($id); | 27 | + $info = $this->getCacheInfo($id); |
| 28 | if(!$info){ | 28 | if(!$info){ |
| 29 | continue; | 29 | continue; |
| 30 | } | 30 | } |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Http\Requests\Bside\product; | ||
| 4 | + | ||
| 5 | +use Illuminate\Foundation\Http\FormRequest; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * Class DescribeRequest | ||
| 9 | + * @package App\Http\Requests\Bside\product | ||
| 10 | + * @author zbj | ||
| 11 | + * @date 2023/4/15 | ||
| 12 | + */ | ||
| 13 | +class DescribeRequest extends FormRequest | ||
| 14 | +{ | ||
| 15 | + /** | ||
| 16 | + * Determine if the user is authorized to make this request. | ||
| 17 | + * | ||
| 18 | + * @return bool | ||
| 19 | + */ | ||
| 20 | + public function authorize() | ||
| 21 | + { | ||
| 22 | + return true; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * Get the validation rules that apply to the request. | ||
| 27 | + * | ||
| 28 | + * @return array | ||
| 29 | + */ | ||
| 30 | + public function rules() | ||
| 31 | + { | ||
| 32 | + return [ | ||
| 33 | + 'title'=>'required|max:30', | ||
| 34 | + 'describe'=>'required', | ||
| 35 | + ]; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + public function messages() | ||
| 39 | + { | ||
| 40 | + return [ | ||
| 41 | + 'title.required' => '请输入描述名称', | ||
| 42 | + 'title.max' => '描述名称不能超过30个字符', | ||
| 43 | + 'seo_title.required' => '请输入描述内容', | ||
| 44 | + ]; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | +} |
app/Models/Product/Describe.php
0 → 100644
| @@ -52,5 +52,11 @@ Route::group([], function () { | @@ -52,5 +52,11 @@ Route::group([], function () { | ||
| 52 | Route::get('attr/info', [\App\Http\Controllers\Bside\Product\AttrController::class, 'info'])->name('product_attr_info'); | 52 | Route::get('attr/info', [\App\Http\Controllers\Bside\Product\AttrController::class, 'info'])->name('product_attr_info'); |
| 53 | Route::post('attr/save', [\App\Http\Controllers\Bside\Product\AttrController::class, 'save'])->name('product_attr_save'); | 53 | Route::post('attr/save', [\App\Http\Controllers\Bside\Product\AttrController::class, 'save'])->name('product_attr_save'); |
| 54 | Route::any('attr/delete', [\App\Http\Controllers\Bside\Product\AttrController::class, 'delete'])->name('product_attr_delete'); | 54 | Route::any('attr/delete', [\App\Http\Controllers\Bside\Product\AttrController::class, 'delete'])->name('product_attr_delete'); |
| 55 | + | ||
| 56 | + //产品描述 | ||
| 57 | + Route::get('describe', [\App\Http\Controllers\Bside\Product\DescribeController::class, 'index'])->name('product_describe'); | ||
| 58 | + Route::get('describe/info', [\App\Http\Controllers\Bside\Product\DescribeController::class, 'info'])->name('product_describe_info'); | ||
| 59 | + Route::post('describe/save', [\App\Http\Controllers\Bside\Product\DescribeController::class, 'save'])->name('product_describe_save'); | ||
| 60 | + Route::any('describe/delete', [\App\Http\Controllers\Bside\Product\DescribeController::class, 'delete'])->name('product_describe_delete'); | ||
| 55 | }); | 61 | }); |
| 56 | }); | 62 | }); |
-
请 注册 或 登录 后发表评论