276 lines
9.8 KiB
PHP
276 lines
9.8 KiB
PHP
<?php
|
||
namespace app\agent\controller;
|
||
use \think\Controller;
|
||
use think\Lang;
|
||
use \think\Session;
|
||
use \think\Request;
|
||
use \think\Db;
|
||
class Online Extends Common{
|
||
public function index(){
|
||
$langType = cookie('think_var');
|
||
$lang = Lang::get('agent');
|
||
$jsonlang = json_encode($lang);
|
||
|
||
$this->assign('langType',$langType);
|
||
$this->assign('lang',$lang);
|
||
$this->assign('jsonlang',$jsonlang);
|
||
// 登录用户信息
|
||
$user_info = Session::get('user_info');
|
||
$account_type = $user_info['account_type'];
|
||
$user_info = Db::connect('DB2')->name('user')->where('id',$user_info['id'])->find();
|
||
$user_info['account_type'] = $account_type;
|
||
// 搜索条件
|
||
$where = array();
|
||
$client = trim(Request::instance()->get('client'));
|
||
$username = trim(Request::instance()->get('username'));
|
||
if($username){
|
||
$searchUser = Db::connect('DB2')->name('user')->where('username',$username)->find();
|
||
$searchUserParentIds = explode(',',$searchUser['agent_parent_id_path']);
|
||
if( in_array($user_info['id'],$searchUserParentIds) && $user_info['id'] > $searchUser['id']){
|
||
$where['user_id'] = $searchUser['id'];
|
||
}
|
||
}
|
||
if($client > 0){
|
||
$where['user_id'] = $client;
|
||
}
|
||
|
||
// 查找所有在线的登录的玩家,检测30分钟内是否有操作
|
||
$session_user = Db::connect('DB2')->name('session')->where($where)->select();
|
||
$user_online = array();
|
||
foreach($session_user as $v){
|
||
$time = time() - config('session_life_time');
|
||
if($v['last_time'] < $time){
|
||
// 30分钟内没操作,移除在线在在线玩家的列表
|
||
Db::name('session')->where('user_id',$v['user_id'])->delete();
|
||
}else{
|
||
// 30分钟内有操作的玩家,并且是该代理下面的直属玩家
|
||
$user = Db::connect('DB2')->name('user')->where(['id'=>$v['user_id']])->find();
|
||
$agentParentIds = explode(',',$user['agent_parent_id_path']);
|
||
if(in_array($user_info['id'],$agentParentIds) && $user_info['id'] < $user['id']){
|
||
$user['table_id'] = $v['table_id'];
|
||
$user['client'] = $v['client'];
|
||
if($user['last_login_time'] > 0){
|
||
$user['last_login_time'] = date('Y-m-d H:i:s',$user['last_login_time']);
|
||
}
|
||
$user_online[] = $user;
|
||
}
|
||
}
|
||
}
|
||
|
||
// 汇总
|
||
$totalData = array();
|
||
$totalData['count'] = count($user_online);
|
||
$totalData['amount'] = 0;
|
||
$totalData['pc'] = 0;
|
||
$totalData['ios'] = 0;
|
||
$totalData['android'] = 0;
|
||
$totalData['wap'] = 0;
|
||
$totalData['wx'] = 0;
|
||
|
||
// 获取在线用户的数据及统计下注总额
|
||
$where = array();
|
||
$where['result'] = 0;
|
||
$IPs = array();
|
||
foreach($user_online as $k => $v){
|
||
$where['user_id'] = $v['id'];
|
||
$v['is_beat'] = 0;
|
||
// 总押
|
||
$v['amount'] = Db::connect('DB2')->name('bet')->where($where)->sum('amount');
|
||
$v['money'] = number_format($v['money'],2,".","");
|
||
// 游戏
|
||
if($v['amount'] > 0){
|
||
$v['game_id'] = Db::connect('DB2')->name('bet')->where($where)->order('create_time DESC')->value('game_id');
|
||
}else{
|
||
$v['game_id'] = '';
|
||
}
|
||
// 桌子名称
|
||
$bets = Db::connect('DB2')->name('bet')->where($where)->order('create_time DESC')->select();
|
||
$v['table_name'] = '';
|
||
if($bets){
|
||
$tableIdArr = array();
|
||
foreach($bets as $b){
|
||
if(!in_array($b['table_id'],$tableIdArr)){
|
||
$table_id = $b['table_id'];
|
||
$v['table_name'] .= Db::connect('DB2')->name('table')->where('id',$table_id)->value('table_name').',';
|
||
$tableIdArr[] = $table_id;
|
||
}
|
||
}
|
||
}
|
||
$v['table_name'] = substr($v['table_name'],0,-1);
|
||
// 客户端
|
||
if($v['client'] == 1){
|
||
$v['client'] = $lang['pc'];
|
||
$totalData['pc'] += 1;
|
||
}else if($v['client'] == 2){
|
||
$v['client'] = $lang['ios'];
|
||
$totalData['ios'] += 1;
|
||
}else if($v['client'] == 3){
|
||
$v['client'] = $lang['android'];
|
||
$totalData['android'] += 1;
|
||
}else if($v['client'] == 4){
|
||
$v['client'] = $lang['web'];
|
||
$totalData['wap'] += 1;
|
||
}else if($v['client'] == 5){
|
||
$v['client'] = $lang['wc'];
|
||
$totalData['wx'] += 1;
|
||
}else{
|
||
$v['client'] = $lang['unknown
|
||
'];
|
||
}
|
||
$user_online[$k] = $v;
|
||
|
||
// 汇总数据
|
||
$totalData['amount'] += $v['amount'];
|
||
}
|
||
// 渲染参数和模板
|
||
$this->assign('user_online',$user_online);
|
||
$this->assign('totalData',$totalData);
|
||
return $this->fetch();
|
||
}
|
||
|
||
// 在线人数自动刷新
|
||
public function autoRefresh(){
|
||
$langType = cookie('think_var');
|
||
$lang = Lang::get('agent');
|
||
if(Request::instance()->post()){
|
||
// 登录用户信息
|
||
$user_info = Session::get('user_info');
|
||
$account_type = $user_info['account_type'];
|
||
$user_info = Db::connect('DB2')->name('user')->where('id',$user_info['id'])->find();
|
||
$user_info['account_type'] = $account_type;
|
||
// 搜索条件
|
||
$where = array();
|
||
$client = trim(Request::instance()->post('client'));
|
||
$username = trim(Request::instance()->post('username'));
|
||
if($username){
|
||
$searchUser = Db::connect('DB2')->name('user')->where('username',$username)->find();
|
||
$searchUserParentIds = explode(',',$searchUser['agent_parent_id_path']);
|
||
if(in_array($user_info['id'],$searchUserParentIds) && $user_info['id'] > $searchUser['id']){
|
||
$where['user_id'] = $searchUser['id'];
|
||
}
|
||
}
|
||
if($client > 0){
|
||
$where['user_id'] = $client;
|
||
}
|
||
|
||
// 查找所有在线的登录的玩家,检测30分钟内是否有操作
|
||
$session_user = Db::connect('DB2')->name('session')->where($where)->select();
|
||
$user_online = array();
|
||
foreach($session_user as $v){
|
||
$time = time() - config('session_life_time');
|
||
if($v['last_time'] < $time){
|
||
//30分钟内没操作,移除在线在在线玩家的列表
|
||
Db::name('session')->where('user_id',$v['user_id'])->delete();
|
||
}else{
|
||
//30分钟内有操作的玩家,并且是该代理下面的直属玩家
|
||
$user = Db::connect('DB2')->name('user')->where(['id'=>$v['user_id']])->find();
|
||
$agentParentIds = explode(',',$user['agent_parent_id_path']);
|
||
if(in_array($user_info['id'],$agentParentIds) && $user_info['id'] < $user['id']){
|
||
$user['table_id'] = $v['table_id'];
|
||
$user['client'] = $v['client'];
|
||
if($user['last_login_time'] > 0){
|
||
$user['last_login_time'] = date('Y-m-d H:i:s');
|
||
}
|
||
$user_online[] = $user;
|
||
}
|
||
}
|
||
}
|
||
|
||
// 汇总
|
||
$totalData = array();
|
||
$totalData['count'] = count($user_online);
|
||
$totalData['amount'] = 0;
|
||
$totalData['pc'] = 0;
|
||
$totalData['ios'] = 0;
|
||
$totalData['android'] = 0;
|
||
$totalData['wap'] = 0;
|
||
$totalData['wx'] = 0;
|
||
|
||
// 获取在线用户的数据及统计下注总额
|
||
$where = array();
|
||
$where['result'] = 0;
|
||
foreach($user_online as $k => $v){
|
||
$where['user_id'] = $v['id'];
|
||
$v['is_beat'] = 0;
|
||
// 总押
|
||
$v['amount'] = Db::connect('DB2')->name('bet')->where($where)->sum('amount');
|
||
$v['money'] = number_format($v['money'],2,".","");
|
||
// 游戏
|
||
if($v['amount'] > 0){
|
||
$v['game_id'] = Db::connect('DB2')->name('bet')->where($where)->order('create_time DESC')->value('game_id');
|
||
}else{
|
||
$v['game_id'] = '';
|
||
}
|
||
|
||
// 桌子名称
|
||
$bets = Db::connect('DB2')->name('bet')->where($where)->order('create_time desc')->select();
|
||
$v['table_name'] = '';
|
||
if($bets){
|
||
$tableIdArr = array();
|
||
foreach($bets as $b){
|
||
if(!in_array($b['table_id'],$tableIdArr)){
|
||
$table_id = $b['table_id'];
|
||
$v['table_name'] .= Db::connect('DB2')->name('table')->where('id',$table_id)->value('table_name').',';
|
||
$tableIdArr[] = $table_id;
|
||
}
|
||
}
|
||
}
|
||
if($v['table_name']){
|
||
$v['table_name'] = substr($v['table_name'],0,-1);
|
||
}
|
||
// 客户端
|
||
if($v['client'] == 1){
|
||
$v['client'] = $lang['pc'];
|
||
$totalData['pc'] += 1;
|
||
}else if($v['client'] == 2){
|
||
$v['client'] = $lang['ios'];
|
||
$totalData['ios'] += 1;
|
||
}else if($v['client'] == 3){
|
||
$v['client'] = $lang['android'];
|
||
$totalData['android'] += 1;
|
||
}else if($v['client'] == 4){
|
||
$v['client'] = $lang['web'];
|
||
$totalData['wap'] += 1;
|
||
}else if($v['client'] == 5){
|
||
$v['client'] = $lang['wc'];
|
||
$totalData['wx'] += 1;
|
||
}else{
|
||
$v['client'] = $lang['unknown'];
|
||
}
|
||
$user_online[$k] = $v;
|
||
|
||
// 汇总数据
|
||
$totalData['amount'] += $v['amount'];
|
||
}
|
||
// 返回数据
|
||
return array('code'=>1,'user_online'=>$user_online,'totalData'=>$totalData);
|
||
}else{
|
||
return array('code'=>0,'msg'=> $lang['operation_error']);
|
||
}
|
||
}
|
||
|
||
// 在线玩家强制下线
|
||
public function logout(){
|
||
$langType = cookie('think_var');
|
||
$lang = Lang::get('agent');
|
||
if(Request::instance()->post()){
|
||
$user_id = Request::instance()->post('user_id');
|
||
if($user_id > 0){
|
||
Db::name('user')->where('id',$user_id)->update(['isout'=>1]);
|
||
Db::name('session')->where('user_id',$user_id)->delete();
|
||
$result = array();
|
||
$result['code'] = 1;
|
||
$result['msg'] = $lang['operation_successful'];
|
||
}else{
|
||
$result = array();
|
||
$result['code'] = 0;
|
||
$result['msg'] = $lang['error_id'];
|
||
}
|
||
}else{
|
||
$result = array();
|
||
$result['code'] = 0;
|
||
$result['msg'] = $lang['operation_error'];
|
||
}
|
||
die(json_encode($result));
|
||
}
|
||
} |