$db = Flight::db();
$prizes = $db->select('tb_luckdraw_prize', ['prize_id', 'all_num'], [
'luckdraw_id' => 1,
'ORDER' => [
'all_num' => 'DESC'
]
]);
if(empty($prizes)){
return false;
}
$prize_num = array_sum(array_column($prizes, 'all_num'));
$step = floor(1000 / $prize_num);
$prize_arr = [];
foreach($prizes as $v){
for($i = 0; $i < $v['all_num']; $i++){
$prize_arr[] = $v['prize_id'];
}
}
$insert = [];
$pStatus = true;
for($i = 0; $i < 1000; $i++){
$y = $i%$step;
if(empty($prize_arr)){
break;
}
if($y == 0){
$pStatus = true;
}
if(!$pStatus){
continue;
}
if($y == $step - 1 || rand(1, 100) < 6){
$pStatus = false;
$insert[] = [
'activity_id' => 1,
'luckdraw_id' => 1,
'prize_id' => array_shift($prize_arr),
'place' => $i
];
}
}