MonthCountLogic.php
2.9 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
<?php
namespace App\Http\Logic\Bside\HomeCount;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\HomeCount\Count;
use App\Models\HomeCount\MonthCount;
use App\Models\Project\ProjectKeyword;
class MonthCountLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new MonthCount();
$this->param = $this->requestAll;
}
/**
* @remark :获取数据
* @name :getCountLists
* @author :lyh
* @method :post
* @time :2023/7/3 9:39
*/
public function getCountLists($map,$order = 'created_at',$filed = ['*']){
$map['project_id'] = $this->user['project_id'];
$lists = $this->model->list($map,$order,$filed,'desc',10);
if(isset($this->project['is_record_china_visit']) && ($this->project['is_record_china_visit'] == 0)){
foreach ($lists as $k => $v){
if(empty($v['source_country'])){
continue;
}
$source_country = json_decode($v['source_country']);
foreach ($source_country as $k1 => $v1){
$v1 = (array)$v1;
if($v1['country'] == '中国'){
unset($source_country[$k1]);
}
}
$v['source_country'] = json_encode(array_values($source_country));
$v['total'] = $new['total'] ?? $v['total'];
$lists[$k] = $v;
}
}
return $this->success($lists);
}
/**
* @remark :根据时间获取pv,ip
* @name :getIpPvCount
* @author :lyh
* @method :post
* @time :2023/7/3 10:30
*/
public function getIpPvCount(){
$count = new Count();
$startTime = date("Y-m-d", strtotime("-9 months", mktime(0, 0, 0)));
$ensTime = date('Y-m-d',time());
$lists = $count->list(['date'=>['between',[$startTime,$ensTime]],'project_id'=>$this->user['project_id']],'id',['*'],'asc');
$groupedData = [];
foreach ($lists as $k=>$v){
$month = date('Y-m', strtotime($v['date']));
if(!isset($groupedData[$month])){
$groupedData[$month] = [];
}
if(empty($v['country'])){
$v['country'] = [];
}
$groupedData[$month][] = $v;
}
return $this->success($groupedData);
}
/**
* @remark :获取关键字列表
* @name :getKeywordLists
* @author :lyh
* @method :post
* @time :2023/7/4 10:19
*/
public function getKeywordLists(){
$projectKeywordModel = new ProjectKeyword();
$info = $projectKeywordModel->read(['project_id'=>$this->user['project_id']],['main_keyword','customer_keywords']);
if($info === false){
$info = [
'main_keyword'=>'',
'customer_keywords'=>''
];
}
return $this->success($info);
}
}