97 lines
3.6 KiB
PHP
97 lines
3.6 KiB
PHP
<?php
|
|
include_once("../../inc/class.php");
|
|
include_once("../../inc/admin.smarty.php");
|
|
$db = new myConn;
|
|
$db->links();
|
|
$GG=$db->getpost($GG);
|
|
$lottery = 32;//32局抽奖一次
|
|
//抽奖方法
|
|
function prize($arr = '',$prize_arr){
|
|
if(is_array($arr) || !$arr){
|
|
$arr = $arr ? $arr : [];
|
|
$shu = 1;
|
|
foreach($prize_arr as $val){
|
|
if(in_array($val['id'],$arr) || !$arr){
|
|
//$info[] = $val;
|
|
$item[$val['id']] = $val['pro'];
|
|
$cj[$val['id']]['min'] = $shu;
|
|
$shu += $val['pro'];
|
|
$cj[$val['id']]['max'] = $shu;
|
|
}
|
|
}
|
|
$num = array_sum($item);
|
|
$rand = mt_rand(1,$num);
|
|
//print_r($cj);
|
|
//echo $rand."<br>";
|
|
foreach ($cj as $k => $v) {
|
|
//echo $v['min']."<=".$rand." && ".$rand."<".$v['max']."<br>";
|
|
if($v['min']<=$rand && $rand<$v['max']){
|
|
return $prize_arr[$k-1];
|
|
}
|
|
}
|
|
}else{
|
|
return $prize_arr[$arr-1];
|
|
}
|
|
}
|
|
if($GG['gameid']){
|
|
$userid = $db->fetch_abc("select UserID from AccountsInfo where GameID='".$GG['gameid']."'");
|
|
$info = $db->fetch_one("select * from QPTreasureDB.dbo.GameScoreInfo where UserID='".$userid."'");
|
|
if($info['LotteryGame']>=$lottery){
|
|
$prize_arr = [
|
|
['id'=>1,"yuanbao"=>"50","pro"=>8],
|
|
['id'=>2,"yuanbao"=>"1","pro"=>3000],
|
|
['id'=>3,"yuanbao"=>"5","pro"=>500],
|
|
['id'=>4,"yuanbao"=>"30","pro"=>10],
|
|
['id'=>5,"yuanbao"=>"8","pro"=>100],
|
|
['id'=>6,"yuanbao"=>"2","pro"=>2000],
|
|
['id'=>7,"yuanbao"=>"60","pro"=>5],
|
|
['id'=>8,"yuanbao"=>"20","pro"=>20],
|
|
['id'=>9,"yuanbao"=>"100","pro"=>1],
|
|
['id'=>10,"yuanbao"=>"3","pro"=>1000],
|
|
['id'=>11,"yuanbao"=>"10","pro"=>50],
|
|
['id'=>12,"yuanbao"=>"6","pro"=>200]
|
|
];
|
|
if(!$info['LotteryHit']){//第一次 50 30 8 60 20 100 10
|
|
$dat = prize([1,4,5,7,8,9,11],$prize_arr);
|
|
}elseif(in_array($info['LotteryHit'],[100,200,600,800,900,1700,2350])){
|
|
$dat = prize([4],$prize_arr);//30
|
|
}elseif(in_array($info['LotteryHit'],[30,350,700,2200])){
|
|
$dat = prize([1],$prize_arr);//50
|
|
}elseif(in_array($info['LotteryHit'],[1100,1300,2700])){
|
|
$dat = prize([7],$prize_arr);//60
|
|
}elseif(in_array($info['LotteryHit'],[500,1000,1500,2000,2500,3000])){
|
|
$dat = prize([9],$prize_arr);//100
|
|
}else{
|
|
$hz = substr($info['LotteryHit'],-1);
|
|
if($hz == 1){// 5 8 20 3 10 6
|
|
$dat = prize([3,5,8,10,11,12],$prize_arr);
|
|
}elseif($hz == 6){//5 8 10 6
|
|
$dat = prize([3,5,11,12],$prize_arr);
|
|
}else{//平常 1 5 8 2 3 6
|
|
$dat = prize([2,3,5,6,10,12],$prize_arr);
|
|
}
|
|
}
|
|
$save=[
|
|
"YuanBao"=>$info['YuanBao']+$dat['yuanbao'],
|
|
"LotteryHit"=>$info['LotteryHit']+1,
|
|
"LotteryGame"=>$info['LotteryGame']-$lottery
|
|
];
|
|
$db->update('QPTreasureDB.dbo.GameScoreInfo',$save,"UserID='".$userid."'");
|
|
//记录日志
|
|
$db->insert("YuanBaoLog",['Types'=>'lottery','UserID'=>$userid,'QYuanBao'=>$info['YuanBao'],'LotteryHit'=>$info['LotteryHit'],'YuanBao'=>$dat['yuanbao']]);
|
|
//记录元宝日志
|
|
$ybd = $db->fetch_one("select * from YuanBaoDay where Day='".date('Y-m-d')."'");
|
|
if($ybd){
|
|
$db->update('YuanBaoDay',['YuanBao'=>$ybd['YuanBao']+$dat['yuanbao'],'Lottery'=>$ybd['Lottery']+$dat['yuanbao']],"YbdID='".$ybd['YbdID']."'");
|
|
}else{
|
|
$db->insert("YuanBaoDay",['Day'=>date('Y-m-d'),'YuanBao'=>$dat['yuanbao'],'Lottery'=>$dat['yuanbao']]);
|
|
}
|
|
echo json_encode(['prize'=>($dat['id']-1),'game'=>$save['LotteryGame'],'yuanbao'=>$dat['yuanbao']]);
|
|
}else{
|
|
echo json_encode(["error"=>"no"]);
|
|
}
|
|
}else{
|
|
echo json_encode(["error"=>"error"]);
|
|
}
|
|
unset($GG,$ppxq);
|
|
?>
|