GeneratePdfData.php 1.8 KB
<?php

namespace App\Console\Commands\GeneratePDF;

use App\Models\File\PdfFile;
use App\Models\ProjectAssociation\ProjectAssociation;
use App\Services\CosService;
use Barryvdh\DomPDF\Facade\Pdf;
use Illuminate\Console\Command;

class GeneratePdfData extends Command
{
//    use CmdSignal;

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'generate_pdf_data';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '生成v6绑定的aicc用户的pdf备用数据';

    // 最大支持5个进程
    public $maxRunNumber = 50;

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {
        return $this->main();
    }

    /**
     * @return int
     */
    public function start(): int
    {
        return $this->main();
    }

    /**
     * @return int
     */
    protected function main()
    {
        $month = date('m');
        $list  = ProjectAssociation::query()->whereStatus(ProjectAssociation::STATUS_NORMAL)
                                   ->where('m_status', '!=', $month)->first();

        if (is_null($list)) {
            $this->error('没有任务,等待中');
            sleep(60);
            return 0;
        }
        $pdfFile = new PdfFile();
        $bool    = $pdfFile->saveData(['pid' => $list->id]);
        if (!$bool) {
            $this->error('生成v6绑定的aicc用户的pdf备用数据添加失败');
            return 0;
        }
        $list->m_status = $month;
        $list->save();
        $this->info('生成v6绑定的aicc用户的pdf备用数据添加成功');
        return 0;
    }
}