作者 赵彬吉

Merge branch 'develop' of http://47.244.231.31:8099/zhl/globalso-v6 into develop

<?php
namespace App\Console\Commands\Domain;
use App\Exceptions\AsideGlobalException;
use App\Exceptions\BsideGlobalException;
use App\Helper\AyrShare as AyrShareHelper;
use App\Http\Logic\Aside\Domain\DomainInfoLogic;
use App\Models\AyrShare\AyrRelease as AyrReleaseModel;
use Carbon\Carbon;
use App\Models\AyrShare\AyrShare as AyrShareModel;
use Illuminate\Console\Command;
class DomainTime extends Command
{
public $error = 0;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'domain_time';
/**
* The console command description.
*
* @var string
*/
protected $description = '域名定时任务 更新域名|证书到期时间';
/**
* @name :(定时执行)handle
* @author :lyh
* @method :post
* @time :2023/5/12 14:48
*/
public function handle()
{
echo $this->update_domain_time();
}
/**
* 更新域名|证书到期时间
* @return int|mixed|void
* @throws AsideGlobalException
* @throws BsideGlobalException
*/
protected function update_domain_time()
{
$domainCon = new DomainInfoLogic();
$all = $domainCon->getAllDomain();
$all = $all->toArray();
if ( empty( $all ) ) {
$this->info( '未获取到数据' );
return;
}
foreach ( $all as $item ) {
$domain = $item['domain'];
// 域名到期时间
$domainT = $domainCon->getDomainTime( $domain );
if ( $domainT ) {
$domain_time = $item['domain_end_time'];
$domainValidFrom = $domainT['validFrom'];
$domainValidTo = $domainT['validTo'];
if ( strtotime( $domain_time ) < strtotime( $domainValidTo ) ) {
$this->info( $domain . '域名到期时间更新成功' );
$domainCon->updateDomain( $item['id'], [ 'domain_end_time' => $domainValidTo ] );
}
} else {
$this->error++;
$this->info( $domain . '域名到期时间获取失败' );
}
// 证书到期时间
$certificateT = $domainCon->getDomainCertificateTime( $domain );
if ( $certificateT ) {
$certificate_time = $item['certificate_end_time'];
$certificateValidFrom = $certificateT['validFrom'];
$certificateValidTo = $certificateT['validTo'];
if ( strtotime( $certificate_time ) < strtotime( $certificateValidTo ) ) {
$this->info( $domain . '证书到期时间更新成功' );
$domainCon->updateDomain( $item['id'], [ 'certificate_end_time' => $certificateValidTo ] );
}
} else {
$this->error++;
$this->info( $domain . '证书到期时间获取失败' );
}
}
return $this->error;
}
}
... ...
... ... @@ -2,13 +2,17 @@
namespace App\Console\Commands\YesterdayCount;
use App\Helper\Common;
use App\Helper\FormGlobalsoApi;
use App\Models\CustomerVisit\CustomerVisitItem;
use App\Models\Project\DeployBuild;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class Yesterday extends Command
{
const STATUS_ERROR = 400;
public $error = 0;
/**
* The name and signature of the console command.
... ... @@ -24,7 +28,7 @@ class Yesterday extends Command
*/
protected $description = '统计昨日数据';
/**
* @name :(定时执行)handle
* @name :(定时执行生成昨日数据统计)handle
* @author :lyh
* @method :post
* @time :2023/5/12 14:48
... ... @@ -34,16 +38,31 @@ class Yesterday extends Command
$deployModel = new DeployBuild();
$list = $deployModel->list();
$data = [];
$yesterday = Carbon::yesterday()->toDateString();
foreach ($list as $v){
$arr = [];
$yesterday = now()->subDay();
$arr['yesterday_pv_num'] = DB::table('gl_customer_visit_item')->whereDate('created_at', $yesterday)->where('domain',$v['test_domain'])->count();
$arr['yesterday_ip_num'] = DB::table('gl_customer_visit')->whereDate('created_at', $yesterday)->where('domain',$v['test_domain'])->count();
$arr['inquiry_num'] = DB::table('gl_inquiry_set')->whereDate('created_at', $yesterday)->where('project_id',$v['project_id'])->count();
$arr['date'] = date('Y-m-d',time());
$arr['yesterday_pv_num'] = DB::table('gl_customer_visit_item')->whereDate('date', $yesterday)->where('domain',$v['test_domain'])->count();
$arr['yesterday_ip_num'] = DB::table('gl_customer_visit')->whereDate('date', $yesterday)->where('domain',$v['test_domain'])->count();
$inquiry_list = (new FormGlobalsoApi())->getInquiryList($v['test_domain']);
if($inquiry_list['status'] == self::STATUS_ERROR){
$arr['inquiry_num'] = 0;
}else{
$arr['inquiry_num'] = count($inquiry_list['data']['total']);
}
$arr['date'] = $yesterday;
$rank_info = DB::table('gl_rank_data')->where(['updated_date'=>$yesterday,'lang'=>''])->select(['compliance_day'])->first();
if(empty($rank_info)){
$arr['compliance_day'] = 0;
}else{
$arr['compliance_day'] = $rank_info->compliance_day;
}
$arr['service_day'] = $v['service_duration'] - Common::getDaysToTargetDate($v['created_at']);
$arr['project_id'] = $v['project_id'];
$arr['created_at'] = date('Y-m-d H:i:s');
$arr['updated_at'] = date('Y-m-d H:i:s');
$data[] = $arr;
}
DB::table('gl_yesterday_count')->insert($data);
DB::table('gl_count')->insert($data);
echo $this->error;
}
}
... ...
... ... @@ -27,6 +27,7 @@ class Kernel extends ConsoleKernel
$schedule->command('web_traffic 1')->everyThirtyMinutes(); // 引流 1-3个月的项目,半小时一次
$schedule->command('web_traffic 2')->cron('*/18 * * * *'); // 引流 4-8个月的项目,18分钟一次
$schedule->command('web_traffic 3')->cron('*/12 * * * *'); // 引流 大于9个月的项目,12分钟一次
// $schedule->command('domain_time')->dailyAt('01:00')->withoutOverlapping(1); // 更新域名|证书结束时间,每天凌晨1点执行一次
}
/**
... ...
... ... @@ -133,4 +133,19 @@ class Common
$arr = array_map('unserialize', $arr);
return $arr;
}
/**
* @param $targetDateTime
* @name :(获取时间差,精确时分秒,返回天数)getDaysToTargetDate
* @author :lyh
* @method :post
* @time :2023/5/24 9:38
*/
public static function getDaysToTargetDate($targetDateTime)
{
$currentTimestamp = time();
$targetTimestamp = strtotime($targetDateTime);
$days = floor(($currentTimestamp - $targetTimestamp) / (60 * 60 * 24));
return (int)$days;
}
}
... ...
... ... @@ -223,3 +223,24 @@ if (!function_exists('getThisWeekStarDate')) {
return Carbon::now()->startOfWeek()->toDateString();
}
}
if (!function_exists('object_to_array')) {
/**
* 获取本周一的日期
* @return mixed
* @author zbj
* @date 2023/5/11
*/
function object_to_array($data)
{
if(is_object($data)){
$data = (array)$data;
}else{
foreach ($data as $k => $v){
$data[$k] = object_to_array($v);
}
}
return $data;
}
}
... ...
... ... @@ -22,9 +22,25 @@ class ServerInformationController extends BaseController
*/
public function lists($deleted = ServerInformation::DELETED_NORMAL)
{
$request = $this->param;
$search = [];
$search_array = [
'ip' => 'ip',
'title' => 'title'
];
foreach ($search_array as $key => $item) {
if (isset($request[$key]) && $request[$key]) {
$search[$item] = $request[$key];
}
}
$size = request()->input('size', $this->row);
$data = ServerInformation::query()->select(['id', 'title', 'ip'])
->where('deleted', $deleted)
$query = ServerInformation::query()->select(['id', 'title', 'ip']);
if ($search) {
foreach ($search as $key => $item) {
$query = $query->Where("{$key}", 'like', "%{$item}%");
}
}
$data = $query->where('deleted', $deleted)
->orderBy('id', 'desc')
->paginate($size);
return $this->response('success', Code::SUCCESS, $data);
... ... @@ -58,9 +74,10 @@ class ServerInformationController extends BaseController
public function edit(ServerInformationRequest $serverInformationRequest, ServerInformationLogic $serverInformationLogic)
{
$serverInformationRequest->validate([
'id' => ['required'],
'id' => 'required|integer',
], [
'id.required' => 'ID不能为空',
'id.integer' => 'ID必须为整数',
]);
$serverInformationLogic->update();
$this->response('服务器修改成功!');
... ... @@ -150,6 +167,7 @@ class ServerInformationController extends BaseController
}
/**
* 获取软删除的服务器信息
* @return JsonResponse
* @throws AsideGlobalException
* @throws BsideGlobalException
... ...
<?php
namespace App\Http\Controllers\Aside\Domain;
use App\Enums\Common\Code;
use App\Exceptions\AsideGlobalException;
use App\Exceptions\BsideGlobalException;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\Domain\DomainInfoLogic;
use App\Http\Requests\Aside\Domain\DomainInfoRequest;
use App\Models\Aside\Domain\DomainInfo;
use App\Models\Aside\Domain\DomainInfoLog;
use Illuminate\Http\JsonResponse;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/**
* Class DomainInfoController
* @package App\Http\Controllers\Aside 域名管理
*/
class DomainInfoController extends BaseController
{
/**
* 域名列表
* @param int $deleted
* @return JsonResponse
*/
public function lists(int $deleted = DomainInfo::DELETED_NORMAL)
{
$request = $this->param;
$search = [];
$search_array = [
'domain' => 'domain',
'belong' => 'belong_to',
'domain_time' => 'domain_end_time',
'certificate_time' => 'certificate_end_time'
];
foreach ($search_array as $key => $item) {
if (isset($request[$key]) && $request[$key]) {
$search[$item] = $request[$key];
}
}
// 每页条数
$size = request()->input('size', $this->row);
$query = DomainInfo::query()->select(['id', 'domain', 'belong_to']);
if ($search) {
foreach ($search as $key => $item) {
$query = $query->Where("{$key}", 'like', "%{$item}%");
}
}
$data = $query->where('deleted', $deleted)
->orderBy('id', 'desc')
->paginate($size);
return $this->response('success', Code::SUCCESS, $data);
}
/**
* 获取软删除的数据
* @return JsonResponse
*/
public function delete_list()
{
return $this->lists(DomainInfo::DELETED_DELETE);
}
/**
* 添加域名
* @param DomainInfoRequest $domainInfoRequest
* @param DomainInfoLogic $domainInfoLogic
* @return void
* @throws AsideGlobalException
* @throws BsideGlobalException
*/
public function add(DomainInfoRequest $domainInfoRequest, DomainInfoLogic $domainInfoLogic)
{
$domainInfoRequest->validated();
$domainInfoLogic->create();
$this->response('域名添加成功!');
}
/**
* 编辑域名
* @param DomainInfoRequest $domainInfoRequest
* @param DomainInfoLogic $domainInfoLogic
* @return void
* @throws AsideGlobalException
* @throws BsideGlobalException
*/
public function edit(DomainInfoRequest $domainInfoRequest, DomainInfoLogic $domainInfoLogic)
{
$domainInfoRequest->validate([
'id' => 'required|integer'
], [
'id.required' => 'id不能为空',
'id.integer' => 'id参数错误'
]);
$domainInfoLogic->update();
$this->response('域名修改成功!');
}
/**
* 删除
* @param DomainInfoLogic $domainInfoLogic
* @return void
* @throws AsideGlobalException
* @throws BsideGlobalException
*/
public function delete(DomainInfoLogic $domainInfoLogic)
{
$domainInfoLogic->get_batch_update();
$this->response('域名删除成功!');
}
/**
* 恢复数据
* @param DomainInfoLogic $domainInfoLogic
* @return void
* @throws AsideGlobalException
* @throws BsideGlobalException
*/
public function restore(DomainInfoLogic $domainInfoLogic)
{
$domainInfoLogic->get_batch_update(DomainInfoLog::ACTION_RECOVER, DomainInfo::DELETED_DELETE);
$this->response('域名恢复成功!');
}
/**
* 域名信息
* @param int $deleted
* @return JsonResponse
* @throws AsideGlobalException
* @throws BsideGlobalException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function info(int $deleted = DomainInfo::DELETED_NORMAL)
{
$domainInfoLogic = new DomainInfoLogic();
$data = $domainInfoLogic->domainInfo($deleted);
if (!$data) {
return $this->response('域名信息不存在', Code::USER_ERROR);
}
return $this->success($data->toArray());
}
/**
* 获取软删除域名信息
* @return JsonResponse
* @throws AsideGlobalException
* @throws BsideGlobalException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getDeleteDomainInfo()
{
return $this->info(DomainInfo::DELETED_DELETE);
}
}
... ...
<?php
namespace App\Http\Controllers\Aside\Domain;
use App\Enums\Common\Code;
use App\Http\Controllers\Aside\BaseController;
use App\Models\Aside\Domain\DomainInfoLog;
use Illuminate\Http\Request;
class DomainInfoLogController extends BaseController
{
public function lists(Request $request)
{
$size = $request->input('size', $this->row);
$data = DomainInfoLog::query()
->orderBy('id', 'desc')
->paginate($size);
return $this->response('success', Code::SUCCESS, $data);
}
}
... ...
... ... @@ -210,5 +210,4 @@ class BaseController extends Controller
}
}
... ...
... ... @@ -3,24 +3,83 @@
namespace App\Http\Controllers\Bside\HomeCount;
use App\Enums\Common\Code;
use App\Helper\Common;
use App\Helper\FormGlobalsoApi;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\HomeCount\CountLogic;
use App\Models\Project\DeployBuild;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
class CountController extends BaseController
{
const STATUS_ERROR = 400;
/**
* @name :(昨日统计数据)yesterday_count
* @author :lyh
* @method :post
* @time :2023/5/23 17:23
*/
public function count(){
public function count(CountLogic $countLogic){
$data = [];
//TODO::昨日数据统计
$data['yesterday'] = $countLogic->yesterday_count();
//TODO::全球搜方案信息
$data['scheme_info'] = $countLogic->scheme_info();
//TODO::网站访问量统计
$data['total_visit'] = $countLogic->total_count(isset($data['yesterday']['inquiry_num']) ? $data['yesterday']['inquiry_num'] : '');
//TODO::关键字排名数据
//TODO::关键字排名数据
$data['keyword_data'] = $countLogic->keyword_data_count();
//TODO::相关数据统计
$data['with_data'] = $countLogic->with_data_count();
//TODO::30天pv,ip统计
$data['visit_data'] = $countLogic->visit_data_count();
//TODO::询盘国家统计
$data['country_data'] = $countLogic->inquiry_country_count();
//TODO::来源排名
$data['referrer_count'] = $countLogic->referrer_count();
//TODO::访问国家前10
$data['access_country_count'] = $countLogic->access_country_count();
//TODO::企业中心服务
$data['enterprise_service'] = $countLogic->enterprise_service();
return $this->response('success',Code::SUCCESS,$data);
}
/***
* @name :(手动获取昨日数据统计)yesterday
* @author :lyh
* @method :post
* @time :2023/5/24 9:13
*/
public function yesterday(){
$deployModel = new DeployBuild();
$list = $deployModel->list();
$data = [];
$yesterday = Carbon::yesterday()->toDateString();
foreach ($list as $v){
$arr = [];
$arr['yesterday_pv_num'] = DB::table('gl_customer_visit_item')->whereDate('date', $yesterday)->where('domain',$v['test_domain'])->count();
$arr['yesterday_ip_num'] = DB::table('gl_customer_visit')->whereDate('date', $yesterday)->where('domain',$v['test_domain'])->count();
$inquiry_list = (new FormGlobalsoApi())->getInquiryList($v['test_domain']);
if($inquiry_list['status'] == self::STATUS_ERROR){
$arr['inquiry_num'] = 0;
}else{
$arr['inquiry_num'] = count($inquiry_list['data']['total']);
}
$arr['date'] = $yesterday;
$rank_info = DB::table('gl_rank_data')->where(['updated_date'=>$yesterday,'lang'=>''])->select(['compliance_day'])->first();
if(empty($rank_info)){
$arr['compliance_day'] = 0;
}else{
$arr['compliance_day'] = $rank_info->compliance_day;
}
$arr['service_day'] = $v['service_duration'] - Common::getDaysToTargetDate($v['created_at']);
$arr['project_id'] = $v['project_id'];
$arr['created_at'] = date('Y-m-d H:i:s');
$arr['updated_at'] = date('Y-m-d H:i:s');
$data[] = $arr;
}
DB::table('gl_count')->insert($data);
$this->response('success');
}
}
... ...
... ... @@ -120,92 +120,16 @@ class TemplateController extends BaseController
$source = $this->param['source']??'';
$source_id = $this->param['source_id']??0;
$data = TemplateLogic::instance()->first($source,$source_id);
$def = '<div class=" d-flex align-items-center justify-content-between py-md-4">
<div class="logo w-25 w-sm-auto"><a href="#"><img class="img-fluid" src="img/logo.png" alt=""></a></div>
<nav class="navbar navbar-expand-md navbar-dark flex-fill justify-content-end mx-2 pe-md-5">
<button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#navMenu"
aria-controls="navMenu">
<span class="navbar-toggler-icon"></span>
</button>
<ul class="nav column-gap-5 justify-content-end text-white d-none d-md-flex">
<li><a href="#">Home</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-bs-toggle="dropdown">Products</a>
<ul class="dropdown-menu fs-6 text-body shadow-sm border-0">
<li><a href="#" class="dropdown-item py-2">Product Information</a></li>
<li><a href="#" class="dropdown-item py-2">Change of Insurance</a></li>
<li><a href="#" class="dropdown-item py-2">Traveling Oxygen Program</a></li>
<li><a href="#" class="dropdown-item py-2">Contact</a></li>
</ul>
</li>
<li><a href="#">News</a></li>
<li><a href="#">Download</a></li>
<li><a href="#">FAQ</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
<div class="d-flex align-items-center justify-content-end">
<div class="search">
<button type="button" class="btn border-0" data-bs-toggle="dropdown">
<svg viewBox="0 0 24 24" width="18" height="18" stroke="#ffffff" stroke-width="2"
fill="none" stroke-linecap="round" stroke-linejoin="round" class="css-i6dzq1">
<circle cx="11" cy="11" r="8"></circle>
<line x1="21" y1="21" x2="16.65" y2="16.65"></line>
</svg>
</button>
<div class="dropdown-menu p-3 shadow-sm border-0">
<form action="">
<div class="d-flex mb-2">
<input type="text" class="form-control" name="search" placeholder="Start Typing...">
<button class="btn btn-search border-0" type="submit">
<svg viewBox="0 0 24 24" width="18" height="18" stroke="#333333"
stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"
class="css-i6dzq1">
<circle cx="11" cy="11" r="8"></circle>
<line x1="21" y1="21" x2="16.65" y2="16.65"></line>
</svg>
</button>
</div>
<p class="search-attr">Hit enter to search or ESC to close</p>
</form>
</div>
</div>
<div class="change-language ms-md-4">
<div role="button" class="dropdown-toggle text-white d-flex align-items-center"
data-bs-toggle="dropdown">
<b class="country-flag language-flag-en"></b> <span>English</span>
</div>
<div class="dropdown-menu shadow-sm border-0">
<div class="d-flex flex-wrap p-3 text-body">
<a href="#" class="col-4 mb-3 pe-2 d-flex align-items-center" title="English">
<b class="country-flag language-flag-en"></b>
<span>English</span>
</a>
<a href="#" class="col-4 mb-3 pe-2 d-flex align-items-center" title="Françai">
<b class="country-flag language-flag-fr"></b>
<span>Françai</span>
</a>
<a href="#" class="col-4 mb-3 pe-2 d-flex align-items-center" title="Español">
<b class="country-flag language-flag-es"></b>
<span>Español</span>
</a>
<a href="#" class="col-4 mb-3 pe-2 d-flex align-items-center" title="Deutsch">
<b class="country-flag language-flag-de"></b>
<span>Deutsch</span>
</a>
<a href="#" class="col-4 mb-3 pe-2 d-flex align-items-center" title="Română">
<b class="country-flag language-flag-ro"></b>
<span>Română</span>
</a>
</div>
</div>
</div>
</div>
</div>';
return $this->response('',Code::SUCCESS,$data?$data['html']:$def);
$res = [
'html' => $data['html']??'',
'name' => 'example'
];
return $this->response('',Code::SUCCESS,$res);
}
... ...
... ... @@ -12,9 +12,7 @@ use App\Models\Devops\ServerInformationLog;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class ServerInformationLogic extends BaseLogic
{
... ... @@ -41,31 +39,25 @@ class ServerInformationLogic extends BaseLogic
*/
public function create()
{
$request = $this->param;
$request = $this->param ?? [];
$service = new ServerInformation();
$this->extracted($request, $service);
if ($this->checkIp($service->ip)) {
return $this->fail('服务器信息添加失败,ip已存在');
$this->extracted( $request, $service );
if ( $this->checkIp( $service->ip ) ) {
return $this->fail( '服务器信息添加失败,ip已存在' );
}
DB::beginTransaction();
if ($service->save()) {
$original = [
'id' => $service->id,
'type' => $service->type,
'ip' => $service->ip,
'title' => $service->title,
'belong_to' => $service->belong_to,
'sshpass' => $service->sshpass,
'ports' => $service->ports,
];
if ( $service->save() ) {
$original = $service->getOriginal();
$original['type'] = $request['type'];
$original['belong_to'] = $request['belong_to'];
// 添加日志
$this->server_action_log(ServerInformationLog::ACTION_ADD, $original, $original, '添加服务器信息成功 - ID : ' . $service->id);
$this->server_action_log( ServerInformationLog::ACTION_ADD, $original, $original, '添加服务器信息成功 - ID : ' . $service->id );
DB::commit();
return $this->success();
}
DB::rollBack();
return $this->fail('服务器信息添加失败');
return $this->fail( '服务器信息添加失败' );
}
... ... @@ -77,51 +69,55 @@ class ServerInformationLogic extends BaseLogic
*/
public function update()
{
$service = new ServerInformation();
$service = $this->getService();
$fields_array = $service->FieldsArray();
$request = $this->param;
$service = $this->ServerInfo();
$original = $service->toArray();
$this->extracted($request, $service);
$request = $this->param ?? [];
$original = $service->getOriginal();
$original['type'] = $service->ServiceStr( $original['type'] );
$original['belong_to'] = $service->BelongToStr( $original['belong_to'] );
$this->extracted( $request, $service, $original );
// 检查ip是否存在
if ($service->ip != $request['ip']) {
if ($this->checkIp($request['ip'])) {
$this->fail('服务器信息修改失败,ip已存在', Code::USER_ERROR);
if ( $service->ip != $request['ip'] ) {
if ( $this->checkIp( $request['ip'] ) ) {
$this->fail( '服务器信息修改失败,ip已存在', Code::USER_ERROR );
}
}
DB::beginTransaction();
if ($service->save()) {
$revised = [
'id' => $service->id,
'type' => $service->type,
'ip' => $service->ip,
'title' => $service->title,
'belong_to' => $service->belong_to,
'sshpass' => $service->sshpass,
'ports' => $service->ports,
'other' => $service->other,
'delete' => $service->delete,
];
$diff = array_diff_assoc($original, $revised);
unset($diff['create_at']);
unset($diff['update_at']);
unset($diff['deleted']);
if ( $service->save() ) {
$revised = $service->getAttributes();
$diff = array_diff_assoc( $original, $revised );
unset( $diff['created_at'] );
unset( $diff['updated_at'] );
unset( $diff['deleted'] );
$remarks = '';
if ($diff) {
if ( $diff ) {
$remarks .= '修改ID为 ' . $service->id . ' 的服务器信息,修改内容为:';
foreach ($diff as $key => $value) {
foreach ( $diff as $key => $value ) {
$remarks .= $fields_array[$key] . ' 由 ' . $value . ' 修改为 ' . $revised[$key] . '; ';
}
} else {
$remarks .= '修改ID为 ' . $service->id . ' 的服务器信息,无修改';
}
// 添加日志
$this->server_action_log(ServerInformationLog::ACTION_UPDATE, $original, $revised, $remarks);
$this->server_action_log( ServerInformationLog::ACTION_UPDATE, $original, $revised, $remarks );
DB::commit();
return $this->success();
}
DB::rollBack();
return $this->fail('服务器信息修改失败');
return $this->fail( '服务器信息修改失败' );
}
public function getService( int $deleted = ServerInformation::DELETED_NORMAL )
{
$id = $this->param['id'] ?? 0;
if ( !$id ) {
return $this->fail( 'ID不能为空' );
}
$data = ServerInformation::query()->where( 'deleted', $deleted )->find( $id );
if ( !$data ) {
return $this->fail( '数据不存在!' );
}
return $data;
}
/**
... ... @@ -129,10 +125,10 @@ class ServerInformationLogic extends BaseLogic
* @param $ip
* @return bool
*/
public function checkIp($ip)
public function checkIp( $ip )
{
$usIp = ServerInformation::query()->where('ip', $ip)->first();
if ($usIp) {
$usIp = ServerInformation::query()->where( 'ip', $ip )->first();
if ( $usIp ) {
return true;
} else {
return false;
... ... @@ -146,15 +142,15 @@ class ServerInformationLogic extends BaseLogic
* @throws AsideGlobalException
* @throws BsideGlobalException
*/
public function serverInfo(int $deleted = ServerInformation::DELETED_NORMAL)
public function serverInfo( int $deleted = ServerInformation::DELETED_NORMAL )
{
$id = \request()->input('id');
if (!$id) {
return $this->fail('参数错误');
$id = $this->param['id'] ?? 0;
if ( !$id ) {
return $this->fail( 'ID不能为空' );
}
$data = ServerInformation::query()->where('deleted', $deleted)->find($id, ['type', 'ip', 'title', 'belong_to', 'sshpass', 'ports', 'create_at', 'update_at']);
if (!$data) {
return $this->fail('数据不存在!');
$data = ServerInformation::query()->where( 'deleted', $deleted )->find( $id, [ 'type', 'ip', 'title', 'belong_to', 'ports', 'created_at', 'updated_at' ] );
if ( !$data ) {
return $this->fail( '数据不存在!' );
}
return $data;
}
... ... @@ -165,32 +161,10 @@ class ServerInformationLogic extends BaseLogic
* @param array $original 原始数据
* @param array $revised 修改后数据
*/
public function server_action_log(int $action = ServerInformationLog::ACTION_ADD, array $original = [], array $revised = [], $remarks = '')
public function server_action_log( int $action = ServerInformationLog::ACTION_ADD, array $original = [], array $revised = [], $remarks = '' )
{
// $action 1:添加 2:修改 3:删除 4:恢复
$actionArr = ServerInformationLog::actionArr();
$actionStr = $actionArr[$action];
$ip = request()->getClientIp();
$url = request()->getRequestUri();
$method = request()->getMethod();
$userId = $this->uid ?? 0;
$log = new ServerInformationLog();
$log->user_id = $userId;
$log->action = $actionStr;
$log->original = json_encode($original);
$log->revised = json_encode($revised);
$log->ip = $ip;
$log->url = $url;
$log->method = $method;
$log->remarks = $remarks;
DB::beginTransaction();
try {
$log->save();
DB::commit();
} catch (\Exception $e) {
DB::rollBack();
Log::error('服务器信息日志添加失败');
}
$this->log( $log, $action, $original, $revised, $remarks );
}
/**
... ... @@ -198,14 +172,14 @@ class ServerInformationLogic extends BaseLogic
* @param $service
* @return void
*/
public function extracted(array $request, $service)
public function extracted( array $request, $service, array $original = [] )
{
$service->type = trim($request['type']); // 服务器类型
$service->ip = trim($request['ip']); // 服务器ip
$service->title = trim($request['title']); // 服务器标题
$service->belong_to = trim($request['belong_to']); // 服务器归属
$service->sshpass = trim($request['sshpass']); // ssh密码
$service->ports = trim($request['ports']); // ssh端口
$service->type = trim( $request['type'] ) ?? $original['type']; // 服务器类型
$service->ip = trim( $request['ip'] ) ?? $original['ip']; // 服务器ip
$service->title = trim( $request['title'] ) ?? $original['title']; // 服务器标题
$service->belong_to = trim( $request['belong_to'] ) ?? $original['belong_to']; // 服务器归属
$service->sshpass = trim( $request['sshpass'] ) ?? $original['sshpass']; // ssh密码
$service->ports = trim( $request['ports'] ) ?? $original['ports']; // ssh端口
}
/**
... ... @@ -214,38 +188,50 @@ class ServerInformationLogic extends BaseLogic
* @throws AsideGlobalException
* @throws BsideGlobalException
*/
public function get_batch_update($action = ServerInformationLog::ACTION_DELETE, $deleted = ServerInformation::DELETED_NORMAL)
public function get_batch_update( $action = ServerInformationLog::ACTION_DELETE, $deleted = ServerInformation::DELETED_NORMAL )
{
$id = request()->input('id');
if (!$id) {
return $this->fail('参数错误');
}
$ids = [];
if (!is_array($id)) {
$ids = explode(',', $id);
}
$ids = array_filter($ids, 'intval');
if (empty($ids)) {
return $this->fail('参数错误');
}
$data = ServerInformation::query()->whereIn('id', $ids)->where('deleted', $deleted)->get();
$restore_ids = $data->pluck('id')->toArray();
$ids = $this->getIds();
$data = ServerInformation::query()->whereIn( 'id', $ids )->where( 'deleted', $deleted )->get();
$restore_ids = $data->pluck( 'id' )->toArray();
$actionArr = ServerInformationLog::actionArr();
$actionStr = $actionArr[$action];
if (empty($restore_ids)) {
$this->fail($actionStr . '服务器信息不存在!', Code::USER_ERROR);
if ( empty( $restore_ids ) ) {
$this->fail( $actionStr . '服务器信息不存在!', Code::USER_ERROR );
}
$original = $data->toArray();
DB::beginTransaction();
try {
$update = $deleted == ServerInformation::DELETED_NORMAL ? ServerInformation::DELETED_DELETE : ServerInformation::DELETED_NORMAL;
ServerInformation::query()->whereIn('id', $restore_ids)->update(['deleted' => $update]);
$this->server_action_log($action, $original, $original, $actionStr . '服务器信息 - ID : ' . implode(', ', $restore_ids));
ServerInformation::query()->whereIn( 'id', $restore_ids )->update( [ 'deleted' => $update ] );
$this->server_action_log( $action, $original, $original, $actionStr . '服务器信息 - ID : ' . implode( ', ', $restore_ids ) );
DB::commit();
return $this->success();
} catch (\Exception $e) {
} catch ( \Exception $e ) {
DB::rollBack();
return $this->fail('服务器信息' . $actionStr . '失败', Code::USER_ERROR);
return $this->fail( '服务器信息' . $actionStr . '失败', Code::USER_ERROR );
}
}
/**
* 批量获取数据恢复
* @return array
* @throws AsideGlobalException
* @throws BsideGlobalException
*/
public function getIds()
{
$id = $this->param['id'] ?? 0;
if ( !$id ) {
return $this->fail( '参数错误' );
}
$ids = [];
if ( !is_array( $id ) ) {
$ids = explode( ',', $id );
}
$ids = array_filter( $ids, 'intval' );
if ( empty( $ids ) ) {
return $this->fail( '参数错误' );
}
return $ids;
}
}
... ...
<?php
namespace App\Http\Logic\Aside\Domain;
use App\Enums\Common\Code;
use App\Exceptions\AsideGlobalException;
use App\Exceptions\BsideGlobalException;
use App\Http\Logic\Aside\BaseLogic;
use App\Http\Logic\Aside\Devops\ServerInformationLogic;
use App\Models\Aside\Domain\DomainInfo;
use App\Models\Aside\Domain\DomainInfoLog;
use App\Models\Devops\ServerInformation;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
class DomainInfoLogic extends BaseLogic
{
/**
* @var array
*/
private $param;
public function __construct()
{
parent::__construct();
$this->model = new ServerInformation();
$this->param = $this->requestAll;
}
/**
* 添加数据
* @return array
* @throws AsideGlobalException
* @throws BsideGlobalException
*/
public function create()
{
$request = $this->param ?? [];
if ($this->checkDomain($request['domain'])) {
return $this->fail('域名已存在!');
}
$domain = new DomainInfo();
$this->extracted($request, $domain);
DB::beginTransaction();
if ($domain->save()) {
$original = $domain->getOriginal();
$original['belong_to'] = $request['belong_to'];
$original['status'] = $request['status'];
// 添加日志
$this->domain_action_log(DomainInfoLog::ACTION_ADD, $original, $original, '添加域名信息成功 - ID : ' . $domain->id);
DB::commit();
return $this->success();
}
DB::rollBack();
return $this->fail('域名信息添加失败');
}
/**
* 修改数据
* @return array
* @throws AsideGlobalException
* @throws BsideGlobalException
*/
public function update()
{
$domain = $this->getDomain();
$original = $domain->getOriginal();
$original['belong_to'] = $domain->BelongToStr($original['belong_to']);
$original['status'] = $domain->StatusToStr($original['status']);
$request = $this->param;
$this->extracted($request, $domain, $original);
// 检查ip是否存在
if ($domain->domain != $request['domain']) {
if ($this->checkDomain($request['domain'])) {
$this->fail('域名信息修改失败,域名已存在', Code::USER_ERROR);
}
}
DB::beginTransaction();
if ($domain->save()) {
$fields_array = $domain->FieldsArray();
$revised = $domain->getAttributes();
$diff = array_diff_assoc($original, $revised);
unset($diff['created_at']);
unset($diff['updated_at']);
unset($diff['deleted']);
$remarks = '';
if ($diff) {
$remarks .= '修改ID为 ' . $domain->id . ' 的服务器信息,修改内容为:';
foreach ($diff as $key => $value) {
$remarks .= $fields_array[$key] . ' 由 ' . $value . ' 修改为 ' . $revised[$key] . '; ';
}
} else {
$remarks .= '修改ID为 ' . $domain->id . ' 的域名信息,无修改';
}
// 添加日志
$this->domain_action_log(DomainInfoLog::ACTION_UPDATE, $original, $revised, $remarks);
DB::commit();
return $this->success();
}
DB::rollBack();
return $this->fail('域名信息修改失败');
}
/**
* 根据ID获取数据
* @return array
* @throws AsideGlobalException
* @throws BsideGlobalException
*/
public function getDomain(int $deleted = DomainInfo::DELETED_NORMAL)
{
$id = $this->param['id'] ?? 0;
if (!$id) {
return $this->fail('ID不能为空');
}
$data = DomainInfo::query()->where('deleted', $deleted)->find($id);
if (!$data) {
return $this->fail('数据不存在!');
}
return $data;
}
/**
* 检查域名是否存在
* @param $domain
* @return bool
*/
public function checkDomain($domain)
{
$usIp = DomainInfo::query()->where('domain', $domain)->first();
if ($usIp) {
return true;
} else {
return false;
}
}
/**
* 详情
* @param int $deleted
* @return array|Builder|Collection|Model
* @throws AsideGlobalException
* @throws BsideGlobalException
*/
public function domainInfo(int $deleted = DomainInfo::DELETED_NORMAL)
{
$id = $this->param['id'] ?? 0;
if (!$id) {
return $this->fail('ID不能为空');
}
$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']);
if (!$data) {
return $this->fail('数据不存在!');
}
return $data;
}
/**
* 服务器操作日志
* @param int $action 1:添加 2:修改 3:删除 4:搜索 5:详情 6:列表
* @param array $original 原始数据
* @param array $revised 修改后数据
*/
public function domain_action_log(int $action = DomainInfoLog::ACTION_ADD, array $original = [], array $revised = [], $remarks = '')
{
$log = new DomainInfoLog();
$this->log($log, $action, $original, $revised, $remarks);
}
/**
* @param array $request
* @param $domain
* @param array $original
* @return void
* @throws AsideGlobalException
* @throws BsideGlobalException
*/
public function extracted( array $request, $domain, array $original = [])
{
$domain->domain = trim($request['domain']) ?? $original['domain'];
if (!$this->validateDomain($domain->domain)) {
$this->fail('域名格式错误');
}
$domain->belong_to = trim($request['belong_to']) ?? $original['belong_to']; // 域名归属 1 - 公司 2 - 客户
$domain->status = trim($request['status']) ?? $original['status']; // 域名状态 0 - 正常 1 - 关闭
$domain->domain_start_time = trim($request['domain_start_time']) ?? $original['domain_start_time']; // 域名开始时间
$domain->domain_end_time = trim($request['domain_end_time']) ?? $original['domain_end_time'];
$domain->certificate_start_time = trim($request['certificate_start_time']) ?? $original['certificate_start_time']; // 证书开始时间
$domain->certificate_end_time = trim($request['certificate_end_time']) ?? $original['certificate_end_time']; // 证书结束时间
}
/**
* 批量获取数据删除
* @return array
* @throws AsideGlobalException
* @throws BsideGlobalException
*/
public function get_batch_update($action = DomainInfoLog::ACTION_DELETE, $deleted = DomainInfo::DELETED_NORMAL)
{
$ids = (new ServerInformationLogic())->getIds();
$data = DomainInfo::query()->whereIn('id', $ids)->where('deleted', $deleted)->get();
$restore_ids = $data->pluck('id')->toArray();
$actionArr = DomainInfoLog::actionArr();
$actionStr = $actionArr[$action];
if (empty($restore_ids)) {
$this->fail($actionStr . '域名信息不存在!', Code::USER_ERROR);
}
$original = $data->toArray();
DB::beginTransaction();
try {
$update = $deleted == DomainInfo::DELETED_NORMAL ? DomainInfo::DELETED_DELETE : DomainInfo::DELETED_NORMAL;
DomainInfo::query()->whereIn('id', $restore_ids)->update(['deleted' => $update]);
$this->domain_action_log($action, $original, $original, $actionStr . '域名信息 - ID : ' . implode(', ', $restore_ids));
DB::commit();
return $this->success();
} catch (\Exception $e) {
DB::rollBack();
return $this->fail('域名信息' . $actionStr . '失败', Code::USER_ERROR);
}
}
/**
* 证书到期时间
* @return array
*/
public function getDomainCertificateTime($domain)
{
$domain = trim($domain);
$data = [];
$context = stream_context_create(['ssl' => ['capture_peer_cert' => true]]); // Notice: only 7.0.7+ supports this
$stream = stream_socket_client("ssl://$domain:443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
if ($stream) {
$params = stream_context_get_params($stream);
$peerCertificate = openssl_x509_parse($params['options']['ssl']['peer_certificate']);
if ($peerCertificate) {
$validFrom = date_create_from_format('U', $peerCertificate['validFrom_time_t']); // 有效期开始时间
$validTo = date_create_from_format('U', $peerCertificate['validTo_time_t']); // 有效期结束时间
$data['validFrom'] = $validFrom->format('Y-m-d H:i:s');
$data['validTo'] = $validTo->format('Y-m-d H:i:s');
}
}
return $data;
}
/**
* 获取所有正常域名信息
* @return Builder[]|Collection
*/
public function getAllDomain()
{
return DomainInfo::query()->where('status', 1)
->where('deleted', DomainInfo::DELETED_NORMAL)
->orderBy('updated_at', 'desc')
->get();
}
/**
* 域名到期时间
* @return array
*/
public function getDomainTime($domain)
{
$conJson = file_get_contents("http://openai.waimaoq.com/v1/whois_api?domain={$domain}");
$conArr = json_decode($conJson, true);
$data = [];
if ($conArr['code'] == 200) {
$con = $conArr['text'];
$data['domain'] = $domain;
$data['validFrom'] = $con['creation_date'];
$data['validTo'] = $con['expiration_date'];
}
return $data;
}
/**
* 验证给定的值是否是有效的域名。
*
* @param mixed $value
* @return bool
*/
public function validateDomain($value)
{
// 从域中删除任何空间或路径。
$domain = preg_replace('/\s|\/.*$/', '', $value);
// 验证域是否至少包含一个句点。
if (strpos($domain, '.') === false) {
return false;
}
// 验证域是否以句点开始或结束。
if (strpos($domain, '.') === 0 || strrpos($domain, '.') === strlen($domain) - 1) {
return false;
}
// 验证域是否不包含无效字符。
if (!preg_match('/^[a-zA-Z0-9\-\.]+$/', $domain)) {
return false;
}
// 验证域是否具有有效的顶级域。
$tld = substr($domain, strrpos($domain, '.') + 1);
if (!in_array($tld, ['com', 'net', 'org'])) { // 如有必要,添加更多TLD。
return false;
}
return true;
}
/**
* 根据域名更新证书到期时间
* @param $id
* @param $updata
* @return array
* @throws AsideGlobalException
* @throws BsideGlobalException
*/
public function updateDomain($id, $updata)
{
$isRes = DomainInfo::query()->where('id', $id)->where('deleted', DomainInfo::DELETED_NORMAL)->update($updata);
if ($isRes) {
return $this->success();
} else {
return $this->fail('更新域名到期时间失败');
}
}
}
... ...
... ... @@ -34,15 +34,12 @@ class CustomLogic extends BaseLogic
*/
public function save($param)
{
$param['html'] = '';
$id = parent::save($param);
$data = $this->getInfo($id['id']);
try {
RouteMap::setRoute($data['url'],RouteMap::SOURCE_CUSTOM,$data['id'],$this->user['project_id']);
}catch (\Throwable $e){
}
return $data;
}
... ...
... ... @@ -2,15 +2,20 @@
namespace App\Http\Logic\Bside\HomeCount;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\EnterpriseService\EnterpriseService as EnterpriseServiceModel;
use App\Models\HomeCount\Count;
use App\Models\RankData\RankData as RankDataModel;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
class CountLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new Yes();
$this->model = new Count();
}
/**
... ... @@ -20,6 +25,166 @@ class CountLogic extends BaseLogic
* @time :2023/5/23 17:30
*/
public function yesterday_count(){
return $this->success();
$yesterday = Carbon::yesterday()->toDateString();
$param = [
'date' => $yesterday,
'project_id' => $this->user['project_id']
];
$info = $this->model->read($param,['pv_num','ip_num','inquiry_num','date','compliance_day','service_day']);
if($info === false){
$info = [];
}
return $this->success($info);
}
/**
* @name :(方案信息)scheme_info
* @author :lyh
* @method :post
* @time :2023/5/24 11:48
*/
public function scheme_info(){
$data = [
'company'=>$this->project['company'],
'scheme'=>$this->project['deploy_build']['plan'],
'service_duration'=>$this->project['deploy_build']['service_duration'],
];
return $this->success($data);
}
/**
* @name :(总访问量)total_count
* @author :lyh
* @method :post
* @time :2023/5/24 13:33
*/
public function total_count($inquiry_num = ''){
$pv = DB::table('gl_customer_visit_item')->where(['domain'=>$this->project['deploy_build']['test_domain']])->count();
$ip = DB::table('gl_customer_visit')->where(['domain'=>$this->project['deploy_build']['test_domain']])->count();
$data = [
'total_pv'=>$pv,
'total_ip'=>$ip,
'conversion_rate' => (isset($inquiry_num) && !empty($inquiry_num)) ? ($inquiry_num / $ip) * 100 : 0,
];
return $this->success($data);
}
/**
* @name :(前一天关键字排名统计)keyword_data
* @author :lyh
* @method :post
* @time :2023/5/24 14:03
*/
public function keyword_data_count(){
$yesterday = Carbon::yesterday()->toDateString();
$rankDataModel = new RankDataModel();
$param = [
'updated_date' => $yesterday,
'project_id' => $this->user['project_id']
];
$data = $rankDataModel->read($param,['first_num','first_page_num','first_three_pages_num','first_five_pages_num','first_ten_pages_num']);
if($data === false){
$data = [];
}
return $this->success($data);
}
/**
* @name :(相关数据统计)with_data_count
* @author :lyh
* @method :post
* @time :2023/5/24 14:12
*/
public function with_data_count(){
$product_count = DB::table('gl_product')->where(['project_id' => $this->user['project_id']])->count();
$news_count = DB::table('gl_news')->where(['project_id' => $this->user['project_id']])->count();
$page_count = DB::table('gl_web_template')->where(['project_id' => $this->user['project_id']])->count();
$data = [
'product_count' => $product_count,
'news_count' => $news_count,
'page_count' => $page_count,
];
return $this->success($data);
}
/**
* @name :(30天数据统计)visit_data_count
* @author :lyh
* @method :post
* @time :2023/5/24 14:18
*/
public function visit_data_count(){
$param = [
'date' => ['between',[now()->subDays(30)->startOfDay()->toDateString(),now()->startOfDay()->toDateString()]],
'project_id' => $this->user['project_id']
];
$data = $this->model->list($param,'id',['id','pv_num','ip_num','date']);
return $this->success($data);
}
/**
* @name :(询盘国家统计)inquiry_country_count
* @author :lyh
* @method :post
* @time :2023/5/24 14:58
*/
public function inquiry_country_count(){
$data = DB::table('gl_inquiry_record')
->select('ip_area', DB::raw('COUNT(ip_area) as count'))
->groupBy('ip_area')->orderBy('count','desc')->limit(20)->get()->toArray();
$data = object_to_array($data);
$total = DB::table('gl_inquiry_record')->count();
foreach ($data as $k=>$v){
$data[$k]['proportion'] = ($v['count']/$total) * 100;
}
return $this->success($data);
}
/**
* @name :(访问来源统计)referrer_count
* @author :lyh
* @method :post
* @time :2023/5/24 15:32
*/
public function referrer_count(){
$data = DB::table('gl_customer_visit')
->select('referrer_url', DB::raw('COUNT(*) as count'))->groupBy('referrer_url')
->orderByDesc('count')->limit(8)->get()->toArray();
$total = DB::table('gl_customer_visit')->count();
$data = object_to_array($data);
foreach ($data as $k=>$v){
$data[$k]['proportion'] = ($v['count']/$total) * 100;
}
return $this->success($data);
}
/**
* @name :(访问国家统计)access_country_count
* @author :lyh
* @method :post
* @time :2023/5/24 15:56
*/
public function access_country_count(){
$data = DB::table('gl_customer_visit')
->select('country',DB::raw('COUNT(*) as ip'),DB::raw('SUM(depth) as pv'))
->groupBy('country')->orderBy('ip','desc')->limit(20)->get()->toArray();
$data = object_to_array($data);
foreach ($data as $k => $v){
$v['pv'] = (int)$v['pv'];
$data[$k] = $v;
}
return $this->success($data);
}
/**
* @name :(售后服务中心)enterprise_service
* @author :lyh
* @method :post
* @time :2023/5/25 10:22
*/
public function enterprise_service(){
$enterpriseServiceModel = new EnterpriseServiceModel();
$info = $enterpriseServiceModel->read(['status'=>0]);
return $this->success($info);
}
}
... ...
... ... @@ -3,6 +3,7 @@
namespace App\Http\Logic\Bside;
use App\Models\RouteMap;
use App\Models\Template\BSetting;
use App\Models\Template\BTemplate;
/**
... ... @@ -82,6 +83,7 @@ class TemplateLogic extends BaseLogic
'project_id'=>$this->user['project_id'],
'data_source' => $source,
'data_source_id' => $source_id,
'template_id' => BSetting::_get($this->user['project_id'])
])->first();
}
... ...
... ... @@ -8,7 +8,10 @@ use \App\Helper\Common as CommonHelper;
use App\Exceptions\AsideGlobalException;
use App\Exceptions\BsideGlobalException;
use App\Helper\Arr;
use App\Models\Devops\ServerInformationLog;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Schema;
/**
... ... @@ -29,7 +32,7 @@ class Logic
* @param array $data
* @return array
*/
public function success(array $data = [])
public function success($data = [])
{
return $data;
}
... ... @@ -393,4 +396,40 @@ class Logic
public static function instance(...$params){
return new static(...$params);
}
/**
* 添加日志
* @param $log
* @param int $action 1:添加 2:修改 3:删除 4:搜索 5:详情 6:列表
* @param array $original 原始数据
* @param array $revised 修改后数据
* @param string $remarks 备注
* @return bool
*/
public function log($log, int $action = ServerInformationLog::ACTION_ADD, array $original = [], array $revised = [], string $remarks = ''): bool
{
// $action 1:添加 2:修改 3:删除 4:恢复
$actionArr = $log->actionArr();
$actionStr = $actionArr[$action];
$ip = request()->getClientIp();
$url = request()->getRequestUri();
$method = request()->getMethod();
$userId = $this->uid ?? 0;
$log->user_id = $userId;
$log->action = $actionStr;
$log->original = json_encode($original);
$log->revised = json_encode($revised);
$log->ip = $ip;
$log->url = $url;
$log->method = $method;
$log->remarks = $remarks;
DB::beginTransaction();
if($log->save()){
DB::commit();
return true;
}
DB::rollBack();
Log::error('日志添加失败');
return false;
}
}
... ...
<?php
namespace App\Http\Requests\Aside\Domain;
use App\Models\Aside\Domain\DomainInfo;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class DomainInfoRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$domain = new DomainInfo();
$status_tot_keys = array_keys($domain->StatusToArray());
$belong_to_keys = array_keys($domain->BelongToArray());
return [
'domain' => 'required|max:200',
'belong_to' => [
'required',
Rule::in($belong_to_keys)
],
'status' => [
'required',
Rule::in($status_tot_keys)
]
];
}
public function messages()
{
return [
'domain.required' => '域名不能为空',
'domain.max' => '域名长度不能超过200个字符',
'belong_to.required' => '域名所属不能为空',
'belong_to.in' => '域名所属参数错误',
'status.required' => '域名状态不能为空',
'status.in' => '域名状态参数错误',
];
}
}
... ...
... ... @@ -36,7 +36,7 @@ class CustomRequest extends FormRequest
'keywords' => ['required','max:200'],
'description' => ['required','max:250'],
// 'html' => ['required'],
'url' => ['required','max:200'],
'url' => ['required','max:200','url'],
'status' => ['required','in:0,1'],
];
... ... @@ -70,6 +70,7 @@ class CustomRequest extends FormRequest
'url.required' => '链接必须',
'url.max' => '链接不能超过200个字符',
'url.url' => '链接不符合规则',
'status.required' => '状态选择错误',
'status.in' => '状态必须是显示/隐藏'
... ...
<?php
namespace App\Models\Aside\Domain;
use App\Models\Base;
/**
* Class DomainInfo
* @package App\Models\Aside\Domain
* @Author YiYuan-LIn
* @Date: 2019/5/16
* 域名信息模型
*/
class DomainInfo extends Base
{
protected $table = 'gl_domain_info';
// 软删除 0:正常 1:删除
/** @var int 软删除 - 正常 */
const DELETED_NORMAL = 0;
/** @var int 软删除 - 删除 */
const DELETED_DELETE = 1;
protected $hidden = [
'created_at',
'updated_at'
];
/**
* 字段信息
* @return array
*/
public function FieldsArray()
{
return [
'domain' => '域名',
'belong_to' => '域名归属',
'status' => '域名状态',
'domain_start_time' => '域名开始时间',
'domain_end_time' => '域名结束时间',
'certificate_start_time' => '证书开始时间',
'certificate_end_time' => '证书结束时间',
];
}
/**
* 域名归属信息
* @return array
*/
public function BelongToArray()
{
return [
1 => '公司',
2 => '客户',
];
}
public function BelongToStr($num)
{
return array_flip($this->BelongToArray())[$num];
}
public function BelongTo($num)
{
return $this->BelongToArray()[$num];
}
/**
* 域名状态信息
* @return array
*/
public function StatusToArray()
{
return [
0 => '未使用',
1 => '使用中',
];
}
public function StatusToStr($num)
{
return array_flip($this->StatusToArray())[$num];
}
/**
* 返回域名状态
* @param $num
*
* @return string
*/
public function StatusTo($num)
{
return $this->StatusToArray()[$num];
}
/**
* 返回服务器归属
* @param $value
*
* @return string
*/
public function getBelongToAttribute($value)
{
return $this->BelongTo($value);
}
/**
* 返回服务器状态
* @param $value
*
* @return string
*/
public function getStatusAttribute($value)
{
return $this->StatusTo($value);
}
}
... ...
<?php
namespace App\Models\Aside\Domain;
use Illuminate\Database\Eloquent\Model;
class DomainInfoLog extends Model
{
protected $table = 'gl_domain_info_log';
public function getOriginalAttribute($value)
{
return json_decode($value, true);
}
public function getRevisedAttribute($value)
{
return json_decode($value, true);
}
/** @var int 日志添加 */
const ACTION_ADD = 1;
/** @var int 日志修改 */
const ACTION_UPDATE = 2;
/** @var int 日志删除 */
const ACTION_DELETE = 3;
/** @var int 日志恢复 */
const ACTION_RECOVER = 4;
/**
* @return string[]
*/
public static function actionArr()
{
return [
1 => '添加',
2 => '修改',
3 => '删除',
4 => '恢复',
];
}
}
... ...
... ... @@ -8,8 +8,6 @@ class ServerInformation extends Model
{
protected $table = 'gl_server_information';
const CREATED_AT = 'create_at';
const UPDATED_AT = 'update_at';
// 软删除 0:正常 1:删除
const DELETED_NORMAL = 0;
... ... @@ -44,6 +42,11 @@ class ServerInformation extends Model
];
}
public function ServiceStr($num)
{
return array_flip($this->ServiceArray())[$num];
}
/**
* 字段信息
* @return array
... ... @@ -73,6 +76,11 @@ class ServerInformation extends Model
];
}
public function BelongToStr($num)
{
return array_flip($this->BelongToArray())[$num];
}
public function BelongTo($num)
{
return $this->BelongToArray()[$num];
... ...
... ... @@ -7,8 +7,6 @@ use Illuminate\Database\Eloquent\Model;
class ServerInformationLog extends Model
{
protected $table = 'gl_server_information_log';
const CREATED_AT = 'create_at';
const UPDATED_AT = 'update_at';
public function getOriginalAttribute($value)
{
... ...
<?php
namespace App\Models\EnterpriseService;
use App\Models\Base;
class EnterpriseService extends Base
{
protected $table = 'gl_enterprise_service';
}
... ...
... ... @@ -4,7 +4,7 @@ namespace App\Models\HomeCount;
use App\Models\Base;
class YesterdayCount extends Base
class Count extends Base
{
protected $table = 'gl_yesterday_count';
protected $table = 'gl_count';
}
... ...
... ... @@ -6,9 +6,11 @@ use App\Models\Base;
class WebSetting extends Base
{
//锚文本常量配置在settingTextModel中
protected $table = 'gl_web_setting';
//连接数据库
// protected $connection = 'custom_mysql';
}
... ...
... ... @@ -116,6 +116,19 @@ Route::middleware(['web'])->group(function (){ //admin用渲染默认要加上w
Route::post('/save_follow', [Aside\Task\TaskController::class, 'save_follow'])->name('admin.task_save_follow');
});
// 域名
Route::prefix('domain')->group(function () {
Route::get('/', [Aside\Domain\DomainInfoController::class, 'lists'])->name('admin.domain'); // 列表 | 搜索
Route::get('/info', [Aside\Domain\DomainInfoController::class, 'info'])->name('admin.domain_info'); // 详情
Route::get('/delete_info', [Aside\Domain\DomainInfoController::class, 'getDeleteDomainInfo'])->name('admin.domain_delete_info'); // 删除信息
Route::post('/add', [Aside\Domain\DomainInfoController::class, 'add'])->name('admin.domain_save'); // 添加
Route::post('/edit', [Aside\Domain\DomainInfoController::class, 'edit'])->name('admin.domain_edit'); // 编辑
Route::any('/delete', [Aside\Domain\DomainInfoController::class, 'delete'])->name('admin.domain_delete'); // 删除
Route::get('/delete_list', [Aside\Domain\DomainInfoController::class, 'delete_list'])->name('admin.domain_delete_list'); // 删除列表
Route::any('/restore', [Aside\Domain\DomainInfoController::class, 'restore'])->name('admin.domain_restore'); // 恢复
Route::get('/log', [Aside\Domain\DomainInfoLogController::class, 'lists'])->name('admin.domain_log_lists'); // 日志
});
//运维
Route::prefix('devops')->group(function () {
//服务器配置
... ... @@ -127,7 +140,7 @@ Route::middleware(['web'])->group(function (){ //admin用渲染默认要加上w
// 服务器添加|修改|删除
Route::prefix('server')->group(function () {
Route::get('/', [Aside\Devops\ServerInformationController::class, 'lists'])->name('admin.devops.bt'); // 列表
Route::get('/', [Aside\Devops\ServerInformationController::class, 'lists'])->name('admin.devops.bt'); // 列表 | 搜索
Route::get('/info', [Aside\Devops\ServerInformationController::class, 'getServerInfo'])->name('admin.devops.bt_info'); // 获取信息
Route::get('/delete_info', [Aside\Devops\ServerInformationController::class, 'getDeleteServerInfo'])->name('admin.devops.bt_delete_info'); // 删除信息
Route::post('/add', [Aside\Devops\ServerInformationController::class, 'add'])->name('admin.devops.bt_add'); // 添加
... ... @@ -135,10 +148,8 @@ Route::middleware(['web'])->group(function (){ //admin用渲染默认要加上w
Route::get('/delete', [Aside\Devops\ServerInformationController::class, 'delete'])->name('admin.devops.bt_delete'); // 删除
Route::get('/delete_list', [Aside\Devops\ServerInformationController::class, 'delete_list'])->name('admin.devops.bt_delete_list'); // 删除列表
Route::get('/restore', [Aside\Devops\ServerInformationController::class, 'restore'])->name('admin.devops.bt_restore'); //恢复数据
Route::get('/search', [Aside\Devops\ServerInformationController::class, 'search'])->name('admin.devops.bt_search'); //搜索
Route::get('/log', [Aside\Devops\ServerInformationLogController::class, 'lists'])->name('admin.devops.bt_log_lists'); //日志列表
});
});
// 自定义页面 模板,头部底部
... ...
... ... @@ -262,12 +262,19 @@ Route::middleware(['bloginauth','accesstoken'])->group(function () {
Route::any('/get_google_rank', [\App\Http\Controllers\Bside\RankDataController::class, 'get_google_rank'])->name('rank_data_get_google_rank');
});
//首页统计数据
Route::prefix('home')->group(function () {
Route::any('/count', [\App\Http\Controllers\Bside\HomeCount\CountController::class, 'count'])->name('home_count');
Route::any('/yesterday', [\App\Http\Controllers\Bside\HomeCount\CountController::class, 'yesterday'])->name('home_yesterday');
});
//访问数据
Route::prefix('visit')->group(function () {
Route::any('/', [\App\Http\Controllers\Bside\VisitController::class, 'index'])->name('visit_list');
Route::any('/item', [\App\Http\Controllers\Bside\VisitController::class, 'item'])->name('visit_item');
});
});
//无需登录验证的路由组
Route::group([], function () {
... ...