作者 lyh

gx

@@ -2,13 +2,17 @@ @@ -2,13 +2,17 @@
2 2
3 namespace App\Console\Commands\YesterdayCount; 3 namespace App\Console\Commands\YesterdayCount;
4 4
  5 +use App\Helper\Common;
  6 +use App\Helper\FormGlobalsoApi;
5 use App\Models\CustomerVisit\CustomerVisitItem; 7 use App\Models\CustomerVisit\CustomerVisitItem;
6 use App\Models\Project\DeployBuild; 8 use App\Models\Project\DeployBuild;
  9 +use Carbon\Carbon;
7 use Illuminate\Console\Command; 10 use Illuminate\Console\Command;
8 use Illuminate\Support\Facades\DB; 11 use Illuminate\Support\Facades\DB;
9 12
10 class Yesterday extends Command 13 class Yesterday extends Command
11 { 14 {
  15 + const STATUS_ERROR = 400;
12 public $error = 0; 16 public $error = 0;
13 /** 17 /**
14 * The name and signature of the console command. 18 * The name and signature of the console command.
@@ -24,7 +28,7 @@ class Yesterday extends Command @@ -24,7 +28,7 @@ class Yesterday extends Command
24 */ 28 */
25 protected $description = '统计昨日数据'; 29 protected $description = '统计昨日数据';
26 /** 30 /**
27 - * @name :(定时执行)handle 31 + * @name :(定时执行生成昨日数据统计)handle
28 * @author :lyh 32 * @author :lyh
29 * @method :post 33 * @method :post
30 * @time :2023/5/12 14:48 34 * @time :2023/5/12 14:48
@@ -34,16 +38,31 @@ class Yesterday extends Command @@ -34,16 +38,31 @@ class Yesterday extends Command
34 $deployModel = new DeployBuild(); 38 $deployModel = new DeployBuild();
35 $list = $deployModel->list(); 39 $list = $deployModel->list();
36 $data = []; 40 $data = [];
  41 + $yesterday = Carbon::yesterday()->toDateString();
37 foreach ($list as $v){ 42 foreach ($list as $v){
38 $arr = []; 43 $arr = [];
39 - $yesterday = now()->subDay();  
40 - $arr['yesterday_pv_num'] = DB::table('gl_customer_visit_item')->whereDate('created_at', $yesterday)->where('domain',$v['test_domain'])->count();  
41 - $arr['yesterday_ip_num'] = DB::table('gl_customer_visit')->whereDate('created_at', $yesterday)->where('domain',$v['test_domain'])->count();  
42 - $arr['inquiry_num'] = DB::table('gl_inquiry_set')->whereDate('created_at', $yesterday)->where('project_id',$v['project_id'])->count();  
43 - $arr['date'] = date('Y-m-d',time()); 44 + $arr['yesterday_pv_num'] = DB::table('gl_customer_visit_item')->whereDate('date', $yesterday)->where('domain',$v['test_domain'])->count();
  45 + $arr['yesterday_ip_num'] = DB::table('gl_customer_visit')->whereDate('date', $yesterday)->where('domain',$v['test_domain'])->count();
  46 + $inquiry_list = (new FormGlobalsoApi())->getInquiryList($v['test_domain']);
  47 + if($inquiry_list['status'] == self::STATUS_ERROR){
  48 + $arr['inquiry_num'] = 0;
  49 + }else{
  50 + $arr['inquiry_num'] = count($inquiry_list['data']['total']);
  51 + }
  52 + $arr['date'] = $yesterday;
  53 + $rank_info = DB::table('gl_rank_data')->where(['updated_date'=>$yesterday,'lang'=>''])->select(['compliance_day'])->first();
  54 + if(empty($rank_info)){
  55 + $arr['compliance_day'] = 0;
  56 + }else{
  57 + $arr['compliance_day'] = $rank_info->compliance_day;
  58 + }
  59 + $arr['service_day'] = $v['service_duration'] - Common::getDaysToTargetDate($v['created_at']);
  60 + $arr['project_id'] = $v['project_id'];
  61 + $arr['created_at'] = date('Y-m-d H:i:s');
  62 + $arr['updated_at'] = date('Y-m-d H:i:s');
44 $data[] = $arr; 63 $data[] = $arr;
45 } 64 }
46 - DB::table('gl_yesterday_count')->insert($data); 65 + DB::table('gl_count')->insert($data);
47 echo $this->error; 66 echo $this->error;
48 } 67 }
49 } 68 }
@@ -143,14 +143,9 @@ class Common @@ -143,14 +143,9 @@ class Common
143 */ 143 */
144 public static function getDaysToTargetDate($targetDateTime) 144 public static function getDaysToTargetDate($targetDateTime)
145 { 145 {
146 - // 当前日期时间  
147 - $currentDateTime = new DateTime();  
148 - // 目标日期时间  
149 - $targetDateTimeObj = new DateTime($targetDateTime);  
150 - // 计算日期时间差距  
151 - $interval = $currentDateTime->diff($targetDateTimeObj);  
152 - // 获取总天数差距  
153 - $days = $interval->days;  
154 - return $days; 146 + $currentTimestamp = time();
  147 + $targetTimestamp = strtotime($targetDateTime);
  148 + $days = floor(($currentTimestamp - $targetTimestamp) / (60 * 60 * 24));
  149 + return (int)$days;
155 } 150 }
156 } 151 }
@@ -223,3 +223,24 @@ if (!function_exists('getThisWeekStarDate')) { @@ -223,3 +223,24 @@ if (!function_exists('getThisWeekStarDate')) {
223 return Carbon::now()->startOfWeek()->toDateString(); 223 return Carbon::now()->startOfWeek()->toDateString();
224 } 224 }
225 } 225 }
  226 +
  227 +if (!function_exists('object_to_array')) {
  228 + /**
  229 + * 获取本周一的日期
  230 + * @return mixed
  231 + * @author zbj
  232 + * @date 2023/5/11
  233 + */
  234 + function object_to_array($data)
  235 + {
  236 + if(is_object($data)){
  237 + $data = (array)$data;
  238 + }else{
  239 + foreach ($data as $k => $v){
  240 + $data[$k] = object_to_array($v);
  241 + }
  242 + }
  243 + return $data;
  244 + }
  245 +}
  246 +
