|
@@ -3,8 +3,10 @@ |
|
@@ -3,8 +3,10 @@ |
|
3
|
namespace App\Console\Commands\MonthlyCount;
|
3
|
namespace App\Console\Commands\MonthlyCount;
|
|
4
|
|
4
|
|
|
5
|
use App\Helper\FormGlobalsoApi;
|
5
|
use App\Helper\FormGlobalsoApi;
|
|
|
|
6
|
+use App\Models\Project\DeployBuild;
|
|
6
|
use Carbon\Carbon;
|
7
|
use Carbon\Carbon;
|
|
7
|
use Illuminate\Console\Command;
|
8
|
use Illuminate\Console\Command;
|
|
|
|
9
|
+use Illuminate\Support\Facades\DB;
|
|
8
|
|
10
|
|
|
9
|
class InquiryMonthlyCount extends Command
|
11
|
class InquiryMonthlyCount extends Command
|
|
10
|
{
|
12
|
{
|
|
@@ -15,7 +17,7 @@ class InquiryMonthlyCount extends Command |
|
@@ -15,7 +17,7 @@ class InquiryMonthlyCount extends Command |
|
15
|
*
|
17
|
*
|
|
16
|
* @var string
|
18
|
* @var string
|
|
17
|
*/
|
19
|
*/
|
|
18
|
- protected $signature = 'yesterday_count';
|
20
|
+ protected $signature = 'month_count';
|
|
19
|
|
21
|
|
|
20
|
/**
|
22
|
/**
|
|
21
|
* The console command description.
|
23
|
* The console command description.
|
|
@@ -32,40 +34,125 @@ class InquiryMonthlyCount extends Command |
|
@@ -32,40 +34,125 @@ class InquiryMonthlyCount extends Command |
|
32
|
* @time :2023/6/30 9:32
|
34
|
* @time :2023/6/30 9:32
|
|
33
|
*/
|
35
|
*/
|
|
34
|
public function handle(){
|
36
|
public function handle(){
|
|
35
|
- //统计数据
|
|
|
|
36
|
- $arr = [];
|
37
|
+ $deployModel = new DeployBuild();
|
|
|
|
38
|
+ $list = $deployModel->list();
|
|
37
|
// 获取上个月的开始时间
|
39
|
// 获取上个月的开始时间
|
|
38
|
- $startTime = Carbon::now()->subMonth()->startOfMonth();
|
40
|
+ $startTime = Carbon::now()->subMonth()->startOfMonth()->toDateString();
|
|
39
|
// 获取上个月的结束时间
|
41
|
// 获取上个月的结束时间
|
|
40
|
- $endTime = Carbon::now()->subMonth()->endOfMonth();
|
42
|
+ $endTime = Carbon::now()->subMonth()->endOfMonth()->toDateString();
|
|
|
|
43
|
+ foreach ($list as $value){
|
|
|
|
44
|
+ //按月统计询盘记录
|
|
|
|
45
|
+ $this->inquiryCount($startTime,$endTime,$value['test_domain'],$value['project_id']);
|
|
|
|
46
|
+ }
|
|
|
|
47
|
+ return true;
|
|
41
|
}
|
48
|
}
|
|
42
|
|
49
|
|
|
43
|
/**
|
50
|
/**
|
|
44
|
- * @param $arr
|
|
|
|
45
|
* @param $domain
|
51
|
* @param $domain
|
|
46
|
- * @name :(询盘统计)inquiry
|
52
|
+ * @param $project_id
|
|
|
|
53
|
+ * @remark :询盘按月统计
|
|
|
|
54
|
+ * @name :inquiryCount
|
|
47
|
* @author :lyh
|
55
|
* @author :lyh
|
|
48
|
* @method :post
|
56
|
* @method :post
|
|
49
|
- * @time :2023/6/14 15:44
|
57
|
+ * @time :2023/6/30 14:29
|
|
50
|
*/
|
58
|
*/
|
|
51
|
- public function inquiry($arr,$domain){
|
59
|
+ public function inquiryCount($startTime,$endTime,$domain,$project_id){
|
|
|
|
60
|
+ //TODO::上线后注释
|
|
|
|
61
|
+ $domain = 'https://demomark.globalso.com/';
|
|
|
|
62
|
+ $arr = [];
|
|
52
|
$inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000);
|
63
|
$inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000);
|
|
53
|
- $arr['count'] = $inquiry_list['data']['total'];
|
|
|
|
54
|
- //询盘国家统计
|
|
|
|
55
|
- $countryData = $inquiry_list['data']['data'];
|
64
|
+ //总数
|
|
|
|
65
|
+ $arr['total'] = $inquiry_list['data']['total'];
|
|
|
|
66
|
+ //数据详情
|
|
|
|
67
|
+ $data = $inquiry_list['data']['data'];
|
|
|
|
68
|
+ $arr['month_total'] = 0;
|
|
56
|
$countryArr = [];
|
69
|
$countryArr = [];
|
|
57
|
- foreach ($countryData as $v1){
|
|
|
|
58
|
- if(isset($countryArr[$v1['country']])){
|
|
|
|
59
|
- $countryArr[$v1['country']]++;
|
70
|
+ foreach ($data as $v){
|
|
|
|
71
|
+ if(($startTime.' 00:00:00' <= $v['submit_time']) && $v['submit_time'] <= $endTime.' 23:59:59'){
|
|
|
|
72
|
+ $arr['month_total']++;
|
|
|
|
73
|
+ }
|
|
|
|
74
|
+ if(isset($countryArr[$v['country']])){
|
|
|
|
75
|
+ $countryArr[$v['country']]++;
|
|
60
|
}else{
|
76
|
}else{
|
|
61
|
- $countryArr[$v1['country']] = 0;
|
77
|
+ $countryArr[$v['country']] = 0;
|
|
62
|
}
|
78
|
}
|
|
63
|
}
|
79
|
}
|
|
|
|
80
|
+ // 获取当前日期时间
|
|
|
|
81
|
+ $arr['month'] = Carbon::now()->subMonth()->format('Y-m');
|
|
64
|
arsort($countryArr);
|
82
|
arsort($countryArr);
|
|
65
|
- $top20 = array_slice($countryArr, 0, 20, true);
|
83
|
+ $top20 = array_slice($countryArr, 0, 15, true);
|
|
66
|
$arr['country'] = json_encode($top20);
|
84
|
$arr['country'] = json_encode($top20);
|
|
|
|
85
|
+ $this->flowCount($arr,$startTime,$endTime,$project_id);
|
|
|
|
86
|
+ $this->sourceCount($arr,$domain,$startTime,$endTime);
|
|
|
|
87
|
+ $arr['created_at'] = date('Y-m-d H:i:s');
|
|
|
|
88
|
+ $arr['updated_at'] = date('Y-m-d H:i:s');
|
|
|
|
89
|
+ $arr['project_id'] = $project_id;
|
|
|
|
90
|
+ DB::table('gl_inquiry_month_count')->insert($arr);
|
|
|
|
91
|
+ }
|
|
67
|
|
92
|
|
|
|
|
93
|
+ /**
|
|
|
|
94
|
+ * @remark :流量统计
|
|
|
|
95
|
+ * @name :flowCount
|
|
|
|
96
|
+ * @author :lyh
|
|
|
|
97
|
+ * @method :post
|
|
|
|
98
|
+ * @time :2023/6/30 14:31
|
|
|
|
99
|
+ */
|
|
|
|
100
|
+ public function flowCount(&$arr,$startTime,$endTime,$project_id){
|
|
|
|
101
|
+ $pv_ip = DB::table('gl_count')
|
|
|
|
102
|
+ ->where(['project_id'=>$project_id])
|
|
|
|
103
|
+ ->where('date','>=',$startTime->toDateString().' 00:00:00')
|
|
|
|
104
|
+ ->where('date','<=',$endTime->toDateString().' 23:59:59')
|
|
|
|
105
|
+ ->select(DB::raw('SUM(pv_num) as pv_num'), DB::raw('SUM(ip_num) as ip_num'))
|
|
|
|
106
|
+ ->first();
|
|
|
|
107
|
+ $arr['pv'] = $pv_ip['pv_num'];
|
|
|
|
108
|
+ $arr['ip'] = $pv_ip['ip_num'];
|
|
|
|
109
|
+ if($arr['ip'] != 0){
|
|
|
|
110
|
+ $arr['rate'] = round(($arr['month_total'] / $arr['ip']) * 10,2);
|
|
|
|
111
|
+ }
|
|
68
|
return $arr;
|
112
|
return $arr;
|
|
69
|
}
|
113
|
}
|
|
70
|
|
114
|
|
|
|
|
115
|
+ /**
|
|
|
|
116
|
+ * @remark :来源访问前8
|
|
|
|
117
|
+ * @name :sourceCount
|
|
|
|
118
|
+ * @author :lyh
|
|
|
|
119
|
+ * @method :post
|
|
|
|
120
|
+ * @time :2023/6/30 16:14
|
|
|
|
121
|
+ */
|
|
|
|
122
|
+ public function sourceCount(&$arr,$domain,$startTime,$endTime){
|
|
|
|
123
|
+ //访问来源前10
|
|
|
|
124
|
+ $arr['source'] = DB::table('gl_customer_visit')
|
|
|
|
125
|
+ ->select('referrer_url', DB::raw('COUNT(*) as count'))
|
|
|
|
126
|
+ ->groupBy('referrer_url')->where(['domain'=>$domain])
|
|
|
|
127
|
+ ->where('updated_date','>=',$startTime->toDateString())
|
|
|
|
128
|
+ ->where('updated_date','<=',$endTime->toDateString())
|
|
|
|
129
|
+ ->orderByDesc('count')->limit(10)->get()->toArray();
|
|
|
|
130
|
+ if(!empty($data)){
|
|
|
|
131
|
+ $arr['source'] = json_encode($arr['source']);
|
|
|
|
132
|
+ }
|
|
|
|
133
|
+ //访问国家前15
|
|
|
|
134
|
+ $arr['source_country'] = DB::table('gl_customer_visit')
|
|
|
|
135
|
+ ->select('country',DB::raw('COUNT(*) as ip'),DB::raw('SUM(depth) as pv'))
|
|
|
|
136
|
+ ->groupBy('country')->where(['domain'=>$domain])
|
|
|
|
137
|
+ ->where('updated_date','>=',$startTime->toDateString())
|
|
|
|
138
|
+ ->where('updated_date','<=',$endTime->toDateString())
|
|
|
|
139
|
+ ->orderBy('ip','desc')->limit(15)->get()->toArray();
|
|
|
|
140
|
+ //受访界面前15
|
|
|
|
141
|
+ $arr['referrer_url'] = DB::table('gl_customer_visit_item')
|
|
|
|
142
|
+ ->select('url',DB::raw('COUNT(*) as num'))
|
|
|
|
143
|
+ ->orderBy('num','desc')->where(['domain'=>$domain])
|
|
|
|
144
|
+ ->where('updated_date','>=',$startTime->toDateString())
|
|
|
|
145
|
+ ->where('updated_date','<=',$endTime->toDateString())
|
|
|
|
146
|
+ ->groupBy('url')
|
|
|
|
147
|
+ ->limit(15)->get()->toArray();
|
|
|
|
148
|
+ //访问断后
|
|
|
|
149
|
+ $arr['referrer_port'] = DB::table('gl_customer_visit_item')
|
|
|
|
150
|
+ ->select('device_port',DB::raw('COUNT(*) as num'))
|
|
|
|
151
|
+ ->orderBy('num','desc')->where(['domain'=>$domain])
|
|
|
|
152
|
+ ->where('updated_date','>=',$startTime->toDateString())
|
|
|
|
153
|
+ ->where('updated_date','<=',$endTime->toDateString())
|
|
|
|
154
|
+ ->groupBy('device_port')
|
|
|
|
155
|
+ ->limit(15)->get()->toArray();
|
|
|
|
156
|
+ return $arr;
|
|
|
|
157
|
+ }
|
|
71
|
} |
158
|
} |