InquiryCount.php 2.4 KB
<?php

namespace App\Console\Commands\DayCount;

use App\Models\Inquiry\InquiryCount as InquiryCountModel;
use App\Models\Inquiry\InquiryInfo;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

/**
 * @remark :
 * @class  :InquiryCount.php
 * @author :lyh
 * @time   :2023/7/14 16:20
 */
class InquiryCount extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'inquiry_count';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '每天统计询盘数量';

    /**
     * @var :根据状态统计
     */
    public $status = [
        1=>'站群询盘',
        2=>'ai站群询盘',
        3=>'amp自建平台',
        4=>'fb询盘',
        5=>'fb广告',
        6=>'广告采集建站',
        7=>'黄金平台询盘',
        8=>'内部统计',
        9=>'GlobalImporter',
        10=>'whatsapp',
        11=>'Skype',
        12=>'建站客户',
        13=>'ChinaCn',
        14=>'EC21',
        15=>'邮件群发'
    ];

    /**
     * @remark :统计
     * @name   :handle
     * @author :lyh
     * @method :post
     * @time   :2023/7/14 16:21
     */
    public function handle(){
        $data = [];
        //获取昨天的时间
        $yesterday = Carbon::yesterday()->toDateString();
        $inquiryInfoModel = new InquiryInfo();
        try {
            foreach ($this->status as $k=>$v){
                $total = $inquiryInfoModel->formatQuery(['created_at'=>['between',[$yesterday.' 00:00:00',$yesterday.' 23:59:59']]])->count();
                $untreated = $inquiryInfoModel->formatQuery(['created_at'=>['between',[$yesterday.' 00:00:00',$yesterday.' 23:59:59']],'status'=>1])->count();
                $invalid = $inquiryInfoModel->formatQuery(['created_at'=>['between',[$yesterday.' 00:00:00',$yesterday.' 23:59:59']],'status'=>0])->count();
                $data[] = [
                    'type'=>$k,
                    'day'=>$yesterday,
                    'total'=>$total ?? 0,
                    'untreated'=>$untreated ?? 0,
                    'invalid'=>$invalid ?? 0
                ];
            }
            $inquiryCount = new InquiryCountModel();
            $inquiryCount->insert($data);
        }catch (\Exception $e){
            Log::error('inquiry_count : error');
        }
        return true;
    }
}