123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?php
- namespace User\Lib;
- use Dever;
- class Info
- {
- public function manage_search_api()
- {
- $table = 'user/info';
- $keyword = Dever::input('keyword');
- $yes = Dever::input('yes');
- $where = array();
- $cate = Dever::input('cate');
- if ($cate) {
- $where['cate_id'] = $cate;
- }
- if ($yes) {
- $yes = Dever::db($table)->search(array('ids' => $yes));
- }
- if (!$keyword) {
- $where['limit'] = '0,10';
- $data = Dever::db($table)->search($where);
- } else {
- $where['search'] = $keyword;
- $data = Dever::db($table)->search($where);
- }
- $result = array();
- if ($yes) {
- foreach ($yes as $k => $v) {
- if (isset($data[$k])) {
- unset($data[$k]);
- }
- $yes[$k]['selected'] = true;
- }
- $data = $yes + $data;
- $data = array_merge($data, array());
- } else {
- $data = array_merge($data, array());
- }
- if (!$data) {
- Dever::alert('暂无数据');
- }
- return $data;
- }
- public function get($uid)
- {
- $info = array();
- if ($uid < 100000000) {
- $info = Dever::db('manage/admin')->find($uid);
- if ($info) {
- $info['name'] = $info['username'];
- $info['area_string'] = '';
- $info['avatar'] = '';
- $info['aname'] = $info['name'] . ($info['mobile'] ? '('.$info['mobile'].')' : '');
- }
- } else {
- $info = Dever::db('user/info')->find($uid);
- if ($info) {
- if (isset($info['area']) && $info['area']) {
- $info['area_string'] = Dever::load('area/api')->string($info['area']);
- }
- if (!$info['avatar'] && $info['avatar_id'] > 0) {
- $avatar = Dever::db('user/avatar')->one($info['avatar_id']);
- if ($avatar) {
- $info['avatar'] = $avatar['avatar'];
- }
- }
- $info['aname'] = $info['name'] . '('.$info['mobile'].')';
- }
- }
- return $info;
- }
- /**
- * 设置项目
- *
- * @return mixed
- */
- public function setProject($uid, $project)
- {
- $where['uid'] = $uid;
- $where['project_id'] = $project;
- $one = Dever::db('user/user_project')->find($where);
- if (!$one) {
- Dever::db('user/user_project')->insert($where);
- }
- }
- /**
- * 获取加密信息
- *
- * @return mixed
- */
- public function getSign($uid, $data = array())
- {
- $data['signature'] = Dever::login($uid);
- return $data;
- }
- /**
- * 检测用户有效性
- *
- * @return mixed
- */
- public function check($state = true, $name = 'signature')
- {
- $signature = Dever::input($name);
- $user = Dever::checkLogin($signature, $state);
- if ($state && !isset($user['uid'])) {
- Dever::alert('user error');
- }
- if (isset($user['uid']) && $user['uid']) {
- return $user['uid'];
- }
- return -1;
- }
- # 更新
- public function update($uid, $name, $avatar, $sex)
- {
- $info = Dever::db('user/info')->find($uid);
- if ($info) {
- $update['username'] = $name;
- $update['avatar'] = $avatar;
- $update['sex'] = $sex;
- $update['where_id'] = $uid;
- Dever::db('user/info')->update($update);
- } else {
- Dever::alert('无效的用户id,请重新登录');
- }
- $result = Dever::db('user/info')->one(array('id' => $uid, 'clear' => true));
-
- return $this->getSign($uid, $result);
- }
- }
|