<?php
include(dirname(__file__)."/../includes.php");

//用户基础api函数
function user_read_base($fields="*",$condition="",$by_col="",$order="",$num="",$cache="",$cache_key=""){
	global $allow_cols;
	global $tablePreStr;
	$t_user=$tablePreStr."users";
	$fields_str='';
	$plugin_rs=array();
	$dbo=new dbex;
  dbplugin('r');
	$allow_cols=array(
		"user_id","user_marry","user_email","user_name","user_sex","user_call","birth_province","birth_city","reside_province","reside_city","user_ico","user_add_time","birth_year","birth_month","birth_day","user_blood","user_qq","creat_group","join_group","guest_num","integral","lastlogin_datetime",
	);
  if($num==''||$num >= 1000){
  	$limit=" limit 1000 ";
  }else{
  	$limit=" limit $num ";
  }
  if($by_col!=''){
  	$by_col=" order by $by_col ";
  }
	if($fields=="*"){
		$fields=join(",",$allow_cols);
	}elseif(strstr($fields,",")){
		$fields=check_item($fields,$allow_cols);
	}else{
		if(!in_array($fields,$allow_cols)){
			$fields='';
		}
	}
  $sql=" select $fields from $t_user where user_pass = 1 $condition $by_col $order $limit ";
  if($cache==1&&in_array($num,array(10,20,50))&&$cache_key!=''){
		$key=$cache_key.$order.'_'.$num;
		$key_mt=$cache_key.'mt_'.$order.'_'.$num;
		$plugin_rs=model_cache($key,$key_mt,$dbo,$sql);
	}
	if(empty($plugin_rs)){
		$plugin_rs=$dbo->getRs($sql);
	}
	return $plugin_rs;
}

function user_self_by_uid($fields="*",$id){
	$fields=filt_fields($fields);
	$id_str=filt_num_array($id);
	$condition=" and user_id in ($id_str) ";
	return user_read_base($fields,$condition);
}

function user_self_by_gnum($fields="*",$num=10){
	$fields=filt_fields($fields);
	return user_read_base($fields,"","guest_num","desc",$num,1,"user_gnum_");
}

function user_self_by_integral($fields="*",$num=10){
	$fields=filt_fields($fields);
	return user_read_base($fields,"","integral","desc",$num,1,"user_int_");
}

function user_self_by_regdate($fields="*",$date,$num=10){
	$fields=filt_fields($fields);
	$condition=str_replace("{date}","user_add_time",date_filter($date));
	return user_read_base($fields,$condition,"user_add_time","desc",$num);
}

function user_self_by_logindate($fields="*",$date,$num=10){
	$fields=filt_fields($fields);
	$condition=str_replace("{date}","lastlogin_datetime",date_filter($date));
	return user_read_base($fields,$condition,"lastlogin_datetime","desc",$num);
}




?>