123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- namespace User\Lib;
- use Dever;
- class Info
- {
- private $user = array();
- # 保存用户信息
- public function up($uid, $info_id, $username, $title, $info)
- {
- $update['username'] = $username;
- if (!$update['username']) {
- Dever::alert('昵称不能为空');
- }
- $update['title'] = $title;
- $update['info'] = $info;
- $update['info_id'] = $info_id;
- $user = Dever::db('user/info')->one(array('uid' => $uid));
- if (!$user) {
- $update['uid'] = $uid;
- Dever::db('user/info')->insert($update);
- } else {
- $update['where_id'] = $user['id'];
- Dever::db('user/info')->update($update);
- }
- return true;
- }
- # 保存头像
- public function upAvatar($uid, $info_id, $avatar)
- {
- $update['avatar'] = $avatar;
- if (!$update['avatar']) {
- Dever::alert('头像不能为空');
- }
- $update['info_id'] = $info_id;
- $user = Dever::db('user/info')->one(array('uid' => $this->uid));
- if (!$user) {
- $update['uid'] = $uid;
- Dever::db('user/info')->insert($update);
- } else {
- $update['where_id'] = $user['id'];
- Dever::db('user/info')->update($update);
- }
- return 'ok';
- }
- # 获取用户信息
- public function get($user, $id, $author = false)
- {
- if (is_array($user)) {
- $uid = $user['id'];
- } else {
- $uid = $user;
- }
- if ($uid <= 0) {
- return array();
- }
- $key = 'user_' . $uid . '_' . $id . '_' . $author;
- if (isset($this->user[$key])) {
- return $this->user[$key];
- }
- if (is_numeric($user)) {
- $user = Dever::load('passport/api')->info($user);
- }
- $result = array();
- if ($user) {
- if ($id) {
- # 获取合集扩展信息
- $result = Dever::db('user/info')->one(array('uid' => $user['id'], 'info_id' => $id));
- if (!$result) {
- $result['uid'] = $user['id'];
- $result['username'] = $user['username'];
- $result['avatar'] = $user['avatar'];
- $result['info'] = $user['info'];
- $result['sex'] = $user['sex'];
- $result['title'] = $user['title'];
- } else {
- !$result['username'] && $result['username'] = $user['username'];
- !$result['avatar'] && $result['avatar'] = $user['avatar'];
- !$result['info'] && $result['info'] = $user['info'];
- !$result['sex'] && $result['sex'] = $user['sex'];
- }
- } else {
- $result = $user;
- }
- }
- $result['mobile'] = $user['mobile'];
- $result['area_id'] = $user['area_id'];
- $result['address'] = $user['address'];
- $result['address_contact'] = $user['address_contact'] ? $user['address_contact'] : $user['username'];
- $result['address_mobile'] = $user['address_mobile'] ? $user['address_mobile'] : $user['mobile'];
- $result['author'] = '';
-
- if ($author) {
- $collection = Dever::load('collection/lib/info')->get($id);
- if ($collection && $collection['uid'] > 0 && $collection['uid'] == $user['id']) {
- $result['author'] = $collection['author_name'];
- if ($collection['author']) {
- $result['username'] = $collection['author'];
- }
- if ($collection['author_logo']) {
- $result['avatar'] = $collection['author_logo'];
- }
- }
- }
- if ($result['author']) {
- $result['username_text'] = '<span style="padding-right:4px;color: #00B3FF;">[' . $result['author'] . ']</span>' . $result['username'];
- }
- $result['username_text'] = $result['username'];
- $this->user[$key] = $result;
-
- return $result;
- }
- }
|