V20190816.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Console\Commands\Upgrade;
  3. use App\Models\PartnerModel;
  4. use Illuminate\Console\Command;
  5. use Illuminate\Database\Eloquent\Collection;
  6. use Illuminate\Support\Facades\Redis;
  7. class V20190816 extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'upgrade:v20190816';
  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. /** @var Collection $partners */
  38. $partners = PartnerModel::where(array(
  39. ['is_sell', 1],
  40. ['score', '>=', 0]
  41. ))->get(['uid', 'sex', 'feed_push_type', 'is_push_feed']);
  42. foreach ($partners as $partner) {
  43. /** @var PartnerModel $partner */
  44. if (!in_array($partner->sex, [1, 2])) {
  45. continue;
  46. }
  47. if ($partner->feed_push_type == 3 && 1 == $partner->is_push_feed) {
  48. $key = "feed:80:sex:{$partner->sex}";
  49. } else {
  50. $key = "feed:20:sex:{$partner->sex}";
  51. }
  52. Redis::sadd($key, [$partner->uid]);
  53. }
  54. Redis::expire("feed:80:sex:1", 86400 * 7);
  55. Redis::expire("feed:80:sex:2", 86400 * 7);
  56. Redis::expire("feed:20:sex:1", 86400 * 7);
  57. Redis::expire("feed:20:sex:2", 86400 * 7);
  58. }
  59. }