RefreshLoginTimeJob.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://doc.hyperf.io
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
  10. */
  11. namespace App\Jobs;
  12. use App\Model\UserModel;
  13. use Carbon\Carbon;
  14. use Hyperf\AsyncQueue\Job;
  15. class RefreshLoginTimeJob extends Job
  16. {
  17. public $params;
  18. public function __construct($params)
  19. {
  20. // 这里最好是普通数据,不要使用携带 IO 的对象,比如 PDO 对象
  21. $this->params = $params;
  22. }
  23. public function handle()
  24. {
  25. try {
  26. UserModel::query()->where('code', $this->params['user_id'])
  27. ->update(
  28. [
  29. 'version' => $this->params['version'],
  30. 'last_login_at' => Carbon::now()->toDateTimeString()
  31. ]
  32. );
  33. } catch (\Exception $exception) {
  34. logger('RefreshLoginTimeJob', [$exception->getMessage()]);
  35. }
  36. // 异步处理该用户的系统消息分配给用户消息.
  37. dispatch_job(new InitSysMessageJob(['receive_uid' => $this->params['user_id']]));
  38. }
  39. }