AiVideoController.php 2.3 KB
<?php
/**
 * @remark :
 * @name   :AiVideoController.php
 * @author :lyh
 * @method :post
 * @time   :2025/8/2 11:18
 */

namespace App\Http\Controllers\Api;

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
{
    /**
     * @remark :回调方法
     * @name   :ImageCallBack
     * @author :lyh
     * @method :post
     * @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'])){
            $aiVideoAutoLogModel->edit(['status'=>9,'result'=>json_encode($this->param,true)],['trigger_id'=>$this->param['id']]);
        }
        //获取当前数据详情
        $info = $aiVideoAutoLogModel->read(['trigger_id'=>$this->param['id']]);
        if($info === false){
            Log::channel('ai_video')->info('当前数据不存在或已被删除'.$this->param['id']);
        }
        //上传图片  返回cdn链接
        $cosService = new CosService();
        $imagePath = $cosService->uploadRemote($info['project_id'],'video',$data['url']);
        try {
            if($imagePath){
                $cos = config('filesystems.disks.cos');
                $url = $cos['cdn1'].'/'.$imagePath;
                //裁剪图片为4张
                $images = [];
                $cosService = new CosService();
                $data = $cosService->cropAndUploadToCOS($url);
                if(!empty($data)){
                    foreach ($data as $item){
                        $images[] = ['url'=>$item,'alt'=>''];
                    }
                }
                $images = array_merge($images,$info['images']);
                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());
        }
        $this->response('success');
    }
}