|
|
|
<?php
|
|
|
|
namespace Base\Repository;
|
|
|
|
|
|
|
|
class SpendRepository {
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private function assembleDayRecords($items, $dayList, $valueColumn, $dayColumn = 'day')
|
|
|
|
{
|
|
|
|
$records = [];
|
|
|
|
foreach ($dayList as $day) {
|
|
|
|
$dayValue = 0;
|
|
|
|
foreach ($items as $item) {
|
|
|
|
if ($item[$dayColumn] == $day) {
|
|
|
|
$dayValue = $item[$valueColumn];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$records[$day] = $dayValue;
|
|
|
|
}
|
|
|
|
return $records;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 付费游戏数
|
|
|
|
*/
|
|
|
|
public function getPayGameCountByDay($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'];
|
|
|
|
|
|
|
|
$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');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 按天统计付款总额
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
$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'];
|
|
|
|
|
|
|
|
$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');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 按天统计付款用户数
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
$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'];
|
|
|
|
|
|
|
|
$field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as day, count(distinct user_id) count';
|
|
|
|
|
|
|
|
$items = M('spend', 'tab_')->field($field)->where($map)->group('day')->select();
|
|
|
|
return $this->assembleDayRecords($items, $dayList, 'count');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 按照时间分组统计新增付费用户数
|
|
|
|
*/
|
|
|
|
public function getNewPayUserCountByDay($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'];
|
|
|
|
$oldMap = $map;
|
|
|
|
|
|
|
|
$records = [];
|
|
|
|
foreach ($dayList as $day) {
|
|
|
|
$time = strtotime($day);
|
|
|
|
$oldMap['pay_time'] = ['lt', $time];
|
|
|
|
$map['pay_time'] = ['between', [$time, ($time + 24 * 3600 -1)]];
|
|
|
|
$oldQuery = M('spend', 'tab_')->field('user_id')->where($oldMap)->group('user_id')->buildSql();
|
|
|
|
$map['user_id'] = ['exp', ' not in (' . $oldQuery . ')'];
|
|
|
|
$result = M('spend', 'tab_')->field('count(distinct user_id) count')->where($map)->find();
|
|
|
|
$records[$day] = $result['count'];
|
|
|
|
}
|
|
|
|
return $records;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 按照时间分组统计新增付费用户付费金额
|
|
|
|
*/
|
|
|
|
public function getNewPayAmountByDay($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'];
|
|
|
|
$oldMap = $map;
|
|
|
|
|
|
|
|
$records = [];
|
|
|
|
foreach ($dayList as $day) {
|
|
|
|
$time = strtotime($day);
|
|
|
|
$oldMap['pay_time'] = ['lt', $time];
|
|
|
|
$map['pay_time'] = ['between', [$time, ($time + 24 * 3600 -1)]];
|
|
|
|
|
|
|
|
$oldQuery = M('spend', 'tab_')->field('user_id')->where($oldMap)->group('user_id')->buildSql();
|
|
|
|
$map['user_id'] = ['exp', ' not in (' . $oldQuery . ')'];
|
|
|
|
$result = M('spend', 'tab_')->field('sum(pay_amount) amount')->where($map)->find();
|
|
|
|
$records[$day] = floatval($result['amount']);
|
|
|
|
}
|
|
|
|
return $records;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 统计给定时间前的付费玩家总数
|
|
|
|
*/
|
|
|
|
public function getHistoryPayCountByDay($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'];
|
|
|
|
|
|
|
|
$records = [];
|
|
|
|
foreach ($dayList as $day) {
|
|
|
|
$time = strtotime($day);
|
|
|
|
$map['pay_time'] = ['elt', $time];
|
|
|
|
$result = M('spend', 'tab_')->field('count(DISTINCT user_id) as count')->where($map)->find();
|
|
|
|
$records[$day] = $result['count'];
|
|
|
|
}
|
|
|
|
return $records;
|
|
|
|
}
|
|
|
|
}
|