This commit is contained in:
aozhiwei 2022-03-28 13:47:57 +08:00
parent 745c2dc627
commit e793f51aa2
5 changed files with 156 additions and 9 deletions

View File

@ -16,6 +16,7 @@ class Wallet(object):
['token', '', 'token'],
['type', 0, '货币类型 1:金币 2钻石'],
['amount', '', '金额'],
['net_id', '', '网络id'],
],
'response': [
_common.RspHead(),
@ -31,6 +32,7 @@ class Wallet(object):
['account', 0, '钱包账号'],
['token', '', 'token'],
['seq_id', 0, '提现序号'],
['net_id', '', '网络id'],
],
'response': [
_common.RspHead(errcode='当errcode!=0的时候客户端不需要再调用(停止定时器)'),
@ -46,6 +48,7 @@ class Wallet(object):
['account', 0, '钱包账号'],
['token', '', 'token'],
['txhash', 0, 'hash值'],
['net_id', '', '网络id'],
],
'response': [
_common.RspHead(),

View File

@ -132,7 +132,6 @@ DROP TABLE IF EXISTS `t_withdrawal`;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `t_withdrawal` (
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
`trans_id` varchar(60) NOT NULL DEFAULT '' COMMENT 'trans_id',
`account` varchar(255) NOT NULL DEFAULT '' COMMENT 'account',
`type` int(11) NOT NULL DEFAULT '0' COMMENT 'type',
`net_id` int(11) NOT NULL DEFAULT '0' COMMENT 'net_id',
@ -144,29 +143,32 @@ CREATE TABLE `t_withdrawal` (
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
PRIMARY KEY (`idx`),
UNIQUE KEY `trans_id` (`trans_id`),
UNIQUE KEY `bc_txhash` (`bc_txhash`),
KEY `account` (`account`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `t_recharge`
-- Table structure for table `t_transfer`
--
DROP TABLE IF EXISTS `t_recharge`;
DROP TABLE IF EXISTS `t_transfer`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `t_recharge` (
CREATE TABLE `t_transfer` (
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
`txhash` varchar(255) NOT NULL DEFAULT '' COMMENT 'txhash',
`account` varchar(255) NOT NULL DEFAULT '' COMMENT 'account',
`amount` bigint NOT NULL DEFAULT '0' COMMENT 'amount',
`type` int(11) NOT NULL DEFAULT '0' COMMENT 'type',
`_from` varchar(255) NOT NULL DEFAULT '' COMMENT '_from',
`_to` varchar(255) NOT NULL DEFAULT '' COMMENT '_to',
`value` bigint NOT NULL DEFAULT '0' COMMENT 'value',
`state` int(11) NOT NULL DEFAULT '0' COMMENT '0:未同步 1:同步成功',
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
PRIMARY KEY (`idx`),
UNIQUE KEY `txhash` (`txhash`),
KEY `account` (`account`),
KEY `_from` (`_from`),
KEY `_to` (`_to`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;

View File

@ -6,11 +6,15 @@ 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 {
@ -21,17 +25,75 @@ class WalletController extends BaseController {
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) {
myself()->_rspErr(1, 'More withdrawals than today');
return;
}
$seqId = Withdrawal::add($account, $type, $netId, $amount);
myself()->_rspData(array(
'seq_id' => $seqId
));
if ($this->isTestMode()) {
}
}
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'] == 2) {
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;
}
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace models;
require_once('phpcommon/bchelper.php');
use mt;
use phpcommon;
use phpcommon\SqlHelper;
class Transfer extends BaseModel {
public static function find($txHash)
{
$row = SqlHelper::ormSelectOne(
myself()->_getSelfMysql(),
't_transfer',
array(
'txhash' => $txHash,
)
);
return $row;
}
}

View File

@ -0,0 +1,55 @@
<?php
namespace models;
require_once('phpcommon/bchelper.php');
use mt;
use phpcommon;
use phpcommon\SqlHelper;
class Withdrawal extends BaseModel {
public static function getTodayWithdrawalTimes($account)
{
$row = myself()->_getMarketMysql()->execQueryOne(
'SELECT COUNT(1) AS times FROM t_withdrawal WHERE account=:account AND createtime>=:now_dayseconds AND createtime:<=:now_dayseconds + 3600 * 24;',
array(
':account' => $account,
':now_dayseconds' => myself()->_getNowDaySeconds()
)
);
return $row ? $row['times'] : 0;
}
public static function add($account, $type, $netId, $amount)
{
SqlHelper::insert
(myself()->_getMarketMysql(),
't_withdrawal',
array(
'account' => $account,
'type' => $type,
'net_id' => $netId,
'amount' => $amount,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
)
);
$seqId = SqlHelper::getLastInsertId(myself()->_getMarketMysql());
return $seqId;
}
public static function get($seqId)
{
$row = SqlHelper::ormSelectOne(
myself()->_getSelfMysql(),
't_withdrawal',
array(
'idx' => $seqId,
)
);
return $row;
}
}