优化用户列表2

master
chenzhi 5 years ago
parent 4aa9ac6767
commit 3f358bb818

@ -65,7 +65,11 @@ class MemberController extends ThinkController
if (isset($_REQUEST['viplevel'])) { if (isset($_REQUEST['viplevel'])) {
$havs = get_vip_level_limit('recharge_total', $_REQUEST['viplevel']); $havs = get_vip_level_limit('recharge_total', $_REQUEST['viplevel']);
} }
//与游戏相关
$game = false;
//计算用户列表
$data = M("user","tab_") $data = M("user","tab_")
->field("tab_user.id,`device_number`,`age_status`,`account`,`balance`,`gold_coin`,`alipay`,tab_user.promote_id,`register_type`,tab_user.promote_account,`register_time`,`lock_status`,`register_way`,`register_ip`,`login_time`,`check_status`,IFNULL(sum(ss.pay_amount), 0) AS recharge_total") ->field("tab_user.id,`device_number`,`age_status`,`account`,`balance`,`gold_coin`,`alipay`,tab_user.promote_id,`register_type`,tab_user.promote_account,`register_time`,`lock_status`,`register_way`,`register_ip`,`login_time`,`check_status`,IFNULL(sum(ss.pay_amount), 0) AS recharge_total")
->join("tab_spend AS ss ON ss.user_id = tab_user.id AND ss.pay_status = 1","left") ->join("tab_spend AS ss ON ss.user_id = tab_user.id AND ss.pay_status = 1","left")
@ -78,26 +82,34 @@ class MemberController extends ThinkController
} }
$data = $data->select(); $data = $data->select();
// echo($data);die();
//计算总数 //计算累计充值总额
$countsql = M("user","tab_") $history_count = M("user","tab_")
->field("IFNULL(sum(ss.pay_amount), 0) AS recharge_total") ->field("IFNULL(sum(ss.pay_amount), 0) AS recharge_total")
->join("tab_spend AS ss ON ss.user_id = tab_user.id AND ss.pay_status = 1","left") ->join("tab_spend AS ss ON ss.user_id = tab_user.id AND ss.pay_status = 1","left")
->where($map) ->where($map);
->group("tab_user.id");
if($havs){ if($havs){
$countsql->having($havs); $countsql->having($havs);
} }
$history_count = $history_count->find()['recharge_total'];
//计算用户总数
$user_count = M("user","tab_")
->field("count(*) user_count")
->where($map);
if($havs){
$user_count->having($havs);
}
$user_count = $user_count->find()['user_count'];
$countsql = $countsql->select(false);
// dump($countsql);die(); // dump($countsql);die();
$countres = M()->table('(' . $countsql . ') as a ')->field("count(*) user_count,sum(recharge_total) recharge_total")->find(); // $countres = M()->table('(' . $countsql . ') as a ')->field("count(*) user_count,sum(recharge_total) recharge_total")->find();
$this->assign('user_count',$countres['user_count']); $this->assign('user_count',$user_count);
$this->assign('now_count', $countres['recharge_total']?:0); $this->assign('now_count', $history_count?:0);
$page = set_pagination($countres['user_count'], $row); $page = set_pagination($user_count, $row);
if ($page) { if ($page) {
$this->assign('_page', $page); $this->assign('_page', $page);
} }

Loading…
Cancel
Save