286 lines
9.3 KiB
PHP
286 lines
9.3 KiB
PHP
<?php
|
|
|
|
require_once('mt/Item.php');
|
|
require_once('mt/Hero.php');
|
|
require_once('mt/Parameter.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/BcOrder.php');
|
|
|
|
require_once('services/BlockChainService.php');
|
|
require_once('services/LogService.php');
|
|
|
|
require_once('phpcommon/bchelper.php');
|
|
|
|
use models\BcOrder;
|
|
use phpcommon\SqlHelper;
|
|
use models\Nft;
|
|
use models\Hero;
|
|
use models\Gun;
|
|
use models\Chip;
|
|
use models\Fragment;
|
|
use models\Transaction;
|
|
use services\LogService;
|
|
|
|
class MarketController extends BaseAuthedController {
|
|
|
|
public function listSellNfts()
|
|
{
|
|
$account = strtolower(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', 0);
|
|
$quality_filter = getReqVal('quality_filter', 0);
|
|
$durability_filter = getReqVal('durability_filter', 0);
|
|
$amount_filter = getReqVal('amount_filter', 0);
|
|
$amount_filter_array = explode('|', $amount_filter);
|
|
$price_filter = getReqVal('price_filter', '');
|
|
$price_filter_array = explode('|', $price_filter);
|
|
|
|
$job_filter_fn = function ($f) {
|
|
$str = '';
|
|
$arr = array();
|
|
foreach ($f as $v) {
|
|
if (!empty($v)) {
|
|
array_push($arr, 'c_job=\'' . $v . '\' ');
|
|
}
|
|
}
|
|
if (count($arr) > 0) {
|
|
$str = implode('OR ', $arr);
|
|
$str = 'AND (' . $str . ') ';
|
|
}
|
|
return $str;
|
|
};
|
|
$price_filter_fn = function ($f) {
|
|
if (count($f) == 2) {
|
|
$low = $f[0];
|
|
$top = $f[1];
|
|
return 'AND s_price>=' . $low . ' AND s_price<=' . $top . ' ';
|
|
}
|
|
return '';
|
|
};
|
|
$amount_filter_fn = function ($f) {
|
|
if (count($f) == 2) {
|
|
$low = $f[0];
|
|
$top = $f[1];
|
|
return 'AND amount>=' . $low . ' AND amount<=' . $top . ' ';
|
|
}
|
|
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) {
|
|
$str = '';
|
|
$arr_options = array();
|
|
foreach ($f as $v) {
|
|
if (!empty($v)) {
|
|
array_push($arr_options, 'c_name=\'' . $v . '\' OR token_id=\'' . $v . '\' ');
|
|
}
|
|
}
|
|
if (count($arr_options) > 0) {
|
|
$str = implode('OR ', $arr_options);
|
|
$str = 'AND (' . $str . ') ';
|
|
}
|
|
return $str;
|
|
};
|
|
|
|
$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()->_getSelfMysql();
|
|
|
|
$counts = $conn->execQuery(
|
|
'SELECT count(idx) 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) .
|
|
$amount_filter_fn($amount_filter_array) .
|
|
$search_filter_fn($search_filter_array) .
|
|
$order_fn($order_method, $order_asc),
|
|
array(
|
|
':token_type' => $type,
|
|
)
|
|
);
|
|
|
|
$total = $counts[0]['count'];
|
|
$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;
|
|
}
|
|
|
|
$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) .
|
|
$amount_filter_fn($amount_filter_array) .
|
|
$search_filter_fn($search_filter_array) .
|
|
$order_fn($order_method, $order_asc) .
|
|
'LIMIT ' . $start . ',' . $page_size,
|
|
array(
|
|
':token_type' => $type,
|
|
)
|
|
);
|
|
|
|
$nfts = array();
|
|
|
|
for ($x = $start; $x < $page_end; $x++) {
|
|
$row = $rows[$x % $page_size];
|
|
$nftDb = Nft::getNft($row['token_id']);
|
|
if (!$nftDb) {
|
|
$nftDb = Nft::findNftByOwner($account, $row['token_id']);
|
|
// 0x768b5faed6dc69816f33377d214ffaf00dcdd0cf
|
|
if (!$nftDb) {
|
|
$nftDb = Nft::findNftByOwner('0xfc628dd79137395f3c9744e33b1c5de554d94882', $row['token_id']);
|
|
if (!$nftDb) {
|
|
if ($row['item_id']) {
|
|
} else {
|
|
myself()->_rspErr(1, 'nft not exists');
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$row['info'] = $nftDb ? Nft::toDto($nftDb) : null;
|
|
$row['detail'] = $nftDb ? $this->getNftGameData($nftDb) : null;
|
|
array_push($nfts, $row);
|
|
}
|
|
|
|
$this->_rspData(array(
|
|
"total" => $total,
|
|
"start" => $start,
|
|
"page_size" => $page_size,
|
|
'nfts' => $nfts,
|
|
));
|
|
}
|
|
|
|
public function listMyNfts()
|
|
{
|
|
$address = $this->_getAddress();
|
|
if (empty($address)) {
|
|
myself()->_rspData(array(
|
|
'total' => 0,
|
|
'start' => 0,
|
|
'page_size' => 0,
|
|
'nfts' => array()
|
|
));
|
|
return;
|
|
}
|
|
$start = getReqVal('start', 0);
|
|
$pageSize = getReqVal('page_size', 10);
|
|
$orderMethod = getReqVal('order_method', 0);
|
|
$orderAsc = getReqVal('order_asc', 1);
|
|
$type = getReqVal('type', 1);
|
|
$jobFilters = getReqVal('job_filters', '');
|
|
|
|
if (empty($jobFilters)) {
|
|
$jobFilterArray = array();
|
|
} else {
|
|
$jobFilterArray = explode('|', $jobFilters);
|
|
}
|
|
|
|
$searchFilters = getReqVal('search_filters', '');
|
|
if ($searchFilters != '') {
|
|
$searchFilterArray = explode('|', $searchFilters);
|
|
} else {
|
|
$searchFilterArray = array();
|
|
}
|
|
|
|
$lvFilter = getReqVal('lv_filter', 0);
|
|
$qualityFilter = getReqVal('quality_filter', 0);
|
|
$durabilityFilter = getReqVal('durability_filter', 0);
|
|
|
|
$rows = $this->getNftListByAccountAndType(
|
|
$account,
|
|
$type,
|
|
$orderMethod,
|
|
$orderAsc,
|
|
$jobFilterArray,
|
|
$searchFilterArray,
|
|
$lvFilter,
|
|
$qualityFilter,
|
|
$durabilityFilter);
|
|
|
|
$total = count($rows);
|
|
$pageEnd = $start + $pageSize;
|
|
if ($pageEnd > $total) {
|
|
$pageEnd = $total;
|
|
$start = $total - 1;
|
|
$start = intval($start / $pageSize) * $pageSize;
|
|
if ($start < 0) $start = 0;
|
|
}
|
|
|
|
$nfts = array();
|
|
for ($x = $start; $x < $pageEnd; $x++) {
|
|
$row = $rows[$x];
|
|
// $this->attach_market_selling($row);
|
|
array_push($nfts, $row);
|
|
}
|
|
|
|
$this->_rspData(array(
|
|
"total" => $total,
|
|
"start" => $start,
|
|
"page_size" => $pageSize,
|
|
'nfts' => $nfts,
|
|
));
|
|
}
|
|
|
|
}
|