优化推广员后台汇总查询

master
ELF 4 years ago
parent 7468057834
commit f95125892a

@ -8,6 +8,7 @@ use Base\Model\UserModel;
use Base\Tool\IdCard;
use Base\Tool\Registry;
use Think\Model;
use Base\Repository\SpendRepository;
class PromoteService {
@ -1233,6 +1234,27 @@ class PromoteService {
}
}
/**
* 推广员所属公会历史所有推广过的游戏ID
* @todo 如果没有用户充值则该游戏ID不会显示
*/
public function getHistoryGameIds($promote)
{
$topPromote = $this->getTopPromote($promote);
$spendRepository = new SpendRepository();
$map = [];
$map['_string'] = ' promote_id in(' . $this->subInSql($topPromote) . ')';
$map = $spendRepository->withIsCheck($map);
$historyGameIds = M('spend', 'tab_')->field(['distinct game_id'])->where($map)->getField('game_id', true);
if (!$historyGameIds) {
$historyGameIds = [];
}
$nowGameIds = $topPromote['game_ids'] == '' ? [] : explode(',', $topPromote['game_ids']);
return array_unique(array_merge($historyGameIds, $nowGameIds));
}
public function checkPromoteLimitRule($promote)
{
$topPromote = $this->getTopPromote($promote);

@ -2279,92 +2279,64 @@ class DownloadController extends BaseController
* 数据汇总添加下载
* @author sunke
*/
public function summary_data_export() {
$promoteId = I('promote_id',0);
$teamLeaderId = I('team_leader_id',0);
$own_id = I('own_id',0);
$relation_game_id = I('relation_game_id',0);
$sdk_version = I('sdk_version',0);
$begtime = I('begtime','');
$endtime = I('endtime','');
// $childPromoteIds = getAllChildPromoteList(3);
$map1['chain'] = ['like','%'.'/'.PID.'/'.'%'];
$rs = M('promote','tab_')->where($map1)->field('id,account,nickname')->select();
$childPromoteIds = '';
if(empty($rs)) {
$map['tab_apply.promote_id'] = PID;
}else {
foreach ($rs as $rsKey => $rsValue) {
$id = $rsValue['id'];
$childPromoteIds .= $id.',';
}
$childPromoteIds = rtrim($childPromoteIds, ',');
$childPromoteIds .= ',' . PID;
$map['tab_apply.promote_id'] = ['in', $childPromoteIds];
}
public function summary_data_export()
{
$ownId = intval(I('own_id'), 0);//本账号
$relationGameId = intval(I('relation_game_id', 0));
$sdkVersion = intval(I('sdk_version', 0));
$serverId = I('server_id', '');
$nowTime = date('Y-m-d');
$initBegTime = date('Y-m-d', strtotime('-6 day', strtotime($nowTime)));
$initBegTime = empty(I('begtime')) ? $initBegTime : I('begtime');
$initEndTime = $nowTime;
$initEndTime = empty(I('endtime')) ? $initEndTime : I('endtime');
$begTime = strtotime($initBegTime);
$endTime = strtotime($initEndTime);
$endTime += 3600 * 24;
$levelPromote = $this->getLevelPromote();
$queryPromote = $this->getQueryPromote($levelPromote);
$map2[] = [
'_logic' => 'or',
'id' => $queryPromote['id'],
'chain' => ['like', $queryPromote['chain'] . $queryPromote['id'] . '/%']
];
$ids = M('promote', 'tab_')->where($map2)->getField('id', true);
if(empty($ids)) {
$ids = array();
}
if(empty($levelPromote)) {
array_push($ids,PID);
}
// array_push($ids,$queryPromote['id']);
if (!empty($ids)) {
$map['tab_apply.promote_id'] = ['in',$ids];
}else {
$map['_string'] = '1<>1';
}
if (!empty($own_id)) {
if (!empty($map['_string'])) {
unset($map['_string']);
}
$map['tab_apply.promote_id'] = $queryPromote['id'];//本账号
$loginPromote = $this->getLoginPromote();
$params = [];
$map = [];
$map = ['_string' => '1=1'];
if ($ownId) {
$params['promote_ids'] = $queryPromote['id'];
} else {
$subMap['chain'] = ['like', $queryPromote['chain'] . $queryPromote['id'] . '/%'];
$ids = M('promote', 'tab_')->where($subMap)->getField('id', true);
$ids[] = $queryPromote['id'];
$params['promote_ids'] = $ids;
}
empty($relation_game_id) || $map['tab_game.relation_game_id'] = $relation_game_id;
empty($sdk_version) || $map['tab_game.sdk_version'] = $sdk_version;
if(empty($begtime) && empty($endtime)) {
$nowTime = date('Y-m-d');
$begtime1 = date('Y-m-d', strtotime('-6 day', strtotime($nowTime)));
$endtime1 = $nowTime;
$map["apply_time"] = ["between",[strtotime($begtime1),strtotime($endtime1) + 3600*24]];
if ($relationGameId > 0) {
$map['relation_game_id'] = $relationGameId;
}
if(!empty($begtime) && !empty($endtime)) {
$map["apply_time"] = ["between",[strtotime($begtime),strtotime($endtime) + 3600 * 24]];
if ($sdkVersion > 0) {
$map['sdk_version'] = $sdkVersion;
}
$serverField = '';
$serverJoin = '';
if (!empty(I('server_id'))) {
$map['tab_server.id'] = I('server_id');
if (!empty($serverId)) {
$params['server_id'] = $serverId;
}
$conditions = json_encode($map,TRUE);
$addtime = time();
$data = [
'logid' => 'hz_'.time(),
'promote_id' => PID,
'type' => '/Home/Query/summary',
'dataname' => '数据汇总数据',
'status' => 0,
'addtime' => $addtime,
'begintime' => 0,
'content' => '',
'conditions' =>$conditions
];
$res = M('downloadlog','tab_')->add($data);
if (!$res) {
$params['begin_time'] = $begTime;
$params['end_time'] = $endTime - 1;
$conditions = json_encode(['map' => $map, 'params' => $params], true);
$addtime = time();
$data = [
'logid' => 'hz_'.time(),
'promote_id' => PID,
'type' => '/Home/Query/summary',
'dataname' => '数据汇总数据',
'status' => 0,
'addtime' => $addtime,
'begintime' => 0,
'content' => '',
'conditions' =>$conditions
];
$res = M('downloadlog','tab_')->add($data);
if (!$res) {
// $this->ajaxReturn(array("status" => -1, "msg" => "添加导出日志失败", 'ret' => $res));
$this->error('添加下载失败');
}
@ -3196,7 +3168,7 @@ public function iosDetailExcelInfo($id,$map) {
}
//数据汇总excel信息
public function summaryExcelInfo($id,$map) {
public function summaryExcelInfo($id, $map) {
$xlsName = "数据汇总";
$xlsCell = array(
array('game_name','游戏名称'),
@ -3219,51 +3191,26 @@ public function iosDetailExcelInfo($id,$map) {
$xlsCell[] = array('spend_discount','折扣币充值');
$xlsCell[] = array('spend_voucher','代金券使用');
}
if(!empty($map['tab_apply.promote_id'][1])) {
$params['promote_ids'] = $map['tab_apply.promote_id'][1];
$loginPromote = $this->getLoginPromote();
$map = json_decode(json_encode($map), true);
$gameMap = $map['map'];
$params = $map['params'];
$promoteService = new PromoteService();
$allGameIs = $promoteService->getHistoryGameIds($loginPromote);
if ($allGameIs && count($allGameIs) > 0) {
$gameMap['_string'] .= ' and id in(' . implode(',', $allGameIs) . ')';
} else {
$gameMap['_string'] .= '1=0';
}
$serverJoin = '';
$initBegTime = date('Y-m-d', strtotime('-6 day', strtotime($nowTime)));
$initBegTime = empty(I('begtime')) ? $initBegTime : I('begtime');
$initEndTime = $nowTime;
$initEndTime = empty(I('endtime')) ? $initEndTime : I('endtime');
$begTime = strtotime($initBegTime);
$endTime = strtotime($initEndTime);
$params['begin_time'] = $begTime;
$params['end_time'] = $endTime -1;
if(!empty($map['apply_time'][1])) {
$begTime = $map['apply_time'][1][0];
$endTime = $map['apply_time'][1][1];
$params['begin_time'] = $begTime;
$params['end_time'] = $endTime -1;
unset($map['apply_time']);
}
if(!empty($map['tab_server.server_id'])) {
$serverJoin = 'tab_server on tab_server.game_id = tab_apply.game_id';
$params['server_id'] = $map['tab_server.server_id'];
}
$data = M('Apply', 'tab_')
->field('tab_apply.game_id,tab_apply.game_name,tab_apply.sdk_version')
->join('tab_game as g on g.id = tab_apply.game_id')
->join($serverJoin)//关联区服表
->where($map)
->group('tab_apply.game_id')
->order('g.sort desc,g.id desc')
->select();
$allGameIs = M('Apply', 'tab_')
->field('distinct tab_apply.game_id')
->join('tab_game as g on g.id = tab_apply.game_id')
->join($serverJoin)
->where($map)
->select();
$allGameIs = array_column($allGameIs, 'game_id');
$data = M('game', 'tab_')->where($gameMap)->order('sort desc,id desc')->select();
$records = [];
if (!empty($data)) {
if (intval($endTime - $begTime) / (24 * 3600) <= 31) {
$gameIds = [];
foreach ($data as $list) {
$gameIds[] = $list['game_id'];
}
$gameIds = array_column($data, 'id');
$params['game_ids'] = $gameIds;
$userRepository = new UserRepository();
$spendRepository = new SpendRepository();
@ -3273,36 +3220,43 @@ public function iosDetailExcelInfo($id,$map) {
$newDeviceNumList = $userRepository->getNewCreateRoleDeviceCountByGame($params);//新创角设备
$newIpNumList = $userRepository->getNewCreateRoleIpCountByGame($params);//新创角IP
$loginUserNumList = $userRepository->getLoginCountGroupByGame($params);//登录用户数
$spendUserNumList = $spendRepository->getPayUserCountGroupByGame($params);//充值人数
$spendNumList = $spendRepository->getPayCountGroupByGame($params);//充值次数
$spendAllAmountList = $spendRepository->getPayAmountGroupByGameAndType($params);//充值总额
$params['pay_way'] = ['in', '1,2,3,4,5,6'];
$spendCashList = $spendRepository->getPayAmountGroupByGameAndType($params);//现金充值
$params['pay_way'] = 0;
$spendGenericList = $spendRepository->getPayAmountGroupByGameAndType($params);//通用币充值
$params['pay_way'] = -1;
$spendBindingList = $spendRepository->getPayAmountGroupByGameAndType($params);//绑定币充值
foreach ($data as &$list) {
if ($this->canViewUserRecharge) {
$spendUserNumList = $spendRepository->getPayUserCountGroupByGame($params);//充值人数
$spendNumList = $spendRepository->getPayCountGroupByGame($params);//充值次数
$spendAllAmountList = $spendRepository->getPayAmountGroupByGameAndType($params);//充值总额
$params['pay_way'] = ['in', '1,2,3,4,5,6'];
$spendCashList = $spendRepository->getPayAmountGroupByGameAndType($params);//现金充值
$params['pay_way'] = 0;
$spendGenericList = $spendRepository->getPayAmountGroupByGameAndType($params);//通用币充值
$params['pay_way'] = -1;
$spendBindingList = $spendRepository->getPayAmountGroupByGameAndType($params);//绑定币充值
}
foreach ($data as $list) {
$gameId = $list['game_id'];
$records[] = [
$record = [
'game_id' => $gameId,
'game_name' => $list['game_name'],
'sdk_version' => $list['sdk_version'],
'role_num' => $roleNumList[$gameId],
'user_num' => $userNumList[$gameId],
'new_user_num' => $newUserNumList[$gameId],
'new_device_num' => $newDeviceNumList[$gameId],
'new_ip_num' => $newIpNumList[$gameId],
'login_user_num' => $loginUserNumList[$gameId],
'spend_user_num' => $spendUserNumList[$gameId],
'spend_num' => $spendNumList[$gameId],
'spend_all_amount' => $spendAllAmountList[$gameId],
'spend_cash' => $spendCashList[$gameId],
'spend_generic' => $spendGenericList[$gameId],
'spend_binding' => $spendBindingList[$gameId],
'spend_discount' => 0,
'spend_voucher' => 0,
'sdk_version' => $list['sdk_version'] == 1 ? '安卓' : '苹果',
'role_num' => intval($roleNumList[$gameId]),
'user_num' => intval($userNumList[$gameId]),
'new_user_num' => intval($newUserNumList[$gameId]),
'new_device_num' => intval($newDeviceNumList[$gameId]),
'new_ip_num' => intval($newIpNumList[$gameId]),
'login_user_num' => intval($loginUserNumList[$gameId]),
];
if ($this->canViewUserRecharge) {
if ($this->canViewUserRecharge) {
$record['spend_user_num'] = intval($spendUserNumList[$gameId]);
$record['spend_num'] = intval($spendNumList[$gameId]);
$record['spend_all_amount'] = $spendAllAmountList[$gameId];
$record['spend_cash'] = $spendCashList[$gameId];
$record['spend_generic'] = $spendGenericList[$gameId];
$record['spend_binding'] = $spendBindingList[$gameId];
$record['spend_discount'] = 0;
$record['spend_voucher'] = 0;
}
}
$records[] = $record;
}
$params['all_data'] = 1;
$params['game_ids'] = $allGameIs;
@ -3316,14 +3270,6 @@ public function iosDetailExcelInfo($id,$map) {
$allData['login_user_num'] = $userRepository->getLoginCountGroupByGame($params);//登录用户数
if($this->canViewUserRecharge) {
$record['spend_user_num'] = $spendUserNumList[$gameId];
$record['spend_num'] = $spendNumList[$gameId];
$record['spend_all_amount'] = $spendAllAmountList[$gameId];
$record['spend_cash'] = $spendCashList[$gameId];
$record['spend_generic'] = $spendGenericList[$gameId];
$record['spend_binding'] = $spendBindingList[$gameId];
$record['spend_discount'] = 0;
$record['spend_voucher'] = 0;
$allData['spend_user_num'] = $spendRepository->getPayUserCountByGame($params);//充值人数
$allData['spend_num'] = $spendRepository->getPayCountByGame($params);//充值次数
unset($params['pay_way']);
@ -3338,24 +3284,10 @@ public function iosDetailExcelInfo($id,$map) {
$allData['spend_voucher'] = '0.00';
}
$records[] = $record;
$records[] = $allData;
}
}
$xlsData = [];
foreach ($records as $key1 => $value1) {
if($value1["sdk_version"] == 1) {
$value1["sdk_version"] = "安卓";
}
if($value1["sdk_version"] == 2) {
$value1["sdk_version"] = "苹果";
}
$xlsData[] = $value1;
}
$this->exportExcel($xlsName, $xlsCell, $xlsData,$id);
$this->exportExcel($xlsName, $xlsCell, $records,$id);
}
/*

@ -1302,61 +1302,44 @@ class QueryController extends BaseController
$loginPromote = $this->getLoginPromote();
$map = [];
$map = ['_string' => '1=1'];
if ($ownId) {
$map['a.promote_id'] = $queryPromote['id'];
$params['promote_ids'] = $queryPromote['id'];
} else {
$map['chain'] = ['like', $queryPromote['chain'] . $queryPromote['id'] . '/%'];
$ids = M('promote', 'tab_')->where($map)->getField('id', true);
$subMap['chain'] = ['like', $queryPromote['chain'] . $queryPromote['id'] . '/%'];
$ids = M('promote', 'tab_')->where($subMap)->getField('id', true);
$ids[] = $queryPromote['id'];
$map = [];
$map['a.promote_id'] = ['in', $ids];
$params['promote_ids'] = $ids;
}
if ($relationGameId > 0) {
$map['g.relation_game_id'] = $relationGameId;
$map['relation_game_id'] = $relationGameId;
}
if ($sdkVersion > 0) {
$map['a.sdk_version'] = $sdkVersion;
$map['sdk_version'] = $sdkVersion;
}
$serverJoin = '';
if (!empty($serverId)) {
$serverJoin = 'tab_server as s on s.game_id = a.game_id';
$map['s.server_id'] = $serverId;
$params['server_id'] = $serverId;
}
$params['begin_time'] = $begTime;
$params['end_time'] = $endTime - 1;
$data = M('Apply', 'tab_')->alias('a')
->field('a.game_id,a.game_name,a.sdk_version')
->join('tab_game as g on g.id = a.game_id')
->join($serverJoin)
->where($map)
->group('a.game_id')
->order('g.sort desc,g.id desc')
->page($page, $row)
->select();
$count = M('Apply', 'tab_')->alias('a')
->join('tab_game as g on g.id = a.game_id')
->join($serverJoin)
->where($map)
->count('distinct a.game_id');
$allGameIs = M('Apply', 'tab_')->alias('a')
->field('distinct a.game_id')
->join('tab_game as g on g.id = a.game_id')
->join($serverJoin)
->where($map)
->select();
$allGameIs = array_column($allGameIs, 'game_id');
$promoteService = new PromoteService();
$allGameIs = $promoteService->getHistoryGameIds($loginPromote);
if ($allGameIs && count($allGameIs) > 0) {
$map['_string'] .= ' and id in(' . implode(',', $allGameIs) . ')';
} else {
$map['_string'] .= '1=0';
}
$data = M('game', 'tab_')->where($map)->order('sort desc,id desc')->page($page, $row)->select();
$count = M('game', 'tab_')->where($map)->count();
$records = [];
$allData = [];
if (!empty($data)) {
if (intval($endTime - $begTime) / (24 * 3600) <= 31) {
$gameIds = array_column($data, 'game_id');
$gameIds = array_column($data, 'id');
$params['game_ids'] = $gameIds;
$userRepository = new UserRepository();
@ -1378,7 +1361,7 @@ class QueryController extends BaseController
$params['pay_way'] = -1;
$spendBindingList = $spendRepository->getPayAmountGroupByGameAndType($params);//绑定币充值
}
foreach ($data as &$list) {
foreach ($data as $list) {
$gameId = $list['game_id'];
$record = [
'game_id' => $gameId,

@ -174,14 +174,14 @@
<tr class="num2">
<td>{$vo.game_name}</td>
<td>{:getSDKTypeName($vo['sdk_version'],true)}</td>
<td>{$vo.role_num}</td>
<td>{$vo.user_num}</td>
<td>{$vo.new_user_num}|{$vo.new_device_num}</td>
<td>{$vo.new_ip_num}</td>
<td>{$vo.login_user_num}</td>
<td><?=intval($vo['role_num'])?></td>
<td><?=intval($vo['user_num'])?></td>
<td><?=intval($vo['new_user_num']).'|'.intval($vo['new_device_num'])?></td>
<td><?=intval($vo['new_ip_num'])?></td>
<td><?=intval($vo['login_user_num'])?></td>
<?php if ($canViewUserRecharge) :?>
<td>{$vo.spend_user_num}</td>
<td>{$vo.spend_num}</td>
<td><?=intval($vo['spend_user_num'])?></td>
<td><?=intval($vo['spend_num'])?></td>
<td>{$vo.spend_all_amount|default=0}</td>
<td class="spend-element th-hide">{$vo.spend_cash|default=0}</td>
<td class="spend-element th-hide">{$vo.spend_generic|default=0}</td>

Loading…
Cancel
Save