Merge branch 'star' of git.kingsome.cn:server/game2006api into star
This commit is contained in:
commit
a91c844117
@ -403,6 +403,27 @@ class Market(object):
|
||||
_common.RspHead()
|
||||
]
|
||||
},
|
||||
{
|
||||
'name': 'sell',
|
||||
'desc': '出售NFT',
|
||||
'group': 'Market',
|
||||
'url': 'webapp/index.php?c=Market&a=sell',
|
||||
'params': [
|
||||
['account', '', '账号id'],
|
||||
['token', '', 'token'],
|
||||
['nft_token', '', 'nft_token'],
|
||||
['item_id', '', '道具id,'],
|
||||
['s_price', '', '出售价格USDT'],
|
||||
['amount', 0, '出售数量'],
|
||||
['payment_token_address', '', 'payment_token_address'],
|
||||
['nonce', '', 'nonce'],
|
||||
['signature', '', '签名soliditySha3(type, payment_token_address, price, nonce), 签名的replace客户端做处理'],
|
||||
['net_id', '', '网络id'],
|
||||
],
|
||||
'response': [
|
||||
_common.RspHead()
|
||||
]
|
||||
},
|
||||
{
|
||||
'name': 'buyNft',
|
||||
'desc': '购买NFT',
|
||||
|
@ -187,7 +187,8 @@ class Shop(object):
|
||||
'response': [
|
||||
_common.RspHead(),
|
||||
['idx', 0, '每日精选的索引'],
|
||||
['cost', 0, '每日精选的当前刷新价格'],
|
||||
['refresh_info', '', '每日精选的刷新信息(格式:刷新次数/可刷新总数)'],
|
||||
['cost', 0, '每日精选的当前刷新价格,-1表示不可刷新'],
|
||||
['!goods_list', [_common.DailySelectionGoods()], '每日精选列表'],
|
||||
]
|
||||
},
|
||||
|
@ -86,6 +86,9 @@ class BaseAuthedController extends BaseController {
|
||||
}
|
||||
$r = $this->_getRedis($this->_getAccountId());
|
||||
$sessionId = $r->get(LAST_SESSION_KEY . $this->_getAccountId());
|
||||
// error_log('SERVER_ENV:' . SERVER_ENV . '_DEBUG:' . _DEBUG);
|
||||
if (SERVER_ENV != _DEBUG)
|
||||
{
|
||||
if (empty($sessionId)) {
|
||||
$this->updateSession(myself()->_getAccountId(),
|
||||
myself()->_getSessionId());
|
||||
@ -96,6 +99,7 @@ class BaseAuthedController extends BaseController {
|
||||
phpcommon\sendError(1001, 'session expiration');
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
$this->_userLvRestriction();
|
||||
}
|
||||
|
@ -35,14 +35,15 @@ use services\MarketService;
|
||||
use services\LuckyBoxService;
|
||||
use services\ActivateNftService;
|
||||
|
||||
class MarketController extends BaseController {
|
||||
class MarketController extends BaseController
|
||||
{
|
||||
|
||||
public function getPreSaleInfo()
|
||||
{
|
||||
$account = strtolower(getReqVal('account', ''));
|
||||
$presaleInfo = MarketService::getPreSaleInfo($account);
|
||||
if (MarketService::isTestMode()) {
|
||||
foreach(array_keys($presaleInfo) as $key) {
|
||||
foreach (array_keys($presaleInfo) as $key) {
|
||||
if (!is_null(getReqVal($key, null))) {
|
||||
$presaleInfo[$key] = getReqVal($key, $presaleInfo[$key]);
|
||||
}
|
||||
@ -69,7 +70,7 @@ class MarketController extends BaseController {
|
||||
'current_page' => $page,
|
||||
'total_pages' => 0
|
||||
);
|
||||
$startPos= $pageInfo['per_page'] * ($pageInfo['current_page'] - 1);
|
||||
$startPos = $pageInfo['per_page'] * ($pageInfo['current_page'] - 1);
|
||||
|
||||
$currBatchMeta = mt\MarketBatch::getCurrentBatch();
|
||||
if ($currBatchMeta) {
|
||||
@ -79,8 +80,10 @@ class MarketController extends BaseController {
|
||||
$saleBox = $this->fillPresaleBox($currBatchMeta, $meta);
|
||||
if ($saleBox) {
|
||||
++$pageInfo['total'];
|
||||
if ($pageInfo['total'] > $startPos &&
|
||||
count($rows) < $pageInfo['per_page']) {
|
||||
if (
|
||||
$pageInfo['total'] > $startPos &&
|
||||
count($rows) < $pageInfo['per_page']
|
||||
) {
|
||||
array_push($rows, $saleBox);
|
||||
}
|
||||
}
|
||||
@ -119,7 +122,8 @@ class MarketController extends BaseController {
|
||||
$paymentTokenAddress,
|
||||
$price,
|
||||
$nonce,
|
||||
$signature);
|
||||
$signature
|
||||
);
|
||||
|
||||
$batchIdx = 0;
|
||||
$idx = 0;
|
||||
@ -129,12 +133,14 @@ class MarketController extends BaseController {
|
||||
return;
|
||||
}
|
||||
|
||||
if (empty($type) ||
|
||||
if (
|
||||
empty($type) ||
|
||||
empty($buyerAddress) ||
|
||||
empty($price) ||
|
||||
empty($paymentTokenAddress) ||
|
||||
empty($signature) ||
|
||||
empty($nonce)) {
|
||||
empty($nonce)
|
||||
) {
|
||||
myself()->_rspErr(2, 'parameter error');
|
||||
return;
|
||||
}
|
||||
@ -192,15 +198,19 @@ class MarketController extends BaseController {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!MarketService::isTestMode() &&
|
||||
BoxOrder::isBuyed($buyerAddress, $currBatchMeta['id'])) {
|
||||
if (
|
||||
!MarketService::isTestMode() &&
|
||||
BoxOrder::isBuyed($buyerAddress, $currBatchMeta['id'])
|
||||
) {
|
||||
myself()->_rspErr(1, 'account can only choose 1 hero to purchase');
|
||||
return;
|
||||
}
|
||||
$orderId = BuyRecord::genOrderId($gameId,
|
||||
$orderId = BuyRecord::genOrderId(
|
||||
$gameId,
|
||||
$funcId,
|
||||
myself()->_getNowTime(),
|
||||
$buyerAddress);
|
||||
$buyerAddress
|
||||
);
|
||||
|
||||
$fieldsKv = array(
|
||||
'game_id' => $gameId,
|
||||
@ -317,7 +327,7 @@ class MarketController extends BaseController {
|
||||
),
|
||||
)
|
||||
),
|
||||
'handle' => function ($row) use(&$nftDbList) {
|
||||
'handle' => function ($row) use (&$nftDbList) {
|
||||
#error_log(json_encode($row));
|
||||
array_push($nftDbList, $row);
|
||||
}
|
||||
@ -385,7 +395,7 @@ class MarketController extends BaseController {
|
||||
public function auth()
|
||||
{
|
||||
$account = strtolower(getReqVal('account', ''));
|
||||
$tips = getReqVal('tips', '') ;
|
||||
$tips = getReqVal('tips', '');
|
||||
$nonce = getReqVal('nonce', '');
|
||||
$signature = getReqVal('signature', '');
|
||||
MarketService::auth($account, $tips, $nonce, $signature);
|
||||
@ -397,17 +407,18 @@ class MarketController extends BaseController {
|
||||
if (!$currencyMeta) {
|
||||
return null;
|
||||
}
|
||||
$boxId = phpcommon\genBoxId($batchMeta['id'],
|
||||
$boxId = phpcommon\genBoxId(
|
||||
$batchMeta['id'],
|
||||
$goodsMeta['id'],
|
||||
$goodsMeta['item_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;
|
||||
{
|
||||
$job = 0; {
|
||||
$heroMeta = mt\Hero::get($goodsMeta['item_id']);
|
||||
if ($heroMeta) {
|
||||
$name = emptyReplace($heroMeta['name'], 'Hill');
|
||||
@ -429,7 +440,8 @@ class MarketController extends BaseController {
|
||||
'decimals' => MarketService::CURRENCY_DECIMALS,
|
||||
'contract_address' => $currencyMeta['address'],
|
||||
)
|
||||
));
|
||||
)
|
||||
);
|
||||
return $saleBox;
|
||||
}
|
||||
|
||||
@ -547,22 +559,22 @@ class MarketController extends BaseController {
|
||||
$sortByLevel = function ($a, $b) use ($order_asc) {
|
||||
return ($order_asc == 1 ? 1 : -1) * ($b['detail']['hero_lv'] - $a['detail']['hero_lv']);
|
||||
};
|
||||
$sortByGunLv = function ($a, $b) use($order_asc) {
|
||||
$sortByGunLv = function ($a, $b) use ($order_asc) {
|
||||
return ($order_asc == 1 ? 1 : -1) * ($b['detail']['gun_lv'] - $a['detail']['gun_lv']);
|
||||
};
|
||||
$sortByTili = function ($a, $b) use($order_asc) {
|
||||
$sortByTili = function ($a, $b) use ($order_asc) {
|
||||
return ($order_asc == 1 ? 1 : -1) * ($b['detail']['hero_tili'] - $a['detail']['hero_tili']);
|
||||
};
|
||||
$sortByStar = function ($a, $b) use($order_asc) {
|
||||
$sortByStar = function ($a, $b) use ($order_asc) {
|
||||
return ($order_asc == 1 ? 1 : -1) * ($b['detail']['quality'] - $a['detail']['quality']);
|
||||
};
|
||||
$sortByDurability = function ($a, $b) use($order_asc) {
|
||||
$sortByDurability = function ($a, $b) use ($order_asc) {
|
||||
return ($order_asc == 1 ? 1 : -1) * ($b['detail']['durability_max'] - $a['detail']['durability_max']);
|
||||
};
|
||||
$sortByPower = function ($a, $b) use($order_asc) {
|
||||
$sortByPower = function ($a, $b) use ($order_asc) {
|
||||
return ($order_asc == 1 ? 1 : -1) * ($b['detail']['strength'] - $a['detail']['strength']);
|
||||
};
|
||||
$sortByGrade = function ($a, $b) use($order_asc) {
|
||||
$sortByGrade = function ($a, $b) use ($order_asc) {
|
||||
return ($order_asc == 1 ? 1 : -1) * ($b['detail']['chip_grade'] - $a['detail']['chip_grade']);
|
||||
};
|
||||
$sortByTokenId = function ($a, $b) use ($order_asc) {
|
||||
@ -570,6 +582,40 @@ class MarketController extends BaseController {
|
||||
};
|
||||
$nfts = array();
|
||||
switch ($type) {
|
||||
case Nft::NONE_TYPE: {
|
||||
$rows = Nft::getNftListByType($account, $type);
|
||||
$rows = array_merge($rows, $this->listMySelledNfts($account, $type));
|
||||
foreach ($rows as &$row) {
|
||||
$nftDb = Nft::findNftByOwner($account, $row['token_id']);
|
||||
if (empty($nftDb)) {
|
||||
$nftDb = Nft::getNft($row['token_id']);
|
||||
}
|
||||
$row['info'] = Nft::toDto($nftDb);
|
||||
// $row['detail'] = Hero::toDtoInfo(Hero::findByTokenId2($row['token_id']));
|
||||
// if (in_array($row['info']['info']['job'], $job) == false) continue;
|
||||
// if ($row['detail']['hero_lv'] < $lv) continue;
|
||||
// if ($row['detail']['quality'] < $quality) continue;
|
||||
// if ($row['detail']['hero_tili'] < $durability) continue;
|
||||
if (count($search) > 0) {
|
||||
$searchLower = array_map('strtolower', $search);
|
||||
if (!(in_array(strtolower($row['detail']['hero_name']), $searchLower) || in_array(strtolower($row['detail']['token_id']), $searchLower))) continue;
|
||||
}
|
||||
// $row['detail'] = $this->appendChipsInfo($row['detail']);
|
||||
array_push($nfts, $row);
|
||||
}
|
||||
switch ($order_method) {
|
||||
case 1:
|
||||
usort($nfts, $sortByLevel);
|
||||
break;
|
||||
case 2:
|
||||
usort($nfts, $sortByTili);
|
||||
break;
|
||||
case 3:
|
||||
usort($nfts, $sortByStar);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Nft::HERO_TYPE: {
|
||||
$rows = Nft::getNftListByType($account, $type);
|
||||
$rows = array_merge($rows, $this->listMySelledNfts($account, $type));
|
||||
@ -580,11 +626,11 @@ class MarketController extends BaseController {
|
||||
}
|
||||
$row['info'] = Nft::toDto($nftDb);
|
||||
$row['detail'] = Hero::toDtoInfo(Hero::findByTokenId2($row['token_id']));
|
||||
if (in_array($row['info']['info']['job'], $job)==false) continue;
|
||||
if ($row['detail']['hero_lv']<$lv) continue;
|
||||
if ($row['detail']['quality']<$quality) continue;
|
||||
if ($row['detail']['hero_tili']<$durability) continue;
|
||||
if (count($search)>0) {
|
||||
if (in_array($row['info']['info']['job'], $job) == false) continue;
|
||||
if ($row['detail']['hero_lv'] < $lv) continue;
|
||||
if ($row['detail']['quality'] < $quality) continue;
|
||||
if ($row['detail']['hero_tili'] < $durability) continue;
|
||||
if (count($search) > 0) {
|
||||
$searchLower = array_map('strtolower', $search);
|
||||
if (!(in_array(strtolower($row['detail']['hero_name']), $searchLower) || in_array(strtolower($row['detail']['token_id']), $searchLower))) continue;
|
||||
}
|
||||
@ -614,10 +660,10 @@ class MarketController extends BaseController {
|
||||
}
|
||||
$row['info'] = Nft::toDto($nftDb);
|
||||
$row['detail'] = Gun::toDtoInfo(Gun::findByTokenId2($row['token_id']));
|
||||
if ($row['detail']['gun_lv']<$lv) continue;
|
||||
if ($row['detail']['quality']<$quality) continue;
|
||||
if ($row['detail']['durability']<$durability) continue;
|
||||
if (count($search)>0) {
|
||||
if ($row['detail']['gun_lv'] < $lv) continue;
|
||||
if ($row['detail']['quality'] < $quality) continue;
|
||||
if ($row['detail']['durability'] < $durability) continue;
|
||||
if (count($search) > 0) {
|
||||
$searchLower = array_map('strtolower', $search);
|
||||
if (!(in_array(strtolower($row['detail']['gun_name']), $searchLower) || in_array(strtolower($row['detail']['token_id']), $searchLower))) continue;
|
||||
}
|
||||
@ -644,8 +690,8 @@ class MarketController extends BaseController {
|
||||
$row['detail'] = Chip::toDto(Chip::getChipByTokenId($row['token_id']));
|
||||
if (!in_array($row['detail']['chip_type'], $job))
|
||||
continue;
|
||||
if ($row['detail']['chip_grade']<$lv) continue;
|
||||
if (count($search)>0) {
|
||||
if ($row['detail']['chip_grade'] < $lv) continue;
|
||||
if (count($search) > 0) {
|
||||
$searchLower = array_map('strtolower', $search);
|
||||
if (!(in_array(strtolower($row['detail']['chip_name']), $searchLower) || in_array(strtolower($row['detail']['token_id']), $searchLower))) continue;
|
||||
}
|
||||
@ -672,7 +718,7 @@ class MarketController extends BaseController {
|
||||
$row['detail'] = $this->getNftGameData($nftDb);
|
||||
if (!in_array($row['detail']['type'], $job))
|
||||
continue;
|
||||
if (count($search)>0) {
|
||||
if (count($search) > 0) {
|
||||
$searchLower = array_map('strtolower', $search);
|
||||
if (!(in_array(strtolower($row['detail']['name']), $searchLower) || in_array(strtolower($row['detail']['token_id']), $searchLower))) continue;
|
||||
}
|
||||
@ -682,7 +728,6 @@ class MarketController extends BaseController {
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
|
||||
}
|
||||
}
|
||||
return $nfts;
|
||||
@ -710,19 +755,19 @@ class MarketController extends BaseController {
|
||||
$job_filter_fn = function ($f) {
|
||||
$str = '';
|
||||
$arr = array();
|
||||
foreach($f as $v) {
|
||||
foreach ($f as $v) {
|
||||
if (!empty($v)) {
|
||||
array_push($arr, 'c_job=\'' . $v . '\' ');
|
||||
}
|
||||
}
|
||||
if (count($arr)>0) {
|
||||
if (count($arr) > 0) {
|
||||
$str = implode('OR ', $arr);
|
||||
$str = 'AND (' . $str . ') ';
|
||||
}
|
||||
return $str;
|
||||
};
|
||||
$price_filter_fn = function ($f) {
|
||||
if (count($f)==2) {
|
||||
if (count($f) == 2) {
|
||||
$low = $f[0];
|
||||
$top = $f[1];
|
||||
return 'AND s_price>=' . $low . ' AND s_price<=' . $top . ' ';
|
||||
@ -731,25 +776,25 @@ class MarketController extends BaseController {
|
||||
};
|
||||
$lv_filter_fn = function ($f) {
|
||||
$f = (int) $f;
|
||||
return 'AND c_lv>=' . $f. ' ';
|
||||
return 'AND c_lv>=' . $f . ' ';
|
||||
};
|
||||
$quality_filter_fn = function ($f) {
|
||||
$f = (int) $f;
|
||||
return 'AND c_quality>=' . $f. ' ';
|
||||
return 'AND c_quality>=' . $f . ' ';
|
||||
};
|
||||
$durability_filter_fn = function ($f) {
|
||||
$f = (int) $f;
|
||||
return 'AND c_durability>=' . $f. ' ';
|
||||
return 'AND c_durability>=' . $f . ' ';
|
||||
};
|
||||
$search_filter_fn = function ($f) {
|
||||
$str = '';
|
||||
$arr_options = array();
|
||||
foreach($f as $v) {
|
||||
foreach ($f as $v) {
|
||||
if (!empty($v)) {
|
||||
array_push($arr_options,'c_name=\'' . $v . '\' OR token_id=\'' . $v. '\' ');
|
||||
array_push($arr_options, 'c_name=\'' . $v . '\' OR token_id=\'' . $v . '\' ');
|
||||
}
|
||||
}
|
||||
if (count($arr_options)>0) {
|
||||
if (count($arr_options) > 0) {
|
||||
$str = implode('OR ', $arr_options);
|
||||
$str = 'AND (' . $str . ') ';
|
||||
}
|
||||
@ -783,14 +828,14 @@ class MarketController extends BaseController {
|
||||
$conn = myself()->_getMarketMysql('');
|
||||
|
||||
$counts = $conn->execQuery(
|
||||
'SELECT count(*) as count FROM t_market_store '.
|
||||
'WHERE token_type=:token_type AND status=0 '.
|
||||
$job_filter_fn($job_filter_array).
|
||||
$lv_filter_fn($lv_filter).
|
||||
$quality_filter_fn($quality_filter).
|
||||
$durability_filter_fn($durability_filter).
|
||||
$price_filter_fn($price_filter_array).
|
||||
$search_filter_fn($search_filter_array).
|
||||
'SELECT count(*) as count FROM t_market_store ' .
|
||||
'WHERE token_type=:token_type AND status=0 ' .
|
||||
$job_filter_fn($job_filter_array) .
|
||||
$lv_filter_fn($lv_filter) .
|
||||
$quality_filter_fn($quality_filter) .
|
||||
$durability_filter_fn($durability_filter) .
|
||||
$price_filter_fn($price_filter_array) .
|
||||
$search_filter_fn($search_filter_array) .
|
||||
$order_fn($order_method, $order_asc),
|
||||
array(
|
||||
':token_type' => $type,
|
||||
@ -801,22 +846,22 @@ class MarketController extends BaseController {
|
||||
$page_end = $start + $page_size;
|
||||
if ($page_end > $total) {
|
||||
$page_end = $total;
|
||||
$start = $total-1;
|
||||
$start = $total - 1;
|
||||
$start = intval($start / $page_size) * $page_size;
|
||||
if ($start<0) $start = 0;
|
||||
if ($start < 0) $start = 0;
|
||||
}
|
||||
|
||||
$rows = $conn->execQuery(
|
||||
'SELECT * FROM t_market_store '.
|
||||
'WHERE token_type=:token_type AND status=0 '.
|
||||
$job_filter_fn($job_filter_array).
|
||||
$lv_filter_fn($lv_filter).
|
||||
$quality_filter_fn($quality_filter).
|
||||
$durability_filter_fn($durability_filter).
|
||||
$price_filter_fn($price_filter_array).
|
||||
$search_filter_fn($search_filter_array).
|
||||
$order_fn($order_method, $order_asc).
|
||||
'LIMIT '.$start.','.$page_size,
|
||||
'SELECT * FROM t_market_store ' .
|
||||
'WHERE token_type=:token_type AND status=0 ' .
|
||||
$job_filter_fn($job_filter_array) .
|
||||
$lv_filter_fn($lv_filter) .
|
||||
$quality_filter_fn($quality_filter) .
|
||||
$durability_filter_fn($durability_filter) .
|
||||
$price_filter_fn($price_filter_array) .
|
||||
$search_filter_fn($search_filter_array) .
|
||||
$order_fn($order_method, $order_asc) .
|
||||
'LIMIT ' . $start . ',' . $page_size,
|
||||
array(
|
||||
':token_type' => $type,
|
||||
)
|
||||
@ -825,7 +870,7 @@ class MarketController extends BaseController {
|
||||
$nfts = array();
|
||||
|
||||
for ($x = $start; $x < $page_end; $x++) {
|
||||
$row = $rows[$x%$page_size];
|
||||
$row = $rows[$x % $page_size];
|
||||
$nftDb = Nft::getNft($row['token_id']);
|
||||
if (!$nftDb) {
|
||||
$nftDb = Nft::findNftByOwner($account, $row['token_id']);
|
||||
@ -833,11 +878,14 @@ class MarketController extends BaseController {
|
||||
if (!$nftDb) {
|
||||
$nftDb = Nft::findNftByOwner('0xfc628dd79137395f3c9744e33b1c5de554d94882', $row['token_id']);
|
||||
if (!$nftDb) {
|
||||
if ($row['item_id']) {
|
||||
} else {
|
||||
myself()->_rspErr(1, 'nft not exists');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$nft = Nft::toDto($nftDb);
|
||||
$row['info'] = $nft;
|
||||
$row['detail'] = $this->getNftGameData($nftDb);
|
||||
@ -864,7 +912,7 @@ class MarketController extends BaseController {
|
||||
$job_filters = getReqVal('job_filters', '');
|
||||
$job_filter_array = explode('|', $job_filters);
|
||||
$search_filters = getReqVal('search_filters', '');
|
||||
if ($search_filters!='') {
|
||||
if ($search_filters != '') {
|
||||
$search_filter_array = explode('|', $search_filters);
|
||||
} else {
|
||||
$search_filter_array = array();
|
||||
@ -880,9 +928,9 @@ class MarketController extends BaseController {
|
||||
$page_end = $start + $page_size;
|
||||
if ($page_end > $total) {
|
||||
$page_end = $total;
|
||||
$start = $total-1;
|
||||
$start = $total - 1;
|
||||
$start = intval($start / $page_size) * $page_size;
|
||||
if ($start<0) $start = 0;
|
||||
if ($start < 0) $start = 0;
|
||||
}
|
||||
|
||||
$nfts = array();
|
||||
@ -900,49 +948,95 @@ class MarketController extends BaseController {
|
||||
));
|
||||
}
|
||||
|
||||
public function sell() {
|
||||
public function sell()
|
||||
{
|
||||
$self = myself();
|
||||
if (!$self) {
|
||||
$this->_rspErr(500, 'internal error, no self');
|
||||
return;
|
||||
}
|
||||
|
||||
$account = strtolower(getReqVal('account', ''));
|
||||
$item_id = getReqVal('item_id', '');
|
||||
$token = getReqVal('token', '');
|
||||
|
||||
$nft_token = getReqVal('nft_token', '');
|
||||
$item_id = getReqVal('item_id', '');
|
||||
|
||||
$s_price = getReqVal('s_price', '');
|
||||
$amount = getReqVal('amount', 1);
|
||||
|
||||
$payment_token_address = getReqVal('payment_token_address', '');
|
||||
$nonce = getReqVal('nonce', '');
|
||||
$signature = getReqVal('signature', '');
|
||||
$net_id = getReqVal('net_id', '');
|
||||
|
||||
$conn = myself()->_getMysql('');
|
||||
$conn = $self->_getMarketMysql('');
|
||||
|
||||
$nftDb = null;
|
||||
|
||||
$c_name = null;
|
||||
$c_job = null;
|
||||
$c_lv = null;
|
||||
$c_quality = null;
|
||||
$c_durability = null;
|
||||
$c_type = null;
|
||||
$c_id = null;
|
||||
|
||||
if ($nft_token) {
|
||||
$nftDb = Nft::findNftByOwner($account, $nft_token);
|
||||
$nftDetail = Nft::toDto($nftDb);
|
||||
$detail = $this->getNftGameData($nftDb);
|
||||
$c_name = $nftDetail['info']['name'];
|
||||
$c_job = isset($nftDetail['info']['job']) ? $nftDetail['info']['job']
|
||||
: (isset($detail['chip_type']) ? $detail['chip_type']
|
||||
: (isset($detail['type']) ? $detail['type']
|
||||
: 0));
|
||||
$c_lv = @$detail['gun_lv'] | @$detail['hero_lv'] | @$detail['chip_grade'];
|
||||
$c_quality = isset($nftDetail['info']['quality']) ? $nftDetail['info']['quality'] : 0;
|
||||
$c_durability = isset($nftDetail['info']['durability']) ? $nftDetail['info']['durability'] : (isset($detail['hero_tili']) ? $detail['hero_tili'] : 0);
|
||||
$c_type = isset($detail['type']) ? $detail['type'] : 0;
|
||||
$c_id = $nftDetail['item_id'];
|
||||
} else {
|
||||
if (!$this->decItems($account, $item_id, $amount)) {
|
||||
$this->_rspErr(1, 'item not enough, item_id:' . $item_id);
|
||||
return;
|
||||
}
|
||||
$itemMeta = mt\Item::get($item_id);
|
||||
$c_name = $itemMeta['name'];
|
||||
$c_job = 0;
|
||||
$c_lv = 0;
|
||||
$c_quality = $itemMeta['quality'];
|
||||
$c_durability = 0;
|
||||
$c_type = 0;
|
||||
$c_id = $item_id;
|
||||
}
|
||||
|
||||
$r = SqlHelper::insert(
|
||||
$conn,
|
||||
't_market_store',
|
||||
array(
|
||||
'token_id' => $nft_token,
|
||||
'token_type' => $nftDetail['type'],
|
||||
'owner' => $account,
|
||||
'price' => $s_price,
|
||||
'item_id' => $item_id,
|
||||
'owner_address' => $account,
|
||||
'token_type' => 0,
|
||||
'amount' => $amount,
|
||||
'payment_token_address' => $payment_token_address,
|
||||
'status' => 0,
|
||||
'create_time' => time(),
|
||||
'update_time' => time(),
|
||||
'createtime' => $self->_getNowTime(),
|
||||
'modifytime' => $self->_getNowTime(),
|
||||
's_price' => $s_price,
|
||||
'c_name' => $c_name,
|
||||
'c_job' => $c_job,
|
||||
'c_lv' => $c_lv,
|
||||
'c_quality' => $c_quality,
|
||||
'c_durability' => $c_durability,
|
||||
'c_type' => $c_type,
|
||||
'c_id' => $c_id,
|
||||
)
|
||||
);
|
||||
if (!$r) {
|
||||
myself()->_rspErr(1, 'insert error');
|
||||
return;
|
||||
}
|
||||
$this->_rspData(array(
|
||||
'nft' => $nftDetail,
|
||||
'detail' => $detail,
|
||||
));
|
||||
$this->_rspOk();
|
||||
}
|
||||
|
||||
public function sellMyNft() {
|
||||
private function sellMyNft()
|
||||
{
|
||||
|
||||
$account = strtolower(getReqVal('account', ''));
|
||||
$token = getReqVal('token', '');
|
||||
@ -954,7 +1048,7 @@ class MarketController extends BaseController {
|
||||
$signature = getReqVal('signature', '');
|
||||
$net_id = getReqVal('net_id', '');
|
||||
|
||||
$conn = myself()->_getMysql('');
|
||||
$conn = myself()->_getMarketMysql('');
|
||||
|
||||
$nftDb = Nft::findNftByOwner($account, $nft_token);
|
||||
$nftDetail = Nft::toDto($nftDb);
|
||||
@ -973,8 +1067,8 @@ class MarketController extends BaseController {
|
||||
'c_name' => $nftDetail['info']['name'],
|
||||
'c_job' => isset($nftDetail['info']['job']) ? $nftDetail['info']['job']
|
||||
: (isset($detail['chip_type']) ? $detail['chip_type']
|
||||
: (isset($detail['type'])?$detail['type']
|
||||
:0)),
|
||||
: (isset($detail['type']) ? $detail['type']
|
||||
: 0)),
|
||||
'c_lv' => @$detail['gun_lv'] | @$detail['hero_lv'] | @$detail['chip_grade'],
|
||||
'c_quality' => isset($nftDetail['info']['quality']) ? $nftDetail['info']['quality'] : 0,
|
||||
'c_durability' => isset($nftDetail['info']['durability']) ? $nftDetail['info']['durability'] : (isset($detail['hero_tili']) ? $detail['hero_tili'] : 0),
|
||||
@ -985,7 +1079,8 @@ class MarketController extends BaseController {
|
||||
$this->_rspOk();
|
||||
}
|
||||
|
||||
public function buyNft() {
|
||||
public function buyNft()
|
||||
{
|
||||
$account = strtolower(getReqVal('account', ''));
|
||||
$token = getReqVal('token', '');
|
||||
$nft_token = getReqVal('nft_token', '');
|
||||
@ -995,12 +1090,13 @@ class MarketController extends BaseController {
|
||||
$net_id = getReqVal('net_id', '');
|
||||
|
||||
$conn = myself()->_getMarketMysql('');
|
||||
$conn->execScript('DELETE FROM t_market_store WHERE '.'token_id=\''.$nft_token.'\'');
|
||||
$conn->execScript('DELETE FROM t_market_store WHERE ' . 'token_id=\'' . $nft_token . '\'');
|
||||
|
||||
$this->_rspOk();
|
||||
}
|
||||
|
||||
public function getSupportedCurrencyTypes() {
|
||||
public function getSupportedCurrencyTypes()
|
||||
{
|
||||
$types = array();
|
||||
if (SERVER_ENV == _ONLINE) {
|
||||
array_push($types, array(
|
||||
@ -1018,27 +1114,27 @@ class MarketController extends BaseController {
|
||||
));
|
||||
}
|
||||
|
||||
public function getTransactionRecord() {
|
||||
public function getTransactionRecord()
|
||||
{
|
||||
$account = strtolower(getReqVal('account', ''));
|
||||
$type = getReqVal('type', 0);
|
||||
$start = getReqVal('start', 0);
|
||||
$page_size = getReqVal('page_size', 10);
|
||||
|
||||
$conn = myself()->_getMysql('');
|
||||
$conn = myself()->_getMarketMysql('');
|
||||
|
||||
$type_filter_fn = function ($f) {
|
||||
if ($f==0) {
|
||||
if ($f == 0) {
|
||||
return '';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 'AND type=' . $f;
|
||||
}
|
||||
};
|
||||
|
||||
$counts = $conn->execQuery(
|
||||
'SELECT count(*) as count FROM t_market_transaction_record '.
|
||||
'WHERE (seller=:account OR buyer=:account) '.
|
||||
$type_filter_fn($type).
|
||||
'SELECT count(*) as count FROM t_market_transaction_record ' .
|
||||
'WHERE (seller=:account OR buyer=:account) ' .
|
||||
$type_filter_fn($type) .
|
||||
' ORDER BY createtime DESC',
|
||||
array(
|
||||
':account' => $account,
|
||||
@ -1049,17 +1145,17 @@ class MarketController extends BaseController {
|
||||
$page_end = $start + $page_size;
|
||||
if ($page_end > $total) {
|
||||
$page_end = $total;
|
||||
$start = $total-1;
|
||||
$start = $total - 1;
|
||||
$start = intval($start / $page_size) * $page_size;
|
||||
if ($start<0) $start = 0;
|
||||
if ($start < 0) $start = 0;
|
||||
}
|
||||
|
||||
$rows = $conn->execQuery(
|
||||
'SELECT * FROM t_market_transaction_record '.
|
||||
'WHERE (seller=:account OR buyer=:account) '.
|
||||
$type_filter_fn($type).
|
||||
' ORDER BY createtime DESC '.
|
||||
'LIMIT '.$start.','.$page_size,
|
||||
'SELECT * FROM t_market_transaction_record ' .
|
||||
'WHERE (seller=:account OR buyer=:account) ' .
|
||||
$type_filter_fn($type) .
|
||||
' ORDER BY createtime DESC ' .
|
||||
'LIMIT ' . $start . ',' . $page_size,
|
||||
array(
|
||||
':account' => $account,
|
||||
)
|
||||
@ -1073,8 +1169,9 @@ class MarketController extends BaseController {
|
||||
));
|
||||
}
|
||||
|
||||
private function addTransactionRecord($record) {
|
||||
$conn = myself()->_getMysql('');
|
||||
private function addTransactionRecord($record)
|
||||
{
|
||||
$conn = myself()->_getMarketMysql('');
|
||||
|
||||
$r = SqlHelper::insert(
|
||||
$conn,
|
||||
@ -1082,11 +1179,12 @@ class MarketController extends BaseController {
|
||||
$record
|
||||
);
|
||||
if (!$r) {
|
||||
$this->_rspErr(2, 'unknown error, orderId='.$record['orderid']);
|
||||
$this->_rspErr(2, 'unknown error, orderId=' . $record['orderid']);
|
||||
}
|
||||
}
|
||||
|
||||
public function eventSellOrder() {
|
||||
public function eventSellOrder()
|
||||
{
|
||||
$tokenId = getReqVal('tokenId', '');
|
||||
$owner = strtolower(getReqVal('owner', ''));
|
||||
$nftToken = getReqVal('nftToken', '');
|
||||
@ -1095,7 +1193,8 @@ class MarketController extends BaseController {
|
||||
$currency = getReqVal('currency', '');
|
||||
$price = getReqVal('price', '');
|
||||
|
||||
error_log("eventSellOrder:" . json_encode(
|
||||
error_log(
|
||||
"eventSellOrder:" . json_encode(
|
||||
array(
|
||||
'tokenId' => $tokenId,
|
||||
'owner' => $owner,
|
||||
@ -1114,7 +1213,7 @@ class MarketController extends BaseController {
|
||||
// 1. check order status
|
||||
$chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId));
|
||||
if (!empty($chk)) {
|
||||
$this->_rspErr(1, 'repeat sell order, orderId='.$orderId);
|
||||
$this->_rspErr(1, 'repeat sell order, orderId=' . $orderId);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1143,8 +1242,8 @@ class MarketController extends BaseController {
|
||||
'c_name' => $nftDetail['info']['name'],
|
||||
'c_job' => isset($nftDetail['info']['job']) ? $nftDetail['info']['job']
|
||||
: (isset($detail['chip_type']) ? $detail['chip_type']
|
||||
: (isset($detail['type'])?$detail['type']
|
||||
:0)),
|
||||
: (isset($detail['type']) ? $detail['type']
|
||||
: 0)),
|
||||
'c_lv' => @$detail['gun_lv'] | @$detail['hero_lv'] | @$detail['chip_grade'],
|
||||
'c_quality' => isset($nftDetail['info']['quality']) ? $nftDetail['info']['quality'] : 0,
|
||||
'c_durability' => isset($nftDetail['info']['durability']) ? $nftDetail['info']['durability'] : (isset($detail['hero_tili']) ? $detail['hero_tili'] : 0),
|
||||
@ -1153,13 +1252,14 @@ class MarketController extends BaseController {
|
||||
)
|
||||
);
|
||||
if (!$r) {
|
||||
$this->_rspErr(2, 'unknown error, orderId='.$orderId);
|
||||
$this->_rspErr(2, 'unknown error, orderId=' . $orderId);
|
||||
}
|
||||
|
||||
$this->_rspOk();
|
||||
}
|
||||
|
||||
public function eventBuyOrder() {
|
||||
public function eventBuyOrder()
|
||||
{
|
||||
$tokenId = getReqVal('tokenId', '');
|
||||
$orderId = getReqVal('orderId', '');
|
||||
$nftToken = getReqVal('nftToken', '');
|
||||
@ -1169,7 +1269,8 @@ class MarketController extends BaseController {
|
||||
$erc20 = getReqVal('erc20', '');
|
||||
$price = getReqVal('price', '');
|
||||
|
||||
error_log("eventBuyOrder:" . json_encode(
|
||||
error_log(
|
||||
"eventBuyOrder:" . json_encode(
|
||||
array(
|
||||
'tokenId' => $tokenId,
|
||||
'orderId' => $orderId,
|
||||
@ -1187,12 +1288,12 @@ class MarketController extends BaseController {
|
||||
$conn = myself()->_getMarketMysql('');
|
||||
|
||||
// 1. check order status
|
||||
$chk = SqlHelper::selectOne($conn, 't_market_store', array('status','idx', 'c_name', 'token_type'), array('o_link' => $orderId));
|
||||
$chk = SqlHelper::selectOne($conn, 't_market_store', array('status', 'idx', 'c_name', 'token_type'), array('o_link' => $orderId));
|
||||
if (empty($chk)) {
|
||||
$this->_rspErr(1, 'not found order, orderId='.$orderId);
|
||||
$this->_rspErr(1, 'not found order, orderId=' . $orderId);
|
||||
return;
|
||||
}
|
||||
if ($chk['status']== '0') {
|
||||
if ($chk['status'] == '0') {
|
||||
$r = SqlHelper::update(
|
||||
$conn,
|
||||
't_market_store',
|
||||
@ -1221,14 +1322,16 @@ class MarketController extends BaseController {
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->_rspErr(1, 'order status error, order='.$orderId);
|
||||
$this->_rspErr(1, 'order status error, order=' . $orderId);
|
||||
}
|
||||
|
||||
public function eventCancelOrder() {
|
||||
public function eventCancelOrder()
|
||||
{
|
||||
$orderId = getReqVal('orderId', '');
|
||||
$nftToken = getReqVal('nftToken', '');
|
||||
$tokenId = getReqVal('tokenId', '');
|
||||
error_log("eventCancelOrder:" . json_encode(
|
||||
error_log(
|
||||
"eventCancelOrder:" . json_encode(
|
||||
array(
|
||||
'orderId' => $orderId,
|
||||
'nftToken' => $nftToken,
|
||||
@ -1243,10 +1346,10 @@ class MarketController extends BaseController {
|
||||
// 1. check order status
|
||||
$chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId));
|
||||
if (empty($chk)) {
|
||||
$this->_rspErr(1, 'not found order, orderId='.$orderId);
|
||||
$this->_rspErr(1, 'not found order, orderId=' . $orderId);
|
||||
return;
|
||||
}
|
||||
if ($chk['status']== '0') {
|
||||
if ($chk['status'] == '0') {
|
||||
$r = SqlHelper::update(
|
||||
$conn,
|
||||
't_market_store',
|
||||
@ -1262,16 +1365,18 @@ class MarketController extends BaseController {
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->_rspErr(1, 'order status error, order='.$orderId);
|
||||
$this->_rspErr(1, 'order status error, order=' . $orderId);
|
||||
}
|
||||
|
||||
public function eventPriceUpdateOrder() {
|
||||
public function eventPriceUpdateOrder()
|
||||
{
|
||||
$orderId = getReqVal('orderId', '');;
|
||||
$nftToken = getReqVal('nftToken', '');
|
||||
$tokenId = getReqVal('tokenId', '');
|
||||
$priceOld = getReqVal('priceOld', '');
|
||||
$price = getReqVal('price', '');
|
||||
error_log("eventPriceUpdateOrder:" . json_encode(
|
||||
error_log(
|
||||
"eventPriceUpdateOrder:" . json_encode(
|
||||
array(
|
||||
'orderId' => $orderId,
|
||||
'nftToken' => $nftToken,
|
||||
@ -1288,11 +1393,11 @@ class MarketController extends BaseController {
|
||||
// 1. check order status
|
||||
$chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId));
|
||||
if (empty($chk)) {
|
||||
$this->_rspErr(1, 'not found order, orderId='.$orderId);
|
||||
$this->_rspErr(1, 'not found order, orderId=' . $orderId);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($chk['status']== '0') {
|
||||
if ($chk['status'] == '0') {
|
||||
$r = SqlHelper::update(
|
||||
$conn,
|
||||
't_market_store',
|
||||
@ -1309,32 +1414,39 @@ class MarketController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
$this->_rspErr(1, 'price update failed, orderId='.$orderId);
|
||||
$this->_rspErr(1, 'price update failed, orderId=' . $orderId);
|
||||
}
|
||||
|
||||
private function getNftGameData($nftRowInfo) {
|
||||
private function getNftGameData($nftRowInfo)
|
||||
{
|
||||
$t = $nftRowInfo['token_type'];
|
||||
$token_id = $nftRowInfo['token_id'];
|
||||
switch($t) {
|
||||
switch ($t) {
|
||||
case Nft::HERO_TYPE: {
|
||||
return $this->appendChipsInfo(Hero::toDtoInfo(Hero::findByTokenId2($token_id)));
|
||||
} break;
|
||||
}
|
||||
break;
|
||||
case Nft::EQUIP_TYPE: {
|
||||
return $this->appendChipsInfo(Gun::toDtoInfo(Gun::findByTokenId2($token_id)));
|
||||
} break;
|
||||
}
|
||||
break;
|
||||
case Nft::CHIP_TYPE: {
|
||||
return Chip::toDto(Chip::getChipByTokenId($token_id));
|
||||
} break;
|
||||
}
|
||||
break;
|
||||
case Nft::FRAGMENT_TYPE: {
|
||||
return Fragment::ToDto($nftRowInfo);
|
||||
} break;
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
} break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return array('unknown' => 'unknown game data type, cannot find data');
|
||||
}
|
||||
|
||||
private function appendChipsInfo($detail) {
|
||||
private function appendChipsInfo($detail)
|
||||
{
|
||||
$detail['chips_info'] = array();
|
||||
if (!empty($detail['chip_ids'])) {
|
||||
$chips = explode('|', $detail['chip_ids']);
|
||||
@ -1349,11 +1461,12 @@ class MarketController extends BaseController {
|
||||
return $detail;
|
||||
}
|
||||
|
||||
private function attach_market_selling(&$row) {
|
||||
private function attach_market_selling(&$row)
|
||||
{
|
||||
$conn = myself()->_getMarketMysql('');
|
||||
|
||||
$rows = $conn->execQuery(
|
||||
'SELECT * FROM t_market_store '.
|
||||
'SELECT * FROM t_market_store ' .
|
||||
'WHERE token_id=:token_id AND owner_address=:owner_address AND status=:status',
|
||||
array(
|
||||
':token_id' => $row['token_id'],
|
||||
@ -1380,7 +1493,7 @@ class MarketController extends BaseController {
|
||||
$conn = myself()->_getMarketMysql('');
|
||||
|
||||
$rows = $conn->execQuery(
|
||||
'SELECT * FROM t_market_store '.
|
||||
'SELECT * FROM t_market_store ' .
|
||||
'WHERE owner_address=:account AND token_type=:token_type AND status=0 ',
|
||||
array(
|
||||
':account' => $account,
|
||||
@ -1390,4 +1503,92 @@ class MarketController extends BaseController {
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
private function decItems($address, $item_id, $amount)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
private function getCostItem($address, $item_id)
|
||||
{
|
||||
$self = myself();
|
||||
if (!$self) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$userInfo = $this->getUserInfo($address, array('gold'));
|
||||
$count = $this->getItemCount($item_id, $userInfo);
|
||||
|
||||
return array(
|
||||
'item_id' => $item_id,
|
||||
'item_amount' => $count
|
||||
);
|
||||
}
|
||||
|
||||
private function getItemCount($item_id, $userInfo)
|
||||
{
|
||||
switch ($item_id) {
|
||||
case V_ITEM_GOLD: {
|
||||
return $userInfo['gold'];
|
||||
}
|
||||
}
|
||||
return "0";
|
||||
}
|
||||
|
||||
private function getUserInfo($address, $fields)
|
||||
{
|
||||
$self = myself();
|
||||
if (!$self) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// $account_id = $this->getAccountId($address);
|
||||
// if (!$account_id) {
|
||||
// return null;
|
||||
// }
|
||||
|
||||
$conn = $self->_getMysql($address);
|
||||
$row = SqlHelper::selectOne(
|
||||
$conn,
|
||||
't_user',
|
||||
$fields,
|
||||
array(
|
||||
'address' => $address
|
||||
)
|
||||
);
|
||||
if (empty($row)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
private function getAccountId($address)
|
||||
{
|
||||
$self = myself();
|
||||
if (!$self) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$row = SqlHelper::selectOne(
|
||||
$self->_getMysql($address),
|
||||
't_user',
|
||||
array('account_id'),
|
||||
array(
|
||||
'address' => $address
|
||||
)
|
||||
);
|
||||
|
||||
return $row['account_id'];
|
||||
}
|
||||
|
||||
private function normalizeWeb3Price($price)
|
||||
{
|
||||
$bn1 = phpcommon\bnInit($price * pow(10, 8));
|
||||
$bn2 = phpcommon\bnInit('1000000000000000000');
|
||||
$ret_price = phpcommon\bnDiv(phpcommon\bnMul($bn1, $bn2), pow(10, 8));
|
||||
|
||||
// error_log('normalizeWeb3Price: ' . $ret_price . ' ' . $price * pow(10, 8));
|
||||
return phpcommon\bnToStr($ret_price);
|
||||
}
|
||||
}
|
||||
|
@ -418,11 +418,14 @@ class ShopController extends BaseAuthedController
|
||||
$count = $this->countTodayRefreshTimes($address);
|
||||
$costs = mt\Parameter::getByName('daily_selection_refresh_cost');
|
||||
$arrCosts = explode('|', $costs['param_value']);
|
||||
$cost = $count < count($arrCosts) ? $arrCosts[$count] : null;
|
||||
|
||||
$max_count = count($arrCosts);
|
||||
$cost = $count < $max_count ? $arrCosts[$count] : -1;
|
||||
|
||||
$this->_rspData(
|
||||
array(
|
||||
'idx' => $selection['idx'],
|
||||
'refresh_info' => "{$count}/{$max_count}",
|
||||
'cost' => $cost,
|
||||
'goods_list' => $goodsList,
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user