216 lines
10 KiB
PHP
216 lines
10 KiB
PHP
<?php
|
|
|
|
namespace services;
|
|
|
|
require_once('mt/MarketGoods.php');
|
|
require_once('mt/MarketBatch.php');
|
|
require_once('mt/Item.php');
|
|
require_once('mt/BlindBox.php');
|
|
require_once('mt/WhiteList.php');
|
|
require_once('mt/Currency.php');
|
|
require_once('mt/Hero.php');
|
|
require_once('mt/Parameter.php');
|
|
require_once('mt/StrHelper.php');
|
|
require_once('mt/AttrHelper.php');
|
|
|
|
require_once('models/BoxOrder.php');
|
|
require_once('models/Nft.php');
|
|
require_once('models/BuyRecord.php');
|
|
|
|
|
|
require_once('phpcommon/bchelper.php');
|
|
|
|
use phpcommon;
|
|
use phpcommon\SqlHelper;
|
|
use models\BoxOrder;
|
|
use models\Nft;
|
|
use models\BuyRecord;
|
|
use mt;
|
|
use mt\StrHelper;
|
|
use mt\AtrrHelper;
|
|
|
|
class MarketService extends BaseService {
|
|
|
|
public static function getNftListByAccountAndType($account, $type, $order_method, $order_asc, $job, $search, $lv, $quality, $durability)
|
|
{
|
|
$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::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));
|
|
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 (!empty($job)) {
|
|
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::EQUIP_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'] = 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) {
|
|
$searchLower = array_map('strtolower', $search);
|
|
if (!(in_array(strtolower($row['detail']['gun_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, $sortByGunLv);
|
|
break;
|
|
case 2:
|
|
usort($nfts, $sortByDurability);
|
|
break;
|
|
case 3:
|
|
usort($nfts, $sortByStar);
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
case Nft::CHIP_TYPE: {
|
|
$rows = Nft::getNft1155List($account, $type);
|
|
$rows = array_merge($rows, $this->listMySelledNfts($account, $type));
|
|
foreach ($rows as &$row) {
|
|
$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) {
|
|
$searchLower = array_map('strtolower', $search);
|
|
if (!(in_array(strtolower($row['detail']['chip_name']), $searchLower) || in_array(strtolower($row['detail']['token_id']), $searchLower))) 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);
|
|
$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['detail'] = $this->getNftGameData($nftDb);
|
|
if (!in_array($row['detail']['type'], $job))
|
|
continue;
|
|
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;
|
|
}
|
|
array_push($nfts, $row);
|
|
}
|
|
usort($nfts, $sortByTokenId);
|
|
}
|
|
break;
|
|
default: {
|
|
}
|
|
}
|
|
return $nfts;
|
|
}
|
|
|
|
}
|