CompleteInfoListen.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace App\Listeners;
  3. use App\Models\User\FeedType4RemindModel;
  4. use App\Models\User\UserModel;
  5. use App\Notifications\CompletedInfo;
  6. use App\Notifications\CompleteInfoRemind;
  7. use Illuminate\Contracts\Queue\ShouldQueue;
  8. use PocketBE\MsyPush\Jobs\RegistEventJob;
  9. /**
  10. * Class CompleteInfoListen
  11. * @package App\Listeners
  12. */
  13. class CompleteInfoListen implements ShouldQueue
  14. {
  15. /**
  16. * Create the event listener.
  17. *
  18. * @return void
  19. */
  20. public function __construct()
  21. {
  22. }
  23. /**
  24. * Handle the event.
  25. *
  26. * @param object $event
  27. * @return void
  28. */
  29. public function handle($event)
  30. {
  31. }
  32. /**
  33. * @param \Illuminate\Events\Dispatcher $events
  34. */
  35. public function subscribe($events)
  36. {
  37. $events->listen(
  38. "App\Events\CompletedInfo",
  39. "App\Listeners\CompleteInfoListen@completedReply"
  40. );
  41. $events->listen(
  42. "App\Events\CompleteInfoRemind",
  43. "App\Listeners\CompleteInfoListen@remind"
  44. );
  45. }
  46. /**
  47. * 提醒补全信息
  48. * @param \App\Events\CompleteInfoRemind $events
  49. * @return bool
  50. */
  51. public function remind($events)
  52. {
  53. $to_uid = $events->is_remind_user->uid;
  54. $buildData = array(
  55. 'remind_nickname' => $events->remind_nickname,
  56. 'is_remind_nickname' => $events->is_remind_user->nickname
  57. );
  58. // 通知队列
  59. $user = UserModel::find($to_uid);
  60. $payload = [
  61. 'to_user' => $user->getAuth(),
  62. 'user' => $user->toArray(),
  63. 'reminder' => $buildData,
  64. ];
  65. dispatch(new RegistEventJob(10702, $payload))->onQueue("{push}");
  66. }
  67. /**
  68. * 补全信息完成提醒查看
  69. * @param \App\Events\CompletedInfo $events
  70. * @return bool
  71. */
  72. public function completedReply($events)
  73. {
  74. $models = FeedType4RemindModel::where([
  75. ['is_remind_uid', $events->is_remind_uid],
  76. ['is_update_feedback_at', 0],
  77. ['type', 1]
  78. ])->get();
  79. $is_remind_user = UserModel::find($events->is_remind_uid);
  80. foreach ($models as $model) {
  81. /** @var FeedType4RemindModel $model */
  82. $model->is_update_feedback_at = time();
  83. $model->save();
  84. $buildData = array(
  85. 'is_remind_nickname' => $is_remind_user->nickname,
  86. 'is_remind_user_partner_id' => $is_remind_user->partner_id
  87. );
  88. $user = UserModel::find($model->uid);
  89. $payload = [
  90. 'to_user' => $user->getAuth(),
  91. 'user' => $user->toArray(),
  92. 'reminder' => $buildData,
  93. ];
  94. dispatch(new RegistEventJob(10703, $payload))->onQueue("{push}");
  95. }
  96. }
  97. }