UpdateHighQualityBooks.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Console\Commands\Recommend;
  3. use Illuminate\Console\Command;
  4. use Redis;
  5. use Log;
  6. use App\Modules\Book\Models\BookConfig;
  7. class UpdateHighQualityBooks extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'UpdateHighQualityBooks';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = '更新缓存优质书库';
  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. //统一在此脚本中维护缓存
  38. print_r("======更新缓存优质书库 【任务执行开始】=====" . date("y-m-d H:i:s" . "\n"));
  39. Log::info("======更新缓存优质书库 【任务执行开始】=====" . date("y-m-d H:i:s" . "\n"));
  40. $channels = ['男频','女频'];
  41. foreach ($channels as $channel_name)
  42. {
  43. if($channel_name == '女频') $key = 'female_high_reco_books';
  44. if($channel_name == '男频') $key = 'male_high_reco_books';
  45. //recommend_books
  46. $books = BookConfig::getChannelHighRecommendBooks($channel_name);
  47. $_high_reco_books = [];
  48. foreach ($books as $book)
  49. {
  50. $encode_book = json_encode($book);
  51. $_high_reco_books[$book->bid] = $encode_book;
  52. $reco_books[$book->bid] = $encode_book;
  53. }
  54. Redis::del($key);
  55. Redis::hmset($key,$_high_reco_books);
  56. }
  57. print_r("======更新缓存优质书库 【任务执行结束】=====" . date("y-m-d H:i:s" . "\n"));
  58. Log::info("======更新缓存优质书库 【任务执行结束】=====" . date("y-m-d H:i:s" . "\n"));
  59. }
  60. }