作者 lyh

gx

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 -}  
@@ -19,6 +19,19 @@ use Illuminate\Support\Facades\DB; @@ -19,6 +19,19 @@ use Illuminate\Support\Facades\DB;
19 class ImportManager extends Command 19 class ImportManager extends Command
20 { 20 {
21 /** 21 /**
  22 + * The name and signature of the console command.
  23 + *
  24 + * @var string
  25 + */
  26 + protected $signature = 'import_manager';
  27 +
  28 + /**
  29 + * The console command description.
  30 + *
  31 + * @var string
  32 + */
  33 + protected $description = '导入数据';
  34 + /**
22 * @remark :导入5.0管理员数据 35 * @remark :导入5.0管理员数据
23 * @name :handle 36 * @name :handle
24 * @author :lyh 37 * @author :lyh
@@ -34,21 +34,6 @@ class Kernel extends ConsoleKernel @@ -34,21 +34,6 @@ class Kernel extends ConsoleKernel
34 $schedule->command('inquiry_count')->dailyAt('01:00')->withoutOverlapping(1); // 询盘统计数据,每天凌晨执行一次 34 $schedule->command('inquiry_count')->dailyAt('01:00')->withoutOverlapping(1); // 询盘统计数据,每天凌晨执行一次
35 // // 更新域名|证书结束时间,每天凌晨1点执行一次 35 // // 更新域名|证书结束时间,每天凌晨1点执行一次
36 // $schedule->command('domain_time')->dailyAt('01:00')->withoutOverlapping(1); 36 // $schedule->command('domain_time')->dailyAt('01:00')->withoutOverlapping(1);
37 -// // B站 - 网站数据统计  
38 -// // 获取当前月份最后一天  
39 -// $lastDay = date('Y-m-t');  
40 -// // 统计当月访问来源数据,每月最后一天23:59点执行一次  
41 -// $schedule->command('statistics_source')->monthlyOn($lastDay, '23:59')->withoutOverlapping(1);  
42 -// // 统计当月地域分布数据,每月最后一天23:59点执行一次  
43 -// $schedule->command('statistics_distribution')->monthlyOn($lastDay, '23:59')->withoutOverlapping(1);  
44 -// // 统计当月受访页面数据,每月最后一天23:59点执行一次  
45 -// $schedule->command('statistics_page')->monthlyOn($lastDay, '23:59')->withoutOverlapping(1);  
46 -// // 统计当月访问终端数据,每月最后一天23:59点执行一次  
47 -// $schedule->command('statistics_terminal')->monthlyOn($lastDay, '23:59')->withoutOverlapping(1);  
48 -// // 统计当月流量趋势数据,每月最后一天23:59点执行一次  
49 -// $schedule->command('statistics_trend')->monthlyOn($lastDay, '23:59')->withoutOverlapping(1);  
50 -// // 统计当天流量趋势数据,每天23:59点执行一次  
51 -// $schedule->command('statistics_day_trend')->dailyAt('23:59')->withoutOverlapping(1);  
52 } 37 }
53 38
54 /** 39 /**