作者 刘锟

update

... ... @@ -14,6 +14,8 @@ use App\Models\Devops\ServersIp;
use App\Models\Domain\DomainCreateTask;
use App\Models\Project\CountryCustom;
use App\Models\Project\Project;
use App\Models\ProjectAssociation\ProjectAssociation;
use App\Models\Workchat\MessagePush;
use Illuminate\Console\Command;
use App\Models\Domain\DomainInfo as DomainInfoModel;
use Illuminate\Support\Facades\Log;
... ... @@ -69,6 +71,7 @@ class DomainInfo extends Command
$projectModel = new Project();
$serverIpModel = new ServersIp();
$domainCreateTaskModel = new DomainCreateTask();
$end_day = date('Y-m-d H:i:s', strtotime('+1 month'));//域名1月后到期
$list = $domainModel->where('status', '=', 1)->get();
foreach ($list as $v) {
$project_info = $projectModel->read(['id' => $v['project_id'], 'type' => ['!=', Project::TYPE_CLOSE]], ['serve_id', 'project_type']);
... ... @@ -90,7 +93,7 @@ class DomainInfo extends Command
$v->save();
}
if (empty($v['domain_end_time']) || $v['domain_end_time'] < date('Y-m-d H:i:s')) {
if (empty($v['domain_end_time']) || $v['domain_end_time'] < $end_day) {
//获取主站域名有效期并更新
$valid_time = $this->getDomainValidTime($v['domain']);
if ($valid_time['start'] && $valid_time['end']) {
... ... @@ -99,6 +102,12 @@ class DomainInfo extends Command
$v->save();
}
}
//域名到期提醒
if ($v->domain_end_time && $v->domain_end_time < $end_day) {
$is_end = $v->domain_end_time < date('Y-m-d H:i:s') ? 1 : 0;
$this->domainChatMessage($v['project_id'], $v['id'], $v['domain'], $is_end);
}
} else {
//除自建站项目外,记录已解析到别的ip的域名
if (!check_domain_record($v['domain'], $servers_ip_info)) {
... ... @@ -125,7 +134,7 @@ class DomainInfo extends Command
$v->save();
}
if (empty($v['domain_end_time']) || $v['domain_end_time'] < date('Y-m-d H:i:s')) {
if (empty($v['domain_end_time']) || $v['domain_end_time'] < $end_day) {
//获取主站域名有效期并更新
$valid_time = $this->getDomainValidTime($v['domain']);
if ($valid_time['start'] && $valid_time['end']) {
... ... @@ -135,6 +144,12 @@ class DomainInfo extends Command
}
}
//域名到期提醒
if ($v->domain_end_time && $v->domain_end_time < $end_day) {
$is_end = $v->domain_end_time < date('Y-m-d H:i:s') ? 1 : 0;
$this->domainChatMessage($v['project_id'], $v['id'], $v['domain'], $is_end);
}
if ($v['amp_status'] == 1) {
$domain_array = parse_url($v['domain']);
$host = $domain_array['host'] ?? $domain_array['path'];
... ... @@ -177,7 +192,7 @@ class DomainInfo extends Command
$projectModel = new Project();
$serverIpModel = new ServersIp();
$domainCreateTaskModel = new DomainCreateTask();
$end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期
$end_day = date('Y-m-d H:i:s', strtotime('+3 day'));//3天后到期
$list = $domainModel->where('status', '=', 1)->where('type', '!=', 2)->where('certificate_end_time', '<', $end_day)->get()->toArray();
foreach ($list as $v) {
$project_info = $projectModel->read(['id' => $v['project_id'], 'type' => ['!=', Project::TYPE_CLOSE]], ['serve_id', 'project_type']);
... ... @@ -230,7 +245,7 @@ class DomainInfo extends Command
$projectModel = new Project();
$serverIpModel = new ServersIp();
$domainCreateTaskModel = new DomainCreateTask();
$end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期
$end_day = date('Y-m-d H:i:s', strtotime('+3 day'));//3天后到期
$list = $domainModel->where('status', '=', 1)->where('amp_status', 1)->where('amp_type', '!=', 2)->where('amp_certificate_end_time', '<', $end_day)->get()->toArray();
foreach ($list as $v) {
$domain_array = parse_url($v['domain']);
... ... @@ -287,7 +302,7 @@ class DomainInfo extends Command
$projectModel = new Project();
$serverIpModel = new ServersIp();
$domainCreateTaskModel = new DomainCreateTask();
$end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期
$end_day = date('Y-m-d H:i:s', strtotime('+3 day'));//3天后到期
$list = $customModel->where('status', 1)->where('is_create', 1)->where('type', '=', 1)->where('certificate_end_time', '<', $end_day)->get()->toArray();
foreach ($list as $v) {
$project_info = $projectModel->read(['id' => $v['project_id'], 'type' => ['!=', Project::TYPE_CLOSE]], ['serve_id']);
... ... @@ -379,4 +394,38 @@ class DomainInfo extends Command
}
return ['start' => $start, 'end' => $end];
}
/**
* 推送域名到期微信消息提醒
* @param $project_id
* @param $domain_id
* @param $domain
* @param $is_end
* @author Akun
* @date 2025/08/14 9:56
*/
public function domainChatMessage($project_id, $domain_id, $domain, $is_end)
{
//项目是否有绑定群
$friend_id = ProjectAssociation::where('project_id', $project_id)
->where('status', ProjectAssociation::STATUS_NORMAL)
->where('binding_app', ProjectAssociation::ENTERPRISE_WECHAT)
->value('friend_id');
if ($friend_id) {
$tips = $is_end ? ' 已经到期' : ' 即将到期';
$message = '【域名到期提醒】' . PHP_EOL . '域名 ' . $domain . $tips . ',请及时处理。';
$param = [
'project_id' => $project_id,
'friend_id' => $friend_id,
'type' => MessagePush::TYPE_DOMAIN,
'content' => $message,
'ref_ids' => $domain_id,
'send_time' => date('Y-m-d H:i:s'),
'status' => 0,
];
//写入一条推送消息 自动消费
$messagePushModel = new MessagePush();
$messagePushModel->add($param);
}
}
}
... ...
... ... @@ -28,6 +28,7 @@ class MessagePush extends Base
const TYPE_INQUIRY = 'inquiry';
const TYPE_WEEK = 'week';
const TYPE_TICKET = 'ticket';
const TYPE_DOMAIN = 'domain';
//设置关联表名
/**
* @var mixed
... ...