作者 lyh

gx

@@ -141,17 +141,6 @@ class UpdateSeoTdk extends Command @@ -141,17 +141,6 @@ class UpdateSeoTdk extends Command
141 try { 141 try {
142 ProjectServer::useProject($project_id); 142 ProjectServer::useProject($project_id);
143 $this->seo_tdk($project_id); 143 $this->seo_tdk($project_id);
144 - } catch (\Exception $e) {  
145 - echo date('Y-m-d H:i:s') . ' line '. $e->getLine() .' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;  
146 - $this->updateProduct($project_id);  
147 - $this->updateProductCate($project_id);  
148 - $this->updateBlogs($project_id);  
149 - $this->updateBlogCate($project_id);  
150 - $this->updateNews($project_id);  
151 - $this->updateNewsCate($project_id);  
152 - $this->updatePage($project_id);  
153 - //发送站内信  
154 - $this->send_message($project_id);  
155 DB::disconnect('custom_mysql'); 144 DB::disconnect('custom_mysql');
156 }catch (\Exception $e){ 145 }catch (\Exception $e){
157 echo date('Y-m-d H:i:s') . ' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL; 146 echo date('Y-m-d H:i:s') . ' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;
@@ -162,19 +151,23 @@ class UpdateSeoTdk extends Command @@ -162,19 +151,23 @@ class UpdateSeoTdk extends Command
162 151
163 public function seo_tdk($project_id) 152 public function seo_tdk($project_id)
164 { 153 {
  154 + $data = [];
  155 + $update = [
  156 + 'created_at'=>date('Y-m-d H:i:s'),
  157 + ];//更新统计
165 $ai_commands = AiCommand::where('is_batch', 1)->select('key', 'scene', 'ai')->get()->toArray(); 158 $ai_commands = AiCommand::where('is_batch', 1)->select('key', 'scene', 'ai')->get()->toArray();
166 $ai_commands = Arr::setValueToKey($ai_commands, 'key'); 159 $ai_commands = Arr::setValueToKey($ai_commands, 'key');
167 -  
168 foreach ($this->maps as $table => $map) { 160 foreach ($this->maps as $table => $map) {
  161 + $update[$table] = ['total_page'=>0, 'title'=>0, 'keyword'=>0, 'des'=>0];
169 echo date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . PHP_EOL; 162 echo date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . PHP_EOL;
170 $list = DB::connection('custom_mysql')->table($table)->get()->toArray(); 163 $list = DB::connection('custom_mysql')->table($table)->get()->toArray();
171 if (!empty($list)) { 164 if (!empty($list)) {
172 foreach ($list as $v) { 165 foreach ($list as $v) {
  166 + $update[$table]['total_page']++;
173 $v = (array)$v; 167 $v = (array)$v;
174 echo date('Y-m-d H:i:s') . '更新--' . $table . ':id' . $v['id'] . PHP_EOL; 168 echo date('Y-m-d H:i:s') . '更新--' . $table . ':id' . $v['id'] . PHP_EOL;
175 $data = []; 169 $data = [];
176 $json_field = ''; 170 $json_field = '';
177 -  
178 foreach ($map as $ai_key => $field) { 171 foreach ($map as $ai_key => $field) {
179 $field_arr = explode('.', $field); 172 $field_arr = explode('.', $field);
180 if (count($field_arr) > 1) { 173 if (count($field_arr) > 1) {
@@ -194,10 +187,25 @@ class UpdateSeoTdk extends Command @@ -194,10 +187,25 @@ class UpdateSeoTdk extends Command
194 if(!$prompt){ 187 if(!$prompt){
195 continue; 188 continue;
196 } 189 }
197 -  
198 if (count($field_arr) > 1) { 190 if (count($field_arr) > 1) {
  191 + if($field_arr[1] == 'title'){
  192 + $update[$table]['title']++;
  193 + }elseif ($field_arr[1] == 'keyword'){
  194 + $update[$table]['keyword']++;
  195 + }elseif ($field_arr[1] == 'description'){
  196 + $update[$table]['des']++;
  197 + }
199 $data[$field_arr[0]][$field_arr[1]] = $this->ai_send($prompt); 198 $data[$field_arr[0]][$field_arr[1]] = $this->ai_send($prompt);
200 }else{ 199 }else{
  200 + if($field == 'title' || $field == 'seo_title'){
  201 + $update[$table]['title']++;
  202 + }
  203 + if($field == 'keywords' || $field == 'seo_keywords'){
  204 + $update[$table]['keyword']++;
  205 + }
  206 + if($field == 'seo_description' || $field == 'description'){
  207 + $update[$table]['des']++;
  208 + }
201 $data[$field] = $this->ai_send($prompt); 209 $data[$field] = $this->ai_send($prompt);
202 } 210 }
203 } else { 211 } else {
@@ -207,12 +215,32 @@ class UpdateSeoTdk extends Command @@ -207,12 +215,32 @@ class UpdateSeoTdk extends Command
207 //使用核心关键词 215 //使用核心关键词
208 if(in_array($ai_key, array_keys($this->core_keyword_keys))){ 216 if(in_array($ai_key, array_keys($this->core_keyword_keys))){
209 $data[$field_arr[0]][$field_arr[1]] = $this->mainKeywords($project_id, $this->core_keyword_keys[$ai_key]); 217 $data[$field_arr[0]][$field_arr[1]] = $this->mainKeywords($project_id, $this->core_keyword_keys[$ai_key]);
  218 + if(!empty($data[$field_arr[0]][$field_arr[1]])){
  219 + if($field_arr[1] == 'title'){
  220 + $data[$table]['title']++;
  221 + }elseif ($field_arr[1] == 'keyword'){
  222 + $data[$table]['keyword']++;
  223 + }elseif ($field_arr[1] == 'description'){
  224 + $data[$table]['des']++;
  225 + }
  226 + }
210 } 227 }
211 }else{ 228 }else{
212 $data[$field] = $v[$this->topic_fields[$table]] ?? ''; 229 $data[$field] = $v[$this->topic_fields[$table]] ?? '';
213 //使用核心关键词 230 //使用核心关键词
214 if(in_array($ai_key, array_keys($this->core_keyword_keys))){ 231 if(in_array($ai_key, array_keys($this->core_keyword_keys))){
215 $data[$field] = $this->mainKeywords($project_id, $this->core_keyword_keys[$ai_key]); 232 $data[$field] = $this->mainKeywords($project_id, $this->core_keyword_keys[$ai_key]);
  233 + if(!empty($data[$field_arr[0]][$field_arr[1]])){
  234 + if($field == 'title' || $field == 'seo_title'){
  235 + $update[$table]['title']++;
  236 + }
  237 + if($field == 'keywords' || $field == 'seo_keywords'){
  238 + $update[$table]['keyword']++;
  239 + }
  240 + if($field == 'seo_description' || $field == 'description'){
  241 + $update[$table]['des']++;
  242 + }
  243 + }
216 } 244 }
217 } 245 }
218 } 246 }
@@ -227,10 +255,12 @@ class UpdateSeoTdk extends Command @@ -227,10 +255,12 @@ class UpdateSeoTdk extends Command
227 } 255 }
228 $data[$json_field] = json_encode($data[$json_field]); 256 $data[$json_field] = json_encode($data[$json_field]);
229 } 257 }
  258 + $update[$table] = json_encode($update[$table]);
230 DB::connection('custom_mysql')->table($table)->where(['id' => $v['id']])->update($data); 259 DB::connection('custom_mysql')->table($table)->where(['id' => $v['id']])->update($data);
231 } 260 }
232 } 261 }
233 } 262 }
  263 + DB::table('gl_project_update_tdk')->insert($update);
234 } 264 }
235 265
236 public function getPrompt($project_id, $prompt, $table, $data){ 266 public function getPrompt($project_id, $prompt, $table, $data){