作者 刘锟

Merge remote-tracking branch 'origin/master' into akun

  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :AiVideoTask.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2025/4/30 11:18
  8 + */
  9 +
  10 +namespace App\Console\Commands\Ai;
  11 +
  12 +use App\Models\Ai\AiVideo;
  13 +use App\Models\Project\AiVideoTask as AiVideoTaskModel;
  14 +use App\Models\RouteMap\RouteMap;
  15 +use App\Services\AiVideoService;
  16 +use App\Services\DingService;
  17 +use App\Services\ProjectServer;
  18 +use Illuminate\Console\Command;
  19 +use Illuminate\Support\Facades\DB;
  20 +use Illuminate\Support\Facades\Redis;
  21 +
  22 +class AiVideoTask extends Command
  23 +{
  24 + /**
  25 + * The name and signature of the console command.
  26 + *
  27 + * @var string
  28 + */
  29 + protected $signature = 'save_ai_video';
  30 +
  31 + public $updateProject = [];//需更新的列表
  32 + public $routes = [];//需要更新的路由
  33 +
  34 + /**
  35 + * The console command description.
  36 + *
  37 + * @var string
  38 + */
  39 + protected $description = '查询ai_video是否已经生成';
  40 +
  41 + /**
  42 + * @return bool
  43 + * @throws \Exception
  44 + */
  45 + public function handle(){
  46 + while (true){
  47 + //获取任务id
  48 + $task_id = $this->getTaskId();
  49 + if(empty($task_id)){
  50 + sleep(300);
  51 + continue;
  52 + }
  53 + $this->_action($task_id);
  54 + }
  55 + return true;
  56 + }
  57 +
  58 + /**
  59 + * 获取任务id
  60 + * @param int $finish_at
  61 + * @return mixed
  62 + */
  63 + public function getTaskId($finish_at = 2)
  64 + {
  65 + $task_id = Redis::rpop('ai_video_task');
  66 + 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 +// }
  75 + $aiVideoTaskModel = new AiVideoTaskModel();
  76 + $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');
  78 + if(!empty($ids)){
  79 + foreach ($ids as $id) {
  80 + Redis::lpush('ai_video_task', $id);
  81 + }
  82 + }
  83 + $task_id = Redis::rpop('ai_video_task');
  84 + }
  85 + return $task_id;
  86 + }
  87 +
  88 + /**
  89 + * @remark :请求
  90 + * @name :sendRequest
  91 + * @author :lyh
  92 + * @method :post
  93 + * @time :2025/4/30 11:31
  94 + */
  95 + public function _action($task_id){
  96 + $aiVideoTaskModel = new AiVideoTaskModel();
  97 + $item = $aiVideoTaskModel->read(['id'=>$task_id]);
  98 + $this->output('ai_video->start:project ID: ' . $item['project_id'] . ',task ID: ' . $task_id);
  99 + $aiVideoService = new AiVideoService($item['project_id']);
  100 + $aiVideoService->task_id = $item['task_id'];
  101 + //拉取文章数据
  102 + $result = $aiVideoService->getVideoDetail();
  103 + if(empty($result['status']) || ($result['status'] != 200)){
  104 + if($item['number'] < 5){
  105 + $aiVideoTaskModel->edit(['number'=>$item['number'] + 1],['id'=>$item['id']]);
  106 + }else{
  107 + $aiVideoTaskModel->edit(['status'=>9],['id'=>$item['id']]);
  108 + // 钉钉通知
  109 + $dingService = new DingService();
  110 + $body = [
  111 + 'keyword' => 'AI_VIDEO获取失败',
  112 + 'msg' => '任务ID:' . $item['task_id'] . PHP_EOL . '返回信息:' . json_encode($result,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
  113 + 'isAtAll' => false, // 是否@所有人
  114 + ];
  115 + $dingService->handle($body);
  116 + }
  117 + $this->output('error: 数据获取失败,status:' . $result['status'] . ',message: ' . ($result['message'] ?? 'null'));
  118 + return false;
  119 + }
  120 + //保存当前项目ai_blog数据
  121 + ProjectServer::useProject($item['project_id']);
  122 + $aiVideoModel = new AiVideo();
  123 + $aiVideoInfo = $aiVideoModel->read(['task_id'=>$item['task_id']],['id','route']);
  124 + if($aiVideoInfo === false){
  125 + // 钉钉通知
  126 + $dingService = new DingService();
  127 + $body = [
  128 + 'keyword' => 'AI_VIDEO生成错误',
  129 + 'msg' => '任务ID:' . $item['task_id'] . ', 子库获取数据失败, 检查子库数据是否被删除!',
  130 + 'isAtAll' => false, // 是否@所有人
  131 + ];
  132 + $dingService->handle($body);
  133 + $this->output('error: 子库获取数据失败, task id: ' . $task_id);
  134 + $aiVideoTaskModel->edit(['status'=>9],['id'=>$item['id']]);
  135 + DB::disconnect('custom_mysql');
  136 + return false;
  137 + }
  138 + //拿到返回的路由查看是否重复
  139 + $route = RouteMap::setRoute($result['data']['url'], RouteMap::SOURCE_AI_VIDEO, $aiVideoInfo['id'], $item['project_id']);
  140 + if($route != $result['data']['url']){
  141 + $aiVideoService->updateDetail(['route'=>$route,'task_id'=>$item['task_id']]);
  142 + }
  143 + $saveData = [
  144 + 'title'=>$result['data']['title'],
  145 + 'image'=>$result['data']['thumb'],
  146 + 'video_url'=>$result['data']['video_url'],
  147 + 'route'=>$route,
  148 + 'author_id'=>$result['data']['author_id'],
  149 + 'keyword'=>json_encode($result['data']['keyword'],true),
  150 + 'content'=>$result['data']['content'],
  151 + 'text'=>$result['data']['section'],
  152 + 'status'=>$aiVideoTaskModel::STATUS_FINISH
  153 + ];
  154 + $aiVideoModel->edit($saveData,['task_id'=>$item['task_id']]);
  155 + DB::disconnect('custom_mysql');
  156 + $aiVideoTaskModel->edit(['status'=>$aiVideoTaskModel::STATUS_FINISH],['id'=>$item['id']]);
  157 + $this->output('success: task id: ' . $task_id);
  158 + return true;
  159 + }
  160 +
  161 + /**
  162 + * 输入日志
  163 + * @param $message
  164 + * @return bool
  165 + */
  166 + public function output($message)
  167 + {
  168 + $message = date('Y-m-d H:i:s') . ' ' . $message . PHP_EOL;
  169 + echo $message;
  170 + return true;
  171 + }
  172 +}
