ChromeExtendTask.php 1.3 KB

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