NotificationTask.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 Cache;
  9. use DB;
  10. use Hhxsv5\LaravelS\Swoole\Task\Task;
  11. class NotificationTask extends Task
  12. {
  13. private $contentId;
  14. /**
  15. * NotificationTask constructor.
  16. * @param int $contentId
  17. */
  18. public function __construct($contentId)
  19. {
  20. $this->contentId = intval($contentId);
  21. }
  22. public function handle()
  23. {
  24. $row = Base::DBC2A(DB::table('chat_msg')->where('id', $this->contentId)->first());
  25. if (empty($row)) {
  26. return;
  27. }
  28. if ($row['roger']) {
  29. return;
  30. }
  31. //
  32. $username = $row['receive'];
  33. $message = Base::string2array($row['message']);
  34. $lists = Base::DBC2A(DB::table('umeng')->where('username', $username)->get());
  35. foreach ($lists AS $item) {
  36. Umeng::notification($item['platform'], $item['token'], Users::nickname($username), Chat::messageDesc($message), [
  37. 'notifyType' => 'userMsg',
  38. 'contentId' => $this->contentId,
  39. 'username' => $username,
  40. ]);
  41. Cache::forever("ws::immediatelyNotify-" . $username, "yes");
  42. }
  43. }
  44. }