作者 lyh

gx

... ... @@ -49,46 +49,83 @@ class UpgradeProjectCount extends Command
$list = DB::connection('custom_mysql')->table('gl_customer_visit')
->select(DB::raw('DATE_FORMAT(updated_date, "%Y-%m") as month'))
->groupBy('month')->get()->toArray();
echo date('Y-m-d H:i:s') . '数据:'.json_encode($list) . PHP_EOL;
$project = new Project();
$projectInfo = $project->read(['id'=>439]);
foreach ($list as $k=>$v){
// 获取当月开始时间
$start = date('Y-m-01', strtotime($v['month']));
// 获取当月结束时间
$end = date('Y-m-t', strtotime($v['month']));
$arr['project_id'] = 439;
$arr['total'] = 70;
$arr['month'] = $v['month'];
$arr['country'] = '{"\u5c3c\u65e5\u5229\u4e9a":1,"\u5370\u5ea6\u5c3c\u897f\u4e9a":1,"\u4f0a\u6717":1}';
$arr = $this->pv_ip($arr,$start,$end);
$arr = $this->sourceCount($arr,$start,$end);
echo date('Y-m-d H:i:s') . '数据:'.json_encode($arr) . PHP_EOL;
}
echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
}
/**
* @remark :询盘数量
* @name :inquiry_num
* @remark :本月询盘总量
* @name :month_total
* @author :lyh
* @method :post
* @time :2024/1/8 9:24
* @time :2024/1/8 11:02
*/
public function inquiry_num($day){
$count = DB::connection('custom_mysql')->table('gl_customer_visit')->whereDate('updated_date', $day)->where('is_inquiry',1)->count();
return $count;
public function pv_ip(&$arr,$start,$end){
$pv_ip = DB::table('gl_count')
->where(['project_id'=>439])
->where('date','>=',$start.' 00:00:00')
->where('date','<=',$end.' 23:59:59')
->select(DB::raw('SUM(pv_num) as pv_num'), DB::raw('SUM(ip_num) as ip_num'),DB::raw('SUM(inquiry_num) as inquiry_num'))
->first();
$arr['pv'] = $pv_ip->pv_num;
$arr['ip'] = $pv_ip->ip_num;
$arr['month_total'] = $pv_ip->inquiry_num;
if($arr['ip'] != 0){
$arr['rate'] = round(($arr['month_total'] / $arr['ip']) * 10,2);
}
/**
* @name :(统计pv)pv_num
* @author :lyh
* @method :post
* @time :2023/6/14 15:40
*/
public function pv_num($day){
$pv = DB::connection('custom_mysql')->table('gl_customer_visit_item')->whereDate('updated_date', $day)->count();
return $pv;
return $arr;
}
/**
* @name :(统计ip)ip_num
* @remark :来源访问前8
* @name :sourceCount
* @author :lyh
* @method :post
* @time :2023/6/14 15:40
* @time :2023/6/30 16:14
*/
public function ip_num($day){
$ip = DB::connection('custom_mysql')->table('gl_customer_visit')->whereDate('updated_date', $day)->count();
return $ip;
public function sourceCount(&$arr,$startTime,$endTime){
//访问来源前10
$source = DB::connection('custom_mysql')->table('gl_customer_visit')
->select('referrer_url', DB::raw('COUNT(*) as count'))
->groupBy('referrer_url')
->whereBetween('updated_date', [$startTime,$endTime])
->orderByDesc('count')->limit(10)->get()->toArray();
$arr['source'] = json_encode($source);
//访问国家前15
$source_country = DB::connection('custom_mysql')->table('gl_customer_visit')
->select('country',DB::raw('COUNT(*) as ip'),DB::raw('SUM(depth) as pv'))
->groupBy('country')
->whereBetween('updated_date', [$startTime,$endTime])
->orderBy('ip','desc')->limit(15)->get()->toArray();
$arr['source_country'] = json_encode($source_country);
//受访界面前15
$referrer_url = DB::connection('custom_mysql')->table('gl_customer_visit')
->select('url',DB::raw('COUNT(*) as num'))
->orderBy('num','desc')
->whereBetween('updated_date', [$startTime,$endTime])
->groupBy('url')
->limit(15)->get()->toArray();
$arr['referrer_url'] = json_encode($referrer_url);
//访问端口
$referrer_port = DB::connection('custom_mysql')->table('gl_customer_visit')
->select('device_port',DB::raw('COUNT(*) as num'))
->orderBy('num','desc')
->whereBetween('updated_date', [$startTime,$endTime])
->groupBy('device_port')
->limit(15)->get()->toArray();
$arr['referrer_port'] = json_encode($referrer_port);
return $arr;
}
}
... ...