|
|
|
1
|
+<?php
|
|
|
|
2
|
+/**
|
|
|
|
3
|
+ * @remark :
|
|
|
|
4
|
+ * @name :UpgradeProjectCount.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\HomeCount\MonthCount;
|
|
|
|
14
|
+use App\Models\Project\Project;
|
|
|
|
15
|
+use App\Models\Visit\Visit;
|
|
|
|
16
|
+use App\Services\ProjectServer;
|
|
|
|
17
|
+use Illuminate\Console\Command;
|
|
|
|
18
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
19
|
+use App\Models\HomeCount\Count;
|
|
|
|
20
|
+
|
|
|
|
21
|
+class UpgradeProjectCount extends Command
|
|
|
|
22
|
+{
|
|
|
|
23
|
+ /**
|
|
|
|
24
|
+ * The name and signature of the console command.
|
|
|
|
25
|
+ *
|
|
|
|
26
|
+ * @var string
|
|
|
|
27
|
+ */
|
|
|
|
28
|
+ protected $signature = 'upgrade_month_count';
|
|
|
|
29
|
+
|
|
|
|
30
|
+ /**
|
|
|
|
31
|
+ * The console command description.
|
|
|
|
32
|
+ *
|
|
|
|
33
|
+ * @var string
|
|
|
|
34
|
+ */
|
|
|
|
35
|
+ protected $description = '升级项目统计';
|
|
|
|
36
|
+
|
|
|
|
37
|
+ public function handle(){
|
|
|
|
38
|
+ ProjectServer::useProject(439);
|
|
|
|
39
|
+ $this->count();
|
|
|
|
40
|
+ DB::disconnect('custom_mysql');
|
|
|
|
41
|
+ }
|
|
|
|
42
|
+
|
|
|
|
43
|
+ /**
|
|
|
|
44
|
+ * @remark :日统计记录
|
|
|
|
45
|
+ * @name :count
|
|
|
|
46
|
+ * @author :lyh
|
|
|
|
47
|
+ * @method :post
|
|
|
|
48
|
+ * @time :2024/1/8 9:05
|
|
|
|
49
|
+ */
|
|
|
|
50
|
+ public function count(){
|
|
|
|
51
|
+ $list = DB::connection('custom_mysql')->table('gl_customer_visit')
|
|
|
|
52
|
+ ->select(DB::raw('DATE_FORMAT(updated_date, "%Y-%m") as month'))
|
|
|
|
53
|
+ ->groupBy('month')->get()->toArray();
|
|
|
|
54
|
+ foreach ($list as $k=>$v){
|
|
|
|
55
|
+ $v = (array)$v;
|
|
|
|
56
|
+ $monthCountModel = new MonthCount();
|
|
|
|
57
|
+ $info = $monthCountModel->read(['month'=>$v['month']]);
|
|
|
|
58
|
+ // 获取当月开始时间
|
|
|
|
59
|
+ $start = date('Y-m-01', strtotime($v['month']));
|
|
|
|
60
|
+ // 获取当月结束时间
|
|
|
|
61
|
+ $end = date('Y-m-t', strtotime($v['month']));
|
|
|
|
62
|
+ $arr['project_id'] = 439;
|
|
|
|
63
|
+ $inquiry_list = (new FormGlobalsoApi())->getInquiryList('www.cnzyl.com','',1,100000000);
|
|
|
|
64
|
+ //总数
|
|
|
|
65
|
+ $arr['total'] = $inquiry_list['data']['total'] ?? 0;
|
|
|
|
66
|
+ $arr['month'] = $v['month'];
|
|
|
|
67
|
+ $arr['country'] = '{"\u5c3c\u65e5\u5229\u4e9a":1,"\u5370\u5ea6\u5c3c\u897f\u4e9a":1,"\u4f0a\u6717":1}';
|
|
|
|
68
|
+ $arr = $this->pv_ip($arr,$start,$end);
|
|
|
|
69
|
+ $arr = $this->sourceCount($arr,$start,$end);
|
|
|
|
70
|
+ if($info === false){
|
|
|
|
71
|
+ $selectedDate = $start;
|
|
|
|
72
|
+ $firstDayOfNextMonth = date('Y-m-01 01:00:00', strtotime("$selectedDate +1 month"));
|
|
|
|
73
|
+ $arr['created_at'] = $firstDayOfNextMonth;
|
|
|
|
74
|
+ $arr['updated_at'] = $firstDayOfNextMonth;
|
|
|
|
75
|
+ $monthCountModel->insert($arr);
|
|
|
|
76
|
+ }else{
|
|
|
|
77
|
+ $monthCountModel->edit($arr,['id'=>$info['id']]);
|
|
|
|
78
|
+ }
|
|
|
|
79
|
+ }
|
|
|
|
80
|
+ echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
|
|
|
|
81
|
+ }
|
|
|
|
82
|
+
|
|
|
|
83
|
+ /**
|
|
|
|
84
|
+ * @remark :本月询盘总量
|
|
|
|
85
|
+ * @name :month_total
|
|
|
|
86
|
+ * @author :lyh
|
|
|
|
87
|
+ * @method :post
|
|
|
|
88
|
+ * @time :2024/1/8 11:02
|
|
|
|
89
|
+ */
|
|
|
|
90
|
+ public function pv_ip(&$arr,$start,$end){
|
|
|
|
91
|
+ $pv_ip = DB::table('gl_count')
|
|
|
|
92
|
+ ->where(['project_id'=>439])
|
|
|
|
93
|
+ ->where('date','>=',$start.' 00:00:00')
|
|
|
|
94
|
+ ->where('date','<=',$end.' 23:59:59')
|
|
|
|
95
|
+ ->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'))
|
|
|
|
96
|
+ ->first();
|
|
|
|
97
|
+ $arr['pv'] = $pv_ip->pv_num;
|
|
|
|
98
|
+ $arr['ip'] = $pv_ip->ip_num;
|
|
|
|
99
|
+ $arr['month_total'] = $pv_ip->inquiry_num;
|
|
|
|
100
|
+ if($arr['ip'] != 0){
|
|
|
|
101
|
+ $arr['rate'] = round(($arr['month_total'] / $arr['ip']) * 10,2);
|
|
|
|
102
|
+ }
|
|
|
|
103
|
+ return $arr;
|
|
|
|
104
|
+ }
|
|
|
|
105
|
+ /**
|
|
|
|
106
|
+ * @remark :来源访问前8
|
|
|
|
107
|
+ * @name :sourceCount
|
|
|
|
108
|
+ * @author :lyh
|
|
|
|
109
|
+ * @method :post
|
|
|
|
110
|
+ * @time :2023/6/30 16:14
|
|
|
|
111
|
+ */
|
|
|
|
112
|
+ public function sourceCount(&$arr,$startTime,$endTime){
|
|
|
|
113
|
+ //访问来源前10
|
|
|
|
114
|
+ $source = DB::connection('custom_mysql')->table('gl_customer_visit')
|
|
|
|
115
|
+ ->select('referrer_url', DB::raw('COUNT(*) as count'))
|
|
|
|
116
|
+ ->groupBy('referrer_url')
|
|
|
|
117
|
+ ->whereBetween('updated_date', [$startTime,$endTime])
|
|
|
|
118
|
+ ->orderByDesc('count')->limit(10)->get()->toArray();
|
|
|
|
119
|
+ $arr['source'] = json_encode($source);
|
|
|
|
120
|
+ //访问国家前15
|
|
|
|
121
|
+ $source_country = DB::connection('custom_mysql')->table('gl_customer_visit')
|
|
|
|
122
|
+ ->select('country',DB::raw('COUNT(*) as ip'),DB::raw('SUM(depth) as pv'))
|
|
|
|
123
|
+ ->groupBy('country')
|
|
|
|
124
|
+ ->whereBetween('updated_date', [$startTime,$endTime])
|
|
|
|
125
|
+ ->orderBy('ip','desc')->limit(15)->get()->toArray();
|
|
|
|
126
|
+ $arr['source_country'] = json_encode($source_country);
|
|
|
|
127
|
+ //受访界面前15
|
|
|
|
128
|
+ $referrer_url = DB::connection('custom_mysql')->table('gl_customer_visit')
|
|
|
|
129
|
+ ->select('url',DB::raw('COUNT(*) as num'))
|
|
|
|
130
|
+ ->orderBy('num','desc')
|
|
|
|
131
|
+ ->whereBetween('updated_date', [$startTime,$endTime])
|
|
|
|
132
|
+ ->groupBy('url')
|
|
|
|
133
|
+ ->limit(15)->get()->toArray();
|
|
|
|
134
|
+ $arr['referrer_url'] = json_encode($referrer_url);
|
|
|
|
135
|
+ //访问端口
|
|
|
|
136
|
+ $referrer_port = DB::connection('custom_mysql')->table('gl_customer_visit')
|
|
|
|
137
|
+ ->select('device_port',DB::raw('COUNT(*) as num'))
|
|
|
|
138
|
+ ->orderBy('num','desc')
|
|
|
|
139
|
+ ->whereBetween('updated_date', [$startTime,$endTime])
|
|
|
|
140
|
+ ->groupBy('device_port')
|
|
|
|
141
|
+ ->limit(15)->get()->toArray();
|
|
|
|
142
|
+ $arr['referrer_port'] = json_encode($referrer_port);
|
|
|
|
143
|
+ return $arr;
|
|
|
|
144
|
+ }
|
|
|
|
145
|
+
|
|
|
|
146
|
+} |