NotificationTask.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Tasks;
  3. @error_reporting(E_ALL & ~E_NOTICE);
  4. use App\Module\Base;
  5. use App\Module\Chat;
  6. use App\Module\Umeng;
  7. use App\Module\Users;
  8. use DB;
  9. use Hhxsv5\LaravelS\Swoole\Task\Task;
  10. class NotificationTask extends Task
  11. {
  12. private $contentId;
  13. /**
  14. * NotificationTask constructor.
  15. * @param int $contentId
  16. */
  17. public function __construct($contentId)
  18. {
  19. $this->contentId = intval($contentId);
  20. }
  21. public function handle()
  22. {
  23. $row = Base::DBC2A(DB::table('chat_msg')->where('id', $this->contentId)->first());
  24. if (empty($row)) {
  25. return;
  26. }
  27. if ($row['roger']) {
  28. return;
  29. }
  30. //
  31. $username = $row['receive'];
  32. $message = Base::string2array($row['message']);
  33. $lists = Base::DBC2A(DB::table('umeng')->where('username', $username)->get());
  34. foreach ($lists AS $item) {
  35. Umeng::notification($item['platform'], $item['token'], Users::nickname($username), Chat::messageDesc($message), [
  36. 'contentId' => $this->contentId,
  37. 'username' => $username,
  38. ]);
  39. }
  40. }
  41. }