正在显示
9 个修改的文件
包含
252 行增加
和
10 行删除
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :NewsExtendController.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2025/5/26 15:05 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Http\Controllers\Bside\Blog; | ||
| 11 | + | ||
| 12 | +use App\Enums\Common\Code; | ||
| 13 | +use App\Http\Controllers\Bside\BaseController; | ||
| 14 | +use App\Http\Logic\Bside\Blog\BlogExtendLogic; | ||
| 15 | +use Illuminate\Http\Request; | ||
| 16 | + | ||
| 17 | +class BlogExtendController extends BaseController | ||
| 18 | +{ | ||
| 19 | + public function __construct(Request $request) | ||
| 20 | + { | ||
| 21 | + parent::__construct($request); | ||
| 22 | + $this->logic = new BlogExtendLogic(); | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * @remark :获取所有扩展字段 | ||
| 27 | + * @name :lists | ||
| 28 | + * @author :lyh | ||
| 29 | + * @method :post | ||
| 30 | + * @time :2025/5/26 15:08 | ||
| 31 | + */ | ||
| 32 | + public function lists() | ||
| 33 | + { | ||
| 34 | + $lists = $this->logic->list($this->map); | ||
| 35 | + $this->response('success', Code::SUCCESS, $lists); | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * @remark :保存扩展字段 | ||
| 40 | + * @name :save | ||
| 41 | + * @author :lyh | ||
| 42 | + * @method :post | ||
| 43 | + * @time :2025/5/26 15:09 | ||
| 44 | + */ | ||
| 45 | + public function save() | ||
| 46 | + { | ||
| 47 | + $this->request->validate([ | ||
| 48 | + 'title' => 'required', | ||
| 49 | + 'type' => 'required', | ||
| 50 | + ], [ | ||
| 51 | + 'title.required' => '字段名称不能为空', | ||
| 52 | + 'type.required' => '字段类型不能为空', | ||
| 53 | + ]); | ||
| 54 | + $data = $this->logic->extendSave(); | ||
| 55 | + $this->response('success', Code::SUCCESS, $data); | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + /** | ||
| 59 | + * @remark :修改状态 | ||
| 60 | + * @name :status | ||
| 61 | + * @author :lyh | ||
| 62 | + * @method :post | ||
| 63 | + * @time :2025/5/27 9:22 | ||
| 64 | + */ | ||
| 65 | + public function status(){ | ||
| 66 | + $this->request->validate([ | ||
| 67 | + 'id' => 'required', | ||
| 68 | + 'status' => 'required', | ||
| 69 | + ], [ | ||
| 70 | + 'id.required' => '字段名称不能为空', | ||
| 71 | + 'status.required' => '字段类型不能为空', | ||
| 72 | + ]); | ||
| 73 | + $data = $this->logic->extendStatus(); | ||
| 74 | + $this->response('success', Code::SUCCESS, $data); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + /** | ||
| 78 | + * @remark :删除扩展字段 | ||
| 79 | + * @name :del | ||
| 80 | + * @author :lyh | ||
| 81 | + * @method :post | ||
| 82 | + * @time :2025/5/26 15:43 | ||
| 83 | + */ | ||
| 84 | + public function del(){ | ||
| 85 | + $this->request->validate([ | ||
| 86 | + 'id' => 'required', | ||
| 87 | + ], [ | ||
| 88 | + 'id.required' => '主键不能为空', | ||
| 89 | + ]); | ||
| 90 | + $data = $this->logic->extendDel(); | ||
| 91 | + $this->response('success', Code::SUCCESS, $data); | ||
| 92 | + } | ||
| 93 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :NewsExtendLogic.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2025/5/26 15:11 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Http\Logic\Bside\Blog; | ||
| 11 | + | ||
| 12 | +use App\Http\Logic\Bside\BaseLogic; | ||
| 13 | +use App\Models\News\BlogExtend; | ||
| 14 | +use App\Models\Product\ExtendInfo; | ||
| 15 | + | ||
| 16 | +class BlogExtendLogic extends BaseLogic | ||
| 17 | +{ | ||
| 18 | + public function __construct() | ||
| 19 | + { | ||
| 20 | + parent::__construct(); | ||
| 21 | + $this->model = new BlogExtend(); | ||
| 22 | + $this->param = $this->requestAll; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * @remark :列表页 | ||
| 27 | + * @name :list | ||
| 28 | + * @author :lyh | ||
| 29 | + * @method :post | ||
| 30 | + * @time :2025/5/26 15:17 | ||
| 31 | + */ | ||
| 32 | + public function list($map){ | ||
| 33 | + $map['status'] = 1; | ||
| 34 | + $data = $this->model->list($map); | ||
| 35 | + return $this->success($data); | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * @remark :保存扩展字段 | ||
| 40 | + * @name :extendSave | ||
| 41 | + * @author :lyh | ||
| 42 | + * @method :post | ||
| 43 | + * @time :2025/5/26 15:13 | ||
| 44 | + * @param :id->主键;title->名称 | ||
| 45 | + */ | ||
| 46 | + public function extendSave(){ | ||
| 47 | + if(isset($this->param['id']) && !empty($this->param['id'])){ | ||
| 48 | + $rs = $this->model->edit($this->param,['id'=>$this->param['id']]); | ||
| 49 | + }else{ | ||
| 50 | + $info = $this->model->read(['title'=>$this->param['title']]); | ||
| 51 | + if($info !== false){ | ||
| 52 | + $this->fail('当前扩展名称已存在'); | ||
| 53 | + } | ||
| 54 | + $this->param['key'] = $this->model->getKey(); | ||
| 55 | + $this->param['project_id'] = $this->user['project_id']; | ||
| 56 | + $rs = $this->model->add($this->param); | ||
| 57 | + } | ||
| 58 | + if($rs === false){ | ||
| 59 | + $this->fail('error'); | ||
| 60 | + } | ||
| 61 | + return $this->success($this->param); | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + /** | ||
| 65 | + * @remark :修改状态 | ||
| 66 | + * @name :extendStatus | ||
| 67 | + * @author :lyh | ||
| 68 | + * @method :post | ||
| 69 | + * @time :2025/5/27 9:20 | ||
| 70 | + */ | ||
| 71 | + public function extendStatus(){ | ||
| 72 | + $result = $this->model->edit(['status'=>$this->param['status']],['id'=>$this->param['id']]); | ||
| 73 | + return $this->success(['result'=>$result]); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + /** | ||
| 77 | + * @remark :删除字段 | ||
| 78 | + * @name :extendDel | ||
| 79 | + * @author :lyh | ||
| 80 | + * @method :post | ||
| 81 | + * @time :2025/5/26 15:45 | ||
| 82 | + * @param :id->主键 | ||
| 83 | + */ | ||
| 84 | + public function extendDel(){ | ||
| 85 | + $info = $this->model->read(['id'=>$this->param['id']]); | ||
| 86 | + //查看当前扩展字段是否设置了值 | ||
| 87 | + $extendInfoModel = new ExtendInfo(); | ||
| 88 | + $extendInfo = $extendInfoModel->read(['key'=>$info['key']]); | ||
| 89 | + if($extendInfo !== false){ | ||
| 90 | + $this->fail('当前扩展字段已有产品在使用,不允许删除'); | ||
| 91 | + } | ||
| 92 | + $this->model->del(['id'=>$this->param['id']]); | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | +} |
| @@ -10,7 +10,7 @@ | @@ -10,7 +10,7 @@ | ||
| 10 | namespace App\Http\Logic\Bside\News; | 10 | namespace App\Http\Logic\Bside\News; |
| 11 | 11 | ||
| 12 | use App\Http\Logic\Bside\BaseLogic; | 12 | use App\Http\Logic\Bside\BaseLogic; |
| 13 | -use App\Models\News\NewsExtend; | 13 | +use App\Models\News\BlogExtend; |
| 14 | use App\Models\Product\ExtendInfo; | 14 | use App\Models\Product\ExtendInfo; |
| 15 | 15 | ||
| 16 | class NewsExtendLogic extends BaseLogic | 16 | class NewsExtendLogic extends BaseLogic |
| @@ -18,7 +18,7 @@ class NewsExtendLogic extends BaseLogic | @@ -18,7 +18,7 @@ class NewsExtendLogic extends BaseLogic | ||
| 18 | public function __construct() | 18 | public function __construct() |
| 19 | { | 19 | { |
| 20 | parent::__construct(); | 20 | parent::__construct(); |
| 21 | - $this->model = new NewsExtend(); | 21 | + $this->model = new BlogExtend(); |
| 22 | $this->param = $this->requestAll; | 22 | $this->param = $this->requestAll; |
| 23 | } | 23 | } |
| 24 | 24 |
| @@ -8,8 +8,8 @@ use App\Http\Logic\Bside\BaseLogic; | @@ -8,8 +8,8 @@ use App\Http\Logic\Bside\BaseLogic; | ||
| 8 | use App\Models\News\News; | 8 | use App\Models\News\News; |
| 9 | use App\Models\News\NewsCategory; | 9 | use App\Models\News\NewsCategory; |
| 10 | use App\Models\News\NewsCategory as NewsCategoryModel; | 10 | use App\Models\News\NewsCategory as NewsCategoryModel; |
| 11 | -use App\Models\News\NewsExtend; | ||
| 12 | -use App\Models\News\NewsExtendInfo; | 11 | +use App\Models\News\BlogExtend; |
| 12 | +use App\Models\News\BlogExtendInfo; | ||
| 13 | use App\Models\RouteMap\RouteMap; | 13 | use App\Models\RouteMap\RouteMap; |
| 14 | use App\Models\Template\BTemplate; | 14 | use App\Models\Template\BTemplate; |
| 15 | use App\Services\CosService; | 15 | use App\Services\CosService; |
| @@ -176,7 +176,7 @@ class NewsLogic extends BaseLogic | @@ -176,7 +176,7 @@ class NewsLogic extends BaseLogic | ||
| 176 | $this->delRoute($id); | 176 | $this->delRoute($id); |
| 177 | $this->model->del(['id' => $id]); | 177 | $this->model->del(['id' => $id]); |
| 178 | //删除扩展字段 | 178 | //删除扩展字段 |
| 179 | - $extendInfoModel = new NewsExtendInfo(); | 179 | + $extendInfoModel = new BlogExtendInfo(); |
| 180 | $extendInfoModel->del(['news_id'=>$id]); | 180 | $extendInfoModel->del(['news_id'=>$id]); |
| 181 | } | 181 | } |
| 182 | } | 182 | } |
app/Models/Blog/BlogExtend.php
0 → 100644
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :BlogExtend.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2025/5/26 15:08 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Models\Blog; | ||
| 11 | + | ||
| 12 | +use App\Models\Base; | ||
| 13 | + | ||
| 14 | +class BlogExtend extends Base | ||
| 15 | +{ | ||
| 16 | + protected $table = 'gl_blog_extend'; | ||
| 17 | + protected $connection = 'custom_mysql'; | ||
| 18 | + | ||
| 19 | + const EXTEND_KEY = 'pd_extended_field_'; | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * @remark :添加扩展字段 | ||
| 23 | + * @name :getKey | ||
| 24 | + * @author :lyh | ||
| 25 | + * @method :post | ||
| 26 | + * @time :2025/5/26 15:39 | ||
| 27 | + */ | ||
| 28 | + public function getKey($key = self::EXTEND_KEY,$i = 1){ | ||
| 29 | + $info = $this->read(['key'=>$key.$i]); | ||
| 30 | + if($info !== false){ | ||
| 31 | + return $this->getKey($key,$i+1); | ||
| 32 | + }else{ | ||
| 33 | + return $key.$i; | ||
| 34 | + } | ||
| 35 | + } | ||
| 36 | +} |
app/Models/Blog/BlogExtendInfo.php
0 → 100644
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :BlogExtendInfo.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2025/5/26 15:49 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Models\Blog; | ||
| 11 | + | ||
| 12 | +use App\Models\Base; | ||
| 13 | + | ||
| 14 | +class BlogExtendInfo extends Base | ||
| 15 | +{ | ||
| 16 | + protected $table = 'gl_blog_extend_info'; | ||
| 17 | + protected $connection = 'custom_mysql'; | ||
| 18 | +} |
| @@ -41,12 +41,12 @@ class News extends Base | @@ -41,12 +41,12 @@ class News extends Base | ||
| 41 | * @time :2023/12/6 14:43 | 41 | * @time :2023/12/6 14:43 |
| 42 | */ | 42 | */ |
| 43 | public function getExtendInfo($news_id){ | 43 | public function getExtendInfo($news_id){ |
| 44 | - $extendModel = new NewsExtend(); | 44 | + $extendModel = new BlogExtend(); |
| 45 | $list = $extendModel->list(['status'=>1],'id',['id','type','key','title']); | 45 | $list = $extendModel->list(['status'=>1],'id',['id','type','key','title']); |
| 46 | if(empty($list)){ | 46 | if(empty($list)){ |
| 47 | return []; | 47 | return []; |
| 48 | } | 48 | } |
| 49 | - $extendInfoModel = new NewsExtendInfo(); | 49 | + $extendInfoModel = new BlogExtendInfo(); |
| 50 | $infoList = $extendInfoModel->list(['news_id'=>$news_id],'created_at'); | 50 | $infoList = $extendInfoModel->list(['news_id'=>$news_id],'created_at'); |
| 51 | foreach ($list as $k=>$v){ | 51 | foreach ($list as $k=>$v){ |
| 52 | if($v['type'] == 3 || $v['type'] == 4){ | 52 | if($v['type'] == 3 || $v['type'] == 4){ |
| @@ -111,7 +111,7 @@ class News extends Base | @@ -111,7 +111,7 @@ class News extends Base | ||
| 111 | */ | 111 | */ |
| 112 | public function saveExtendInfo($news_id,$extend,$project_id){ | 112 | public function saveExtendInfo($news_id,$extend,$project_id){ |
| 113 | //先删除以前的数据 | 113 | //先删除以前的数据 |
| 114 | - $extendInfoModel = new NewsExtendInfo(); | 114 | + $extendInfoModel = new BlogExtendInfo(); |
| 115 | $extendInfoModel->del(['news_id'=>$news_id]); | 115 | $extendInfoModel->del(['news_id'=>$news_id]); |
| 116 | if(empty($extend)) { | 116 | if(empty($extend)) { |
| 117 | return true; | 117 | return true; |
-
请 注册 或 登录 后发表评论