|
|
|
<?php
|
|
|
|
namespace Base\Repository;
|
|
|
|
|
|
|
|
class PromoteRepository {
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取业绩公共map
|
|
|
|
*/
|
|
|
|
private function getPublicAchievementMap($ids, $params, $type = null)
|
|
|
|
{
|
|
|
|
$isContainSubs = false;
|
|
|
|
if (isset($params['isContainSubs']) && $params['isContainSubs']) {
|
|
|
|
$isContainSubs = true;
|
|
|
|
}
|
|
|
|
foreach ($ids as $key => $id) {
|
|
|
|
$ids[$key] = intval($id);
|
|
|
|
}
|
|
|
|
$map = [];
|
|
|
|
$map['promote_id'] = ['in', $ids];
|
|
|
|
$allIds = $ids;
|
|
|
|
if ($isContainSubs) {
|
|
|
|
$allIds = array_merge($ids, array_keys($params['basicPromotes']));
|
|
|
|
$map['promote_id'] = ['in', $allIds];
|
|
|
|
}
|
|
|
|
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'];
|
|
|
|
}
|
|
|
|
if (isset($params['role_level'])) {
|
|
|
|
$map['role_level'] = $params['role_level'];
|
|
|
|
}
|
|
|
|
if (isset($params['begin_time']) && isset($params['end_time']) && isset($params['time_column'])) {
|
|
|
|
$map[$params['time_column']] = ['between', [$params['begin_time'], $params['end_time']]];
|
|
|
|
}
|
|
|
|
if ($type == 'spend') {
|
|
|
|
$spendRepository = new SpendRepository();
|
|
|
|
$map = $spendRepository->withIsCheck($map);
|
|
|
|
}
|
|
|
|
if (isset($params['lock_status'])) {
|
|
|
|
$lockUserIds = M('user', 'tab_')->where(['lock_status' => 0, 'promote_id' => ['in', $allIds]])->getField('id', 'true');
|
|
|
|
if (count($lockUserIds) > 0) {
|
|
|
|
if ($params['lock_status'] == 1) {
|
|
|
|
$map['user_id'] = ['not in', $lockUserIds];
|
|
|
|
} else {
|
|
|
|
$map['user_id'] = ['in', $lockUserIds];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($params['lock_status'] == 2) {
|
|
|
|
$map['_string'] = ' 1<>1';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $map;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取指定推广员底下的角色创建数
|
|
|
|
*/
|
|
|
|
public function getCreateRoleCountByIds(array $ids, array $params = [])
|
|
|
|
{
|
|
|
|
if (count($ids) == 0) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
$params['time_column'] = 'create_time';
|
|
|
|
$map = $this->getPublicAchievementMap($ids, $params);
|
|
|
|
$items = M('user_play_info', 'tab_')->field(['count(*) count', 'promote_id'])->where($map)->group('promote_id')->select();
|
|
|
|
$records = [];
|
|
|
|
foreach ($items as $item) {
|
|
|
|
$promoteId = $item['promote_id'];
|
|
|
|
if (isset($params['basicPromotes'][$item['promote_id']])) {
|
|
|
|
$promoteId = $params['basicPromotes'][$item['promote_id']];
|
|
|
|
}
|
|
|
|
if (isset($records[$promoteId])) {
|
|
|
|
$records[$promoteId] += $item['count'];
|
|
|
|
} else {
|
|
|
|
$records[$promoteId] = $item['count'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$records = $this->assembleZero($ids, $records, 0);
|
|
|
|
|
|
|
|
return $records;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取指定推广员底下的角色创建的用户数
|
|
|
|
*/
|
|
|
|
public function getCreateRoleUserCountByIds(array $ids, array $params = [])
|
|
|
|
{
|
|
|
|
if (count($ids) == 0) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
$params['time_column'] = 'create_time';
|
|
|
|
$map = $this->getPublicAchievementMap($ids, $params);
|
|
|
|
$items = M('user_play_info', 'tab_')->field(['count(distinct user_id) count', 'promote_id'])->where($map)->group('promote_id')->select();
|
|
|
|
$records = [];
|
|
|
|
foreach ($items as $item) {
|
|
|
|
$promoteId = $item['promote_id'];
|
|
|
|
if (isset($params['basicPromotes'][$item['promote_id']])) {
|
|
|
|
$promoteId = $params['basicPromotes'][$item['promote_id']];
|
|
|
|
}
|
|
|
|
if (isset($records[$promoteId])) {
|
|
|
|
$records[$promoteId] += $item['count'];
|
|
|
|
} else {
|
|
|
|
$records[$promoteId] = $item['count'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$records = $this->assembleZero($ids, $records, 0);
|
|
|
|
|
|
|
|
return $records;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取指定推广员底下的新创角设备数
|
|
|
|
*/
|
|
|
|
public function getNewCreateRoleDeviceCountByIds(array $ids, array $params = [])
|
|
|
|
{
|
|
|
|
if (count($ids) == 0) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
$params['time_column'] = 'create_time';
|
|
|
|
$map = $this->getPublicAchievementMap($ids, $params);
|
|
|
|
|
|
|
|
$subMap = $map;
|
|
|
|
if (isset($params['begin_time']) && isset($params['begin_time'])) {
|
|
|
|
$subMap['create_time'] = ['lt', $params['begin_time']];
|
|
|
|
}
|
|
|
|
|
|
|
|
$subQuery = M('user_play_info', 'tab_')->field('create_device_number')->group('create_device_number')->where($subMap)->buildSql();
|
|
|
|
$map['create_device_number'] = ['exp', ' not in (' . $subQuery . ')'];
|
|
|
|
$inQuery = M('user_play_info', 'tab_')->field('create_device_number')->group('create_device_number')->where($map)->buildSql();
|
|
|
|
|
|
|
|
$resultMap = ['create_device_number' => ['exp', ' in (' . $inQuery . ')']];
|
|
|
|
$items = M('user_play_info', 'tab_')->field(['count(*) count', 'promote_id'])->where($resultMap)->group('promote_id')->select();
|
|
|
|
|
|
|
|
$records = [];
|
|
|
|
foreach ($items as $item) {
|
|
|
|
$promoteId = $item['promote_id'];
|
|
|
|
if (isset($params['basicPromotes'][$item['promote_id']])) {
|
|
|
|
$promoteId = $params['basicPromotes'][$item['promote_id']];
|
|
|
|
}
|
|
|
|
if (isset($records[$promoteId])) {
|
|
|
|
$records[$promoteId] += $item['count'];
|
|
|
|
} else {
|
|
|
|
$records[$promoteId] = $item['count'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$records = $this->assembleZero($ids, $records, 0);
|
|
|
|
return $records;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取指定推广员底下的新创角IP数
|
|
|
|
*/
|
|
|
|
public function getNewCreateRoleIpCountByIds(array $ids, array $params = [])
|
|
|
|
{
|
|
|
|
if (count($ids) == 0) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
$params['time_column'] = 'create_time';
|
|
|
|
$map = $this->getPublicAchievementMap($ids, $params);
|
|
|
|
|
|
|
|
$subMap = $map;
|
|
|
|
if (isset($params['begin_time']) && isset($params['begin_time'])) {
|
|
|
|
$subMap['create_time'] = ['lt', $params['begin_time']];
|
|
|
|
}
|
|
|
|
|
|
|
|
$subQuery = M('user_play_info', 'tab_')->field('create_ip')->group('create_ip')->where($subMap)->buildSql();
|
|
|
|
$map['create_ip'] = ['exp', ' not in (' . $subQuery . ')'];
|
|
|
|
$inQuery = M('user_play_info', 'tab_')->field('create_ip')->group('create_ip')->where($map)->buildSql();
|
|
|
|
|
|
|
|
$resultMap = ['create_ip' => ['exp', ' in (' . $inQuery . ')']];
|
|
|
|
$items = M('user_play_info', 'tab_')->field(['count(DISTINCT create_ip) count', 'promote_id'])->where($resultMap)->group('promote_id')->select();
|
|
|
|
|
|
|
|
$records = [];
|
|
|
|
foreach ($items as $item) {
|
|
|
|
$promoteId = $item['promote_id'];
|
|
|
|
if (isset($params['basicPromotes'][$item['promote_id']])) {
|
|
|
|
$promoteId = $params['basicPromotes'][$item['promote_id']];
|
|
|
|
}
|
|
|
|
if (isset($records[$promoteId])) {
|
|
|
|
$records[$promoteId] += $item['count'];
|
|
|
|
} else {
|
|
|
|
$records[$promoteId] = $item['count'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$records = $this->assembleZero($ids, $records, 0);
|
|
|
|
return $records;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取指定推广员底下的新创角用户数
|
|
|
|
*/
|
|
|
|
public function getNewCreateRoleUserCountByIds(array $ids, array $params = [])
|
|
|
|
{
|
|
|
|
if (count($ids) == 0) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
$params['time_column'] = 'create_time';
|
|
|
|
$map = $this->getPublicAchievementMap($ids, $params);
|
|
|
|
|
|
|
|
$subMap = $map;
|
|
|
|
if (isset($params['begin_time']) && isset($params['begin_time'])) {
|
|
|
|
$subMap['create_time'] = ['lt', $params['begin_time']];
|
|
|
|
}
|
|
|
|
|
|
|
|
$subQuery = M('user_play_info', 'tab_')->field('user_id')->group('user_id')->where($subMap)->buildSql();
|
|
|
|
if (isset($map['_string'])) {
|
|
|
|
$map['_string'] .= ' and user_id not in (' . $subQuery . ')';
|
|
|
|
} else {
|
|
|
|
$map['_string'] = ' user_id not in (' . $subQuery . ')';
|
|
|
|
}
|
|
|
|
$inQuery = M('user_play_info', 'tab_')->field('user_id')->group('user_id')->where($map)->buildSql();
|
|
|
|
|
|
|
|
$resultMap = ['_string' => 'user_id in (' . $inQuery . ')'];
|
|
|
|
$items = M('user_play_info', 'tab_')->field(['count(DISTINCT user_id) count', 'promote_id'])->where($resultMap)->group('promote_id')->select();
|
|
|
|
// var_dump(M()->getLastSql());
|
|
|
|
$records = [];
|
|
|
|
foreach ($items as $item) {
|
|
|
|
$promoteId = $item['promote_id'];
|
|
|
|
if (isset($params['basicPromotes'][$item['promote_id']])) {
|
|
|
|
$promoteId = $params['basicPromotes'][$item['promote_id']];
|
|
|
|
}
|
|
|
|
if (isset($records[$promoteId])) {
|
|
|
|
$records[$promoteId] += $item['count'];
|
|
|
|
} else {
|
|
|
|
$records[$promoteId] = $item['count'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$records = $this->assembleZero($ids, $records, 0);
|
|
|
|
return $records;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取指定推广员底下的登录用户数
|
|
|
|
*/
|
|
|
|
public function getLoginUserCountByIds(array $ids, array $params = [])
|
|
|
|
{
|
|
|
|
if (count($ids) == 0) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
$params['time_column'] = 'create_time';
|
|
|
|
$map = $this->getPublicAchievementMap($ids, $params);
|
|
|
|
$items = M('login_daily_record', 'tab_')->field(['count(DISTINCT user_id) as count', 'promote_id'])->where($map)->group('promote_id')->select();
|
|
|
|
/* $promoteIds = $map['promote_id'][1];
|
|
|
|
$tempRows = [];
|
|
|
|
$tempCount = 0;
|
|
|
|
$items = [];
|
|
|
|
foreach ($promoteIds as $promoteId) {
|
|
|
|
$tempCount ++;
|
|
|
|
$tempRows[] = $promoteId;
|
|
|
|
if ($tempCount == 20) {
|
|
|
|
$map['promote_id'] = ['in', $tempRows];
|
|
|
|
$rows = M('login_daily_record', 'tab_')->field(['count(DISTINCT user_id) as count', 'promote_id'])->where($map)->group('promote_id')->select();
|
|
|
|
$tempRows = [];
|
|
|
|
$tempCount = 0;
|
|
|
|
$items = array_merge($items, $rows);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
$records = [];
|
|
|
|
foreach ($items as $item) {
|
|
|
|
$promoteId = $item['promote_id'];
|
|
|
|
if (isset($params['basicPromotes'][$item['promote_id']])) {
|
|
|
|
$promoteId = $params['basicPromotes'][$item['promote_id']];
|
|
|
|
}
|
|
|
|
if (isset($records[$promoteId])) {
|
|
|
|
$records[$promoteId] += $item['count'];
|
|
|
|
} else {
|
|
|
|
$records[$promoteId] = $item['count'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$records = $this->assembleZero($ids, $records, 0);
|
|
|
|
|
|
|
|
return $records;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取指定推广员底下的充值次数
|
|
|
|
*/
|
|
|
|
public function getRechargeCountByIds(array $ids, array $params = [])
|
|
|
|
{
|
|
|
|
if (count($ids) == 0) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
$params['time_column'] = 'pay_time';
|
|
|
|
$map = $this->getPublicAchievementMap($ids, $params, 'spend');
|
|
|
|
|
|
|
|
$items = M('spend', 'tab_')->field(['count(*) count', 'promote_id'])->where($map)->group('promote_id')->select();
|
|
|
|
|
|
|
|
$records = [];
|
|
|
|
foreach ($items as $item) {
|
|
|
|
$promoteId = $item['promote_id'];
|
|
|
|
if (isset($params['basicPromotes'][$item['promote_id']])) {
|
|
|
|
$promoteId = $params['basicPromotes'][$item['promote_id']];
|
|
|
|
}
|
|
|
|
if (isset($records[$promoteId])) {
|
|
|
|
$records[$promoteId] += $item['count'];
|
|
|
|
} else {
|
|
|
|
$records[$promoteId] = $item['count'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$records = $this->assembleZero($ids, $records, 0);
|
|
|
|
|
|
|
|
return $records;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取指定推广员底下的充值用户数
|
|
|
|
*/
|
|
|
|
public function getRechargeUserCountByIds(array $ids, array $params = [])
|
|
|
|
{
|
|
|
|
if (count($ids) == 0) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
$params['time_column'] = 'pay_time';
|
|
|
|
$map = $this->getPublicAchievementMap($ids, $params, 'spend');
|
|
|
|
$items = M('spend', 'tab_')->field(['count(distinct user_id) count', 'promote_id'])->where($map)->group('promote_id')->select();
|
|
|
|
|
|
|
|
$records = [];
|
|
|
|
foreach ($items as $item) {
|
|
|
|
$promoteId = $item['promote_id'];
|
|
|
|
if (isset($params['basicPromotes'][$item['promote_id']])) {
|
|
|
|
$promoteId = $params['basicPromotes'][$item['promote_id']];
|
|
|
|
}
|
|
|
|
if (isset($records[$promoteId])) {
|
|
|
|
$records[$promoteId] += $item['count'];
|
|
|
|
} else {
|
|
|
|
$records[$promoteId] = $item['count'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$records = $this->assembleZero($ids, $records, 0);
|
|
|
|
|
|
|
|
return $records;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取指定推广员底下的充值金额(分类型)
|
|
|
|
*/
|
|
|
|
public function getRechargeAmountByIds(array $ids, array $params = [])
|
|
|
|
{
|
|
|
|
if (count($ids) == 0) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
$params['time_column'] = 'pay_time';
|
|
|
|
$map = $this->getPublicAchievementMap($ids, $params, 'spend');
|
|
|
|
$map['pay_status'] = 1;
|
|
|
|
$items = M('spend', 'tab_')->field(['sum(pay_amount) amount', 'promote_id', 'pay_way'])->where($map)->group('promote_id, pay_way')->select();
|
|
|
|
// echo M()->getLastSql();die();
|
|
|
|
$records = [];
|
|
|
|
foreach ($items as $item) {
|
|
|
|
$promoteId = $item['promote_id'];
|
|
|
|
if (isset($params['basicPromotes'][$promoteId])) {
|
|
|
|
$promoteId = $params['basicPromotes'][$promoteId];
|
|
|
|
}
|
|
|
|
if ($item['pay_way'] == -1) {
|
|
|
|
if (isset($records[$promoteId]) && isset($records[$promoteId]['ban_coin'])) {
|
|
|
|
$records[$promoteId]['ban_coin'] += $item['amount'];
|
|
|
|
} else {
|
|
|
|
$records[$promoteId]['ban_coin'] = $item['amount'];
|
|
|
|
}
|
|
|
|
} elseif ($item['pay_way'] == 0) {
|
|
|
|
if (isset($records[$promoteId]) && isset($records[$promoteId]['coin'])) {
|
|
|
|
$records[$promoteId]['coin'] += $item['amount'];
|
|
|
|
} else {
|
|
|
|
$records[$promoteId]['coin'] = $item['amount'];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (isset($records[$promoteId]) && isset($records[$promoteId]['cash'])) {
|
|
|
|
$records[$promoteId]['cash'] += $item['amount'];
|
|
|
|
} else {
|
|
|
|
$records[$promoteId]['cash'] = $item['amount'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach ($ids as $id) {
|
|
|
|
if (isset($records[$id])) {
|
|
|
|
$records[$id] = [
|
|
|
|
'ban_coin' => isset($records[$id]['ban_coin']) ? $records[$id]['ban_coin'] : 0,
|
|
|
|
'coin' => isset($records[$id]['coin']) ? $records[$id]['coin'] : 0,
|
|
|
|
'cash' => isset($records[$id]['cash']) ? $records[$id]['cash'] : 0,
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
$records[$id] = [
|
|
|
|
'ban_coin' => 0,
|
|
|
|
'coin' => 0,
|
|
|
|
'cash' => 0,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $records;
|
|
|
|
}
|
|
|
|
}
|