Info.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 < 1000000) {
  48. $info = Dever::db('manage/admin')->find($uid);
  49. if ($info) {
  50. $info['name'] = $info['username'];
  51. $info['area_string'] = '';
  52. $info['avatar'] = '';
  53. }
  54. } else {
  55. $info = Dever::db('user/info')->find($uid);
  56. if ($info) {
  57. if (isset($info['area']) && $info['area']) {
  58. $info['area_string'] = Dever::load('area/api')->string($info['area']);
  59. }
  60. if (!$info['avatar'] && $info['avatar_id'] > 0) {
  61. $avatar = Dever::db('user/avatar')->one($info['avatar_id']);
  62. if ($avatar) {
  63. $info['avatar'] = $avatar['avatar'];
  64. }
  65. }
  66. }
  67. }
  68. return $info;
  69. }
  70. /**
  71. * 设置项目
  72. *
  73. * @return mixed
  74. */
  75. public function setProject($uid, $project)
  76. {
  77. $where['uid'] = $uid;
  78. $where['project_id'] = $project;
  79. $one = Dever::db('user/user_project')->find($where);
  80. if (!$one) {
  81. Dever::db('user/user_project')->insert($where);
  82. }
  83. }
  84. /**
  85. * 获取加密信息
  86. *
  87. * @return mixed
  88. */
  89. public function getSign($uid, $data = array())
  90. {
  91. $data['signature'] = Dever::login($uid);
  92. return $data;
  93. }
  94. /**
  95. * 检测用户有效性
  96. *
  97. * @return mixed
  98. */
  99. public function check($state = true, $name = 'signature')
  100. {
  101. $signature = Dever::input($name);
  102. $user = Dever::checkLogin($signature, $state);
  103. if ($state && !isset($user['uid'])) {
  104. Dever::alert('user error');
  105. }
  106. if (isset($user['uid']) && $user['uid']) {
  107. return $user['uid'];
  108. }
  109. return -1;
  110. }
  111. }