作者 lyh

gx

@@ -391,6 +391,8 @@ class UpdateSeoTdk extends Command @@ -391,6 +391,8 @@ class UpdateSeoTdk extends Command
391 'keywords'=>$keywords, 391 'keywords'=>$keywords,
392 ]; 392 ];
393 $data = Common::send_openai_msg($chat_url,$param,$name); 393 $data = Common::send_openai_msg($chat_url,$param,$name);
  394 + $data['text'] = Common::deal_keywords($data['text']);
  395 + $data['text'] = Common::deal_str($data['text']);
394 return $data['text']; 396 return $data['text'];
395 } 397 }
396 398
@@ -188,7 +188,7 @@ class Common @@ -188,7 +188,7 @@ class Common
188 } 188 }
189 189
190 //处理关键词 190 //处理关键词
191 - public function deal_keywords($data){ 191 + public static function deal_keywords($data){
192 $str = ['1. ','2. ','3. ','4. ','5. ','6. ','7. ','8. ','1) ','2) ','3) ','4) ','5) ','6) ','7) ','7) ','8) ']; 192 $str = ['1. ','2. ','3. ','4. ','5. ','6. ','7. ','8. ','1) ','2) ','3) ','4) ','5) ','6) ','7) ','7) ','8) '];
193 $ar_keywords_t = explode("\n",$data); 193 $ar_keywords_t = explode("\n",$data);
194 $ar_keywords = []; 194 $ar_keywords = [];
@@ -218,7 +218,7 @@ class Common @@ -218,7 +218,7 @@ class Common
218 218
219 219
220 //过滤特殊字符 220 //过滤特殊字符
221 - public function deal_str($str){ 221 + public static function deal_str($str){
222 return str_replace(['{','}','”','“','"'],'',$str); 222 return str_replace(['{','}','”','“','"'],'',$str);
223 } 223 }
224 } 224 }
@@ -38,119 +38,6 @@ class UpdateController extends BaseController @@ -38,119 +38,6 @@ class UpdateController extends BaseController
38 'project_id.required' => 'project_id不能为空', 38 'project_id.required' => 'project_id不能为空',
39 ]); 39 ]);
40 Redis::lpush('updateSeoTdk', $this->param['project_id']); 40 Redis::lpush('updateSeoTdk', $this->param['project_id']);
41 -// ProjectServer::useProject($this->param['project_id']);  
42 -// $this->updateProduct($this->param['project_id']);  
43 -// $this->updateBlogs($this->param['project_id']);  
44 -// $this->updateNews($this->param['project_id']);  
45 -// DB::disconnect('custom_mysql');  
46 $this->response('任务添加成功'); 41 $this->response('任务添加成功');
47 } 42 }
48 -  
49 - /**  
50 - * @remark :更新产品tdk  
51 - * @name :updateProduct  
52 - * @author :lyh  
53 - * @method :post  
54 - * @time :2023/8/19 9:25  
55 - */  
56 - public function updateProduct($project_id){  
57 - $list = DB::connection('custom_mysql')->table('gl_product')->where(['status'=>1,'project_id'=>$project_id])->get()->toArray();  
58 - if(!empty($list)){  
59 - foreach ($list as $v){  
60 - $v = (array)$v;  
61 - if(!empty($v['seo_mate'])){  
62 - $seo_arr = json_decode($v['seo_mate'], true);  
63 - //更新seo_title  
64 - if(!isset($seo_arr['title'])){  
65 - //生成seo_title  
66 - $seo_arr['title'] = $this->ai_send('product_seo_title',$v['title']);  
67 - }  
68 - //更新seo_keyword  
69 - if(!isset($seo_arr['keyword'])){  
70 - $seo_arr['keyword'] = $this->ai_send('product_seo_keyword',$v['title']);  
71 - }  
72 - //更新seo_keyword  
73 - if(!isset($seo_arr['description'])){  
74 - $seo_arr['description'] = $this->ai_send('product_seo_description',$v['title']);  
75 - }  
76 - $ser_str = json_encode($seo_arr,true);  
77 - DB::connection('custom_mysql')->table('gl_product')->where(['id'=>$v['id']])->update(['seo_mate'=>$ser_str]);  
78 - }  
79 - }  
80 - }  
81 - return true;  
82 - }  
83 -  
84 - /**  
85 - * @remark :更新新闻Tdk  
86 - * @name :updateNews  
87 - * @author :lyh  
88 - * @method :post  
89 - * @time :2023/8/19 10:06  
90 - */  
91 - public function updateNews($project_id){  
92 - $list = DB::connection('custom_mysql')->table('gl_news')->where(['status'=>1,'project_id'=>$project_id])->get()->toArray();  
93 - if(!empty($list)){  
94 - foreach ($list as $k => $v){  
95 - $v = (array)$v;  
96 - $data = [];  
97 - if(empty($v['seo_title'])){  
98 - $data['seo_title'] = $this->ai_send('news_seo_title',$v['name']);  
99 - }  
100 - if(empty($v['seo_keywords'])){  
101 - $data['seo_keywords'] = $this->ai_send('news_seo_keyword',$v['name']);  
102 - }  
103 - if(empty($v['seo_description'])){  
104 - $data['seo_description'] = $this->ai_send('news_seo_description',$v['name']);  
105 - }  
106 - DB::connection('custom_mysql')->table('gl_news')->where(['id'=>$v['id']])->update($data);  
107 - }  
108 - }  
109 - return true;  
110 - }  
111 -  
112 - /**  
113 - * @remark :更新blogTdk  
114 - * @name :updateBlogs  
115 - * @author :lyh  
116 - * @method :post  
117 - * @time :2023/8/19 10:07  
118 - */  
119 - public function updateBlogs($project_id){  
120 - $list = DB::connection('custom_mysql')->table('gl_blog')->where(['status'=>1,'project_id'=>$project_id])->get()->toArray();  
121 - if(!empty($list)){  
122 - foreach ($list as $k => $v){  
123 - $v = (array)$v;  
124 - $data = [];  
125 - if(empty($v['seo_title'])){  
126 - $data['seo_title'] = $this->ai_send('blog_seo_title',$v['name']);  
127 - }  
128 - if(empty($v['seo_keywords'])){  
129 - $data['seo_keywords'] = $this->ai_send('blog_seo_keyword',$v['name']);  
130 - }  
131 - if(empty($v['seo_description'])){  
132 - $data['seo_description'] = $this->ai_send('blog_seo_description',$v['name']);  
133 - }  
134 - DB::connection('custom_mysql')->table('gl_product')->where(['id'=>$v['id']])->update($data);  
135 - }  
136 - }  
137 - return true;  
138 - }  
139 -  
140 - /**  
141 - * @remark :AI发送  
142 - * @name :ai_send  
143 - * @author :lyh  
144 - * @method :post  
145 - * @time :2023/8/19 10:40  
146 - */  
147 - public function ai_send($key,$keywords){  
148 - $chat_url = 'v2/openai_chat';  
149 - $param = [  
150 - 'key'=>$key,  
151 - 'keywords'=>$keywords,  
152 - ];  
153 - $data = Common::send_openai_msg($chat_url,$param);  
154 - return $data['text'];  
155 - }  
156 } 43 }
@@ -30,6 +30,8 @@ class AiCommandController extends BaseController @@ -30,6 +30,8 @@ class AiCommandController extends BaseController
30 ]); 30 ]);
31 #TODO 通过key获取到ai指令对象 31 #TODO 通过key获取到ai指令对象
32 $data = Common::send_openai_msg($this->chat_url,$this->param,$this->companyName($this->user['project_id'])); 32 $data = Common::send_openai_msg($this->chat_url,$this->param,$this->companyName($this->user['project_id']));
  33 + $data['text'] = Common::deal_keywords($data['text']);
  34 + $data['text'] = Common::deal_str($data['text']);
