CountAll.php
5.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
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
<?php
/**
* @remark :
* @name :CountProject.php
* @author :lyh
* @method :post
* @time :2024/1/8 9:03
*/
namespace App\Console\Commands\DayCount;
use App\Helper\FormGlobalsoApi;
use App\Models\Inquiry\InquiryFormData;
use App\Models\Project\Project;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use App\Models\HomeCount\Count;
class CountAll extends Command
{
const STATUS_ERROR = 400;
public $error = 0;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'count_all';
/**
* The console command description.
*
* @var string
*/
protected $description = '所有项目统计';
public function handle(){
$projectModel = new Project();
$list = $projectModel->list(['delete_status'=>0,'type'=>['in',[1,2,3,4,6]]]);
foreach ($list as $v) {
echo date('Y-m-d H:i:s') . '项目id:'.$v['id'] . PHP_EOL;
ProjectServer::useProject($v['id']);
$this->count($v['id']);
DB::disconnect('custom_mysql');
}
return true;
}
/**
* @remark :日统计记录
* @name :count
* @author :lyh
* @method :post
* @time :2024/1/8 9:05
*/
public function count($project_id){
$list = DB::connection('custom_mysql')->table('gl_customer_visit')->select('updated_date')
->groupBy('updated_date')->get()->toArray();
$project = new Project();
$projectInfo = $project->read(['id'=>$project_id]);
if(!empty($list)){
$arr = [];
foreach ($list as $k=>$v){
$v = (array)$v;
if($v['updated_date'] == date('Y-m-d')){
continue;
}
echo date('Y-m-d H:i:s') . '时间:'.$v['updated_date'] . PHP_EOL;
$count = new Count();
$arr['project_id'] = $project_id;
$arr['date'] = $v['updated_date'];
$arr['pv_num'] = $this->pv_num($v['updated_date']);
$arr['ip_num'] = $this->ip_num($v['updated_date']);
$arr['inquiry_num'] = $this->inquiry_num($v['updated_date']);
//服务达标天数
$arr['compliance_day'] = $projectInfo['finish_remain_day'];
//剩余服务时常
$arr['service_day'] = $projectInfo['remain_day'];
$arr['country'] = json_encode([]);
//查询当天数据是否存在 存在则更新
$info = $count->read(['date'=>$v['updated_date'],'project_id'=>$project_id]);
if($info === false){
$arr['created_at'] = $v['updated_date'].' 01:00:00';
$arr['updated_at'] = $v['updated_date'].' 01:00:00';
$count->insert($arr);
}else{
$count->edit($arr,['id'=>$info['id']]);
}
}
}
echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
}
/**
* @param $arr
* @param $domain
* @name :(询盘统计)inquiry
* @author :lyh
* @method :post
* @time :2023/6/14 15:44
*/
public function inquiry($arr,$domain,$project_id,$is_upgrade = 0){
$inquiry_list = (new FormGlobalsoApi())->getInquiryAll($domain,$is_upgrade);
if($inquiry_list == false){
return $arr;
}
if($inquiry_list['status'] == self::STATUS_ERROR){
$arr['inquiry_num'] = 0;
$countryArr = [];
}else{
$arr['inquiry_num'] = $inquiry_list['data']['count'];
//询盘国家统计
$countryArr = $inquiry_list['data']['country'];
}
//加上其他询盘
ProjectServer::useProject($project_id);
$arr['inquiry_num'] += InquiryFormData::getCount();
$countryData = InquiryFormData::getCountryCount();
foreach ($countryData as $v1){
if(isset($countryArr[$v1['country']])){
$countryArr[$v1['country']] += $v1['count'];
}else{
$countryArr[$v1['country']] = $v1['count'];
}
}
arsort($countryArr);
$top20 = array_slice($countryArr, 0, 20, true);
$arr['country'] = json_encode($top20);
return $arr;
}
/**
* @remark :询盘数量
* @name :inquiry_num
* @author :lyh
* @method :post
* @time :2024/1/8 9:24
*/
public function inquiry_num($day){
$count = DB::connection('custom_mysql')->table('gl_customer_visit')->whereDate('updated_date', $day)->where('is_inquiry',1)->count();
return $count;
}
/**
* @name :(统计pv)pv_num
* @author :lyh
* @method :post
* @time :2023/6/14 15:40
*/
public function pv_num($day){
//$pv = DB::connection('custom_mysql')->table('gl_customer_visit_item')->whereDate('updated_date', $day)->count();
$pv = DB::connection('custom_mysql')->table('gl_customer_visit')->whereDate('updated_date', $day)->sum('depth');
return $pv;
}
/**
* @name :(统计ip)ip_num
* @author :lyh
* @method :post
* @time :2023/6/14 15:40
*/
public function ip_num($day){
$ip = DB::connection('custom_mysql')->table('gl_customer_visit')->whereDate('updated_date', $day)->count();
return $ip;
}
}