作者 liyuhang

gx

@@ -10,6 +10,7 @@ use App\Models\Ai\AiLog; @@ -10,6 +10,7 @@ use App\Models\Ai\AiLog;
10 10
11 class AiCommandController extends BaseController 11 class AiCommandController extends BaseController
12 { 12 {
  13 + //获取文本内容
13 public $chat_url = 'v2/openai_chat'; 14 public $chat_url = 'v2/openai_chat';
14 /** 15 /**
15 * @name :ai生成 16 * @name :ai生成
@@ -89,21 +89,6 @@ class BlogLogic extends BaseLogic @@ -89,21 +89,6 @@ class BlogLogic extends BaseLogic
89 } 89 }
90 90
91 /** 91 /**
92 - * @param $category_id  
93 - * @name :产品计数  
94 - * @return bool  
95 - * @author :liyuhang  
96 - * @method  
97 - */  
98 - public function category_set_num($category_id){  
99 - $category_data = explode(',',trim($category_id,','));  
100 - foreach ($category_data as $v){  
101 - BlogCategoryModel::where('id',$v)->increment('num');  
102 - }  
103 - return true;  
104 - }  
105 -  
106 - /**  
107 * @name : 编辑博客 92 * @name : 编辑博客
108 * @return void 93 * @return void
109 * @author :liyuhang 94 * @author :liyuhang
@@ -208,10 +193,35 @@ class BlogLogic extends BaseLogic @@ -208,10 +193,35 @@ class BlogLogic extends BaseLogic
208 */ 193 */
209 public function blog_del(){ 194 public function blog_del(){
210 $ids = $this->param['id']; 195 $ids = $this->param['id'];
  196 + $str = $this->get_category_id($ids);
  197 + DB::beginTransaction();
  198 + try {
  199 + if(!empty($str)){
  200 + $category_data = explode(',',$str);
  201 + $this->set_num(NewsCategoryModel::class,$category_data,'del');
211 $this->param['id'] = ['in',$this->param['id']]; 202 $this->param['id'] = ['in',$this->param['id']];
212 $this->del($this->param,$ids); 203 $this->del($this->param,$ids);
213 - $this->set_num(BlogCategoryModel::class,'id','del',count($ids)); 204 + }
  205 + DB::commit();
  206 + }catch (Exception $e){
  207 + DB::rollBack();
  208 + $this->fail('当前数据不存在');
  209 + }
214 return $this->success(); 210 return $this->success();
215 } 211 }
216 - 212 + /**
  213 + * @param $ids
  214 + * @name :删除数据时获取所有数据的分类id
  215 + * @return void
  216 + * @author :liyuhang
  217 + * @method
  218 + */
  219 + public function get_category_id($ids = []){
  220 + $str = '';
  221 + $list = $this->model->list(['id'=>['in',$ids]],'id',['id','category_id']);
  222 + foreach ($list as $v){
  223 + $str .= trim($v['category_id'],',').',';
  224 + }
  225 + return trim($str,',');
  226 + }
217 } 227 }
@@ -10,6 +10,7 @@ use App\Models\News\News; @@ -10,6 +10,7 @@ use App\Models\News\News;
10 use App\Models\News\NewsCategory as NewsCategoryModel; 10 use App\Models\News\NewsCategory as NewsCategoryModel;
11 use App\Models\RouteMap; 11 use App\Models\RouteMap;
12 use Illuminate\Support\Facades\DB; 12 use Illuminate\Support\Facades\DB;
  13 +use mysql_xdevapi\Exception;
13 14
14 class NewsLogic extends BaseLogic 15 class NewsLogic extends BaseLogic
15 { 16 {
@@ -68,7 +69,7 @@ class NewsLogic extends BaseLogic @@ -68,7 +69,7 @@ class NewsLogic extends BaseLogic
68 $rs = $this->model->insertGetId($this->param); 69 $rs = $this->model->insertGetId($this->param);
69 //产品计数 70 //产品计数
70 $category_data = explode(',',trim($this->param['category_id'],',')); 71 $category_data = explode(',',trim($this->param['category_id'],','));
71 - $this->_set_num(NewsCategoryModel::class,$category_data); 72 + $this->set_num(NewsCategoryModel::class,$category_data);
72 RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']); 73 RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']);
73 DB::commit(); 74 DB::commit();
74 }catch (\Exception $e){ 75 }catch (\Exception $e){
@@ -95,7 +96,7 @@ class NewsLogic extends BaseLogic @@ -95,7 +96,7 @@ class NewsLogic extends BaseLogic
95 } 96 }
96 $this->param['operator_id'] = $this->user['id']; 97 $this->param['operator_id'] = $this->user['id'];
97 //多个分类按逗号隔开 98 //多个分类按逗号隔开
98 - $this->param['category_id'] = ','.$this->param['category_id'].','; 99 + $this->param['category_id'] = $this->param['category_id'];
99 DB::beginTransaction(); 100 DB::beginTransaction();
100 try { 101 try {
101 //上传图片 102 //上传图片
@@ -112,6 +113,7 @@ class NewsLogic extends BaseLogic @@ -112,6 +113,7 @@ class NewsLogic extends BaseLogic
112 } 113 }
113 $this->param['image'] = $this->upload(); 114 $this->param['image'] = $this->upload();
114 } 115 }
  116 + //设置路由
