@ -1135,8 +1135,8 @@ class DownloadController extends BaseController {
public function recharge_data_export() {
$beginTime = strtotime(I('begtime') . ' 00:00:00');
$endtime = strtotime(I('endtime') . ' 23:59:59');
if (($endtime - $beginTime) > 31 * 24 * 3600) {
$this->error('时间范围不能超过31 天');
if (($endtime - $beginTime) > 7 * 24 * 3600) {
$this->error('时间范围不能超过7 天');
}
$map1['chain'] = ['like','%'.'/'.PID.'/'.'%'];
$rs = M('promote','tab_')->where($map1)->field('id,account,nickname')->select();
@ -1182,13 +1182,20 @@ class DownloadController extends BaseController {
}
if (!empty(I('begtime')) & & empty(I('endtime'))) {
$map['tab_spend.pay_time'] = ['egt', strtotime(I('begtime'))];
} elseif (empty(I('begtime')) & & !empty(I('endtime'))) {
$map['tab_spend.pay_time'] = ['elt', strtotime(I('endtime')) + 86399];
} elseif (!empty(I('begtime')) & & !empty(I('endtime'))) {
$map['tab_spend.pay_time'] = ['between', [strtotime(I('begtime')), strtotime(I('endtime')) + 86399]];
}else {
$nowTime = date('Y-m-d');
$initBegTime = date('Y-m-d', strtotime('-6 day', strtotime($nowTime)));
$initEndTime = date('Y-m-d');
$initBegTime = strtotime($initBegTime);
$initEndTime = strtotime($initEndTime);
$map['tab_spend.pay_time'] = ['between',[$initBegTime,$initEndTime]];
}
empty(I('relation_game_id')) || $map['tab_game.relation_game_id'] = I('relation_game_id');
@ -1196,7 +1203,7 @@ class DownloadController extends BaseController {
empty(I('server_id')) || $map['tab_spend.server_id'] = I('server_id');
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('order_number')) || $map['tab_spend.order_number'] = I('order_number');
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];
@ -1233,8 +1240,8 @@ class DownloadController extends BaseController {
$costBegin = I('cost_begin', ''); //充值总额范围
$costEnd = I('cost_end', '');
$nowTime = date('Y-m-d');
$initBegTime = date('Y-m-d', strtotime('-6 day', strtotime($nowTime)));
$initBegTime = empty(I('begtime')) ? $initBegTime : I('begtime');
$initBegTime = date('Y-m-d', strtotime('-7 day', strtotime($nowTime)));
$initBegTime = empty(I('begtime')) ? $initBegTime : I('begtime');
$initEndTime = $nowTime;
$initEndTime = empty(I('endtime')) ? $initEndTime : I('endtime');
$begTime = strtotime($initBegTime);
@ -1854,7 +1861,13 @@ class DownloadController extends BaseController {
->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');
$records = [];
if (!empty($data)) {
if (intval($endTime - $begTime) / (24 * 3600) < = 30) {
@ -1902,6 +1915,30 @@ class DownloadController extends BaseController {
'spend_voucher' => 0,
];
}
$params['all_data'] = 1;
$params['game_ids'] = $allGameIs;
$allData['game_name'] = "合计";
$allData['sdk_version'] = '--';
$allData['role_num'] = $userRepository->getCreateRoleCountByGame($params);//创角数
$allData['user_num'] = $userRepository->getCreateRoleUserCountByGame($params);//创角用户
$allData['new_user_num'] = $userRepository->getNewCreateRoleUserCountByGame($params);//新创角用户
$allData['new_device_num'] = $userRepository->getNewCreateRoleDeviceCountByGame($params);//新创角设备
$allData['new_ip_num'] = $userRepository->getNewCreateRoleIpCountByGame($params);//新创角IP
$allData['login_user_num'] = $userRepository->getLoginCountGroupByGame($params);//登录用户数
$allData['spend_user_num'] = $spendRepository->getPayUserCountByGame($params);//充值人数
$allData['spend_num'] = $spendRepository->getPayCountByGame($params);//充值次数
unset($params['pay_way']);
$allData['spend_all_amount'] = null_to_0($spendRepository->getPayAmountByGameAndType($params));//充值总额
$params['pay_way'] = ['in', '1,2,3,4,5,6'];
$allData['spend_cash'] = null_to_0($spendRepository->getPayAmountByGameAndType($params));//现金充值
$params['pay_way'] = 0;
$allData['spend_generic'] = null_to_0($spendRepository->getPayAmountByGameAndType($params));//通用币充值
$params['pay_way'] = -1;
$allData['spend_binding'] = null_to_0($spendRepository->getPayAmountByGameAndType($params));//绑定币充值
$allData['spend_discount'] = '0.00';
$allData['spend_voucher'] = '0.00';
$records[] = $allData;
}
}
@ -2454,72 +2491,141 @@ class DownloadController extends BaseController {
public function settlementExcelInfo($id,$map) {
$xlsName = "结算明细";
$xlsCell = array(
array('pay_order_number', '游戏订单号') ,
array('game_name', '游戏') ,
array('user_account', '玩家账号') ,
array('promote_account', '推广员账号') ,
array('pay_amount', '订单总额') ,
array('pay_amount_zhi', '直充') ,
array('pay_amount_nei', '内充') ,
array('selle_ratio', '分成比例(直充)') ,
array('selle_ratio', '分成比例(内充)') ,
array('income', '收益') ,
array('pay_time', '充值时间') ,
array('selle_status', '订单状态') ,
'游戏订单号',
'游戏',
'玩家账号',
'推广员账号',
'订单总额',
'直充',
'内充',
'分成比例(直充)',
'分成比例(内充)',
'收益',
'充值时间',
'订单状态',
);
$model = M('spend', 'tab_');
$data = $model->field('pay_order_number,game_name,user_account,promote_account,pay_amount,pay_way,if(selle_ratio >= 0,selle_ratio,0) as selle_ratio,pay_time,selle_status,pay_status,withdraw_id')
->where($map)
->order('id desc')
->select();
->select();
$total = [];
$total = $model->field('sum(pay_amount) as pay_amount,sum(if(pay_way > -1,pay_amount,0)) as direct_pay_amount,sum(if(pay_way = -1,pay_amount,0)) as inner_pay_amount,sum(if(selle_ratio >= 0,selle_ratio * pay_amount,0)) as income')
->where($map)
->find();
$total['direct_pay_amount'] = empty($total['direct_pay_amount']) ? '0.00' : $total['direct_pay_amount'];
$total['inner_pay_amount'] = empty($total['inner_pay_amount']) ? '0.00' : $total['inner_pay_amount'];
$total['income'] = empty($total['income']) ? 0 : $total['income'];
$total['income'] = bcdiv($total['income'], 100, 2);
//提现状态
$withdrawIds = [];
foreach ($data as $key => $value) {
if ($value['withdraw_id'] > 0 & & !in_array($value['withdraw_id'], $withdrawIds)) {
$withdrawIds[] = $value['withdraw_id'];
}
}
if(empty($withdrawIds)) {
$withdrawIds = "-10000" ;
}
$withdrawStatus = M('withdraw', 'tab_')
->where(array('id' => ['in',$withdrawIds]))
->getField('id,status') ;
$csvFileName = $xlsName.'.csv' ;
//设置好告诉浏览器要下载excel文件的headers
header('Content-Description: File Transfer');
header('Content-Type: application/vnd.ms-excel') ;
header('Content-Disposition: attachment; filename="'. $csvFileName .'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public') ;
$fp = fopen('php://output', 'a');//打开output流
mb_convert_variables('gb2312', 'UTF-8', $xlsCell);
fputcsv($fp, $xlsCell);//将数据格式化为CSV格式并写入到output流中
$accessNum = count($data)?:0 ;
foreach ($data as & $list) {
//提现状态
$list['pay_order_number'] = $this->encryption($list['pay_order_number']);
$list['user_account'] = $this->encryption($list['user_account']);
if ($list['pay_status'] == 1) {
switch ($list['selle_status']) {
case 0:
$list['selle_status'] = '未提现';
break;
default:
if ($list['withdraw_id'] > 0) {
$list['selle_status'] = FinanceController::$withdrawStatus[$withdrawStatus[$list['withdraw_id']]];
} else {
$list['selle_status'] = '';
}
break;
$perSize = 5000;//每次查询的条数
$pages = ceil($accessNum / $perSize);
for($i = 1; $i < = $pages; $i++) {
$data = $model->field('pay_order_number,game_name,user_account,promote_account,pay_amount,pay_way,if(selle_ratio >= 0,selle_ratio,0) as selle_ratio,pay_time,selle_status,pay_status,withdraw_id')
->where($map)
->order('id desc')
->limit(($i-1)*$perSize ,$perSize)
->select();
$withdrawIds = [];
foreach ($data as $key => $value) {
if ($value['withdraw_id'] > 0 & & !in_array($value['withdraw_id'], $withdrawIds)) {
$withdrawIds[] = $value['withdraw_id'];
}
} else {
$list['selle_status'] = '支付失败';
}
$list['income'] = bcmul($list['pay_amount'], bcdiv($list['selle_ratio'], 100, 2), 2);
$list['pay_time'] = date('Y-m-d H:i:s', $list['pay_time']);
if($list['pay_way'] == -1) {
$list['pay_amount_zhi'] = 0;
$list['pay_amount_nei'] = $list['pay_amount'];
}else {
$list['pay_amount_zhi'] = $list['pay_amount'];
$list['pay_amount_nei'] = 0;
if(empty($withdrawIds)) {
$withdrawIds = "-10000";
}
}
$withdrawStatus = M('withdraw', 'tab_')
->where(array('id' => ['in',$withdrawIds]))
->getField('id,status');
foreach ($data as & $list) {
//提现状态
$list['pay_order_number'] = $this->encryption($list['pay_order_number']);
$list['user_account'] = $this->encryption($list['user_account']);
if ($list['pay_status'] == 1) {
switch ($list['selle_status']) {
case 0:
$list['selle_status'] = '未提现';
break;
default:
if ($list['withdraw_id'] > 0) {
$list['selle_status'] = FinanceController::$withdrawStatus[$withdrawStatus[$list['withdraw_id']]];
} else {
$list['selle_status'] = '';
}
break;
}
} else {
$list['selle_status'] = '支付失败';
}
$list['income'] = bcmul($list['pay_amount'], bcdiv($list['selle_ratio'], 100, 2), 2);
$list['pay_time'] = date('Y-m-d H:i:s', $list['pay_time']);
if($list['pay_way'] == -1) {
$list['pay_amount_zhi'] = 0;
$list['pay_amount_nei'] = $list['pay_amount'];
}else {
$list['pay_amount_zhi'] = $list['pay_amount'];
$list['pay_amount_nei'] = 0;
}
$csvData["pay_order_number"] = $list["pay_order_number"];
$csvData["game_name"] = $list["game_name"];
$csvData["user_account"] = $list["user_account"];
$csvData["promote_account"] = $list["promote_account"];
$csvData["pay_amount"] = $list["pay_amount"];
$csvData["pay_amount_zhi"] = $list["pay_amount_zhi"];
$csvData["pay_amount_nei"] = $list["pay_amount_nei"];
$csvData["selle_ratio"] = $list["selle_ratio"];
$csvData["selle_ratio1"] = $list["selle_ratio"];
$csvData["income"] = $list["income"];
$csvData["pay_time"] = $list["pay_time"];
$csvData["selle_status"] = $list["selle_status"];
mb_convert_variables('GBK', 'UTF-8', $csvData);
fputcsv($fp, $csvData);
$xlsData[] = $csvData;
}
unset($xlsData);
ob_flush();
flush();
}
$allData['pay_order_number'] = '合计';
$allData['game_name'] = '--';
$allData['user_account'] = '--';
$allData['promote_account'] = '--';
$allData['pay_amount'] = $total['pay_amount'];
$allData['pay_amount_zhi'] = $total['direct_pay_amount'];
$allData['pay_amount_nei'] = $total['inner_pay_amount'];
$allData['selle_ratio'] = '--';
$allData['selle_ratio1'] = '--';
$allData['income'] = $total['income'];
$allData['pay_time'] = '--';
$allData['selle_status'] = '--';
mb_convert_variables('GBK', 'UTF-8', $allData);
fputcsv($fp, $allData);
$xlsData[] = $allData;
fclose($fp);
$this->backSuccessExport($id);
$xlsData = $data;
$this->exportExcel($xlsName, $xlsCell, $xlsData,$id);
// $this->exportExcel($xlsName, $xlsCell, $xlsData,$id);
}
@ -2797,7 +2903,7 @@ class DownloadController extends BaseController {
array('role_level','等级'),
array('recharge_cost','充值总额'),
array('recharge_count','充值次数'),
array('recharge_cost_today','今 日充值'),
array('recharge_cost_today','昨 日充值'),
array('unlogin_day','未登录天数'),
array('play_time','最后登录时间'),
array('promote_account','推广员账号'),
@ -2849,7 +2955,8 @@ class DownloadController extends BaseController {
->buildSql();
$map['_string'] = 'ui.role_id in (' . $subQuery . ')';
}
$map['uc.create_time'] = ['between', [$map['begintime'], $map['endtime'] - 1]];
$secondDay = 24*3600 + 1;
$map['uc.create_time'] = ['between', [$map['begintime'], $map['endtime'] - $secondDay]];
unset($map['begintime']);
unset($map['endtime']);
//$spendMap['_string'] = 'uc.game_id = tab_user_play_info.game_id and uc.server_id = tab_user_play_info.server_id and uc.role_id = tab_user_play_info.role_id';
@ -2858,34 +2965,55 @@ class DownloadController extends BaseController {
$field = $fieldUC . ',' . $fieldUI;
$subQuery = M('user_play_data_count', 'tab_')->alias('uc')
->field($field)
->join('tab_user_play_info as ui on ui.game_id = uc.game_id and ui.server_id = uc.server_id and ui.role_id = uc.role_id')
->join('left join tab_user_play_info as ui on ui.game_id = uc.game_id and ui.server_id = uc.server_id and ui.role_id = uc.role_id')
->where($map)
->group('uc.role_id,uc.server_id,uc.game_id')
->buildSql();
$roles = M()->alias('record')
->table($subQuery)
->select();
$total = [];
$total = M('user_play_data_count', 'tab_')->alias('uc')
->field($fieldUC)
->join('left join tab_user_play_info as ui on ui.game_id = uc.game_id and ui.server_id = uc.server_id and ui.role_id = uc.role_id')
->where($map)
->find();
foreach ($roles as $role) {
$records[] = [
'user_account' => encryption($role['user_account']),
'game_name' => $role['game_name'],
'role_name' => $role['role_name'],
'role_id' => $role['role_id'],
'role_level' => $role['role_level'],
'server_id' => $role['server_id'],
'server_name' => $role['server_name'],
'user_account' => empty($role['user_account']) ? '--' : e ncryption($role['user_account']),
'game_name' => empty($role['game_name']) ? '--' : $role['game_name'],
'role_name' => empty($role['role_name']) ? '--' : $role['role_name'],
'role_id' => empty($role['role_id']) ? '--' : $role['role_id'],
'role_level' => empty($role['role_level']) ? '--' : $role['role_level'],
'server_id' => empty($role['server_id']) ? '--' : $role['server_id'],
'server_name' => empty($role['server_name']) ? '--' : $role['server_name'],
'recharge_cost' => empty($role['recharge_cost']) ? 0 : $role['recharge_cost'],
'recharge_count' => empty($role['recharge_count']) ? 0 : $role['recharge_count'],
'recharge_cost_today' => empty($role['recharge_cost_today']) ? 0 : $role['recharge_cost_today'],
'play_time' => $role['play_time'],
'play_ip' => $role['play_ip'],
'promote_id' => $role['promote_id'],
'promote_account' => $role['promote_account'],
'sdk_version' => $role['sdk_version'],
'unlogin_day' => intval((strtotime(date('Y-m-d 00:00:00')) - strtotime(date('Y-m-d 00:00:00', $role['play_time']))) / (24 * 3600))
'play_time' => empty($role['play_time']) ? '--' : $role['play_time'],
'play_ip' => empty($role['play_ip']) ? '--' : $role['play_ip'],
'promote_id' => empty($role['promote_id']) ? '--' : $role['promote_id'],
'promote_account' => empty($role['promote_account']) ? '--' : $role['promote_account'],
'sdk_version' => empty($role['sdk_version']) ? '--' : $role['sdk_version'],
'unlogin_day' => empty($role['play_time']) ? '--' : intval((strtotime(date('Y-m-d 00:00:00')) - strtotime(date('Y-m-d 00:00:00', $role['play_time']))) / (24 * 3600))
];
}
$allData['user_account'] = '合计';
$allData['game_name'] = '--';
$allData['role_name'] = '--';
$allData['role_id'] = '--';
$allData['role_level'] = '--';
$allData['server_id'] = '--';
$allData['server_name'] = '--';
$allData['recharge_cost'] = $total['recharge_cost'];
$allData['recharge_count'] = $total['recharge_count'];
$allData['recharge_cost_today'] = $total['recharge_cost_today'];
$allData['play_time'] = '--';
$allData['play_ip'] = '--';
$allData['promote_id'] = '--';
$allData['promote_account'] = '--';
$allData['sdk_version'] = '--';
$allData['unlogin_day'] = '--';
$xlsData = [];
foreach ($records as $key1 => $value1) {
$value1['user_account'] = $this->encryption($value1['user_account']);
@ -2897,6 +3025,7 @@ class DownloadController extends BaseController {
}
$xlsData[] = $value1;
}
$xlsData[] = $allData;
$this->exportExcel($xlsName, $xlsCell, $xlsData,$id);
}
@ -2957,7 +3086,7 @@ class DownloadController extends BaseController {
$value1['proinfo'] = $value1['pro_account'].'('.$value1['pro_real_name'].')';
// $value1['user_account'] = substr_replace($value1['user_account'],'************',3,12);
$value1['user_account'] = $this->encryption($value1['user_account']);
$value1['order_number'] = $this->encryption($value1['order_number']);
$value1['pay_ order_number'] = $this->encryption($value1['pay_ order_number']);
if(!empty($value1['chain'])) {
$chain = trim($value1['chain'],'/');
$chainArr = explode('/', $chain);
@ -2977,9 +3106,9 @@ class DownloadController extends BaseController {
}
}
}
$csvData["user_account"] = $value1["user_account"];
$csvData["order_number"] = $value1["order_number"];
$csvData["pay_ order_number"] = $value1["pay_ order_number"];
$csvData["pay_amount"] = $value1["pay_amount"];
$csvData["pay_way"] = $value1["pay_way"];
$csvData["game_name"] = $value1["game_name"];
@ -2997,6 +3126,28 @@ class DownloadController extends BaseController {
ob_flush();
flush();
}
$income = '0.00';
$income = M('Spend', 'tab_')
->field('sum(tab_spend.pay_amount) as income')
->join('tab_game on tab_spend.game_id = tab_game.id')
->join('left join tab_promote on tab_spend.promote_id = tab_promote.id')
->where($map)
->order('tab_spend.id desc')
->find()['income'];
$csvData1["user_account"] = "合计";
$csvData1["pay_order_number"] = "--";
$csvData1["pay_amount"] = $income;
$csvData1["pay_way"] = "--";
$csvData1["game_name"] = "--";
$csvData1["server_name"] = "--";
$csvData1["game_player_name"] = "--";
$csvData1["p_p_proinfo"] = "--";
$csvData1["p_proinfo"] = "--";
$csvData1["proinfo"] = "--";
$csvData1["pay_time"] = "--";
mb_convert_variables('GBK', 'UTF-8', $csvData1);
fputcsv($fp, $csvData1);
$xlsData[] = $csvData1;
fclose($fp);
$this->backSuccessExport($id);
}