@@ -4,24 +4,42 @@ namespace App\Http\Controllers\Bside\HomeCount; @@ -4,24 +4,42 @@ namespace App\Http\Controllers\Bside\HomeCount;
4 4
5 use App\Enums\Common\Code; 5 use App\Enums\Common\Code;
6 use App\Helper\Common; 6 use App\Helper\Common;
  7 +use App\Helper\FormGlobalsoApi;
7 use App\Http\Controllers\Bside\BaseController; 8 use App\Http\Controllers\Bside\BaseController;
  9 +use App\Http\Logic\Bside\HomeCount\CountLogic;
8 use App\Models\Project\DeployBuild; 10 use App\Models\Project\DeployBuild;
  11 +use Carbon\Carbon;
9 use Illuminate\Support\Facades\DB; 12 use Illuminate\Support\Facades\DB;
10 13
11 class CountController extends BaseController 14 class CountController extends BaseController
12 { 15 {
  16 + const STATUS_ERROR = 400;
13 /** 17 /**
14 * @name :(昨日统计数据)yesterday_count 18 * @name :(昨日统计数据)yesterday_count
15 * @author :lyh 19 * @author :lyh
16 * @method :post 20 * @method :post
17 * @time :2023/5/23 17:23 21 * @time :2023/5/23 17:23
18 */ 22 */
19 - public function count(){ 23 + public function count(CountLogic $countLogic){
20 $data = []; 24 $data = [];
  25 + //TODO::昨日数据统计
  26 + $data['yesterday'] = $countLogic->yesterday_count();
21 //TODO::全球搜方案信息 27 //TODO::全球搜方案信息
  28 + $data['scheme_info'] = $countLogic->scheme_info();
22 //TODO::网站访问量统计 29 //TODO::网站访问量统计
  30 + $data['total_visit'] = $countLogic->total_count($data['yesterday']['inquiry_num']);
23 //TODO::关键字排名数据 31 //TODO::关键字排名数据
24 - //TODO::关键字排名数据 32 + $data['keyword_data'] = $countLogic->keyword_data_count();
  33 + //TODO::相关数据统计
  34 + $data['with_data'] = $countLogic->with_data_count();
  35 + //TODO::30天pv,ip统计
  36 + $data['visit_data'] = $countLogic->visit_data_count();
  37 + //TODO::询盘国家统计
  38 + $data['country_data'] = $countLogic->inquiry_country_count();
  39 + //TODO::来源排名
  40 + $data['country_data'] = $countLogic->referrer_count();
  41 + //TODO::访问国家前10
  42 + $data['access_country_count'] = $countLogic->access_country_count();
25 return $this->response('success',Code::SUCCESS,$data); 43 return $this->response('success',Code::SUCCESS,$data);
26 } 44 }
27 45
@@ -32,23 +50,34 @@ class CountController extends BaseController @@ -32,23 +50,34 @@ class CountController extends BaseController
32 * @time :2023/5/24 9:13 50 * @time :2023/5/24 9:13
33 */ 51 */
34 public function yesterday(){ 52 public function yesterday(){
35 - var_dump(11111);  
36 - die();  
37 $deployModel = new DeployBuild(); 53 $deployModel = new DeployBuild();
38 $list = $deployModel->list(); 54 $list = $deployModel->list();
39 $data = []; 55 $data = [];
  56 + $yesterday = Carbon::yesterday()->toDateString();
40 foreach ($list as $v){ 57 foreach ($list as $v){
41 $arr = []; 58 $arr = [];
42 - $yesterday = now()->subDay();  
43 - $arr['yesterday_pv_num'] = DB::table('gl_customer_visit_item')->whereDate('created_at', $yesterday)->where('domain',$v['test_domain'])->count();  
44 - $arr['yesterday_ip_num'] = DB::table('gl_customer_visit')->whereDate('created_at', $yesterday)->where('domain',$v['test_domain'])->count();  
45 - $arr['inquiry_num'] = DB::table('gl_inquiry_set')->whereDate('created_at', $yesterday)->where('project_id',$v['project_id'])->count();  
46 - $arr['date'] = date('Y-m-d',time());  
47 - $arr['compliance_day'] = DB::table('gl_rank_data')->where(['updated_date'=>$yesterday,'lang'=>null])->select(['compliance_day'])->first()['compliance_day']; 59 + $arr['yesterday_pv_num'] = DB::table('gl_customer_visit_item')->whereDate('date', $yesterday)->where('domain',$v['test_domain'])->count();
  60 + $arr['yesterday_ip_num'] = DB::table('gl_customer_visit')->whereDate('date', $yesterday)->where('domain',$v['test_domain'])->count();
  61 + $inquiry_list = (new FormGlobalsoApi())->getInquiryList($v['test_domain']);
  62 + if($inquiry_list['status'] == self::STATUS_ERROR){
  63 + $arr['inquiry_num'] = 0;
  64 + }else{
  65 + $arr['inquiry_num'] = count($inquiry_list['data']['total']);
  66 + }
  67 + $arr['date'] = $yesterday;
  68 + $rank_info = DB::table('gl_rank_data')->where(['updated_date'=>$yesterday,'lang'=>''])->select(['compliance_day'])->first();
  69 + if(empty($rank_info)){
  70 + $arr['compliance_day'] = 0;
  71 + }else{
  72 + $arr['compliance_day'] = $rank_info->compliance_day;
  73 + }
48 $arr['service_day'] = $v['service_duration'] - Common::getDaysToTargetDate($v['created_at']); 74 $arr['service_day'] = $v['service_duration'] - Common::getDaysToTargetDate($v['created_at']);
  75 + $arr['project_id'] = $v['project_id'];
  76 + $arr['created_at'] = date('Y-m-d H:i:s');
  77 + $arr['updated_at'] = date('Y-m-d H:i:s');
49 $data[] = $arr; 78 $data[] = $arr;
50 } 79 }
51 - DB::table('gl_yesterday_count')->insert($data); 80 + DB::table('gl_count')->insert($data);
52 $this->response('success'); 81 $this->response('success');
53 } 82 }
54 } 83 }
@@ -2,15 +2,19 @@ @@ -2,15 +2,19 @@
2 2
3 namespace App\Http\Logic\Bside\HomeCount; 3 namespace App\Http\Logic\Bside\HomeCount;
4 4
  5 +
