优化游戏导出

master
chenzhi 4 years ago
parent f00ef7fcc9
commit c5bc21cb36

@ -8352,212 +8352,212 @@ class ExportController extends Controller
/**
*充值-》财务管理-》游戏统计-》导出
*/
public function exportGameStatistics() {
$month = I("count_date");
$xlsName = $month . '游戏统计导出';
$xlsCell = array(
array('game_name','游戏'),
array('sdk_version','设备类型'),
array('game_type_name','游戏类型'),
array('partner_name','合作公司'),
array('cash_count','游戏现金金额'),
array('balance_coin_count','平台币直充支出'),
array('inside_cash_count','内充支出'),
array('all_cash_count','游戏内充值合计'),
array('notice_fail_count','联运通知失败合计'),
array('agg_wm_amount','聚合万盟数据'),
array('agg_wm_failed_amount','聚合万盟通知失败'),
array('test_amount','聚合平台测试订单'),
array('agg_amount','聚合其他渠道数据'),
array('agg_failed_amount','聚合其他渠道通知失败订单'),
);
$map = [];
$searchGameIds = null;
$game_ids = array_column(getGameByName(I("game_name"), I("sdk_type")), 'id');
$gameWhere = [];
$testStrWhere = '1=1';
if ($game_ids) {
$map['s.game_id'] = ['in', $game_ids];
$gameWhere['id'] = ['in', $game_ids];
}
if (!empty(I('partner_id'))) {
$map['g.partner_id'] = I('partner_id');
$gameWhere['partner_id'] = I('partner_id');
}
// public function exportGameStatistics() {
// $month = I("count_date");
// $xlsName = $month . '游戏统计导出';
if (!empty(I('timestart'))) {
$timestart = strtotime(I('timestart'));
$map['_string'] = "s.payed_time >= {$timestart}";
$testStrWhere .= " and pay_time >= {$timestart}";
}
if (!empty(I('timeend'))) {
$timeend = strtotime(I('timeend') . ' 23:59:59');
if (!empty($map['_string'])) {
$map['_string'] .= " and ";
}
$map['_string'] .= " s.pay_time <= {$timeend}";
$testStrWhere .= " and pay_time <= {$timeend}";
}
if (!empty(I('game_type_id'))) {
$map['g.game_type_id'] = I('game_type_id');
$gameWhere['game_type_id'] = I('game_type_id', 0);
}
$searchGameIds = M('game', 'tab_')->where($gameWhere)->getField('id', true);
// $xlsCell = array(
// array('game_name','游戏'),
// array('sdk_version','设备类型'),
// array('game_type_name','游戏类型'),
// array('partner_name','合作公司'),
// array('cash_count','游戏现金金额'),
// array('balance_coin_count','平台币直充支出'),
// array('inside_cash_count','内充支出'),
// array('all_cash_count','游戏内充值合计'),
// array('notice_fail_count','联运通知失败合计'),
// array('agg_wm_amount','聚合万盟数据'),
// array('agg_wm_failed_amount','聚合万盟通知失败'),
// array('test_amount','聚合平台测试订单'),
// array('agg_amount','聚合其他渠道数据'),
// array('agg_failed_amount','聚合其他渠道通知失败订单'),
// );
// $map = [];
// $searchGameIds = null;
// $game_ids = array_column(getGameByName(I("game_name"), I("sdk_type")), 'id');
// $gameWhere = [];
// $testStrWhere = '1=1';
// if ($game_ids) {
// $map['s.game_id'] = ['in', $game_ids];
// $gameWhere['id'] = ['in', $game_ids];
// }
$xlsData = D("spend")->gameStatistics($map);
$uniqueCodes = array_column($xlsData, 'unique_code');
$gameIds = array_column($xlsData, 'game_id');
$uniqueCodes = array_filter($uniqueCodes, function($value) {
if ($value) {
return true;
}
return false;
});
// if (!empty(I('partner_id'))) {
// $map['g.partner_id'] = I('partner_id');
// $gameWhere['partner_id'] = I('partner_id');
// }
$gameSets = M('game_set', 'tab_')->field(['game_id', 'pay_notify_url'])->select();
$gameSets = index_by_column('game_id', $gameSets);
// if (!empty(I('timestart'))) {
// $timestart = strtotime(I('timestart'));
// $map['_string'] = "s.payed_time >= {$timestart}";
// $testStrWhere .= " and pay_time >= {$timestart}";
// }
$searchGameCodes = [];
$testList = [];
$testWhere = [
'game_id' => 0,
'_string' => $testStrWhere,
];
if (count($searchGameIds) > 0) {
$searchGameCodes = M('game', 'tab_')->where(['id' => ['in', $searchGameIds], 'unique_code' => ['neq', '']])->getField('unique_code', true);
$searchGameCodes = array_unique($searchGameCodes);
$testWhere['game_id'] = ['in', $searchGameIds];
$testRows = M('test_order', 'tab_')
->field(['game_id', 'sum(pay_amount) amount'])
->where($testWhere)
->group('game_id')
->select();
foreach ($testRows as $testRow) {
$testList[$testRow['game_id']] = round(floatval($testRow['amount']), 2);
}
}
// if (!empty(I('timeend'))) {
// $timeend = strtotime(I('timeend') . ' 23:59:59');
// if (!empty($map['_string'])) {
// $map['_string'] .= " and ";
// }
// $map['_string'] .= " s.pay_time <= {$timeend}";
// $testStrWhere .= " and pay_time <= {$timeend}";
// }
$client = new AggregateClient();
$result = $client->api('game-data', [
'unique_codes' => $uniqueCodes,
'started_at' => I('timestart', ''),
'ended_at' => I('timeend', ''),
'search_games' => $searchGameCodes,
'device_type' => I("sdk_type", 0),
]);
// if (!empty(I('game_type_id'))) {
// $map['g.game_type_id'] = I('game_type_id');
// $gameWhere['game_type_id'] = I('game_type_id', 0);
// }
$aggData = [];
$aggWmData = [];
$aggFailData = [];
$aggWmFailData = [];
$aggTotal = '0.00';
$aggWmTotal = '0.00';
$aggFailTotal = '0.00';
$aggWmFailTotal = '0.00';
if ($result['code'] == '0000') {
$aggData = $result['data']['records'] ?? [];
$aggWmData = $result['data']['wm_records'] ?? [];
$aggFailData = $result['data']['fail_records'] ?? [];
$aggWmFailData = $result['data']['wm_fail_records'] ?? [];
$aggTotal = $result['data']['total'] ?? '0.00';
$aggWmTotal = $result['data']['wm_total'] ?? '0.00';
$aggFailTotal = $result['data']['fail_total'] ?? '0.00';
$aggWmFailTotal = $result['data']['wm_fail_total'] ?? '0.00';
}
$exceptIds = getAggExceptIds($gameSets);
// $searchGameIds = M('game', 'tab_')->where($gameWhere)->getField('id', true);
foreach ($xlsData as $key => $value) {
$aggAmount = '0.00';
$aggWmAmount = '0.00';
$aggFailAmount = '0.00';
$aggWmFailAmount = '0.00';
$testAmount = '0.00';
$deviceType = $value['sdk_version'] == 1 ? 'android' : 'ios';
if ($value['unique_code']) {
if (isset($aggData[$value['unique_code']]) && isset($aggData[$value['unique_code']][$deviceType])) {
$aggAmount = number_format($aggData[$value['unique_code']][$deviceType], 2, '.', '');
}
if (isset($aggWmData[$value['unique_code']]) && isset($aggWmData[$value['unique_code']][$deviceType])) {
$aggWmAmount = number_format($aggWmData[$value['unique_code']][$deviceType], 2, '.', '');
}
if (isset($aggFailData[$value['unique_code']]) && isset($aggFailData[$value['unique_code']][$deviceType])) {
$aggFailAmount = number_format($aggFailData[$value['unique_code']][$deviceType], 2, '.', '');
}
if (isset($aggWmFailData[$value['unique_code']]) && isset($aggWmFailData[$value['unique_code']][$deviceType])) {
$aggWmFailAmount = number_format($aggWmFailData[$value['unique_code']][$deviceType], 2, '.', '');
}
// $xlsData = D("spend")->gameStatistics($map);
}
$xlsData[$key]['agg_amount'] = $aggAmount;
$xlsData[$key]['agg_wm_amount'] = $aggWmAmount;
$xlsData[$key]['agg_failed_amount'] = $aggFailAmount;
$xlsData[$key]['agg_wm_failed_amount'] = $aggWmFailAmount;
if (isset($gameSets[$value['game_id']]) && isAggGame($gameSets[$value['game_id']]['pay_notify_url'])) {
$xlsData[$key]['cash_count'] = $value['cash_count'] = 0;
$xlsData[$key]['balance_coin_count'] = $value['balance_coin_count'] = 0;
$xlsData[$key]['inside_cash_count'] = $value['inside_cash_count'] = 0;
$testAmount = $testList[$value['game_id']] ?? '0.00';
}
// $uniqueCodes = array_column($xlsData, 'unique_code');
// $gameIds = array_column($xlsData, 'game_id');
// $uniqueCodes = array_filter($uniqueCodes, function($value) {
// if ($value) {
// return true;
// }
// return false;
// });
// $gameSets = M('game_set', 'tab_')->field(['game_id', 'pay_notify_url'])->select();
// $gameSets = index_by_column('game_id', $gameSets);
// $searchGameCodes = [];
// $testList = [];
// $testWhere = [
// 'game_id' => 0,
// '_string' => $testStrWhere,
// ];
// if (count($searchGameIds) > 0) {
// $searchGameCodes = M('game', 'tab_')->where(['id' => ['in', $searchGameIds], 'unique_code' => ['neq', '']])->getField('unique_code', true);
// $searchGameCodes = array_unique($searchGameCodes);
// $testWhere['game_id'] = ['in', $searchGameIds];
// $testRows = M('test_order', 'tab_')
// ->field(['game_id', 'sum(pay_amount) amount'])
// ->where($testWhere)
// ->group('game_id')
// ->select();
// foreach ($testRows as $testRow) {
// $testList[$testRow['game_id']] = round(floatval($testRow['amount']), 2);
// }
// }
$xlsData[$key]['test_amount'] = $testAmount;
// $xlsData[$key]['game_name'] = substr($value["game_name"],0,strrpos($value["game_name"],'('));
$xlsData[$key]['all_cash_count'] = $value['cash_count'] + $value['balance_coin_count'] + $value['inside_cash_count'];
if ($value['sdk_version'] == 1) {
$xlsData[$key]['sdk_version'] = '安卓';
} else if ($value['sdk_version'] == 2) {
$xlsData[$key]['sdk_version'] = '苹果';
}
}
// $client = new AggregateClient();
// $result = $client->api('game-data', [
// 'unique_codes' => $uniqueCodes,
// 'started_at' => I('timestart', ''),
// 'ended_at' => I('timeend', ''),
// 'search_games' => $searchGameCodes,
// 'device_type' => I("sdk_type", 0),
// ]);
// $aggData = [];
// $aggWmData = [];
// $aggFailData = [];
// $aggWmFailData = [];
// $aggTotal = '0.00';
// $aggWmTotal = '0.00';
// $aggFailTotal = '0.00';
// $aggWmFailTotal = '0.00';
// if ($result['code'] == '0000') {
// $aggData = $result['data']['records'] ?? [];
// $aggWmData = $result['data']['wm_records'] ?? [];
// $aggFailData = $result['data']['fail_records'] ?? [];
// $aggWmFailData = $result['data']['wm_fail_records'] ?? [];
// $aggTotal = $result['data']['total'] ?? '0.00';
// $aggWmTotal = $result['data']['wm_total'] ?? '0.00';
// $aggFailTotal = $result['data']['fail_total'] ?? '0.00';
// $aggWmFailTotal = $result['data']['wm_fail_total'] ?? '0.00';
// }
if (count($exceptIds) > 0) {
if (isset($map['_string'])) {
$map['_string'] .= " and s.game_id not in (" . implode(',', $exceptIds) . ")";
} else {
$map['_string'] = " s.game_id not in (" . implode(',', $exceptIds) . ")";
}
}
// $exceptIds = getAggExceptIds($gameSets);
// foreach ($xlsData as $key => $value) {
// $aggAmount = '0.00';
// $aggWmAmount = '0.00';
// $aggFailAmount = '0.00';
// $aggWmFailAmount = '0.00';
// $testAmount = '0.00';
// $deviceType = $value['sdk_version'] == 1 ? 'android' : 'ios';
// if ($value['unique_code']) {
// if (isset($aggData[$value['unique_code']]) && isset($aggData[$value['unique_code']][$deviceType])) {
// $aggAmount = number_format($aggData[$value['unique_code']][$deviceType], 2, '.', '');
// }
// if (isset($aggWmData[$value['unique_code']]) && isset($aggWmData[$value['unique_code']][$deviceType])) {
// $aggWmAmount = number_format($aggWmData[$value['unique_code']][$deviceType], 2, '.', '');
// }
// if (isset($aggFailData[$value['unique_code']]) && isset($aggFailData[$value['unique_code']][$deviceType])) {
// $aggFailAmount = number_format($aggFailData[$value['unique_code']][$deviceType], 2, '.', '');
// }
// if (isset($aggWmFailData[$value['unique_code']]) && isset($aggWmFailData[$value['unique_code']][$deviceType])) {
// $aggWmFailAmount = number_format($aggWmFailData[$value['unique_code']][$deviceType], 2, '.', '');
// }
$testWhere['_string'] .= ' and game_id in(' . implode(',', $exceptIds) . ')';
// }
// $xlsData[$key]['agg_amount'] = $aggAmount;
// $xlsData[$key]['agg_wm_amount'] = $aggWmAmount;
// $xlsData[$key]['agg_failed_amount'] = $aggFailAmount;
// $xlsData[$key]['agg_wm_failed_amount'] = $aggWmFailAmount;
// if (isset($gameSets[$value['game_id']]) && isAggGame($gameSets[$value['game_id']]['pay_notify_url'])) {
// $xlsData[$key]['cash_count'] = $value['cash_count'] = 0;
// $xlsData[$key]['balance_coin_count'] = $value['balance_coin_count'] = 0;
// $xlsData[$key]['inside_cash_count'] = $value['inside_cash_count'] = 0;
// $testAmount = $testList[$value['game_id']] ?? '0.00';
// }
$testAllAmount = M('test_order', 'tab_')->where($testWhere)->sum('pay_amount');
// $xlsData[$key]['test_amount'] = $testAmount;
// // $xlsData[$key]['game_name'] = substr($value["game_name"],0,strrpos($value["game_name"],'('));
// $xlsData[$key]['all_cash_count'] = $value['cash_count'] + $value['balance_coin_count'] + $value['inside_cash_count'];
// if ($value['sdk_version'] == 1) {
// $xlsData[$key]['sdk_version'] = '安卓';
// } else if ($value['sdk_version'] == 2) {
// $xlsData[$key]['sdk_version'] = '苹果';
// }
// }
$totalData = D("spend")->totalGameStatistics($map);
// if (count($exceptIds) > 0) {
// if (isset($map['_string'])) {
// $map['_string'] .= " and s.game_id not in (" . implode(',', $exceptIds) . ")";
// } else {
// $map['_string'] = " s.game_id not in (" . implode(',', $exceptIds) . ")";
// }
// }
$sumCash = $totalData['cash_count'];
$sumBalance = $totalData['balance_coin_count'];
$sumInside = $totalData['inside_cash_count'];
$sumNoticeFail = $totalData['notice_fail_count']? $totalData['notice_fail_count']:0;
$sumAll = $sumCash + $sumBalance + $sumInside;
$sumData = [
[
'game_name'=>'总计',
'cash_count'=>$sumCash,
'balance_coin_count'=>$sumBalance,
'inside_cash_count'=>$sumInside,
'all_cash_count'=>$sumAll,
'notice_fail_count'=>$sumNoticeFail,
'agg_wm_amount' => $aggWmTotal,
'agg_wm_failed_amount' => $aggWmFailTotal,
'test_amount' => round(floatval($testAllAmount), 2),
'agg_amount' => $aggTotal,
'agg_failed_amount' => $aggFailTotal,
]
];
$xlsData = array_merge($xlsData,$sumData);
$this->exportAddOperationLog("Finance/gameStatistics","充值-财务管理-游戏统计-导出");
$this->exportExcel($xlsName, $xlsCell, $xlsData);
}
// $testWhere['_string'] .= ' and game_id in(' . implode(',', $exceptIds) . ')';
// $testAllAmount = M('test_order', 'tab_')->where($testWhere)->sum('pay_amount');
// $totalData = D("spend")->totalGameStatistics($map);
// $sumCash = $totalData['cash_count'];
// $sumBalance = $totalData['balance_coin_count'];
// $sumInside = $totalData['inside_cash_count'];
// $sumNoticeFail = $totalData['notice_fail_count']? $totalData['notice_fail_count']:0;
// $sumAll = $sumCash + $sumBalance + $sumInside;
// $sumData = [
// [
// 'game_name'=>'总计',
// 'cash_count'=>$sumCash,
// 'balance_coin_count'=>$sumBalance,
// 'inside_cash_count'=>$sumInside,
// 'all_cash_count'=>$sumAll,
// 'notice_fail_count'=>$sumNoticeFail,
// 'agg_wm_amount' => $aggWmTotal,
// 'agg_wm_failed_amount' => $aggWmFailTotal,
// 'test_amount' => round(floatval($testAllAmount), 2),
// 'agg_amount' => $aggTotal,
// 'agg_failed_amount' => $aggFailTotal,
// ]
// ];
// $xlsData = array_merge($xlsData,$sumData);
// $this->exportAddOperationLog("Finance/gameStatistics","充值-财务管理-游戏统计-导出");
// $this->exportExcel($xlsName, $xlsCell, $xlsData);
// }
// public function gameStatisticsDetail() {
// $game_name = I("game_name");

@ -154,17 +154,7 @@
style="width: 100px;border: #3C95C8 solid 1px;">搜索</a>
<!-- <a class="sch-btn" href="javascript:history.go(-1)" style="background:#fff;color: #000;border: #000 solid 1px;width: 100px">返回</a>-->
<if condition="$role_export_check eq true ">
<a class="sch-btn" href="{:U('Export/exportGameStatistics',
array(
'timestart'=>$_GET['timestart'],
'timeend'=>$_GET['timeend'],
'sdk_type'=>$_GET['sdk_type'],
'game_name'=>$_GET['game_name'],
'game_type_id'=>$_GET['game_type_id'],
'game_id'=>$_REQUEST['game_id'],
'partner_id'=>$_REQUEST['partner_id'],
false))}"
style="width: 100px;border: #3C95C8 solid 1px;">导出</a>
<a class="sch-btn" href="{:U(CONTROLLER_NAME.'/'.ACTION_NAME,array_merge(['export'=>1],I('get.')))}" style="width: 100px;border: #3C95C8 solid 1px;">导出</a>
</if>
</div>

Loading…
Cancel
Save