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