作者 lyh

gx ai视频

@@ -9,9 +9,12 @@ @@ -9,9 +9,12 @@
9 9
10 namespace App\Console\Commands\Ai; 10 namespace App\Console\Commands\Ai;
11 11
  12 +use App\Models\Ai\AiBlogAuthor;
12 use App\Models\Ai\AiVideo; 13 use App\Models\Ai\AiVideo;
  14 +use App\Models\Ai\AiVideoList;
13 use App\Models\Project\AiVideoTask as AiVideoTaskModel; 15 use App\Models\Project\AiVideoTask as AiVideoTaskModel;
14 use App\Models\RouteMap\RouteMap; 16 use App\Models\RouteMap\RouteMap;
  17 +use App\Services\AiBlogService;
15 use App\Services\AiVideoService; 18 use App\Services\AiVideoService;
16 use App\Services\DingService; 19 use App\Services\DingService;
17 use App\Services\ProjectServer; 20 use App\Services\ProjectServer;
@@ -64,14 +67,14 @@ class AiVideoTask extends Command @@ -64,14 +67,14 @@ class AiVideoTask extends Command
64 { 67 {
65 $task_id = Redis::rpop('ai_video_task'); 68 $task_id = Redis::rpop('ai_video_task');
66 if (empty($task_id)) { 69 if (empty($task_id)) {
67 -// if(!empty($this->updateProject)){  
68 -// $this->updateProject($this->updateProject);  
69 -// $this->updateProject = [];  
70 -// }  
71 -// if(!empty($this->routes)){  
72 -// $this->updateRoutes($this->routes);  
73 -// $this->routes = [];  
74 -// } 70 + if(!empty($this->updateProject)){
  71 + $this->updateProject($this->updateProject);
  72 + $this->updateProject = [];
  73 + }
  74 + if(!empty($this->routes)){
  75 + $this->updateRoutes($this->routes);
  76 + $this->routes = [];
  77 + }
75 $aiVideoTaskModel = new AiVideoTaskModel(); 78 $aiVideoTaskModel = new AiVideoTaskModel();
76 $finish_at = date('Y-m-d H:i:s', strtotime('-' . $finish_at . ' hour')); 79 $finish_at = date('Y-m-d H:i:s', strtotime('-' . $finish_at . ' hour'));
77 $ids = $aiVideoTaskModel->formatQuery(['status'=>$aiVideoTaskModel::STATUS_RUNNING,'updated_at'=>['<=',$finish_at]])->pluck('id'); 80 $ids = $aiVideoTaskModel->formatQuery(['status'=>$aiVideoTaskModel::STATUS_RUNNING,'updated_at'=>['<=',$finish_at]])->pluck('id');
@@ -152,6 +155,13 @@ class AiVideoTask extends Command @@ -152,6 +155,13 @@ class AiVideoTask extends Command
152 'status'=>$aiVideoTaskModel::STATUS_FINISH 155 'status'=>$aiVideoTaskModel::STATUS_FINISH
153 ]; 156 ];
154 $aiVideoModel->edit($saveData,['task_id'=>$item['task_id']]); 157 $aiVideoModel->edit($saveData,['task_id'=>$item['task_id']]);
  158 + //需要更新的路由
  159 + if (!in_array($result['data']['author_id'], $this->updateProject[$item['project_id']] ?? [])) {
  160 + $this->updateProject[$item['project_id']][] = $result['data']['author_id'];
  161 + }
  162 + if (!in_array($route, $this->routes[$item['project_id']] ?? [])) {
  163 + $this->routes[$item['project_id']][] = $route;
  164 + }
155 DB::disconnect('custom_mysql'); 165 DB::disconnect('custom_mysql');
156 $aiVideoTaskModel->edit(['status'=>$aiVideoTaskModel::STATUS_FINISH],['id'=>$item['id']]); 166 $aiVideoTaskModel->edit(['status'=>$aiVideoTaskModel::STATUS_FINISH],['id'=>$item['id']]);
157 $this->output('success: task id: ' . $task_id); 167 $this->output('success: task id: ' . $task_id);
@@ -159,6 +169,102 @@ class AiVideoTask extends Command @@ -159,6 +169,102 @@ class AiVideoTask extends Command
159 } 169 }
160 170
161 /** 171 /**
  172 + * @remark :更新项目作者页面及列表页
  173 + * @name :updateProject
  174 + * @author :lyh
  175 + * @method :post
  176 + * @time :2025/4/30 15:43
  177 + */
  178 + public function updateProject($updateProject){
  179 + if(empty($updateProject)){
  180 + return true;
  181 + }
  182 + foreach ($updateProject as $project_id => $author){
  183 + ProjectServer::useProject($project_id);
  184 + $this->output('sync: list start, project_id: ' . $project_id);
  185 + $this->updateBlogList($project_id);
  186 + $this->output('sync: list end');
  187 + //更新作者
  188 + $this->output('sync: author start, project_id: ' . $project_id);
  189 + foreach ($author as $val){
  190 + $this->updateAiBlogAuthor($val,$project_id);
  191 + }
  192 + $this->output('sync: author end');
  193 + DB::disconnect('custom_mysql');
  194 + }
  195 +
  196 + return true;
  197 + }
  198 +
  199 + /**
  200 + * @remark :更新作者页面
  201 + * @name :updateAiBlogAuthor
  202 + * @author :lyh
  203 + * @method :post
  204 + * @time :2025/4/30 15:52
  205 + */
  206 + public function updateAiBlogAuthor($author_id,$project_id){
  207 + if(empty($author_id)){
  208 + return true;
  209 + }
  210 + $aiBlogService = new AiBlogService($project_id);
  211 + $aiBlogService->author_id = $author_id;
  212 + $result = $aiBlogService->getAuthorDetail();
  213 + if(isset($result['status']) && $result['status'] == 200){
  214 + //当前作者的页面
  215 + $aiBlogAuthorModel = new AiBlogAuthor();
  216 + $authorInfo = $aiBlogAuthorModel->read(['author_id'=>$author_id],['id','route']);
  217 + if($authorInfo !== false && !empty($result['data']['section'])){
  218 + //需要更新的路由
  219 + if (!in_array($authorInfo['route'], $this->routes[$project_id] ?? [])) {
  220 + $this->routes[$project_id][] = $authorInfo['route'];
  221 + }
  222 + $aiBlogAuthorModel->edit(['text'=>$result['data']['section']],['author_id'=>$author_id]);
  223 + }
  224 + }
  225 + return true;
  226 + }
  227 +
  228 + /**
  229 + * @remark :更新
  230 + * @name :updateBlogList
  231 + * @author :lyh
  232 + * @method :post
  233 + * @time :2025/4/30 15:45
  234 + */
  235 + public function updateBlogList($project_id){
  236 + $aiVideoService = new AiVideoService($project_id);
  237 + $page = 1;
  238 + $saveData = [];
  239 + $result = $aiVideoService->getAiVideoList($page,15);
  240 + if(!isset($result['status']) && $result['status'] != 200){
  241 + return true;
  242 + }
  243 + $total_page = $result['data']['total_page'];
  244 + //组装数据保存
  245 + $saveData[] = [
  246 + 'route'=>$page,
  247 + 'text'=>$result['data']['section'],
  248 + ];
  249 + while ($total_page > $page){
  250 + $page++;
  251 + $result = $aiVideoService->getAiVideoList($page,15);
  252 + if(isset($result['status']) && $result['status'] == 200){
  253 + $saveData[] = [
  254 + 'route'=>$page,
  255 + 'text'=>$result['data']['section'],
  256 + ];
  257 + }
  258 + }
  259 + $aiVideoListModel = new AiVideoList();
  260 + if(!empty($saveData)){
  261 + //写一条路由信息
  262 + $aiVideoListModel->truncate();
  263 + $aiVideoListModel->insertAll($saveData);
  264 + }
  265 + return true;
  266 + }
  267 + /**
162 * 输入日志 268 * 输入日志
163 * @param $message 269 * @param $message
164 * @return bool 270 * @return bool
@@ -82,11 +82,13 @@ class UpdateRoute extends Command @@ -82,11 +82,13 @@ class UpdateRoute extends Command
82 $projectModel = new Project(); 82 $projectModel = new Project();
83 $lists = $projectModel->list(['delete_status' => 0,'extend_type'=>0,'type'=>['in',[1,2,3,4]]], 'id', ['id']); 83 $lists = $projectModel->list(['delete_status' => 0,'extend_type'=>0,'type'=>['in',[1,2,3,4]]], 'id', ['id']);
84 foreach ($lists as $val) { 84 foreach ($lists as $val) {
85 - echo date('Y-m-d H:i:s') . '开始--项目的id:'. $val['id'] . PHP_EOL; 85 +// echo date('Y-m-d H:i:s') . '开始--项目的id:'. $val['id'] . PHP_EOL;
86 ProjectServer::useProject($val['id']); 86 ProjectServer::useProject($val['id']);
87 $aiBlogModel = new AiBlogAuthor(); 87 $aiBlogModel = new AiBlogAuthor();
88 $results = $aiBlogModel->whereColumn('title', '!=', 'seo_title')->get(); 88 $results = $aiBlogModel->whereColumn('title', '!=', 'seo_title')->get();
  89 + echo '项目id:'.json_encode($results,true).PHP_EOL;
89 if(!$results){ 90 if(!$results){
  91 + $aiBlogModel->edit(['seo_title'=>'','seo_keyword'=>'','seo_description'=>''],['id'=>['>',0]]);
90 echo '项目id:'.$val['id'].PHP_EOL; 92 echo '项目id:'.$val['id'].PHP_EOL;
91 } 93 }
92 DB::disconnect('custom_mysql'); 94 DB::disconnect('custom_mysql');
@@ -54,13 +54,11 @@ class AiVideoLogic extends BaseLogic @@ -54,13 +54,11 @@ class AiVideoLogic extends BaseLogic
54 */ 54 */
55 public function videoSave(){ 55 public function videoSave(){
56 try { 56 try {
57 - $this->param['route'] = RouteMap::setRoute($this->param['tit'], RouteMap::SOURCE_AI_VIDEO, $this->param['id'], $this->user['project_id']); 57 + $this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_AI_VIDEO, $this->param['id'], $this->user['project_id']);
58 $this->model->edit($this->param,['id'=>$this->param['id']]); 58 $this->model->edit($this->param,['id'=>$this->param['id']]);
59 - $aiSettingInfo = $this->getProjectAiSetting();  
60 - $aiBlogService = new AiBlogService();  
61 - $aiBlogService->mch_id = $aiSettingInfo['mch_id'];  
62 - $aiBlogService->key = $aiSettingInfo['key'];  
63 - $aiBlogService->updateDetail(['task_id'=>$this->param['task_id'],'title'=>$this->param['new_title'],'thumb'=>$this->param['image'],'route'=>$this->param['route'],'author_id'=>$this->param['author_id']]); 59 + $aiVideoService = new AiVideoService($this->user['project_id']);
  60 + $aiVideoService->updateDetail(['task_id'=>$this->param['task_id'],'title'=>$this->param['title'],
  61 + 'content'=>$this->param['content'] ?? '','video_url'=>$this->param['video_url'],'thumb'=>$this->param['image'],'url'=>$this->param['route'],'author_id'=>$this->param['author_id']]);
64 }catch (\Exception $e){ 62 }catch (\Exception $e){
65 $this->fail('保存失败,请联系管理员'); 63 $this->fail('保存失败,请联系管理员');
66 } 64 }
@@ -96,13 +94,10 @@ class AiVideoLogic extends BaseLogic @@ -96,13 +94,10 @@ class AiVideoLogic extends BaseLogic
96 */ 94 */
97 public function videoDelete(){ 95 public function videoDelete(){
98 try { 96 try {
99 - $aiSettingInfo = $this->getProjectAiSetting();  
100 - $aiBlogService = new AiBlogService(); 97 + $aiBlogService = new AiVideoService($this->user['project_id']);
101 foreach ($this->param['ids'] as $id) { 98 foreach ($this->param['ids'] as $id) {
102 $info = $this->model->read(['id'=>$id],['task_id']); 99 $info = $this->model->read(['id'=>$id],['task_id']);
103 - $aiBlogService->mch_id = $aiSettingInfo['mch_id'];  
104 - $aiBlogService->key = $aiSettingInfo['key'];  
105 - $aiBlogService->delDetail($info['task_id']); 100 + $aiBlogService->delVideoDetail($info['task_id']);
106 //删除路由映射 101 //删除路由映射
107 RouteMap::delRoute(RouteMap::SOURCE_AI_VIDEO, $id, $this->user['project_id']); 102 RouteMap::delRoute(RouteMap::SOURCE_AI_VIDEO, $id, $this->user['project_id']);
108 $this->model->del(['id'=>$id]); 103 $this->model->del(['id'=>$id]);
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :AiBlogList.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2025/2/21 15:57
  8 + */
  9 +
  10 +namespace App\Models\Ai;
  11 +
  12 +use App\Models\Base;
  13 +
  14 +class AiVideoList extends Base
  15 +{
  16 + protected $table = 'gl_ai_video_list';
  17 + //连接数据库
  18 + protected $connection = 'custom_mysql';
  19 +}
@@ -99,6 +99,41 @@ class AiVideoService @@ -99,6 +99,41 @@ class AiVideoService
99 } 99 }
100 100
101 /** 101 /**
  102 + * @remark :获取列表页数据
  103 + * @name :getAiVideoList
  104 + * @author :lyh
  105 + * @method :post
  106 + * @time :2025/4/30 15:48
  107 + */
  108 + public function getAiVideoList($page,$page_size){
  109 + $request_url = $this->url.'api/video/list';
  110 + $param['mch_id'] = $this->mch_id;
  111 + $param['page'] = $page;
  112 + $param['page_size'] = $page_size;
  113 + $this->sign = $this->generateSign($param,$this->key);
  114 + $param['sign'] = $this->sign;
  115 + $result = http_post($request_url,json_encode($param,true));
  116 + return $result;
  117 + }
  118 +
  119 + /**
  120 + * @remark :删除详情数据
  121 + * @name :delDetail
  122 + * @author :lyh
  123 + * @method :post
  124 + * @time :2025/4/30 16:00
  125 + */
  126 + public function delVideoDetail($task_id){
  127 + $param['task_id'] = $task_id;
  128 + $request_url = $this->url.'api/video/delete';
  129 + $param['mch_id'] = $this->mch_id;
  130 + $this->sign = $this->generateSign($param,$this->key);
  131 + $param['sign'] = $this->sign;
  132 + $result = http_post($request_url,json_encode($param,true));
  133 + return $result;
  134 + }
  135 +
  136 + /**
102 * @remark :计算签名 137 * @remark :计算签名
103 * @name :generateSign 138 * @name :generateSign
104 * @author :lyh 139 * @author :lyh