1
This commit is contained in:
parent
7fe27eca41
commit
efe1187307
@ -41,7 +41,7 @@ class SeasonCard(object):
|
||||
'url': 'webapp/index.php?c=SeasonCard&a=buyLevel',
|
||||
'params': [
|
||||
_common.ReqHead(),
|
||||
['level', 0, '购买的等级数'],
|
||||
['add_level', 0, '购买的等级数(是新增值)'],
|
||||
],
|
||||
'response': [
|
||||
_common.RspHead(),
|
||||
|
@ -176,15 +176,6 @@ class Mission(object):
|
||||
['state', 0, '任务状态 0:可领取 1:已领取 2:未完成(不可领取)'],
|
||||
]
|
||||
|
||||
class SeassonCardLvUnlockReward(object):
|
||||
|
||||
def __init__(self):
|
||||
self.fields = [
|
||||
['card_lv', 0, '手册等级'],
|
||||
['state', 0, '0:不可领取 1:可领取 2:已领取'],
|
||||
['items', [AwardItem()], '奖品'],
|
||||
]
|
||||
|
||||
class SeasonCardGiftPackage(object):
|
||||
|
||||
def __init__(self):
|
||||
@ -202,7 +193,7 @@ class SeasonCard(object):
|
||||
['card_lv', 0, '手册等级'],
|
||||
['card_exp', 0, '手册经验'],
|
||||
['!gift_packages', [SeasonCardGiftPackage()], '礼包列表'],
|
||||
['!unlock_rewards', [SeassonCardLvUnlockReward()], '等级解锁的奖励领取列表'],
|
||||
['!received_level_rewards', [0], '等级解锁的奖励已领取等级列表'],
|
||||
]
|
||||
|
||||
class SeasonMission(object):
|
||||
|
@ -52,6 +52,7 @@ class SeasonCardController extends BaseAuthedController {
|
||||
$this->_rspErr(10, '服务器内部错误');
|
||||
die();
|
||||
}
|
||||
$this->seasonCardDb = SeasonCard::allHash($this->currSeasonMeta['id']);
|
||||
}
|
||||
|
||||
public function info()
|
||||
@ -63,7 +64,7 @@ class SeasonCardController extends BaseAuthedController {
|
||||
'card_lv' => $this->seasonDb ? $this->seasonDb['card_lv'] : 1,
|
||||
'card_exp' => $this->seasonDb ? $this->seasonDb['card_exp'] : 0,
|
||||
'gift_packages' => $this->getGiftPackages(),
|
||||
'unlock_rewards' => $this->getUnlockRewards()
|
||||
'received_level_rewards' => $this->getReceivedLevelRewards()
|
||||
)
|
||||
)
|
||||
));
|
||||
@ -71,10 +72,54 @@ class SeasonCardController extends BaseAuthedController {
|
||||
|
||||
public function getReward()
|
||||
{
|
||||
$level = getReqVal('level', 0);
|
||||
$cardMeta = mt\SeasonCard::get($level);
|
||||
if ($level) {
|
||||
$this->_rspErr(1, 'level参数错误');
|
||||
return;
|
||||
}
|
||||
if ($level > $this->seasonDb['card_lv']) {
|
||||
$this->_rspErr(2, '等级未解锁不可领取');
|
||||
return;
|
||||
}
|
||||
$cardDb = getXVal($this->seasonCardDb, $level);
|
||||
if ($cardDd) {
|
||||
$this->_rspErr(3, '不能重复领取');
|
||||
return;
|
||||
}
|
||||
SeasonCard::add($this->currSeasonMeta['id'], $level);
|
||||
$this->_rspData(array(
|
||||
'award' => $this->awardService->toDto(),
|
||||
'property_chg' => $this->propertyChgService->toDto(),
|
||||
));
|
||||
}
|
||||
|
||||
public function buyLevel()
|
||||
{
|
||||
$addLevel = (int)getReqVal('add_level', 0);
|
||||
if ($addLevel < 0) {
|
||||
$this->_rspErr(1, 'add_level参数错误');
|
||||
return;
|
||||
}
|
||||
$newLevel = $this->seasonDb['card_lv'] + $addLevel;
|
||||
$currCardMeta = mt\SeasonCard::get($this->seasonDb['card_lv']);
|
||||
$newCardMeta = mt\SeasonCard::get($newLevel);
|
||||
if (!$currCardMeta || !$newCardMeta) {
|
||||
$this->_rspErr(2, 'add_level越界');
|
||||
return;
|
||||
}
|
||||
$costItemId = V_ITEM_GOLD;
|
||||
$costItemNum = mt\SeasonCard::calcCost($currCardMeta, $newCardMeta);
|
||||
$itemNum = $this->_getItemCount($costItemId, $this->userInfo);
|
||||
if ($itemNum < $costItemId) {
|
||||
$this->_rspErr(3, '金币不足');
|
||||
return;
|
||||
}
|
||||
Season::updateCardLv($this->currSeasonMeta['id'], $newLevel);
|
||||
$this->_rspData(array(
|
||||
'award' => $this->awardService->toDto(),
|
||||
'property_chg' => $this->propertyChgService->toDto(),
|
||||
));
|
||||
}
|
||||
|
||||
public function buyGiftPackage()
|
||||
@ -105,12 +150,11 @@ class SeasonCardController extends BaseAuthedController {
|
||||
return $giftPackages;
|
||||
}
|
||||
|
||||
private function getUnlockRewards()
|
||||
private function getReceivedLevelRewards()
|
||||
{
|
||||
$rewards = array(
|
||||
|
||||
);
|
||||
return $rewards;
|
||||
return array_map(function ($val) {
|
||||
return $val['card_lv'];
|
||||
}, $this->seasonCardDb);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -72,4 +72,20 @@ class Season extends BaseModel {
|
||||
}
|
||||
}
|
||||
|
||||
public static function updateCardLv($seasonId, $cardLv)
|
||||
{
|
||||
|
||||
SqlHelper::update(
|
||||
myself()->_getSelfMysql(),
|
||||
't_season',
|
||||
array(
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'season_id' => $seasonId,
|
||||
),
|
||||
array(
|
||||
"card_lv" => $cardLv,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,14 +9,15 @@ use phpcommon\SqlHelper;
|
||||
|
||||
class SeasonCard extends BaseModel {
|
||||
|
||||
public static function find($itemId)
|
||||
public static function find($seasonId, $cardLv)
|
||||
{
|
||||
$row = SqlHelper::ormSelectOne(
|
||||
myself()->_getSelfMysql(),
|
||||
't_bag',
|
||||
't_season',
|
||||
array(
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'item_id' => $itemId,
|
||||
'season_id' => $seasonId,
|
||||
'card_lv' => $cardLv,
|
||||
)
|
||||
);
|
||||
return $row;
|
||||
@ -25,8 +26,56 @@ class SeasonCard extends BaseModel {
|
||||
public static function toDto($row)
|
||||
{
|
||||
return array(
|
||||
'item_id' => $row['item_id'],
|
||||
'item_num' => $row['item_num'],
|
||||
);
|
||||
}
|
||||
|
||||
public static function all($seasonId)
|
||||
{
|
||||
$rows = SqlHelper::ormSelect(
|
||||
myself()->_getSelfMysql(),
|
||||
't_season_card',
|
||||
array(
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'season_id' => $seasonId,
|
||||
)
|
||||
);
|
||||
return array_map(function($row) {
|
||||
$nowDaySeconds = myself()->_getNowDaySeconds();
|
||||
$mondaySeconds = myself()->_getMondaySeconds();
|
||||
return $row;
|
||||
}, $rows);
|
||||
}
|
||||
|
||||
public static function allHash($seasonId)
|
||||
{
|
||||
$cardHash = array();
|
||||
foreach (self::all($seasonId) as $row) {
|
||||
$cardHash[$row['card_lv']] = $row;
|
||||
}
|
||||
return $cardHash;
|
||||
}
|
||||
|
||||
public function add($seasonId, $cardLv)
|
||||
{
|
||||
$initSeasonCard = mt\SeasonCard::getInitCard();
|
||||
SqlHelper::upsert(
|
||||
myself()->_getSelfMysql(),
|
||||
't_season_card',
|
||||
array(
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'season_id' => $seasonId,
|
||||
'card_lv' => $cardLv,
|
||||
),
|
||||
array(
|
||||
),
|
||||
array(
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'season_id' => $seasonId,
|
||||
'card_lv' => $cardLv,
|
||||
'reward_received' => 1,
|
||||
'createtime' => myself()->_getNowTime(),
|
||||
'modifytime' => myself()->_getNowTime()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,17 @@ class SeasonCard {
|
||||
return self::get(1);
|
||||
}
|
||||
|
||||
public static function calcCost($currMeta, $newMeta)
|
||||
{
|
||||
$cost = 0;
|
||||
$nextMeta = self::get($currMeta['lv']);
|
||||
while ($nextMeta && $nextMeta['lv'] <= $newMeta['lv']) {
|
||||
$cost += $nextMeta['cost'];
|
||||
$nextMeta = self::get($nextMeta['lv'] + 1);
|
||||
}
|
||||
return $cost;
|
||||
}
|
||||
|
||||
protected static function getMetaList()
|
||||
{
|
||||
if (!self::$metaList) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user