From 5a93f1ed81ab1c15df2c12cc7458cb5ab71ca4f4 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 25 Jan 2022 19:19:52 +0800 Subject: [PATCH] 1 --- doc/_common.py | 2 +- webapp/controller/MarketController.class.php | 115 ++++++++++++++++++- webapp/mt/MarketGoods.php | 20 ++++ 3 files changed, 134 insertions(+), 3 deletions(-) diff --git a/doc/_common.py b/doc/_common.py index 5e153f1b..b9d944aa 100644 --- a/doc/_common.py +++ b/doc/_common.py @@ -45,7 +45,7 @@ class SystemCurrency(object): def __init__(self): self.fields = [ ['name', '', '货币名称'], - ['original price', 0, '原价'], + ['original_price', 0, '原价'], ['discount_price', 0, '折后价'], ['discount_rate', 0, '折扣百分比(0-100)'], ['contract_address', 0, '合约地址'], diff --git a/webapp/controller/MarketController.class.php b/webapp/controller/MarketController.class.php index d920da67..a60f9653 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -15,20 +15,131 @@ class MarketController extends BaseController { public function searchBox() { - $currBatch = mt\MarketBatch::getCurrentBatch(); - myself()->_rspData($currBatch); + $page = getReqVal('page', 1); + $type = getReqVal('type', 0); + $sort = getReqVal('sort', ''); + + $currBatchMeta = mt\MarketBatch::getCurrentBatch(); + if (!$currBatchMeta) { + myself()->_rspErr(500, 'server internal error'); + return; + } + + $rows = array(); + $pageInfo = array( + 'total' => 0, + 'count' => 0, + 'per_page' => 10, + 'current_page' => $page, + 'total_pages' => 0 + ); + $presaleInfo = array( + 'batch_id' => $currBatchMeta['batch_id'], + 'countdown' => max(0, $currBatchMeta['_start_time_utc'] - myself()->_getNowTime()), + 'sold_num' => 0, + 'inventory_num' => 0, + 'hint' => $currBatchMeta['hint'], + 'buyed' => 0 + ); + + $batchMetas = mt\MarketGoods::getBatchMetas($currBatchMeta['batch_id']); + if ($batchMetas) { + foreach ($batchMetas as $meta) { + $saleBox = array( + 'box_id' => $meta['item_id'], + 'item_id' => $meta['item_id'], + 'currency_list' => array( + array( + 'name' => 'BNB', + 'original_price' => 100, + 'discount_price' => 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() { + myself()->_rspOk(); } public function getNftList() { + $account = getReqVal('account', ''); + $nftList = array(); + for ($i = 0; $i < 10; ++$i) { + $nft = array( + 'token_id' => $i + 1, + 'owner_address' => $account, + 'owner_name' => '', + 'item_id' => 30100 + $i * 100, + 'currency_list' => array(), + 'transaction_recrod' => array(), + 'info' => array( + 'name' => 'hero' . $i, + 'level' => 1, + 'quality' => 1, + 'hp' => 100, + 'speed' => 100, + 'atk' => 1, + 'def' => 100, + 'advanced_count' => 0, + 'lucky' => 0, + 'success_rate' => 0 + ), + 'mint_time' => myself()->_getNowTime() + ); + array_push($nftList, $nft); + } + myself()->_rspData(array( + 'nfts' => $nftList + )); } public function getNftDetail() { + $account = getReqVal('account', ''); + $i = 0; + $nft = array( + 'token_id' => $i + 1, + 'owner_address' => $account, + 'owner_name' => '', + 'item_id' => 30100 + $i * 100, + 'currency_list' => array(), + 'transaction_recrod' => array(), + 'info' => array( + 'name' => 'hero' . $i, + 'level' => 1, + 'quality' => 1, + 'hp' => 100, + 'speed' => 100, + 'atk' => 1, + 'def' => 100, + 'advanced_count' => 0, + 'lucky' => 0, + 'success_rate' => 0 + ), + 'mint_time' => myself()->_getNowTime() + ); + myself()->_rspData(array( + 'info' => $nft + )); } } diff --git a/webapp/mt/MarketGoods.php b/webapp/mt/MarketGoods.php index 2eadd869..d77da29c 100644 --- a/webapp/mt/MarketGoods.php +++ b/webapp/mt/MarketGoods.php @@ -21,6 +21,12 @@ class MarketGoods { } } + public static function getBatchMetas($batchId) + { + self::mustBeBatchHash(); + return getXVal(self::$batchHash, $batchId, null); + } + protected static function getMetaList() { if (!self::$metaList) { @@ -29,6 +35,20 @@ class MarketGoods { return self::$metaList; } + protected static function mustBeBatchHash() + { + if (!self::$batchHash) { + self::$batchHash = array(); + self::traverseMeta(function ($meta) { + if (!getXVal(self::$batchHash, $meta['batch_id'], null)) { + self::$batchHash[$meta['batch_id']] = array(); + } + array_push(self::$batchHash[$meta['batch_id']], $meta); + }); + } + } + protected static $metaList; + protected static $batchHash; }