@ -18,7 +18,8 @@ use GuzzleHttp\Client;
/**
* @author elf< 360197197 @ qq . com >
*/
class DownloadController extends BaseController {
class DownloadController extends BaseController
{
public $payWay = [
-1 => '绑币',
0 => '平台币',
@ -46,6 +47,14 @@ class DownloadController extends BaseController {
0 => '下单未支付',
1 => '充值成功',
];
public $spendRepository;
protected function _initialize()
{
parent::_initialize();
$this->spendRepository = new SpendRepository();
}
/**
* excel
@ -1491,8 +1500,6 @@ class DownloadController extends BaseController {
empty(I('game_player_name')) || $map['tab_spend.game_player_name'] = ['like', '%' . I('game_player_name') . '%'];
empty(I('user_account')) || $map['tab_spend.user_account'] = ['like', '%' . I('user_account') . '%'];
empty(I('pay_order_number')) || $map['tab_spend.pay_order_number'] = I('pay_order_number');
// $map['tab_spend.pay_status'] = 1;
// $map['tab_spend.is_check'] = ['neq', 2];
if (isset($_REQUEST['pay_status']) & & $_REQUEST['pay_status'] !== '') {
$payStatus = intval(I('pay_status'));
@ -1500,9 +1507,12 @@ class DownloadController extends BaseController {
$map['tab_spend.pay_status'] = $payStatus + 2;
}
}
$conditions = json_encode($map,TRUE);
$addtime = time();
$data = [
$map = $this->spendRepository->withIsCheck($map, 'tab_spend.is_check');
$conditions = json_encode($map, true);
$addtime = time();
$data = [
'logid' => 'cz_'.time(),
'promote_id' => PID,
'type' => '/Home/Query/recharge',
@ -2234,6 +2244,8 @@ class DownloadController extends BaseController {
}
}
$spendMap = $this->spendRepository->withIsCheck($spendMap);
$spendSubSql = M('spend', 'tab_')->field(['game_id', 'server_id', 'sum(pay_amount) amount'])->where($spendMap)->group('game_id, server_id')->select(false);
$roleSubSql = M('user_play_info', 'tab_')->field(['game_id', 'server_id', 'count(*) count'])->where($roleMap)->group('game_id, server_id')->select(false);
@ -2267,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('添加下载失败');
}
@ -3184,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','游戏名称'),
@ -3207,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();
@ -3261,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;
@ -3304,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']);
@ -3326,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);
}
/*
@ -4476,6 +4420,9 @@ public function iosDetailExcelInfo($id,$map) {
$spendMap['today.pay_status'] = 1;
$spendMap['today.pay_time'] = ['between', [$now, $nowTimeEnd]];
$map = $this->spendRepository->withIsCheck($map, 'uc.is_check');
$spendMap = $this->spendRepository->withIsCheck($spendMap, 'today.is_check');
$fieldToday = M('spend', 'tab_')->alias('today')
->field('sum(pay_amount) as recharge_cost_today')
->where($spendMap)