作者 liyuhang

gx

... ... @@ -10,6 +10,7 @@ use App\Models\Ai\AiLog;
class AiCommandController extends BaseController
{
//获取文本内容
public $chat_url = 'v2/openai_chat';
/**
* @name :ai生成
... ...
... ... @@ -89,21 +89,6 @@ class BlogLogic extends BaseLogic
}
/**
* @param $category_id
* @name :产品计数
* @return bool
* @author :liyuhang
* @method
*/
public function category_set_num($category_id){
$category_data = explode(',',trim($category_id,','));
foreach ($category_data as $v){
BlogCategoryModel::where('id',$v)->increment('num');
}
return true;
}
/**
* @name : 编辑博客
* @return void
* @author :liyuhang
... ... @@ -208,10 +193,35 @@ class BlogLogic extends BaseLogic
*/
public function blog_del(){
$ids = $this->param['id'];
$this->param['id'] = ['in',$this->param['id']];
$this->del($this->param,$ids);
$this->set_num(BlogCategoryModel::class,'id','del',count($ids));
$str = $this->get_category_id($ids);
DB::beginTransaction();
try {
if(!empty($str)){
$category_data = explode(',',$str);
$this->set_num(NewsCategoryModel::class,$category_data,'del');
$this->param['id'] = ['in',$this->param['id']];
$this->del($this->param,$ids);
}
DB::commit();
}catch (Exception $e){
DB::rollBack();
$this->fail('当前数据不存在');
}
return $this->success();
}
/**
* @param $ids
* @name :删除数据时获取所有数据的分类id
* @return void
* @author :liyuhang
* @method
*/
public function get_category_id($ids = []){
$str = '';
$list = $this->model->list(['id'=>['in',$ids]],'id',['id','category_id']);
foreach ($list as $v){
$str .= trim($v['category_id'],',').',';
}
return trim($str,',');
}
}
... ...
... ... @@ -10,6 +10,7 @@ use App\Models\News\News;
use App\Models\News\NewsCategory as NewsCategoryModel;
use App\Models\RouteMap;
use Illuminate\Support\Facades\DB;
use mysql_xdevapi\Exception;
class NewsLogic extends BaseLogic
{
... ... @@ -68,7 +69,7 @@ class NewsLogic extends BaseLogic
$rs = $this->model->insertGetId($this->param);
//产品计数
$category_data = explode(',',trim($this->param['category_id'],','));
$this->_set_num(NewsCategoryModel::class,$category_data);
$this->set_num(NewsCategoryModel::class,$category_data);
RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']);
DB::commit();
}catch (\Exception $e){
... ... @@ -95,7 +96,7 @@ class NewsLogic extends BaseLogic
}
$this->param['operator_id'] = $this->user['id'];
//多个分类按逗号隔开
$this->param['category_id'] = ','.$this->param['category_id'].',';
$this->param['category_id'] = $this->param['category_id'];
DB::beginTransaction();
try {
//上传图片
... ... @@ -112,6 +113,7 @@ class NewsLogic extends BaseLogic
}
$this->param['image'] = $this->upload();
}
//设置路由
RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $this->param['id'], $this->user['project_id']);
$this->model->edit($this->param,['id'=>$this->param['id']]);
DB::commit();
... ... @@ -181,10 +183,36 @@ class NewsLogic extends BaseLogic
*/
public function news_del(){
$ids = $this->param['id'];
$this->param['id'] = ['in',$this->param['id']];
$this->del($this->param,$ids);
//数量自减
$this->set_num(NewsCategoryModel::class,'id','del',count($ids));
$str = $this->get_category_id($ids);
DB::beginTransaction();
try {
if(!empty($str)){
$category_data = explode(',',$str);
$this->set_num(NewsCategoryModel::class,$category_data,'del');
$this->param['id'] = ['in',$this->param['id']];
$this->del($this->param,$ids);
}
DB::commit();
}catch (Exception $e){
DB::rollBack();
$this->fail('当前数据不存在');
}
return $this->success();
}
/**
* @param $ids
* @name :删除数据时获取所有数据的分类id
* @return void
* @author :liyuhang
* @method
*/
public function get_category_id($ids){
$str = '';
$list = $this->model->list(['id'=>['in',$ids]],'id',['id','category_id']);
foreach ($list as $v){
$str .= trim($v['category_id'],',').',';
}
return trim($str,',');
}
}
... ...
... ... @@ -26,6 +26,7 @@ class BlogCategoryRequest extends FormRequest
return [
'name'=>'required|max:100',
'remark'=>'required|max:255',
'alias'=>'required|max:10',
];
}
... ... @@ -36,6 +37,8 @@ class BlogCategoryRequest extends FormRequest
'name.max'=>'名称最大100字',
'remark.required'=>'请填写简介',
'remark.max'=>'简介最大255字',
'remark.required'=>'请填写别名',
'remark.max'=>'别名最大10字',
];
}
}
... ...
... ... @@ -26,6 +26,7 @@ class NewsCategoryRequest extends FormRequest
return [
'name'=>'required|max:100',
'remark'=>'required|max:255',
'alias'=>'required|max:10',
];
}
... ... @@ -36,6 +37,8 @@ class NewsCategoryRequest extends FormRequest
'name.max'=>'名称最大100字',
'remark.required'=>'请填写简介',
'remark.max'=>'简介最大255字',
];
'remark.required'=>'请填写别名',
'remark.max'=>'别名最大10字',
];
}
}
... ...