108 lines
2.6 KiB
PHP
108 lines
2.6 KiB
PHP
<?php
|
|
|
|
require_once('mt/Market.php');
|
|
require_once('mt/Item.php');
|
|
require_once('mt/WhiteList.php');
|
|
require_once('mt/Currency.php');
|
|
|
|
require_once('models/Goods.php');
|
|
|
|
use phpcommon\SqlHelper;
|
|
use models\Goods;
|
|
|
|
class MarketController extends BaseController {
|
|
|
|
public function search()
|
|
{
|
|
$type = getReqVal('type', 0);
|
|
if ($type == mt\Market::SYS_TYPE) {
|
|
$this->searchSys();
|
|
} else {
|
|
$this->_rspData(array(
|
|
'rows' => array(),
|
|
'page' => array(
|
|
'total' => 0,
|
|
'count' => 0,
|
|
'per_page' => 10,
|
|
'current_page' => 1,
|
|
'total_pages' => 0
|
|
)
|
|
));
|
|
}
|
|
}
|
|
|
|
public function buy()
|
|
{
|
|
}
|
|
|
|
public function prebuy()
|
|
{
|
|
}
|
|
|
|
public function sell()
|
|
{
|
|
}
|
|
|
|
public function detail()
|
|
{
|
|
}
|
|
|
|
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'] = 0;
|
|
$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;
|
|
}
|
|
|
|
}
|