作者 赵彬吉

update

... ... @@ -164,10 +164,5 @@ class RankData extends BaseCommands
$model->updated_date = date('Y-m-d');
@file_put_contents(storage_path('logs/lyh_error.log'), var_export($model, true) . PHP_EOL, FILE_APPEND);
$model->save();
//保存项目 剩余服务天数
$project = Project::with('deploy_build')->find(1);
$project->remain_day = $project['deploy_build']['service_duration'] - $model->compliance_day;
$project->save();
}
}
... ...
<?php
namespace App\Console\Commands;
use App\Helper\Arr;
use App\Models\Product\Category;
use App\Models\Product\Product;
use App\Models\Project\OnlineCheck;
use App\Models\Project\Project;
use App\Models\RankData\RankData as GoogleRankModel;
use App\Models\RouteMap\RouteMap;
use GuzzleHttp\Client;
use GuzzleHttp\Promise\Utils;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
/**
* 剩余服务时长
* Class Traffic
* @package App\Console\Commands
* @author zbj
* @date 2023/5/18
*/
class RemainDay extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'remain_day';
/**
* The console command description.
*
* @var string
*/
protected $description = '网站服务剩余时长';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* @return bool
*/
public function handle()
{
$list = Project::whereIn('type', ['2,3,4'])->get();
foreach ($list as $item){
if($item['type'] == 3){
//排名达标天数
$compliance_day = GoogleRankModel::where(['project_id' => $item['id'], 'lang' => ''])->value('compliance_day') ?: 0;
$remain_day = $item['deploy_build']['service_duration'] - $compliance_day;
}else{
//审核上线后开始
$check_time = OnlineCheck::where('project_id', $item['id'])->where('status', 1)->value('created_at') ?: '';
if($check_time){
$remain_day = $item['deploy_build']['service_duration'];
}else{
$diff = time() - strtotime($check_time);
$remain_day = floor($diff / (60 * 60 * 24));
}
}
$item->remain_day = $remain_day > 0 ? $remain_day : 0;
$item->save();
}
}
}
... ...
... ... @@ -16,6 +16,7 @@ class Kernel extends ConsoleKernel
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')->hourly();
$schedule->command('remain_day')->dailyAt('00:30')->withoutOverlapping(1); // 项目剩余服务时长
$schedule->command('rank_data')->dailyAt('01:00')->withoutOverlapping(1); // 排名数据,每天凌晨执行一次
$schedule->command('rank_data_speed')->weeklyOn(1, '01:00')->withoutOverlapping(1); // 排名数据-测速数据,每周一凌晨执行一次
$schedule->command('rank_data_external_links')->weeklyOn(1, '01:00')->withoutOverlapping(1); // 排名数据-外链,每周一凌晨执行一次
... ...
... ... @@ -426,4 +426,18 @@ class ProjectController extends BaseController
$list = $domainModel->list(['status'=>0,'project_id'=>['or',$this->param['project_id']]]);
$this->response('success',Code::SUCCESS,$list);
}
/**
* 通过企业名称查询项目是否在服务中, 有项目并且在服务中的返回1, 其他的返回0
* @author zbj
* @date 2023/9/4
*/
public function getProjectInService(){
$company = $this->param['company'];
if(!$company){
$this->response('企业名称必传',Code::SYSTEM_ERROR);
}
$project = Project::where('company', $company)->where('remain_day', '>', 0)->first();
$this->response('success',Code::SUCCESS, ['in_service' => $project ? 1 : 0]);
}
}
... ...
... ... @@ -307,7 +307,7 @@ Route::group([], function () {
Route::any('/domain/exportData', [Aside\Domain\DomainInfoController::class, 'exportData'])->name('admin.domain_exportData');//导出数据
Route::any('/notice/project', [Aside\Notice\NoticeController::class, 'project'])->name('admin.notice.project');
Route::any('/sendLoginSms', [Aside\LoginController::class, 'sendLoginSms'])->name('admin.sendLoginSms');//发送验证码
Route::any('/getProjectInService', [Aside\Project\ProjectController::class, 'getProjectInService'])->name('admin.getProjectInService');//获取项目服务状态
});
... ...