作者 lyh

gx ai视频

... ... @@ -9,9 +9,12 @@
namespace App\Console\Commands\Ai;
use App\Models\Ai\AiBlogAuthor;
use App\Models\Ai\AiVideo;
use App\Models\Ai\AiVideoList;
use App\Models\Project\AiVideoTask as AiVideoTaskModel;
use App\Models\RouteMap\RouteMap;
use App\Services\AiBlogService;
use App\Services\AiVideoService;
use App\Services\DingService;
use App\Services\ProjectServer;
... ... @@ -64,14 +67,14 @@ class AiVideoTask extends Command
{
$task_id = Redis::rpop('ai_video_task');
if (empty($task_id)) {
// if(!empty($this->updateProject)){
// $this->updateProject($this->updateProject);
// $this->updateProject = [];
// }
// if(!empty($this->routes)){
// $this->updateRoutes($this->routes);
// $this->routes = [];
// }
if(!empty($this->updateProject)){
$this->updateProject($this->updateProject);
$this->updateProject = [];
}
if(!empty($this->routes)){
$this->updateRoutes($this->routes);
$this->routes = [];
}
$aiVideoTaskModel = new AiVideoTaskModel();
$finish_at = date('Y-m-d H:i:s', strtotime('-' . $finish_at . ' hour'));
$ids = $aiVideoTaskModel->formatQuery(['status'=>$aiVideoTaskModel::STATUS_RUNNING,'updated_at'=>['<=',$finish_at]])->pluck('id');
... ... @@ -152,6 +155,13 @@ class AiVideoTask extends Command
'status'=>$aiVideoTaskModel::STATUS_FINISH
];
$aiVideoModel->edit($saveData,['task_id'=>$item['task_id']]);
//需要更新的路由
if (!in_array($result['data']['author_id'], $this->updateProject[$item['project_id']] ?? [])) {
$this->updateProject[$item['project_id']][] = $result['data']['author_id'];
}
if (!in_array($route, $this->routes[$item['project_id']] ?? [])) {
$this->routes[$item['project_id']][] = $route;
}
DB::disconnect('custom_mysql');
$aiVideoTaskModel->edit(['status'=>$aiVideoTaskModel::STATUS_FINISH],['id'=>$item['id']]);
$this->output('success: task id: ' . $task_id);
... ... @@ -159,6 +169,102 @@ class AiVideoTask extends Command
}
/**
* @remark :更新项目作者页面及列表页
* @name :updateProject
* @author :lyh
* @method :post
* @time :2025/4/30 15:43
*/
public function updateProject($updateProject){
if(empty($updateProject)){
return true;
}
foreach ($updateProject as $project_id => $author){
ProjectServer::useProject($project_id);
$this->output('sync: list start, project_id: ' . $project_id);
$this->updateBlogList($project_id);
$this->output('sync: list end');
//更新作者
$this->output('sync: author start, project_id: ' . $project_id);
foreach ($author as $val){
$this->updateAiBlogAuthor($val,$project_id);
}
$this->output('sync: author end');
DB::disconnect('custom_mysql');
}
return true;
}
/**
* @remark :更新作者页面
* @name :updateAiBlogAuthor
* @author :lyh
* @method :post
* @time :2025/4/30 15:52
*/
public function updateAiBlogAuthor($author_id,$project_id){
if(empty($author_id)){
return true;
}
$aiBlogService = new AiBlogService($project_id);
$aiBlogService->author_id = $author_id;
$result = $aiBlogService->getAuthorDetail();
if(isset($result['status']) && $result['status'] == 200){
//当前作者的页面
$aiBlogAuthorModel = new AiBlogAuthor();
$authorInfo = $aiBlogAuthorModel->read(['author_id'=>$author_id],['id','route']);
if($authorInfo !== false && !empty($result['data']['section'])){
//需要更新的路由
if (!in_array($authorInfo['route'], $this->routes[$project_id] ?? [])) {
$this->routes[$project_id][] = $authorInfo['route'];
}
$aiBlogAuthorModel->edit(['text'=>$result['data']['section']],['author_id'=>$author_id]);
}
}
return true;
}
/**
* @remark :更新
* @name :updateBlogList
* @author :lyh
* @method :post
* @time :2025/4/30 15:45
*/
public function updateBlogList($project_id){
$aiVideoService = new AiVideoService($project_id);
$page = 1;
$saveData = [];
$result = $aiVideoService->getAiVideoList($page,15);
if(!isset($result['status']) && $result['status'] != 200){
return true;
}
$total_page = $result['data']['total_page'];
//组装数据保存
$saveData[] = [
'route'=>$page,
'text'=>$result['data']['section'],
];
while ($total_page > $page){
$page++;
$result = $aiVideoService->getAiVideoList($page,15);
if(isset($result['status']) && $result['status'] == 200){
$saveData[] = [
'route'=>$page,
'text'=>$result['data']['section'],
];
}
}
$aiVideoListModel = new AiVideoList();
if(!empty($saveData)){
//写一条路由信息
$aiVideoListModel->truncate();
$aiVideoListModel->insertAll($saveData);
}
return true;
}
/**
* 输入日志
* @param $message
* @return bool
... ...
... ... @@ -82,11 +82,13 @@ class UpdateRoute extends Command
$projectModel = new Project();
$lists = $projectModel->list(['delete_status' => 0,'extend_type'=>0,'type'=>['in',[1,2,3,4]]], 'id', ['id']);
foreach ($lists as $val) {
echo date('Y-m-d H:i:s') . '开始--项目的id:'. $val['id'] . PHP_EOL;
// echo date('Y-m-d H:i:s') . '开始--项目的id:'. $val['id'] . PHP_EOL;
ProjectServer::useProject($val['id']);
$aiBlogModel = new AiBlogAuthor();
$results = $aiBlogModel->whereColumn('title', '!=', 'seo_title')->get();
echo '项目id:'.json_encode($results,true).PHP_EOL;
if(!$results){
$aiBlogModel->edit(['seo_title'=>'','seo_keyword'=>'','seo_description'=>''],['id'=>['>',0]]);
echo '项目id:'.$val['id'].PHP_EOL;
}
DB::disconnect('custom_mysql');
... ...
... ... @@ -54,13 +54,11 @@ class AiVideoLogic extends BaseLogic
*/
public function videoSave(){
try {
$this->param['route'] = RouteMap::setRoute($this->param['tit'], RouteMap::SOURCE_AI_VIDEO, $this->param['id'], $this->user['project_id']);
$this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_AI_VIDEO, $this->param['id'], $this->user['project_id']);
$this->model->edit($this->param,['id'=>$this->param['id']]);
$aiSettingInfo = $this->getProjectAiSetting();
$aiBlogService = new AiBlogService();
$aiBlogService->mch_id = $aiSettingInfo['mch_id'];
$aiBlogService->key = $aiSettingInfo['key'];
$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']]);
$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'],'thumb'=>$this->param['image'],'url'=>$this->param['route'],'author_id'=>$this->param['author_id']]);
}catch (\Exception $e){
$this->fail('保存失败,请联系管理员');
}
... ... @@ -96,13 +94,10 @@ class AiVideoLogic extends BaseLogic
*/
public function videoDelete(){
try {
$aiSettingInfo = $this->getProjectAiSetting();
$aiBlogService = new AiBlogService();
$aiBlogService = new AiVideoService($this->user['project_id']);
foreach ($this->param['ids'] as $id) {
$info = $this->model->read(['id'=>$id],['task_id']);
$aiBlogService->mch_id = $aiSettingInfo['mch_id'];
$aiBlogService->key = $aiSettingInfo['key'];
$aiBlogService->delDetail($info['task_id']);
$aiBlogService->delVideoDetail($info['task_id']);
//删除路由映射
RouteMap::delRoute(RouteMap::SOURCE_AI_VIDEO, $id, $this->user['project_id']);
$this->model->del(['id'=>$id]);
... ...
<?php
/**
* @remark :
* @name :AiBlogList.php
* @author :lyh
* @method :post
* @time :2025/2/21 15:57
*/
namespace App\Models\Ai;
use App\Models\Base;
class AiVideoList extends Base
{
protected $table = 'gl_ai_video_list';
//连接数据库
protected $connection = 'custom_mysql';
}
... ...
... ... @@ -99,6 +99,41 @@ class AiVideoService
}
/**
* @remark :获取列表页数据
* @name :getAiVideoList
* @author :lyh
* @method :post
* @time :2025/4/30 15:48
*/
public function getAiVideoList($page,$page_size){
$request_url = $this->url.'api/video/list';
$param['mch_id'] = $this->mch_id;
$param['page'] = $page;
$param['page_size'] = $page_size;
$this->sign = $this->generateSign($param,$this->key);
$param['sign'] = $this->sign;
$result = http_post($request_url,json_encode($param,true));
return $result;
}
/**
* @remark :删除详情数据
* @name :delDetail
* @author :lyh
* @method :post
* @time :2025/4/30 16:00
*/
public function delVideoDetail($task_id){
$param['task_id'] = $task_id;
$request_url = $this->url.'api/video/delete';
$param['mch_id'] = $this->mch_id;
$this->sign = $this->generateSign($param,$this->key);
$param['sign'] = $this->sign;
$result = http_post($request_url,json_encode($param,true));
return $result;
}
/**
* @remark :计算签名
* @name :generateSign
* @author :lyh
... ...