推广后台->数据管理->每日概况|数据汇总 -- 更新

master
chenxiaojun 5 years ago
parent 8633efd7d6
commit b1b10645fc

@ -61,6 +61,28 @@ class SpendRepository {
return $conditions;
}
private function getDayGroupConditionsNew($params)
{
$beginTime = $params['begin_time'] ?? 0;
$endTime = $params['end_time'] ?? 0;
$gameId = $params['game_id'] ?? 0;
$serverId = $params['server_id'] ?? 0;
$ids = $params['promote_id'] ?? [];
$conditions = [];
$conditions['pay_status'] = 1;
$conditions['promote_id'] = ['in', $ids];
$conditions['pay_time'] = ['between', [$beginTime, $endTime]];
$conditions['game_id'] = $gameId > 0 ? $gameId : ['gt', 0];
if (isset($params['server_id'])) {
$conditions['server_id'] = $serverId;
}
if (isset($params['pay_way'])) {
$conditions['pay_way'] = $params['pay_way'];
}
return $conditions;
}
/**
* 付费游戏数
*/
@ -84,6 +106,17 @@ class SpendRepository {
return $this->assembleRecords($items, $dayList, 'amount');
}
/**
* 按天统计类型付款总额
*/
public function getPayAmountGroupByDayAndType($params) {
$dayList = $params['dayList'] ?? [];
$conditions = $this->getDayGroupConditionsNew($params);
$field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as day, sum(pay_amount) as amount';
$items = M('spend', 'tab_')->field($field)->where($conditions)->group('day')->select();
return $this->assembleRecords($items, $dayList, 'amount');
}
/**
* 按游戏统计付款总额
*/
@ -106,6 +139,17 @@ class SpendRepository {
return $this->assembleRecords($items, $dayList, 'count');
}
/**
* 按天统计付款次数
*/
public function getPayCountGroupByDay($params) {
$dayList = $params['dayList'] ?? [];
$conditions = $this->getDayGroupConditions($params);
$field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as day, count(*) count';
$items = M('spend', 'tab_')->field($field)->where($conditions)->group('day')->select();
return $this->assembleRecords($items, $dayList, 'count');
}
/**
* 游戏统计付款用户数
*/

