<?php /** * Created by PhpStorm. * User: tandunzhao * Date: 2017/11/20 * Time: 下午5:26 */ namespace App\Console\Commands; use App\Libs\ChapterToImage; use App\Modules\Book\Models\Book; use App\Modules\Book\Services\ChapterImageService; use Log; use Illuminate\Console\Command; class ChapterImageTask extends Command { /** * 执行命令 php artisan chapter_to_image_task * * The name and signature of the console command. * * @var string */ protected $signature = 'chapter_to_image_task'; /** * The console command description. * * @var string */ protected $description = '章节图片生成生成'; /** * Execute the console command. * * @return mixed */ public function handle() { print_r("======章节图片生成生成 【任务执行开始】=====".date("y-m-d H:i:s"."\n")); Log::info("======章节图片生成生成 【任务执行开始】=====".date("y-m-d H:i:s"."\n")); $books = Book::select('id')->orderBy('id')->get(); foreach ($books as $book) { $cimages = ChapterImageService::getChapterImage($book['id']); if(empty($cimages) || sizeof($cimages) == 0) { ChapterToImage::createChapterImage($book['id']); print_r($book['id']." ".date("y-m-d H:i:s")."\n"); Log::info($book['id']." ".date("y-m-d H:i:s"."\n")); sleep(1); } else { print_r("已经生成图片: ".$book['id']." ".date("y-m-d H:i:s")."\n"); } } Log::info("======章节图片生成生成 【任务执行结束】=====".date("y-m-d H:i:s"."\n")); print_r("======章节图片生成生成 【任务执行结束】=====".date("y-m-d H:i:s"."\n")); } }