5 use App\Http\Logic\Bside\BaseLogic; 6 use App\Http\Logic\Bside\BaseLogic;
6 -use App\Models\HomeCount\YesterdayCount; 7 +use App\Models\HomeCount\Count;
  8 +use App\Models\RankData\RankData as RankDataModel;
  9 +use Carbon\Carbon;
  10 +use Illuminate\Support\Facades\DB;
7 11
8 class CountLogic extends BaseLogic 12 class CountLogic extends BaseLogic
9 { 13 {
10 public function __construct() 14 public function __construct()
11 { 15 {
12 parent::__construct(); 16 parent::__construct();
13 - $this->model = new YesterdayCount(); 17 + $this->model = new Count();
14 } 18 }
15 19
16 /** 20 /**
@@ -20,15 +24,148 @@ class CountLogic extends BaseLogic @@ -20,15 +24,148 @@ class CountLogic extends BaseLogic
20 * @time :2023/5/23 17:30 24 * @time :2023/5/23 17:30
21 */ 25 */
22 public function yesterday_count(){ 26 public function yesterday_count(){
23 - $yesterday = now()->subDay(); 27 + $yesterday = Carbon::yesterday()->toDateString();
24 $param = [ 28 $param = [
25 'date' => $yesterday, 29 'date' => $yesterday,
26 'project_id' => $this->user['project_id'] 30 'project_id' => $this->user['project_id']
27 ]; 31 ];
28 - $info = $this->model->read($param); 32 + $info = $this->model->read($param,['pv_num','ip_num','inquiry_num','date','compliance_day','service_day']);
29 return $this->success($info); 33 return $this->success($info);
30 } 34 }
31 35
  36 + /**
  37 + * @name :(方案信息)scheme_info
  38 + * @author :lyh
  39 + * @method :post
  40 + * @time :2023/5/24 11:48
  41 + */
  42 + public function scheme_info(){
  43 + $data = [
  44 + 'company'=>$this->project['company'],
  45 + 'scheme'=>$this->project['deploy_build']['plan'],
  46 + 'service_duration'=>$this->project['deploy_build']['service_duration'],
  47 + ];
  48 + return $this->success($data);
  49 + }
  50 +
  51 + /**
  52 + * @name :(总访问量)total_count
  53 + * @author :lyh
  54 + * @method :post
  55 + * @time :2023/5/24 13:33
  56 + */
  57 + public function total_count($inquiry_num){
  58 + $pv = DB::table('gl_customer_visit_item')->where(['domain'=>$this->project['deploy_build']['test_domain']])->count();
  59 + $ip = DB::table('gl_customer_visit')->where(['domain'=>$this->project['deploy_build']['test_domain']])->count();
  60 + $data = [
  61 + 'total_pv'=>$pv,
  62 + 'total_ip'=>$ip,
  63 + 'conversion_rate' => ($inquiry_num / $ip) * 100,
  64 + ];
  65 + return $this->success($data);
  66 + }
32 67
  68 + /**
  69 + * @name :(前一天关键字排名统计)keyword_data
  70 + * @author :lyh
  71 + * @method :post
  72 + * @time :2023/5/24 14:03
  73 + */
  74 + public function keyword_data_count(){
  75 + $yesterday = Carbon::yesterday()->toDateString();
  76 + $rankDataModel = new RankDataModel();
  77 + $param = [
  78 + 'updated_date' => $yesterday,
  79 + 'project_id' => $this->user['project_id']
  80 + ];
  81 + $data = $rankDataModel->read($param,['first_num','first_page_num','first_three_pages_num','first_five_pages_num','first_ten_pages_num']);
  82 + return $this->success($data);
  83 + }
33 84
  85 + /**
  86 + * @name :(相关数据统计)with_data_count
  87 + * @author :lyh
  88 + * @method :post
  89 + * @time :2023/5/24 14:12
  90 + */
  91 + public function with_data_count(){
  92 + $product_count = DB::table('gl_product')->where(['project_id' => $this->user['project_id']])->count();
  93 + $news_count = DB::table('gl_news')->where(['project_id' => $this->user['project_id']])->count();
  94 + $page_count = DB::table('gl_web_template')->where(['project_id' => $this->user['project_id']])->count();
  95 + $data = [
  96 + 'product_count' => $product_count,
  97 + 'news_count' => $news_count,
  98 + 'page_count' => $page_count,
  99 + ];
  100 + return $this->success($data);
  101 + }
  102 +
  103 + /**
  104 + * @name :(30天数据统计)visit_data_count
  105 + * @author :lyh
  106 + * @method :post
  107 + * @time :2023/5/24 14:18
  108 + */
  109 + public function visit_data_count(){
  110 + $param = [
  111 + 'date' => ['between',[now()->subDays(30)->startOfDay()->toDateString(),now()->startOfDay()->toDateString()]],
  112 + 'project_id' => $this->user['project_id']
  113 + ];
  114 + $data = $this->model->list($param,'id',['id','pv_num','ip_num','date']);
  115 + return $this->success($data);
  116 + }
  117 +
  118 + /**
  119 + * @name :(询盘国家统计)inquiry_country_count
  120 + * @author :lyh
  121 + * @method :post
  122 + * @time :2023/5/24 14:58
  123 + */
  124 + public function inquiry_country_count(){
  125 + $data = DB::table('gl_xunpan_ipdata')
  126 + ->select('ip_area', DB::raw('COUNT(ip_area) as count'))
  127 + ->groupBy('ip_area')->orderBy('count','desc')->limit(20)->get()->toArray();
  128 + $data = object_to_array($data);
  129 + $total = DB::table('gl_xunpan_ipdata')->count();
  130 + foreach ($data as $k=>$v){
  131 + $data[$k]['proportion'] = ($v['count']/$total) * 100;
  132 + }
  133 + return $this->success($data);
  134 + }
  135 +
  136 + /**
  137 + * @name :(访问来源统计)referrer_count
  138 + * @author :lyh
  139 + * @method :post
  140 + * @time :2023/5/24 15:32
  141 + */
  142 + public function referrer_count(){
  143 + $data = DB::table('gl_customer_visit')
  144 + ->select('referrer_url', DB::raw('COUNT(*) as count'))->groupBy('referrer_url')
  145 + ->orderBy('count','desc')->limit(8)->get()->toArray();
  146 + $total = DB::table('gl_customer_visit')->count();
  147 + $data = object_to_array($data);
  148 + foreach ($data as $k=>$v){
  149 + $data[$k]['proportion'] = ($v['count']/$total) * 100;
  150 + }
  151 + return $this->success($data);
  152 + }
  153 +
  154 + /**
  155 + * @name :(访问国家统计)access_country_count
  156 + * @author :lyh
  157 + * @method :post
  158 + * @time :2023/5/24 15:56
  159 + */
  160 + public function access_country_count(){
  161 + $data = DB::table('gl_customer_visit')
  162 + ->select('country',DB::raw('COUNT(*) as ip'),DB::raw('SUM(depth) as pv'))
  163 + ->groupBy('country')->orderBy('ip','desc')->limit(20)->get()->toArray();
  164 + $data = object_to_array($data);
  165 + foreach ($data as $k => $v){
  166 + $v['pv'] = (int)$v['pv'];
  167 + $data[$k] = $v;
  168 + }
  169 + return $this->success($data);
  170 + }
34 } 171 }
@@ -4,7 +4,7 @@ namespace App\Models\HomeCount; @@ -4,7 +4,7 @@ namespace App\Models\HomeCount;
4 4
5 use App\Models\Base; 5 use App\Models\Base;
6 6
7 -class YesterdayCount extends Base 7 +class Count extends Base
8 { 8 {
9 - protected $table = 'gl_yesterday_count'; 9 + protected $table = 'gl_count';
10 } 10 }