<?php
namespace Home\Controller;
use OT\DataDictionary;
use User\Api\PromoteApi;
/**
* 前台首页控制器
* 主要获取首页聚合数据
*/
class QueryController extends BaseController
{
public static $payWay = [
-1 => '绑币',
0 => '平台币',
1 => '支付宝',
2 => '微信',
5 => '聚宝云',
6 => '竣付通',
7 => '苹果支付',
8 => '金猪支付',
9 => '双乾支付',
];
public function recharge($p = 0)
{
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据arraypage
if (isset($_REQUEST['row'])) {
$row = $_REQUEST['row'];
} else {
$row = 10;
}
$childPromoteIds = getAllChildPromoteList(3);
if (empty($childPromoteIds)) {
$map['tab_spend.promote_id'] = 0;
} else {
$map['tab_spend.promote_id'] = ['in', $childPromoteIds];
}
$teamLeaderId = I('team_leader_id');//组长账号
if (!empty($teamLeaderId)) {
$hasTeamLeaderPermission = hasPromotePermission(PID, $teamLeaderId);
if ($hasTeamLeaderPermission === false) {
$this->error('组长权限异常');
}
$map['tab_spend.promote_id'] = $teamLeaderId;
}
$promoteId = I('promote_id');//推广员账号
if (!empty($promoteId)) {
$hasPromotePermission = hasPromotePermission(PID, $promoteId);
if ($hasPromotePermission === false) {
$this->error('推广员权限异常');
}
if (!empty($map['tab_spend.promote_id'])) {
$map['_string'] = 'tab_spend.promote_id = ' . $promoteId;
} else {
$map['tab_spend.promote_id'] = $promoteId;
}
}
if (!empty(I('own_id'))) {
if (!empty($map['_string'])) {
unset($map['_string']);
}
$map['tab_spend.promote_id'] = I('own_id');//本账号
}
if (!empty(I('begtime')) & & empty(I('endtime'))) {
$map['tab_spend.pay_time'] = ['egt', strtotime(I('begtime'))];
} elseif (empty(I('begtime')) & & !empty(I('endtime'))) {
$map['tab_spend.pay_time'] = ['elt', strtotime(I('endtime')) + 86399];
} elseif (!empty(I('begtime')) & & !empty(I('endtime'))) {
$map['tab_spend.pay_time'] = ['between', [strtotime(I('begtime')), strtotime(I('endtime')) + 86399]];
}
if (I('pay_way') !== null & & I('pay_way') !== '') {
if (I('pay_way') == 2) {
$map['tab_spend.pay_way'] = ['in', '2,3,4'];
} else {
$map['tab_spend.pay_way'] = I('pay_way');
}
}
empty(I('relation_game_id')) || $map['tab_game.relation_game_id'] = I('relation_game_id');
empty(I('sdk_version')) || $map['tab_game.sdk_version'] = I('sdk_version');
empty(I('server_id')) || $map['tab_spend.server_id'] = I('server_id');
empty(I('game_player_name')) || $map['tab_spend.game_player_name'] = ['like', '%' . I('game_player_name') . '%'];
empty(I('user_account')) || $map['tab_spend.user_account'] = ['like', '%' . I('user_account') . '%'];
empty(I('order_number')) || $map['tab_spend.order_number'] = I('order_number');
$map['tab_spend.pay_status'] = 1;
$map['tab_spend.is_check'] = ['neq', 2];
$data = M('Spend', 'tab_')
->field('tab_spend.*,tab_promote.account as pro_account,tab_promote.real_name as pro_real_name,tab_promote.grand_id as pro_grand_id')
->join('tab_game on tab_spend.game_id = tab_game.id')
->join('left join tab_promote on tab_spend.promote_id = tab_promote.id')
->where($map)
->order('tab_spend.id desc')
->page($page, $row)
->select();
$count = M('Spend', 'tab_')
->join('tab_game on tab_spend.game_id = tab_game.id')
->where($map)
->count();
if (!empty($data)) {
foreach ($data as & $list) {
$list['user_account'] = substr($list['user_account'], 0, 2) . '******' . substr($list['user_account'], 8);
}
}
//分页
$parameter['p'] = I('get.p', 1);
$parameter['row'] = I('get.row');
empty(I('relation_game_id')) || $parameter['relation_game_id'] = I('relation_game_id');
empty(I('sdk_version')) || $parameter['sdk_version'] = I('sdk_version');
empty(I('server_id')) || $parameter['server_id'] = I('server_id');
empty(I('game_player_name')) || $parameter['game_player_name'] = I('game_player_name');
empty(I('user_account')) || $parameter['user_account'] = I('user_account');
empty(I('team_leader_id')) || $parameter['team_leader_id'] = I('team_leader_id');
empty(I('promote_id')) || $parameter['promote_id'] = I('promote_id');
empty(I('own_id')) || $parameter['own_id'] = I('own_id');
empty(I('begtime')) || $parameter['begtime'] = I('begtime');
empty(I('endtime')) || $parameter['endtime'] = I('endtime');
$serverData = $this->getServer(I('relation_game_id'), I('sdk_version'));
$thisParentPromoteId = getParentPromoteId(PID);//本账号上级渠道ID
$page = set_pagination($count, $row, $parameter);
if ($page) {
$this->assign('_page', $page);
}
$this->assign('listData', $data);
$this->assign('count', $count);
$this->assign('setdate', date("Y-m-d"));
$this->assign('serverData', $serverData['data']);
$this->assign('thisParentPromoteId', $thisParentPromoteId);
$this->assign('pID', PID);
$this->assign('ownId', I('own_id'));
$this->assign('payWayData', QueryController::$payWay);
$this->meta_title = "充值明细";
$this->display();
}
public function register($p = 0)
{
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据arraypage
if (isset($_REQUEST['row'])) {
$row = $_REQUEST['row'];
} else {
$row = 10;
}
$childPromoteIds = getAllChildPromoteList(3);
if (empty($childPromoteIds)) {
$map['tab_user.promote_id'] = 0;
} else {
$map['tab_user.promote_id'] = ['in', $childPromoteIds];
}
$teamLeaderId = I('team_leader_id');//组长账号
if (!empty($teamLeaderId)) {
$hasTeamLeaderPermission = hasPromotePermission(PID, $teamLeaderId);
if ($hasTeamLeaderPermission === false) {
$this->error('组长权限异常');
}
$map['tab_user.promote_id'] = $teamLeaderId;
}
$promoteId = I('promote_id');//推广员账号
if (!empty($promoteId)) {
$hasPromotePermission = hasPromotePermission(PID, $promoteId);
if ($hasPromotePermission === false) {
$this->error('推广员权限异常');
}
if (!empty($map['tab_user.promote_id'])) {
$map['_string'] = 'tab_user.promote_id = ' . $promoteId;
} else {
$map['tab_user.promote_id'] = $promoteId;
}
}
if (!empty(I('own_id'))) {
if (!empty($map['_string'])) {
unset($map['_string']);
}
$map['tab_user.promote_id'] = I('own_id');//本账号
}
if (!empty(I('begtime')) & & empty(I('endtime'))) {
$map['tab_user.register_time'] = ['egt', strtotime(I('begtime'))];
} elseif (empty(I('begtime')) & & !empty(I('endtime'))) {
$map['tab_user.register_time'] = ['elt', strtotime(I('endtime')) + 86399];
} elseif (!empty(I('begtime')) & & !empty(I('endtime'))) {
$map['tab_user.register_time'] = ['between', [strtotime(I('begtime')), strtotime(I('endtime')) + 86399]];
}
empty(I('account')) || $map['tab_user.account'] = ['like', '%' . I('account') . '%'];
$data = M('User', 'tab_')
->field('tab_user.*,tab_promote.real_name as pro_real_name')
->join('left join tab_promote on tab_user.promote_id = tab_promote.id')
->where($map)
->order('tab_user.id desc')
->page($page, $row)
->select();
$count = M('User', 'tab_')
->where($map)
->count();
if (!empty($data)) {
foreach ($data as & $list) {
$newLoginData = M('User', 'tab_')
->field('login_time,login_ip')
->where(array('user_id' => $list['id']))
->order('login_time desc')
->find();
$list['new_login_time'] = date('Y-m-d H:i:s', $newLoginData['login_time']);
$list['new_login_ip'] = $newLoginData['login_ip'];
$list['account'] = substr($list['account'], 0, 2) . '******' . substr($list['account'], 8);
}
}
//分页
$parameter['p'] = I('get.p', 1);
$parameter['row'] = I('get.row');
empty(I('team_leader_id')) || $parameter['team_leader_id'] = I('team_leader_id');
empty(I('promote_id')) || $parameter['promote_id'] = I('promote_id');
empty(I('own_id')) || $parameter['own_id'] = I('own_id');
empty(I('account')) || $parameter['account'] = I('account');
empty(I('begtime')) || $parameter['begtime'] = I('begtime');
empty(I('endtime')) || $parameter['endtime'] = I('endtime');
$thisParentPromoteId = getParentPromoteId(PID);//本账号上级渠道ID
$page = set_pagination($count, $row, $parameter);
if ($page) {
$this->assign('_page', $page);
}
$this->assign('listData', $data);
$this->assign('count', $count);
$this->assign('setdate', date("Y-m-d"));
$this->assign('thisParentPromoteId', $thisParentPromoteId);
$this->assign('pID', PID);
$this->assign('ownId', I('own_id'));
$this->meta_title = '注册明细';
$this->display();
}
/**
*我的对账单
*/
public function bill()
{
$map['promote_id'] = get_pid();
if (isset($_REQUEST['bill_number']) & & !empty($_REQUEST['bill_number'])) {
$map['bill_number'] = $_REQUEST['bill_number'];
}
if (isset($_REQUEST['game_id']) & & !empty($_REQUEST['game_id'])) {
$map['game_id'] = $_REQUEST['game_id'];
}
if (!empty($_REQUEST['timestart']) & & !empty($_REQUEST['timeend'])) {
$map['bill_start_time'] = array('egt', strtotime($_REQUEST['timestart']));
$map['bill_end_time'] = array('elt', strtotime($_REQUEST['timeend']) + 24 * 3600 - 1);
}
$model = array(
'm_name' => 'bill',
'map' => $map,
'template_list' => 'bill',
'title' => '我的对账单',
);
$user = A('User', 'Event');
$user->bill_list($model, $_GET['p']);
}
/**
*我的结算
*/
public function my_earning($p = 1)
{
$pro_map['id'] = get_pid();
$pro = M("promote", "tab_")->where($pro_map)->find();
$map['promote_id'] = get_pid();
if ($pro['parent_id'] == 0) {
if (isset($_REQUEST['settlement_number']) & & !empty($_REQUEST['settlement_number'])) {
$map['settlement_number'] = ['like', '%' . $_REQUEST['settlement_number'] . '%'];
}
if (!empty($_REQUEST['timestart']) & & !empty($_REQUEST['timeend'])) {
/*$map['bill_start_time'] = array('egt',strtotime($_REQUEST['timestart']));
$map['bill_end_time'] = array('elt',strtotime($_REQUEST['timeend'])+24*3600-1);*/
$map['starttime'] = array('egt', strtotime($_REQUEST['timestart']));
$map['endtime'] = array('elt', strtotime($_REQUEST['timeend']) + 24 * 3600 - 1);
} elseif (!empty($_REQUEST['timestart']) & & empty($_REQUEST['timeend'])) {
$map['starttime'] = array('egt', strtotime($_REQUEST['timestart']));
} elseif (empty($_REQUEST['timestart']) & & !empty($_REQUEST['timeend'])) {
$map['endtime'] = array('elt', strtotime($_REQUEST['timeend']) + 24 * 3600 - 1);
}
$model = array(
'm_name' => 'TotalSettlement',
'map' => $map,
'fields' => true,
'order' => 'create_time desc ',
'template_list' => 'my_earning',
'title' => '我的结算',
);
} else {
if (isset($_REQUEST['settlement_number']) & & !empty($_REQUEST['settlement_number'])) {
$map['settlement_number'] = ['like', '%' . $_REQUEST['settlement_number'] . '%'];
}
if (!empty($_REQUEST['timestart']) & & !empty($_REQUEST['timeend'])) {
$map['settlement_start_time'] = array('egt', strtotime($_REQUEST['timestart']));
$map['settlement_end_time'] = array('elt', strtotime($_REQUEST['timeend']) + 24 * 3600 - 1);
} elseif (!empty($_REQUEST['timestart']) & & empty($_REQUEST['timeend'])) {
$map['settlement_start_time'] = array('egt', strtotime($_REQUEST['timestart']));
} elseif (empty($_REQUEST['timestart']) & & !empty($_REQUEST['timeend'])) {
$map['settlement_end_time'] = array('elt', strtotime($_REQUEST['timeend']) + 24 * 3600 - 1);
}
$model = array(
'm_name' => 'son_settlement',
'fields' => 'settlement_number,settlement_start_time,create_time,
settlement_end_time,game_id,game_name,promote_id,
promote_account,pattern,bind_coin_status,floor(sum(sum_money*100))/100 as sum_money,
sum(reg_number) as reg_number,ratio,money,floor(sum(jie_money*100))/100 as jie_money,status,ti_status',
'map' => $map,
'template_list' => 'my_earning_sub',
'order' => 'create_time desc',
'group' => 'settlement_number, create_time',
'title' => '我的结算',
);
}
$user = A('User', 'Event');
$this->assign("parent_id", $pro['parent_id']);
$user->shou_list($model, $p);
}
/**
*子渠道结算单
*/
public function son_earning_($p = 1)
{
if (PLEVEL == 0) {
if (isset($_REQUEST['timestart']) & & isset($_REQUEST['timeend']) & & !empty($_REQUEST['timestart']) & & !empty($_REQUEST['timeend'])) {
$starttime = strtotime($_REQUEST['timestart']);
$endtime = strtotime($_REQUEST['timeend']) + 24 * 60 * 60 - 1;
$this->assign('starttime', $starttime);
$this->assign('endtime', $endtime);
$map[0]['register_time'] = array('BETWEEN', array($starttime, $endtime));
$map[1]['pay_time'] = array('BETWEEN', array($starttime, $endtime));
unset($_REQUEST['timestart']);
unset($_REQUEST['timeend']);
$map[1]['parent_id'] = $map[0]['u.parent_id'] = PID;
if (isset($_REQUEST['ch_promote_id']) & & !empty($_REQUEST['ch_promote_id'])) {
$map[1]['s.promote_id'] = $map[0]['u.promote_id'] = $_REQUEST['ch_promote_id'];
}
$model = array(
'title' => '子渠道结算单',
'template_list' => 'son_earning',
);
$user = A('User', 'Event');
$user->check_bill($model, $p, $map);
} else {
$this->display();
}
} else {
$model = array(
'm_name' => 'SonSettlement',
'order' => 'id ',
'title' => '结算账单',
'template_list' => 'son_earning',
);
$user = A('User', 'Event');
$user->money_list($model, $p);
}
}
//子渠道结算单
public function son_list($p = 0)
{
if (!empty($_REQUEST['timestart']) & & !empty($_REQUEST['timeend'])) {
$map['settlement_start_time'] = array('egt', strtotime($_REQUEST['timestart']));
$map['settlement_end_time'] = array('elt', strtotime($_REQUEST['timeend']) + 86399);
} elseif (!empty($_REQUEST['timestart']) & & empty($_REQUEST['timeend'])) {
$map['settlement_start_time'] = array('egt', strtotime($_REQUEST['timestart']));
$map['settlement_end_time'] = array('elt', time());
} elseif (empty($_REQUEST['timestart']) & & !empty($_REQUEST['timeend'])) {
$map['settlement_end_time'] = array('elt', strtotime($_REQUEST['timeend']) + 86399);
}
if (!empty($_REQUEST['start']) & & !empty($_REQUEST['end'])) {
$start = strtotime($_REQUEST['start']);
$end = strtotime($_REQUEST['end']) + 86399;
$map['create_time'] = array('BETWEEN', array($start, $end));
} elseif (!empty($_REQUEST['start']) & & empty($_REQUEST['end'])) {
$start = strtotime($_REQUEST['start']);
$end = time();
$map['create_time'] = array('BETWEEN', array($start, $end));
} elseif (empty($_REQUEST['start']) & & !empty($_REQUEST['end'])) {
$end = strtotime($_REQUEST['end']) + 86399;
$map['create_time'] = array('elt', $end);
}
if (!empty($_REQUEST['ch_promote_id'])) {
$map['promote_id'] = $_REQUEST['ch_promote_id'];
} else {
$promote = M('Promote', 'tab_')->field('id')->where(['parent_id' => PID])->select();
$zi_p = implode(',', array_column($promote, 'id'));
$map['promote_id'] = array('in', "$zi_p");
}
$model = array(
'm_name' => 'SonSettlement',
'fields' => array(
'settlement_number',
'settlement_start_time',
'settlement_end_time',
'promote_id',
'promote_account',
'bind_coin_status',
'FLOOR(sum(sum_money*100))/100 as sum_money',
'sum(reg_number) as reg_number',
'FLOOR(sum(jie_money*100))/100 as jie_money',
'ti_status',
'create_time'
),
'order' => 'create_time desc',
'group' => 'settlement_number,create_time',
'title' => '子渠道结算单',
'template_list' => 'son_list',
);
$user = A('User', 'Event');
$user->money_list($model, $p, $map);
}
/**
*子渠道结算单
*/
public function son_earning($p = 0)
{
if (!empty($_REQUEST['timestart']) || !empty($_REQUEST['timeend'])) {
$starttime = empty($_REQUEST['timestart']) ? strtotime("-7 day {$_REQUEST['timeend']}") : strtotime($_REQUEST['timestart']);
$endtime = empty($_REQUEST['timeend']) ? mktime(23, 59, 59, date('m'), date('d') - 1, date('Y')) : strtotime($_REQUEST['timeend']) + 24 * 60 * 60 - 1;
$this->assign('starttime', date('Y-m-d', $starttime));
$this->assign('endtime', date('Y-m-d', $endtime));
$mapp['u.register_time'] = array('BETWEEN', array($starttime, $endtime));
$mapp['u.' . SETTLEMENT_GRADE] = 0;
$map['s.pay_time'] = array('BETWEEN', array($starttime, $endtime));
$map['s.pay_status'] = 1;
$map['s.' . SETTLEMENT_GRADE] = 0;
if ($_REQUEST['bind_coin'] == 0) {
$map['s.pay_way'] = array('neq', -1);
}
unset($_REQUEST['timestart']);
unset($_REQUEST['timeend']);
if (isset($_REQUEST['ch_promote_id']) & & !empty($_REQUEST['ch_promote_id'])) {
$chid = $_REQUEST['ch_promote_id'];
$promote_child = get_sub_channel_id($chid, PRO_GRADE + 1);
$map['s.promote_id'] = $mapp['u.promote_id'] = array('in', $promote_child);
} else {
$promote_child = get_zi_promote_id(PID);
if (empty($promote_child)) {
$this->error('该渠道无子渠道');
}
$map['s.promote_id'] = $mapp['u.promote_id'] = array('in', $promote_child);
}
$model = array(
'fields' => 'sum(s.pay_amount) as total_amount,s.promote_account,s.promote_id,s.game_name,s.game_id,s.sub_status',
'm_name' => 'Spend',
'title' => '子渠道结算单',
'template_list' => 'son_earning',
'join' => 'tab_apply on tab_Spend.game_id=tab_apply.game_id and tab_Spend.promote_id=tab_apply.promote_id',
'group' => 's.promote_id,s.game_id',
'currentid' => $chid ? $chid : '',
);
$mmap = array($mapp, $map);
$user = A('User', 'Event');
$user->check_child_bill($model, $p, $mmap);
} else {
$this->meta_title = '子渠道结算';
$this->display();
}
}
public function generatesub()
{
//$data = $_REQUEST;
if (empty($_REQUEST['ids'])) {
$this->error('请选择要结算的数据');
} else {
$settData = array();
$settlement_number = 'js_' . date('YmdHis', time()) . rand(100, 999);
$create_time = time();
$start = $_REQUEST['timestart'];
$end = $_REQUEST['timeend'];
foreach ($_REQUEST['ids'] as $key => $value) {
$data = json_decode($value, true);
$data['settlement_number'] = $settlement_number;
$data['create_time'] = time();
$data['settlement_start_time'] = strtotime($data['settlement_start_time']);
$data['settlement_end_time'] = strtotime($data['settlement_end_time']);
switch ($data['cooperation']) {
case 'CPS':
$data['pattern'] = 0;
$cps = $data['ratio'];
$data['jie_money'] = round(($cps * $data['sum_money']) / 100, 2);
break;
case 'CPA':
$data['pattern'] = 1;
$cpa = $data['money'];
$data['jie_money'] = round($cpa * $data['reg_number'], 2);
break;
}
$userMap['register_time'] = array('BETWEEN', array($data['settlement_start_time'], $data['settlement_end_time'] + 86399));
$userMap['fgame_id'] = $data['game_id'];
$userMap[SETTLEMENT_GRADE] = $spendMap[SETTLEMENT_GRADE] = 0;
$userMap['promote_id'] = $spendMap['promote_id'] = array('in', $data['tpid']);
$spendMap['game_id'] = $data['game_id'];
$spendMap['pay_time'] = $userMap['register_time'];
$user = M('user', 'tab_')->where($userMap)->save(array(SETTLEMENT_GRADE => 1));
$spend = M('spend', 'tab_')->where($spendMap)->save(array(SETTLEMENT_GRADE => 1));
$settData[$key] = $data;
}
$result = M('SonSettlement', 'tab_')->addAll($settData);
if ($result) {
/*$this->success('生成结算单成功!',U('son_earning?success=1',array('timestart' => $start,'timeend' => $end)),true);*/
$this->success('生成结算单成功!', U('son_list'), true);
} else {
$this->error('生成结算单失败!', U('son_earning?fall=1', array('timestart' => $start, 'timeend' => $end)), true);
}
}
$this->error('生成结算单失败!!!', U('son_earning?fall=1', array('timestart' => $start, 'timeend' => $end)), true);
}
//申请提现
public function apply_withdraw($id, $op = 0)
{
$map['id'] = $id;
$with = M("withdraw", "tab_");
$totalSett = M("TotalSettlement", "tab_")->where($map)->find();
$with_map['settlement_number'] = $totalSett['settlement_number'];
$fid = $with->where($with_map)->find();
if ($fid == null) {
$add['settlement_number'] = $totalSett['settlement_number'];
$add['sum_money'] = $totalSett['jie_money'] ? $totalSett['jie_money'] : $totalSett['sum_money'];
$add['promote_id'] = $totalSett['promote_id'];
$add['promote_account'] = $totalSett['promote_account'];
$add['create_time'] = time();
$add['status'] = 0;
$with->add($add);
M("TotalSettlement", "tab_")->where($map)->save(array('ti_status' => 0));
$settMap['promote_id'] = $totalSett['promote_id'];
$settMap['starttime'] = $totalSett['starttime'];
$settMap['endtime'] = $totalSett['endtime'];
$settMap['create_time'] = $totalSett['create_time'];
M("settlement", "tab_")->where($settMap)->save(array('ti_status' => 0));
echo json_encode(array("status" => 1));
} else {
if ($op > 0) {
$with->where($with_map)->setField('status', 0);
M("settlement", "tab_")->where($map)->setField('ti_status', 0);
M("TotalSettlement", "tab_")->where($map)->save(array('ti_status' => 0));
echo json_encode(array("status" => 1));
} else {
echo json_encode(array("status" => 0));
}
}
}
//申请提现
public function son_apply_withdraw($settlement_number = '')
{
$map['settlement_number'] = $settlement_number;
$with_map['settlement_number'] = $totalSett['settlement_number'];
$result = M("SonSettlement", "tab_")->where($map)->save(array('ti_status' => 0));
if ($result !== false) {
echo json_encode(array("status" => 1));
} else {
echo json_encode(array("status" => 0));
}
}
public function audit_withdraw($settlement_number = '')
{
$map['settlement_number'] = $settlement_number;
$with_map['settlement_number'] = $totalSett['settlement_number'];
$result = M("SonSettlement", "tab_")->where($map)->save(array('ti_status' => 1));
if ($result !== false) {
$this->success('审核成功');
} else {
$this->error('审核失败');
}
}
public function arpu_analysis()
{
$this->meta_title = "ARPU统计";
A('User', 'Event')->arpu_analysis();
}
public function cha_userarpu($p = 0)
{
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据arraypage
$arraypage = $page ? $page : 1; //默认显示第一页数据
$row = 10;
if (isset($_REQUEST['row'])) {
$row = $_REQUEST['row'];
} else {
$row = 10;
}
$time = $_REQUEST['time'];
$promote_id = $_REQUEST['promote_id'];
/* if ($promote_id < 1 ) {
$pid = D('Promote')->get_child_promote(PID,'id');
if (empty($pid[0])) {
$promote_id = PID;
} else {
$id = implode(',',array_column($pid,'id'));
$promote_id = PID.','.$id;
}
} */
$join = "left join tab_user u on u.fgame_id = tab_game.id";
if ($time == '') {
$this->error('参数错误,缺少时间');
} else {
$map['register_time'] = array('between', array(strtotime($time), strtotime($time) + 24 * 60 * 60 - 1));
}
/* if($promote_id!=''){
$map_list['promote_id']=array('in',$promote_id);
$map['promote_id']=array('in',$promote_id);
$join .= " AND u.promote_id = {$promote_id}";
} */
if ($promote_id > 0) {
if (PID == $promote_id) {
$pro_arr[] = PID;
} else {
$pro_id1 = get_prmoote_chlid_account2($promote_id);
$pro_arr = array_column($pro_id1, 'id');
$pro_arr[] = $promote_id;
}
$map['promote_id'] = array('in', $pro_arr);
$map_list['promote_id'] = array('in', $pro_arr);
$promote_id = implode(',', $pro_arr);
$join .= " AND u.promote_id in ({$promote_id})";
} else {
$pid = D('Promote')->get_child_promote(PID, 'id');
if (empty($pid[0])) {
$pro_arr[] = PID;
} else {
$pro_arr = array_column($pid, 'id');
$pro_arr[] = PID;
}
$map['promote_id'] = array('in', $pro_arr);
$map_list['promote_id'] = array('in', $pro_arr);
$promote_id = implode(',', $pro_arr);
$join .= " AND u.promote_id in ({$promote_id})";
}
$spend2 = D('Spend');
$data = M('Game', 'tab_')->field('id as game_id, game_name')->order('id desc')->select();
foreach ($data as $key => $value) {
$game_id = $value['game_id'];
$map_list['game_id'] = $game_id;
$user = M('User', 'tab_');
$spend = M('spend', 'tab_');
//新增人数
$rdata = $user
->field('count(id) as register_num')
->where(array('fgame_id' => $game_id))
->where(array_merge($map, ['puid' => 0]))
->find();
$data[$key]['register_num'] = $rdata['register_num'];
//活跃玩家
//$data[$key]['act_user'] = $this->count_act_user($time,$game_id,$promote_id);
$activedata = D('User')->login_count_by_time(strtotime($time), strtotime($time) + 86399, $game_id, $promote_id);
$data[$key]['act_user'] = $activedata[0]['login_num'] ? $activedata[0]['login_num'] : 0;
//1日留存
$mapl = $map_list;
$mapl["FROM_UNIXTIME(register_time,'%Y-%m-%d')"] = $time;
$mapl['tab_user.promote_id'] = $mapl['promote_id'];
$mapl['tab_user.puid'] = 0;
unset($mapl['promote_id']);
$login_time = date('Y-m-d', strtotime("+1 day", strtotime($time)));
$num = $user
->field('count(DISTINCT tab_user.id) as num')
->join("right join tab_user_login_record as ur on ur.user_id = tab_user.id and FROM_UNIXTIME(ur.login_time,'%Y-%m-%d') = '{$login_time}'")
->where($mapl)
->find();
$data[$key]['keep_num'] = round($num['num'] / $data[$key]['register_num'], 4) * 100;
//充值
$mapl = $map_list;
empty($game_name) || $mapl['game_name'] = array('like', '%' . $game_name . '%');
$mapl['pay_status'] = 1;
$mapl["FROM_UNIXTIME(pay_time,'%Y-%m-%d')"] = $time;
if (I('bangbi') == 1) {
$mapl['pay_way'] = array('neq', '-10');
$bangbi = true;
} else {
$mapl['pay_way'] = array('neq', -1);
$bangbi = false;
}
$spend = $spend->field("IFNULL(sum(pay_amount),0) as money,IFNULL(count(distinct user_id),0) as people")->where($mapl)->find();
$data[$key]['spend'] = $spend['money'];
//付费玩家数
$data[$key]['spend_people'] = $spend['people'];
//新付费玩家
$newsdata = $spend2->pay_count_by_time_class([$time], $game_id, $promote_id, 1, $bangbi);
$data[$key]['spend_news'] = $newsdata[0]['pay_num'] ? $newsdata[0]['pay_num'] : 0;
//付费率
$data[$key]['spend_rate'] = round($data[$key]['spend_people'] / $data[$key]['act_user'], 4) * 100;
//ARPU
$data[$key]['ARPU'] = round($data[$key]['spend'] / $data[$key]['act_user'], 2);
//ARPPU
$data[$key]['ARPPU'] = round($data[$key]['spend'] / $data[$key]['spend_people'], 2);
if ($data[$key]['register_num'] == 0 & & $data[$key]['act_user'] == 0 & & $data[$key]['keep_num'] == 0 & & $data[$key]['spend'] == 0 & & $data[$key]['spend_people'] == 0) {
unset($data[$key]);
}
}
$count = count($data);
/* if($count > $row){
$page = new \Think\Page($count, $row);
$page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
$this->assign('_page', $page->show());
} */
/*$page = set_pagination($count,++$count);
if($page) {$this->assign('_page', $page);}*/
$this->assign('_page', '< div > < span class = "rows" > 共 ' . $count . ' 条记录< / span > < / div > ');
/*$size=$row;//每页显示的记录数
$pnum = ceil(count($data) / $size); //总页数, ceil()函数用于求大于数字的最小整数
//用array_slice(array,offset,length) 函数在数组中根据条件取出一段值;array(数组),offset(元素的开始位置),length(组的长度)
$data = array_slice($data, ($arraypage-1)*$size, $size);*/
$this->assign('list_data', $data);
$this->display();
}
/**
* 获取活跃用户数
* @param $time
*/
public function count_act_user($time, $game_id = "", $promote_id = "")
{
$map["FROM_UNIXTIME(login_time,'%Y-%m-%d')"] = $time;
$map1["FROM_UNIXTIME(register_time,'%Y-%m-%d')"] = $time;
empty($game_id) || $map['game_id'] = $game_id;
empty($game_id) || $map1['fgame_id'] = $game_id;
if (!empty($promote_id)) {
$user = M('User', 'tab_')->field('id')->where(array('promote_id' => $promote_id))->select();
$user = implode(',', array_column($user, 'id'));
$map['user_id'] = array('in', $user);
$map1['id'] = array('in', $user);
};
$uudata = M('User', 'tab_')
->field('id')
->where($map1)
->select(false);
$data = M('user_login_record', 'tab_')
->field('id')
->where($map)
->union($uudata)
->group('user_id')
->select();
$data = count($data);
return $data;
}
public function retention_analysis()
{
$this->meta_title = '留存统计';
A('User', 'Event')->retention_analysis();
}
public function details()
{
$map['id'] = $_REQUEST['id'];
$data = M('TotalSettlement', 'tab_')->where($map)->find();
$mapSett['promote_id'] = $data['promote_id'];
$mapSett['starttime'] = $data['starttime'];
$mapSett['endtime'] = $data['endtime'];
$mapSett['create_time'] = $data['create_time'];
$listData = M('settlement', 'tab_')->where($mapSett)->select();
$totalData = M('settlement', 'tab_')->where($mapSett)->sum('sum_money');
$this->assign('list_data', $listData);
$this->assign('total', $totalData);
$this->display();
}
public function son_details()
{
$map['promote_id'] = $_REQUEST['promote_id'];
$map['settlement_number'] = $_REQUEST['settlement_number'];
$data = M('SonSettlement', 'tab_')->where($map)->select();
$total = M('SonSettlement', 'tab_')->where($map)->sum('jie_money');
$this->assign('total', floor($total * 100) / 100);
$this->assign('list_data', $data);
$this->display();
}
public function dailySummary()
{
$childPromoteIds = getAllChildPromoteList(3);
if (empty($childPromoteIds)) {
$userPlayInfoWhere['tab_user_play_info.promote_id'] = 0;
$userGameLoginWhere['tab_user_game_login_record.promote_id'] = 0;
$spendWhere['tab_spend.promote_id'] = 0;
} else {
$userPlayInfoWhere['tab_user_play_info.promote_id'] = ['in', $childPromoteIds];
$userGameLoginWhere['tab_user_game_login_record.promote_id'] = ['in', $childPromoteIds];
$spendWhere['tab_spend.promote_id'] = ['in', $childPromoteIds];
}
$teamLeaderId = I('team_leader_id');//组长账号
if (!empty($teamLeaderId)) {
$hasTeamLeaderPermission = hasPromotePermission(PID, $teamLeaderId);
if ($hasTeamLeaderPermission === false) {
$this->error('组长权限异常');
}
$userPlayInfoWhere['tab_user_play_info.promote_id'] = $teamLeaderId;
$userGameLoginWhere['tab_user_game_login_record.promote_id'] = $teamLeaderId;
$spendWhere['tab_spend.promote_id'] = $teamLeaderId;
}
$promoteId = I('promote_id');//推广员账号
if (!empty($promoteId)) {
$hasPromotePermission = hasPromotePermission(PID, $promoteId);
if ($hasPromotePermission === false) {
$this->error('推广员权限异常');
}
if (!empty($userPlayInfoWhere['tab_apply.promote_id'])) {
$userPlayInfoWhere['_string'] = 'tab_user_play_info.promote_id = ' . $promoteId;
$userGameLoginWhere['_string'] = 'tab_user_game_login_record.promote_id = ' . $promoteId;
$spendWhere['_string'] = 'tab_spend.promote_id = ' . $promoteId;
} else {
$userPlayInfoWhere['tab_user_play_info.promote_id'] = $promoteId;
$userGameLoginWhere['tab_user_game_login_record.promote_id'] = $promoteId;
$spendWhere['tab_spend.promote_id'] = $promoteId;
}
}
if (!empty(I('own_id'))) {
if (!empty($userPlayInfoWhere['_string'])) {
unset($userPlayInfoWhere['_string']);
unset($userGameLoginWhere['_string']);
unset($spendWhere['_string']);
}
$userPlayInfoWhere['tab_user_play_info.promote_id'] = I('own_id');
$userGameLoginWhere['tab_user_game_login_record.promote_id'] = I('own_id');
$spendWhere['tab_spend.promote_id'] = I('own_id');
}
$map['_string'] = '1 = 1';
$join = '';
if (!empty(I('relation_game_id'))) {
$map['tab_game.relation_game_id'] = I('relation_game_id');
$join = 'tab_game on game_id = tab_game.id';
}
if (!empty(I('sdk_version'))) {
$userPlayInfoWhere['tab_user_play_info.sdk_version'] = I('sdk_version');
$userGameLoginWhere['tab_user_game_login_record.sdk_version'] = I('sdk_version');
$spendWhere['tab_spend.sdk_version'] = I('sdk_version');
}
$nowTime = date('Y-m-d');
$initBegTime = date('Y-m-d', strtotime('-6 day', strtotime($nowTime)));
$initBegTime = empty(I('begtime')) ? $initBegTime : I('begtime');
$initEndTime = $nowTime;
$initEndTime = empty(I('endtime')) ? $initEndTime : I('endtime');
$userPlayInfoModel = M('UserPlayInfo', 'tab_');
$newWhere = '';
$begTime = strtotime($initBegTime);
$endTime = strtotime($initEndTime);
$spendWhere['tab_spend.pay_status'] = 1;
if (!empty(I('server_id'))) {
$userPlayInfoWhere['tab_user_play_info.server_id'] = I('server_id');
$userGameLoginWhere['tab_user_game_login_record.server_id'] = I('server_id');
$spendWhere['tab_spend.server_id'] = I('server_id');
$newWhere = ' and ti.server_id = ' . I('server_id');
}
$summaryData = [];
$data = [];
$dataNum = ($endTime - $begTime) / 86400 + 1;
$dateTime = $endTime;
for ($index = 0; $index < $dataNum; $index++) {
$thisDateTime = date('Ymd', $dateTime);
$summaryData['date'][] = $thisDateTime;
$data[]['day'] = $thisDateTime;
$dateTime = strtotime('-1 day', $dateTime);
}
$allData['spend_num'] = 0;
$allData['spend_all_amount'] = 0;
$allData['spend_cash'] = 0;
$allData['spend_generic'] = 0;
$allData['pay_amount'] = 0;
$allData['spend_discount'] = 0;
$allData['spend_voucher'] = 0;
foreach ($data as & $list) {
$thisDateTime = strtotime($list['day']);
$userPlayInfoWhere['tab_user_play_info.play_time'] = ['between', [$thisDateTime, $thisDateTime + 86399]];
$userGameLoginWhere['tab_user_game_login_record.login_time'] = ['between', [$thisDateTime, $thisDateTime + 86399]];
$spendWhere['tab_spend.pay_time'] = ['between', [$thisDateTime, $thisDateTime + 86399]];
$list['role_num'] = $userPlayInfoModel
->join($join)
->where($userPlayInfoWhere)
->where($map)
->order('play_time desc')
->count();//创角数
$list['user_num'] = count($userPlayInfoModel
->field('tab_user_play_info.id')
->join($join)
->where($userPlayInfoWhere)
->where($map)
->group('tab_user_play_info.user_id')
->select());//创角用户
$newUserSql = '(select count(ti.id) from tab_user_play_info as ti where ti.user_id = tab_user_play_info.user_id and ti.game_id = tab_user_play_info.game_id and ti.play_time < ' . $thisDateTime . $newWhere . ') as old_num';
$list['new_user_num'] = count($userPlayInfoModel
->field($newUserSql)
->join($join)
->where($userPlayInfoWhere)
->where($map)
->group('tab_user_play_info.user_id')
->having('old_num = 0')
->select());//新创角用户
$list['new_device_num'] = 0;//新创角设备
$newIpSql = '(select count(ti.id) from tab_user_play_info as ti where ti.play_ip = tab_user_play_info.play_ip and ti.game_id = tab_user_play_info.game_id and ti.play_time < ' . $thisDateTime . $newWhere . ') as old_num';
$list['new_ip_num'] = count($userPlayInfoModel
->field($newIpSql)
->join($join)
->where($userPlayInfoWhere)
->where($map)
->group('tab_user_play_info.play_ip')
->having('old_num = 0')
->fetchSql(true)
->select());//新增创角IP
$list['login_user_num'] = count(M('UserGameLoginRecord', 'tab_')
->field('tab_user_game_login_record.id')
->join($join)
->where($userGameLoginWhere)
->where($map)
->group('user_id')
->select());//登录用户数
$list['spend_user_num'] = count(M('Spend', 'tab_')
->field('tab_spend.id')
->join($join)
->where($spendWhere)
->where($map)
->group('tab_spend.user_id')
->select());//充值人数
$list['spend_num'] = M('Spend', 'tab_')
->join($join)
->where($spendWhere)
->where($map)
->count();//充值次数
$list['spend_all_amount'] = M('Spend', 'tab_')
->join($join)
->where($spendWhere)
->where($map)
->sum('tab_spend.pay_amount');//充值总额
$list['spend_all_amount'] = empty($list['spend_all_amount']) ? 0 : $list['spend_all_amount'];
$list['spend_cash'] = M('Spend', 'tab_')
->join($join)
->where($spendWhere)
->where($map)
->where(array('tab_spend.pay_way' => ['in', '1,2,3,4,5,6']))
->sum('tab_spend.pay_amount');//现金充值
$list['spend_cash'] = empty($list['spend_cash']) ? 0 : $list['spend_cash'];
$list['spend_generic'] = M('Spend', 'tab_')
->join($join)
->where($spendWhere)
->where($map)
->where(array('tab_spend.pay_way' => 0))
->sum('tab_spend.pay_amount');//通用币
$list['spend_generic'] = empty($list['spend_generic']) ? 0 : $list['spend_generic'];
$list['spend_binding'] = M('Spend', 'tab_')
->join($join)
->where($spendWhere)
->where($map)
->where(array('tab_spend.pay_way' => -1))
->sum('tab_spend.pay_amount');//绑定币
$list['spend_binding'] = empty($list['spend_binding']) ? 0 : $list['spend_binding'];
$list['spend_discount'] = 0;//折扣币
$list['spend_voucher'] = 0;//代金券
$allData['spend_num'] += $list['spend_num'];
$allData['spend_all_amount'] += $list['spend_all_amount'];
$allData['spend_cash'] += $list['spend_cash'];
$allData['spend_generic'] += $list['spend_generic'];
$allData['spend_binding'] += $list['spend_binding'];
$allData['spend_discount'] += $list['spend_discount'];
$allData['spend_voucher'] += $list['spend_voucher'];
$summaryData['role_num'][] = $list['role_num'];
$summaryData['user_num'][] = $list['user_num'];
$summaryData['new_user_num'][] = $list['new_user_num'];
$summaryData['new_device_num'][] = $list['new_device_num'];
$summaryData['spend_user_num'][] = $list['spend_user_num'];
$summaryData['spend_all_amount'][] = $list['spend_all_amount'];
}
$summaryData['date'] = array_reverse($summaryData['date']);
$summaryData['role_num'] = array_reverse($summaryData['role_num']);
$summaryData['user_num'] = array_reverse($summaryData['user_num']);
$summaryData['new_user_num'] = array_reverse($summaryData['new_user_num']);
$summaryData['new_device_num'] = array_reverse($summaryData['new_device_num']);
$summaryData['spend_user_num'] = array_reverse($summaryData['spend_user_num']);
$summaryData['spend_all_amount'] = array_reverse($summaryData['spend_all_amount']);
$serverData = $this->getServer(I('relation_game_id'), I('sdk_version'));
$thisParentPromoteId = getParentPromoteId(PID);//本账号上级渠道ID
$this->assign('meta_title', '每日概况');
$this->assign('listData', $data);
$this->assign('allData', $allData);
$this->assign('summaryData', $summaryData);
$this->assign('setdate', date("Y-m-d"));
$this->assign('initBegTime', $initBegTime);
$this->assign('initEndTime', $initEndTime);
$this->assign('serverData', $serverData['data']);
$this->assign('thisParentPromoteId', $thisParentPromoteId);
$this->assign('pID', PID);
$this->display();
}
public function summary($p = 1)
{
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据arraypage
if (isset($_REQUEST['row'])) {
$row = $_REQUEST['row'];
} else {
$row = 10;
}
$childPromoteIds = getAllChildPromoteList(3);
if (empty($childPromoteIds)) {
$map['tab_apply.promote_id'] = 0;
$userPlayInfoWhere['tab_user_play_info.promote_id'] = 0;
$userGameLoginWhere['tab_user_game_login_record.promote_id'] = 0;
$spendWhere['tab_spend.promote_id'] = 0;
} else {
$map['tab_apply.promote_id'] = ['in', $childPromoteIds];
$userPlayInfoWhere['tab_user_play_info.promote_id'] = ['in', $childPromoteIds];
$userGameLoginWhere['tab_user_game_login_record.promote_id'] = ['in', $childPromoteIds];
$spendWhere['tab_spend.promote_id'] = ['in', $childPromoteIds];
}
$teamLeaderId = I('team_leader_id');//组长账号
if (!empty($teamLeaderId)) {
$hasTeamLeaderPermission = hasPromotePermission(PID, $teamLeaderId);
if ($hasTeamLeaderPermission === false) {
$this->error('组长权限异常');
}
$map['tab_apply.promote_id'] = $teamLeaderId;
$userPlayInfoWhere['tab_user_play_info.promote_id'] = $teamLeaderId;
$userGameLoginWhere['tab_user_game_login_record.promote_id'] = $teamLeaderId;
$spendWhere['tab_spend.promote_id'] = $teamLeaderId;
}
$promoteId = I('promote_id');//推广员账号
if (!empty($promoteId)) {
$hasPromotePermission = hasPromotePermission(PID, $promoteId);
if ($hasPromotePermission === false) {
$this->error('推广员权限异常');
}
if (!empty($map['tab_apply.promote_id'])) {
$map['_string'] = 'tab_apply.promote_id = ' . $promoteId;
$userPlayInfoWhere['_string'] = 'tab_user_play_info.promote_id = ' . $promoteId;
$userGameLoginWhere['_string'] = 'tab_user_game_login_record.promote_id = ' . $promoteId;
$spendWhere['_string'] = 'tab_spend.promote_id = ' . $promoteId;
} else {
$map['tab_apply.promote_id'] = $promoteId;
$userPlayInfoWhere['tab_user_play_info.promote_id'] = $promoteId;
$userGameLoginWhere['tab_user_game_login_record.promote_id'] = $promoteId;
$spendWhere['tab_spend.promote_id'] = $promoteId;
}
}
if (!empty(I('own_id'))) {
if (!empty($map['_string'])) {
unset($map['_string']);
unset($userPlayInfoWhere['_string']);
unset($userGameLoginWhere['_string']);
unset($spendWhere['_string']);
}
$map['tab_apply.promote_id'] = I('own_id');//本账号
$userPlayInfoWhere['tab_user_play_info.promote_id'] = I('own_id');
$userGameLoginWhere['tab_user_game_login_record.promote_id'] = I('own_id');
$spendWhere['tab_spend.promote_id'] = I('own_id');
}
empty(I('relation_game_id')) || $map['tab_game.relation_game_id'] = I('relation_game_id');
empty(I('sdk_version')) || $map['tab_game.sdk_version'] = I('sdk_version');
$serverField = '';
$serverJoin = '';
if (!empty(I('server_id'))) {
$serverField = ',tab_server.id as server_id';
$serverJoin = 'tab_server on tab_apply.game_id = tab_server.game_id';
$map['tab_server.id'] = I('server_id');
}
$data = M('Apply', 'tab_')
->field('tab_apply.game_id,tab_game.game_name,tab_game.sdk_version' . $serverField)
->join('tab_game on tab_apply.game_id = tab_game.id')
->join($serverJoin)//关联区服表
->where($map)
->group('tab_apply.game_id')
->order('tab_game.sort desc,tab_game.id desc')
->page($page, $row)
->select();
$count = M('Apply', 'tab_')
->join('tab_game on tab_apply.game_id = tab_game.id')
->join($serverJoin)//关联区服表
->where($map)
->group('tab_apply.game_id')
->select();
$count = count($count);
$nowTime = date('Y-m-d');
$initBegTime = date('Y-m-d', strtotime('-6 day', strtotime($nowTime)));
$initBegTime = empty(I('begtime')) ? $initBegTime : I('begtime');
$initEndTime = $nowTime;
$initEndTime = empty(I('endtime')) ? $initEndTime : I('endtime');
//分页
$parameter['p'] = I('get.p', 1);
$parameter['row'] = I('get.row');
empty(I('team_leader_id')) || $parameter['team_leader_id'] = I('team_leader_id');
empty(I('promote_id')) || $parameter['promote_id'] = I('promote_id');
empty(I('own_id')) || $parameter['own_id'] = I('own_id');
empty(I('relation_game_id')) || $parameter['relation_game_id'] = I('relation_game_id');
empty(I('sdk_version')) || $parameter['sdk_version'] = I('sdk_version');
empty(I('server_id')) || $parameter['server_id'] = I('server_id');
$parameter['begtime'] = $initBegTime;
$parameter['endtime'] = $initEndTime;
$allData = [];
if (!empty($data)) {
$userPlayInfoModel = M('UserPlayInfo', 'tab_');
$newWhere = '';
$begTime = strtotime($initBegTime);
$endTime = strtotime($initEndTime);
$userPlayInfoWhere['tab_user_play_info.play_time'] = ['between', [$begTime, $endTime + 86399]];
$userGameLoginWhere['tab_user_game_login_record.login_time'] = ['between', [$begTime, $endTime + 86399]];
$spendWhere['tab_spend.pay_time'] = ['between', [$begTime, $endTime + 86399]];
$spendWhere['tab_spend.pay_status'] = 1;
if (!empty(I('server_id'))) {
$userPlayInfoWhere['tab_user_play_info.server_id'] = I('server_id');
$userGameLoginWhere['tab_user_game_login_record.server_id'] = I('server_id');
$spendWhere['tab_spend.server_id'] = I('server_id');
$newWhere = ' and ti.server_id = ' . I('server_id');
}
foreach ($data as & $list) {
$userPlayInfoWhere['tab_user_play_info.game_id'] = $list['game_id'];
$list['role_num'] = $userPlayInfoModel
->where($userPlayInfoWhere)
->count();//创角数
$list['user_num'] = count($userPlayInfoModel
->field('tab_user_play_info.id')
->where($userPlayInfoWhere)
->group('tab_user_play_info.user_id')
->select());//创角用户
$newUserSql = '(select count(ti.id) from tab_user_play_info as ti where ti.user_id = tab_user_play_info.user_id and ti.game_id = tab_user_play_info.game_id and ti.play_time < ' . $begTime . $newWhere . ') as old_num';
$list['new_user_num'] = count($userPlayInfoModel
->field($newUserSql)
->where($userPlayInfoWhere)
->group('tab_user_play_info.user_id')
->having('old_num = 0')
->select());//新创角用户
$list['new_device_num'] = 0;//新创角设备
$newIpSql = '(select count(ti.id) from tab_user_play_info as ti where ti.play_ip = tab_user_play_info.play_ip and ti.game_id = tab_user_play_info.game_id and ti.play_time < ' . $begTime . $newWhere . ') as old_num';
$list['new_ip_num'] = count($userPlayInfoModel
->field($newIpSql)
->where($userPlayInfoWhere)
->group('tab_user_play_info.play_ip')
->having('old_num = 0')
->fetchSql(true)
->select());//新增创角IP
$list['login_user_num'] = count(M('UserGameLoginRecord', 'tab_')
->field('id')
->where($userGameLoginWhere)
->group('user_id')
->select());//登录用户数
$list['spend_user_num'] = count(M('Spend', 'tab_')
->field('tab_spend.id')
->where($spendWhere)
->group('tab_spend.user_id')
->select());//充值人数
$list['spend_num'] = M('Spend', 'tab_')
->where($spendWhere)
->count();//充值次数
$list['spend_all_amount'] = M('Spend', 'tab_')
->where($spendWhere)
->sum('tab_spend.pay_amount');//充值总额
$list['spend_all_amount'] = empty($list['spend_all_amount']) ? 0 : $list['spend_all_amount'];
$list['spend_cash'] = M('Spend', 'tab_')
->where($spendWhere)
->where(array('tab_spend.pay_way' => ['in', '1,2,3,4,5,6']))
->sum('tab_spend.pay_amount');//现金充值
$list['spend_cash'] = empty($list['spend_cash']) ? 0 : $list['spend_cash'];
$list['spend_generic'] = M('Spend', 'tab_')
->where($spendWhere)
->where(array('tab_spend.pay_way' => 0))
->sum('tab_spend.pay_amount');//通用币
$list['spend_generic'] = empty($list['spend_generic']) ? 0 : $list['spend_generic'];
$list['spend_binding'] = M('Spend', 'tab_')
->where($spendWhere)
->where(array('tab_spend.pay_way' => -1))
->sum('tab_spend.pay_amount');//绑定币
$list['spend_binding'] = empty($list['spend_binding']) ? 0 : $list['spend_binding'];
$list['spend_discount'] = 0;//折扣币
$list['spend_voucher'] = 0;//代金券
}
$allData['spend_num'] = M('Spend', 'tab_')
->where($spendWhere)
->count();//充值次数
$allData['spend_all_amount'] = M('Spend', 'tab_')
->where($spendWhere)
->sum('tab_spend.pay_amount');//充值总额
$allData['spend_all_amount'] = empty($list['spend_all_amount']) ? 0 : $list['spend_all_amount'];
$allData['spend_cash'] = M('Spend', 'tab_')
->where($spendWhere)
->where(array('tab_spend.pay_way' => ['in', '1,2,3,4,5,6']))
->sum('tab_spend.pay_amount');//现金充值
$allData['spend_cash'] = empty($list['spend_cash']) ? 0 : $list['spend_cash'];
$allData['spend_generic'] = M('Spend', 'tab_')
->where($spendWhere)
->where(array('tab_spend.pay_way' => 0))
->sum('tab_spend.pay_amount');//通用币
$allData['spend_generic'] = empty($list['spend_generic']) ? 0 : $list['spend_generic'];
$allData['spend_binding'] = M('Spend', 'tab_')
->where($spendWhere)
->where(array('tab_spend.pay_way' => -1))
->sum('tab_spend.pay_amount');//绑定币
$allData['spend_binding'] = empty($list['spend_binding']) ? 0 : $list['spend_binding'];
$allData['spend_discount'] = 0;//折扣币
$allData['spend_voucher'] = 0;//代金券
}
$serverData = $this->getServer(I('relation_game_id'), I('sdk_version'));
$thisParentPromoteId = getParentPromoteId(PID);//本账号上级渠道ID
$page = set_pagination($count, $row, $parameter);
if ($page) {
$this->assign('_page', $page);
}
$this->assign('meta_title', '数据汇总列表');
$this->assign('listData', $data);
$this->assign('allData', $allData);
$this->assign('count', $count);
$this->assign('setdate', date("Y-m-d"));
$this->assign('initBegTime', $initBegTime);
$this->assign('initEndTime', $initEndTime);
$this->assign('serverData', $serverData['data']);
$this->assign('thisParentPromoteId', $thisParentPromoteId);
$this->assign('pID', PID);
$this->display();
}
public function dabiao_game()
{
if (isset($_REQUEST['game_id']) & & !empty($_REQUEST['game_id'])) {
$game_id = M('game', 'tab_')->field('id')->where(array('relation_game_id' => $_REQUEST['game_id']))->select();
$game_id = array_map('array_shift', $game_id);
$gmap['game_id'] = array('in', $game_id);
//unset($_REQUEST['game_id']);
}
if (isset($_REQUEST['server_name']) & & !empty($_REQUEST['server_name'])) {
$dmap['server_name'] = $_REQUEST['server_name'];
unset($_REQUEST['server_name']);
}
if (isset($_REQUEST['server_id']) & & !empty($_REQUEST['server_id'])) {
$dmap['server_id'] = $_REQUEST['server_id'];
unset($_REQUEST['server_id']);
}
if (isset($_REQUEST['game_level']) & & !empty($_REQUEST['game_level'])) {
$gamedata = M('game', 'tab_')->field('first_level,first_level_name,second_level_name,second_level,third_level,third_level_name')->where(array('relation_game_id' => $_REQUEST['game_id']))->find();
if ($gamedata['first_level_name'] == $_REQUEST['game_level']) {
$dmap['role_level'] = array('egt', $gamedata['first_level']);
} elseif ($gamedata['second_level_name'] == $_REQUEST['game_level']) {
$dmap['role_level'] = array('egt', $gamedata['second_level']);
} elseif ($gamedata['third_level_name'] == $_REQUEST['game_level']) {
$dmap['role_level'] = array('egt', $gamedata['third_level']);
}
unset($_REQUEST['game_level']);
}
if (isset($_REQUEST['begtime']) & & isset($_REQUEST['endtime']) & & !empty($_REQUEST['begtime']) & & !empty($_REQUEST['endtime'])) {
$dmap['play_time'] = array('BETWEEN', [strtotime($_REQUEST['begtime']), strtotime($_REQUEST['endtime']) + 86400]);
unset($_REQUEST['begtime']);
unset($_REQUEST['endtime']);
} elseif (isset($_REQUEST['begtime']) & & !empty($_REQUEST['begtime'])) {
$dmap['play_time'] = array('BETWEEN', [strtotime($_REQUEST['begtime']), date("Y-m-d", strtotime("-1 day"))]);
unset($_REQUEST['begtime']);
} elseif (isset($_REQUEST['endtime']) & & !empty($_REQUEST['endtime'])) {
$dmap['play_time'] = array('ELT', strtotime($_REQUEST['endtime']) + 86400);
unset($_REQUEST['endtime']);
}
$promote = $_REQUEST['promote_id'];
if (PID == $promote) {
} else {
$pids = get_prmoote_chlid_account($promote);
$pro_arr = array_column($pids, 'id');
$pro_arr[] = $promote;
$promote = implode(',', $pro_arr);
}
$game = M('apply', 'tab_')
->field('game_id,game_name')
->where($gmap)
->where(array('promote_id' => array('in', $promote), 'status' => 1))
->group('game_id')
->select();
$game_count = count($game);
for ($y = 0; $y < = $game_count; $y++) {
$game_level = M('game', 'tab_')->field('first_level')->where(array('id' => $game[$y]['game_id']))->find();
if ($dmap['role_level']) {
$game_level['first_level'] = $dmap['role_level'][1];
}
$gdabiao = M('user_play_info', 'tab_')
->field('user_id')
->where($dmap)
->where(array('game_id' => $game[$y]['game_id'], 'role_level' => array('egt', $game_level['first_level']), 'promote_id' => array('in', $promote)))
->group('user_id')
->select();
$gdabiao = count($gdabiao);
$game[$y]['num'] = $gdabiao;
if ($game[$y]['num'] == 0) {
unset($game[$y]);
}
}
$this->assign('list_data', $game);
$this->display();
}
private function map_game_list()
{
$uid = session('promote_auth.pid');
$map['tab_game.game_status'] = 1;
$map['tab_apply.status'] = 1;
$promote = $this->get_child_promote();
array_push($promote, $uid);
$map['tab_promote.id'] = array('in', $promote);
$data = M('game', 'tab_')
->field('relation_game_name,relation_game_id')
->join('tab_apply on tab_apply.game_id = tab_game.id')
->join('tab_promote ON tab_apply.promote_id = tab_promote.id')
->where($map)
->group('relation_game_id')
->select();
$this->assign("game_list", $data);
}
public function getServerAjax()
{
$serverData = $this->getServer(I('relation_game_id'), I('sdk_version'));
$this->ajaxReturn($serverData);
}
public function getServer($relationGameId, $sdkVersion)
{
$result['status'] = 0;
$result['data'] = [];
if (empty($relationGameId) & & empty($sdkVersion)) {
return $result;
}
empty($relationGameId) || $map['relation_game_id'] = $relationGameId;
empty($sdkVersion) || $map['sdk_version'] = $sdkVersion;
$gameIds = M('Game', 'tab_')
->where($map)
->getField('id', true);
if (empty($gameIds)) {
return $result;
}
$gameIds = implode(',', $gameIds);
$where['game_id'] = ['in', $gameIds];
$where['show_status'] = 1;
$serverData = M('Server', 'tab_')
->field('id,server_name')
->where($where)
->select();
$result['status'] = 1;
$result['data'] = $serverData;
return $result;
}
public function get_child_promote()
{
$uid = session('promote_auth.pid');
$map['parent_id'] = $uid;
$map['status'] = 1;
$data = M('promote', 'tab_')
->field('id')
->where($map)
->select();
return array_map('array_shift', $data);
}
//查看角色详情
public function viewRole($p = 0)
{
$promoteId = D('User')->where('id = %d', I('get.id'))->getField('promote_id');
$permission = hasPromotePermission(PID, $promoteId);//是否有该推广员权限
if ($permission === false) {
$this->error('无推广员权限');
}
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据arraypage
if (isset($_REQUEST['row'])) {
$row = $_REQUEST['row'];
} else {
$row = 10;
}
if (!empty(I('begtime')) & & empty(I('endtime'))) {
$map['tab_user_play_info.play_time'] = ['egt', strtotime(I('begtime'))];
} elseif (empty(I('begtime')) & & !empty(I('endtime'))) {
$map['tab_user_play_info.play_time'] = ['elt', strtotime(I('endtime')) + 86399];
} elseif (!empty(I('begtime')) & & !empty(I('endtime'))) {
$map['tab_user_play_info.play_time'] = ['between', [strtotime(I('begtime')), strtotime(I('endtime')) + 86399]];
}
empty(I('relation_game_id')) || $map['tab_game.relation_game_id'] = I('relation_game_id');
empty(I('sdk_version')) || $map['tab_game.sdk_version'] = I('sdk_version');
empty(I('server_id')) || $map['tab_user_play_info.server_id'] = I('server_id');
empty(I('role_name')) || $map['tab_user_play_info.role_name'] = ['like', '%' . I('role_name') . '%'];
$map['tab_user_play_info.user_id'] = I('get.id');
$map['tab_user_play_info.promote_id'] = $promoteId;
$data = M('user_play_info', 'tab_')
->field('tab_user_play_info.user_account,tab_user_play_info.game_name,tab_user_play_info.sdk_version,tab_user_play_info.play_time,tab_user_play_info.server_name,tab_user_play_info.role_name')
->join('tab_game on tab_user_play_info.game_id = tab_game.id')
->where($map)
->order('tab_user_play_info.id desc')
->page($page, $row)
->select();
$count = M('user_play_info', 'tab_')
->where($map)
->join('tab_game on tab_user_play_info.game_id = tab_game.id')
->count();
if (!empty($data)) {
foreach ($data as & $list) {
$list['user_account'] = substr($list['user_account'], 0, 2) . '******' . substr($list['user_account'], 8);
}
}
//分页
$parameter['p'] = I('get.p', 1);
$parameter['row'] = I('get.row');
$parameter['id'] = I('get.id');
empty(I('relation_game_id')) || $parameter['relation_game_id'] = I('relation_game_id');
empty(I('sdk_version')) || $parameter['sdk_version'] = I('sdk_version');
empty(I('server_id')) || $parameter['server_id'] = I('server_id');
empty(I('role_name')) || $parameter['role_name'] = I('role_name');
empty(I('begtime')) || $parameter['begtime'] = I('begtime');
empty(I('endtime')) || $parameter['endtime'] = I('endtime');
$page = set_pagination($count, $row, $parameter);
if ($page) {
$this->assign('_page', $page);
}
$serverData = $this->getServer(I('relation_game_id'), I('sdk_version'));
$this->assign('listData', $data);
$this->assign('count', $count);
$this->assign('setdate', date("Y-m-d"));
$this->assign('serverData', $serverData['data']);
$this->meta_title = '角色详情';
$this->display('view_role');
}
public function users()
{
$promote = $this->getLoginPromote();
$promoteId = $promote['id'];
$map = [
'_logic' => 'or',
'id' => $promoteId,
'parent_id' => $promoteId,
'grand_id' => $promoteId,
];
$ids = M('promote', 'tab_')->where($map)->getField('id', true);
$promotes = [];
$groupPromotes = [];
if ($promote['parent_id'] == 0) {
$groupPromotes = M('promote', 'tab_')->field(['id', 'account', 'real_name'])->where(['parent_id' => $promoteId])->select();
$promotes = M('promote', 'tab_')->field(['id', 'account', 'real_name'])->where(['grand_id' => $promoteId])->select();
}
if ($promote['parent_id'] > 0 & & $promote['grand_id'] == 0) {
$promotes = M('promote', 'tab_')->field(['id', 'account', 'real_name'])->where(['parent_id' => $promoteId])->select();
}
$fields = [
'id', 'account', 'promote_account', 'promote_id', 'device_number', 'register_time', 'register_ip', 'login_time', 'login_ip', 'device_type'
];
$query = M('user', 'tab_')->field($fields)->where(['promote_id' => ['in', $ids]]);
list($records, $pagination, $count) = $this->paginate($query);
$this->assign('promotes', $promotes);
$this->assign('groupPromotes', $groupPromotes);
$this->assign('records', $records);
$this->assign('pagination', $pagination);
$this->assign('count', $count);
$this->display();
}
public function userRoles()
{
$gameId = I('game_id', 0);
$serverId = I('server_id', 0);
$isSelf = I('is_self', 0);
$roleName = I('role_name', '');
$userAccount = I('user_account', '');
$promoteId = I('promote_id', 0);
$sdkVersion = I('sdk_version', 0);
$roleLevelBegin = intval(I('role_level_begin', 0));
$roleLevelEnd = intval(I('role_level_end', 0));
$headmanPromoteId = I('headman_promote_id', 0);
$playTime = I('play_time', '');
$promote = $this->getLoginPromote();
$map = [
'_logic' => 'or',
'id' => $promote['id'],
'parent_id' => $promote['id'],
'grand_id' => $promote['id'],
];
$ids = M('promote', 'tab_')->where($map)->getField('id', true);
$promotes = [];
$groupPromotes = $this->getGroupPromotes($promote);
if ($promote['parent_id'] > 0 & & $promote['grand_id'] == 0) {
$promotes = $this->getNormalPromotes($promote);
}
$map = [];
$map = ['promote_id' => ['in', $ids]];
if ($gameId != 0) {
$map['game_id'] = $gameId;
}
if ($serverId != 0) {
$map['serverId'] = $serverId;
}
if ($roleName != '') {
$map['role_name'] = ['like', '%' . $roleName . '%'];
}
if ($userAccount != '') {
$map['user_acount'] = ['like', '%' . $userAccount . '%'];
}
if ($sdkVersion != 0) {
$map['sdk_version'] = $sdkVersion;
}
if ($roleLevelBegin != 0 & & $roleLevelEnd == 0) {
$map['role_level'] = ['egt', $roleLevelBegin];
} elseif ($roleLevelEnd != 0 & & $roleLevelBegin == 0) {
$map['role_level'] = ['elt', $roleLevelEnd];
} elseif ($roleLevelEnd != 0 & & $roleLevelBegin != 0) {
$map['role_level'] = ['between', [$roleLevelBegin, $roleLevelEnd]];
}
if ($playTime != '') {
$playTimeRow = explode(' 至 ', $playTime);
$playTimeBegin = 0;
$playTimeEnd = 0;
if (count($playTimeRow) == 2) {
$playTimeBegin = strtotime($playTimeRow[0] . ' 00:00:00');
$playTimeEnd = strtotime($playTimeRow[1] . ' 23:59:59');
} else {
$playTimeBegin = strtotime($playTimeRow[0] . ' 00:00:00');
$playTimeEnd = strtotime($playTimeRow[0] . ' 23:59:59');
}
$map['play_time'] = ['between', [$playTimeBegin, $playTimeEnd]];
}
if ($isSelf) {
$map['promote_id'] = $promote['id'];
} else {
if ($headmanPromoteId != 0) {
$map['promote_id'] = $headmanPromoteId;
}
if ($promoteId != 0) {
$map['promote_id'] = $promoteId;
}
}
$query = M('user_play_info', 'tab_')->where($map);
list($records, $pagination, $count) = $this->paginate($query);
$games = $this->getGamesByPromote($promote);
$this->assign('promotes', $promotes);
$this->assign('groupPromotes', $groupPromotes);
$this->assign('games', $games);
$this->assign('records', $records);
$this->assign('pagination', $pagination);
$this->assign('count', $count);
$this->display('userRoles');
}
public function userRecharges()
{
$gameId = I('game_id', 0);
$serverId = I('server_id', 0);
$isSelf = I('is_self', 0);
$roleName = I('role_name', '');
$userAccount = I('user_account', '');
$promoteId = I('promote_id', 0);
$sdkVersion = I('sdk_version', 0);
$headmanPromoteId = I('headman_promote_id', 0);
$promote = $this->getLoginPromote();
$map = [
'_logic' => 'or',
'id' => $promote['id'],
'parent_id' => $promote['id'],
'grand_id' => $promote['id'],
];
$ids = M('promote', 'tab_')->where($map)->getField('id', true);
$promotes = [];
$groupPromotes = $this->getGroupPromotes($promote);
if ($promote['parent_id'] > 0 & & $promote['grand_id'] == 0) {
$promotes = $this->getNormalPromotes($promote);
}
$map = $spendMap = ['promote_id' => ['in' => $ids]];
if ($gameId != 0) {
$map['game_id'] = $gameId;
}
if ($serverId != 0) {
$map['serverId'] = $serverId;
}
if ($roleName != '') {
$map['role_name'] = ['like', '%' . $roleName . '%'];
}
if ($userAccount != '') {
$map['user_acount'] = ['like', '%' . $userAccount . '%'];
}
if ($sdkVersion != 0) {
$map['sdk_version'] = $sdkVersion;
}
if ($isSelf) {
$map['promote_id'] = $promote['id'];
$spendMap['promote_id'] = $promote['id'];
} else {
if ($headmanPromoteId != 0) {
$map['promote_id'] = $headmanPromoteId;
$spendMap['promote_id'] = $headmanPromoteId;
}
if ($promoteId != 0) {
$map['promote_id'] = $promoteId;
$spendMap['promote_id'] = $promoteId;
}
}
$query = M('user_play_info', 'tab_')->where($map);
list($roles, $pagination, $count) = $this->paginate($query);
$roleIds = array_column($roles, 'role_id');
$spendMap['pay_status'] = 1;
$spendMap['pay_game_status'] = 1;
if (count($roleIds) > 0) {
$spendMap['game_player_id'] = ['in', $roleIds];
} else {
$spendMap['_string'] = '1< >1';
}
$allRecharges = M('spend', 'tab_')->field('count(*) count, sum(cost) cost, game_player_id')->where($gameMap)->group('game_player_id')->select();
$allRecords = [];
foreach ($allRecharges as $recharge) {
$allRecords[$recharge['game_player_id']] = $recharge;
}
$map['pay_time'] = ['between', [strtotime(date('Y-m-d 00:00:00')), strtotime(date('Y-m-d 23:59:59'))]];
$todayRecharges = M('spend', 'tab_')->field('sum(cost) cost, game_player_id')->where($map)->group('game_player_id')->select();
$todayRecords = [];
foreach ($todayRecharges as $recharge) {
$todayRecords[$recharge['game_player_id']] = $recharge;
}
$records = [];
foreach ($roles as $role) {
$records[] = [
'user_account' => $role['user_account'],
'game_name' => $role['game_name'],
'role_name' => $role['role_name'],
'role_id' => $role['role_id'],
'role_level' => $role['role_level'],
'server_id' => $role['server_id'],
'server_name' => $role['server_name'],
'recharge_cost' => isset($allRecords[$role['role_id']]) ? round(floatval($allRecords[$role['role_id']]['cost']), 2) : 0,
'recharge_count' => isset($allRecords[$role['role_id']]) ? $allRecords[$role['role_id']]['count'] : 0,
'recharge_cost_today' => isset($todayRecords[$role['role_id']]) ? round(floatval($todayRecords[$role['role_id']]['cost']), 2) : 0,
'play_time' => $role['play_time'],
'play_ip' => $role['play_ip'],
'promote_id' => $role['promote_id'],
'promote_account' => $role['promote_account'],
'sdk_version' => $role['sdk_version'],
'unlogin_day' => intval((strtotime(date('Y-m-d 00:00:00')) - strtotime(date('Y-m-d 00:00:00', $role['play_time']))) / (24 * 3600))
];
}
$games = $this->getGamesByPromote($promote);
$this->assign('games', $games);
$this->assign('promotes', $promotes);
$this->assign('groupPromotes', $groupPromotes);
$this->assign('records', $records);
$this->assign('pagination', $pagination);
$this->assign('count', $count);
$this->display('userRecharges');
}
private function getGamesByPromote($promote)
{
return M('apply', 'tab_')->field(['game_id', 'game_name'])->where(['promote_id' => $promote['id']])->select();
}
private function getGroupPromotes($promote)
{
$promotes = [];
if ($promote['parent_id'] == 0) {
$promotes = M('promote', 'tab_')->field(['id', 'account', 'real_name'])->where(['parent_id' => $promote['id']])->select();
}
return $promotes;
}
private function getNormalPromotes($promote)
{
$promotes = [];
if ($promote['parent_id'] > 0 & & $promote['grand_id'] == 0) {
$promotes = M('promote', 'tab_')->field(['id', 'account', 'real_name'])->where(['parent_id' => $promote['id']])->select();
} elseif ($promote['parent_id'] == 0) {
$promotes = M('promote', 'tab_')->field(['id', 'account', 'real_name'])->where(['grand_id' => $promote['id']])->select();
}
return $promotes;
}
public function getGameServers()
{
$gameId = I('game_id', 0);
$servers = M('server', 'tab_')->field(['id', 'server_name'])->where(['game_id' => $gameId])->select();
$this->ajaxReturn([
'status' => 1,
'msg' => '成功',
'data' => ['servers' => $servers]
]);
}
public function getSubPromotes()
{
$promoteId = I('promote_id', 0);
$promotes = M('promote', 'tab_')->field(['id', 'account'])->where(['parent_id' => $promoteId])->select();
$this->ajaxReturn([
'status' => 1,
'msg' => '成功',
'data' => ['promotes' => $promotes]
]);
}
/**
* [充值详细信息]
* @param $id [充值id]
*/
public function viewSpendDetailed($id)
{
$spendData = array();
if ($id > 0) {
$promoteId = D('Spend')->where('id = %d', $id)->getField('promote_id');
$permission = hasPromotePermission(PID, $promoteId);//是否有该推广员权限
if ($permission) {
$map['id'] = $id;
$spendData = D('Spend')->where($map)->find();
$spendData['pay_status'] = ($spendData['pay_status'] == 1) ? '成功' : '失败';
}
}
$this->assign('list_data', $spendData);
$this->display('view_spend_detailed');
}
}