NewUserPushMsgDelay.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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()
  29. {
  30. $user = User::find($this->uid);
  31. if ($user) {
  32. $send_order_id = $user->send_order_id;
  33. $send_order = QappSendOrder::where('send_order_id', $send_order_id)->first();
  34. if ($send_order) {
  35. $account = $send_order->account;
  36. return QappNewUserPushTask::where('qapp_account', $account)
  37. ->where('is_enabled', 1)
  38. ->where('is_deleted', 0)
  39. ->get();
  40. }
  41. }
  42. }
  43. /**
  44. * Execute the job.
  45. *
  46. * @return void
  47. */
  48. public function handle()
  49. {
  50. $tasks = $this->findUserTasks();
  51. if ($tasks) {
  52. foreach ($tasks as $task) {
  53. $job = new NewUserPushMsg($this->uid, $task);
  54. dispatch($job)->onConnection('redis_queue')->onQueue('{new_user_push_msg}')->delay($task->time_delay);
  55. myLog('new_user_push_msg')->info("task_id:{$task->id}; uid: {$this->uid}");
  56. }
  57. }
  58. }
  59. }