|
...
|
...
|
@@ -3,8 +3,10 @@ |
|
|
|
namespace App\Console\Commands\MonthlyCount;
|
|
|
|
|
|
|
|
use App\Helper\FormGlobalsoApi;
|
|
|
|
use App\Models\Project\DeployBuild;
|
|
|
|
use Carbon\Carbon;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
class InquiryMonthlyCount extends Command
|
|
|
|
{
|
|
...
|
...
|
@@ -15,7 +17,7 @@ class InquiryMonthlyCount extends Command |
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $signature = 'yesterday_count';
|
|
|
|
protected $signature = 'month_count';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
...
|
...
|
@@ -32,40 +34,125 @@ class InquiryMonthlyCount extends Command |
|
|
|
* @time :2023/6/30 9:32
|
|
|
|
*/
|
|
|
|
public function handle(){
|
|
|
|
//统计数据
|
|
|
|
$arr = [];
|
|
|
|
$deployModel = new DeployBuild();
|
|
|
|
$list = $deployModel->list();
|
|
|
|
// 获取上个月的开始时间
|
|
|
|
$startTime = Carbon::now()->subMonth()->startOfMonth();
|
|
|
|
$startTime = Carbon::now()->subMonth()->startOfMonth()->toDateString();
|
|
|
|
// 获取上个月的结束时间
|
|
|
|
$endTime = Carbon::now()->subMonth()->endOfMonth();
|
|
|
|
$endTime = Carbon::now()->subMonth()->endOfMonth()->toDateString();
|
|
|
|
foreach ($list as $value){
|
|
|
|
//按月统计询盘记录
|
|
|
|
$this->inquiryCount($startTime,$endTime,$value['test_domain'],$value['project_id']);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $arr
|
|
|
|
* @param $domain
|
|
|
|
* @name :(询盘统计)inquiry
|
|
|
|
* @param $project_id
|
|
|
|
* @remark :询盘按月统计
|
|
|
|
* @name :inquiryCount
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/6/14 15:44
|
|
|
|
* @time :2023/6/30 14:29
|
|
|
|
*/
|
|
|
|
public function inquiry($arr,$domain){
|
|
|
|
public function inquiryCount($startTime,$endTime,$domain,$project_id){
|
|
|
|
//TODO::上线后注释
|
|
|
|
$domain = 'https://demomark.globalso.com/';
|
|
|
|
$arr = [];
|
|
|
|
$inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000);
|
|
|
|
$arr['count'] = $inquiry_list['data']['total'];
|
|
|
|
//询盘国家统计
|
|
|
|
$countryData = $inquiry_list['data']['data'];
|
|
|
|
//总数
|
|
|
|
$arr['total'] = $inquiry_list['data']['total'];
|
|
|
|
//数据详情
|
|
|
|
$data = $inquiry_list['data']['data'];
|
|
|
|
$arr['month_total'] = 0;
|
|
|
|
$countryArr = [];
|
|
|
|
foreach ($countryData as $v1){
|
|
|
|
if(isset($countryArr[$v1['country']])){
|
|
|
|
$countryArr[$v1['country']]++;
|
|
|
|
foreach ($data as $v){
|
|
|
|
if(($startTime.' 00:00:00' <= $v['submit_time']) && $v['submit_time'] <= $endTime.' 23:59:59'){
|
|
|
|
$arr['month_total']++;
|
|
|
|
}
|
|
|
|
if(isset($countryArr[$v['country']])){
|
|
|
|
$countryArr[$v['country']]++;
|
|
|
|
}else{
|
|
|
|
$countryArr[$v1['country']] = 0;
|
|
|
|
$countryArr[$v['country']] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 获取当前日期时间
|
|
|
|
$arr['month'] = Carbon::now()->subMonth()->format('Y-m');
|
|
|
|
arsort($countryArr);
|
|
|
|
$top20 = array_slice($countryArr, 0, 20, true);
|
|
|
|
$top20 = array_slice($countryArr, 0, 15, true);
|
|
|
|
$arr['country'] = json_encode($top20);
|
|
|
|
$this->flowCount($arr,$startTime,$endTime,$project_id);
|
|
|
|
$this->sourceCount($arr,$domain,$startTime,$endTime);
|
|
|
|
$arr['created_at'] = date('Y-m-d H:i:s');
|
|
|
|
$arr['updated_at'] = date('Y-m-d H:i:s');
|
|
|
|
$arr['project_id'] = $project_id;
|
|
|
|
DB::table('gl_inquiry_month_count')->insert($arr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :流量统计
|
|
|
|
* @name :flowCount
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/6/30 14:31
|
|
|
|
*/
|
|
|
|
public function flowCount(&$arr,$startTime,$endTime,$project_id){
|
|
|
|
$pv_ip = DB::table('gl_count')
|
|
|
|
->where(['project_id'=>$project_id])
|
|
|
|
->where('date','>=',$startTime->toDateString().' 00:00:00')
|
|
|
|
->where('date','<=',$endTime->toDateString().' 23:59:59')
|
|
|
|
->select(DB::raw('SUM(pv_num) as pv_num'), DB::raw('SUM(ip_num) as ip_num'))
|
|
|
|
->first();
|
|
|
|
$arr['pv'] = $pv_ip['pv_num'];
|
|
|
|
$arr['ip'] = $pv_ip['ip_num'];
|
|
|
|
if($arr['ip'] != 0){
|
|
|
|
$arr['rate'] = round(($arr['month_total'] / $arr['ip']) * 10,2);
|
|
|
|
}
|
|
|
|
return $arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :来源访问前8
|
|
|
|
* @name :sourceCount
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/6/30 16:14
|
|
|
|
*/
|
|
|
|
public function sourceCount(&$arr,$domain,$startTime,$endTime){
|
|
|
|
//访问来源前10
|
|
|
|
$arr['source'] = DB::table('gl_customer_visit')
|
|
|
|
->select('referrer_url', DB::raw('COUNT(*) as count'))
|
|
|
|
->groupBy('referrer_url')->where(['domain'=>$domain])
|
|
|
|
->where('updated_date','>=',$startTime->toDateString())
|
|
|
|
->where('updated_date','<=',$endTime->toDateString())
|
|
|
|
->orderByDesc('count')->limit(10)->get()->toArray();
|
|
|
|
if(!empty($data)){
|
|
|
|
$arr['source'] = json_encode($arr['source']);
|
|
|
|
}
|
|
|
|
//访问国家前15
|
|
|
|
$arr['source_country'] = DB::table('gl_customer_visit')
|
|
|
|
->select('country',DB::raw('COUNT(*) as ip'),DB::raw('SUM(depth) as pv'))
|
|
|
|
->groupBy('country')->where(['domain'=>$domain])
|
|
|
|
->where('updated_date','>=',$startTime->toDateString())
|
|
|
|
->where('updated_date','<=',$endTime->toDateString())
|
|
|
|
->orderBy('ip','desc')->limit(15)->get()->toArray();
|
|
|
|
//受访界面前15
|
|
|
|
$arr['referrer_url'] = DB::table('gl_customer_visit_item')
|
|
|
|
->select('url',DB::raw('COUNT(*) as num'))
|
|
|
|
->orderBy('num','desc')->where(['domain'=>$domain])
|
|
|
|
->where('updated_date','>=',$startTime->toDateString())
|
|
|
|
->where('updated_date','<=',$endTime->toDateString())
|
|
|
|
->groupBy('url')
|
|
|
|
->limit(15)->get()->toArray();
|
|
|
|
//访问断后
|
|
|
|
$arr['referrer_port'] = DB::table('gl_customer_visit_item')
|
|
|
|
->select('device_port',DB::raw('COUNT(*) as num'))
|
|
|
|
->orderBy('num','desc')->where(['domain'=>$domain])
|
|
|
|
->where('updated_date','>=',$startTime->toDateString())
|
|
|
|
->where('updated_date','<=',$endTime->toDateString())
|
|
|
|
->groupBy('device_port')
|
|
|
|
->limit(15)->get()->toArray();
|
|
|
|
return $arr;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|