通行证修改购买货币

This commit is contained in:
hujiabin 2023-07-15 14:12:36 +08:00
parent c08fefcca4
commit 613678b98e
2 changed files with 118 additions and 45 deletions

View File

@ -18,9 +18,9 @@ class Pass(object):
_common.RspHead(), _common.RspHead(),
['!time_info', [TimeInfo()], '赛季时间'], ['!time_info', [TimeInfo()], '赛季时间'],
['!reward_info', [Reward()], '任务列表'], ['!reward_info', [Reward()], '任务列表'],
['pass_buy_state', 0, '通行证购买状态 1购买中'], #['pass_buy_state', 0, '通行证购买状态 1购买中'],
['pass_price', 0, '通行证价格'], ['pass_price', 0, '通行证价格'],
['lv_buy_state', 0, '通行证经验购买状态 1购买中'], #['lv_buy_state', 0, '通行证经验购买状态 1购买中'],
['lv_price', 0, '通行证经验价格(exp/price)'], ['lv_price', 0, '通行证经验价格(exp/price)'],
] ]
},{ },{
@ -58,12 +58,12 @@ class Pass(object):
'url': 'webapp/index.php?c=Pass&a=buyPlatinumPass', 'url': 'webapp/index.php?c=Pass&a=buyPlatinumPass',
'params': [ 'params': [
_common.ReqHead(), _common.ReqHead(),
['price', 0, '价格'], #['price', 0, '价格'],
], ],
'response': [ 'response': [
_common.RspHead(), _common.RspHead(),
['trans_id', 0, '订单号'], #['trans_id', 0, '订单号'],
['params', 0, 'params'], #['params', 0, 'params'],
] ]
},{ },{
'name': 'buyLevel', 'name': 'buyLevel',
@ -73,12 +73,12 @@ class Pass(object):
'params': [ 'params': [
_common.ReqHead(), _common.ReqHead(),
['level', 0, '等级'], ['level', 0, '等级'],
['price', 0, '价格'], #['price', 0, '价格'],
], ],
'response': [ 'response': [
_common.RspHead(), _common.RspHead(),
['trans_id', 0, '订单号'], #['trans_id', 0, '订单号'],
['params', 0, 'params'], #['params', 0, 'params'],
] ]
}, },

View File

