正在显示
2 个修改的文件
包含
206 行增加
和
0 行删除
| @@ -9,9 +9,69 @@ | @@ -9,9 +9,69 @@ | ||
| 9 | 9 | ||
| 10 | namespace App\Http\Controllers\Bside\Ai; | 10 | namespace App\Http\Controllers\Bside\Ai; |
| 11 | 11 | ||
| 12 | +use App\Enums\Common\Code; | ||
| 12 | use App\Http\Controllers\Bside\BaseController; | 13 | use App\Http\Controllers\Bside\BaseController; |
| 14 | +use App\Http\Logic\Bside\Ai\AiVideoLogic; | ||
| 15 | +use App\Models\Ai\AiVideo; | ||
| 13 | 16 | ||
| 14 | class AiVideoController extends BaseController | 17 | class AiVideoController extends BaseController |
| 15 | { | 18 | { |
| 19 | + /** | ||
| 20 | + * @remark :获取aiVideo列表 | ||
| 21 | + * @name :lists | ||
| 22 | + * @author :lyh | ||
| 23 | + * @method :post | ||
| 24 | + * @time :2025/3/5 14:12 | ||
| 25 | + */ | ||
| 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']); | ||
| 28 | + if(!empty($lists) && !empty($lists['list'])){ | ||
| 29 | + foreach ($lists['list'] as $k => $v){ | ||
| 30 | + $v['image'] = getImageUrl($v['image']); | ||
| 31 | + if(!empty($v['route'])){ | ||
| 32 | + $v['route'] = $this->user['test_domain'] . 'video/' . $v['route']; | ||
| 33 | + } | ||
| 34 | + $lists['list'][$k] = $v; | ||
| 35 | + } | ||
| 36 | + } | ||
| 37 | + $this->response('success',Code::SUCCESS,$lists); | ||
| 38 | + } | ||
| 16 | 39 | ||
| 40 | + /** | ||
| 41 | + * @remark :获取详情 | ||
| 42 | + * @name :getInfo | ||
| 43 | + * @author :lyh | ||
| 44 | + * @method :post | ||
| 45 | + * @time :2025/3/5 14:22 | ||
| 46 | + */ | ||
| 47 | + public function getInfo(AiVideo $aiVideo){ | ||
| 48 | + $this->request->validate([ | ||
| 49 | + 'id'=>['required'], | ||
| 50 | + ],[ | ||
| 51 | + 'id.required' => '主键不能为空', | ||
| 52 | + ]); | ||
| 53 | + $info = $aiVideo->read(['id'=>$this->param['id']]); | ||
| 54 | + $info['image'] = getImageUrl($info['image']); | ||
| 55 | + $this->response('success',Code::SUCCESS,$info); | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + /** | ||
| 59 | + * @remark :发布任务 | ||
| 60 | + * @name :sendTask | ||
| 61 | + * @author :lyh | ||
| 62 | + * @method :post | ||
| 63 | + * @time :2025/3/5 14:29 | ||
| 64 | + */ | ||
| 65 | + public function sendTask(AiVideoLogic $aiVideoLogic){ | ||
| 66 | + $this->request->validate([ | ||
| 67 | + 'keyword'=>['required'], | ||
| 68 | + 'type'=>['required'], | ||
| 69 | + ],[ | ||
| 70 | + 'keyword.required' => '关键字不能为空', | ||
| 71 | + 'type.required' => '场景不能为空', | ||
| 72 | + ]); | ||
| 73 | + //获取当前项目的ai_blog设置 | ||
| 74 | + $result = $aiVideoLogic->sendTask(); | ||
| 75 | + $this->response('success',Code::SUCCESS,$result); | ||
| 76 | + } | ||
| 17 | } | 77 | } |
app/Http/Logic/Bside/Ai/AiVideoLogic.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Http\Logic\Bside\Ai; | ||
| 4 | + | ||
| 5 | +use App\Helper\Translate; | ||
| 6 | +use App\Http\Logic\Bside\BaseLogic; | ||
| 7 | +use App\Models\Ai\AiBlogAuthor; | ||
| 8 | +use App\Models\Ai\AiVideo; | ||
| 9 | +use App\Models\Project\AiBlogTask; | ||
| 10 | +use App\Models\Project\ProjectAiSetting; | ||
| 11 | +use App\Models\RouteMap\RouteMap; | ||
| 12 | +use App\Services\AiBlogService; | ||
| 13 | + | ||
| 14 | +/** | ||
| 15 | + * @remark :视频模块 | ||
| 16 | + * @name :AiVideoLogic | ||
| 17 | + * @author :lyh | ||
| 18 | + * @method :post | ||
| 19 | + * @time :2025/3/5 14:11 | ||
| 20 | + */ | ||
| 21 | +class AiVideoLogic extends BaseLogic | ||
| 22 | +{ | ||
| 23 | + public function __construct() | ||
| 24 | + { | ||
| 25 | + parent::__construct(); | ||
| 26 | + $this->param = $this->requestAll; | ||
| 27 | + $this->model = new AiVideo(); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * @remark :获取配置信息 | ||
| 32 | + * @name :getProjectAiSetting | ||
| 33 | + * @author :lyh | ||
| 34 | + * @method :post | ||
| 35 | + * @time :2025/2/21 14:51 | ||
| 36 | + */ | ||
| 37 | + public function getProjectAiSetting(){ | ||
| 38 | + $projectAiSettingModel = new ProjectAiSetting(); | ||
| 39 | + $aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$this->user['project_id']]); | ||
| 40 | + if($aiSettingInfo === false){ | ||
| 41 | + $this->fail('请先联系管理员开启Ai配置'); | ||
| 42 | + } | ||
| 43 | + return $aiSettingInfo; | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * @remark :ai发布博客 | ||
| 48 | + * @name :blogSave | ||
| 49 | + * @author :lyh | ||
| 50 | + * @method :post | ||
| 51 | + * @time :2023/7/5 14:46 | ||
| 52 | + */ | ||
| 53 | + public function blogSave(){ | ||
| 54 | + 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_BLOG, $this->param['id'], $this->user['project_id']); | ||
| 59 | + $this->model->edit($this->param,['id'=>$this->param['id']]); | ||
| 60 | + $aiSettingInfo = $this->getProjectAiSetting(); | ||
| 61 | + $aiBlogService = new AiBlogService(); | ||
| 62 | + $aiBlogService->mch_id = $aiSettingInfo['mch_id']; | ||
| 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']]); | ||
| 88 | + }catch (\Exception $e){ | ||
| 89 | + $this->fail('保存失败,请联系管理员'); | ||
| 90 | + } | ||
| 91 | + return $this->success(); | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + /** | ||
| 95 | + * @remark :发布任务 | ||
| 96 | + * @name :sendTask | ||
| 97 | + * @author :lyh | ||
| 98 | + * @method :post | ||
| 99 | + * @time :2025/2/14 10:28 | ||
| 100 | + * @detail :type=2/生成文章 type=3/更新列表页记录 | ||
| 101 | + * @detail :status=1/待执行 | ||
| 102 | + */ | ||
| 103 | + public function sendTask(){ | ||
| 104 | + $aiSettingInfo = $this->getProjectAiSetting(); | ||
| 105 | + $aiBlogService = new AiBlogService(); | ||
| 106 | + $aiBlogService->mch_id = $aiSettingInfo['mch_id']; | ||
| 107 | + $aiBlogService->key = $aiSettingInfo['key']; | ||
| 108 | + $aiBlogService->route = generateRoute(Translate::tran($this->param['keyword'], 'en')); | ||
| 109 | + $result = $aiBlogService->createTask($this->param['keyword'],$this->param['type'],'video'); | ||
| 110 | + if($result['status'] == 200){ | ||
| 111 | + $aiBlogTaskModel = new AiBlogTask(); | ||
| 112 | + $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']]); | ||
| 114 | + } | ||
| 115 | + return $this->success(); | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + /** | ||
| 119 | + * @remark :删除 | ||
| 120 | + * @name :blogDelete | ||
| 121 | + * @author :lyh | ||
| 122 | + * @method :post | ||
| 123 | + * @time :2025/2/20 18:21 | ||
| 124 | + */ | ||
| 125 | + public function blogDelete(){ | ||
| 126 | + try { | ||
| 127 | + $aiSettingInfo = $this->getProjectAiSetting(); | ||
| 128 | + $aiBlogService = new AiBlogService(); | ||
| 129 | + foreach ($this->param['ids'] as $id) { | ||
| 130 | + $info = $this->model->read(['id'=>$id],['task_id']); | ||
| 131 | + $aiBlogService->mch_id = $aiSettingInfo['mch_id']; | ||
| 132 | + $aiBlogService->key = $aiSettingInfo['key']; | ||
| 133 | + $aiBlogService->delDetail($info['task_id']); | ||
| 134 | + //删除路由映射 | ||
| 135 | + RouteMap::delRoute(RouteMap::SOURCE_AI_BLOG, $id, $this->user['project_id']); | ||
| 136 | + $this->model->del(['id'=>$id]); | ||
| 137 | + } | ||
| 138 | + shell_exec('php artisan save_ai_blog_list '.$this->user['project_id'].' > /dev/null 2>&1 &'); | ||
| 139 | + }catch (\Exception $e){ | ||
| 140 | + $this->fail('删除失败'); | ||
| 141 | + } | ||
| 142 | + return $this->success(); | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + | ||
| 146 | +} |
-
请 注册 或 登录 后发表评论