优化游戏统计

master
chenzhi 4 years ago
parent 8ef35174dc
commit 76874cf34a

@ -712,12 +712,12 @@ class FinanceController extends ThinkController
$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');
} }
@ -737,14 +737,14 @@ class FinanceController extends ThinkController
} }
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);
$startTime = time(); $startTime = time();
//游戏统计列表 //游戏统计列表
$data = D("spend")->gameStatistics($map, $row, $p); $data = D("spend")->gameStatistics($map,$searchGameIds, $row, $p);
$gameIds = array_column($data, 'game_id'); $gameIds = array_column($data, 'game_id');
$uniqueCodes = array_column($data, 'unique_code'); $uniqueCodes = array_column($data, 'unique_code');
$uniqueCodes = array_filter($uniqueCodes, function($value) { $uniqueCodes = array_filter($uniqueCodes, function($value) {

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

Loading…
Cancel
Save