@ -11,12 +11,14 @@ require_once('models/Pass.php');
require_once('models/RealtimeData.php'); require_once('models/RealtimeData.php');
require_once('models/Transaction.php'); require_once('models/Transaction.php');
require_once('models/BcOrder.php'); require_once('models/BcOrder.php');
require_once('models/User.php');
use models\Transaction; use models\Transaction;
use phpcommon\SqlHelper; use phpcommon\SqlHelper;
use models\Pass; use models\Pass;
use models\RealtimeData; use models\RealtimeData;
use models\BcOrder; use models\BcOrder;
use models\User;
use services\LogService; use services\LogService;
class PassController extends BaseAuthedController class PassController extends BaseAuthedController
@ -53,8 +55,8 @@ class PassController extends BaseAuthedController
$data = emptyReplace(json_decode($row['data'], true), array()); $data = emptyReplace(json_decode($row['data'], true), array());
$pass_price = \mt\Parameter::getVal('battlepass_price', ''); $pass_price = \mt\Parameter::getVal('battlepass_price', '');
$lv_price = \mt\Parameter::getVal('battlepass_buy_lv_price', ''); $lv_price = \mt\Parameter::getVal('battlepass_buy_lv_price', '');
$pass_state = $this->_getDailyV(TN_DAILY_BUY_PASS_STATE, 0); // $pass_state = $this->_getDailyV(TN_DAILY_BUY_PASS_STATE, 0);
$lv_state = $this->_getDailyV(TN_DAILY_BUY_LEVEL_STATE, 0); // $lv_state = $this->_getDailyV(TN_DAILY_BUY_LEVEL_STATE, 0);
$this->_rspData(array( $this->_rspData(array(
'time_info' => array( 'time_info' => array(
'name' => $this->currSeasonMeta['battlepass_name'], 'name' => $this->currSeasonMeta['battlepass_name'],
@ -63,9 +65,9 @@ class PassController extends BaseAuthedController
'end_time' => strtotime($this->currSeasonMeta['end_time']) 'end_time' => strtotime($this->currSeasonMeta['end_time'])
), ),
'reward_info' => $data, 'reward_info' => $data,
'pass_buy_state' => $pass_state, // 'pass_buy_state' => $pass_state,
'pass_price' => $pass_price, 'pass_price' => $pass_price,
'lv_buy_state' => $lv_state, // 'lv_buy_state' => $lv_state,
'lv_price' => $lv_price, 'lv_price' => $lv_price,
)); ));
} }
@ -235,55 +237,108 @@ class PassController extends BaseAuthedController
public function buyPlatinumPass() public function buyPlatinumPass()
{ {
error_log("buyPlatinumPass : " . json_encode($_REQUEST)); error_log("buyPlatinumPass : " . json_encode($_REQUEST));
if (!$this->_isValidAddress()) { // if (!$this->_isValidAddress()) {
$this->_rspErr(1, 'address is empty'); // $this->_rspErr(1, 'address is empty');
return; // return;
} // }
$price = getReqVal('price', ''); // $price = getReqVal('price', '');
if ($price != \mt\Parameter::getVal('battlepass_price', '')) { // if ($price != \mt\Parameter::getVal('battlepass_price', '')) {
$this->_rspErr(1, 'The price is wrong'); // $this->_rspErr(1, 'The price is wrong');
return; // return;
} // }
$response = services\BlockChainService::gameItemMallBuy( // $response = services\BlockChainService::gameItemMallBuy(
Transaction::BUY_PASS_ACTION_TYPE, services\BlockChainService::formatCurrency($price), V_ITEM_PASS, 1); // 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( $costItems = array(
'item_id' => V_ITEM_PASS, array(
'item_num' => 1, 'item_id' => V_ITEM_DIAMOND,
'price' => $price, '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() public function buyLevel()
{ {
error_log("buyLevel : " . json_encode($_REQUEST)); error_log("buyLevel : " . json_encode($_REQUEST));
if (!$this->_isValidAddress()) { // if (!$this->_isValidAddress()) {
$this->_rspErr(1, 'address is empty'); // $this->_rspErr(1, 'address is empty');
return; // return;
} // }
$level = getReqVal('level', ''); $level = getReqVal('level', '');
$price = getReqVal('price', ''); // $price = getReqVal('price', '');
$passMeta = \mt\BattlePass::find($level); $passMeta = \mt\BattlePass::find($level);
if (!$passMeta) { if (!$passMeta || $this->userInfo['level'] > $level ) {
$this->_rspErr(1, 'param level error or null'); $this->_rspErr(1, 'param level error or null');
return; return;
} }
$celPrice = ($passMeta['total_exp'] - $this->userInfo['exp']) * \mt\Parameter::getVal('battlepass_buy_lv_price', ''); $celPrice = ($passMeta['total_exp'] - $this->userInfo['exp']) * \mt\Parameter::getVal('battlepass_buy_lv_price', '');
if ($celPrice != $price) { // if ($celPrice != $price) {
$this->_rspErr(1, 'The price is wrong'); // $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; return;
} }
$response = services\BlockChainService::gameItemMallBuy( $this->_decItems($costItems);
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); User::update(array(
BcOrder::upsert($response['trans_id'], array( 'exp' => $passMeta['total_exp'],
'item_id' => V_ITEM_EXP, 'level' => $level,
'item_num' => $passMeta['total_exp'] - $this->userInfo['exp'], ));
'price' => $price, $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() public function resetPassLevel()
@ -366,4 +421,22 @@ class PassController extends BaseAuthedController
Pass::upsert($season, json_encode($data)); 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));
}
} }