game2006api/webapp/models/Fragment.php
hujiabin 83668e039b 1
2022-12-15 14:58:43 +08:00

84 lines
2.4 KiB
PHP

<?php
namespace models;
require_once('services/NftService.php');
require_once('mt/Item.php');
use mt;
use phpcommon\SqlHelper;
use services\NftService;
class Fragment extends BaseModel
{
public static function getFragmentList() {
$sql = "select * from t_nft1155 where owner_address=:owner_address and token_id<10000000 and balance>0";
$whereKv =array(
'owner_address' => myself()->_getOpenId(),
);
$fragmentNft = myself()->_getMarketMysql()->execQuery($sql,$whereKv);
return $fragmentNft;
}
public static function ToDto($row){
$itemMeta = mt\Item::get($row['token_id']);
$name = 'XXX';
$type=0;
if ($itemMeta && $itemMeta['type'] == mt\Item::FRAGMENT_TYPE){
$name = $itemMeta['name'];
switch ($itemMeta['sub_type']){
case 1 :
$type=1;
break;
case 2 :
$type = 2;
break;
case 3 :
$type=1;
break;
case 4 :
$type=2;
break;
default:$type=0;
}
}
$dto = array(
// 'owner_address' => $row['owner_address'],
'token_id' => $row['token_id'],
'item_id' => $row['token_id'],
'balance' => $row['balance'],
'createtime' => $row['createtime'],
'modifytime' => $row['modifytime'],
);
$nft_address = '';
if ($row['token_id']){
$nft_address = SERVER_ENV == _ONLINE ? '0xFc21A863bFb4E4534B246078772e2074e076f0a7' : '0x0E696947A06550DEf604e82C26fd9E493e576337';
}
$dto['nft_address'] = $nft_address;
$dto['name'] = $name;
$dto['type'] = $type;
return $dto;
}
public static function oldToDto($row){
$itemMeta = mt\Item::get($row['token_id']);
$dto = array();
if ($itemMeta){
$dto = array(
'token_id' => $row['token_id'],
'item_id' => $row['token_id'],
'type' => $itemMeta['sub_type'],
'parts' => substr($itemMeta['id'],-2,1),
'balance' => $row['balance'],
'createtime' => $row['createtime'],
'modifytime' => $row['modifytime'],
);
}
return $dto;
}
}