用户表优化1

master
chenzhi 5 years ago
parent d48b0f1341
commit 4aa9ac6767

@ -11,7 +11,102 @@ class MemberController extends ThinkController
/** /**
*玩家列表信息 *玩家列表信息
*/ */
public function user_info($p = 0) public function user_info($p=0){
//基础信息
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
if (isset($_REQUEST['row'])) {
$row = $_REQUEST['row'];
} else {
$row = 10;
}
//累计充值,账户平台币排序
$order = '';
if (I('key') == 1) {
if (I('balance_status') == 1) {
$order = 'balance,';
} elseif (I('balance_status') == 2) {
$order = 'balance desc,';
}
} else {
if (I('recharge_status') == 1) {
$order .= 'recharge_total,';
} elseif (I('recharge_status') == 2) {
$order .= 'recharge_total desc,';
}
}
$order .= 'tab_user.id desc';
//条件筛选
$map = [];
$map['puid'] = array('eq', 0);
$map['is_platform'] = 0;
$havs=false;
//user表相关
if (isset($_REQUEST['user_id'])) {
$map['tab_user.id'] = $_REQUEST['user_id'];
}
if (isset($_REQUEST['account'])) {
$map['tab_user.account'] = ['like',I('account') . "%"];
}
if (isset($_REQUEST['time_start']) && isset($_REQUEST['time_end'])) {
$map['tab_user.register_time'] = ['between', [strtotime(I('time_start')), strtotime(I('time_end')) + 86399]];
} elseif (isset($_REQUEST['time_start'])) {
$map['tab_user.register_time'] = ['GT', strtotime(I('time_start'))];
} elseif (isset($_REQUEST['time_end'])) {
$map['tab_user.register_time'] = ['LT', strtotime(I('time_end')) + 86399];
}
if (isset($_GET['register_way'])) {
$map['tab_user.register_type'] = $_GET['register_way'];
}
if (isset($_REQUEST['status'])) {
$map['lock_status'] = $_REQUEST['status'];
}
if (isset($_REQUEST['viplevel'])) {
$havs = get_vip_level_limit('recharge_total', $_REQUEST['viplevel']);
}
$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")
->join("tab_spend AS ss ON ss.user_id = tab_user.id AND ss.pay_status = 1","left")
->where($map)
->group("tab_user.id")
->page($page, $row)
->order($order);
if($havs){
$data->having($havs);
}
$data = $data->select();
// echo($data);die();
//计算总数
$countsql = M("user","tab_")
->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")
->where($map)
->group("tab_user.id");
if($havs){
$countsql->having($havs);
}
$countsql = $countsql->select(false);
// dump($countsql);die();
$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('now_count', $countres['recharge_total']?:0);
$page = set_pagination($countres['user_count'], $row);
if ($page) {
$this->assign('_page', $page);
}
$this->assign('list_data', $data);
$this->display();
}
public function user_info2($p = 0)
{ {
$hav = ''; $hav = '';
if ($_REQUEST['promote_id'] != '') { if ($_REQUEST['promote_id'] != '') {

Loading…
Cancel
Save