@@ -68,6 +68,7 @@ class AfterDayCount extends Command @@ -68,6 +68,7 @@ class AfterDayCount extends Command
68 $idArr = $this->managerHrModel->selectField(['name'=>['in',$valM]],'id'); 68 $idArr = $this->managerHrModel->selectField(['name'=>['in',$valM]],'id');
69 $project_count = $projectModel->where('gl_project.extend_type',0) 69 $project_count = $projectModel->where('gl_project.extend_type',0)
70 ->where('gl_project.delete_status',0) 70 ->where('gl_project.delete_status',0)
  71 + ->where('gl_project.old_project_id',0)
71 ->where('gl_project.created_at','<=',$todayMidnight) 72 ->where('gl_project.created_at','<=',$todayMidnight)
72 ->whereIn('gl_project_deploy_optimize.optimist_mid',$idArr) 73 ->whereIn('gl_project_deploy_optimize.optimist_mid',$idArr)
73 ->whereIn('gl_project.type',[2,4]) 74 ->whereIn('gl_project.type',[2,4])
@@ -77,6 +78,7 @@ class AfterDayCount extends Command @@ -77,6 +78,7 @@ class AfterDayCount extends Command
77 ->count(); 78 ->count();
78 $qualified_count = $projectModel->where('gl_project.extend_type',0) 79 $qualified_count = $projectModel->where('gl_project.extend_type',0)
79 ->where('gl_project.delete_status',0) 80 ->where('gl_project.delete_status',0)
  81 + ->where('gl_project.old_project_id',0)
