作者 lyh

列表页聚合页模式

@@ -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视频自动发布
@@ -104,7 +105,7 @@ class AiVideoAutoPublish extends Command @@ -104,7 +105,7 @@ class AiVideoAutoPublish extends Command
104 $random = rand(1, 2); 105 $random = rand(1, 2);
105 if($random == 1){//取产品 106 if($random == 1){//取产品
106 $productModel = new Product(); 107 $productModel = new Product();
107 - $info = $productModel->formatQuery(['title'=>['!=',null],'intro'=>['!=',null]])->select(['title','gallery','intro'])->inRandomOrder()->first(); 108 + $info = $productModel->formatQuery(['status'=>1,'title'=>['!=',null],'intro'=>['!=',null]])->select(['title','gallery','intro'])->inRandomOrder()->first();
108 if(empty($info)){ 109 if(empty($info)){
109 return $data; 110 return $data;
110 } 111 }
@@ -139,23 +140,30 @@ class AiVideoAutoPublish extends Command @@ -139,23 +140,30 @@ class AiVideoAutoPublish extends Command
139 * @time :2025/8/2 10:37 140 * @time :2025/8/2 10:37
140 */ 141 */
141 public function auto_send_video(){ 142 public function auto_send_video(){
  143 + $number = Redis::get('ai_video_image') ?? 0;
  144 + $aiVideoAutoLogModel = new AiVideoAutoLog();
142 while (true){ 145 while (true){
143 - $aiVideoAutoLogModel = new AiVideoAutoLog();  
144 - $lists = $aiVideoAutoLogModel->list(['status'=>0]);  
145 - if(empty($lists)){ 146 + if($number > 5){
  147 + sleep(300);
  148 + continue;
  149 + }
  150 + $item = $aiVideoAutoLogModel->read(['status'=>0]);
  151 + if(empty($info)){
146 sleep(60); 152 sleep(60);
  153 + continue;
147 } 154 }
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']]); 155 + if(count($item['images']) < 6){
  156 + //需要生成图片
  157 + $content = "{$item['remark']}{$item['title']}4K,高清 --no logo --ar 16:9";
  158 + $midJourneyService = new MidJourneyService();
  159 + $result = $midJourneyService->imagine($content);
  160 + if($result && !empty($result['trigger_id'])){
  161 + Redis::incr('ai_video_image');
  162 + $aiVideoAutoLogModel->edit(['trigger_id'=>$result['trigger_id']],['id'=>$item['id']]);
158 } 163 }
  164 + }else{
  165 + //提交到待执行
  166 + $aiVideoAutoLogModel->edit(['status'=>1],['id'=>$item['id']]);
159 } 167 }
160 } 168 }
161 } 169 }
@@ -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);