ChromeExtendTask.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Tasks;
  3. use App\Module\Base;
  4. use App\Module\Chat;
  5. use DB;
  6. use Hhxsv5\LaravelS\Swoole\Task\Task;
  7. class ChromeExtendTask extends Task
  8. {
  9. private $username;
  10. /**
  11. * ChromeExtendTask constructor.
  12. * @param $username
  13. */
  14. public function __construct($username)
  15. {
  16. $this->username = $username;
  17. }
  18. public function handle()
  19. {
  20. $lists = Base::DBC2A(DB::table('ws')->select(['fd', 'username', 'channel'])->where([
  21. 'username' => $this->username,
  22. 'channel' => 'chromeExtend',
  23. ])->where([
  24. ['update', '>', time() - 600],
  25. ])->get());
  26. if (count($lists) > 0) {
  27. $unread = intval(DB::table('chat_dialog')->where('user1', $this->username)->sum('unread1'));
  28. $unread+= intval(DB::table('chat_dialog')->where('user2', $this->username)->sum('unread2'));
  29. //
  30. $swoole = app('swoole');
  31. foreach ($lists AS $item) {
  32. $swoole->push($item['fd'], Chat::formatMsgSend([
  33. 'messageType' => 'unread',
  34. 'body' => [
  35. 'unread' => $unread
  36. ],
  37. ]));
  38. }
  39. }
  40. }
  41. }