优化游戏统计

master
chenzhi 4 years ago
parent 8ef35174dc
commit 76874cf34a

@ -712,12 +712,12 @@ class FinanceController extends ThinkController
$gameWhere = [];
$testStrWhere = '1=1';
if ($game_ids) {
$map['s.game_id'] = ['in', $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');
// $map['g.partner_id'] = I('partner_id');
$gameWhere['partner_id'] = I('partner_id');
}
@ -737,14 +737,14 @@ class FinanceController extends ThinkController
}
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);
}
$searchGameIds = M('game', 'tab_')->where($gameWhere)->getField('id', true);
$startTime = time();
//游戏统计列表
$data = D("spend")->gameStatistics($map, $row, $p);
$data = D("spend")->gameStatistics($map,$searchGameIds, $row, $p);
$gameIds = array_column($data, 'game_id');
$uniqueCodes = array_column($data, 'unique_code');
$uniqueCodes = array_filter($uniqueCodes, function($value) {

@ -861,68 +861,48 @@ class SpendModel extends Model
* @param $row int 每页条数
* @param $page int 第几页
*/
public function gameStatistics($map, $row = 0, $page = 1)
{
$gameMap = $this->getGameMapByGameStatMap($map);
$gameQuery = M('game', 'tab_')->field(['id', 'relation_game_name', 'unique_code', 'partner_id', 'game_type_name', 'sdk_version'])->where($gameMap);
public function gameStatistics($map,$gameIds, $row = 0, $page = 1)
{
$gameMap = [
"g.id"=>["in",$gameIds]
];
$gameQuery = M('game', 'tab_')
->alias('g')
->field(['g.id game_id', 'g.relation_game_name game_name', 'g.unique_code', 'g.game_type_name', 'g.sdk_version','IFNULL(p.partner,"无") as partner_name'])
->join('LEFT JOIN tab_partner as p ON g.partner_id=p.id')
->where($gameMap);
if ($row) {
$gameQuery->page($page,$row);
}
$games = $gameQuery->select();
$partners = [];
if (count($games)) {
$map['s.game_id'] = ['in', array_column($games, 'id')];
$partners = M('partner', 'tab_')->field(['id', 'partner'])->where(['id' => ['in', array_column($games, 'partner_id')]])->select();
$partners = index_by_column('id', $partners);
$map['s.game_id'] = ['in', array_column($games, 'game_id')];
}
$noticeFailData = M("Spend s use index(game_time)","tab_")
->field("SUM(pay_amount) as notice_fail_count,game_id")
->join('LEFT JOIN tab_game as g ON s.game_id=g.id')
->join('LEFT JOIN tab_partner as p ON g.partner_id=p.id')
->where(['s.pay_status' => 1, 'pay_game_status' => 0])
$data = M("Spend s use index(game_time)","tab_")
->where(['s.pay_status' => 1])
->where($map)
->group('s.game_id')
->select(false);
$query = M("Spend s use index(game_time)","tab_")
->field("s.game_id,g.relation_game_name game_name, g.unique_code, p.partner as partner_name, g.game_type_name,
->getField("s.game_id,
SUM(CASE WHEN pay_way > 0 and s.pay_status = 1 and pay_game_status = 1 THEN pay_amount ELSE 0 END) as cash_count,
SUM(CASE WHEN pay_way = 0 and s.pay_status = 1 and pay_game_status = 1 THEN pay_amount ELSE 0 END) as balance_coin_count,
SUM(CASE WHEN pay_way = -1 and s.pay_status = 1 and pay_game_status = 1 THEN pay_amount ELSE 0 END) as inside_cash_count,g.sdk_version,notice_fail_count")
->join('LEFT JOIN tab_game as g ON s.game_id=g.id')
->join('LEFT JOIN tab_partner as p ON g.partner_id=p.id')
->join("LEFT JOIN ({$noticeFailData})a ON s.game_id = a.game_id")
->where(['s.pay_status' => 1])
// ->where("(s.pay_status = 1 and pay_game_status = 1) or (s.pay_status = 1 and pay_game_status = 0)")
->where($map)
->group('s.game_id');
/* if ($row) {
$query = $query->page($page,$row);
} */
$data = $query->select();
$data = index_by_column('game_id', $data);
SUM(CASE WHEN pay_way = 0 and s.pay_status = 1 and pay_game_status = 1 THEN pay_amount ELSE 0 END) as balance_coin_count,
SUM(CASE WHEN pay_way = -1 and s.pay_status = 1 and pay_game_status = 1 THEN pay_amount ELSE 0 END) as inside_cash_count,
SUM(CASE WHEN s.pay_status = 1 and pay_game_status = 0 THEN pay_amount ELSE 0 END) as notice_fail_count");
$base = [
'cash_count' => 0,
'balance_coin_count' => 0,
'inside_cash_count' => 0,
'notice_fail_count' => 0
];
$records = [];
foreach ($games as $game) {
if (isset($data[$game['id']])) {
$records[] = $data[$game['id']];
if (isset($data[$game['game_id']])) {
$records[] = array_merge($game,$data[$game['game_id']]);
} else {
$partner = $partners[$game['partner_id']] ?? null;
$records[] = [
'game_id' => $game['id'],
'game_name' => $game['relation_game_name'],
'unique_code' => $game['unique_code'],
'partner_name' => $partner ? $partner['partner'] : '无',
'game_type_name' => $game['game_type_name'],
'cash_count' => 0,
'balance_coin_count' => 0,
'inside_cash_count' => 0,
'sdk_version' => $game['sdk_version'],
'notice_fail_count' => 0
];
$records[] = array_merge($game,$base);
}
}
return $records;
}
public function gameStatisticsCount($map)

Loading…
Cancel
Save