From f6970a94029f599997703c4273e48b37727cde96 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 4 Apr 2022 13:19:32 +0800 Subject: [PATCH] 1 --- webapp/controller/BcShopController.class.php | 109 +++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/webapp/controller/BcShopController.class.php b/webapp/controller/BcShopController.class.php index f62a2dba..2e004c80 100644 --- a/webapp/controller/BcShopController.class.php +++ b/webapp/controller/BcShopController.class.php @@ -20,7 +20,45 @@ class BcShopController extends BaseController { public function search() { + $account = getReqVal('account', ''); + $page = getReqVal('page', 1); + $type = getReqVal('type', 0); + $sort = getReqVal('sort', ''); + $perPage = 10000; + $rows = array(); + $pageInfo = array( + 'total' => 0, + 'count' => 0, + 'per_page' => $perPage, + 'current_page' => $page, + 'total_pages' => 0 + ); + $startPos= $pageInfo['per_page'] * ($pageInfo['current_page'] - 1); + + $currBatchMeta = mt\MarketBatch::getCurrentBatch(); + if ($currBatchMeta) { + $batchMetas = mt\MarketGoods::getBatchMetas($currBatchMeta['batch_id']); + if ($batchMetas) { + foreach ($batchMetas as $meta) { + $saleBox = $this->fillPresaleBox($currBatchMeta, $meta); + if ($saleBox) { + ++$pageInfo['total']; + if ($pageInfo['total'] > $startPos && + 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, + )); } public function buy() @@ -30,7 +68,78 @@ class BcShopController extends BaseController { public function queryOrder() { + $token = getReqVal('token', ''); + $account = getReqVal('account', ''); + $orderId = getReqVal('order_id', ''); + if (!MarketService::isValidToken($account, $token)) { + myself()->_rspErr(100, 'invalid token'); + return; + } + $orderDb = BoxOrder::findByOrderId($orderId); + if ($orderDb) { + if (!$orderDb['done']) { + myself()->_rspData(array( + 'state' => 2 + )); + } else { + if ($orderDb['bc_paid'] == 1) { + myself()->_rspData(array( + 'state' => 1 + )); + } else { + myself()->_rspData(array( + 'state' => 3 + )); + } + } + } else { + myself()->_rspData(array( + 'state' => 0 + )); + } + } + + private function fillPresaleBox($batchMeta, $goodsMeta) + { + $currencyMeta = mt\Currency::get($goodsMeta['currency_id']); + if (!$currencyMeta) { + return null; + } + $boxId = phpcommon\genBoxId($batchMeta['id'], + $goodsMeta['id'], + $goodsMeta['item_id']); + + $itemMeta = mt\Item::get($goodsMeta['item_id']); + $originalPrice = $goodsMeta['price'] * pow(10, MarketService::CURRENCY_DECIMALS); + $discountPrice = $goodsMeta['discount'] * 100 > 0 ? + $originalPrice * $goodsMeta['discount'] : $originalPrice; + $name = ''; + $job = 0; + { + $heroMeta = mt\Hero::get($goodsMeta['item_id']); + if ($heroMeta) { + $name = emptyReplace($heroMeta['name'], 'Hill'); + $job = emptyReplace($heroMeta['herotype'], '1'); + } + } + $saleBox = array( + 'box_id' => $boxId, + 'item_id' => $goodsMeta['item_id'], + 'name' => $name, + 'job' => $job, + //'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' => $goodsMeta['discount'], + 'decimals' => MarketService::CURRENCY_DECIMALS, + 'contract_address' => $currencyMeta['address'], + ) + )); + return $saleBox; } }