diff --git a/doc/Market.py b/doc/Market.py index 2fb693b8..cbcf279a 100644 --- a/doc/Market.py +++ b/doc/Market.py @@ -6,6 +6,18 @@ class Market(object): def __init__(self): self.apis = [ + { + 'name': 'getPreSaleInfo', + 'desc': '获取预售信息', + 'group': 'Market', + 'url': 'webapp/index.php?c=Market&a=getPreSaleInfo', + 'params': [ + ], + 'response': [ + _common.RspHead(), + ['presale_info', _common.PreSaleInfo(), '预售信息'], + ] + }, { 'name': 'searchBox', 'desc': '获取预售商品信息', @@ -20,7 +32,6 @@ class Market(object): _common.RspHead(), ['!rows', [_common.PreSaleBox()], '商品信息'], ['page', _common.Page(), '分页信息'], - ['presale_info', _common.PreSaleInfo(), '预售信息'], ] }, { diff --git a/webapp/controller/MarketController.class.php b/webapp/controller/MarketController.class.php index 39699099..9b124ecf 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -21,6 +21,38 @@ class MarketController extends BaseController { return isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443 && SERVER_ENV == _TEST; } + public function getPreSaleInfo() + { + $currBatchMeta = mt\MarketBatch::getCurrentBatch(); + if (!$currBatchMeta) { + myself()->_rspErr(500, 'server internal error'); + return; + } + + $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'], + 'state' => 2, + 'title' => '', + 'hint' => str_replace("\n", '\n', $currBatchMeta['hint']), + 'buyed' => $this->isTestMode() ? 0 : BoxOrder::isBuyed($account, $currBatchMeta['batch_id']) + ); + + if ($this->isTestMode()) { + foreach(array_keys($presaleInfo) as $key) { + if (!is_null(getReqVal($key, null))) { + $presaleInfo[$key] = getReqVal($key, $presaleInfo[$key]); + } + } + } + + myself()->_rspData(array( + 'presale_info' => $presaleInfo + )); + } + public function searchBox() { $account = getReqVal('account', ''); @@ -43,16 +75,6 @@ class MarketController extends BaseController { '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'], - 'state' => 2, - 'title' => '', - '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) { @@ -81,20 +103,11 @@ class MarketController extends BaseController { } } - if ($this->isTestMode()) { - foreach(array_keys($presaleInfo) as $key) { - if (!is_null(getReqVal($key, null))) { - $presaleInfo[$key] = getReqVal($key, $presaleInfo[$key]); - } - } - } - $pageInfo['count'] = count($rows); $pageInfo['total_pages'] = ceil($pageInfo['total'] / $pageInfo['per_page']); myself()->_rspData(array( 'rows' => $rows, 'page' => $pageInfo, - 'presale_info' => $presaleInfo, )); }