作者 刘锟

update

@@ -14,6 +14,8 @@ use App\Models\Devops\ServersIp; @@ -14,6 +14,8 @@ use App\Models\Devops\ServersIp;
14 use App\Models\Domain\DomainCreateTask; 14 use App\Models\Domain\DomainCreateTask;
15 use App\Models\Project\CountryCustom; 15 use App\Models\Project\CountryCustom;
16 use App\Models\Project\Project; 16 use App\Models\Project\Project;
  17 +use App\Models\ProjectAssociation\ProjectAssociation;
  18 +use App\Models\Workchat\MessagePush;
17 use Illuminate\Console\Command; 19 use Illuminate\Console\Command;
18 use App\Models\Domain\DomainInfo as DomainInfoModel; 20 use App\Models\Domain\DomainInfo as DomainInfoModel;
19 use Illuminate\Support\Facades\Log; 21 use Illuminate\Support\Facades\Log;
@@ -69,6 +71,7 @@ class DomainInfo extends Command @@ -69,6 +71,7 @@ class DomainInfo extends Command
69 $projectModel = new Project(); 71 $projectModel = new Project();
70 $serverIpModel = new ServersIp(); 72 $serverIpModel = new ServersIp();
71 $domainCreateTaskModel = new DomainCreateTask(); 73 $domainCreateTaskModel = new DomainCreateTask();
  74 + $end_day = date('Y-m-d H:i:s', strtotime('+1 month'));//域名1月后到期
72 $list = $domainModel->where('status', '=', 1)->get(); 75 $list = $domainModel->where('status', '=', 1)->get();
73 foreach ($list as $v) { 76 foreach ($list as $v) {
74 $project_info = $projectModel->read(['id' => $v['project_id'], 'type' => ['!=', Project::TYPE_CLOSE]], ['serve_id', 'project_type']); 77 $project_info = $projectModel->read(['id' => $v['project_id'], 'type' => ['!=', Project::TYPE_CLOSE]], ['serve_id', 'project_type']);
@@ -90,7 +93,7 @@ class DomainInfo extends Command @@ -90,7 +93,7 @@ class DomainInfo extends Command
90 $v->save(); 93 $v->save();
91 } 94 }
92 95
93 - if (empty($v['domain_end_time']) || $v['domain_end_time'] < date('Y-m-d H:i:s')) { 96 + if (empty($v['domain_end_time']) || $v['domain_end_time'] < $end_day) {
94 //获取主站域名有效期并更新 97 //获取主站域名有效期并更新
95 $valid_time = $this->getDomainValidTime($v['domain']); 98 $valid_time = $this->getDomainValidTime($v['domain']);
96 if ($valid_time['start'] && $valid_time['end']) { 99 if ($valid_time['start'] && $valid_time['end']) {
@@ -99,6 +102,12 @@ class DomainInfo extends Command @@ -99,6 +102,12 @@ class DomainInfo extends Command
99 $v->save(); 102 $v->save();
100 } 103 }
101 } 104 }
  105 +
  106 + //域名到期提醒
  107 + if ($v->domain_end_time && $v->domain_end_time < $end_day) {
  108 + $is_end = $v->domain_end_time < date('Y-m-d H:i:s') ? 1 : 0;
  109 + $this->domainChatMessage($v['project_id'], $v['id'], $v['domain'], $is_end);
  110 + }
