作者 lyh

列表页聚合页模式

... ... @@ -9,11 +9,14 @@
namespace App\Console\Commands\Ai;
use App\Models\Ai\AiVideo;
use App\Models\Product\Keyword;
use App\Models\Product\Product;
use App\Models\Project\AiBlogTask as AiBlogTaskModel;
use App\Models\Project\AiVideoAutoLog;
use App\Models\Project\DeployOptimize;
use App\Models\Project\Project;
use App\Services\AiVideoService;
use App\Services\MidJourneyService;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
... ... @@ -63,7 +66,7 @@ class AiVideoAutoPublish extends Command
$this->output('开始自动发布Video文章');
$projectModel = new Project();
$optimizeModel = new DeployOptimize();
$projectList = $projectModel->list(['is_ai_video'=>1,'project_type'=>0,'delete_status'=>0,'site_status'=>0,'extend_type'=>0],'id',['id']);
$projectList = $projectModel->list(['is_ai_video'=>1,'id'=>1,'project_type'=>0,'delete_status'=>0,'site_status'=>0,'extend_type'=>0],'id',['id']);
foreach ($projectList as $item){
$this->output("项目{$item['id']}开始自动发布");
//获取当前是否开启自动发布aiVideo
... ... @@ -147,11 +150,13 @@ class AiVideoAutoPublish extends Command
$aiVideoAutoLogModel = new AiVideoAutoLog();
while (true){
if($number > 5){
echo date('Y-m-d H:i:s').':当前生成图片数量已达到最大限度。'.$number.PHP_EOL;
sleep(300);
continue;
}
$item = $aiVideoAutoLogModel->read(['status'=>0]);
if(empty($info)){
if($item === false){
echo date('Y-m-d H:i:s').':无需生成图片的数据。'.PHP_EOL;
sleep(60);
continue;
}
... ... @@ -172,6 +177,73 @@ class AiVideoAutoPublish extends Command
}
/**
* @remark :状态为1的数据推送至生成视频任务表
* @name :auto_save_video_task
* @author :lyh
* @method :post
* @time :2025/8/4 9:39
*/
public function auto_save_video_task(){
$aiVideoAutoLogModel = new AiVideoAutoLog();
while (true){
//获取任务id
$task_id = $this->getAutoTaskId();
if(empty($task_id)){
sleep(300);
continue;
}
$info = $aiVideoAutoLogModel->read(['id'=>$task_id]);
if($info === false){
echo date('Y-m-d H:i:s').':当前数据不存在或已被删除'.$task_id.PHP_EOL;
continue;
}
try {
$aiVideoTaskModel = new AiVideoTask();
$aiVideoService = new AiVideoService($info['project_id']);
$projectModel = new DeployOptimize();
$video_setting = $projectModel->getValue(['project_id'=>$info['project_id']],'video_setting');
$storage = $aiVideoTaskModel->videoSetting()[$video_setting ?? 1];
$result = $aiVideoService->createTask($info['title'],$info['remark'],$info['images'],[],$storage);
if($result['status'] == 200){
$aiVideoTaskModel->addReturnId(['task_id'=>$result['data']['task_id'],'project_id'=>$info['project_id'],'storage'=>$storage]);
ProjectServer::useProject($info['project_id']);
$aiVideoModel = new AiVideo();
$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)]);
DB::disconnect('custom_mysql');
}
}catch (\Exception $e){
echo '错误信息:'.$e->getMessage().PHP_EOL;
continue;
}
}
}
/**
* @remark :火锅自动发布任务id
* @name :getAutoTaskId
* @author :lyh
* @method :post
* @time :2025/8/4 9:44
*/
public function getAutoTaskId()
{
$task_id = Redis::rpop('auto_ai_video_task');
if (empty($task_id)) {
$aiVideoAutoLogModel = new AiVideoAutoLog();
$ids = $aiVideoAutoLogModel->formatQuery(['status'=>1])->pluck('id');
if(!empty($ids)){
foreach ($ids as $id) {
Redis::lpush('auto_ai_video_task', $id);
}
}
$task_id = Redis::rpop('auto_ai_video_task');
}
return $task_id;
}
/**
* @remark :
* @name :getAiVideoParam
* @author :lyh
... ...
... ... @@ -13,6 +13,7 @@ use App\Enums\Common\Code;
use App\Models\Project\AiVideoAutoLog;
use App\Services\CosService;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
class AiVideoController extends BaseController
{
... ... @@ -24,6 +25,10 @@ class AiVideoController extends BaseController
* @time :2025/8/2 11:19
*/
public function ImageCallBack(){
$count = Redis::decr('ai_video_image');
if ($count < 0) {
Redis::set('ai_video_image', 0);
}
$data = $this->param['attachments'] ?? [];
$aiVideoAutoLogModel = new AiVideoAutoLog();
if(empty($data) || empty($data['url'])){
... ... @@ -51,7 +56,8 @@ class AiVideoController extends BaseController
}
}
$images = array_merge($images,$info['images']);
$aiVideoAutoLogModel->edit(['images'=>$images,'result'=>json_encode($this->param,true)],['id'=>$info['id']]);
Log::channel('ai_video')->info('图片:'.json_encode($images));
$aiVideoAutoLogModel->edit(['images'=>$images,'result'=>json_encode($this->param,true),'status'=>1],['id'=>$info['id']]);
}
}catch (\Exception $e){
Log::channel('ai_video')->info('上传图片失败'.$e->getMessage());
... ...