167 lines
5.2 KiB
PHP
167 lines
5.2 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;
|
|
}
|
|
|
|
public static function getList($type=null){
|
|
$itemList = array();
|
|
$fragmentItem = self::getFragmentItem();
|
|
$list1 = $fragmentItem['all'];
|
|
$list2 = $fragmentItem['hero'];
|
|
$list3 = $fragmentItem['gun'];
|
|
switch ($type){
|
|
case 1:{
|
|
Bag::getItemList(function ($row) use(&$itemList,$list2) {
|
|
if (in_array($row['item_id'],$list2) && $row['item_num'] > 0) {
|
|
array_push($itemList, $row);
|
|
}
|
|
});
|
|
}
|
|
break;
|
|
case 2:{
|
|
Bag::getItemList(function ($row) use(&$itemList,$list3) {
|
|
if (in_array($row['item_id'],$list3) && $row['item_num'] > 0) {
|
|
array_push($itemList, $row);
|
|
}
|
|
});
|
|
}
|
|
break;
|
|
default:{
|
|
Bag::getItemList(function ($row) use(&$itemList,$list1) {
|
|
if (in_array($row['item_id'],$list1) && $row['item_num'] > 0) {
|
|
array_push($itemList, $row);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
return $itemList;
|
|
}
|
|
|
|
public static function getFragmentItem(){
|
|
$itemMetas = mt\Item::getMetaListByType(mt\Item::FRAGMENT_TYPE);
|
|
$list1 = array();
|
|
$list2 = array();
|
|
$list3 = array();
|
|
foreach ($itemMetas as $meta ){
|
|
array_push($list1,$meta['id']);
|
|
if ($meta['sub_type'] == mt\Item::HERO_FRAGMENT_SUBTYPE){
|
|
array_push($list2,$meta['id']);
|
|
}else if ($meta['sub_type'] == mt\Item::GUN_FRAGMENT_SUBTYPE){
|
|
array_push($list3,$meta['id']);
|
|
}
|
|
}
|
|
return array(
|
|
'all'=>$list1,
|
|
'hero'=>$list2,
|
|
'gun'=>$list3,
|
|
);
|
|
}
|
|
|
|
public static function isSatisfy(){
|
|
$data = array(
|
|
'hero' => 0,
|
|
'gun' => 0,
|
|
);
|
|
$heroFragmentList = self::getList(1);
|
|
$heroFragmentListPro = array();
|
|
foreach ($heroFragmentList as $value){
|
|
array_push($heroFragmentListPro,$value['item_id']);
|
|
}
|
|
$fragmentItem = self::getFragmentItem();
|
|
$heroFragmentItem = $fragmentItem['hero'];
|
|
$heroDiff = array_diff($heroFragmentItem,$heroFragmentListPro);
|
|
if (empty($heroDiff)){
|
|
$data['hero'] = 1;
|
|
}
|
|
$gunFragmentList = self::getList(2);
|
|
$gunFragmentListPro = array();
|
|
foreach ($gunFragmentList as $value){
|
|
array_push($gunFragmentListPro,$value['item_id']);
|
|
}
|
|
$gunFragmentItem = $fragmentItem['gun'];
|
|
$gunDiff = array_diff($gunFragmentItem,$gunFragmentListPro);
|
|
if (empty($gunDiff)){
|
|
$data['gun'] = 1;
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
|
|
}
|