作者 lyh

变更数据

<?php
/**
* @remark :
* @name :NewsExtendController.php
* @author :lyh
* @method :post
* @time :2025/5/26 15:05
*/
namespace App\Http\Controllers\Bside\Blog;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Blog\BlogExtendLogic;
use Illuminate\Http\Request;
class BlogExtendController extends BaseController
{
public function __construct(Request $request)
{
parent::__construct($request);
$this->logic = new BlogExtendLogic();
}
/**
* @remark :获取所有扩展字段
* @name :lists
* @author :lyh
* @method :post
* @time :2025/5/26 15:08
*/
public function lists()
{
$lists = $this->logic->list($this->map);
$this->response('success', Code::SUCCESS, $lists);
}
/**
* @remark :保存扩展字段
* @name :save
* @author :lyh
* @method :post
* @time :2025/5/26 15:09
*/
public function save()
{
$this->request->validate([
'title' => 'required',
'type' => 'required',
], [
'title.required' => '字段名称不能为空',
'type.required' => '字段类型不能为空',
]);
$data = $this->logic->extendSave();
$this->response('success', Code::SUCCESS, $data);
}
/**
* @remark :修改状态
* @name :status
* @author :lyh
* @method :post
* @time :2025/5/27 9:22
*/
public function status(){
$this->request->validate([
'id' => 'required',
'status' => 'required',
], [
'id.required' => '字段名称不能为空',
'status.required' => '字段类型不能为空',
]);
$data = $this->logic->extendStatus();
$this->response('success', Code::SUCCESS, $data);
}
/**
* @remark :删除扩展字段
* @name :del
* @author :lyh
* @method :post
* @time :2025/5/26 15:43
*/
public function del(){
$this->request->validate([
'id' => 'required',
], [
'id.required' => '主键不能为空',
]);
$data = $this->logic->extendDel();
$this->response('success', Code::SUCCESS, $data);
}
}
... ...
<?php
/**
* @remark :
* @name :NewsExtendLogic.php
* @author :lyh
* @method :post
* @time :2025/5/26 15:11
*/
namespace App\Http\Logic\Bside\Blog;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\News\BlogExtend;
use App\Models\Product\ExtendInfo;
class BlogExtendLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new BlogExtend();
$this->param = $this->requestAll;
}
/**
* @remark :列表页
* @name :list
* @author :lyh
* @method :post
* @time :2025/5/26 15:17
*/
public function list($map){
$map['status'] = 1;
$data = $this->model->list($map);
return $this->success($data);
}
/**
* @remark :保存扩展字段
* @name :extendSave
* @author :lyh
* @method :post
* @time :2025/5/26 15:13
* @param :id->主键;title->名称
*/
public function extendSave(){
if(isset($this->param['id']) && !empty($this->param['id'])){
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
$info = $this->model->read(['title'=>$this->param['title']]);
if($info !== false){
$this->fail('当前扩展名称已存在');
}
$this->param['key'] = $this->model->getKey();
$this->param['project_id'] = $this->user['project_id'];
$rs = $this->model->add($this->param);
}
if($rs === false){
$this->fail('error');
}
return $this->success($this->param);
}
/**
* @remark :修改状态
* @name :extendStatus
* @author :lyh
* @method :post
* @time :2025/5/27 9:20
*/
public function extendStatus(){
$result = $this->model->edit(['status'=>$this->param['status']],['id'=>$this->param['id']]);
return $this->success(['result'=>$result]);
}
/**
* @remark :删除字段
* @name :extendDel
* @author :lyh
* @method :post
* @time :2025/5/26 15:45
* @param :id->主键
*/
public function extendDel(){
$info = $this->model->read(['id'=>$this->param['id']]);
//查看当前扩展字段是否设置了值
$extendInfoModel = new ExtendInfo();
$extendInfo = $extendInfoModel->read(['key'=>$info['key']]);
if($extendInfo !== false){
$this->fail('当前扩展字段已有产品在使用,不允许删除');
}
$this->model->del(['id'=>$this->param['id']]);
}
}
... ...
... ... @@ -10,7 +10,7 @@
namespace App\Http\Logic\Bside\News;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\News\NewsExtend;
use App\Models\News\BlogExtend;
use App\Models\Product\ExtendInfo;
class NewsExtendLogic extends BaseLogic
... ... @@ -18,7 +18,7 @@ class NewsExtendLogic extends BaseLogic
public function __construct()
{
parent::__construct();
$this->model = new NewsExtend();
$this->model = new BlogExtend();
$this->param = $this->requestAll;
}
... ...
... ... @@ -8,8 +8,8 @@ use App\Http\Logic\Bside\BaseLogic;
use App\Models\News\News;
use App\Models\News\NewsCategory;
use App\Models\News\NewsCategory as NewsCategoryModel;
use App\Models\News\NewsExtend;
use App\Models\News\NewsExtendInfo;
use App\Models\News\BlogExtend;
use App\Models\News\BlogExtendInfo;
use App\Models\RouteMap\RouteMap;
use App\Models\Template\BTemplate;
use App\Services\CosService;
... ... @@ -176,7 +176,7 @@ class NewsLogic extends BaseLogic
$this->delRoute($id);
$this->model->del(['id' => $id]);
//删除扩展字段
$extendInfoModel = new NewsExtendInfo();
$extendInfoModel = new BlogExtendInfo();
$extendInfoModel->del(['news_id'=>$id]);
}
}
... ...
<?php
/**
* @remark :
* @name :BlogExtend.php
* @author :lyh
* @method :post
* @time :2025/5/26 15:08
*/
namespace App\Models\Blog;
use App\Models\Base;
class BlogExtend extends Base
{
protected $table = 'gl_blog_extend';
protected $connection = 'custom_mysql';
const EXTEND_KEY = 'pd_extended_field_';
/**
* @remark :添加扩展字段
* @name :getKey
* @author :lyh
* @method :post
* @time :2025/5/26 15:39
*/
public function getKey($key = self::EXTEND_KEY,$i = 1){
$info = $this->read(['key'=>$key.$i]);
if($info !== false){
return $this->getKey($key,$i+1);
}else{
return $key.$i;
}
}
}
... ...
<?php
/**
* @remark :
* @name :BlogExtendInfo.php
* @author :lyh
* @method :post
* @time :2025/5/26 15:49
*/
namespace App\Models\Blog;
use App\Models\Base;
class BlogExtendInfo extends Base
{
protected $table = 'gl_blog_extend_info';
protected $connection = 'custom_mysql';
}
... ...
... ... @@ -41,12 +41,12 @@ class News extends Base
* @time :2023/12/6 14:43
*/
public function getExtendInfo($news_id){
$extendModel = new NewsExtend();
$extendModel = new BlogExtend();
$list = $extendModel->list(['status'=>1],'id',['id','type','key','title']);
if(empty($list)){
return [];
}
$extendInfoModel = new NewsExtendInfo();
$extendInfoModel = new BlogExtendInfo();
$infoList = $extendInfoModel->list(['news_id'=>$news_id],'created_at');
foreach ($list as $k=>$v){
if($v['type'] == 3 || $v['type'] == 4){
... ... @@ -111,7 +111,7 @@ class News extends Base
*/
public function saveExtendInfo($news_id,$extend,$project_id){
//先删除以前的数据
$extendInfoModel = new NewsExtendInfo();
$extendInfoModel = new BlogExtendInfo();
$extendInfoModel->del(['news_id'=>$news_id]);
if(empty($extend)) {
return true;
... ...
<?php
/**
* @remark :
* @name :NewsExtend.php
* @name :BlogExtend.php
* @author :lyh
* @method :post
* @time :2025/5/26 15:08
... ...
<?php
/**
* @remark :
* @name :NewsExtendInfo.php
* @name :BlogExtendInfo.php
* @author :lyh
* @method :post
* @time :2025/5/26 15:49
... ...