MonthReportController.php
2.4 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
<?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 Carbon\Carbon;
class MonthReportController extends BaseController
{
/**
* @remark :获取项目当前所有月份
* @name :getMonth
* @author :lyh
* @method :post
* @time :2024/2/2 15:14
*/
public function getMonth(){
$monthCountModel = new MonthCount();
$this->map['project_id'] = $this->user['project_id'];
$month = $monthCountModel->formatQuery($this->map)->pluck('month')->unique()->toArray();
$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);
foreach ($info as $k => $v){
if(!empty($v['source_country'])){
$v['source_country'] = json_decode($v['source_country']);
}
if(!empty($v['referrer_port'])){
$v['referrer_port'] = json_decode($v['referrer_port']);
}
if(!empty($v['referrer_url'])){
$v['referrer_url'] = json_decode($v['referrer_url']);
}
if(!empty($v['source'])){
$v['source'] = json_decode($v['source']);
}
if(!empty($v['country'])){
$v['country'] = json_decode($v['country']);
}
//获取上去的流量统计
// 获取上个月的开始时间
$startTime = Carbon::now()->subMonth()->startOfMonth()->toDateString();
// 获取上个月的结束时间
$endTime = Carbon::now()->subMonth()->endOfMonth()->toDateString();
$param = [
'date' => ['between',[$startTime,$endTime]],
'project_id' => $this->user['project_id']
];
$v['pv_ip'] = (new Count())->list($param,'date',['id','pv_num','ip_num','date']);
$info[$k] = $v;
}
$this->response('success',Code::SUCCESS,$info);
}
}