diff --git a/Application/Home/Controller/PromoteController.class.php b/Application/Home/Controller/PromoteController.class.php index f5df36fba..940b21e5e 100644 --- a/Application/Home/Controller/PromoteController.class.php +++ b/Application/Home/Controller/PromoteController.class.php @@ -120,10 +120,10 @@ class PromoteController extends BaseController //计算当日用户充值数据 // $map['_string'] = "promote_id = {$promote_id} or tab_promote.parent_id = {$promote_id} or tab_promote.grand_id = {$promote_id} "; //计算当日用户充值数据 - $map['_string'] = "promote_id = {$promote_id} or tab_promote.parent_id = {$promote_id} or tab_promote.chain like '%/{$promote_id}/%' "; +// $map['_string'] = "promote_id = {$promote_id} or tab_promote.parent_id = {$promote_id} or tab_promote.chain like '%/{$promote_id}/%' "; $pay_time = " between 0 and " . time(); - $spendData = $this->caculateSpend($pay_time, $map['_string']); + $spendData = $this->caculateSpend($pay_time, []); $promoteId = implode(',', $promoteId); if ($promoteId) { @@ -136,21 +136,39 @@ class PromoteController extends BaseController $yesterdays = total(5); $week = total(2); $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, - 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') + + $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 ' . $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 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) - ->group('promote_id1') - ->having('promote_id != 0') - ->order('count desc,register_time') + ->group('tp1.id') + ->order('count desc, register_time') ->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') +// ->where($map) +// ->group('promote_id1') +// ->having('promote_id != 0') +// ->order('count desc,register_time') +// ->find(); +// var_dump($data);die(); +// echo M('promote', 'tab_')->_sql();die(); $total_money = $this->pay_total(0, 0, $promoteId); $today_add_user_money = $this->pay_total(1, 1, $promoteId); @@ -161,11 +179,12 @@ class PromoteController extends BaseController //计算昨天用户的统计数据,当日用户充值数据 $pay_time = " between {$yesterday_start} and {$yesterday_end}"; $createTime = ['between', array($yesterday_start, $yesterday_end - 1)]; - $yesterdaySpendData = $this->caculateSpend($pay_time, $map['_string'], $createTime); + $yesterdaySpendData = $this->caculateSpend($pay_time, [], $createTime); - $todayAddSpendData = $this->caculateSpend($pay_time, $map['_string'], [], 1); + $todayAddSpendData = $this->caculateSpend($pay_time, [], [], 1); +// var_dump($todayAddSpendData);die(); - $mounthAddSpendData = $this->caculateSpend($pay_time, $map['_string'], [], 2); + $mounthAddSpendData = $this->caculateSpend($pay_time, [], [], 2); $yesterday_user_regist_count = M("user", "tab_")->where( array("promote_id" => array('in', $promoteId), @@ -289,10 +308,14 @@ class PromoteController extends BaseController ->group('promote_id') ->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') - ->join('tab_promote on promote_id = tab_promote.id', 'left') - ->where($condition) - ->table('(' . $spendData . ') as a')->group('promote_id1')->order('count desc,a.ordertime')->find(); +// $promote_map = "tp1.`chain` = '/'"; + $promote_id = get_pid(); + $promote_map = "tp1.`id` = {$promote_id}"; + + $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(); +// var_dump($spendData);die(); $spendData['rand'] = 1; $spendData['count'] = $spendData['count'] / 100; $spendData['today'] = $spendData['today'] / 100;