ChapterImageTask.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: tandunzhao
  5. * Date: 2017/11/20
  6. * Time: 下午5:26
  7. */
  8. namespace App\Console\Commands;
  9. use App\Libs\ChapterToImage;
  10. use App\Modules\Book\Models\Book;
  11. use App\Modules\Book\Services\ChapterImageService;
  12. use Log;
  13. use Illuminate\Console\Command;
  14. class ChapterImageTask extends Command
  15. {
  16. /**
  17. * 执行命令 php artisan chapter_to_image_task
  18. *
  19. * The name and signature of the console command.
  20. *
  21. * @var string
  22. */
  23. protected $signature = 'chapter_to_image_task';
  24. /**
  25. * The console command description.
  26. *
  27. * @var string
  28. */
  29. protected $description = '章节图片生成生成';
  30. /**
  31. * Execute the console command.
  32. *
  33. * @return mixed
  34. */
  35. public function handle()
  36. {
  37. print_r("======章节图片生成生成 【任务执行开始】=====".date("y-m-d H:i:s"."\n"));
  38. Log::info("======章节图片生成生成 【任务执行开始】=====".date("y-m-d H:i:s"."\n"));
  39. $books = Book::select('id')->orderBy('id')->get();
  40. foreach ($books as $book) {
  41. $cimages = ChapterImageService::getChapterImage($book['id']);
  42. if(empty($cimages) || sizeof($cimages) == 0) {
  43. ChapterToImage::createChapterImage($book['id']);
  44. print_r($book['id']." ".date("y-m-d H:i:s")."\n");
  45. Log::info($book['id']." ".date("y-m-d H:i:s"."\n"));
  46. sleep(1);
  47. } else {
  48. print_r("已经生成图片: ".$book['id']." ".date("y-m-d H:i:s")."\n");
  49. }
  50. }
  51. Log::info("======章节图片生成生成 【任务执行结束】=====".date("y-m-d H:i:s"."\n"));
  52. print_r("======章节图片生成生成 【任务执行结束】=====".date("y-m-d H:i:s"."\n"));
  53. }
  54. }