作者 lyh

GXgeo设置

  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :AiBlogTask.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2025/2/14 11:14
  8 + */
  9 +
  10 +namespace App\Console\Commands\Ai;
  11 +
  12 +use App\Models\Ai\AiBlog;
  13 +use App\Models\Ai\AiBlogAuthor;
  14 +use App\Models\Ai\AiBlogList;
  15 +use App\Models\Domain\DomainInfo;
  16 +use App\Models\Project\Project;
  17 +use App\Models\Project\ProjectAiSetting;
  18 +use App\Models\RouteMap\RouteMap;
  19 +use App\Services\AiBlogService;
  20 +use App\Services\ProjectServer;
  21 +use Illuminate\Console\Command;
  22 +use App\Models\Project\AiBlogTask as AiBlogTaskModel;
  23 +use Illuminate\Support\Facades\Cache;
  24 +use Illuminate\Support\Facades\DB;
  25 +use function Symfony\Component\String\s;
  26 +
  27 +/***
  28 + * @remark :根据项目更新blog列表
  29 + * @name :AiBlogListTask
  30 + * @author :lyh
  31 + * @method :post
  32 + * @time :2025/3/6 9:45
  33 + */
  34 +class AiBlogListAllTask extends Command
  35 +{
  36 + /**
  37 + * The name and signature of the console command.
  38 + *
  39 + * @var string
  40 + */
  41 + protected $signature = 'save_all_ai_blog_list';
  42 +
  43 + /**
  44 + * The console command description.
  45 + *
  46 + * @var string
  47 + */
  48 + protected $description = '生成blog列表';
  49 +
  50 + public function handle(){
  51 + $projectModel = new Project();
  52 + $lists = $projectModel->list(['delete_status' => 0,'project_type'=>0,'extend_type'=>0,'type'=>['in',[2,3,4,6]]], 'id', ['id']);
  53 + foreach ($lists as $item){
  54 + $project_id = $item['id'];
  55 + @file_put_contents(storage_path('logs/lyh_error.log'), var_export('执行的项目id->'.$project_id, true) . PHP_EOL, FILE_APPEND);
  56 + ProjectServer::useProject($project_id);
  57 + $projectAiSettingModel = new ProjectAiSetting();
  58 + $aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$project_id]);
  59 + $this->updateBlogList($aiSettingInfo);
  60 + $this->curlDelRoute($project_id);
  61 + DB::disconnect('custom_mysql');
  62 + }
  63 + return true;
  64 + }
  65 +
  66 + /**
  67 + * @remark :更新列表页数据
  68 + * @name :updateBlogList
  69 + * @author :lyh
  70 + * @method :post
  71 + * @time :2025/3/5 11:07
  72 + */
  73 + public function updateBlogList($aiSettingInfo){
  74 + $aiBlogService = new AiBlogService();
  75 + $aiBlogService->mch_id = $aiSettingInfo['mch_id'];
  76 + $aiBlogService->key = $aiSettingInfo['key'];
  77 + $page = 1;
  78 + $saveData = [];
  79 + $result = $aiBlogService->getAiBlogList($page,15);
  80 + if(!isset($result['status']) || $result['status'] != 200){
  81 + return true;
  82 + }
  83 + $total_page = $result['data']['total_page'];
  84 + //组装数据保存
  85 + $saveData[] = [
  86 + 'route'=>$page,
  87 + 'text'=>$result['data']['section'],
  88 + ];
  89 + while ($total_page > $page){
  90 + $page++;
  91 + $result = $aiBlogService->getAiBlogList($page,15);
  92 + if(isset($result['status']) && $result['status'] == 200){
  93 + $saveData[] = [
  94 + 'route'=>$page,
  95 + 'text'=>$result['data']['section'],
  96 + ];
  97 + }
  98 + }
  99 + $aiBlogListModel = new AiBlogList();
  100 + if(!empty($saveData)){
  101 + //写一条路由信息
  102 + $aiBlogListModel->truncate();
  103 + $aiBlogListModel->insertAll($saveData);
  104 + }
  105 + return true;
  106 + }
  107 +
  108 + /**
  109 + * @remark :通知C端生成界面
  110 + * @name :sendNotice
  111 + * @author :lyh
  112 + * @method :post
  113 + * @time :2025/3/6 11:51
  114 + */
  115 + public function curlDelRoute($project_id){
  116 + $domainModel = new DomainInfo();
  117 + //获取项目域名
  118 + $domain = $domainModel->getProjectIdDomain($project_id);
  119 + if(!empty($domain)){
  120 + $c_url = $domain.'api/update_page/';
  121 + $param = [
  122 + 'project_id' => $project_id,
  123 + 'type' => 1,
  124 + 'route' => 3,
  125 + 'url' => ['top-blog'],
  126 + 'language'=> [],
  127 + 'is_sitemap' => 0
  128 + ];
  129 + http_post($c_url, json_encode($param));
  130 + }
  131 + return true;
  132 + }
  133 +}