102 } else { 111 } else {
103 //除自建站项目外,记录已解析到别的ip的域名 112 //除自建站项目外,记录已解析到别的ip的域名
104 if (!check_domain_record($v['domain'], $servers_ip_info)) { 113 if (!check_domain_record($v['domain'], $servers_ip_info)) {
@@ -125,7 +134,7 @@ class DomainInfo extends Command @@ -125,7 +134,7 @@ class DomainInfo extends Command
125 $v->save(); 134 $v->save();
126 } 135 }
127 136
128 - if (empty($v['domain_end_time']) || $v['domain_end_time'] < date('Y-m-d H:i:s')) { 137 + if (empty($v['domain_end_time']) || $v['domain_end_time'] < $end_day) {
129 //获取主站域名有效期并更新 138 //获取主站域名有效期并更新
130 $valid_time = $this->getDomainValidTime($v['domain']); 139 $valid_time = $this->getDomainValidTime($v['domain']);
131 if ($valid_time['start'] && $valid_time['end']) { 140 if ($valid_time['start'] && $valid_time['end']) {
@@ -135,6 +144,12 @@ class DomainInfo extends Command @@ -135,6 +144,12 @@ class DomainInfo extends Command
135 } 144 }
136 } 145 }
137 146
  147 + //域名到期提醒
  148 + if ($v->domain_end_time && $v->domain_end_time < $end_day) {
  149 + $is_end = $v->domain_end_time < date('Y-m-d H:i:s') ? 1 : 0;
  150 + $this->domainChatMessage($v['project_id'], $v['id'], $v['domain'], $is_end);
  151 + }
  152 +
138 if ($v['amp_status'] == 1) { 153 if ($v['amp_status'] == 1) {
139 $domain_array = parse_url($v['domain']); 154 $domain_array = parse_url($v['domain']);
140 $host = $domain_array['host'] ?? $domain_array['path']; 155 $host = $domain_array['host'] ?? $domain_array['path'];
@@ -177,7 +192,7 @@ class DomainInfo extends Command @@ -177,7 +192,7 @@ class DomainInfo extends Command
177 $projectModel = new Project(); 192 $projectModel = new Project();
178 $serverIpModel = new ServersIp(); 193 $serverIpModel = new ServersIp();
179 $domainCreateTaskModel = new DomainCreateTask(); 194 $domainCreateTaskModel = new DomainCreateTask();
180 - $end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期 195 + $end_day = date('Y-m-d H:i:s', strtotime('+3 day'));//3天后到期
181 $list = $domainModel->where('status', '=', 1)->where('type', '!=', 2)->where('certificate_end_time', '<', $end_day)->get()->toArray(); 196 $list = $domainModel->where('status', '=', 1)->where('type', '!=', 2)->where('certificate_end_time', '<', $end_day)->get()->toArray();
182 foreach ($list as $v) { 197 foreach ($list as $v) {
183 $project_info = $projectModel->read(['id' => $v['project_id'], 'type' => ['!=', Project::TYPE_CLOSE]], ['serve_id', 'project_type']); 198 $project_info = $projectModel->read(['id' => $v['project_id'], 'type' => ['!=', Project::TYPE_CLOSE]], ['serve_id', 'project_type']);
@@ -230,7 +245,7 @@ class DomainInfo extends Command @@ -230,7 +245,7 @@ class DomainInfo extends Command
230 $projectModel = new Project(); 245 $projectModel = new Project();
231 $serverIpModel = new ServersIp(); 246 $serverIpModel = new ServersIp();
232 $domainCreateTaskModel = new DomainCreateTask(); 247 $domainCreateTaskModel = new DomainCreateTask();
233 - $end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期 248 + $end_day = date('Y-m-d H:i:s', strtotime('+3 day'));//3天后到期
234 $list = $domainModel->where('status', '=', 1)->where('amp_status', 1)->where('amp_type', '!=', 2)->where('amp_certificate_end_time', '<', $end_day)->get()->toArray(); 249 $list = $domainModel->where('status', '=', 1)->where('amp_status', 1)->where('amp_type', '!=', 2)->where('amp_certificate_end_time', '<', $end_day)->get()->toArray();
235 foreach ($list as $v) { 250 foreach ($list as $v) {
236 $domain_array = parse_url($v['domain']); 251 $domain_array = parse_url($v['domain']);
@@ -287,7 +302,7 @@ class DomainInfo extends Command @@ -287,7 +302,7 @@ class DomainInfo extends Command
287 $projectModel = new Project(); 302 $projectModel = new Project();
288 $serverIpModel = new ServersIp(); 303 $serverIpModel = new ServersIp();
289 $domainCreateTaskModel = new DomainCreateTask(); 304 $domainCreateTaskModel = new DomainCreateTask();
290 - $end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期 305 + $end_day = date('Y-m-d H:i:s', strtotime('+3 day'));//3天后到期
291 $list = $customModel->where('status', 1)->where('is_create', 1)->where('type', '=', 1)->where('certificate_end_time', '<', $end_day)->get()->toArray(); 306 $list = $customModel->where('status', 1)->where('is_create', 1)->where('type', '=', 1)->where('certificate_end_time', '<', $end_day)->get()->toArray();
292 foreach ($list as $v) { 307 foreach ($list as $v) {
293 $project_info = $projectModel->read(['id' => $v['project_id'], 'type' => ['!=', Project::TYPE_CLOSE]], ['serve_id']); 308 $project_info = $projectModel->read(['id' => $v['project_id'], 'type' => ['!=', Project::TYPE_CLOSE]], ['serve_id']);
@@ -379,4 +394,38 @@ class DomainInfo extends Command @@ -379,4 +394,38 @@ class DomainInfo extends Command
379 } 394 }
380 return ['start' => $start, 'end' => $end]; 395 return ['start' => $start, 'end' => $end];
381 } 396 }
  397 +
  398 + /**
  399 + * 推送域名到期微信消息提醒
  400 + * @param $project_id
  401 + * @param $domain_id
  402 + * @param $domain
  403 + * @param $is_end
  404 + * @author Akun
  405 + * @date 2025/08/14 9:56
  406 + */
  407 + public function domainChatMessage($project_id, $domain_id, $domain, $is_end)
  408 + {
  409 + //项目是否有绑定群
  410 + $friend_id = ProjectAssociation::where('project_id', $project_id)
  411 + ->where('status', ProjectAssociation::STATUS_NORMAL)
  412 + ->where('binding_app', ProjectAssociation::ENTERPRISE_WECHAT)
  413 + ->value('friend_id');
  414 + if ($friend_id) {
  415 + $tips = $is_end ? ' 已经到期' : ' 即将到期';
  416 + $message = '【域名到期提醒】' . PHP_EOL . '域名 ' . $domain . $tips . ',请及时处理。';
  417 + $param = [
  418 + 'project_id' => $project_id,
  419 + 'friend_id' => $friend_id,
  420 + 'type' => MessagePush::TYPE_DOMAIN,
  421 + 'content' => $message,
  422 + 'ref_ids' => $domain_id,
  423 + 'send_time' => date('Y-m-d H:i:s'),
  424 + 'status' => 0,
  425 + ];
  426 + //写入一条推送消息 自动消费
  427 + $messagePushModel = new MessagePush();
  428 + $messagePushModel->add($param);
  429 + }
  430 + }
382 } 431 }
@@ -28,6 +28,7 @@ class MessagePush extends Base @@ -28,6 +28,7 @@ class MessagePush extends Base
28 const TYPE_INQUIRY = 'inquiry'; 28 const TYPE_INQUIRY = 'inquiry';
29 const TYPE_WEEK = 'week'; 29 const TYPE_WEEK = 'week';
30 const TYPE_TICKET = 'ticket'; 30 const TYPE_TICKET = 'ticket';
  31 + const TYPE_DOMAIN = 'domain';
31 //设置关联表名 32 //设置关联表名
32 /** 33 /**
33 * @var mixed 34 * @var mixed