获取碎片列表

This commit is contained in:
hujiabin 2022-11-03 20:19:13 +08:00
parent a50a11aaff
commit a0a5557663
3 changed files with 38 additions and 125 deletions

View File

@ -225,23 +225,6 @@ CREATE TABLE `t_bag` (
-- Table structure for table `t_bag`
--
DROP TABLE IF EXISTS `t_fragment`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `t_fragment` (
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
`token_id` varchar(60) COMMENT 'token_id',
`item_id` int(11) NOT NULL DEFAULT '0' COMMENT '道具id',
`type` int(11) NOT NULL DEFAULT '1' COMMENT '1:角色碎片 2:武器碎片 3:角色特殊碎片 4:武器特殊碎片',
`parts` int(11) NOT NULL DEFAULT '1' COMMENT '部位',
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
PRIMARY KEY (`idx`),
UNIQUE KEY `token_id` (`token_id`),
KEY `item_id` (`item_id`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `t_chip`
--
@ -268,6 +251,7 @@ CREATE TABLE `t_chip` (
`strength_max` varchar(10) NOT NULL DEFAULT '0' COMMENT '最大体力值',
`strength` varchar(10) NOT NULL DEFAULT '0' COMMENT '前一天体力值',
`upgrade_mint` double NOT NULL DEFAULT '0' COMMENT 'mint费用',
`activate` int(11) NOT NULL DEFAULT '0' COMMENT '是否激活 1已初始激活',
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
`labour` int(11) NOT NULL DEFAULT '0' COMMENT '劳力值',

View File

@ -18,31 +18,12 @@ class FragmentController extends BaseAuthedController
public function fragmentList()
{
$type = getReqVal('type','');
if (! $type || !in_array($type,[1,2])){
$this->_rspErr(1,'type parameter error');
return ;
$fragmentList = array();
foreach (Fragment::getFragmentList() as $val){
array_push($fragmentList,Fragment::oldToDto($val));
}
$fragmentList = [];
Fragment::getFragmentList(function ($row) use(&$fragmentList,$type) {
switch ($type){
case 1:
{
if ( $row['type'] == 1 || $row['type'] == 3){
array_push($fragmentList, $row);
}
}
break;
case 2:
{
if ( $row['type'] == 2 || $row['type'] == 4){
array_push($fragmentList, $row);
};
}
}
});
$this->_rspData(array(
'fragment_list' => $fragmentList
'data' => $fragmentList,
));
}

View File

@ -13,95 +13,43 @@ 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
)
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(),
);
foreach ($nft as $nftDb) {
$row = SqlHelper::ormSelectOne(
myself()->_getSelfMysql(),
't_fragment',
array(
'token_id' => $nftDb['token_id'],
)
$fragmentNft = myself()->_getMarketMysql()->execQuery($sql,$whereKv);
return $fragmentNft;
}
public static function ToDto($row){
$dto = array(
// 'owner_address' => $row['owner_address'],
'token_id' => $row['token_id'],
'item_id' => $row['item_id'],
'balance' => $row['balance'],
'createtime' => $row['createtime'],
'modifytime' => $row['modifytime'],
);
return $dto;
}
public static function oldToDto($row){
$itemMeta = mt\Item::get($row['item_id']);
$dto = array();
if ($itemMeta){
$dto = array(
'token_id' => $row['token_id'],
'item_id' => $row['item_id'],
'type' => $itemMeta['sub_type'],
'parts' => substr($itemMeta['id'],-2,1),
'balance' => $row['balance'],
'createtime' => $row['createtime'],
'modifytime' => $row['modifytime'],
);
// if (!$row) {
// $itemMeta = mt\Item::get($nftDb['item_id']);
// if ($itemMeta) {
// self::addFragment($itemMeta, $nftDb['token_id']);
// $row = SqlHelper::ormSelectOne(
// myself()->_getSelfMysql(),
// 't_fragment',
// array(
// 'token_id' => $nftDb['token_id'],
// )
// );
// }
// }
if ($row) {
$cb($row);
}
}
return $dto;
}
public static function addFragment($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]
// );
// }
}