<?php 
	require "../Run.php";
	echo head('购买帖子');
	if(LOGIN !=1){
		echo head('购买帖子');
		echo '您还，您还没有登录';
		echo footer(1);
		exit;
	}
	$sql="SELECT bbsid,userid,title,content,pic,name,v,time,gro,zip,zan,xi,nu,zipstr,viewType,viewValue FROM bbs WHERE bbsid='{$_GET['id']}' AND siteid='".WAPID."';";
	$view = mysql_query($sql);
	if($view && mysql_num_rows($view)>0){
	list($bbsid,$userid,$title,$content,$pic,$name,$v,$time,$hgro,$zip,$zan,$xi,$nu,$zipstr,$viewType,$viewValue,$siteid) = mysql_fetch_row($view);
	if(crevalue < $viewValue || $viewType != 'buy'){
	echo head('购买帖子');
		echo '积分不够或者参数错误';
		echo footer(1);
		exit;
	}
	if(is_file("buylog/".$_GET['id']."_".MYID."_".XID.".txt")){
		echo head('购买帖子');
		echo '您好，您已经购买了，无需重复购买';
		echo footer(1);
		exit;
	}
		echo head('购买帖子');
		$now = crevalue - $viewValue;
		$sql="UPDATE user SET crevalue='".$now."' WHERE id='".MYID."'";
		$result = mysql_query($sql);
	        if($result && mysql_affected_rows()>0){
				file_put_contents("buylog/".$_GET['id']."_".MYID."_".XID.".txt","isbuy");
				$getcre = user('crevalue','id',$userid) + $viewValue;
				$sql2 = "UPDATE user SET crevalue='".$getcre."' WHERE id='".$userid."';";
				$result2 = mysql_query($sql2);
				if($result2 && mysql_affected_rows()>0){
				
				$title = $nc.'购买了您的帖子《 '.$title.' 》';
			
				$content = '您好，'.$nc.' 购买了您的帖子《[url=http://'.HTTP_HOST.'/bbs/content.php?cid='.$_GET['cid'].'&id='.$_GET['id'].']'.$title.'[/url]》[br]快去看看吧。[url=http://'.HTTP_HOST.'/bbs/content.php?cid='.$_GET['cid'].'&id='.$_GET['id'].']飞机直达[/url]！';
			
				$user_id = $userid;
				SendMessage($title,$content,$user_id,NULL,NULL);
				}
				echo '<div class="tip">已经成功支付了'.$viewValue.'</div>';
			}else{
			echo '<div class="tip">支付失败了</div>';
		   }
		echo '<div class="mylink"><a href="content.php?cid='.$_GET['cid'].'&id='.$_GET['id'].'">返回主题</a><a href="http://'.HTTP_HOST.'/index.php">网站首页</a></div>';
		echo footer(1);
		exit;
	}else{
	echo head('购买帖子');
		echo '您好，找不到资源了';
		echo footer(1);
		exit;
	}
?>