$map['_string'] = "promote_id = {$_REQUEST['promote_id']} or tab_promote.parent_id = {$_REQUEST['promote_id']} or tab_promote.grand_id = {$_REQUEST['promote_id']} ";
unset($_REQUEST['promote_id']);
$play_info_map = '';
if (isset($_REQUEST['game_name'])) {
$map['fgame_name'] = $_REQUEST['game_name'];
$play_info_map .= " and upi.game_name = '{$_REQUEST['game_name']}' ";
unset($_REQUEST['game_name']);
}
if (isset($_REQUEST['server_id'])) {
$play_info_map .= " and upi.server_name = '{$_REQUEST['server_id']}' ";
}
$today=total(1);
$week=total(2);
$mounth=total(3);
$map['puid'] = 0;
$data=$user
->field('promote_account,promote_id,date_format(FROM_UNIXTIME(register_time),"%Y-%m-%d") AS time, count(tab_user.id) as count,
IF(tab_promote.grand_id>0,tab_promote.grand_id,IF(tab_promote.grand_id=0 and tab_promote.parent_id >0,tab_promote.parent_id,promote_id)) as promote_id1 ,
count(IF(register_time '.$today.',1,null)) as today,
count(IF(register_time '.$week.',1,null)) as week,
count(IF(register_time '.$mounth.',1,null)) as mounth')
->join('tab_promote on promote_id = tab_promote.id','left')
if (isset($_REQUEST['promote_id'])) {
$map['tp1.id'] = $_REQUEST['promote_id'];
} else {
$map['tp1.chain'] = '/';
}
$data = M('promote', 'tab_')->alias('tp1')->field('tp1.account as promote_account,tp1.id as promote_id, date_format(FROM_UNIXTIME(register_time),"%Y-%m-%d") AS time, count(u.id) as count,
count(IF(register_time ' . $today . ',1,null)) as today,
count(IF(register_time ' . $week . ',1,null)) as week,
count(IF(register_time ' . $mounth . ',1,null)) as mounth')
->join("tab_promote AS tp2 ON tp2.`chain` LIKE CONCAT('%/', tp1.id, '/%')", 'left')
->join("tab_user as u on tp2.id = u.promote_id", 'left')
->join($play_info_map ? "tab_user_play_info as upi on upi.user_id = u.id " . $play_info_map : false)
->where($map)
->group('promote_id1')
->having('promote_id != 0')
->order('count desc,register_time')
->group('tp1.id')
->order('count desc, register_time')
->select();
$count=count($data);
foreach ($data as $key => $value) {
@ -1874,7 +1881,7 @@ class ExportController extends Controller
$data = $spend->field('a.promote_account,a.promote_id,a.time,sum(a.count) as count,sum(a.today) as today,sum(a.week) as week,sum(a.mounth) as mounth,IF(tab_promote.grand_id>0,tab_promote.grand_id,IF(tab_promote.grand_id=0 and tab_promote.parent_id >0,tab_promote.parent_id,promote_id)) as promote_id1')
->join('tab_promote on promote_id = tab_promote.id','left')
->where($condition)
->table('('.$data.') as a')->group('promote_id')->order('a.count desc,a.ordertime')->select();
$data = $spend->field('t.pid as promote_id,t.promote_account,sum(a.count) AS count,sum(a.today) AS today,sum(a. WEEK) AS WEEK,sum(a.mounth) AS mounth')
->join("INNER JOIN (SELECT tp2.*, tp1.id AS pid, tp1.account as promote_account FROM tab_promote tp1 LEFT JOIN tab_promote tp2 ON tp2.`chain` LIKE CONCAT('%/', tp1.id, '/%') where $promote_map ) AS t ON promote_id = t.id")
->where($condition)->table('(' . $data . ') as a')->group('t.pid')->order('count desc,a.ordertime')->select();
@ -360,6 +360,10 @@ class PlatformController extends ThinkController
$play_info_map .= " and upi.game_name = '{$_REQUEST['game_name']}' ";
unset($_REQUEST['game_name']);
}
if (isset($_REQUEST['server_id'])) {
$play_info_map .= " and upi.server_name = '{$_REQUEST['server_id']}' ";
}
$today = total(1);
$week = total(2);
$mounth = total(3);
@ -371,11 +375,6 @@ class PlatformController extends ThinkController
$map['tp1.chain'] = '/';
}
if (isset($_REQUEST['server_id'])) {
$play_info_map .= " and upi.server_name = '{$_REQUEST['server_id']}' ";
}
$data = M('promote', 'tab_')->alias('tp1')->field('tp1.account as promote_account,tp1.id, date_format(FROM_UNIXTIME(register_time),"%Y-%m-%d") AS time, count(u.id) as count,
count(IF(register_time ' . $today . ',1,null)) as today,
@ -454,15 +453,6 @@ class PlatformController extends ThinkController
@ -39,8 +39,17 @@ class SettlementEvent extends ThinkEvent {
$spend = M('Spend','tab_');
$ssql=$spend
->field('tab_spend.pay_order_number,tab_spend.game_id,tab_spend.game_name,if(tab_promote.grand_id = 0,if(tab_promote.parent_id=0,tab_spend.promote_id,tab_promote.parent_id),grand_id) as pid,pay_amount,if(isnull(tab_apply.promote_ratio),tab_game.ratio,tab_apply.promote_ratio) as ratio,if(isnull(tab_apply.promote_money),tab_game.money,tab_apply.promote_money) as money')
->join('tab_promote on tab_spend.promote_id = tab_promote.id')
->field('tab_spend.pay_order_number,tab_spend.game_id,tab_spend.game_name,t.pid as pid,pay_amount,if(isnull(tab_apply.promote_ratio),tab_game.ratio,tab_apply.promote_ratio) as ratio,if(isnull(tab_apply.promote_money),tab_game.money,tab_apply.promote_money) as money')
->join("INNER JOIN (
SELECT
tp2.*, tp1.id AS pid,
tp1.account AS promote_account
FROM
tab_promote tp1
LEFT JOIN tab_promote tp2 ON tp2.`chain` LIKE CONCAT('%/', tp1.id, '/%')
WHERE
tp1. LEVEL = 1
) AS t ON promote_id = t.id")
->join('tab_game on tab_spend.game_id= tab_game.id')
->join('left join tab_apply on tab_apply.game_id = tab_game.id and tab_apply.promote_id = '.$pid['id'])
->where($smap)
@ -50,9 +59,8 @@ class SettlementEvent extends ThinkEvent {
$sdata= $spend->table('('.$ssql.') as a')
->field('a.game_id,a.game_name,a.pid,sum(a.pay_amount) as spay_amount,a.ratio,a.money')