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.

221 lines
7.1 KiB
PHTML

5 years ago
<?php
namespace Base\Repository;
class PromoteRepository {
private $model;
public function __construct()
{
}
private function assembleZero($allKeys, $records, $zeroValue) {
$noExistKeys = array_diff($allKeys, array_keys($records));
foreach ($noExistKeys as $key) {
$records[$key] = $zeroValue;
}
return $records;
}
/**
* 获取指定推广员底下的角色创建数
*/
public function getCreateRoleCountByIds(array $ids, $params)
{
$map = [];
$map['id'] = ['in', $ids];
if (isset($params['begin_time']) && isset($params['begin_time'])) {
$map['create_time'] = ['between', [$params['begin_time'], $params['end_time']]];
}
if (isset($params['game_id'])) {
$map['game_id'] = $params['game_id'];
}
if (isset($params['server_id'])) {
$map['server_id'] = $params['server_id'];
}
if (isset($params['sdk_version'])) {
$map['sdk_version'] = $params['sdk_version'];
}
$items = M('user_play_info', 'tab_')->field(['count(*) count', 'promote_id'])->where($map)->groupBy('promote_id')->select();
$records = [];
foreach ($items as $item) {
$records[$item['promote_id']] = $item['count'];
}
$records = $this->assembleZero($ids, $records, 0);
return $records;
}
/**
* 获取指定推广员底下的角色创建的用户数
*/
public function getCreateRoleUserCountByIds($ids, $beginTime, $endTime)
{
$map = [];
$map['id'] = ['in', $ids];
if (isset($params['begin_time']) && isset($params['begin_time'])) {
$map['create_time'] = ['between', [$params['begin_time'], $params['end_time']]];
}
if (isset($params['game_id'])) {
$map['game_id'] = $params['game_id'];
}
if (isset($params['server_id'])) {
$map['server_id'] = $params['server_id'];
}
if (isset($params['sdk_version'])) {
$map['sdk_version'] = $params['sdk_version'];
}
$items = M('user_play_info', 'tab_')->field(['count(distinct user_id) count', 'promote_id'])->where($map)->groupBy('promote_id')->select();
$records = [];
foreach ($items as $item) {
$records[$item['promote_id']] = $item['count'];
}
$records = $this->assembleZero($ids, $records, 0);
return $records;
}
/**
*
*/
public function getCreateRoleDeviceCountByIds($ids, $beginTime, $endTime)
{
}
public function getCreateRoleIpCountByIds($ids, $beginTime, $endTime)
{
}
/**
* 获取指定推广员底下的登录用户数
*/
public function getLoginUserCountByIds($ids, $beginTime, $endTime)
{
$map = [];
$map['id'] = ['in', $ids];
if (isset($params['begin_time']) && isset($params['begin_time'])) {
$map['login_time'] = ['between', [$params['begin_time'], $params['end_time']]];
}
if (isset($params['game_id'])) {
$map['game_id'] = $params['game_id'];
}
if (isset($params['server_id'])) {
$map['server_id'] = $params['server_id'];
}
if (isset($params['sdk_version'])) {
$map['sdk_version'] = $params['sdk_version'];
}
$items = M('user', 'tab_')->field(['count(*) count', 'promote_id'])->where($map)->groupBy('promote_id')->select();
$records = [];
foreach ($items as $item) {
$records[$item['promote_id']] = $item['count'];
}
$records = $this->assembleZero($ids, $records, 0);
return $records;
}
/**
* 获取指定推广员底下的充值次数
*/
public function getRechargeCountByIds($ids, $beginTime, $endTime)
{
$map = ['pay_status' => 1, 'id' => ['in', $ids]];
if (isset($params['begin_time']) && isset($params['begin_time'])) {
$map['pay_time'] = ['between', [$params['begin_time'], $params['end_time']]];
}
if (isset($params['game_id'])) {
$map['game_id'] = $params['game_id'];
}
if (isset($params['server_id'])) {
$map['server_id'] = $params['server_id'];
}
if (isset($params['sdk_version'])) {
$map['sdk_version'] = $params['sdk_version'];
}
$items = M('spend', 'tab_')->field(['count(*) count', 'promote_id'])->where($map)->groupBy('promote_id')->select();
$records = [];
foreach ($items as $item) {
$records[$item['promote_id']] = $item['count'];
}
$records = $this->assembleZero($ids, $records, 0);
return $records;
}
/**
* 获取指定推广员底下的充值用户数
*/
public function getRechargeUserCountByIds($ids, $beginTime, $endTime)
{
$map = ['pay_status' => 1, 'id' => ['in', $ids]];
if (isset($params['begin_time']) && isset($params['begin_time'])) {
$map['pay_time'] = ['between', [$params['begin_time'], $params['end_time']]];
}
if (isset($params['game_id'])) {
$map['game_id'] = $params['game_id'];
}
if (isset($params['server_id'])) {
$map['server_id'] = $params['server_id'];
}
if (isset($params['sdk_version'])) {
$map['sdk_version'] = $params['sdk_version'];
}
$items = M('spend', 'tab_')->field(['count(distinct user_id) count', 'promote_id'])->where($map)->groupBy('promote_id')->select();
$records = [];
foreach ($items as $item) {
$records[$item['promote_id']] = $item['count'];
}
$records = $this->assembleZero($ids, $records, 0);
return $records;
}
public function getRechargeAmountByIds($ids, $beginTime, $endTime)
{
$map = ['pay_status' => 1, 'id' => ['in', $ids]];
if (isset($params['begin_time']) && isset($params['begin_time'])) {
$map['pay_time'] = ['between', [$params['begin_time'], $params['end_time']]];
}
if (isset($params['game_id'])) {
$map['game_id'] = $params['game_id'];
}
if (isset($params['server_id'])) {
$map['server_id'] = $params['server_id'];
}
if (isset($params['sdk_version'])) {
$map['sdk_version'] = $params['sdk_version'];
}
$items = M('spend', 'tab_')->field(['sum(pay_amount) amount', 'promote_id', 'pay_way'])->where($map)->groupBy('promote_id, pay_way')->select();
$records = [];
foreach ($items as $item) {
if (isset($records[$item['promote_id']])) {
if ($item['pay_way'] == -1) {
$records[$item['promote_id']]['ban_coin'] = $item['amount'];
} elseif ($item['pay_way'] == 0) {
$records[$item['promote_id']]['coin'] = $item['amount'];
} else {
$records[$item['promote_id']]['cash'] = isset$item['amount'];
}
} else {
}
$records[$item['promote_id']] = $item['count'];
}
}
}