301 lines
11 KiB
PHP
301 lines
11 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/Item.php');
|
|
require_once('mt/Parameter.php');
|
|
require_once('mt/Drop.php');
|
|
require_once('mt/Season.php');
|
|
require_once('mt/SeasonCard.php');
|
|
|
|
require_once('services/AwardService.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 $awardService = 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->awardService = new services\AwardService();
|
|
$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 = array(
|
|
SeasonCard::NORMAL_PACKAGE_ID => SeasonCard::allHash($this->currSeasonMeta['id'],
|
|
SeasonCard::NORMAL_PACKAGE_ID),
|
|
SeasonCard::VIP_PACKAGE_ID => SeasonCard::allHash($this->currSeasonMeta['id'],
|
|
SeasonCard::VIP_PACKAGE_ID),
|
|
);
|
|
}
|
|
|
|
public function info()
|
|
{
|
|
$seasonCardMeta = mt\SeasonCard::get(1);
|
|
$this->_rspData(array(
|
|
'info' => array(
|
|
'season_id' => $this->currSeasonMeta['id'],
|
|
'season_begin_time' => strtotime($this->currSeasonMeta['begin_time']),
|
|
'season_end_time' => strtotime($this->currSeasonMeta['end_time']),
|
|
'card_lv' => $this->seasonDb ? $this->seasonDb['card_lv'] : 1,
|
|
'card_exp' => $this->seasonDb ? $this->seasonDb['card_exp'] : 0,
|
|
'card_max_exp' => $this->seasonDb ? $this->seasonDb['card_exp'] : 1,
|
|
'gift_packages' => $this->getGiftPackages(),
|
|
'buy_level_price' => $seasonCardMeta ? $seasonCardMeta['cost'] : 0,
|
|
'received_level_rewards1' => $this->getReceivedLevelRewards(SeasonCard::NORMAL_PACKAGE_ID),
|
|
'received_level_rewards2' => $this->getReceivedLevelRewards(SeasonCard::VIP_PACKAGE_ID),
|
|
)
|
|
));
|
|
}
|
|
|
|
public function getReward()
|
|
{
|
|
$type = getReqVal('type', 0);
|
|
$level = getReqVal('level', 0);
|
|
$cardMeta = mt\SeasonCard::get($level);
|
|
if (!$level) {
|
|
$this->_rspErr(1, 'level参数错误');
|
|
return;
|
|
}
|
|
if (!in_array($type, array(
|
|
SeasonCard::NORMAL_PACKAGE_ID,
|
|
SeasonCard::VIP_PACKAGE_ID
|
|
))) {
|
|
$this->_rspErr(1, 'type参数错误');
|
|
return;
|
|
}
|
|
if ($level > $this->seasonDb['card_lv']) {
|
|
$this->_rspErr(2, '等级未解锁不可领取');
|
|
return;
|
|
}
|
|
$cardDb = getXVal($this->seasonCardDb[$type], $level);
|
|
if ($cardDb) {
|
|
$this->_rspErr(3, '不能重复领取');
|
|
return;
|
|
}
|
|
$dropMeta = mt\Drop::get($type == SeasonCard::NORMAL_PACKAGE_ID ? $cardMeta['reward'] : $cardMeta['advanced_reward']);
|
|
if (!$dropMeta){
|
|
$this->_rspErr(4, '配置表错误');
|
|
return;
|
|
}
|
|
$this->_scatterDrop('season:level_reward:' . $type . ':' . $level,
|
|
$dropMeta,
|
|
$this->awardService,
|
|
$this->propertyChgService);
|
|
SeasonCard::add($this->currSeasonMeta['id'], $type, $level);
|
|
$this->_rspData(array(
|
|
'award' => $this->awardService->toDto(),
|
|
'property_chg' => $this->propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
public function getAllReward()
|
|
{
|
|
$seasonCardMeta = mt\SeasonCard::get(1);
|
|
$info = array(
|
|
'season_id' => $this->currSeasonMeta['id'],
|
|
'season_begin_time' => strtotime($this->currSeasonMeta['begin_time']),
|
|
'season_end_time' => strtotime($this->currSeasonMeta['end_time']),
|
|
'card_lv' => $this->seasonDb ? $this->seasonDb['card_lv'] : 1,
|
|
'card_exp' => $this->seasonDb ? $this->seasonDb['card_exp'] : 0,
|
|
'card_max_exp' => $this->seasonDb ? $this->seasonDb['card_exp'] : 1,
|
|
'gift_packages' => $this->getGiftPackages(),
|
|
'buy_level_price' => $seasonCardMeta ? $seasonCardMeta['cost'] : 0,
|
|
'received_level_rewards1' => $this->getReceivedLevelRewards(SeasonCard::NORMAL_PACKAGE_ID),
|
|
'received_level_rewards2' => $this->getReceivedLevelRewards(SeasonCard::VIP_PACKAGE_ID),
|
|
);
|
|
$vipPackageBuyed = false;
|
|
foreach ($info['gift_packages'] as $package) {
|
|
if ($package['package_id'] == SeasonCard::VIP_PACKAGE_ITEM_ID) {
|
|
if ($package['state'] == 1) {
|
|
$vipPackageBuyed = true;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
for ($i = 1; $i < $info['card_lv']; ++$i) {
|
|
$level = $i;
|
|
$type = SeasonCard::NORMAL_PACKAGE_ID;
|
|
{
|
|
$received1 = array_find($info['received_level_rewards1'], function ($val) use($i) {
|
|
return $val == $i;
|
|
});
|
|
if (!$received1) {
|
|
$this->_scatterDrop('season:level_reward:' . $type . ':' . $level,
|
|
$dropMeta,
|
|
$this->awardService,
|
|
$this->propertyChgService);
|
|
SeasonCard::add($this->currSeasonMeta['id'], $type, $level);
|
|
}
|
|
}
|
|
$type = SeasonCard::VIP_PACKAGE_ID;
|
|
if ($vipPackageBuyed) {
|
|
$received2 = array_find($info['received_level_rewards2'], function ($val) use($i) {
|
|
return $val == $i;
|
|
});
|
|
if (!$received2) {
|
|
$this->_scatterDrop('season:level_reward:' . $type . ':' . $level,
|
|
$dropMeta,
|
|
$this->awardService,
|
|
$this->propertyChgService);
|
|
SeasonCard::add($this->currSeasonMeta['id'], $type, $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_DIAMOND;
|
|
$costItemNum = mt\SeasonCard::calcCost($currCardMeta, $newCardMeta);
|
|
$itemNum = $this->_getItemCount($costItemId, $this->userInfo);
|
|
if ($itemNum < $costItemNum) {
|
|
$this->_rspErr(3, '钻石不足');
|
|
return;
|
|
}
|
|
$this->_decItems(array(
|
|
array(
|
|
'item_id' => $costItemId,
|
|
'item_num' => $costItemNum
|
|
)
|
|
));
|
|
Season::updateCardLv($this->currSeasonMeta['id'], $newLevel);
|
|
$this->propertyChgService->addUserChg();
|
|
$this->_rspData(array(
|
|
'award' => $this->awardService->toDto(),
|
|
'property_chg' => $this->propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
public function buyGiftPackage()
|
|
{
|
|
$packageId = getReqVal('package_id', 0);
|
|
$costItemId = getReqVal('cost_item_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;
|
|
}
|
|
$priceInfo = $giftPackage['price_info'];
|
|
if (empty($priceInfo)) {
|
|
$this->_rspErr(3, '配置表错误');
|
|
return;
|
|
}
|
|
$itemMeta = mt\Item::get($giftPackage['item_id']);
|
|
if (empty($itemMeta)) {
|
|
$this->_rspErr(3, '配置表错误1');
|
|
return;
|
|
}
|
|
$dropMeta = mt\Drop::get($itemMeta['drop']);
|
|
if (empty($dropMeta)) {
|
|
$this->_rspErr(3, '配置表错误3');
|
|
return;
|
|
}
|
|
$costItems = mt\Item::getCostItems($priceInfo, $costItemId);
|
|
if (empty($costItems)) {
|
|
$this->_rspErr(3, '配置表错误2');
|
|
return;
|
|
}
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(4, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
Season::updateGiftPackageState($this->currSeasonMeta['id'], $packageId);
|
|
$this->_decItems($costItems);
|
|
$this->_scatterDrop('season:gift_package:' . $packageId,
|
|
$dropMeta,
|
|
$this->awardService,
|
|
$this->propertyChgService);
|
|
$this->_rspData(array(
|
|
'award' => $this->awardService->toDto(),
|
|
'property_chg' => $this->propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
private function getGiftPackages()
|
|
{
|
|
$itemMeta = mt\Item::get(SeasonCard::VIP_PACKAGE_ITEM_ID);
|
|
$priceInfo = $itemMeta ? mt\Item::getPriceInfo($itemMeta) : null;
|
|
$giftPackages = array(
|
|
array(
|
|
'package_id' => SeasonCard::VIP_PACKAGE_ID,
|
|
'item_id' => SeasonCard::VIP_PACKAGE_ITEM_ID,
|
|
'state' => $this->seasonDb['gift_state2'],
|
|
'price_info' => $priceInfo ? $priceInfo['price_info'] : null
|
|
)
|
|
);
|
|
return $giftPackages;
|
|
}
|
|
|
|
private function getReceivedLevelRewards($type)
|
|
{
|
|
$levels = array();
|
|
foreach (getXVal($this->seasonCardDb, $type, array()) as $val) {
|
|
array_push($levels, $val['card_lv']);
|
|
}
|
|
return $levels;
|
|
}
|
|
|
|
}
|