|
...
|
...
|
@@ -4,12 +4,15 @@ namespace App\Console\Commands\DayCount; |
|
|
|
|
|
|
|
use App\Helper\Common;
|
|
|
|
use App\Helper\FormGlobalsoApi;
|
|
|
|
use App\Models\Domain\DomainInfo;
|
|
|
|
use App\Models\Project\DeployBuild;
|
|
|
|
use App\Models\Project\DeployOptimize;
|
|
|
|
use App\Models\Project\Project;
|
|
|
|
use App\Services\ProjectServer;
|
|
|
|
use Carbon\Carbon;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
|
|
class Count extends Command
|
|
|
|
{
|
|
...
|
...
|
@@ -28,6 +31,7 @@ class Count extends Command |
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = '统计昨日数据';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :(定时执行生成昨日数据统计)handle
|
|
|
|
* @author :lyh
|
|
...
|
...
|
@@ -39,35 +43,48 @@ class Count extends Command |
|
|
|
$list = DB::table('gl_project')->where('gl_project.extend_type','!=',5)
|
|
|
|
->leftJoin('gl_project_deploy_build', 'gl_project.id', '=', 'gl_project_deploy_build.project_id')
|
|
|
|
->leftJoin('gl_project_deploy_optimize', 'gl_project.id', '=', 'gl_project_deploy_optimize.project_id')
|
|
|
|
->select($this->selectParam())->get()->toArray();
|
|
|
|
$data = [];
|
|
|
|
$yesterday = Carbon::yesterday()->toDateString();
|
|
|
|
foreach ($list as $v){
|
|
|
|
$v = (array)$v;
|
|
|
|
if($v['domain'] != ''){
|
|
|
|
$v['test_domain'] = $v['domain'];
|
|
|
|
->select($this->selectParam())->get();
|
|
|
|
try {
|
|
|
|
if(!empty($list)){
|
|
|
|
$list = $list->toArray();
|
|
|
|
$data = [];
|
|
|
|
$yesterday = Carbon::yesterday()->toDateString();
|
|
|
|
$domainInfo = new DomainInfo();
|
|
|
|
foreach ($list as $v){
|
|
|
|
$v = (array)$v;
|
|
|
|
if(!empty($v['domain'])){
|
|
|
|
$info = $domainInfo->read(['id'=>$v['domain']]);
|
|
|
|
if($info !== false){
|
|
|
|
$v['test_domain'] = $info['domain'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$arr = [];
|
|
|
|
//统计时间
|
|
|
|
$arr['date'] = $yesterday;
|
|
|
|
ProjectServer::useProject($v['id']);
|
|
|
|
//pv统计
|
|
|
|
$arr['pv_num'] = $this->pv_num($yesterday,$v['test_domain']);
|
|
|
|
//ip统计
|
|
|
|
$arr['ip_num'] = $this->ip_num($yesterday,$v['test_domain']);
|
|
|
|
DB::disconnect('custom_mysql');
|
|
|
|
//服务达标天数
|
|
|
|
$arr['compliance_day'] = $this->compliance_day($v['id']);
|
|
|
|
//剩余服务时常
|
|
|
|
$arr['service_day'] = ((int)$v['service_duration'] - (int)$arr['compliance_day']) > 0 ? ((int)$v['service_duration'] - (int)$arr['compliance_day']) : 0;
|
|
|
|
//项目id
|
|
|
|
$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');
|
|
|
|
//询盘统计
|
|
|
|
$arr = $this->inquiry($arr,$v['test_domain']);
|
|
|
|
$data[] = $arr;
|
|
|
|
}
|
|
|
|
//判断数据是否存在
|
|
|
|
DB::table('gl_count')->insert($data);
|
|
|
|
}
|
|
|
|
$arr = [];
|
|
|
|
//统计时间
|
|
|
|
$arr['date'] = $yesterday;
|
|
|
|
//pv统计
|
|
|
|
$arr['pv_num'] = $this->pv_num($yesterday,$v['test_domain']);
|
|
|
|
//ip统计
|
|
|
|
$arr['ip_num'] = $this->ip_num($yesterday,$v['test_domain']);
|
|
|
|
//服务达标天数
|
|
|
|
$arr['compliance_day'] = $this->compliance_day($v['test_domain']);
|
|
|
|
//剩余服务时常
|
|
|
|
$arr['service_day'] = ((int)$v['service_duration'] - (int)$arr['compliance_day']) > 0 ? ((int)$v['service_duration'] - (int)$arr['compliance_day']) : 0;
|
|
|
|
//项目id
|
|
|
|
$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');
|
|
|
|
//询盘统计
|
|
|
|
$arr = $this->inquiry($arr,$v['test_domain']);
|
|
|
|
$data[] = $arr;
|
|
|
|
}catch (\Exception $e){
|
|
|
|
Log::error('同步数据执行失败');
|
|
|
|
}
|
|
|
|
//判断数据是否存在
|
|
|
|
DB::table('gl_count')->insert($data);
|
|
|
|
echo $this->error;
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -78,7 +95,7 @@ class Count extends Command |
|
|
|
* @time :2023/6/14 15:40
|
|
|
|
*/
|
|
|
|
public function pv_num($yesterday,$domain){
|
|
|
|
$pv = DB::table('gl_customer_visit_item')->whereDate('updated_date', $yesterday)->where('domain',$domain)->count();
|
|
|
|
$pv = DB::connection('custom_mysql')->table('gl_customer_visit_item')->whereDate('updated_date', $yesterday)->where('domain',$domain)->count();
|
|
|
|
return $pv;
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -89,7 +106,7 @@ class Count extends Command |
|
|
|
* @time :2023/6/14 15:40
|
|
|
|
*/
|
|
|
|
public function ip_num($yesterday,$domain){
|
|
|
|
$ip = DB::table('gl_customer_visit')->whereDate('updated_date', $yesterday)->where('domain',$domain)->count();
|
|
|
|
$ip = DB::connection('custom_mysql')->table('gl_customer_visit')->whereDate('updated_date', $yesterday)->where('domain',$domain)->count();
|
|
|
|
return $ip;
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -150,7 +167,7 @@ class Count extends Command |
|
|
|
*/
|
|
|
|
public function selectParam(){
|
|
|
|
$select = [
|
|
|
|
'gl_project.id AS user_id',
|
|
|
|
'gl_project.id AS id',
|
|
|
|
'gl_project.extend_type AS extend_type',
|
|
|
|
'gl_project_deploy_build.test_domain AS test_domain',
|
|
|
|
'gl_project_deploy_optimize.domain AS domain',
|
...
|
...
|
|