FeedCleanPartnerJob.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace App\Jobs;
  3. use App\Models\PraiseModel;
  4. use Illuminate\Bus\Queueable;
  5. use Illuminate\Queue\SerializesModels;
  6. use Illuminate\Queue\InteractsWithQueue;
  7. use Illuminate\Contracts\Queue\ShouldQueue;
  8. use Illuminate\Foundation\Bus\Dispatchable;
  9. use Illuminate\Support\Facades\Redis;
  10. class FeedCleanPartnerJob implements ShouldQueue
  11. {
  12. use Dispatchable;
  13. use InteractsWithQueue;
  14. use Queueable;
  15. use SerializesModels;
  16. private $uid;
  17. private $key;
  18. /**
  19. * Create a new job instance.
  20. *
  21. * @param int $uid
  22. */
  23. public function __construct(int $uid)
  24. {
  25. $this->uid = $uid;
  26. $this->key = "charge_feed_{$this->uid}";
  27. }
  28. /**
  29. * Execute the job.
  30. *
  31. * @return void
  32. */
  33. public function handle()
  34. {
  35. $max = time() - 7 * 86400;
  36. $ids = Redis::Zrevrangebyscore($this->key, $max, "-inf");
  37. $thumbIds = PraiseModel::where([['uid', $this->uid], ['type', 1]])->whereIn(
  38. 'partner_id',
  39. $ids
  40. )->get(['partner_id'])->pluck('partner_id')->toArray();
  41. $cleanIds = array_merge(array_diff($ids, $thumbIds), [1]);
  42. Redis::zrem($this->key, ...$cleanIds);
  43. $mockids = Redis::zrevrangebyscore("fpdx:mock:feed:{$this->uid}", $max, "-inf");
  44. $cleanIds = array_merge(array_diff($mockids, $thumbIds), [1]);
  45. Redis::zrem("fpdx:mock:feed:{$this->uid}", ...$cleanIds);
  46. }
  47. }