作者 刘锟

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

  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 +}
@@ -54,12 +54,12 @@ class UpdateRoute extends Command @@ -54,12 +54,12 @@ class UpdateRoute extends Command
54 */ 54 */
55 public function handle(){ 55 public function handle(){
56 $projectModel = new Project(); 56 $projectModel = new Project();
57 - $lists = $projectModel->list(['is_upgrade'=>0,'type'=>['!=',0]]); 57 + $lists = $projectModel->list(['is_upgrade'=>0,'id'=>['>',167],'type'=>['!=',0]]);
58 foreach ($lists as $k => $v){ 58 foreach ($lists as $k => $v){
59 echo date('Y-m-d H:i:s') . ' start: 项目id为' . $v['id'] . PHP_EOL; 59 echo date('Y-m-d H:i:s') . ' start: 项目id为' . $v['id'] . PHP_EOL;
60 ProjectServer::useProject($v['id']); 60 ProjectServer::useProject($v['id']);
61 - $this->setProductRoute($v['id']);  
62 -// $this->setProductKeywordRoute($v['id']); 61 +// $this->setProductRoute($v['id']);
  62 + $this->setProductKeywordRoute($v['id']);
63 // $this->setBlogRoute($v['id']); 63 // $this->setBlogRoute($v['id']);
64 // $this->setNewsRoute($v['id']); 64 // $this->setNewsRoute($v['id']);
65 // $this->setBlogCateRoute($v['id']); 65 // $this->setBlogCateRoute($v['id']);
@@ -194,11 +194,15 @@ class UpdateRoute extends Command @@ -194,11 +194,15 @@ class UpdateRoute extends Command
194 public function setProductKeywordRoute($project_id){ 194 public function setProductKeywordRoute($project_id){
195 $keywordModel = new Keyword(); 195 $keywordModel = new Keyword();
196 $keywordList = $keywordModel->list([],'id',['id','route']); 196 $keywordList = $keywordModel->list([],'id',['id','route']);
  197 + if(!empty($keywordList)){
197 foreach ($keywordList as $v){ 198 foreach ($keywordList as $v){
198 - if(!ends_with($v['route'],'-tag')){  
199 - $route = $v['route'].'-tag';  
200 - $keywordModel->edit(['route'=>$route],['id'=>$v['id']]);  
201 - RouteMap::setRoute($route, RouteMap::SOURCE_BLOG_CATE, $v['id'], $project_id); 199 +// if(!ends_with($v['route'],'-tag')){
  200 +// $route = $v['route'].'-tag';
  201 +// $keywordModel->edit(['route'=>$route],['id'=>$v['id']]);
  202 +// }
  203 + $routeMapModel = new RouteMap();
  204 + $routeMapModel->edit(['route'=>$v['route']],['source_id'=>$v['id'],'source'=>RouteMap::SOURCE_PRODUCT_KEYWORD]);
  205 + RouteMap::setRoute($v['route'], RouteMap::SOURCE_PRODUCT_KEYWORD, $v['id'], $project_id);
202 } 206 }
203 } 207 }
204 return true; 208 return true;
@@ -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 }
@@ -213,7 +213,7 @@ class Common @@ -213,7 +213,7 @@ class Common
213 } 213 }
214 } 214 }
215 } 215 }
216 - return implode(',',$ar_keywords); 216 + return implode(', ',$ar_keywords);
217 } 217 }
218 218
219 219
@@ -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 }
@@ -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 /**
@@ -4,9 +4,7 @@ namespace App\Http\Logic\Aside\Project; @@ -4,9 +4,7 @@ namespace App\Http\Logic\Aside\Project;
4 4
5 5
6 use App\Http\Logic\Aside\BaseLogic; 6 use App\Http\Logic\Aside\BaseLogic;
7 -use App\Models\Project\DomainInfo;  
8 -use App\Models\Project\Payment;  
9 -use MongoDB\Client; 7 +use App\Models\Domain\DomainInfo;
10 8
11 class DomainInfoLogic extends BaseLogic 9 class DomainInfoLogic extends BaseLogic
12 { 10 {
@@ -18,26 +16,15 @@ class DomainInfoLogic extends BaseLogic @@ -18,26 +16,15 @@ class DomainInfoLogic extends BaseLogic
18 16
19 public function getDomainInfo($project_id) 17 public function getDomainInfo($project_id)
20 { 18 {
21 - $project = (new ProjectLogic())->getProjectInfo($project_id);  
22 - $domain = (!empty($project['deploy_optimize']['domain']) ? ((new \App\Models\Domain\DomainInfo())->getDomain($project['deploy_optimize']['domain'])) : '');  
23 - $info = $this->model->where('project_id', $project_id)->first();  
24 - //不存在或时间过期了 重新获取信息  
25 - $expiration_date = $info['domain_info']['expiration_date'] ?? '';  
26 - $end_time = $info['ssl']['end_time'] ?? '';  
27 - if(!$info || $expiration_date < date("Y-m-d") || $end_time < date('Y-m-d')){  
28 - try {  
29 - $mongo = new Client("mongodb://root:globalso8837840@23.228.125.2:27017");  
30 - $db = $mongo->globalso_monitor;  
31 - $collection = $db->project_v1;  
32 - $project_zk = $collection->findOne(['main_url' => $domain]);  
33 - $info['domain'] = $domain;  
34 - $info['domain_info'] = (array) $project_zk['domain_info'] ?? [];  
35 - $info['ssl'] = (array) $project_zk['ssl'] ?? [];  
36 - parent::save($info);  
37 - }catch (\Exception $e){ 19 + $domain_info = $this->model->where('project_id', $project_id)->first();
  20 + if(!$domain_info){
38 return []; 21 return [];
39 } 22 }
40 - }  
41 - return $info; 23 +
  24 + return [
  25 + 'domain' => 'https://'.$domain_info['domain'].'/',
  26 + 'domain_info' => date('Y-m-d', strtotime($domain_info['domain_start_time'])) . ' - ' .date('Y-m-d', strtotime($domain_info['domain_end_time'])),
  27 + 'cert_info' => date('Y-m-d', strtotime($domain_info['certificate_start_time'])) . ' - ' .date('Y-m-d', strtotime($domain_info['certificate_end_time'])),
  28 + ];
42 } 29 }
43 } 30 }
  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 +}
@@ -60,9 +60,9 @@ class RankDataLogic extends BaseLogic @@ -60,9 +60,9 @@ class RankDataLogic extends BaseLogic
60 //项目信息 60 //项目信息
61 $data['project'] = [ 61 $data['project'] = [
62 'company' => $project['company'], 62 'company' => $project['company'],
63 - 'domain' => (!empty($project['deploy_optimize']['domain']) ? ((new DomainInfo())->getDomain($project['deploy_optimize']['domain'])) : ''),  
64 - 'domain_info' => ($domain_info['domain_info']['creation_date'] ?? '') . ' - ' . ($domain_info['domain_info']['expiration_date'] ?? ''),  
65 - 'cert_info' => ($domain_info['ssl']['start_time'] ?? '') . ' - ' . ($domain_info['ssl']['end_time'] ?? ''), 63 + 'domain' => $domain_info['domain'] ?? '',
  64 + 'domain_info' => $domain_info['domain_info'] ?? '',
  65 + 'cert_info' => $domain_info['cert_info'] ?? '',
66 'plan' => Project::planMap()[$project['deploy_build']['plan']], 66 'plan' => Project::planMap()[$project['deploy_build']['plan']],
67 'keyword_num' => $project['deploy_build']['keyword_num'], 67 'keyword_num' => $project['deploy_build']['keyword_num'],
68 'compliance_day' => $rank['compliance_day'] ?? 0, 68 'compliance_day' => $rank['compliance_day'] ?? 0,
@@ -56,12 +56,10 @@ class RouteMap extends Base @@ -56,12 +56,10 @@ class RouteMap extends Base
56 $i=1; 56 $i=1;
57 $sign = generateRoute($title); 57 $sign = generateRoute($title);
58 $route = $sign; 58 $route = $sign;
59 - if($source != BTemplate::SOURCE_PRODUCT){  
60 while(self::isExist($route, $source, $source_id, $project_id)){ 59 while(self::isExist($route, $source, $source_id, $project_id)){
61 $route = $sign .'-'.$i; 60 $route = $sign .'-'.$i;
62 $i++; 61 $i++;
63 } 62 }
64 - }  
65 return $route; 63 return $route;
66 } 64 }
67 65