|
|
|
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
|
+} |