884 lines
31 KiB
PHP
884 lines
31 KiB
PHP
<?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');
|
|
require_once('mt/Hero.php');
|
|
require_once('mt/Parameter.php');
|
|
|
|
require_once('models/BoxOrder.php');
|
|
require_once('models/Nft.php');
|
|
require_once('models/Hero.php');
|
|
require_once('models/Gun.php');
|
|
require_once('models/Chip.php');
|
|
require_once('models/Fragment.php');
|
|
require_once('models/BuyRecord.php');
|
|
|
|
require_once('services/MarketService.php');
|
|
require_once('services/LuckyBoxService.php');
|
|
require_once('services/ActivateNftService.php');
|
|
|
|
require_once('phpcommon/bchelper.php');
|
|
|
|
use phpcommon\SqlHelper;
|
|
use models\BoxOrder;
|
|
use models\Nft;
|
|
use models\Hero;
|
|
use models\Gun;
|
|
use models\Chip;
|
|
use models\Fragment;
|
|
use models\BuyRecord;
|
|
use services\MarketService;
|
|
use services\LuckyBoxService;
|
|
use services\ActivateNftService;
|
|
|
|
class MarketController extends BaseController {
|
|
|
|
public function getPreSaleInfo()
|
|
{
|
|
$account = strtolower(getReqVal('account', ''));
|
|
$presaleInfo = MarketService::getPreSaleInfo($account);
|
|
if (MarketService::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 = strtolower(getReqVal('account', ''));
|
|
$page = getReqVal('page', 1);
|
|
$type = getReqVal('type', 0);
|
|
$sort = getReqVal('sort', '');
|
|
|
|
$perPage = 10000;
|
|
$rows = array();
|
|
$pageInfo = array(
|
|
'total' => 0,
|
|
'count' => 0,
|
|
'per_page' => $perPage,
|
|
'current_page' => $page,
|
|
'total_pages' => 0
|
|
);
|
|
$startPos= $pageInfo['per_page'] * ($pageInfo['current_page'] - 1);
|
|
|
|
$currBatchMeta = mt\MarketBatch::getCurrentBatch();
|
|
if ($currBatchMeta) {
|
|
$batchMetas = mt\MarketGoods::getBatchMetas($currBatchMeta['batch_id']);
|
|
if ($batchMetas) {
|
|
foreach ($batchMetas as $meta) {
|
|
$saleBox = $this->fillPresaleBox($currBatchMeta, $meta);
|
|
if ($saleBox) {
|
|
++$pageInfo['total'];
|
|
if ($pageInfo['total'] > $startPos &&
|
|
count($rows) < $pageInfo['per_page']) {
|
|
array_push($rows, $saleBox);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$pageInfo['count'] = count($rows);
|
|
$pageInfo['total_pages'] = ceil($pageInfo['total'] / $pageInfo['per_page']);
|
|
myself()->_rspData(array(
|
|
'rows' => $rows,
|
|
'page' => $pageInfo,
|
|
));
|
|
}
|
|
|
|
public function buyBox()
|
|
{
|
|
$token = getReqVal('token', '');
|
|
$type = getReqVal('type', '');
|
|
$rawBuyerAddress = getReqVal('buyer_address', '');
|
|
$buyerAddress = strtolower($rawBuyerAddress);
|
|
$price = getReqVal('price', '');
|
|
$paymentTokenAddress = getReqVal('payment_token_address', '');
|
|
$nonce = getReqVal('nonce', '');
|
|
$signature = getReqVal('signature', '');
|
|
$netId = getReqVal('net_id', '');
|
|
$gameId = 2006;
|
|
$funcId = MarketService::FUNCID_PRESALE;
|
|
if (!MarketService::isValidToken($buyerAddress, $token)) {
|
|
myself()->_rspErr(100, 'invalid token');
|
|
return;
|
|
}
|
|
MarketService::buyBoxVerifySignature(
|
|
$buyerAddress,
|
|
$type,
|
|
$paymentTokenAddress,
|
|
$price,
|
|
$nonce,
|
|
$signature);
|
|
|
|
$batchIdx = 0;
|
|
$idx = 0;
|
|
$itemId = 0;
|
|
if (!phpcommon\extractBoxId($type, $batchIdx, $idx, $itemId)) {
|
|
myself()->_rspErr(2, 'type parameter error');
|
|
return;
|
|
}
|
|
|
|
if (empty($type) ||
|
|
empty($buyerAddress) ||
|
|
empty($price) ||
|
|
empty($paymentTokenAddress) ||
|
|
empty($signature) ||
|
|
empty($nonce)) {
|
|
myself()->_rspErr(2, 'parameter error');
|
|
return;
|
|
}
|
|
|
|
$currBatchMeta = mt\MarketBatch::getCurrentBatch();
|
|
if (!$currBatchMeta) {
|
|
myself()->_rspErr(500, 'server internal error1');
|
|
return;
|
|
}
|
|
if ($batchIdx != $currBatchMeta['id']) {
|
|
myself()->_rspErr(500, 'server internal error2');
|
|
return;
|
|
}
|
|
$goodsMeta = mt\MarketGoods::getOnSaleGoods($currBatchMeta['batch_id'], $idx, $itemId);
|
|
if (!$goodsMeta) {
|
|
myself()->_rspErr(500, 'server internal error3');
|
|
return;
|
|
}
|
|
if ($currBatchMeta['white_list'] && !mt\WhiteList::inWhiteList($buyerAddress)) {
|
|
myself()->_rspErr(500, 'not white list user');
|
|
return;
|
|
}
|
|
$originalPrice = $goodsMeta['price'] * pow(10, MarketService::CURRENCY_DECIMALS);
|
|
$discountPrice = $goodsMeta['discount'] * 100 > 0 ?
|
|
$originalPrice * $goodsMeta['discount'] : $originalPrice;
|
|
|
|
$discountPrice .= MarketService::PRICE_PAD;
|
|
if (!$discountPrice || strcmp($price, $discountPrice) != 0) {
|
|
myself()->_rspErr(500, 'price error');
|
|
return;
|
|
}
|
|
$itemMeta = mt\Item::get($itemId);
|
|
if (!$itemMeta) {
|
|
myself()->_rspErr(500, 'server internal error11');
|
|
return;
|
|
}
|
|
$currencyMeta = mt\Currency::get($goodsMeta['currency_id']);
|
|
if (!$currencyMeta || $currencyMeta['address'] != $paymentTokenAddress) {
|
|
myself()->_rspErr(500, 'currency error');
|
|
return;
|
|
}
|
|
|
|
if (!phpcommon\isValidBcGameId($gameId)) {
|
|
myself()->_rspErr(500, 'server internal error12');
|
|
return;
|
|
}
|
|
|
|
if (!phpcommon\isValidBcTime(myself()->_getNowTime())) {
|
|
myself()->_rspErr(500, 'server internal error13');
|
|
return;
|
|
}
|
|
|
|
if (!phpcommon\isValidBcFuncId($funcId)) {
|
|
myself()->_rspErr(500, 'server internal error14');
|
|
return;
|
|
}
|
|
|
|
if (!MarketService::isTestMode() &&
|
|
BoxOrder::isBuyed($buyerAddress, $currBatchMeta['id'])) {
|
|
myself()->_rspErr(1, 'account can only choose 1 hero to purchase');
|
|
return;
|
|
}
|
|
$orderId = BuyRecord::genOrderId($gameId,
|
|
$funcId,
|
|
myself()->_getNowTime(),
|
|
$buyerAddress);
|
|
|
|
$fieldsKv = array(
|
|
'game_id' => $gameId,
|
|
'func_id' => $funcId,
|
|
'batch_idx' => $currBatchMeta['id'],
|
|
'type' => $type,
|
|
'raw_buyer_address' => $rawBuyerAddress,
|
|
'buyer_address' => $buyerAddress,
|
|
'price' => $price,
|
|
'payment_token_address' => $paymentTokenAddress,
|
|
'nonce' => $nonce,
|
|
'signature' => $signature,
|
|
'net_id' => $netId,
|
|
'done' => 0,
|
|
'createtime' => myself()->_getNowTime(),
|
|
'modifytime' => myself()->_getNowTime()
|
|
);
|
|
$items = array();
|
|
MarketService::openBox($itemMeta, $items);
|
|
for ($i = 1; $i <= BoxOrder::MAX_NFT_NUM; ++$i) {
|
|
if ($i <= count($items)) {
|
|
$tokenId = phpcommon\setOrderIdSubIdx($orderId, $i);
|
|
$fieldsKv['bc_mint_tokenid' . $i] = $tokenId;
|
|
$fieldsKv['bc_mint_need' . $i] = $items[$i - 1]['need'];
|
|
$fieldsKv['bc_mint_itemid' . $i] = $items[$i - 1]['item_id'];
|
|
$fieldsKv['bc_mint_token_type' . $i] = $items[$i - 1]['token_type'];
|
|
}
|
|
}
|
|
/*if (MarketService::isTestMode()) {
|
|
$fieldsKv['bc_paid'] = 1;
|
|
}*/
|
|
$fieldsKv['order_id'] = $orderId;
|
|
SqlHelper::insert(
|
|
myself()->_getMarketMysql(),
|
|
't_box_order',
|
|
$fieldsKv
|
|
);
|
|
myself()->_rspData(array(
|
|
'order_id' => $orderId
|
|
));
|
|
}
|
|
|
|
public function queryOrder()
|
|
{
|
|
$token = getReqVal('token', '');
|
|
$account = strtolower(getReqVal('account', ''));
|
|
$orderId = getReqVal('order_id', '');
|
|
if (!MarketService::isValidToken($account, $token)) {
|
|
myself()->_rspErr(100, 'invalid token');
|
|
return;
|
|
}
|
|
|
|
$orderDb = BoxOrder::findByOrderId($orderId);
|
|
if ($orderDb) {
|
|
if (!$orderDb['done']) {
|
|
myself()->_rspData(array(
|
|
'state' => 2
|
|
));
|
|
} else {
|
|
if ($orderDb['bc_paid'] == 1) {
|
|
myself()->_rspData(array(
|
|
'state' => 1
|
|
));
|
|
} else {
|
|
myself()->_rspData(array(
|
|
'state' => 3
|
|
));
|
|
}
|
|
}
|
|
} else {
|
|
myself()->_rspData(array(
|
|
'state' => 0
|
|
));
|
|
}
|
|
}
|
|
|
|
public function getNftList()
|
|
{
|
|
$account = strtolower(getReqVal('account', ''));
|
|
$token = getReqVal('token', '');
|
|
$page = getReqVal('page', 0);
|
|
if (MarketService::isTestMode()) {
|
|
} else {
|
|
if (!MarketService::isValidToken($account, $token)) {
|
|
myself()->_rspErr(100, 'invalid token');
|
|
return;
|
|
}
|
|
}
|
|
$nftDbList = array();
|
|
$pagination = array();
|
|
SqlHelper::rawQueryPage(
|
|
myself()->_getMarketMysql(),
|
|
'SELECT * FROM t_nft WHERE owner_address=:owner_address',
|
|
array(
|
|
':owner_address' => $account
|
|
),
|
|
array(
|
|
'page' => $page,
|
|
'perPage' => 8,
|
|
'filter' => array(
|
|
'data' => $_REQUEST,
|
|
'fields' => array(
|
|
array(
|
|
'name' => 'type',
|
|
'field_name' => 'token_type',
|
|
'cond' => '=',
|
|
'ignore_empty' => true
|
|
),
|
|
array(
|
|
'name' => 'state',
|
|
'field_name' => 'token_state',
|
|
'cond' => '=',
|
|
'ignore_empty' => true
|
|
),
|
|
)
|
|
),
|
|
'handle' => function ($row) use(&$nftDbList) {
|
|
#error_log(json_encode($row));
|
|
array_push($nftDbList, $row);
|
|
}
|
|
),
|
|
$pagination
|
|
);
|
|
$nftList = array();
|
|
foreach ($nftDbList as $nftDb) {
|
|
$nft = Nft::toDto($nftDb);
|
|
if ($nft) {
|
|
array_push($nftList, $nft);
|
|
}
|
|
}
|
|
myself()->_rspData(array(
|
|
'nfts' => $nftList,
|
|
'page' => $pagination
|
|
));
|
|
}
|
|
|
|
public function getNftDetail()
|
|
{
|
|
$account = strtolower(getReqVal('account', ''));
|
|
$token = getReqVal('token', '');
|
|
$tokenId = getReqVal('token_id', '');
|
|
if (!MarketService::isValidToken($account, $token)) {
|
|
myself()->_rspErr(100, 'invalid token');
|
|
return;
|
|
}
|
|
|
|
$nftDb = Nft::getNft($tokenId);
|
|
if (!$nftDb) {
|
|
myself()->_rspErr(1, 'nft not exists');
|
|
return;
|
|
}
|
|
$nft = Nft::toDto($nftDb);
|
|
myself()->_rspData(array(
|
|
'info' => $nft
|
|
));
|
|
}
|
|
|
|
public function getNonce()
|
|
{
|
|
$account = strtolower(getReqVal('account', ''));
|
|
$token = getReqVal('token', '');
|
|
$nonce = uniqid() . '_' . myself()->_getNowTime();
|
|
myself()->_rspData(array(
|
|
'state' => MarketService::isValidToken($account, $token) ? 1 : 0,
|
|
'nonce' => $nonce,
|
|
));
|
|
}
|
|
|
|
public function tokenAuth()
|
|
{
|
|
$account = strtolower(getReqVal('account', ''));
|
|
$token = getReqVal('token', '');
|
|
if (!MarketService::isValidToken($account, $token)) {
|
|
myself()->_rspErr(1, 'invalid token');
|
|
return;
|
|
}
|
|
myself()->_rspData(array(
|
|
'account' => $account
|
|
));
|
|
}
|
|
|
|
public function auth()
|
|
{
|
|
$account = strtolower(getReqVal('account', ''));
|
|
$tips = getReqVal('tips', '') ;
|
|
$nonce = getReqVal('nonce', '');
|
|
$signature = getReqVal('signature', '');
|
|
MarketService::auth($account, $tips, $nonce, $signature);
|
|
}
|
|
|
|
private function fillPresaleBox($batchMeta, $goodsMeta)
|
|
{
|
|
$currencyMeta = mt\Currency::get($goodsMeta['currency_id']);
|
|
if (!$currencyMeta) {
|
|
return null;
|
|
}
|
|
$boxId = phpcommon\genBoxId($batchMeta['id'],
|
|
$goodsMeta['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;
|
|
{
|
|
$heroMeta = mt\Hero::get($goodsMeta['item_id']);
|
|
if ($heroMeta) {
|
|
$name = emptyReplace($heroMeta['name'], 'Hill');
|
|
$job = emptyReplace($heroMeta['herotype'], '1');
|
|
}
|
|
}
|
|
$saleBox = array(
|
|
'box_id' => $boxId,
|
|
'item_id' => $goodsMeta['item_id'],
|
|
'name' => $name,
|
|
'job' => $job,
|
|
'avatar_url' => 'https://www.cebg.games/res/avatars/' . 501 . '.png',
|
|
'currency_list' => array(
|
|
array(
|
|
'name' => $currencyMeta['name'],
|
|
'original_price' => $originalPrice,
|
|
'discount_price' => $discountPrice,
|
|
'discount_rate' => $goodsMeta['discount'],
|
|
'decimals' => MarketService::CURRENCY_DECIMALS,
|
|
'contract_address' => $currencyMeta['address'],
|
|
)
|
|
));
|
|
return $saleBox;
|
|
}
|
|
|
|
public function openLuckyBox()
|
|
{
|
|
$token = getReqVal('token', '');
|
|
$account = getReqVal('account', '');
|
|
$tokenId = getReqVal('token_id', '');
|
|
$netId = getReqVal('net_id', '');
|
|
$account = strtolower(getReqVal('account', ''));
|
|
$token = getReqVal('token', '');
|
|
if (!MarketService::isValidToken($account, $token)) {
|
|
myself()->_rspErr(1, 'invalid token');
|
|
return;
|
|
}
|
|
LuckyBoxService::open($account, $tokenId, $netId);
|
|
}
|
|
|
|
public function queryLuckyBox()
|
|
{
|
|
$this->queryLuckyBoxResult();
|
|
}
|
|
|
|
public function queryLuckyBoxResult()
|
|
{
|
|
$token = getReqVal('token', '');
|
|
$account = getReqVal('account', '');
|
|
$tokenId = getReqVal('token_id', '');
|
|
$netId = getReqVal('net_id', '');
|
|
$account = strtolower(getReqVal('account', ''));
|
|
if (!MarketService::isValidToken($account, $token)) {
|
|
myself()->_rspErr(1, 'invalid token');
|
|
return;
|
|
}
|
|
LuckyBoxService::queryResult($account, $tokenId, $netId);
|
|
}
|
|
|
|
public function activateNft()
|
|
{
|
|
$token = getReqVal('token', '');
|
|
$account = getReqVal('account', '');
|
|
$tokenId = getReqVal('token_id', '');
|
|
$netId = getReqVal('net_id', '');
|
|
$account = strtolower(getReqVal('account', ''));
|
|
if (!MarketService::isValidToken($account, $token)) {
|
|
myself()->_rspErr(1, 'invalid token');
|
|
return;
|
|
}
|
|
ActivateNftService::activate($account, $tokenId, $netId);
|
|
}
|
|
|
|
public function queryActivateResult()
|
|
{
|
|
$token = getReqVal('token', '');
|
|
$account = getReqVal('account', '');
|
|
$tokenId = getReqVal('token_id', '');
|
|
$netId = getReqVal('net_id', '');
|
|
$account = strtolower(getReqVal('account', ''));
|
|
if (!MarketService::isValidToken($account, $token)) {
|
|
myself()->_rspErr(1, 'invalid token');
|
|
return;
|
|
}
|
|
ActivateNftService::queryResult($account, $tokenId, $netId);
|
|
}
|
|
|
|
public function getPhase3Box()
|
|
{
|
|
$token = getReqVal('token', '');
|
|
$account = getReqVal('account', '');
|
|
$tokenId = getReqVal('token_id', '');
|
|
$netId = getReqVal('net_id', '');
|
|
$account = strtolower(getReqVal('account', ''));
|
|
if (!MarketService::isValidToken($account, $token)) {
|
|
myself()->_rspErr(1, 'invalid token');
|
|
return;
|
|
}
|
|
$rows = array();
|
|
myself()->_rspData(array(
|
|
'rows' => $rows
|
|
));
|
|
}
|
|
|
|
public function openPhase3Box()
|
|
{
|
|
$token = getReqVal('token', '');
|
|
$account = getReqVal('account', '');
|
|
$tokenId = getReqVal('token_id', '');
|
|
$netId = getReqVal('net_id', '');
|
|
$boxId = getReqVal('box_id', '');
|
|
$account = strtolower(getReqVal('account', ''));
|
|
if (!MarketService::isValidToken($account, $token)) {
|
|
myself()->_rspErr(1, 'invalid token');
|
|
return;
|
|
}
|
|
myself()->_rspOk();
|
|
}
|
|
|
|
public function queryPhase3Box()
|
|
{
|
|
$token = getReqVal('token', '');
|
|
$account = getReqVal('account', '');
|
|
$tokenId = getReqVal('token_id', '');
|
|
$netId = getReqVal('net_id', '');
|
|
$boxId = getReqVal('box_id', '');
|
|
$account = strtolower(getReqVal('account', ''));
|
|
if (!MarketService::isValidToken($account, $token)) {
|
|
myself()->_rspErr(1, 'invalid token');
|
|
return;
|
|
}
|
|
myself()->_rspOk();
|
|
}
|
|
|
|
private function getNftListByAccountAndType($account, $type, $order_method, $order_asc, $job, $search, $lv)
|
|
{
|
|
$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) {
|
|
return ($order_asc == 1 ? 1 : -1) * ($b['detail']['gun_lv'] - $a['detail']['gun_lv']);
|
|
};
|
|
$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) {
|
|
return ($order_asc == 1 ? 1 : -1) * ($b['detail']['quality'] - $a['detail']['quality']);
|
|
};
|
|
$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) {
|
|
return ($order_asc == 1 ? 1 : -1) * ($b['detail']['strength'] - $a['detail']['strength']);
|
|
};
|
|
$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) {
|
|
return ($order_asc == 1 ? 1 : -1) * ($b['token_id'] - $a['token_id']);
|
|
};
|
|
$nfts = array();
|
|
switch ($type) {
|
|
case Nft::HERO_TYPE: {
|
|
$rows = Nft::getNftListByType($account, $type);
|
|
foreach ($rows as &$row) {
|
|
$nftDb = Nft::findNftByOwner($account, $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 (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;
|
|
}
|
|
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::EQUIP_TYPE: {
|
|
$rows = Nft::getNftListByType($account, $type);
|
|
foreach ($rows as &$row) {
|
|
$nftDb = Nft::findNftByOwner($account, $row['token_id']);
|
|
$row['info'] = Nft::toDto($nftDb);
|
|
$row['detail'] = Gun::toDtoInfo(Gun::findByTokenId2($row['token_id']));
|
|
if ($row['detail']['gun_lv']<$lv) continue;
|
|
if (count($search)>0) {
|
|
if (!(in_array($rwo['detail']['gun_name'], $search) || in_array($row['detail']['token_id'], $search))) continue;
|
|
}
|
|
array_push($nfts, $row);
|
|
}
|
|
switch ($order_method) {
|
|
case 1:
|
|
usort($nfts, $sortByGunLv);
|
|
break;
|
|
case 2:
|
|
usort($nfts, $sortByDurability);
|
|
break;
|
|
case 3:
|
|
usort($nfts, $sortByStar);
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
case Nft::CHIP_TYPE: {
|
|
$rows = Nft::getNft1155List($account, $type);
|
|
foreach ($rows as &$row) {
|
|
$row['detail'] = Chip::toDto(Chip::getChipByTokenId($row['token_id']));
|
|
if ($row['detail']['chip_grade']<$lv) continue;
|
|
if (count($search)>0) {
|
|
if (!(in_array($row['detail']['token_id'], $search))) continue;
|
|
}
|
|
array_push($nfts, $row);
|
|
}
|
|
switch ($order_method) {
|
|
case 1:
|
|
usort($nfts, $sortByGrade);
|
|
break;
|
|
case 2:
|
|
usort($nfts, $sortByPower);
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
case Nft::FRAGMENT_TYPE: {
|
|
$rows = Nft::getNft1155List($account, $type);
|
|
usort($nfts, $sortByTokenId);
|
|
$nfts = $rows;
|
|
}
|
|
break;
|
|
default: {
|
|
|
|
}
|
|
}
|
|
return $nfts;
|
|
}
|
|
|
|
public function listSellNfts()
|
|
{
|
|
$account = getReqVal('account', '');
|
|
$token = getReqVal('token', '');
|
|
$start = getReqVal('start', 0);
|
|
$page_size = getReqVal('page_size', 10);
|
|
$order_method = getReqVal('order_method', 0);
|
|
$order_asc = getReqVal('order_asc', 1);
|
|
$type = getReqVal('type', 1);
|
|
$job_filters = getReqVal('job_filters', '');
|
|
$job_filter_array = explode('|', $job_filters);
|
|
$search_filters = getReqVal('search_filters', '');
|
|
$search_filter_array = explode('|', $search_filters);
|
|
$lv_filter = getReqVal('lv_filter', 1);
|
|
$quality_filter = getReqVal('quality_filter', 1);
|
|
$durability_filter = getReqVal('durability_filter', 0);
|
|
$price_filter = getReqVal('price_filter', '');
|
|
$price_filter_array = explode('|', $price_filter);
|
|
|
|
$job_filter_fn = function ($f) {
|
|
return '';
|
|
};
|
|
$lv_filter_fn = function ($f) {
|
|
$f = (int) $f;
|
|
return 'AND c_lv>=' . $f. ' ';
|
|
};
|
|
$quality_filter_fn = function ($f) {
|
|
$f = (int) $f;
|
|
return 'AND c_quality>=' . $f. ' ';
|
|
};
|
|
$durability_filter_fn = function ($f) {
|
|
$f = (int) $f;
|
|
return 'AND c_durability>=' . $f. ' ';
|
|
};
|
|
$search_filter_fn = function ($f) {
|
|
return '';
|
|
};
|
|
|
|
$order_fn = function ($method, $asc) {
|
|
switch ($method) {
|
|
case 2:
|
|
return 'ORDER BY s_price ' . ($asc == 0 ? 'ASC' : 'DESC' . ' ');
|
|
break;
|
|
case 3:
|
|
return 'ORDER BY c_quality ' . ($asc == 0 ? 'ASC' : 'DESC' . ' ');
|
|
break;
|
|
case 4:
|
|
return 'ORDER BY c_lv ' . ($asc == 0 ? 'ASC' : 'DESC' . ' ');
|
|
break;
|
|
case 5:
|
|
return 'ORDER BY c_durability ' . ($asc == 0 ? 'ASC' : 'DESC' . ' ');
|
|
break;
|
|
|
|
// 所有其他不正常的排序都执行最新上架
|
|
case 1:
|
|
default:
|
|
return 'ORDER BY createtime ' . ($asc == 0 ? 'ASC' : 'DESC' . ' ');
|
|
break;
|
|
}
|
|
return '';
|
|
};
|
|
|
|
$conn = myself()->_getMysql('');
|
|
|
|
$rows = $conn->execQuery(
|
|
'SELECT * FROM t_market_store '.
|
|
'WHERE token_type=:token_type '.
|
|
$job_filter_fn($job_filter_array).
|
|
$lv_filter_fn($lv_filter).
|
|
$quality_filter_fn($quality_filter).
|
|
$durability_filter_fn($durability_filter).
|
|
$search_filter_fn($search_filter_array).
|
|
$order_fn($order_method, $order_asc).
|
|
'LIMIT '.$start.','.$page_size,
|
|
array(
|
|
':token_type' => $type,
|
|
)
|
|
);
|
|
|
|
$total = count($rows);
|
|
$page_end = $start + $page_size;
|
|
if ($page_end > $total) {
|
|
$page_end = $total;
|
|
$start = $total-1;
|
|
$start = intval($start / $page_size) * $page_size;
|
|
if ($start<0) $start = 0;
|
|
}
|
|
|
|
$nfts = array();
|
|
|
|
for ($x = $start; $x < $page_end; $x++) {
|
|
$row = $rows[$x];
|
|
$nftDb = Nft::findNftByOwner($row['owner_address'], $row['token_id']);
|
|
if (!$nftDb) {
|
|
myself()->_rspErr(1, 'nft not exists');
|
|
return;
|
|
}
|
|
$nft = Nft::toDto($nftDb);
|
|
|
|
$t = $row['token_type'];
|
|
switch($t) {
|
|
case Nft::HERO_TYPE: {
|
|
$row['detail'] = Hero::toDtoInfo(Hero::findByTokenId2($row['token_id']));
|
|
} break;
|
|
case Nft::EQUIP_TYPE: {
|
|
$row['detail'] = Gun::toDtoInfo(Gun::findByTokenId2($row['token_id']));
|
|
} break;
|
|
case Nft::CHIP_TYPE: {
|
|
$row['detail'] = Chip::toDto(Chip::getChipByTokenId($row['token_id']));
|
|
} break;
|
|
case Nft::FRAGMENT_TYPE: {
|
|
|
|
} break;
|
|
default: {
|
|
|
|
} break;
|
|
}
|
|
$row['info'] = $nft;
|
|
array_push($nfts, $row);
|
|
}
|
|
|
|
$this->_rspData(array(
|
|
"total" => count($rows),
|
|
"start" => $start,
|
|
"page_size" => $page_size,
|
|
'nfts' => $nfts,
|
|
));
|
|
}
|
|
|
|
public function listMyNfts()
|
|
{
|
|
$account = getReqVal('account', '');
|
|
$token = getReqVal('token', '');
|
|
$start = getReqVal('start', 0);
|
|
$page_size = getReqVal('page_size', 10);
|
|
$order_method = getReqVal('order_method', 0);
|
|
$order_asc = getReqVal('order_asc', 1);
|
|
$type = getReqVal('type', 1);
|
|
$job_filters = getReqVal('job_filters', '');
|
|
$job_filter_array = explode('|', $job_filters);
|
|
$search_filters = getReqVal('search_filters', '');
|
|
if ($search_filters!='') {
|
|
$search_filter_array = explode('|', $search_filters);
|
|
} else {
|
|
$search_filter_array = array();
|
|
}
|
|
|
|
$lv_filter = getReqVal('lv_filter', 15);
|
|
$account = '0x9a4d9dd2bfcad659975f0f5a480625c7929e9385';
|
|
|
|
$rows = $this->getNftListByAccountAndType($account, $type, $order_method, $order_asc, $job_filter_array, $search_filter_array, $lv_filter);
|
|
|
|
$total = count($rows);
|
|
$page_end = $start + $page_size;
|
|
if ($page_end > $total) {
|
|
$page_end = $total;
|
|
$start = $total-1;
|
|
$start = intval($start / $page_size) * $page_size;
|
|
if ($start<0) $start = 0;
|
|
}
|
|
|
|
$nfts = array();
|
|
for ($x = $start; $x < $page_end; $x++) {
|
|
$row = $rows[$x];
|
|
array_push($nfts, $row);
|
|
}
|
|
|
|
$this->_rspData(array(
|
|
"total" => count($rows),
|
|
"start" => $start,
|
|
"page_size" => $page_size,
|
|
'nfts' => $nfts,
|
|
));
|
|
}
|
|
|
|
public function sellMyNft() {
|
|
|
|
$account = getReqVal('account', '');
|
|
$token = getReqVal('token', '');
|
|
$nft_token = getReqVal('nft_token', '');
|
|
$s_price = getReqVal('s_price', '');
|
|
$payment_token_address = getReqVal('payment_token_address', '');
|
|
$nonce = getReqVal('nonce', '');
|
|
$signature = getReqVal('signature', '');
|
|
$net_id = getReqVal('net_id', '');
|
|
|
|
$account = '0x9a4d9dd2bfcad659975f0f5a480625c7929e9385';
|
|
|
|
$conn = myself()->_getMysql('');
|
|
|
|
$nft = Nft::findNftByOwner($account, $nft_token);
|
|
$nftDetail = Nft::toDto($nft);
|
|
$r = SqlHelper::insert(
|
|
$conn,
|
|
't_market_store',
|
|
array(
|
|
'token_id' => $nft_token,
|
|
'owner_address' => $nftDetail['owner_address'],
|
|
'token_type' => $nftDetail['type'],
|
|
'createtime' => myself()->_getNowTime(),
|
|
'modifytime' => myself()->_getNowTime(),
|
|
's_price' => $s_price,
|
|
'c_name' => $nftDetail['info']['name'],
|
|
'c_job' => isset($nftDetail['info']['job']) ? $nftDetail['info']['job'] : -1,
|
|
'c_lv' => isset($nftDetail['info']['level']) ? $nftDetail['info']['level'] : -1,
|
|
'c_id' => $nftDetail['item_id'],
|
|
)
|
|
);
|
|
$this->_rspOk();
|
|
}
|
|
|
|
public function buyNft() {
|
|
$account = getReqVal('account', '');
|
|
$token = getReqVal('token', '');
|
|
$nft_token = getReqVal('nft_token', '');
|
|
$payment_token_address = getReqVal('payment_token_address', '');
|
|
$nonce = getReqVal('nonce', '');
|
|
$signature = getReqVal('signature', '');
|
|
$net_id = getReqVal('net_id', '');
|
|
|
|
$conn = myself()->_getMysql('');
|
|
$conn->execScript('DELETE FROM t_market_store WHERE '.'token_id=\''.$nft_token.'\'');
|
|
|
|
$this->_rspOk();
|
|
}
|
|
|
|
}
|