115 RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $this->param['id'], $this->user['project_id']); 117 RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $this->param['id'], $this->user['project_id']);
116 $this->model->edit($this->param,['id'=>$this->param['id']]); 118 $this->model->edit($this->param,['id'=>$this->param['id']]);
117 DB::commit(); 119 DB::commit();
@@ -181,10 +183,36 @@ class NewsLogic extends BaseLogic @@ -181,10 +183,36 @@ class NewsLogic extends BaseLogic
181 */ 183 */
182 public function news_del(){ 184 public function news_del(){
183 $ids = $this->param['id']; 185 $ids = $this->param['id'];
  186 + $str = $this->get_category_id($ids);
  187 + DB::beginTransaction();
  188 + try {
  189 + if(!empty($str)){
  190 + $category_data = explode(',',$str);
  191 + $this->set_num(NewsCategoryModel::class,$category_data,'del');
184 $this->param['id'] = ['in',$this->param['id']]; 192 $this->param['id'] = ['in',$this->param['id']];
185 $this->del($this->param,$ids); 193 $this->del($this->param,$ids);
186 - //数量自减  
187 - $this->set_num(NewsCategoryModel::class,'id','del',count($ids)); 194 + }
  195 + DB::commit();
  196 + }catch (Exception $e){
  197 + DB::rollBack();
  198 + $this->fail('当前数据不存在');
  199 + }
188 return $this->success(); 200 return $this->success();
189 } 201 }
  202 +
  203 + /**
  204 + * @param $ids
  205 + * @name :删除数据时获取所有数据的分类id
  206 + * @return void
  207 + * @author :liyuhang
  208 + * @method
  209 + */
  210 + public function get_category_id($ids){
  211 + $str = '';
  212 + $list = $this->model->list(['id'=>['in',$ids]],'id',['id','category_id']);
  213 + foreach ($list as $v){
  214 + $str .= trim($v['category_id'],',').',';
  215 + }
  216 + return trim($str,',');
  217 + }
190 } 218 }
@@ -26,6 +26,7 @@ class BlogCategoryRequest extends FormRequest @@ -26,6 +26,7 @@ class BlogCategoryRequest extends FormRequest
26 return [ 26 return [
27 'name'=>'required|max:100', 27 'name'=>'required|max:100',
28 'remark'=>'required|max:255', 28 'remark'=>'required|max:255',
  29 + 'alias'=>'required|max:10',
29 ]; 30 ];
30 } 31 }
31 32
@@ -36,6 +37,8 @@ class BlogCategoryRequest extends FormRequest @@ -36,6 +37,8 @@ class BlogCategoryRequest extends FormRequest
36 'name.max'=>'名称最大100字', 37 'name.max'=>'名称最大100字',
37 'remark.required'=>'请填写简介', 38 'remark.required'=>'请填写简介',
38 'remark.max'=>'简介最大255字', 39 'remark.max'=>'简介最大255字',
  40 + 'remark.required'=>'请填写别名',
  41 + 'remark.max'=>'别名最大10字',
39 ]; 42 ];
40 } 43 }
41 } 44 }
@@ -26,6 +26,7 @@ class NewsCategoryRequest extends FormRequest @@ -26,6 +26,7 @@ class NewsCategoryRequest extends FormRequest
26 return [ 26 return [
27 'name'=>'required|max:100', 27 'name'=>'required|max:100',
28 'remark'=>'required|max:255', 28 'remark'=>'required|max:255',
  29 + 'alias'=>'required|max:10',
29 ]; 30 ];
30 } 31 }
31 32
@@ -36,6 +37,8 @@ class NewsCategoryRequest extends FormRequest @@ -36,6 +37,8 @@ class NewsCategoryRequest extends FormRequest
36 'name.max'=>'名称最大100字', 37 'name.max'=>'名称最大100字',
37 'remark.required'=>'请填写简介', 38 'remark.required'=>'请填写简介',
38 'remark.max'=>'简介最大255字', 39 'remark.max'=>'简介最大255字',
  40 + 'remark.required'=>'请填写别名',
  41 + 'remark.max'=>'别名最大10字',
39 ]; 42 ];
40 } 43 }
41 } 44 }