作者 李宇航

合并分支 'lyh-server' 到 'master'

Lyh server



查看合并请求 !2485
@@ -20,6 +20,7 @@ use Illuminate\Console\Command; @@ -20,6 +20,7 @@ use Illuminate\Console\Command;
20 use Illuminate\Support\Facades\DB; 20 use Illuminate\Support\Facades\DB;
21 use Illuminate\Support\Facades\Log; 21 use Illuminate\Support\Facades\Log;
22 use App\Models\Project\AiVideoTask; 22 use App\Models\Project\AiVideoTask;
  23 +use Illuminate\Support\Facades\Redis;
23 24
24 /** 25 /**
25 * @remark :ai视频自动发布 26 * @remark :ai视频自动发布
@@ -45,7 +46,10 @@ class AiVideoAutoPublish extends Command @@ -45,7 +46,10 @@ class AiVideoAutoPublish extends Command
45 protected $description = '自动发布AI Video'; 46 protected $description = '自动发布AI Video';
46 47
47 public function handle(){ 48 public function handle(){
48 - 49 + $action = $this->argument('action');
  50 + if($action == 'auto_publish'){
  51 + $this->auto_publish();
  52 + }
49 } 53 }
50 54
51 /** 55 /**
@@ -104,7 +108,7 @@ class AiVideoAutoPublish extends Command @@ -104,7 +108,7 @@ class AiVideoAutoPublish extends Command
104 $random = rand(1, 2); 108 $random = rand(1, 2);
105 if($random == 1){//取产品 109 if($random == 1){//取产品
106 $productModel = new Product(); 110 $productModel = new Product();
107 - $info = $productModel->formatQuery(['title'=>['!=',null],'intro'=>['!=',null]])->select(['title','gallery','intro'])->inRandomOrder()->first(); 111 + $info = $productModel->formatQuery(['status'=>1,'title'=>['!=',null],'intro'=>['!=',null]])->select(['title','gallery','intro'])->inRandomOrder()->first();
108 if(empty($info)){ 112 if(empty($info)){
109 return $data; 113 return $data;
110 } 114 }
@@ -139,23 +143,30 @@ class AiVideoAutoPublish extends Command @@ -139,23 +143,30 @@ class AiVideoAutoPublish extends Command
139 * @time :2025/8/2 10:37 143 * @time :2025/8/2 10:37
140 */ 144 */
141 public function auto_send_video(){ 145 public function auto_send_video(){
  146 + $number = Redis::get('ai_video_image') ?? 0;
  147 + $aiVideoAutoLogModel = new AiVideoAutoLog();
142 while (true){ 148 while (true){
143 - $aiVideoAutoLogModel = new AiVideoAutoLog();  
144 - $lists = $aiVideoAutoLogModel->list(['status'=>0]);  
145 - if(empty($lists)){ 149 + if($number > 5){
  150 + sleep(300);
  151 + continue;
  152 + }
  153 + $item = $aiVideoAutoLogModel->read(['status'=>0]);
  154 + if(empty($info)){
146 sleep(60); 155 sleep(60);
  156 + continue;
147 } 157 }
148 - foreach ($lists as $item){  
149 - if(count($item['images']) < 6){  
150 - //需要生成图片  
151 - $content = "{$item['remark']}{$item['title']}4K,高清 --no logo --ar 16:9";  
152 - $midJourneyService = new MidJourneyService();  
153 - $result = $midJourneyService->imagine($content);  
154 - dd($result);  
155 - }else{  
156 - //提交到待执行  
157 - $aiVideoAutoLogModel->edit(['status'=>1],['id'=>$item['id']]); 158 + if(count($item['images']) < 6){
  159 + //需要生成图片
  160 + $content = "{$item['remark']}{$item['title']}4K,高清 --no logo --ar 16:9";
  161 + $midJourneyService = new MidJourneyService();
  162 + $result = $midJourneyService->imagine($content);
  163 + if($result && !empty($result['trigger_id'])){
  164 + Redis::incr('ai_video_image');
  165 + $aiVideoAutoLogModel->edit(['trigger_id'=>$result['trigger_id']],['id'=>$item['id']]);
158 } 166 }
  167 + }else{
  168 + //提交到待执行
  169 + $aiVideoAutoLogModel->edit(['status'=>1],['id'=>$item['id']]);
159 } 170 }
160 } 171 }
161 } 172 }
@@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
10 namespace App\Http\Controllers\Api; 10 namespace App\Http\Controllers\Api;
11 11
12 use App\Enums\Common\Code; 12 use App\Enums\Common\Code;
  13 +use App\Models\Project\AiVideoAutoLog;
13 14
14 class AiVideoController extends BaseController 15 class AiVideoController extends BaseController
15 { 16 {
@@ -23,6 +24,8 @@ class AiVideoController extends BaseController @@ -23,6 +24,8 @@ class AiVideoController extends BaseController
23 public function ImageCallBack(){ 24 public function ImageCallBack(){
24 $data = $this->param; 25 $data = $this->param;
25 @file_put_contents(storage_path('logs/lyh_error.log'), var_export($data, true) . PHP_EOL, FILE_APPEND); 26 @file_put_contents(storage_path('logs/lyh_error.log'), var_export($data, true) . PHP_EOL, FILE_APPEND);
  27 +// $aiVideoAutoLogModel = new AiVideoAutoLog();
  28 +// $aiVideoAutoLogModel->edit(['result'=>$data],['trigger_id'=>$data['trigger_id']]);
26 $this->response('success'); 29 $this->response('success');
27 } 30 }
28 } 31 }
@@ -108,7 +108,6 @@ class CosService @@ -108,7 +108,6 @@ class CosService
108 { 108 {
109 if(!$key){ 109 if(!$key){
110 $url_arr = parse_url($file_url); 110 $url_arr = parse_url($file_url);
111 -  
112 if($same_name){ 111 if($same_name){
113 $path_arr = explode('/',$url_arr['path']); 112 $path_arr = explode('/',$url_arr['path']);
114 $filename = end($path_arr); 113 $filename = end($path_arr);