@ -136,21 +136,39 @@ class PromoteController extends BaseController
$yesterdays = total(5);
$yesterdays = total(5);
$week = total(2);
$week = total(2);
$mounth = total(3);
$mounth = total(3);
$map['tp1.id'] = $promote_id;
//计算今日的统计数据
//计算今日的统计数据
$data = M('User', 'tab_')
->field('promote_account,promote_id,date_format(FROM_UNIXTIME(register_time),"%Y-%m-%d") AS time, count(tab_user.id) as count,
$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,
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 ' . $yesterdays . ',1,null)) as yesterday,
count(IF(register_time ' . $yesterdays . ',1,null)) as yesterday,
count(IF(register_time ' . $today . ',1,null)) as today,
count(IF(register_time ' . $today . ',1,null)) as today,
count(IF(register_time ' . $week . ',1,null)) as week,
count(IF(register_time ' . $week . ',1,null)) as week,
count(IF(register_time ' . $mounth . ',1,null)) as mounth')
count(IF(register_time ' . $mounth . ',1,null)) as mounth')
->join('tab_promote on promote_id = tab_promote.id', 'left')
->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(false)
->where($map)
->where($map)
->group('promote_id1')
->group('tp1.id')
->having('promote_id != 0')
->order('count desc, register_time')
->order('count desc, register_time')
->find();
->find();
// echo M('User','tab_')->_sql();die();
// $data = M('User', 'tab_')
// ->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 ' . $yesterdays . ',1,null)) as yesterday,
// 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')
@ -289,10 +308,14 @@ class PromoteController extends BaseController
->group('promote_id')
->group('promote_id')
->select(false);
->select(false);
$spendData = $spend->field('a.promote_account,a.promote_id,a.time,sum(a.scount) 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')
// $promote_map = "tp1.`chain` = '/'";
->join('tab_promote on promote_id = tab_promote.id', 'left')
$promote_id = get_pid();
->where($condition)
$promote_map = "tp1.`id` = {$promote_id}";
->table('(' . $spendData . ') as a')->group('promote_id1')->order('count desc,a.ordertime')->find();
$spendData = $spend->field('t.pid as promote_id,t.promote_account,sum(a.scount) 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('(' . $spendData . ') as a')->group('t.pid')->order('count desc,a.ordertime')->find();