作者 lyh

gx

@@ -41,8 +41,19 @@ class InquiryMonthlyCount extends Command @@ -41,8 +41,19 @@ class InquiryMonthlyCount extends Command
41 // 获取上个月的结束时间 41 // 获取上个月的结束时间
42 $endTime = Carbon::now()->subMonth()->endOfMonth(); 42 $endTime = Carbon::now()->subMonth()->endOfMonth();
43 foreach ($list as $value){ 43 foreach ($list as $value){
  44 + $arr = [];
44 //按月统计询盘记录 45 //按月统计询盘记录
45 - $this->inquiryCount($startTime,$endTime,$value['test_domain'],$value['project_id']); 46 + $arr = $this->inquiryCount($startTime,$endTime,$value['test_domain']);
  47 + $arr = $this->flowCount($arr,$startTime,$endTime,$value['project_id']);
  48 + $arr = $this->sourceCount($arr,$value['test_domain'],$startTime,$endTime);
  49 + $arr['created_at'] = date('Y-m-d H:i:s');
  50 + $arr['updated_at'] = date('Y-m-d H:i:s');
  51 + $arr['project_id'] = $value['project_id'];
  52 + // 获取当前日期时间
  53 + $arr['month'] = Carbon::now()->subMonth()->format('Y-m');
  54 + var_dump($arr);
  55 + die();
  56 + DB::table('gl_month_count')->insert($arr);
46 } 57 }
47 return true; 58 return true;
48 } 59 }
@@ -56,10 +67,9 @@ class InquiryMonthlyCount extends Command @@ -56,10 +67,9 @@ class InquiryMonthlyCount extends Command
56 * @method :post 67 * @method :post
57 * @time :2023/6/30 14:29 68 * @time :2023/6/30 14:29
58 */ 69 */
59 - public function inquiryCount(&$startTime,&$endTime,$domain,$project_id){ 70 + public function inquiryCount(&$arr,&$startTime,&$endTime,$domain){
60 //TODO::上线后注释 71 //TODO::上线后注释
61 $domain = 'https://demomark.globalso.com/'; 72 $domain = 'https://demomark.globalso.com/';
62 - $arr = [];  
63 $inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000); 73 $inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000);
64 //总数 74 //总数
65 $arr['total'] = $inquiry_list['data']['total']; 75 $arr['total'] = $inquiry_list['data']['total'];
@@ -77,17 +87,10 @@ class InquiryMonthlyCount extends Command @@ -77,17 +87,10 @@ class InquiryMonthlyCount extends Command
77 $countryArr[$v['country']] = 0; 87 $countryArr[$v['country']] = 0;
78 } 88 }
79 } 89 }
80 - // 获取当前日期时间  
81 - $arr['month'] = Carbon::now()->subMonth()->format('Y-m');  
82 arsort($countryArr); 90 arsort($countryArr);
83 $top20 = array_slice($countryArr, 0, 15, true); 91 $top20 = array_slice($countryArr, 0, 15, true);
84 $arr['country'] = json_encode($top20); 92 $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_month_count')->insert($arr); 93 + return $arr;
91 } 94 }
92 95
93 /** 96 /**
@@ -121,47 +124,39 @@ class InquiryMonthlyCount extends Command @@ -121,47 +124,39 @@ class InquiryMonthlyCount extends Command
121 */ 124 */
122 public function sourceCount(&$arr,$domain,$startTime,$endTime){ 125 public function sourceCount(&$arr,$domain,$startTime,$endTime){
123 //访问来源前10 126 //访问来源前10
124 - $arr['source'] = DB::table('gl_customer_visit') 127 + $source = DB::table('gl_customer_visit')
125 ->select('referrer_url', DB::raw('COUNT(*) as count')) 128 ->select('referrer_url', DB::raw('COUNT(*) as count'))
126 ->groupBy('referrer_url')->where(['domain'=>$domain]) 129 ->groupBy('referrer_url')->where(['domain'=>$domain])
127 ->where('updated_date','>=',$startTime->toDateString()) 130 ->where('updated_date','>=',$startTime->toDateString())
128 ->where('updated_date','<=',$endTime->toDateString()) 131 ->where('updated_date','<=',$endTime->toDateString())
129 ->orderByDesc('count')->limit(10)->get()->toArray(); 132 ->orderByDesc('count')->limit(10)->get()->toArray();
130 - if(!empty($arr['source'])){  
131 - $arr['source'] = json_encode($arr['source']);  
132 - } 133 + $arr['source'] = json_encode($source);
133 //访问国家前15 134 //访问国家前15
134 - $arr['source_country'] = DB::table('gl_customer_visit') 135 + $source_country = DB::table('gl_customer_visit')
135 ->select('country',DB::raw('COUNT(*) as ip'),DB::raw('SUM(depth) as pv')) 136 ->select('country',DB::raw('COUNT(*) as ip'),DB::raw('SUM(depth) as pv'))
136 ->groupBy('country')->where(['domain'=>$domain]) 137 ->groupBy('country')->where(['domain'=>$domain])
137 ->where('updated_date','>=',$startTime->toDateString()) 138 ->where('updated_date','>=',$startTime->toDateString())
138 ->where('updated_date','<=',$endTime->toDateString()) 139 ->where('updated_date','<=',$endTime->toDateString())
139 ->orderBy('ip','desc')->limit(15)->get()->toArray(); 140 ->orderBy('ip','desc')->limit(15)->get()->toArray();
140 - if(!empty($arr['source_country'])){  
141 - $arr['source_country'] = json_encode($arr['source_country']);  
142 - } 141 + $arr['source_country'] = json_encode($source_country);
143 //受访界面前15 142 //受访界面前15
144 - $arr['referrer_url'] = DB::table('gl_customer_visit_item') 143 + $referrer_url = DB::table('gl_customer_visit_item')
145 ->select('url',DB::raw('COUNT(*) as num')) 144 ->select('url',DB::raw('COUNT(*) as num'))
146 ->orderBy('num','desc')->where(['domain'=>$domain]) 145 ->orderBy('num','desc')->where(['domain'=>$domain])
147 ->where('updated_date','>=',$startTime->toDateString()) 146 ->where('updated_date','>=',$startTime->toDateString())
148 ->where('updated_date','<=',$endTime->toDateString()) 147 ->where('updated_date','<=',$endTime->toDateString())
149 ->groupBy('url') 148 ->groupBy('url')
150 ->limit(15)->get()->toArray(); 149 ->limit(15)->get()->toArray();
151 - if(!empty($arr['referrer_url'])){  
152 - $arr['referrer_url'] = json_encode($arr['referrer_url']);  
153 - } 150 + $arr['referrer_url'] = json_encode($referrer_url);
154 //访问断后 151 //访问断后
155 - $arr['referrer_port'] = DB::table('gl_customer_visit_item') 152 + $referrer_port = DB::table('gl_customer_visit_item')
156 ->select('device_port',DB::raw('COUNT(*) as num')) 153 ->select('device_port',DB::raw('COUNT(*) as num'))
157 ->orderBy('num','desc')->where(['domain'=>$domain]) 154 ->orderBy('num','desc')->where(['domain'=>$domain])
158 ->where('updated_date','>=',$startTime->toDateString()) 155 ->where('updated_date','>=',$startTime->toDateString())
159 ->where('updated_date','<=',$endTime->toDateString()) 156 ->where('updated_date','<=',$endTime->toDateString())
160 ->groupBy('device_port') 157 ->groupBy('device_port')
161 ->limit(15)->get()->toArray(); 158 ->limit(15)->get()->toArray();
162 - if(!empty($arr['referrer_port'])){  
163 - $arr['referrer_port'] = json_encode($arr['referrer_port']);  
164 - } 159 + $arr['referrer_port'] = json_encode($referrer_port);
165 return $arr; 160 return $arr;
166 } 161 }
167 } 162 }