134 lines
4.0 KiB
PHP
134 lines
4.0 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 CallbackController 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', '0');
|
|
|
|
$gameId = 2006;
|
|
$channel = BC_CHANNEL;
|
|
$accountId = phpcommon\createAccountId($channel, $gameId, $account);
|
|
|
|
$conn = myself()->_getMysql($accountId);
|
|
if (UserWalletRecord::find($conn, $txHash)) {
|
|
myself()->_rspOk();
|
|
return;
|
|
}
|
|
UserWalletRecord::add($conn, $txHash, $dir, $account, $type, $value);
|
|
|
|
if (!in_array($dir, array(0, 1))){
|
|
myself()->_rspErr(1, '');
|
|
return;
|
|
}
|
|
|
|
if (!in_array($type, array(1, 2))){
|
|
myself()->_rspErr(2, '');
|
|
return;
|
|
}
|
|
if (strlen($value) <= 18){
|
|
myself()->_rspErr(4, '');
|
|
return;
|
|
}
|
|
$value = substr($value, 0, -18);
|
|
if ($value < 0 || empty($value)) {
|
|
myself()->_rspErr(3, '');
|
|
return;
|
|
}
|
|
|
|
$gold = 0;
|
|
$diamond = 0;
|
|
if ($type == 1) {
|
|
$gold = $value;
|
|
} else {
|
|
$diamond = $value;
|
|
}
|
|
if ($dir == 1) {
|
|
$gold = -$gold;
|
|
$diamond = -$diamond;
|
|
}
|
|
|
|
$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 "CASE WHEN gold + ${gold} < 0 THEN 0 ELSE gold + ${gold} END";
|
|
},
|
|
'diamond' => function() use($diamond) {
|
|
return "CASE WHEN diamond + ${diamond} < 0 THEN 0 ELSE diamond + ${diamond} END";
|
|
},
|
|
));
|
|
} else {
|
|
SqlHelper::upsert(
|
|
$conn,
|
|
't_user_wallet_offline',
|
|
array(
|
|
'account_id' => $accountId,
|
|
),
|
|
array(
|
|
'gold' => function() use($gold) {
|
|
return "CASE WHEN gold + ${gold} < 0 THEN 0 ELSE gold + ${gold} END";
|
|
},
|
|
'diamond' => function() use($diamond) {
|
|
return "CASE WHEN diamond + ${diamond} < 0 THEN 0 ELSE diamond + ${diamond} END";
|
|
},
|
|
'modifytime' => myself()->_getNowTime()
|
|
),
|
|
array(
|
|
'account_id' => $accountId,
|
|
'gold' => $gold,
|
|
'diamond' => $diamond,
|
|
'createtime' => myself()->_getNowTime(),
|
|
'modifytime' => myself()->_getNowTime()
|
|
));
|
|
}
|
|
UserWalletRecord::update($conn,
|
|
$txHash,
|
|
array(
|
|
'state' => 1,
|
|
'modifytime' => myself()->_getNowTime()
|
|
));
|
|
|
|
myself()->_rspOk();
|
|
}
|
|
|
|
}
|