UserInfoResponse.php 1003 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * 单个用户信息返回数据封装.
  4. *
  5. * @author nj <nj@gmail.com>
  6. * @date 2020-01-16 17:57:50
  7. */
  8. declare(strict_types=1);
  9. namespace Modules\Api\Responses;
  10. use App\Contracts\Responsable;
  11. class UserInfoResponse implements Responsable
  12. {
  13. /**
  14. * 录入的数据.
  15. *
  16. * @var mixed
  17. */
  18. private $data = null;
  19. /**
  20. * 附加条件参数.
  21. *
  22. * @var array
  23. */
  24. private $params = [];
  25. public function __construct($data = null, $params = [])
  26. {
  27. $this->data = $data;
  28. $this->params = $params;
  29. }
  30. public function toResponse(
  31. $request = null
  32. ) {
  33. $res = [];
  34. if (!empty($this->data->code)) {
  35. $res = [
  36. 'user_id' => $this->data->code,
  37. 'nick' => $this->data->nick,
  38. 'avatar' => $this->data->avatar,
  39. ];
  40. return json_success($res);
  41. } else {
  42. return json_fail('信息有误');
  43. }
  44. }
  45. }