作者 lyh

列表页聚合页模式

  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :AiVideoAutoPublish.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2025/8/1 15:19
  8 + */
  9 +
  10 +namespace App\Console\Commands\Ai;
  11 +
  12 +use App\Models\Product\Product;
  13 +use App\Models\Project\DeployOptimize;
  14 +use App\Models\Project\Project;
  15 +use App\Models\WebSetting\WebSetting;
  16 +use App\Services\ProjectServer;
  17 +use Illuminate\Console\Command;
  18 +use Illuminate\Support\Facades\DB;
  19 +use Illuminate\Support\Facades\Log;
  20 +use App\Models\Project\AiVideoTask;
  21 +
  22 +/**
  23 + * @remark :ai视频自动发布
  24 + * @name :AiVideoAutoPublish
  25 + * @author :lyh
  26 + * @method :post
  27 + * @time :2025/8/1 15:19
  28 + */
  29 +class AiVideoAutoPublish extends Command
  30 +{
  31 + /**
  32 + * The name and signature of the console command.
  33 + *
  34 + * @var string
  35 + */
  36 + protected $signature = 'ai_video_auto_publish';
  37 +
  38 + /**
  39 + * The console command description.
  40 + *
  41 + * @var string
  42 + */
  43 + protected $description = '自动发布AI Video';
  44 +
  45 + public function handle(){
  46 +
  47 + }
  48 +
  49 + /**
  50 + * @remark :普通项目--自动发布
  51 + * @name :auto_publish
  52 + * @author :lyh
  53 + * @method :post
  54 + * @time :2025/8/1 15:22
  55 + */
  56 + public function auto_six_publish(){
  57 + $this->output('开始自动发布Video文章');
  58 + $projectModel = new Project();
  59 + $optimizeModel = new DeployOptimize();
  60 + $projectList = $projectModel->list(['is_ai_video'=>1,'project_type'=>0,'delete_status'=>0,'site_status'=>0,'extend_type'=>0],'id',['id']);
  61 + foreach ($projectList as $item){
  62 + $this->output("项目{$item['id']}开始自动发布");
  63 + //获取当前是否开启自动发布aiVideo
  64 + $opInfo = $optimizeModel->read(['project_id'=>$item['id']],['is_ai_video_send','send_ai_video_frequency','start_date']);
  65 + if($opInfo['is_ai_video_send'] != 1){
  66 + $this->output("项目{$item['id']}未开启自动发布" . $opInfo['start_date']);
  67 + continue;
  68 + }
  69 + if(($opInfo['start_date'] > date('Y-m-d')) || empty($opInfo['start_date'])){
  70 + $this->output("项目{$item['id']}未到推广时间" . $opInfo['start_date']);
  71 + continue;
  72 + }
  73 + $aiVideoTaskModel = new AiVideoTask();
  74 + $next_auto_date = $aiVideoTaskModel->formatQuery(['project_id'=>$item['id'],'next_auto_date'=>['!=',null]])->orderBy('id', 'desc')->value('next_auto_date');
  75 + if($next_auto_date && ($next_auto_date > date('Y-m-d'))){
  76 + $this->output("项目{$item['id']}未到执行时间" . $next_auto_date);
  77 + continue;
  78 + }
  79 + //获取当前网站的标题
  80 + ProjectServer::useProject($item['id']);
  81 + $data = $this->getProduct();
  82 + DB::disconnect('custom_mysql');
  83 + }
  84 + }
  85 +
  86 + /**
  87 + * @remark :获取产品标题+产品描述
  88 + * @name :getProduct
  89 + * @author :lyh
  90 + * @method :post
  91 + * @time :2025/8/1 16:09
  92 + */
  93 + public function getProduct(){
  94 + $data = [];
  95 + $productModel = new Product();
  96 + $info = $productModel->formatQuery(['gallery'=>['!=',null]])->select(['title','gallery','intro'])->inRandomOrder()->first();
  97 + if(empty($info)){
  98 + return $data;
  99 + }
  100 + $data['title'] = $info['title'];
  101 + $data['remark'] = $info['intro'];
  102 + $data['images'] = array_walk($info['gallery'], function (&$item) {$item['alt'] = $item['title'];unset($item['title']);});
  103 + if(count($data['images']) < 6){
  104 + //todo::需要生成图片
  105 + }
  106 + return $data;
  107 + }
  108 +
  109 + /**
  110 + * @remark :
  111 + * @name :getAiVideoParam
  112 + * @author :lyh
  113 + * @method :post
  114 + * @time :2025/8/1 16:25
  115 + */
  116 + public function getAiVideoParam()
  117 + {
  118 + $project_id = '1';
  119 + $domain = 'www.cs-conveyor.com';
  120 + try {
  121 + $sitemap_url = 'https://' . $domain . '/sitemap_post_tag.xml';
  122 + $sitemap_string = file_get_contents($sitemap_url);
  123 + $xml = new \SimpleXMLElement($sitemap_string);
  124 + $json = json_encode($xml);
  125 + $array = json_decode($json, true);
  126 + $urls = array_column($array['url'], 'loc');
  127 + $num = 0;
  128 + if ($num >= 10) {
  129 + return false;
  130 + }
  131 + AGAIN:
  132 + $url = $urls[array_rand($urls)];
  133 + $dom = file_get_html($url);
  134 + $h1 = $dom->find('.layout .global_section h1', 0);
  135 + $title = $h1 ? trim($h1->plaintext) : '';
  136 + $p = $dom->find('.layout .global_section p', 0);
  137 + $content = $p ? trim($p->plaintext) : '';
  138 + $img = $dom->find('.layout .global_section img');
  139 + $images = [];
  140 + foreach ($img as $item) {
  141 + if (empty($item->src) || empty($item->alt))
  142 + continue;
  143 + array_push($images, ['src' => $item->src, 'alt' => $item->alt]);
  144 + }
  145 + if (empty($title) || empty($content) || empty($images)) {
  146 + $num++;
  147 + goto AGAIN;
  148 + }
  149 + } catch (\Exception $e) {
  150 + echo 'project_id: ' . $project_id . ', domain: ' . $domain . ', error: ' . $e->getMessage() . PHP_EOL;
  151 + }
  152 + }
  153 +
  154 + /**
  155 + * @remark :日志
  156 + * @name :output
  157 + * @author :lyh
  158 + * @method :post
  159 + * @time :2025/8/1 15:28
  160 + */
  161 + public function output($message)
  162 + {
  163 + Log::channel('ai_video')->info($message);
  164 + echo date('Y-m-d H:i:s') . ' ' . $message . PHP_EOL;
  165 + }
  166 +}
@@ -37,7 +37,7 @@ class GoogleSearchController extends BaseController @@ -37,7 +37,7 @@ class GoogleSearchController extends BaseController
37 //查询详情数据 37 //查询详情数据
38 $searchDetailModel = new GoogleSearchDetail(); 38 $searchDetailModel = new GoogleSearchDetail();
39 $this->map['project_id'] = $this->user['project_id']; 39 $this->map['project_id'] = $this->user['project_id'];
40 - $data = $searchDetailModel->lists($this->map,$this->page,$this->row,'impressions',['keys','click_rate','position','impressions_rate']); 40 + $data = $searchDetailModel->lists($this->map,$this->page,$this->row,'impressions');
41 if(!empty($data)){ 41 if(!empty($data)){
42 if($this->param['type'] == 'country'){ 42 if($this->param['type'] == 'country'){
43 $codeCountryModel = new GoogleCodeCountry(); 43 $codeCountryModel = new GoogleCodeCountry();