作者 lyh

gx

@@ -2,7 +2,13 @@ @@ -2,7 +2,13 @@
2 2
3 namespace App\Http\Controllers\Bside\HomeCount; 3 namespace App\Http\Controllers\Bside\HomeCount;
4 4
  5 +use App\Enums\Common\Code;
  6 +use App\Helper\FormGlobalsoApi;
5 use App\Http\Controllers\Bside\BaseController; 7 use App\Http\Controllers\Bside\BaseController;
  8 +use App\Http\Logic\Bside\HomeCount\MonthCountLogic;
  9 +use App\Models\Project\DeployBuild;
  10 +use Carbon\Carbon;
  11 +use Illuminate\Support\Facades\DB;
6 12
7 /** 13 /**
8 * @remark :月统计报告 14 * @remark :月统计报告
@@ -12,6 +18,7 @@ use App\Http\Controllers\Bside\BaseController; @@ -12,6 +18,7 @@ use App\Http\Controllers\Bside\BaseController;
12 */ 18 */
13 class MonthCountController extends BaseController 19 class MonthCountController extends BaseController
14 { 20 {
  21 +
15 /** 22 /**
16 * @remark :月统计报告 23 * @remark :月统计报告
17 * @name :Count 24 * @name :Count
@@ -19,7 +26,20 @@ class MonthCountController extends BaseController @@ -19,7 +26,20 @@ class MonthCountController extends BaseController
19 * @method :post 26 * @method :post
20 * @time :2023/6/30 17:58 27 * @time :2023/6/30 17:58
21 */ 28 */
22 - public function InquiryCount(){ 29 + public function lists(MonthCountLogic $monthCountLogic){
  30 + $lists = $monthCountLogic->getCountLists($this->map,$this->page,$this->row,$this->order);
  31 + $this->response('success',Code::SUCCESS,$lists);
  32 + }
23 33
  34 + /**
  35 + * @remark :根据时间获取ip,pv
  36 + * @name :getIpPvCount
  37 + * @author :lyh
  38 + * @method :post
  39 + * @time :2023/7/3 11:04
  40 + */
  41 + public function getIpPvCount(MonthCountLogic $monthCountLogic){
  42 + $lists = $monthCountLogic->getIpPvCount();
  43 + $this->response('success',Code::SUCCESS,$lists);
24 } 44 }
25 } 45 }
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Bside\HomeCount;
  4 +
  5 +use App\Helper\FormGlobalsoApi;
  6 +use App\Http\Logic\Bside\BaseLogic;
  7 +use App\Models\HomeCount\Count;
  8 +use App\Models\HomeCount\MonthCount;
  9 +use Carbon\Carbon;
  10 +use Illuminate\Support\Facades\DB;
  11 +
  12 +class MonthCountLogic extends BaseLogic
  13 +{
  14 + public function __construct()
  15 + {
  16 + parent::__construct();
  17 + $this->model = new MonthCount();
  18 + $this->param = $this->requestAll;
  19 + }
  20 +
  21 + /**
  22 + * @remark :获取数据
  23 + * @name :getCountLists
  24 + * @author :lyh
  25 + * @method :post
  26 + * @time :2023/7/3 9:39
  27 + */
  28 + public function getCountLists($map,$page,$row = 10,$order = 'created_at',$filed = ['*']){
  29 + $lists = $this->model->lists($map,$page,$row,$order,$filed);
  30 + if(!empty($lists)){
  31 + $lists['list']['new'] = $this->currentMonthCount();
  32 + }
  33 + return $this->success($lists);
  34 + }
  35 +
  36 + /**
  37 + * @remark :获取当前月数据统计
  38 + * @name :currentMonth
  39 + * @author :lyh
  40 + * @method :post
  41 + * @time :2023/7/3 9:55
  42 + */
  43 + public function currentMonthCount(){
  44 + $startTime = Carbon::now()->startOfMonth()->toDateString();
  45 + $endTime = date('Y-m-d H:i:s',time());
  46 + $arr = [];
  47 + $arr = $this->inquiryCount($arr,$startTime,$endTime,$this->user['domain']);
  48 + $arr = $this->flowCount($arr,$startTime,$endTime,$this->user['project_id']);
  49 + $arr = $this->sourceCount($arr,$startTime,$endTime,$this->user['domain']);
  50 + return $this->success($arr);
  51 + }
  52 + /**
  53 + * @param $domain
  54 + * @param $project_id
  55 + * @remark :询盘按月统计
  56 + * @name :inquiryCount
  57 + * @author :lyh
  58 + * @method :post
  59 + * @time :2023/6/30 14:29
  60 + */
  61 + public function inquiryCount(&$arr,&$startTime,&$endTime,$domain){
  62 + //TODO::上线后注释
  63 + $domain = 'https://demomark.globalso.com/';
  64 + $inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000);
  65 + //总数
  66 + $arr['total'] = $inquiry_list['data']['total'];
  67 + //数据详情
  68 + $data = $inquiry_list['data']['data'];
  69 + $arr['month_total'] = 0;
  70 + $countryArr = [];
  71 + foreach ($data as $v){
  72 + if(($startTime.' 00:00:00' <= $v['submit_time']) && $v['submit_time'] <= $endTime.' 23:59:59'){
  73 + $arr['month_total']++;
  74 + }
  75 + if(isset($countryArr[$v['country']])){
  76 + $countryArr[$v['country']]++;
  77 + }else{
  78 + $countryArr[$v['country']] = 0;
  79 + }
  80 + }
  81 + arsort($countryArr);
  82 + $top20 = array_slice($countryArr, 0, 15, true);
  83 + $arr['country'] = json_encode($top20);
  84 + return $arr;
  85 + }
  86 +
  87 + /**
  88 + * @remark :流量统计
  89 + * @name :flowCount
  90 + * @author :lyh
  91 + * @method :post
  92 + * @time :2023/6/30 14:31
  93 + */
  94 + public function flowCount(&$arr,&$startTime,&$endTime,$project_id){
  95 + $pv_ip = DB::table('gl_count')
  96 + ->where(['project_id'=>$project_id])
  97 + ->where('date','>=',$startTime->toDateString().' 00:00:00')
  98 + ->where('date','<=',$endTime->toDateString().' 23:59:59')
  99 + ->select(DB::raw('SUM(pv_num) as pv_num'), DB::raw('SUM(ip_num) as ip_num'))
  100 + ->first();
  101 + $arr['pv'] = $pv_ip->pv_num;
  102 + $arr['ip'] = $pv_ip->ip_num;
  103 + if($arr['ip'] != 0){
  104 + $arr['rate'] = round(($arr['month_total'] / $arr['ip']) * 10,2);
  105 + }
  106 + return $arr;
  107 + }
  108 +
  109 + /**
  110 + * @remark :来源访问前8
  111 + * @name :sourceCount
  112 + * @author :lyh
  113 + * @method :post
  114 + * @time :2023/6/30 16:14
  115 + */
  116 + public function sourceCount(&$arr,$startTime,$endTime,$domain){
  117 + //访问来源前10
  118 + $source = DB::table('gl_customer_visit')
  119 + ->select('referrer_url', DB::raw('COUNT(*) as count'))
  120 + ->groupBy('referrer_url')->where(['domain'=>$domain])
  121 + ->where('updated_date','>=',$startTime->toDateString())
  122 + ->where('updated_date','<=',$endTime->toDateString())
  123 + ->orderByDesc('count')->limit(10)->get()->toArray();
  124 + $arr['source'] = json_encode($source);
  125 + //访问国家前15
  126 + $source_country = DB::table('gl_customer_visit')
  127 + ->select('country',DB::raw('COUNT(*) as ip'),DB::raw('SUM(depth) as pv'))
  128 + ->groupBy('country')->where(['domain'=>$domain])
  129 + ->where('updated_date','>=',$startTime->toDateString())
  130 + ->where('updated_date','<=',$endTime->toDateString())
  131 + ->orderBy('ip','desc')->limit(15)->get()->toArray();
  132 + $arr['source_country'] = json_encode($source_country);
  133 + //受访界面前15
  134 + $referrer_url = DB::table('gl_customer_visit_item')
  135 + ->select('url',DB::raw('COUNT(*) as num'))
  136 + ->orderBy('num','desc')->where(['domain'=>$domain])
  137 + ->where('updated_date','>=',$startTime->toDateString())
  138 + ->where('updated_date','<=',$endTime->toDateString())
  139 + ->groupBy('url')
  140 + ->limit(15)->get()->toArray();
  141 + $arr['referrer_url'] = json_encode($referrer_url);
  142 + //访问断后
  143 + $referrer_port = DB::table('gl_customer_visit_item')
  144 + ->select('device_port',DB::raw('COUNT(*) as num'))
  145 + ->orderBy('num','desc')->where(['domain'=>$domain])
  146 + ->where('updated_date','>=',$startTime->toDateString())
  147 + ->where('updated_date','<=',$endTime->toDateString())
  148 + ->groupBy('device_port')
  149 + ->limit(15)->get()->toArray();
  150 + $arr['referrer_port'] = json_encode($referrer_port);
  151 + return $arr;
  152 + }
  153 +
  154 + /**
  155 + * @remark :根据时间获取pv,ip
  156 + * @name :getIpPvCount
  157 + * @author :lyh
  158 + * @method :post
  159 + * @time :2023/7/3 10:30
  160 + */
  161 + public function getIpPvCount(){
  162 + $count = new Count();
  163 + $startTime = date("Y-m-d", strtotime("-9 months", mktime(0, 0, 0)));
  164 + $ensTime = date('Y-m-d',time());
  165 + $lists = $count->read(['date'=>['between',[$startTime,$ensTime]]]);
  166 + return $this->success($lists);
  167 + }
  168 +}
@@ -293,6 +293,12 @@ Route::middleware(['bloginauth'])->group(function () { @@ -293,6 +293,12 @@ Route::middleware(['bloginauth'])->group(function () {
293 Route::any('/item', [\App\Http\Controllers\Bside\VisitController::class, 'item'])->name('visit_item'); 293 Route::any('/item', [\App\Http\Controllers\Bside\VisitController::class, 'item'])->name('visit_item');
294 }); 294 });
295 295
  296 + //访问数据
  297 + Route::prefix('month')->group(function () {
  298 + Route::any('/', [\App\Http\Controllers\Bside\HomeCount\MonthCountController::class, 'lists'])->name('month_lists');
  299 + Route::any('/', [\App\Http\Controllers\Bside\HomeCount\MonthCountController::class, 'getIpPvCount'])->name('month_getIpPvCount');
  300 + });
  301 +
296 // 流量统计 302 // 流量统计
297 Route::prefix('stat')->group(function () { 303 Route::prefix('stat')->group(function () {
298 // 访问来源 304 // 访问来源