game2006api/webapp/models/Fragment.php
2022-09-09 20:44:18 +08:00

108 lines
2.7 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($cb){
$nft = SqlHelper::ormSelect(
myself()->_getMarketMysql(),
't_nft',
array(
'owner_address' => myself()->_getOpenId(),
'token_type' =>Nft::FRAGMENT_TYPE,
'deleted' => 0
)
);
// print_r($nft);die;
foreach ($nft as $nftDb) {
$row = SqlHelper::ormSelectOne(
myself()->_getSelfMysql(),
't_fragment',
array(
'token_id' => $nftDb['token_id'],
)
);
if (!$row) {
$itemMeta = mt\Item::get($nftDb['item_id']);
if ($itemMeta) {
self::addNftHero($itemMeta, $nftDb['token_id']);
$row = SqlHelper::ormSelectOne(
myself()->_getSelfMysql(),
't_fragment',
array(
'token_id' => $nftDb['token_id'],
)
);
}
}
if ($row) {
$cb($row);
}
}
}
public static function addNftHero($fragmentMeta, $tokenId)
{
return self::internalAddHero(
myself()->_getMysql($tokenId),
$fragmentMeta,
null,
$tokenId);
}
public static function internalAddHero($conn, $fragmentMeta, $accountId, $tokenId)
{
$fieldsKv = array(
'item_id' => $fragmentMeta['id'],
'type' => $fragmentMeta['sub_type'],
'parts' => substr($fragmentMeta['id'],-2,1),
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
);
if ($accountId) {
$fieldsKv['account_id'] = $accountId;
}
if ($tokenId) {
$fieldsKv['token_id'] = $tokenId;
}
SqlHelper::insert(
myself()->_getSelfMysql(),
't_fragment',
$fieldsKv
);
}
public static function getFragmentByIdx($idx){
return SqlHelper::ormSelectOne(
myself()->_getSelfMysql(),
't_fragment',
array(
'idx' => $idx,
)
);
}
public static function deleteFragment($whereKv){
SqlHelper::update(
myself()->_getMarketMysql(),
't_nft',
$whereKv,
['deleted'=>1]
);
}
}