diff --git a/doc/Market.py b/doc/Market.py index 513fb08d..07f7b246 100644 --- a/doc/Market.py +++ b/doc/Market.py @@ -29,8 +29,12 @@ class Market(object): 'group': 'Market', 'url': 'webapp/index.php?c=Market&a=buyBox', 'params': [ - ['account', '', '账号id'], - ['box_id', '', '箱子id'], + ['type', '', '注意是箱子id!!!(box_id)'], + ['buyer_address', '', '购买者账号id'], + ['price', '', 'price'], + ['payment_token_address', '', 'payment_token_address'], + ['nonce', '', 'nonce'], + ['signature', '', '签名soliditySha3(type, payment_token_address, price, nonce), 签名的replace客户端做处理'], ], 'response': [ _common.RspHead(), @@ -40,7 +44,7 @@ class Market(object): 'name': 'getNftList', 'desc': '获取账号对应的nft列表', 'group': 'Market', - 'url': 'webapp/index.php?c=Market&a=getMyNftList', + 'url': 'webapp/index.php?c=Market&a=getNftList', 'params': [ ['account', '', '账号id'], ], diff --git a/webapp/controller/MarketController.class.php b/webapp/controller/MarketController.class.php index 963e950d..d920da67 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -1,6 +1,7 @@ searchSys(); - } else { - $this->_rspData(array( - 'rows' => array(), - 'page' => array( - 'total' => 0, - 'count' => 0, - 'per_page' => 10, - 'current_page' => 1, - 'total_pages' => 0 - ) - )); - } + $currBatch = mt\MarketBatch::getCurrentBatch(); + myself()->_rspData($currBatch); } - public function buy() + public function buyBox() { } - public function prebuy() - { - $account = getReqVal('account', ''); - $goodsId = getReqVal('goods_id', ''); - - $goodsMeta = mt\Market::get($goodsId); - if (!$goodsMeta) { - $this->_rspErr(1, 'config error'); - return; - } - $inventory = Goods::getRemainBuyableNum($meta); - if ($inventory < 0) { - $this->_rspErr(2, 'insufficient inventory'); - return; - } - $params = array( - 'account' => $account, - 'goods_id' => $goodsId, - ); - $response = ''; - $url = ''; - if (!phpcommon\HttpClient::get($url, - $params, - $response)) { - phpcommon\sendError(100, 'internal error'); - die(); - return; - } - } - - public function sell() + public function getNftList() { } - public function detail() + public function getNftDetail() { } - private function searchSys() - { - $page = getReqVal('page', 1); - $type = getReqVal('type', 0); - $sort = getReqVal('sort', ''); - - $rows = array(); - $pageInfo = array( - 'total' => 0, - 'count' => 0, - 'per_page' => 10, - 'current_page' => $page, - 'total_pages' => 0 - ); - mt\Market::traverseMeta(function ($meta) use(&$rows, &$pageInfo) { - $remainBuyableNum = Goods::getRemainBuyableNum($meta); - if ($remainBuyableNum > 0) { - ++$pageInfo['total']; - if ($pageInfo['total'] > $pageInfo['per_page'] * ($pageInfo['current_page'] - 1) && - count($rows) < $pageInfo['per_page']) { - array_push($rows, $this->wrapNft($meta, $remainBuyableNum)); - } - } - }); - - $pageInfo['count'] = count($rows); - $pageInfo['total_pages'] = ceil($pageInfo['total'] / $pageInfo['per_page']); - $this->_rspData(array( - 'rows' => $rows, - 'page' => $pageInfo - )); - } - - private function wrapNft($meta, $inventory) - { - $nft = array(); - $nft['goods_id'] = $meta['id']; - $nft['nft_id'] = ''; - $nft['type'] = 0; - $nft['token_id'] = ''; - $nft['status'] = 0; - $nft['inventory'] = $inventory; - $nft['owner_address'] = ''; - $nft['owner_id'] = ''; - $nft['image_avatar'] = ''; - $nft['image_full'] = ''; - $nft['price'] = array( - 'type' => 0, - 'name' => '', - 'value' => 0, - 'decimals' => 0 - ); - $nft['created_at'] = 0; - $nft['last_modified_at'] = 0; - return $nft; - } - } diff --git a/webapp/mt/MarketBatch.php b/webapp/mt/MarketBatch.php new file mode 100644 index 00000000..7c1395c7 --- /dev/null +++ b/webapp/mt/MarketBatch.php @@ -0,0 +1,80 @@ +_getNowTime() > $meta['_start_time_utc']) { + return $meta; + } + } + return $currentMeta; + } + + protected static function getMetaList() + { + if (!self::$metaList) { + self::$metaList = getMetaTable('batch@market.php'); + foreach (self::$metaList as &$meta) { + if (empty($meta['start_time'])) { + $meta['_start_time_utc'] = 0; + } else { + $meta['_start_time_utc'] = strtotime($meta['start_time']) - $meta['world_time_zone'] * 3600; + } + + if (empty($meta['end_time'])) { + $meta['_end_time_utc'] = 0; + } else { + $meta['_end_time_utc'] = strtotime($meta['end_time']) - $meta['world_time_zone'] * 3600; + } + } + } + return self::$metaList; + } + + protected static function mustBeSortedList() + { + if (!self::$sortedList) { + self::$sortedList = array(); + foreach (self::getMetaList() as $meta) { + array_push(self::$sortedList, $meta); + } + usort(self::$sortedList, function ($a, $b) { + if ($a['_start_time_utc'] == $b['_start_time_utc']) { + die(json_encode(array( + 'errcode' => 500, + 'errmsg' => 'server internal error' + ))); + } + return $a['_start_time_utc'] < $b['_start_time_utc']; + }); + } + } + + protected static $metaList; + protected static $sortedList; + +} diff --git a/webapp/mt/Market.php b/webapp/mt/MarketGoods.php similarity index 83% rename from webapp/mt/Market.php rename to webapp/mt/MarketGoods.php index 804000c1..2eadd869 100644 --- a/webapp/mt/Market.php +++ b/webapp/mt/MarketGoods.php @@ -7,9 +7,7 @@ require_once('mt/StrHelper.php'); use phpcommon; -class Market { - - const SYS_TYPE = 0; +class MarketGoods { public static function get($id) { @@ -26,7 +24,7 @@ class Market { protected static function getMetaList() { if (!self::$metaList) { - self::$metaList = getMetaTable('market@market.php'); + self::$metaList = getMetaTable('goods@market.php'); } return self::$metaList; }