作者 lyh

gx

@@ -7,6 +7,7 @@ use App\Helper\FormGlobalsoApi; @@ -7,6 +7,7 @@ use App\Helper\FormGlobalsoApi;
7 use App\Models\Project\DeployBuild; 7 use App\Models\Project\DeployBuild;
8 use App\Models\Project\DeployOptimize; 8 use App\Models\Project\DeployOptimize;
9 use App\Models\Project\Project; 9 use App\Models\Project\Project;
  10 +use App\Services\ProjectServer;
10 use Carbon\Carbon; 11 use Carbon\Carbon;
11 use Illuminate\Console\Command; 12 use Illuminate\Console\Command;
12 use Illuminate\Support\Facades\DB; 13 use Illuminate\Support\Facades\DB;
@@ -54,12 +55,14 @@ class Count extends Command @@ -54,12 +55,14 @@ class Count extends Command
54 $arr = []; 55 $arr = [];
55 //统计时间 56 //统计时间
56 $arr['date'] = $yesterday; 57 $arr['date'] = $yesterday;
  58 + ProjectServer::useProject($v['id']);
57 //pv统计 59 //pv统计
58 $arr['pv_num'] = $this->pv_num($yesterday,$v['test_domain']); 60 $arr['pv_num'] = $this->pv_num($yesterday,$v['test_domain']);
59 //ip统计 61 //ip统计
60 $arr['ip_num'] = $this->ip_num($yesterday,$v['test_domain']); 62 $arr['ip_num'] = $this->ip_num($yesterday,$v['test_domain']);
  63 + DB::disconnect('custom_mysql');
