function getRand($proArr, $proCount) {

$result = '';

$proSum = 0;

php抽奖源码PHP新写的年夜转盘抽奖源码 PHP

foreach ($proCount as $key => $val) {

if ($val <= 0) {

continue;

} else {

$proSum = $proSum + $proArr[$key];

}

}

foreach ($proArr as $key => $proCur) {

if ($proCount[$key] <= 0) {

continue;

} else {

$randNum = mt_rand(1, $proSum);

if ($randNum <= $proCur) {

$result = $key;

break;

} else {

$proSum -= $proCur;

}

}

}

unset($proArr);

return $result;

}

奖品设置

$prizes = array(

0 => array(

\公众id\公众 => 0, //中奖id

\"大众name\"大众 => \公众感激参与\"大众, //奖品名称

\公众count\公众 => \"大众100\"大众, //库存

),

1 => array(

\"大众id\"大众 => 1,

\"大众name\"大众 => \"大众罗浮山门票\"大众,

\公众count\"大众 => \"大众40\"大众,

),

2 => array(

\"大众id\"大众 => 2,

\公众name\公众 => \"大众罗浮山嘉宝田温泉体验券\"大众,

\公众count\公众 => \公众40\"大众,

),

3 => array(

\公众id\公众 => 3,

\"大众name\公众 => \"大众精美旅游书本《山水酿惠州》\"大众,

\"大众count\公众 => \公众40\公众,

),

4 => array(

\"大众id\"大众 => 4,

\公众name\"大众 => \"大众碧海湾漂流门票\"大众,

\"大众count\"大众 => \"大众40\"大众,

),

5 => array(

\"大众id\"大众 => 5,

\"大众name\"大众 => \公众南昆山门票\"大众,

\"大众count\公众 => \公众40\公众,

),

6 => array(

\公众id\"大众 => 6,

\"大众name\"大众 => \公众云顶温泉精美礼品\"大众,

\公众count\"大众 => \"大众40\"大众,

),

);

源码来源:https://gitee.com/lanrenzhijia/codes/d342lk1yw5nm8x09euqag50