通行证修改购买货币
This commit is contained in:
parent
c08fefcca4
commit
613678b98e
@ -18,9 +18,9 @@ class Pass(object):
|
||||
_common.RspHead(),
|
||||
['!time_info', [TimeInfo()], '赛季时间'],
|
||||
['!reward_info', [Reward()], '任务列表'],
|
||||
['pass_buy_state', 0, '通行证购买状态 1:购买中'],
|
||||
#['pass_buy_state', 0, '通行证购买状态 1:购买中'],
|
||||
['pass_price', 0, '通行证价格'],
|
||||
['lv_buy_state', 0, '通行证经验购买状态 1:购买中'],
|
||||
#['lv_buy_state', 0, '通行证经验购买状态 1:购买中'],
|
||||
['lv_price', 0, '通行证经验价格(exp/price)'],
|
||||
]
|
||||
},{
|
||||
@ -58,12 +58,12 @@ class Pass(object):
|
||||
'url': 'webapp/index.php?c=Pass&a=buyPlatinumPass',
|
||||
'params': [
|
||||
_common.ReqHead(),
|
||||
['price', 0, '价格'],
|
||||
#['price', 0, '价格'],
|
||||
],
|
||||
'response': [
|
||||
_common.RspHead(),
|
||||
['trans_id', 0, '订单号'],
|
||||
['params', 0, 'params'],
|
||||
#['trans_id', 0, '订单号'],
|
||||
#['params', 0, 'params'],
|
||||
]
|
||||
},{
|
||||
'name': 'buyLevel',
|
||||
@ -73,12 +73,12 @@ class Pass(object):
|
||||
'params': [
|
||||
_common.ReqHead(),
|
||||
['level', 0, '等级'],
|
||||
['price', 0, '价格'],
|
||||
#['price', 0, '价格'],
|
||||
],
|
||||
'response': [
|
||||
_common.RspHead(),
|
||||
['trans_id', 0, '订单号'],
|
||||
['params', 0, 'params'],
|
||||
#['trans_id', 0, '订单号'],
|
||||
#['params', 0, 'params'],
|
||||
]
|
||||
},
|
||||
|
||||
|
@ -11,12 +11,14 @@ 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
|
||||
@ -53,8 +55,8 @@ class PassController extends BaseAuthedController
|
||||
$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);
|
||||
// $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'],
|
||||
@ -63,9 +65,9 @@ class PassController extends BaseAuthedController
|
||||
'end_time' => strtotime($this->currSeasonMeta['end_time'])
|
||||
),
|
||||
'reward_info' => $data,
|
||||
'pass_buy_state' => $pass_state,
|
||||
// 'pass_buy_state' => $pass_state,
|
||||
'pass_price' => $pass_price,
|
||||
'lv_buy_state' => $lv_state,
|
||||
// 'lv_buy_state' => $lv_state,
|
||||
'lv_price' => $lv_price,
|
||||
));
|
||||
}
|
||||
@ -235,55 +237,108 @@ class PassController extends BaseAuthedController
|
||||
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::formatCurrency($price), V_ITEM_PASS, 1);
|
||||
// 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::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);
|
||||
|
||||
$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,
|
||||
//校验用户钻石数量
|
||||
$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);
|
||||
//激活白金通行证状态
|
||||
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(),
|
||||
));
|
||||
$this->_rspData($response);
|
||||
}
|
||||
|
||||
public function buyLevel()
|
||||
{
|
||||
error_log("buyLevel : " . json_encode($_REQUEST));
|
||||
if (!$this->_isValidAddress()) {
|
||||
$this->_rspErr(1, 'address is empty');
|
||||
return;
|
||||
}
|
||||
// if (!$this->_isValidAddress()) {
|
||||
// $this->_rspErr(1, 'address is empty');
|
||||
// return;
|
||||
// }
|
||||
$level = getReqVal('level', '');
|
||||
$price = getReqVal('price', '');
|
||||
// $price = getReqVal('price', '');
|
||||
$passMeta = \mt\BattlePass::find($level);
|
||||
if (!$passMeta) {
|
||||
if (!$passMeta || $this->userInfo['level'] > $level ) {
|
||||
$this->_rspErr(1, 'param level error or null');
|
||||
return;
|
||||
}
|
||||
$celPrice = ($passMeta['total_exp'] - $this->userInfo['exp']) * \mt\Parameter::getVal('battlepass_buy_lv_price', '');
|
||||
if ($celPrice != $price) {
|
||||
$this->_rspErr(1, 'The price is wrong');
|
||||
// if ($celPrice != $price) {
|
||||
// $this->_rspErr(1, 'The price is wrong');
|
||||
// return;
|
||||
// }
|
||||
// $response = services\BlockChainService::gameItemMallBuy(
|
||||
// Transaction::BUY_EXP_ACTION_TYPE, services\BlockChainService::formatCurrency($price), V_ITEM_EXP, $passMeta['total_exp'] - $this->userInfo['exp']);
|
||||
// $this->_setV(TN_DAILY_BUY_LEVEL_STATE, 0, 1);
|
||||
// BcOrder::upsert($response['trans_id'], array(
|
||||
// 'item_id' => V_ITEM_EXP,
|
||||
// 'item_num' => $passMeta['total_exp'] - $this->userInfo['exp'],
|
||||
// 'price' => $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;
|
||||
}
|
||||
$response = services\BlockChainService::gameItemMallBuy(
|
||||
Transaction::BUY_EXP_ACTION_TYPE, services\BlockChainService::formatCurrency($price), V_ITEM_EXP, $passMeta['total_exp'] - $this->userInfo['exp']);
|
||||
$this->_setV(TN_DAILY_BUY_LEVEL_STATE, 0, 1);
|
||||
BcOrder::upsert($response['trans_id'], array(
|
||||
'item_id' => V_ITEM_EXP,
|
||||
'item_num' => $passMeta['total_exp'] - $this->userInfo['exp'],
|
||||
'price' => $price,
|
||||
$this->_decItems($costItems);
|
||||
//提升通行证等级
|
||||
User::update(array(
|
||||
'exp' => $passMeta['total_exp'],
|
||||
'level' => $level,
|
||||
));
|
||||
$this->userInfo = $this->_safeGetOrmUserInfo();
|
||||
//解锁至相应等级的奖励
|
||||
$this->_updatePassData();
|
||||
$propertyChgService = new services\PropertyChgService();
|
||||
$propertyChgService->addUserChg();
|
||||
$this->_rspData(array(
|
||||
'property_chg' => $propertyChgService->toDto(),
|
||||
));
|
||||
$this->_rspData($response);
|
||||
}
|
||||
|
||||
public function resetPassLevel()
|
||||
@ -366,4 +421,22 @@ class PassController extends BaseAuthedController
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user