game2006api/webapp/controller/WalletController.class.php
aozhiwei 370ec39a2e 1
2022-03-28 20:25:17 +08:00

125 lines
3.4 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('phpcommon/bchelper.php');
use phpcommon\SqlHelper;
use models\Nft;
use models\Withdrawal;
use models\Transfer;
class WalletController extends BaseController {
private function isTestMode()
{
return isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443 && SERVER_ENV == _TEST;
}
public function withdrawal()
{
$account = strtolower(getReqVal('account', ''));
$token = getReqVal('token', '');
$type = getReqVal('type', '');
$netId = getReqVal('net_id', '');
$amount = getReqVal('amount', '');
$times = Withdrawal::getTodayWithdrawalTimes($account);
if ($times > 200) {
myself()->_rspErr(1, 'More withdrawals than today');
return;
}
$seqId = Withdrawal::add($account, $type, $netId, $amount);
myself()->_rspData(array(
'seq_id' => $seqId
));
if ($this->isTestMode()) {
Withdrawal::testOk($seqId, $account, $type, $netId, $amount);
$this->notifyGame(0, $seqId, $account, $type, $netId, $amount);
}
}
public function queryWithdrawalResult()
{
$account = strtolower(getReqVal('account', ''));
$seqId = getReqVal('seq_id', '');
$row = Withdrawal::find($seqId);
if (!$row || $row['account'] != $account) {
myself()->_rspErr(0, 'not found');
return;
}
if ($row['state'] == 1) {
myself()->_rspErr(2, 'processing');
return;
}
if ($row['state'] == 3) {
myself()->_rspErr(3, 'failed');
return;
}
$transferDb = Transfer::find($row['bc_txhash']);
if (!$transferDb) {
myself()->_rspErr(2, 'processing');
return;
}
if ($transferDb['state'] == 0) {
myself()->_rspErr(2, 'processing');
return;
} else {
myself()->_rspErr(1, 'processing');
return;
}
}
public function queryRechargeResult()
{
$account = strtolower(getReqVal('account', ''));
$txHash = getReqVal('txhash', '');
if ($this->isTestMode()) {
}
$transferDb = Transfer::find($txHash);
if (!$transferDb) {
myself()->_rspErr(2, 'processing');
return;
}
if ($transferDb['state'] == 0) {
myself()->_rspErr(2, 'processing');
return;
} else {
myself()->_rspErr(1, 'processing');
return;
}
}
private function notifyGame($dir, $txhash, $account, $type, $netId, $value)
{
$apiUrl = "https://game2006api-test.kingsome.cn";
$params = array(
'c' => 'Callback',
'a' => 'transfer',
'dir' => $dir,
'txhash' => $txhash,
'account' => $account,
'type' => $type,
'value' => $value
);
$url = $apiUrl . '/webapp/index.php';
$response = '';
if (!phpcommon\HttpClient::get
($url,
$params,
$response)) {
phpcommon\sendError(500, 'server internal error');
die();
return;
}
}
}