Yesterday.php 2.4 KB
<?php

namespace App\Console\Commands\YesterdayCount;

use App\Helper\Common;
use App\Helper\FormGlobalsoApi;
use App\Http\Logic\Aside\Project\ProjectLogic;
use App\Models\CustomerVisit\CustomerVisitItem;
use App\Models\Project\DeployBuild;
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 DeployBuild();
        $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['test_domain'])->count();
            $arr['ip_num'] = DB::table('gl_customer_visit')->whereDate('updated_date', $yesterday)->where('domain',$v['test_domain'])->count();
            $inquiry_list = (new FormGlobalsoApi())->getInquiryList($v['test_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;
    }
}