作者 刘锟

按需更新tdk

@@ -6,6 +6,7 @@ use App\Helper\Arr; @@ -6,6 +6,7 @@ use App\Helper\Arr;
6 use App\Helper\Common; 6 use App\Helper\Common;
7 use App\Helper\Gpt; 7 use App\Helper\Gpt;
8 use App\Models\Ai\AiCommand; 8 use App\Models\Ai\AiCommand;
  9 +use App\Models\Com\UpdateNotify;
9 use App\Models\Domain\DomainInfo; 10 use App\Models\Domain\DomainInfo;
10 use App\Models\Mail\Mail; 11 use App\Models\Mail\Mail;
11 use App\Models\Project\DeployBuild; 12 use App\Models\Project\DeployBuild;
@@ -135,6 +136,40 @@ class UpdateSeoTdk extends Command @@ -135,6 +136,40 @@ class UpdateSeoTdk extends Command
135 ]; 136 ];
136 137
137 /** 138 /**
  139 + * '表' => 'C端页面更新的数据类型'
  140 + * @return array
  141 + * @author akun
  142 + * @date 2024/11/14
  143 + */
  144 + protected $maps_type = [
  145 + 'gl_web_custom_template' => 'page',
  146 + 'gl_product' => 'product',
  147 + 'gl_product_category' => 'product_category',
  148 + 'gl_blog' => 'blog',
  149 + 'gl_blog_category' => 'blog_category',
  150 + 'gl_news' => 'news',
  151 + 'gl_news_category' => 'news_category',
  152 + 'gl_product_keyword' => 'product_keyword'
  153 + ];
  154 +
  155 + /**
  156 + * '表' => '对应数据路由字段'
  157 + * @return array
  158 + * @author akun
  159 + * @date 2024/11/14
  160 + */
  161 + protected $maps_route = [
  162 + 'gl_web_custom_template' => 'url',
  163 + 'gl_product' => 'route',
  164 + 'gl_product_category' => 'route',
  165 + 'gl_blog' => 'url',
  166 + 'gl_blog_category' => 'alias',
  167 + 'gl_news' => 'url',
  168 + 'gl_news_category' => 'alias',
  169 + 'gl_product_keyword' => 'route'
  170 + ];
  171 +
  172 + /**
138 * @return bool 173 * @return bool
139 */ 174 */
140 public function handle() 175 public function handle()
@@ -326,9 +361,15 @@ class UpdateSeoTdk extends Command @@ -326,9 +361,15 @@ class UpdateSeoTdk extends Command
326 $data[$json_field] = json_encode($data[$json_field]); 361 $data[$json_field] = json_encode($data[$json_field]);
327 } 362 }
328 DB::connection('custom_mysql')->table($table)->where(['id' => $v['id']])->update($data); 363 DB::connection('custom_mysql')->table($table)->where(['id' => $v['id']])->update($data);
329 - if($table == 'gl_product_keyword'){  
330 - $notify_keyword = true;  
331 - }else{ 364 +// if($table == 'gl_product_keyword'){
  365 +// $notify_keyword = true;
  366 +// }else{
  367 +// $notify_master = true;
  368 +// }
  369 + //tdk已更新的数据,存入按需更新表
  370 + $route = DB::connection('custom_mysql')->table($table)->where(['id' => $v['id']])->value($this->maps_route[$table]);
  371 + if($route){
  372 + UpdateNotify::addUpdateItem($project_id,$this->maps_type[$table],$route);
332 $notify_master = true; 373 $notify_master = true;
333 } 374 }
334 } 375 }
@@ -337,8 +378,9 @@ class UpdateSeoTdk extends Command @@ -337,8 +378,9 @@ class UpdateSeoTdk extends Command
337 ProjectUpdateTdk::finish($task_id, $update); 378 ProjectUpdateTdk::finish($task_id, $update);
338 379
339 //通知C端更新界面 380 //通知C端更新界面
340 - $notify_master && $this->sendNotify($project_id, 1); //通知主站更新  
341 - $notify_keyword && $this->sendNotify($project_id, 4); //通知聚合页更新 381 +// $notify_master && $this->sendNotify($project_id, 1); //通知主站更新
  382 +// $notify_keyword && $this->sendNotify($project_id, 4); //通知聚合页更新
  383 + $notify_master && $this->sendNotify($project_id, 2); //通知主站按需更新
342 } 384 }
343 385
344 public function getPrompt($project_id, $prompt, $table, $data){ 386 public function getPrompt($project_id, $prompt, $table, $data){
@@ -22,4 +22,19 @@ class UpdateNotify extends Base @@ -22,4 +22,19 @@ class UpdateNotify extends Base
22 22
23 const PAGE_ALL= 1;//所有 23 const PAGE_ALL= 1;//所有
24 const PAGE_SINGLE = 2;//按需 24 const PAGE_SINGLE = 2;//按需
  25 +
  26 + public static function addUpdateItem($project_id,$type,$route){
  27 + $data = self::where(['project_id'=>$project_id,'type'=>$type,'route'=>$route])->first();
  28 + if(!$data){
  29 + $data = new self();
  30 + $data->project_id = $project_id;
  31 + $data->type = $type;
  32 + $data->route = $route;
  33 + }
  34 +
  35 + $data->status = 0;
  36 + $data->minor_languages_status = 0;
  37 +
  38 + $data->save();
  39 + }
25 } 40 }