->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();