This commit is contained in:
aozhiwei 2022-01-25 17:27:01 +08:00
parent af63f4e5af
commit 0811688c39
4 changed files with 97 additions and 114 deletions

View File

@ -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'],
],

View File

@ -1,6 +1,7 @@
<?php
require_once('mt/Market.php');
require_once('mt/MarketGoods.php');
require_once('mt/MarketBatch.php');
require_once('mt/Item.php');
require_once('mt/WhiteList.php');
require_once('mt/Currency.php');
@ -12,122 +13,22 @@ use models\Goods;
class MarketController extends BaseController {
public function search()
public function searchBox()
{
$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
)
));
}
$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;
}
}

80
webapp/mt/MarketBatch.php Normal file
View File

@ -0,0 +1,80 @@
<?php
namespace mt;
use phpcommon;
class MarketBatch {
public static function get($id)
{
return getXVal(self::getMetaList(), $id, null);
}
public static function traverseMeta($cb)
{
foreach (self::getMetaList() as $meta) {
$cb($meta);
}
}
public static function getCurrentBatch()
{
self::mustBeSortedList();
$currentMeta = null;
foreach (self::$sortedList as $meta) {
if (!$currentMeta) {
$currentMeta = $meta;
continue;
}
if (myself()->_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;
}

View File

@ -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;
}