作者 刘锟

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

<?php
namespace App\Console\Commands;
use App\Helper\Arr;
use App\Helper\Common;
use App\Helper\Gpt;
use App\Helper\Translate;
use App\Http\Logic\Aside\Project\ProjectLogic;
use App\Models\Ai\AiCommand;
use App\Models\Mail\Mail;
use App\Models\Project\DeployOptimize;
use App\Models\Project\ProjectUpdateTdk;
use App\Models\User\User;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
/**
* 清除项目sdk
* Class InitProject
* @package App\Console\Commands
* @author zbj
* @date 2023/10/8
*/
class ClearSeoTdk extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'clear_seo_tdk {project_id}';
/**
* The console command description.
*
* @var string
*/
protected $description = '清除项目sdk';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* '表' => [
* '指令key' => '表字段'
* ]
* @return array
* @author zbj
* @date 2023/11/3
*/
protected $maps = [
'gl_web_custom_template' => [
'title' => '',
'keywords' => '',
'description' => '',
],
'gl_product' => [
'seo_mate' => null
],
'gl_product_category' => [
'seo_title' => '',
'seo_keywords' => '',
'seo_des' => '',
],
'gl_blog' => [
'seo_title' => '',
'seo_keywords' => '',
'seo_description' => '',
],
'gl_blog_category' => [
'seo_title' => '',
'seo_keywords' => '',
'seo_des' => '',
],
'gl_news' => [
'seo_title' => '',
'seo_keywords' => '',
'seo_description' => '',
],
'gl_news_category' => [
'seo_title' => '',
'seo_keywords' => '',
'seo_des' => '',
],
'gl_product_keyword' => [
'seo_title' => '',
'seo_keywords' => '',
'seo_description' => '',
'keyword_title' => '',
'keyword_content' => '',
]
];
/**
* @return bool
*/
public function handle()
{
$project_id = $this->argument('project_id');
$project = ProjectServer::useProject($project_id);
if(!$project){
echo '项目不存在或数据库未配置' . PHP_EOL;
exit;
}
if ($this->confirm('你确认清空['. $project['title'] .']的sdk?')) {
foreach ($this->maps as $table => $data) {
echo date('Y-m-d H:i:s') . '清空SDK--' . $table . PHP_EOL;
DB::connection('custom_mysql')->table($table)->update($data);
}
}
echo date('Y-m-d H:i:s') . '清空完成' . PHP_EOL;
}
}
... ...
... ... @@ -54,12 +54,12 @@ class UpdateRoute extends Command
*/
public function handle(){
$projectModel = new Project();
$lists = $projectModel->list(['is_upgrade'=>0,'type'=>['!=',0]]);
$lists = $projectModel->list(['is_upgrade'=>0,'id'=>['>',167],'type'=>['!=',0]]);
foreach ($lists as $k => $v){
echo date('Y-m-d H:i:s') . ' start: 项目id为' . $v['id'] . PHP_EOL;
ProjectServer::useProject($v['id']);
$this->setProductRoute($v['id']);
// $this->setProductKeywordRoute($v['id']);
// $this->setProductRoute($v['id']);
$this->setProductKeywordRoute($v['id']);
// $this->setBlogRoute($v['id']);
// $this->setNewsRoute($v['id']);
// $this->setBlogCateRoute($v['id']);
... ... @@ -194,11 +194,15 @@ class UpdateRoute extends Command
public function setProductKeywordRoute($project_id){
$keywordModel = new Keyword();
$keywordList = $keywordModel->list([],'id',['id','route']);
foreach ($keywordList as $v){
if(!ends_with($v['route'],'-tag')){
$route = $v['route'].'-tag';
$keywordModel->edit(['route'=>$route],['id'=>$v['id']]);
RouteMap::setRoute($route, RouteMap::SOURCE_BLOG_CATE, $v['id'], $project_id);
if(!empty($keywordList)){
foreach ($keywordList as $v){
// if(!ends_with($v['route'],'-tag')){
// $route = $v['route'].'-tag';
// $keywordModel->edit(['route'=>$route],['id'=>$v['id']]);
// }
$routeMapModel = new RouteMap();
$routeMapModel->edit(['route'=>$v['route']],['source_id'=>$v['id'],'source'=>RouteMap::SOURCE_PRODUCT_KEYWORD]);
RouteMap::setRoute($v['route'], RouteMap::SOURCE_PRODUCT_KEYWORD, $v['id'], $project_id);
}
}
return true;
... ...
... ... @@ -360,7 +360,7 @@ class UpdateSeoTdk extends Command
//随机取
shuffle($main_keywords);
$main_keywords = array_slice($main_keywords, 0, $num);
$str = implode(",", $main_keywords);
$str = implode(", ", $main_keywords);
}
return $str;
}
... ...
... ... @@ -213,7 +213,7 @@ class Common
}
}
}
return implode(',',$ar_keywords);
return implode(', ',$ar_keywords);
}
... ...
... ... @@ -201,13 +201,13 @@ class ProjectController extends BaseController
*/
public function searchChannel(&$query){
if(isset($this->map['zone_id']) && !empty($this->map['zone_id'])){
$query->where('gl_project.channel','like','%"zone_id": "'.$this->map['channel_id'].'"%');
$query->where('gl_project.channel','like','%"zone_id": "'.$this->map['zone_id'].'"%');
}
if(isset($this->map['channel_id']) && !empty($this->map['channel_id'])){
$query->where('gl_project.channel','like','%"channel_id": "'.$this->map['channel_id'].'"%');
}
if(isset($this->map['user_id']) && !empty($this->map['user_id'])){
$query->where('gl_project.channel','like','%"user_id": "'.$this->map['channel_id'].'"%');
$query->where('gl_project.channel','like','%"user_id": "'.$this->map['user_id'].'"%');
}
return $query;
}
... ...
... ... @@ -7,18 +7,17 @@ use App\Helper\Common;
use App\Helper\Translate;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Controllers\Bside\:写入日志;
use App\Http\Logic\Bside\Ai\AiCommandLogic;
use App\Models\Ai\AiCommand;
use App\Models\Ai\AiLog;
use App\Models\Project\DeployOptimize;
use App\Models\Project\Project;
class AiCommandController extends BaseController
{
//获取文本内容
public $chat_url = 'v2/openai_chat_qqs';
/**
* @name :ai生成
* @author :liyuhang
* @method
* @author zbj
* @date 2023/11/22
*/
public function ai_http_post(){
$this->request->validate([
... ... @@ -28,39 +27,19 @@ class AiCommandController extends BaseController
'keywords.required' => '关键字不能为空',
'key.required' => '场景不能为空',
]);
#TODO 通过key获取到ai指令对象
$data = Common::send_openai_msg($this->chat_url,$this->param,$this->companyName($this->param['key'],$this->user['project_id']));
$data['text'] = Common::deal_keywords($data['text']);
$data['text'] = Common::deal_str($data['text']);
$param = [
'key'=>$this->param['key'],
'keywords'=>$this->param['keywords'],
'remark'=>json_encode($data)
];
$this->set_ai_log($param);
$this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :获取公司英文名称
* @name :companyName
* @author :lyh
* @method :post
* @time :2023/10/30 11:22
*/
public function companyName($key,$project_id){
$text = AiCommandLogic::instance()->ai_send();
$data = [
'news_remark',
'blog_remark',
'product_long_description'
'code' => $text ? 200 : 500,
'text' => $text
];
$projectOptimizeModel = new DeployOptimize();
$info = $projectOptimizeModel->read(['project_id'=>$project_id],['id','company_en_name','company_en_description']);
if(in_array($key,$data)){
return $info['company_en_description'];
}else{
return $info['company_en_name'];
}
$param = [
'key' => $this->param['key'],
'keywords' => $this->param['keywords'],
'remark' => $text
];
$this->set_ai_log($param);
$this->response('success', Code::SUCCESS, $data);
}
/**
... ...
... ... @@ -32,7 +32,7 @@ class BTemplateModuleController extends BaseController
$moduleProjectModel = new BModuleProject();
$module_list = $moduleProjectModel->list(['project_id'=>$this->user['project_id']]);
$data['module_list'] = $module_list;
$this->response('success',Code::SUCCESS,$list);
$this->response('success',Code::SUCCESS,$data);
}
/**
... ...
... ... @@ -4,9 +4,7 @@ namespace App\Http\Logic\Aside\Project;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Project\DomainInfo;
use App\Models\Project\Payment;
use MongoDB\Client;
use App\Models\Domain\DomainInfo;
class DomainInfoLogic extends BaseLogic
{
... ... @@ -18,26 +16,15 @@ class DomainInfoLogic extends BaseLogic
public function getDomainInfo($project_id)
{
$project = (new ProjectLogic())->getProjectInfo($project_id);
$domain = (!empty($project['deploy_optimize']['domain']) ? ((new \App\Models\Domain\DomainInfo())->getDomain($project['deploy_optimize']['domain'])) : '');
$info = $this->model->where('project_id', $project_id)->first();
//不存在或时间过期了 重新获取信息
$expiration_date = $info['domain_info']['expiration_date'] ?? '';
$end_time = $info['ssl']['end_time'] ?? '';
if(!$info || $expiration_date < date("Y-m-d") || $end_time < date('Y-m-d')){
try {
$mongo = new Client("mongodb://root:globalso8837840@23.228.125.2:27017");
$db = $mongo->globalso_monitor;
$collection = $db->project_v1;
$project_zk = $collection->findOne(['main_url' => $domain]);
$info['domain'] = $domain;
$info['domain_info'] = (array) $project_zk['domain_info'] ?? [];
$info['ssl'] = (array) $project_zk['ssl'] ?? [];
parent::save($info);
}catch (\Exception $e){
return [];
}
}
return $info;
$domain_info = $this->model->where('project_id', $project_id)->first();
if(!$domain_info){
return [];
}
return [
'domain' => 'https://'.$domain_info['domain'].'/',
'domain_info' => date('Y-m-d', strtotime($domain_info['domain_start_time'])) . ' - ' .date('Y-m-d', strtotime($domain_info['domain_end_time'])),
'cert_info' => date('Y-m-d', strtotime($domain_info['certificate_start_time'])) . ' - ' .date('Y-m-d', strtotime($domain_info['certificate_end_time'])),
];
}
}
... ...
<?php
namespace App\Http\Logic\Bside\Ai;
use App\Helper\Common;
use App\Helper\Gpt;
use App\Helper\Translate;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Ai\AiCommand;
use App\Models\Project\DeployOptimize;
use Illuminate\Support\Facades\Cache;
class AiCommandLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->param = $this->requestAll;
$this->model = new AiCommand();
}
/**
* @author zbj
* @date 2023/11/22
*/
public function getPrompt($is_batch = 0){
$ai_command = $this->model->where('key', $this->param['key'])->where('is_batch', $is_batch)->first();
if(!$ai_command){
$this->fail('指令不存在');
}
$prompt = $ai_command->ai;
if(strpos($prompt, '{keyword}') !== false) {
$prompt = str_replace('{keyword}', $this->param['keywords'], $prompt);
}
if(strpos($prompt, '{company introduction}') !== false) {
$company_introduction = $this->getDeployOptimize('company_en_description');
$prompt = str_replace('{company introduction}', $company_introduction, $prompt);
}
if(strpos($prompt, '{company name}') !== false) {
$company_name = $this->getDeployOptimize('company_en_name');
$prompt = str_replace('{company name}', $company_name, $prompt);
}
if(strpos($prompt, '{core keywords 8}') !== false) {
$main_keywords = $this->getDeployOptimize('main_keywords');
if ($main_keywords) {
$main_keywords = explode("\r\n", $main_keywords);
//随机取
shuffle($main_keywords);
$main_keywords = array_slice($main_keywords, 0, 8);
$main_keywords = implode(", ", $main_keywords);
$prompt = str_replace('{core keywords 8}', $main_keywords, $prompt);
}else{
$prompt = '';
}
}
if(trim($ai_command->ai) == '{core keywords 8}'){
$ai_send = false;
}else{
$lang = $this->getLang($this->param['keywords']);
$prompt .= '.Please answer in ' . ($lang ?: 'English');
$ai_send = true;
}
return [
'prompt' => $prompt,
'scene' => $ai_command->scene,
'ai_send' => $ai_send,
];
}
/**
* @param $content
* @return string
* @author zbj
* @date 2023/11/22
*/
public function getLang($content){
$result = Translate::translateSl($content);
if (isset($result['texts']['sl']) && isset(Translate::$tls_list[$result['texts']['sl']])) {
$lang = Translate::$tls_list[$result['texts']['sl']]['lang_en'];
} else {
$lang = 'English';
}
return $lang;
}
/**
* @param string $key
* @return false|mixed|string
* @author zbj
* @date 2023/11/22
*/
public function getDeployOptimize($key = ''){
$project_id = $this->project['id'];
$cache_key = 'project_deploy_optimize_info_' . $project_id;
$info = Cache::get($cache_key);
if(!$info){
$projectOptimizeModel = new DeployOptimize();
$info = $projectOptimizeModel->read(['project_id' => $project_id], ['id', 'company_en_name', 'company_en_description', 'main_keywords']);
Cache::put($cache_key, $info, 600);
}
if($key){
return $info[$key] ??'';
}
return $info;
}
/**
* @param int $is_batch
* @return array|string|string[]
* @author zbj
* @date 2023/11/22
*/
public function ai_send($is_batch = 0){
$prompt = $this->getPrompt($is_batch);
if(!$prompt['ai_send']){
return $prompt['prompt'];
}
$text = Gpt::instance()->openai_chat_qqs($prompt['prompt'], $prompt['scene']);
$text = Common::deal_keywords($text);
return Common::deal_str($text);
}
}
... ...
... ... @@ -60,9 +60,9 @@ class RankDataLogic extends BaseLogic
//项目信息
$data['project'] = [
'company' => $project['company'],
'domain' => (!empty($project['deploy_optimize']['domain']) ? ((new DomainInfo())->getDomain($project['deploy_optimize']['domain'])) : ''),
'domain_info' => ($domain_info['domain_info']['creation_date'] ?? '') . ' - ' . ($domain_info['domain_info']['expiration_date'] ?? ''),
'cert_info' => ($domain_info['ssl']['start_time'] ?? '') . ' - ' . ($domain_info['ssl']['end_time'] ?? ''),
'domain' => $domain_info['domain'] ?? '',
'domain_info' => $domain_info['domain_info'] ?? '',
'cert_info' => $domain_info['cert_info'] ?? '',
'plan' => Project::planMap()[$project['deploy_build']['plan']],
'keyword_num' => $project['deploy_build']['keyword_num'],
'compliance_day' => $rank['compliance_day'] ?? 0,
... ...
... ... @@ -56,11 +56,9 @@ class RouteMap extends Base
$i=1;
$sign = generateRoute($title);
$route = $sign;
if($source != BTemplate::SOURCE_PRODUCT){
while(self::isExist($route, $source, $source_id, $project_id)){
$route = $sign .'-'.$i;
$i++;
}
while(self::isExist($route, $source, $source_id, $project_id)){
$route = $sign .'-'.$i;
$i++;
}
return $route;
}
... ...