作者 lyh

gx

... ... @@ -141,17 +141,6 @@ class UpdateSeoTdk extends Command
try {
ProjectServer::useProject($project_id);
$this->seo_tdk($project_id);
} catch (\Exception $e) {
echo date('Y-m-d H:i:s') . ' line '. $e->getLine() .' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;
$this->updateProduct($project_id);
$this->updateProductCate($project_id);
$this->updateBlogs($project_id);
$this->updateBlogCate($project_id);
$this->updateNews($project_id);
$this->updateNewsCate($project_id);
$this->updatePage($project_id);
//发送站内信
$this->send_message($project_id);
DB::disconnect('custom_mysql');
}catch (\Exception $e){
echo date('Y-m-d H:i:s') . ' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;
... ... @@ -162,19 +151,23 @@ class UpdateSeoTdk extends Command
public function seo_tdk($project_id)
{
$data = [];
$update = [
'created_at'=>date('Y-m-d H:i:s'),
];//更新统计
$ai_commands = AiCommand::where('is_batch', 1)->select('key', 'scene', 'ai')->get()->toArray();
$ai_commands = Arr::setValueToKey($ai_commands, 'key');
foreach ($this->maps as $table => $map) {
$update[$table] = ['total_page'=>0, 'title'=>0, 'keyword'=>0, 'des'=>0];
echo date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . PHP_EOL;
$list = DB::connection('custom_mysql')->table($table)->get()->toArray();
if (!empty($list)) {
foreach ($list as $v) {
$update[$table]['total_page']++;
$v = (array)$v;
echo date('Y-m-d H:i:s') . '更新--' . $table . ':id' . $v['id'] . PHP_EOL;
$data = [];
$json_field = '';
foreach ($map as $ai_key => $field) {
$field_arr = explode('.', $field);
if (count($field_arr) > 1) {
... ... @@ -194,10 +187,25 @@ class UpdateSeoTdk extends Command
if(!$prompt){
continue;
}
if (count($field_arr) > 1) {
if($field_arr[1] == 'title'){
$update[$table]['title']++;
}elseif ($field_arr[1] == 'keyword'){
$update[$table]['keyword']++;
}elseif ($field_arr[1] == 'description'){
$update[$table]['des']++;
}
$data[$field_arr[0]][$field_arr[1]] = $this->ai_send($prompt);
}else{
if($field == 'title' || $field == 'seo_title'){
$update[$table]['title']++;
}
if($field == 'keywords' || $field == 'seo_keywords'){
$update[$table]['keyword']++;
}
if($field == 'seo_description' || $field == 'description'){
$update[$table]['des']++;
}
$data[$field] = $this->ai_send($prompt);
}
} else {
... ... @@ -207,12 +215,32 @@ class UpdateSeoTdk extends Command
//使用核心关键词
if(in_array($ai_key, array_keys($this->core_keyword_keys))){
$data[$field_arr[0]][$field_arr[1]] = $this->mainKeywords($project_id, $this->core_keyword_keys[$ai_key]);
if(!empty($data[$field_arr[0]][$field_arr[1]])){
if($field_arr[1] == 'title'){
$data[$table]['title']++;
}elseif ($field_arr[1] == 'keyword'){
$data[$table]['keyword']++;
}elseif ($field_arr[1] == 'description'){
$data[$table]['des']++;
}
}
}
}else{
$data[$field] = $v[$this->topic_fields[$table]] ?? '';
//使用核心关键词
if(in_array($ai_key, array_keys($this->core_keyword_keys))){
$data[$field] = $this->mainKeywords($project_id, $this->core_keyword_keys[$ai_key]);
if(!empty($data[$field_arr[0]][$field_arr[1]])){
if($field == 'title' || $field == 'seo_title'){
$update[$table]['title']++;
}
if($field == 'keywords' || $field == 'seo_keywords'){
$update[$table]['keyword']++;
}
if($field == 'seo_description' || $field == 'description'){
$update[$table]['des']++;
}
}
}
}
}
... ... @@ -227,10 +255,12 @@ class UpdateSeoTdk extends Command
}
$data[$json_field] = json_encode($data[$json_field]);
}
$update[$table] = json_encode($update[$table]);
DB::connection('custom_mysql')->table($table)->where(['id' => $v['id']])->update($data);
}
}
}
DB::table('gl_project_update_tdk')->insert($update);
}
public function getPrompt($project_id, $prompt, $table, $data){
... ...