作者 lms

合并分支 'lms' 到 'develop'

Lms



查看合并请求 !7
  1 +<?php
  2 +
  3 +namespace App\Console\Commands\Bside\Statistics;
  4 +
  5 +use App\Models\Bside\Statistics\TrafficStatistics;
  6 +use App\Models\CustomerVisit\CustomerVisit;
  7 +use Illuminate\Console\Command;
  8 +use Illuminate\Support\Facades\DB;
  9 +use Throwable;
  10 +
  11 +class Logic
  12 +{
  13 +
  14 + /**
  15 + * @param int $type 统计类型
  16 + * @return array
  17 + */
  18 + public function getMonths(int $type = TrafficStatistics::TYPE_SOURCE)
  19 + {
  20 + $date = getPreviousMonthsDate();
  21 + $TrafficStatistics = new TrafficStatistics();
  22 + $lists = $TrafficStatistics->getMonthsLists($type, $date);
  23 + if (!empty($lists)) {
  24 + $dd = [];
  25 + $lists->map(function ($item) use (&$dd) {
  26 + $dd[] = $item->year . '-' . str_pad($item->month, 2, '0', STR_PAD_LEFT);
  27 + });
  28 + $date = array_diff($date, $dd);
  29 + }
  30 + return $date;
  31 + }
  32 +
  33 + /**
  34 + * @param array $column 统计数据
  35 + * @param int $type 统计类型
  36 + * @param string|null $date 日期 格式:Y-m
  37 + * @param string $message
  38 + * @return array
  39 + * @throws Throwable
  40 + */
  41 + public function save(array $column, int $type = TrafficStatistics::TYPE_SOURCE, string $date = null, $message = '统计当月访问来源数据')
  42 + {
  43 + DB::beginTransaction();
  44 + // 获取当天的IP|PV数量
  45 + $customerVisit = new CustomerVisit();
  46 + $ip_count = $customerVisit->getMonthIPCount($date);
  47 + $pv_count = $customerVisit->getMonthPVCount($date);
  48 + $column['pvnum'] = $pv_count;
  49 + $column['ipnum'] = $ip_count;
  50 + $date = $date ?? date('Y-m');
  51 + // 统计数据并插入到数据库
  52 + $dd = explode('-', $date);
  53 + $year = $dd[0];
  54 + $month = $dd[1];
  55 + $column['year'] = $year;
  56 + $column['month'] = $month;
  57 + $trafficStatistics = new TrafficStatistics();
  58 + $isRes = $trafficStatistics->getMonth($type, $year, $month);
  59 + if ($isRes) {
  60 + $trafficStatistics = $isRes;
  61 + }
  62 + foreach ($column as $key => $value) {
  63 + $trafficStatistics->$key = $value;
  64 + }
  65 + $res = $trafficStatistics->save();
  66 + if ($res) {
  67 + DB::commit();
  68 + $meg = "{$date} - {$message}成功!";
  69 + } else {
  70 + DB::rollBack();
  71 + $meg = "{$date} - {$message}失败!";
  72 + }
  73 + return ['status' => $res, 'msg' => $meg];
  74 + }
  75 +}
  1 +<?php
  2 +
  3 +namespace App\Console\Commands\Bside\Statistics;
  4 +
  5 +use App\Models\Bside\Statistics\TrafficTrends;
  6 +use App\Models\CustomerVisit\CustomerVisit;
  7 +use GuzzleHttp\Exception\GuzzleException;
  8 +use Illuminate\Console\Command;
  9 +use Illuminate\Support\Facades\DB;
  10 +use Throwable;
  11 +
  12 +class StatisticsDayTrend extends Command
  13 +{
  14 + public $error = 0;
  15 + /**
  16 + * The name and signature of the console command.
  17 + *
  18 + * @var string
  19 + */
  20 + protected $signature = 'statistics_day_trend';
  21 +
  22 + /**
  23 + * The console command description.
  24 + *
  25 + * @var string
  26 + */
  27 + protected $description = '统计当天流量趋势数据';
  28 +
  29 + /**
  30 + * @return void
  31 + * @throws GuzzleException
  32 + * @throws Throwable
  33 + */
  34 + public function handle()
  35 + {
  36 + $date = getPreviousDaysDate();
  37 + $trafficTrends = new TrafficTrends();
  38 + $lists = $trafficTrends->getDaysLists($date);
  39 + if (!empty($lists)) {
  40 + $date = array_diff($date, $lists->pluck('day')->all());
  41 + }
  42 + if (!empty($date)) {
  43 + foreach ($date as $value) {
  44 + echo $this->statistics_day_trend($value);
  45 + }
  46 + }
  47 + echo $this->statistics_day_trend();
  48 + }
  49 +
  50 + /**
  51 + * 统计当天流量趋势数据PV|IP数量
  52 + * @return int|mixed
  53 + * @throws GuzzleException|Throwable
  54 + */
  55 + protected function statistics_day_trend($date = null)
  56 + {
  57 + DB::beginTransaction();
  58 + $date = $date ?? date('Y-m-d');
  59 + // 获取当天的IP|PV数量
  60 + $customerVisit = new CustomerVisit();
  61 + $ip_count = $customerVisit->getDayIPCount($date);
  62 + $pv_count = $customerVisit->getDayPVCount($date);
  63 + // 统计数据并插入到数据库
  64 + $trafficTrends = new TrafficTrends();
  65 + $isRes = $trafficTrends->getDay($date);
  66 + if ($isRes) {
  67 + $trafficTrends = $isRes;
  68 + }
  69 + $trafficTrends->day = $date;
  70 + $trafficTrends->pvnum = $pv_count;
  71 + $trafficTrends->ipnum = $ip_count;
  72 + $res = $trafficTrends->save();
  73 + if ($res) {
  74 + DB::commit();
  75 + $this->info($date . ' - 统计当天流量趋势数据PV|IP数量成功');
  76 + } else {
  77 + DB::rollBack();
  78 + $this->error++;
  79 + $this->info($date . ' - 统计当天流量趋势数据PV|IP数量失败');
  80 + }
  81 + return $this->error;
  82 + }
  83 +}
  1 +<?php
  2 +
  3 +namespace App\Console\Commands\Bside\Statistics;
  4 +
  5 +use App\Models\Bside\Statistics\TrafficStatistics;
  6 +use App\Models\CustomerVisit\CustomerVisit;
  7 +use Illuminate\Console\Command;
  8 +use Throwable;
  9 +
  10 +class StatisticsDistribution extends Command
  11 +{
  12 + public $error = 0;
  13 + /**
  14 + * The name and signature of the console command.
  15 + *
  16 + * @var string
  17 + */
  18 + protected $signature = 'statistics_distribution';
  19 +
  20 + /**
  21 + * The console command description.
  22 + *
  23 + * @var string
  24 + */
  25 + protected $description = '统计当月地域分布数据';
  26 +
  27 + public $logic;
  28 +
  29 + public function __construct()
  30 + {
  31 + parent::__construct();
  32 + $this->logic = new Logic();
  33 + }
  34 +
  35 + /**
  36 + * 定时执行
  37 + * @return void
  38 + * @throws Throwable
  39 + */
  40 + public function handle()
  41 + {
  42 + $date = $this->logic->getMonths(TrafficStatistics::TYPE_DISTRIBUTION);
  43 + if (!empty($date)) {
  44 + foreach ($date as $value) {
  45 + echo $this->statistics_distribution($value);
  46 + }
  47 + }
  48 + echo $this->statistics_distribution();
  49 + }
  50 +
  51 + /**
  52 + * 统计当天流量趋势数据PV|IP数量
  53 + * @param string|null $date
  54 + * @return int|mixed
  55 + * @throws Throwable
  56 + */
  57 + protected function statistics_distribution(string $date = null)
  58 + {
  59 + $customerVisit = new CustomerVisit();
  60 + $type = TrafficStatistics::TYPE_DISTRIBUTION;
  61 + $top = json_encode($customerVisit->getCountryCount($date) ?? []);
  62 + $res = $this->logic->save(compact('top', 'type'), $type, $date, '统计当月地域分布数据');
  63 + if (!$res['status']) {
  64 + $this->info($res['msg']);
  65 + $this->error++;
  66 + }
  67 + $this->info($res['msg']);
  68 + return $this->error;
  69 + }
  70 +}
  1 +<?php
  2 +
  3 +namespace App\Console\Commands\Bside\Statistics;
  4 +
  5 +use App\Models\Bside\Statistics\TrafficStatistics;
  6 +use App\Models\CustomerVisit\CustomerVisit;
  7 +use Illuminate\Console\Command;
  8 +use Throwable;
  9 +
  10 +class StatisticsPage extends Command
  11 +{
  12 + public $error = 0;
  13 +
  14 + /**
  15 + * The name and signature of the console command.
  16 + *
  17 + * @var string
  18 + */
  19 + protected $signature = 'statistics_page';
  20 +
  21 + /**
  22 + * The console command description.
  23 + *
  24 + * @var string
  25 + */
  26 + protected $description = '统计当月受访页面数据';
  27 +
  28 + public $logic;
  29 +
  30 + public function __construct()
  31 + {
  32 + parent::__construct();
  33 + $this->logic = new Logic();
  34 + }
  35 +
  36 + /**
  37 + * 定时执行
  38 + * @return void
  39 + */
  40 + public function handle()
  41 + {
  42 + $date = $this->logic->getMonths(TrafficStatistics::TYPE_PAGE);
  43 + if (!empty($date)) {
  44 + foreach ($date as $value) {
  45 + echo $this->statistics_page($value);
  46 + }
  47 + }
  48 + echo $this->statistics_page();
  49 + }
  50 +
  51 + /**
  52 + * 统计当月受访页面数据
  53 + * @param null $date
  54 + * @return int|mixed
  55 + * @throws Throwable
  56 + */
  57 + protected function statistics_page($date = null)
  58 + {
  59 + $customerVisit = new CustomerVisit();
  60 + $top = json_encode($customerVisit->getPageCount($date) ?? []);
  61 + $type = TrafficStatistics::TYPE_PAGE;
  62 + $res = $this->logic->save(compact('top', 'type'), $type, $date, '统计当月受访页面数据');
  63 + if (!$res['status']) {
  64 + $this->info($res['msg']);
  65 + $this->error++;
  66 + }
  67 + $this->info($res['msg']);
  68 + return $this->error;
  69 + }
  70 +}
  1 +<?php
  2 +
  3 +namespace App\Console\Commands\Bside\Statistics;
  4 +
  5 +use App\Models\Bside\Statistics\TrafficStatistics;
  6 +use App\Models\CustomerVisit\CustomerVisit;
  7 +use Illuminate\Console\Command;
  8 +use Throwable;
  9 +
  10 +class StatisticsSource extends Command
  11 +{
  12 + public $error = 0;
  13 + /**
  14 + * The name and signature of the console command.
  15 + *
  16 + * @var string
  17 + */
  18 + protected $signature = 'statistics_source';
  19 +
  20 + /**
  21 + * The console command description.
  22 + *
  23 + * @var string
  24 + */
  25 + protected $description = '统计当月访问来源数据';
  26 +
  27 + public $logic;
  28 +
  29 + public function __construct()
  30 + {
  31 + parent::__construct();
  32 + $this->logic = new Logic();
  33 + }
  34 +
  35 + /**
  36 + * @return void
  37 + * @throws Throwable
  38 + */
  39 + public function handle()
  40 + {
  41 + $date = $this->logic->getMonths();
  42 + if (!empty($date)) {
  43 + foreach ($date as $value) {
  44 + echo $this->statistics_source($value);
  45 + }
  46 + }
  47 + echo $this->statistics_source();
  48 + }
  49 +
  50 + /**
  51 + * 统计当天流量趋势数据
  52 + * @param string|null $date
  53 + * @return int|mixed
  54 + * @throws Throwable
  55 + */
  56 + protected function statistics_source(string $date = null)
  57 + {
  58 + // 获取当天的IP|PV数量
  59 + $customerVisit = new CustomerVisit();
  60 + $top = json_encode($customerVisit->getUrlCount($date) ?? []);
  61 + $type = TrafficStatistics::TYPE_SOURCE;
  62 + $res = $this->logic->save(compact('top', 'type'), $type, $date);
  63 + if (!$res['status']) {
  64 + $this->info($res['msg']);
  65 + $this->error++;
  66 + }
  67 + $this->info($res['msg']);
  68 + return $this->error;
  69 + }
  70 +}
  1 +<?php
  2 +
  3 +namespace App\Console\Commands\Bside\Statistics;
  4 +
  5 +use App\Models\Bside\Statistics\TrafficStatistics;
  6 +use App\Models\CustomerVisit\CustomerVisit;
  7 +use GuzzleHttp\Exception\GuzzleException;
  8 +use Illuminate\Console\Command;
  9 +use Throwable;
  10 +
  11 +class StatisticsTerminal extends Command
  12 +{
  13 + public $error = 0;
  14 +
  15 + /**
  16 + * The name and signature of the console command.
  17 + *
  18 + * @var string
  19 + */
  20 + protected $signature = 'statistics_terminal';
  21 +
  22 + /**
  23 + * The console command description.
  24 + *
  25 + * @var string
  26 + */
  27 + protected $description = '统计当月访问终端数据';
  28 +
  29 + public $logic;
  30 +
  31 + public function __construct()
  32 + {
  33 + parent::__construct();
  34 + $this->logic = new Logic();
  35 + }
  36 +
  37 + /**
  38 + * @return void
  39 + * @throws Throwable
  40 + */
  41 + public function handle()
  42 + {
  43 + $date = $this->logic->getMonths(TrafficStatistics::TYPE_TERMINAL);
  44 + if (!empty($date)) {
  45 + foreach ($date as $value) {
  46 + echo $this->statistics_terminal($value);
  47 + }
  48 + }
  49 + echo $this->statistics_terminal();
  50 + }
  51 +
  52 + /**
  53 + * 统计当月访问终端数据
  54 + * @param string|null $date
  55 + * @return int|mixed
  56 + * @throws Throwable
  57 + */
  58 + protected function statistics_terminal(string $date = null)
  59 + {
  60 + $customerVisit = new CustomerVisit();
  61 + $pcnum = $customerVisit->getTerminalPcCount($date);
  62 + $mbnum = $customerVisit->getTerminalMobileCount($date);
  63 + $top = json_encode($customerVisit->getCountryCount($date) ?? []);
  64 + $type = TrafficStatistics::TYPE_TERMINAL;
  65 + $res = $this->logic->save(compact('top', 'type', 'pcnum', 'mbnum'), $type, $date, '统计当月访问终端数据');
  66 + if (!$res['status']) {
  67 + $this->info($res['msg']);
  68 + $this->error++;
  69 + }
  70 + $this->info($res['msg']);
  71 + return $this->error;
  72 + }
  73 +}
  1 +<?php
  2 +
  3 +namespace App\Console\Commands\Bside\Statistics;
  4 +
  5 +use App\Models\Bside\Statistics\TrafficStatistics;
  6 +use GuzzleHttp\Exception\GuzzleException;
  7 +use Illuminate\Console\Command;
  8 +use Throwable;
  9 +
  10 +class StatisticsTrend extends Command
  11 +{
  12 + public $error = 0;
  13 +
  14 + /**
  15 + * The name and signature of the console command.
  16 + *
  17 + * @var string
  18 + */
  19 + protected $signature = 'statistics_trend';
  20 +
  21 + /**
  22 + * The console command description.
  23 + *
  24 + * @var string
  25 + */
  26 + protected $description = '统计当月流量趋势数据';
  27 +
  28 + public $logic;
  29 +
  30 + public function __construct()
  31 + {
  32 + parent::__construct();
  33 + $this->logic = new Logic();
  34 + }
  35 +
  36 + /**
  37 + * 定时执行
  38 + * @return void
  39 + * @throws GuzzleException|Throwable
  40 + */
  41 + public function handle()
  42 + {
  43 + $date = $this->logic->getMonths(TrafficStatistics::TYPE_TREND);
  44 + if (!empty($date)) {
  45 + foreach ($date as $value) {
  46 + echo $this->statistics_trend($value);
  47 + }
  48 + }
  49 + echo $this->statistics_trend();
  50 + }
  51 +
  52 + /**
  53 + * 统计当天流量趋势数据
  54 + * @param string|null $date
  55 + * @return int|mixed
  56 + * @throws GuzzleException|Throwable
  57 + */
  58 + protected function statistics_trend(string $date = null)
  59 + {
  60 + $domain = request()->getHttpHost(); //'www.wowstainless.com';
  61 + $sta_date = !is_null($date) ? $date . "-01" : date('Y-m-01');
  62 + $inquiry = getInquiryInformation($domain, $sta_date);
  63 + $innum = $inquiry['count'] ?? 0;
  64 + $top = json_encode($inquiry['lists'] ?? []);
  65 + $type = TrafficStatistics::TYPE_TREND;
  66 + $res = $this->logic->save(compact('top', 'type', 'innum'), $type, $date, '统计当月流量趋势数据');
  67 + if (!$res['status']) {
  68 + $this->info($res['msg']);
  69 + $this->error++;
  70 + }
  71 + $this->info($res['msg']);
  72 + return $this->error;
  73 + }
  74 +}
