diff --git a/webapp/controller/DailySelectionController.class.php b/webapp/controller/DailySelectionController.class.php index d277c392..e0335332 100644 --- a/webapp/controller/DailySelectionController.class.php +++ b/webapp/controller/DailySelectionController.class.php @@ -1,6 +1,7 @@ data['refresh_count']; + if ($count >= $maxCount) { + myself()->_rspErr(1, 'The maximum number of refreshes has been reached'); + return; + } + + $cost = $arrCosts[$count]; + $costItems = array( + array( + 'item_id' => V_ITEM_GOLD, + 'item_num' => $cost + ) + ); + $lackItem = null; + if (!myself()->_hasEnoughItems($costItems, $lackItem)) { + myself()->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); + return; + } + myself()->_decItems($costItems); + $this->internalRefresh(true); $this->save(); + $propertyChgService = new PropertyChgService(); + $propertyChgService->addUserChg(); + myself()->_rspData(array( + 'property_chg' => $propertyChgService->toDto() + )); } public function buy() @@ -123,50 +153,13 @@ class DailySelectionController extends BaseAuthedController { { $remainSec = 3600 * 24 - (myself()->_getNowTime() - myself()->_getNowDaySeconds()); $remainSec = max(0, $remainSec); - myself()->_getSelfRedis()->setNxPx( + myself()->_getSelfRedis()->set( DAILY_SELECTION_KEY . myself()->_getAccountId(), - json_encode($this->data), - myself()->_getNowDaySeconds(), - $remainSec * 1000 + json_encode($this->data) ); - } - - public function refreshDailySelectionOld() - { - $address = $this->_getAccountId(); - - $costs = mt\Parameter::getByName('daily_selection_refresh_cost'); - $arrCosts = explode('|', $costs['param_value']); - $maxCount = count($arrCosts); - - $count = $this->countTodayRefreshTimes($address); - if ($count >= $maxCount) { - $this->_rspErr(2, 'The maximum number of refreshes has been reached'); - return; - } - - $cost = $arrCosts[$count]; - $costItemId = $this->getCostItemIdByTokenType(ShopController::TOKEN_TYPE_GOLD); - $costItems = $this->makeCostItems($costItemId, $cost); - $lackItem = null; - if (!$this->_hasEnoughItems($costItems, $lackItem)) { - $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); - return; - } - - $chk = $this->refreshDailySelectionWithMode($address, 1); - if ($chk) { - $this->_decItems($costItems); - - // error_log("refreshDailySelection-------" . $address . "---" . $cost); - $this->_rspData( - array( - 'cost' => $cost, - ) - ); - } else { - $this->_rspErr(3, 'refresh failed'); - } + myself()->_getSelfRedis()->pexpire( + DAILY_SELECTION_KEY . myself()->_getAccountId(), + $remainSec * 1000); } public function buyGoodsDSOld() diff --git a/webapp/mt/Shop.php b/webapp/mt/Shop.php index c2fdaf53..4ad35949 100644 --- a/webapp/mt/Shop.php +++ b/webapp/mt/Shop.php @@ -48,6 +48,27 @@ class Shop { const OUTSIDE_SHOP = 100; + public static function getCostItemIdByTokenType($tokenType) + { + switch ($tokenType) { + case self::TOKEN_TYPE_GOLD: + { + return V_ITEM_GOLD; + } + break; + case self::TOKEN_TYPE_DIAMOND: + { + return V_ITEM_DIAMOND; + } + break; + default: + { + return -1; + } + break; + } + } + public static function get($id) { return getXVal(self::getMetaList(), $id);