作者 刘锟

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

@@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
7 * @time :2025/2/21 11:12 7 * @time :2025/2/21 11:12
8 */ 8 */
9 9
10 -namespace App\Console\Commands\AiBlog; 10 +namespace App\Console\Commands\Ai;
11 11
12 use App\Models\Ai\AiBlog; 12 use App\Models\Ai\AiBlog;
13 use App\Models\Ai\AiBlogAuthor; 13 use App\Models\Ai\AiBlogAuthor;
@@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
7 * @time :2025/2/14 11:14 7 * @time :2025/2/14 11:14
8 */ 8 */
9 9
10 -namespace App\Console\Commands\AiBlog; 10 +namespace App\Console\Commands\Ai;
11 11
12 use App\Models\Ai\AiBlog; 12 use App\Models\Ai\AiBlog;
13 use App\Models\Ai\AiBlogAuthor; 13 use App\Models\Ai\AiBlogAuthor;
@@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
7 * @time :2025/2/14 11:14 7 * @time :2025/2/14 11:14
8 */ 8 */
9 9
10 -namespace App\Console\Commands\AiBlog; 10 +namespace App\Console\Commands\Ai;
11 11
12 use App\Models\Ai\AiBlog; 12 use App\Models\Ai\AiBlog;
13 use App\Models\Ai\AiBlogAuthor; 13 use App\Models\Ai\AiBlogAuthor;
@@ -74,7 +74,7 @@ class AiBlogTask extends Command @@ -74,7 +74,7 @@ class AiBlogTask extends Command
74 //拿到返回的路由查看是否重复 74 //拿到返回的路由查看是否重复
75 $route = RouteMap::setRoute($result['data']['url'], RouteMap::SOURCE_AI_BLOG, $aiBlogInfo['id'], $item['project_id']); 75 $route = RouteMap::setRoute($result['data']['url'], RouteMap::SOURCE_AI_BLOG, $aiBlogInfo['id'], $item['project_id']);
76 if($route != $result['data']['url']){ 76 if($route != $result['data']['url']){
77 - $aiBlogService->updateDetail(['route'=>$this->param['route']]); 77 + $aiBlogService->updateDetail(['route'=>$route,'task_id'=>$item['task_id']]);
78 } 78 }
79 $aiBlogModel->edit(['new_title'=>$result['data']['title'], 'image'=>$result['data']['thumb'], 'text'=>$result['data']['section'], 'author_id'=>$result['data']['author_id'], 'route'=>$route ,'status'=>2], ['task_id'=>$item['task_id']]); 79 $aiBlogModel->edit(['new_title'=>$result['data']['title'], 'image'=>$result['data']['thumb'], 'text'=>$result['data']['section'], 'author_id'=>$result['data']['author_id'], 'route'=>$route ,'status'=>2], ['task_id'=>$item['task_id']]);
80 DB::disconnect('custom_mysql'); 80 DB::disconnect('custom_mysql');
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :AiBlogTask.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2025/2/14 11:14
  8 + */
  9 +
  10 +namespace App\Console\Commands\Ai;
  11 +
  12 +use App\Models\Ai\AiBlog;
  13 +use App\Models\Ai\AiBlogAuthor;
  14 +use App\Models\Ai\AiBlogList;
  15 +use App\Models\Ai\AiVideo;
  16 +use App\Models\Project\ProjectAiSetting;
  17 +use App\Models\RouteMap\RouteMap;
  18 +use App\Services\AiBlogService;
  19 +use App\Services\ProjectServer;
  20 +use Illuminate\Console\Command;
  21 +use App\Models\Project\AiBlogTask as AiBlogTaskModel;
  22 +use Illuminate\Support\Facades\Cache;
  23 +use Illuminate\Support\Facades\DB;
  24 +use function Symfony\Component\String\s;
  25 +
  26 +class AiVideoTask extends Command
  27 +{
  28 + /**
  29 + * The name and signature of the console command.
  30 + *
  31 + * @var string
  32 + */
  33 + protected $signature = 'save_ai_video';
  34 +
  35 + /**
  36 + * The console command description.
  37 + *
  38 + * @var string
  39 + */
  40 + protected $description = '查询ai_video是否已经生成';
  41 +
  42 + public function handle(){
  43 + $aiBlogTaskModel = new AiBlogTaskModel();
  44 + while (true){
  45 + $list = $aiBlogTaskModel->list(['status'=>1,'type'=>3],'id',['*'],'asc',1000);
  46 + if(empty($list)){
  47 + sleep(300);
  48 + continue;
  49 + }
  50 + $updateProject = [];
  51 + foreach ($list as $item){
  52 + echo '开始->任务id:' . $item['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
  53 + //获取配置
  54 + $aiSettingInfo = $this->getSetting($item['project_id']);
  55 + $aiBlogService = new AiBlogService();
  56 + $aiBlogService->mch_id = $aiSettingInfo['mch_id'];
  57 + $aiBlogService->key = $aiSettingInfo['key'];
  58 + $aiBlogService->task_id = $item['task_id'];
  59 + $result = $aiBlogService->getDetail();
  60 + if($result['status'] != 200){
  61 + sleep(5);
  62 + continue;
  63 + }
  64 + //保存当前项目ai_blog数据
  65 + ProjectServer::useProject($item['project_id']);
  66 + $aiVideoModel = new AiVideo();
  67 + $aiBlogInfo = $aiVideoModel->read(['task_id'=>$item['task_id']],['id']);
  68 + if($aiBlogInfo === false){
  69 + $aiBlogTaskModel->edit(['status'=>2],['id'=>$item['id']]);
  70 + continue;
  71 + }
  72 + if (!in_array($result['data']['author_id'], $updateProject[$item['project_id']] ?? [])) {
  73 + $updateProject[$item['project_id']][] = $result['data']['author_id'];
  74 + }
  75 + //拿到返回的路由查看是否重复
  76 + $route = RouteMap::setRoute($result['data']['url'], RouteMap::SOURCE_AI_VIDEO, $aiBlogInfo['id'], $item['project_id']);
  77 + if($route != $result['data']['url']){
  78 + $aiBlogService->updateDetail(['route'=>$route,'task_id'=>$item['task_id']]);
  79 + }
  80 + $aiVideoModel->edit(['new_title'=>$result['data']['title'], 'image'=>$result['data']['thumb'], 'text'=>$result['data']['section'], 'author_id'=>$result['data']['author_id'], 'route'=>$route ,'status'=>2], ['task_id'=>$item['task_id']]);
  81 + DB::disconnect('custom_mysql');
  82 + $aiBlogTaskModel->edit(['status'=>2],['id'=>$item['id']]);
  83 + }
  84 + //TODO::更新列表页及作者
  85 +// $this->updateProject($updateProject);
  86 + echo '结束->任务id:' . $item['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
  87 + }
  88 + return true;
  89 + }
  90 +
  91 + /**
  92 + * @remark :更新项目作者页面及列表页
  93 + * @name :updateProject
  94 + * @author :lyh
  95 + * @method :post
  96 + * @time :2025/3/4 10:25
  97 + */
  98 + public function updateProject($updateProject){
  99 + if(empty($updateProject)){
  100 + return true;
  101 + }
  102 + foreach ($updateProject as $project_id => $author){
  103 + ProjectServer::useProject($project_id);
  104 + $aiSettingInfo = $this->getSetting($project_id);
  105 + $this->updateBlogList($aiSettingInfo);
  106 + //更新作者
  107 + foreach ($author as $val){
  108 + $this->updateAiBlogAuthor($aiSettingInfo,$val);
  109 + }
  110 + DB::disconnect('custom_mysql');
  111 + }
  112 + return true;
  113 + }
  114 +
  115 + /**
  116 + * @remark :获取项目配置
  117 + * @name :getSetting
  118 + * @author :lyh
  119 + * @method :post
  120 + * @time :2025/2/14 11:27
  121 + */
  122 + public function getSetting($project_id){
  123 + $ai_cache = Cache::get('ai_blog_'.$project_id);
  124 + if($ai_cache){
  125 + return $ai_cache;
  126 + }
  127 + $projectAiSettingModel = new ProjectAiSetting();
  128 + $aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$project_id]);
  129 + Cache::put('ai_blog_'.$project_id,$aiSettingInfo,3600);
  130 + return $aiSettingInfo;
  131 + }
  132 +
  133 + /**
  134 + * @remark :更新作者的页面
  135 + * @name :updateAiBlogAuthor
  136 + * @author :lyh
  137 + * @method :post
  138 + * @time :2025/2/21 11:53
  139 + */
  140 + public function updateAiBlogAuthor($aiSettingInfo,$author_id){
  141 + if(empty($author_id)){
  142 + return true;
  143 + }
  144 + $aiBlogService = new AiBlogService();
  145 + $aiBlogService->mch_id = $aiSettingInfo['mch_id'];
  146 + $aiBlogService->key = $aiSettingInfo['key'];
  147 + $aiBlogService->author_id = $author_id;
  148 + $result = $aiBlogService->getAuthorDetail();
  149 + if(isset($result['status']) && $result['status'] == 200){
  150 + //当前作者的页面
  151 + $aiBlogAuthorModel = new AiBlogAuthor();
  152 + if(!empty($result['data']['section'])){
  153 + $aiBlogAuthorModel->edit(['text'=>$result['data']['section']],['author_id'=>$author_id]);
  154 + }
  155 + }
  156 + return true;
  157 + }
  158 +
  159 + /**
  160 + * @remark :更新列表页
  161 + * @name :updateBlogList
  162 + * @author :lyh
  163 + * @method :post
  164 + * @time :2025/2/26 15:42
  165 + */
  166 + public function updateBlogList($aiSettingInfo){
  167 + $aiBlogService = new AiBlogService();
  168 + $aiBlogService->mch_id = $aiSettingInfo['mch_id'];
  169 + $aiBlogService->key = $aiSettingInfo['key'];
  170 + $page = 1;
  171 + $saveData = [];
  172 + $result = $aiBlogService->getAiBlogList($page,15);
  173 + if(!isset($result['status']) && $result['status'] != 200){
  174 + return true;
  175 + }
  176 + $total_page = $result['data']['total_page'];
  177 + //组装数据保存
  178 + $saveData[] = [
  179 + 'route'=>$page,
  180 + 'text'=>$result['data']['section'],
  181 + ];
  182 + while ($total_page > $page){
  183 + $page++;
  184 + $result = $aiBlogService->getAiBlogList($page,15);
  185 + if(isset($result['status']) && $result['status'] == 200){
  186 + $saveData[] = [
  187 + 'route'=>$page,
  188 + 'text'=>$result['data']['section'],
  189 + ];
  190 + }
  191 + }
  192 + $aiBlogListModel = new AiBlogList();
  193 + if(!empty($saveData)){
  194 + //写一条路由信息
  195 + $aiBlogListModel->truncate();
  196 + $aiBlogListModel->insertAll($saveData);
  197 + }
  198 + return true;
  199 + }
  200 +}