@ -1,7 +1,9 @@
<?php
namespace Base\Repository;
class UserRepository {
class UserRepository
{
public function __construct()
{
@ -23,6 +25,15 @@ class UserRepository {
return $records;
}
private function setKeys($params, $alias)
{
$records = [];
foreach ($params as $key => $value) {
$records[$alias . '.' . $key] = $value;
}
return $records;
}
private function getDayGroupConditions($params)
{
$beginTime = $params['begin_time'] ?? 0;
@ -59,10 +70,32 @@ class UserRepository {
return $conditions;
}
private function getCreateRoleConditions($params)
{
$beginTime = $params['begin_time'] ?? 0;
$endTime = $params['end_time'] ?? 0;
$gameId = $params['game_id'] ?? 0;
$serverId = $params['server_id'] ?? 0;
$ids = $params['promote_id'] ?? [];
$conditions = [];
$conditions['promote_id'] = ['in', $ids];
$conditions[$params['time_column']] = ['between', [$beginTime, $endTime]];
if ($gameId > 0) {
$conditions['game_id'] = $gameId;
}
if ($serverId > 0) {
$conditions['server_id'] = $serverId;
}
return $conditions;
}
/**
* 按照时间分组统计登录总数
*/
public function getLoginCountGroupByDay($params) {
public function getLoginCountGroupByDay($params)
{
$dayList = $params['dayList'] ?? [];
$params['time_column'] = 'login_time';
$conditions = $this->getDayGroupConditions($params);
@ -77,7 +110,8 @@ class UserRepository {
/**
* 按照游戏分组统计登录总数
*/
public function getLoginCountGroupByGame($params) {
public function getLoginCountGroupByGame($params)
{
$gameIds = $params['game_ids'] ?? [];
$params['time_column'] = 'login_time';
$conditions = $this->getGameGroupConditions($params);
@ -92,7 +126,8 @@ class UserRepository {
/**
* 按照时间分组统计注册总数
*/
public function getRegisterCountGroupByDay($params) {
public function getRegisterCountGroupByDay($params)
{
$dayList = $params['dayList'] ?? [];
$params['time_column'] = 'register_time';
$conditions = $this->getDayGroupConditions($params);
@ -107,7 +142,8 @@ class UserRepository {
/**
* 按照游戏分分组统计注册总数
*/
public function getRegisterCountGroupByGame($params) {
public function getRegisterCountGroupByGame($params)
{
$gameIds = $params['game_ids'] ?? [];
$params['time_column'] = 'register_time';
$conditions = $this->getGameGroupConditions($params);
@ -129,41 +165,161 @@ class UserRepository {
* @return array 详细数据
* @author 鹿文学
*/
public function getRatentionRate($newslist,$game_id=0,$promote_id=0,$flag=1) {
public function getRatentionRate($newslist, $game_id = 0, $promote_id = 0, $flag = 1)
{
$map['lock_status']=1;
if($game_id>0) {
$map['lock_status'] = 1;
if ($game_id > 0) {
$map['up.game_id'] = $game_id;
}
$map['tab_user.promote_id'] = is_numeric($promote_id)?$promote_id:array('in',$promote_id);
$map['tab_user.promote_id'] = is_numeric($promote_id) ? $promote_id : array('in', $promote_id);
$group = 'up.login_time';
$fieldname = 'retention_rate'.$flag;
$fieldname = 'retention_rate' . $flag;
foreach ($newslist as $value) {
$ct1 = strtotime("+$flag day",strtotime($value['time']));
$ct2 = strtotime("+1 day",$ct1)-1;
$ct1 = strtotime("+$flag day", strtotime($value['time']));
$ct2 = strtotime("+1 day", $ct1) - 1;
$map[$group] = array(array('egt',$ct1),array('elt',$ct2));
$map[$group] = array(array('egt', $ct1), array('elt', $ct2));
$map['user_id']=array('in',$value['id']);
$count = count(explode(',',$value['id']));
$map['user_id'] = array('in', $value['id']);
$count = count(explode(',', $value['id']));
$d = $this
->field('count(distinct up.user_id) as '.$fieldname.' ,FROM_UNIXTIME(up.login_time,"%Y-%m-%d") as play_time')
->join('tab_user_login_record up on tab_user.id=up.user_id','right')
->field('count(distinct up.user_id) as ' . $fieldname . ' ,FROM_UNIXTIME(up.login_time,"%Y-%m-%d") as play_time')
->join('tab_user_login_record up on tab_user.id=up.user_id', 'right')
->where($map)
->group('play_time')
->select();
if ($d)
$data[]=array(
"play_time"=>$value['time'],
$fieldname=>($d[0][$fieldname]==0)?0:sprintf("%.2f",($d[0][$fieldname]/$count)*100)
$data[] = array(
"play_time" => $value['time'],
$fieldname => ($d[0][$fieldname] == 0) ? 0 : sprintf("%.2f", ($d[0][$fieldname] / $count) * 100)
);
}
return $data;
}
/**
* 按照时间统计创角数
*/
public function getCreateRoleCountByDay($params)
{
$dayList = $params['dayList'] ?? [];
$params['time_column'] = 'create_time';
$conditions = $this->getCreateRoleConditions($params);
$items = M('user_play_info', 'tab_')->field('count(*) count, FROM_UNIXTIME(create_time, "%Y-%m-%d") as day')
->where($conditions)
->group('day')
->select();
return $this->assembleRecords($items, $dayList, 'count');
}
/**
* 按照时间统计创角用户(去重)
*/
public function getCreateRoleUserCountByDay($params)
{
$dayList = $params['dayList'] ?? [];
$params['time_column'] = 'create_time';
$conditions = $this->getCreateRoleConditions($params);
$items = M('user_play_info', 'tab_')->field('count(distinct game_id,user_id) count, FROM_UNIXTIME(create_time, "%Y-%m-%d") as day')
->where($conditions)
->group('day')
->select();
return $this->assembleRecords($items, $dayList, 'count');
}
/**
* 按照时间统计新创角用户(去重)
*/
public function getNewCreateRoleUserCountByDay($params)
{
$dayList = $params['dayList'] ?? [];
$params['time_column'] = 'create_time';
$conditions = $this->getCreateRoleConditions($params);
$conditionsSql = $conditions;
unset($conditionsSql['begin_time']);
unset($conditionsSql['end_time']);
$alias = 'ti';
$conditionsSql = $this->setKeys($conditionsSql, $alias);
$model = M('user_play_info', 'tab_');
$sql = $model->alias($alias)
->where($conditionsSql)
->where("ti.user_id = user_id and ti.game_id = game_id and ti.create_time < " . $params['begin_time'])
->fetchSql(true)
->count();
$items = $model->field("count(distinct game_id,user_id) count, FROM_UNIXTIME(create_time, '%Y-%m-%d') as day,
(" . $sql . ") as num")
->where($conditions)
->group("day")
->having('num = 0')
->select();
return $this->assembleRecords($items, $dayList, 'count');
}
/**
* 按照时间统计新创角设备(去重)
*/
public function getNewCreateRoleDeviceCountByDay($params)
{
$dayList = $params['dayList'] ?? [];
$params['time_column'] = 'create_time';
$conditions = $this->getCreateRoleConditions($params);
$conditionsSql = $conditions;
unset($conditionsSql['begin_time']);
unset($conditionsSql['end_time']);
$alias = 'ti';
$conditionsSql = $this->setKeys($conditionsSql, $alias);
$model = M('user_play_info', 'tab_');
$sql = $model->alias($alias)
->where($conditionsSql)
->where("ti.create_device_number = create_device_number and ti.game_id = game_id and ti.create_time < " . $params['begin_time'])
->fetchSql(true)
->count();
$items = $model->field("count(distinct game_id,create_device_number) count, FROM_UNIXTIME(create_time, '%Y-%m-%d') as day,
(" . $sql . ") as num")
->where($conditions)
->group("day")
->having('num = 0')
->select();
return $this->assembleRecords($items, $dayList, 'count');
}
/**
* 按照时间统计新创角IP(去重)
*/
public function getNewCreateRoleIpCountByDay($params)
{
$dayList = $params['dayList'] ?? [];
$params['time_column'] = 'create_time';
$conditions = $this->getCreateRoleConditions($params);
$conditionsSql = $conditions;
unset($conditionsSql['begin_time']);
unset($conditionsSql['end_time']);
$alias = 'ti';
$conditionsSql = $this->setKeys($conditionsSql, $alias);
$model = M('user_play_info', 'tab_');
$sql = $model->alias($alias)
->where($conditionsSql)
->where("ti.create_ip = create_ip and ti.game_id = game_id and ti.create_time < " . $params['begin_time'])
->fetchSql(true)
->count();
$items = $model->field("count(distinct game_id,create_ip) count, FROM_UNIXTIME(create_time, '%Y-%m-%d') as day,
(" . $sql . ") as num")
->where($conditions)
->group("day")
->having('num = 0')
->select();
return $this->assembleRecords($items, $dayList, 'count');
}
}

@ -47,15 +47,15 @@ class QueryController extends BaseController
// }
$map1['chain'] = ['like','%'.PID.'/'.'%'];
$rs = M('promote','tab_')->where($map1)->field('id,account,nickname')->select();
$map1['chain'] = ['like', '%' . PID . '/' . '%'];
$rs = M('promote', 'tab_')->where($map1)->field('id,account,nickname')->select();
$childPromoteIds = '';
if(empty($rs)) {
if (empty($rs)) {
$map['tab_spend.promote_id'] = PID;
}else {
} else {
foreach ($rs as $rsKey => $rsValue) {
$id = $rsValue['id'];
$childPromoteIds .= $id.',';
$childPromoteIds .= $id . ',';
}
$childPromoteIds = rtrim($childPromoteIds, ',');
$childPromoteIds .= ',' . PID;
@ -70,18 +70,18 @@ class QueryController extends BaseController
'chain' => ['like', $queryPromote['chain'] . $queryPromote['id'] . '/%']
];
$ids = M('promote', 'tab_')->where($map2)->getField('id', true);
if(empty($ids)) {
if (empty($ids)) {
$ids = array();
}
if(empty($levelPromote)) {
array_push($ids,PID);
if (empty($levelPromote)) {
array_push($ids, PID);
}
array_push($ids,$queryPromote['id']);
array_push($ids, $queryPromote['id']);
if (!empty($ids)) {
$map['tab_spend.promote_id'] = ['in',$ids];
$map['tab_spend.promote_id'] = ['in', $ids];
}else {
} else {
$map['_string'] = '1<>1';
}
@ -209,15 +209,15 @@ class QueryController extends BaseController
// $map['tab_user.promote_id'] = ['in', $childPromoteIds];
// }
// $map['tab_user.promote_id'] = ['like','%'.PID.'/'.'%'];
$map1['chain'] = ['like','%'.PID.'/'.'%'];
$rs = M('promote','tab_')->where($map1)->field('id,account,nickname')->select();
$map1['chain'] = ['like', '%' . PID . '/' . '%'];
$rs = M('promote', 'tab_')->where($map1)->field('id,account,nickname')->select();
$childPromoteIds = '';
if(empty($rs)) {
if (empty($rs)) {
$map['tab_user.promote_id'] = PID;
}else {
} else {
foreach ($rs as $rsKey => $rsValue) {
$id = $rsValue['id'];
$childPromoteIds .= $id.',';
$childPromoteIds .= $id . ',';
}
$childPromoteIds = rtrim($childPromoteIds, ',');
$childPromoteIds .= ',' . PID;
@ -233,18 +233,18 @@ class QueryController extends BaseController
'chain' => ['like', $queryPromote['chain'] . $queryPromote['id'] . '/%']
];
$ids = M('promote', 'tab_')->where($map2)->getField('id', true);
if(empty($ids)) {
if (empty($ids)) {
$ids = array();
}
if(empty($levelPromote)) {
array_push($ids,PID);
if (empty($levelPromote)) {
array_push($ids, PID);
}
array_push($ids,$queryPromote['id']);
array_push($ids, $queryPromote['id']);
if (!empty($ids)) {
$map['tab_user.promote_id'] = ['in',$ids];
$map['tab_user.promote_id'] = ['in', $ids];
}else {
} else {
$map['_string'] = '1<>1';
}
@ -1080,56 +1080,58 @@ class QueryController extends BaseController
$loginPromote = $this->getLoginPromote();
$map = [];
$ownId = intval(I('own_id'), 0);//本账号
if ($ownId) {
$userPlayInfoWhere['tab_user_play_info.promote_id'] = $queryPromote['id'];
$userPlayInfoWhere2['ti.promote_id'] = $queryPromote['id'];
$userGameLoginWhere['tab_user_game_login_record.promote_id'] = $queryPromote['id'];
$spendWhere['tab_spend.promote_id'] = $queryPromote['id'];
$params['promote_id'] = $queryPromote['id'];
} else {
$map['chain'] = ['like', $queryPromote['chain'] . $queryPromote['id'] . '/%'];
$ids = M('promote', 'tab_')->where($map)->getField('id', true);
$ids[] = $queryPromote['id'];
$ids = implode(',', $ids);
$userPlayInfoWhere['tab_user_play_info.promote_id'] = ['in', $ids];
$userPlayInfoWhere2['ti.promote_id'] = ['in', $ids];
$userGameLoginWhere['tab_user_game_login_record.promote_id'] = ['in', $ids];
$spendWhere['tab_spend.promote_id'] = ['in', $ids];
$params['promote_id'] = $ids;
}
if ($relationGameId > 0 || $serverId > 0) {
if ($sdkVersion > 0) {
$map['sdk_version'] = $sdkVersion;
}
$map = [];
$map['_string'] = '1 = 1';
$join = '';
if ($relationGameId > 0) {
$map['tab_game.relation_game_id'] = I('relation_game_id');
$join = 'tab_game on game_id = tab_game.id';
$map = ['relation_game_id' => $relationGameId];
}
if ($sdkVersion > 0) {
$userPlayInfoWhere['tab_user_play_info.sdk_version'] = $sdkVersion;
$userPlayInfoWhere2['ti.sdk_version'] = $sdkVersion;
$userGameLoginWhere['tab_user_game_login_record.sdk_version'] = $sdkVersion;
$spendWhere['tab_spend.sdk_version'] = $sdkVersion;
$gameIds = M('Game', 'tab_')->where($map)->getField('id', true);
if (empty($gameIds)) {
$params['_string'] = '1=2';
} else {
$gameIds = implode(',', $gameIds);
$params['game_id'] = ['in', $gameIds];
}
$spendWhere['tab_spend.pay_status'] = 1;
if ($serverId > 0) {
$userPlayInfoWhere['tab_user_play_info.server_id'] = $serverId;
$userPlayInfoWhere2['ti.server_id'] = $serverId;
$userGameLoginWhere['tab_user_game_login_record.server_id'] = $serverId;
$spendWhere['tab_spend.server_id'] = $serverId;
}
$userPlayInfoModel = M('UserPlayInfo', 'tab_');
$params['begin_time'] = $begTime;
$params['end_time'] = $endTime;
$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);
}
$dayList = $this->getDayList($begTime, $endTime);
$params['dayList'] = $dayList;
$records = [];
if (intval($endTime - $begTime) / (24 * 3600) <= 30) {
$userRepository = new UserRepository();
$spendRepository = new SpendRepository();
$roleNumList = $userRepository->getCreateRoleCountByDay($params);//创角数
$userNumList = $userRepository->getCreateRoleUserCountByDay($params);//创角用户
$newUserNumList = $userRepository->getNewCreateRoleUserCountByDay($params);//新创角用户
$newDeviceNumList = $userRepository->getNewCreateRoleDeviceCountByDay($params);//新创角设备
$newIpNumList = $userRepository->getNewCreateRoleIpCountByDay($params);//新创角IP
$loginUserNumList = $userRepository->getLoginCountGroupByDay($params);//登录用户数
$spendUserNumList = $spendRepository->getPayUserCountGroupByDay($params);//充值人数
$spendNumList = $spendRepository->getPayCountGroupByDay($params);//充值次数
$spendAllAmountList = $spendRepository->getPayAmountGroupByDayAndType($params);//充值总额
$params['pay_way'] = ['in', '1,2,3,4,5,6'];
$spendCashList = $spendRepository->getPayAmountGroupByDayAndType($params);//现金充值
$params['pay_way'] = 0;
$spendGenericList = $spendRepository->getPayAmountGroupByDayAndType($params);//通用币充值
$params['pay_way'] = -1;
$spendBindingList = $spendRepository->getPayAmountGroupByDayAndType($params);//绑定币充值
$allData['role_num'] = 0;
$allData['user_num'] = 0;
@ -1142,152 +1144,52 @@ class QueryController extends BaseController
$allData['spend_all_amount'] = 0;
$allData['spend_cash'] = 0;
$allData['spend_generic'] = 0;
$allData['pay_amount'] = 0;
$allData['spend_binding'] = 0;
$allData['spend_discount'] = 0;
$allData['spend_voucher'] = 0;
foreach ($data as &$list) {
$thisDateTime = strtotime($list['day']);
$userPlayInfoWhere['tab_user_play_info.create_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
->join($join)
->where($userPlayInfoWhere)
->where($map)
->group('tab_user_play_info.game_id,tab_user_play_info.user_id')
->select());//创角用户
$newUserNumSql = $userPlayInfoModel
->table('tab_user_play_info as ti')
->where($userPlayInfoWhere2)
->where('ti.user_id = tab_user_play_info.user_id and ti.game_id = tab_user_play_info.game_id and ti.create_time < ' . $thisDateTime)
->fetchSql(true)
->count();
$newUserNumData = $userPlayInfoModel
->field('tab_user_play_info.create_time,(' . $newUserNumSql . ') as num')
->join($join)
->where($userPlayInfoWhere)
->where($map)
->group('tab_user_play_info.user_id')
->having('num = 0')
->order('tab_user_play_info.id')
->select();
$list['new_user_num'] = count($newUserNumData);//新创角用户
$newDeviceSql = $userPlayInfoModel
->table('tab_user_play_info as ti')
->where($userPlayInfoWhere2)
->where('ti.create_device_number = tab_user_play_info.create_device_number and ti.game_id = tab_user_play_info.game_id and ti.create_time < ' . $thisDateTime)
->fetchSql(true)
->count();
$newDeviceData = $userPlayInfoModel
->field('tab_user_play_info.create_time,(' . $newDeviceSql . ') as num')
->join($join)
->where($userPlayInfoWhere)
->where($map)
->group('tab_user_play_info.create_device_number')
->having('num = 0')
->order('tab_user_play_info.id')
->select();
$list['new_device_num'] = count($newDeviceData);//新创角设备
$newIpNumSql = $userPlayInfoModel
->table('tab_user_play_info as ti')
->where($userPlayInfoWhere2)
->where('ti.create_ip = tab_user_play_info.create_ip and ti.game_id = tab_user_play_info.game_id and ti.create_time < ' . $thisDateTime)
->fetchSql(true)
->count();
$newIpNumData = $userPlayInfoModel
->field('tab_user_play_info.create_time,(' . $newIpNumSql . ') as num')
->join($join)
->where($userPlayInfoWhere)
->where($map)
->group('tab_user_play_info.create_ip')
->having('num = 0')
->order('tab_user_play_info.id')
->select();
$list['new_ip_num'] = count($newIpNumData);//新增创角IP
$list['login_user_num'] = count(M('UserGameLoginRecord', 'tab_')
->join($join)
->where($userGameLoginWhere)
->where($map)
->group('tab_user_game_login_record.game_id,tab_user_game_login_record.user_id')
->select());//登录用户数
$list['spend_user_num'] = count(M('Spend', 'tab_')
->join($join)
->where($spendWhere)
->where($map)
->group('tab_spend.game_id,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['role_num'] += $list['role_num'];
$allData['user_num'] += $list['user_num'];
$allData['new_user_num'] += $list['new_user_num'];
$allData['new_device_num'] += $list['new_device_num'];
$allData['new_ip_num'] += $list['new_ip_num'];
$allData['login_user_num'] += $list['login_user_num'];
$allData['spend_user_num'] += $list['spend_user_num'];
$allData['spend_num'] += $list['spend_num'];
$allData['spend_all_amount'] = bcadd($allData['spend_all_amount'], $list['spend_all_amount'], 2);
$allData['spend_cash'] = bcadd($allData['spend_cash'], $list['spend_cash'], 2);
$allData['spend_generic'] = bcadd($allData['spend_generic'], $list['spend_generic'], 2);
$allData['spend_binding'] = bcadd($allData['spend_binding'], $list['spend_binding'], 2);
$allData['spend_discount'] = bcadd($allData['spend_discount'], $list['spend_discount'], 2);
$allData['spend_voucher'] = bcadd($allData['spend_voucher'], $list['spend_voucher'], 2);
foreach ($dayList as $day) {
$date = date('Ymd', strtotime($day));
$records[] = [
'day' => $date,
'role_num' => $roleNumList[$day],
'user_num' => $userNumList[$day],
'new_user_num' => $newUserNumList[$day],
'new_device_num' => $newDeviceNumList[$day],
'new_ip_num' => $newIpNumList[$day],
'login_user_num' => $loginUserNumList[$day],
'spend_user_num' => $spendUserNumList[$day],
'spend_num' => $spendNumList[$day],
'spend_all_amount' => $spendAllAmountList[$day],
'spend_cash' => $spendCashList[$day],
'spend_generic' => $spendGenericList[$day],
'spend_binding' => $spendBindingList[$day],
'spend_discount' => 0,
'spend_voucher' => 0,
];
$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'];
$allData['role_num'] += $roleNumList[$day];
$allData['user_num'] += $userNumList[$day];
$allData['new_user_num'] += $newUserNumList[$day];
$allData['new_device_num'] += $newDeviceNumList[$day];
$allData['new_ip_num'] += $newIpNumList[$day];
$allData['login_user_num'] += $loginUserNumList[$day];
$allData['spend_user_num'] += $spendUserNumList[$day];
$allData['spend_num'] += $spendNumList[$day];
$allData['spend_all_amount'] = bcadd($allData['spend_all_amount'], $spendAllAmountList[$day], 2);
$allData['spend_cash'] = bcadd($allData['spend_cash'], $spendCashList[$day], 2);
$allData['spend_generic'] = bcadd($allData['spend_generic'], $spendGenericList[$day], 2);
$allData['spend_binding'] = bcadd($allData['spend_binding'], $spendBindingList[$day], 2);
$allData['spend_discount'] = bcadd($allData['spend_discount'], 0, 2);
$allData['spend_voucher'] = bcadd($allData['spend_voucher'], 0, 2);
$summaryData['date'][] = $date;
$summaryData['role_num'][] = $roleNumList[$day];
$summaryData['user_num'][] = $userNumList[$day];
$summaryData['new_user_num'][] = $newUserNumList[$day];
$summaryData['new_device_num'][] = $newDeviceNumList[$day];
$summaryData['spend_user_num'][] = $spendUserNumList[$day];
$summaryData['spend_all_amount'][] = $spendAllAmountList[$day];
}
}
$summaryData['date'] = array_reverse($summaryData['date']);
@ -1303,7 +1205,7 @@ class QueryController extends BaseController
$this->assign('meta_title', '每日概况');
$this->assign('loginPromote', $loginPromote);
$this->assign('ownId', $ownId);
$this->assign('listData', $data);
$this->assign('listData', $records);
$this->assign('allData', $allData);
$this->assign('summaryData', $summaryData);
$this->assign('setdate', date("Y-m-d"));
@ -1422,72 +1324,44 @@ class QueryController extends BaseController
$userGameLoginMap['tab_user_game_login_record.game_id'] = $list['game_id'];
$spendMap['tab_spend.game_id'] = $list['game_id'];
$list['role_num'] = $userPlayInfoModel
$thisData = $userPlayInfoModel
->field('count(*) as role_num,count(distinct tab_user_play_info.user_id) as user_num')
->where($userPlayInfoMap)
->count();//创角数
$list['user_num'] = $userPlayInfoModel
->where($userPlayInfoMap)
->count('distinct tab_user_play_info.user_id');//创角用户
$newUserNumData = $userPlayInfoModel
->field('tab_user_play_info.create_time')
->where($userPlayInfoMap2)
->group('tab_user_play_info.user_id')
->having('tab_user_play_info.create_time between ' . $begTime . ' and ' . ($endTime + 86399))
->order('tab_user_play_info.id')
->select();
$list['new_user_num'] = count($newUserNumData);//新创角用户
$newDeviceData = $userPlayInfoModel
->field('tab_user_play_info.create_time')
->where($userPlayInfoMap2)
->group('tab_user_play_info.create_device_number')
->having('tab_user_play_info.create_time between ' . $begTime . ' and ' . ($endTime + 86399))
->order('tab_user_play_info.id')
->select();
$list['new_device_num'] = count($newDeviceData);//新创角设备
->find();
$list['role_num'] = $thisData['role_num'];//创角数
$list['user_num'] = $thisData['user_num'];//创角用户
$newIpData = $userPlayInfoModel
->field('tab_user_play_info.create_time')
$thisData = $userPlayInfoModel
->field('tab_user_play_info.create_time,count(distinct tab_user_play_info.user_id) as new_user_num,
count(distinct tab_user_play_info.create_device_number) as new_device_num,
count(distinct tab_user_play_info.create_ip) as new_ip_num')
->where($userPlayInfoMap2)
->group('tab_user_play_info.create_ip')
->having('tab_user_play_info.create_time between ' . $begTime . ' and ' . ($endTime + 86399))
->order('tab_user_play_info.id')
->select();
$list['new_ip_num'] = count($newIpData);//新增创角IP
->find();
$list['new_user_num'] = empty($thisData['new_user_num']) ? 0 : $thisData['new_user_num'];//新创角用户
$list['new_device_num'] = empty($thisData['new_device_num']) ? 0 : $thisData['new_device_num'];//新创角设备
$list['new_ip_num'] = empty($thisData['new_ip_num']) ? 0 : $thisData['new_ip_num'];//新增创角IP
$list['login_user_num'] = count($userGameLoginModel
->where($userGameLoginMap)
->group('tab_user_game_login_record.game_id,tab_user_game_login_record.user_id')
->select());//登录用户数
$list['spend_user_num'] = $spendModel
->where($spendMap)
->count('distinct tab_spend.user_id');//充值人数
$list['spend_num'] = $spendModel
$thisData = $spendModel
->field('count(distinct tab_spend.user_id) as spend_user_num,count(*) as spend_num,
sum(tab_spend.pay_amount) as spend_all_amount,
sum(if(tab_spend.pay_way > 0,tab_spend.pay_amount,0)) as spend_cash,
sum(if(tab_spend.pay_way = 0,tab_spend.pay_amount,0)) as spend_generic,
sum(if(tab_spend.pay_way = -1,tab_spend.pay_amount,0)) as spend_binding')
->where($spendMap)
->count();//充值次数
$list['spend_all_amount'] = $spendModel
->where($spendMap)
->sum('tab_spend.pay_amount');//充值总额
$list['spend_cash'] = $spendModel
->where($spendMap)
->where(array('tab_spend.pay_way' => ['in', '1,2,3,4,5,6']))
->sum('tab_spend.pay_amount');//现金充值
$list['spend_generic'] = $spendModel
->where($spendMap)
->where(array('tab_spend.pay_way' => 0))
->sum('tab_spend.pay_amount');//通用币
$list['spend_binding'] = $spendModel
->where($spendMap)
->where(array('tab_spend.pay_way' => -1))
->sum('tab_spend.pay_amount');//绑定币
->find();
$list['spend_user_num'] = $thisData['spend_user_num'];//充值人数
$list['spend_num'] = $thisData['spend_num'];//充值次数
$list['spend_all_amount'] = $thisData['spend_all_amount'];//充值总额
$list['spend_cash'] = $thisData['spend_cash'];//现金充值
$list['spend_generic'] = $thisData['spend_generic'];//通用币
$list['spend_binding'] = $thisData['spend_binding'];//绑定币
$list['spend_discount'] = 0;//折扣币
$list['spend_voucher'] = 0;//代金券

Loading…
Cancel
Save