|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Logic\Bside\HomeCount;
|
|
|
|
|
|
|
|
use App\Helper\FormGlobalsoApi;
|
|
|
|
use App\Http\Logic\Bside\BaseLogic;
|
|
|
|
use App\Models\HomeCount\Count;
|
|
|
|
use App\Models\HomeCount\MonthCount;
|
|
|
|
use Carbon\Carbon;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
class MonthCountLogic extends BaseLogic
|
|
|
|
{
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
$this->model = new MonthCount();
|
|
|
|
$this->param = $this->requestAll;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取数据
|
|
|
|
* @name :getCountLists
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/7/3 9:39
|
|
|
|
*/
|
|
|
|
public function getCountLists($map,$page,$row = 10,$order = 'created_at',$filed = ['*']){
|
|
|
|
$lists = $this->model->lists($map,$page,$row,$order,$filed);
|
|
|
|
if(!empty($lists)){
|
|
|
|
$lists['list']['new'] = $this->currentMonthCount();
|
|
|
|
}
|
|
|
|
return $this->success($lists);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取当前月数据统计
|
|
|
|
* @name :currentMonth
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/7/3 9:55
|
|
|
|
*/
|
|
|
|
public function currentMonthCount(){
|
|
|
|
$startTime = Carbon::now()->startOfMonth()->toDateString();
|
|
|
|
$endTime = date('Y-m-d H:i:s',time());
|
|
|
|
$arr = [];
|
|
|
|
$arr = $this->inquiryCount($arr,$startTime,$endTime,$this->user['domain']);
|
|
|
|
$arr = $this->flowCount($arr,$startTime,$endTime,$this->user['project_id']);
|
|
|
|
$arr = $this->sourceCount($arr,$startTime,$endTime,$this->user['domain']);
|
|
|
|
return $this->success($arr);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @param $domain
|
|
|
|
* @param $project_id
|
|
|
|
* @remark :询盘按月统计
|
|
|
|
* @name :inquiryCount
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/6/30 14:29
|
|
|
|
*/
|
|
|
|
public function inquiryCount(&$arr,&$startTime,&$endTime,$domain){
|
|
|
|
//TODO::上线后注释
|
|
|
|
$domain = 'https://demomark.globalso.com/';
|
|
|
|
$inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000);
|
|
|
|
//总数
|
|
|
|
$arr['total'] = $inquiry_list['data']['total'];
|
|
|
|
//数据详情
|
|
|
|
$data = $inquiry_list['data']['data'];
|
|
|
|
$arr['month_total'] = 0;
|
|
|
|
$countryArr = [];
|
|
|
|
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[$v['country']] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
arsort($countryArr);
|
|
|
|
$top20 = array_slice($countryArr, 0, 15, true);
|
|
|
|
$arr['country'] = json_encode($top20);
|
|
|
|
return $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,$startTime,$endTime,$domain){
|
|
|
|
//访问来源前10
|
|
|
|
$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();
|
|
|
|
$arr['source'] = json_encode($source);
|
|
|
|
//访问国家前15
|
|
|
|
$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();
|
|
|
|
$arr['source_country'] = json_encode($source_country);
|
|
|
|
//受访界面前15
|
|
|
|
$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_url'] = json_encode($referrer_url);
|
|
|
|
//访问断后
|
|
|
|
$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();
|
|
|
|
$arr['referrer_port'] = json_encode($referrer_port);
|
|
|
|
return $arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :根据时间获取pv,ip
|
|
|
|
* @name :getIpPvCount
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/7/3 10:30
|
|
|
|
*/
|
|
|
|
public function getIpPvCount(){
|
|
|
|
$count = new Count();
|
|
|
|
$startTime = date("Y-m-d", strtotime("-9 months", mktime(0, 0, 0)));
|
|
|
|
$ensTime = date('Y-m-d',time());
|
|
|
|
$lists = $count->read(['date'=>['between',[$startTime,$ensTime]]]);
|
|
|
|
return $this->success($lists);
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|