作者 刘锟

update

... ... @@ -9,10 +9,8 @@ use App\Models\Devops\ServersIp;
use App\Models\Domain\DomainCreateTask;
use App\Models\Domain\DomainInfo;
use App\Models\Product\Keyword;
use App\Models\Product\KeywordRelated;
use App\Models\Product\Product;
use App\Models\Project\DeployBuild;
use App\Models\Project\Project;
use App\Models\Project\ProjectUpdateTdk;
use App\Models\WebSetting\WebLanguage;
use App\Services\BatchExportService;
use App\Services\ProjectServer;
... ... @@ -37,9 +35,76 @@ class Temp extends Command
public function handle()
{
$this->domain_rewrite_https();
}
/**
* 小语种为二级目录的项目强制跳转https
* @author Akun
* @date 2025/03/01 10:48
*/
public function domain_rewrite_https()
{
$domainModel = new DomainInfo();
$projectModel = new Project();
$buildModel = new DeployBuild();
$serverIpModel = new ServersIp();
$domainCreateTaskModel = new DomainCreateTask();
$list = $domainModel->select(['id', 'domain', 'project_id'])->where('status', '=', 1)->where('project_id', '>', 0)->get();
foreach ($list as $v) {
$project_info = $projectModel->read(['id' => $v['project_id']], ['serve_id']);
if (!$project_info) {
continue;
}
$build_info = $buildModel->read(['project_id' => $v['project_id']], ['linking_format']);
if (!$build_info) {
continue;
}
if ($build_info['linking_format'] != 1) {
continue;
}
$servers_ip_info = $serverIpModel->read(['id' => $project_info['serve_id']], ['servers_id', 'ip', 'domain']);
if (!$servers_ip_info) {
continue;
}
//过滤测试项目域名
if ($servers_ip_info['servers_id'] == ServerConfig::SELF_TEST_ID) {
continue;
}
//过滤自建站项目域名
if ($servers_ip_info['servers_id'] == ServerConfig::SELF_SITE_ID) {
continue;
}
//过滤已解析到别的ip的域名
if (!check_domain_record($v['domain'], $servers_ip_info)) {
continue;
}
//强制跳转https
$v->is_https = 1;
$v->save();
//创建更新站点证书任务
$task_info = $domainCreateTaskModel->read(['type' => DomainCreateTask::TYPE_MAIN, 'domain_id' => $v['id'], 'status' => ['<', DomainCreateTask::STATUS_SUC]]);
if (!$task_info) {
$domainCreateTaskModel->add([
'server_id' => $servers_ip_info['servers_id'],
'project_id' => $v['project_id'],
'domain_id' => $v['id'],
'type' => DomainCreateTask::TYPE_MAIN
]);
}
$this->output($v['id'] . ' , success');
}
}
/**
* 240服务器上解析cname的项目迁移
* @author Akun
... ... @@ -128,42 +193,6 @@ class Temp extends Command
}
/**
* 2025-02-05 日以来的项目,重写tdk(keyword_title)
* @author Akun
* @date 2025/02/15 10:58
*/
public function product_keyword_rewrite()
{
$products = ProjectUpdateTdk::where('created_at', '>=', '2025-02-05 00:00:00')->pluck('project_id')->toArray();
$products_ids = array_unique($products);
$success_json = file_get_contents(storage_path('logs/lk/success.log'));
$success = json_decode($success_json, true) ?: [];
foreach ($products_ids as $project_id) {
if (in_array($project_id, $success)) {
$this->output($project_id . ' | 已执行,跳过');
continue;
}
ProjectServer::useProject($project_id);
DB::connection('custom_mysql')->table('gl_product_keyword')->update(['keyword_title' => '']);
try {
ProjectUpdateTdk::add_task($project_id);
} catch (\Exception $e) {
$this->output($project_id . ' | ' . $e->getMessage());
}
DB::disconnect('custom_mysql');
array_push($success, $project_id);
file_put_contents(storage_path('logs/lk/success.log'), json_encode($success));
}
$this->output('success');
}
/**
* 创建所有站点建站任务
* @author Akun
* @date 2025/01/27 9:48
... ... @@ -386,33 +415,6 @@ class Temp extends Command
}
}
/**
* 关联所有项目关键词
* @author Akun
* @date 2024/11/18 15:07
*/
public function relation_all_keywords()
{
$projects = Project::select(['id'])->orderBy('id', 'asc')->get();
foreach ($projects as $project) {
ProjectServer::useProject($project->id);
try {
Product::select(['id', 'keyword_id'])->chunk(1000, function ($query) {
foreach ($query as $item) {
KeywordRelated::saveRelated($item->id, $item->keyword_id);
}
});
} catch (\Exception $e) {
$this->output($e->getMessage());
continue;
}
$this->output('ID:' . $project->id . ',success');
}
}
/**
* 获取指定服务器所有项目
* @author Akun
... ... @@ -692,66 +694,6 @@ class Temp extends Command
}
}
/**
* 创建指定项目聚合页生成任务
* @author Akun
* @date 2025/02/11 13:50
*/
public function create_update_keyword_page()
{
$ids_arr = ["46", "83", "91", "150", "190", "206", "219", "221", "232", "233", "238", "287", "290", "299", "319", "321", "353", "356", "388", "389", "456", "457", "475", "491", "518", "535", "554", "600", "624", "650", "728", "732", "783", "807", "835", "881", "896", "913", "947", "1001", "1320", "1336", "1373", "1424", "1442", "1455", "1466", "1505", "1584", "1597", "1617", "1682", "1770", "1816", "1824", "1835", "1860", "1870", "1896", "1913", "1989", "1991", "1992", "2022", "2037", "2059", "2060", "2062", "2104", "2115", "2129", "2131", "2135", "2191", "2204", "2217", "2245", "2257", "2287", "2309", "2313", "2330", "2336", "2337", "2338", "2351", "2391", "2418", "2423", "2435", "2462", "2496", "2504", "2505", "2660", "2768", "2811", "2874", "3157"];
$project_list = Project::select(['id', 'serve_id'])->whereIn('id', $ids_arr)->get();
$domain_model = new DomainInfo();
$notify_model = new Notify();
$server_ip_model = new ServersIp();
foreach ($project_list as $value) {
$project_id = $value->id;
$domain_info = $domain_model->read(['project_id' => $project_id, 'status' => 1], ['id', 'domain']);
if (!$domain_info) {
//过滤未绑定正式域名的项目
continue;
}
$domain = $domain_info['domain'];
//获取项目所在服务器
$serve_ip_info = $server_ip_model->read(['id' => $value->serve_id], ['domain', 'ip', 'servers_id']);
if (!$serve_ip_info) {
$this->output('项目id:' . $project_id . ' | 未查询到服务器数据');
continue;
}
if ($serve_ip_info['servers_id'] != ServerConfig::SELF_SITE_ID) {
if (!check_domain_record($domain, $serve_ip_info)) {
$this->output('项目id:' . $project_id . ', domain:' . $domain . ' | 未解析到目标服务器');
continue;
}
}
$data = [
'project_id' => $project_id,
'type' => 1,
'route' => 4,
'server_id' => $serve_ip_info['servers_id'],
'status' => ['!=', Notify::STATUS_FINISH_SITEMAP]
];
$notify = $notify_model->read($data, ['id']);
if (!$notify) {
$data['data'] = Arr::a2s(['domain' => $domain, 'url' => null, 'language' => []]);
$data['status'] = Notify::STATUS_INIT;
if ($serve_ip_info['servers_id'] == 2) {
$data['is_pull_html_zip'] = Notify::IS_PULL_HTML_ZIP_TRUE;
}
$notify_model->add($data);
$this->output('项目id:' . $project_id . ', domain:' . $domain . ' | success');
}
}
}
public function output($msg)
{
... ...