game2006api/webapp/controller/OutAppPlanetController.class.php
aozhiwei c7e9f9f504 1
2023-09-01 13:19:20 +08:00

68 lines
1.7 KiB
PHP

<?php
require_once('models/Transaction.php');
require_once('services/BlockChainService.php');
use phpcommon\SqlHelper;
use models\Transaction;
use services\BlockChainService;
class OutAppPlanetController extends BaseController {
public function buy()
{
$netId = getReqVal('net_id', '');
$address = getReqVal('address', '');
$num = getReqVal('num', '');
if ($netId != NET_ID) {
myself()->_rspErr(1, 'net_id error');
return;
}
if ($num < 1) {
myself()->_rspErr(1, 'num error');
return;
}
$decimals = BlockChainService::getCurrencyDecimals(BlockChainService::CURRENCY_USDT);
if ($decimals === false) {
myself()->_rspErr(1, 'deciamls error');
return;
}
$ids = array(
'280002'
);
$price = BlockChainService::formatCurrencyEx(1 * count($ids), $decimals);
$rspObj = BlockChainService::beNftMallTransBuyPlanet(
Transaction::BUY_OUTAPP_PLANET_ACTION_TYPE,
$address,
$ids,
BlockChainService::CURRENCY_USDT,
$price
);
$this->_rspData(array(
'trans_id' => $rspObj['trans_id'],
'params' => $rspObj['params'],
));
}
private function load($period)
{
$rawData = myself()->_getRedis('')->get(PLANET_BUY_KEY . $period);
if (empty($rawData)) {
return array();
}
return json_decode($rawData, true);
}
private function save($data)
{
myself()->_getRedis('')->get(PLANET_BUY_KEY . $period, json_encode($data));
}
}