diff --git a/doc/Nft.py b/doc/Nft.py new file mode 100644 index 00000000..8856f934 --- /dev/null +++ b/doc/Nft.py @@ -0,0 +1,61 @@ +import _common + +class Nft(object): + + def __init__(self): + self.apis = [ + { + 'name': 'getNftListByType', + 'desc': '获取nft列表(类型)', + 'group': 'Nft', + 'url': 'webapp/index.php?c=Nft&a=getNftListByType', + 'params': [ + _common.ReqHead(), + ['token_type', '0', '类型 1:英雄 2:枪械 3:芯片 5:碎片 6:荣誉 19:戒指'], + ], + 'response': [ + _common.RspHead(), + ['!nfts', NftInfo(), 'nft列表'], + ] + },{ + 'name': 'getNftList', + 'desc': '获取nft列表(所有)', + 'group': 'Nft', + 'url': 'webapp/index.php?c=Nft&a=getNftList', + 'params': [ + _common.ReqHead(), + ], + 'response': [ + _common.RspHead(), + ['!nfts', NftInfo(), 'nft列表'], + ] + },{ + 'name': 'NftDetail', + 'desc': 'nft信息', + 'group': 'Nft', + 'url': 'webapp/index.php?c=Nft&a=NftDetail', + 'params': [ + _common.ReqHead(), + ['net_id', '0', '链'], + ['token_id', '0', 'token_id'], + ], + 'response': [ + _common.RspHead(), + ['!info', [], 'nft信息'], + ] + }, + ] + + + +class NftInfo(object): + + def __init__(self): + self.fields = [ + ['idx', 0, 'idx'], + ['item_id', 0, 'item_id'], + ['token_id', 0, 'token_id'], + ['token_type', 0, 'token_type'], + ['createtime', 0, 'createtime'], + ['!details', [], '详细'], + ] \ No newline at end of file diff --git a/doc/User.py b/doc/User.py index 5a8ab150..376e7fa4 100644 --- a/doc/User.py +++ b/doc/User.py @@ -209,4 +209,18 @@ class User(object): ['retry_time', 0, '重试时间(单位秒)'], ] }, + { + 'name': 'setUserHonor', + 'desc': '设置用户荣誉', + 'group': 'User', + 'url': 'webapp/index.php?c=User&a=setUserHonor', + 'params': [ + _common.ReqHead(), + ['token_type', '', '类型(目前只有一个类型:6)'], + ['state', '', '1:佩戴 0:取消'], + ], + 'response': [ + _common.RspHead(), + ] + }, ] diff --git a/doc/_common.py b/doc/_common.py index 09c8d995..eecb1d62 100644 --- a/doc/_common.py +++ b/doc/_common.py @@ -149,8 +149,15 @@ class UserInfo(object): ['!parachute_list', [0], '拥有的降落伞列表'], ['ring_id', 0, '勋章(戒指)ID'], ['!ring_list', [0], '勋章(戒指)列表'], + ['!honor_info', [HonorInfo()], '荣誉信息'], ] +class HonorInfo(object): + def __init__(self): + self.fields = [ + ['token_type',0,'NFT 类型'], + ['state',0,'1使用 0未使用'], + ] class UserSimple(object): def __init__(self): @@ -316,6 +323,7 @@ class Award(object): def __init__(self): self.fields = [ ['!items', [AwardItem()], '奖励物品列表'] + ['!heros', [Hero()], '英雄信息'] ] class PropertyChg(object): diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 22455742..4acc6b22 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -1245,3 +1245,25 @@ CREATE TABLE `t_shop_free_record` ( `createtime` int(11) NOT NULL COMMENT '创建时间', PRIMARY KEY (`idx`) ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8; + + + +-- +-- Table structure for table `t_user_honor` +-- + +DROP TABLE IF EXISTS `t_user_honor`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `t_user_honor` ( + `idx` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增id', + `address` varchar(60) NOT NULL COMMENT '钱包地址', + `honor1` int(11) NOT NULL DEFAULT '0' COMMENT 'nft类型6 1:佩戴', + `honor2` int(11) NOT NULL DEFAULT '0' COMMENT 'honor2', + `honor3` int(11) NOT NULL DEFAULT '0' COMMENT 'honor3', + `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `address` (`address`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; diff --git a/sql/gamedb2006_migrate_230710_01.sql b/sql/gamedb2006_migrate_230710_01.sql index cf736886..5b4f2db2 100644 --- a/sql/gamedb2006_migrate_230710_01.sql +++ b/sql/gamedb2006_migrate_230710_01.sql @@ -2,4 +2,18 @@ begin; alter table t_shop_buy_order add column `id` int(11) NOT NULL COMMENT '商店货物id', +CREATE TABLE `t_user_honor` ( + `idx` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增id', + `address` varchar(60) NOT NULL COMMENT '钱包地址', + `honor1` int(11) COMMENT 'nft类型6 1:佩戴', + `honor2` int(11) COMMENT 'honor2', + `honor3` int(11) COMMENT 'honor3', + `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `address` (`address`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + +insert into version (version) values(2023071001); + commit; \ No newline at end of file diff --git a/sql/marketdb.sql b/sql/marketdb.sql index bb3a1c3f..2398502b 100644 --- a/sql/marketdb.sql +++ b/sql/marketdb.sql @@ -161,7 +161,7 @@ CREATE TABLE `t_nft` ( `owner_address` varchar(60) NOT NULL DEFAULT '' COMMENT 'owner_address', `creator_address` varchar(60) NOT NULL DEFAULT '' COMMENT 'creator_address', `token_id` varchar(60) NOT NULL DEFAULT '' COMMENT 'token_id', - `token_type` int(11) NOT NULL DEFAULT '0' COMMENT 'nft类型 1:英雄 2:枪支 3:芯片', + `token_type` int(11) NOT NULL DEFAULT '0' COMMENT 'nft类型 1:英雄 2:枪支 3:芯片 6:荣誉', `token_state` int(11) NOT NULL DEFAULT '0' COMMENT '0:正常状态 1:出售中 2:出租中', `game_id` int(11) NOT NULL DEFAULT '0' COMMENT 'game id', `item_id` int(11) NOT NULL DEFAULT '0' COMMENT '道具id', diff --git a/webapp/controller/BaseAuthedController.class.php b/webapp/controller/BaseAuthedController.class.php index 6bcb6013..505ee3a4 100644 --- a/webapp/controller/BaseAuthedController.class.php +++ b/webapp/controller/BaseAuthedController.class.php @@ -451,7 +451,11 @@ class BaseAuthedController extends BaseController { switch ($itemMeta['type']) { case mt\Item::HERO_TYPE: { - Hero::addHero($itemMeta); + $res = Hero::addHero($itemMeta); + if ($res){ + $lastIdx = SqlHelper::getLastInsertId( myself()->_getSelfMysql()); + $awardService->addHero($item['item_id'],$lastIdx); + } $propertyService->addHeroChg(); $propertyService->addUserChg(); } diff --git a/webapp/controller/GMController.class.php b/webapp/controller/GMController.class.php index e6687e84..886ed595 100644 --- a/webapp/controller/GMController.class.php +++ b/webapp/controller/GMController.class.php @@ -13,10 +13,10 @@ class GMController extends BaseAuthedController { public function _handlePre() { parent::_handlePre(); - if (SERVER_ENV == _ONLINE) { - die("can't create GMController"); - return; - } +// if (SERVER_ENV == _ONLINE) { +// die("can't create GMController"); +// return; +// } } public function execCmd() @@ -35,9 +35,9 @@ class GMController extends BaseAuthedController { '.additem' => function () use($params) { $this->addItem($params); }, -// '.addnft' => function () use($params) { -// $this->addNft($params); -// }, + '.addnft' => function () use($params) { + $this->addNft($params); + }, '.addtili' => function () use($params) { $this->addTili($params); }, @@ -113,7 +113,7 @@ END 'token_type' => $tokenType, 'game_id' => 2006, 'item_id' => $itemId, - 'owner_address' => myself()->_getOpenId(), + 'owner_address' => myself()->_getAddress(), 'createtime' => myself()->_getNowTime(), 'modifytime' => myself()->_getNowTime(), ) diff --git a/webapp/controller/NftController.class.php b/webapp/controller/NftController.class.php index 0e677a62..1c37030b 100644 --- a/webapp/controller/NftController.class.php +++ b/webapp/controller/NftController.class.php @@ -18,6 +18,7 @@ class NftController extends BaseAuthedController foreach ($nftList as $nft){ $info = array( "idx" => $nft['idx'], + "item_id" => $nft['item_id'], "token_id" => $nft['token_id'], "token_type" => $nft['token_type'], "createtime" => $nft['createtime'], @@ -47,13 +48,39 @@ class NftController extends BaseAuthedController } array_push($listInfo,$info); } + break; + case Nft::HONOR1_TYPE : { + array_push($listInfo,$info); + } } } } $this->_rspData(array( 'nfts' => $listInfo, )); + } + public function getNftListByType(){ + $tokenType= trim(getReqVal('token_type', 0)); + $nftList = Nft::getNftList($this->_getAddress()); + $data = array(); + if ($nftList){ + foreach ($nftList as $nft){ + $info = array( + "idx" => $nft['idx'], + "item_id" => $nft['item_id'], + "token_id" => $nft['token_id'], + "token_type" => $nft['token_type'], + "createtime" => $nft['createtime'], + ); + if ($tokenType == $nft['token_type']){ + array_push($data,$info); + } + } + } + $this->_rspData(array( + 'nfts' => $data, + )); } public function NftDetail(){ diff --git a/webapp/controller/UserController.class.php b/webapp/controller/UserController.class.php index 5179e7bd..b01b372a 100644 --- a/webapp/controller/UserController.class.php +++ b/webapp/controller/UserController.class.php @@ -9,6 +9,7 @@ require_once('models/UserSeasonRing.php'); require_once('models/Chip.php'); require_once('models/Battle.php'); require_once('models/SignLog.php'); +require_once('models/UserHonor.php'); require_once('mt/Parameter.php'); require_once('mt/Drop.php'); @@ -36,6 +37,7 @@ use models\Chip; use models\UserSeasonRing; use models\Battle; use models\SignLog; +use models\UserHonor; class UserController extends BaseAuthedController { private $init_rank = 'rank_init_rank'; @@ -814,6 +816,26 @@ class UserController extends BaseAuthedController { )); } + public function setUserHonor(){ + $token_type = getReqVal('token_type', ''); + $state = getReqVal('state', ''); + if (!$this->_isValidAddress()) { + $this->_rspErr(1, 'address is empty'); + return; + } + if (UserHonor::_isValidHonorType($token_type)) { + $this->_rspErr(1, 'token_type is error'); + return; + } + + UserHonor::upsert($token_type,$state); + $propertyChgService = new services\PropertyChgService(); + $propertyChgService->addUserChg(); + $this->_rspData(array( + 'property_chg' => $propertyChgService->toDto(), + )); + } + private function dampingElo($userInfo){ //每天elo衰减 $time_diff = myself()->_getNowTime()-$userInfo['last_login_time']; diff --git a/webapp/models/Hero.php b/webapp/models/Hero.php index 2a3f772e..f141b51c 100644 --- a/webapp/models/Hero.php +++ b/webapp/models/Hero.php @@ -382,6 +382,7 @@ class Hero extends BaseModel { 't_hero', $fieldsKv ); + return true; } private static function getRandAttr($heroId){ diff --git a/webapp/models/Nft.php b/webapp/models/Nft.php index 98cc0a7d..cb9b5fb8 100644 --- a/webapp/models/Nft.php +++ b/webapp/models/Nft.php @@ -13,7 +13,8 @@ use phpcommon\SqlHelper; use phpcommon; -class Nft extends BaseModel { +class Nft extends BaseModel +{ const NONE_TYPE = 0; const HERO_TYPE = 1; //英雄 @@ -21,6 +22,7 @@ class Nft extends BaseModel { const CHIP_TYPE = 3; //芯片 const BLIND_BOX_TYPE = 4; const FRAGMENT_TYPE = 5; //碎片 + const HONOR1_TYPE = 6; //荣誉 const RING_TYPE = 19; //戒指 const GENESIS_TAG = 1; @@ -28,42 +30,46 @@ class Nft extends BaseModel { public static function getTokenType($itemMeta) { switch ($itemMeta['type']) { - case mt\Item::HERO_TYPE: - { - return self::HERO_TYPE; - } - break; - case mt\Item::GUN_TYPE: - { - return self::EQUIP_TYPE; - } - break; - case mt\Item::MATERIAL_TYPE: - { - if ($itemMeta['sub_type'] == mt\Item::MATERIAL_CHIP_SUBTYPE){ - return self::CHIP_TYPE; + case mt\Item::HERO_TYPE: + { + return self::HERO_TYPE; + } + break; + case mt\Item::GUN_TYPE: + { + return self::EQUIP_TYPE; + } + break; + case mt\Item::MATERIAL_TYPE: + { + if ($itemMeta['sub_type'] == mt\Item::MATERIAL_CHIP_SUBTYPE) { + return self::CHIP_TYPE; + } + } + break; + case mt\Item::BLIND_BOX_TYPE: + { + return self::BLIND_BOX_TYPE; + } + break; + case mt\Item::CHIP_TYPE: + { + return self::CHIP_TYPE; + } + break; + case mt\Item::FRAGMENT_BOX_TYPE: + { + return self::FRAGMENT_TYPE; + } + break; + case mt\Item::RING_TYPE: + { + return self::RING_TYPE; + } + case mt\Item::HONOR_TYPE: + { + return self::HONOR1_TYPE; } - } - break; - case mt\Item::BLIND_BOX_TYPE: - { - return self::BLIND_BOX_TYPE; - } - break; - case mt\Item::CHIP_TYPE: - { - return self::CHIP_TYPE; - } - break; - case mt\Item::FRAGMENT_BOX_TYPE: - { - return self::FRAGMENT_TYPE; - } - break; - case mt\Item::RING_TYPE: - { - return self::RING_TYPE; - } } return self::NONE_TYPE; } @@ -78,7 +84,7 @@ class Nft extends BaseModel { 'owner_address' => $account, 'deleted' => 0, ), - function ($row) use(&$nftList) { + function ($row) use (&$nftList) { if (self::isVisableNft($row)) { array_push($nftList, $row); } @@ -109,35 +115,40 @@ class Nft extends BaseModel { array( 'owner_address' => $account, 'token_type' => $type, + 'deleted' => 0, ), - function ($row) use(&$nftList) { + function ($row) use (&$nftList) { array_push($nftList, $row); } ); return $nftList; } - public static function getNft1155List($account,$type){ + public static function getNft1155List($account, $type) + { - switch ($type){ - case 3:{ - $sql = "select * from t_nft1155 where owner_address=:owner_address and token_id>10000000 and balance>0"; - }; - break; - case 5:{ - $sql = "select * from t_nft1155 where owner_address=:owner_address and token_id<10000000 and balance>0"; - }; - break; - default:{ + switch ($type) { + case 3: + { + $sql = "select * from t_nft1155 where owner_address=:owner_address and token_id>10000000 and balance>0"; + }; + break; + case 5: + { + $sql = "select * from t_nft1155 where owner_address=:owner_address and token_id<10000000 and balance>0"; + }; + break; + default: + { $sql = ""; } } - $whereKv =array( + $whereKv = array( 'owner_address' => $account, ); - if ($sql){ - $list = myself()->_getMarketMysql()->execQuery($sql,$whereKv); - }else{ + if ($sql) { + $list = myself()->_getMarketMysql()->execQuery($sql, $whereKv); + } else { $list = array(); } return $list; @@ -155,33 +166,34 @@ class Nft extends BaseModel { return $row; } - public static function findNftByOwner($owner,$tokenId){ - if (!$owner || !$tokenId){ + public static function findNftByOwner($owner, $tokenId) + { + if (!$owner || !$tokenId) { return; } $row = SqlHelper::ormSelectOne( myself()->_getMarketMysql(), 't_nft', array( - 'owner_address'=>$owner, + 'owner_address' => $owner, 'token_id' => $tokenId, ) ); - if (!$row){ + if (!$row) { $row = SqlHelper::ormSelectOne( myself()->_getMarketMysql(), 't_nft1155', array( - 'owner_address'=>$owner, + 'owner_address' => $owner, 'token_id' => $tokenId, ) ); - if ($row){ - if ($row['token_id'] > 10000000){ + if ($row) { + if ($row['token_id'] > 10000000) { $row['token_type'] = self::CHIP_TYPE; $row['token_state'] = 0; $row['tags'] = ''; - }else{ + } else { $row['token_type'] = self::FRAGMENT_TYPE; $row['token_state'] = 0; $row['tags'] = ''; @@ -195,7 +207,7 @@ class Nft extends BaseModel { public static function toDto($nftDb) { $itemMeta = mt\Item::get($nftDb['item_id']); - if (!$itemMeta){ + if (!$itemMeta) { return null; } $tags = self::parseTags($nftDb['tags']); @@ -230,41 +242,41 @@ class Nft extends BaseModel { 'mint_time' => $nftDb['createtime'] ); switch ($nftDb['token_type']) { - case Nft::HERO_TYPE: - { - $heroMeta = mt\Hero::get($nftDb['item_id']); - if ($heroMeta) { - //$nft['info']['name'] = $heroMeta['name']; - $nft['info']['job'] = $heroMeta['herotype']; - $nft['info']['level'] = 1; - $nft['info']['quality'] = 1; - $nft['info']['hp'] = $heroMeta['hp']; - $nft['info']['speed'] = $heroMeta['move_speed']; - $nft['info']['atk'] = $heroMeta['damage']; - $nft['info']['def'] = $heroMeta['defence']; - $nft['info']['advanced_count'] = 0; - $nft['info']['lucky'] = $heroMeta['hero_lucky']; - $nft['info']['success_rate'] = 0; - } - } - break; - case Nft::EQUIP_TYPE: - { - $equipMeta = mt\Equip::get($itemMeta['relationship']); - /*error_log(json_encode(array( - 'equpMeta' => $equipMeta, - 'nftDb' => $nftDb - )));*/ - $nft['full_image'] = $nft['image']; - $nft['info']['level'] = 1; - $nft['info']['quality'] = 1; - $nft['info']['lucky'] = $equipMeta ? $equipMeta['gun_lucky'] : 0; - $randAttr = array(); - if (!is_null($nftDb['rand_attr'])) { - $initQualityMeta = mt\GunQuality::getByQuality(1); - if ($initQualityMeta) { - $randAttr = mt\GunQuality::getRandAttr($initQualityMeta); + case Nft::HERO_TYPE: + { + $heroMeta = mt\Hero::get($nftDb['item_id']); + if ($heroMeta) { + //$nft['info']['name'] = $heroMeta['name']; + $nft['info']['job'] = $heroMeta['herotype']; + $nft['info']['level'] = 1; + $nft['info']['quality'] = 1; + $nft['info']['hp'] = $heroMeta['hp']; + $nft['info']['speed'] = $heroMeta['move_speed']; + $nft['info']['atk'] = $heroMeta['damage']; + $nft['info']['def'] = $heroMeta['defence']; + $nft['info']['advanced_count'] = 0; + $nft['info']['lucky'] = $heroMeta['hero_lucky']; + $nft['info']['success_rate'] = 0; + } } + break; + case Nft::EQUIP_TYPE: + { + $equipMeta = mt\Equip::get($itemMeta['relationship']); + /*error_log(json_encode(array( + 'equpMeta' => $equipMeta, + 'nftDb' => $nftDb + )));*/ + $nft['full_image'] = $nft['image']; + $nft['info']['level'] = 1; + $nft['info']['quality'] = 1; + $nft['info']['lucky'] = $equipMeta ? $equipMeta['gun_lucky'] : 0; + $randAttr = array(); + if (!is_null($nftDb['rand_attr'])) { + $initQualityMeta = mt\GunQuality::getByQuality(1); + if ($initQualityMeta) { + $randAttr = mt\GunQuality::getRandAttr($initQualityMeta); + } // SqlHelper::update( // myself()->_getMarketMysql(), // 't_nft', @@ -275,42 +287,42 @@ class Nft extends BaseModel { // 'rand_attr' => json_encode($randAttr) // ) // ); - } - { - foreach($randAttr as &$attr) { - $attrMeta = mt\Attr::get($attr['attr_id']); - if ($attrMeta) { - $attr['name'] = $attrMeta['attr_ename']; - } else { - $attr['name'] = ''; } + { + foreach ($randAttr as &$attr) { + $attrMeta = mt\Attr::get($attr['attr_id']); + if ($attrMeta) { + $attr['name'] = $attrMeta['attr_ename']; + } else { + $attr['name'] = ''; + } + } + } + { + $nft['info']['clip_volume'] = getXVal($equipMeta, 'clip_volume', 0); + $nft['info']['reload_time'] = getXVal($equipMeta, 'reload_time', 0); + $nft['info']['fire_rate'] = getXVal($equipMeta, 'fire_rate', 0); + $nft['info']['atk'] = getXVal($equipMeta, 'atk', 0); + $nft['info']['bullet_speed'] = getXVal($equipMeta, 'bullet_speed', 0); + $nft['info']['range'] = getXVal($equipMeta, 'range', 0); + } + $nft['info']['attr'] = $randAttr; } - } - { - $nft['info']['clip_volume'] = getXVal($equipMeta, 'clip_volume', 0); - $nft['info']['reload_time'] = getXVal($equipMeta, 'reload_time', 0); - $nft['info']['fire_rate'] = getXVal($equipMeta, 'fire_rate', 0); - $nft['info']['atk'] = getXVal($equipMeta, 'atk', 0); - $nft['info']['bullet_speed'] = getXVal($equipMeta, 'bullet_speed', 0); - $nft['info']['range'] = getXVal($equipMeta, 'range', 0); - } - $nft['info']['attr'] = $randAttr; - } - break; - case Nft::CHIP_TYPE: - { - $nft['hide_attr'] = 1; - } - break; - case Nft::FRAGMENT_TYPE: - { + break; + case Nft::CHIP_TYPE: + { + $nft['hide_attr'] = 1; + } + break; + case Nft::FRAGMENT_TYPE: + { - } - break; - default: - { - return null; - } + } + break; + default: + { + return null; + } } return $nft; } @@ -394,14 +406,18 @@ class Nft extends BaseModel { private static function isVisableNft($nftDb) { return in_array($nftDb['token_type'], - array( - self::HERO_TYPE, - self::EQUIP_TYPE, - self::CHIP_TYPE - )); + array( + self::HERO_TYPE, + self::EQUIP_TYPE, + self::CHIP_TYPE, + self::BLIND_BOX_TYPE, + self::FRAGMENT_TYPE, + self::HONOR1_TYPE, + self::RING_TYPE + )); } - public static function genTempTokenId() + public static function genTempTokenId() { $row = SqlHelper::ormSelectOne (myself()->_getSelfMysql(), diff --git a/webapp/models/User.php b/webapp/models/User.php index 556e7b1c..7620a403 100644 --- a/webapp/models/User.php +++ b/webapp/models/User.php @@ -10,6 +10,7 @@ require_once('models/Parachute.php'); require_once('models/Hero.php'); require_once('models/HeroPreset.php'); require_once('models/SignLog.php'); +require_once('models/UserHonor.php'); use mt; use phpcommon; @@ -86,6 +87,10 @@ class User extends BaseModel { // )); // $row = myself()->_getOrmUserInfo(); // } + $honorInfo = array(); + if ($row['address']){ + $honorInfo = UserHonor::info($row['address']); + } return array( 'activated' => $row['activated'], 'rename_count' => $row['rename_count'], @@ -124,7 +129,8 @@ class User extends BaseModel { 'ring_list' => UserSeasonRing::ringList($row['account_id']), 'current_star_num' => $current_star_num, 'next_star_num' => $next_star_num, - 'status_bar' => self::_getState() + 'status_bar' => self::_getState(), + 'honor_info' => $honorInfo ); } @@ -158,7 +164,10 @@ class User extends BaseModel { // )); // $row = myself()->_getOrmUserInfo(); // } - + $honorInfo = array(); + if ($row['address']){ + $honorInfo = UserHonor::info($row['address']); + } return array( 'activated' => $row['activated'], 'rename_count' => $row['rename_count'], @@ -198,7 +207,8 @@ class User extends BaseModel { 'parachute_list' => Parachute::getMyParachute(), 'current_star_num' => $current_star_num, 'next_star_num' => $next_star_num, - 'status_bar' => self::_getState() + 'status_bar' => self::_getState(), + 'honor_info' => $honorInfo ); } diff --git a/webapp/models/UserHonor.php b/webapp/models/UserHonor.php new file mode 100644 index 00000000..8b34d7a9 --- /dev/null +++ b/webapp/models/UserHonor.php @@ -0,0 +1,89 @@ +_getSelfMysql(), + 't_user_honor', + array( + 'address' => myself()->_getAddress() + ) + ); + return $row ? $row : null; + } + + public static function info($address){ + if (!$address){ + return ; + } + $honorDb = self::findByAddress($address); + $data = array(); + + if ($honorDb){ + array_push($data,array( + 'token_type' => Nft::HONOR1_TYPE, + 'state' => $honorDb['honor1'] + )); + } + return $data; + } + + public static function findByAddress($address){ + if (!$address){ + return ; + } + $row = SqlHelper::ormSelectOne + (myself()->_getMysql($address), + 't_user_honor', + array( + 'address' => $address + ) + ); + return $row ? $row : null; + } + + public static function _isValidHonorType($type){ + if (!in_array($type,array( + Nft::HONOR1_TYPE, + ))){ + return false; + } + return true; + } + + public static function upsert($tokenType,$state){ + $insertKv = array(); + $updateKv = array(); + switch ($tokenType){ + case Nft::HONOR1_TYPE : { + $updateKv = array( + 'honor1' => $state, + ); + $insertKv = array( + 'address' => myself()->_getAddress(), + 'honor1' => $state, + ); + } + } + + SqlHelper::upsert + (myself()->_getSelfMysql(), + 't_user_honor', + array( + 'address' => myself()->_getAddress() + ), + $updateKv, + $insertKv + ); + } + + +} \ No newline at end of file diff --git a/webapp/mt/Item.php b/webapp/mt/Item.php index 850d7a37..21e57952 100644 --- a/webapp/mt/Item.php +++ b/webapp/mt/Item.php @@ -97,6 +97,7 @@ class Item { const RING_TYPE = 19; const EMOJI_TYPE = 20; const RANDOM_BOX_TYPE = 21; + const HONOR_TYPE = 24; const CHEST_BOX_TYPE = 23; diff --git a/webapp/services/AwardService.php b/webapp/services/AwardService.php index 83a1f85a..69f3aa31 100644 --- a/webapp/services/AwardService.php +++ b/webapp/services/AwardService.php @@ -2,11 +2,13 @@ namespace services; +use models\Hero; use mt\Item; class AwardService extends BaseService { private $items = array(); + private $heros = array(); public function addItem($itemId, $itemNum) { @@ -31,11 +33,22 @@ class AwardService extends BaseService { } } + public function addHero($itemId,$unnid) + { + $itemMeta = Item::get($itemId); + if (!$itemMeta){ + return; + } + if ($itemMeta['type'] == Item::HERO_TYPE){ + array_push($this->heros,Hero::toDto(Hero::find($unnid))); + } + } public function toDto() { return array( - 'items' => $this->items + 'items' => $this->items, + 'heros' => $this->heros, ); }