436 lines
15 KiB
PHP
436 lines
15 KiB
PHP
<?php
|
|
require_once('services/AwardService.php');
|
|
require_once('services/PropertyChgService.php');
|
|
require_once('services/BlockChainService.php');
|
|
require_once('services/LogService.php');
|
|
|
|
require_once('mt/BattlePass.php');
|
|
require_once('mt/StarLevel.php');
|
|
|
|
require_once('models/Pass.php');
|
|
require_once('models/RealtimeData.php');
|
|
require_once('models/Transaction.php');
|
|
require_once('models/BcOrder.php');
|
|
require_once('models/User.php');
|
|
|
|
use models\Transaction;
|
|
use phpcommon\SqlHelper;
|
|
use models\Pass;
|
|
use models\RealtimeData;
|
|
use models\BcOrder;
|
|
use models\User;
|
|
use services\LogService;
|
|
|
|
class PassController extends BaseAuthedController
|
|
{
|
|
|
|
private $awardService = null;
|
|
private $propertyChgService = null;
|
|
private $userInfo = null;
|
|
private $currSeasonMeta = null;
|
|
|
|
public function _handlePre()
|
|
{
|
|
if (getReqVal('a', '') != 'resetPassLevel') {
|
|
parent::_handlePre();
|
|
}
|
|
$this->currSeasonMeta = \mt\BattlePass::getCurrentSeason();
|
|
if (!$this->currSeasonMeta) {
|
|
$this->_rspErr(10, 'season server internal error');
|
|
die();
|
|
}
|
|
$this->propertyChgService = new services\PropertyChgService();
|
|
$this->awardService = new services\AwardService();
|
|
$this->userInfo = $this->_safeGetOrmUserInfo();
|
|
}
|
|
|
|
|
|
public function getPassList()
|
|
{
|
|
$row = Pass::find($this->currSeasonMeta['id']);
|
|
if (!$row) {
|
|
$this->_initPassList($this->currSeasonMeta['id']);
|
|
$row = Pass::find($this->currSeasonMeta['id']);
|
|
}
|
|
$data = emptyReplace(json_decode($row['data'], true), array());
|
|
$pass_price = \mt\Parameter::getVal('battlepass_price', '');
|
|
$lv_price = \mt\Parameter::getVal('battlepass_buy_lv_price', '');
|
|
// $pass_state = $this->_getDailyV(TN_DAILY_BUY_PASS_STATE, 0);
|
|
// $lv_state = $this->_getDailyV(TN_DAILY_BUY_LEVEL_STATE, 0);
|
|
$this->_rspData(array(
|
|
'time_info' => array(
|
|
'name' => $this->currSeasonMeta['battlepass_name'],
|
|
'sub_name' => $this->currSeasonMeta['battlepass_sub_name'],
|
|
'begin_time' => strtotime($this->currSeasonMeta['begin_time']),
|
|
'end_time' => strtotime($this->currSeasonMeta['end_time'])
|
|
),
|
|
'reward_info' => $data,
|
|
// 'pass_buy_state' => $pass_state,
|
|
'pass_price' => $pass_price,
|
|
// 'lv_buy_state' => $lv_state,
|
|
'lv_price' => $lv_price,
|
|
));
|
|
}
|
|
|
|
public function commit()
|
|
{
|
|
$gold = 0;
|
|
$level = getReqVal('level', 0);
|
|
$type = getReqVal('type', 0);
|
|
$passMeta = \mt\BattlePass::find($level);
|
|
if (!$passMeta) {
|
|
$this->_rspErr(1, 'param error or null');
|
|
return;
|
|
}
|
|
if ($this->userInfo['level'] < $level) {
|
|
$this->_rspErr(1, 'objectives not achieved');
|
|
return;
|
|
}
|
|
$passDb = Pass::find($this->currSeasonMeta['id']);
|
|
$rewards = emptyReplace(json_decode($passDb['data'], true), array());
|
|
|
|
$data = $this->_rewardHash($rewards);
|
|
$items = array();
|
|
switch ($type) {
|
|
case 0 :
|
|
{
|
|
if ($data['basic'][$level]['state'] != 0) {
|
|
$this->_rspErr(1, "basic Can't get it again");
|
|
return;
|
|
} else {
|
|
array_push($items, array(
|
|
'item_id' => $passMeta['basic_item_id'],
|
|
'item_num' => $passMeta['basic_item_num'],
|
|
));
|
|
if ($passMeta['basic_item_id'] == V_ITEM_GOLD){
|
|
$gold += $passMeta['basic_item_num'];
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case 1 :
|
|
{
|
|
if ($this->userInfo['activated'] != 1) {
|
|
$this->_rspErr(1, "don't is platinum pass ");
|
|
return;
|
|
}
|
|
if ($data['platinum'][$level]['state'] != 0) {
|
|
$this->_rspErr(1, "platinum Can't get it again");
|
|
return;
|
|
} else {
|
|
array_push($items, array(
|
|
'item_id' => $passMeta['platinum_item_id1'],
|
|
'item_num' => $passMeta['platinum_item_num1'],
|
|
));
|
|
array_push($items, array(
|
|
'item_id' => $passMeta['platinum_item_id2'],
|
|
'item_num' => $passMeta['platinum_item_num2'],
|
|
'is_payed' => 1
|
|
));
|
|
if ($passMeta['platinum_item_id1'] == V_ITEM_GOLD){
|
|
$gold += $passMeta['platinum_item_num1'];
|
|
}
|
|
if ($passMeta['platinum_item_id2'] == V_ITEM_GOLD){
|
|
$gold += $passMeta['platinum_item_num2'];
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
default :
|
|
{
|
|
$this->_rspErr(1, "param type is error");
|
|
return;
|
|
}
|
|
}
|
|
|
|
$this->_addItems($items, $this->awardService, $this->propertyChgService);
|
|
switch ($type) {
|
|
case 0 :
|
|
{
|
|
$data['basic'][$level]['state'] = 1;
|
|
|
|
}
|
|
break;
|
|
case 1 :
|
|
{
|
|
$data['platinum'][$level]['state'] = 1;
|
|
|
|
}
|
|
}
|
|
$data['basic'] = array_values($data['basic']);
|
|
$data['platinum'] = array_values($data['platinum']);
|
|
if ($gold > 0){
|
|
//埋点
|
|
$event = [
|
|
'name' => LogService::BATTLE_PASS_AWARD,
|
|
'val' => $gold
|
|
];
|
|
LogService::productGold($event);
|
|
}
|
|
Pass::upsert($this->currSeasonMeta['id'], json_encode($data));
|
|
$this->_rspData(array(
|
|
'award' => $this->awardService->toDto(),
|
|
'property_chg' => $this->propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
public function commitAll()
|
|
{
|
|
$gold = 0;
|
|
$passDb = Pass::find($this->currSeasonMeta['id']);
|
|
$rewards = emptyReplace(json_decode($passDb['data'], true), array());
|
|
foreach ($rewards['basic'] as &$reward) {
|
|
if ($this->userInfo['level'] >= $reward['level'] && $reward['state'] == 0) {
|
|
$passMeta = \mt\BattlePass::find($reward['level']);
|
|
$items = array(
|
|
array(
|
|
'item_id' => $passMeta['basic_item_id'],
|
|
'item_num' => $passMeta['basic_item_num'],
|
|
)
|
|
);
|
|
if ($passMeta['basic_item_id'] == V_ITEM_GOLD){
|
|
$gold += $passMeta['basic_item_num'];
|
|
}
|
|
$this->_addItems($items, $this->awardService, $this->propertyChgService);
|
|
$reward['state'] = 1;
|
|
}
|
|
}
|
|
if ($this->userInfo['activated']) {
|
|
foreach ($rewards['platinum'] as &$reward) {
|
|
if ($this->userInfo['level'] >= $reward['level'] && $reward['state'] == 0) {
|
|
$passMeta = \mt\BattlePass::find($reward['level']);
|
|
$items = array(
|
|
array(
|
|
'item_id' => $passMeta['platinum_item_id1'],
|
|
'item_num' => $passMeta['platinum_item_num1'],
|
|
),
|
|
array(
|
|
'item_id' => $passMeta['platinum_item_id2'],
|
|
'item_num' => $passMeta['platinum_item_num2'],
|
|
'is_payed' => 1
|
|
)
|
|
);
|
|
if ($passMeta['platinum_item_id1'] == V_ITEM_GOLD){
|
|
$gold += $passMeta['platinum_item_num1'];
|
|
}
|
|
if ($passMeta['platinum_item_id2'] == V_ITEM_GOLD){
|
|
$gold += $passMeta['platinum_item_num2'];
|
|
}
|
|
$this->_addItems($items, $this->awardService, $this->propertyChgService);
|
|
$reward['state'] = 1;
|
|
}
|
|
}
|
|
}
|
|
if ($gold > 0){
|
|
//埋点
|
|
$event = [
|
|
'name' => LogService::BATTLE_PASS_AWARD,
|
|
'val' => $gold
|
|
];
|
|
LogService::productGold($event);
|
|
}
|
|
Pass::upsert($this->currSeasonMeta['id'], json_encode($rewards));
|
|
$this->_rspData(array(
|
|
'award' => $this->awardService->toDto(),
|
|
'property_chg' => $this->propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
public function buyPlatinumPass()
|
|
{
|
|
error_log("buyPlatinumPass : " . json_encode($_REQUEST));
|
|
// if (!$this->_isValidAddress()) {
|
|
// $this->_rspErr(1, 'address is empty');
|
|
// return;
|
|
// }
|
|
// $price = getReqVal('price', '');
|
|
// if ($price != \mt\Parameter::getVal('battlepass_price', '')) {
|
|
// $this->_rspErr(1, 'The price is wrong');
|
|
// return;
|
|
// }
|
|
// $response = services\BlockChainService::gameItemMallBuy(
|
|
// Transaction::BUY_PASS_ACTION_TYPE, services\BlockChainService::CURRENCY_CEG, services\BlockChainService::formatCurrency($price), V_ITEM_PASS, 1);
|
|
//
|
|
// $this->_setV(TN_DAILY_BUY_PASS_STATE, 0, 1);
|
|
// BcOrder::upsert($response['trans_id'], array(
|
|
// 'item_id' => V_ITEM_PASS,
|
|
// 'item_num' => 1,
|
|
// 'price' => $price,
|
|
// ));
|
|
// $this->_rspData($response);
|
|
|
|
//校验用户钻石数量
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => V_ITEM_DIAMOND,
|
|
'item_num' => \mt\Parameter::getVal('battlepass_price', '')
|
|
)
|
|
);
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
$this->_decItems($costItems);
|
|
//埋点
|
|
$event = [
|
|
'name' => LogService::BUY_BATTLE_PASS,
|
|
'val' => \mt\Parameter::getVal('battlepass_price', '')
|
|
];
|
|
LogService::consumeDiamond($event);
|
|
//激活白金通行证状态
|
|
User::update(array(
|
|
'activated' => 1,
|
|
'activatetime' => myself()->_getNowTime(),
|
|
));
|
|
$this->userInfo = $this->_safeGetOrmUserInfo();
|
|
//解锁白金用户的奖励
|
|
$this->_updatePassData();
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$propertyChgService->addUserChg();
|
|
$this->_rspData(array(
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
public function buyLevel()
|
|
{
|
|
error_log("buyLevel : " . json_encode($_REQUEST));
|
|
$exp = getReqVal('exp', '');
|
|
$celPrice = $exp * \mt\Parameter::getVal('battlepass_buy_lv_price', '');
|
|
//校验用户钻石数量
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => V_ITEM_DIAMOND,
|
|
'item_num' => $celPrice
|
|
)
|
|
);
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
$this->_decItems($costItems);
|
|
//埋点
|
|
$event = [
|
|
'name' => LogService::BUY_PASS_EXP,
|
|
'val' => $celPrice
|
|
];
|
|
LogService::consumeDiamond($event);
|
|
//提升通行证等级
|
|
$items = array(
|
|
array(
|
|
'item_id' => V_ITEM_EXP,
|
|
'item_num' => $exp
|
|
)
|
|
);
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$awardService = new services\AwardService();
|
|
$this->_addItems($items,$awardService,$propertyChgService);
|
|
$propertyChgService->addUserChg();
|
|
$this->_rspData(array(
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
public function resetPassLevel()
|
|
{
|
|
return;
|
|
$season = RealtimeData::getPassSeason();
|
|
if ($this->currSeasonMeta['id'] > $season) {
|
|
myself()->_getSelfMysql()->execQuery(
|
|
'UPDATE t_user SET activated=:activated,level=:level,exp=:exp',
|
|
array(
|
|
"activated" => 0,
|
|
"level" => 1,
|
|
"exp" => 0,
|
|
)
|
|
);
|
|
error_log("request resetPassLevel time : ". date('Y-M-D h:i:s',time()));
|
|
RealtimeData::setPassSeason($this->currSeasonMeta['id']);
|
|
}
|
|
|
|
}
|
|
|
|
private function _rewardHash($reward)
|
|
{
|
|
if (!$reward) {
|
|
return array();
|
|
}
|
|
$data = array();
|
|
foreach ($reward['basic'] as $value) {
|
|
$data['basic'][$value['level']] = $value;
|
|
}
|
|
|
|
foreach ($reward['platinum'] as $value) {
|
|
$data['platinum'][$value['level']] = $value;
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
private function _initPassList($season)
|
|
{
|
|
$passList = \mt\BattlePass::all();
|
|
if (!$passList) {
|
|
return;
|
|
}
|
|
$data = array(
|
|
'basic' => array(),
|
|
'platinum' => array()
|
|
);
|
|
foreach ($passList as $pass) {
|
|
$basic_state = -1;
|
|
$platinum_state = -1;
|
|
if ($this->userInfo['level'] >= $pass['id']) {
|
|
$basic_state = 0;
|
|
if ($this->userInfo['activated']) {
|
|
$platinum_state = 0;
|
|
}
|
|
}
|
|
array_push($data['basic'], array(
|
|
'level' => $pass['id'],
|
|
'state' => $basic_state,
|
|
// 'reward' => array(
|
|
// 'item_id' => $pass['basic_item_id'],
|
|
// 'item_num' => $pass['basic_item_num'],
|
|
// ),
|
|
));
|
|
array_push($data['platinum'], array(
|
|
'level' => $pass['id'],
|
|
'state' => $platinum_state,
|
|
// 'reward' => array(
|
|
// array(
|
|
// 'item_id' => $pass['platinum_item_id1'],
|
|
// 'item_num' => $pass['platinum_item_num1'],
|
|
// ),
|
|
// array(
|
|
// 'item_id' => $pass['platinum_item_id2'],
|
|
// 'item_num' => $pass['platinum_item_num2'],
|
|
// ),
|
|
// )
|
|
));
|
|
}
|
|
Pass::upsert($season, json_encode($data));
|
|
}
|
|
|
|
private function _updatePassData(){
|
|
$passDb = Pass::find($this->currSeasonMeta['id']);
|
|
$rewards = emptyReplace(json_decode($passDb['data'], true), array());
|
|
foreach ($rewards['basic'] as &$reward){
|
|
if ($this->userInfo['level'] >= $reward['level'] && $reward['state']==-1){
|
|
$reward['state'] = 0;
|
|
}
|
|
}
|
|
if ($this->userInfo['activated']){
|
|
foreach ($rewards['platinum'] as &$reward){
|
|
if ($this->userInfo['level'] >= $reward['level'] && $reward['state']==-1){
|
|
$reward['state'] = 0;
|
|
}
|
|
}
|
|
}
|
|
Pass::upsert($this->currSeasonMeta['id'], json_encode($rewards));
|
|
}
|
|
|
|
}
|