diff --git a/sql/gamedb.sql b/sql/gamedb.sql index fb147fb9..054c6781 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -186,6 +186,7 @@ DROP TABLE IF EXISTS `t_hero_skin`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `t_hero_skin` ( `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', + `token_id` varchar(60) COMMENT 'token_id', `account_id` varchar(60) CHARACTER SET utf8 NOT NULL COMMENT 'account_id', `skin_id` int(11) NOT NULL DEFAULT '0' COMMENT '英雄皮肤id', `hero_id` int(11) NOT NULL DEFAULT '0' COMMENT '英雄id', @@ -196,7 +197,8 @@ CREATE TABLE `t_hero_skin` ( `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', PRIMARY KEY (`idx`), - UNIQUE KEY `account_id_skinid` (`account_id`, `skin_id`) + UNIQUE KEY `token_id` (`token_id`), + KEY `account_id` (`account_id`) ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*!40101 SET character_set_client = @saved_cs_client */; diff --git a/webapp/controller/BaseAuthedController.class.php b/webapp/controller/BaseAuthedController.class.php index b56bf7dc..50a37544 100644 --- a/webapp/controller/BaseAuthedController.class.php +++ b/webapp/controller/BaseAuthedController.class.php @@ -486,7 +486,11 @@ class BaseAuthedController extends BaseController { break; case mt\Item::HERO_SKIN_TYPE: { - HeroSkin::addSkin($itemMeta); + if (isset($item['is_payed']) && $item['is_payed']) { + HeroSkin::addHeroSkin($itemMeta); + } else { + HeroSkin::addFreeHeroSkin($itemMeta); + } $propertyService->addHeroSkinChg(); } break; diff --git a/webapp/controller/BattleController.class.php b/webapp/controller/BattleController.class.php index 508d4624..57b8c971 100644 --- a/webapp/controller/BattleController.class.php +++ b/webapp/controller/BattleController.class.php @@ -365,7 +365,7 @@ class BattleController extends BaseAuthedController { $info['is_valid_battle'] = 1; $info['hero_dto'] = Hero::toDto($heroDb); {//选用皮肤id - $skinDb = HeroSkin::findBx($heroDb['hero_id']); + $skinDb = HeroSkin::findByAccountId($member['account_id'],$heroDb['skin_id']); if ($skinDb){ $info['hero_dto']['skin_id'] = $skinDb['skin_id']; } diff --git a/webapp/controller/HeroController.class.php b/webapp/controller/HeroController.class.php index 57cc72d6..7723ad50 100644 --- a/webapp/controller/HeroController.class.php +++ b/webapp/controller/HeroController.class.php @@ -94,50 +94,50 @@ class HeroController extends BaseAuthedController { )); } - public function skinList() - { - $heroId = getReqVal('hero_id',0); - if (!$heroId){ - $this->_rspErr(1, "param null"); - return; - } - $itemMeta = \mt\Item::get($heroId); - if (!$itemMeta || $itemMeta['type']!=\mt\Item::HERO_TYPE){ - $this->_rspErr(1, "param error"); - return; - } - $skinList = array(); - $skinMeta = \mt\Item::getMetaListByType(\mt\Item::HERO_SKIN_TYPE); - if ($skinMeta){ - foreach ($skinMeta as $value){ - if ($value['playerid'] == $heroId){ - array_push($skinList,HeroSkin::toDto($value)); - } - } - } - $this->_rspData(array( - 'skin_list' => $skinList - )); - } +// public function skinList() +// { +// $heroId = getReqVal('hero_id',0); +// if (!$heroId){ +// $this->_rspErr(1, "param null"); +// return; +// } +// $itemMeta = \mt\Item::get($heroId); +// if (!$itemMeta || $itemMeta['type']!=\mt\Item::HERO_TYPE){ +// $this->_rspErr(1, "param error"); +// return; +// } +// $skinList = array(); +// $skinMeta = \mt\Item::getMetaListByType(\mt\Item::HERO_SKIN_TYPE); +// if ($skinMeta){ +// foreach ($skinMeta as $value){ +// if ($value['playerid'] == $heroId){ +// array_push($skinList,HeroSkin::toDto($value)); +// } +// } +// } +// $this->_rspData(array( +// 'skin_list' => $skinList +// )); +// } - public function takeonSkin() - { - $heroUniId = getReqVal('hero_uniid', 0); - $skinId = getReqVal('skin_id', 0); - $heroDb = Hero::find($heroUniId); - $heroSkinDb = HeroSkin::find($skinId); - if (!$heroDb) { - $this->_rspErr(1, "You don't have the hero yet"); - return; - } - $itemMeta = \mt\Item::get($skinId); - if ($itemMeta['isdefaultskin'] != 1 && !$heroSkinDb) { - $this->_rspErr(2, "You don't have the skin yet"); - return; - } - HeroSkin::takeonSkin( $skinId,$heroDb['hero_id']); - $this->_rspOk(); - } +// public function takeonSkin() +// { +// $heroUniId = getReqVal('hero_uniid', 0); +// $skinId = getReqVal('skin_id', 0); +// $heroDb = Hero::find($heroUniId); +// $heroSkinDb = HeroSkin::find($skinId); +// if (!$heroDb) { +// $this->_rspErr(1, "You don't have the hero yet"); +// return; +// } +// $itemMeta = \mt\Item::get($skinId); +// if ($itemMeta['isdefaultskin'] != 1 && !$heroSkinDb) { +// $this->_rspErr(2, "You don't have the skin yet"); +// return; +// } +// HeroSkin::takeonSkin( $skinId,$heroDb['hero_id']); +// $this->_rspOk(); +// } /* 升级预览 diff --git a/webapp/controller/HeroSkinController.class.php b/webapp/controller/HeroSkinController.class.php new file mode 100644 index 00000000..e6e54c9b --- /dev/null +++ b/webapp/controller/HeroSkinController.class.php @@ -0,0 +1,54 @@ +_rspData(array( + 'skin_list' => $skinList + )); + } + + public function takeonSkin() + { + $heroUniId = getReqVal('hero_uniid', 0); + $skinUniId = getReqVal('skin_uniid', 0); + $heroDb = Hero::find($heroUniId); + $heroSkinDb = HeroSkin::find($skinUniId); + if (!$heroDb) { + $this->_rspErr(1, "You don't have the hero yet"); + return; + } + + if (!$heroSkinDb) { + $this->_rspErr(1, "You don't have the skin yet"); + return; + } + Hero::update( $heroUniId,array( + 'skin_id' => $skinUniId + )); + $this->_rspOk(); + } + + public function unequip(){ + $heroUniId = getReqVal('hero_uniid', 0); + $heroDb = Hero::find($heroUniId); + if (!$heroDb) { + $this->_rspErr(1, "You don't have the hero yet"); + return; + } + Hero::update( $heroUniId,array( + 'skin_id' => 0 + )); + $this->_rspOk(); + } + +} \ No newline at end of file diff --git a/webapp/controller/PassController.class.php b/webapp/controller/PassController.class.php index 297fb886..b20a17a2 100644 --- a/webapp/controller/PassController.class.php +++ b/webapp/controller/PassController.class.php @@ -125,6 +125,7 @@ class PassController extends BaseAuthedController array_push($items, array( 'item_id' => $passMeta['platinum_item_id2'], 'item_num' => $passMeta['platinum_item_num2'], + 'is_payed' => 1 )); if ($passMeta['platinum_item_id1'] == V_ITEM_GOLD){ $gold += $passMeta['platinum_item_num1']; @@ -206,6 +207,7 @@ class PassController extends BaseAuthedController array( 'item_id' => $passMeta['platinum_item_id2'], 'item_num' => $passMeta['platinum_item_num2'], + 'is_payed' => 1 ) ); if ($passMeta['platinum_item_id1'] == V_ITEM_GOLD){ diff --git a/webapp/controller/RankingController.class.php b/webapp/controller/RankingController.class.php index bc8b58ae..ac7d15ec 100644 --- a/webapp/controller/RankingController.class.php +++ b/webapp/controller/RankingController.class.php @@ -117,9 +117,8 @@ class RankingController extends BaseAuthedController { $heroDb = Hero::findByAccountId($row['account_id'],$row['hero_id']); if ($heroDb){ - $heroItemId = $heroDb['hero_id']; - $skinDb = HeroSkin::findByAccountId($row['account_id'],$heroItemId); - $hero_skin = $skinDb['skin_id']; + $skinDb = HeroSkin::findByAccountId($row['account_id'],$heroDb['skin_id']); + $hero_skin = $skinDb ? $skinDb['skin_id'] : 0; } $info = array( diff --git a/webapp/controller/TeamController.class.php b/webapp/controller/TeamController.class.php index d8cf1bf3..093f3ba5 100644 --- a/webapp/controller/TeamController.class.php +++ b/webapp/controller/TeamController.class.php @@ -517,39 +517,39 @@ class TeamController extends BaseAuthedController { $this->_rspOk(); } - public function setHeroSkin(){ - $teamUuid = getReqVal('team_uuid', ''); - $heroUniId = getReqVal('hero_uid', 0); - $skinId = getReqVal('skin_id', 0); - $r = $this->_getRedis($teamUuid); - $teamDb = $this->readTeamDb($r, $teamUuid); - if (empty($teamDb)) { - $this->_rspErr(1, 'The team has been disbanded'); - return; - } - $heroDb = Hero::find($heroUniId); - $heroSkinDb = HeroSkin::find($skinId); - if (!$heroDb) { - $this->_rspErr(1, "You don't have the hero yet"); - return; - } - if (!$heroSkinDb) { - $this->_rspErr(2, "You don't have the skin yet"); - return; - } - HeroSkin::takeonSkin( $skinId,$heroDb['hero_id']); - $newUserInfo = User::toPreset($this->_getOrmUserInfo()); - foreach ($teamDb['member_list'] as &$member) { - if ($member['account_id'] == $this->_getAccountId()){ - $newUserInfo['is_leader'] = $member['is_leader']; - $newUserInfo['is_ready'] = $member['is_ready']; - $member = $newUserInfo; - } - - } - $this->saveTeamDb($r, $teamUuid, $teamDb); - $this->_rspOk(); - } +// public function setHeroSkin(){ +// $teamUuid = getReqVal('team_uuid', ''); +// $heroUniId = getReqVal('hero_uid', 0); +// $skinId = getReqVal('skin_id', 0); +// $r = $this->_getRedis($teamUuid); +// $teamDb = $this->readTeamDb($r, $teamUuid); +// if (empty($teamDb)) { +// $this->_rspErr(1, 'The team has been disbanded'); +// return; +// } +// $heroDb = Hero::find($heroUniId); +// $heroSkinDb = HeroSkin::find($skinId); +// if (!$heroDb) { +// $this->_rspErr(1, "You don't have the hero yet"); +// return; +// } +// if (!$heroSkinDb) { +// $this->_rspErr(2, "You don't have the skin yet"); +// return; +// } +// HeroSkin::takeonSkin( $skinId,$heroDb['hero_id']); +// $newUserInfo = User::toPreset($this->_getOrmUserInfo()); +// foreach ($teamDb['member_list'] as &$member) { +// if ($member['account_id'] == $this->_getAccountId()){ +// $newUserInfo['is_leader'] = $member['is_leader']; +// $newUserInfo['is_ready'] = $member['is_ready']; +// $member = $newUserInfo; +// } +// +// } +// $this->saveTeamDb($r, $teamUuid, $teamDb); +// $this->_rspOk(); +// } public function getPveFragmentNumOrDay(){ $todayPveGetHeroFragmentNum = myself()->_getDailyV(TN_DAILY_PVE_GET_HERO_FRAGMENT_NUM, 0); diff --git a/webapp/models/Hero.php b/webapp/models/Hero.php index f6fc0b40..3125d559 100644 --- a/webapp/models/Hero.php +++ b/webapp/models/Hero.php @@ -272,7 +272,7 @@ class Hero extends BaseModel { if ($row['idx'] == $userDb['hero_id']){ $isSelect = 1; } - $skinDb = HeroSkin::findBx($row['hero_id']); + $skinDb = HeroSkin::find($row['skin_id']); $dto = array( 'idx' => $row['idx'], 'token_id' => $row['token_id'], @@ -375,14 +375,14 @@ class Hero extends BaseModel { public static function internalAddHero($conn, $heroMeta, $accountId, $tokenId,$type) { - $skinItemMeta = \mt\Item::getMetaListByType(\mt\Item::HERO_SKIN_TYPE); - if ($skinItemMeta){ - foreach ($skinItemMeta as $value){ - if ($value['playerid'] == $heroMeta['id'] && $value['isdefaultskin'] ==1){ - HeroSkin::addSkin($value); - } - } - } +// $skinItemMeta = \mt\Item::getMetaListByType(\mt\Item::HERO_SKIN_TYPE); +// if ($skinItemMeta){ +// foreach ($skinItemMeta as $value){ +// if ($value['playerid'] == $heroMeta['id'] && $value['isdefaultskin'] ==1){ +// HeroSkin::addSkin($value); +// } +// } +// } $state = $type > 0 ? self::GETED_STATE : self::FREE_STATE; $realHeroMeta = mt\Hero::get($heroMeta['id']); $randAttr = self::getRandAttr($heroMeta['id'],$type) ; diff --git a/webapp/models/HeroSkin.php b/webapp/models/HeroSkin.php index 5cb12459..348b42bd 100644 --- a/webapp/models/HeroSkin.php +++ b/webapp/models/HeroSkin.php @@ -3,89 +3,80 @@ namespace models; require_once('mt/Hero.php'); +require_once('services/NftService.php'); use mt; +use services\NftService; use phpcommon\SqlHelper; class HeroSkin extends BaseModel { const GETED_STATE = 0; - const TRY_USING_STATE = 1; + const FREE_STATE = 1; - public static function find($skinId) +// public static function find($skinId) +// { +// $row = SqlHelper::ormSelectOne( +// myself()->_getSelfMysql(), +// 't_hero_skin', +// array( +// 'account_id' => myself()->_getAccountId(), +// 'skin_id' => $skinId +// ) +// ); +// return $row; +// } + public static function find($skinUniId) { - $row = SqlHelper::ormSelectOne( - myself()->_getSelfMysql(), - 't_hero_skin', - array( - 'account_id' => myself()->_getAccountId(), - 'skin_id' => $skinId - ) - ); - return $row; + return self::internalFind(myself()->_getAccountId(), myself()->_getAddress(), $skinUniId); } - public static function findBx($heroId) +// public static function findBx($accountId,$skinUniId) +// { +// return self::internalFind($accountId, User::findUserAddress($accountId), $skinUniId); +// } + + public static function findByAccountId($accountId, $skinUniId) { - $row = SqlHelper::ormSelectOne( - myself()->_getSelfMysql(), - 't_hero_skin', - array( - 'account_id' => myself()->_getAccountId(), - 'hero_id' => $heroId - ) - ); - return $row; - } - public static function findByAccountId($accountId, $heroId) - { - $row = SqlHelper::ormSelectOne( - myself()->_getSelfMysql(), - 't_hero_skin', - array( - 'account_id' => $accountId, - 'hero_id' => $heroId - ) - ); - return $row; + return self::internalFind($accountId, User::findUserAddress($accountId), $skinUniId); } - public static function takeonSkin($skinId,$heroId){ - $row = self::findBx($heroId); - SqlHelper::update( - myself()->_getSelfMysql(), - 't_hero_skin', - array( - 'account_id' => myself()->_getAccountId(), - 'skin_id' => $row['skin_id'] - ), - array( - 'hero_id'=>0 - ) - ); - SqlHelper::upsert( - myself()->_getSelfMysql(), - 't_hero_skin', - array( - 'account_id' => myself()->_getAccountId(), - 'skin_id' => $skinId - ), - array( - 'hero_id'=>$heroId - ), - array( - 'account_id' => myself()->_getAccountId(), - 'skin_id' => $skinId, - 'skin_state' => 0, - 'get_from' => 0, - 'consume_num' => 0, - 'try_expire_at' => 0, - 'hero_id' => $heroId, - 'createtime' => myself()->_getNowTime(), - 'modifytime' => myself()->_getNowTime() - ) - ); - } +// public static function takeonSkin($skinId,$heroId){ +// $row = self::findBx($heroId); +// SqlHelper::update( +// myself()->_getSelfMysql(), +// 't_hero_skin', +// array( +// 'account_id' => myself()->_getAccountId(), +// 'skin_id' => $row['skin_id'] +// ), +// array( +// 'hero_id'=>0 +// ) +// ); +// SqlHelper::upsert( +// myself()->_getSelfMysql(), +// 't_hero_skin', +// array( +// 'account_id' => myself()->_getAccountId(), +// 'skin_id' => $skinId +// ), +// array( +// 'hero_id'=>$heroId +// ), +// array( +// 'account_id' => myself()->_getAccountId(), +// 'skin_id' => $skinId, +// 'skin_state' => 0, +// 'get_from' => 0, +// 'consume_num' => 0, +// 'try_expire_at' => 0, +// 'hero_id' => $heroId, +// 'createtime' => myself()->_getNowTime(), +// 'modifytime' => myself()->_getNowTime() +// ) +// ); +// } public static function getSkinList($cb){ @@ -99,6 +90,20 @@ class HeroSkin extends BaseModel { $cb($row); } ); + foreach (NftService::getHeroSkin(myself()->_getAddress()) as $nftDb) { + if (! $nftDb['deleted']){ + $row = SqlHelper::ormSelectOne( + myself()->_getSelfMysql(), + 't_hero_skin', + array( + 'token_id' => $nftDb['token_id'], + ) + ); + if ($row) { + $cb($row); + } + } + } } @@ -120,32 +125,100 @@ class HeroSkin extends BaseModel { ); } - public static function addSkin($itemMeta) +// public static function addSkin($itemMeta) +// { +// $heroId = 0; +// if ($itemMeta['isdefaultskin'] == 1){ +// $heroId = $itemMeta['playerid']; +// } +// SqlHelper::upsert( +// myself()->_getSelfMysql(), +// 't_hero_skin', +// array( +// 'account_id' => myself()->_getAccountId(), +// 'skin_id' => $itemMeta['id'] +// ), +// array(), +// array( +// 'account_id' => myself()->_getAccountId(), +// 'skin_id' => $itemMeta['id'], +// 'skin_state' => 0, +// 'get_from' => 0, +// 'consume_num' => 0, +// 'try_expire_at' => 0, +// 'hero_id' => $heroId, +// 'createtime' => myself()->_getNowTime(), +// 'modifytime' => myself()->_getNowTime() +// ) +// ); +// } + + + private static function internalFind($accountId, $address, $skinUniId) { - $heroId = 0; - if ($itemMeta['isdefaultskin'] == 1){ - $heroId = $itemMeta['playerid']; - } - SqlHelper::upsert( - myself()->_getSelfMysql(), + $row = SqlHelper::ormSelectOne( + myself()->_getMysql($accountId), 't_hero_skin', array( - 'account_id' => myself()->_getAccountId(), - 'skin_id' => $itemMeta['id'] - ), - array(), - array( - 'account_id' => myself()->_getAccountId(), - 'skin_id' => $itemMeta['id'], - 'skin_state' => 0, - 'get_from' => 0, - 'consume_num' => 0, - 'try_expire_at' => 0, - 'hero_id' => $heroId, - 'createtime' => myself()->_getNowTime(), - 'modifytime' => myself()->_getNowTime() + 'idx' => $skinUniId, ) ); + if ($row) { + $row['skin_uniid'] = $row['idx']; + if ($row['account_id'] != $accountId) { + $openId = $address; + if (!NftService::isHeroSkinOwner($openId, $row['token_id'])) { + $row = null; + } + } + } + return $row; + } + + public static function addFreeHeroSkin($heroSkinMeta) + { + return self::internalAddHeroSkin( + myself()->_getSelfMysql(), + $heroSkinMeta, + myself()->_getAccountId(), + null, + self::FREE_STATE); + } + + public static function addHeroSkin($heroSkinMeta) + { + return self::internalAddHeroSkin( + myself()->_getSelfMysql(), + $heroSkinMeta, + myself()->_getAccountId(), + null, + self::GETED_STATE); + } + + private static function internalAddHeroSkin($conn, $heroSkinMeta, $accountId, $tokenId,$state) + { + $fieldsKv = array( + + 'skin_id' => $heroSkinMeta['id'], + 'skin_state' => $state, + 'get_from' => 0, + 'consume_num' => 0, + 'try_expire_at' => 0, + 'hero_id' => $heroSkinMeta['playerid'], + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime() + ); + if ($accountId) { + $fieldsKv['account_id'] = $accountId; + } + if ($tokenId) { + $fieldsKv['token_id'] = $tokenId; + } + SqlHelper::insert( + $conn, + 't_hero_skin', + $fieldsKv + ); } } diff --git a/webapp/models/Nft.php b/webapp/models/Nft.php index 1153b041..14435012 100644 --- a/webapp/models/Nft.php +++ b/webapp/models/Nft.php @@ -23,6 +23,7 @@ class Nft extends BaseModel const BLIND_BOX_TYPE = 4; const FRAGMENT_TYPE = 5; //碎片 const HONOR1_TYPE = 6; //荣誉 + const HERO_SKIN_TYPE = 9; //英雄皮肤 const RING_TYPE = 19; //戒指 const GENESIS_TAG = 1; diff --git a/webapp/models/User.php b/webapp/models/User.php index 47c949eb..33411dbf 100644 --- a/webapp/models/User.php +++ b/webapp/models/User.php @@ -283,7 +283,11 @@ class User extends BaseModel { $heroId = $heroDb['hero_id']; } $preset = HeroPreset::getHeroPreset($row['hero_id']); - $skinDb = HeroSkin::findBx($heroId); + $skinDb = HeroSkin::findByAccountId($row['account_id'],$heroDb['skin_id']); + $skin_id = 0; + if ($skinDb){ + $skin_id = $skinDb['skin_id']; + } $honorInfo = array(); if ($row['address']){ $honorInfo = UserHonor::info($row['address']); @@ -307,7 +311,7 @@ class User extends BaseModel { 'parachute' => $row['parachute'] ? $row['parachute'] : Parachute::$parachute, 'hero_uniId' => $row['hero_id'], 'hero_id' => $heroId, - 'hero_skin' =>$skinDb['skin_id'], + 'hero_skin' =>$skin_id, 'presetInfo' => $preset, 'is_leader' => 0, 'is_ready' => 0, diff --git a/webapp/services/NftService.php b/webapp/services/NftService.php index e13aec34..386825a0 100644 --- a/webapp/services/NftService.php +++ b/webapp/services/NftService.php @@ -21,6 +21,7 @@ class NftService extends BaseService { 'equip' => Nft::EQUIP_TYPE, 'chip' => Nft::CHIP_TYPE, 'ring' => Nft::RING_TYPE, + 'heroSkin' => Nft::HERO_SKIN_TYPE, ); public static function getChipBlance($account, $tokenId) @@ -43,6 +44,11 @@ class NftService extends BaseService { return self::internalIsOwner($openId, 'chip', $tokenId); } + public static function isHeroSkinOwner($openId, $tokenId) + { + return self::internalIsOwner($openId, 'heroSkin', $tokenId); + } + public static function getHeros($openId) { return self::internalGetList($openId, 'hero'); @@ -58,6 +64,10 @@ class NftService extends BaseService { return self::internalGetList($openId, 'chip'); } + public static function getHeroSkin($openId) + { + return self::internalGetList($openId, 'heroSkin'); + } public static function getRing($openId) { return self::internalGetList($openId, 'ring');