作者 lyh

gx

@@ -49,46 +49,83 @@ class UpgradeProjectCount extends Command @@ -49,46 +49,83 @@ class UpgradeProjectCount extends Command
49 $list = DB::connection('custom_mysql')->table('gl_customer_visit') 49 $list = DB::connection('custom_mysql')->table('gl_customer_visit')
50 ->select(DB::raw('DATE_FORMAT(updated_date, "%Y-%m") as month')) 50 ->select(DB::raw('DATE_FORMAT(updated_date, "%Y-%m") as month'))
51 ->groupBy('month')->get()->toArray(); 51 ->groupBy('month')->get()->toArray();
52 - echo date('Y-m-d H:i:s') . '数据:'.json_encode($list) . PHP_EOL;  
53 - $project = new Project();  
54 - $projectInfo = $project->read(['id'=>439]); 52 + foreach ($list as $k=>$v){
  53 + // 获取当月开始时间
  54 + $start = date('Y-m-01', strtotime($v['month']));
  55 + // 获取当月结束时间
  56 + $end = date('Y-m-t', strtotime($v['month']));
  57 + $arr['project_id'] = 439;
  58 + $arr['total'] = 70;
  59 + $arr['month'] = $v['month'];
  60 + $arr['country'] = '{"\u5c3c\u65e5\u5229\u4e9a":1,"\u5370\u5ea6\u5c3c\u897f\u4e9a":1,"\u4f0a\u6717":1}';
  61 + $arr = $this->pv_ip($arr,$start,$end);
  62 + $arr = $this->sourceCount($arr,$start,$end);
  63 + echo date('Y-m-d H:i:s') . '数据:'.json_encode($arr) . PHP_EOL;
  64 + }
55 echo date('Y-m-d H:i:s') . 'end' . PHP_EOL; 65 echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
56 } 66 }
57 67
58 /** 68 /**
59 - * @remark :询盘数量  
60 - * @name :inquiry_num 69 + * @remark :本月询盘总量
  70 + * @name :month_total
61 * @author :lyh 71 * @author :lyh
62 * @method :post 72 * @method :post
63 - * @time :2024/1/8 9:24 73 + * @time :2024/1/8 11:02
64 */ 74 */
65 - public function inquiry_num($day){  
66 - $count = DB::connection('custom_mysql')->table('gl_customer_visit')->whereDate('updated_date', $day)->where('is_inquiry',1)->count();  
67 - return $count; 75 + public function pv_ip(&$arr,$start,$end){
  76 + $pv_ip = DB::table('gl_count')
  77 + ->where(['project_id'=>439])
  78 + ->where('date','>=',$start.' 00:00:00')
  79 + ->where('date','<=',$end.' 23:59:59')
  80 + ->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'))
  81 + ->first();
  82 + $arr['pv'] = $pv_ip->pv_num;
  83 + $arr['ip'] = $pv_ip->ip_num;
  84 + $arr['month_total'] = $pv_ip->inquiry_num;
  85 + if($arr['ip'] != 0){
  86 + $arr['rate'] = round(($arr['month_total'] / $arr['ip']) * 10,2);
  87 + }
  88 + return $arr;
68 } 89 }
69 -  
70 /** 90 /**
71 - * @name :(统计pv)pv_num 91 + * @remark :来源访问前8
  92 + * @name :sourceCount
72 * @author :lyh 93 * @author :lyh
73 * @method :post 94 * @method :post
74 - * @time :2023/6/14 15:40 95 + * @time :2023/6/30 16:14
75 */ 96 */
76 - public function pv_num($day){  
77 - $pv = DB::connection('custom_mysql')->table('gl_customer_visit_item')->whereDate('updated_date', $day)->count();  
78 - return $pv; 97 + public function sourceCount(&$arr,$startTime,$endTime){
  98 + //访问来源前10
  99 + $source = DB::connection('custom_mysql')->table('gl_customer_visit')
  100 + ->select('referrer_url', DB::raw('COUNT(*) as count'))
  101 + ->groupBy('referrer_url')
  102 + ->whereBetween('updated_date', [$startTime,$endTime])
  103 + ->orderByDesc('count')->limit(10)->get()->toArray();
  104 + $arr['source'] = json_encode($source);
  105 + //访问国家前15
  106 + $source_country = DB::connection('custom_mysql')->table('gl_customer_visit')
  107 + ->select('country',DB::raw('COUNT(*) as ip'),DB::raw('SUM(depth) as pv'))
  108 + ->groupBy('country')
  109 + ->whereBetween('updated_date', [$startTime,$endTime])
  110 + ->orderBy('ip','desc')->limit(15)->get()->toArray();
  111 + $arr['source_country'] = json_encode($source_country);
  112 + //受访界面前15
  113 + $referrer_url = DB::connection('custom_mysql')->table('gl_customer_visit')
  114 + ->select('url',DB::raw('COUNT(*) as num'))
  115 + ->orderBy('num','desc')
  116 + ->whereBetween('updated_date', [$startTime,$endTime])
  117 + ->groupBy('url')
  118 + ->limit(15)->get()->toArray();
  119 + $arr['referrer_url'] = json_encode($referrer_url);
  120 + //访问端口
  121 + $referrer_port = DB::connection('custom_mysql')->table('gl_customer_visit')
  122 + ->select('device_port',DB::raw('COUNT(*) as num'))
  123 + ->orderBy('num','desc')
  124 + ->whereBetween('updated_date', [$startTime,$endTime])
  125 + ->groupBy('device_port')
  126 + ->limit(15)->get()->toArray();
  127 + $arr['referrer_port'] = json_encode($referrer_port);
  128 + return $arr;
79 } 129 }
80 130
81 - /**  
82 - * @name :(统计ip)ip_num  
83 - * @author :lyh  
84 - * @method :post  
85 - * @time :2023/6/14 15:40  
86 - */  
87 - public function ip_num($day){  
88 - $ip = DB::connection('custom_mysql')->table('gl_customer_visit')->whereDate('updated_date', $day)->count();  
89 - return $ip;  
90 - }  
91 -  
92 -  
93 -  
94 } 131 }