DailyScanForSupriorNewBook.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Console\Commands\SuperiorBooks;
  3. use App\Modules\Book\Services\SuperiorNewBookService;
  4. use DB;
  5. use Illuminate\Console\Command;
  6. class DailyScanForSupriorNewBook extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'addSuperiorBook';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = '扫描新上架优质书,加入榜单';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return mixed
  33. */
  34. public function handle()
  35. {
  36. //
  37. $month_ago = date('Y-m-d',strtotime(' -30 day'));
  38. $new_books = DB::table('book_configs as bc')
  39. ->leftjoin('books as b','b.id','=','bc.bid')
  40. ->leftjoin('book_categories as bcs','bcs.id','=','b.category_id')
  41. ->select('bc.bid','bcs.pid','b.category_id','bc.recommend_index')
  42. ->where([
  43. ['bc.created_at','>=',$month_ago.' 00:00:00'],
  44. ['bc.created_at','<=',date('Y-m-d')],
  45. ['bc.recommend_index','>=',90]
  46. ])
  47. ->orderBy('bc.created_at','asc')
  48. ->get();
  49. \Log::info('new_books:'.json_encode($new_books));
  50. foreach ($new_books as $new_book){
  51. try{
  52. SuperiorNewBookService::addSuperiorItem($new_book);
  53. }catch (\Exception $e){
  54. \Log::error('优质新书库加入失败!'.($e->getMessage()));
  55. }
  56. }
  57. }
  58. }