->field('max(id) as id,promote_account,promote_id,create_time as ordertime,date_format(FROM_UNIXTIME(create_time),"%Y-%m-%d") AS time, sum(real_amount) as count,
sum(IF(create_time '.$today.',real_amount,0)) as today,
sum(IF(create_time '.$week.',real_amount,0)) as week,
sum(IF(create_time '.$mounth.',real_amount,0)) as mounth')
->where($map1)
->group('promote_id')
->select(false);
$deposit_data = M('deposit','tab_')
->field('max(id) as id,promote_account,promote_id,create_time as ordertime,date_format(FROM_UNIXTIME(create_time),"%Y-%m-%d") AS time, sum(pay_amount) as count,
sum(IF(create_time '.$today.',pay_amount,0)) as today,
sum(IF(create_time '.$week.',pay_amount,0)) as week,
sum(IF(create_time '.$mounth.',pay_amount,0)) as mounth')
->where($map1)
->group('promote_id')
->select(false);
if(isset($_REQUEST['game_name'])){
$map['game_name'] = $_REQUEST['game_name'];
if(isset($_REQUEST['server_id'])){
$map['server_name'] = $_REQUEST['server_id'];
unset($_REQUEST['server_id']);
}
$data=$spend
->field('max(id) as id,promote_account,promote_id,pay_time as ordertime,date_format(FROM_UNIXTIME(pay_time),"%Y-%m-%d") AS time, sum(pay_amount) as count,
sum(IF(pay_time '.$today.',pay_amount,0)) as today,
sum(IF(pay_time '.$week.',pay_amount,0)) as week,
sum(IF(pay_time '.$mounth.',pay_amount,0)) as mounth')
->where($map)
->group('promote_id')
->select(false);
}else{
$data=$spend
->field('max(id) as id,promote_account,promote_id,pay_time as ordertime,date_format(FROM_UNIXTIME(pay_time),"%Y-%m-%d") AS time, sum(pay_amount) as count,
sum(IF(pay_time '.$today.',pay_amount,0)) as today,
sum(IF(pay_time '.$week.',pay_amount,0)) as week,
sum(IF(pay_time '.$mounth.',pay_amount,0)) as mounth')
$promote_map = "`chain` = '%/{$_REQUEST['promote_id']}/%' OR id = {$_REQUEST['promote_id']}";
}
$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();