@@ -4,11 +4,8 @@ namespace App\Console\Commands\Domain; @@ -4,11 +4,8 @@ namespace App\Console\Commands\Domain;
4 4
5 use App\Exceptions\AsideGlobalException; 5 use App\Exceptions\AsideGlobalException;
6 use App\Exceptions\BsideGlobalException; 6 use App\Exceptions\BsideGlobalException;
7 -use App\Helper\AyrShare as AyrShareHelper;  
8 use App\Http\Logic\Aside\Domain\DomainInfoLogic; 7 use App\Http\Logic\Aside\Domain\DomainInfoLogic;
9 -use App\Models\AyrShare\AyrRelease as AyrReleaseModel;  
10 -use Carbon\Carbon;  
11 -use App\Models\AyrShare\AyrShare as AyrShareModel; 8 +use GuzzleHttp\Exception\GuzzleException;
12 use Illuminate\Console\Command; 9 use Illuminate\Console\Command;
13 10
14 class DomainTime extends Command 11 class DomainTime extends Command
@@ -43,7 +40,7 @@ class DomainTime extends Command @@ -43,7 +40,7 @@ class DomainTime extends Command
43 * 更新域名|证书到期时间 40 * 更新域名|证书到期时间
44 * @return int|mixed|void 41 * @return int|mixed|void
45 * @throws AsideGlobalException 42 * @throws AsideGlobalException
46 - * @throws BsideGlobalException 43 + * @throws BsideGlobalException|GuzzleException
47 */ 44 */
48 protected function update_domain_time() 45 protected function update_domain_time()
49 { 46 {
@@ -27,7 +27,23 @@ class Kernel extends ConsoleKernel @@ -27,7 +27,23 @@ class Kernel extends ConsoleKernel
27 $schedule->command('web_traffic 1')->everyThirtyMinutes(); // 引流 1-3个月的项目,半小时一次 27 $schedule->command('web_traffic 1')->everyThirtyMinutes(); // 引流 1-3个月的项目,半小时一次
28 $schedule->command('web_traffic 2')->cron('*/18 * * * *'); // 引流 4-8个月的项目,18分钟一次 28 $schedule->command('web_traffic 2')->cron('*/18 * * * *'); // 引流 4-8个月的项目,18分钟一次
29 $schedule->command('web_traffic 3')->cron('*/12 * * * *'); // 引流 大于9个月的项目,12分钟一次 29 $schedule->command('web_traffic 3')->cron('*/12 * * * *'); // 引流 大于9个月的项目,12分钟一次
30 -// $schedule->command('domain_time')->dailyAt('01:00')->withoutOverlapping(1); // 更新域名|证书结束时间,每天凌晨1点执行一次 30 + // 更新域名|证书结束时间,每天凌晨1点执行一次
  31 +// $schedule->command('domain_time')->dailyAt('01:00')->withoutOverlapping(1);
  32 + // B站 - 网站数据统计
  33 + // 获取当前月份最后一天
  34 + $lastDay = date('Y-m-t');
  35 + // 统计当月访问来源数据,每月最后一天23:59点执行一次
  36 + $schedule->command('statistics_source')->monthlyOn($lastDay, '23:59')->withoutOverlapping(1);
  37 + // 统计当月地域分布数据,每月最后一天23:59点执行一次
  38 + $schedule->command('statistics_distribution')->monthlyOn($lastDay, '23:59')->withoutOverlapping(1);
  39 + // 统计当月受访页面数据,每月最后一天23:59点执行一次
  40 + $schedule->command('statistics_page')->monthlyOn($lastDay, '23:59')->withoutOverlapping(1);
  41 + // 统计当月访问终端数据,每月最后一天23:59点执行一次
  42 + $schedule->command('statistics_terminal')->monthlyOn($lastDay, '23:59')->withoutOverlapping(1);
  43 + // 统计当月流量趋势数据,每月最后一天23:59点执行一次
  44 + $schedule->command('statistics_trend')->monthlyOn($lastDay, '23:59')->withoutOverlapping(1);
  45 + // 统计当天流量趋势数据,每天23:59点执行一次
  46 + $schedule->command('statistics_day_trend')->dailyAt('23:59')->withoutOverlapping(1);
31 } 47 }
32 48
33 /** 49 /**
1 <?php 1 <?php
2 2
3 use App\Utils\LogUtils; 3 use App\Utils\LogUtils;
  4 +use GuzzleHttp\Client;
  5 +use GuzzleHttp\Exception\GuzzleException;
4 use Illuminate\Support\Carbon; 6 use Illuminate\Support\Carbon;
5 7
6 -define('HTTP_OPENAI_URL','http://openai.waimaoq.com/'); 8 +define('HTTP_OPENAI_URL', 'http://openai.waimaoq.com/');
7 /** 9 /**
8 * 生成路由标识 10 * 生成路由标识
9 * @param $string 11 * @param $string
@@ -28,7 +30,8 @@ if (!function_exists('generateRoute')) { @@ -28,7 +30,8 @@ if (!function_exists('generateRoute')) {
28 * @author zbj 30 * @author zbj
29 * @date 2023/4/27 31 * @date 2023/4/27
30 */ 32 */
31 -function errorLog($title, $params, Throwable $exception){ 33 +function errorLog($title, $params, Throwable $exception)
  34 +{
32 $exceptionMessage = "错误CODE:" . $exception->getCode() . 35 $exceptionMessage = "错误CODE:" . $exception->getCode() .
33 "-----错误message:" . $exception->getMessage() . 36 "-----错误message:" . $exception->getMessage() .
34 '------错误文件:' . $exception->getFile() . 37 '------错误文件:' . $exception->getFile() .
@@ -37,15 +40,15 @@ function errorLog($title, $params, Throwable $exception){ @@ -37,15 +40,15 @@ function errorLog($title, $params, Throwable $exception){
37 LogUtils::error($title, $params, $exceptionMessage); 40 LogUtils::error($title, $params, $exceptionMessage);
38 } 41 }
39 42
40 -if(!function_exists('http_post')){ 43 +if (!function_exists('http_post')) {
41 /** 44 /**
42 * 发送http post请求 45 * 发送http post请求
43 * @param type $url 46 * @param type $url
44 * @param type $post_data 47 * @param type $post_data
45 */ 48 */
46 - function http_post($url, $post_data,$header = []) 49 + function http_post($url, $post_data, $header = [])
47 { 50 {
48 - if(empty($header)){ 51 + if (empty($header)) {
49 $header = array( 52 $header = array(
50 "Accept: application/json", 53 "Accept: application/json",
51 "Content-Type:application/json;charset=utf-8", 54 "Content-Type:application/json;charset=utf-8",
@@ -71,15 +74,15 @@ if(!function_exists('http_post')){ @@ -71,15 +74,15 @@ if(!function_exists('http_post')){
71 } 74 }
72 } 75 }
73 76
74 -if(!function_exists('http_get')){ 77 +if (!function_exists('http_get')) {
75 /** 78 /**
76 * 发送http get请求 79 * 发送http get请求
77 * @param type $url 80 * @param type $url
78 * @return type 81 * @return type
79 */ 82 */
80 - function http_get($url,$header = []) 83 + function http_get($url, $header = [])
81 { 84 {
82 - if(empty($header)){ 85 + if (empty($header)) {
83 $header[] = "content-type: application/json; 86 $header[] = "content-type: application/json;
84 charset = UTF-8"; 87 charset = UTF-8";
85 } 88 }
@@ -99,7 +102,7 @@ if(!function_exists('http_get')){ @@ -99,7 +102,7 @@ if(!function_exists('http_get')){
99 } 102 }
100 103
101 104
102 -if(!function_exists('_get_child')){ 105 +if (!function_exists('_get_child')) {
103 /** 106 /**
104 * 菜单权限->得到子级数组 107 * 菜单权限->得到子级数组
105 * @param int 108 * @param int
@@ -111,7 +114,7 @@ if(!function_exists('_get_child')){ @@ -111,7 +114,7 @@ if(!function_exists('_get_child')){
111 foreach ($arr as $k => $v) { 114 foreach ($arr as $k => $v) {
112 $v = (array)$v; 115 $v = (array)$v;
113 if ($v['pid'] == $my_id) { 116 if ($v['pid'] == $my_id) {
114 - $v['sub'] = _get_child($v['id'],$arr); 117 + $v['sub'] = _get_child($v['id'], $arr);
115 $new_arr[] = $v; 118 $new_arr[] = $v;
116 } 119 }
117 } 120 }
@@ -120,7 +123,6 @@ if(!function_exists('_get_child')){ @@ -120,7 +123,6 @@ if(!function_exists('_get_child')){
120 } 123 }
121 124
122 125
123 -  
124 if (!function_exists('checkDomain')) { 126 if (!function_exists('checkDomain')) {
125 /** 127 /**
126 * 检查并补全域名协议 128 * 检查并补全域名协议
@@ -131,12 +133,12 @@ if (!function_exists('checkDomain')) { @@ -131,12 +133,12 @@ if (!function_exists('checkDomain')) {
131 function checkDomain($value) 133 function checkDomain($value)
132 { 134 {
133 $urlParts = parse_url(strtolower($value)); 135 $urlParts = parse_url(strtolower($value));
134 - if(empty($urlParts['host'])){ 136 + if (empty($urlParts['host'])) {
135 $urlParts = parse_url('https://' . $value); 137 $urlParts = parse_url('https://' . $value);
136 } 138 }
137 - $host = $urlParts['host'] ?? ''; 139 + $host = $urlParts['host'] ?? '';
138 $scheme = $urlParts['scheme'] ?? 'https'; 140 $scheme = $urlParts['scheme'] ?? 'https';
139 - if(!in_array($scheme, ['http', 'https'])){ 141 + if (!in_array($scheme, ['http', 'https'])) {
140 return false; 142 return false;
141 } 143 }
142 if (preg_match('/^(?:[-A-Za-z0-9]+\.)+[A-Za-z]{2,6}$/', $host)) { 144 if (preg_match('/^(?:[-A-Za-z0-9]+\.)+[A-Za-z]{2,6}$/', $host)) {
@@ -148,7 +150,6 @@ if (!function_exists('checkDomain')) { @@ -148,7 +150,6 @@ if (!function_exists('checkDomain')) {
148 } 150 }
149 151
150 152
151 -  
152 /** 153 /**
153 * 把返回的数据集转换成Tree 154 * 把返回的数据集转换成Tree
154 * @param $list array 数据列表 155 * @param $list array 数据列表
@@ -159,20 +160,21 @@ if (!function_exists('checkDomain')) { @@ -159,20 +160,21 @@ if (!function_exists('checkDomain')) {
159 * @param bool $empty_child 当子数据不存在,是否要返回空子数据 160 * @param bool $empty_child 当子数据不存在,是否要返回空子数据
160 * @return array 161 * @return array
161 */ 162 */
162 -function list_to_tree($list, $pk='id',$pid = 'pid',$child = '_child',$root=0,$empty_child=true) { 163 +function list_to_tree($list, $pk = 'id', $pid = 'pid', $child = '_child', $root = 0, $empty_child = true)
  164 +{
163 // 如果是数字,则是root 165 // 如果是数字,则是root
164 - if(is_numeric($pk)){  
165 - $root = $pk;  
166 - $pk = 'id'; 166 + if (is_numeric($pk)) {
  167 + $root = $pk;
  168 + $pk = 'id';
167 } 169 }
168 // 创建Tree 170 // 创建Tree
169 $tree = array(); 171 $tree = array();
170 - if(is_array($list)) { 172 + if (is_array($list)) {
171 // 创建基于主键的数组引用 173 // 创建基于主键的数组引用
172 $refer = array(); 174 $refer = array();
173 foreach ($list as $key => $data) { 175 foreach ($list as $key => $data) {
174 - if($empty_child){  
175 - $list[$key][$child] = []; 176 + if ($empty_child) {
  177 + $list[$key][$child] = [];
176 } 178 }
177 $refer[$data[$pk]] =& $list[$key]; 179 $refer[$data[$pk]] =& $list[$key];
178 } 180 }
@@ -181,9 +183,9 @@ function list_to_tree($list, $pk='id',$pid = 'pid',$child = '_child',$root=0,$em @@ -181,9 +183,9 @@ function list_to_tree($list, $pk='id',$pid = 'pid',$child = '_child',$root=0,$em
181 $parentId = $data[$pid]; 183 $parentId = $data[$pid];
182 if ($root == $parentId) { 184 if ($root == $parentId) {
183 $tree[] =& $list[$key]; 185 $tree[] =& $list[$key];
184 - }else{ 186 + } else {
185 if (isset($refer[$parentId])) { 187 if (isset($refer[$parentId])) {
186 - $refer[$parentId][$child][] = & $list[$key]; 188 + $refer[$parentId][$child][] = &$list[$key];
187 } 189 }
188 } 190 }
189 } 191 }
@@ -199,14 +201,15 @@ function list_to_tree($list, $pk='id',$pid = 'pid',$child = '_child',$root=0,$em @@ -199,14 +201,15 @@ function list_to_tree($list, $pk='id',$pid = 'pid',$child = '_child',$root=0,$em
199 * @author:dc 201 * @author:dc
200 * @time 2022/1/11 10:13 202 * @time 2022/1/11 10:13
201 */ 203 */
202 -function tree_to_list($tree, $child='_child'){  
203 - $lists = [];  
204 - foreach ($tree as $item){  
205 - $c = $item[$child]??[]; 204 +function tree_to_list($tree, $child = '_child')
  205 +{
  206 + $lists = [];
  207 + foreach ($tree as $item) {
  208 + $c = $item[$child] ?? [];
206 unset($item[$child]); 209 unset($item[$child]);
207 $lists[] = $item; 210 $lists[] = $item;
208 - if ($c){  
209 - $lists = array_merge($lists,tree_to_list($c, $child)); 211 + if ($c) {
  212 + $lists = array_merge($lists, tree_to_list($c, $child));
210 } 213 }
211 } 214 }
212 return $lists; 215 return $lists;
@@ -234,10 +237,10 @@ if (!function_exists('object_to_array')) { @@ -234,10 +237,10 @@ if (!function_exists('object_to_array')) {
234 */ 237 */
235 function object_to_array($data) 238 function object_to_array($data)
236 { 239 {
237 - if(is_object($data)){ 240 + if (is_object($data)) {
238 $data = (array)$data; 241 $data = (array)$data;
239 - }else{  
240 - foreach ($data as $k => $v){ 242 + } else {
  243 + foreach ($data as $k => $v) {
241 $data[$k] = object_to_array($v); 244 $data[$k] = object_to_array($v);
242 } 245 }
243 } 246 }
@@ -245,3 +248,76 @@ if (!function_exists('object_to_array')) { @@ -245,3 +248,76 @@ if (!function_exists('object_to_array')) {
245 } 248 }
246 } 249 }
247 250
  251 +if (!function_exists('getPreviousDaysDate')) {
  252 + /**
  253 + * 获取当前指定前几天日期,默认获取前三天日期
  254 + * @param int $day
  255 + * @return array
  256 + */
  257 + function getPreviousDaysDate(int $day = 3)
  258 + {
  259 + $days = [];
  260 + while ($day > 0) {
  261 + $days[] = date("Y-m-d", strtotime("-{$day} days"));
  262 + $day -= 1;
  263 + }
  264 + return $days;
  265 + }
  266 +}
  267 +
  268 +if (!function_exists('getPreviousMonthsDate')) {
  269 + /**
  270 + * 获取当前指定前几天日期,默认获取前三天日期
  271 + * @param int $month
  272 + * @return array
  273 + */
  274 + function getPreviousMonthsDate(int $month = 3)
  275 + {
  276 + $months = [];
  277 + while ($month > 0) {
  278 + $months[] = date("Y-m", strtotime("-{$month} months"));
  279 + $month -= 1;
  280 + }
  281 + return $months;
  282 + }
  283 +}
  284 +
  285 +if (!function_exists('getInquiryInformation')) {
  286 + /**
  287 + * 获取第三方询盘信息
  288 + * @return array|string
  289 + * @throws GuzzleException
  290 + */
  291 + function getInquiryInformation($domain, $sta_date)
  292 + {
  293 + $token = md5($domain . date("Y-m-d"));
  294 + $source = '1,3';
  295 + $url = "https://form.globalso.com/api/external-interface/country_con/15243d63ed5a5738?domain={$domain}&token={$token}&source={$source}&sta_date={$sta_date}";
  296 + $client = new Client(['verify' => false]);
  297 + $http = $client->get($url);
  298 + $data = [];
  299 + if ($http->getStatusCode() != 200) {
  300 + return $data;
  301 + }
  302 + $content = $http->getBody()->getContents();
  303 + $json = json_decode($content, true);
  304 + if ($json['status'] != 200) {
  305 + return $content;
  306 + }
  307 + $data['count'] = $json['data']['count'];
  308 + $data['lists'] = $json['data']['data'];
  309 + return $data;
  310 + }
  311 +}
  312 +
  313 +if (!function_exists('stringUnderlineLowercase')) {
  314 + /**
  315 + * 正则 - 名字转为小写并将空格转为下划线
  316 + * @param $name
  317 + * @return string
  318 + */
  319 + function stringUnderlineLowercase($name)
  320 + {
  321 + return trim(strtolower(preg_replace('/[^a-zA-Z0-9]/', '_', $name)));
  322 + }
  323 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside;
  4 +
  5 +
  6 +use App\Http\Logic\Bside\Statistics\StatisticsLogic;
  7 +use App\Models\Bside\Statistics\TrafficStatistics;
  8 +use Illuminate\Http\JsonResponse;
  9 +use Psr\Container\ContainerExceptionInterface;
  10 +use Psr\Container\NotFoundExceptionInterface;
  11 +use Throwable;
  12 +
  13 +/**
  14 + * 流量统计
  15 + * Class StatisticsController
  16 + * @package App\Http\Controllers\Bside
  17 + */
  18 +class StatisticsController extends BaseController
  19 +{
  20 + public $statisticsLogic;
  21 +
  22 + public $trafficStatistics;
  23 +
  24 + public function __construct()
  25 + {
  26 + $this->statisticsLogic = new StatisticsLogic();
  27 + $this->trafficStatistics = new TrafficStatistics();
  28 + }
  29 +
  30 + /**
  31 + * 访问来源
  32 + * @return JsonResponse
  33 + * @throws ContainerExceptionInterface
  34 + * @throws NotFoundExceptionInterface
  35 + */
  36 + public function source()
  37 + {
  38 + $type = $this->trafficStatistics::TYPE_SOURCE;
  39 + $response = $this->statisticsLogic->getStatisticsData($type);
  40 + return $this->success($response);
  41 + }
  42 +
  43 + /**
  44 + * 地域分布
  45 + * @return JsonResponse
  46 + * @throws ContainerExceptionInterface
  47 + * @throws NotFoundExceptionInterface|Throwable
  48 + */
  49 + public function distribution()
  50 + {
  51 + $type = $this->trafficStatistics::TYPE_DISTRIBUTION;
  52 + $response = $this->statisticsLogic->getStatisticsData($type);
  53 + return $this->success($response);
  54 + }
  55 +
  56 + /**
  57 + * 受访页面
  58 + * @return JsonResponse
  59 + * @throws ContainerExceptionInterface
  60 + * @throws NotFoundExceptionInterface|Throwable
  61 + */
  62 + public function page()
  63 + {
  64 + $type = $this->trafficStatistics::TYPE_PAGE;
  65 + $response = $this->statisticsLogic->getStatisticsData($type);
  66 + return $this->success($response);
  67 + }
  68 +
  69 + /**
  70 + * 访问终端
  71 + * @return JsonResponse
  72 + * @throws ContainerExceptionInterface
  73 + * @throws NotFoundExceptionInterface|Throwable
  74 + */
  75 + public function terminal()
  76 + {
  77 + $type = $this->trafficStatistics::TYPE_TERMINAL;
  78 + $response = $this->statisticsLogic->getStatisticsData($type);
  79 + return $this->success($response);
  80 + }
  81 +
  82 + /**
  83 + * 流量趋势
  84 + * @return JsonResponse
  85 + * @throws ContainerExceptionInterface
  86 + * @throws NotFoundExceptionInterface|Throwable
  87 + */
  88 + public function trend()
  89 + {
  90 + $type = $this->trafficStatistics::TYPE_TREND;
  91 + $response = $this->statisticsLogic->getStatisticsData($type);
  92 + return $this->success($response);
  93 + }
  94 +
  95 +
  96 +}
@@ -10,6 +10,8 @@ use App\Http\Logic\Aside\BaseLogic; @@ -10,6 +10,8 @@ use App\Http\Logic\Aside\BaseLogic;
10 use App\Http\Logic\Aside\Devops\ServerInformationLogic; 10 use App\Http\Logic\Aside\Devops\ServerInformationLogic;
11 use App\Models\Aside\Domain\DomainInfo; 11 use App\Models\Aside\Domain\DomainInfo;
12 use App\Models\Aside\Domain\DomainInfoLog; 12 use App\Models\Aside\Domain\DomainInfoLog;
  13 +use GuzzleHttp\Client;
  14 +use GuzzleHttp\Exception\GuzzleException;
13 use Illuminate\Database\Eloquent\Builder; 15 use Illuminate\Database\Eloquent\Builder;
14 use Illuminate\Database\Eloquent\Collection; 16 use Illuminate\Database\Eloquent\Collection;
15 use Illuminate\Database\Eloquent\Model; 17 use Illuminate\Database\Eloquent\Model;
@@ -74,7 +76,7 @@ class DomainInfoLogic extends BaseLogic @@ -74,7 +76,7 @@ class DomainInfoLogic extends BaseLogic
74 $request = $this->param; 76 $request = $this->param;
75 $this->extracted($request, $domain, $original); 77 $this->extracted($request, $domain, $original);
76 // 检查ip是否存在 78 // 检查ip是否存在
77 - if(array_key_exists('domain', $request)){ 79 + if (array_key_exists('domain', $request)) {
78 if ($domain->domain != $request['domain']) { 80 if ($domain->domain != $request['domain']) {
79 if ($this->checkDomain($request['domain'])) { 81 if ($this->checkDomain($request['domain'])) {
80 $this->fail('域名信息修改失败,域名已存在', Code::USER_ERROR); 82 $this->fail('域名信息修改失败,域名已存在', Code::USER_ERROR);
@@ -254,15 +256,23 @@ class DomainInfoLogic extends BaseLogic @@ -254,15 +256,23 @@ class DomainInfoLogic extends BaseLogic
254 256
255 /** 257 /**
256 * 域名到期时间 258 * 域名到期时间
  259 + * @param $domain
257 * @return array 260 * @return array
  261 + * @throws GuzzleException
258 */ 262 */
259 public function getDomainTime($domain) 263 public function getDomainTime($domain)
260 { 264 {
261 - $conJson = file_get_contents("http://openai.waimaoq.com/v1/whois_api?domain={$domain}");  
262 - $conArr = json_decode($conJson, true);  
263 - $data = [];  
264 - if ($conArr['code'] == 200) {  
265 - $con = $conArr['text']; 265 + $url = "http://openai.waimaoq.com/v1/whois_api?domain={$domain}";
  266 + $client = new Client(['verify' => false]);
  267 + $http = $client->get($url);
  268 + $data = [];
  269 + if ($http->getStatusCode() != 200) {
  270 + return $data;
  271 + }
  272 + $content = $http->getBody()->getContents();
  273 + $json = json_decode($content, true);
  274 + if ($json['code'] == 200) {
  275 + $con = $json['text'];
266 $data['domain'] = $domain; 276 $data['domain'] = $domain;
267 $data['validFrom'] = $con['creation_date']; 277 $data['validFrom'] = $con['creation_date'];
268 $data['validTo'] = $con['expiration_date']; 278 $data['validTo'] = $con['expiration_date'];
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Bside\Statistics;
  4 +
  5 +use App\Http\Logic\Bside\BaseLogic;
  6 +use App\Models\Bside\Statistics\TrafficStatistics;
  7 +use App\Models\CustomerVisit\CustomerVisit;
  8 +use GuzzleHttp\Exception\GuzzleException;
  9 +use Illuminate\Contracts\Cache\Repository;
  10 +use Illuminate\Support\Facades\DB;
  11 +use Psr\Container\ContainerExceptionInterface;
  12 +use Psr\Container\NotFoundExceptionInterface;
  13 +use Throwable;
  14 +
  15 +class StatisticsLogic extends BaseLogic
  16 +{
  17 + public $trafficStatistics;
  18 +
  19 + private $customerVisit;
  20 +
  21 + public $date;
  22 +
  23 + public $time = 60 * 60 * 2;
  24 +
  25 + public function __construct()
  26 + {
  27 + parent::__construct();
  28 + $this->customerVisit = new CustomerVisit();
  29 + $this->trafficStatistics = new TrafficStatistics();
  30 + try {
  31 + $this->date = request()->get('date') ?? null;
  32 + // 判断传入日期是否大于当月
  33 + if ($this->checkIsGreaterMonth($this->date)) {
  34 + $this->date = null;
  35 + }
  36 + // 判断传入日期是否是当月
  37 + if ($this->checkIsMonth($this->date)) {
  38 + $this->date = null;
  39 + }
  40 + } catch (NotFoundExceptionInterface|ContainerExceptionInterface $e) {
  41 + $this->date = null;
  42 + }
  43 + }
  44 +
  45 + /**
  46 + * @param $type
  47 + * @return array|Repository|mixed
  48 + * @throws ContainerExceptionInterface
  49 + * @throws NotFoundExceptionInterface|Throwable
  50 + */
  51 + public function getStatisticsData($type)
  52 + {
  53 + $function = debug_backtrace()[1]['function'];
  54 + // 判断是否查询当月数据
  55 + if (!is_null($this->date)) {
  56 + // 获取缓存名
  57 + $key = $this->cacheName($type, $this->date);
  58 + $response = cache()->get($key);
  59 + if (empty($response)) {
  60 + $dd = explode('-', $this->date);
  61 + $year = $dd[0] ?? null;
  62 + $month = str_pad($dd[1], 2, '0', STR_PAD_LEFT) ?? null;
  63 + // 获取当前数据是否存在
  64 + $data = $this->trafficStatistics->getData($type, $year, $month);
  65 + if (is_null($data)) {
  66 + $response = $this->$function();
  67 + // 存在则直接返回
  68 + $response_data = array_filter($response);
  69 + if ($response_data) {
  70 + // 不存在则请求接口获取数据并保存
  71 + $this->create($response_data);
  72 + }
  73 + } else {
  74 + $response = $data->toArray();
  75 + }
  76 + // 缓存数据
  77 + cache()->put($key, $response, $this->time);
  78 + }
  79 + } else {
  80 + $response = $this->$function();
  81 + }
  82 + return $response;
  83 + }
  84 +
  85 + /**
  86 + * @param $response
  87 + * @return bool
  88 + * @throws Throwable
  89 + */
  90 + public function create($response)
  91 + {
  92 + DB::beginTransaction();
  93 + $keys = array_flip($this->trafficStatistics::KEY_VALUE);
  94 + foreach ($response as $k => $v) {
  95 + if (is_array($v)) {
  96 + $v = json_encode($v);
  97 + }
  98 + $field = $keys[$k];
  99 + $this->trafficStatistics->$field = $v;
  100 + }
  101 + $isRes = $this->trafficStatistics->save();
  102 + if (!$isRes) {
  103 + DB::rollBack();
  104 + return false;
  105 + }
  106 + DB::commit();
  107 + return true;
  108 + }
  109 +
  110 + /**
  111 + * 访问来源
  112 + * @return array
  113 + */
  114 + public function source()
  115 + {
  116 + $response = $this->getPvIp();
  117 + $response['lists'] = $this->customerVisit->getUrlCount();
  118 + return $response;
  119 + }
  120 +
  121 + public function getPvIp()
  122 + {
  123 + $response['pv_count'] = $this->customerVisit->getMonthPVCount();
  124 + $response['ip_count'] = $this->customerVisit->getMonthIPCount();
  125 + return $response;
  126 + }
  127 +
  128 + /**
  129 + * 地域分布
  130 + * @return array
  131 + */
  132 + public function distribution()
  133 + {
  134 + $response = $this->getPvIp();
  135 + $response['lists'] = $this->customerVisit->getCountryCount();
  136 + return $response;
  137 + }
  138 +
  139 + /**
  140 + * 流量趋势
  141 + * @return array
  142 + * @throws ContainerExceptionInterface
  143 + * @throws GuzzleException
  144 + * @throws NotFoundExceptionInterface
  145 + */
  146 + public function trend()
  147 + {
  148 + $response = $this->getPvIp();
  149 + $inquiry = $this->getCache('inquiry_information', $this->date);
  150 + $response['in_count'] = $inquiry['count'] ?? 0;
  151 + $response['lists'] = $inquiry['lists'] ?? [];
  152 + return $response;
  153 + }
  154 +
  155 + /**
  156 + * 访问终端
  157 + * @return array
  158 + */
  159 + public function terminal()
  160 + {
  161 + $response = $this->getPvIp();
  162 + $response['pc_count'] = $this->customerVisit->getTerminalPcCount();
  163 + $response['mobile_count'] = $this->customerVisit->getTerminalMobileCount();
  164 + $response['lists'] = $this->customerVisit->getCountryCount();
  165 + return $response;
  166 + }
  167 +
  168 + /**
  169 + * 受访页面
  170 + * @return array
  171 + */
  172 + public function page()
  173 + {
  174 + $response = $this->getPvIp();
  175 + $response['lists'] = $this->customerVisit->getPageCount();
  176 + return $response;
  177 + }
  178 +
  179 + /**
  180 + * 获取缓存
  181 + * @param string $key 缓存键名
  182 + * @param string|null $date 日期 格式:Y-m
  183 + * @param float|int $time 缓存时间,默认2小时
  184 + * @return mixed
  185 + * @throws ContainerExceptionInterface
  186 + * @throws GuzzleException
  187 + * @throws NotFoundExceptionInterface
  188 + */
  189 + public function getCache(string $key, string $date = null, $time = 60 * 60 * 2)
  190 + {
  191 + $domain = request()->getHttpHost(); //'www.wowstainless.com';
  192 + $sta_date = !is_null($date) ? $date . '-01' : date('Y-m-01');
  193 + $key = $key . '_' . stringUnderlineLowercase($domain) . '_' . str_replace('-', '_', $sta_date);
  194 + $value = cache()->get($key);
  195 + if (!$value) {
  196 + $value = getInquiryInformation($domain, $sta_date);
  197 + cache()->put($key, $value, $time);
  198 + }
  199 + return $value;
  200 + }
  201 +
  202 + /**
  203 + * @param int $type
  204 + * @param string|null $date 日期 格式:Y-m-d
  205 + * @return string
  206 + */
  207 + public function cacheName(int $type = TrafficStatistics::TYPE_SOURCE, string $date = null)
  208 + {
  209 + return 'statistics_' . $type . '_' . str_replace('-', '_', $date);
  210 + }
  211 +
  212 + /**
  213 + * 判断传入日期是否是当日
  214 + * @param $date
  215 + * @return bool
  216 + */
  217 + public function checkIsDay($date)
  218 + {
  219 + // 传入日期的时间戳
  220 + $timestamp = strtotime($date);
  221 + // 当日的日期格式,如:2021-10-13
  222 + $today = date('Y-m-d');
  223 + // 传入日期的日期格式,如:2021-10-12
  224 + $date = date('Y-m-d', $timestamp);
  225 + // 判断传入日期是否是当日
  226 + return $date == $today;
  227 + }
  228 +
  229 + /**
  230 + * 判断传入日期是否大于当日
  231 + * @param $date
  232 + * @return bool
  233 + */
  234 + public function checkIsGreaterDay($date)
  235 + {
  236 + // 传入日期的时间戳
  237 + $timestamp = strtotime($date);
  238 + // 当前日期的时间戳
  239 + $now = strtotime(date('Y-m-d'));
  240 + // 判断传入日期是否大于当前日期
  241 + return $timestamp > $now;
  242 + }
  243 +
  244 + /**
  245 + * 判断传入日期是否大于当月
  246 + * @param $date
  247 + * @return bool
  248 + */
  249 + public function checkIsGreaterMonth($date)
  250 + {
  251 + // 传入日期的时间戳
  252 + $timestamp = strtotime($date);
  253 + // 当前月份的时间戳
  254 + $nowMonth = strtotime(date('Y-m'));
  255 + // 判断传入日期是否大于当前月份
  256 + return $timestamp > $nowMonth;
  257 + }
  258 +
  259 + /**
  260 + * 判断传入日期是否是当月
  261 + * @param $date
  262 + * @return bool
  263 + */
  264 + public function checkIsMonth($date)
  265 + {
  266 + // 获取当前时间戳
  267 + $now = time();
  268 + // 获取当月的起始时间戳和结束时间戳
  269 + $firstDay = strtotime(date('Y-m-01', $now));
  270 + $lastDay = strtotime(date('Y-m-t', $now));
  271 + // 传入日期的时间戳
  272 + $timestamp = strtotime($date);
  273 + // 判断传入日期是否在当月范围内
  274 + return $timestamp >= $firstDay && $timestamp <= $lastDay;
  275 + }
  276 +}
@@ -6,10 +6,37 @@ use App\Models\Base; @@ -6,10 +6,37 @@ use App\Models\Base;
6 6
7 /** 7 /**
8 * Class DomainInfo 8 * Class DomainInfo
  9 + *
9 * @package App\Models\Aside\Domain 10 * @package App\Models\Aside\Domain
10 * @Author YiYuan-LIn 11 * @Author YiYuan-LIn
11 - * @Date: 2019/5/16 12 + * @Date : 2019/5/16
12 * 域名信息模型 13 * 域名信息模型
  14 + * @property int $id
  15 + * @property string|null $domain 域名
  16 + * @property string $belong_to 域名归属 1 - 公司 2 - 客户
  17 + * @property string $status 域名状态 0 - 正常 1 - 关闭
  18 + * @property string|null $domain_start_time 域名开始时间
  19 + * @property string|null $domain_end_time 域名结束时间
  20 + * @property string|null $certificate_start_time 证书开始时间
  21 + * @property string|null $certificate_end_time 证书结束时间
  22 + * @property \Illuminate\Support\Carbon|null $created_at
  23 + * @property \Illuminate\Support\Carbon|null $updated_at
  24 + * @property int|null $deleted 软删除 0 - 正常 1 - 软删除
  25 + * @method static \Illuminate\Database\Eloquent\Builder|DomainInfo newModelQuery()
  26 + * @method static \Illuminate\Database\Eloquent\Builder|DomainInfo newQuery()
  27 + * @method static \Illuminate\Database\Eloquent\Builder|DomainInfo query()
  28 + * @method static \Illuminate\Database\Eloquent\Builder|DomainInfo whereBelongTo($value)
  29 + * @method static \Illuminate\Database\Eloquent\Builder|DomainInfo whereCertificateEndTime($value)
  30 + * @method static \Illuminate\Database\Eloquent\Builder|DomainInfo whereCertificateStartTime($value)
  31 + * @method static \Illuminate\Database\Eloquent\Builder|DomainInfo whereCreatedAt($value)
  32 + * @method static \Illuminate\Database\Eloquent\Builder|DomainInfo whereDeleted($value)
  33 + * @method static \Illuminate\Database\Eloquent\Builder|DomainInfo whereDomain($value)
  34 + * @method static \Illuminate\Database\Eloquent\Builder|DomainInfo whereDomainEndTime($value)
  35 + * @method static \Illuminate\Database\Eloquent\Builder|DomainInfo whereDomainStartTime($value)
  36 + * @method static \Illuminate\Database\Eloquent\Builder|DomainInfo whereId($value)
  37 + * @method static \Illuminate\Database\Eloquent\Builder|DomainInfo whereStatus($value)
  38 + * @method static \Illuminate\Database\Eloquent\Builder|DomainInfo whereUpdatedAt($value)
  39 + * @mixin \Eloquent
13 */ 40 */
14 class DomainInfo extends Base 41 class DomainInfo extends Base
15 { 42 {
@@ -4,6 +4,36 @@ namespace App\Models\Aside\Domain; @@ -4,6 +4,36 @@ namespace App\Models\Aside\Domain;
4 4
5 use Illuminate\Database\Eloquent\Model; 5 use Illuminate\Database\Eloquent\Model;
6 6
  7 +/**
  8 + * App\Models\Aside\Domain\DomainInfoLog
  9 + *
  10 + * @property int $id
  11 + * @property int|null $user_id 操作用户
  12 + * @property string|null $action 用户操作 - 增删改查
  13 + * @property string|null $original 初始数据
  14 + * @property string|null $revised 修改后的数据
  15 + * @property string|null $ip 用户IP
  16 + * @property string|null $url
  17 + * @property string|null $method 请求类型
  18 + * @property string|null $remarks 备注
  19 + * @property \Illuminate\Support\Carbon|null $created_at
  20 + * @property \Illuminate\Support\Carbon|null $updated_at
  21 + * @method static \Illuminate\Database\Eloquent\Builder|DomainInfoLog newModelQuery()
  22 + * @method static \Illuminate\Database\Eloquent\Builder|DomainInfoLog newQuery()
  23 + * @method static \Illuminate\Database\Eloquent\Builder|DomainInfoLog query()
  24 + * @method static \Illuminate\Database\Eloquent\Builder|DomainInfoLog whereAction($value)
  25 + * @method static \Illuminate\Database\Eloquent\Builder|DomainInfoLog whereCreatedAt($value)
  26 + * @method static \Illuminate\Database\Eloquent\Builder|DomainInfoLog whereId($value)
  27 + * @method static \Illuminate\Database\Eloquent\Builder|DomainInfoLog whereIp($value)
  28 + * @method static \Illuminate\Database\Eloquent\Builder|DomainInfoLog whereMethod($value)
  29 + * @method static \Illuminate\Database\Eloquent\Builder|DomainInfoLog whereOriginal($value)
  30 + * @method static \Illuminate\Database\Eloquent\Builder|DomainInfoLog whereRemarks($value)
  31 + * @method static \Illuminate\Database\Eloquent\Builder|DomainInfoLog whereRevised($value)
  32 + * @method static \Illuminate\Database\Eloquent\Builder|DomainInfoLog whereUpdatedAt($value)
  33 + * @method static \Illuminate\Database\Eloquent\Builder|DomainInfoLog whereUrl($value)
  34 + * @method static \Illuminate\Database\Eloquent\Builder|DomainInfoLog whereUserId($value)
  35 + * @mixin \Eloquent
  36 + */
7 class DomainInfoLog extends Model 37 class DomainInfoLog extends Model
8 { 38 {
9 protected $table = 'gl_domain_info_log'; 39 protected $table = 'gl_domain_info_log';
  1 +<?php
  2 +
  3 +namespace App\Models\Bside\Statistics;
  4 +
  5 +use App\Models\Base;
  6 +use Illuminate\Database\Eloquent\Builder;
  7 +use Illuminate\Database\Eloquent\Collection;
  8 +use Illuminate\Database\Eloquent\Model;
  9 +
  10 +/**
  11 + * App\Models\Bside\Statistics\TrafficStatistics
  12 + *
  13 + * @property int $id
  14 + * @property int|null $type 类型:
  15 + * 1 - 访问来源
  16 + * 2 - 地域分布
  17 + * 3 - 受访页面
  18 + * 4 - 访问终端
  19 + * 5 - 流量趋势
  20 + * @property int|null $year 年
  21 + * @property int|null $month 月
  22 + * @property string|null $top 访问来源|国家|页面TOP15 - 百分比 - json格式
  23 + * @property int|null $innum 询盘量
  24 + * @property float|null $conversion 询盘转化率
  25 + * @property int|null $pvnum 浏览量
  26 + * @property int|null $ipnum 访客量
  27 + * @property int|null $pcnum PC端访问量
  28 + * @property int|null $mbnum 移动端访问量
  29 + * @property \Illuminate\Support\Carbon|null $created_at
  30 + * @property \Illuminate\Support\Carbon|null $updated_at
  31 + * @method static Builder|TrafficStatistics newModelQuery()
  32 + * @method static Builder|TrafficStatistics newQuery()
  33 + * @method static Builder|TrafficStatistics query()
  34 + * @method static Builder|TrafficStatistics whereConversion($value)
  35 + * @method static Builder|TrafficStatistics whereCreatedAt($value)
  36 + * @method static Builder|TrafficStatistics whereId($value)
  37 + * @method static Builder|TrafficStatistics whereInnum($value)
  38 + * @method static Builder|TrafficStatistics whereIpnum($value)
  39 + * @method static Builder|TrafficStatistics whereMbnum($value)
  40 + * @method static Builder|TrafficStatistics whereMonth($value)
  41 + * @method static Builder|TrafficStatistics wherePageview($value)
  42 + * @method static Builder|TrafficStatistics wherePcnum($value)
  43 + * @method static Builder|TrafficStatistics wherePvnum($value)
  44 + * @method static Builder|TrafficStatistics whereTop($value)
  45 + * @method static Builder|TrafficStatistics whereType($value)
  46 + * @method static Builder|TrafficStatistics whereUpdatedAt($value)
  47 + * @method static Builder|TrafficStatistics whereUserSessions($value)
  48 + * @method static Builder|TrafficStatistics whereYear($value)
  49 + * @mixin \Eloquent
  50 + */
  51 +class TrafficStatistics extends Base
  52 +{
  53 + protected $table = 'gl_traffic_statistics';
  54 +
  55 + /** @var int 访问来源 */
  56 + const TYPE_SOURCE = 1;
  57 + /** @var int 地域分布 */
  58 + const TYPE_DISTRIBUTION = 2;
  59 + /** @var int 受访页面 */
  60 + const TYPE_PAGE = 3;
  61 + /** @var int 访问终端 */
  62 + const TYPE_TERMINAL = 4;
  63 + /** @var int 流量趋势 */
  64 + const TYPE_TREND = 5;
  65 + /** @var string[] 类型对应字段 */
  66 + const FIELDS = [
  67 + self::TYPE_SOURCE => ['pvnum', 'ipnum', 'top'],
  68 + self::TYPE_DISTRIBUTION => ['pvnum', 'ipnum', 'top'],
  69 + self::TYPE_PAGE => ['pvnum', 'ipnum', 'top'],
  70 + self::TYPE_TERMINAL => ['pvnum', 'ipnum', 'top', 'pcnum', 'mbnum'],
  71 + self::TYPE_TREND => ['pvnum', 'ipnum', 'top', 'innum'],
  72 + ];
  73 + /** @var string[] 数据库字段对应返回字段 */
  74 + const KEY_VALUE = [
  75 + 'pvnum' => 'pv_count',
  76 + 'ipnum' => 'ip_count',
  77 + 'pcnum' => 'pc_count',
  78 + 'mbnum' => 'mobile_count',
  79 + 'innum' => 'in_count',
  80 + 'top' => 'lists'
  81 + ];
  82 +
  83 + /**
  84 + * 根据类型获取字段
  85 + * @param int $type
  86 + * @return string[]
  87 + */
  88 + public function selectFields(int $type = self::TYPE_SOURCE)
  89 + {
  90 + return self::FIELDS[$type] ?? [];
  91 + }
  92 +
  93 + /**
  94 + * 根据类型获取月份列表数据
  95 + * @param int $type
  96 + * @param $date
  97 + * @return TrafficStatistics[]|Builder[]|Collection
  98 + */
  99 + public function getMonthsLists(int $type = self::TYPE_SOURCE, $date = null)
  100 + {
  101 + $query = $this->query()->where('type', $type);
  102 + if ($date != null) {
  103 + if (is_array($date)) {
  104 + $years = $months = [];
  105 + foreach ($date as $value) {
  106 + $dd = explode('-', $value);
  107 + $year = $dd[0];
  108 + $month = $dd[1];
  109 + if (!in_array($year, $years)) {
  110 + $years[] = $year;
  111 + }
  112 + if (!in_array($month, $months)) {
  113 + $months[] = $month;
  114 + }
  115 + }
  116 + $query->whereIn('year', $years)
  117 + ->whereIn('month', $months);
  118 + } else {
  119 + $dd = explode('-', $date);
  120 + $year = $dd[0];
  121 + $month = $dd[1];
  122 + $query->where('year', $year)
  123 + ->where('month', $month);
  124 + }
  125 + } else {
  126 + $query->where('year', date('Y'))
  127 + ->where('month', date('m'));
  128 + }
  129 + return $query->get();
  130 + }
  131 +
  132 + /**
  133 + * 根据类型获取单条月份数据
  134 + * @param int $type
  135 + * @param $year
  136 + * @param $month
  137 + * @return TrafficStatistics|Builder|Model|object|null
  138 + */
  139 + public function getMonth(int $type = self::TYPE_SOURCE, $year = null, $month = null)
  140 + {
  141 + $year = $year ?? date('Y');
  142 + $month = $month ?? date('m');
  143 + return $this->query()->where('type', $type)
  144 + ->where('year', $year)
  145 + ->where('month', $month)
  146 + ->first();
  147 + }
  148 +
  149 + /**
  150 + * 根据类型获取数据
  151 + * @param int $type
  152 + * @param null $year
  153 + * @param null $month
  154 + * @return TrafficStatistics|Builder|Model|object|null
  155 + */
  156 + public function getData(int $type = self::TYPE_SOURCE, $year = null, $month = null)
  157 + {
  158 + $key_value = self::KEY_VALUE;
  159 + $field_arr = [];
  160 + foreach ($this->selectFields($type) as $field) {
  161 + $field_arr[] = "{$field} as {$key_value[$field]}";
  162 + }
  163 + $query = $this->query();
  164 + if ($field_arr) {
  165 + $query->selectRaw(implode(',', $field_arr));
  166 + }
  167 + return $query->where('type', $type)
  168 + ->where('year', $year)
  169 + ->where('month', $month)
  170 + ->first();
  171 + }
  172 +
  173 + /**
  174 + * 格式化数据
  175 + * @param $value
  176 + * @return mixed
  177 + */
  178 + public function getListsAttribute($value)
  179 + {
  180 + return json_decode($value);
  181 + }
  182 +}
  1 +<?php
  2 +
  3 +namespace App\Models\Bside\Statistics;
  4 +
  5 +use App\Models\Base;
  6 +use Illuminate\Database\Eloquent\Builder;
  7 +use Illuminate\Database\Eloquent\Collection;
  8 +use Illuminate\Database\Eloquent\Model;
  9 +
  10 +/**
  11 + * App\Models\Bside\Statistics\TrafficTrends
  12 + *
  13 + * @property int $id
  14 + * @property string|null $day 统计当天日期
  15 + * @property int|null $pvnum 当天的访问次数PV
  16 + * @property int|null $ipnum 当天的独立访问IP数量
  17 + * @property \Illuminate\Support\Carbon|null $created_at
  18 + * @property \Illuminate\Support\Carbon|null $updated_at
  19 + * @method static Builder|TrafficTrends newModelQuery()
  20 + * @method static Builder|TrafficTrends newQuery()
  21 + * @method static Builder|TrafficTrends query()
  22 + * @method static Builder|TrafficTrends whereCreatedAt($value)
  23 + * @method static Builder|TrafficTrends whereDay($value)
  24 + * @method static Builder|TrafficTrends whereId($value)
  25 + * @method static Builder|TrafficTrends whereIpnum($value)
  26 + * @method static Builder|TrafficTrends wherePvnum($value)
  27 + * @method static Builder|TrafficTrends whereUpdatedAt($value)
  28 + * @mixin \Eloquent
  29 + */
  30 +class TrafficTrends extends Base
  31 +{
  32 + protected $table = 'gl_traffic_trends';
  33 +
  34 + /**
  35 + * * 根据时间获取数据
  36 + * @param array|string $date
  37 + * @return TrafficTrends[]|Builder[]|Collection
  38 + */
  39 + public function getDaysLists($date = null)
  40 + {
  41 + $query = $this->query();
  42 + if ($date != null) {
  43 + if (is_array($date)) {
  44 + $query->whereIn('day', $date);
  45 + } else {
  46 + $query->where('day', $date);
  47 + }
  48 + } else {
  49 + $query->whereYear('day', '=', date("Y"))
  50 + ->whereMonth('day', '=', date("m"))
  51 + ->whereDay('day', '=', date("d"));
  52 + }
  53 + return $query->get();
  54 + }
  55 +
  56 + /**
  57 + * @param string|null $date
  58 + * @return TrafficTrends|Builder|Model|object|null
  59 + */
  60 + public function getDay(string $date = null)
  61 + {
  62 + return $this->query()->where('day', $date ?? date('Y-m-d'))->first();
  63 + }
  64 +}
@@ -3,8 +3,273 @@ @@ -3,8 +3,273 @@
3 namespace App\Models\CustomerVisit; 3 namespace App\Models\CustomerVisit;
4 4
5 use App\Models\Base; 5 use App\Models\Base;
  6 +use Illuminate\Database\Eloquent\Builder;
  7 +use Illuminate\Database\Eloquent\Collection;
  8 +use Illuminate\Database\Eloquent\Factories\HasFactory;
6 9
  10 +/**
  11 + * App\Models\CustomerVisit\CustomerVisit
  12 + *
  13 + * @property int $id ID
  14 + * @property string $url 客户访问URL
  15 + * @property string $referrer_url 访问来源
  16 + * @property int $device_port 设备端口 1:PC端,2:移动端
  17 + * @property string $country 国家
  18 + * @property string $city 地区
  19 + * @property string $ip 访问ip
  20 + * @property int $depth 访问深度
  21 + * @property string $domain 域名
  22 + * @property \Illuminate\Support\Carbon $created_at 访问时间
  23 + * @property \Illuminate\Support\Carbon $updated_at 更新时间
  24 + * @property string $updated_date 统计日期
  25 + * @method static \Database\Factories\CustomerVisit\CustomerVisitFactory factory(...$parameters)
  26 + * @method static Builder|CustomerVisit newModelQuery()
  27 + * @method static Builder|CustomerVisit newQuery()
  28 + * @method static Builder|CustomerVisit query()
  29 + * @method static Builder|CustomerVisit whereCity($value)
  30 + * @method static Builder|CustomerVisit whereCountry($value)
  31 + * @method static Builder|CustomerVisit whereCreatedAt($value)
  32 + * @method static Builder|CustomerVisit whereDepth($value)
  33 + * @method static Builder|CustomerVisit whereDevicePort($value)
  34 + * @method static Builder|CustomerVisit whereDomain($value)
  35 + * @method static Builder|CustomerVisit whereId($value)
  36 + * @method static Builder|CustomerVisit whereIp($value)
  37 + * @method static Builder|CustomerVisit whereReferrerUrl($value)
  38 + * @method static Builder|CustomerVisit whereUpdatedAt($value)
  39 + * @method static Builder|CustomerVisit whereUpdatedDate($value)
  40 + * @method static Builder|CustomerVisit whereUrl($value)
  41 + * @mixin \Eloquent
  42 + */
7 class CustomerVisit extends Base 43 class CustomerVisit extends Base
8 { 44 {
  45 + use HasFactory;
  46 +
9 protected $table = 'gl_customer_visit'; 47 protected $table = 'gl_customer_visit';
  48 +
  49 + const LIMIT = 15;
  50 +
  51 + /** @var int PC端 */
  52 + const TERMINAL_PC = 1;
  53 + /** @var int 移动端 */
  54 + const TERMINAL_MOBILE = 2;
  55 +
  56 + /**
  57 + * @param string $field 统计字段
  58 + * @param string $action 统计方法 count|sum
  59 + * @param bool $isDay 是否按天查询
  60 + * @param string|null $date 日期 格式:Y-m-d
  61 + * @return int
  62 + */
  63 + public function queryField(string $field, string $action = 'count', bool $isDay = false, string $date = null)
  64 + {
  65 + $query = $this->query()->selectRaw("{$action}({$field}) as count");
  66 + if ($date) {
  67 + $dd = explode('-', $date);
  68 + $year = $dd[0] ?? null;
  69 + $month = $dd[1] ?? null;
  70 + $day = $dd[2] ?? null;
  71 + if (!is_null($year)) {
  72 + $query->whereYear('updated_date', '=', $year);
  73 + }
  74 + if (!is_null($month)) {
  75 + $query->whereMonth('updated_date', '=', $month);
  76 + }
  77 + if (!is_null($day)) {
  78 + $query->whereDay('updated_date', '=', $day);
  79 + }
  80 + } else {
  81 + $query->whereYear('updated_date', '=', date("Y"))
  82 + ->whereMonth('updated_date', '=', date("m"));
  83 + if ($isDay) {
  84 + $query->whereDay('updated_date', '=', date("d"));
  85 + }
  86 + }
  87 +
  88 + return (int)$query->value('count') ?? 0;
  89 + }
  90 +
  91 +
  92 + /**
  93 + * @param string $field 统计字段
  94 + * @param int $action 终端类型
  95 + * @param string|null $date 日期 格式:Y-m
  96 + * @return int
  97 + */
  98 + public function queryTerminal(string $field, string $date = null, int $action = self::TERMINAL_PC)
  99 + {
  100 + $query = $this->query()
  101 + ->selectRaw("count(*) as count")
  102 + ->where($field, '=', $action);
  103 + $this->extracted($date, $query);
  104 + return (int)$query->value('count') ?? 0;
  105 + }
  106 +
  107 + /**
  108 + * @param string $field 查询字段
  109 + * @param string|null $date 日期 格式:Y-m-d
  110 + * @param int $limit 查询条数
  111 + * @return Builder[]|Collection|\Illuminate\Support\Collection
  112 + */
  113 + public function getRankingData(string $field, string $date = null, int $limit = self::LIMIT)
  114 + {
  115 + $query = $this->query()
  116 + ->selectRaw('count(*) as count, ' . $field . ' as request');
  117 + $this->extracted($date, $query);
  118 + return $query->groupBy($field)
  119 + ->orderBy('count', 'desc')
  120 + ->limit($limit)
  121 + ->get();
  122 + }
  123 +
  124 + /**
  125 + * 获取相加总数
  126 + * @param string $field
  127 + * @param string|null $date 日期 格式:Y-m-d
  128 + * @return int
  129 + */
  130 + public function getSum(string $field, string $date = null)
  131 + {
  132 + return $this->queryField($field, 'sum', false, $date);
  133 + }
  134 +
  135 + /**
  136 + * 获取总数
  137 + * @param string $field
  138 + * @param string|null $date 日期 格式:Y-m-d
  139 + * @return int
  140 + */
  141 + public function getCount(string $field, string $date = null)
  142 + {
  143 + return $this->queryField($field, 'count', false, $date);
  144 + }
  145 +
  146 + /**
  147 + * 获取列表和总数
  148 + * @param Collection $data
  149 + * @param int $limit
  150 + * @return array
  151 + */
  152 + public function returnLists(Collection $data, int $limit = self::LIMIT)
  153 + {
  154 + $lists = $data->toArray();
  155 + $lists = $lists ? array_slice($lists, 0, $limit) : [];
  156 + $count = $data->count();
  157 + return compact('lists', 'count');
  158 + }
  159 +
  160 + /**
  161 + * 查询当月流量的浏览量
  162 + * @param string|null $data 日期 格式:Y-m-d
  163 + * @return int
  164 + */
  165 + public function getMonthPVCount(string $data = null)
  166 + {
  167 + return $this->getSum('depth', $data);
  168 + }
  169 +
  170 + /**
  171 + * 查询当月流量的访客量
  172 + * @param string|null $data 日期 格式:Y-m-d
  173 + * @return int
  174 + */
  175 + public function getMonthIPCount(string $data = null)
  176 + {
  177 + return $this->getCount('ip', $data);
  178 + }
  179 +
  180 + /**
  181 + * 查询当月TOP15访问来源
  182 + * @param string|null $date 日期 格式:Y-m-d
  183 + * @param int $limit 查询条数
  184 + * @return array
  185 + */
  186 + public function getUrlCount(string $date = null, int $limit = self::LIMIT)
  187 + {
  188 + return $this->getRankingData('referrer_url', $date, $limit);
  189 + }
  190 +
  191 + /**
  192 + * 查询当月TOP15访问国家来源
  193 + * @param string|null $date 日期 格式:Y-m
  194 + * @param int $limit
  195 + * @return array
  196 + */
  197 + public function getCountryCount(string $date = null, int $limit = self::LIMIT)
  198 + {
  199 + return $this->getRankingData('country', $date, $limit);
  200 + }
  201 +
  202 + /**
  203 + * 查询当月TOP15受访页面
  204 + * @param string|null $date 日期 格式:Y-m
  205 + * @param int $limit
  206 + * @return array
  207 + */
  208 + public function getPageCount(string $date = null, int $limit = self::LIMIT)
  209 + {
  210 + return $this->getRankingData('url', $date, $limit);
  211 + }
  212 +
  213 + /**
  214 + * 查询当月TOP15访问终端
  215 + * @param string|null $date 日期 格式:Y-m-d
  216 + * @return int
  217 + */
  218 + public function getTerminalPcCount(string $date = null)
  219 + {
  220 + return $this->queryTerminal('device_port', $date);
  221 + }
  222 +
  223 + /**
  224 + * 查询当月TOP15访问终端
  225 + * @param string|null $date 日期 格式:Y-m-d
  226 + * @return int
  227 + */
  228 + public function getTerminalMobileCount(string $date = null)
  229 + {
  230 + return $this->queryTerminal('device_port', $date, self::TERMINAL_MOBILE);
  231 + }
  232 +
  233 + /**
  234 + * 查询当日流量的浏览量
  235 + * @param string|null $date 日期 格式:Y-m-d
  236 + * @return int
  237 + */
  238 + public function getDayPVCount(string $date = null)
  239 + {
  240 + return $this->queryField('depth', 'sum', true, $date);
  241 + }
  242 +
  243 + /**
  244 + * 查询当日流量的访客量
  245 + * @param string|null $date 日期 格式:Y-m-d
  246 + * @return int
  247 + */
  248 + public function getDayIPCount(string $date = null)
  249 + {
  250 + return $this->queryField('ip', 'count', true, $date);
  251 + }
  252 +
  253 + /**
  254 + * @param $date
  255 + * @param $query
  256 + * @return void
  257 + */
  258 + public function extracted($date, $query)
  259 + {
  260 + if (!is_null($date)) {
  261 + $dd = explode('-', $date);
  262 + $year = $dd[0] ?? null;
  263 + $month = $dd[1] ?? null;
  264 + if (!is_null($year)) {
  265 + $query->whereYear('updated_date', '=', $year);
  266 + }
  267 + if (!is_null($month)) {
  268 + $query->whereMonth('updated_date', '=', $month);
  269 + }
  270 + } else {
  271 + $query->whereYear('updated_date', '=', date("Y"))
  272 + ->whereMonth('updated_date', '=', date("m"));
  273 + }
  274 + }
10 } 275 }
@@ -4,6 +4,36 @@ namespace App\Models\Devops; @@ -4,6 +4,36 @@ namespace App\Models\Devops;
4 4
5 use App\Models\Base; 5 use App\Models\Base;
6 6
  7 +/**
  8 + * App\Models\Devops\ServerInformation
  9 + *
  10 + * @property int $id
  11 + * @property string $type 服务器类型
  12 + * @property string|null $ip 服务器ip
  13 + * @property string|null $title 服务器标题
  14 + * @property string $belong_to 服务器归属 1 - 公司 2 - 客户
  15 + * @property string|null $sshpass SSH 密码
  16 + * @property int|null $ports SSH 端口
  17 + * @property string|null $other 其他信息 json格式
  18 + * @property \Illuminate\Support\Carbon|null $created_at
  19 + * @property \Illuminate\Support\Carbon|null $updated_at
  20 + * @property int|null $deleted 软删除 0 - 正常 1 - 软删除
  21 + * @method static \Illuminate\Database\Eloquent\Builder|ServerInformation newModelQuery()
  22 + * @method static \Illuminate\Database\Eloquent\Builder|ServerInformation newQuery()
  23 + * @method static \Illuminate\Database\Eloquent\Builder|ServerInformation query()
  24 + * @method static \Illuminate\Database\Eloquent\Builder|ServerInformation whereBelongTo($value)
  25 + * @method static \Illuminate\Database\Eloquent\Builder|ServerInformation whereCreatedAt($value)
  26 + * @method static \Illuminate\Database\Eloquent\Builder|ServerInformation whereDeleted($value)
  27 + * @method static \Illuminate\Database\Eloquent\Builder|ServerInformation whereId($value)
  28 + * @method static \Illuminate\Database\Eloquent\Builder|ServerInformation whereIp($value)
  29 + * @method static \Illuminate\Database\Eloquent\Builder|ServerInformation whereOther($value)
  30 + * @method static \Illuminate\Database\Eloquent\Builder|ServerInformation wherePorts($value)
  31 + * @method static \Illuminate\Database\Eloquent\Builder|ServerInformation whereSshpass($value)
  32 + * @method static \Illuminate\Database\Eloquent\Builder|ServerInformation whereTitle($value)
  33 + * @method static \Illuminate\Database\Eloquent\Builder|ServerInformation whereType($value)
  34 + * @method static \Illuminate\Database\Eloquent\Builder|ServerInformation whereUpdatedAt($value)
  35 + * @mixin \Eloquent
  36 + */
7 class ServerInformation extends Base 37 class ServerInformation extends Base
8 { 38 {
9 39
@@ -4,6 +4,36 @@ namespace App\Models\Devops; @@ -4,6 +4,36 @@ namespace App\Models\Devops;
4 4
5 use App\Models\Base; 5 use App\Models\Base;
6 6
  7 +/**
  8 + * App\Models\Devops\ServerInformationLog
  9 + *
  10 + * @property int $id
  11 + * @property int|null $user_id 操作用户
  12 + * @property string|null $action 用户操作 - 增删改查
  13 + * @property string|null $original 初始数据
  14 + * @property string|null $revised 修改后的数据
  15 + * @property string|null $ip 用户IP
  16 + * @property string|null $url
  17 + * @property string|null $method 请求类型
  18 + * @property string|null $remarks 备注
  19 + * @property \Illuminate\Support\Carbon|null $created_at
  20 + * @property \Illuminate\Support\Carbon|null $updated_at
  21 + * @method static \Illuminate\Database\Eloquent\Builder|ServerInformationLog newModelQuery()
  22 + * @method static \Illuminate\Database\Eloquent\Builder|ServerInformationLog newQuery()
  23 + * @method static \Illuminate\Database\Eloquent\Builder|ServerInformationLog query()
  24 + * @method static \Illuminate\Database\Eloquent\Builder|ServerInformationLog whereAction($value)
  25 + * @method static \Illuminate\Database\Eloquent\Builder|ServerInformationLog whereCreatedAt($value)
  26 + * @method static \Illuminate\Database\Eloquent\Builder|ServerInformationLog whereId($value)
  27 + * @method static \Illuminate\Database\Eloquent\Builder|ServerInformationLog whereIp($value)
  28 + * @method static \Illuminate\Database\Eloquent\Builder|ServerInformationLog whereMethod($value)
  29 + * @method static \Illuminate\Database\Eloquent\Builder|ServerInformationLog whereOriginal($value)
  30 + * @method static \Illuminate\Database\Eloquent\Builder|ServerInformationLog whereRemarks($value)
  31 + * @method static \Illuminate\Database\Eloquent\Builder|ServerInformationLog whereRevised($value)
  32 + * @method static \Illuminate\Database\Eloquent\Builder|ServerInformationLog whereUpdatedAt($value)
  33 + * @method static \Illuminate\Database\Eloquent\Builder|ServerInformationLog whereUrl($value)
  34 + * @method static \Illuminate\Database\Eloquent\Builder|ServerInformationLog whereUserId($value)
  35 + * @mixin \Eloquent
  36 + */
7 class ServerInformationLog extends Base 37 class ServerInformationLog extends Base
8 { 38 {
9 protected $table = 'gl_server_information_log'; 39 protected $table = 'gl_server_information_log';
@@ -19,6 +19,7 @@ @@ -19,6 +19,7 @@
19 "mrgoon/aliyun-sms": "^2.0" 19 "mrgoon/aliyun-sms": "^2.0"
20 }, 20 },
21 "require-dev": { 21 "require-dev": {
  22 + "barryvdh/laravel-ide-helper": "^2.13",
22 "facade/ignition": "^2.5", 23 "facade/ignition": "^2.5",
23 "fakerphp/faker": "^1.9.1", 24 "fakerphp/faker": "^1.9.1",
24 "laravel/sail": "^1.0.1", 25 "laravel/sail": "^1.0.1",
@@ -106,7 +106,7 @@ return [ @@ -106,7 +106,7 @@ return [
106 | 106 |
107 */ 107 */
108 108
109 - 'faker_locale' => 'en_US', 109 + 'faker_locale' => 'zh_CN',
110 110
111 /* 111 /*
112 |-------------------------------------------------------------------------- 112 |--------------------------------------------------------------------------
@@ -167,6 +167,20 @@ Route::middleware(['bloginauth'])->group(function () { @@ -167,6 +167,20 @@ Route::middleware(['bloginauth'])->group(function () {
167 Route::any('describe/delete', [\App\Http\Controllers\Bside\Product\DescribeController::class, 'delete'])->name('product_describe_delete'); 167 Route::any('describe/delete', [\App\Http\Controllers\Bside\Product\DescribeController::class, 'delete'])->name('product_describe_delete');
168 }); 168 });
169 169
  170 + // 流量统计
  171 + Route::prefix('stat')->group(function () {
  172 + // 访问来源
  173 + Route::get('/source', [\App\Http\Controllers\Bside\StatisticsController::class, 'source'])->name('stat_source');
  174 + // 地域分布
  175 + Route::get('/distribution', [\App\Http\Controllers\Bside\StatisticsController::class, 'distribution'])->name('stat_distribution');
  176 + // 受访页面
  177 + Route::get('/page', [\App\Http\Controllers\Bside\StatisticsController::class, 'page'])->name('stat_page');
  178 + // 访问终端
  179 + Route::get('/terminal', [\App\Http\Controllers\Bside\StatisticsController::class, 'terminal'])->name('stat_terminal');
  180 + // 流量趋势
  181 + Route::get('/trend', [\App\Http\Controllers\Bside\StatisticsController::class, 'trend'])->name('stat_trend');
  182 + });
  183 +
170 //组织架构 184 //组织架构
171 Route::prefix('dept')->group(function () { 185 Route::prefix('dept')->group(function () {
172 Route::get('/', [\App\Http\Controllers\Bside\User\DeptController::class, 'index'])->name('dept'); 186 Route::get('/', [\App\Http\Controllers\Bside\User\DeptController::class, 'index'])->name('dept');
@@ -242,20 +256,19 @@ Route::middleware(['bloginauth'])->group(function () { @@ -242,20 +256,19 @@ Route::middleware(['bloginauth'])->group(function () {
242 256
243 Route::post('/chunk/create', [\App\Http\Controllers\Aside\TemplateController::class, 'chunk_save'])->name('admin.template.chunk_create'); 257 Route::post('/chunk/create', [\App\Http\Controllers\Aside\TemplateController::class, 'chunk_save'])->name('admin.template.chunk_create');
244 Route::post('/chunk/update', [\App\Http\Controllers\Aside\TemplateController::class, 'chunk_save'])->name('admin.template.chunk_update'); 258 Route::post('/chunk/update', [\App\Http\Controllers\Aside\TemplateController::class, 'chunk_save'])->name('admin.template.chunk_update');
245 - Route::delete('/chunk/delete/{chunk_id}', [\App\Http\Controllers\Aside\TemplateController::class, 'chunk_delete'])->where('chunk_id','\d+')->name('admin.template.chunk_delete'); 259 + Route::delete('/chunk/delete/{chunk_id}', [\App\Http\Controllers\Aside\TemplateController::class, 'chunk_delete'])->where('chunk_id', '\d+')->name('admin.template.chunk_delete');
246 260
247 261
248 }); 262 });
249 263
250 264
251 -  
252 // 自定义页面,专题页 265 // 自定义页面,专题页
253 Route::prefix('custom')->group(function () { 266 Route::prefix('custom')->group(function () {
254 Route::get('/', [\App\Http\Controllers\Bside\CustomController::class, 'index'])->name('bside_custom'); 267 Route::get('/', [\App\Http\Controllers\Bside\CustomController::class, 'index'])->name('bside_custom');
255 Route::post('/create', [\App\Http\Controllers\Bside\CustomController::class, 'save'])->name('bside_custom_create'); 268 Route::post('/create', [\App\Http\Controllers\Bside\CustomController::class, 'save'])->name('bside_custom_create');
256 Route::post('/update', [\App\Http\Controllers\Bside\CustomController::class, 'save'])->name('bside_custom_update'); 269 Route::post('/update', [\App\Http\Controllers\Bside\CustomController::class, 'save'])->name('bside_custom_update');
257 Route::delete('/delete', [\App\Http\Controllers\Bside\CustomController::class, 'delete'])->name('bside_custom_delete'); 270 Route::delete('/delete', [\App\Http\Controllers\Bside\CustomController::class, 'delete'])->name('bside_custom_delete');
258 - Route::any('/html/{id}', [\App\Http\Controllers\Bside\CustomController::class, 'html'])->where('id','\d+')->name('bside_custom_delete'); 271 + Route::any('/html/{id}', [\App\Http\Controllers\Bside\CustomController::class, 'html'])->where('id', '\d+')->name('bside_custom_delete');
259 }); 272 });
260 273
261 // 导航栏编辑 274 // 导航栏编辑
@@ -281,7 +294,7 @@ Route::middleware(['bloginauth'])->group(function () { @@ -281,7 +294,7 @@ Route::middleware(['bloginauth'])->group(function () {
281 Route::prefix('home')->group(function () { 294 Route::prefix('home')->group(function () {
282 Route::any('/count', [\App\Http\Controllers\Bside\HomeCount\CountController::class, 'count'])->name('home_count'); 295 Route::any('/count', [\App\Http\Controllers\Bside\HomeCount\CountController::class, 'count'])->name('home_count');
283 Route::any('/yesterday', [\App\Http\Controllers\Bside\HomeCount\CountController::class, 'yesterday'])->name('home_yesterday'); 296 Route::any('/yesterday', [\App\Http\Controllers\Bside\HomeCount\CountController::class, 'yesterday'])->name('home_yesterday');
284 - }); 297 + });
285 298
286 //访问数据 299 //访问数据
287 Route::prefix('visit')->group(function () { 300 Route::prefix('visit')->group(function () {
@@ -297,6 +310,6 @@ Route::group([], function () { @@ -297,6 +310,6 @@ Route::group([], function () {
297 Route::any('/ceshi', [\App\Http\Controllers\Bside\ComController::class, 'ceshi'])->name('ceshi'); 310 Route::any('/ceshi', [\App\Http\Controllers\Bside\ComController::class, 'ceshi'])->name('ceshi');
298 Route::any('/sendLoginSms', [\App\Http\Controllers\Bside\ComController::class, 'sendLoginSms'])->name('sendLoginSms'); 311 Route::any('/sendLoginSms', [\App\Http\Controllers\Bside\ComController::class, 'sendLoginSms'])->name('sendLoginSms');
299 Route::get('/file/download', [\App\Http\Controllers\Bside\FileController::class, 'download'])->name('file_download'); 312 Route::get('/file/download', [\App\Http\Controllers\Bside\FileController::class, 'download'])->name('file_download');
300 - Route::any('/image/{hash}/{w?}/{h?}', [\App\Http\Controllers\File\ImageController::class,'index'])->name('image_show');  
301 - Route::any('/file_hash/{hash}', [\App\Http\Controllers\File\FileController::class,'index'])->name('file_show'); 313 + Route::any('/image/{hash}/{w?}/{h?}', [\App\Http\Controllers\File\ImageController::class, 'index'])->name('image_show');
  314 + Route::any('/file_hash/{hash}', [\App\Http\Controllers\File\FileController::class, 'index'])->name('file_show');
302 }); 315 });