MonthReportController.php
4.0 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* @remark :
* @name :MonthReportController.php
* @author :lyh
* @method :post
* @time :2024/2/2 15:01
*/
namespace App\Http\Controllers\Bside\BCom;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Models\HomeCount\Count;
use App\Models\HomeCount\MonthCount;
use App\Models\News\News;
use App\Models\Product\Category;
use App\Models\Product\Product;
use App\Models\Visit\Visit;
use Carbon\Carbon;
class MonthReportController extends BaseController
{
/**
* @remark :获取项目当前所有月份
* @name :getMonth
* @author :lyh
* @method :post
* @time :2024/2/2 15:14
* @param :is_upgrade;1->升级项目
*/
public function getMonth(){
$monthCountModel = new MonthCount();
$this->map['project_id'] = $this->user['project_id'];
if($this->user['is_upgrade'] != 1){
$this->map['month'] = ['>=',date('Y-m',strtotime($this->user['uptime']))];
}
$month = $monthCountModel->formatQuery($this->map)->pluck('month')->unique()->toArray();
$month = sort($month);
$this->response('success',Code::SUCCESS,$month);
}
/**
* @remark :月报告详情
* @name :monthReportInfo
* @author :lyh
* @method :post
* @time :2024/2/2 15:02
*/
public function monthReportInfo(){
$monthCountModel = new MonthCount();
$this->map['project_id'] = $this->user['project_id'];
$info = $monthCountModel->read($this->map);
if(!empty($info['source_country'])){
$info['source_country'] = json_decode($info['source_country']);
}
if(!empty($info['referrer_port'])){
$info['referrer_port'] = json_decode($info['referrer_port']);
}
if(!empty($info['referrer_url'])){
$info['referrer_url'] = json_decode($info['referrer_url']);
}
if(!empty($info['source'])){
$info['source'] = json_decode($info['source']);
}
if(!empty($info['country'])){
$info['country'] = json_decode($info['country']);
}
// 创建指定年月的 DateTime 对象
$date = $this->map['month'];
$start = new \DateTime("$date-01 00:00:00");
// 克隆 $start 对象并设置到下个月的第一天,减去1秒得到该月的最后一秒
$end = (clone $start)->modify('last day of this month')->setTime(23, 59, 59);
$startTime = $start->format('Y-m-d H:i:s');
$endTime = $end->format('Y-m-d H:i:s');
$param = [
'date' => ['between',[$startTime,$endTime]],
'project_id' => $this->user['project_id']
];
$info['pv_ip'] = (new Count())->list($param,'date',['id','pv_num','ip_num','date']);
$categoryModel = new Category();
$info['category_num'] = $categoryModel->formatQuery(['status'=>1])->count();
$productModel = new Product();
$info['products_num'] = $productModel->formatQuery(['status'=>1])->count();
$info['products_num_last_30'] = $productModel->formatQuery(
['status'=>1,'created_at'=>['between',[now()->subDays(30)->startOfDay()->toDateString(). ' 23:59:59',now()->startOfDay()->toDateString(). ' 23:59:59']]
])->count();
$newsModel = new News();
$info['news_num'] = $newsModel->formatQuery(['status'=>1])->count();
$info['news_num_last_7'] = $newsModel->formatQuery(
['status'=>1,'created_at'=>['between',[now()->subDays(7)->startOfDay()->toDateString() . ' 23:59:59',now()->startOfDay()->toDateString(). ' 23:59:59']]
])->count();
$info['service_duration'] = $this->user['service_duration'];//服务天数
$info['ip_total'] = (new Visit())->count();//ip总数
$info['remain_day'] = $this->user['remain_day'];//剩余服务天数
$info['speed'] = round((0.3 + mt_rand()/mt_getrandmax() * (1-0.3)),2);
$info['month_total'] = (int)$info['month_total'];
$this->response('success',Code::SUCCESS,$info);
}
}