game2006api/webapp/controller/CallbackController.class.php
aozhiwei 38c7acc215 1
2022-03-28 16:20:28 +08:00

103 lines
2.9 KiB
PHP

<?php
require_once('mt/Item.php');
require_once('mt/Currency.php');
require_once('mt/Hero.php');
require_once('mt/Parameter.php');
require_once('models/Nft.php');
require_once('models/Withdrawal.php');
require_once('models/Transfer.php');
require_once('models/UserWalletRecord.php');
require_once('phpcommon/bchelper.php');
use phpcommon\SqlHelper;
use models\Nft;
use models\Withdrawal;
use models\Transfer;
use models\UserWalletRecord;
class Callback extends BaseController {
private function isTestMode()
{
return isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443 && SERVER_ENV == _TEST;
}
public function transfer()
{
$dir = getReqVal('dir', '');
$account = strtolower(getReqVal('account', ''));
$txHash = getReqVal('txhash', '');
$type = getReqVal('type', '');
$value = getReqVal('value', '');
$gameId = 2006;
$channel = BC_CHANNEL;
$accountId = phpcommon\createAccountId($channel, $gameId, $account);
$gold = 0;
$diamond = 0;
$conn = myself()->_getMysql($accontId);
if (UserWalletRecord::find($conn, $txHash)) {
myself()->_rspOk();
return;
}
$userRow = SqlHelper::ormSelect(
$conn,
't_user',
array(
'account_id' => $accountId,
));
if ($userRow) {
SqlHelper::update(
$conn,
't_user',
array(
'account_id' => $accountId,
),
array(
'gold' => function() use($gold) {
return 'max(0, gold + ${gold})';
},
'diamond' => function() use($diamond) {
return 'max(0, diamond + ${diamond}';
},
));
} else {
SqlHelper::upsert(
$conn,
't_user_wallet_offline',
array(
'account_id' => $accountId,
),
array(
'gold' => function() use($gold) {
return 'gold + ${gold}';
},
'diamond' => function() use($diamond) {
return 'diamond + ${diamond}';
},
'modifytime' => myself()->_getNowTime()
),
array(
'account_id' => $accountId,
'gold' => $gold,
'diamond' => $diamond,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
));
}
UserWalletRecord::add($txHash, $dir, $accontId, $type, $value);
if ($this->isTestMode()) {
}
myself()->_rspOk();
}
}