game2006api/webapp/models/Withdrawal.php
aozhiwei 268a3713d6 1
2022-03-28 20:09:14 +08:00

87 lines
2.4 KiB
PHP

<?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 find($seqId)
{
$row = SqlHelper::ormSelectOne(
myself()->_getMarketMysql(),
't_withdrawal',
array(
'idx' => $seqId,
)
);
return $row;
}
public static function testOk($idx, $account, $type, $netId, $amount)
{
SqlHelper::update(
myself()->_getMarketMysql(),
't_withdrawal',
array(
'idx' => $idx,
),
array(
'state' => 2,
'bc_block_number' => 1,
'bc_txhash' => $idx,
'bc_time' => myself()->_getNowTime(),
)
);
SqlHelper::insert
(myself()->_getMarketMysql(),
't_transfer',
array(
'txhash' => $idx,
'type' => $type,
'_from' => $account,
'_to' => $account,
'value' => $amount,
'state' => 1,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
)
);
}
}