From 22ef1be25bfc8762553699a7b583e8d1e4af4ba3 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sun, 3 Apr 2022 09:28:46 +0800 Subject: [PATCH] 1 --- webapp/controller/MarketController.class.php | 85 ++++++++++---------- webapp/services/MarketService.php | 2 + 2 files changed, 44 insertions(+), 43 deletions(-) diff --git a/webapp/controller/MarketController.class.php b/webapp/controller/MarketController.class.php index 77181cc2..6d4579a7 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -56,51 +56,21 @@ class MarketController extends BaseController { 'current_page' => $page, 'total_pages' => 0 ); + $startPos= $pageInfo['per_page'] * ($pageInfo['current_page'] - 1); $currBatchMeta = mt\MarketBatch::getCurrentBatch(); - if (!$currBatchMeta) { - myself()->_rspData(array( - 'rows' => $rows, - 'page' => $pageInfo, - )); - return; - } - - $batchMetas = mt\MarketGoods::getBatchMetas($currBatchMeta['batch_id']); - if ($batchMetas) { - foreach ($batchMetas as $meta) { - $heroMeta = mt\Hero::get($meta['item_id']); - $itemMeta = mt\Item::get($meta['item_id']); - $boxId = phpcommon\genBoxId($currBatchMeta['id'], $meta['id'], $meta['item_id']); - $currencyMeta = mt\Currency::get($meta['currency_id']); - if (!$currencyMeta) { - myself()->_rspErr(500, 'server internal error'); - return; - } - $originalPrice = $meta['price'] * pow(10, MarketService::CURRENCY_DECIMALS); - $discountPrice = $meta['discount'] * 100 > 0 ? - $originalPrice * $meta['discount'] : $originalPrice; - $saleBox = array( - 'box_id' => $boxId, - 'item_id' => $meta['item_id'], - 'name' => emptyReplace($heroMeta['name'], 'Hill'), - 'job' => emptyReplace($heroMeta['herotype'], '1'), - //'avatar_url' => 'https://www.cebg.games/res/avatars/' . $itemMeta['nft_image_id'] . '.png', - 'currency_list' => array( - array( - 'name' => $currencyMeta['name'], - 'original_price' => $originalPrice, - 'discount_price' => $discountPrice, - 'discount_rate' => $meta['discount'], - 'decimals' => MarketService::CURRENCY_DECIMALS, - 'contract_address' => $currencyMeta['address'], - ) - ) - ); - ++$pageInfo['total']; - if ($pageInfo['total'] > $pageInfo['per_page'] * ($pageInfo['current_page'] - 1) && - count($rows) < $pageInfo['per_page']) { - array_push($rows, $saleBox); + if ($currBatchMeta) { + $batchMetas = mt\MarketGoods::getBatchMetas($currBatchMeta['batch_id']); + if ($batchMetas) { + foreach ($batchMetas as $meta) { + $currencyMeta = mt\Currency::get($meta['currency_id']); + if ($currencyMeta) { + ++$pageInfo['total']; + if ($pageInfo['total'] > $startPos && + count($rows) < $pageInfo['per_page']) { + array_push($rows, $saleBox); + } + } } } } @@ -398,4 +368,33 @@ class MarketController extends BaseController { MarketService::auth($account, $tips, $nonce, $signature); } + private function fillPresaleBox() + { + $boxId = phpcommon\genBoxId($currBatchMeta['id'], + $meta['id'], + $meta['item_id']); + + $itemMeta = mt\Item::get($meta['item_id']); + $heroMeta = mt\Hero::get($meta['item_id']); + $originalPrice = $meta['price'] * pow(10, MarketService::CURRENCY_DECIMALS); + $discountPrice = $meta['discount'] * 100 > 0 ? + $originalPrice * $meta['discount'] : $originalPrice; + $saleBox = array( + 'box_id' => $boxId, + 'item_id' => $meta['item_id'], + 'name' => emptyReplace($heroMeta['name'], 'Hill'), + 'job' => emptyReplace($heroMeta['herotype'], '1'), + //'avatar_url' => 'https://www.cebg.games/res/avatars/' . $itemMeta['nft_image_id'] . '.png', + 'currency_list' => array( + array( + 'name' => $currencyMeta['name'], + 'original_price' => $originalPrice, + 'discount_price' => $discountPrice, + 'discount_rate' => $meta['discount'], + 'decimals' => MarketService::CURRENCY_DECIMALS, + 'contract_address' => $currencyMeta['address'], + ) + )); + } + } diff --git a/webapp/services/MarketService.php b/webapp/services/MarketService.php index 6f4adc52..8c6483c1 100644 --- a/webapp/services/MarketService.php +++ b/webapp/services/MarketService.php @@ -258,4 +258,6 @@ class MarketService extends BaseService { return str_replace("\n", '\n', $str); } + + }