PHP页面抽奖

/**
* 根据概率获取中奖号码
*
* @param 中奖设置信息
* @return 返回中奖ID
*/
private function get_rand($daily) {
$daily_max = 0;
foreach($daily as $dai)
{
if($dai[‘gailv’]==0) continue;
$daily_max += round(1/($dai[‘gailv’]/100));
}
$daily_rand = rand(1,$daily_max);
$front_max = 0;
foreach($daily as $dai)
{
$odd = $this->get_odd_prize($dai[‘id’]);
$id = 0;
if($odd<=0){//奖品剩余0 continue; } if(date("H:i:s")<$dai['time_start'] || date("H:i:s")>$dai[‘time_end’]){ //不在中奖时间段内
continue;
}
if($dai[‘gailv’]==0){ //概率为0
continue;
}
$count = $this->get_now_winner($dai[‘id’],$dai[‘time_start’],$dai[‘time_end’]);
if($count>=$dai[‘number’]){ //该时间段中奖数量超出设定
continue;
}

$max = ceil(1/($dai[‘gailv’]/100));
$rand = rand(1,$max);

$my_max = $daily_max*$dai[‘gailv’]/100;

if($daily_rand <= $my_max+$front_max){//随机抽中返回奖品id $id = $dai['id']; break; } else{ $front_max+= $my_max; } } return $id; } [/php]

发表评论

This site uses Akismet to reduce spam. Learn how your comment data is processed.

关闭菜单