Merge remote-tracking branch 'origin/master' into akun
正在显示
2 个修改的文件
包含
190 行增加
和
1 行删除
app/Console/Commands/DayCount/CountDate.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Console\Commands\DayCount; | ||
| 4 | + | ||
| 5 | +use App\Helper\Common; | ||
| 6 | +use App\Helper\FormGlobalsoApi; | ||
| 7 | +use App\Models\Domain\DomainInfo; | ||
| 8 | +use App\Models\Inquiry\InquiryForm; | ||
| 9 | +use App\Models\Inquiry\InquiryFormData; | ||
| 10 | +use App\Models\Project\DeployBuild; | ||
| 11 | +use App\Models\Project\DeployOptimize; | ||
| 12 | +use App\Models\Project\Project; | ||
| 13 | +use App\Services\ProjectServer; | ||
| 14 | +use Carbon\Carbon; | ||
| 15 | +use Illuminate\Console\Command; | ||
| 16 | +use Illuminate\Support\Facades\DB; | ||
| 17 | +use Illuminate\Support\Facades\Log; | ||
| 18 | + | ||
| 19 | +class CountDate extends Command | ||
| 20 | +{ | ||
| 21 | + const STATUS_ERROR = 400; | ||
| 22 | + public $error = 0; | ||
| 23 | + /** | ||
| 24 | + * The name and signature of the console command. | ||
| 25 | + * | ||
| 26 | + * @var string | ||
| 27 | + */ | ||
| 28 | + protected $signature = 'count_data'; | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * The console command description. | ||
| 32 | + * | ||
| 33 | + * @var string | ||
| 34 | + */ | ||
| 35 | + protected $description = '统计昨日数据'; | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * @name :(定时执行生成昨日数据统计)handle | ||
| 39 | + * @author :lyh | ||
| 40 | + * @method :post | ||
| 41 | + * @time :2023/5/12 14:48 | ||
| 42 | + */ | ||
| 43 | + public function handle() | ||
| 44 | + { | ||
| 45 | + $list = DB::table('gl_project')->where('gl_project.extend_type','=',0) | ||
| 46 | + ->whereIn('gl_project.type',[1,2,3,4,6]) | ||
| 47 | + ->leftJoin('gl_project_deploy_build', 'gl_project.id', '=', 'gl_project_deploy_build.project_id') | ||
| 48 | + ->leftJoin('gl_project_deploy_optimize', 'gl_project.id', '=', 'gl_project_deploy_optimize.project_id') | ||
| 49 | + ->select($this->selectParam())->get(); | ||
| 50 | + try { | ||
| 51 | + if(!empty($list)){ | ||
| 52 | + $list = $list->toArray(); | ||
| 53 | +// $yesterday = Carbon::yesterday()->toDateString(); | ||
| 54 | + $yesterday = '2024-08-31 00:00:00'; | ||
| 55 | + $domainInfo = new DomainInfo(); | ||
| 56 | + foreach ($list as $v){ | ||
| 57 | + $v = (array)$v; | ||
| 58 | + echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL; | ||
| 59 | + if($v['type'] == Project::TYPE_ZERO){ | ||
| 60 | + continue; | ||
| 61 | + } | ||
| 62 | + if(!empty($v['domain'])){ | ||
| 63 | + $info = $domainInfo->read(['id'=>$v['domain']]); | ||
| 64 | + if($info !== false){ | ||
| 65 | + $v['test_domain'] = $info['domain']; | ||
| 66 | + } | ||
| 67 | + } | ||
| 68 | + $arr = []; | ||
| 69 | + //统计时间 | ||
| 70 | + $arr['date'] = $yesterday; | ||
| 71 | + ProjectServer::useProject($v['id']); | ||
| 72 | + //pv统计 | ||
| 73 | + $arr['pv_num'] = $this->pv_num($yesterday,$v['test_domain']); | ||
| 74 | + //ip统计 | ||
| 75 | + $arr['ip_num'] = $this->ip_num($yesterday,$v['test_domain']); | ||
| 76 | + DB::disconnect('custom_mysql'); | ||
| 77 | + //服务达标天数 | ||
| 78 | + $arr['compliance_day'] = $v['finish_remain_day']; | ||
| 79 | + //剩余服务时常 | ||
| 80 | + $arr['service_day'] = ($v['remain_day'] - 1) < 0 ? 0: $v['remain_day'] - 1; | ||
| 81 | + //项目id | ||
| 82 | + $arr['project_id'] = $v['project_id']; | ||
| 83 | + $arr['created_at'] = date('Y-m-d H:i:s'); | ||
| 84 | + $arr['updated_at'] = date('Y-m-d H:i:s'); | ||
| 85 | + //询盘统计 | ||
| 86 | + $arr = $this->inquiry($arr,$v['test_domain'], $v['id']); | ||
| 87 | + if($arr === false){ | ||
| 88 | + continue; | ||
| 89 | + } | ||
| 90 | + //查询当天数据是否存在 存在则更新 | ||
| 91 | + $countModel = new \App\Models\HomeCount\Count(); | ||
| 92 | + $info = $countModel->read(['date'=>$arr['date'],'project_id'=>$v['id']]); | ||
| 93 | + if($info === false){ | ||
| 94 | + DB::table('gl_count')->insert($arr); | ||
| 95 | + }else{ | ||
| 96 | + $countModel->edit($arr,['id'=>$info['id']]); | ||
| 97 | + } | ||
| 98 | + Log::channel('day_count')->error('日期:'.$arr['created_at'].'success: ' .$v['test_domain']); | ||
| 99 | + } | ||
| 100 | + } | ||
| 101 | + }catch (\Exception $e){ | ||
| 102 | + Log::channel('day_count')->error('day_count:->error ' . $e->getMessage()); | ||
| 103 | + } | ||
| 104 | + Log::channel('day_count')->error('success:end'); | ||
| 105 | + echo $this->error; | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + /** | ||
| 109 | + * @name :(统计pv)pv_num | ||
| 110 | + * @author :lyh | ||
| 111 | + * @method :post | ||
| 112 | + * @time :2023/6/14 15:40 | ||
| 113 | + */ | ||
| 114 | + public function pv_num($yesterday,$domain){ | ||
| 115 | + $pv = DB::connection('custom_mysql')->table('gl_customer_visit_item')->whereDate('updated_date', $yesterday)->count(); | ||
| 116 | + return $pv; | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + /** | ||
| 120 | + * @name :(统计ip)ip_num | ||
| 121 | + * @author :lyh | ||
| 122 | + * @method :post | ||
| 123 | + * @time :2023/6/14 15:40 | ||
| 124 | + */ | ||
| 125 | + public function ip_num($yesterday,$domain){ | ||
| 126 | + $ip = DB::connection('custom_mysql')->table('gl_customer_visit')->whereDate('updated_date', $yesterday)->count(); | ||
| 127 | + return $ip; | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + /** | ||
| 131 | + * @param $arr | ||
| 132 | + * @param $domain | ||
| 133 | + * @name :(询盘统计)inquiry | ||
| 134 | + * @author :lyh | ||
| 135 | + * @method :post | ||
| 136 | + * @time :2023/6/14 15:44 | ||
| 137 | + */ | ||
| 138 | + public function inquiry($arr,$domain,$project_id){ | ||
| 139 | + $inquiry_list = (new FormGlobalsoApi())->getInquiryAll($domain); | ||
| 140 | + if($inquiry_list == false){ | ||
| 141 | + return false; | ||
| 142 | + } | ||
| 143 | + if($inquiry_list['status'] == self::STATUS_ERROR){ | ||
| 144 | + $arr['inquiry_num'] = 0; | ||
| 145 | + $countryArr = []; | ||
| 146 | + }else{ | ||
| 147 | + $arr['inquiry_num'] = $inquiry_list['data']['count']; | ||
| 148 | + //询盘国家统计 | ||
| 149 | + $countryArr = $inquiry_list['data']['country']; | ||
| 150 | + } | ||
| 151 | + //加上其他询盘 | ||
| 152 | + ProjectServer::useProject($project_id); | ||
| 153 | + $arr['inquiry_num'] += InquiryFormData::getCount(); | ||
| 154 | + $countryData = InquiryFormData::getCountryCount(); | ||
| 155 | + foreach ($countryData as $v1){ | ||
| 156 | + if(isset($countryArr[$v1['country']])){ | ||
| 157 | + $countryArr[$v1['country']] += $v1['count']; | ||
| 158 | + }else{ | ||
| 159 | + $countryArr[$v1['country']] = $v1['count']; | ||
| 160 | + } | ||
| 161 | + } | ||
| 162 | + arsort($countryArr); | ||
| 163 | + $top20 = array_slice($countryArr, 0, 20, true); | ||
| 164 | + $arr['country'] = json_encode($top20); | ||
| 165 | + return $arr; | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + /** | ||
| 169 | + * @name :(查询参数设置)selectParam | ||
| 170 | + * @author :lyh | ||
| 171 | + * @method :post | ||
| 172 | + * @time :2023/6/14 15:00 | ||
| 173 | + */ | ||
| 174 | + public function selectParam(){ | ||
| 175 | + $select = [ | ||
| 176 | + 'gl_project.id AS id', | ||
| 177 | + 'gl_project.type AS type', | ||
| 178 | + 'gl_project.extend_type AS extend_type', | ||
| 179 | + 'gl_project.remain_day AS remain_day', | ||
| 180 | + 'gl_project.finish_remain_day AS finish_remain_day', | ||
| 181 | + 'gl_project_deploy_build.test_domain AS test_domain', | ||
| 182 | + 'gl_project_deploy_optimize.domain AS domain', | ||
| 183 | + 'gl_project_deploy_build.project_id AS project_id', | ||
| 184 | + 'gl_project.cooperate_date AS cooperate_date', | ||
| 185 | + 'gl_project_deploy_build.service_duration AS service_duration', | ||
| 186 | + ]; | ||
| 187 | + return $select; | ||
| 188 | + } | ||
| 189 | +} |
| @@ -37,7 +37,7 @@ class LogFormatterFactory | @@ -37,7 +37,7 @@ class LogFormatterFactory | ||
| 37 | if (!file_exists($path)) { | 37 | if (!file_exists($path)) { |
| 38 | $directory = pathinfo($path, PATHINFO_DIRNAME); | 38 | $directory = pathinfo($path, PATHINFO_DIRNAME); |
| 39 | if(!file_exists($directory)){ | 39 | if(!file_exists($directory)){ |
| 40 | - mkdir($directory, 0644, true); | 40 | + mkdir($directory, 0755, true); |
| 41 | chown($directory, 'www'); | 41 | chown($directory, 'www'); |
| 42 | } | 42 | } |
| 43 | touch($path); | 43 | touch($path); |
-
请 注册 或 登录 后发表评论