This commit is contained in:
hujiabin 2023-06-25 17:25:01 +08:00
parent 96e1d87ba9
commit f10bcce6a4
4 changed files with 174 additions and 117 deletions

View File

@ -8,10 +8,12 @@ const constant = require('../constant');
class Star { class Star {
async start() { async start() {
console.log('Star.start'); console.log('Star And Pass Start');
let url = getUrl(); let url_star = getUrl('resetStar');
let url_pass = getUrl('resetPassLevel');
while (true) { while (true) {
await http.get(url,null) await http.get(url_star,null)
await http.get(url_pass,null)
const nowTime = utils.getUtcTime(); const nowTime = utils.getUtcTime();
const daySeconds = utils.getDaySeconds(nowTime, constant.TIME_ZONE); const daySeconds = utils.getDaySeconds(nowTime, constant.TIME_ZONE);
const sleepTime = daySeconds + 3600 * 24 - nowTime; const sleepTime = daySeconds + 3600 * 24 - nowTime;
@ -23,13 +25,13 @@ class Star {
} }
function getUrl(){ function getUrl(action){
// let url = 'http://james.com/webapp/index.php?&c=Star&a=resetStar'; // let url = 'http://james.com/webapp/index.php?&c=Star&a=resetStar';
let url = ''; let url = '';
if (utils.isOnlineEnv()) { if (utils.isOnlineEnv()) {
url = 'https://game2006api-test.cebggame.com/webapp/index.php?&c=Star&a=resetStar'; url = 'https://game2006api-test.cebggame.com/webapp/index.php?&c=Star&a=' + action;
} else { } else {
url = 'https://game2006api-test.kingsome.cn/webapp/index.php?&c=Star&a=resetStar '; url = 'https://game2006api-test.kingsome.cn/webapp/index.php?&c=Star&a=' + action;
} }
return url; return url;
} }

View File

@ -16,18 +16,20 @@ use phpcommon\SqlHelper;
use models\Pass; use models\Pass;
use models\RealtimeData; use models\RealtimeData;
use models\BcOrder; use models\BcOrder;
class PassController extends BaseAuthedController {
class PassController extends BaseAuthedController
{
private $awardService = null; private $awardService = null;
private $propertyChgService = null; private $propertyChgService = null;
private $userInfo = null; private $userInfo = null;
private $currSeasonMeta = null; private $currSeasonMeta = null;
public function _handlePre() public function _handlePre()
{ {
// if(getReqVal('a', '') != 'resetStar'){ if (getReqVal('a', '') != 'resetPassLevel') {
parent::_handlePre(); parent::_handlePre();
// } }
$this->currSeasonMeta = \mt\BattlePass::getCurrentSeason(); $this->currSeasonMeta = \mt\BattlePass::getCurrentSeason();
if (!$this->currSeasonMeta) { if (!$this->currSeasonMeta) {
$this->_rspErr(10, 'season server internal error'); $this->_rspErr(10, 'season server internal error');
@ -35,27 +37,28 @@ class PassController extends BaseAuthedController {
} }
$this->propertyChgService = new services\PropertyChgService(); $this->propertyChgService = new services\PropertyChgService();
$this->awardService = new services\AwardService(); $this->awardService = new services\AwardService();
$this->userInfo = $this->_getOrmUserInfo(); $this->userInfo = $this->_safeGetOrmUserInfo();
} }
public function getPassList(){ public function getPassList()
{
$row = Pass::find($this->currSeasonMeta['id']); $row = Pass::find($this->currSeasonMeta['id']);
if (!$row){ if (!$row) {
$this->_initPassList($this->currSeasonMeta['id']); $this->_initPassList($this->currSeasonMeta['id']);
$row = Pass::find($this->currSeasonMeta['id']); $row = Pass::find($this->currSeasonMeta['id']);
} }
$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->_getV(TN_DAILY_BUY_PASS_STATE, 0); $pass_state = $this->_getV(TN_DAILY_BUY_PASS_STATE, 0);
$lv_state = $this->_getV(TN_DAILY_BUY_LEVEL_STATE, 0); $lv_state = $this->_getV(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'],
'sub_name'=>$this->currSeasonMeta['battlepass_sub_name'], 'sub_name' => $this->currSeasonMeta['battlepass_sub_name'],
'begin_time'=>strtotime($this->currSeasonMeta['begin_time']), 'begin_time' => strtotime($this->currSeasonMeta['begin_time']),
'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,
@ -65,15 +68,16 @@ class PassController extends BaseAuthedController {
)); ));
} }
public function commit(){ public function commit()
{
$level = getReqVal('level', 0); $level = getReqVal('level', 0);
$type= getReqVal('type', 0); $type = getReqVal('type', 0);
$passMeta = \mt\BattlePass::find($level); $passMeta = \mt\BattlePass::find($level);
if (!$passMeta){ if (!$passMeta) {
$this->_rspErr(1, 'param error or null'); $this->_rspErr(1, 'param error or null');
return; return;
} }
if ($this->userInfo['level'] < $level){ if ($this->userInfo['level'] < $level) {
$this->_rspErr(1, 'objectives not achieved'); $this->_rspErr(1, 'objectives not achieved');
return; return;
} }
@ -82,197 +86,221 @@ class PassController extends BaseAuthedController {
$data = $this->_rewardHash($rewards); $data = $this->_rewardHash($rewards);
$items = array(); $items = array();
switch ($type){ switch ($type) {
case 0 : { case 0 :
if ($data['basic'][$level]['state'] != 0){ {
$this->_rspErr(1, "basic Can't get it again"); if ($data['basic'][$level]['state'] != 0) {
return; $this->_rspErr(1, "basic Can't get it again");
}else{ return;
array_push($items,array( } else {
'item_id'=>$passMeta['basic_item_id'], array_push($items, array(
'item_num'=>$passMeta['basic_item_num'], 'item_id' => $passMeta['basic_item_id'],
)); 'item_num' => $passMeta['basic_item_num'],
));
}
} }
} break;
break; case 1 :
case 1 : { {
if ($this->userInfo['activated'] != 1){ if ($this->userInfo['activated'] != 1) {
$this->_rspErr(1, "don't is platinum pass "); $this->_rspErr(1, "don't is platinum pass ");
return; 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'],
));
}
} }
if ($data['platinum'][$level]['state'] != 0){ break;
$this->_rspErr(1, "platinum Can't get it again"); default :
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'],
));
}
}
break;
default : {
$this->_rspErr(1, "param type is error"); $this->_rspErr(1, "param type is error");
return; return;
} }
} }
$this->_addItems($items,$this->awardService, $this->propertyChgService); $this->_addItems($items, $this->awardService, $this->propertyChgService);
switch ($type){ switch ($type) {
case 0 : { case 0 :
$data['basic'][$level]['state'] = 1; {
$data['basic'][$level]['state'] = 1;
} }
break; break;
case 1 : { case 1 :
{
$data['platinum'][$level]['state'] = 1; $data['platinum'][$level]['state'] = 1;
} }
} }
$data['basic'] = array_values($data['basic']); $data['basic'] = array_values($data['basic']);
$data['platinum'] = array_values($data['platinum']); $data['platinum'] = array_values($data['platinum']);
Pass::upsert($this->currSeasonMeta['id'],json_encode($data)); Pass::upsert($this->currSeasonMeta['id'], json_encode($data));
$this->_rspData(array( $this->_rspData(array(
'award' => $this->awardService->toDto(), 'award' => $this->awardService->toDto(),
'property_chg' => $this->propertyChgService->toDto(), 'property_chg' => $this->propertyChgService->toDto(),
)); ));
} }
public function commitAll(){ public function commitAll()
{
$passDb = Pass::find($this->currSeasonMeta['id']); $passDb = Pass::find($this->currSeasonMeta['id']);
$rewards = emptyReplace(json_decode($passDb['data'], true), array()); $rewards = emptyReplace(json_decode($passDb['data'], true), array());
foreach ($rewards['basic'] as &$reward){ foreach ($rewards['basic'] as &$reward) {
if ($this->userInfo['level'] >= $reward['level'] && $reward['state']==0){ if ($this->userInfo['level'] >= $reward['level'] && $reward['state'] == 0) {
$passMeta = \mt\BattlePass::find($reward['level']); $passMeta = \mt\BattlePass::find($reward['level']);
$items = array( $items = array(
array( array(
'item_id'=>$passMeta['basic_item_id'], 'item_id' => $passMeta['basic_item_id'],
'item_num'=>$passMeta['basic_item_num'], 'item_num' => $passMeta['basic_item_num'],
) )
); );
$this->_addItems($items,$this->awardService, $this->propertyChgService); $this->_addItems($items, $this->awardService, $this->propertyChgService);
$reward['state'] = 1; $reward['state'] = 1;
} }
} }
if ($this->userInfo['activated']){ if ($this->userInfo['activated']) {
foreach ($rewards['platinum'] as &$reward){ foreach ($rewards['platinum'] as &$reward) {
if ($this->userInfo['level'] >= $reward['level'] && $reward['state']==0){ if ($this->userInfo['level'] >= $reward['level'] && $reward['state'] == 0) {
$passMeta = \mt\BattlePass::find($reward['level']); $passMeta = \mt\BattlePass::find($reward['level']);
$items = array( $items = array(
array( array(
'item_id'=>$passMeta['platinum_item_id1'], 'item_id' => $passMeta['platinum_item_id1'],
'item_num'=>$passMeta['platinum_item_num1'], 'item_num' => $passMeta['platinum_item_num1'],
), ),
array( array(
'item_id'=>$passMeta['platinum_item_id2'], 'item_id' => $passMeta['platinum_item_id2'],
'item_num'=>$passMeta['platinum_item_num2'], 'item_num' => $passMeta['platinum_item_num2'],
) )
); );
$this->_addItems($items,$this->awardService, $this->propertyChgService); $this->_addItems($items, $this->awardService, $this->propertyChgService);
$reward['state'] = 1; $reward['state'] = 1;
} }
} }
} }
Pass::upsert($this->currSeasonMeta['id'],json_encode($rewards)); Pass::upsert($this->currSeasonMeta['id'], json_encode($rewards));
$this->_rspData(array( $this->_rspData(array(
'award' => $this->awardService->toDto(), 'award' => $this->awardService->toDto(),
'property_chg' => $this->propertyChgService->toDto(), 'property_chg' => $this->propertyChgService->toDto(),
)); ));
} }
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,$price,V_ITEM_PASS,1); Transaction::BUY_PASS_ACTION_TYPE, $price, V_ITEM_PASS, 1);
$this->_setV(TN_DAILY_BUY_PASS_STATE, 0,1); $this->_setV(TN_DAILY_BUY_PASS_STATE, 0, 1);
BcOrder::upsert($response['trans_id'],array( BcOrder::upsert($response['trans_id'], array(
'item_id'=>V_ITEM_PASS, 'item_id' => V_ITEM_PASS,
'item_num'=>1, 'item_num' => 1,
)); ));
$this->_rspData($response); $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->_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; return;
} }
$response = services\BlockChainService::gameItemMallBuy( $response = services\BlockChainService::gameItemMallBuy(
Transaction::BUY_EXP_ACTION_TYPE,$price,V_ITEM_EXP,$passMeta['total_exp'] - $this->userInfo['exp']); Transaction::BUY_EXP_ACTION_TYPE, $price, V_ITEM_EXP, $passMeta['total_exp'] - $this->userInfo['exp']);
$this->_setV(TN_DAILY_BUY_LEVEL_STATE, 0,1); $this->_setV(TN_DAILY_BUY_LEVEL_STATE, 0, 1);
BcOrder::upsert($response['trans_id'],array( BcOrder::upsert($response['trans_id'], array(
'item_id'=>V_ITEM_EXP, 'item_id' => V_ITEM_EXP,
'item_num'=>$passMeta['total_exp'] - $this->userInfo['exp'], 'item_num' => $passMeta['total_exp'] - $this->userInfo['exp'],
)); ));
$this->_rspData($response); $this->_rspData($response);
} }
public function resetPassLevel(){ public function resetPassLevel()
{
$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){ private function _rewardHash($reward)
if (!$reward){ {
if (!$reward) {
return array(); return array();
} }
$data = array(); $data = array();
foreach ($reward['basic'] as $value){ foreach ($reward['basic'] as $value) {
$data['basic'][$value['level']] = $value; $data['basic'][$value['level']] = $value;
} }
foreach ($reward['platinum'] as $value){ foreach ($reward['platinum'] as $value) {
$data['platinum'][$value['level']] = $value; $data['platinum'][$value['level']] = $value;
} }
return $data; return $data;
} }
private function _initPassList($season){ private function _initPassList($season)
$passList = \mt\BattlePass::all(); {
if (!$passList){ $passList = \mt\BattlePass::all();
if (!$passList) {
return; return;
} }
$data = array( $data = array(
'basic' => array(), 'basic' => array(),
'platinum' => array() 'platinum' => array()
); );
foreach ($passList as $pass){ foreach ($passList as $pass) {
$basic_state = -1; $basic_state = -1;
$platinum_state = -1; $platinum_state = -1;
if ($this->userInfo['level'] >= $pass['id']){ if ($this->userInfo['level'] >= $pass['id']) {
$basic_state = 0; $basic_state = 0;
if ($this->userInfo['activated']){ if ($this->userInfo['activated']) {
$platinum_state = 0; $platinum_state = 0;
} }
} }
array_push($data['basic'],array( array_push($data['basic'], array(
'level' => $pass['id'], 'level' => $pass['id'],
'state' => $basic_state, 'state' => $basic_state,
// 'reward' => array( // 'reward' => array(
@ -280,7 +308,7 @@ class PassController extends BaseAuthedController {
// 'item_num' => $pass['basic_item_num'], // 'item_num' => $pass['basic_item_num'],
// ), // ),
)); ));
array_push($data['platinum'],array( array_push($data['platinum'], array(
'level' => $pass['id'], 'level' => $pass['id'],
'state' => $platinum_state, 'state' => $platinum_state,
// 'reward' => array( // 'reward' => array(
@ -295,7 +323,7 @@ class PassController extends BaseAuthedController {
// ) // )
)); ));
} }
Pass::upsert($season,json_encode($data)); Pass::upsert($season, json_encode($data));
} }
} }

View File

@ -158,6 +158,7 @@ class StarController extends BaseAuthedController {
); );
} }
} }
error_log("request resetStar time : ". date('Y-M-D h:i:s',time()));
RealtimeData::setMissionSeason($this->currMissionSeasonMeta['id']); RealtimeData::setMissionSeason($this->currMissionSeasonMeta['id']);
} }

View File

@ -62,6 +62,32 @@ class RealtimeData extends BaseModel {
); );
} }
//获取通行证的赛季
public static function getPassSeason(){
$db = self::internalGet('battle_pass_season');
return max(1, $db ? $db['value1']: 0);
}
//设置通行证的赛季
public static function setPassSeason($value){
SqlHelper::upsert
(myself()->_getMysql(''),
't_realtime_data',
array(
'name' => 'battle_pass_season'
),
array(
'value1' => $value,
'modifytime' => myself()->_getNowTime()
),
array(
'name' => 'battle_pass_season',
'value1' => $value,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
)
);
}
private static function internalGet($name) private static function internalGet($name)
{ {
$row = SqlHelper::ormSelectOne $row = SqlHelper::ormSelectOne