作者 邓超

Merge branch 'develop' into dc

@@ -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,154 @@ class CountLogic extends BaseLogic @@ -20,6 +24,154 @@ 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 + if($info === false){
  34 + $info = [];
  35 + }
  36 + return $this->success($info);
  37 + }
  38 +
  39 + /**
  40 + * @name :(方案信息)scheme_info
  41 + * @author :lyh
  42 + * @method :post
  43 + * @time :2023/5/24 11:48
  44 + */
  45 + public function scheme_info(){
  46 + $data = [
  47 + 'company'=>$this->project['company'],
  48 + 'scheme'=>$this->project['deploy_build']['plan'],
  49 + 'service_duration'=>$this->project['deploy_build']['service_duration'],
  50 + ];
  51 + return $this->success($data);
  52 + }
  53 +
  54 + /**
  55 + * @name :(总访问量)total_count
  56 + * @author :lyh
  57 + * @method :post
  58 + * @time :2023/5/24 13:33
  59 + */
  60 + public function total_count($inquiry_num){
  61 + $pv = DB::table('gl_customer_visit_item')->where(['domain'=>$this->project['deploy_build']['test_domain']])->count();
  62 + $ip = DB::table('gl_customer_visit')->where(['domain'=>$this->project['deploy_build']['test_domain']])->count();
  63 + $data = [
  64 + 'total_pv'=>$pv,
  65 + 'total_ip'=>$ip,
  66 + 'conversion_rate' => ($inquiry_num / $ip) * 100,
  67 + ];
  68 + return $this->success($data);
  69 + }
  70 +
  71 + /**
  72 + * @name :(前一天关键字排名统计)keyword_data
  73 + * @author :lyh
  74 + * @method :post
  75 + * @time :2023/5/24 14:03
  76 + */
  77 + public function keyword_data_count(){
  78 + $yesterday = Carbon::yesterday()->toDateString();
  79 + $rankDataModel = new RankDataModel();
  80 + $param = [
  81 + 'updated_date' => $yesterday,
  82 + 'project_id' => $this->user['project_id']
  83 + ];
  84 + $data = $rankDataModel->read($param,['first_num','first_page_num','first_three_pages_num','first_five_pages_num','first_ten_pages_num']);
  85 + if($data === false){
  86 + $data = [];
  87 + }
  88 + return $this->success($data);
  89 + }
  90 +
  91 + /**
  92 + * @name :(相关数据统计)with_data_count
  93 + * @author :lyh
  94 + * @method :post
  95 + * @time :2023/5/24 14:12
  96 + */
  97 + public function with_data_count(){
  98 + $product_count = DB::table('gl_product')->where(['project_id' => $this->user['project_id']])->count();
  99 + $news_count = DB::table('gl_news')->where(['project_id' => $this->user['project_id']])->count();
  100 + $page_count = DB::table('gl_web_template')->where(['project_id' => $this->user['project_id']])->count();
  101 + $data = [
  102 + 'product_count' => $product_count,
  103 + 'news_count' => $news_count,
  104 + 'page_count' => $page_count,
  105 + ];
  106 + return $this->success($data);
  107 + }
  108 +
  109 + /**
  110 + * @name :(30天数据统计)visit_data_count
  111 + * @author :lyh
  112 + * @method :post
  113 + * @time :2023/5/24 14:18
  114 + */
  115 + public function visit_data_count(){
  116 + $param = [
  117 + 'date' => ['between',[now()->subDays(30)->startOfDay()->toDateString(),now()->startOfDay()->toDateString()]],
  118 + 'project_id' => $this->user['project_id']
  119 + ];
  120 + $data = $this->model->list($param,'id',['id','pv_num','ip_num','date']);
  121 + return $this->success($data);
  122 + }
  123 +
  124 + /**
  125 + * @name :(询盘国家统计)inquiry_country_count
  126 + * @author :lyh
  127 + * @method :post
  128 + * @time :2023/5/24 14:58
  129 + */
  130 + public function inquiry_country_count(){
  131 + $data = DB::table('gl_inquiry_record')
  132 + ->select('ip_area', DB::raw('COUNT(ip_area) as count'))
  133 + ->groupBy('ip_area')->orderBy('count','desc')->limit(20)->get()->toArray();
  134 + $data = object_to_array($data);
  135 + $total = DB::table('gl_inquiry_record')->count();
  136 + foreach ($data as $k=>$v){
  137 + $data[$k]['proportion'] = ($v['count']/$total) * 100;
  138 + }
  139 + return $this->success($data);
  140 + }
  141 +
  142 + /**
  143 + * @name :(访问来源统计)referrer_count
  144 + * @author :lyh
  145 + * @method :post
  146 + * @time :2023/5/24 15:32
  147 + */
  148 + public function referrer_count(){
  149 + $data = DB::table('gl_customer_visit')
  150 + ->select('referrer_url', DB::raw('COUNT(*) as count'))->groupBy('referrer_url')
  151 + ->orderBy('count','desc')->limit(8)->get()->toArray();
  152 + $total = DB::table('gl_customer_visit')->count();
  153 + $data = object_to_array($data);
  154 + foreach ($data as $k=>$v){
  155 + $data[$k]['proportion'] = ($v['count']/$total) * 100;
  156 + }
  157 + return $this->success($data);
  158 + }
  159 +
  160 + /**
  161 + * @name :(访问国家统计)access_country_count
  162 + * @author :lyh
  163 + * @method :post
  164 + * @time :2023/5/24 15:56
  165 + */
  166 + public function access_country_count(){
  167 + $data = DB::table('gl_customer_visit')
  168 + ->select('country',DB::raw('COUNT(*) as ip'),DB::raw('SUM(depth) as pv'))
  169 + ->groupBy('country')->orderBy('ip','desc')->limit(20)->get()->toArray();
  170 + $data = object_to_array($data);
  171 + foreach ($data as $k => $v){
  172 + $v['pv'] = (int)$v['pv'];
  173 + $data[$k] = $v;
  174 + }
  175 + return $this->success($data);
24 } 176 }
25 } 177 }
@@ -29,7 +29,7 @@ class Logic @@ -29,7 +29,7 @@ class Logic
29 * @param array $data 29 * @param array $data
30 * @return array 30 * @return array
31 */ 31 */
32 - public function success(array $data = []) 32 + public function success($data = [])
33 { 33 {
34 return $data; 34 return $data;
35 } 35 }
@@ -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 () {