NotificationTask.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace App\Tasks;
  3. @error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
  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. $receive = $row['receive'];
  33. $username = $row['username'];
  34. $message = Base::string2array($row['message']);
  35. $lists = Base::DBC2A(DB::table('umeng')->where('username', $receive)->get());
  36. foreach ($lists AS $item) {
  37. Umeng::notification($item['platform'], $item['token'], Users::nickname($username), Chat::messageDesc($message), [
  38. 'notifyType' => 'userMsg',
  39. 'contentId' => $this->contentId,
  40. 'username' => $username,
  41. ]);
  42. Cache::forever("ws::immediatelyNotify-" . $receive, "yes");
  43. }
  44. }
  45. }