From bda153a656b84d99d400f0fad0cb77a7ad4307d2 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 1 Aug 2024 17:00:30 +0800 Subject: [PATCH] 1 --- .../controller/BigwheelController.class.php | 89 ++++++++++++++++++- 1 file changed, 86 insertions(+), 3 deletions(-) diff --git a/webapp/controller/BigwheelController.class.php b/webapp/controller/BigwheelController.class.php index 37a06085..a84263ba 100644 --- a/webapp/controller/BigwheelController.class.php +++ b/webapp/controller/BigwheelController.class.php @@ -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; } }