Merge branch 'master' into lms
正在显示
12 个修改的文件
包含
449 行增加
和
115 行删除
app/Console/Commands/ClearSeoTdk.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Console\Commands; | ||
| 4 | + | ||
| 5 | +use App\Helper\Arr; | ||
| 6 | +use App\Helper\Common; | ||
| 7 | +use App\Helper\Gpt; | ||
| 8 | +use App\Helper\Translate; | ||
| 9 | +use App\Http\Logic\Aside\Project\ProjectLogic; | ||
| 10 | +use App\Models\Ai\AiCommand; | ||
| 11 | +use App\Models\Mail\Mail; | ||
| 12 | +use App\Models\Project\DeployOptimize; | ||
| 13 | +use App\Models\Project\ProjectUpdateTdk; | ||
| 14 | +use App\Models\User\User; | ||
| 15 | +use App\Services\ProjectServer; | ||
| 16 | +use Illuminate\Console\Command; | ||
| 17 | +use Illuminate\Support\Facades\Cache; | ||
| 18 | +use Illuminate\Support\Facades\DB; | ||
| 19 | +use Illuminate\Support\Facades\Redis; | ||
| 20 | + | ||
| 21 | +/** | ||
| 22 | + * 清除项目sdk | ||
| 23 | + * Class InitProject | ||
| 24 | + * @package App\Console\Commands | ||
| 25 | + * @author zbj | ||
| 26 | + * @date 2023/10/8 | ||
| 27 | + */ | ||
| 28 | +class ClearSeoTdk extends Command | ||
| 29 | +{ | ||
| 30 | + /** | ||
| 31 | + * The name and signature of the console command. | ||
| 32 | + * | ||
| 33 | + * @var string | ||
| 34 | + */ | ||
| 35 | + protected $signature = 'clear_seo_tdk {project_id}'; | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * The console command description. | ||
| 39 | + * | ||
| 40 | + * @var string | ||
| 41 | + */ | ||
| 42 | + protected $description = '清除项目sdk'; | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * Create a new command instance. | ||
| 46 | + * | ||
| 47 | + * @return void | ||
| 48 | + */ | ||
| 49 | + public function __construct() | ||
| 50 | + { | ||
| 51 | + parent::__construct(); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * '表' => [ | ||
| 56 | + * '指令key' => '表字段' | ||
| 57 | + * ] | ||
| 58 | + * @return array | ||
| 59 | + * @author zbj | ||
| 60 | + * @date 2023/11/3 | ||
| 61 | + */ | ||
| 62 | + protected $maps = [ | ||
| 63 | + 'gl_web_custom_template' => [ | ||
| 64 | + 'title' => '', | ||
| 65 | + 'keywords' => '', | ||
| 66 | + 'description' => '', | ||
| 67 | + ], | ||
| 68 | + 'gl_product' => [ | ||
| 69 | + 'seo_mate' => null | ||
| 70 | + ], | ||
| 71 | + 'gl_product_category' => [ | ||
| 72 | + 'seo_title' => '', | ||
| 73 | + 'seo_keywords' => '', | ||
| 74 | + 'seo_des' => '', | ||
| 75 | + ], | ||
| 76 | + 'gl_blog' => [ | ||
| 77 | + 'seo_title' => '', | ||
| 78 | + 'seo_keywords' => '', | ||
| 79 | + 'seo_description' => '', | ||
| 80 | + ], | ||
| 81 | + 'gl_blog_category' => [ | ||
| 82 | + 'seo_title' => '', | ||
| 83 | + 'seo_keywords' => '', | ||
| 84 | + 'seo_des' => '', | ||
| 85 | + ], | ||
| 86 | + 'gl_news' => [ | ||
| 87 | + 'seo_title' => '', | ||
| 88 | + 'seo_keywords' => '', | ||
| 89 | + 'seo_description' => '', | ||
| 90 | + ], | ||
| 91 | + 'gl_news_category' => [ | ||
| 92 | + 'seo_title' => '', | ||
| 93 | + 'seo_keywords' => '', | ||
| 94 | + 'seo_des' => '', | ||
| 95 | + ], | ||
| 96 | + 'gl_product_keyword' => [ | ||
| 97 | + 'seo_title' => '', | ||
| 98 | + 'seo_keywords' => '', | ||
| 99 | + 'seo_description' => '', | ||
| 100 | + 'keyword_title' => '', | ||
| 101 | + 'keyword_content' => '', | ||
| 102 | + ] | ||
| 103 | + ]; | ||
| 104 | + | ||
| 105 | + /** | ||
| 106 | + * @return bool | ||
| 107 | + */ | ||
| 108 | + public function handle() | ||
| 109 | + { | ||
| 110 | + $project_id = $this->argument('project_id'); | ||
| 111 | + $project = ProjectServer::useProject($project_id); | ||
| 112 | + if(!$project){ | ||
| 113 | + echo '项目不存在或数据库未配置' . PHP_EOL; | ||
| 114 | + exit; | ||
| 115 | + } | ||
| 116 | + if ($this->confirm('你确认清空['. $project['title'] .']的sdk?')) { | ||
| 117 | + foreach ($this->maps as $table => $data) { | ||
| 118 | + echo date('Y-m-d H:i:s') . '清空SDK--' . $table . PHP_EOL; | ||
| 119 | + DB::connection('custom_mysql')->table($table)->update($data); | ||
| 120 | + } | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + echo date('Y-m-d H:i:s') . '清空完成' . PHP_EOL; | ||
| 124 | + } | ||
| 125 | +} |
app/Console/Commands/TdkTest.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Console\Commands; | ||
| 4 | + | ||
| 5 | +use App\Helper\Arr; | ||
| 6 | +use App\Helper\Common; | ||
| 7 | +use App\Helper\Gpt; | ||
| 8 | +use App\Helper\Translate; | ||
| 9 | +use App\Models\Ai\AiCommand; | ||
| 10 | +use App\Models\Mail\Mail; | ||
| 11 | +use App\Models\Project\DeployOptimize; | ||
| 12 | +use App\Models\Project\Project; | ||
| 13 | +use App\Models\Project\ProjectUpdateTdk; | ||
| 14 | +use App\Models\User\User; | ||
| 15 | +use App\Services\ProjectServer; | ||
| 16 | +use Illuminate\Console\Command; | ||
| 17 | +use Illuminate\Support\Facades\Cache; | ||
| 18 | +use Illuminate\Support\Facades\DB; | ||
| 19 | +use Illuminate\Support\Facades\Redis; | ||
| 20 | + | ||
| 21 | +/** | ||
| 22 | + * 初始化项目 | ||
| 23 | + * Class InitProject | ||
| 24 | + * @package App\Console\Commands | ||
| 25 | + * @author zbj | ||
| 26 | + * @date 2023/10/8 | ||
| 27 | + */ | ||
| 28 | +class TdkTest extends Command | ||
| 29 | +{ | ||
| 30 | + /** | ||
| 31 | + * The name and signature of the console command. | ||
| 32 | + * | ||
| 33 | + * @var string | ||
| 34 | + */ | ||
| 35 | + protected $signature = 'tdk_test'; | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * The console command description. | ||
| 39 | + * | ||
| 40 | + * @var string | ||
| 41 | + */ | ||
| 42 | + protected $description = 'keywords ,分割加空格'; | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * Create a new command instance. | ||
| 46 | + * | ||
| 47 | + * @return void | ||
| 48 | + */ | ||
| 49 | + public function __construct() | ||
| 50 | + { | ||
| 51 | + parent::__construct(); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * '表' => [ | ||
| 56 | + * '指令key' => '表字段' | ||
| 57 | + * ] | ||
| 58 | + * @return array | ||
| 59 | + * @author zbj | ||
| 60 | + * @date 2023/11/3 | ||
| 61 | + */ | ||
| 62 | + protected $maps = [ | ||
| 63 | + 'gl_web_custom_template' => 'keywords', | ||
| 64 | + 'gl_product' => 'seo_mate.keyword', | ||
| 65 | + 'gl_product_category' => 'seo_keywords', | ||
| 66 | + 'gl_blog' => 'seo_keywords', | ||
| 67 | + 'gl_blog_category' => 'seo_keywords', | ||
| 68 | + 'gl_news' => 'seo_keywords', | ||
| 69 | + 'gl_news_category' => 'seo_keywords', | ||
| 70 | + 'gl_product_keyword' => 'seo_keywords', | ||
| 71 | + ]; | ||
| 72 | + | ||
| 73 | + /** | ||
| 74 | + * @return bool | ||
| 75 | + */ | ||
| 76 | + public function handle() | ||
| 77 | + { | ||
| 78 | + $project_ids = Project::where('type', Project::TYPE_TWO)->pluck('id')->toArray(); | ||
| 79 | + foreach ($project_ids as $project_id){ | ||
| 80 | + echo date('Y-m-d H:i:s') . ' start project_id: ' . $project_id . PHP_EOL; | ||
| 81 | + ProjectServer::useProject($project_id); | ||
| 82 | + foreach ($this->maps as $table=>$field){ | ||
| 83 | + $list = DB::connection('custom_mysql')->table($table)->get(); | ||
| 84 | + foreach ($list as $item){ | ||
| 85 | + $item = (array) $item; | ||
| 86 | + $field_arr = explode('.', $field); | ||
| 87 | + if ($field == 'seo_mate.keyword') { | ||
| 88 | + $data = json_decode($item[$field_arr[0]], true); | ||
| 89 | + $value = $data['keyword'] ?? ''; | ||
| 90 | + if(!$value){ | ||
| 91 | + continue; | ||
| 92 | + } | ||
| 93 | + $data['keyword'] = implode(', ', array_map('trim', explode(',', $value))); | ||
| 94 | + DB::connection('custom_mysql')->table($table)->where('id', $item['id'])->update(['seo_mate' => json_encode($data)]); | ||
| 95 | + } else { | ||
| 96 | + $value = $item[$field]; | ||
| 97 | + if(!$value){ | ||
| 98 | + continue; | ||
| 99 | + } | ||
| 100 | + $value = implode(', ', array_map('trim', explode(',', $value))); | ||
| 101 | + DB::connection('custom_mysql')->table($table)->where('id', $item['id'])->update([$field => $value]); | ||
| 102 | + } | ||
| 103 | + } | ||
| 104 | + } | ||
| 105 | + } | ||
| 106 | + } | ||
| 107 | +} |
| @@ -139,18 +139,16 @@ class ProjectUpdate extends Command | @@ -139,18 +139,16 @@ class ProjectUpdate extends Command | ||
| 139 | 'seo_title' => $item['seo_title'] ?? '', | 139 | 'seo_title' => $item['seo_title'] ?? '', |
| 140 | 'seo_keywords' => $item['seo_keywords'] ?? '', | 140 | 'seo_keywords' => $item['seo_keywords'] ?? '', |
| 141 | 'seo_description' => $item['seo_description'] ?? '', | 141 | 'seo_description' => $item['seo_description'] ?? '', |
| 142 | + 'route' => $this->get_url_route($item['url']) | ||
| 142 | ]); | 143 | ]); |
| 143 | - $route = $this->set_map($this->get_url_route($item['url']), RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $project_id); | ||
| 144 | - $model->edit(['route' => $route], ['id' => $id]); | 144 | + $this->set_map($this->get_url_route($item['url']), RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $project_id); |
| 145 | + | ||
| 146 | + CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $link_type, $language_list, $page_list); | ||
| 145 | } catch (\Exception $e) { | 147 | } catch (\Exception $e) { |
| 146 | echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL; | 148 | echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL; |
| 147 | continue; | 149 | continue; |
| 148 | } | 150 | } |
| 149 | - } else { | ||
| 150 | - $id = $keyword['id']; | ||
| 151 | } | 151 | } |
| 152 | - | ||
| 153 | - CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $link_type, $language_list, $page_list); | ||
| 154 | } | 152 | } |
| 155 | } | 153 | } |
| 156 | } | 154 | } |
| @@ -271,19 +269,17 @@ class ProjectUpdate extends Command | @@ -271,19 +269,17 @@ class ProjectUpdate extends Command | ||
| 271 | 'keyword' => $item['keywords'] ?? '', | 269 | 'keyword' => $item['keywords'] ?? '', |
| 272 | 'description' => $item['description'] ?? '' | 270 | 'description' => $item['description'] ?? '' |
| 273 | ]), | 271 | ]), |
| 274 | - 'status' => Product::STATUS_ON | 272 | + 'status' => Product::STATUS_ON, |
| 273 | + 'route' => $this->get_url_route($item['url']) | ||
| 275 | ]); | 274 | ]); |
| 276 | - $route = $this->set_map($this->get_url_route($item['url']), RouteMap::SOURCE_PRODUCT, $id, $project_id); | ||
| 277 | - $model->edit(['route' => $route], ['id' => $id]); | 275 | + $this->set_map($this->get_url_route($item['url']), RouteMap::SOURCE_PRODUCT, $id, $project_id); |
| 276 | + | ||
| 277 | + CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT, $id, $link_type, $language_list, $page_list); | ||
| 278 | } catch (\Exception $e) { | 278 | } catch (\Exception $e) { |
| 279 | echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL; | 279 | echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL; |
| 280 | continue; | 280 | continue; |
| 281 | } | 281 | } |
| 282 | - } else { | ||
| 283 | - $id = $product['id']; | ||
| 284 | } | 282 | } |
| 285 | - | ||
| 286 | - CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT, $id, $link_type, $language_list, $page_list); | ||
| 287 | } | 283 | } |
| 288 | } | 284 | } |
| 289 | } | 285 | } |
| @@ -318,6 +314,15 @@ class ProjectUpdate extends Command | @@ -318,6 +314,15 @@ class ProjectUpdate extends Command | ||
| 318 | if (!$news) { | 314 | if (!$news) { |
| 319 | try { | 315 | try { |
| 320 | $item['ttile'] = $this->special2str($item['ttile']); | 316 | $item['ttile'] = $this->special2str($item['ttile']); |
| 317 | + | ||
| 318 | + if (is_array($item['images'])) { | ||
| 319 | + $image = $item['images'][0] ?? ''; | ||
| 320 | + } else { | ||
| 321 | + $image = $item['images'] ?? ''; | ||
| 322 | + } | ||
| 323 | + if(strpos($image,'//') === 0){ | ||
| 324 | + $image = 'https:'.$image; | ||
| 325 | + } | ||
| 321 | $id = $model->addReturnId([ | 326 | $id = $model->addReturnId([ |
| 322 | 'project_id' => $project_id, | 327 | 'project_id' => $project_id, |
| 323 | 'name' => $item['ttile'], | 328 | 'name' => $item['ttile'], |
| @@ -325,20 +330,18 @@ class ProjectUpdate extends Command | @@ -325,20 +330,18 @@ class ProjectUpdate extends Command | ||
| 325 | 'seo_keywords' => $item['keywords'] ?? '', | 330 | 'seo_keywords' => $item['keywords'] ?? '', |
| 326 | 'seo_description' => $item['description'] ?? '', | 331 | 'seo_description' => $item['description'] ?? '', |
| 327 | 'text' => $item['content'] ?? '', | 332 | 'text' => $item['content'] ?? '', |
| 328 | - 'image' => $item['images'][0] ?? '', | ||
| 329 | - 'status' => $api_type == 'news' ? News::STATUS_ONE : Blog::STATUS_ONE | 333 | + 'image' => $image, |
| 334 | + 'status' => $api_type == 'news' ? News::STATUS_ONE : Blog::STATUS_ONE, | ||
| 335 | + 'url' => $this->get_url_route($item['url']) | ||
| 330 | ]); | 336 | ]); |
| 331 | - $route = $this->set_map($this->get_url_route($item['url']), $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $project_id); | ||
| 332 | - $model->edit(['url' => $route], ['id' => $id]); | 337 | + $this->set_map($this->get_url_route($item['url']), $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $project_id); |
| 338 | + | ||
| 339 | + CollectTask::_insert($item['url'], $project_id, $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $link_type, $language_list, $page_list); | ||
| 333 | } catch (\Exception $e) { | 340 | } catch (\Exception $e) { |
| 334 | echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL; | 341 | echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL; |
| 335 | continue; | 342 | continue; |
| 336 | } | 343 | } |
| 337 | - } else { | ||
| 338 | - $id = $news['id']; | ||
| 339 | } | 344 | } |
| 340 | - | ||
| 341 | - CollectTask::_insert($item['url'], $project_id, $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $link_type, $language_list, $page_list); | ||
| 342 | } | 345 | } |
| 343 | } | 346 | } |
| 344 | } | 347 | } |
| @@ -375,19 +378,17 @@ class ProjectUpdate extends Command | @@ -375,19 +378,17 @@ class ProjectUpdate extends Command | ||
| 375 | 'keywords' => $item['keywords'] ?? '', | 378 | 'keywords' => $item['keywords'] ?? '', |
| 376 | 'description' => $item['description'] ?? '', | 379 | 'description' => $item['description'] ?? '', |
| 377 | 'html' => $item['content'] ?? '', | 380 | 'html' => $item['content'] ?? '', |
| 378 | - 'status' => 1 | 381 | + 'status' => 1, |
| 382 | + 'url' => $this->get_url_route($item['url']) | ||
| 379 | ]); | 383 | ]); |
| 380 | - $route = $this->set_map($this->get_url_route($item['url']), RouteMap::SOURCE_PAGE, $id, $project_id); | ||
| 381 | - $model->edit(['url' => $route], ['id' => $id]); | 384 | + $this->set_map($this->get_url_route($item['url']), RouteMap::SOURCE_PAGE, $id, $project_id); |
| 385 | + | ||
| 386 | + CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PAGE, $id, $link_type, $language_list, $page_list); | ||
| 382 | } catch (\Exception $e) { | 387 | } catch (\Exception $e) { |
| 383 | echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL; | 388 | echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL; |
| 384 | continue; | 389 | continue; |
| 385 | } | 390 | } |
| 386 | - } else { | ||
| 387 | - $id = $custom['id']; | ||
| 388 | } | 391 | } |
| 389 | - | ||
| 390 | - CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PAGE, $id, $link_type, $language_list, $page_list); | ||
| 391 | } | 392 | } |
| 392 | } | 393 | } |
| 393 | } | 394 | } |
| @@ -463,10 +464,10 @@ class ProjectUpdate extends Command | @@ -463,10 +464,10 @@ class ProjectUpdate extends Command | ||
| 463 | 'title' => $item['name'], | 464 | 'title' => $item['name'], |
| 464 | 'pid' => $pid, | 465 | 'pid' => $pid, |
| 465 | 'keywords' => $item['keywords'] ?? '', | 466 | 'keywords' => $item['keywords'] ?? '', |
| 466 | - 'describe' => $item['description'] ?? '' | 467 | + 'describe' => $item['description'] ?? '', |
| 468 | + 'route' => $this->get_url_route($item['url']) | ||
| 467 | ]); | 469 | ]); |
| 468 | - $route = $this->set_map($this->get_url_route($item['url']), RouteMap::SOURCE_PRODUCT_CATE, $parent_id, $project_id); | ||
| 469 | - $model->edit(['route' => $route], ['id' => $parent_id]); | 470 | + $this->set_map($this->get_url_route($item['url']), RouteMap::SOURCE_PRODUCT_CATE, $parent_id, $project_id); |
| 470 | } catch (\Exception $e) { | 471 | } catch (\Exception $e) { |
| 471 | echo 'date:' . date('Y-m-d H:i:s') . ', category_insert error: ' . $e->getMessage() . PHP_EOL; | 472 | echo 'date:' . date('Y-m-d H:i:s') . ', category_insert error: ' . $e->getMessage() . PHP_EOL; |
| 472 | continue; | 473 | continue; |
| @@ -520,24 +521,23 @@ class ProjectUpdate extends Command | @@ -520,24 +521,23 @@ class ProjectUpdate extends Command | ||
| 520 | //路由入库 | 521 | //路由入库 |
| 521 | protected function set_map($route, $source, $source_id, $project_id) | 522 | protected function set_map($route, $source, $source_id, $project_id) |
| 522 | { | 523 | { |
| 523 | - if (empty($route)) { | ||
| 524 | - return ''; | ||
| 525 | - } | ||
| 526 | - | ||
| 527 | - $route_map = new RouteMap(); | ||
| 528 | - $route_map->project_id = $project_id; | ||
| 529 | - $route_map->source = $source; | ||
| 530 | - $route_map->source_id = $source_id; | ||
| 531 | - $route_map->route = $route; | 524 | + if ($route) { |
| 525 | + $route_map = RouteMap::where('project_id', $project_id)->where('source', $source)->where('source_id', $source_id)->first(); | ||
| 526 | + if (!$route_map) { | ||
| 527 | + $route_map = new RouteMap(); | ||
| 528 | + $route_map->project_id = $project_id; | ||
| 529 | + $route_map->source = $source; | ||
| 530 | + $route_map->source_id = $source_id; | ||
| 531 | + $route_map->route = $route; | ||
| 532 | + | ||
| 533 | + if ($source == RouteMap::SOURCE_NEWS) { | ||
| 534 | + $route_map->path = RouteMap::SOURCE_NEWS; | ||
| 535 | + } elseif ($source == RouteMap::SOURCE_BLOG) { | ||
| 536 | + $route_map->path = RouteMap::SOURCE_BLOG; | ||
| 537 | + } | ||
| 532 | 538 | ||
| 533 | - if ($source == RouteMap::SOURCE_NEWS) { | ||
| 534 | - $route_map->path = RouteMap::SOURCE_NEWS; | ||
| 535 | - } elseif ($source == RouteMap::SOURCE_BLOG) { | ||
| 536 | - $route_map->path = RouteMap::SOURCE_BLOG; | 539 | + $route_map->save(); |
| 540 | + } | ||
| 537 | } | 541 | } |
| 538 | - | ||
| 539 | - $route_map->save(); | ||
| 540 | - | ||
| 541 | - return $route; | ||
| 542 | } | 542 | } |
| 543 | } | 543 | } |
| @@ -360,7 +360,7 @@ class UpdateSeoTdk extends Command | @@ -360,7 +360,7 @@ class UpdateSeoTdk extends Command | ||
| 360 | //随机取 | 360 | //随机取 |
| 361 | shuffle($main_keywords); | 361 | shuffle($main_keywords); |
| 362 | $main_keywords = array_slice($main_keywords, 0, $num); | 362 | $main_keywords = array_slice($main_keywords, 0, $num); |
| 363 | - $str = implode(",", $main_keywords); | 363 | + $str = implode(", ", $main_keywords); |
| 364 | } | 364 | } |
| 365 | return $str; | 365 | return $str; |
| 366 | } | 366 | } |
| @@ -201,13 +201,13 @@ class ProjectController extends BaseController | @@ -201,13 +201,13 @@ class ProjectController extends BaseController | ||
| 201 | */ | 201 | */ |
| 202 | public function searchChannel(&$query){ | 202 | public function searchChannel(&$query){ |
| 203 | if(isset($this->map['zone_id']) && !empty($this->map['zone_id'])){ | 203 | if(isset($this->map['zone_id']) && !empty($this->map['zone_id'])){ |
| 204 | - $query->where('gl_project.channel','like','%"zone_id": "'.$this->map['channel_id'].'"%'); | 204 | + $query->where('gl_project.channel','like','%"zone_id": "'.$this->map['zone_id'].'"%'); |
| 205 | } | 205 | } |
| 206 | if(isset($this->map['channel_id']) && !empty($this->map['channel_id'])){ | 206 | if(isset($this->map['channel_id']) && !empty($this->map['channel_id'])){ |
| 207 | $query->where('gl_project.channel','like','%"channel_id": "'.$this->map['channel_id'].'"%'); | 207 | $query->where('gl_project.channel','like','%"channel_id": "'.$this->map['channel_id'].'"%'); |
| 208 | } | 208 | } |
| 209 | if(isset($this->map['user_id']) && !empty($this->map['user_id'])){ | 209 | if(isset($this->map['user_id']) && !empty($this->map['user_id'])){ |
| 210 | - $query->where('gl_project.channel','like','%"user_id": "'.$this->map['channel_id'].'"%'); | 210 | + $query->where('gl_project.channel','like','%"user_id": "'.$this->map['user_id'].'"%'); |
| 211 | } | 211 | } |
| 212 | return $query; | 212 | return $query; |
| 213 | } | 213 | } |
| @@ -25,7 +25,6 @@ class ATemplateController extends BaseController | @@ -25,7 +25,6 @@ class ATemplateController extends BaseController | ||
| 25 | */ | 25 | */ |
| 26 | public function lists(ATemplateLogic $aTemplateLogic){ | 26 | public function lists(ATemplateLogic $aTemplateLogic){ |
| 27 | $filed = ['id','name','image','url','status','sort','deleted_status','test_model','created_at','project_id']; | 27 | $filed = ['id','name','image','url','status','sort','deleted_status','test_model','created_at','project_id']; |
| 28 | - $this->map['project_id'] = 0; | ||
| 29 | $lists = $aTemplateLogic->aTemplateList($this->map,$this->page,$this->row,$this->order,$filed); | 28 | $lists = $aTemplateLogic->aTemplateList($this->map,$this->page,$this->row,$this->order,$filed); |
| 30 | if(!empty($lists) && !empty($lists['list'])){ | 29 | if(!empty($lists) && !empty($lists['list'])){ |
| 31 | foreach ($lists['list'] as $k => $v){ | 30 | foreach ($lists['list'] as $k => $v){ |
| @@ -7,18 +7,17 @@ use App\Helper\Common; | @@ -7,18 +7,17 @@ use App\Helper\Common; | ||
| 7 | use App\Helper\Translate; | 7 | use App\Helper\Translate; |
| 8 | use App\Http\Controllers\Bside\BaseController; | 8 | use App\Http\Controllers\Bside\BaseController; |
| 9 | use App\Http\Controllers\Bside\:写入日志; | 9 | use App\Http\Controllers\Bside\:写入日志; |
| 10 | +use App\Http\Logic\Bside\Ai\AiCommandLogic; | ||
| 11 | +use App\Models\Ai\AiCommand; | ||
| 10 | use App\Models\Ai\AiLog; | 12 | use App\Models\Ai\AiLog; |
| 11 | use App\Models\Project\DeployOptimize; | 13 | use App\Models\Project\DeployOptimize; |
| 12 | use App\Models\Project\Project; | 14 | use App\Models\Project\Project; |
| 13 | 15 | ||
| 14 | class AiCommandController extends BaseController | 16 | class AiCommandController extends BaseController |
| 15 | { | 17 | { |
| 16 | - //获取文本内容 | ||
| 17 | - public $chat_url = 'v2/openai_chat_qqs'; | ||
| 18 | /** | 18 | /** |
| 19 | - * @name :ai生成 | ||
| 20 | - * @author :liyuhang | ||
| 21 | - * @method | 19 | + * @author zbj |
| 20 | + * @date 2023/11/22 | ||
| 22 | */ | 21 | */ |
| 23 | public function ai_http_post(){ | 22 | public function ai_http_post(){ |
| 24 | $this->request->validate([ | 23 | $this->request->validate([ |
| @@ -28,39 +27,19 @@ class AiCommandController extends BaseController | @@ -28,39 +27,19 @@ class AiCommandController extends BaseController | ||
| 28 | 'keywords.required' => '关键字不能为空', | 27 | 'keywords.required' => '关键字不能为空', |
| 29 | 'key.required' => '场景不能为空', | 28 | 'key.required' => '场景不能为空', |
| 30 | ]); | 29 | ]); |
| 31 | - #TODO 通过key获取到ai指令对象 | ||
| 32 | - $data = Common::send_openai_msg($this->chat_url,$this->param,$this->companyName($this->param['key'],$this->user['project_id'])); | ||
| 33 | - $data['text'] = Common::deal_keywords($data['text']); | ||
| 34 | - $data['text'] = Common::deal_str($data['text']); | ||
| 35 | - $param = [ | ||
| 36 | - 'key'=>$this->param['key'], | ||
| 37 | - 'keywords'=>$this->param['keywords'], | ||
| 38 | - 'remark'=>json_encode($data) | ||
| 39 | - ]; | ||
| 40 | - $this->set_ai_log($param); | ||
| 41 | - $this->response('success',Code::SUCCESS,$data); | ||
| 42 | - } | ||
| 43 | 30 | ||
| 44 | - /** | ||
| 45 | - * @remark :获取公司英文名称 | ||
| 46 | - * @name :companyName | ||
| 47 | - * @author :lyh | ||
| 48 | - * @method :post | ||
| 49 | - * @time :2023/10/30 11:22 | ||
| 50 | - */ | ||
| 51 | - public function companyName($key,$project_id){ | 31 | + $text = AiCommandLogic::instance()->ai_send(); |
| 52 | $data = [ | 32 | $data = [ |
| 53 | - 'news_remark', | ||
| 54 | - 'blog_remark', | ||
| 55 | - 'product_long_description' | 33 | + 'code' => $text ? 200 : 500, |
| 34 | + 'text' => $text | ||
| 56 | ]; | 35 | ]; |
| 57 | - $projectOptimizeModel = new DeployOptimize(); | ||
| 58 | - $info = $projectOptimizeModel->read(['project_id'=>$project_id],['id','company_en_name','company_en_description']); | ||
| 59 | - if(in_array($key,$data)){ | ||
| 60 | - return $info['company_en_description']; | ||
| 61 | - }else{ | ||
| 62 | - return $info['company_en_name']; | ||
| 63 | - } | 36 | + $param = [ |
| 37 | + 'key' => $this->param['key'], | ||
| 38 | + 'keywords' => $this->param['keywords'], | ||
| 39 | + 'remark' => $text | ||
| 40 | + ]; | ||
| 41 | + $this->set_ai_log($param); | ||
| 42 | + $this->response('success', Code::SUCCESS, $data); | ||
| 64 | } | 43 | } |
| 65 | 44 | ||
| 66 | /** | 45 | /** |
| @@ -32,7 +32,7 @@ class BTemplateModuleController extends BaseController | @@ -32,7 +32,7 @@ class BTemplateModuleController extends BaseController | ||
| 32 | $moduleProjectModel = new BModuleProject(); | 32 | $moduleProjectModel = new BModuleProject(); |
| 33 | $module_list = $moduleProjectModel->list(['project_id'=>$this->user['project_id']]); | 33 | $module_list = $moduleProjectModel->list(['project_id'=>$this->user['project_id']]); |
| 34 | $data['module_list'] = $module_list; | 34 | $data['module_list'] = $module_list; |
| 35 | - $this->response('success',Code::SUCCESS,$list); | 35 | + $this->response('success',Code::SUCCESS,$data); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | /** | 38 | /** |
| @@ -28,6 +28,7 @@ class ATemplateLogic extends BaseLogic | @@ -28,6 +28,7 @@ class ATemplateLogic extends BaseLogic | ||
| 28 | * @time :2023/6/28 17:03 | 28 | * @time :2023/6/28 17:03 |
| 29 | */ | 29 | */ |
| 30 | public function aTemplateList($map,$page,$row,$order = ['created_at'],$filed = ['*']){ | 30 | public function aTemplateList($map,$page,$row,$order = ['created_at'],$filed = ['*']){ |
| 31 | + $map['project_id'] = 0; | ||
| 31 | $map['deleted_status'] = 0; | 32 | $map['deleted_status'] = 0; |
| 32 | $map['status'] = 0; | 33 | $map['status'] = 0; |
| 33 | $lists = $this->model->lists($map,$page,$row,$order,$filed); | 34 | $lists = $this->model->lists($map,$page,$row,$order,$filed); |
app/Http/Logic/Bside/Ai/AiCommandLogic.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Http\Logic\Bside\Ai; | ||
| 4 | + | ||
| 5 | +use App\Helper\Common; | ||
| 6 | +use App\Helper\Gpt; | ||
| 7 | +use App\Helper\Translate; | ||
| 8 | +use App\Http\Logic\Bside\BaseLogic; | ||
| 9 | +use App\Models\Ai\AiCommand; | ||
| 10 | +use App\Models\Project\DeployOptimize; | ||
| 11 | +use Illuminate\Support\Facades\Cache; | ||
| 12 | + | ||
| 13 | +class AiCommandLogic extends BaseLogic | ||
| 14 | +{ | ||
| 15 | + public function __construct() | ||
| 16 | + { | ||
| 17 | + parent::__construct(); | ||
| 18 | + $this->param = $this->requestAll; | ||
| 19 | + $this->model = new AiCommand(); | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * @author zbj | ||
| 24 | + * @date 2023/11/22 | ||
| 25 | + */ | ||
| 26 | + public function getPrompt($is_batch = 0){ | ||
| 27 | + $ai_command = $this->model->where('key', $this->param['key'])->where('is_batch', $is_batch)->first(); | ||
| 28 | + if(!$ai_command){ | ||
| 29 | + $this->fail('指令不存在'); | ||
| 30 | + } | ||
| 31 | + $prompt = $ai_command->ai; | ||
| 32 | + | ||
| 33 | + if(strpos($prompt, '{keyword}') !== false) { | ||
| 34 | + $prompt = str_replace('{keyword}', $this->param['keywords'], $prompt); | ||
| 35 | + } | ||
| 36 | + if(strpos($prompt, '{company introduction}') !== false) { | ||
| 37 | + $company_introduction = $this->getDeployOptimize('company_en_description'); | ||
| 38 | + $prompt = str_replace('{company introduction}', $company_introduction, $prompt); | ||
| 39 | + } | ||
| 40 | + if(strpos($prompt, '{company name}') !== false) { | ||
| 41 | + $company_name = $this->getDeployOptimize('company_en_name'); | ||
| 42 | + $prompt = str_replace('{company name}', $company_name, $prompt); | ||
| 43 | + } | ||
| 44 | + if(strpos($prompt, '{core keywords 8}') !== false) { | ||
| 45 | + $main_keywords = $this->getDeployOptimize('main_keywords'); | ||
| 46 | + if ($main_keywords) { | ||
| 47 | + $main_keywords = explode("\r\n", $main_keywords); | ||
| 48 | + //随机取 | ||
| 49 | + shuffle($main_keywords); | ||
| 50 | + $main_keywords = array_slice($main_keywords, 0, 8); | ||
| 51 | + $main_keywords = implode(", ", $main_keywords); | ||
| 52 | + $prompt = str_replace('{core keywords 8}', $main_keywords, $prompt); | ||
| 53 | + }else{ | ||
| 54 | + $prompt = ''; | ||
| 55 | + } | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + if(trim($ai_command->ai) == '{core keywords 8}'){ | ||
| 59 | + $ai_send = false; | ||
| 60 | + }else{ | ||
| 61 | + $lang = $this->getLang($this->param['keywords']); | ||
| 62 | + $prompt .= '.Please answer in ' . ($lang ?: 'English'); | ||
| 63 | + $ai_send = true; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + return [ | ||
| 67 | + 'prompt' => $prompt, | ||
| 68 | + 'scene' => $ai_command->scene, | ||
| 69 | + 'ai_send' => $ai_send, | ||
| 70 | + ]; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + /** | ||
| 74 | + * @param $content | ||
| 75 | + * @return string | ||
| 76 | + * @author zbj | ||
| 77 | + * @date 2023/11/22 | ||
| 78 | + */ | ||
| 79 | + public function getLang($content){ | ||
| 80 | + $result = Translate::translateSl($content); | ||
| 81 | + if (isset($result['texts']['sl']) && isset(Translate::$tls_list[$result['texts']['sl']])) { | ||
| 82 | + $lang = Translate::$tls_list[$result['texts']['sl']]['lang_en']; | ||
| 83 | + } else { | ||
| 84 | + $lang = 'English'; | ||
| 85 | + } | ||
| 86 | + return $lang; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + /** | ||
| 90 | + * @param string $key | ||
| 91 | + * @return false|mixed|string | ||
| 92 | + * @author zbj | ||
| 93 | + * @date 2023/11/22 | ||
| 94 | + */ | ||
| 95 | + public function getDeployOptimize($key = ''){ | ||
| 96 | + $project_id = $this->project['id']; | ||
| 97 | + $cache_key = 'project_deploy_optimize_info_' . $project_id; | ||
| 98 | + $info = Cache::get($cache_key); | ||
| 99 | + if(!$info){ | ||
| 100 | + $projectOptimizeModel = new DeployOptimize(); | ||
| 101 | + $info = $projectOptimizeModel->read(['project_id' => $project_id], ['id', 'company_en_name', 'company_en_description', 'main_keywords']); | ||
| 102 | + Cache::put($cache_key, $info, 600); | ||
| 103 | + } | ||
| 104 | + if($key){ | ||
| 105 | + return $info[$key] ??''; | ||
| 106 | + } | ||
| 107 | + return $info; | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + /** | ||
| 111 | + * @param int $is_batch | ||
| 112 | + * @return array|string|string[] | ||
| 113 | + * @author zbj | ||
| 114 | + * @date 2023/11/22 | ||
| 115 | + */ | ||
| 116 | + public function ai_send($is_batch = 0){ | ||
| 117 | + $prompt = $this->getPrompt($is_batch); | ||
| 118 | + if(!$prompt['ai_send']){ | ||
| 119 | + return $prompt['prompt']; | ||
| 120 | + } | ||
| 121 | + $text = Gpt::instance()->openai_chat_qqs($prompt['prompt'], $prompt['scene']); | ||
| 122 | + $text = Common::deal_keywords($text); | ||
| 123 | + return Common::deal_str($text); | ||
| 124 | + } | ||
| 125 | +} |
| @@ -29,8 +29,6 @@ class CollectTask extends Base | @@ -29,8 +29,6 @@ class CollectTask extends Base | ||
| 29 | 'project_id' => $project_id, | 29 | 'project_id' => $project_id, |
| 30 | 'source' => $source, | 30 | 'source' => $source, |
| 31 | 'source_id' => $source_id, | 31 | 'source_id' => $source_id, |
| 32 | - 'domain' => $url_arr['host'], | ||
| 33 | - 'route' => $url_arr['path'], | ||
| 34 | 'language' => '' | 32 | 'language' => '' |
| 35 | ]; | 33 | ]; |
| 36 | 34 | ||
| @@ -48,33 +46,33 @@ class CollectTask extends Base | @@ -48,33 +46,33 @@ class CollectTask extends Base | ||
| 48 | 'created_at' => $now, | 46 | 'created_at' => $now, |
| 49 | 'updated_at' => $now, | 47 | 'updated_at' => $now, |
| 50 | ]; | 48 | ]; |
| 51 | - } | ||
| 52 | 49 | ||
| 53 | - if ($link_type > 0 && $language_list && in_array($url_arr['path'], $page_list)) { | ||
| 54 | - $domain_arr = explode('.', $url_arr['host']); | ||
| 55 | - foreach ($language_list as $v_lan) { | ||
| 56 | - if ($link_type == 1) { | ||
| 57 | - //二级域名 | ||
| 58 | - $domain_arr[0] = $v_lan; | ||
| 59 | - $new_domain = implode('.', $domain_arr); | ||
| 60 | - } else { | ||
| 61 | - //二级目录 | ||
| 62 | - $new_domain = $url_arr['host'] . '/' . $v_lan; | ||
| 63 | - } | 50 | + if ($link_type > 0 && $language_list && in_array($url_arr['path'], $page_list)) { |
| 51 | + $domain_arr = explode('.', $url_arr['host']); | ||
| 52 | + foreach ($language_list as $v_lan) { | ||
| 53 | + if ($link_type == 1) { | ||
| 54 | + //二级域名 | ||
| 55 | + $domain_arr[0] = $v_lan; | ||
| 56 | + $new_domain = implode('.', $domain_arr); | ||
| 57 | + } else { | ||
| 58 | + //二级目录 | ||
| 59 | + $new_domain = $url_arr['host'] . '/' . $v_lan; | ||
| 60 | + } | ||
| 64 | 61 | ||
| 65 | - $data[] = [ | ||
| 66 | - 'project_id' => $project_id, | ||
| 67 | - 'source' => $source, | ||
| 68 | - 'source_id' => $source_id, | ||
| 69 | - 'domain' => $new_domain, | ||
| 70 | - 'route' => $url_arr['path'], | ||
| 71 | - 'language' => $v_lan, | ||
| 72 | - 'created_at' => $now, | ||
| 73 | - 'updated_at' => $now, | ||
| 74 | - ]; | 62 | + $data[] = [ |
| 63 | + 'project_id' => $project_id, | ||
| 64 | + 'source' => $source, | ||
| 65 | + 'source_id' => $source_id, | ||
| 66 | + 'domain' => $new_domain, | ||
| 67 | + 'route' => $url_arr['path'], | ||
| 68 | + 'language' => $v_lan, | ||
| 69 | + 'created_at' => $now, | ||
| 70 | + 'updated_at' => $now, | ||
| 71 | + ]; | ||
| 72 | + } | ||
| 75 | } | 73 | } |
| 76 | - } | ||
| 77 | 74 | ||
| 78 | - self::insert($data); | 75 | + self::insert($data); |
| 76 | + } | ||
| 79 | } | 77 | } |
| 80 | } | 78 | } |
-
请 注册 或 登录 后发表评论