0 && $row['chip_type'] == $type) { array_push($chipList, $row); } }); return $chipList; } public static function getChipList($cb) { $nft = SqlHelper::ormSelect( myself()->_getMarketMysql(), 't_nft', array( 'owner_address' => myself()->_getOpenId(), 'token_type' =>3, 'deleted' => 0 ) ); foreach ($nft as $nftDb) { $row = SqlHelper::ormSelectOne( myself()->_getSelfMysql(), 't_chip', array( 'token_id' => $nftDb['token_id'], ) ); if (!$row) { $itemMeta = mt\Item::get($nftDb['item_id']); if ($itemMeta) { self::addChip($nftDb['item_id'], $nftDb['token_id']); $row = SqlHelper::ormSelectOne( myself()->_getSelfMysql(), 't_chip', array( 'token_id' => $nftDb['token_id'], ) ); } } if ($row) { $cb($row); } } } public static function toDto($row) { $todayGetGold = $row['today_get_gold']; $lastGetGoldTime = $row['last_get_gold_time']; if (myself()->_getDaySeconds($lastGetGoldTime) > myself()->_getNowDaySeconds()) { $todayGetGold = 0; } $attr_pool = emptyReplace(json_decode($row['rand_attr'], true), array()); $attrs = array(); foreach ($attr_pool as $key=>$val){ $attr = mt\ChipAttr::getAttrById($val['attr_id'],$val['attr_type']); $newAttr = [ 'attr_id' => $attr['attr_id'], 'type' => 2, 'val' => $attr['lv'.$row['chip_grade']]*$val['attr_pool_number'], // 'chip_name' => $attr['chip_name'], 'chip_type' => $attr['chip_type'], 'attr_num' => $attr['lv'.$row['chip_grade']], 'attr_pool_num' => $val['attr_pool_number'], ]; array_push($attrs,$newAttr); } $row['rand_attr'] = $attrs; $row['today_get_gold'] = $todayGetGold; $row['last_get_gold_time'] = $lastGetGoldTime; return $row; } public static function addChip($itemId, $tokenId) { return self::internalAddItem( myself()->_getMysql($tokenId), $itemId, 1, null, $tokenId); } public static function internalAddItem($conn, $itemId, $itemNum, $accountId, $tokenId) { $grade = rand(1,4);//随机一个等级 if (myself()->_isVirtualItem($itemId)) { return; } if ($itemNum <= 0) { return; } $itemMeta = mt\Item::get($itemId); if (!$itemMeta) { return; } $randAttr = array(); if (mt\Item::isRoleChipItem($itemMeta)) { $randAttr = mt\ChipAttr::generateAttrRandom($itemMeta,$grade); } if (mt\Item::isGunChipItem($itemMeta)) { $randAttr = mt\ChipAttr::generateAttrRandom($itemMeta,$grade); } $fieldsKv = array( 'account_id' => myself()->_getAccountId(), 'item_id' => $itemId, 'item_num' => 1, 'rand_attr' => json_encode($randAttr), 'chip_grade' => $grade, 'chip_type' => $itemMeta['sub_type'], 'createtime' => myself()->_getNowTime(), 'modifytime' => myself()->_getNowTime() ); if ($accountId) { $fieldsKv['account_id'] = $accountId; } if ($tokenId) { $fieldsKv['token_id'] = $tokenId; } SqlHelper::insert ($conn, 't_chip', $fieldsKv ); } public static function getChipByTokenId($token_ids){ return SqlHelper::ormSelectOne( myself()->_getSelfMysql(), 't_chip', array( 'token_id' => $token_ids, ) ); } public static function getChipByIdx($idx){ return SqlHelper::ormSelectOne( myself()->_getSelfMysql(), 't_chip', array( 'idx' => $idx, ) ); } public static function update($token_id, $fieldsKv){ SqlHelper::update (myself()->_getSelfMysql(), 't_chip', array( 'token_id' => $token_id, ), $fieldsKv ); } public static function updateChipInlayState($token_id,$state){ return SqlHelper::update( myself()->_getSelfMysql(), 't_chip', ['token_id' => $token_id], ['inlay_state'=>$state] ); } public static function getChipInlay($type){ return SqlHelper::ormSelect( myself()->_getSelfMysql(), 't_chip', array( 'chip_type' => $type, 'supper_state' => 0, 'inlay_state' => 0, ) ); } public static function deleteChip($whereKv){ SqlHelper::update( myself()->_getMarketMysql(), 't_nft', $whereKv, ['deleted'=>1] ); } public static function updateRandAttr($chip){ $attr_pool = mt\ChipAttr::generateOneAttr($chip['chip_type']); $rand_attr = emptyReplace(json_decode($chip['rand_attr'], true), array()); array_push($rand_attr,$attr_pool); $fieldsKv = [ 'rand_attr'=>json_encode($rand_attr) ]; self::update($chip['token_id'],$fieldsKv); } }