Yesterday.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
<?php
namespace App\Console\Commands\YesterdayCount;
use App\Helper\Common;
use App\Helper\FormGlobalsoApi;
use App\Models\CustomerVisit\CustomerVisitItem;
use App\Models\Project\DeployBuild;
use App\Models\Project\DeployOptimize;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class Yesterday extends Command
{
const STATUS_ERROR = 400;
public $error = 0;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'yesterday_count';
/**
* The console command description.
*
* @var string
*/
protected $description = '统计昨日数据';
/**
* @name :(定时执行生成昨日数据统计)handle
* @author :lyh
* @method :post
* @time :2023/5/12 14:48
*/
public function handle()
{
$deployModel = new DeployOptimize();
$list = $deployModel->list();
$data = [];
$yesterday = Carbon::yesterday()->toDateString();
foreach ($list as $v){
$arr = [];
$arr['pv_num'] = DB::table('gl_customer_visit_item')->whereDate('updated_date', $yesterday)->where('domain',$v['domain'])->count();
$arr['ip_num'] = DB::table('gl_customer_visit')->whereDate('updated_date', $yesterday)->where('domain',$v['domain'])->count();
$inquiry_list = (new FormGlobalsoApi())->getInquiryList($v['domain']);
if($inquiry_list['status'] == self::STATUS_ERROR){
$arr['inquiry_num'] = 0;
}else{
$arr['inquiry_num'] = count($inquiry_list['data']['total']);
}
$arr['date'] = $yesterday;
$rank_info = DB::table('gl_rank_data')->where(['updated_date'=>$yesterday,'lang'=>''])->select(['compliance_day'])->first();
if(empty($rank_info)){
$arr['compliance_day'] = 0;
}else{
$arr['compliance_day'] = $rank_info->compliance_day;
}
$arr['service_day'] = $v['service_duration'] - Common::getDaysToTargetDate($v['created_at']);
$arr['project_id'] = $v['project_id'];
$arr['created_at'] = date('Y-m-d H:i:s');
$arr['updated_at'] = date('Y-m-d H:i:s');
$data[] = $arr;
}
//判断数据是否存在
DB::table('gl_count')->insert($data);
echo $this->error;
}
}