|
1
|
-<?php
|
|
|
|
2
|
-
|
|
|
|
3
|
-namespace App\Console\Commands\MonthlyCount;
|
|
|
|
4
|
-
|
|
|
|
5
|
-use App\Helper\FormGlobalsoApi;
|
|
|
|
6
|
-use App\Models\Domain\DomainInfo;
|
|
|
|
7
|
-use App\Models\Inquiry\InquiryFormData;
|
|
|
|
8
|
-use App\Models\Project\Project;
|
|
|
|
9
|
-use App\Services\ProjectServer;
|
|
|
|
10
|
-use Carbon\Carbon;
|
|
|
|
11
|
-use Illuminate\Console\Command;
|
|
|
|
12
|
-use Illuminate\Support\Facades\DB;
|
|
|
|
13
|
-use Illuminate\Support\Facades\Log;
|
|
|
|
14
|
-
|
|
|
|
15
|
-class InquiryMonthlyCount extends Command
|
|
|
|
16
|
-{
|
|
|
|
17
|
- const STATUS_ERROR = 400;
|
|
|
|
18
|
- public $error = 0;
|
|
|
|
19
|
- /**
|
|
|
|
20
|
- * The name and signature of the console command.
|
|
|
|
21
|
- *
|
|
|
|
22
|
- * @var string
|
|
|
|
23
|
- */
|
|
|
|
24
|
- protected $signature = 'month_count';
|
|
|
|
25
|
-
|
|
|
|
26
|
- /**
|
|
|
|
27
|
- * The console command description.
|
|
|
|
28
|
- *
|
|
|
|
29
|
- * @var string
|
|
|
|
30
|
- */
|
|
|
|
31
|
- protected $description = '询盘月报告统计';
|
|
|
|
32
|
-
|
|
|
|
33
|
- /**
|
|
|
|
34
|
- * @remark :询盘月报告
|
|
|
|
35
|
- * @name :handle
|
|
|
|
36
|
- * @author :lyh
|
|
|
|
37
|
- * @method :post
|
|
|
|
38
|
- * @time :2023/6/30 9:32
|
|
|
|
39
|
- */
|
|
|
|
40
|
- public function handle(){
|
|
|
|
41
|
- $list = DB::table('gl_project')->where('gl_project.extend_type','=',0)
|
|
|
|
42
|
- ->where('gl_project.type','!=',0)
|
|
|
|
43
|
- ->leftJoin('gl_project_deploy_build', 'gl_project.id', '=', 'gl_project_deploy_build.project_id')
|
|
|
|
44
|
- ->leftJoin('gl_project_deploy_optimize', 'gl_project.id', '=', 'gl_project_deploy_optimize.project_id')
|
|
|
|
45
|
- ->select($this->selectParam())->get()->toArray();
|
|
|
|
46
|
- // 获取上个月的开始时间
|
|
|
|
47
|
- $startTime = Carbon::now()->subMonth()->startOfMonth()->toDateString();
|
|
|
|
48
|
- // 获取上个月的结束时间
|
|
|
|
49
|
- $endTime = Carbon::now()->subMonth()->endOfMonth()->toDateString();
|
|
|
|
50
|
- $domainInfo = new DomainInfo();
|
|
|
|
51
|
- foreach ($list as $value){
|
|
|
|
52
|
- $value = (array)$value;
|
|
|
|
53
|
- if($value['type'] == Project::TYPE_ZERO){
|
|
|
|
54
|
- continue;
|
|
|
|
55
|
- }
|
|
|
|
56
|
- if(!empty($value['domain'])){
|
|
|
|
57
|
- $info = $domainInfo->read(['id'=>$value['domain']]);
|
|
|
|
58
|
- if($info !== false){
|
|
|
|
59
|
- $value['test_domain'] = $info['domain'];
|
|
|
|
60
|
- }
|
|
|
|
61
|
- }
|
|
|
|
62
|
- $arr = [];
|
|
|
|
63
|
- //按月统计询盘记录
|
|
|
|
64
|
- $arr = $this->inquiryCount($arr,$startTime,$endTime,$value['test_domain'],$value['project_id']);
|
|
|
|
65
|
- $arr = $this->flowCount($arr,$startTime,$endTime,$value['project_id']);
|
|
|
|
66
|
- ProjectServer::useProject($value['project_id']);
|
|
|
|
67
|
- $arr = $this->sourceCount($arr,$value['test_domain'],$startTime,$endTime);
|
|
|
|
68
|
- DB::disconnect('custom_mysql');
|
|
|
|
69
|
- $arr['created_at'] = date('Y-m-d H:i:s');
|
|
|
|
70
|
- $arr['updated_at'] = date('Y-m-d H:i:s');
|
|
|
|
71
|
- $arr['project_id'] = $value['project_id'];
|
|
|
|
72
|
- // 获取当前日期时间
|
|
|
|
73
|
- $arr['month'] = Carbon::now()->subMonth()->format('Y-m');
|
|
|
|
74
|
- try {
|
|
|
|
75
|
- DB::table('gl_month_count')->insert($arr);
|
|
|
|
76
|
- Log::channel('month_count')->error('success:project_id .'.$arr['project_id']);
|
|
|
|
77
|
- }catch (\Exception $e){
|
|
|
|
78
|
- Log::channel('month_count')->error('month_count:error ' . $e->getMessage());
|
|
|
|
79
|
- }
|
|
|
|
80
|
- }
|
|
|
|
81
|
- return true;
|
|
|
|
82
|
- }
|
|
|
|
83
|
-
|
|
|
|
84
|
- /**
|
|
|
|
85
|
- * @param $domain
|
|
|
|
86
|
- * @param $project_id
|
|
|
|
87
|
- * @remark :询盘按月统计
|
|
|
|
88
|
- * @name :inquiryCount
|
|
|
|
89
|
- * @author :lyh
|
|
|
|
90
|
- * @method :post
|
|
|
|
91
|
- * @time :2023/6/30 14:29
|
|
|
|
92
|
- */
|
|
|
|
93
|
- public function inquiryCount(&$arr,&$startTime,&$endTime,$domain,$project_id){
|
|
|
|
94
|
- $inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000);
|
|
|
|
95
|
- //总数
|
|
|
|
96
|
- $arr['total'] = $inquiry_list['data']['total'] ?? 0;
|
|
|
|
97
|
- //数据详情
|
|
|
|
98
|
- $data = $inquiry_list['data']['data'] ?? 0;
|
|
|
|
99
|
- $arr['month_total'] = 0;
|
|
|
|
100
|
- $countryArr = [];
|
|
|
|
101
|
- $arr['country'] = "";
|
|
|
|
102
|
- if(!empty($data)){
|
|
|
|
103
|
- foreach ($data as $v){
|
|
|
|
104
|
- if(($startTime.' 00:00:00' <= $v['submit_time']) && $v['submit_time'] <= $endTime.' 23:59:59'){
|
|
|
|
105
|
- $arr['month_total']++;
|
|
|
|
106
|
- if(isset($countryArr[$v['country']])){
|
|
|
|
107
|
- $countryArr[$v['country']]++;
|
|
|
|
108
|
- }else{
|
|
|
|
109
|
- $countryArr[$v['country']] = 1;
|
|
|
|
110
|
- }
|
|
|
|
111
|
- }
|
|
|
|
112
|
- }
|
|
|
|
113
|
- }
|
|
|
|
114
|
- //加上其他询盘
|
|
|
|
115
|
- ProjectServer::useProject($project_id);
|
|
|
|
116
|
- $arr['total'] += InquiryFormData::count();
|
|
|
|
117
|
- $arr['month_total'] += InquiryFormData::getCount([$startTime, $endTime]);
|
|
|
|
118
|
- $countryData = InquiryFormData::getCountryCount([$startTime, $endTime]);
|
|
|
|
119
|
- foreach ($countryData as $v1){
|
|
|
|
120
|
- if(isset($countryArr[$v1['country']])){
|
|
|
|
121
|
- $countryArr[$v1['country']] += $v1['count'];
|
|
|
|
122
|
- }else{
|
|
|
|
123
|
- $countryArr[$v1['country']] = $v1['count'];
|
|
|
|
124
|
- }
|
|
|
|
125
|
- }
|
|
|
|
126
|
-
|
|
|
|
127
|
- arsort($countryArr);
|
|
|
|
128
|
- $top20 = array_slice($countryArr, 0, 15, true);
|
|
|
|
129
|
- $arr['country'] = json_encode($top20);
|
|
|
|
130
|
- return $arr;
|
|
|
|
131
|
- }
|
|
|
|
132
|
-
|
|
|
|
133
|
- /**
|
|
|
|
134
|
- * @remark :流量统计
|
|
|
|
135
|
- * @name :flowCount
|
|
|
|
136
|
- * @author :lyh
|
|
|
|
137
|
- * @method :post
|
|
|
|
138
|
- * @time :2023/6/30 14:31
|
|
|
|
139
|
- */
|
|
|
|
140
|
- public function flowCount(&$arr,&$startTime,&$endTime,$project_id){
|
|
|
|
141
|
- $pv_ip = DB::table('gl_count')
|
|
|
|
142
|
- ->where(['project_id'=>$project_id])
|
|
|
|
143
|
- ->where('date','>=',$startTime.' 00:00:00')
|
|
|
|
144
|
- ->where('date','<=',$endTime.' 23:59:59')
|
|
|
|
145
|
- ->select(DB::raw('SUM(pv_num) as pv_num'), DB::raw('SUM(ip_num) as ip_num'))
|
|
|
|
146
|
- ->first();
|
|
|
|
147
|
- $arr['pv'] = $pv_ip->pv_num;
|
|
|
|
148
|
- $arr['ip'] = $pv_ip->ip_num;
|
|
|
|
149
|
- if($arr['ip'] != 0){
|
|
|
|
150
|
- $arr['rate'] = round(($arr['month_total'] / $arr['ip']) * 10,2);
|
|
|
|
151
|
- }
|
|
|
|
152
|
- return $arr;
|
|
|
|
153
|
- }
|
|
|
|
154
|
-
|
|
|
|
155
|
- /**
|
|
|
|
156
|
- * @remark :来源访问前8
|
|
|
|
157
|
- * @name :sourceCount
|
|
|
|
158
|
- * @author :lyh
|
|
|
|
159
|
- * @method :post
|
|
|
|
160
|
- * @time :2023/6/30 16:14
|
|
|
|
161
|
- */
|
|
|
|
162
|
- public function sourceCount(&$arr,$domain,$startTime,$endTime){
|
|
|
|
163
|
- //访问来源前10
|
|
|
|
164
|
- $source = DB::connection('custom_mysql')->table('gl_customer_visit')
|
|
|
|
165
|
- ->select('referrer_url', DB::raw('COUNT(*) as count'))
|
|
|
|
166
|
- ->groupBy('referrer_url')
|
|
|
|
167
|
- ->whereBetween('updated_date', [$startTime,$endTime])
|
|
|
|
168
|
- ->orderByDesc('count')->limit(10)->get()->toArray();
|
|
|
|
169
|
- $arr['source'] = json_encode($source);
|
|
|
|
170
|
- //访问国家前15
|
|
|
|
171
|
- $source_country = DB::connection('custom_mysql')->table('gl_customer_visit')
|
|
|
|
172
|
- ->select('country',DB::raw('COUNT(*) as ip'),DB::raw('SUM(depth) as pv'))
|
|
|
|
173
|
- ->groupBy('country')
|
|
|
|
174
|
- ->whereBetween('updated_date', [$startTime,$endTime])
|
|
|
|
175
|
- ->orderBy('ip','desc')->limit(15)->get()->toArray();
|
|
|
|
176
|
- $arr['source_country'] = json_encode($source_country);
|
|
|
|
177
|
- //受访界面前15
|
|
|
|
178
|
- $referrer_url = DB::connection('custom_mysql')->table('gl_customer_visit')
|
|
|
|
179
|
- ->select('url',DB::raw('COUNT(*) as num'))
|
|
|
|
180
|
- ->orderBy('num','desc')
|
|
|
|
181
|
- ->whereBetween('updated_date', [$startTime,$endTime])
|
|
|
|
182
|
- ->groupBy('url')
|
|
|
|
183
|
- ->limit(15)->get()->toArray();
|
|
|
|
184
|
- $arr['referrer_url'] = json_encode($referrer_url);
|
|
|
|
185
|
- //访问端口
|
|
|
|
186
|
- $referrer_port = DB::connection('custom_mysql')->table('gl_customer_visit')
|
|
|
|
187
|
- ->select('device_port',DB::raw('COUNT(*) as num'))
|
|
|
|
188
|
- ->orderBy('num','desc')
|
|
|
|
189
|
- ->whereBetween('updated_date', [$startTime,$endTime])
|
|
|
|
190
|
- ->groupBy('device_port')
|
|
|
|
191
|
- ->limit(15)->get()->toArray();
|
|
|
|
192
|
- $arr['referrer_port'] = json_encode($referrer_port);
|
|
|
|
193
|
- return $arr;
|
|
|
|
194
|
- }
|
|
|
|
195
|
-
|
|
|
|
196
|
- /**
|
|
|
|
197
|
- * @name :(查询参数设置)selectParam
|
|
|
|
198
|
- * @author :lyh
|
|
|
|
199
|
- * @method :post
|
|
|
|
200
|
- * @time :2023/6/14 15:00
|
|
|
|
201
|
- */
|
|
|
|
202
|
- public function selectParam(){
|
|
|
|
203
|
- $select = [
|
|
|
|
204
|
- 'gl_project.id AS id',
|
|
|
|
205
|
- 'gl_project.type AS type',
|
|
|
|
206
|
- 'gl_project.extend_type AS extend_type',
|
|
|
|
207
|
- 'gl_project_deploy_build.test_domain AS test_domain',
|
|
|
|
208
|
- 'gl_project_deploy_optimize.domain AS domain',
|
|
|
|
209
|
- 'gl_project_deploy_build.project_id AS project_id',
|
|
|
|
210
|
- 'gl_project.cooperate_date AS cooperate_date',
|
|
|
|
211
|
- 'gl_project_deploy_build.service_duration AS service_duration',
|
|
|
|
212
|
- ];
|
|
|
|
213
|
- return $select;
|
|
|
|
214
|
- }
|
|
|
|
215
|
-} |
|
|