NewUserPushMsgDelay.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App\Jobs\Push;
  3. use App\Modules\Push\Models\QappNewUserPushTask;
  4. use App\Modules\SendOrder\Models\QappSendOrder;
  5. use App\Modules\User\Models\User;
  6. use Illuminate\Bus\Queueable;
  7. use Illuminate\Queue\SerializesModels;
  8. use Illuminate\Queue\InteractsWithQueue;
  9. use Illuminate\Contracts\Queue\ShouldQueue;
  10. use Illuminate\Database\Eloquent\Collection;
  11. use Illuminate\Foundation\Bus\Dispatchable;
  12. /**
  13. * 新用户延时push消息推送队列
  14. */
  15. class NewUserPushMsgDelay implements ShouldQueue
  16. {
  17. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  18. private $uid;
  19. /**
  20. * Create a new job instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct(int $uid)
  25. {
  26. $this->uid = $uid;
  27. }
  28. private function findUserTasks(): Collection
  29. {
  30. $user = User::find($this->uid);
  31. $send_order_id = $user->send_order_id;
  32. $send_order = QappSendOrder::where('send_order_id', $send_order_id)->first();
  33. $account = $send_order->account;
  34. return QappNewUserPushTask::where('qapp_account', $account)->where('status', 1)->where('is_enabled', 1)->get();
  35. }
  36. /**
  37. * Execute the job.
  38. *
  39. * @return void
  40. */
  41. public function handle()
  42. {
  43. $tasks = $this->findUserTasks();
  44. foreach ($tasks as $task) {
  45. $job = new NewUserPushMsg($this->uid, $task);
  46. dispatch($job)->onConnection('rabbitmq')->onQueue('new_user_push_msg')->delay($task->time_delay);
  47. }
  48. }
  49. }