优化首页计算代码

master
zyx 5 years ago
parent 7ead67f8cb
commit a16c77181c

@ -101,27 +101,14 @@ class PromoteController extends BaseController
$this->assign("_page", $page);
$promote = M("promote","tab_")->field("parent_id,grand_id")->where("id=".get_pid())->find();
$promoteId = array(get_pid());
// $map = "promote_id = {$promote_id} ";
// if ($promote['parent_id'] == 1) {
// $promoteId = M("promote", "tab_")->field('id')->where("parent_id=" . get_pid()." or grand_id=". get_pid())->select();
// $promoteId = array_column($promoteId,'id');
// array_push($promoteId,get_pid());
//计算当日用户充值数据
$map['_string'] = "promote_id = {$promote_id} or tab_promote.parent_id = {$promote_id} or tab_promote.grand_id = {$promote_id} ";
$pay_time = " between 0 and ".time();
$spendData = $this->caculateSpend($pay_time,$map['_string']);
// } elseif ($promote['parent_id'] > 0 && $promote['grand_id'] == 0) {
// $promoteId = M("promote", "tab_")->field('id')->where("parent_id=" . get_pid())->select();
// $promoteId = array_column($promoteId,'id');
// array_push($promoteId,get_pid());
//
// $map = "promote_id = {$promote_id} or tab_promote.parent_id = {$promote_id} ";
// }
// var_dump($map);
$promoteId = implode(',',$promoteId);
if ($promoteId) {
$user_count = M("user", "tab_")->where("promote_id IN({$promoteId})")->count();
@ -137,6 +124,7 @@ class PromoteController extends BaseController
$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')
@ -146,6 +134,7 @@ class PromoteController extends BaseController
->having('promote_id != 0')
->order('count desc,register_time')
->find();
// echo M('User','tab_')->_sql();die();
$total_money = $this->pay_total(0, 0,$promoteId);
$today_add_user_money = $this->pay_total(1,1,$promoteId);
@ -162,25 +151,6 @@ class PromoteController extends BaseController
$mounthAddSpendData = $this->caculateSpend($pay_time,$map['_string'],[],2);
// var_dump($mounthAddSpendData);die();
// $map['register_time'] = ['between',array($yesterday_start,$yesterday_end-1)];
$yesterdayData = 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 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();
// echo M('User','tab_')->_sql();die();
// var_dump($yesterdayData);die();
$yesterday_user_regist_count = M("user", "tab_")->where(
array("promote_id" => array('in',$promoteId),
"register_time" => array("BETWEEN", array($yesterday_start, $yesterday_end))))
@ -197,7 +167,7 @@ class PromoteController extends BaseController
$today_total_money = $this->pay_total(1, 0,$promoteId);
$this->assign('data',$data);
$this->assign('yesterdayData',$yesterdayData);
// $this->assign('yesterdayData',$yesterdayData);
$this->assign('spendData',$spendData);
$this->assign('yesterdaySpendData',$yesterdaySpendData);
$this->assign('todayAddSpendData',$todayAddSpendData);

@ -11,7 +11,7 @@
<li><div class="icon"><span class="placeholder-graphic"><img src="__IMG__/20180207/icon_chongzhi5.png"/></span></div> <div class="text text5"><p>当月新增用户充值</p><span>¥{$mounthAddSpendData.mounth}</span></div> </li>
</ul>
<ul style="margin-top: 10px">
<li><div class="icon"><span class="placeholder-graphic"><img src="__IMG__/20180207/icon_chongzhi1.png"/></span></div> <div class="text text2"><p>昨日注册用户</p><span>{$yesterdayData.today}</span></div> </li>
<li><div class="icon"><span class="placeholder-graphic"><img src="__IMG__/20180207/icon_chongzhi1.png"/></span></div> <div class="text text2"><p>昨日注册用户</p><span>{$data.yesterday}</span></div> </li>
<li><div class="icon"><span class="placeholder-graphic"><img src="__IMG__/20180207/icon_chongzhi2.png"/></span></div> <div class="text text1"><p>昨日充值金额</p><span>¥{$yesterdaySpendData.count}</span></div> </li>
<li><div class="icon"><span class="placeholder-graphic"><img src="__IMG__/20180207/icon_chongzhi3.png"/></span></div> <div class="text text3"><p>今日注册用户</p><span>{$data.today}</span></div> </li>
<li><div class="icon"><span class="placeholder-graphic"><img src="__IMG__/20180207/icon_chongzhi5.png"/></span></div> <div class="text text5"><p>今日充值金额</p><span>¥{$spendData.today}</span></div> </li>

Loading…
Cancel
Save