@@ -173,7 +173,7 @@ class AiBlogController extends BaseController @@ -173,7 +173,7 @@ class AiBlogController extends BaseController
173 $lists = $aiBlogList->lists($this->map,$this->page,$this->row,'id',['id','route','created_at','updated_at']); 173 $lists = $aiBlogList->lists($this->map,$this->page,$this->row,'id',['id','route','created_at','updated_at']);
174 if(!empty($lists) && !empty($lists['list'])){ 174 if(!empty($lists) && !empty($lists['list'])){
175 foreach ($lists['list'] as $k => $v){ 175 foreach ($lists['list'] as $k => $v){
176 - $v['route'] = $this->user['domain'] . 'top-blog/' . ($v['route'] > 1) ? $v['route'] : ''; 176 + $v['route'] = $this->user['domain'] . 'top-blog/' . (($v['route'] > 1) ? $v['route'] : '');
177 $lists['list'][$k] = $v; 177 $lists['list'][$k] = $v;
178 } 178 }
179 } 179 }
@@ -56,7 +56,7 @@ class AiBlogLogic extends BaseLogic @@ -56,7 +56,7 @@ class AiBlogLogic extends BaseLogic
56 $aiBlogService = new AiBlogService(); 56 $aiBlogService = new AiBlogService();
57 $aiBlogService->mch_id = $aiSettingInfo['mch_id']; 57 $aiBlogService->mch_id = $aiSettingInfo['mch_id'];
58 $aiBlogService->key = $aiSettingInfo['key']; 58 $aiBlogService->key = $aiSettingInfo['key'];
59 - $aiBlogService->updateDetail(['title'=>$this->param['new_title'],'thumb'=>$this->param['image'],'route'=>$this->param['route'],'author_id'=>$this->param['author_id']]); 59 + $res = $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']]);
60 }catch (\Exception $e){ 60 }catch (\Exception $e){
61 $this->fail('保存失败,请联系管理员'); 61 $this->fail('保存失败,请联系管理员');
62 } 62 }
@@ -34,6 +34,7 @@ class RouteMap extends Base @@ -34,6 +34,7 @@ class RouteMap extends Base
34 //自定义模块 34 //自定义模块
35 const SOURCE_MODULE = 'module'; 35 const SOURCE_MODULE = 'module';
36 const SOURCE_AI_BLOG = 'ai_blog'; 36 const SOURCE_AI_BLOG = 'ai_blog';
  37 + const SOURCE_AI_VIDEO = 'ai_video';
37 const SOURCE_AI_BLOG_AUTHOR = 'ai_blog_author';//ai博客作者 38 const SOURCE_AI_BLOG_AUTHOR = 'ai_blog_author';//ai博客作者
38 const SOURCE_AI_BLOG_LIST = 'ai_blog_list'; 39 const SOURCE_AI_BLOG_LIST = 'ai_blog_list';
39 //自定义模块分类 40 //自定义模块分类