1
This commit is contained in:
parent
79acc95aa9
commit
bda153a656
@ -74,14 +74,97 @@ class BigwheelController extends BaseAuthedController {
|
||||
myself()->_rspErr(3, 'config error');
|
||||
return;
|
||||
}
|
||||
} else if ($drawType == 1 || $drawType == 2) {
|
||||
} else {
|
||||
$costItemNum = $priceInfo['price_single'] * $priceInfo['discount_single'];
|
||||
if (empty($costItemNum)) {
|
||||
myself()->_rspErr(3, 'config error');
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
myself()->_rspErr(2, 'type param error');
|
||||
}
|
||||
$item1Hash = array();
|
||||
$item1Arr = array();
|
||||
$item2Hash = array();
|
||||
$item2Arr = array();
|
||||
mt\Bigwheel::traverseMeta(
|
||||
function ($meta) use(&$data, &$item1Hash, &$item2Hash, &$item1Arr, &$item2Arr) {
|
||||
$gridRef = null;
|
||||
$this->getGridRefByGridId($data, $meta['id'], $girdRef);
|
||||
switch ($meta['Wheel_type']) {
|
||||
case 1:{
|
||||
$item1Hash[$meta['id']] = $meta;
|
||||
array_push($item1Arr, array(
|
||||
'weight' => 0,
|
||||
'meta' => $meta
|
||||
));
|
||||
}
|
||||
break;
|
||||
case 2:{
|
||||
$item2Hash[$meta['id']] = $meta;
|
||||
array_push($item2Arr, array(
|
||||
'weight' => 0,
|
||||
'meta' => $meta
|
||||
));
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
if (count($item1Hash) != count($item2Hash) ||
|
||||
count($item1Arr) != count($item2Arr) ||
|
||||
count($item1Arr) != count($item1Hash) ||
|
||||
count($item1Hash) < 1) {
|
||||
myself()->_rspErr(1, 'The maximum number of lucky draws has been reached');
|
||||
return;
|
||||
}
|
||||
$randSpace1 = 0;
|
||||
foreach ($item1Arr as &$item) {
|
||||
$randSpace1 += $item['meta']['reWeight'];
|
||||
$item['weight'] = $randSpace1;
|
||||
}
|
||||
$randSpace2 = 0;
|
||||
foreach ($item2Arr as &$item) {
|
||||
$randSpace2 += $item['meta']['reWeight'];
|
||||
$item['weight'] = $randSpace2;
|
||||
}
|
||||
error_log(json_encode(array(
|
||||
'randSpace1' => $randSpace1,
|
||||
'randSpace2' => $randSpace2,
|
||||
'item1Arr' => $item1Arr,
|
||||
'item2Arr' => $item2Arr,
|
||||
)));
|
||||
if ($randSpace1 <= 0 ||
|
||||
$randSpace2 <= 0) {
|
||||
myself()->_rspErr(1, 'server internal error');
|
||||
return;
|
||||
}
|
||||
$item1 = null;
|
||||
{
|
||||
$rnd = rand(0, $randSpace1 - 1);
|
||||
foreach ($item1Arr as $item) {
|
||||
if ($item['weight'] <= $rnd) {
|
||||
$item1 = $item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$item2 = null;
|
||||
{
|
||||
$rnd = rand(0, $randSpace2 - 2);
|
||||
foreach ($item2Arr as $item) {
|
||||
if ($item['weight'] <= $rnd) {
|
||||
$item2 = $item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (empty($item1) || empty($item2)) {
|
||||
myself()->_rspErr(1, 'server internal error');
|
||||
return;
|
||||
}
|
||||
$lootMeta1 = myself()->_callMtStatic('LootConfig', 'find', $item1['meta']['content_loot']);
|
||||
$lootMeta2 = myself()->_callMtStatic('LootConfig', 'find', $item2['meta']['content_loot']);
|
||||
if (empty($lootMeta2) || empty($lootMeta2)) {
|
||||
myself()->_rspErr(1, 'server internal error');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user