UpdateHighQualityBooks.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace App\Console\Commands\SuperiorBooks;
  3. use App\Modules\Book\Models\BookConfig;
  4. use App\Modules\Book\Services\SuperiorNewBookService;
  5. use DB;
  6. use Illuminate\Console\Command;
  7. class UpdateHighQualityBooks extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'update_high_quality_books';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = '更新优质书库到Redis';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. /**
  31. * Execute the console command.
  32. *
  33. * @return mixed
  34. */
  35. public function handle()
  36. {
  37. $high_quality_books = BookConfig::join('books','books.id','=','book_configs.bid')
  38. ->join('book_categories','book_categories.id','=','books.category_id')
  39. ->where('is_high_quality',1)
  40. ->whereIn('is_on_shelf',[1,2])
  41. ->select('book_configs.bid','book_categories.pid')
  42. ->get();
  43. //->pluck('bid');
  44. $male = $female = [];
  45. foreach ($high_quality_books as $high_quality_book) {
  46. if ($high_quality_book->pid == 1) {
  47. $male[] = $high_quality_book->bid;
  48. }
  49. if ($high_quality_book->pid == 2) {
  50. $female[] = $high_quality_book->bid;
  51. }
  52. }
  53. \Redis::del('male_high_reco_bids','female_high_reco_bids');
  54. if(!empty($male)){
  55. \Redis::sadd('male_high_reco_bids',$male);
  56. }
  57. if(!empty($female)){
  58. \Redis::sadd('female_high_reco_bids',$female);
  59. }
  60. }
  61. }