61 //服务达标天数 64 //服务达标天数
62 - $arr['compliance_day'] = $this->compliance_day($v['test_domain']); 65 + $arr['compliance_day'] = $this->compliance_day($v['id']);
63 //剩余服务时常 66 //剩余服务时常
64 $arr['service_day'] = ((int)$v['service_duration'] - (int)$arr['compliance_day']) > 0 ? ((int)$v['service_duration'] - (int)$arr['compliance_day']) : 0; 67 $arr['service_day'] = ((int)$v['service_duration'] - (int)$arr['compliance_day']) > 0 ? ((int)$v['service_duration'] - (int)$arr['compliance_day']) : 0;
65 //项目id 68 //项目id
@@ -86,7 +89,7 @@ class Count extends Command @@ -86,7 +89,7 @@ class Count extends Command
86 * @time :2023/6/14 15:40 89 * @time :2023/6/14 15:40
87 */ 90 */
88 public function pv_num($yesterday,$domain){ 91 public function pv_num($yesterday,$domain){
89 - $pv = DB::table('gl_customer_visit_item')->whereDate('updated_date', $yesterday)->where('domain',$domain)->count(); 92 + $pv = DB::connection('custom_mysql')->table('gl_customer_visit_item')->whereDate('updated_date', $yesterday)->where('domain',$domain)->count();
90 return $pv; 93 return $pv;
91 } 94 }
92 95
@@ -97,7 +100,7 @@ class Count extends Command @@ -97,7 +100,7 @@ class Count extends Command
97 * @time :2023/6/14 15:40 100 * @time :2023/6/14 15:40
98 */ 101 */
99 public function ip_num($yesterday,$domain){ 102 public function ip_num($yesterday,$domain){
100 - $ip = DB::table('gl_customer_visit')->whereDate('updated_date', $yesterday)->where('domain',$domain)->count(); 103 + $ip = DB::connection('custom_mysql')->table('gl_customer_visit')->whereDate('updated_date', $yesterday)->where('domain',$domain)->count();
101 return $ip; 104 return $ip;
102 } 105 }
103 106
@@ -158,7 +161,7 @@ class Count extends Command @@ -158,7 +161,7 @@ class Count extends Command
158 */ 161 */
159 public function selectParam(){ 162 public function selectParam(){
160 $select = [ 163 $select = [
161 - 'gl_project.id AS user_id', 164 + 'gl_project.id AS id',
162 'gl_project.extend_type AS extend_type', 165 'gl_project.extend_type AS extend_type',
163 'gl_project_deploy_build.test_domain AS test_domain', 166 'gl_project_deploy_build.test_domain AS test_domain',
164 'gl_project_deploy_optimize.domain AS domain', 167 'gl_project_deploy_optimize.domain AS domain',
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
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\Services\ProjectServer;
6 use Carbon\Carbon; 7 use Carbon\Carbon;
7 use Illuminate\Console\Command; 8 use Illuminate\Console\Command;
8 use Illuminate\Support\Facades\DB; 9 use Illuminate\Support\Facades\DB;
@@ -50,7 +51,9 @@ class InquiryMonthlyCount extends Command @@ -50,7 +51,9 @@ class InquiryMonthlyCount extends Command
50 //按月统计询盘记录 51 //按月统计询盘记录
51 $arr = $this->inquiryCount($arr,$startTime,$endTime,$value['test_domain']); 52 $arr = $this->inquiryCount($arr,$startTime,$endTime,$value['test_domain']);
52 $arr = $this->flowCount($arr,$startTime,$endTime,$value['project_id']); 53 $arr = $this->flowCount($arr,$startTime,$endTime,$value['project_id']);
  54 + ProjectServer::useProject($value['project_id']);
53 $arr = $this->sourceCount($arr,$value['test_domain'],$startTime,$endTime); 55 $arr = $this->sourceCount($arr,$value['test_domain'],$startTime,$endTime);
  56 + DB::disconnect('custom_mysql');
54 $arr['created_at'] = date('Y-m-d H:i:s'); 57 $arr['created_at'] = date('Y-m-d H:i:s');
55 $arr['updated_at'] = date('Y-m-d H:i:s'); 58 $arr['updated_at'] = date('Y-m-d H:i:s');
56 $arr['project_id'] = $value['project_id']; 59 $arr['project_id'] = $value['project_id'];
@@ -128,21 +131,21 @@ class InquiryMonthlyCount extends Command @@ -128,21 +131,21 @@ class InquiryMonthlyCount extends Command
128 */ 131 */
129 public function sourceCount(&$arr,$domain,$startTime,$endTime){ 132 public function sourceCount(&$arr,$domain,$startTime,$endTime){
130 //访问来源前10 133 //访问来源前10
131 - $source = DB::table('gl_customer_visit') 134 + $source = DB::connection('custom_mysql')->table('gl_customer_visit')
132 ->select('referrer_url', DB::raw('COUNT(*) as count')) 135 ->select('referrer_url', DB::raw('COUNT(*) as count'))
133 ->groupBy('referrer_url')->where(['domain'=>$domain]) 136 ->groupBy('referrer_url')->where(['domain'=>$domain])
134 ->whereBetween('updated_date', [$startTime,$endTime]) 137 ->whereBetween('updated_date', [$startTime,$endTime])
135 ->orderByDesc('count')->limit(10)->get()->toArray(); 138 ->orderByDesc('count')->limit(10)->get()->toArray();
136 $arr['source'] = json_encode($source); 139 $arr['source'] = json_encode($source);
137 //访问国家前15 140 //访问国家前15
138 - $source_country = DB::table('gl_customer_visit') 141 + $source_country = DB::connection('custom_mysql')->table('gl_customer_visit')
139 ->select('country',DB::raw('COUNT(*) as ip'),DB::raw('SUM(depth) as pv')) 142 ->select('country',DB::raw('COUNT(*) as ip'),DB::raw('SUM(depth) as pv'))
140 ->groupBy('country')->where(['domain'=>$domain]) 143 ->groupBy('country')->where(['domain'=>$domain])
141 ->whereBetween('updated_date', [$startTime,$endTime]) 144 ->whereBetween('updated_date', [$startTime,$endTime])
142 ->orderBy('ip','desc')->limit(15)->get()->toArray(); 145 ->orderBy('ip','desc')->limit(15)->get()->toArray();
143 $arr['source_country'] = json_encode($source_country); 146 $arr['source_country'] = json_encode($source_country);
144 //受访界面前15 147 //受访界面前15
145 - $referrer_url = DB::table('gl_customer_visit') 148 + $referrer_url = DB::connection('custom_mysql')->table('gl_customer_visit')
146 ->select('url',DB::raw('COUNT(*) as num')) 149 ->select('url',DB::raw('COUNT(*) as num'))
147 ->orderBy('num','desc')->where(['domain'=>$domain]) 150 ->orderBy('num','desc')->where(['domain'=>$domain])
148 ->whereBetween('updated_date', [$startTime,$endTime]) 151 ->whereBetween('updated_date', [$startTime,$endTime])
@@ -150,7 +153,7 @@ class InquiryMonthlyCount extends Command @@ -150,7 +153,7 @@ class InquiryMonthlyCount extends Command
150 ->limit(15)->get()->toArray(); 153 ->limit(15)->get()->toArray();
151 $arr['referrer_url'] = json_encode($referrer_url); 154 $arr['referrer_url'] = json_encode($referrer_url);
152 //访问端口 155 //访问端口
153 - $referrer_port = DB::table('gl_customer_visit') 156 + $referrer_port = DB::connection('custom_mysql')->table('gl_customer_visit')
154 ->select('device_port',DB::raw('COUNT(*) as num')) 157 ->select('device_port',DB::raw('COUNT(*) as num'))
155 ->orderBy('num','desc')->where(['domain'=>$domain]) 158 ->orderBy('num','desc')->where(['domain'=>$domain])
156 ->whereBetween('updated_date', [$startTime,$endTime]) 159 ->whereBetween('updated_date', [$startTime,$endTime])
@@ -168,7 +171,7 @@ class InquiryMonthlyCount extends Command @@ -168,7 +171,7 @@ class InquiryMonthlyCount extends Command
168 */ 171 */
169 public function selectParam(){ 172 public function selectParam(){
170 $select = [ 173 $select = [
171 - 'gl_project.id AS user_id', 174 + 'gl_project.id AS id',
172 'gl_project.extend_type AS extend_type', 175 'gl_project.extend_type AS extend_type',
173 'gl_project_deploy_build.test_domain AS test_domain', 176 'gl_project_deploy_build.test_domain AS test_domain',
174 'gl_project_deploy_optimize.domain AS domain', 177 'gl_project_deploy_optimize.domain AS domain',
@@ -16,7 +16,8 @@ class Visit extends Base @@ -16,7 +16,8 @@ class Visit extends Base
16 16
17 //设置关联表名 17 //设置关联表名
18 protected $table = 'gl_customer_visit'; 18 protected $table = 'gl_customer_visit';
19 - 19 + //连接数据库
  20 + protected $connection = 'custom_mysql';
20 protected $appends = ['device_text']; 21 protected $appends = ['device_text'];
21 22
22 public static function deviceMap(){ 23 public static function deviceMap(){
@@ -14,4 +14,6 @@ class VisitItem extends Base @@ -14,4 +14,6 @@ class VisitItem extends Base
14 { 14 {
15 //设置关联表名 15 //设置关联表名
16 protected $table = 'gl_customer_visit_item'; 16 protected $table = 'gl_customer_visit_item';
  17 + //连接数据库
  18 + protected $connection = 'custom_mysql';
17 } 19 }