<?php
function point($userid,$point,$remark,$tjnum=0,$prodvid=0){
//账户积分管理,要添加数据库,记录各种积分的收入、支出
// $tj=0;不影响注册人数，$tj=X，修改注册人数
	global $db;
	$user=$db->pe_select('user', array('user_id'=>$userid));//用户信息,用于修改账户资金

	$add['user_tjnum']=$user['user_tjnum']+$point;
	//注册人数和积分比例兑换，扣除积分同时会扣除注册人数
	if($tjnum)$add['tj_user_num']=$user['tj_user_num']+$tjnum;
	$r=$db->pe_update('user',array('user_id'=>$userid),$add);
	if($r){
		$info['userid']=$userid;
		$info['point']=$point;
		$info['tjnum']=$tjnum;
		$info['remark']=$remark;
		$info['prodvid']=$prodvid;//积分记录，该字段记录虚拟产品的id号
		$info['addtime']=TIME;
		$r=$db->pe_insert('point_log',$info);
	}
	return $r;
}
function getads($type,$num=0,$w=array()){
	global $db;
	if($type=='logo'){$where['type']=9;$limit=array(1);}
	else {
		$where['type']=$type;
		if($num)$limit=array($num);else $limit=array();
	}
	if($w)$where+=$w;
	$infos = $db->pe_selectall('ad', $where,'*',$limit);
	return $infos;
}
function random($length, $chars = '0123456789') {
	$hash = '';
	$max = strlen($chars) - 1;
	for($i = 0; $i < $length; $i++) {
		$hash .= $chars[mt_rand(0, $max)];
	}
	return $hash;
}
function getkf(){
	global $db;
	$qq = $db->pe_select('setting',array('setting_key'=>'qq'));
	$qqarr=unserialize(base64_decode($qq['setting_value']));
	return $qqarr;
}
function p($a,$b=2)
{
		if(is_array($a) or is_object($a))
		{
			print('<pre>');
			print_r($a);
		}
		else if(isset($a))
		{		
			if($a===false)echo 'false';
			elseif(trim($a)=='')echo 'space';
			else echo $a;
		}
		else 
			echo 'var is no exits!';
		switch($b)
		{
			case 1:
				exit;
			break;
			case 2:
				exit('<hr/>'.microtime());
			break;
			case 3:
				echo '<br/>';
			break;
			case 4:
				echo '<hr/>';
			break;
		}
}
?>