<?php
require('path.inc.php');

$housesell = new HouseSell($query);
$return_to = $_SERVER['HTTP_REFERER'];
if($page->action == 'save'){
    $member_id = $member->getAuthInfo('id');  //获取会员ID
	//计算余额是否够用
	$price = intval($_POST['num'])*$page->sellNum;
	$memberInfo = $member->getInfo($member_id,'*',true);
	if(empty($_POST['num'])){
		$page->goto($return_to,'请输入购买条数');
		}
	if($memberInfo['money'] >= $price){
	try{
		//扣除费用
		$member->deletemoney($member_id,$price);
		//增加出售条数
		$member->updateNum(0,$member_id,$_POST['num']);
		$page->goto($return_to,'购买成功');
	}catch (Exception $e){
		$page->back('输入了非法条数');
		//$page->back($e->getMessage());
	}
	
	exit;
		
		}else{
		$page->goto($return_to,'余额不足，请充值！');
		}
	

}else{
	$page->name = 'saleNum';
	$money =  $member->getAuthInfo('money');
	$page->tpl->assign('money', $money);
}

$page->show();
?>