NotificationTask.php 1.1 KB

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