game2006api/webapp/controller/NewMarketController.class.php
aozhiwei 6796aad0a8 1
2022-01-26 11:20:10 +08:00

163 lines
5.3 KiB
PHP

<?php
require_once('mt/MarketGoods.php');
require_once('mt/MarketBatch.php');
require_once('mt/Item.php');
require_once('mt/WhiteList.php');
require_once('mt/Currency.php');
require_once('mt/Hero.php');
require_once('models/BoxOrder.php');
require_once('models/Nft.php');
use phpcommon\SqlHelper;
use models\BoxOrder;
use models\Nft;
class NewMarketController extends BaseController {
private function isTestMode()
{
return true;
}
public function searchBox()
{
$account = getReqVal('account', '');
$page = getReqVal('page', 1);
$type = getReqVal('type', 0);
$sort = getReqVal('sort', '');
$currBatchMeta = mt\MarketBatch::getCurrentBatch();
if (!$currBatchMeta) {
myself()->_rspErr(500, 'server internal error');
return;
}
$perPage = 10000;
$rows = array();
$pageInfo = array(
'total' => 0,
'count' => 0,
'per_page' => $perPage,
'current_page' => $page,
'total_pages' => 0
);
$presaleInfo = array(
'batch_id' => $currBatchMeta['batch_id'],
'countdown' => max(0, $currBatchMeta['_start_time_utc'] - myself()->_getNowTime()),
'sold_num' => min(BoxOrder::getSoldNum($currBatchMeta['batch_id']), $currBatchMeta['number_of_props']),
'total_num' => $currBatchMeta['number_of_props'],
'hint' => str_replace("\n", '\n', $currBatchMeta['hint']),
'buyed' => $this->isTestMode() ? 0 : BoxOrder::isBuyed($account, $currBatchMeta['batch_id'])
);
$batchMetas = mt\MarketGoods::getBatchMetas($currBatchMeta['batch_id']);
if ($batchMetas) {
foreach ($batchMetas as $meta) {
$heroMeta = mt\Hero::get($meta['item_id']);
$saleBox = array(
'box_id' => $meta['item_id'],
'item_id' => $meta['item_id'],
'name' => emptyReplace($heroMeta['name'], 'Hill'),
'job' => emptyReplace($heroMeta['herotype'], '1'),
'currency_list' => array(
array(
'name' => 'BNB',
'original_price' => 100,
'discount_price' => 80,
'discount_rate' => 80,
'contract_address' => '0xCfEB869F69431e42cdB54A4F4f105C19C080A601',
)
)
);
++$pageInfo['total'];
if ($pageInfo['total'] > $pageInfo['per_page'] * ($pageInfo['current_page'] - 1) &&
count($rows) < $pageInfo['per_page']) {
array_push($rows, $saleBox);
}
}
}
$pageInfo['count'] = count($rows);
$pageInfo['total_pages'] = ceil($pageInfo['total'] / $pageInfo['per_page']);
myself()->_rspData(array(
'rows' => $rows,
'page' => $pageInfo,
'presale_info' => $presaleInfo,
));
}
public function buyBox()
{
$type = getReqVal('type', '');
$buyer_address = getReqVal('buyer_address', '');
$price = getReqVal('price', '');
$payment_token_address = getReqVal('payment_token_address', '');
$nonce = getReqVal('nonce', '');
$signature = getReqVal('signature', '');
myself()->_rspOk();
}
public function getNftList()
{
$account = getReqVal('account', '');
$nftDbList = Nft::getNftList($accont);
$nftList = array();
foreach ($nftDbList as $nftDb) {
$nft = $this->toNftDto($nftDb);
array_push($nftList, $nft);
}
myself()->_rspData(array(
'nfts' => $nftList
));
}
public function getNftDetail()
{
$account = getReqVal('account', '');
$tokenId = getReqVal('token_id', '');
$nftDb = Nft::getNft($tokenId);
if (!$nftDb) {
myself()->_rspErr(1, 'nft not exists');
return;
}
$nft = $this->toNftDto($nftDb);
myself()->_rspData(array(
'info' => $nft
));
}
private function toNftDto($nftDb)
{
$nft = array(
'token_id' => $nftDb['tokenId'],
'owner_address' => $nftDb['owner_address'],
'owner_name' => $nftDb['owner_name'],
'item_id' => $nftDb['item_id'],
'currency_list' => array(),
'transaction_recrod' => array(),
'info' => array(
),
'mint_time' => $nftDb['createtime']
);
$heroMeta = mt\Hero::get($nftDb['item_id']);
if ($heroMeta) {
$nft['info']['name'] = $heroMeta['name'];
$nft['info']['job'] = $heroMeta['herotype'];
$nft['info']['level'] = 1;
$nft['info']['quality'] = 1;
$nft['info']['hp'] = $heroMeta['hp'];
$nft['info']['speed'] = $heroMeta['move_speed'];
$nft['info']['atk'] = $heroMeta['damage'];
$nft['info']['def'] = $heroMeta['defence'];
$nft['info']['advanced_count'] = 0;
$nft['info']['lucky'] = 0;
$nft['info']['success_rate'] = 0;
}
return $nft;
}
}