作者 lyh

Merge branch 'dev' into develop

@@ -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 }
@@ -133,4 +133,19 @@ class Common @@ -133,4 +133,19 @@ class Common
133 $arr = array_map('unserialize', $arr); 133 $arr = array_map('unserialize', $arr);
134 return $arr; 134 return $arr;
135 } 135 }
  136 +
  137 + /**
  138 + * @param $targetDateTime
  139 + * @name :(获取时间差,精确时分秒,返回天数)getDaysToTargetDate
  140 + * @author :lyh
  141 + * @method :post
  142 + * @time :2023/5/24 9:38
  143 + */
  144 + public static function getDaysToTargetDate($targetDateTime)
  145 + {
  146 + $currentTimestamp = time();
  147 + $targetTimestamp = strtotime($targetDateTime);
  148 + $days = floor(($currentTimestamp - $targetTimestamp) / (60 * 60 * 24));
  149 + return (int)$days;
  150 + }
136 } 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 +
@@ -210,5 +210,4 @@ class BaseController extends Controller @@ -210,5 +210,4 @@ class BaseController extends Controller
210 } 210 }
211 211
212 212
213 -  
214 } 213 }
@@ -3,24 +3,81 @@ @@ -3,24 +3,81 @@
3 namespace App\Http\Controllers\Bside\HomeCount; 3 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;
  7 +use App\Helper\FormGlobalsoApi;
6 use App\Http\Controllers\Bside\BaseController; 8 use App\Http\Controllers\Bside\BaseController;
  9 +use App\Http\Logic\Bside\HomeCount\CountLogic;
  10 +use App\Models\Project\DeployBuild;
  11 +use Carbon\Carbon;
  12 +use Illuminate\Support\Facades\DB;
7 13
8 class CountController extends BaseController 14 class CountController extends BaseController
9 { 15 {
  16 + const STATUS_ERROR = 400;
10 /** 17 /**
11 * @name :(昨日统计数据)yesterday_count 18 * @name :(昨日统计数据)yesterday_count
12 * @author :lyh 19 * @author :lyh
13 * @method :post 20 * @method :post
14 * @time :2023/5/23 17:23 21 * @time :2023/5/23 17:23
15 */ 22 */
16 - public function count(){ 23 + public function count(CountLogic $countLogic){
17 $data = []; 24 $data = [];
  25 + //TODO::昨日数据统计
  26 + $data['yesterday'] = $countLogic->yesterday_count();
18 //TODO::全球搜方案信息 27 //TODO::全球搜方案信息
  28 + $data['scheme_info'] = $countLogic->scheme_info();
19 //TODO::网站访问量统计 29 //TODO::网站访问量统计
  30 + $data['total_visit'] = $countLogic->total_count($data['yesterday']['inquiry_num']);
20 //TODO::关键字排名数据 31 //TODO::关键字排名数据
21 - //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();
22 return $this->response('success',Code::SUCCESS,$data); 43 return $this->response('success',Code::SUCCESS,$data);
23 } 44 }
24 45
25 - 46 + /***
  47 + * @name :(手动获取昨日数据统计)yesterday
  48 + * @author :lyh
  49 + * @method :post
  50 + * @time :2023/5/24 9:13
  51 + */
  52 + public function yesterday(){
  53 + $deployModel = new DeployBuild();
  54 + $list = $deployModel->list();
  55 + $data = [];
  56 + $yesterday = Carbon::yesterday()->toDateString();
  57 + foreach ($list as $v){
  58 + $arr = [];
  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 + }
  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');
  78 + $data[] = $arr;
  79 + }
  80 + DB::table('gl_count')->insert($data);
  81 + $this->response('success');
  82 + }
26 } 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;
  7 +use App\Models\HomeCount\Count;
  8 +use App\Models\RankData\RankData as RankDataModel;
  9 +use Carbon\Carbon;
  10 +use Illuminate\Support\Facades\DB;
6 11
7 class CountLogic extends BaseLogic 12 class CountLogic extends BaseLogic
8 { 13 {
9 public function __construct() 14 public function __construct()
10 { 15 {
11 parent::__construct(); 16 parent::__construct();
12 -  
13 - $this->model = new Yes(); 17 + $this->model = new Count();
14 } 18 }
15 19
16 /** 20 /**
@@ -20,6 +24,148 @@ class CountLogic extends BaseLogic @@ -20,6 +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 - return $this->success(); 27 + $yesterday = Carbon::yesterday()->toDateString();
  28 + $param = [
  29 + 'date' => $yesterday,
  30 + 'project_id' => $this->user['project_id']
  31 + ];
  32 + $info = $this->model->read($param,['pv_num','ip_num','inquiry_num','date','compliance_day','service_day']);
  33 + return $this->success($info);
  34 + }
  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 + }
  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 + }
  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);
24 } 170 }
25 } 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 }
@@ -6,9 +6,11 @@ use App\Models\Base; @@ -6,9 +6,11 @@ use App\Models\Base;
6 6
7 class WebSetting extends Base 7 class WebSetting extends Base
8 { 8 {
  9 + //锚文本常量配置在settingTextModel中
9 protected $table = 'gl_web_setting'; 10 protected $table = 'gl_web_setting';
10 11
11 //连接数据库 12 //连接数据库
12 // protected $connection = 'custom_mysql'; 13 // protected $connection = 'custom_mysql';
13 14
  15 +
14 } 16 }
@@ -262,12 +262,19 @@ Route::middleware(['bloginauth','accesstoken'])->group(function () { @@ -262,12 +262,19 @@ Route::middleware(['bloginauth','accesstoken'])->group(function () {
262 Route::any('/get_google_rank', [\App\Http\Controllers\Bside\RankDataController::class, 'get_google_rank'])->name('rank_data_get_google_rank'); 262 Route::any('/get_google_rank', [\App\Http\Controllers\Bside\RankDataController::class, 'get_google_rank'])->name('rank_data_get_google_rank');
263 }); 263 });
264 264
  265 + //首页统计数据
  266 + Route::prefix('home')->group(function () {
  267 + Route::any('/count', [\App\Http\Controllers\Bside\HomeCount\CountController::class, 'count'])->name('home_count');
  268 + Route::any('/yesterday', [\App\Http\Controllers\Bside\HomeCount\CountController::class, 'yesterday'])->name('home_yesterday');
  269 + });
  270 +
265 //访问数据 271 //访问数据
266 Route::prefix('visit')->group(function () { 272 Route::prefix('visit')->group(function () {
267 Route::any('/', [\App\Http\Controllers\Bside\VisitController::class, 'index'])->name('visit_list'); 273 Route::any('/', [\App\Http\Controllers\Bside\VisitController::class, 'index'])->name('visit_list');
268 Route::any('/item', [\App\Http\Controllers\Bside\VisitController::class, 'item'])->name('visit_item'); 274 Route::any('/item', [\App\Http\Controllers\Bside\VisitController::class, 'item'])->name('visit_item');
269 }); 275 });
270 276
  277 +
271 }); 278 });
272 //无需登录验证的路由组 279 //无需登录验证的路由组
273 Route::group([], function () { 280 Route::group([], function () {