You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

198 lines
6.8 KiB
PHTML

5 years ago
<?php
namespace Base\Repository;
class SpendRepository {
public function __construct()
{
}
5 years ago
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;
}
5 years ago
/**
* 付费游戏数
*/
public function getPayGameCountByDay($params) {
5 years ago
$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;
5 years ago
$dayList = $params['dayList'] ?? [];
5 years ago
$map = [];
5 years ago
$map['pay_status'] = 1;
$map['promote_id'] = ['in', $ids];
5 years ago
$map['pay_time'] = ['between', [$beginTime, $endTime]];
$map['game_id'] = $gameId > 0 ? $gameId : ['gt', 0];
$map['pay_way'] = $isBan ? ['neq', '-10'] : ['neq', '-1'];
5 years ago
$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');
5 years ago
}
5 years ago
5 years ago
/**
* 按天统计付款总额
*/
5 years ago
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;
5 years ago
$dayList = $params['dayList'] ?? [];
5 years ago
$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'];
5 years ago
$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();
5 years ago
return $this->assembleDayRecords($items, $dayList, 'amount');
5 years ago
}
5 years ago
/**
* 按天统计付款用户数
*/
5 years ago
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;
5 years ago
$dayList = $params['dayList'] ?? [];
5 years ago
$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'];
5 years ago
$field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as day, count(distinct user_id) count';
5 years ago
5 years ago
$items = M('spend', 'tab_')->field($field)->where($map)->group('day')->select();
return $this->assembleDayRecords($items, $dayList, 'count');
5 years ago
}
/**
* 按照时间分组统计新增付费用户数
*/
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];
5 years ago
$map['pay_time'] = ['between', [$time, ($time + 24 * 3600 -1)]];
5 years ago
$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;
}
/**
5 years ago
* 按照时间分组统计新增付费用户付费金额
5 years ago
*/
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];
5 years ago
$map['pay_time'] = ['between', [$time, ($time + 24 * 3600 -1)]];
5 years ago
$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();
5 years ago
$records[$day] = floatval($result['amount']);
5 years ago
}
return $records;
}
/**
* 统计给定时间前的付费玩家总数
*/
5 years ago
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;
5 years ago
5 years ago
$map = [];
5 years ago
$map['pay_status']=1;
5 years ago
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'];
5 years ago
5 years ago
$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;
5 years ago
}
5 years ago
}