AiVideoLogic.php
3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
namespace App\Http\Logic\Bside\Ai;
use App\Helper\Translate;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Ai\AiBlogAuthor;
use App\Models\Ai\AiVideo;
use App\Models\Project\AiBlogTask;
use App\Models\Project\AiVideoTask;
use App\Models\Project\ProjectAiSetting;
use App\Models\RouteMap\RouteMap;
use App\Services\AiBlogService;
use App\Services\AiVideoService;
/**
* @remark :视频模块
* @name :AiVideoLogic
* @author :lyh
* @method :post
* @time :2025/3/5 14:11
*/
class AiVideoLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->param = $this->requestAll;
$this->model = new AiVideo();
}
/**
* @remark :ai发布博客
* @name :blogSave
* @author :lyh
* @method :post
* @time :2023/7/5 14:46
*/
public function videoSave(){
try {
$this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_AI_VIDEO, $this->param['id'], $this->user['project_id']);
$anchor = $this->param['anchor'] ?? [];
$this->param['anchor'] = json_encode($anchor,true);
$this->param['images'] = json_encode($this->param['images'],true);
$this->model->edit($this->param,['id'=>$this->param['id']]);
$aiVideoService = new AiVideoService($this->user['project_id']);
$aiVideoService->updateDetail(['task_id'=>$this->param['task_id'],'title'=>$this->param['title'],
'content'=>$this->param['content'] ?? '','video_url'=>$this->param['video_url'],'anchor'=>$anchor,'thumb'=>$this->param['image'],'url'=>$this->param['route'],'author_id'=>$this->param['author_id']]);
}catch (\Exception $e){
$this->fail('保存失败,请联系管理员');
}
shell_exec("php artisan save_ai_video_list {$this->user['project_id']} > /dev/null 2>&1 &");
return $this->success();
}
/**
* @remark :发布任务
* @name :sendTask
* @author :lyh
* @method :post
* @time :2025/2/14 10:28
* @detail :status=1/待执行
*/
public function sendTask(){
$aiVideoTaskModel = new AiVideoTask();
$aiVideoService = new AiVideoService($this->user['project_id']);
$storage = $aiVideoTaskModel->videoSetting()[$this->user['video_setting'] ?? 1];
$result = $aiVideoService->createTask($this->param['title'],$this->param['description'],$this->param['images'],$this->param['anchor'] ?? [],$storage);
if($result['status'] == 200){
$aiVideoTaskModel->addReturnId(['task_id'=>$result['data']['task_id'],'project_id'=>$this->user['project_id'],'storage'=>$storage]);
$id = $this->model->addReturnId(['title'=>$this->param['title'],'task_id'=>$result['data']['task_id'],'description'=>$this->param['description'],'project_id'=>$this->user['project_id'],'images'=>json_encode($this->param['images'],true),'anchor'=>json_encode($this->param['anchor'] ?? [],true)]);
return $this->success(['id'=>$id]);
}
return $this->success();
}
/**
* @remark :删除aiVideo
* @name :videoDelete
* @author :lyh
* @method :post
* @time :2025/3/6 10:00
*/
public function videoDelete(){
try {
$aiBlogService = new AiVideoService($this->user['project_id']);
foreach ($this->param['ids'] as $id) {
$info = $this->model->read(['id'=>$id],['task_id']);
$aiBlogService->delVideoDetail($info['task_id']);
//删除路由映射
RouteMap::delRoute(RouteMap::SOURCE_AI_VIDEO, $id, $this->user['project_id']);
$this->model->del(['id'=>$id]);
}
}catch (\Exception $e){
$this->fail('删除失败,请联系管理员');
}
shell_exec("php artisan save_ai_video_list {$this->user['project_id']} > /dev/null 2>&1 &");
return $this->success();
}
}