作者 lyh

列表页聚合页模式

@@ -9,11 +9,14 @@ @@ -9,11 +9,14 @@
9 9
10 namespace App\Console\Commands\Ai; 10 namespace App\Console\Commands\Ai;
11 11
  12 +use App\Models\Ai\AiVideo;
12 use App\Models\Product\Keyword; 13 use App\Models\Product\Keyword;
13 use App\Models\Product\Product; 14 use App\Models\Product\Product;
  15 +use App\Models\Project\AiBlogTask as AiBlogTaskModel;
14 use App\Models\Project\AiVideoAutoLog; 16 use App\Models\Project\AiVideoAutoLog;
15 use App\Models\Project\DeployOptimize; 17 use App\Models\Project\DeployOptimize;
16 use App\Models\Project\Project; 18 use App\Models\Project\Project;
  19 +use App\Services\AiVideoService;
17 use App\Services\MidJourneyService; 20 use App\Services\MidJourneyService;
18 use App\Services\ProjectServer; 21 use App\Services\ProjectServer;
19 use Illuminate\Console\Command; 22 use Illuminate\Console\Command;
@@ -63,7 +66,7 @@ class AiVideoAutoPublish extends Command @@ -63,7 +66,7 @@ class AiVideoAutoPublish extends Command
63 $this->output('开始自动发布Video文章'); 66 $this->output('开始自动发布Video文章');
64 $projectModel = new Project(); 67 $projectModel = new Project();
65 $optimizeModel = new DeployOptimize(); 68 $optimizeModel = new DeployOptimize();
66 - $projectList = $projectModel->list(['is_ai_video'=>1,'project_type'=>0,'delete_status'=>0,'site_status'=>0,'extend_type'=>0],'id',['id']); 69 + $projectList = $projectModel->list(['is_ai_video'=>1,'id'=>1,'project_type'=>0,'delete_status'=>0,'site_status'=>0,'extend_type'=>0],'id',['id']);
67 foreach ($projectList as $item){ 70 foreach ($projectList as $item){
68 $this->output("项目{$item['id']}开始自动发布"); 71 $this->output("项目{$item['id']}开始自动发布");
69 //获取当前是否开启自动发布aiVideo 72 //获取当前是否开启自动发布aiVideo
@@ -147,11 +150,13 @@ class AiVideoAutoPublish extends Command @@ -147,11 +150,13 @@ class AiVideoAutoPublish extends Command
147 $aiVideoAutoLogModel = new AiVideoAutoLog(); 150 $aiVideoAutoLogModel = new AiVideoAutoLog();
148 while (true){ 151 while (true){
149 if($number > 5){ 152 if($number > 5){
  153 + echo date('Y-m-d H:i:s').':当前生成图片数量已达到最大限度。'.$number.PHP_EOL;
150 sleep(300); 154 sleep(300);
151 continue; 155 continue;
152 } 156 }
153 $item = $aiVideoAutoLogModel->read(['status'=>0]); 157 $item = $aiVideoAutoLogModel->read(['status'=>0]);
154 - if(empty($info)){ 158 + if($item === false){
  159 + echo date('Y-m-d H:i:s').':无需生成图片的数据。'.PHP_EOL;
155 sleep(60); 160 sleep(60);
156 continue; 161 continue;
157 } 162 }
@@ -172,6 +177,73 @@ class AiVideoAutoPublish extends Command @@ -172,6 +177,73 @@ class AiVideoAutoPublish extends Command
172 } 177 }
173 178
174 /** 179 /**
  180 + * @remark :状态为1的数据推送至生成视频任务表
  181 + * @name :auto_save_video_task
  182 + * @author :lyh
  183 + * @method :post
  184 + * @time :2025/8/4 9:39
  185 + */
  186 + public function auto_save_video_task(){
  187 + $aiVideoAutoLogModel = new AiVideoAutoLog();
  188 + while (true){
  189 + //获取任务id
  190 + $task_id = $this->getAutoTaskId();
  191 + if(empty($task_id)){
  192 + sleep(300);
  193 + continue;
  194 + }
  195 + $info = $aiVideoAutoLogModel->read(['id'=>$task_id]);
  196 + if($info === false){
  197 + echo date('Y-m-d H:i:s').':当前数据不存在或已被删除'.$task_id.PHP_EOL;
  198 + continue;
  199 + }
  200 + try {
  201 + $aiVideoTaskModel = new AiVideoTask();
  202 + $aiVideoService = new AiVideoService($info['project_id']);
  203 + $projectModel = new DeployOptimize();
  204 + $video_setting = $projectModel->getValue(['project_id'=>$info['project_id']],'video_setting');
  205 + $storage = $aiVideoTaskModel->videoSetting()[$video_setting ?? 1];
  206 + $result = $aiVideoService->createTask($info['title'],$info['remark'],$info['images'],[],$storage);
  207 + if($result['status'] == 200){
  208 + $aiVideoTaskModel->addReturnId(['task_id'=>$result['data']['task_id'],'project_id'=>$info['project_id'],'storage'=>$storage]);
  209 + ProjectServer::useProject($info['project_id']);
  210 + $aiVideoModel = new AiVideo();
  211 + $aiVideoModel->addReturnId(['title'=>$info['title'],'task_id'=>$result['data']['task_id'],'description'=>$info['remark'],'project_id'=>$info['project_id'],'images'=>json_encode($info['images'],true),'anchor'=>json_encode([],true)]);
  212 + DB::disconnect('custom_mysql');
  213 + }
  214 + }catch (\Exception $e){
  215 + echo '错误信息:'.$e->getMessage().PHP_EOL;
  216 + continue;
  217 + }
  218 + }
  219 +
  220 +
  221 + }
  222 +
  223 + /**
  224 + * @remark :火锅自动发布任务id
  225 + * @name :getAutoTaskId
  226 + * @author :lyh
  227 + * @method :post
  228 + * @time :2025/8/4 9:44
  229 + */
  230 + public function getAutoTaskId()
  231 + {
  232 + $task_id = Redis::rpop('auto_ai_video_task');
  233 + if (empty($task_id)) {
  234 + $aiVideoAutoLogModel = new AiVideoAutoLog();
  235 + $ids = $aiVideoAutoLogModel->formatQuery(['status'=>1])->pluck('id');
  236 + if(!empty($ids)){
  237 + foreach ($ids as $id) {
  238 + Redis::lpush('auto_ai_video_task', $id);
  239 + }
  240 + }
  241 + $task_id = Redis::rpop('auto_ai_video_task');
  242 + }
  243 + return $task_id;
  244 + }
  245 +
  246 + /**
175 * @remark : 247 * @remark :
176 * @name :getAiVideoParam 248 * @name :getAiVideoParam
177 * @author :lyh 249 * @author :lyh
@@ -13,6 +13,7 @@ use App\Enums\Common\Code; @@ -13,6 +13,7 @@ use App\Enums\Common\Code;
13 use App\Models\Project\AiVideoAutoLog; 13 use App\Models\Project\AiVideoAutoLog;
14 use App\Services\CosService; 14 use App\Services\CosService;
15 use Illuminate\Support\Facades\Log; 15 use Illuminate\Support\Facades\Log;
  16 +use Illuminate\Support\Facades\Redis;
16 17
17 class AiVideoController extends BaseController 18 class AiVideoController extends BaseController
18 { 19 {
@@ -24,6 +25,10 @@ class AiVideoController extends BaseController @@ -24,6 +25,10 @@ class AiVideoController extends BaseController
24 * @time :2025/8/2 11:19 25 * @time :2025/8/2 11:19
25 */ 26 */
26 public function ImageCallBack(){ 27 public function ImageCallBack(){
  28 + $count = Redis::decr('ai_video_image');
  29 + if ($count < 0) {
  30 + Redis::set('ai_video_image', 0);
  31 + }
27 $data = $this->param['attachments'] ?? []; 32 $data = $this->param['attachments'] ?? [];
28 $aiVideoAutoLogModel = new AiVideoAutoLog(); 33 $aiVideoAutoLogModel = new AiVideoAutoLog();
29 if(empty($data) || empty($data['url'])){ 34 if(empty($data) || empty($data['url'])){
@@ -51,7 +56,8 @@ class AiVideoController extends BaseController @@ -51,7 +56,8 @@ class AiVideoController extends BaseController
51 } 56 }
52 } 57 }
53 $images = array_merge($images,$info['images']); 58 $images = array_merge($images,$info['images']);
54 - $aiVideoAutoLogModel->edit(['images'=>$images,'result'=>json_encode($this->param,true)],['id'=>$info['id']]); 59 + Log::channel('ai_video')->info('图片:'.json_encode($images));
  60 + $aiVideoAutoLogModel->edit(['images'=>$images,'result'=>json_encode($this->param,true),'status'=>1],['id'=>$info['id']]);
55 } 61 }
56 }catch (\Exception $e){ 62 }catch (\Exception $e){
57 Log::channel('ai_video')->info('上传图片失败'.$e->getMessage()); 63 Log::channel('ai_video')->info('上传图片失败'.$e->getMessage());