UserService.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Services;
  3. use App\Http\Traits\CommonTrait;
  4. use App\Http\Traits\AgentTrait;
  5. use App\Http\Traits\BoardTrait;
  6. use App\Models\User;
  7. use App\Models\LoginLog;
  8. use App\Models\DTO\SearchData;
  9. class UserService
  10. {
  11. use CommonTrait;
  12. use AgentTrait;
  13. use BoardTrait;
  14. public User $userModel;
  15. public LoginLog $loginLogModel;
  16. public function __construct()
  17. {
  18. $this->userModel = new User();
  19. $this->loginLogModel = new LoginLog();
  20. }
  21. /**
  22. * 로그인 기록 조회
  23. */
  24. public function loginLog(int $userID, SearchData $params): object
  25. {
  26. $loginLogs = $this->loginLogModel->logs($userID, $params);
  27. if ($loginLogs->rows > 0) {
  28. $num = listNum($loginLogs->total, $params->page, $params->perPage);
  29. foreach ($loginLogs->list as $i => $row) {
  30. $row->num = $num--;
  31. $row->os = $this->platform($row->user_agent);
  32. $row->browser = $this->browser($row->user_agent);
  33. $row->device = $this->device($row->user_agent);
  34. $row->result = ($row->success ? '성공' : '실패');
  35. $loginLogs->list[$i] = $row;
  36. }
  37. }
  38. return $loginLogs;
  39. }
  40. }