33 $param = [ 35 $param = [
34 'key'=>$this->param['key'], 36 'key'=>$this->param['key'],
35 'keywords'=>$this->param['keywords'], 37 'keywords'=>$this->param['keywords'],
1 -<?php  
2 -/**  
3 - * @remark :  
4 - * @name :UpdateController.php  
5 - * @author :lyh  
6 - * @method :post  
7 - * @time :2023/8/19 9:08  
8 - */  
9 -  
10 -namespace App\Http\Controllers\Bside\BCom;  
11 -  
12 -use App\Helper\Common;  
13 -use App\Http\Controllers\Bside\BaseController;  
14 -use App\Models\Blog\Blog;  
15 -use App\Models\News\News;  
16 -use App\Models\Product\Product;  
17 -  
18 -/**  
19 - * @remark :b端网站更新相关  
20 - * @name :UpdateController  
21 - * @author :lyh  
22 - * @method :post  
23 - * @time :2023/8/19 9:08  
24 - */  
25 -class UpdateController extends BaseController  
26 -{  
27 - /**  
28 - * @remark :一键更新所有tdk  
29 - * @name :updateSeoTdk  
30 - * @author :lyh  
31 - * @method :post  
32 - * @time :2023/8/19 9:25  
33 - */  
34 - public function updateSeoTdk(){  
35 - $this->updateProduct();  
36 - $this->updateBlogs();  
37 - $this->updateNews();  
38 - $this->response('success');  
39 - }  
40 -  
41 - /**  
42 - * @remark :更新产品tdk  
43 - * @name :updateProduct  
44 - * @author :lyh  
45 - * @method :post  
46 - * @time :2023/8/19 9:25  
47 - */  
48 - public function updateProduct(){  
49 - $productModel = new Product();  
50 - $list = $productModel->list(['status'=>Product::STATUS_ON,'project_id'=>$this->user['project_id']],'id',['id','seo_mate','title']);  
51 - if(!empty($list)){  
52 - foreach ($list as $v){  
53 - if(!empty($v['seo_mate'])){  
54 - $seo_arr = $v['seo_mate'];  
55 - //更新seo_title  
56 - if(!isset($seo_arr['title'])){  
57 - //生成seo_title  
58 - $seo_arr['title'] = $this->ai_send('product_seo_title',$v['title']);  
59 - }  
60 - //更新seo_keyword  
61 - if(!isset($seo_arr['keyword'])){  
62 - $seo_arr['keyword'] = $this->ai_send('product_seo_keyword',$v['title']);  
63 - }  
64 - //更新seo_keyword  
65 - if(!isset($seo_arr['description'])){  
66 - $seo_arr['description'] = $this->ai_send('product_seo_description',$v['title']);  
67 - }  
68 - $ser_str = json_encode($seo_arr,true);  
69 - $productModel->edit(['seo_mate'=>$ser_str],['id'=>$v['id']]);  
70 - }  
71 - }  
72 - }  
73 - return true;  
74 - }  
75 -  
76 - /**  
77 - * @remark :更新新闻Tdk  
78 - * @name :updateNews  
79 - * @author :lyh  
80 - * @method :post  
81 - * @time :2023/8/19 10:06  
82 - */  
83 - public function updateNews(){  
84 - $newsModel = new News();  
85 - $list = $newsModel->list(['status'=>$newsModel::STATUS_ONE],'id',['id','name','seo_title','seo_keywords','seo_description']);  
86 - if(!empty($list)){  
87 - foreach ($list as $k => $v){  
88 - $data = [];  
89 - if(empty($v['seo_title'])){  
90 - $data['seo_title'] = $this->ai_send('news_seo_title',$v['name']);  
91 - }  
92 - if(empty($v['seo_keywords'])){  
93 - $data['seo_keywords'] = $this->ai_send('news_seo_keyword',$v['name']);  
94 - }  
95 - if(empty($v['seo_description'])){  
96 - $data['seo_description'] = $this->ai_send('news_seo_description',$v['name']);  
97 - }  
98 - $newsModel->edit($data,['id'=>$v['id']]);  
99 - }  
100 - }  
101 - return true;  
102 - }  
103 -  
104 - /**  
105 - * @remark :更新blogTdk  
106 - * @name :updateBlogs  
107 - * @author :lyh  
108 - * @method :post  
109 - * @time :2023/8/19 10:07  
110 - */  
111 - public function updateBlogs(){  
112 - $blogModel = new Blog();  
113 - $list = $blogModel->list(['status'=>$blogModel::STATUS_ONE]);  
114 - if(!empty($list)){  
115 - foreach ($list as $k => $v){  
116 - $data = [];  
117 - if(empty($v['seo_title'])){  
118 - $data['seo_title'] = $this->ai_send('blog_seo_title',$v['name']);  
119 - }  
120 - if(empty($v['seo_keywords'])){  
121 - $data['seo_keywords'] = $this->ai_send('blog_seo_keyword',$v['name']);  
122 - }  
123 - if(empty($v['seo_description'])){  
124 - $data['seo_description'] = $this->ai_send('blog_seo_description',$v['name']);  
125 - }  
126 - $blogModel->edit($data,['id'=>$v['id']]);  
127 - }  
128 - }  
129 - return true;  
130 - }  
131 -  
132 - /**  
133 - * @remark :AI发送  
134 - * @name :ai_send  
135 - * @author :lyh  
136 - * @method :post  
137 - * @time :2023/8/19 10:40  
138 - */  
139 - public function ai_send($key,$keywords){  
140 - $chat_url = 'v2/openai_chat';  
141 - $param = [  
142 - 'key'=>$key,  
143 - 'keywords'=>$keywords,  
144 - ];  
145 - $data = Common::send_openai_msg($chat_url,$param);  
146 - return $data['text'];  
147 - }  
148 -}