Info.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace User\Lib;
  3. use Dever;
  4. class Info
  5. {
  6. private $user = array();
  7. # 保存用户信息
  8. public function up($uid, $info_id, $username, $title, $info)
  9. {
  10. $update['username'] = $username;
  11. if (!$update['username']) {
  12. Dever::alert('昵称不能为空');
  13. }
  14. $update['title'] = $title;
  15. $update['info'] = $info;
  16. $update['info_id'] = $info_id;
  17. $user = Dever::db('user/info')->one(array('uid' => $uid));
  18. if (!$user) {
  19. $update['uid'] = $uid;
  20. Dever::db('user/info')->insert($update);
  21. } else {
  22. $update['where_id'] = $user['id'];
  23. Dever::db('user/info')->update($update);
  24. }
  25. return true;
  26. }
  27. # 保存头像
  28. public function upAvatar($uid, $info_id, $avatar)
  29. {
  30. $update['avatar'] = $avatar;
  31. if (!$update['avatar']) {
  32. Dever::alert('头像不能为空');
  33. }
  34. $update['info_id'] = $info_id;
  35. $user = Dever::db('user/info')->one(array('uid' => $this->uid));
  36. if (!$user) {
  37. $update['uid'] = $uid;
  38. Dever::db('user/info')->insert($update);
  39. } else {
  40. $update['where_id'] = $user['id'];
  41. Dever::db('user/info')->update($update);
  42. }
  43. return 'ok';
  44. }
  45. # 获取用户信息
  46. public function get($user, $id, $author = false)
  47. {
  48. if (is_array($user)) {
  49. $uid = $user['id'];
  50. } else {
  51. $uid = $user;
  52. }
  53. if ($uid <= 0) {
  54. return array();
  55. }
  56. $key = 'user_' . $uid . '_' . $id . '_' . $author;
  57. if (isset($this->user[$key])) {
  58. return $this->user[$key];
  59. }
  60. if (is_numeric($user)) {
  61. $user = Dever::load('passport/api')->info($user);
  62. }
  63. $result = array();
  64. if ($user) {
  65. if ($id) {
  66. # 获取合集扩展信息
  67. $result = Dever::db('user/info')->one(array('uid' => $user['id'], 'info_id' => $id));
  68. if (!$result) {
  69. $result['uid'] = $user['id'];
  70. $result['username'] = $user['username'];
  71. $result['avatar'] = $user['avatar'];
  72. $result['info'] = $user['info'];
  73. $result['sex'] = $user['sex'];
  74. $result['title'] = $user['title'];
  75. } else {
  76. !$result['username'] && $result['username'] = $user['username'];
  77. !$result['avatar'] && $result['avatar'] = $user['avatar'];
  78. !$result['info'] && $result['info'] = $user['info'];
  79. !$result['sex'] && $result['sex'] = $user['sex'];
  80. }
  81. } else {
  82. $result = $user;
  83. }
  84. }
  85. $result['mobile'] = $user['mobile'];
  86. $result['area_id'] = $user['area_id'];
  87. $result['address'] = $user['address'];
  88. $result['address_contact'] = $user['address_contact'] ? $user['address_contact'] : $user['username'];
  89. $result['address_mobile'] = $user['address_mobile'] ? $user['address_mobile'] : $user['mobile'];
  90. $result['author'] = '';
  91. if ($author) {
  92. $collection = Dever::load('collection/lib/info')->get($id);
  93. if ($collection && $collection['uid'] > 0 && $collection['uid'] == $user['id']) {
  94. $result['author'] = $collection['author_name'];
  95. if ($collection['author']) {
  96. $result['username'] = $collection['author'];
  97. }
  98. if ($collection['author_logo']) {
  99. $result['avatar'] = $collection['author_logo'];
  100. }
  101. }
  102. }
  103. if ($result['author']) {
  104. $result['username_text'] = '<span style="padding-right:4px;color: #00B3FF;">[' . $result['author'] . ']</span>' . $result['username'];
  105. }
  106. $result['username_text'] = $result['username'];
  107. $this->user[$key] = $result;
  108. return $result;
  109. }
  110. }