TrafficTrends.php
2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
namespace App\Models\Bside\Statistics;
use App\Models\Base;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
/**
* App\Models\Bside\Statistics\TrafficTrends
*
* @property int $id
* @property string|null $day 统计当天日期
* @property int|null $pvnum 当天的访问次数PV
* @property int|null $ipnum 当天的独立访问IP数量
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @method static Builder|TrafficTrends newModelQuery()
* @method static Builder|TrafficTrends newQuery()
* @method static Builder|TrafficTrends query()
* @method static Builder|TrafficTrends whereCreatedAt($value)
* @method static Builder|TrafficTrends whereDay($value)
* @method static Builder|TrafficTrends whereId($value)
* @method static Builder|TrafficTrends whereIpnum($value)
* @method static Builder|TrafficTrends wherePvnum($value)
* @method static Builder|TrafficTrends whereUpdatedAt($value)
* @mixin \Eloquent
*/
class TrafficTrends extends Base
{
protected $table = 'gl_traffic_trends';
/**
* 根据时间获取数据
* @param string|null $date 日期,格式:Y-m-d
* @return TrafficTrends[]|Builder[]|Collection
*/
public function getDaysLists(string $date = null)
{
$query = $this->query();
if ($date != null && is_array($date)) {
$query->whereIn('day', $date);
} else {
$query->where('day', $date);
}
return $query->get();
}
/**
* @param string|null $date 日期,格式:Y-m-d
* @return TrafficTrends|Builder|Model|object|null
*/
public function getDay(string $date = null)
{
return $this->query()->where('day', $date ?? date('Y-m-d'))->first();
}
/**
* 获取当月的IP|PV数量
* @param string|null $date 日期,格式:Y-m
* @return Builder[]|Collection
*/
public function getMonthsLists(string $date = null)
{
if (!is_null($date)) {
$dd = explode('-', $date);
$year = $dd[0];
$month = $dd[1];
} else {
$year = date('Y');
$month = date('m');
}
return $this->query()
->selectRaw('day as date, pvnum as pv_count, ipnum as ip_count')
->whereYear('day', '=', $year)
->whereMonth('day', '=', $month)
->orderBy('day', 'asc')
->get();
}
}