优化游戏导出

master
chenzhi 4 years ago
parent f00ef7fcc9
commit c5bc21cb36

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

@ -154,17 +154,7 @@
style="width: 100px;border: #3C95C8 solid 1px;">搜索</a> 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>--> <!-- <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 "> <if condition="$role_export_check eq true ">
<a class="sch-btn" href="{:U('Export/exportGameStatistics', <a class="sch-btn" href="{:U(CONTROLLER_NAME.'/'.ACTION_NAME,array_merge(['export'=>1],I('get.')))}" style="width: 100px;border: #3C95C8 solid 1px;">导出</a>
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>
</if> </if>
</div> </div>

Loading…
Cancel
Save