176 lines
5.6 KiB
PHP
176 lines
5.6 KiB
PHP
<?php
|
|
|
|
|
|
namespace services;
|
|
|
|
require_once('mt/BattlePass.php');
|
|
require_once ('services/callback/ShopAddItemService.php');
|
|
|
|
use mt\BattlePass;
|
|
use phpcommon\SqlHelper;
|
|
|
|
class BuyPassCbService
|
|
{
|
|
public function process($order){
|
|
error_log("BuyPassCbService----------------");
|
|
$itemService = new ShopAddItemService();
|
|
switch ($order['item_id']){
|
|
//购买通行证回调
|
|
case V_ITEM_PASS : {
|
|
$itemService->addGameLog($order['address'],"buyItem","begin",array(
|
|
'param1' => $order['order_id'],
|
|
'param2' => json_encode(array(
|
|
'item_id' => $order['item_id'],
|
|
'item_num' => $order['item_num'],
|
|
)),
|
|
));
|
|
$this->_activateUser($order['address']);
|
|
error_log("callback buyBattlePass address: {$order['address']}, order_id: {$order['order_id']}, item_id: {$order['item_id']}, item_num: {$order['item_num']}");
|
|
$itemService->addGameLog($order['address'],"buyItem","end",array(
|
|
'param1' => $order['order_id'],
|
|
'param2' => json_encode(array(
|
|
'item_id' => $order['item_id'],
|
|
'item_num' => $order['item_num'],
|
|
)),
|
|
));
|
|
}
|
|
break;
|
|
//购买等级回调
|
|
case V_ITEM_EXP : {
|
|
$itemService->addGameLog($order['address'],"buyItem","begin",array(
|
|
'param1' => $order['order_id'],
|
|
'param2' => json_encode(array(
|
|
'item_id' => $order['item_id'],
|
|
'item_num' => $order['item_num'],
|
|
)),
|
|
));
|
|
$this->_updateUserLevel($order['address'],$order['item_num']);
|
|
error_log("callback buyPassExp address: {$order['address']}, order_id: {$order['order_id']}, item_id: {$order['item_id']}, item_num: {$order['item_num']}");
|
|
$itemService->addGameLog($order['address'],"buyItem","end",array(
|
|
'param1' => $order['order_id'],
|
|
'param2' => json_encode(array(
|
|
'item_id' => $order['item_id'],
|
|
'item_num' => $order['item_num'],
|
|
)),
|
|
));
|
|
}
|
|
default : {
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
private function _activateUser($address){
|
|
SqlHelper::update
|
|
(myself()->_getMysql($address),
|
|
't_user',
|
|
array(
|
|
'address' => $address
|
|
),
|
|
array(
|
|
'activated' => 1,
|
|
'activatetime' => myself()->_getNowTime(),
|
|
)
|
|
);
|
|
|
|
$userDb = SqlHelper::ormSelectOne(
|
|
myself()->_getMysql($address),
|
|
't_user',
|
|
array(
|
|
'address' => $address
|
|
)
|
|
);
|
|
$this->_updatePassData($userDb);
|
|
}
|
|
|
|
private function _updateUserLevel($address,$exp){
|
|
$userDb = SqlHelper::ormSelectOne(
|
|
myself()->_getMysql($address),
|
|
't_user',
|
|
array(
|
|
'address' => $address
|
|
)
|
|
);
|
|
|
|
$expNew = $userDb['exp'] + $exp;
|
|
$levelNew = $userDb['level'];
|
|
BattlePass::getExpByLv($levelNew,$expNew);
|
|
SqlHelper::update
|
|
(myself()->_getMysql($address),
|
|
't_user',
|
|
array(
|
|
'address' => $address
|
|
),
|
|
array(
|
|
'exp' => $expNew,
|
|
'level' => $levelNew,
|
|
)
|
|
);
|
|
$userDbNew = SqlHelper::ormSelectOne(
|
|
myself()->_getMysql($address),
|
|
't_user',
|
|
array(
|
|
'address' => $address
|
|
)
|
|
);
|
|
$this->_updatePassData($userDbNew);
|
|
$this->_updateDynData($userDbNew);
|
|
}
|
|
|
|
private function _updateDynData($user){
|
|
SqlHelper::update
|
|
( myself()->_getMysql($user['address']),
|
|
't_dyndata',
|
|
array(
|
|
'account_id' => $user['account_id'],
|
|
'x' => TN_DAILY_BUY_LEVEL_STATE,
|
|
'y' => 0
|
|
),
|
|
array(
|
|
'val' => 0,
|
|
'modifytime' => myself()->_getNowTime()
|
|
)
|
|
);
|
|
}
|
|
|
|
private function _updatePassData($user){
|
|
$currSeasonMeta = BattlePass::getCurrentSeason();
|
|
$passDb = SqlHelper::ormSelectOne(
|
|
myself()->_getMysql($user['address']),
|
|
't_user_pass',
|
|
array(
|
|
'account_id' => $user['account_id'],
|
|
'season_id' => $currSeasonMeta['id'],
|
|
)
|
|
);
|
|
$rewards = emptyReplace(json_decode($passDb['data'], true), array());
|
|
foreach ($rewards['basic'] as &$reward){
|
|
if ($user['level'] >= $reward['level'] && $reward['state']==-1){
|
|
$reward['state'] = 0;
|
|
}
|
|
}
|
|
if ($user['activated']){
|
|
foreach ($rewards['platinum'] as &$reward){
|
|
if ($user['level'] >= $reward['level'] && $reward['state']==-1){
|
|
$reward['state'] = 0;
|
|
}
|
|
}
|
|
}
|
|
SqlHelper::update(
|
|
myself()->_getMysql($user['address']),
|
|
't_user_pass',
|
|
array(
|
|
'account_id' => $user['account_id'],
|
|
'season_id' => $currSeasonMeta['id'],
|
|
|
|
),
|
|
array(
|
|
'data' => json_encode($rewards),
|
|
'modifytime' => myself()->_getNowTime()
|
|
)
|
|
);
|
|
}
|
|
|
|
|
|
|
|
} |