You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

71 lines
2.1 KiB

  1. <?php
  2. /**
  3. * 用户信息类
  4. */
  5. class Api_User extends PhalApi_Api {
  6. public function getRules() {
  7. return array(
  8. 'getBaseInfo' => array(
  9. 'userId' => array('name' => 'user_id', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
  10. ),
  11. 'getMultiBaseInfo' => array(
  12. 'userIds' => array('name' => 'user_ids', 'type' => 'array', 'format' => 'explode', 'require' => true, 'desc' => '用户ID,多个以逗号分割'),
  13. ),
  14. );
  15. }
  16. /**
  17. * 获取用户基本信息
  18. * @desc 用于获取单个用户基本信息
  19. * @return int code 操作码,0表示成功, 1表示用户不存在
  20. * @return object info 用户信息对象
  21. * @return int info.id 用户ID
  22. * @return string info.name 用户名字
  23. * @return string info.note 用户来源
  24. * @return string msg 提示信息
  25. */
  26. public function getBaseInfo() {
  27. $rs = array('code' => 0, 'msg' => '', 'info' => array()); //定义返回值
  28. $domain = new Domain_User();
  29. $info = $domain->getBaseInfo($this->userId);
  30. if (empty($info)) {
  31. DI()->logger->debug('user not found', $this->userId);
  32. $rs['code'] = 1;
  33. $rs['msg'] = T('user not exists');
  34. return $rs;
  35. }
  36. $rs['info'] = $info;
  37. return $rs;
  38. }
  39. /**
  40. * 批量获取用户基本信息
  41. * @desc 用于获取多个用户基本信息
  42. * @return int code 操作码,0表示成功
  43. * @return array list 用户列表
  44. * @return int list[].id 用户ID
  45. * @return string list[].name 用户名字
  46. * @return string list[].note 用户来源
  47. * @return string msg 提示信息
  48. * @exception 400 参数传递错误
  49. * @exception 500 服务器内部错误
  50. */
  51. public function getMultiBaseInfo() {
  52. $rs = array('code' => 0, 'msg' => '', 'list' => array());
  53. $domain = new Domain_User();
  54. foreach ($this->userIds as $userId) {
  55. $rs['list'][] = $domain->getBaseInfo($userId);
  56. }
  57. return $rs;
  58. }
  59. }