<?php
require_once("../check.php");
require_once("../../config.php");
$usersql = "select * from dunling_user where username='$username'";
$userery = mysql_query($usersql,$config);
$user = mysql_fetch_array($userery);
$time = time();
isset($_SERVER['HTTP_X_FORWARDED_FOR'])?$ip = $_SERVER['HTTP_X_FORWARDED_FOR']:$ip = $_SERVER['REMOTE_ADDR'];
$danhao = "WB".rand(1000,9999).rand(1000,9999);
$consql = "select * from dunling_config where id='1'";
$conery = mysql_query($consql,$config);
$con = mysql_fetch_array($conery);
$fangshi = $con['zhongjiangfangshi'];

$jinbi = $user['jinbi'];
$m = $con['m'];//每开一次宝箱消耗多少钱
$jl = $con['j'];//中奖机率 10为10%
$newjifen = $jinbi-$m;

if($jinbi<$m){
    echo "err001:".$newjifen;
    exit;
}
$jilv = rand(1,100);
if($jilv>$jl){
    $upsql = "update dunling_user set jinbi=jinbi-'$m' where username='$username'";
    mysql_query($upsql,$config);
    $basql = "insert into dunling_wabao_log (username,danjia,datetime,jinbi,danhao,zhongjiang,ip) values ('$username','0','$time','$m','$danhao','0','$ip')";
    mysql_query($basql,$config);
    
    echo "no:".$newjifen;
    exit;
}

if($jilv<=$jl){
    //中奖了，判断金额能中多少钱
   if($fangshi=="0"){
    //判断奖励方式
    $jj = $con['gudingmoney'];
    
   }
   if($fangshi=="1"){
   $min = $con['minmoney']*100;
   $max = $con['maxmoney']*100;
   //计算产生随机数
   $jj = rand($min,$max);
   $jj = $jj/100;
    
    
    
   }
   
   
   
   


    $upsql = "update dunling_user set money=money+'$jj',zmoney=zmoney+'$jj',jinbi=jinbi-'$m' where username='$username'";
    $basql = "insert into dunling_wabao_log (username,danjia,datetime,jinbi,danhao,zhongjiang,ip) values ('$username','$jj','$time','$m','$danhao','1','$ip')";
    mysql_query($upsql,$config);
    mysql_query($basql,$config);
    echo $jj.":".$newjifen;    
}
mysql_close($config);
?>