MonthCountLogic.php
7.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?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 App\Models\Inquiry\InquiryOther;
use App\Models\Project\DeployOptimize;
use App\Services\ProjectServer;
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,$order = 'created_at',$filed = ['*']){
$map['project_id'] = $this->user['project_id'];
$lists = $this->model->list($map,$order,$filed);
$lists['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',time());
$arr = [];
ProjectServer::useProject($this->user['project_id']);
$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']);
$arr['month'] = date('Y-m',time());
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){
$inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000);
if(!empty($inquiry_list)){
//总数
$arr['total'] = $inquiry_list['data']['total'] ?? 0;
//数据详情
$data = $inquiry_list['data']['data'] ?? '';
$arr['month_total'] = 0;
$countryArr = [];
if(isset($data) && !empty($data)){
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']] = 1;
}
}
}
}
//加上其他询盘
$arr['total'] += InquiryOther::count();
$arr['month_total'] += InquiryOther::whereBetween('submit_time',[$startTime, $endTime])->count();
$countryData = InquiryOther::whereBetween('submit_time',[$startTime, $endTime])
->select("country",DB::raw('COUNT(*) as count'))
->groupBy('country')->get()->toArray();
foreach ($countryData as $v1){
if(isset($countryArr[$v1['country']])){
$countryArr[$v1['country']] += $v1['count'];
}else{
$countryArr[$v1['country']] = $v1['count'];
}
}
arsort($countryArr);
$top20 = array_slice($countryArr, 0, 15, true);
$arr['country'] = $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])
->whereBetween('date', [$startTime,$endTime])
->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;
$arr['rate'] = 0;
if($arr['ip'] != 0){
$arr['rate'] = round(($arr['month_total'] / $arr['ip']) * 100,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::connection('custom_mysql')->table('gl_customer_visit')
->select('referrer_url', DB::raw('COUNT(*) as count'))
->groupBy('referrer_url')->where(['domain'=>$domain])
->whereBetween('updated_date', [$startTime,$endTime])
->orderByDesc('count')->limit(10)->get()->toArray();
$arr['source'] = $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')->where(['domain'=>$domain])
->whereBetween('updated_date', [$startTime,$endTime])
->orderBy('ip','desc')->limit(15)->get()->toArray();
$arr['source_country'] = $source_country;
//受访界面前15
$referrer_url = DB::connection('custom_mysql')->table('gl_customer_visit')
->select('url',DB::raw('COUNT(*) as num'))
->orderBy('num','desc')->where(['domain'=>$domain])
->whereBetween('updated_date', [$startTime,$endTime])
->groupBy('url')
->limit(15)->get()->toArray();
$arr['referrer_url'] = $referrer_url;
//访问断后
$referrer_port = DB::connection('custom_mysql')->table('gl_customer_visit')
->select('device_port',DB::raw('COUNT(*) as num'))
->orderBy('num','desc')->where(['domain'=>$domain])
->whereBetween('updated_date', [$startTime,$endTime])
->groupBy('device_port')
->limit(15)->get()->toArray();
$arr['referrer_port'] = $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->list(['date'=>['between',[$startTime,$ensTime]],'project_id'=>$this->user['project_id']]);
$groupedData = [];
foreach ($lists as $k=>$v){
$month = date('Y-m', strtotime($v['date']));
if(!isset($groupedData[$month])){
$groupedData[$month] = [];
}
if(empty($v['country'])){
$v['country'] = ['中国'=>0];
}
$groupedData[$month][] = $v;
}
return $this->success($groupedData);
}
/**
* @remark :获取关键字列表
* @name :getKeywordLists
* @author :lyh
* @method :post
* @time :2023/7/4 10:19
*/
public function getKeywordLists(){
$optimizeModel = new DeployOptimize();
$info = $optimizeModel->read(['project_id'=>$this->user['project_id']],['main_keywords','customer_keywords']);
return $this->success($info);
}
}