CountLogic.php
8.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<?php
namespace App\Http\Logic\Bside\HomeCount;
use App\Helper\FormGlobalsoApi;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Template\BCustomTemplate;
use App\Models\Visit\Visit;
use App\Models\Visit\VisitItem;
use App\Models\HomeCount\Count;
use App\Models\News\News;
use App\Models\Product\Product;
use App\Models\Project\Project;
use App\Models\RankData\RankData as RankDataModel;
use App\Models\Service\Service;
use Carbon\Carbon;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
class CountLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new Count();
}
/**
* @name :(昨日统计数据)yesterday_count
* @author :lyh
* @method :post
* @time :2023/5/23 17:30
*/
public function yesterday_count(){
$yesterday = Carbon::yesterday()->toDateString();
$param = [
'date' => $yesterday,
'project_id' => $this->user['project_id']
];
$info = $this->model->read($param,['pv_num','ip_num','inquiry_num','date','compliance_day','service_day','country']);
if($info === false){
$info = $this->model->read(['project_id' => $this->user['project_id']],
['pv_num','ip_num','inquiry_num','date','compliance_day','service_day','country']);
}
$inquiry_num = Cache::get('inquiry_num_'.$this->user['project_id']);
if(empty($inquiry_num)){
$domain = parse_url($this->user['domain'], PHP_URL_HOST); // 直接取域名部分
$inquiry_list = (new FormGlobalsoApi())->getInquiryAll($domain,$this->user['is_upgrade']);
if($inquiry_list !== false){
if(isset($inquiry_list['status']) && $inquiry_list['status'] != 400){
$info['inquiry_num'] = $inquiry_list['data']['count'];
Cache::add('inquiry_num_'.$this->user['project_id'],$inquiry_list['data']['count'],3600);
}
}
}
//获取项目的剩余时长
$projectModel = new Project();
$projectInfo = $projectModel->read(['id'=>$this->user['project_id']],['remain_day','finish_remain_day']);
$info['service_day'] = $projectInfo['remain_day'];
$info['compliance_day'] = $projectInfo['finish_remain_day'];
return $this->success($info);
}
/**
* @name :(方案信息)scheme_info
* @author :lyh
* @method :post
* @time :2023/5/24 11:48
*/
public function scheme_info(){
$data = [
'company'=>$this->project['company'] ?? '',
'scheme'=>!empty($this->project['deploy_build']['plan']) ? Project::planMap()[$this->project['deploy_build']['plan']] : '',
'service_duration'=>$this->project['deploy_build']['service_duration'] ?? 0,
];
return $this->success($data);
}
/**
* @name :(总访问量)total_count
* @author :lyh
* @method :post
* @time :2023/5/24 13:33
*/
public function total_count($inquiry_num = ''){
$pv = (new VisitItem())->count();
$ip = (new Visit())->count();
$data = [
'total_pv'=>$pv,
'total_ip'=>$ip,
'conversion_rate' => (isset($inquiry_num) && !empty($inquiry_num) && ($ip != 0)) ? round(($inquiry_num / $ip) * 100,2) : 0,
];
return $this->success($data);
}
/**
* @name :(前一天关键字排名统计)keyword_data
* @author :lyh
* @method :post
* @time :2023/5/24 14:03
*/
public function keyword_data_count(){
$version = $this->project['version'] ?? '';
if(!empty($version) && $version != '7.5'){
}
$yesterday = date('Y-m-d');
$rankDataModel = new RankDataModel();
$param = [
'updated_date' => $yesterday,
'project_id' => $this->user['project_id']
];
$data = $rankDataModel->read($param,['first_num','first_page_num','first_three_pages_num','first_five_pages_num','first_ten_pages_num']);
if($data === false){
$param = [
'project_id' => $this->user['project_id']
];
$data = $rankDataModel->read($param,['first_num','first_page_num','first_three_pages_num','first_five_pages_num','first_ten_pages_num']);
if($data === false){
$data = [];
}
}
return $this->success($data);
}
/**
* @name :(相关数据统计)with_data_count
* @author :lyh
* @method :post
* @time :2023/5/24 14:12
*/
public function with_data_count(){
$product_count = (new Product())->where(['project_id' => $this->user['project_id']])->count();
$news_count = (new News())->where(['project_id' => $this->user['project_id']])->count();
$page_count = (new BCustomTemplate())->where(['project_id' => $this->user['project_id'],'status'=>1])->count();
$data = [
'product_count' => $product_count,
'news_count' => $news_count,
'page_count' => $page_count,
];
return $this->success($data);
}
/**
* @name :(30天数据统计)visit_data_count
* @author :lyh
* @method :post
* @time :2023/5/24 14:18
*/
public function visit_data_count(){
$param = [
'date' => ['between',[now()->subDays(30)->startOfDay()->toDateString(),now()->startOfDay()->toDateString()]],
'project_id' => $this->user['project_id']
];
$data = $this->model->list($param,'date',['id','pv_num','ip_num','date']);
return $this->success($data);
}
/**
* @name :(访问来源统计)referrer_count
* @author :lyh
* @method :post
* @time :2023/5/24 15:32
*/
public function referrer_count(){
$customerVisitModel = new Visit();
$data = $customerVisitModel->select('referrer_url', DB::raw('COUNT(*) as count'))
->groupBy('referrer_url')->where(['domain'=>trim(str_replace('https://','',$this->user['domain']),'/')])
->orderByDesc('count')->limit(9)->get()->toArray();
$total = $customerVisitModel->count();
if(!empty($data)){
foreach ($data as $k=>$v){
if(empty($v['referrer_url'])){
unset($data[$k]);
continue;
}
$data[$k]['proportion'] = ($v['count']/$total) * 100;
}
$data = array_values($data);
}
return $this->success($data);
}
/**
* @name :(访问国家统计)access_country_count
* @author :lyh
* @method :post
* @time :2023/5/24 15:56
*/
public function access_country_count(){
$customerVisitModel = new Visit();
$data = $customerVisitModel->select('country',DB::raw('COUNT(*) as ip'),DB::raw('SUM(depth) as pv'))
->groupBy('country')
->orderBy('ip','desc')->limit(11)->get()->toArray();
$result =array();
if(!empty($data)){
foreach ($data as $k => $v){
if(isset($v['country']) && isset($this->project['is_record_china_visit']) && ($this->project['is_record_china_visit'] != 1) && ($v['country'] == '中国')){
continue;
}else{
$v['pv'] = (int)$v['pv'];
$result[] = $v;
}
}
}
return $this->success($result);
}
/**
* @name :(售后服务中心)enterprise_service
* @author :lyh
* @method :post
* @time :2023/5/25 10:22
*/
public function enterprise_service(){
$serviceModel = new Service();
$lists = $serviceModel->list(['type'=>1],'created_at');
foreach ($lists as $k => $v){
switch ($v['key']){
case 'images':
$arr = explode(',',$v['values']);
foreach ($arr as $k1 => $v1){
$v['images_link'][$k1] = getImageUrl($v1);
}
break;
case 'android':
$v['android_link'] = getImageUrl($v['values']);
break;
case 'official_account':
$v['official_account_link'] = getImageUrl($v['values']);
break;
case 'ios':
$v['ios_link'] = getImageUrl($v['values']);
break;
}
$lists[$k] = $v;
}
return $this->success($lists);
}
}