group('uid')->field('uid, sum(price) as price')->select(); $total_price = db::name('user_monster_feed_log')->sum('price'); dump($list); dump($total_price); } //清除用户token public function create_user_token($uid, $phone){ if(empty($uid) && empty($phone)){ return ['code' => 201, 'msg' => '参数错误', 'data' => null]; } if(!empty($uid)){ $user_info = db::name('user')->where('uid',$uid)->find(); if($user_info){ $data = []; $data['login_token'] = ''; $data['update_time'] = time(); $reslut = db::name('user')->where('uid',$uid)->update($data); if($reslut){ return ['code' => 200, 'msg' => '清除成功', 'data' => null]; } } }else if(!empty($phone)){ $user_info = db::name('user')->where('user_name',$phone)->find(); if($user_info){ $data = []; $data['login_token'] = ''; $data['update_time'] = time(); $reslut = db::name('user')->where('uid',$user_info['uid'])->update($data); if($reslut){ return ['code' => 200, 'msg' => '清除成功', 'data' => null]; } } } return ['code' => 200, 'msg' => '请求成功', 'data' => null]; } //检查用户登录状态 public function check_login_token($login_token) { if (empty($login_token)) { return ['code' => 201, 'msg' => '登录失效', 'data' => null]; } $map = []; $map[] = ['login_token', '=', $login_token]; $user_info = db::name('user')->where($map)->find(); if (empty($user_info)) { return ['code' => 201, 'msg' => '登录失效', 'data' => null]; } elseif ($user_info['login_status'] != 1) { if($user_info['login_status'] == 3){ return ['code' => 202, 'msg' => '该账号已被注销', 'data' => null]; } return ['code' => 202, 'msg' => '用户已被封禁', 'data' => null]; } else { //用户IP是否被封禁 $map = []; $map[] = ['type', '=', 3]; $map[] = ['type_text', '=', $user_info['login_ip']]; $map[] = ['is_delete', '=', 1]; $block_ip = db::name('block')->where($map)->find(); if($block_ip){ return ['code' => 202, 'msg' => '当前IP地址已被封禁。', 'data' => null]; } //用户设备号是否被封禁 $map = []; $map[] = ['type', '=', 1]; $map[] = ['type_text', '=', $user_info['last_login_device']]; $map[] = ['is_delete', '=', 1]; $block_device = db::name('block')->where($map)->find(); if($block_device){ return ['code' => 202, 'msg' => '当前设备号已被封禁。', 'data' => null]; } return ['code' => 200, 'msg' => '登录成功', 'data' => $user_info['uid']]; } } //生成邀请 二维码 public function get_user_reg_qrcode($uid) { $user_info = db::name('user')->where('uid', $uid)->find(); if (empty($user_info)) { return ['code' => 200, 'msg' => '信息不存在', 'data' => null]; } $web_site = model('admin/Config')->get_system_config('web_site'); if (empty($user_info['reg_code_path'])||1) { $url = $web_site . "/index.php/index/index/register?reg_code=" . $user_info['reg_code']; //二维码地址 require_once Env::get('root_path') . "/extend/phpqrcode/phpqrcode.php"; $data = $url; $level = 'L'; // 容错级别:L、M、Q、H $size = 4; $qrcode = new \QRcode(""); ob_start(); //设置二维码图片名称,以及存放的路径 $filename = './uploads/qrcode/' . time() . rand(10000, 99999) . '.jpg'; $qrcode->png($data, $filename, $level, $size, 2); //上传到七牛云 $reg_code_path = substr($filename, 1); dump($reg_code_path);exit; model('admin/Upload')->server_local_upload($reg_code_path); // $reg_code_path = $web_site . substr($filename, 1); db::name('user')->where(['uid' => $uid])->update(['reg_code_path' => $reg_code_path]); return ['code' => 200, 'msg' => '获取成功', 'data' => $reg_code_path]; } else { return ['code' => 200, 'msg' => '获取成功', 'data' => $user_info['reg_code_path']]; } } //获取用户信息 public function get_user_info($uid) { $config = get_uncache_system_config(); $map = []; $map[] = ['uid', '=', $uid]; $user_info = db::name('user')->field('uid,user_name,base64_nick_name,head_pic,sex,birthday,special_uid,money,frozen_money,integral,room_profit,is_real,follow_num,fans_num,autograph,hobby,country,province,city,constellation,reg_code_path,charm_level,contribution_level,is_can_recharge,user_sig,is_teenager,reg_code,add_time,nick_name_color,is_room_hiding,is_open_address,vid')->where($map)->find(); if (empty($user_info)) { return ['code' => 201, 'msg' => '用户信息不存在', 'data' => null]; } $user_info['head_pic'] = localpath_to_netpath($user_info['head_pic']); $user_info['reg_code_path'] = localpath_to_netpath($user_info['reg_code_path']); $user_info['nick_name'] = mb_convert_encoding(base64_decode($user_info['base64_nick_name']), 'UTF-8', 'UTF-8'); $user_info['collect_room_num'] = db::name('user_collect_room')->where(['uid' => $uid])->count(); //获取用户收藏房间总数 $room = db::name('room')->where(['room_owner_uid' => $uid])->find(); $user_info['rid'] = 0; if (!empty($room)) { $user_info['rid'] = $room['rid']; } if(empty($user_info['nick_name_color'])){ $user_info['nick_name_color'] = ''; } // $user_info['reg_url'] = 'http://' . $_SERVER['HTTP_HOST'] . '/index.php/index/index/register?reg_code=' . $user_info['reg_code']; $user_info['reg_url'] = $config['loacl_resource_url'] . '/index.php/index/index/register?reg_code=' . $user_info['reg_code']; //是否有公会 $guild_id = 0; $map = []; $map[] = ['uid', '=', $uid]; $map[] = ['status', '=', 1]; $map[] = ['is_delete', '=', 1]; $guild_info = db::name('user_guild')->where($map)->find(); if($guild_info){ $guild_id = $guild_info['guild_id']; } $user_info['guild_id'] = $guild_id; $user_info['is_new'] = 2; $is_new_time = $user_info['add_time'] + (60*60*24*7); if(time() < $is_new_time){ $user_info['is_new'] = 1; } //cp数量 $user_info['cp_num'] = 0; //CP信息 $user_cp_info = model('Coupling')->user_coupling_info($uid); if($user_cp_info['data']['is_have_cp'] == 1){ $user_info['cp_num'] = 1; } return ['code' => 200, 'msg' => '获取成功', 'data' => $user_info]; } //指定用户信息 public function get_base_user_info($uid) { $map = []; $map[] = ['uid', '=', $uid]; $user_info = db::name('user')->field('uid,base64_nick_name,head_pic,sex,birthday,special_uid,follow_num,fans_num,autograph,country,province,city,constellation,charm_level,contribution_level')->where($map)->find(); if (empty($user_info)) { return ['code' => 201, 'msg' => '用户不存在', 'data' => null]; } $user_info['head_pic'] = localpath_to_netpath($user_info['head_pic']); $user_info['nick_name'] = mb_convert_encoding(base64_decode($user_info['base64_nick_name']), 'UTF-8', 'UTF-8'); return ['code' => 200, 'msg' => '获取成功', 'data' => $user_info]; } //用户资金信息 public function get_user_money($uid) { $user_money = db::name('user')->field('uid,integral,money,real_name,alipay_name,alipay_account,room_profit,bank_card,open_bank,bank_card_number,bank_user_name')->find($uid); $user_money['money'] = $user_money['money']; // if (empty($user_money['alipay_account']) && empty($user_money['alipay_name'])) { if(empty($user_money['bank_card_number']) && empty($user_money['bank_card']) && empty($user_money['bank_user_name']) && empty($user_money['open_bank'])){ $user_money['is_ali'] = 0; } else { $user_money['is_ali'] = 1; } $user_money['integral'] = (int)$user_money['integral']; // $map = []; // $map[] = ['player_uid', '=', $uid]; // $map[] = ['status', '=', 3]; // $map[] = ['is_over', '=', 1]; // $order_income = db::name('user_player_order')->where($map)->sum('total_amount'); $map = []; $map[] = ['uid', '=', $uid]; $map[] = ['change_type', '=', 6]; $gifts_income = db::name('user_money_log')->field('change_type,change_value')->where($map)->sum('change_value'); // $map = []; // $map[] = ['uid', '=', $uid]; // $map[] = ['change_type', '=', 5]; // $order_income = db::name('user_money_log')->field('change_type,change_value')->where($map)->sum('change_value'); $user_money['gifts_income'] = $gifts_income; //礼物收入 // $user_money['order_income'] = $order_income; //获取陪玩订单收益 return ['code' => 200, 'msg' => '获取成功', 'data' => $user_money]; } //用户收藏房间列表 public function get_user_collect_room_list($uid, $page, $page_limit) { $page = intval($page); $page_limit = $page_limit < 10 ? $page_limit : 10; $model = Db::name('user_collect_room')->alias('a')->join('yy_room b', 'a.rid = b.rid'); $map = []; $map[] = ['a.uid', '=', $uid]; $map[] = ['b.is_delete', '=', 1]; $model = $model->where($map); $list = $model->field('b.room_number,b.room_name,b.room_cover')->order('a.id desc')->page($page, $page_limit)->select(); foreach ($list as $k => &$v) { $v['room_cover'] = localpath_to_netpath($v['room_cover']); } $data['on'] = $list; $data['off'] = []; return ['code' => 200, 'msg' => '获取成功', 'data' => $data]; } //用户余额资金日志列表 public function get_user_money_log_list($uid, $page, $page_limit) { $page = intval($page); $page_limit = $page_limit < 30 ? $page_limit : 30; $ChangeTypeLable = model('admin/UserMoneyLog')->ChangeTypeLable(); $map = []; $map[] = ['uid', '=', $uid]; $map[] = ['money_type', '=', 1]; $list = db::name('user_money_log')->field('log_id,change_type,change_value,remarks,add_time')->where($map)->order('log_id desc')->page($page, $page_limit)->select(); foreach ($list as $k => &$v) { $v['change_type_desc'] = $ChangeTypeLable[$v['change_type']]; } return ['code' => 200, 'msg' => '获取成功', 'data' => $list]; } //用户积分资金日志列表 public function get_user_integral_log_list($uid, $page, $page_limit) { $page = intval($page); $page_limit = $page_limit < 30 ? $page_limit : 30; $ChangeTypeLable = model('admin/UserMoneyLog')->ChangeTypeLable(); $map = []; $map[] = ['uid', '=', $uid]; $map[] = ['money_type', '=', 2]; $list = db::name('user_money_log')->field('change_type,change_value,remarks,add_time')->where($map)->order('log_id desc')->page($page, $page_limit)->select(); foreach ($list as $k => &$v) { $v['change_type_desc'] = $ChangeTypeLable[$v['change_type']]; $v['change_value'] = (int)$v['change_value']; } return ['code' => 200, 'msg' => '获取成功', 'data' => $list]; } //获取陪玩订单收益 public function get_player_order_list($uid, $page, $page_limit) { $page = intval($page); $page_limit = $page_limit < 30 ? $page_limit : 30; $ChangeTypeLable = model('admin/UserMoneyLog')->ChangeTypeLable(); $map = []; $map[] = ['uid', '=', $uid]; $map[] = ['change_type', '=', 5]; $list = db::name('user_money_log')->field('change_type,change_value,remarks,add_time')->where($map)->order('log_id desc')->page($page, $page_limit)->select(); foreach ($list as $k => &$v) { $v['change_type_desc'] = $ChangeTypeLable[$v['change_type']]; } return ['code' => 200, 'msg' => '获取成功', 'data' => $list]; } //获取礼物收入 public function get_gift_reward_list($uid, $page, $page_limit) { $page = intval($page); $page_limit = $page_limit < 30 ? $page_limit : 30; $ChangeTypeLable = model('admin/UserMoneyLog')->ChangeTypeLable(); $map = []; $map[] = ['uid', '=', $uid]; $map[] = ['change_type', '=', 4]; $list = db::name('user_money_log')->field('change_type,change_value,remarks,add_time')->where($map)->order('log_id desc')->page($page, $page_limit)->select(); foreach ($list as $k => &$v) { $v['change_type_desc'] = $ChangeTypeLable[$v['change_type']]; } return ['code' => 200, 'msg' => '获取成功', 'data' => $list]; } public function get_send_gift_user_list($uid, $gift_from_type, $page, $page_limit) { $map = []; $map[] = ['uid', '=', $uid]; if (!empty($gift_from_type)) { $map[] = ['gift_from_type', '=', $gift_from_type]; } $list = db::name('user_send_gift')->field('uid,receive_uid,sum(gift_total_price) as total_send_amount,max(add_time) as last_send_time')->where($map)->group('receive_uid')->page($page, $page_limit)->order('add_time desc')->select(); $map = []; $map[] = ['uid', 'in', array_column($list, 'receive_uid')]; $user_list = db::name('user')->field('uid,base64_nick_name,head_pic')->where($map)->select(); $user_data = []; foreach ($user_list as $k => $v) { $user_data[$v['uid']]['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8'); $user_data[$v['uid']]['head_pic'] = localpath_to_netpath($v['head_pic']); $user_data[$v['uid']]['uid'] = $v['uid']; } foreach ($list as $k => &$v) { $v['send_user_info'] = $user_data[$v['receive_uid']]; } return ['code' => 200, 'msg' => '获取成功', 'data' => $list]; } public function get_send_gift_list($uid, $gift_from_type, $receive_uid, $page, $page_limit) { $map = []; $map[] = ['uid', '=', $uid]; if (!empty($gift_from_type)) { $map[] = ['gift_from_type', '=', $gift_from_type]; } if (!empty($receive_uid)) { $map[] = ['receive_uid', '=', $receive_uid]; } $list = db::name('user_send_gift')->field('gid,gift_name,gift_price,gift_num,gift_total_price')->where($map)->page($page, $page_limit)->select(); $gift_data = db::name('gift')->cache(10)->column('base_image', 'gid'); foreach ($list as $k => &$v) { $v['base_image'] = localpath_to_netpath($gift_data[$v['gid']]); } return ['code' => 200, 'msg' => '获取成功', 'data' => $list]; } public function get_receive_gift_user_list($uid, $gift_from_type, $page, $page_limit) { $map = []; $map[] = ['receive_uid', '=', $uid]; if (!empty($gift_from_type)) { $map[] = ['gift_from_type', '=', $gift_from_type]; } $list = db::name('user_send_gift')->field('uid,receive_uid,sum(gift_total_price) as total_send_amount,max(add_time) as last_send_time')->where($map)->group('uid')->page($page, $page_limit)->order('add_time desc')->select(); $map = []; $map[] = ['uid', 'in', array_column($list, 'uid')]; $user_list = db::name('user')->field('uid,base64_nick_name,head_pic')->where($map)->select(); $user_data = []; foreach ($user_list as $k => $v) { $user_data[$v['uid']]['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8'); $user_data[$v['uid']]['head_pic'] = localpath_to_netpath($v['head_pic']); $user_data[$v['uid']]['uid'] = $v['uid']; } foreach ($list as $k => &$v) { $v['send_user_info'] = $user_data[$v['uid']]; } return ['code' => 200, 'msg' => '获取成功', 'data' => $list]; } public function get_receive_gift_list($receive_uid, $gift_from_type, $uid, $page, $page_limit) { $map = []; $map[] = ['uid', '=', $uid]; $map[] = ['receive_uid', '=', $receive_uid]; if (!empty($gift_from_type)) { $map[] = ['gift_from_type', '=', $gift_from_type]; } $list = db::name('user_send_gift')->field('gid,gift_name,gift_price,gift_num,gift_total_price,add_time')->where($map)->page($page, $page_limit)->select(); $gift_data = db::name('gift')->cache(10)->column('base_image', 'gid'); foreach ($list as $k => &$v) { $v['base_image'] = localpath_to_netpath($gift_data[$v['gid']]); } return ['code' => 200, 'msg' => '获取成功', 'data' => $list]; } public function get_user_level_info($uid) { $charm_level_info = $this->get_user_charm_level_info($uid); $contribution_level_info = $this->get_user_contribution_info($uid); $nobility_info = $this->get_user_nobility_info($uid); $data = []; $data['charm_level_info'] = $charm_level_info['data']; $data['contribution_level_info'] = $contribution_level_info['data']; $data['nobility_info'] = $nobility_info['data']; return ['code' => 200, 'msg' => '获取成功', 'data' => $data]; } //用户爵位信息 public function get_user_nobility_info($uid){ $user_info = db::name('user')->field('nobility_id')->find($uid); $nobility_id = $user_info['nobility_id']; $nobility_image = ''; if(!empty($user_info['nobility_id'])){ $nobility_info = db::name('nobility')->find($nobility_id); $nobility_image = localpath_to_netpath($nobility_info['image']); } $data = []; $data['nobility_id'] = $nobility_id; $data['nobility_image'] = $nobility_image; return ['code' => 200, 'msg' => '获取成功', 'data' => $data]; } //获取用户等级魅力值详情 public function get_user_charm_level_info($uid) { $user_info = db::name('user')->field('charm_value,charm_level')->find($uid); $map = []; $map[] = ['type', '=', 1]; $map[] = ['is_delete', '=', 1]; $user_level_list = db::name('user_level')->cache(600)->where($map)->order('level asc')->select(); $rest_value = $user_info['charm_value']; $next_value = 0; $now_level_image = ""; $next_level_image = ""; $next_level = $user_info['charm_level']; foreach ($user_level_list as $k => $v) { if ($v['level'] == $user_info['charm_level']) { $now_level_image = $v['image']; } $rest_values = $rest_value; $rest_value = $rest_value - $v['number']; //下一等级初始化 $next_value = $v['level']; $next_level_image = $v['image']; if ($rest_value < 0) { $rest_values = $rest_values; $next_value = $v['number']; $next_level_image = $v['image']; $next_level = $v['level']; break; } } $data = []; $data['now_level'] = $user_info['charm_level']; // $data['now_value'] = $user_info['charm_value'] * 1; $data['now_value'] = $rest_values; $data['now_level_image'] = localpath_to_netpath($now_level_image); $data['next_level'] = $next_level; $data['next_level_image'] = localpath_to_netpath($next_level_image); $data['next_value'] = $next_value; return ['code' => 200, 'msg' => '获取成功', 'data' => $data]; } //获取用户头像框详情 public function get_user_avatar_info($uid) { $data = []; //获取用户头像框 $map = []; $map[] = ['a.is_using', '=', 1]; $map[] = ['a.uid', '=', $uid]; $map[] = ['a.end_time', '>', time()]; $map[] = ['a.type', '=', 1]; $map[] = ['b.show_status', '=', 1]; $map[] = ['b.is_delete', '=', 1]; $model = Db::name('user_decorate')->alias('a')->join('yy_decorate b', 'a.did = b.did'); $user_decorate_info = $model->field('b.base_image,b.play_image,b.title,a.uid')->where($map)->find(); $data['avatar_play_image'] = ''; if (!empty($user_decorate_info)) { $data['avatar_play_image'] = localpath_to_netpath($user_decorate_info['play_image']); } //翅膀装扮 $map = []; $map[] = ['a.is_using', '=', 1]; $map[] = ['a.uid', '=', $uid]; $map[] = ['a.end_time', '>', time()]; $map[] = ['a.type', '=', 1]; $map[] = ['b.show_status', '=', 1]; $map[] = ['b.is_delete', '=', 1]; $model = Db::name('user_decorate')->alias('a')->join('yy_decorate b', 'a.did = b.did'); $user_decorate_info = $model->field('b.base_image,b.play_image,b.title,a.uid')->where($map)->find(); $data['win_base_image'] = ''; $data['win_play_image'] = ''; if (!empty($user_decorate_info)) { $data['win_base_image'] = localpath_to_netpath($user_decorate_info['base_image']); $data['win_play_image'] = localpath_to_netpath($user_decorate_info['play_image']); } return ['code' => 200, 'msg' => '获取成功', 'data' => $data]; } //获取用户魅力等级、财富值等级详情 public function get_user_charm_contribution_info($user_info) { $user_info = db::name('user')->field('charm_level,contribution_level')->find($user_info); //获取用户财富值、魅力值等级 $map = []; $map[] = ['is_delete', '=', 1]; $user_level_list = db::name('user_level')->cache(600)->where($map)->order('level asc')->select(); $data = []; $data['charm_level_image'] = ''; $data['contribution_level_image'] = ''; foreach ($user_level_list as $k => $v) { if ($v['type'] == 1 && $user_info['charm_level'] == $v['level']) { $data['charm_level_image'] = localpath_to_netpath($v['image']); } elseif ($v['type'] == 2 && $user_info['contribution_level'] == $v['level']) { $data['contribution_level_image'] = localpath_to_netpath($v['image']); } } return ['code' => 200, 'msg' => '获取成功', 'data' => $data]; } //获取用户贡献值详情 public function get_user_contribution_info($uid) { $user_info = db::name('user')->field('contribution_value,contribution_level')->find($uid); $map = []; $map[] = ['type', '=', 2]; $map[] = ['is_delete', '=', 1]; $user_level_list = db::name('user_level')->cache(600)->where($map)->order('level asc')->select(); $rest_value = $user_info['contribution_value']; $next_value = 0; $now_level_image = ""; $next_level_image = ""; $next_level = $user_info['contribution_level']; foreach ($user_level_list as $k => $v) { if ($v['level'] == $user_info['contribution_level']) { $now_level_image = $v['image']; } $rest_values = $rest_value; $rest_value = $rest_value - $v['number']; //下一等级初始化 $next_value = $v['level']; $next_level_image = $v['image']; if ($rest_value < 0) { $rest_values = $rest_values; $next_value = $v['number']; $next_level_image = $v['image']; $next_level = $v['level']; break; } } $data = []; $data['now_level'] = $user_info['contribution_level']; // $data['now_value'] = $user_info['contribution_value'] * 1; $data['now_value'] = $rest_values; $data['now_level_image'] = localpath_to_netpath($now_level_image); $data['next_level'] = $next_level; $data['next_level_image'] = localpath_to_netpath($next_level_image); $data['next_value'] = $next_value; return ['code' => 200, 'msg' => '获取成功', 'data' => $data]; } public function get_user_follow_list($uid, $page, $page_limit) { $page = intval($page); $page_limit = $page_limit < 30 ? $page_limit : 30; $map = []; $map[] = ['a.uid', '=', $uid]; $model = Db::name('user_follow')->alias('a')->join('yy_user b', 'a.follow_uid = b.uid'); $model = $model->where($map); $list = $model->field('a.fid,a.follow_uid,b.uid,b.base64_nick_name,b.head_pic,b.uid,b.sex,b.special_uid,b.is_online')->order('a.fid desc')->page($page, $page_limit)->select(); foreach ($list as $k => &$v) { $v['head_pic'] = localpath_to_netpath($v['head_pic']); $v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8'); $v['is_follow'] = 2; $is_follow = db::name('user_follow')->where(['uid' => $v['follow_uid'], 'follow_uid' => $uid])->find(); if ($is_follow) { $v['is_follow'] = 1; } } return ['code' => 200, 'msg' => '获取成功', 'data' => $list]; } public function get_user_fans_list($uid, $page, $page_limit) { $page = intval($page); $page_limit = $page_limit < 30 ? $page_limit : 30; $map = []; $map[] = ['a.follow_uid', '=', $uid]; $model = Db::name('user_follow')->alias('a')->join('yy_user b', 'a.uid = b.uid'); $model = $model->where($map); $list = $model->field('a.fid,a.uid as fuid,a.follow_uid,b.uid,b.base64_nick_name,b.head_pic,b.uid,b.sex,b.special_uid,b.is_online')->order('a.fid desc')->page($page, $page_limit)->select(); foreach ($list as $k => &$v) { $v['head_pic'] = localpath_to_netpath($v['head_pic']); $v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8'); $v['is_follow'] = 2; $is_follow = db::name('user_follow')->where(['uid' => $uid, 'follow_uid' => $v['fuid']])->find(); if ($is_follow) { $v['is_follow'] = 1; } } return ['code' => 200, 'msg' => '获取成功', 'data' => $list]; } //获取我的邀请人 public function get_user_child_list($uid, $page, $page_limit) { $page = intval($page); $page_limit = $page_limit < 30 ? $page_limit : 30; $map = []; $map[] = ['pid', '=', $uid]; $list = Db::name('user')->where($map)->field('uid,pid,nick_name,base64_nick_name,head_pic,sex,special_uid,add_time')->order('uid desc')->page($page, $page_limit)->select(); foreach ($list as $k => &$v) { $v['head_pic'] = localpath_to_netpath($v['head_pic']); $v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8'); $v['add_time'] = date('Y-m-d H:i:s', $v['add_time']); $where = []; $where[] = ['uid', '=', $uid]; $where[] = ['change_type', '=', 22]; $where[] = ['from_uid', '=', $v['uid']]; $v['give_earnings'] = db::name('user_money_log')->where($where)->sum('change_value'); } //用户总收益 $user_earnings = db::name('user_money_log')->where('uid', $uid)->where('change_type', 22)->sum('change_value'); $data = []; $data['list'] = $list; $data['user_total_earnings'] = $user_earnings; return ['code' => 200, 'msg' => '获取成功', 'data' => $data]; } //关注用户 public function follow_user($uid, $follow_uid) { $user_info = db::name('user')->find($follow_uid); if (empty($user_info)) { return ['code' => 201, 'msg' => '关注用户不存在', 'data' => null]; } if ($uid == $follow_uid) { return ['code' => 201, 'msg' => '不能关注自己', 'data' => null]; } $map = []; $map[] = ['uid', '=', $uid]; $map[] = ['follow_uid', '=', $follow_uid]; $info = db::name('user_follow')->where($map)->find(); if (!empty($info)) { return ['code' => 200, 'msg' => '关注成功', 'data' => null]; } $data = []; $data['uid'] = $uid; $data['follow_uid'] = $follow_uid; $data['add_time'] = time(); $data['update_time'] = time(); $reslut = db::name('user_follow')->insert($data); if ($reslut) { db::name('user')->where(['uid' => $uid])->setInc('follow_num'); db::name('user')->where(['uid' => $follow_uid])->setInc('fans_num'); return ['code' => 200, 'msg' => '关注成功', 'data' => null]; } else { return ['code' => 201, 'msg' => '关注失败', 'data' => null]; } } //取消关注 public function unfollow_user($uid, $follow_uid) { $user_info = db::name('user')->find($follow_uid); if (empty($user_info)) { return ['code' => 201, 'msg' => '关注用户不存在', 'data' => null]; } $map = []; $map[] = ['uid', '=', $uid]; $map[] = ['follow_uid', '=', $follow_uid]; $info = db::name('user_follow')->where($map)->find(); if (empty($info)) { return ['code' => 200, 'msg' => '取关成功', 'data' => null]; } $reslut = db::name('user_follow')->delete($info['fid']); if ($reslut) { db::name('user')->where(['uid' => $uid])->setDec('follow_num'); db::name('user')->where(['uid' => $follow_uid])->setDec('fans_num'); return ['code' => 200, 'msg' => '取注成功', 'data' => null]; } else { return ['code' => 201, 'msg' => '取注失败', 'data' => null]; } } public function modify_user_info($uid, $nick_name, $birthday, $sex, $head_pic, $city, $autograph, $hobby) { $text = $nick_name . $autograph . $hobby; if(!empty($text)) { $result = model('Tencent')->content_moderation('Text', $text); if($result['code'] != 200) { return ['code' => 201, 'msg' => '昵称或签名或爱好有违禁词!', 'data' => null]; } } $data = []; $data['uid'] = $uid; if (!empty($nick_name)) { $nick_name = htmlspecialchars_decode($nick_name); $data['nick_name'] = $nick_name; $data['base64_nick_name'] = base64_encode($nick_name); $nick_name_info = db::name('user')->where('base64_nick_name', $data['base64_nick_name'])->find(); if(!empty($nick_name_info)){ if($uid != $nick_name_info['uid']){ return['code' => 201, 'msg' => '该昵称已被占用', 'data' => null]; } } if(mb_strlen($nick_name) > 15){ return['code' => 201, 'msg' => '昵称长度不能超过15个字符', 'data' => null]; } } if (!empty($birthday)) { $data['birthday'] = $birthday; $constellation = $this->get_user_constellation($birthday); $data['constellation'] = $constellation['data']; } if (!empty($head_pic)) { // $data['head_pic'] = $param['path']; $filepath_url = get_filepath_url(); $params = parse_url($filepath_url); $param = parse_url($head_pic); if(isset($param['host'])) { if (!empty($param['path'])) { if($params['host'] == $param['host']) { $head_pic = $param['path']; $head_pic = trim($head_pic, '/'); } $data['head_pic'] = $head_pic; } } else { $data['head_pic'] = $head_pic; } } if (!empty($city)) { $data['city'] = $city; } if (!empty($autograph)) { $data['autograph'] = $autograph; } if(!empty($hobby)){ $data['hobby'] = $hobby; } $validate = validate('admin/User'); $reslut = $validate->scene('apiEditInfo')->check($data); if ($reslut !== true) { return ['code' => 201, 'msg' => $validate->getError(), 'data' => null]; } $data['sex'] = $sex; $data['update_time'] = time(); // $reslut = model('admin/user')->save($data); $reslut = db::name('user')->update($data); if ($reslut) { $user_info = db::name('user')->field('uid,user_name,base64_nick_name,head_pic,sex,birthday,special_uid,money,frozen_money,integral,room_profit,is_real,follow_num,fans_num,autograph,hobby,country,province,city,constellation')->find($uid); $user_info['nick_name'] = mb_convert_encoding(base64_decode($user_info['base64_nick_name']), 'UTF-8', 'UTF-8'); $user_info['head_pic'] = localpath_to_netpath($user_info['head_pic']); return ['code' => 200, 'msg' => '修改成功', 'data' => $user_info]; } else { return ['code' => 201, 'msg' => '修改失败', 'data' => null]; } } public function modify_password($mobile, $password) { $uid = db::name('user')->where(['user_name' => $mobile])->value('uid'); $data = []; $data['uid'] = $uid; $data['password'] = $password; $validate = validate('admin/User'); $reslut = $validate->scene('apiEditPassword')->check($data); if ($reslut !== true) { return ['code' => 201, 'msg' => $validate->getError(), 'data' => null]; } // $reslut = model('admin/user')->save($data); $reslut = db::name('user')->where(['uid' => $uid])->update(['password' => md5($password)]); //撸号修改密码 $user_lu_pwd = db::name('user_lu_pwd')->where(['uid'=>$uid])->find(); if(!empty($user_lu_pwd)){ db::name('user_lu_pwd')->where(['uid'=>$uid])->update(['pwd'=>$password]); } if ($reslut) { return ['code' => 200, 'msg' => '修改成功', 'data' => null]; } else { return ['code' => 201, 'msg' => '修改失败', 'data' => null]; } } public function modify_trade_password($uid, $trade_password) { $data = []; $data['uid'] = $uid; $data['trade_password'] = $trade_password; $validate = validate('admin/User'); $reslut = $validate->scene('apiEditTradePassword')->check($data); if ($reslut !== true) { return ['code' => 201, 'msg' => $validate->getError(), 'data' => null]; } // $reslut = model('admin/user')->save($data); $data['trade_password'] = md5($trade_password); $reslut = $reslut = db::name('user')->update($data); if ($reslut) { return ['code' => 200, 'msg' => '修改成功', 'data' => null]; } else { return ['code' => 201, 'msg' => '修改失败', 'data' => null]; } } //修改用户打赏价值/等级 // public function change_user_contribution_value($uid, $change_value) // { // $user_info = db::name('user')->field('uid,contribution_value')->find($uid); // $map = []; // $map[] = ['type', '=', 2]; // $map[] = ['is_delete', '=', 1]; // $user_level_list = db::name('user_level')->where($map)->order('level asc')->select(); // $rest_value = $user_info['contribution_value'] + $change_value; // $now_level = 0; // foreach ($user_level_list as $k => $v) { // $rest_value = $rest_value - $v['number']; // if ($rest_value < 0) { // break; // } // $now_level = $v['level']; // } // $map = []; // $map[] = ['uid', '=', $uid]; // $data = []; // $data['contribution_value'] = Db::raw('contribution_value+' . $change_value); // $data['contribution_level'] = $now_level; // $data['update_time'] = time(); // $reslut = db::name('user')->where($map)->update($data); // if ($reslut) { // return ['code' => 200, 'msg' => '修改成功', 'data' => null]; // } else { // return ['code' => 201, 'msg' => '修改失败', 'data' => null]; // } // } //修改用户打赏价值/等级 public function change_user_contribution_value($uid, $change_value) { $user_info = db::name('user')->field('uid,contribution_value,sex,contribution_level')->find($uid); $change_value = $change_value * 10; $map = []; $map[] = ['type', '=', 2]; $map[] = ['is_delete', '=', 1]; $user_level_list = db::name('user_level')->where($map)->order('level asc')->select(); $rest_value = $user_info['contribution_value'] + $change_value; $now_level = 0; foreach ($user_level_list as $k => $v) { $rest_value = $rest_value - $v['number']; if ($rest_value < 0) { // if ($rest_value < $v['number']) { break; } $now_level = $v['level']; } $level_difference = $now_level - $user_info['contribution_level']; $now_levels = $now_level+1; $contribution_level = $user_info['contribution_level']+1; Db::startTrans(); try { //该等级是否获得新装扮 if($level_difference > 0){ // dump(1111); for($i = $contribution_level; $i < $now_levels; $i++){ $map = []; $map[] = ['type', '=', 2]; $map[] = ['is_delete', '=', 1]; $map[] = ['level', '=', $i]; $user_level_info = db::name('user_level')->where($map)->find(); if(!empty($user_level_info['head_decorate_id'])){//head_decorate_id //该装扮是否存在 $map = []; $map[] = ['is_delete', '=', 1]; $map[] = ['did', '=', $user_level_info['head_decorate_id']]; $decorate = db::name('decorate')->where($map)->find(); // dump($decorate); if($decorate){ //添加到用户装扮 $map = []; $map[] = ['uid', '=', $uid]; $map[] = ['did', '=', $user_level_info['head_decorate_id']]; $user_decorate = db::name('user_decorate')->where($map)->find(); if(!$user_decorate){ $add_date = []; $add_date['uid'] = $uid; $add_date['type'] = 1; $add_date['did'] = $user_level_info['head_decorate_id']; $time = 720 * 60 * 60 * 24; $add_date['end_time'] = time() + $time; $add_date['add_time'] = time(); $reslut = db::name('user_decorate')->insert($add_date); if(!$reslut){ Db::rollback(); return ['code' => 201, 'msg' => "获取失败", 'data' => null]; } } } } if(!empty($user_level_info['mount_decorate_id'])){ //该进场特效是否存在 $map = []; $map[] = ['is_delete', '=', 1]; $map[] = ['did', '=', $user_level_info['mount_decorate_id']]; $decorate = db::name('decorate')->where($map)->find(); if($decorate){ //添加到用户装扮 $map = []; $map[] = ['uid', '=', $uid]; $map[] = ['did', '=', $user_level_info['mount_decorate_id']]; $user_decorate = db::name('user_decorate')->where($map)->find(); if(!$user_decorate){ $add_date = []; $add_date['uid'] = $uid; $add_date['type'] = 3; $add_date['did'] = $user_level_info['mount_decorate_id']; $time = 720 * 60 * 60 * 24; $add_date['end_time'] = time() + $time; $add_date['add_time'] = time(); $reslut = db::name('user_decorate')->insert($add_date); if(!$reslut){ Db::rollback(); return ['code' => 201, 'msg' => "获取失败", 'data' => null]; } } } } //判断用户性别 // if($user_info['sex'] == 1){ // if(!empty($user_level_info['head_decorate_id'])){//head_decorate_id // //该装扮是否存在 // $map = []; // $map[] = ['is_delete', '=', 1]; // $map[] = ['did', '=', $user_level_info['man_head_decorate_id']]; // $decorate = db::name('decorate')->where($map)->find(); // // dump($decorate); // if($decorate){ // //添加到用户装扮 // $map = []; // $map[] = ['uid', '=', $uid]; // $map[] = ['did', '=', $user_level_info['man_head_decorate_id']]; // $user_decorate = db::name('user_decorate')->where($map)->find(); // if(!$user_decorate){ // $add_date = []; // $add_date['uid'] = $uid; // $add_date['type'] = 1; // $add_date['did'] = $user_level_info['man_head_decorate_id']; // $time = 720 * 60 * 60 * 24; // $add_date['end_time'] = time() + $time; // $add_date['add_time'] = time(); // $reslut = db::name('user_decorate')->insert($add_date); // if(!$reslut){ // Db::rollback(); // return ['code' => 201, 'msg' => "获取失败", 'data' => null]; // } // } // } // } // if(!empty($user_level_info['man_mount_decorate_id'])){ // //该进场特效是否存在 // $map = []; // $map[] = ['is_delete', '=', 1]; // $map[] = ['did', '=', $user_level_info['man_mount_decorate_id']]; // $decorate = db::name('decorate')->where($map)->find(); // if($decorate){ // //添加到用户装扮 // $map = []; // $map[] = ['uid', '=', $uid]; // $map[] = ['did', '=', $user_level_info['man_mount_decorate_id']]; // $user_decorate = db::name('user_decorate')->where($map)->find(); // if(!$user_decorate){ // $add_date = []; // $add_date['uid'] = $uid; // $add_date['type'] = 3; // $add_date['did'] = $user_level_info['man_mount_decorate_id']; // $time = 720 * 60 * 60 * 24; // $add_date['end_time'] = time() + $time; // $add_date['add_time'] = time(); // $reslut = db::name('user_decorate')->insert($add_date); // if(!$reslut){ // Db::rollback(); // return ['code' => 201, 'msg' => "获取失败", 'data' => null]; // } // } // } // } // }else{ // if(!empty($user_level_info['woman_head_decorate_id'])){//head_decorate_id // //该装扮是否存在 // $map = []; // $map[] = ['is_delete', '=', 1]; // $map[] = ['did', '=', $user_level_info['woman_head_decorate_id']]; // $decorate = db::name('decorate')->where($map)->find(); // // dump($decorate); // if($decorate){ // //添加到用户装扮 // $map = []; // $map[] = ['uid', '=', $uid]; // $map[] = ['did', '=', $user_level_info['woman_head_decorate_id']]; // $user_decorate = db::name('user_decorate')->where($map)->find(); // if(!$user_decorate){ // $add_date = []; // $add_date['uid'] = $uid; // $add_date['type'] = 1; // $add_date['did'] = $user_level_info['woman_head_decorate_id']; // $time = 720 * 60 * 60 * 24; // $add_date['end_time'] = time() + $time; // $add_date['add_time'] = time(); // $reslut = db::name('user_decorate')->insert($add_date); // if(!$reslut){ // Db::rollback(); // return ['code' => 201, 'msg' => "获取失败", 'data' => null]; // } // } // } // } // if(!empty($user_level_info['woman_mount_decorate_id'])){ // //该进场特效是否存在 // $map = []; // $map[] = ['is_delete', '=', 1]; // $map[] = ['did', '=', $user_level_info['woman_mount_decorate_id']]; // $decorate = db::name('decorate')->where($map)->find(); // if($decorate){ // //添加到用户装扮 // $map = []; // $map[] = ['uid', '=', $uid]; // $map[] = ['did', '=', $user_level_info['woman_mount_decorate_id']]; // $user_decorate = db::name('user_decorate')->where($map)->find(); // if(!$user_decorate){ // $add_date = []; // $add_date['uid'] = $uid; // $add_date['type'] = 3; // $add_date['did'] = $user_level_info['woman_mount_decorate_id']; // $time = 720 * 60 * 60 * 24; // $add_date['end_time'] = time() + $time; // $add_date['add_time'] = time(); // $reslut = db::name('user_decorate')->insert($add_date); // if(!$reslut){ // Db::rollback(); // return ['code' => 201, 'msg' => "获取失败", 'data' => null]; // } // } // } // } // } } } $map = []; $map[] = ['uid', '=', $uid]; $data = []; $data['contribution_value'] = Db::raw('contribution_value+' . $change_value); $data['contribution_level'] = $now_level; $data['update_time'] = time(); $reslut = db::name('user')->where($map)->update($data); if (!$reslut) { return ['code' => 201, 'msg' => '修改失败', 'data' => null]; } Db::commit(); return ['code' => 200, 'msg' => "修改成功", 'data' => null]; } catch (\Exception $e) { //回滚事务 Db::rollback(); return ['code' => 201, 'msg' => "修改失败", 'data' => null]; } // $map = []; // $map[] = ['uid', '=', $uid]; // $data = []; // $data['contribution_value'] = Db::raw('contribution_value+' . $change_value); // $data['contribution_level'] = $now_level; // $data['update_time'] = time(); // $reslut = db::name('user')->where($map)->update($data); // if ($reslut) { // return ['code' => 200, 'msg' => '修改成功', 'data' => null]; // } else { // return ['code' => 201, 'msg' => '修改失败', 'data' => null]; // } } //修改用户房间魅力值 public function change_user_room_charm_value($uid, $rid, $change_value, $user_id) { $change_value = $change_value * 10; $map = []; $map[] = ['uid', '=', $uid]; $map[] = ['rid', '=', $rid]; $data = []; $data['update_time'] = time(); $info = db::name('room_user_cc')->where($map)->find(); Db::startTrans(); try { if($info){ $cid = $info['cid']; $reslut = db::name('room_user_cc')->where('cid', $cid)->inc('charm_value', $change_value)->inc('total_charm_value', $change_value)->update($data); if (!$reslut) { Db::rollback(); return ['code' => 201, 'msg' => "失败", 'data' => null]; } }else{ $data = []; $data['uid'] = $uid; $data['rid'] = $rid; $data['charm_value'] = $change_value; $data['total_charm_value'] = $change_value; $data['uid'] = $uid; $data['add_time'] = time(); $data['update_time'] = time(); $cid = db::name('room_user_cc')->insertGetId($data); if (!$cid) { Db::rollback(); return ['code' => 201, 'msg' => "失败", 'data' => null]; } } //增加用户明细 $charm_log = db::name('room_user_micro_charm_log')->where('uid', $user_id)->where('cid', $cid)->find(); if($charm_log){ $reslut = db::name('room_user_micro_charm_log')->where('id', $charm_log['id'])->inc('change_value', $change_value)->update(['update_time' => time()]); }else{ $insert = []; $insert['uid'] = $user_id; $insert['cid'] = $cid; $insert['change_value'] = $change_value; $insert['add_time'] = time(); $reslut = db::name('room_user_micro_charm_log')->insert($insert); } if(!$reslut){ Db::rollback(); return ['code' => 201, 'msg' => "失败", 'data' => null]; } Db::commit(); return ['code' => 200, 'msg' => "成功", 'data' => null]; } catch (\Exception $e) { dump($e); //回滚事务 Db::rollback(); return ['code' => 201, 'msg' => "失败", 'data' => null]; } } //修改用户房间财富值 public function change_user_room_contribution_value($uid, $rid, $change_value) { $change_value = $change_value * 10; $map = []; $map[] = ['uid', '=', $uid]; $map[] = ['rid', '=', $rid]; $data = []; $data['update_time'] = time(); $reslut = db::name('room_user_cc')->where($map)->inc('contribution_value', $change_value)->inc('total_contribution_value', $change_value)->update($data); if (!$reslut) { $data = []; $data['uid'] = $uid; $data['rid'] = $rid; $data['contribution_value'] = $change_value; $data['total_contribution_value'] = $change_value; $data['uid'] = $uid; $data['add_time'] = time(); $data['update_time'] = time(); db::name('room_user_cc')->insert($data); } return ['code' => 200, 'msg' => '修改成功', 'data' => null]; } //修改用户打赏价值/等级 public function change_user_charm_value($uid, $change_value) { $change_value = $change_value * 10; $user_info = db::name('user')->field('uid,charm_value')->find($uid); $map = []; $map[] = ['type', '=', 1]; $map[] = ['is_delete', '=', 1]; $user_level_list = db::name('user_level')->where($map)->order('level asc')->select(); $rest_value = $user_info['charm_value'] + $change_value; $now_level = 0; foreach ($user_level_list as $k => $v) { $rest_value = $rest_value - $v['number']; if ($rest_value < 0) { break; } $now_level = $v['level']; } $map = []; $map[] = ['uid', '=', $uid]; $data = []; $data['charm_value'] = Db::raw('charm_value+' . $change_value); $data['charm_level'] = $now_level; $data['update_time'] = time(); $reslut = db::name('user')->where($map)->update($data); if ($reslut) { return ['code' => 200, 'msg' => '修改成功', 'data' => null]; } else { return ['code' => 201, 'msg' => '修改失败', 'data' => null]; } } //增加厅主房间收益记录 public function change_user_room_profit($uid, $rid, $change_value) { $change_value = $change_value * 10; $map = []; $map[] = ['uid', '=', $uid]; $map[] = ['rid', '=', $rid]; $data = []; $data['update_time'] = time(); $reslut = db::name('room_user_cc')->where($map)->inc('room_profit', $change_value)->update($data); if (!$reslut) { $data = []; $data['uid'] = $uid; $data['rid'] = $rid; $data['room_profit'] = $change_value; $data['add_time'] = time(); $data['update_time'] = time(); db::name('room_user_cc')->insert($data); } return ['code' => 200, 'msg' => '修改成功', 'data' => null]; } //兑换查询 public function exchange_check($money) { $config = model('admin/Config')->get_system_config(); $exchange_rate = $config['exchange_rate']; $data['money'] = ($money * $exchange_rate); return ['code' => 200, 'msg' => '查询成功', 'data' => $data]; } //用户转赠 public function user_give_integral($uid, $reveive_uid, $integral, $last_login_device) { if ($integral < 1 || intval($integral) != $integral) { return ['code' => 201, 'msg' => '转赠数量必须为正整数', 'data' => null]; } if($uid == $reveive_uid){ return ['code' => 201, 'msg' => '无法转赠给自己', 'data' => null]; } $user_info = db::name('user')->find($uid); if($user_info['is_teenager'] == 1){ return ['code' => 201, 'msg' => '已开启青少年模式', 'data' => null]; } if($user_info['is_can_recharge'] != 1){ return ['code' => 201, 'msg' => '您当前未有转赠权限', 'data' => null]; } $ress = model('api/UserWallet')->get_user_wallet($uid, $user_info['money'], $user_info['integral']); if($ress['code'] != 200) { return $ress; } $map = []; $map[] = ['uid','=',$uid]; $map[] = ['change_type', '=', 17]; $map[] = ['add_time', '>', time()-5]; $time_lag = db::name('user_money_log')->where($map)->order('log_id desc')->find(); if($time_lag){ return ['code' => 201, 'msg' => '转赠间隔不能少于5秒', 'data' => null]; } Db::startTrans(); try { //扣除积分 $reslut = model('admin/User')->change_user_money_by_uid($uid, -$integral, 2, 17, "转赠扣除", $reveive_uid, 0); if ($reslut['code'] != 200) { Db::rollback(); return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null]; } //增加积分 $reslut = model('admin/User')->change_user_money_by_uid($reveive_uid, $integral, 2, 17, "转赠增加", $uid, 0); if ($reslut['code'] != 200) { Db::rollback(); return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null]; } //发送消息开始 $message_data = [ 'from_uid' => $uid, 'to_uid' => $reveive_uid, 'integral' => $integral, ]; model('api/AsyncPushMessage')->store_message($message_data, 1); //发送消息结束 // 提交事务 Db::commit(); return ['code' => 200, 'msg' => "转赠成功", 'data' => null]; } catch (\Exception $e) { // 回滚事务 Db::rollback(); return ['code' => 201, 'msg' => "转赠失败", 'data' => null]; } } //用户转赠列表查询 public function get_user_give_integral_list($uid,$page,$page_limit){ $page = intval($page); $page_limit = $page_limit < 30 ? $page_limit : 30; $ChangeTypeLable = model('admin/UserMoneyLog')->ChangeTypeLable(); $map = []; $map[] = ['uid', '=', $uid]; $map[] = ['money_type', '=', 2]; $map[]=['change_type','=',17];//用户转赠 $list = db::name('user_money_log')->field('change_type,change_value,remarks,from_uid,add_time')->where($map)->order('log_id desc')->page($page, $page_limit)->select(); $map=[]; $map[] = ['uid', 'in', array_column($list, 'from_uid')]; $user_data = db::name('user')->field('uid,base64_nick_name,head_pic')->where($map)->column('uid,base64_nick_name,head_pic','uid'); foreach ($user_data as $a => &$b) { $b['nick_name'] = mb_convert_encoding(base64_decode($b['base64_nick_name']), 'UTF-8', 'UTF-8'); $b['head_pic'] = localpath_to_netpath($b['head_pic']); } foreach ($list as $k => &$v) { $v['change_type_desc'] = $ChangeTypeLable[$v['change_type']]; $v['from_user_info']=$user_data[$v['from_uid']]; } return ['code' => 200, 'msg' => '获取成功', 'data' => $list]; } // 兑换 public function exchange($uid, $money) { $user_info = db::name('user')->find($uid); if($user_info['is_teenager'] == 1){ return ['code' => 201, 'msg' => '已开启青少年模式', 'data' => null]; } $exchange_rate = get_system_config('exchange_rate'); if ($money < 1) { return ['code' => 201, 'msg' => '兑换余额必须大于1', 'data' => null]; } if (floor($money) != $money) { return ['code' => 201, 'msg' => '兑换余额必须为整数', 'data' => null]; } $ress = model('api/UserWallet')->get_user_wallet($uid, $user_info['money'], $user_info['integral']); if($ress['code'] != 200) { return $ress; } Db::startTrans(); try { //扣除余额记录 $change_money = $money; $reslut = model('admin/User')->change_user_money_by_uid($uid, -$change_money, 1, 11, "金币兑换扣除余额", $uid, $uid); if ($reslut['code'] != 200) { Db::rollback(); return ['code' => 201, 'msg' => '余额不足', 'data' => null]; } //增加金币 $change_integral = $money * $exchange_rate; $reslut = model('admin/User')->change_user_money_by_uid($uid, $change_integral, 2, 12, "余额兑换增加金币", $uid, $uid); if ($reslut['code'] != 200) { Db::rollback(); return ['code' => 201, 'msg' => '余额不足', 'data' => null]; } $arr = []; $arr['uid'] = $uid; $arr['money'] = $change_money; $arr['integral'] = $change_integral; $arr['add_time'] = time(); $arr['update_time'] = time(); $reslut = DB::name('user_exchange')->insert($arr); if (!$reslut) { Db::rollback(); return ['code' => 201, 'msg' => '兑换失败', 'data' => null]; } Db::commit(); return ['code' => 200, 'msg' => '兑换成功', 'data' => null]; } catch (\Exception $e) { // 回滚事务 Db::rollback(); } } // 提现 public function user_withdrawal($uid, $money, $type) { // if($money < 30){ // return ['code' => 201, 'msg' => '提现金额不能小于0', 'data' => null]; // } $user_info = Db::name('user')->find($uid); if($user_info['is_teenager'] == 1){ return ['code' => 201, 'msg' => '已开启青少年模式', 'data' => null]; } $ress = model('api/UserWallet')->get_user_wallet($uid, $user_info['money'], $user_info['integral']); if($ress['code'] != 200) { return $ress; } if($user_info['is_real'] != 1){ return ['code' => 201, 'msg' => '请先实名认证', 'data' => null]; } $real_name = $user_info['real_name']; $id_card = $user_info['card_id']; $result = SignContract::getSignStatus($real_name, $id_card); if(!(isset($result[2]['status']) && ($result[2]['status']==1))){ return ['code' => 201, 'msg' => '您尚未签约!', 'data' => null]; } $age = getAgeId($user_info['card_id']); if(!$age){ return ['code' => 201, 'msg' => '该身份证号未满18岁', 'data' => null]; } if($type == 1){ if (empty($user_info['alipay_account'])) { return ['code' => 201, 'msg' => '请先绑定支付宝', 'data' => null]; } if(trim($user_info['alipay_name']) != trim($real_name)){ return ['code' => 201, 'msg' => '认证(签约)姓名和支付宝姓名不一致!', 'data' => null]; } }else if($type == 2){ if (empty($user_info['bank_card_number'])) { return ['code' => 201, 'msg' => '请先绑定银行卡', 'data' => null]; } //银行卡姓名 和 真实姓名 if(trim($user_info['bank_user_name']) != trim($real_name)){ return ['code' => 201, 'msg' => '认证(签约)姓名和银行卡姓名不一致!', 'data' => null]; } } $config = model('admin/Config')->get_system_config(); if ($money < $config['min_withdraw_amount']) { return ['code' => 201, 'msg' => '提现金额不能小于' . $config['min_withdraw_amount'], 'data' => null]; } //一天最多提现次数 $today_withdraw_num = get_system_config('today_withdraw_num'); $user_withdraw_num = db::name('user_withdrawal')->where('uid', $uid)->whereTime('add_time', 'today')->count(); if($user_withdraw_num >= $today_withdraw_num){ return ['code' => 201, 'msg' => '用户当天提现次数已达上限', 'data' => null]; } // $map = []; // $map[] = ['uid', '=', $uid]; // $map[] = ['status', '=', 2]; // $user_player_info = Db::name('user_player')->where($map)->find(); // if (empty($user_player_info)) { // return ['code' => 201, 'msg' => '请先通过陪玩资质认证,即可提现']; // } // $map = []; // $map[] = ['uid', '=', $uid]; // $map[] = ['add_time', '>', (time() - 46200)]; // $user_withdraw_info = Db::name('user_withdrawal')->where($map)->find(); // if (!empty($user_withdraw_info)) { // return ['code' => 201, 'msg' => '12小时内只能提现一次', 'data' => null]; // } // $withdraw_week = get_system_config('withdraw_week'); // $withdraw_week = explode(',', $withdraw_week); // if (!in_array(date('w'), $withdraw_week)) { // $weekarray = ["日", "一", "二", "三", "四", "五", "六"]; // $msg = "请于"; // foreach ($withdraw_week as $k => $v) { // $msg .= "周" . $weekarray[$v]; // } // $msg .= "进行提现"; // return ['code' => 201, 'msg' => $msg, 'data' => null]; // } if ($money > $user_info['money']) { return ['code' => 201, 'msg' => '余额不足', 'data' => null]; } Db::startTrans(); try { $order_sn = $this->create_user_withdrawal_order_sn(); $data = []; $data['order_sn'] = $order_sn; $data['uid'] = $uid; $data['money'] = $money; $data['general_money'] = $money * (1 - $config['user_withdraw_rate']); //到账金额 $data['type'] = $type; if($type == 1){ $data['real_name'] = $user_info['alipay_name']; $data['alipay_account'] = $user_info['alipay_account']; }else if($type == 2){ $data['real_name'] = $user_info['bank_user_name']; $data['bank_card'] = $user_info['bank_card']; $data['open_bank'] = $user_info['open_bank']; $data['bank_card_number'] = $user_info['bank_card_number']; } $data['remarke'] = ''; $data['status'] = 1; $data['deal_time'] = 0; $data['add_time'] = time(); $data['update_time'] = time(); $data['new_type'] = 2; $user_withdrawal_wid = DB::name('user_withdrawal')->insertGetId($data); if (!$user_withdrawal_wid) { Db::rollback(); return ['code' => 201, 'msg' => "请重试", 'data' => null]; } //扣除账户余额 $reslut = model('admin/User')->change_user_money_by_uid($uid, -$money, 1, 13, "余额提现:" . $order_sn, $uid, $user_withdrawal_wid); if ($reslut['code'] != 200) { Db::rollback(); return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null]; } //增加冻结余额 $reslut = Db::name('user')->where('uid', $user_info['uid'])->setInc('frozen_money', $money); if (!$reslut) { Db::rollback(); return ['code' => 201, 'msg' => "请重试", 'data' => null]; } //修改提现余额 $surplus_money_money = Db::name('user')->where('uid', $user_info['uid'])->value('money'); DB::name('user_withdrawal')->where(['wid'=>$user_withdrawal_wid])->update(['surplus_money'=>$surplus_money_money]); // 提交事务 Db::commit(); return ['code' => 200, 'msg' => "提现成功", 'data' => null]; } catch (\Exception $e) { // 回滚事务 Db::rollback(); return ['code' => 201, 'msg' => "提现失败", 'data' => null]; } } /** * 银行卡提现 * @param $uid * @param $money * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function user_withdrawal_bank($uid, $money){ return ['code' => 201, 'msg' => '请升级app!', 'data' => null]; if(!preg_match("/^[1-9][0-9]*$/" ,$money) || $money <= 30){ return ['code' => 201, 'msg' => '提现金额至少30元!', 'data' => null]; } // $w_num = db::name('user_withdrawal')->whereTime('add_time', 'today')->where([['uid','=',$uid],['status','in',[1,2]]])->count('*'); // if($w_num > 3){ // return ['code' => 201, 'msg' => '每天最多提现3笔!', 'data' => null]; // } // return ['code' => 201, 'msg' => '提现维护中,马上回来!', 'data' => null]; $user_info = Db::name('user')->find($uid); if($user_info['is_teenager'] == 1){ return ['code' => 201, 'msg' => '已开启青少年模式', 'data' => null]; } if($user_info['is_real'] != 1){ return ['code' => 201, 'msg' => '请先实名认证', 'data' => null]; } $age = getAgeId($user_info['card_id']); if(!$age){ return ['code' => 201, 'msg' => '该身份证号未满18岁', 'data' => null]; } if (empty($user_info['is_bind_bank_card']) || ($user_info['is_bind_bank_card']==2) || empty($user_info['bank_card_number'])) { return ['code' => 201, 'msg' => '请先绑定银行卡!', 'data' => null]; } $config = model('admin/Config')->get_system_config(); // if ($money < $config['min_withdraw_amount']) { // return ['code' => 201, 'msg' => '提现金额不能小于' . $config['min_withdraw_amount'], 'data' => null]; // } $reslut = model('HuiFu')->check_member_card($uid); if($reslut['code'] != 200){ return ['code' => 201, 'msg' =>$reslut['msg'] , 'data' => null]; } if ($money > $user_info['money']) { return ['code' => 201, 'msg' => '余额不足', 'data' => null]; } $map = []; $map[] = ['uid', '=', $uid]; $map[] = ['add_time', '>', (time() - 46200)]; // $user_withdraw_info = Db::name('user_withdrawal')->where($map)->find(); $user_withdraw_num = Db::name('user_withdrawal')->where($map)->count("*"); if($user_withdraw_num > 3){ return ['code' => 201, 'msg' => '12小时内最多可提现3次', 'data' => null]; } // if (!empty($user_withdraw_info)) { // return ['code' => 201, 'msg' => '12小时内只能提现一次', 'data' => null]; // } if($money>10000){ return ['code' => 201, 'msg' => '最大提现金额不能超过10000元', 'data' => null]; } Db::startTrans(); try { $order_sn = $this->create_user_withdrawal_order_sn(); $data = []; $data['order_sn'] = $order_sn; $data['uid'] = $uid; $data['money'] = $money; $data['general_money'] = $money * (1 - $config['bank_user_withdraw_rate']); //到账金额 // $data['real_name'] = $user_info['alipay_name']; // $data['alipay_account'] = $user_info['alipay_account']; $data['bank_card_name'] = $user_info['bank_card_name']; $data['bank_card_number'] = $user_info['bank_card_number']; $data['bank_user_name'] = $user_info['bank_user_name']; $data['bank_cert_id'] = $user_info['bank_cert_id']; $data['bank_tel_no'] = $user_info['bank_tel_no']; $data['withd_type'] = 2; //银行卡提现 $data['type'] = 2; //银行卡提现 $data['remarke'] = ''; $data['status'] = 1; $data['deal_time'] = 0; $data['add_time'] = time(); $data['update_time'] = time(); $user_withdrawal_wid = DB::name('user_withdrawal')->insertGetId($data); if (!$user_withdrawal_wid) { Db::rollback(); return ['code' => 201, 'msg' => "请重试", 'data' => null]; } //扣除账户余额 $reslut = model('admin/User')->change_user_money_by_uid($uid, -$money, 1, 13, "余额提现:" . $order_sn, $uid, $user_withdrawal_wid); if ($reslut['code'] != 200) { Db::rollback(); return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null]; } //增加冻结余额 $reslut = Db::name('user')->where('uid', $user_info['uid'])->setInc('frozen_money', $money); if (!$reslut) { Db::rollback(); return ['code' => 201, 'msg' => "请重试", 'data' => null]; } // 提交事务 Db::commit(); return ['code' => 200, 'msg' => "提现成功", 'data' => null]; } catch (\Exception $e) { // 回滚事务 Db::rollback(); // halt($e); return ['code' => 201, 'msg' => "提现失败", 'data' => null]; } } public function binding_zfb($uid, $alipay_name, $alipay_account) { if (empty($alipay_name)) { return ['code' => 201, 'msg' => '真实姓名必须', 'data' => null]; } if (empty($alipay_account)) { return ['code' => 201, 'msg' => '支付宝账号必须', 'data' => null]; } $user_info = db::name('user')->find($uid); if (!empty($user_info['alipay_name']) || !empty($user_info['alipay_account'])) { // return ['code' => 201, 'msg' => '您已绑定支付宝信息', 'data' => null]; } //该支付宝是否已被绑定 $where = []; $where[] = ['alipay_account', '=', $alipay_account]; $where[] = ['uid', 'neq', $uid]; $user_alipay_account = db::name('user')->where($where)->count(); if($user_alipay_account > 2){ return ['code' => 201, 'msg' => '该支付宝已被绑定3个账号 不能再次绑定', 'data' => null]; } $map = []; $map[] = ['uid', '=', $uid]; //调用第三方实名认证接口 $data = []; $data['alipay_name'] = $alipay_name; $data['alipay_account'] = $alipay_account; $data['update_time'] = time(); $reslut = Db::name('user')->where($map)->update($data); if ($reslut) { return ['code' => 200, 'msg' => '绑定成功', 'data' => null]; } else { return ['code' => 201, 'msg' => '绑定失败', 'data' => null]; } } public function binding_bank_card($uid, $bank_user_name, $bank_card, $open_bank, $bank_card_number) { if (empty($bank_user_name)) { return ['code' => 201, 'msg' => '真实姓名必须', 'data' => null]; } if (empty($bank_card_number)) { return ['code' => 201, 'msg' => '银行卡号必须', 'data' => null]; } if (empty($bank_card)) { return ['code' => 201, 'msg' => '所属银行必须', 'data' => null]; } if (empty($open_bank)) { return ['code' => 201, 'msg' => '开户行必须', 'data' => null]; } $user_info = db::name('user')->find($uid); if (!empty($user_info['bank_user_name']) || !empty($user_info['bank_card_number'])) { // return ['code' => 201, 'msg' => '您已绑定银行卡信息', 'data' => null]; } $map = []; $map[] = ['uid', '=', $uid]; //调用第三方实名认证接口 $data = []; $data['bank_user_name'] = $bank_user_name; $data['bank_card_number'] = $bank_card_number; $data['bank_card'] = $bank_card; $data['open_bank'] = $open_bank; $data['update_time'] = time(); $reslut = Db::name('user')->where($map)->update($data); if ($reslut) { return ['code' => 200, 'msg' => '绑定成功', 'data' => null]; } else { return ['code' => 201, 'msg' => '绑定失败', 'data' => null]; } } /** * 绑定银行卡 * @param $bank_card_number //银行卡号 * @param $bank_user_name //银行卡姓名 * @param $bank_cert_id //银行卡对应身份证号 * @param $bank_tel_no //银行卡电话 * @param $bank_card_name //银行卡名字 * @return array * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ // public function binding_bank_card($uid,$bank_card_number, $bank_user_name, $bank_cert_id, $bank_tel_no,$bank_card_name) // { // if(empty($bank_card_name)){ // return ['code' => 201, 'msg' => '请填写银行卡所属银行!', 'data' => null]; // } // if (empty($bank_card_number)) { // return ['code' => 201, 'msg' => '请填写银行卡卡号!', 'data' => null]; // } // if (empty($bank_user_name)) { // return ['code' => 201, 'msg' => '请填写银行卡所属真实姓名!', 'data' => null]; // } // if (empty($bank_cert_id)) { // return ['code' => 201, 'msg' => '请填写银行卡身份证号', 'data' => null]; // } // if (empty($bank_tel_no)) { // return ['code' => 201, 'msg' => '请填写银行卡绑定手机号', 'data' => null]; // } // $user_info = db::name('user')->find($uid); // if(empty($user_info)){ // return ['code' => 201, 'msg' => '被绑定对象不存在!', 'data' => null]; // } // //进行换绑流程 // if($user_info['is_bind_bank_card']==1 && !empty($user_info['bind_bank_card_id'])){ // if(!(($user_info['bank_card_number']==$bank_card_number) && ($user_info['bank_tel_no'] == $bank_tel_no))){ // //进行换绑 // $result = $this->change_bank_card($uid,$bank_card_number, $bank_user_name, $bank_cert_id, $bank_tel_no,$bank_card_name); // return $result; // }else{ // return ['code' => 201, 'msg' => '您已经绑定过银行卡了!', 'data' => null]; // } // } // // if (!empty($user_info['bank_card_number']) && !empty($user_info['bank_cert_id'])) { // // // return ['code' => 201, 'msg' => '您已绑定银行卡信息', 'data' => null]; // // } // $data = []; // //1:创建支付对象[创建过的对象 不需要重复创建] // if($user_info['is_bank_member_create'] == 2){ // // $memberBankCreate = new MemberCreate(); // // $createMemberResult = $memberBankCreate->create($user_info['uid'],$bank_user_name); // $createMemberResult = model('HuiFu')->member_create($user_info['uid'],$bank_user_name); // if($createMemberResult['status'] != 'succeeded'){ // return ['code' => 201, 'msg' => $createMemberResult['error_msg'], 'data' => null]; // } // //支付对象已经产生 // Db::name('user')->where(['uid'=>$uid])->update(['is_bank_member_create'=>1,'update_time'=>time()]); // } // //2:绑定银行卡[还未绑定银行卡] // if(empty($user_info['bind_bank_card_id'])){ // $accountInfo = [ // 'card_id'=>$bank_card_number, //银行卡卡号 // 'card_name'=>$bank_user_name, //银行卡姓名 // 'cert_id' =>$bank_cert_id, //银行卡身份证号 // 'tel_no' => $bank_tel_no, //银行卡手机号 // ]; // // $bindCard = new BindCard(); // // $bindCardResult = $bindCard->bind_card($user_info['uid'],$accountInfo); // $bindCardResult = model('HuiFu')->bind_card($user_info['uid'],$accountInfo); // if($bindCardResult['status'] !='succeeded'){ // return ['code' => 201, 'msg' => $bindCardResult['error_msg'], 'data' => null]; // } // //生成结算对象id // if(empty($bindCardResult['id'])){ // return ['code' => 201, 'msg' => '获取不到银行卡创建id!', 'data' => null]; // } // $data['bind_bank_card_id'] = $bindCardResult['id']; // } // $data['bank_card_name'] = $bank_card_name; // $data['bank_card_number'] = $bank_card_number; // $data['bank_user_name'] = $bank_user_name; // $data['bank_cert_id'] = $bank_cert_id; // $data['bank_tel_no'] = $bank_tel_no; // $data['update_time'] = time(); // $data['is_bank_member_create'] = 1; // $data['is_bind_bank_card'] = 1; // $map = []; // $map[] = ['uid', '=', $uid]; // $reslut = Db::name('user')->where($map)->update($data); // if ($reslut) { // return ['code' => 200, 'msg' => '绑定成功', 'data' => null]; // } else { // return ['code' => 201, 'msg' => '绑定失败', 'data' => null]; // } // } /** * 换绑银行卡 * @param $uid * @param $bank_card_number * @param $bank_user_name * @param $bank_cert_id * @param $bank_tel_no * @param $bank_card_name */ // public function change_bank_card($uid,$bank_card_number, $bank_user_name, $bank_cert_id, $bank_tel_no,$bank_card_name){ // //1:删除原有绑定的银行卡 // $user_info = db::name('user')->find($uid); // // $deleteCard = new DeleteCard(); // // $result = $deleteCard->delete_card($uid,$user_info['bind_bank_card_id']); // $result = model('HuiFu')->delete_card($uid,$user_info['bind_bank_card_id']); // if($result['status'] !== 'succeeded'){ // return ['code' => 200, 'msg' => $result['error_msg'], 'data' => null]; // }else{ // //1:清除原先绑定的银行卡信息 // $data['bank_card_name'] = ''; // $data['bank_card_number'] = ''; // $data['bank_user_name'] = ''; // $data['bank_cert_id'] = ''; // $data['bank_tel_no'] = ''; // $data['update_time'] = time(); // $data['bind_bank_card_id'] = ''; //清除绑定对象id // $data['is_bind_bank_card'] = 2; //未绑定银行卡 // $map = []; // $map[] = ['uid', '=', $uid]; // $reslut = Db::name('user')->where($map)->update($data); // } // //2:在度创建银行对象 // $data = []; // $accountInfo = [ // 'card_id'=>$bank_card_number, //银行卡卡号 // 'card_name'=>$bank_user_name, //银行卡姓名 // 'cert_id' =>$bank_cert_id, //银行卡身份证号 // 'tel_no' => $bank_tel_no, //银行卡手机号 // ]; // // $bindCard = new BindCard(); // // $bindCardResult = $bindCard->bind_card($user_info['uid'],$accountInfo); // $bindCardResult = model('HuiFu')->bind_card($user_info['uid'],$accountInfo); // if($bindCardResult['status'] !='succeeded'){ // return ['code' => 201, 'msg' => $bindCardResult['error_msg'], 'data' => null]; // } // //生成结算对象id // if(empty($bindCardResult['id'])){ // return ['code' => 201, 'msg' => '获取不到银行卡创建id!', 'data' => null]; // } // $data['bind_bank_card_id'] = $bindCardResult['id']; // //3:修改数据库信息 // $data['bank_card_name'] = $bank_card_name; // $data['bank_card_number'] = $bank_card_number; // $data['bank_user_name'] = $bank_user_name; // $data['bank_cert_id'] = $bank_cert_id; // $data['bank_tel_no'] = $bank_tel_no; // $data['update_time'] = time(); // $data['is_bank_member_create'] = 1; // $data['is_bind_bank_card'] = 1; // $map = []; // $map[] = ['uid', '=', $uid]; // $reslut = Db::name('user')->where($map)->update($data); // if ($reslut) { // return ['code' => 200, 'msg' => '绑定成功', 'data' => null]; // } else { // return ['code' => 201, 'msg' => '绑定失败', 'data' => null]; // } // } //生成订单号 private function create_user_withdrawal_order_sn() { $order_sn = 'TX' . date('YmdHis') . mt_rand(10000, 99999); $map = []; $map[] = ['order_sn', '=', $order_sn]; $reslut = db::name('user_withdrawal')->where($map)->find(); if (empty($reslut)) { return $order_sn; } else { $this->create_user_withdrawal_order_sn(); } } public function get_user_withdrawal_info($uid) { $config = get_uncache_system_config(); $user_info = DB::name('user')->field(['alipay_name', 'alipay_account', 'integral', 'money','bank_user_name', 'bank_card', 'open_bank','is_bind_bank_card','bank_card_name','bank_card_number','bank_user_name','bank_cert_id','bank_tel_no'])->find($uid); // dump($user);die; $user_info['is_bingd_alipay'] = 1; //已绑定 if (empty($user_info['alipay_name']) || empty($user_info['alipay_name'])) { $user_info['is_bingd_alipay']; //未绑定 } $user_info['withdraw_rate'] = round((1 - $config['user_withdraw_rate']),2); $user_info['user_withdraw_rate'] = $config['user_withdraw_rate']; return ['code' => 200, 'msg' => '获取成功', 'data' => $user_info]; } // 提现记录 public function get_user_withdrawal_list($uid, $page, $page_limit) { $page = intval($page); $page_limit = $page_limit < 30 ? $page_limit : 30; $list = Db::name('user_withdrawal')->field('order_sn, money,general_money,real_name,alipay_account,bank_card_number,bank_card,open_bank,remarke,status,add_time')->where('uid', $uid)->order('wid', 'desc')->page($page, $page_limit)->select(); foreach ($list as $key => &$v) { if ($v['status'] == 1) { $v['status_desc'] = '审核中'; } elseif ($v['status'] == 2) { $v['status_desc'] = '已提现'; } elseif ($v['status'] == 3) { $v['status_desc'] = '已拒绝' . ':' . $v['remarke']; } } return ['code' => 200, 'msg' => '获取成功', 'data' => $list]; } // 兑换记录 public function exchange_log($uid, $page, $page_limit) { $page = intval($page); $page_limit = $page_limit < 10 ? $page_limit : 10; $data = DB::name('user_exchange')->where('uid', $uid)->order('eid', 'desc')->page($page, $page_limit)->select(); foreach ($data as $key => &$v) { $v['add_time'] = date('Y-m-d H:i:s', $v['add_time']); } return ['code' => 200, 'msg' => '查询成功', 'data' => $data]; } //上传用户相册 public function add_user_albums($uid, $image) { $image_list = explode(',', $image); $insert_data = []; foreach ($image_list as $k => $v) { if (!empty($v)) { $data = []; $data['uid'] = $uid; $data['image'] = $v; $data['add_time'] = time(); $data['update_time'] = time(); $insert_data[] = $data; } else { return ['code' => 201, 'msg' => '图片格式错误', 'data' => null]; } } if (!empty($insert_data)) { $reslut = db::name('user_albums')->insertAll($insert_data); if (!$reslut) { return ['code' => 201, 'msg' => '添加失败', 'data' => null]; } else { return ['code' => 200, 'msg' => '添加成功', 'data' => null]; } } } //上传用户相册 public function delete_user_albums($uid, $aid) { $map = []; $map[] = ['aid', '=', $aid]; $map[] = ['uid', '=', $uid]; $data = []; $data['is_delete'] = 2; $data['delete_time'] = time(); $data['update_time'] = time(); $reslut = db::name('user_albums')->where($map)->update($data); if (!$reslut) { return ['code' => 201, 'msg' => '移除失败', 'data' => null]; } else { return ['code' => 200, 'msg' => '移除成功', 'data' => null]; } } //获取星座 public function get_user_constellation($birthday) { $birthday = date('Y-m-d', strtotime($birthday)); if (empty($birthday)) { return ['code' => 201, 'msg' => '生日日期格式非法', 'data' => null]; } $birthday_arr = explode('-', $birthday); $month = $birthday_arr[1]; $day = $birthday_arr[2]; $xingzuo = ''; // 检查参数有效性 if ($month < 1 || $month > 12 || $day < 1 || $day > 31) { return $xingzuo; } if (($month == 1 && $day >= 20) || ($month == 2 && $day <= 18)) { $xingzuo = "水瓶座"; } else if (($month == 2 && $day >= 19) || ($month == 3 && $day <= 20)) { $xingzuo = "双鱼座"; } else if (($month == 3 && $day >= 21) || ($month == 4 && $day <= 19)) { $xingzuo = "白羊座"; } else if (($month == 4 && $day >= 20) || ($month == 5 && $day <= 20)) { $xingzuo = "金牛座"; } else if (($month == 5 && $day >= 21) || ($month == 6 && $day <= 21)) { $xingzuo = "双子座"; } else if (($month == 6 && $day >= 22) || ($month == 7 && $day <= 22)) { $xingzuo = "巨蟹座"; } else if (($month == 7 && $day >= 23) || ($month == 8 && $day <= 22)) { $xingzuo = "狮子座"; } else if (($month == 8 && $day >= 23) || ($month == 9 && $day <= 22)) { $xingzuo = "处女座"; } else if (($month == 9 && $day >= 23) || ($month == 10 && $day <= 23)) { $xingzuo = "天秤座"; } else if (($month == 10 && $day >= 24) || ($month == 11 && $day <= 22)) { $xingzuo = "天蝎座"; } else if (($month == 11 && $day >= 23) || ($month == 12 && $day <= 21)) { $xingzuo = "射手座"; } else if (($month == 12 && $day >= 22) || ($month == 1 && $day <= 19)) { $xingzuo = "摩羯座"; } return ['code' => 200, 'msg' => '获取成功', 'data' => $xingzuo]; } //退出登录 public function log_out($uid){ $user_info = db::name('user')->find($uid); if($user_info){ $map = []; $map[] = ['uid', '=', $uid]; $data = []; $data['login_token'] = ''; db::name('user')->where($map)->update($data); } return ['code' => 200, 'msg' => '退出成功', 'data' => null]; } //注销账号 public function logout_user_name($uid){ $user_info = db::name('user')->find($uid); if(!$user_info){ return ['code' => 201, 'msg' => '参数错误', 'data' => null]; } if($user_info['is_teenager'] == 1){ return ['code' => 201, 'msg' => '青少年模式已开启', 'data' => null]; } //注册时间是否超过七天 $reg_time = $user_info['add_time'] + (60*60*24*7); $now_time = time(); if($now_time < $reg_time){ return ['code' => 201, 'msg' => '注册七天内无法注销', 'data' => null]; } //背包里是否还有礼物 $map = []; $map[] = ['uid', '=', $uid]; $map[] = ['is_tester', '=', 1]; $map[] = ['num', '>', 0]; $user_gift_pack = db::name('user_gift_pack')->where($map)->select(); if(!empty($user_gift_pack)){ return ['code' => 201, 'msg' => '背包中尚且有礼物无法注销', 'data' => null]; } if($user_info['money'] >= 100 || $user_info['integral'] >= 100){ return ['code' => 201, 'msg' => '当前用户金币或者钻石大于100,无法注销', 'data' => null]; } Db::startTrans(); try { $update = []; $update['login_status'] = 3; $update['is_online'] = 2; $update['user_name'] = $user_info['user_name'].'zx'.time(); if(!empty($user_info['alipay_name'])){ $update['alipay_name'] = $user_info['alipay_name'].'zx'.time(); } if(!empty($user_info['alipay_account'])){ $update['alipay_account'] = $user_info['alipay_account'].'zx'.time(); } //身份证号注销 if(!empty($user_info['card_id'])){ $update['card_id'] = $user_info['card_id'].'zx'; } // $update['wx_openid'] = $user_info['wx_openid'].'zx'.$user_info['uid']; // $update['qq_openid'] = $user_info['qq_openid'].'zx'.$user_info['uid']; $update['login_token'] = ''; $update['update_time'] = time(); $reslut = db::name('user')->where('uid', $uid)->update($update); if(!$reslut){ Db::rollback(); return ['code' => 201, 'msg' => '注销失败', 'data' => null]; } //用户是否已有所在房间 $user_room_visitor = db::name('room_visitor')->where('uid', $uid)->find(); if($user_room_visitor){ model('api/room')->quit_room($uid, $user_room_visitor['rid']);//踢出房间 } Db::commit(); $push_user_data = []; $push_user_data['uid'] = $uid; //推送信息 $push_data = []; $push_data['code'] = 311; $push_data['msg'] = "账号注销"; $push_data['data'] = $push_user_data; model('api/WebSocketPush')->send_to_one($uid, $push_data); return ['code' => 200, 'msg' => '注销成功', 'data' => null]; } catch (\Exception $e) { // 回滚事务 dump($e); Db::rollback(); return ['code' => 201, 'msg' => '注销失败', 'data' => null]; } } //是否进厅隐身 public function user_is_room_hiding($uid, $is_room_hiding){ $user_info = db::name('user')->find($uid); if(!$user_info){ return ['code' => 201, 'msg' => '参数错误', 'data' => null]; } if($user_info['nobility_id'] < 6){ return ['code' => 201, 'msg' => '需要国王爵位', 'data' => null]; } $data = []; $data['is_room_hiding'] = $is_room_hiding; $update = []; $update['is_room_hiding'] = $is_room_hiding; $update['update_time'] = time(); $reslut = db::name('user')->where('uid', $uid)->update($update); if ($reslut) { return ['code' => 200, 'msg' => '成功', 'data' => $data]; } else { return ['code' => 201, 'msg' => '失败', 'data' => null]; } } //位置信息开关 public function options_is_open_address($uid, $is_open_address){ $user_info = db::name('user')->find($uid); if(!$user_info){ return ['code' => 201, 'msg' => '参数错误', 'data' => null]; } $data = []; $data['is_open_address'] = $is_open_address; $update = []; $update['is_open_address'] = $is_open_address; $update['update_time'] = time(); $reslut = db::name('user')->where('uid', $uid)->update($update); if ($reslut) { return ['code' => 200, 'msg' => '成功', 'data' => $data]; } else { return ['code' => 201, 'msg' => '失败', 'data' => null]; } } public function check_user_is_real($uid) { $is_real = Db::name('user')->where('uid', $uid)->value('is_real'); $data['is_real'] = empty($is_real) ? 2 : $is_real; return ['code' => 200, 'msg' => '已实名', 'data' => $data]; } //客服信息 public function get_kf_message(){ $data = db::name('support_staff')->field("id,image,content,contents")->order('id','asc')->select(); foreach($data as &$v){ $v['image'] = localpath_to_netpath($v['image']); } return ['code' => 200, 'msg' => 'success', 'data' => $data]; } //用户提现方式 public function get_user_withdrawal_detail($uid,$start="",$end="",$page,$page_limit){ $where = []; $where[] = ['uw.uid','=',$uid]; //提现数据大于 9月26号 $where[] = ['uw.add_time','>=',1727280000]; if(!empty($start)){ $start = strtotime($start. " 00:00"); $where[] = ['uw.add_time','>=',$start]; } if(!empty($end)){ $end = strtotime($end . " 23:59:59"); $where[] = ['uw.add_time','<=',$end]; } $user_withdraw_detail = db::name('user_withdrawal') ->alias('uw') ->field('uw.wid,uw.type,uw.general_money,uw.money,uw.surplus_money,uw.withd_type,uw.status,deal_type,add_time') ->where($where) ->order(['wid'=>'desc']) ->page($page,$page_limit) ->select(); foreach ($user_withdraw_detail as &$v){ //线下提现 if($v['deal_type'] == 2){ // if(in_array($v['status'],[4,5])){ // $v['status'] = 1; // }elseif($v['status'] == 6){ // $v['status'] = 2; // } if(in_array($v['status'],[4,5,6])){ $v['status'] = 2; } } } $with_money = db::name('user_withdrawal') ->alias('uw') ->where($where) // ->whereRaw("(uw.deal_type=1 and uw.status=2) or (uw.deal_type=2 and uw.status=6)") ->whereRaw("uw.status in (2,4,5,6)") ->sum('general_money'); return ['code' => 200, 'msg' => 'success', 'data' => ['detail'=>$user_withdraw_detail,'all'=>$with_money]]; } //用户提现方式 public function get_one_withdrawal_detail($uid,$wid){ $with_info = db::name('user_withdrawal') ->alias('uw') ->field('uw.wid,uw.type,uw.general_money,uw.money,uw.surplus_money,server_money,uw.withd_type,uw.status,deal_type,add_time,remarke,alipay_account,bank_card_number,deal_type') ->where(['uid'=>$uid,'wid'=>$wid]) ->find(); if(empty($with_info)){ return ['code' => 201, 'msg' => '提现不存在!', 'data' => null]; } if($with_info['type'] == 1){ $with_info['account'] = $with_info['alipay_account']; } if($with_info['type'] == 2){ $with_info['account'] = $with_info['bank_card_number']; } if($with_info['deal_type'] == 2){ if(in_array($with_info['status'],[4,5,6])){ $with_info['status'] = 2; } } $with_info['server_money'] = del_coin_num($with_info['money'] - $with_info['general_money'],2); unset($with_info['alipay_account'],$with_info['bank_card_number'],$with_info['deal_type']); return ['code' => 200, 'msg' => 'success', 'data' => $with_info]; } }