Info.php 2.7 KB

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