1
This commit is contained in:
parent
6b236e038b
commit
644917b1bf
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
require_once('mt/Item.php');
|
||||
require_once('mt/Shop.php');
|
||||
require_once('mt/Parameter.php');
|
||||
require_once('mt/Dailyselection.php');
|
||||
|
||||
@ -72,7 +73,36 @@ class DailySelectionController extends BaseAuthedController {
|
||||
|
||||
public function refresh()
|
||||
{
|
||||
$costs = mt\Parameter::getByName('daily_selection_refresh_cost');
|
||||
$arrCosts = explode('|', $costs['param_value']);
|
||||
$maxCount = count($arrCosts);
|
||||
|
||||
$count = $this->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()
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user