作者 lms

合并分支 'lms' 到 'develop'

Lms



查看合并请求 !4
  1 +<?php
  2 +
  3 +namespace App\Console\Commands\Domain;
  4 +
  5 +use App\Exceptions\AsideGlobalException;
  6 +use App\Exceptions\BsideGlobalException;
  7 +use App\Helper\AyrShare as AyrShareHelper;
  8 +use App\Http\Logic\Aside\Domain\DomainInfoLogic;
  9 +use App\Models\AyrShare\AyrRelease as AyrReleaseModel;
  10 +use Carbon\Carbon;
  11 +use App\Models\AyrShare\AyrShare as AyrShareModel;
  12 +use Illuminate\Console\Command;
  13 +
  14 +class DomainTime extends Command
  15 +{
  16 + public $error = 0;
  17 + /**
  18 + * The name and signature of the console command.
  19 + *
  20 + * @var string
  21 + */
  22 + protected $signature = 'domain_time';
  23 +
  24 + /**
  25 + * The console command description.
  26 + *
  27 + * @var string
  28 + */
  29 + protected $description = '域名定时任务 更新域名|证书到期时间';
  30 +
  31 + /**
  32 + * @name :(定时执行)handle
  33 + * @author :lyh
  34 + * @method :post
  35 + * @time :2023/5/12 14:48
  36 + */
  37 + public function handle()
  38 + {
  39 + echo $this->update_domain_time();
  40 + }
  41 +
  42 + /**
  43 + * 更新域名|证书到期时间
  44 + * @return int|mixed|void
  45 + * @throws AsideGlobalException
  46 + * @throws BsideGlobalException
  47 + */
  48 + protected function update_domain_time()
  49 + {
  50 + $domainCon = new DomainInfoLogic();
  51 + $all = $domainCon->getAllDomain();
  52 + $all = $all->toArray();
  53 + if ( empty( $all ) ) {
  54 + $this->info( '未获取到数据' );
  55 + return;
  56 + }
  57 + foreach ( $all as $item ) {
  58 + $domain = $item['domain'];
  59 + // 域名到期时间
  60 + $domainT = $domainCon->getDomainTime( $domain );
  61 + if ( $domainT ) {
  62 + $domain_time = $item['domain_end_time'];
  63 + $domainValidFrom = $domainT['validFrom'];
  64 + $domainValidTo = $domainT['validTo'];
  65 + if ( strtotime( $domain_time ) < strtotime( $domainValidTo ) ) {
  66 + $this->info( $domain . '域名到期时间更新成功' );
  67 + $domainCon->updateDomain( $item['id'], [ 'domain_end_time' => $domainValidTo ] );
  68 + }
  69 + } else {
  70 + $this->error++;
  71 + $this->info( $domain . '域名到期时间获取失败' );
  72 + }
  73 + // 证书到期时间
  74 + $certificateT = $domainCon->getDomainCertificateTime( $domain );
  75 + if ( $certificateT ) {
  76 + $certificate_time = $item['certificate_end_time'];
  77 + $certificateValidFrom = $certificateT['validFrom'];
  78 + $certificateValidTo = $certificateT['validTo'];
  79 + if ( strtotime( $certificate_time ) < strtotime( $certificateValidTo ) ) {
  80 + $this->info( $domain . '证书到期时间更新成功' );
  81 + $domainCon->updateDomain( $item['id'], [ 'certificate_end_time' => $certificateValidTo ] );
  82 + }
  83 + } else {
  84 + $this->error++;
  85 + $this->info( $domain . '证书到期时间获取失败' );
  86 + }
  87 + }
  88 + return $this->error;
  89 + }
  90 +}
@@ -27,6 +27,7 @@ class Kernel extends ConsoleKernel @@ -27,6 +27,7 @@ class Kernel extends ConsoleKernel
27 $schedule->command('web_traffic 1')->everyThirtyMinutes(); // 引流 1-3个月的项目,半小时一次 27 $schedule->command('web_traffic 1')->everyThirtyMinutes(); // 引流 1-3个月的项目,半小时一次
28 $schedule->command('web_traffic 2')->cron('*/18 * * * *'); // 引流 4-8个月的项目,18分钟一次 28 $schedule->command('web_traffic 2')->cron('*/18 * * * *'); // 引流 4-8个月的项目,18分钟一次
29 $schedule->command('web_traffic 3')->cron('*/12 * * * *'); // 引流 大于9个月的项目,12分钟一次 29 $schedule->command('web_traffic 3')->cron('*/12 * * * *'); // 引流 大于9个月的项目,12分钟一次
  30 +// $schedule->command('domain_time')->dailyAt('01:00')->withoutOverlapping(1); // 更新域名|证书结束时间,每天凌晨1点执行一次
