修改bug

master
ELF 5 years ago
parent b2f357608f
commit d9e7a55af4

@ -8,112 +8,131 @@ class SpendRepository {
}
private function assembleDayRecords($items, $dayList, $valueColumn, $dayColumn = 'day')
private function assembleRecords($items, $keys, $valueColumn, $keyColumn = 'day')
{
$records = [];
foreach ($dayList as $day) {
$dayValue = 0;
foreach ($keys as $key) {
$value = 0;
foreach ($items as $item) {
if ($item[$dayColumn] == $day) {
$dayValue = $item[$valueColumn];
if ($item[$keyColumn] == $key) {
$value = $item[$valueColumn];
}
}
$records[$day] = $dayValue;
$records[$key] = $value;
}
return $records;
}
/**
* 付费游戏数
*/
public function getPayGameCountByDay($params) {
private function getGameGroupConditions($params)
{
$beginTime = $params['begin_time'] ?? 0;
$endTime = $params['end_time'] ?? 0;
$ids = $params['promote_ids'] ?? [];
$isBan = $params['is_ban'] ?? false;
$gameIds = $params['game_ids'] ?? [];
$conditions = [];
$conditions['pay_status'] = 1;
$conditions['promote_id'] = ['in', $ids];
$conditions['pay_time'] = ['between', [$beginTime, $endTime]];
$conditions['game_id'] = ['in', $gameIds];
$conditions['pay_way'] = $isBan ? ['neq', '-10'] : ['neq', '-1'];
return $conditions;
}
private function getDayGroupConditions($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'] ?? [];
$isBan = $params['is_ban'] ?? false;
$dayList = $params['dayList'] ?? [];
$map = [];
$map['pay_status'] = 1;
$map['promote_id'] = ['in', $ids];
$map['pay_time'] = ['between', [$beginTime, $endTime]];
$map['game_id'] = $gameId > 0 ? $gameId : ['gt', 0];
$map['pay_way'] = $isBan ? ['neq', '-10'] : ['neq', '-1'];
$conditions = [];
$conditions['pay_status'] = 1;
$conditions['promote_id'] = ['in', $ids];
$conditions['pay_time'] = ['between', [$beginTime, $endTime]];
$conditions['game_id'] = $gameId > 0 ? $gameId : ['gt', 0];
$conditions['pay_way'] = $isBan ? ['neq', '-10'] : ['neq', '-1'];
$field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as day, count(DISTINCT game_id) count';
$items = M('spend', 'tab_')->field($field)->where($map)->group('day')->select();
return $this->assembleDayRecords($items, $dayList, 'count');
return $conditions;
}
/**
* 按天统计付款总额
* 付费游戏数
*/
public function getPayAmountByDay($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'] ?? [];
$isBan = $params['is_ban'] ?? false;
public function getPayGameCountGroupByDay($params)
{
$dayList = $params['dayList'] ?? [];
$conditions = $this->getDayGroupConditions($params);
$field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as day, count(DISTINCT game_id) count';
$items = M('spend', 'tab_')->field($field)->where($conditions)->group('day')->select();
return $this->assembleRecords($items, $dayList, 'count');
}
$map['pay_status'] = 1;
$map['pay_time'] = ['between', [$beginTime, $endTime]];
$map['game_id'] = $gameId > 0 ? $gameId : ['gt', 0];
$map['promote_id'] = ['in', $ids];
$map['pay_way'] = $isBan ? ['neq', '-10'] : ['neq', '-1'];
/**
* 付费游戏数
*/
public function getPayGameCountGroupByGame($params)
{
$gameIds = $params['game_ids'] ?? [];
$conditions = $this->getGameGroupConditions($params);
$field = 'game_id, count(*) count';
$items = M('spend', 'tab_')->field($field)->where($conditions)->group('game_id')->select();
return $this->assembleRecords($items, $gameIds, 'count', 'game_id');
}
/**
* 按天统计付款总额
*/
public function getPayAmountGroupByDay($params) {
$dayList = $params['dayList'] ?? [];
$conditions = $this->getDayGroupConditions($params);
$field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as day, sum(pay_amount) as amount';
$items = M('spend', 'tab_')->field($field)->where($map)->group('day')->select();
return $this->assembleDayRecords($items, $dayList, 'amount');
$items = M('spend', 'tab_')->field($field)->where($conditions)->group('day')->select();
return $this->assembleRecords($items, $dayList, 'amount');
}
/**
* 按游戏统计付款总额
*/
public function getPayAmountGroupByGame($params) {
$gameIds = $params['game_ids'] ?? [];
$conditions = $this->getGameGroupConditions($params);
$field = 'game_id, sum(pay_amount) as amount';
$items = M('spend', 'tab_')->field($field)->where($conditions)->group('game_id')->select();
return $this->assembleRecords($items, $gameIds, 'amount', 'game_id');
}
/**
* 按天统计付款用户数
*/
public function getPayUserCountByDay($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'] ?? [];
$isBan = $params['is_ban'] ?? false;
public function getPayUserCountGroupByDay($params) {
$dayList = $params['dayList'] ?? [];
$map['pay_status'] = 1;
$map['pay_time'] = ['between', [$beginTime, $endTime]];
$map['game_id'] = $gameId > 0 ? $gameId : ['gt', 0];
$map['promote_id'] = ['in', $ids];
$map['pay_way'] = $isBan ? ['neq', '-10'] : ['neq', '-1'];
$conditions = $this->getDayGroupConditions($params);
$field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as day, count(distinct user_id) count';
$items = M('spend', 'tab_')->field($field)->where($conditions)->group('day')->select();
return $this->assembleRecords($items, $dayList, 'count');
}
$items = M('spend', 'tab_')->field($field)->where($map)->group('day')->select();
return $this->assembleDayRecords($items, $dayList, 'count');
/**
* 游戏统计付款用户数
*/
public function getPayUserCountGroupByGame($params) {
$gameIds = $params['game_ids'] ?? [];
$conditions = $this->getGameGroupConditions($params);
$field = 'game_id, count(distinct user_id) count';
$items = M('spend', 'tab_')->field($field)->where($conditions)->group('game_id')->select();
return $this->assembleRecords($items, $dayList, 'count', 'game_id');
}
/**
* 按照时间分组统计新增付费用户数
*/
public function getNewPayUserCountByDay($params) {
public function getNewPayUserCountGroupByDay($params) {
$dayList = $params['dayList'] ?? [];
$gameId = $params['game_id'] ?? 0;
$serverId = $params['server_id'] ?? 0;
$ids = $params['promote_id'] ?? [];
$isBan = $params['is_ban'] ?? false;
$map = [];
$map['pay_status']=1;
if ($gameId > 0) {
$map['game_id'] = $gameId;
}
if ($serverId > 0) {
$map['server_id'] = $serverId;
}
$map['promote_id'] = ['in', $ids];
$map['pay_way'] = $isBan ? ['neq', '-10'] : ['neq', '-1'];
$conditions = $this->getDayGroupConditions($params);
$oldMap = $map;
$records = [];
@ -129,26 +148,27 @@ class SpendRepository {
return $records;
}
/**
* 按照时间分组统计新增付费用户数
*/
public function getNewPayUserCountGroupByGame($params) {
$beginTime = $params['begin_time'] ?? 0;
$gameIds = $params['game_ids'] ?? [];
$conditions = $this->getGameGroupConditions($params);
$oldConditions = $conditions;
$oldConditions['pay_time'] = ['lt', $beginTime];
$oldQuery = M('spend', 'tab_')->field('user_id')->where($oldConditions)->group('user_id')->buildSql();
$map['user_id'] = ['exp', ' not in (' . $oldQuery . ')'];
$items = M('spend', 'tab_')->field('count(distinct user_id) count, game_id')->where($conditions)->group('game_id')->find();
return $this->assembleRecords($items, $gameIds, 'amount', 'game_id');
}
/**
* 按照时间分组统计新增付费用户付费金额
*/
public function getNewPayAmountByDay($params) {
public function getNewPayAmountGroupByDay($params) {
$dayList = $params['dayList'] ?? [];
$gameId = $params['game_id'] ?? 0;
$serverId = $params['server_id'] ?? 0;
$ids = $params['promote_id'] ?? [];
$isBan = $params['is_ban'] ?? false;
$map = [];
$map['pay_status']=1;
if ($gameId > 0) {
$map['game_id'] = $gameId;
}
if ($serverId > 0) {
$map['server_id'] = $serverId;
}
$map['promote_id'] = ['in', $ids];
$map['pay_way'] = $isBan ? ['neq', '-10'] : ['neq', '-1'];
$conditions = $this->getDayGroupConditions($params);
$oldMap = $map;
$records = [];
@ -165,26 +185,28 @@ class SpendRepository {
return $records;
}
/**
/**
* 按照游戏统计新增付费用户付费金额
*/
public function getNewPayAmountGroupByGame($params) {
$beginTime = $params['begin_time'] ?? 0;
$gameIds = $params['game_ids'] ?? [];
$conditions = $this->getGameGroupConditions($params);
$oldConditions = $conditions;
$oldConditions['pay_time'] = ['lt', $beginTime];
$oldQuery = M('spend', 'tab_')->field('user_id')->where($oldConditions)->group('user_id')->buildSql();
$map['user_id'] = ['exp', ' not in (' . $oldQuery . ')'];
$items = M('spend', 'tab_')->field('sum(pay_amount) amount, game_id')->where($conditions)->group('game_id')->find();
return $this->assembleRecords($items, $gameIds, 'amount', 'game_id');
}
/**
* 统计给定时间前的付费玩家总数
*/
public function getHistoryPayCountByDay($params) {
public function getHistoryPayCountGroupByDay($params)
{
$dayList = $params['dayList'] ?? [];
$gameId = $params['game_id'] ?? 0;
$serverId = $params['server_id'] ?? 0;
$ids = $params['promote_id'] ?? [];
$isBan = $params['is_ban'] ?? false;
$map = [];
$map['pay_status']=1;
if ($gameId > 0) {
$map['game_id'] = $gameId;
}
if ($serverId > 0) {
$map['server_id'] = $serverId;
}
$map['promote_id'] = ['in', $ids];
$map['pay_way'] = $isBan ? ['neq', '-10'] : ['neq', '-1'];
$conditions = $this->getDayGroupConditions($params);
$records = [];
foreach ($dayList as $day) {
@ -195,4 +217,16 @@ class SpendRepository {
}
return $records;
}
/**
* 统计给定时间前的付费玩家总数
*/
public function getHistoryPayCountGroupByGame($params)
{
$beginTime = $params['begin_time'] ?? 0;
$conditions = $this->getGameGroupConditions($params);
$conditions['pay_time'] = ['elt', $beginTime];
$items = M('spend', 'tab_')->field('count(DISTINCT user_id) as count, game_id')->where($conditions)->group('game_id')->find();
return $this->assembleRecords($items, $gameIds, 'count', 'game_id');
}
}

@ -8,79 +8,115 @@ class UserRepository {
}
private function assembleDayRecords($items, $dayList, $valueColumn, $dayColumn = 'day')
private function assembleRecords($items, $keys, $valueColumn, $keyColumn = 'day')
{
$records = [];
foreach ($dayList as $day) {
$dayValue = 0;
foreach ($keys as $key) {
$value = 0;
foreach ($items as $item) {
if ($item[$dayColumn] == $day) {
$dayValue = $item[$valueColumn];
if ($item[$keyColumn] == $key) {
$value = $item[$valueColumn];
}
}
$records[$day] = $dayValue;
$records[$key] = $value;
}
return $records;
}
/**
* 按照时间分组统计登录总数
*/
public function getLoginCountByDay($params) {
private function getDayGroupConditions($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'] ?? [];
$dayList = $params['dayList'] ?? [];
$map = [];
$map['login_time'] = ['between', [$beginTime, $endTime]];
$conditions = [];
$conditions['promote_id'] = ['in', $ids];
$conditions[$params['time_column']] = ['between', [$beginTime, $endTime]];
if ($gameId > 0) {
$map['game_id'] = $gameId;
$conditions['game_id'] = $gameId;
}
if ($serverId > 0) {
$map['server_id'] = $serverId;
$conditions['server_id'] = $serverId;
}
$map['promote_id'] = ['in', $ids];
$conditions['pay_way'] = $isBan ? ['neq', '-10'] : ['neq', '-1'];
$items = M('user_login_record', 'tab_')->field('FROM_UNIXTIME(login_time, "%Y-%m-%d") as day, count(DISTINCT user_id) as count')
->where($map)
->group('day')
->select();
return $conditions;
}
return $this->assembleDayRecords($items, $dayList, 'count');
private function getGameGroupConditions($params)
{
$beginTime = $params['begin_time'] ?? 0;
$endTime = $params['end_time'] ?? 0;
$ids = $params['promote_ids'] ?? [];
$gameIds = $params['game_ids'] ?? [];
$conditions = [];
$conditions['promote_id'] = ['in', $ids];
$conditions[$params['time_column']] = ['between', [$beginTime, $endTime]];
$conditions['game_id'] = ['in', $gameIds];
return $conditions;
}
/**
* 按照时间分组统计注册总数
* 按照时间分组统计登录总数
*/
public function getRegisterCountByDay($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'] ?? [];
public function getLoginCountGroupByDay($params) {
$dayList = $params['dayList'] ?? [];
$params['time_column'] = 'login_time';
$conditions = $this->getDayGroupConditions($params);
$items = M('user_login_record', 'tab_')->field('FROM_UNIXTIME(login_time, "%Y-%m-%d") as day, count(DISTINCT user_id) as count')
->where($conditions)
->group('day')
->select();
$dateform = '%Y-%m-%d';
return $this->assembleRecords($items, $dayList, 'count');
}
$map = [];
$map['register_time'] = ['between', [$beginTime, $endTime]];
/**
* 按照游戏分组统计登录总数
*/
public function getLoginCountGroupByGame($params) {
$gameIds = $params['game_ids'] ?? [];
$params['time_column'] = 'login_time';
$conditions = $this->getGameGroupConditions($params);
$items = M('user_login_record', 'tab_')->field('game_id, count(DISTINCT user_id) as count')
->where($conditions)
->group('game_id')
->select();
if ($gameId > 0) {
$map['fgame_id'] = $gameId;
}
return $this->assembleRecords($items, $gameIds, 'count', 'game_id');
}
$map['promote_id'] = ['in', $ids];
$map['puid'] = 0;
/**
* 按照时间分组统计注册总数
*/
public function getRegisterCountGroupByDay($params) {
$dayList = $params['dayList'] ?? [];
$params['time_column'] = 'register_time';
$conditions = $this->getDayGroupConditions($params);
$items = M('user', 'tab_')->field('count(*) count, FROM_UNIXTIME(register_time,"'.$dateform.'") as day')
$items = M('user', 'tab_')->field('count(*) count, FROM_UNIXTIME(register_time, "%Y-%m-%d") as day')
->where($map)
->group('day')
->select();
return $this->assembleDayRecords($items, $dayList, 'count');
return $this->assembleRecords($items, $dayList, 'count');
}
/**
* 按照游戏分分组统计注册总数
*/
public function getRegisterCountGroupByGame($params) {
$gameIds = $params['game_ids'] ?? [];
$params['time_column'] = 'register_time';
$conditions = $this->getGameGroupConditions($params);
$items = M('user', 'tab_')->field('count(*) count, game_id')
->where($conditions)
->group('game_id')
->select();
return $this->assembleRecords($items, $gameIds, 'count', 'game_id');
}
/**
@ -95,7 +131,6 @@ class UserRepository {
*/
public function getRatentionRate($newslist,$game_id=0,$promote_id=0,$flag=1) {
$map['lock_status']=1;
if($game_id>0) {
$map['up.game_id'] = $game_id;

@ -172,7 +172,8 @@ class BaseController extends HomeController{
'p' => $page,
'row' => $pageSize
];
$pagination = set_pagination($count, $pageSize, $_POST);
$params = array_merge($params, $_POST);
$pagination = set_pagination($count, $pageSize, $params);
return [$records, $pagination, $count];
}

@ -703,14 +703,14 @@ class QueryController extends BaseController
if (intval($endTime - $beginTime) / (24 * 3600) <= 30) {
$userRepository = new UserRepository();
$spendRepository = new SpendRepository();
$payGameCountList = $spendRepository->getPayGameCountByDay($params);
$payUserCountList = $spendRepository->getPayUserCountByDay($params);
$newPayUserCountList = $spendRepository->getNewPayUserCountByDay($params);
$payAmountList = $spendRepository->getPayAmountByDay($params);
$newPayAmountList = $spendRepository->getNewPayAmountByDay($params);
$historyPayCountList = $spendRepository->getHistoryPayCountByDay($params);
$loginCountList = $userRepository->getLoginCountByDay($params);
$registerCountList = $userRepository->getRegisterCountByDay($params);
$payGameCountList = $spendRepository->getPayGameCountGroupByDay($params);
$payUserCountList = $spendRepository->getPayUserCountGroupByDay($params);
$newPayUserCountList = $spendRepository->getNewPayUserCountGroupByDay($params);
$payAmountList = $spendRepository->getPayAmountGroupByDay($params);
$newPayAmountList = $spendRepository->getNewPayAmountGroupByDay($params);
$historyPayCountList = $spendRepository->getHistoryPayCountGroupByDay($params);
$loginCountList = $userRepository->getLoginCountGroupByDay($params);
$registerCountList = $userRepository->getRegisterCountGroupByDay($params);
foreach ($dayList as $day) {
$records[] = [
@ -743,10 +743,30 @@ class QueryController extends BaseController
public function gameArpu()
{
$time = I('time');
$data = M('Apply', 'tab_')->field('game_id, game_name')->where(['promote_id' => $promote_id])->order('game_id desc')->select();
$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);
$time = I('time', date('Y-m-d'));
$applys = M('Apply', 'tab_')->field('game_id, game_name')->where(['promote_id' => $promote['id']])->order('game_id desc')->select();
$gameIds = array_column($applys, 'game_id');
$params = [
'begin_time' => strtotime($time . ' 00:00:00'),
'end_time' => strtotime($time . ' 23:59:59'),
'game_ids' => $gameIds,
'promote_ids' => $ids,
];
$spendRepository = new SpendRepository();
// $result = $spendRepository->getHistoryPayCountGroupByGame($params);
$result = $spendRepository->getPayGameCountGroupByGame($params);
var_dump($result);
}
public function arpu_analysis()

@ -74,7 +74,7 @@
</if>
<div class="form-group normal_space fr">
<label>起止时间:</label>
<input type="text" class="txt range-date" name="time" placeholder="起止时间" value="{:I('time')}" >
<input type="text" class="txt range-date" name="time" placeholder="起止时间" value="{:I('time', date('Y-m-d'))}" >
</div>
<div class="form-group">
<input type="submit" class="submit normal_space" value="查询">

Loading…
Cancel
Save