80 ->where('gl_project.created_at','<=',$todayMidnight) 82 ->where('gl_project.created_at','<=',$todayMidnight)
81 ->where('gl_project.is_remain_today',1) 83 ->where('gl_project.is_remain_today',1)
82 ->where('gl_project_deploy_build.plan','!=',0) 84 ->where('gl_project_deploy_build.plan','!=',0)
@@ -91,6 +93,7 @@ class AfterDayCount extends Command @@ -91,6 +93,7 @@ class AfterDayCount extends Command
91 $threeMonthsAgo = date('Y-m-d 00:00:00', strtotime('-3 months')); 93 $threeMonthsAgo = date('Y-m-d 00:00:00', strtotime('-3 months'));
92 $three_project_count = $projectModel->where('gl_project.extend_type',0) 94 $three_project_count = $projectModel->where('gl_project.extend_type',0)
93 ->where('gl_project.delete_status',0) 95 ->where('gl_project.delete_status',0)
  96 + ->where('gl_project.old_project_id',0)
94 ->where('gl_project.created_at','<=',$threeMonthsAgo) 97 ->where('gl_project.created_at','<=',$threeMonthsAgo)
95 ->whereIn('gl_project_deploy_optimize.optimist_mid',$idArr) 98 ->whereIn('gl_project_deploy_optimize.optimist_mid',$idArr)
96 ->whereIn('gl_project.type',[2,4]) 99 ->whereIn('gl_project.type',[2,4])
@@ -101,6 +104,7 @@ class AfterDayCount extends Command @@ -101,6 +104,7 @@ class AfterDayCount extends Command
101 $three_qualified_count = $projectModel->where('gl_project.extend_type',0) 104 $three_qualified_count = $projectModel->where('gl_project.extend_type',0)
102 ->whereIn('gl_project.id',$projectIdArr) 105 ->whereIn('gl_project.id',$projectIdArr)
103 ->where('gl_project.delete_status',0) 106 ->where('gl_project.delete_status',0)
  107 + ->where('gl_project.old_project_id',0)
104 ->where('gl_project.created_at','<=',$threeMonthsAgo) 108 ->where('gl_project.created_at','<=',$threeMonthsAgo)
105 ->whereIn('gl_project_deploy_optimize.optimist_mid',$idArr) 109 ->whereIn('gl_project_deploy_optimize.optimist_mid',$idArr)
106 ->whereIn('gl_project.type',[2,4]) 110 ->whereIn('gl_project.type',[2,4])
@@ -12,6 +12,7 @@ namespace App\Console\Commands\LyhTest; @@ -12,6 +12,7 @@ namespace App\Console\Commands\LyhTest;
12 use App\Helper\Arr; 12 use App\Helper\Arr;
13 use App\Helper\Translate; 13 use App\Helper\Translate;
14 use App\Models\Ai\AiBlog; 14 use App\Models\Ai\AiBlog;
  15 +use App\Models\Ai\AiBlogAuthor;
