getMidDataKey(); $data = $this->getAndCreateData($key); $priceInfo = $this->getPriceInfo($data['drawed_times']); if (empty($priceInfo)) { myself()->_rspErr(500, 'server internal error'); return; } $info = array(); $this->fillInfo($info, $data, $priceInfo); myself()->_rspData(array( 'info' => $info )); } public function drawS() { $drawType = getReqVal('type', 0); if (!($drawType == 0 || $drawType == 1 || $drawType == 2)) { myself()->_rspErr(2, 'type param error'); return; } $key = $this->getMidDataKey(); $data = $this->getAndCreateData($key); if ($data['drawed_times'] >= self::MAX_DRAW_TIMES) { myself()->_rspErr(1, 'The maximum number of lucky draws has been reached'); return; } $priceInfo = $this->getPriceInfo($data['drawed_times']); if (empty($priceInfo)) { myself()->_rspErr(500, 'server internal error'); return; } if ($priceInfo['cost_item_id'] != V_ITEM_DIAMOND) { myself()->_rspErr(500, 'server internal error'); return; } $costItemNum = 0; if ($drawType == 0) { $costItemNum = $priceInfo['price_double'] * $priceInfo['discount_double']; if (empty($costItemNum)) { myself()->_rspErr(3, 'config error'); return; } } else if ($drawType == 1 || $drawType == 2) { $costItemNum = $priceInfo['price_single'] * $priceInfo['discount_single']; if (empty($costItemNum)) { myself()->_rspErr(3, 'config error'); return; } } else { myself()->_rspErr(2, 'type param error'); return; } } public function buyS() { $key = $this->getMidDataKey(); $data = $this->getAndCreateData($key); } private function getMidDataKey() { return myself()->_getModelConstant('MidData', 'BIG_WHEEL_TYPE'); } private function getAndCreateData($key) { $data = myself()->_callModelStatic('MidData', 'getData', $key); if (!empty($data)) { $data = json_decode($data, true); } if (empty($data)) { $data = array( 'drawed_times' => 0, "grid_list" => array() ); } return $data; } private function fillInfo(&$info, &$data, $priceInfo) { $info = array( 'drawed_times' => $data['drawed_times'], 'total_times' => self::MAX_DRAW_TIMES, 'single_cost' => $priceInfo['price_single'] * $priceInfo['discount_single'], 'double_cost' => $priceInfo['price_double'] * $priceInfo['discount_double'], 'items1' => array(), 'items2' => array(), ); mt\Bigwheel::traverseMeta( function ($meta) use(&$data, &$info) { $item = array( 'grid_id' => $meta['id'], 'grid_state' => 0, 'item_id' => 0, 'item_num' => 0, 'buy_price' => 0, ); $gridRef = null; $this->getGridRefByGridId($data, $meta['id'], $girdRef); if (!empty($gridRef)) { $item = $gridRef; } switch ($meta['Wheel_type']) { case 1:{ array_push($info['items1'], $item); } break; case 2:{ array_push($info['items2'], $item); } break; } return true; }); } private function getGridRefByGridId(&$data, $gridId, &$gridRefOut) { foreach ($data['grid_list'] as &$grid) { if ($grid['grid_id'] == $girdId) { $gridRefOut = $grid; break; } } } private function getPriceInfo($drawedTimes) { $costItem = mt\Parameter::getVal('gacha_cost_item', 0); $gachaPriceSingles = mt\Parameter::getListValue('gacha_price_single'); $gachaDiscountSingles = mt\Parameter::getListValue('gacha_discount_single'); $gachaPriceDoubles = mt\Parameter::getListValue('gacha_price_double'); $gachaDiscountDoubles = mt\Parameter::getListValue('gacha_discount_double'); $gachaPriceBuys = mt\Parameter::getListValue('gacha_price_buy'); $gachaDiscountBuys = mt\Parameter::getListValue('gacha_discount_buy'); if (count($gachaPriceSingles) != count($gachaDiscountSingles) && count($gachaPriceDoubles) != count($gachaDiscountDoubles) && count($gachaPriceBuys) != count($gachaDiscountBuys) && count($gachaDiscountBuys) != self::MAX_DRAW_TIMES) { return null; } if ($drawedTimes < 0) { return null; } if ($drawedTimes > self::MAX_DRAW_TIMES) { $drawedTimes = self::MAX_DRAW_TIMES - 1; } $priceInfo = array( 'cost_item_id' => $costItem, 'price_single' => $gachaPriceSingles[$drawedTimes], 'discount_single' => $gachaDiscountSingles[$drawedTimes], 'price_double' => $gachaPriceDoubles[$drawedTimes], 'discount_double' => $gachaDiscountSingles[$drawedTimes], 'price_buy' => $gachaPriceBuys[$drawedTimes], 'discount_buy' => $gachaDiscountBuys[$drawedTimes], ); return $priceInfo; } }