作者 lyh

gx异步执行更新列表页

@@ -22,6 +22,13 @@ use Illuminate\Support\Facades\Cache; @@ -22,6 +22,13 @@ use Illuminate\Support\Facades\Cache;
22 use Illuminate\Support\Facades\DB; 22 use Illuminate\Support\Facades\DB;
23 use function Symfony\Component\String\s; 23 use function Symfony\Component\String\s;
24 24
  25 +/***
  26 + * @remark :根据项目更新blog列表
  27 + * @name :AiBlogListTask
  28 + * @author :lyh
  29 + * @method :post
  30 + * @time :2025/3/6 9:45
  31 + */
25 class AiBlogListTask extends Command 32 class AiBlogListTask extends Command
26 { 33 {
27 /** 34 /**
@@ -82,7 +82,7 @@ class AiVideoTask extends Command @@ -82,7 +82,7 @@ class AiVideoTask extends Command
82 $aiBlogTaskModel->edit(['status'=>2],['id'=>$item['id']]); 82 $aiBlogTaskModel->edit(['status'=>2],['id'=>$item['id']]);
83 } 83 }
84 //TODO::更新列表页及作者 84 //TODO::更新列表页及作者
85 -// $this->updateProject($updateProject); 85 + $this->updateProject($updateProject);
86 echo '结束->任务id:' . $item['task_id'] . PHP_EOL . date('Y-m-d H:i:s'); 86 echo '结束->任务id:' . $item['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
87 } 87 }
88 return true; 88 return true;
@@ -102,7 +102,7 @@ class AiVideoTask extends Command @@ -102,7 +102,7 @@ class AiVideoTask extends Command
102 foreach ($updateProject as $project_id => $author){ 102 foreach ($updateProject as $project_id => $author){
103 ProjectServer::useProject($project_id); 103 ProjectServer::useProject($project_id);
104 $aiSettingInfo = $this->getSetting($project_id); 104 $aiSettingInfo = $this->getSetting($project_id);
105 - $this->updateBlogList($aiSettingInfo); 105 +// $this->updateBlogList($aiSettingInfo);
106 //更新作者 106 //更新作者
107 foreach ($author as $val){ 107 foreach ($author as $val){
108 $this->updateAiBlogAuthor($aiSettingInfo,$val); 108 $this->updateAiBlogAuthor($aiSettingInfo,$val);
@@ -380,7 +380,7 @@ class ProjectController extends BaseController @@ -380,7 +380,7 @@ class ProjectController extends BaseController
380 * @time :2023/8/18 14:44 380 * @time :2023/8/18 14:44
381 */ 381 */
382 public function handleParam(&$item){ 382 public function handleParam(&$item){
383 - if($item['type'] != Project::TYPE_ZERO){ 383 + if(($item['type'] != Project::TYPE_ZERO) && ($item['project_type'] == 0)){
384 $data = APublicModel::getNumByProjectId($item['id']); 384 $data = APublicModel::getNumByProjectId($item['id']);
385 } 385 }
386 if($item['type'] == Project::TYPE_ONE){//建站中 386 if($item['type'] == Project::TYPE_ONE){//建站中
@@ -70,8 +70,42 @@ class AiVideoController extends BaseController @@ -70,8 +70,42 @@ class AiVideoController extends BaseController
70 'keyword.required' => '关键字不能为空', 70 'keyword.required' => '关键字不能为空',
71 'type.required' => '场景不能为空', 71 'type.required' => '场景不能为空',
72 ]); 72 ]);
73 - //获取当前项目的ai_blog设置  
74 $result = $aiVideoLogic->sendTask(); 73 $result = $aiVideoLogic->sendTask();
75 $this->response('success',Code::SUCCESS,$result); 74 $this->response('success',Code::SUCCESS,$result);
76 } 75 }
  76 +
  77 + /**
  78 + * @remark :更新任务
  79 + * @name :save
  80 + * @author :lyh
  81 + * @method :post
  82 + * @time :2025/3/6 10:51
  83 + */
  84 + public function save(AiVideoLogic $aiVideoLogic){
  85 + $this->request->validate([
  86 + 'id'=>['required'],
  87 + ],[
  88 + 'id.required' => '关键字不能为空',
  89 + ]);
  90 + $aiVideoLogic->videoSave();
  91 + $this->response('success');
  92 + }
  93 +
  94 + /**
  95 + * @remark :删除ai视频
  96 + * @name :delete
  97 + * @author :lyh
  98 + * @method :post
  99 + * @time :2025/3/6 9:56
  100 + */
  101 + public function delete(AiVideoLogic $aiVideoLogic)
  102 + {
  103 + $this->request->validate([
  104 + 'ids'=>['required'],
  105 + ],[
  106 + 'ids.required' => 'ID不能为空'
  107 + ]);
  108 + $result = $aiVideoLogic->videoDelete();
  109 + $this->response('success',Code::SUCCESS,$result);
  110 + }
