diff --git a/Application/Home/Controller/QueryController.class.php b/Application/Home/Controller/QueryController.class.php index c3921b8fe..d928c9914 100644 --- a/Application/Home/Controller/QueryController.class.php +++ b/Application/Home/Controller/QueryController.class.php @@ -94,7 +94,7 @@ class QueryController extends BaseController $income = '0.00'; if (intval($endTime - $begTime) / (24 * 3600) <= 31) { $data = M('Spend', 'tab_') - ->field('tab_spend.*,tab_promote.account as pro_account,tab_promote.real_name as pro_real_name,tab_promote.chain as chain') + ->field('tab_spend.*,tab_promote.account as pro_account,tab_promote.real_name as pro_real_name,tab_promote.chain as chain,tab_promote.level,tab_promote.parent_id') ->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) @@ -116,32 +116,49 @@ class QueryController extends BaseController ->find()['income']; } if (!empty($data)) { + $promoteIdData = []; + foreach ($data as $list) { + switch ($list['level']) { + case 3: + $promoteIdData[] = $list['parent_id']; + break; + case 4: + $promoteIdData[] = $list['parent_id']; + $chain = trim($list['chain'], '/'); + $chainArr = explode('/', $chain); + $promoteIdData[] = $chainArr[1]; + break; + } + } + $promoteData = []; + if (!empty($promoteIdData)) { + $promoteIdData = array_unique($promoteIdData); + $promoteData = M('promote', 'tab_')->where(array('id' => ['in',$promoteIdData]))->getField('id,account,real_name'); + } foreach ($data as &$list) { - $list['p_p_pro_account'] = $list['pro_account']; - $list['p_p_pro_real_name'] = $list['pro_real_name']; - $list['p_pro_account'] = $list['pro_account']; - $list['p_pro_real_name'] = $list['pro_real_name']; - if (!empty($list['chain'])) { - $chain = trim($list['chain'], '/'); - $chainArr = explode('/', $chain); - if (!empty($chainArr[1])) { - $thisPromoteData1 = D('Promote') - ->field('account,real_name') - ->where(array('id' => $chainArr[1])) - ->find(); - $list['p_p_pro_account'] = $thisPromoteData1['account']; //部门长 - $list['p_p_pro_real_name'] = $thisPromoteData1['real_name']; - } - if (!empty($chainArr[2])) { - $thisPromoteData2 = D('Promote') - ->field('account,real_name') - ->where(array('id' => $chainArr[2])) - ->find(); - $list['p_pro_account'] = $thisPromoteData2['account']; //组长 - $list['p_pro_real_name'] = $thisPromoteData2['real_name']; - } - - + switch ($list['level']) { + case 1: + case 2: + $list['p_p_pro_account'] = $list['pro_account']; + $list['p_p_pro_real_name'] = $list['pro_real_name']; + $list['p_pro_account'] = $list['pro_account']; + $list['p_pro_real_name'] = $list['pro_real_name']; + break; + case 3: + $list['p_p_pro_account'] = $promoteData[$list['parent_id']]['account']; + $list['p_p_pro_real_name'] = $promoteData[$list['parent_id']]['real_name']; + $list['p_pro_account'] = $list['pro_account']; + $list['p_pro_real_name'] = $list['pro_real_name']; + break; + case 4: + $promoteIdData[] = $list['parent_id']; + $chain = trim($list['chain'], '/'); + $chainArr = explode('/', $chain); + $list['p_p_pro_account'] = $promoteData[$chainArr[1]]['account']; + $list['p_p_pro_real_name'] = $promoteData[$chainArr[1]]['real_name']; + $list['p_pro_account'] = $promoteData[$list['parent_id']]['account']; + $list['p_pro_real_name'] = $promoteData[$list['parent_id']]['real_name']; + break; } $list['user_account'] = substr($list['user_account'], 0, 2) . '******' . substr($list['user_account'], 8); @@ -1828,7 +1845,7 @@ class QueryController extends BaseController $field = $fieldUC . ',' . $fieldUI; $subQuery = M('user_play_data_count', 'tab_')->alias('uc') ->field($field) - ->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') + ->join('left join tab_user_play_info as ui on ui.user_id = uc.user_id and 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(); @@ -1837,7 +1854,7 @@ class QueryController extends BaseController ->order($orderBy); $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') + ->join('left join tab_user_play_info as ui on ui.user_id = uc.user_id and ui.game_id = uc.game_id and ui.server_id = uc.server_id and ui.role_id = uc.role_id') ->where($map) ->find();