123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- <?php
- namespace Passport\Lib;
- use Dever;
- class Manage
- {
- public function updateAddress($id, $name, $param)
- {
- $area = Dever::param('area', $param);
- if ($area && is_array($area)) {
- $update['where_id'] = $id;
- $update['province'] = $area[0];
- $update['city'] = $area[1];
- $update['county'] = isset($area[2]) ? $area[2] : '';
- $update['town'] = isset($area[3]) ? $area[3] : '';
- $update['address'] = Dever::load("area/api.string", implode(',', $area), '');
- Dever::db('passport/address')->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['头像'] = '<img src="'.$user['avatar'].'" width="150" />';
- } elseif ($user['avatar_id'] > 0) {
- $avatar = Dever::db('passport/avatar')->one($user['avatar_id']);
- if ($avatar) {
- $table['头像'] = '<img src="'.$avatar['avatar'].'" width="150" />';
- }
-
- }
- 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['头像'] = '<img src="'.$user['avatar'].'" width="150" />';
- }
- 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 . '%';
- }
- }
|