15 use App\Models\Blog\Blog; 16 use App\Models\Blog\Blog;
16 use App\Models\Com\WordCountry; 17 use App\Models\Com\WordCountry;
17 use App\Models\CustomModule\CustomModuleContent; 18 use App\Models\CustomModule\CustomModuleContent;
@@ -67,7 +68,7 @@ class UpdateRoute extends Command @@ -67,7 +68,7 @@ class UpdateRoute extends Command
67 */ 68 */
68 public function handle() 69 public function handle()
69 { 70 {
70 - return $this->getNullRoute(); 71 + return $this->getAiBlog();
71 } 72 }
72 73
73 /** 74 /**
@@ -77,16 +78,16 @@ class UpdateRoute extends Command @@ -77,16 +78,16 @@ class UpdateRoute extends Command
77 * @method :post 78 * @method :post
78 * @time :2025/4/21 11:52 79 * @time :2025/4/21 11:52
79 */ 80 */
80 - public function getNullRoute(){ 81 + public function getAiBlog(){
81 $projectModel = new Project(); 82 $projectModel = new Project();
82 $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']);
83 foreach ($lists as $val) { 84 foreach ($lists as $val) {
84 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;
85 ProjectServer::useProject($val['id']); 86 ProjectServer::useProject($val['id']);
86 - $keywordModel = new Keyword();  
87 - $info = $keywordModel->read(['route'=>'']);  
88 - if($info !== false){  
89 - echo '存在路由为空--项目id:'.$val['id'].PHP_EOL; 87 + $aiBlogModel = new AiBlogAuthor();
  88 + $results = $aiBlogModel->whereColumn('title', '!=', 'seo_title')->get();
  89 + if(!$results){
  90 + echo '项目id:'.$val['id'].PHP_EOL;
90 } 91 }
91 DB::disconnect('custom_mysql'); 92 DB::disconnect('custom_mysql');
92 } 93 }
@@ -151,7 +152,7 @@ class UpdateRoute extends Command @@ -151,7 +152,7 @@ class UpdateRoute extends Command
151 * @method :post 152 * @method :post
152 * @time :2025/3/21 17:45 153 * @time :2025/3/21 17:45
153 */ 154 */
154 - public function getAiBlog($project_id){ 155 + public function getAiBlogs($project_id){
155 $aiBlogModel = new AiBlog(); 156 $aiBlogModel = new AiBlog();
156 $lists = $aiBlogModel->list(['updated_at'=>['<=','2025-03-21 00:00:00']]); 157 $lists = $aiBlogModel->list(['updated_at'=>['<=','2025-03-21 00:00:00']]);
157 if(!empty($lists)){ 158 if(!empty($lists)){
@@ -84,7 +84,11 @@ class CopyOldProject extends Command @@ -84,7 +84,11 @@ class CopyOldProject extends Command
84 'gl_customer_visit_item', 84 'gl_customer_visit_item',
85 'gl_inquiry_other', 85 'gl_inquiry_other',
86 'gl_inquiry_form_data', 86 'gl_inquiry_form_data',
87 - 'gl_inquiry_form' 87 + 'gl_inquiry_form',
  88 + 'gl_ai_blog',
  89 + 'gl_ai_blog_author',
  90 + 'gl_ai_blog_list',
  91 + 'gl_ai_blog_log',
88 ])) { 92 ])) {
89 continue; 93 continue;
90 } 94 }
@@ -245,7 +245,7 @@ class CopyProject extends Command @@ -245,7 +245,7 @@ class CopyProject extends Command
245 $result1 = DB::connection('custom_mysql')->statement(get_object_vars($sql[0])['Create Table']); 245 $result1 = DB::connection('custom_mysql')->statement(get_object_vars($sql[0])['Create Table']);
246 @file_put_contents(storage_path('logs/copy_mysql_error.log'), var_export('创建对应表数据:'.$result1, true) . PHP_EOL, FILE_APPEND); 246 @file_put_contents(storage_path('logs/copy_mysql_error.log'), var_export('创建对应表数据:'.$result1, true) . PHP_EOL, FILE_APPEND);
247 // 3. 跳过指定的表 247 // 3. 跳过指定的表
248 - if (in_array($table, ['gl_customer_visit', 'gl_customer_visit_item', 'gl_inquiry_other', 'gl_inquiry_form_data', 'gl_inquiry_form'])) { 248 + if (in_array($table, ['gl_customer_visit', 'gl_customer_visit_item', 'gl_inquiry_other', 'gl_inquiry_form_data', 'gl_inquiry_form','gl_ai_blog', 'gl_ai_blog_author', 'gl_ai_blog_list','gl_ai_blog_log'])) {
249 continue; 249 continue;
250 } 250 }
251 // 4. 原生 SQL 插入数据(完全复制) 251 // 4. 原生 SQL 插入数据(完全复制)
@@ -34,7 +34,7 @@ class UpdateSeoTdkCrontab extends Command @@ -34,7 +34,7 @@ class UpdateSeoTdkCrontab extends Command
34 */ 34 */
35 public function handle() 35 public function handle()
36 { 36 {
37 - $project_ids = Project::where('type', Project::TYPE_TWO)->pluck('id')->toArray(); 37 + $project_ids = Project::where('type', Project::TYPE_TWO)->where('uptime', '<=', date('Y-m-d H:i:s'))->pluck('id')->toArray();
38 foreach ($project_ids as $project_id){ 38 foreach ($project_ids as $project_id){
39 try { 39 try {
40 ProjectUpdateTdk::add_task($project_id); 40 ProjectUpdateTdk::add_task($project_id);
@@ -24,7 +24,7 @@ class AiVideoController extends BaseController @@ -24,7 +24,7 @@ class AiVideoController extends BaseController
24 * @time :2025/3/5 14:12 24 * @time :2025/3/5 14:12
25 */ 25 */
26 public function lists(AiVideo $aiVideo){ 26 public function lists(AiVideo $aiVideo){
27 - $lists = $aiVideo->lists($this->map,$this->page,$this->row,'id',['id','keyword','new_title','route','image','task_id','status','created_at','updated_at']); 27 + $lists = $aiVideo->lists($this->map,$this->page,$this->row,'id',['id','title','route','video_url','image','task_id','status','created_at','updated_at']);
28 if(!empty($lists) && !empty($lists['list'])){ 28 if(!empty($lists) && !empty($lists['list'])){
29 foreach ($lists['list'] as $k => $v){ 29 foreach ($lists['list'] as $k => $v){
30 $v['image'] = getImageUrl($v['image']); 30 $v['image'] = getImageUrl($v['image']);
@@ -51,7 +51,6 @@ class AiVideoController extends BaseController @@ -51,7 +51,6 @@ class AiVideoController extends BaseController
51 'id.required' => '主键不能为空', 51 'id.required' => '主键不能为空',
52 ]); 52 ]);
53 $info = $aiVideo->read(['id'=>$this->param['id']]); 53 $info = $aiVideo->read(['id'=>$this->param['id']]);
54 - $info['image'] = getImageUrl($info['image']);  
55 $this->response('success',Code::SUCCESS,$info); 54 $this->response('success',Code::SUCCESS,$info);
56 } 55 }
57 56
@@ -64,11 +63,13 @@ class AiVideoController extends BaseController @@ -64,11 +63,13 @@ class AiVideoController extends BaseController
64 */ 63 */
65 public function sendTask(AiVideoLogic $aiVideoLogic){ 64 public function sendTask(AiVideoLogic $aiVideoLogic){
66 $this->request->validate([ 65 $this->request->validate([
67 - 'keyword'=>['required'],  
68 - 'type'=>['required'], 66 + 'title'=>['required'],
  67 + 'description'=>['required'],
  68 + 'images'=>['required'],
69 ],[ 69 ],[
70 - 'keyword.required' => '关键字不能为空',  
71 - 'type.required' => '场景不能为空', 70 + 'title.required' => '标题不能为空',
  71 + 'description.required' => '短描述不能为空',
  72 + 'images.required' => '图片集合不能为空',
72 ]); 73 ]);
73 $result = $aiVideoLogic->sendTask(); 74 $result = $aiVideoLogic->sendTask();
74 $this->response('success',Code::SUCCESS,$result); 75 $this->response('success',Code::SUCCESS,$result);
@@ -28,6 +28,7 @@ use App\Models\Project\Project; @@ -28,6 +28,7 @@ use App\Models\Project\Project;
28 use App\Models\Project\ProjectAiSetting; 28 use App\Models\Project\ProjectAiSetting;
29 use App\Models\RouteMap\RouteMap; 29 use App\Models\RouteMap\RouteMap;
30 use App\Services\AiBlogService; 30 use App\Services\AiBlogService;
  31 +use App\Services\AiVideoService;
31 use App\Services\RapIdApIService; 32 use App\Services\RapIdApIService;
32 use App\Services\ProjectServer; 33 use App\Services\ProjectServer;
33 use Illuminate\Support\Facades\DB; 34 use Illuminate\Support\Facades\DB;
@@ -42,8 +43,16 @@ class TestController extends BaseController @@ -42,8 +43,16 @@ class TestController extends BaseController
42 * @time :2025/2/13 16:34 43 * @time :2025/2/13 16:34
43 */ 44 */
44 public function ceshi(){ 45 public function ceshi(){
45 - //获取上一周询盘数量  
46 - $transData = Translate::tran(['heidenhain programming','heidenhain tnc 620'], 'zh');  
47 - $this->response('success',Code::SUCCESS,$transData); 46 + $this->param = [
  47 + 'title'=>'apple',
  48 + 'description'=>'apples',
  49 + 'images'=>[
  50 + ['url'=>'https://ecdn6.globalso.com/upload/public/template/64e332671b32e25328.png','title'=>'apple'],
  51 + ['url'=>'https://ecdn6.globalso.com/upload/public/template/64e32a24b314a39425.png','title'=>'apples'],
  52 + ],
  53 + ];
  54 + $aiVideoService = new AiVideoService(467);
  55 + $result = $aiVideoService->createTask($this->param['title'],$this->param['description'],$this->param['images'],$this->param['anchor'] ?? []);
  56 + $this->response('success',Code::SUCCESS,$result);
48 } 57 }
49 } 58 }
@@ -268,12 +268,13 @@ class ProjectLogic extends BaseLogic @@ -268,12 +268,13 @@ class ProjectLogic extends BaseLogic
268 public function checkAiBlog($param){ 268 public function checkAiBlog($param){
269 $main_lang_id = $param['main_lang_id'] ?? 0; 269 $main_lang_id = $param['main_lang_id'] ?? 0;
270 $is_ai_blog = $param['is_ai_blog'] ?? 0; 270 $is_ai_blog = $param['is_ai_blog'] ?? 0;
  271 + $is_ai_video = $param['is_ai_video'] ?? 0;
271 $company = $param['company'] ?? ''; 272 $company = $param['company'] ?? '';
272 $company_en_name = $param['deploy_optimize']['company_en_name'] ?? ''; 273 $company_en_name = $param['deploy_optimize']['company_en_name'] ?? '';
273 $company_en_description = $param['deploy_optimize']['company_en_description'] ?? ''; 274 $company_en_description = $param['deploy_optimize']['company_en_description'] ?? '';
274 - if($is_ai_blog == 1){ 275 + if($is_ai_blog == 1 || $is_ai_video){
275 if(empty($main_lang_id) || empty($company) || empty($company_en_name) || empty($company_en_description)){ 276 if(empty($main_lang_id) || empty($company) || empty($company_en_name) || empty($company_en_description)){
276 - $this->fail('开启ai_blog--请填写主语种+公司名称+公司英文名称+公司英文介绍'); 277 + $this->fail('开启ai博客/视频功能--请填写主语种+公司名称+公司英文名称+公司英文介绍');
277 } 278 }
278 } 279 }
279 return true; 280 return true;
@@ -7,9 +7,11 @@ use App\Http\Logic\Bside\BaseLogic; @@ -7,9 +7,11 @@ use App\Http\Logic\Bside\BaseLogic;
7 use App\Models\Ai\AiBlogAuthor; 7 use App\Models\Ai\AiBlogAuthor;
8 use App\Models\Ai\AiVideo; 8 use App\Models\Ai\AiVideo;
9 use App\Models\Project\AiBlogTask; 9 use App\Models\Project\AiBlogTask;
  10 +use App\Models\Project\AiVideoTask;
10 use App\Models\Project\ProjectAiSetting; 11 use App\Models\Project\ProjectAiSetting;
11 use App\Models\RouteMap\RouteMap; 12 use App\Models\RouteMap\RouteMap;
12 use App\Services\AiBlogService; 13 use App\Services\AiBlogService;
  14 +use App\Services\AiVideoService;
13 15
14 /** 16 /**
15 * @remark :视频模块 17 * @remark :视频模块
@@ -52,10 +54,7 @@ class AiVideoLogic extends BaseLogic @@ -52,10 +54,7 @@ class AiVideoLogic extends BaseLogic
52 */ 54 */
53 public function videoSave(){ 55 public function videoSave(){
54 try { 56 try {
55 - if(!empty($this->param['image'])){  
56 - $this->param['image'] = str_replace_url($this->param['image']);  
57 - }  
58 - $this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_AI_VIDEO, $this->param['id'], $this->user['project_id']); 57 + $this->param['route'] = RouteMap::setRoute($this->param['tit'], RouteMap::SOURCE_AI_VIDEO, $this->param['id'], $this->user['project_id']);
59 $this->model->edit($this->param,['id'=>$this->param['id']]); 58 $this->model->edit($this->param,['id'=>$this->param['id']]);
60 $aiSettingInfo = $this->getProjectAiSetting(); 59 $aiSettingInfo = $this->getProjectAiSetting();
61 $aiBlogService = new AiBlogService(); 60 $aiBlogService = new AiBlogService();
@@ -74,20 +73,16 @@ class AiVideoLogic extends BaseLogic @@ -74,20 +73,16 @@ class AiVideoLogic extends BaseLogic
74 * @author :lyh 73 * @author :lyh
75 * @method :post 74 * @method :post
76 * @time :2025/2/14 10:28 75 * @time :2025/2/14 10:28
77 - * @detail :createTask =>type=2/生成文章  
78 * @detail :status=1/待执行 76 * @detail :status=1/待执行
79 */ 77 */
80 public function sendTask(){ 78 public function sendTask(){
81 - $aiSettingInfo = $this->getProjectAiSetting();  
82 - $aiBlogService = new AiBlogService();  
83 - $aiBlogService->mch_id = $aiSettingInfo['mch_id'];  
84 - $aiBlogService->key = $aiSettingInfo['key'];  
85 - $aiBlogService->route = generateRoute(Translate::tran($this->param['keyword'], 'en'));  
86 - $result = $aiBlogService->createTask($this->param['keyword'],2,'video',$this->param['anchor'] ?? []); 79 + $aiVideoService = new AiVideoService($this->user['project_id']);
  80 + $result = $aiVideoService->createTask($this->param['title'],$this->param['description'],$this->param['images'],$this->param['anchor'] ?? []);
87 if($result['status'] == 200){ 81 if($result['status'] == 200){
88 - $aiBlogTaskModel = new AiBlogTask();  
89 - $aiBlogTaskModel->addReturnId(['project_id'=>$this->user['project_id'],'type'=>3,'task_id'=>$result['data']['task_id'],'status'=>1]);  
90 - $this->model->addReturnId(['keyword'=>$this->param['keyword'],'status'=>1,'task_id'=>$result['data']['task_id'],'project_id'=>$this->user['project_id'],'anchor'=>json_encode($this->param['anchor'] ?? [],true)]); 82 + $aiVideoTaskModel = new AiVideoTask();
  83 + $aiVideoTaskModel->addReturnId(['task_id'=>$result['data']['task_id'],'project_id'=>$this->user['project_id']]);
  84 + $id = $this->model->addReturnId(['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)]);
  85 + return $this->success(['id'=>$id]);
91 } 86 }
92 return $this->success(); 87 return $this->success();
93 } 88 }
@@ -21,4 +21,6 @@ use App\Models\Base; @@ -21,4 +21,6 @@ use App\Models\Base;
21 class AiVideo extends Base 21 class AiVideo extends Base
22 { 22 {
23 protected $table = 'gl_ai_video'; 23 protected $table = 'gl_ai_video';
  24 + //连接数据库
  25 + protected $connection = 'custom_mysql';
24 } 26 }
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :AiVideoTask.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2025/4/30 9:41
  8 + */
  9 +
  10 +namespace App\Models\Project;
  11 +
  12 +use App\Models\Base;
  13 +
  14 +class AiVideoTask extends Base
  15 +{
  16 + protected $table = 'gl_ai_video_task';
  17 +
  18 + /**
  19 + * 任务状态
  20 + */
  21 + const STATUS_RUNNING = 1;
  22 + const STATUS_FINISH = 2;
  23 +}
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :AiVideoService.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2025/4/29 17:39
  8 + */
  9 +
  10 +namespace App\Services;
  11 +
  12 +use App\Helper\Translate;
  13 +use App\Models\Project\ProjectAiSetting;
  14 +
  15 +class AiVideoService
  16 +{
  17 + public $url = 'https://ai-extend.ai.cc/';
  18 +
  19 + public $mch_id = 1;//默认配置
  20 + public $sign = '';//签名
  21 + public $key = 'b3e4c722b821';//默认key
  22 + public $route = '';//回调地址
  23 + public $task_id = '';//任务id
  24 + public $author_id = '';//作者id
  25 +
  26 + public function __construct($project_id = 0)
  27 + {
  28 + if($project_id){
  29 + $projectAiSettingModel = new ProjectAiSetting();
  30 + $aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$project_id]);
  31 + $this->mch_id = $aiSettingInfo['mch_id'];
  32 + $this->key = $aiSettingInfo['key'];
  33 + }
  34 + }
  35 +
  36 + /**
  37 + * @remark :设置路由
  38 + * @name :setRoute
  39 + * @author :lyh
  40 + * @method :post
  41 + * @time :2025/3/25 9:45
  42 + */
  43 + public function setRoute($keyword)
  44 + {
  45 + $this->route = generateRoute(Translate::tran($keyword, 'en'));
  46 + return $this;
  47 + }
  48 +
  49 + /**
  50 + * @remark :创建任务
  51 + * @name :createTask
  52 + * @author :lyh
  53 + * @method :post
  54 + * @time :2025/4/29 17:59
  55 + */
  56 + public function createTask($title,$description,$images = [],$anchor = []){
  57 + $request_url = $this->url.'api/video/create';
  58 + $param = ['title'=>$title, 'description'=>$description, 'images'=>$images,'anchor'=>$anchor];
  59 + $param['mch_id'] = $this->mch_id;
  60 + $this->sign = $this->generateSign($param,$this->key);
  61 + $param['sign'] = $this->sign;
  62 + return http_post($request_url,json_encode($param,true));
  63 + }
  64 +
  65 + /**
  66 + * @remark :获取视频详情
  67 + * @name :getVideoDetail
  68 + * @author :lyh
  69 + * @method :post
  70 + * @time :2025/2/14 11:23
  71 + */
  72 + public function getVideoDetail(){
  73 + $request_url = $this->url.'api/video/detail';
  74 + $param = [
  75 + 'mch_id'=>$this->mch_id,
  76 + 'task_id'=>$this->task_id,
  77 + ];
  78 + $this->sign = $this->generateSign($param,$this->key);
  79 + $param['sign'] = $this->sign;
  80 + $result = http_post($request_url,json_encode($param,true));
  81 + return $result;
  82 + }
  83 +
  84 + /**
  85 + * @remark :更新文章
  86 + * @name :updateDetail
  87 + * @author :lyh
  88 + * @method :post
  89 + * @time :2025/2/21 14:38
  90 + * @param :task_id , title , video_url ,thumb , content , author_id , url ,
  91 + */
  92 + public function updateDetail($param){
  93 + $request_url = $this->url.'api/video/save';
  94 + $param['mch_id'] = $this->mch_id;
  95 + $this->sign = $this->generateSign($param,$this->key);
  96 + $param['sign'] = $this->sign;
  97 + $result = http_post($request_url,json_encode($param,true));
  98 + return $result;
  99 + }
  100 +
  101 + /**
  102 + * @remark :计算签名
  103 + * @name :generateSign
  104 + * @author :lyh
  105 + * @method :post
  106 + * @time :2025/2/13 15:07
  107 + */
  108 + public function generateSign($params, $key)
  109 + {
  110 + // 去除数组中所有值为空的项
  111 + array_filter($params);
  112 + // 按照key值的ASCII码从小到大排序
  113 + ksort($params);
  114 + // 生成URL的查询字符串
  115 + $string = http_build_query($params);
  116 + // 生成签名
  117 + $sign = md5($string . $key);
  118 + // 转换成大写
  119 + $sign = strtoupper($sign);
  120 + return $sign;
  121 + }
  122 +}