Merge remote-tracking branch 'origin/master' into akun
正在显示
11 个修改的文件
包含
482 行增加
和
39 行删除
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :AiBlogAuthorTask.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2025/2/21 11:12 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Console\Commands\AiBlog; | ||
| 11 | + | ||
| 12 | +use App\Models\Ai\AiBlog; | ||
| 13 | +use App\Models\Ai\AiBlogAuthor; | ||
| 14 | +use App\Models\Project\AiBlogTask as AiBlogTaskModel; | ||
| 15 | +use App\Models\Project\ProjectAiSetting; | ||
| 16 | +use App\Models\RouteMap\RouteMap; | ||
| 17 | +use App\Services\AiBlogService; | ||
| 18 | +use App\Services\ProjectServer; | ||
| 19 | +use Illuminate\Console\Command; | ||
| 20 | +use Illuminate\Support\Facades\Cache; | ||
| 21 | +use Illuminate\Support\Facades\DB; | ||
| 22 | + | ||
| 23 | +class AiBlogAuthorTask extends Command | ||
| 24 | +{ | ||
| 25 | + /** | ||
| 26 | + * The name and signature of the console command. | ||
| 27 | + * | ||
| 28 | + * @var string | ||
| 29 | + */ | ||
| 30 | + protected $signature = 'save_ai_blog_author'; | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * The console command description. | ||
| 34 | + * | ||
| 35 | + * @var string | ||
| 36 | + */ | ||
| 37 | + protected $description = '查询ai_blog_author是否已经生成'; | ||
| 38 | + | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * @remark :获取作者 | ||
| 42 | + * @name :handle | ||
| 43 | + * @author :lyh | ||
| 44 | + * @method :post | ||
| 45 | + * @time :2025/2/21 11:30 | ||
| 46 | + */ | ||
| 47 | + public function handle(){ | ||
| 48 | + $aiBlogTaskModel = new AiBlogTaskModel(); | ||
| 49 | + while (true){ | ||
| 50 | + $info = $aiBlogTaskModel->where('status',1)->where('type',1)->inRandomOrder()->first(); | ||
| 51 | + if(empty($info)){ | ||
| 52 | + sleep(300); | ||
| 53 | + continue; | ||
| 54 | + } | ||
| 55 | + $info = $info->toArray(); | ||
| 56 | + echo '开始->project_id:' . $info['project_id'] . PHP_EOL . date('Y-m-d H:i:s'); | ||
| 57 | + //获取配置 | ||
| 58 | + $aiSettingInfo = $this->getSetting($info['project_id']); | ||
| 59 | + $aiBlogService = new AiBlogService(); | ||
| 60 | + $aiBlogService->mch_id = $aiSettingInfo['mch_id']; | ||
| 61 | + $aiBlogService->key = $aiSettingInfo['key']; | ||
| 62 | + $result = $aiBlogService->getAuthor(); | ||
| 63 | + if(!isset($result['status'])){ | ||
| 64 | + continue; | ||
| 65 | + } | ||
| 66 | + if($result['status'] != 200){ | ||
| 67 | + sleep(10); | ||
| 68 | + continue; | ||
| 69 | + } | ||
| 70 | + //保存当前项目ai_blog数据 | ||
| 71 | + ProjectServer::useProject($info['project_id']); | ||
| 72 | + $this->saveAiBlogAuthor($result['data'] ?? [],$info['project_id']); | ||
| 73 | + DB::disconnect('custom_mysql'); | ||
| 74 | + //修改任务状态 | ||
| 75 | + $aiBlogTaskModel->edit(['status'=>2],['id'=>$info['id']]); | ||
| 76 | + echo '结束->任务id:' . $info['task_id'] . PHP_EOL . date('Y-m-d H:i:s'); | ||
| 77 | + } | ||
| 78 | + return true; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + | ||
| 82 | + /** | ||
| 83 | + * @remark :获取项目配置 | ||
| 84 | + * @name :getSetting | ||
| 85 | + * @author :lyh | ||
| 86 | + * @method :post | ||
| 87 | + * @time :2025/2/14 11:27 | ||
| 88 | + */ | ||
| 89 | + public function getSetting($project_id){ | ||
| 90 | + $ai_cache = Cache::get('ai_blog_'.$project_id); | ||
| 91 | + if($ai_cache){ | ||
| 92 | + return $ai_cache; | ||
| 93 | + } | ||
| 94 | + $projectAiSettingModel = new ProjectAiSetting(); | ||
| 95 | + $aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$project_id]); | ||
| 96 | + Cache::put('ai_blog_'.$project_id,$aiSettingInfo,3600); | ||
| 97 | + return $aiSettingInfo; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + /** | ||
| 101 | + * @remark :保存数据 | ||
| 102 | + * @name :saveAiBlogAuthor | ||
| 103 | + * @author :lyh | ||
| 104 | + * @method :post | ||
| 105 | + * @time :2025/2/21 11:36 | ||
| 106 | + */ | ||
| 107 | + public function saveAiBlogAuthor($data,$project_id){ | ||
| 108 | + if(empty($data)){ | ||
| 109 | + return true; | ||
| 110 | + } | ||
| 111 | + $aiBlogAuthorModel = new AiBlogAuthor(); | ||
| 112 | + foreach ($data as $v){ | ||
| 113 | + $param = [ | ||
| 114 | + 'author_id'=>$v['id'], | ||
| 115 | + 'title'=>$v['title'], | ||
| 116 | + 'image'=>str_replace_url($v['picture']), | ||
| 117 | + 'description'=>$v['description'], | ||
| 118 | + ]; | ||
| 119 | + $id = $aiBlogAuthorModel->addReturnId($param); | ||
| 120 | + $route = RouteMap::setRoute($v['title'], RouteMap::SOURCE_AI_BLOG_AUTHOR, $id, $project_id); | ||
| 121 | + $aiBlogAuthorModel->edit(['route'=>$route],['id'=>$id]); | ||
| 122 | + } | ||
| 123 | + return true; | ||
| 124 | + } | ||
| 125 | +} |
| @@ -10,7 +10,9 @@ | @@ -10,7 +10,9 @@ | ||
| 10 | namespace App\Console\Commands\AiBlog; | 10 | namespace App\Console\Commands\AiBlog; |
| 11 | 11 | ||
| 12 | use App\Models\Ai\AiBlog; | 12 | use App\Models\Ai\AiBlog; |
| 13 | +use App\Models\Ai\AiBlogAuthor; | ||
| 13 | use App\Models\Project\ProjectAiSetting; | 14 | use App\Models\Project\ProjectAiSetting; |
| 15 | +use App\Models\RouteMap\RouteMap; | ||
| 14 | use App\Services\AiBlogService; | 16 | use App\Services\AiBlogService; |
| 15 | use App\Services\ProjectServer; | 17 | use App\Services\ProjectServer; |
| 16 | use Illuminate\Console\Command; | 18 | use Illuminate\Console\Command; |
| @@ -38,9 +40,9 @@ class AiBlogTask extends Command | @@ -38,9 +40,9 @@ class AiBlogTask extends Command | ||
| 38 | public function handle(){ | 40 | public function handle(){ |
| 39 | $aiBlogTaskModel = new AiBlogTaskModel(); | 41 | $aiBlogTaskModel = new AiBlogTaskModel(); |
| 40 | while (true){ | 42 | while (true){ |
| 41 | - $info = $aiBlogTaskModel->where('status',1)->orderBy('id','asc')->first(); | 43 | + $info = $aiBlogTaskModel->where('status',1)->where('type',2)->inRandomOrder()->first(); |
| 42 | if(empty($info)){ | 44 | if(empty($info)){ |
| 43 | - sleep(30); | 45 | + sleep(300); |
| 44 | continue; | 46 | continue; |
| 45 | } | 47 | } |
| 46 | $info = $info->toArray(); | 48 | $info = $info->toArray(); |
| @@ -53,26 +55,36 @@ class AiBlogTask extends Command | @@ -53,26 +55,36 @@ class AiBlogTask extends Command | ||
| 53 | $aiBlogService->task_id = $info['task_id']; | 55 | $aiBlogService->task_id = $info['task_id']; |
| 54 | $result = $aiBlogService->getDetail(); | 56 | $result = $aiBlogService->getDetail(); |
| 55 | if(!isset($result['status'])){ | 57 | if(!isset($result['status'])){ |
| 56 | - //修改任务状态 | ||
| 57 | - $aiBlogTaskModel->edit(['status'=>3],['id'=>$info['id']]); | ||
| 58 | continue; | 58 | continue; |
| 59 | } | 59 | } |
| 60 | if($result['status'] != 200){ | 60 | if($result['status'] != 200){ |
| 61 | - sleep(300); | 61 | + sleep(10); |
| 62 | continue; | 62 | continue; |
| 63 | } | 63 | } |
| 64 | - //修改任务状态 | ||
| 65 | - $aiBlogTaskModel->edit(['status'=>2],['id'=>$info['id']]); | ||
| 66 | //保存当前项目ai_blog数据 | 64 | //保存当前项目ai_blog数据 |
| 67 | ProjectServer::useProject($info['project_id']); | 65 | ProjectServer::useProject($info['project_id']); |
| 68 | $aiBlogModel = new AiBlog(); | 66 | $aiBlogModel = new AiBlog(); |
| 69 | - $aiBlogModel->edit(['new_title'=>$result['data']['title'],'image'=>$result['data']['thumb'],'text'=>$result['data']['section'],'status'=>2],['task_id'=>$info['task_id']]); | 67 | + $aiBlogInfo = $aiBlogModel->read(['task_id'=>$info['task_id']],['id']); |
| 68 | + if($aiBlogInfo === false){ | ||
| 69 | + $aiBlogTaskModel->edit(['status'=>2],['id'=>$info['id']]); | ||
| 70 | + continue; | ||
| 71 | + } | ||
| 72 | + //拿到返回的路由查看是否重复 | ||
| 73 | + $route = RouteMap::setRoute($result['data']['url'], RouteMap::SOURCE_AI_BLOG, $aiBlogInfo['id'], $info['project_id']); | ||
| 74 | + if($route != $result['data']['url']){ | ||
| 75 | + $aiBlogService->updateDetail(['route'=>$this->param['route']]); | ||
| 76 | + } | ||
| 77 | + $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'=>$info['task_id']]); | ||
| 78 | + $this->updateAiBlogAuthor($aiSettingInfo,$result['data']['author_id']); | ||
| 70 | DB::disconnect('custom_mysql'); | 79 | DB::disconnect('custom_mysql'); |
| 80 | + //修改任务状态 | ||
| 81 | + $aiBlogTaskModel->edit(['status'=>2],['id'=>$info['id']]); | ||
| 71 | echo '结束->任务id:' . $info['task_id'] . PHP_EOL . date('Y-m-d H:i:s'); | 82 | echo '结束->任务id:' . $info['task_id'] . PHP_EOL . date('Y-m-d H:i:s'); |
| 72 | } | 83 | } |
| 73 | return true; | 84 | return true; |
| 74 | } | 85 | } |
| 75 | 86 | ||
| 87 | + | ||
| 76 | /** | 88 | /** |
| 77 | * @remark :获取项目配置 | 89 | * @remark :获取项目配置 |
| 78 | * @name :getSetting | 90 | * @name :getSetting |
| @@ -90,4 +102,30 @@ class AiBlogTask extends Command | @@ -90,4 +102,30 @@ class AiBlogTask extends Command | ||
| 90 | Cache::put('ai_blog_'.$project_id,$aiSettingInfo,3600); | 102 | Cache::put('ai_blog_'.$project_id,$aiSettingInfo,3600); |
| 91 | return $aiSettingInfo; | 103 | return $aiSettingInfo; |
| 92 | } | 104 | } |
| 105 | + | ||
| 106 | + /** | ||
| 107 | + * @remark :更新作者的页面 | ||
| 108 | + * @name :updateAiBlogAuthor | ||
| 109 | + * @author :lyh | ||
| 110 | + * @method :post | ||
| 111 | + * @time :2025/2/21 11:53 | ||
| 112 | + */ | ||
| 113 | + public function updateAiBlogAuthor($aiSettingInfo,$author_id){ | ||
| 114 | + if(empty($author_id)){ | ||
| 115 | + return true; | ||
| 116 | + } | ||
| 117 | + $aiBlogService = new AiBlogService(); | ||
| 118 | + $aiBlogService->mch_id = $aiSettingInfo['mch_id']; | ||
| 119 | + $aiBlogService->key = $aiSettingInfo['key']; | ||
| 120 | + $aiBlogService->author_id = $author_id; | ||
| 121 | + $result = $aiBlogService->getAuthorDetail(); | ||
| 122 | + if(isset($result['status']) && $result['status'] == 200){ | ||
| 123 | + //当前作者的页面 | ||
| 124 | + $aiBlogAuthorModel = new AiBlogAuthor(); | ||
| 125 | + if(!empty($result['data']['section'])){ | ||
| 126 | + $aiBlogAuthorModel->edit(['text'=>$result['data']['section']],['author_id'=>$author_id]); | ||
| 127 | + } | ||
| 128 | + } | ||
| 129 | + return true; | ||
| 130 | + } | ||
| 93 | } | 131 | } |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :RequestUrlLog.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2025/2/21 9:55 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Console\Commands\RequestUrlLog; | ||
| 11 | + | ||
| 12 | +use Illuminate\Console\Command; | ||
| 13 | + | ||
| 14 | +class RequestUrlLog extends Command | ||
| 15 | +{ | ||
| 16 | + /** | ||
| 17 | + * The name and signature of the console command. | ||
| 18 | + * | ||
| 19 | + * @var string | ||
| 20 | + */ | ||
| 21 | + protected $signature = 'request_url_log'; | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * The console command description. | ||
| 25 | + * | ||
| 26 | + * @var string | ||
| 27 | + */ | ||
| 28 | + protected $description = '统计昨日数据'; | ||
| 29 | +} |
| @@ -7,6 +7,7 @@ use App\Http\Controllers\Bside\BaseController; | @@ -7,6 +7,7 @@ use App\Http\Controllers\Bside\BaseController; | ||
| 7 | use App\Http\Logic\Bside\Ai\AiBlogLogic; | 7 | use App\Http\Logic\Bside\Ai\AiBlogLogic; |
| 8 | use App\Http\Requests\Bside\Ai\AiBlogRequest; | 8 | use App\Http\Requests\Bside\Ai\AiBlogRequest; |
| 9 | use App\Models\Ai\AiBlog; | 9 | use App\Models\Ai\AiBlog; |
| 10 | +use App\Models\Ai\AiBlogAuthor; | ||
| 10 | use App\Services\AiBlogService; | 11 | use App\Services\AiBlogService; |
| 11 | use App\Services\ProjectServer; | 12 | use App\Services\ProjectServer; |
| 12 | use Illuminate\Support\Facades\DB; | 13 | use Illuminate\Support\Facades\DB; |
| @@ -27,6 +28,42 @@ class AiBlogController extends BaseController | @@ -27,6 +28,42 @@ class AiBlogController extends BaseController | ||
| 27 | } | 28 | } |
| 28 | 29 | ||
| 29 | /** | 30 | /** |
| 31 | + * @remark :获取详情 | ||
| 32 | + * @name :getInfo | ||
| 33 | + * @author :lyh | ||
| 34 | + * @method :post | ||
| 35 | + * @time :2025/2/20 18:17 | ||
| 36 | + */ | ||
| 37 | + public function getInfo(AiBlog $aiBlog){ | ||
| 38 | + $this->request->validate([ | ||
| 39 | + 'id'=>['required'], | ||
| 40 | + ],[ | ||
| 41 | + 'id.required' => '主键不能为空', | ||
| 42 | + ]); | ||
| 43 | + $info = $aiBlog->read(['id'=>$this->param['id']]); | ||
| 44 | + $info['image'] = getImageUrl($info['image']); | ||
| 45 | + $this->response('success',Code::SUCCESS,$info); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + /** | ||
| 49 | + * @remark :删除 | ||
| 50 | + * @name :delete | ||
| 51 | + * @author :lyh | ||
| 52 | + * @method :post | ||
| 53 | + * @time :2025/2/20 18:19 | ||
| 54 | + */ | ||
| 55 | + public function delete(AiBlogLogic $aiBlogLogic) | ||
| 56 | + { | ||
| 57 | + $this->request->validate([ | ||
| 58 | + 'ids'=>['required', new Ids()] | ||
| 59 | + ],[ | ||
| 60 | + 'ids.required' => 'ID不能为空' | ||
| 61 | + ]); | ||
| 62 | + $aiBlogLogic->blogDelete(); | ||
| 63 | + $this->response('success'); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + /** | ||
| 30 | * @remark :获取ai博客列表 | 67 | * @remark :获取ai博客列表 |
| 31 | * @name :getAiBlog | 68 | * @name :getAiBlog |
| 32 | * @author :lyh | 69 | * @author :lyh |
| @@ -37,7 +74,7 @@ class AiBlogController extends BaseController | @@ -37,7 +74,7 @@ class AiBlogController extends BaseController | ||
| 37 | $lists = $aiBlog->lists($this->map,$this->page,$this->row,'id',['id','new_title','image','task_id','status','created_at','updated_at']); | 74 | $lists = $aiBlog->lists($this->map,$this->page,$this->row,'id',['id','new_title','image','task_id','status','created_at','updated_at']); |
| 38 | if(!empty($lists) && !empty($lists['list'])){ | 75 | if(!empty($lists) && !empty($lists['list'])){ |
| 39 | foreach ($lists['list'] as $k => $v){ | 76 | foreach ($lists['list'] as $k => $v){ |
| 40 | - $v['image'] = getImageUrl($v['image'],$this->user['storage_type'],$this->user['project_location']); | 77 | + $v['image'] = getImageUrl($v['image']); |
| 41 | $lists['list'][$k] = $v; | 78 | $lists['list'][$k] = $v; |
| 42 | } | 79 | } |
| 43 | } | 80 | } |
| @@ -55,11 +92,9 @@ class AiBlogController extends BaseController | @@ -55,11 +92,9 @@ class AiBlogController extends BaseController | ||
| 55 | $this->request->validate([ | 92 | $this->request->validate([ |
| 56 | 'keyword'=>['required'], | 93 | 'keyword'=>['required'], |
| 57 | 'type'=>['required'], | 94 | 'type'=>['required'], |
| 58 | - 'route'=>['required'] | ||
| 59 | ],[ | 95 | ],[ |
| 60 | 'keyword.required' => '关键字不能为空', | 96 | 'keyword.required' => '关键字不能为空', |
| 61 | 'type.required' => '场景不能为空', | 97 | 'type.required' => '场景不能为空', |
| 62 | - 'route.required' => '路由不能为空', | ||
| 63 | ]); | 98 | ]); |
| 64 | //获取当前项目的ai_blog设置 | 99 | //获取当前项目的ai_blog设置 |
| 65 | $result = $aiBlogLogic->sendTask(); | 100 | $result = $aiBlogLogic->sendTask(); |
| @@ -67,15 +102,50 @@ class AiBlogController extends BaseController | @@ -67,15 +102,50 @@ class AiBlogController extends BaseController | ||
| 67 | } | 102 | } |
| 68 | 103 | ||
| 69 | /** | 104 | /** |
| 70 | - * @remark :创建作者 | ||
| 71 | - * @name :createAuthor | 105 | + * @remark :获取作者列表 |
| 106 | + * @name :getAiBlogAuthor | ||
| 72 | * @author :lyh | 107 | * @author :lyh |
| 73 | * @method :post | 108 | * @method :post |
| 74 | - * @time :2025/2/20 10:45 | 109 | + * @time :2025/2/21 11:44 |
| 75 | */ | 110 | */ |
| 76 | - public function createAuthor(AiBlogLogic $aiBlogLogic){ | ||
| 77 | - //获取当前项目的ai_blog设置 | ||
| 78 | - $result = $aiBlogLogic->createAuthor(); | ||
| 79 | - $this->response('success',Code::SUCCESS,$result); | 111 | + public function getAiBlogAuthor(AiBlogAuthor $aiBlogAuthor){ |
| 112 | + $field = ['id','route','author_id','title','image','created_at','updated_at']; | ||
| 113 | + $lists = $aiBlogAuthor->lists($this->map,$this->page,$this->row,'id',$field); | ||
| 114 | + $this->response('success',Code::SUCCESS,$lists); | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + /** | ||
| 118 | + * @remark :获取详情数据 | ||
| 119 | + * @name :getAuthorInfo | ||
| 120 | + * @author :lyh | ||
| 121 | + * @method :post | ||
| 122 | + * @time :2025/2/21 13:54 | ||
| 123 | + */ | ||
| 124 | + public function getAuthorInfo(AiBlogAuthor $aiBlogAuthor){ | ||
| 125 | + $this->request->validate([ | ||
| 126 | + 'id'=>['required'], | ||
| 127 | + ],[ | ||
| 128 | + 'id.required' => '主键不能为空', | ||
| 129 | + ]); | ||
| 130 | + $info = $aiBlogAuthor->read($this->map); | ||
| 131 | + $info['image'] = getImageUrl($info['image']); | ||
| 132 | + $this->response('success',Code::SUCCESS,$info); | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + /** | ||
| 136 | + * @remark :编辑详情数据 | ||
| 137 | + * @name :saveBlogAuthor | ||
| 138 | + * @author :lyh | ||
| 139 | + * @method :post | ||
| 140 | + * @time :2025/2/21 13:54 | ||
| 141 | + */ | ||
| 142 | + public function saveBlogAuthor(AiBlogLogic $aiBlogLogic){ | ||
| 143 | + $this->request->validate([ | ||
| 144 | + 'id'=>['required'], | ||
| 145 | + ],[ | ||
| 146 | + 'id.required' => '主键不能为空', | ||
| 147 | + ]); | ||
| 148 | + $info = $aiBlogLogic->saveBlogAuthor(); | ||
| 149 | + $this->response('success',Code::SUCCESS,$info); | ||
| 80 | } | 150 | } |
| 81 | } | 151 | } |
| @@ -12,6 +12,7 @@ use App\Helper\FormGlobalsoApi; | @@ -12,6 +12,7 @@ use App\Helper\FormGlobalsoApi; | ||
| 12 | use App\Http\Logic\Aside\BaseLogic; | 12 | use App\Http\Logic\Aside\BaseLogic; |
| 13 | use App\Jobs\CopyImageFileJob; | 13 | use App\Jobs\CopyImageFileJob; |
| 14 | use App\Jobs\CopyProjectJob; | 14 | use App\Jobs\CopyProjectJob; |
| 15 | +use App\Models\Ai\AiBlogAuthor; | ||
| 15 | use App\Models\Channel\Channel; | 16 | use App\Models\Channel\Channel; |
| 16 | use App\Models\Channel\User; | 17 | use App\Models\Channel\User; |
| 17 | use App\Models\Channel\Zone; | 18 | use App\Models\Channel\Zone; |
| @@ -24,6 +25,7 @@ use App\Models\Inquiry\InquiryIP; | @@ -24,6 +25,7 @@ use App\Models\Inquiry\InquiryIP; | ||
| 24 | use App\Models\Inquiry\InquirySet; | 25 | use App\Models\Inquiry\InquirySet; |
| 25 | use App\Models\Manage\Manage; | 26 | use App\Models\Manage\Manage; |
| 26 | use App\Models\Project\After; | 27 | use App\Models\Project\After; |
| 28 | +use App\Models\Project\AiBlogTask; | ||
| 27 | use App\Models\Project\DeployBuild; | 29 | use App\Models\Project\DeployBuild; |
| 28 | use App\Models\Project\DeployOptimize; | 30 | use App\Models\Project\DeployOptimize; |
| 29 | use App\Models\Project\InquiryFilterConfig; | 31 | use App\Models\Project\InquiryFilterConfig; |
| @@ -222,6 +224,7 @@ class ProjectLogic extends BaseLogic | @@ -222,6 +224,7 @@ class ProjectLogic extends BaseLogic | ||
| 222 | 'key'=>$result['data']['key'], | 224 | 'key'=>$result['data']['key'], |
| 223 | ]; | 225 | ]; |
| 224 | $aiSettingModel->add($resData); | 226 | $aiSettingModel->add($resData); |
| 227 | + $this->createAuthor($project_id,$result['data']['mch_id'],$result['data']['key']); | ||
| 225 | } | 228 | } |
| 226 | }else{ | 229 | }else{ |
| 227 | //有信息更新 | 230 | //有信息更新 |
| @@ -244,6 +247,30 @@ class ProjectLogic extends BaseLogic | @@ -244,6 +247,30 @@ class ProjectLogic extends BaseLogic | ||
| 244 | } | 247 | } |
| 245 | 248 | ||
| 246 | /** | 249 | /** |
| 250 | + * @remark :创建作者 | ||
| 251 | + * @name :createAuthor | ||
| 252 | + * @author :lyh | ||
| 253 | + * @method :post | ||
| 254 | + * @time :2025/2/21 11:17 | ||
| 255 | + */ | ||
| 256 | + public function createAuthor($project_id,$mch_id,$key){ | ||
| 257 | + //查看当前项目是否已经创建了作者 | ||
| 258 | + $aiBlogTaskModel = new AiBlogTask(); | ||
| 259 | + $count = $aiBlogTaskModel->counts(); | ||
| 260 | + if($count > 0){ | ||
| 261 | + return true; | ||
| 262 | + } | ||
| 263 | + $aiBlogService = new AiBlogService(); | ||
| 264 | + $aiBlogService->mch_id = $mch_id; | ||
| 265 | + $aiBlogService->key = $key; | ||
| 266 | + $result = $aiBlogService->createAuthor(); | ||
| 267 | + if($result['status'] == 200){ | ||
| 268 | + $aiBlogTaskModel->add(['project_id'=>$project_id,'status'=>1,'type'=>1]); | ||
| 269 | + } | ||
| 270 | + return true; | ||
| 271 | + } | ||
| 272 | + | ||
| 273 | + /** | ||
| 247 | * @remark :选择服务器后双向绑定 | 274 | * @remark :选择服务器后双向绑定 |
| 248 | * @name :setServers | 275 | * @name :setServers |
| 249 | * @author :lyh | 276 | * @author :lyh |
| @@ -28,30 +28,68 @@ class AiBlogLogic extends BaseLogic | @@ -28,30 +28,68 @@ class AiBlogLogic extends BaseLogic | ||
| 28 | * @time :2023/7/5 14:46 | 28 | * @time :2023/7/5 14:46 |
| 29 | */ | 29 | */ |
| 30 | public function blogSave(){ | 30 | public function blogSave(){ |
| 31 | - if(!empty($this->param['image'])){ | ||
| 32 | - $this->param['image'] = str_replace_url($this->param['image']); | ||
| 33 | - } | ||
| 34 | - $this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $this->param['id'], $this->user['project_id']); | ||
| 35 | - $rs = $this->model->edit($this->param,['id'=>$this->param['id']]); | ||
| 36 | - if($rs === false){ | ||
| 37 | - $this->fail('error'); | 31 | + try { |
| 32 | + if(!empty($this->param['image'])){ | ||
| 33 | + $this->param['image'] = str_replace_url($this->param['image']); | ||
| 34 | + } | ||
| 35 | + $this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_AI_BLOG, $this->param['id'], $this->user['project_id']); | ||
| 36 | + $this->model->edit($this->param,['id'=>$this->param['id']]); | ||
| 37 | + $aiSettingInfo = $this->getProjectAiSetting(); | ||
| 38 | + $aiBlogService = new AiBlogService(); | ||
| 39 | + $aiBlogService->mch_id = $aiSettingInfo['mch_id']; | ||
| 40 | + $aiBlogService->key = $aiSettingInfo['key']; | ||
| 41 | + $aiBlogService->updateDetail(['title'=>$this->param['title'],'thumb'=>$this->param['image'],'route'=>$this->param['route'],'author_id'=>$this->param['author_id']]); | ||
| 42 | + }catch (\Exception $e){ | ||
| 43 | + $this->fail('保存失败,请联系管理员'); | ||
| 38 | } | 44 | } |
| 39 | return $this->success(); | 45 | return $this->success(); |
| 40 | } | 46 | } |
| 41 | 47 | ||
| 42 | /** | 48 | /** |
| 43 | - * @remark :发布任务 | ||
| 44 | - * @name :sendTask | 49 | + * @remark :获取配置信息 |
| 50 | + * @name :getProjectAiSetting | ||
| 45 | * @author :lyh | 51 | * @author :lyh |
| 46 | * @method :post | 52 | * @method :post |
| 47 | - * @time :2025/2/14 10:28 | 53 | + * @time :2025/2/21 14:51 |
| 48 | */ | 54 | */ |
| 49 | - public function sendTask(){ | 55 | + public function getProjectAiSetting(){ |
| 50 | $projectAiSettingModel = new ProjectAiSetting(); | 56 | $projectAiSettingModel = new ProjectAiSetting(); |
| 51 | $aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$this->user['project_id']]); | 57 | $aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$this->user['project_id']]); |
| 52 | if($aiSettingInfo === false){ | 58 | if($aiSettingInfo === false){ |
| 53 | $this->fail('请先联系管理员开启Ai博客'); | 59 | $this->fail('请先联系管理员开启Ai博客'); |
| 54 | } | 60 | } |
| 61 | + return $aiSettingInfo; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + /** | ||
| 65 | + * @remark :编辑作者 | ||
| 66 | + * @name :saveAuthor | ||
| 67 | + * @author :lyh | ||
| 68 | + * @method :post | ||
| 69 | + * @time :2025/2/21 14:46 | ||
| 70 | + */ | ||
| 71 | + public function saveBlogAuthor(){ | ||
| 72 | + try { | ||
| 73 | + if(!empty($this->param['image'])){ | ||
| 74 | + $this->param['image'] = str_replace_url($this->param['image']); | ||
| 75 | + } | ||
| 76 | + $this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_AI_BLOG_AUTHOR, $this->param['id'], $this->user['project_id']); | ||
| 77 | + $this->model->edit($this->param,['id'=>$this->param['id']]); | ||
| 78 | + }catch (\Exception $e){ | ||
| 79 | + $this->fail('保存失败,请联系管理员'); | ||
| 80 | + } | ||
| 81 | + return $this->success(); | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + /** | ||
| 85 | + * @remark :发布任务 | ||
| 86 | + * @name :sendTask | ||
| 87 | + * @author :lyh | ||
| 88 | + * @method :post | ||
| 89 | + * @time :2025/2/14 10:28 | ||
| 90 | + */ | ||
| 91 | + public function sendTask(){ | ||
| 92 | + $aiSettingInfo = $this->getProjectAiSetting(); | ||
| 55 | $aiBlogService = new AiBlogService(); | 93 | $aiBlogService = new AiBlogService(); |
| 56 | $aiBlogService->mch_id = $aiSettingInfo['mch_id']; | 94 | $aiBlogService->mch_id = $aiSettingInfo['mch_id']; |
| 57 | $aiBlogService->key = $aiSettingInfo['key']; | 95 | $aiBlogService->key = $aiSettingInfo['key']; |
| @@ -61,10 +99,8 @@ class AiBlogLogic extends BaseLogic | @@ -61,10 +99,8 @@ class AiBlogLogic extends BaseLogic | ||
| 61 | $aiBlogTaskModel = new AiBlogTask(); | 99 | $aiBlogTaskModel = new AiBlogTask(); |
| 62 | $aiBlogTaskModel->addReturnId(['project_id'=>$this->user['project_id'],'task_id'=>$result['data']['task_id'],'status'=>$result['data']['status']]); | 100 | $aiBlogTaskModel->addReturnId(['project_id'=>$this->user['project_id'],'task_id'=>$result['data']['task_id'],'status'=>$result['data']['status']]); |
| 63 | $aiBlogModel = new AiBlog(); | 101 | $aiBlogModel = new AiBlog(); |
| 64 | - $aiBlogId = $aiBlogModel->addReturnId(['keyword'=>$this->param['keyword'], 'status'=>$result['data']['status'], 'task_id'=>$result['data']['task_id'],'project_id'=>$this->user['project_id'], | 102 | + $aiBlogModel->addReturnId(['keyword'=>$this->param['keyword'], 'status'=>$result['data']['status'], 'task_id'=>$result['data']['task_id'],'project_id'=>$this->user['project_id'], |
| 65 | ]); | 103 | ]); |
| 66 | - $route = RouteMap::setRoute($aiBlogService->route, RouteMap::SOURCE_AI_BLOG, $aiBlogId, $this->user['project_id']); | ||
| 67 | - $aiBlogModel->edit(['route'=>$route],['id'=>$aiBlogId]); | ||
| 68 | } | 104 | } |
| 69 | return $this->success(); | 105 | return $this->success(); |
| 70 | } | 106 | } |
| @@ -77,15 +113,31 @@ class AiBlogLogic extends BaseLogic | @@ -77,15 +113,31 @@ class AiBlogLogic extends BaseLogic | ||
| 77 | * @time :2025/2/20 10:46 | 113 | * @time :2025/2/20 10:46 |
| 78 | */ | 114 | */ |
| 79 | public function createAuthor(){ | 115 | public function createAuthor(){ |
| 80 | - $projectAiSettingModel = new ProjectAiSetting(); | ||
| 81 | - $aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$this->user['project_id']]); | ||
| 82 | - if($aiSettingInfo === false){ | ||
| 83 | - $this->fail('请先联系管理员开启Ai博客'); | ||
| 84 | - } | 116 | + $aiSettingInfo = $this->getProjectAiSetting(); |
| 85 | $aiBlogService = new AiBlogService(); | 117 | $aiBlogService = new AiBlogService(); |
| 86 | $aiBlogService->mch_id = $aiSettingInfo['mch_id']; | 118 | $aiBlogService->mch_id = $aiSettingInfo['mch_id']; |
| 87 | $aiBlogService->key = $aiSettingInfo['key']; | 119 | $aiBlogService->key = $aiSettingInfo['key']; |
| 88 | $result = $aiBlogService->createAuthor(); | 120 | $result = $aiBlogService->createAuthor(); |
| 89 | return $this->success($result); | 121 | return $this->success($result); |
| 90 | } | 122 | } |
| 123 | + | ||
| 124 | + /** | ||
| 125 | + * @remark :删除 | ||
| 126 | + * @name :blogDelete | ||
| 127 | + * @author :lyh | ||
| 128 | + * @method :post | ||
| 129 | + * @time :2025/2/20 18:21 | ||
| 130 | + */ | ||
| 131 | + public function blogDelete(){ | ||
| 132 | + try { | ||
| 133 | + foreach ($this->param['ids'] as $id) { | ||
| 134 | + //删除路由映射 | ||
| 135 | + RouteMap::delRoute(RouteMap::SOURCE_AI_BLOG, $id, $this->user['project_id']); | ||
| 136 | + $this->model->del(['id'=>$id]); | ||
| 137 | + } | ||
| 138 | + }catch (\Exception $e){ | ||
| 139 | + $this->fail('删除失败'); | ||
| 140 | + } | ||
| 141 | + return $this->success(); | ||
| 142 | + } | ||
| 91 | } | 143 | } |
app/Models/Ai/AiBlogAuthor.php
0 → 100644
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :AiBlogAuthor.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2025/2/21 10:59 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Models\Ai; | ||
| 11 | + | ||
| 12 | +use App\Models\Base; | ||
| 13 | + | ||
| 14 | +class AiBlogAuthor extends Base | ||
| 15 | +{ | ||
| 16 | + protected $table = 'gl_ai_blog_author'; | ||
| 17 | + //连接数据库 | ||
| 18 | + protected $connection = 'custom_mysql'; | ||
| 19 | +} |
app/Models/RequestUrlLog/RequestUrlLog.php
0 → 100644
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :RequestUrlLog.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2025/2/21 9:38 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Models\RequestUrlLog; | ||
| 11 | + | ||
| 12 | +use App\Models\Base; | ||
| 13 | + | ||
| 14 | +/** | ||
| 15 | + * @remark :url请求日志 | ||
| 16 | + * @name :RequestUrlLog | ||
| 17 | + * @author :lyh | ||
| 18 | + * @method :post | ||
| 19 | + * @time :2025/2/21 9:48 | ||
| 20 | + */ | ||
| 21 | +class RequestUrlLog extends Base | ||
| 22 | +{ | ||
| 23 | + protected $table = 'gl_request_url_log'; | ||
| 24 | +} |
| @@ -33,8 +33,8 @@ class RouteMap extends Base | @@ -33,8 +33,8 @@ class RouteMap extends Base | ||
| 33 | const SOURCE_NEWS_CATE = 'news_category'; | 33 | const SOURCE_NEWS_CATE = 'news_category'; |
| 34 | //自定义模块 | 34 | //自定义模块 |
| 35 | const SOURCE_MODULE = 'module'; | 35 | const SOURCE_MODULE = 'module'; |
| 36 | - | ||
| 37 | const SOURCE_AI_BLOG = 'ai_blog'; | 36 | const SOURCE_AI_BLOG = 'ai_blog'; |
| 37 | + const SOURCE_AI_BLOG_AUTHOR = 'ai_blog_author';//ai博客作者 | ||
| 38 | //自定义模块分类 | 38 | //自定义模块分类 |
| 39 | const SOURCE_MODULE_CATE = 'module_category'; | 39 | const SOURCE_MODULE_CATE = 'module_category'; |
| 40 | 40 |
| @@ -20,6 +20,7 @@ class AiBlogService | @@ -20,6 +20,7 @@ class AiBlogService | ||
| 20 | public $route = '';//回调地址 | 20 | public $route = '';//回调地址 |
| 21 | 21 | ||
| 22 | public $task_id = '';//任务id | 22 | public $task_id = '';//任务id |
| 23 | + public $author_id = '';//作者id | ||
| 23 | /** | 24 | /** |
| 24 | * @remark :创建项目 | 25 | * @remark :创建项目 |
| 25 | * @name :createProject | 26 | * @name :createProject |
| @@ -104,6 +105,24 @@ class AiBlogService | @@ -104,6 +105,24 @@ class AiBlogService | ||
| 104 | } | 105 | } |
| 105 | 106 | ||
| 106 | /** | 107 | /** |
| 108 | + * @remark :获取作者信息 | ||
| 109 | + * @name :getAuthor | ||
| 110 | + * @author :lyh | ||
| 111 | + * @method :post | ||
| 112 | + * @time :2025/2/21 10:57 | ||
| 113 | + */ | ||
| 114 | + public function getAuthor(){ | ||
| 115 | + $request_url = $this->url.'api/author/list'; | ||
| 116 | + $param = [ | ||
| 117 | + 'mch_id'=>$this->mch_id, | ||
| 118 | + ]; | ||
| 119 | + $this->sign = $this->generateSign($param,$this->key); | ||
| 120 | + $param['sign'] = $this->sign; | ||
| 121 | + $result = http_post($request_url,json_encode($param,true)); | ||
| 122 | + return $result; | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + /** | ||
| 107 | * @remark :计算签名 | 126 | * @remark :计算签名 |
| 108 | * @name :generateSign | 127 | * @name :generateSign |
| 109 | * @author :lyh | 128 | * @author :lyh |
| @@ -143,4 +162,40 @@ class AiBlogService | @@ -143,4 +162,40 @@ class AiBlogService | ||
| 143 | $result = http_post($request_url,json_encode($param,true)); | 162 | $result = http_post($request_url,json_encode($param,true)); |
| 144 | return $result; | 163 | return $result; |
| 145 | } | 164 | } |
| 165 | + | ||
| 166 | + /** | ||
| 167 | + * @remark :获取作者页面 | ||
| 168 | + * @name :getAuthorDetail | ||
| 169 | + * @author :lyh | ||
| 170 | + * @method :post | ||
| 171 | + * @time :2025/2/21 11:55 | ||
| 172 | + */ | ||
| 173 | + public function getAuthorDetail(){ | ||
| 174 | + $request_url = $this->url.'api/author/detail'; | ||
| 175 | + $param = [ | ||
| 176 | + 'mch_id'=>$this->mch_id, | ||
| 177 | + 'author_id'=>$this->author_id, | ||
| 178 | + ]; | ||
| 179 | + $this->sign = $this->generateSign($param,$this->key); | ||
| 180 | + $param['sign'] = $this->sign; | ||
| 181 | + $result = http_post($request_url,json_encode($param,true)); | ||
| 182 | + return $result; | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + /** | ||
| 186 | + * @remark :更新文章 | ||
| 187 | + * @name :updateDetail | ||
| 188 | + * @author :lyh | ||
| 189 | + * @method :post | ||
| 190 | + * @time :2025/2/21 14:38 | ||
| 191 | + * @param :title , thumb , route , task_id | ||
| 192 | + */ | ||
| 193 | + public function updateDetail($param){ | ||
| 194 | + $request_url = $this->url.'api/result/save'; | ||
| 195 | + $param['mch_id'] = $this->mch_id; | ||
| 196 | + $this->sign = $this->generateSign($param,$this->key); | ||
| 197 | + $param['sign'] = $this->sign; | ||
| 198 | + $result = http_post($request_url,json_encode($param,true)); | ||
| 199 | + return $result; | ||
| 200 | + } | ||
| 146 | } | 201 | } |
| @@ -156,7 +156,11 @@ Route::middleware(['bloginauth'])->group(function () { | @@ -156,7 +156,11 @@ Route::middleware(['bloginauth'])->group(function () { | ||
| 156 | Route::any('/blog/getAiBlog', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'getAiBlog'])->name('ai_blog_getAiBlog'); | 156 | Route::any('/blog/getAiBlog', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'getAiBlog'])->name('ai_blog_getAiBlog'); |
| 157 | Route::any('/blog/save', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'save'])->name('ai_blog_save'); | 157 | Route::any('/blog/save', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'save'])->name('ai_blog_save'); |
| 158 | Route::any('/blog/sendTask', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'sendTask'])->name('ai_blog_sendTask'); | 158 | Route::any('/blog/sendTask', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'sendTask'])->name('ai_blog_sendTask'); |
| 159 | - Route::any('/blog/createAuthor', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'createAuthor'])->name('ai_blog_createAuthor'); | 159 | + Route::any('/blog/del', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'delete'])->name('ai_blog_delete'); |
| 160 | + Route::any('/blog/getAiBlogAuthor', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'getAiBlogAuthor'])->name('ai_blog_getAiBlogAuthor'); | ||
| 161 | + Route::any('/blog/getAuthorInfo', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'getAuthorInfo'])->name('ai_blog_getAuthorInfo'); | ||
| 162 | + Route::any('/blog/saveBlogAuthor', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'saveBlogAuthor'])->name('ai_blog_saveBlogAuthor'); | ||
| 163 | + Route::any('/blog/getInfo', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'getInfo'])->name('ai_blog_getInfo'); | ||
| 160 | Route::any('/product/', [\App\Http\Controllers\Bside\Ai\AiProductController::class, 'save'])->name('ai_product_save'); | 164 | Route::any('/product/', [\App\Http\Controllers\Bside\Ai\AiProductController::class, 'save'])->name('ai_product_save'); |
| 161 | Route::any('/product/productList', [\App\Http\Controllers\Bside\Ai\AiProductController::class, 'productList'])->name('ai_product_productList'); | 165 | Route::any('/product/productList', [\App\Http\Controllers\Bside\Ai\AiProductController::class, 'productList'])->name('ai_product_productList'); |
| 162 | Route::any('/product/productCateList', [\App\Http\Controllers\Bside\Ai\AiProductController::class, 'productCateList'])->name('ai_product_productCateList'); | 166 | Route::any('/product/productCateList', [\App\Http\Controllers\Bside\Ai\AiProductController::class, 'productCateList'])->name('ai_product_productCateList'); |
-
请 注册 或 登录 后发表评论