161 lines
5.0 KiB
PHP
161 lines
5.0 KiB
PHP
<?php
|
|
|
|
require_once('models/User.php');
|
|
require_once('models/Hero.php');
|
|
require_once('models/Season.php');
|
|
require_once('models/SeasonCard.php');
|
|
|
|
require_once('mt/Parameter.php');
|
|
require_once('mt/Drop.php');
|
|
require_once('mt/Season.php');
|
|
require_once('mt/SeasonCard.php');
|
|
|
|
require_once('services/PropertyChgService.php');
|
|
require_once('services/SeasonService.php');
|
|
|
|
use phpcommon\SqlHelper;
|
|
use models\User;
|
|
use models\Hero;
|
|
use models\Season;
|
|
use models\SeasonCard;
|
|
|
|
class SeasonCardController extends BaseAuthedController {
|
|
|
|
private $propertyChgService = null;
|
|
private $userInfo = null;
|
|
private $seasonService = null;
|
|
private $currSeasonMeta = null;
|
|
private $seasonDb = null;
|
|
private $seasonCardDb = null;
|
|
|
|
public function _handlePre()
|
|
{
|
|
parent::_handlePre();
|
|
$this->currSeasonMeta = mt\Season::getCurrentSeason();
|
|
if (!$this->currSeasonMeta) {
|
|
$this->_rspErr(10, '服务器内部错误');
|
|
die();
|
|
}
|
|
$this->propertyChgService = new services\PropertyChgService();
|
|
$this->userInfo = $this->_safeGetOrmUserInfo();
|
|
$this->seasonService = new services\SeasonService();
|
|
if (!$this->seasonService->checkSeason($this->userInfo)) {
|
|
$this->userInfo = $this->_safeGetOrmUserInfo();
|
|
$this->propertyChgService->addUserChg();
|
|
}
|
|
$this->seasonDb = Season::find($this->currSeasonMeta['id']);
|
|
if (!$this->seasonDb) {
|
|
Season::add($this->currSeasonMeta['id']);
|
|
$this->seasonDb = Season::find($this->currSeasonMeta['id']);
|
|
}
|
|
if (!$this->seasonDb) {
|
|
$this->_rspErr(10, '服务器内部错误');
|
|
die();
|
|
}
|
|
$this->seasonCardDb = SeasonCard::allHash($this->currSeasonMeta['id']);
|
|
}
|
|
|
|
public function info()
|
|
{
|
|
$this->_rspData(array(
|
|
array(
|
|
'info' => array(
|
|
'season_id' => $this->currSeasonMeta['id'],
|
|
'card_lv' => $this->seasonDb ? $this->seasonDb['card_lv'] : 1,
|
|
'card_exp' => $this->seasonDb ? $this->seasonDb['card_exp'] : 0,
|
|
'gift_packages' => $this->getGiftPackages(),
|
|
'received_level_rewards' => $this->getReceivedLevelRewards()
|
|
)
|
|
)
|
|
));
|
|
}
|
|
|
|
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()
|
|
{
|
|
$packageId = getReqVal('package_id', 0);
|
|
$giftPackage = array_find($this->getGiftPackages(), function ($val) use($packageId) {
|
|
if ($val['package_id'] == $packageId) {
|
|
return true;
|
|
}
|
|
return false;
|
|
});
|
|
if (!$giftPackage) {
|
|
$this->_rspErr(1, 'pacakge_id参数错误');
|
|
return;
|
|
}
|
|
if ($giftPackage['state'] == 1) {
|
|
$this->_rspErr(2, '不能重复购买');
|
|
return;
|
|
}
|
|
Season::updateGiftPackageState($this->currSeasonMeta['id'], $packageId);
|
|
}
|
|
|
|
private function getGiftPackages()
|
|
{
|
|
$giftPackages = array(
|
|
|
|
);
|
|
return $giftPackages;
|
|
}
|
|
|
|
private function getReceivedLevelRewards()
|
|
{
|
|
return array_map(function ($val) {
|
|
return $val['card_lv'];
|
|
}, $this->seasonCardDb);
|
|
}
|
|
|
|
}
|