',1]; } } //高级搜索 //靓号,//登录设备,//昵称, //状态,//金币,//主持时间 $search_type =['user_code','login_device','nickname','status','coin1','coin2','createtime']; foreach ($search_type as $v) { $input_data = input($v, ''); if($input_data!==""){ if($v=='coin1'){ $where['c.coin'] = ['>=',$input_data]; }elseif($v=='coin2'){ if($input_data){ $where['c.coin'] = ['<=',$input_data]; } }elseif($v=='createtime'){ $where['a.createtime'] = ['>=',strtotime($input_data)]; $where['a.createtime'] = ['<=',strtotime($input_data)]; }else{ $where['a.'.$v] = $input_data; } } } $field = ' a.id, a.avatar, a.mobile, a.nickname, a.sex, a.user_code, a.login_device, a.loginip, c.coin, c.earnings, b.is_real, a.init_code, a.status '; $user_data = db::name('user')->alias('a') ->join('(SELECT * FROM fa_user_auth WHERE id IN (SELECT MAX(id) FROM fa_user_auth GROUP BY mobile)) b', 'a.mobile = b.mobile', 'LEFT') ->join('user_wallet c', 'a.id = c.user_id','LEFT') ->where($where) ->field($field) ->order('a.id desc'); $lists = $user_data->page($page, $page_limit)->select(); $count = db::name('user')->alias('a') ->join('(SELECT * FROM fa_user_auth WHERE id IN (SELECT MAX(id) FROM fa_user_auth GROUP BY mobile)) b', 'a.mobile = b.mobile', 'LEFT') ->join('user_wallet c', 'a.id = c.user_id','LEFT') ->where($where) ->field($field) ->order('a.id desc')->count(); foreach ($lists as $key => $value) { $lists[$key]['status_str'] = $value['status'] == 1 ? '正常' : '禁用'; $lists[$key]['is_real_str'] = $value['is_real'] == 1 ? '已实名' : '未实名'; //禁用状态 //1:禁用账号 2:禁用设备号 3:禁用IP $lists[$key]['is_block_user'] = $lists[$key]['is_block_mobile'] =$lists[$key]['is_block_ip'] = 0; $is_block_user = Db::name('block')->where(['type_text' => $value['id'],'type'=>1,'block_time'=>['>=',time ()]])->find(); // $is_block_mobile = Db::name('block')->where(['type_text' => $value['login_device'],'type'=>2,'block_time'=>['>=',time ()]])->find(); // $is_block_ip = Db::name('block')->where(['type_text' => $value['loginip'],'type'=>3,'block_time'=>['>=',time ()]])->find(); $lists[$key]['user_block_time'] = ''; $lists[$key]['mobile_block_time'] = ''; $lists[$key]['ip_block_time'] = ''; if($is_block_user){ $lists[$key]['is_block_user'] = 1; if($is_block_user['block_time']==0){ $lists[$key]['user_block_time'] = '永久封禁'; }else{ $lists[$key]['user_block_time'] = date('Y-m-d H:i:s',$is_block_user['block_time']); } } // if($is_block_mobile){ // $lists[$key]['is_block_mobile'] = 1; // $lists[$key]['mobile_block_time'] = date('Y-m-d H:i:s',$is_block_mobile['block_time']); // } // if($is_block_ip){ // $lists[$key]['is_block_ip'] = 1; // $lists[$key]['ip_block_time'] = date('Y-m-d H:i:s',$is_block_ip['block_time']); // } //靓号处理 //查询用是否有靓号 $special_num = db::name('vs_user_decorate')->where(['user_id'=>$value['id'],'type'=>6,'is_using'=>1])->where('end_time',['>=',time()],'or')->value('special_num'); if($special_num){ $lists[$key]['special_num'] = $special_num; }else{ $lists[$key]['special_num'] = "无"; } } $return_data = [ 'page' =>$page, 'page_limit' => $page_limit, 'count' => $count, 'lists' => $lists ]; return V(1,"成功", $return_data); } /* * 删除用户 */ public function delUser(){ $user_id = input('user_id', 0); if(!$user_id){ return V(0, "用户不存在"); } $res = model('User')->where('id', $user_id)->update(['status' => 0,'delete_time'=>time()]); if (!$res) { return V(0, "删除失败"); } return V(1,"成功", null); } /* * 封禁用户 * @ type 1:禁用账号 2:禁用设备号 3:禁用IP */ public function banUser(){ //获取管理员ID $admin_id = Session::get('id'); $user_id = input('user_id', 0); $type = input('type', 0); $time = input('time', 0); $status = input('status', 1); $user_info = model('User')->where('id', $user_id)->find(); if(!$user_info){ return V(0, "用户不存在"); } if($status ==1){ $type_text = ""; if($type ==1){ $res = model('User')->where('id', $user_id)->update(['status' => 2]); if (!$res) { return V(0, "禁用失败"); } $type_text = $user_id; } if($type ==2){ $type_text = $user_info['login_device']; } if($type ==3){ $type_text = $user_info['loginip']; } if($time){ $block_time = strtotime($time); }else{ $block_time = ''; //永久 } //插入fa_block 表 $res = Db::name('block')->insert([ 'admin_id' => $admin_id, 'type' => $type, 'type_text' => $type_text, 'block_time' => $block_time, 'createtime' => time(), ]); if (!$res) { return V(0, "添加失败"); } }else{ if($type ==1) { $res = model('User')->where('id', $user_id)->update(['status' => 1]); $type_text = $user_id; } if($type ==2){ $type_text = $user_info['login_device']; } if($type ==3){ $type_text = $user_info['loginip']; } $map = [ 'type' => $type, 'type_text' => $type_text, ]; Db::name('block')->where($map)->delete(); Db::name('sms_error')->where(['mobile' => $user_info['mobile']])->delete(); } return V(1,"成功", null); } /* * 设为官方账号 */ public function setSysTester(){ $user_id = input('user_id', 0); if(!$user_id){ return V(0, "用户不存在"); } $res = model('User')->where('id', $user_id)->update(['is_sys_tester' => 1]); if (!$res) { return V(0, "添加失败"); } return V(1,"成功", null); } /* * 修改密码 * */ public function changePwd(){ $user_id = input('user_id', 0); if(!$user_id){ return V(0, "用户不存在"); } $new_pwd = input('new_pwd', ''); if(!$new_pwd){ return V(0, "请输入新密码"); } $res = model('User')->where('id', $user_id)->update(['password' => md5($new_pwd)]); if (!$res) { return V(0, "修改失败"); } return V(1,"成功", null); } /* * 设置资金 */ public function setMoney(){ $user_id = input('user_id', 0); $money_type = input('money_type', ''); $change_value = input('change_value', 0); $secondary_password = input('secondary_password',''); $remark = input('remarks', ''); if(!$user_id){ return V(0, "用户不存在"); } if(!$money_type){ return V(0, "请选择类型"); } $check_pass = model('adminapi/admin')->check_secondary_password($secondary_password); if($check_pass['code']==0){ return v($check_pass['code'], $check_pass['msg'], $check_pass['data']); } if(!$change_value){ return V(0, "请输入金额"); } if($remark){ $remarks = model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::OPERATION_SYSTEM)." 备注:".$remark; }else{ $remarks = model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::OPERATION_SYSTEM); } if($change_value<0){ $remarks = "后台扣除-".$remarks; } $res = model('common/UserWallet')->change_user_money($user_id, $change_value, $money_type, model('common/UserWallet')::OPERATION_SYSTEM,$remarks); if($res['code']==0){ return V($res['code'],$res['msg']); } $return = db::name('vs_admin_recharge_log')->insert([ 'user_id' => $user_id, 'type' => $money_type, 'change_value' => $change_value, 'remarks' => $remark, 'createtime' => time(), 'admin_id' => Session::get('admin_id') ]); if(!$return){ return v(0,'添加失败'); } return v(1,'添加成功'); } /* * 用户信息 */ public function userInfo(){ $user_id = input('user_id', 0); $user = model('api/User')->get_user_info($user_id); if(!$user){ return V(0, "用户不存在"); } //数据处理 $user_data['user_info']['avatar'] = $user['avatar']; $user_data['user_info']['nickname'] = $user['nickname']; $user_data['user_info']['charm_level_icon'] = $user['charm_level_icon']; $user_data['user_info']['wealth_level_icon'] = $user['wealth_level_icon']; $user_data['user_info']['user_code'] = $user['user_code']; $user_data['user_info']['mobile'] = $user['mobile']; $user_data['user_info']['sex'] = $user['sex']==1 ? '男' : '女'; $user_data['user_info']['birthday'] = $user['birthday']; $user_data['user_info']['system'] = $user['system']; $user_data['user_info']['age'] = $user['age']; $user_data['user_info']['profile'] = $user['profile']; $user_data['user_info']['status'] = $user['status']; //状态 1正常,2禁止登录,0注销 $user_data['user_info']['status_str'] = $user['status']==1 ? '正常' : ($user['status']==2 ? '禁止登录' : '注销'); $user_data['user_info']['red_status'] = $user['red_status']; $user_data['user_info']['red_status_str'] = $user['red_status']==1 ? '开启' : '禁止'; //标签 $user_data['user_info']['tag'] = $user['tag_list']; $user_data['user_info']['createtime'] = date('Y-m-d H:i:s', $user['createtime']);//主持时间 //统计相关: $user_data['follow_num']['user_recharge_all_money'] = $user['user_recharge_all_money']; $user_data['follow_num']['coin'] = $user['coin']; $user_data['follow_num']['earnings'] = $user['earnings']; $user_data['follow_num']['follow_num'] = $user['follow_num']; $user_data['follow_num']['fans_num'] = $user['fans_num']; $user_data['follow_num']['invited_num'] = $user['invited_num']; $user_data['follow_num']['invited_earnings'] = $user['invited_earnings']; //收藏话题【咱无】 //收藏评论【咱无】 $user_data['follow_num']['is_real'] = $user['is_real'] == 1 ? '已实名' : '未实名';; $user_data['follow_num']['real_name'] = $user['real_name']; $user_data['follow_num']['card_id'] = $user['card_id']; return V(1,"成功", $user_data); } /* * 编辑用户信息 */ public function editUser(){ $user_id = input('user_id', 0); $user = model('User')->get($user_id); if (!$user) { return V(0, "用户不存在"); } $up_user = []; $nickname = input('nickname', ''); if ($nickname) { $up_user['nickname'] = $nickname; } $sex = input('sex', ''); if ($sex) { $up_user['sex'] = $sex; } $birthday = input('birthday', ''); if ($birthday) { $up_user['birthday'] = $birthday; } $profile = input('profile', ''); if ($profile) { $up_user['profile'] = $profile; } $status = input('status', ''); if ($status) { $up_user['status'] = $status; } $red_status = input('red_status', ''); if($red_status!=""){ $up_user['red_status'] = $red_status; } $up_user_data =[]; $real_name = input('real_name', ''); if ($real_name) { $up_user_data['real_name'] = $real_name; } $card_id = input('card_id', ''); if ($card_id) { $up_user_data['card_id'] = $card_id; } $is_real = input('is_real', ''); if ($is_real) { $up_user_data['is_real'] = $is_real; } $init_code = input('init_code', ''); if($init_code){ //绑定 $reslut = model('api/Invited')->invited_bind($init_code, $user_id); if ($reslut['code'] == 0) { return v($reslut['code'], $reslut['msg'], $reslut['data']); } } if($up_user){ $reslut = DB::name('user')->where('id', $user_id)->update($up_user); } if($up_user_data){ $res = DB::name('user_auth')->where('mobile', $user['mobile'])->update($up_user_data); } return V(1,'操作成功'); } /* * 会员收支日志 */ public function money_log_list(){ $user_id = input('user_id'); $page = input('page',1); $page_limit = input('page_limit',10); $type = input('type',''); $stime = input('stime',''); $etime = input('etime',''); $change_type = input('change_type',''); $seach = [ 'stime' => $stime, 'etime' => $etime, 'change_type' => $change_type ]; $return = model('UserWallet')->money_change_log($user_id,$seach,$type,$page,$page_limit); $list = []; foreach($return['list'] as $k=>$v){ $list[$k] = [ 'title' => $v['change_type'], 'change_time' => $v['createtime'], 'type' => $v['change_in_out'], 'content' => $v['remarks'], 'change_money' => $v['change_value'], ]; } $return_data = [ 'page' =>$page, 'page_limit' => $page_limit, 'count' => $return['count'], 'lists' => $list ]; return V(1,"操作成功", $return_data); } /* * 获取用户资金类型 */ public function get_money_type(){ $reslut = model('UserWallet')->getChangeTypeLableList(); return V(1,"操作成功", $reslut); } /* * 相册列表 */ public function get_album_list(){ $user_id = input('user_id',0); $reslut = model('api/user')->get_album_list($user_id); return V($reslut['code'], $reslut['msg'], $reslut['data']); } /* * 相册详情 */ public function get_album_detail() { $album_id = input('album_id', 0); $user_id = input('user_id',0); $pwd = input('pwd',''); $page = input('page', 1); $page_limit = input('page_limit', 30); $reslut = model('api/user')->get_album_detail($user_id,$album_id,$pwd, $page, $page_limit,1); return V($reslut['code'], $reslut['msg'], $reslut['data']); } //删除相册 public function delete_album() { $album_id = input('album_id', 0); $user_id = input('user_id',0); $reslut = model('api/user')->delete_album($user_id,$album_id); return V($reslut['code'], $reslut['msg'], $reslut['data']); } /** * 机器人列表 */ public function get_robot_list(){ $page = input('page', 1); $page_limit = input('page_limit', 30); $search_mobile = input('search_mobile', ''); $search_nickname = input('search_nickname', ''); $search_id = input('search_id', ''); $where['is_robot'] =1; $where['a.delete_time'] = 0; $where['a.status'] = 1; if($search_id!==""){ $where['user_code'] = $search_id; } if($search_mobile !==''){ $where['a.mobile'] = ['like', '%'.$search_mobile.'%']; } if($search_nickname !==''){ $where['a.nickname'] = ['like', '%'.$search_nickname.'%']; } $field = ' a.id, a.avatar, a.mobile, a.nickname, a.sex, a.user_code, a.login_device, c.coin, c.earnings, b.is_real, a.init_code, a.status, a.createtime '; $count = db::name('user')->alias('a') ->join('fa_user_auth b', 'a.mobile = b.mobile','LEFT') ->join('user_wallet c', 'a.id = c.user_id','LEFT') ->where($where) ->count(); $user_data = db::name('user')->alias('a') ->join('fa_user_auth b', 'a.mobile = b.mobile','LEFT') ->join('user_wallet c', 'a.id = c.user_id','LEFT') ->where($where) ->field($field) ->order('a.id desc'); $lists = $user_data->page($page, $page_limit)->select(); foreach ($lists as $key => $value) { $lists[$key]['createtime'] = date('Y-m-d H:i:s',$value['createtime']); } $return_data = [ 'page' =>$page, 'page_limit' => $page_limit, 'count' => $count, 'lists' => $lists ]; return V(1,"成功", $return_data); } /** * 批量生成机器人 */ public function get_robot_detail(){ $num = 20; for($i=1;$i<=$num;$i++){ $user_name = $this->hao_duan_create(); $reslut = model('User')->user_reg($user_name); } return V(1,"操作成功", null); } //单个生成账号 public function create_robot(){ //根据号段生成账号 $user_name = $this->hao_duan_create(); $reslut = model('User')->user_reg($user_name); return V($reslut['code'], $reslut['msg'], $reslut['data']); } //虚拟号段 public function hao_duan_create(){ $user_name = generateRandomPhoneNumber(); $user_name_exist = db::name('user')->where('username','=',$user_name)->field('id')->find(); if(!empty($user_name_exist)){ return $this->hao_duan_create(); // return false; } return $user_name; } /* * 删除机器人 */ public function delete_robot(){ $user_id = input('user_id', 0); if(!$user_id){ return V(0, "用户不存在"); } $res = model('User')->where('id', $user_id)->update(['status' => 0,'delete_time'=>time()]); if (!$res) { return V(0, "删除失败"); } return V(1,"成功", null); } /* * 背包列表 */ public function get_backpack_list(){ $user_id = input('user_id',0); $gid = input('gid',0); $page = input('page',1); $page_limit = input('page_limit',10); $where['a.is_tester'] = 1; if($user_id){ $where['a.user_id'] = $user_id; } if($gid){ $where['a.gid'] = $gid; } $count = db::name('vs_user_gift_pack')->alias('a')->join('user b', 'a.user_id = b.id')->where($where)->count(); $list = db::name('vs_user_gift_pack') ->alias('a') ->join('user b', 'a.user_id = b.id') ->join('vs_gift c', 'a.gid = c.gid') ->field('a.*,b.user_code,b.nickname,c.gift_name,c.base_image,c.gift_price')->where($where)->order('a.pid', "desc")->page($page, $page_limit)->select(); foreach ($list as $key => &$value) { $value['createtime'] = date('Y-m-d H:i:s',$value['createtime']); $value['user_id_nickname'] = $value['user_code'].'——'.$value['nickname']; $value['gift_id_name'] = $value['gid'].'——'.$value['gift_name']; } //礼物个数 $gift_count = db::name('vs_user_gift_pack')->alias('a')->join('user b', 'a.user_id = b.id')->where($where)->group('a.gid')->count(); //礼物总金额 $gift_total = db::name('vs_user_gift_pack')->alias('a')->join('user b', 'a.user_id = b.id') ->join('vs_gift c', 'a.gid = c.gid') ->where($where)->sum('c.gift_price'); $return_data = [ 'page' =>$page, 'page_limit' => $page_limit, 'count' => $count, 'gift_count' => $gift_count, 'gift_total' => $gift_total, 'lists' => $list ]; return V(1,"操作成功", $return_data); } /* * 禁用列表 */ public function get_forbidden_list(){ $user_id = input('user_id',); $seach_value = input('seach_value', ''); $search_user_id = input('search_user_id', ''); $page = input('page', 1); $page_limit = input('page_limit', 30); $where = ['is_delete'=>0,'type'=>['<>',1]]; //判断seach_value是否是IP地址 if($seach_value!=''){ if(filter_var($seach_value, FILTER_VALIDATE_IP)){ $type = 3; }else{ $type = 2; } $where['type'] = $type; $where['type_text'] = $seach_value; } // if($search_user_id!=''){ // $type = 1; // $where['type'] = $type; // $where['type_text'] = $search_user_id; // } $list = Db::name('block')->where($where)->order('id desc')->page($page,$page_limit)->select(); $count = Db::name('block')->where($where)->count(); $type_arr = [ 1=>'账号', 2=>'设备', 3=>'ip', 4=>'禁言', ]; foreach ($list as $key => &$value) { //封禁类型 1账号, 2设备, 3ip 4禁言 $value['type_str'] = $type_arr[$value['type']]; if($value['block_time'] == 0){ $value['block_time'] = '永久封禁'; $value['status_str'] = '封禁中'; $value['status'] = 1; }else{ $value['block_time'] = date('Y-m-d H:i:s',$value['block_time']); if($value['block_time']>time()){ $value['status_str'] = '封禁中'; $value['status'] = 1; }else{ $value['status_str'] = '已解封'; $value['status'] =2; } } $value['createtime'] = date('Y-m-d H:i:s',$value['createtime']); } $return_data = [ 'page' =>$page, 'page_limit' => $page_limit, 'count' => $count, 'lists' => $list ]; return V(1,"成功", $return_data); } /* * 封禁添加 */ public function add_forbidden(){ $type = input('type', 1); $type_text = input('type_text', ''); $block_time = input('block_time', 0); $admin_id = Session::get('admin_id'); //插入fa_block 表 $res = Db::name('block')->insert([ 'admin_id' => $admin_id, 'type' => $type, 'type_text' => $type_text, 'block_time' => strtotime($block_time), 'createtime' => time(), ]); if (!$res) { return V(0, "添加失败"); } return V(1,"添加成功", null); } /* * 解封 */ public function del_forbidden(){ $id = input('id', 0); if (!$id) { return V(0, "参数错误"); } $res = Db::name('block')->where(['id'=>$id])->delete(); if (!$res) { return V(0, "解封失败"); } return V(1,"解封成功", null); } /* * 用户列表 */ public function get_user_list(){ $user_code = input('user_code', 0); $where = []; if($user_code){ $where['user_code'] = $user_code; } $user = db::name('user')->field('id,nickname,avatar')->where($where)->where(['status'=>1,'is_robot'=>0,'delete_time'=>0])->select(); return V(1,"操作成功", $user); } }