77 } 111 }
@@ -38,7 +38,7 @@ class ComController extends BaseController @@ -38,7 +38,7 @@ class ComController extends BaseController
38 } 38 }
39 $lists = $projectMenuModel->list($this->map,'sort'); 39 $lists = $projectMenuModel->list($this->map,'sort');
40 $menu = array(); 40 $menu = array();
41 - foreach ($lists as $k => $v){ 41 + foreach ($lists as $v){
42 $v = (array)$v; 42 $v = (array)$v;
43 if ($v['pid'] == 0) { 43 if ($v['pid'] == 0) {
44 $v['sub'] = _get_child($v['id'], $lists); 44 $v['sub'] = _get_child($v['id'], $lists);
@@ -57,9 +57,10 @@ class ComController extends BaseController @@ -57,9 +57,10 @@ class ComController extends BaseController
57 */ 57 */
58 public function seo_get_menu(){ 58 public function seo_get_menu(){
59 $seoMenuModel = new ProjectMenuSeo(); 59 $seoMenuModel = new ProjectMenuSeo();
  60 + $this->map['status'] = 0;
60 $lists = $seoMenuModel->list($this->map,'sort'); 61 $lists = $seoMenuModel->list($this->map,'sort');
61 $menu = array(); 62 $menu = array();
62 - foreach ($lists as $k => $v){ 63 + foreach ($lists as $v){
63 $v = (array)$v; 64 $v = (array)$v;
64 if ($v['pid'] == 0) { 65 if ($v['pid'] == 0) {
65 $v['sub'] = _get_child($v['id'], $lists); 66 $v['sub'] = _get_child($v['id'], $lists);
@@ -101,12 +101,12 @@ class AiBlogLogic extends BaseLogic @@ -101,12 +101,12 @@ class AiBlogLogic extends BaseLogic
101 $aiBlogService->mch_id = $aiSettingInfo['mch_id']; 101 $aiBlogService->mch_id = $aiSettingInfo['mch_id'];
102 $aiBlogService->key = $aiSettingInfo['key']; 102 $aiBlogService->key = $aiSettingInfo['key'];
103 $aiBlogService->route = generateRoute(Translate::tran($this->param['keyword'], 'en')); 103 $aiBlogService->route = generateRoute(Translate::tran($this->param['keyword'], 'en'));
104 - $result = $aiBlogService->createTask($this->param['keyword'],$this->param['type']); 104 + $result = $aiBlogService->createTask($this->param['keyword'],2,'blog',$this->param['anchor'] ?? []);
105 if($result['status'] == 200){ 105 if($result['status'] == 200){
106 $aiBlogTaskModel = new AiBlogTask(); 106 $aiBlogTaskModel = new AiBlogTask();
107 $aiBlogTaskModel->addReturnId(['project_id'=>$this->user['project_id'],'type'=>2,'task_id'=>$result['data']['task_id'],'status'=>1]); 107 $aiBlogTaskModel->addReturnId(['project_id'=>$this->user['project_id'],'type'=>2,'task_id'=>$result['data']['task_id'],'status'=>1]);
108 $aiBlogModel = new AiBlog(); 108 $aiBlogModel = new AiBlog();
109 - $aiBlogModel->addReturnId(['keyword'=>$this->param['keyword'], 'status'=>1, 'task_id'=>$result['data']['task_id'],'project_id'=>$this->user['project_id'], 109 + $aiBlogModel->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)
110 ]); 110 ]);
111 } 111 }
112 return $this->success(); 112 return $this->success();
@@ -50,41 +50,18 @@ class AiVideoLogic extends BaseLogic @@ -50,41 +50,18 @@ class AiVideoLogic extends BaseLogic
50 * @method :post 50 * @method :post
51 * @time :2023/7/5 14:46 51 * @time :2023/7/5 14:46
52 */ 52 */
53 - public function blogSave(){ 53 + public function videoSave(){
54 try { 54 try {
55 if(!empty($this->param['image'])){ 55 if(!empty($this->param['image'])){
56 $this->param['image'] = str_replace_url($this->param['image']); 56 $this->param['image'] = str_replace_url($this->param['image']);
57 } 57 }
58 - $this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_AI_BLOG, $this->param['id'], $this->user['project_id']); 58 + $this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_AI_VIDEO, $this->param['id'], $this->user['project_id']);
59 $this->model->edit($this->param,['id'=>$this->param['id']]); 59 $this->model->edit($this->param,['id'=>$this->param['id']]);
60 $aiSettingInfo = $this->getProjectAiSetting(); 60 $aiSettingInfo = $this->getProjectAiSetting();
61 $aiBlogService = new AiBlogService(); 61 $aiBlogService = new AiBlogService();
62 $aiBlogService->mch_id = $aiSettingInfo['mch_id']; 62 $aiBlogService->mch_id = $aiSettingInfo['mch_id'];
63 $aiBlogService->key = $aiSettingInfo['key']; 63 $aiBlogService->key = $aiSettingInfo['key'];
64 - $aiBlogService->updateDetail(['title'=>$this->param['new_title'],'thumb'=>$this->param['image'],'route'=>$this->param['route'],'author_id'=>$this->param['author_id']]);  
65 - }catch (\Exception $e){  
66 - $this->fail('保存失败,请联系管理员');  
67 - }  
68 - return $this->success();  
69 - }  
70 -  
71 - /**  
72 - * @remark :编辑作者  
73 - * @name :saveAuthor  
74 - * @author :lyh  
75 - * @method :post  
76 - * @time :2025/2/21 14:46  
77 - */  
78 - public function saveBlogAuthor(){  
79 - try {  
80 - $aiAuthorModel = new AiBlogAuthor();  
81 - if(!empty($this->param['image'])){  
82 - $this->param['image'] = str_replace_url($this->param['image']);  
83 - }  
84 - $this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_AI_BLOG_AUTHOR, $this->param['id'], $this->user['project_id']);  
85 - $aiAuthorModel->edit($this->param,['id'=>$this->param['id']]);  
86 - $aiBlogService = new AiBlogService();  
87 - $aiBlogService->updateAuthorInfo(['author_id'=>$this->param['author_id'],'title'=>$this->param['title'],'picture'=>$this->param['image'],'description'=>$this->param['description']]); 64 + $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']]);
88 }catch (\Exception $e){ 65 }catch (\Exception $e){
89 $this->fail('保存失败,请联系管理员'); 66 $this->fail('保存失败,请联系管理员');
90 } 67 }
@@ -97,7 +74,7 @@ class AiVideoLogic extends BaseLogic @@ -97,7 +74,7 @@ class AiVideoLogic extends BaseLogic
97 * @author :lyh 74 * @author :lyh
98 * @method :post 75 * @method :post
99 * @time :2025/2/14 10:28 76 * @time :2025/2/14 10:28
100 - * @detail :type=2/生成文章 type=3/更新列表页记录 77 + * @detail :createTask =>type=2/生成文章
101 * @detail :status=1/待执行 78 * @detail :status=1/待执行
102 */ 79 */
103 public function sendTask(){ 80 public function sendTask(){
@@ -106,23 +83,23 @@ class AiVideoLogic extends BaseLogic @@ -106,23 +83,23 @@ class AiVideoLogic extends BaseLogic
106 $aiBlogService->mch_id = $aiSettingInfo['mch_id']; 83 $aiBlogService->mch_id = $aiSettingInfo['mch_id'];
107 $aiBlogService->key = $aiSettingInfo['key']; 84 $aiBlogService->key = $aiSettingInfo['key'];
108 $aiBlogService->route = generateRoute(Translate::tran($this->param['keyword'], 'en')); 85 $aiBlogService->route = generateRoute(Translate::tran($this->param['keyword'], 'en'));
109 - $result = $aiBlogService->createTask($this->param['keyword'],$this->param['type'],'video'); 86 + $result = $aiBlogService->createTask($this->param['keyword'],2,'video',$this->param['anchor'] ?? []);
110 if($result['status'] == 200){ 87 if($result['status'] == 200){
111 $aiBlogTaskModel = new AiBlogTask(); 88 $aiBlogTaskModel = new AiBlogTask();
112 $aiBlogTaskModel->addReturnId(['project_id'=>$this->user['project_id'],'type'=>3,'task_id'=>$result['data']['task_id'],'status'=>1]); 89 $aiBlogTaskModel->addReturnId(['project_id'=>$this->user['project_id'],'type'=>3,'task_id'=>$result['data']['task_id'],'status'=>1]);
113 - $this->model->addReturnId(['keyword'=>$this->param['keyword'],'status'=>1,'task_id'=>$result['data']['task_id'],'project_id'=>$this->user['project_id']]); 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)]);
114 } 91 }
115 return $this->success(); 92 return $this->success();
116 } 93 }
117 94
118 /** 95 /**
119 - * @remark :删除  
120 - * @name :blogDelete 96 + * @remark :删除aiVideo
  97 + * @name :videoDelete
121 * @author :lyh 98 * @author :lyh
122 * @method :post 99 * @method :post
123 - * @time :2025/2/20 18:21 100 + * @time :2025/3/6 10:00
124 */ 101 */
125 - public function blogDelete(){ 102 + public function videoDelete(){
126 try { 103 try {
127 $aiSettingInfo = $this->getProjectAiSetting(); 104 $aiSettingInfo = $this->getProjectAiSetting();
128 $aiBlogService = new AiBlogService(); 105 $aiBlogService = new AiBlogService();
@@ -132,12 +109,11 @@ class AiVideoLogic extends BaseLogic @@ -132,12 +109,11 @@ class AiVideoLogic extends BaseLogic
132 $aiBlogService->key = $aiSettingInfo['key']; 109 $aiBlogService->key = $aiSettingInfo['key'];
133 $aiBlogService->delDetail($info['task_id']); 110 $aiBlogService->delDetail($info['task_id']);
134 //删除路由映射 111 //删除路由映射
135 - RouteMap::delRoute(RouteMap::SOURCE_AI_BLOG, $id, $this->user['project_id']); 112 + RouteMap::delRoute(RouteMap::SOURCE_AI_VIDEO, $id, $this->user['project_id']);
136 $this->model->del(['id'=>$id]); 113 $this->model->del(['id'=>$id]);
137 } 114 }
138 - shell_exec('php artisan save_ai_blog_list '.$this->user['project_id'].' > /dev/null 2>&1 &');  
139 }catch (\Exception $e){ 115 }catch (\Exception $e){
140 - $this->fail('删除失败'); 116 + $this->fail('删除失败,请联系管理员');
141 } 117 }
142 return $this->success(); 118 return $this->success();
143 } 119 }
@@ -70,16 +70,17 @@ class AiBlogService @@ -70,16 +70,17 @@ class AiBlogService
70 * @time :2025/2/13 14:39 70 * @time :2025/2/13 14:39
71 * @param :type=(1作者2文章) keyword=关键词 subtype=blog url=回调url 71 * @param :type=(1作者2文章) keyword=关键词 subtype=blog url=回调url
72 */ 72 */
73 - public function createTask($keyword,$type = 2,$subtype = 'Blog',$template_id = 1){ 73 + public function createTask($keyword,$type = 2,$subtype = 'Blog',$anchor = []){
74 $request_url = $this->url.'api/task/create'; 74 $request_url = $this->url.'api/task/create';
75 $param = [ 75 $param = [
76 - 'mch_id'=>$this->mch_id,  
77 'keyword'=>$keyword, 76 'keyword'=>$keyword,
78 'type'=>$type, 77 'type'=>$type,
79 'subtype'=>$subtype, 78 'subtype'=>$subtype,
80 - 'url'=>$this->route,  
81 - 'template_id'=>$template_id  
82 ]; 79 ];
  80 + $param['anchor'] = json_encode($anchor,true);
  81 + $param['url'] = $this->route;
  82 + $param['mch_id'] = $this->mch_id;
  83 + $param['template_id'] = 1;
83 $this->sign = $this->generateSign($param,$this->key); 84 $this->sign = $this->generateSign($param,$this->key);
84 $param['sign'] = $this->sign; 85 $param['sign'] = $this->sign;
85 $result = http_post($request_url,json_encode($param,true)); 86 $result = http_post($request_url,json_encode($param,true));
@@ -152,6 +152,13 @@ Route::middleware(['bloginauth'])->group(function () { @@ -152,6 +152,13 @@ Route::middleware(['bloginauth'])->group(function () {
152 152
153 //ai生成相关接口 153 //ai生成相关接口
154 Route::prefix('ai')->group(function () { 154 Route::prefix('ai')->group(function () {
  155 + //ai视屏
  156 + Route::prefix('video')->group(function () {
  157 + Route::any('/', [\App\Http\Controllers\Bside\Ai\AiVideoController::class, 'lists'])->name('ai_video_lists');
  158 + Route::any('/getInfo', [\App\Http\Controllers\Bside\Ai\AiVideoController::class, 'getInfo'])->name('ai_video_getInfo');
  159 + Route::any('/sendTask', [\App\Http\Controllers\Bside\Ai\AiVideoController::class, 'sendTask'])->name('ai_video_sendTask');
  160 + Route::any('/del', [\App\Http\Controllers\Bside\Ai\AiVideoController::class, 'delete'])->name('ai_video_delete');
  161 + });
155 //ai 162 //ai
156 Route::any('/news/', [\App\Http\Controllers\Bside\Ai\AiNewsController::class, 'save'])->name('ai_news_save'); 163 Route::any('/news/', [\App\Http\Controllers\Bside\Ai\AiNewsController::class, 'save'])->name('ai_news_save');
157 Route::any('/blog/getAiBlog', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'getAiBlog'])->name('ai_blog_getAiBlog'); 164 Route::any('/blog/getAiBlog', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'getAiBlog'])->name('ai_blog_getAiBlog');