Info.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. namespace User\Lib;
  3. use Dever;
  4. class Info
  5. {
  6. public function manage_search_api()
  7. {
  8. $table = 'user/info';
  9. $keyword = Dever::input('keyword');
  10. $yes = Dever::input('yes');
  11. $where = array();
  12. $cate = Dever::input('cate');
  13. if ($cate) {
  14. $where['cate_id'] = $cate;
  15. }
  16. if ($yes) {
  17. $yes = Dever::db($table)->search(array('ids' => $yes));
  18. }
  19. if (!$keyword) {
  20. $where['limit'] = '0,10';
  21. $data = Dever::db($table)->search($where);
  22. } else {
  23. $where['search'] = $keyword;
  24. $data = Dever::db($table)->search($where);
  25. }
  26. $result = array();
  27. if ($yes) {
  28. foreach ($yes as $k => $v) {
  29. if (isset($data[$k])) {
  30. unset($data[$k]);
  31. }
  32. $yes[$k]['selected'] = true;
  33. }
  34. $data = $yes + $data;
  35. $data = array_merge($data, array());
  36. } else {
  37. $data = array_merge($data, array());
  38. }
  39. if (!$data) {
  40. Dever::alert('暂无数据');
  41. }
  42. return $data;
  43. }
  44. public function get($uid)
  45. {
  46. $info = array();
  47. if ($uid < 100000000) {
  48. $info = Dever::db('manage/admin')->find($uid);
  49. if ($info) {
  50. $info['name'] = $info['username'];
  51. $info['area_string'] = '';
  52. $info['avatar'] = '';
  53. $info['aname'] = $info['name'] . ($info['mobile'] ? '('.$info['mobile'].')' : '');
  54. }
  55. } else {
  56. $info = Dever::db('user/info')->find($uid);
  57. if ($info) {
  58. if (isset($info['area']) && $info['area']) {
  59. $info['area_string'] = Dever::load('area/api')->string($info['area']);
  60. }
  61. if (!$info['avatar'] && $info['avatar_id'] > 0) {
  62. $avatar = Dever::db('user/avatar')->one($info['avatar_id']);
  63. if ($avatar) {
  64. $info['avatar'] = $avatar['avatar'];
  65. }
  66. }
  67. $info['aname'] = $info['name'] . '('.$info['mobile'].')';
  68. }
  69. }
  70. return $info;
  71. }
  72. /**
  73. * 设置项目
  74. *
  75. * @return mixed
  76. */
  77. public function setProject($uid, $project)
  78. {
  79. $where['uid'] = $uid;
  80. $where['project_id'] = $project;
  81. $one = Dever::db('user/user_project')->find($where);
  82. if (!$one) {
  83. Dever::db('user/user_project')->insert($where);
  84. }
  85. }
  86. /**
  87. * 获取加密信息
  88. *
  89. * @return mixed
  90. */
  91. public function getSign($uid, $data = array())
  92. {
  93. $data['signature'] = Dever::login($uid);
  94. return $data;
  95. }
  96. /**
  97. * 检测用户有效性
  98. *
  99. * @return mixed
  100. */
  101. public function check($state = true, $name = 'signature')
  102. {
  103. $signature = Dever::input($name);
  104. $user = Dever::checkLogin($signature, $state);
  105. if ($state && !isset($user['uid'])) {
  106. Dever::alert('user error');
  107. }
  108. if (isset($user['uid']) && $user['uid']) {
  109. return $user['uid'];
  110. }
  111. return -1;
  112. }
  113. # 更新
  114. public function update($uid, $name, $avatar, $sex)
  115. {
  116. $info = Dever::db('user/info')->find($uid);
  117. if ($info) {
  118. $update['username'] = $name;
  119. $update['avatar'] = $avatar;
  120. $update['sex'] = $sex;
  121. $update['where_id'] = $uid;
  122. Dever::db('user/info')->update($update);
  123. } else {
  124. Dever::alert('无效的用户id,请重新登录');
  125. }
  126. $result = Dever::db('user/info')->one(array('id' => $uid, 'clear' => true));
  127. return $this->getSign($uid, $result);
  128. }
  129. }