update($update);
}
}
# 同步将其他地方的分类更新为system
public function updateSystem($id, $name, $param)
{
$name = Dever::param('name', $param);
$appid = Dever::param('appid', $param);
$appsecret = Dever::param('appsecret', $param);
$data['name'] = $name;
if ($appid && $appsecret) {
$data['appid'] = $appid;
$data['secret'] = $appsecret;
}
$info = Dever::db('passport/system')->one($id);
if (!$info) {
Dever::db('passport/system')->insert($data);
} else {
$data['where_id'] = $info['id'];
$data['state'] = Dever::param('state', $param);
if (!$name) {
unset($data['name']);
};
Dever::db('passport/system')->update($data);
}
return $info;
}
public function show($id)
{
$db = Dever::db('passport/user');
$user = $db->one($id);
$config = $db->config;
if ($user['avatar']) {
$table['头像'] = '';
} elseif ($user['avatar_id'] > 0) {
$avatar = Dever::db('passport/avatar')->one($user['avatar_id']);
if ($avatar) {
$table['头像'] = '';
}
}
if ($user['area']) {
$table['地区'] = $user['area'];
}
if (isset($user['address']) && $user['address']) {
$table['详细地址'] = $user['address'];
}
if ($user['system_source']) {
$table['来源'] = $config['system_source'][$user['system_source']];
} elseif ($user['source_type']) {
$table['来源'] = $config['source_type'][$user['source_type']];
}
if ($user['profession']) {
$profession = Dever::db('passport/profession')->one($user['profession']);
if ($profession) {
$table['职业'] = $profession['name'];
}
}
if ($user['sex']) {
$table['性别'] = $config['sex'][$user['sex']];
}
if ($user['wechat']) {
$table['微信号'] = $user['wechat'];
}
if ($user['email']) {
$table['邮箱'] = $user['email'];
}
if (Dever::project('invite')) {
$invite = Dever::db('invite/code')->one(array('uid' => $user['id']));
if ($invite) {
$table['邀请码'] = $invite['value'];
}
}
return Dever::table($table);
}
public function showAvatar($id)
{
$db = Dever::db('passport/avatar');
$user = $db->one($id);
if ($user['avatar']) {
$table['头像'] = '';
}
return Dever::table($table);
}
public function search_api()
{
$table = 'passport/user';
$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['username'] = $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'] = 'selected';
}
$data = $yes + $data;
$data = array_merge($data, array());
} else {
$data = array_merge($data, array());
}
if (!$data) {
Dever::alert('暂无数据');
}
return $data;
}
# 获取环比增长
public function getHb($user, $day)
{
$where = array('day' => Dever::maketime($day));
$search = Dever::search_button();
if ($search) {
$where['config']['group'] = $search[0];
$where['config']['col'] = str_replace('|id', '', $search[1]);
}
$prev = Dever::db('passport/stat')->prev($where);
if ($prev) {
$hb = round(($user-$prev['user'])/$prev['user'], 2)*100;
} else {
$hb = 0;
}
return $hb . '%';
}
}