作者 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,21 @@ class UpdateSeoTdk extends Command
public function seo_tdk($project_id)
{
$data = [];
$update = [];//更新统计
$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) {
... ... @@ -196,8 +187,24 @@ class UpdateSeoTdk extends Command
}
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 +214,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,6 +254,7 @@ 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);
}
}
... ...
... ... @@ -33,12 +33,12 @@ class BlogLogic extends BaseLogic
DB::beginTransaction();
try {
$this->param = $this->paramProcessing($this->param);
$this->param['url'] = $this->param['url'].'-'.RouteMap::SOURCE_BLOG;
if(isset($this->param['id']) && !empty($this->param['id'])){
//是否更新路由
$id = $this->editNewsRoute($this->param['id'],$this->param['url']);
$this->edit($this->param,['id'=>$this->param['id']]);
}else{
$this->param['url'] = $this->param['url'].'-'.RouteMap::SOURCE_BLOG;
$id = $this->model->addReturnId($this->param);
}
$route = RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_BLOG, $id, $this->user['project_id']);
... ...
... ... @@ -62,12 +62,12 @@ class NewsLogic extends BaseLogic
DB::beginTransaction();
try {
$this->param = $this->paramProcessing($this->param);
$this->param['url'] = $this->param['url'].'-'.RouteMap::SOURCE_NEWS;
if (isset($this->param['id']) && !empty($this->param['id'])) {
//是否更新路由
$id = $this->editNewsRoute($this->param['id'], $this->param['url']);
$this->edit($this->param, ['id' => $this->param['id']]);
} else {
$this->param['url'] = $this->param['url'].'-'.RouteMap::SOURCE_NEWS;
$id = $this->model->addReturnId($this->param);
}
//更新路由
... ...