30 } 31 }
31 32
32 /** 33 /**
@@ -22,9 +22,25 @@ class ServerInformationController extends BaseController @@ -22,9 +22,25 @@ class ServerInformationController extends BaseController
22 */ 22 */
23 public function lists($deleted = ServerInformation::DELETED_NORMAL) 23 public function lists($deleted = ServerInformation::DELETED_NORMAL)
24 { 24 {
  25 + $request = $this->param;
  26 + $search = [];
  27 + $search_array = [
  28 + 'ip' => 'ip',
  29 + 'title' => 'title'
  30 + ];
  31 + foreach ($search_array as $key => $item) {
  32 + if (isset($request[$key]) && $request[$key]) {
  33 + $search[$item] = $request[$key];
  34 + }
  35 + }
25 $size = request()->input('size', $this->row); 36 $size = request()->input('size', $this->row);
26 - $data = ServerInformation::query()->select(['id', 'title', 'ip'])  
27 - ->where('deleted', $deleted) 37 + $query = ServerInformation::query()->select(['id', 'title', 'ip']);
  38 + if ($search) {
  39 + foreach ($search as $key => $item) {
  40 + $query = $query->Where("{$key}", 'like', "%{$item}%");
  41 + }
  42 + }
  43 + $data = $query->where('deleted', $deleted)
28 ->orderBy('id', 'desc') 44 ->orderBy('id', 'desc')
29 ->paginate($size); 45 ->paginate($size);
30 return $this->response('success', Code::SUCCESS, $data); 46 return $this->response('success', Code::SUCCESS, $data);
@@ -58,9 +74,10 @@ class ServerInformationController extends BaseController @@ -58,9 +74,10 @@ class ServerInformationController extends BaseController
58 public function edit(ServerInformationRequest $serverInformationRequest, ServerInformationLogic $serverInformationLogic) 74 public function edit(ServerInformationRequest $serverInformationRequest, ServerInformationLogic $serverInformationLogic)
59 { 75 {
60 $serverInformationRequest->validate([ 76 $serverInformationRequest->validate([
61 - 'id' => ['required'], 77 + 'id' => 'required|integer',
62 ], [ 78 ], [
63 'id.required' => 'ID不能为空', 79 'id.required' => 'ID不能为空',
  80 + 'id.integer' => 'ID必须为整数',
64 ]); 81 ]);
65 $serverInformationLogic->update(); 82 $serverInformationLogic->update();
66 $this->response('服务器修改成功!'); 83 $this->response('服务器修改成功!');
@@ -150,6 +167,7 @@ class ServerInformationController extends BaseController @@ -150,6 +167,7 @@ class ServerInformationController extends BaseController
150 } 167 }
151 168
152 /** 169 /**
  170 + * 获取软删除的服务器信息
153 * @return JsonResponse 171 * @return JsonResponse
154 * @throws AsideGlobalException 172 * @throws AsideGlobalException
155 * @throws BsideGlobalException 173 * @throws BsideGlobalException
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Aside\Domain;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Exceptions\AsideGlobalException;
  7 +use App\Exceptions\BsideGlobalException;
  8 +use App\Http\Controllers\Aside\BaseController;
  9 +use App\Http\Logic\Aside\Domain\DomainInfoLogic;
  10 +use App\Http\Requests\Aside\Domain\DomainInfoRequest;
  11 +use App\Models\Aside\Domain\DomainInfo;
  12 +use App\Models\Aside\Domain\DomainInfoLog;
  13 +use Illuminate\Http\JsonResponse;
  14 +use Psr\Container\ContainerExceptionInterface;
  15 +use Psr\Container\NotFoundExceptionInterface;
  16 +
  17 +/**
  18 + * Class DomainInfoController
  19 + * @package App\Http\Controllers\Aside 域名管理
  20 + */
  21 +class DomainInfoController extends BaseController
  22 +{
  23 + /**
  24 + * 域名列表
  25 + * @param int $deleted
  26 + * @return JsonResponse
  27 + */
  28 + public function lists(int $deleted = DomainInfo::DELETED_NORMAL)
  29 + {
  30 + $request = $this->param;
  31 + $search = [];
  32 + $search_array = [
  33 + 'domain' => 'domain',
  34 + 'belong' => 'belong_to',
  35 + 'domain_time' => 'domain_end_time',
  36 + 'certificate_time' => 'certificate_end_time'
  37 + ];
  38 + foreach ($search_array as $key => $item) {
  39 + if (isset($request[$key]) && $request[$key]) {
  40 + $search[$item] = $request[$key];
  41 + }
  42 + }
  43 + // 每页条数
  44 + $size = request()->input('size', $this->row);
  45 + $query = DomainInfo::query()->select(['id', 'domain', 'belong_to']);
  46 + if ($search) {
  47 + foreach ($search as $key => $item) {
  48 + $query = $query->Where("{$key}", 'like', "%{$item}%");
  49 + }
  50 + }
  51 + $data = $query->where('deleted', $deleted)
  52 + ->orderBy('id', 'desc')
  53 + ->paginate($size);
  54 + return $this->response('success', Code::SUCCESS, $data);
  55 + }
  56 +
  57 + /**
  58 + * 获取软删除的数据
  59 + * @return JsonResponse
  60 + */
  61 + public function delete_list()
  62 + {
  63 + return $this->lists(DomainInfo::DELETED_DELETE);
  64 + }
  65 +
  66 + /**
  67 + * 添加域名
  68 + * @param DomainInfoRequest $domainInfoRequest
  69 + * @param DomainInfoLogic $domainInfoLogic
  70 + * @return void
  71 + * @throws AsideGlobalException
  72 + * @throws BsideGlobalException
  73 + */
  74 + public function add(DomainInfoRequest $domainInfoRequest, DomainInfoLogic $domainInfoLogic)
  75 + {
  76 + $domainInfoRequest->validated();
  77 + $domainInfoLogic->create();
  78 + $this->response('域名添加成功!');
  79 + }
  80 +
  81 + /**
  82 + * 编辑域名
  83 + * @param DomainInfoRequest $domainInfoRequest
  84 + * @param DomainInfoLogic $domainInfoLogic
  85 + * @return void
  86 + * @throws AsideGlobalException
  87 + * @throws BsideGlobalException
  88 + */
  89 + public function edit(DomainInfoRequest $domainInfoRequest, DomainInfoLogic $domainInfoLogic)
  90 + {
  91 + $domainInfoRequest->validate([
  92 + 'id' => 'required|integer'
  93 + ], [
  94 + 'id.required' => 'id不能为空',
  95 + 'id.integer' => 'id参数错误'
  96 + ]);
  97 + $domainInfoLogic->update();
  98 + $this->response('域名修改成功!');
  99 + }
  100 +
  101 + /**
  102 + * 删除
  103 + * @param DomainInfoLogic $domainInfoLogic
  104 + * @return void
  105 + * @throws AsideGlobalException
  106 + * @throws BsideGlobalException
  107 + */
  108 + public function delete(DomainInfoLogic $domainInfoLogic)
  109 + {
  110 + $domainInfoLogic->get_batch_update();
  111 + $this->response('域名删除成功!');
  112 + }
  113 +
  114 + /**
  115 + * 恢复数据
  116 + * @param DomainInfoLogic $domainInfoLogic
  117 + * @return void
  118 + * @throws AsideGlobalException
  119 + * @throws BsideGlobalException
  120 + */
  121 + public function restore(DomainInfoLogic $domainInfoLogic)
  122 + {
  123 + $domainInfoLogic->get_batch_update(DomainInfoLog::ACTION_RECOVER, DomainInfo::DELETED_DELETE);
  124 + $this->response('域名恢复成功!');
  125 + }
  126 +
  127 + /**
  128 + * 域名信息
  129 + * @param int $deleted
  130 + * @return JsonResponse
  131 + * @throws AsideGlobalException
  132 + * @throws BsideGlobalException
  133 + * @throws ContainerExceptionInterface
  134 + * @throws NotFoundExceptionInterface
  135 + */
  136 + public function info(int $deleted = DomainInfo::DELETED_NORMAL)
  137 + {
  138 + $domainInfoLogic = new DomainInfoLogic();
  139 + $data = $domainInfoLogic->domainInfo($deleted);
  140 + if (!$data) {
  141 + return $this->response('域名信息不存在', Code::USER_ERROR);
  142 + }
  143 + return $this->success($data->toArray());
  144 + }
  145 +
  146 + /**
  147 + * 获取软删除域名信息
  148 + * @return JsonResponse
  149 + * @throws AsideGlobalException
  150 + * @throws BsideGlobalException
  151 + * @throws ContainerExceptionInterface
  152 + * @throws NotFoundExceptionInterface
  153 + */
  154 + public function getDeleteDomainInfo()
  155 + {
  156 + return $this->info(DomainInfo::DELETED_DELETE);
  157 + }
  158 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Aside\Domain;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Http\Controllers\Aside\BaseController;
  7 +use App\Models\Aside\Domain\DomainInfoLog;
  8 +use Illuminate\Http\Request;
  9 +
  10 +class DomainInfoLogController extends BaseController
  11 +{
  12 + public function lists(Request $request)
  13 + {
  14 + $size = $request->input('size', $this->row);
  15 + $data = DomainInfoLog::query()
  16 + ->orderBy('id', 'desc')
  17 + ->paginate($size);
  18 + return $this->response('success', Code::SUCCESS, $data);
  19 +
  20 + }
  21 +}
@@ -12,9 +12,7 @@ use App\Models\Devops\ServerInformationLog; @@ -12,9 +12,7 @@ use App\Models\Devops\ServerInformationLog;
12 use Illuminate\Database\Eloquent\Builder; 12 use Illuminate\Database\Eloquent\Builder;
13 use Illuminate\Database\Eloquent\Collection; 13 use Illuminate\Database\Eloquent\Collection;
14 use Illuminate\Database\Eloquent\Model; 14 use Illuminate\Database\Eloquent\Model;
15 -use Illuminate\Http\JsonResponse;  
16 use Illuminate\Support\Facades\DB; 15 use Illuminate\Support\Facades\DB;
17 -use Illuminate\Support\Facades\Log;  
18 16
19 class ServerInformationLogic extends BaseLogic 17 class ServerInformationLogic extends BaseLogic
20 { 18 {
@@ -41,31 +39,25 @@ class ServerInformationLogic extends BaseLogic @@ -41,31 +39,25 @@ class ServerInformationLogic extends BaseLogic
41 */ 39 */
42 public function create() 40 public function create()
43 { 41 {
44 - $request = $this->param; 42 + $request = $this->param ?? [];
45 $service = new ServerInformation(); 43 $service = new ServerInformation();
46 - $this->extracted($request, $service);  
47 - if ($this->checkIp($service->ip)) {  
48 - return $this->fail('服务器信息添加失败,ip已存在'); 44 + $this->extracted( $request, $service );
  45 + if ( $this->checkIp( $service->ip ) ) {
  46 + return $this->fail( '服务器信息添加失败,ip已存在' );
49 } 47 }
50 DB::beginTransaction(); 48 DB::beginTransaction();
51 49
52 - if ($service->save()) {  
53 - $original = [  
54 - 'id' => $service->id,  
55 - 'type' => $service->type,  
56 - 'ip' => $service->ip,  
57 - 'title' => $service->title,  
58 - 'belong_to' => $service->belong_to,  
59 - 'sshpass' => $service->sshpass,  
60 - 'ports' => $service->ports,  
61 - ]; 50 + if ( $service->save() ) {
  51 + $original = $service->getOriginal();
  52 + $original['type'] = $request['type'];
  53 + $original['belong_to'] = $request['belong_to'];
62 // 添加日志 54 // 添加日志
63 - $this->server_action_log(ServerInformationLog::ACTION_ADD, $original, $original, '添加服务器信息成功 - ID : ' . $service->id); 55 + $this->server_action_log( ServerInformationLog::ACTION_ADD, $original, $original, '添加服务器信息成功 - ID : ' . $service->id );
64 DB::commit(); 56 DB::commit();
65 return $this->success(); 57 return $this->success();
66 } 58 }
67 DB::rollBack(); 59 DB::rollBack();
68 - return $this->fail('服务器信息添加失败'); 60 + return $this->fail( '服务器信息添加失败' );
69 61
70 } 62 }
71 63
@@ -77,51 +69,55 @@ class ServerInformationLogic extends BaseLogic @@ -77,51 +69,55 @@ class ServerInformationLogic extends BaseLogic
77 */ 69 */
78 public function update() 70 public function update()
79 { 71 {
80 -  
81 - $service = new ServerInformation(); 72 + $service = $this->getService();
82 $fields_array = $service->FieldsArray(); 73 $fields_array = $service->FieldsArray();
83 - $request = $this->param;  
84 - $service = $this->ServerInfo();  
85 - $original = $service->toArray();  
86 - $this->extracted($request, $service);  
87 - 74 + $request = $this->param ?? [];
  75 + $original = $service->getOriginal();
  76 + $original['type'] = $service->ServiceStr( $original['type'] );
  77 + $original['belong_to'] = $service->BelongToStr( $original['belong_to'] );
  78 + $this->extracted( $request, $service, $original );
88 // 检查ip是否存在 79 // 检查ip是否存在
89 - if ($service->ip != $request['ip']) {  
90 - if ($this->checkIp($request['ip'])) {  
91 - $this->fail('服务器信息修改失败,ip已存在', Code::USER_ERROR); 80 + if ( $service->ip != $request['ip'] ) {
  81 + if ( $this->checkIp( $request['ip'] ) ) {
  82 + $this->fail( '服务器信息修改失败,ip已存在', Code::USER_ERROR );
92 } 83 }
93 } 84 }
94 DB::beginTransaction(); 85 DB::beginTransaction();
95 - if ($service->save()) {  
96 - $revised = [  
97 - 'id' => $service->id,  
98 - 'type' => $service->type,  
99 - 'ip' => $service->ip,  
100 - 'title' => $service->title,  
101 - 'belong_to' => $service->belong_to,  
102 - 'sshpass' => $service->sshpass,  
103 - 'ports' => $service->ports,  
104 - 'other' => $service->other,  
105 - 'delete' => $service->delete,  
106 - ];  
107 - $diff = array_diff_assoc($original, $revised);  
108 - unset($diff['create_at']);  
109 - unset($diff['update_at']);  
110 - unset($diff['deleted']); 86 + if ( $service->save() ) {
  87 + $revised = $service->getAttributes();
  88 + $diff = array_diff_assoc( $original, $revised );
  89 + unset( $diff['created_at'] );
  90 + unset( $diff['updated_at'] );
  91 + unset( $diff['deleted'] );
111 $remarks = ''; 92 $remarks = '';
112 - if ($diff) { 93 + if ( $diff ) {
113 $remarks .= '修改ID为 ' . $service->id . ' 的服务器信息,修改内容为:'; 94 $remarks .= '修改ID为 ' . $service->id . ' 的服务器信息,修改内容为:';
114 - foreach ($diff as $key => $value) { 95 + foreach ( $diff as $key => $value ) {
115 $remarks .= $fields_array[$key] . ' 由 ' . $value . ' 修改为 ' . $revised[$key] . '; '; 96 $remarks .= $fields_array[$key] . ' 由 ' . $value . ' 修改为 ' . $revised[$key] . '; ';
116 } 97 }
  98 + } else {
  99 + $remarks .= '修改ID为 ' . $service->id . ' 的服务器信息,无修改';
117 } 100 }
118 // 添加日志 101 // 添加日志
119 - $this->server_action_log(ServerInformationLog::ACTION_UPDATE, $original, $revised, $remarks); 102 + $this->server_action_log( ServerInformationLog::ACTION_UPDATE, $original, $revised, $remarks );
120 DB::commit(); 103 DB::commit();
121 return $this->success(); 104 return $this->success();
122 } 105 }
123 DB::rollBack(); 106 DB::rollBack();
124 - return $this->fail('服务器信息修改失败'); 107 + return $this->fail( '服务器信息修改失败' );
  108 + }
  109 +
  110 + public function getService( int $deleted = ServerInformation::DELETED_NORMAL )
  111 + {
  112 + $id = $this->param['id'] ?? 0;
  113 + if ( !$id ) {
  114 + return $this->fail( 'ID不能为空' );
  115 + }
  116 + $data = ServerInformation::query()->where( 'deleted', $deleted )->find( $id );
  117 + if ( !$data ) {
  118 + return $this->fail( '数据不存在!' );
  119 + }
  120 + return $data;
125 } 121 }
126 122
127 /** 123 /**
@@ -129,10 +125,10 @@ class ServerInformationLogic extends BaseLogic @@ -129,10 +125,10 @@ class ServerInformationLogic extends BaseLogic
129 * @param $ip 125 * @param $ip
130 * @return bool 126 * @return bool
131 */ 127 */
132 - public function checkIp($ip) 128 + public function checkIp( $ip )
133 { 129 {
134 - $usIp = ServerInformation::query()->where('ip', $ip)->first();  
135 - if ($usIp) { 130 + $usIp = ServerInformation::query()->where( 'ip', $ip )->first();
  131 + if ( $usIp ) {
136 return true; 132 return true;
137 } else { 133 } else {
138 return false; 134 return false;
@@ -146,15 +142,15 @@ class ServerInformationLogic extends BaseLogic @@ -146,15 +142,15 @@ class ServerInformationLogic extends BaseLogic
146 * @throws AsideGlobalException 142 * @throws AsideGlobalException
147 * @throws BsideGlobalException 143 * @throws BsideGlobalException
148 */ 144 */
149 - public function serverInfo(int $deleted = ServerInformation::DELETED_NORMAL) 145 + public function serverInfo( int $deleted = ServerInformation::DELETED_NORMAL )
150 { 146 {
151 - $id = \request()->input('id');  
152 - if (!$id) {  
153 - return $this->fail('参数错误'); 147 + $id = $this->param['id'] ?? 0;
  148 + if ( !$id ) {
  149 + return $this->fail( 'ID不能为空' );
154 } 150 }
155 - $data = ServerInformation::query()->where('deleted', $deleted)->find($id, ['type', 'ip', 'title', 'belong_to', 'sshpass', 'ports', 'create_at', 'update_at']);  
156 - if (!$data) {  
157 - return $this->fail('数据不存在!'); 151 + $data = ServerInformation::query()->where( 'deleted', $deleted )->find( $id, [ 'type', 'ip', 'title', 'belong_to', 'ports', 'created_at', 'updated_at' ] );
  152 + if ( !$data ) {
  153 + return $this->fail( '数据不存在!' );
158 } 154 }
159 return $data; 155 return $data;
160 } 156 }
@@ -165,32 +161,10 @@ class ServerInformationLogic extends BaseLogic @@ -165,32 +161,10 @@ class ServerInformationLogic extends BaseLogic
165 * @param array $original 原始数据 161 * @param array $original 原始数据
166 * @param array $revised 修改后数据 162 * @param array $revised 修改后数据
167 */ 163 */
168 - public function server_action_log(int $action = ServerInformationLog::ACTION_ADD, array $original = [], array $revised = [], $remarks = '') 164 + public function server_action_log( int $action = ServerInformationLog::ACTION_ADD, array $original = [], array $revised = [], $remarks = '' )
169 { 165 {
170 - // $action 1:添加 2:修改 3:删除 4:恢复  
171 - $actionArr = ServerInformationLog::actionArr();  
172 - $actionStr = $actionArr[$action];  
173 - $ip = request()->getClientIp();  
174 - $url = request()->getRequestUri();  
175 - $method = request()->getMethod();  
176 - $userId = $this->uid ?? 0;  
177 $log = new ServerInformationLog(); 166 $log = new ServerInformationLog();
178 - $log->user_id = $userId;  
179 - $log->action = $actionStr;  
180 - $log->original = json_encode($original);  
181 - $log->revised = json_encode($revised);  
182 - $log->ip = $ip;  
183 - $log->url = $url;  
184 - $log->method = $method;  
185 - $log->remarks = $remarks;  
186 - DB::beginTransaction();  
187 - try {  
188 - $log->save();  
189 - DB::commit();  
190 - } catch (\Exception $e) {  
191 - DB::rollBack();  
192 - Log::error('服务器信息日志添加失败');  
193 - } 167 + $this->log( $log, $action, $original, $revised, $remarks );
194 } 168 }
195 169
196 /** 170 /**
@@ -198,14 +172,14 @@ class ServerInformationLogic extends BaseLogic @@ -198,14 +172,14 @@ class ServerInformationLogic extends BaseLogic
198 * @param $service 172 * @param $service
199 * @return void 173 * @return void
200 */ 174 */
201 - public function extracted(array $request, $service) 175 + public function extracted( array $request, $service, array $original = [] )
202 { 176 {
203 - $service->type = trim($request['type']); // 服务器类型  
204 - $service->ip = trim($request['ip']); // 服务器ip  
205 - $service->title = trim($request['title']); // 服务器标题  
206 - $service->belong_to = trim($request['belong_to']); // 服务器归属  
207 - $service->sshpass = trim($request['sshpass']); // ssh密码  
208 - $service->ports = trim($request['ports']); // ssh端口 177 + $service->type = trim( $request['type'] ) ?? $original['type']; // 服务器类型
  178 + $service->ip = trim( $request['ip'] ) ?? $original['ip']; // 服务器ip
  179 + $service->title = trim( $request['title'] ) ?? $original['title']; // 服务器标题
  180 + $service->belong_to = trim( $request['belong_to'] ) ?? $original['belong_to']; // 服务器归属
  181 + $service->sshpass = trim( $request['sshpass'] ) ?? $original['sshpass']; // ssh密码
  182 + $service->ports = trim( $request['ports'] ) ?? $original['ports']; // ssh端口
209 } 183 }
210 184
211 /** 185 /**
@@ -214,38 +188,50 @@ class ServerInformationLogic extends BaseLogic @@ -214,38 +188,50 @@ class ServerInformationLogic extends BaseLogic
214 * @throws AsideGlobalException 188 * @throws AsideGlobalException
215 * @throws BsideGlobalException 189 * @throws BsideGlobalException
216 */ 190 */
217 - public function get_batch_update($action = ServerInformationLog::ACTION_DELETE, $deleted = ServerInformation::DELETED_NORMAL) 191 + public function get_batch_update( $action = ServerInformationLog::ACTION_DELETE, $deleted = ServerInformation::DELETED_NORMAL )
218 { 192 {
219 - $id = request()->input('id');  
220 - if (!$id) {  
221 - return $this->fail('参数错误');  
222 - }  
223 - $ids = [];  
224 - if (!is_array($id)) {  
225 - $ids = explode(',', $id);  
226 - }  
227 - $ids = array_filter($ids, 'intval');  
228 - if (empty($ids)) {  
229 - return $this->fail('参数错误');  
230 - }  
231 - $data = ServerInformation::query()->whereIn('id', $ids)->where('deleted', $deleted)->get();  
232 - $restore_ids = $data->pluck('id')->toArray(); 193 + $ids = $this->getIds();
  194 + $data = ServerInformation::query()->whereIn( 'id', $ids )->where( 'deleted', $deleted )->get();
  195 + $restore_ids = $data->pluck( 'id' )->toArray();
233 $actionArr = ServerInformationLog::actionArr(); 196 $actionArr = ServerInformationLog::actionArr();
234 $actionStr = $actionArr[$action]; 197 $actionStr = $actionArr[$action];
235 - if (empty($restore_ids)) {  
236 - $this->fail($actionStr . '服务器信息不存在!', Code::USER_ERROR); 198 + if ( empty( $restore_ids ) ) {
  199 + $this->fail( $actionStr . '服务器信息不存在!', Code::USER_ERROR );
237 } 200 }
238 $original = $data->toArray(); 201 $original = $data->toArray();
239 DB::beginTransaction(); 202 DB::beginTransaction();
240 try { 203 try {
241 $update = $deleted == ServerInformation::DELETED_NORMAL ? ServerInformation::DELETED_DELETE : ServerInformation::DELETED_NORMAL; 204 $update = $deleted == ServerInformation::DELETED_NORMAL ? ServerInformation::DELETED_DELETE : ServerInformation::DELETED_NORMAL;
242 - ServerInformation::query()->whereIn('id', $restore_ids)->update(['deleted' => $update]);  
243 - $this->server_action_log($action, $original, $original, $actionStr . '服务器信息 - ID : ' . implode(', ', $restore_ids)); 205 + ServerInformation::query()->whereIn( 'id', $restore_ids )->update( [ 'deleted' => $update ] );
  206 + $this->server_action_log( $action, $original, $original, $actionStr . '服务器信息 - ID : ' . implode( ', ', $restore_ids ) );
244 DB::commit(); 207 DB::commit();
245 return $this->success(); 208 return $this->success();
246 - } catch (\Exception $e) { 209 + } catch ( \Exception $e ) {
247 DB::rollBack(); 210 DB::rollBack();
248 - return $this->fail('服务器信息' . $actionStr . '失败', Code::USER_ERROR); 211 + return $this->fail( '服务器信息' . $actionStr . '失败', Code::USER_ERROR );
  212 + }
  213 + }
  214 +
  215 + /**
  216 + * 批量获取数据恢复
  217 + * @return array
  218 + * @throws AsideGlobalException
  219 + * @throws BsideGlobalException
  220 + */
  221 + public function getIds()
  222 + {
  223 + $id = $this->param['id'] ?? 0;
  224 + if ( !$id ) {
  225 + return $this->fail( '参数错误' );
  226 + }
  227 + $ids = [];
  228 + if ( !is_array( $id ) ) {
  229 + $ids = explode( ',', $id );
  230 + }
  231 + $ids = array_filter( $ids, 'intval' );
  232 + if ( empty( $ids ) ) {
  233 + return $this->fail( '参数错误' );
249 } 234 }
  235 + return $ids;
250 } 236 }
251 } 237 }
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Aside\Domain;
  4 +
  5 +
  6 +use App\Enums\Common\Code;
  7 +use App\Exceptions\AsideGlobalException;
  8 +use App\Exceptions\BsideGlobalException;
  9 +use App\Http\Logic\Aside\BaseLogic;
  10 +use App\Http\Logic\Aside\Devops\ServerInformationLogic;
  11 +use App\Models\Aside\Domain\DomainInfo;
  12 +use App\Models\Aside\Domain\DomainInfoLog;
  13 +use App\Models\Devops\ServerInformation;
  14 +use Illuminate\Database\Eloquent\Builder;
  15 +use Illuminate\Database\Eloquent\Collection;
  16 +use Illuminate\Database\Eloquent\Model;
  17 +use Illuminate\Support\Facades\DB;
  18 +
  19 +class DomainInfoLogic extends BaseLogic
  20 +{
  21 + /**
  22 + * @var array
  23 + */
  24 + private $param;
  25 +
  26 + public function __construct()
  27 + {
  28 + parent::__construct();
  29 +
  30 + $this->model = new ServerInformation();
  31 +
  32 + $this->param = $this->requestAll;
  33 +
  34 + }
  35 +
  36 + /**
  37 + * 添加数据
  38 + * @return array
  39 + * @throws AsideGlobalException
  40 + * @throws BsideGlobalException
  41 + */
  42 + public function create()
  43 + {
  44 + $request = $this->param ?? [];
  45 + if ($this->checkDomain($request['domain'])) {
  46 + return $this->fail('域名已存在!');
  47 + }
  48 + $domain = new DomainInfo();
  49 + $this->extracted($request, $domain);
  50 + DB::beginTransaction();
  51 + if ($domain->save()) {
  52 + $original = $domain->getOriginal();
  53 + $original['belong_to'] = $request['belong_to'];
  54 + $original['status'] = $request['status'];
  55 + // 添加日志
  56 + $this->domain_action_log(DomainInfoLog::ACTION_ADD, $original, $original, '添加域名信息成功 - ID : ' . $domain->id);
  57 + DB::commit();
  58 + return $this->success();
  59 + }
  60 + DB::rollBack();
  61 + return $this->fail('域名信息添加失败');
  62 +
  63 + }
  64 +
  65 + /**
  66 + * 修改数据
  67 + * @return array
  68 + * @throws AsideGlobalException
  69 + * @throws BsideGlobalException
  70 + */
  71 + public function update()
  72 + {
  73 + $domain = $this->getDomain();
  74 + $original = $domain->getOriginal();
  75 + $original['belong_to'] = $domain->BelongToStr($original['belong_to']);
  76 + $original['status'] = $domain->StatusToStr($original['status']);
  77 + $request = $this->param;
  78 + $this->extracted($request, $domain, $original);
  79 + // 检查ip是否存在
  80 + if ($domain->domain != $request['domain']) {
  81 + if ($this->checkDomain($request['domain'])) {
  82 + $this->fail('域名信息修改失败,域名已存在', Code::USER_ERROR);
  83 + }
  84 + }
  85 + DB::beginTransaction();
  86 + if ($domain->save()) {
  87 + $fields_array = $domain->FieldsArray();
  88 + $revised = $domain->getAttributes();
  89 + $diff = array_diff_assoc($original, $revised);
  90 + unset($diff['created_at']);
  91 + unset($diff['updated_at']);
  92 + unset($diff['deleted']);
  93 + $remarks = '';
  94 + if ($diff) {
  95 + $remarks .= '修改ID为 ' . $domain->id . ' 的服务器信息,修改内容为:';
  96 + foreach ($diff as $key => $value) {
  97 + $remarks .= $fields_array[$key] . ' 由 ' . $value . ' 修改为 ' . $revised[$key] . '; ';
  98 + }
  99 + } else {
  100 + $remarks .= '修改ID为 ' . $domain->id . ' 的域名信息,无修改';
  101 + }
  102 + // 添加日志
  103 + $this->domain_action_log(DomainInfoLog::ACTION_UPDATE, $original, $revised, $remarks);
  104 + DB::commit();
  105 + return $this->success();
  106 + }
  107 + DB::rollBack();
  108 + return $this->fail('域名信息修改失败');
  109 + }
  110 +
  111 + /**
  112 + * 根据ID获取数据
  113 + * @return array
  114 + * @throws AsideGlobalException
  115 + * @throws BsideGlobalException
  116 + */
  117 + public function getDomain(int $deleted = DomainInfo::DELETED_NORMAL)
  118 + {
  119 + $id = $this->param['id'] ?? 0;
  120 + if (!$id) {
  121 + return $this->fail('ID不能为空');
  122 + }
  123 + $data = DomainInfo::query()->where('deleted', $deleted)->find($id);
  124 + if (!$data) {
  125 + return $this->fail('数据不存在!');
  126 + }
  127 + return $data;
  128 + }
  129 +
  130 + /**
  131 + * 检查域名是否存在
  132 + * @param $domain
  133 + * @return bool
  134 + */
  135 + public function checkDomain($domain)
  136 + {
  137 + $usIp = DomainInfo::query()->where('domain', $domain)->first();
  138 + if ($usIp) {
  139 + return true;
  140 + } else {
  141 + return false;
  142 + }
  143 + }
  144 +
  145 + /**
  146 + * 详情
  147 + * @param int $deleted
  148 + * @return array|Builder|Collection|Model
  149 + * @throws AsideGlobalException
  150 + * @throws BsideGlobalException
  151 + */
  152 + public function domainInfo(int $deleted = DomainInfo::DELETED_NORMAL)
  153 + {
  154 + $id = $this->param['id'] ?? 0;
  155 + if (!$id) {
  156 + return $this->fail('ID不能为空');
  157 + }
  158 + $data = DomainInfo::query()->where('deleted', $deleted)->find($id, ['domain', 'belong_to', 'status', 'domain_start_time', 'domain_end_time', 'certificate_start_time', 'certificate_end_time', 'created_at', 'updated_at']);
  159 + if (!$data) {
  160 + return $this->fail('数据不存在!');
  161 + }
  162 + return $data;
  163 + }
  164 +
  165 + /**
  166 + * 服务器操作日志
  167 + * @param int $action 1:添加 2:修改 3:删除 4:搜索 5:详情 6:列表
  168 + * @param array $original 原始数据
  169 + * @param array $revised 修改后数据
  170 + */
  171 + public function domain_action_log(int $action = DomainInfoLog::ACTION_ADD, array $original = [], array $revised = [], $remarks = '')
  172 + {
  173 + $log = new DomainInfoLog();
  174 + $this->log($log, $action, $original, $revised, $remarks);
  175 + }
  176 +
  177 + /**
  178 + * @param array $request
  179 + * @param $domain
  180 + * @param array $original
  181 + * @return void
  182 + * @throws AsideGlobalException
  183 + * @throws BsideGlobalException
  184 + */
  185 + public function extracted( array $request, $domain, array $original = [])
  186 + {
  187 + $domain->domain = trim($request['domain']) ?? $original['domain'];
  188 + if (!$this->validateDomain($domain->domain)) {
  189 + $this->fail('域名格式错误');
  190 + }
  191 + $domain->belong_to = trim($request['belong_to']) ?? $original['belong_to']; // 域名归属 1 - 公司 2 - 客户
  192 + $domain->status = trim($request['status']) ?? $original['status']; // 域名状态 0 - 正常 1 - 关闭
  193 + $domain->domain_start_time = trim($request['domain_start_time']) ?? $original['domain_start_time']; // 域名开始时间
  194 + $domain->domain_end_time = trim($request['domain_end_time']) ?? $original['domain_end_time'];
  195 + $domain->certificate_start_time = trim($request['certificate_start_time']) ?? $original['certificate_start_time']; // 证书开始时间
  196 + $domain->certificate_end_time = trim($request['certificate_end_time']) ?? $original['certificate_end_time']; // 证书结束时间
  197 + }
  198 +
  199 + /**
  200 + * 批量获取数据删除
  201 + * @return array
  202 + * @throws AsideGlobalException
  203 + * @throws BsideGlobalException
  204 + */
  205 + public function get_batch_update($action = DomainInfoLog::ACTION_DELETE, $deleted = DomainInfo::DELETED_NORMAL)
  206 + {
  207 + $ids = (new ServerInformationLogic())->getIds();
  208 + $data = DomainInfo::query()->whereIn('id', $ids)->where('deleted', $deleted)->get();
  209 + $restore_ids = $data->pluck('id')->toArray();
  210 + $actionArr = DomainInfoLog::actionArr();
  211 + $actionStr = $actionArr[$action];
  212 + if (empty($restore_ids)) {
  213 + $this->fail($actionStr . '域名信息不存在!', Code::USER_ERROR);
  214 + }
  215 + $original = $data->toArray();
  216 + DB::beginTransaction();
  217 + try {
  218 + $update = $deleted == DomainInfo::DELETED_NORMAL ? DomainInfo::DELETED_DELETE : DomainInfo::DELETED_NORMAL;
  219 + DomainInfo::query()->whereIn('id', $restore_ids)->update(['deleted' => $update]);
  220 + $this->domain_action_log($action, $original, $original, $actionStr . '域名信息 - ID : ' . implode(', ', $restore_ids));
  221 + DB::commit();
  222 + return $this->success();
  223 + } catch (\Exception $e) {
  224 + DB::rollBack();
  225 + return $this->fail('域名信息' . $actionStr . '失败', Code::USER_ERROR);
  226 + }
  227 + }
  228 +
  229 + /**
  230 + * 证书到期时间
  231 + * @return array
  232 + */
  233 + public function getDomainCertificateTime($domain)
  234 + {
  235 + $domain = trim($domain);
  236 + $data = [];
  237 + $context = stream_context_create(['ssl' => ['capture_peer_cert' => true]]); // Notice: only 7.0.7+ supports this
  238 + $stream = stream_socket_client("ssl://$domain:443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
  239 + if ($stream) {
  240 + $params = stream_context_get_params($stream);
  241 + $peerCertificate = openssl_x509_parse($params['options']['ssl']['peer_certificate']);
  242 + if ($peerCertificate) {
  243 + $validFrom = date_create_from_format('U', $peerCertificate['validFrom_time_t']); // 有效期开始时间
  244 + $validTo = date_create_from_format('U', $peerCertificate['validTo_time_t']); // 有效期结束时间
  245 + $data['validFrom'] = $validFrom->format('Y-m-d H:i:s');
  246 + $data['validTo'] = $validTo->format('Y-m-d H:i:s');
  247 + }
  248 + }
  249 + return $data;
  250 + }
  251 +
  252 + /**
  253 + * 获取所有正常域名信息
  254 + * @return Builder[]|Collection
  255 + */
  256 + public function getAllDomain()
  257 + {
  258 + return DomainInfo::query()->where('status', 1)
  259 + ->where('deleted', DomainInfo::DELETED_NORMAL)
  260 + ->orderBy('updated_at', 'desc')
  261 + ->get();
  262 + }
  263 +
  264 + /**
  265 + * 域名到期时间
  266 + * @return array
  267 + */
  268 + public function getDomainTime($domain)
  269 + {
  270 + $conJson = file_get_contents("http://openai.waimaoq.com/v1/whois_api?domain={$domain}");
  271 + $conArr = json_decode($conJson, true);
  272 + $data = [];
  273 + if ($conArr['code'] == 200) {
  274 + $con = $conArr['text'];
  275 + $data['domain'] = $domain;
  276 + $data['validFrom'] = $con['creation_date'];
  277 + $data['validTo'] = $con['expiration_date'];
  278 + }
  279 + return $data;
  280 + }
  281 +
  282 + /**
  283 + * 验证给定的值是否是有效的域名。
  284 + *
  285 + * @param mixed $value
  286 + * @return bool
  287 + */
  288 + public function validateDomain($value)
  289 + {
  290 + // 从域中删除任何空间或路径。
  291 + $domain = preg_replace('/\s|\/.*$/', '', $value);
  292 + // 验证域是否至少包含一个句点。
  293 + if (strpos($domain, '.') === false) {
  294 + return false;
  295 + }
  296 + // 验证域是否以句点开始或结束。
  297 + if (strpos($domain, '.') === 0 || strrpos($domain, '.') === strlen($domain) - 1) {
  298 + return false;
  299 + }
  300 + // 验证域是否不包含无效字符。
  301 + if (!preg_match('/^[a-zA-Z0-9\-\.]+$/', $domain)) {
  302 + return false;
  303 + }
  304 + // 验证域是否具有有效的顶级域。
  305 + $tld = substr($domain, strrpos($domain, '.') + 1);
  306 + if (!in_array($tld, ['com', 'net', 'org'])) { // 如有必要,添加更多TLD。
  307 + return false;
  308 + }
  309 + return true;
  310 + }
  311 +
  312 + /**
  313 + * 根据域名更新证书到期时间
  314 + * @param $id
  315 + * @param $updata
  316 + * @return array
  317 + * @throws AsideGlobalException
  318 + * @throws BsideGlobalException
  319 + */
  320 + public function updateDomain($id, $updata)
  321 + {
  322 + $isRes = DomainInfo::query()->where('id', $id)->where('deleted', DomainInfo::DELETED_NORMAL)->update($updata);
  323 + if ($isRes) {
  324 + return $this->success();
  325 + } else {
  326 + return $this->fail('更新域名到期时间失败');
  327 + }
  328 + }
  329 +}
@@ -8,7 +8,10 @@ use \App\Helper\Common as CommonHelper; @@ -8,7 +8,10 @@ use \App\Helper\Common as CommonHelper;
8 use App\Exceptions\AsideGlobalException; 8 use App\Exceptions\AsideGlobalException;
9 use App\Exceptions\BsideGlobalException; 9 use App\Exceptions\BsideGlobalException;
10 use App\Helper\Arr; 10 use App\Helper\Arr;
  11 +use App\Models\Devops\ServerInformationLog;
11 use Illuminate\Support\Facades\Cache; 12 use Illuminate\Support\Facades\Cache;
  13 +use Illuminate\Support\Facades\DB;
  14 +use Illuminate\Support\Facades\Log;
12 use Illuminate\Support\Facades\Schema; 15 use Illuminate\Support\Facades\Schema;
13 16
14 /** 17 /**
@@ -393,4 +396,40 @@ class Logic @@ -393,4 +396,40 @@ class Logic
393 public static function instance(...$params){ 396 public static function instance(...$params){
394 return new static(...$params); 397 return new static(...$params);
395 } 398 }
  399 +
  400 + /**
  401 + * 添加日志
  402 + * @param $log
  403 + * @param int $action 1:添加 2:修改 3:删除 4:搜索 5:详情 6:列表
  404 + * @param array $original 原始数据
  405 + * @param array $revised 修改后数据
  406 + * @param string $remarks 备注
  407 + * @return bool
  408 + */
  409 + public function log($log, int $action = ServerInformationLog::ACTION_ADD, array $original = [], array $revised = [], string $remarks = ''): bool
  410 + {
  411 + // $action 1:添加 2:修改 3:删除 4:恢复
  412 + $actionArr = $log->actionArr();
  413 + $actionStr = $actionArr[$action];
  414 + $ip = request()->getClientIp();
  415 + $url = request()->getRequestUri();
  416 + $method = request()->getMethod();
  417 + $userId = $this->uid ?? 0;
  418 + $log->user_id = $userId;
  419 + $log->action = $actionStr;
  420 + $log->original = json_encode($original);
  421 + $log->revised = json_encode($revised);
  422 + $log->ip = $ip;
  423 + $log->url = $url;
  424 + $log->method = $method;
  425 + $log->remarks = $remarks;
  426 + DB::beginTransaction();
  427 + if($log->save()){
  428 + DB::commit();
  429 + return true;
  430 + }
  431 + DB::rollBack();
  432 + Log::error('日志添加失败');
  433 + return false;
  434 + }
396 } 435 }
  1 +<?php
  2 +
  3 +namespace App\Http\Requests\Aside\Domain;
  4 +
  5 +use App\Models\Aside\Domain\DomainInfo;
  6 +use Illuminate\Foundation\Http\FormRequest;
  7 +use Illuminate\Validation\Rule;
  8 +
  9 +class DomainInfoRequest extends FormRequest
  10 +{
  11 + /**
  12 + * Determine if the user is authorized to make this request.
  13 + *
  14 + * @return bool
  15 + */
  16 + public function authorize()
  17 + {
  18 + return true;
  19 + }
  20 +
  21 + /**
  22 + * Get the validation rules that apply to the request.
  23 + *
  24 + * @return array
  25 + */
  26 + public function rules()
  27 + {
  28 + $domain = new DomainInfo();
  29 + $status_tot_keys = array_keys($domain->StatusToArray());
  30 + $belong_to_keys = array_keys($domain->BelongToArray());
  31 + return [
  32 + 'domain' => 'required|max:200',
  33 + 'belong_to' => [
  34 + 'required',
  35 + Rule::in($belong_to_keys)
  36 + ],
  37 + 'status' => [
  38 + 'required',
  39 + Rule::in($status_tot_keys)
  40 + ]
  41 + ];
  42 + }
  43 +
  44 + public function messages()
  45 + {
  46 + return [
  47 + 'domain.required' => '域名不能为空',
  48 + 'domain.max' => '域名长度不能超过200个字符',
  49 + 'belong_to.required' => '域名所属不能为空',
  50 + 'belong_to.in' => '域名所属参数错误',
  51 + 'status.required' => '域名状态不能为空',
  52 + 'status.in' => '域名状态参数错误',
  53 + ];
  54 + }
  55 +
  56 +}
  1 +<?php
  2 +
  3 +namespace App\Models\Aside\Domain;
  4 +
  5 +use App\Models\Base;
  6 +
  7 +/**
  8 + * Class DomainInfo
  9 + * @package App\Models\Aside\Domain
  10 + * @Author YiYuan-LIn
  11 + * @Date: 2019/5/16
  12 + * 域名信息模型
  13 + */
  14 +class DomainInfo extends Base
  15 +{
  16 + protected $table = 'gl_domain_info';
  17 +
  18 + // 软删除 0:正常 1:删除
  19 + /** @var int 软删除 - 正常 */
  20 + const DELETED_NORMAL = 0;
  21 + /** @var int 软删除 - 删除 */
  22 + const DELETED_DELETE = 1;
  23 +
  24 + protected $hidden = [
  25 + 'created_at',
  26 + 'updated_at'
  27 + ];
  28 +
  29 + /**
  30 + * 字段信息
  31 + * @return array
  32 + */
  33 + public function FieldsArray()
  34 + {
  35 + return [
  36 + 'domain' => '域名',
  37 + 'belong_to' => '域名归属',
  38 + 'status' => '域名状态',
  39 + 'domain_start_time' => '域名开始时间',
  40 + 'domain_end_time' => '域名结束时间',
  41 + 'certificate_start_time' => '证书开始时间',
  42 + 'certificate_end_time' => '证书结束时间',
  43 + ];
  44 + }
  45 +
  46 + /**
  47 + * 域名归属信息
  48 + * @return array
  49 + */
  50 + public function BelongToArray()
  51 + {
  52 + return [
  53 + 1 => '公司',
  54 + 2 => '客户',
  55 + ];
  56 + }
  57 +
  58 + public function BelongToStr($num)
  59 + {
  60 + return array_flip($this->BelongToArray())[$num];
  61 + }
  62 +
  63 + public function BelongTo($num)
  64 + {
  65 + return $this->BelongToArray()[$num];
  66 + }
  67 +
  68 + /**
  69 + * 域名状态信息
  70 + * @return array
  71 + */
  72 + public function StatusToArray()
  73 + {
  74 + return [
  75 + 0 => '未使用',
  76 + 1 => '使用中',
  77 + ];
  78 + }
  79 +
  80 + public function StatusToStr($num)
  81 + {
  82 + return array_flip($this->StatusToArray())[$num];
  83 + }
  84 +
  85 + /**
  86 + * 返回域名状态
  87 + * @param $num
  88 + *
  89 + * @return string
  90 + */
  91 + public function StatusTo($num)
  92 + {
  93 + return $this->StatusToArray()[$num];
  94 + }
  95 +
  96 + /**
  97 + * 返回服务器归属
  98 + * @param $value
  99 + *
  100 + * @return string
  101 + */
  102 + public function getBelongToAttribute($value)
  103 + {
  104 + return $this->BelongTo($value);
  105 + }
  106 +
  107 + /**
  108 + * 返回服务器状态
  109 + * @param $value
  110 + *
  111 + * @return string
  112 + */
  113 + public function getStatusAttribute($value)
  114 + {
  115 + return $this->StatusTo($value);
  116 + }
  117 +}
  1 +<?php
  2 +
  3 +namespace App\Models\Aside\Domain;
  4 +
  5 +use Illuminate\Database\Eloquent\Model;
  6 +
  7 +class DomainInfoLog extends Model
  8 +{
  9 + protected $table = 'gl_domain_info_log';
  10 +
  11 + public function getOriginalAttribute($value)
  12 + {
  13 + return json_decode($value, true);
  14 + }
  15 +
  16 + public function getRevisedAttribute($value)
  17 + {
  18 + return json_decode($value, true);
  19 + }
  20 +
  21 + /** @var int 日志添加 */
  22 + const ACTION_ADD = 1;
  23 + /** @var int 日志修改 */
  24 + const ACTION_UPDATE = 2;
  25 + /** @var int 日志删除 */
  26 + const ACTION_DELETE = 3;
  27 + /** @var int 日志恢复 */
  28 + const ACTION_RECOVER = 4;
  29 +
  30 +
  31 + /**
  32 + * @return string[]
  33 + */
  34 + public static function actionArr()
  35 + {
  36 + return [
  37 + 1 => '添加',
  38 + 2 => '修改',
  39 + 3 => '删除',
  40 + 4 => '恢复',
  41 + ];
  42 + }
  43 +}
@@ -8,8 +8,6 @@ class ServerInformation extends Model @@ -8,8 +8,6 @@ class ServerInformation extends Model
8 { 8 {
9 9
10 protected $table = 'gl_server_information'; 10 protected $table = 'gl_server_information';
11 - const CREATED_AT = 'create_at';  
12 - const UPDATED_AT = 'update_at';  
13 11
14 // 软删除 0:正常 1:删除 12 // 软删除 0:正常 1:删除
15 const DELETED_NORMAL = 0; 13 const DELETED_NORMAL = 0;
@@ -44,6 +42,11 @@ class ServerInformation extends Model @@ -44,6 +42,11 @@ class ServerInformation extends Model
44 ]; 42 ];
45 } 43 }
46 44
  45 + public function ServiceStr($num)
  46 + {
  47 + return array_flip($this->ServiceArray())[$num];
  48 + }
  49 +
47 /** 50 /**
48 * 字段信息 51 * 字段信息
49 * @return array 52 * @return array
@@ -73,6 +76,11 @@ class ServerInformation extends Model @@ -73,6 +76,11 @@ class ServerInformation extends Model
73 ]; 76 ];
74 } 77 }
75 78
  79 + public function BelongToStr($num)
  80 + {
  81 + return array_flip($this->BelongToArray())[$num];
  82 + }
  83 +
76 public function BelongTo($num) 84 public function BelongTo($num)
77 { 85 {
78 return $this->BelongToArray()[$num]; 86 return $this->BelongToArray()[$num];
@@ -7,8 +7,6 @@ use Illuminate\Database\Eloquent\Model; @@ -7,8 +7,6 @@ use Illuminate\Database\Eloquent\Model;
7 class ServerInformationLog extends Model 7 class ServerInformationLog extends Model
8 { 8 {
9 protected $table = 'gl_server_information_log'; 9 protected $table = 'gl_server_information_log';
10 - const CREATED_AT = 'create_at';  
11 - const UPDATED_AT = 'update_at';  
12 10
13 public function getOriginalAttribute($value) 11 public function getOriginalAttribute($value)
14 { 12 {
@@ -116,6 +116,19 @@ Route::middleware(['web'])->group(function (){ //admin用渲染默认要加上w @@ -116,6 +116,19 @@ Route::middleware(['web'])->group(function (){ //admin用渲染默认要加上w
116 Route::post('/save_follow', [Aside\Task\TaskController::class, 'save_follow'])->name('admin.task_save_follow'); 116 Route::post('/save_follow', [Aside\Task\TaskController::class, 'save_follow'])->name('admin.task_save_follow');
117 }); 117 });
118 118
  119 + // 域名
  120 + Route::prefix('domain')->group(function () {
  121 + Route::get('/', [Aside\Domain\DomainInfoController::class, 'lists'])->name('admin.domain'); // 列表 | 搜索
  122 + Route::get('/info', [Aside\Domain\DomainInfoController::class, 'info'])->name('admin.domain_info'); // 详情
  123 + Route::get('/delete_info', [Aside\Domain\DomainInfoController::class, 'getDeleteDomainInfo'])->name('admin.domain_delete_info'); // 删除信息
  124 + Route::post('/add', [Aside\Domain\DomainInfoController::class, 'add'])->name('admin.domain_save'); // 添加
  125 + Route::post('/edit', [Aside\Domain\DomainInfoController::class, 'edit'])->name('admin.domain_edit'); // 编辑
  126 + Route::any('/delete', [Aside\Domain\DomainInfoController::class, 'delete'])->name('admin.domain_delete'); // 删除
  127 + Route::get('/delete_list', [Aside\Domain\DomainInfoController::class, 'delete_list'])->name('admin.domain_delete_list'); // 删除列表
  128 + Route::any('/restore', [Aside\Domain\DomainInfoController::class, 'restore'])->name('admin.domain_restore'); // 恢复
  129 + Route::get('/log', [Aside\Domain\DomainInfoLogController::class, 'lists'])->name('admin.domain_log_lists'); // 日志
  130 + });
  131 +
119 //运维 132 //运维
120 Route::prefix('devops')->group(function () { 133 Route::prefix('devops')->group(function () {
121 //服务器配置 134 //服务器配置
@@ -127,7 +140,7 @@ Route::middleware(['web'])->group(function (){ //admin用渲染默认要加上w @@ -127,7 +140,7 @@ Route::middleware(['web'])->group(function (){ //admin用渲染默认要加上w
127 140
128 // 服务器添加|修改|删除 141 // 服务器添加|修改|删除
129 Route::prefix('server')->group(function () { 142 Route::prefix('server')->group(function () {
130 - Route::get('/', [Aside\Devops\ServerInformationController::class, 'lists'])->name('admin.devops.bt'); // 列表 143 + Route::get('/', [Aside\Devops\ServerInformationController::class, 'lists'])->name('admin.devops.bt'); // 列表 | 搜索
131 Route::get('/info', [Aside\Devops\ServerInformationController::class, 'getServerInfo'])->name('admin.devops.bt_info'); // 获取信息 144 Route::get('/info', [Aside\Devops\ServerInformationController::class, 'getServerInfo'])->name('admin.devops.bt_info'); // 获取信息
132 Route::get('/delete_info', [Aside\Devops\ServerInformationController::class, 'getDeleteServerInfo'])->name('admin.devops.bt_delete_info'); // 删除信息 145 Route::get('/delete_info', [Aside\Devops\ServerInformationController::class, 'getDeleteServerInfo'])->name('admin.devops.bt_delete_info'); // 删除信息
133 Route::post('/add', [Aside\Devops\ServerInformationController::class, 'add'])->name('admin.devops.bt_add'); // 添加 146 Route::post('/add', [Aside\Devops\ServerInformationController::class, 'add'])->name('admin.devops.bt_add'); // 添加
@@ -135,10 +148,8 @@ Route::middleware(['web'])->group(function (){ //admin用渲染默认要加上w @@ -135,10 +148,8 @@ Route::middleware(['web'])->group(function (){ //admin用渲染默认要加上w
135 Route::get('/delete', [Aside\Devops\ServerInformationController::class, 'delete'])->name('admin.devops.bt_delete'); // 删除 148 Route::get('/delete', [Aside\Devops\ServerInformationController::class, 'delete'])->name('admin.devops.bt_delete'); // 删除
136 Route::get('/delete_list', [Aside\Devops\ServerInformationController::class, 'delete_list'])->name('admin.devops.bt_delete_list'); // 删除列表 149 Route::get('/delete_list', [Aside\Devops\ServerInformationController::class, 'delete_list'])->name('admin.devops.bt_delete_list'); // 删除列表
137 Route::get('/restore', [Aside\Devops\ServerInformationController::class, 'restore'])->name('admin.devops.bt_restore'); //恢复数据 150 Route::get('/restore', [Aside\Devops\ServerInformationController::class, 'restore'])->name('admin.devops.bt_restore'); //恢复数据
138 - Route::get('/search', [Aside\Devops\ServerInformationController::class, 'search'])->name('admin.devops.bt_search'); //搜索  
139 Route::get('/log', [Aside\Devops\ServerInformationLogController::class, 'lists'])->name('admin.devops.bt_log_lists'); //日志列表 151 Route::get('/log', [Aside\Devops\ServerInformationLogController::class, 'lists'])->name('admin.devops.bt_log_lists'); //日志列表
140 }); 152 });
141 -  
142 }); 153 });
143 154
144 // 自定义页面 模板,头部底部 155 // 自定义页面 模板,头部底部