From 0be29c4e35f37f493f2dc83f883d728c0bcc5072 Mon Sep 17 00:00:00 2001 From: hujiabin <519660157@qq.com> Date: Thu, 21 Sep 2023 16:11:51 +0800 Subject: [PATCH] add avatar --- sql/gamedb.sql | 24 ++++++ sql/gamedb2006_migrate_230920_01.sql | 19 +++++ webapp/controller/AvatarController.class.php | 68 +++++++++++++++++ webapp/models/Avatar.php | 78 ++++++++++++++++++++ webapp/models/Nft.php | 1 + webapp/mt/Item.php | 1 + webapp/services/NftService.php | 10 +++ 7 files changed, 201 insertions(+) create mode 100644 sql/gamedb2006_migrate_230920_01.sql create mode 100644 webapp/controller/AvatarController.class.php create mode 100644 webapp/models/Avatar.php diff --git a/sql/gamedb.sql b/sql/gamedb.sql index a8fa2add..2464c962 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -1671,3 +1671,27 @@ CREATE TABLE `t_mail` ( KEY `account_id_mailid` (`account_id`, `mailid`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*!40101 SET character_set_client = @saved_cs_client */; + + +-- +-- Table structure for table `t_avatar` +-- + +DROP TABLE IF EXISTS `t_avatar`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `t_avatar` ( + `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', + `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)', + `token_id` varchar(60) COMMENT 'token_id', + `address` varchar(60) COMMENT 'address', + `item_id` int(11) NOT NULL COMMENT 'item_id', + `item_type` int(11) NOT NULL COMMENT 'item类型', + `status` int(11) NOT NULL DEFAULT '0' COMMENT '装备状态', + `hero_idx` bigint DEFAULT NULL COMMENT '英雄外键id', + `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `hero_idx_type` (`hero_idx`, `item_type`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; \ No newline at end of file diff --git a/sql/gamedb2006_migrate_230920_01.sql b/sql/gamedb2006_migrate_230920_01.sql new file mode 100644 index 00000000..bbd3f238 --- /dev/null +++ b/sql/gamedb2006_migrate_230920_01.sql @@ -0,0 +1,19 @@ +begin; + +CREATE TABLE `t_avatar` ( + `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', + `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)', + `token_id` varchar(60) COMMENT 'token_id', + `item_id` int(11) NOT NULL COMMENT 'item_id', + `item_type` int(11) NOT NULL COMMENT 'item类型', + `status` int(11) NOT NULL DEFAULT '0' COMMENT '装备状态', + `hero_idx` bigint DEFAULT NULL COMMENT '英雄外键id', + `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `hero_idx_type` (`hero_idx`, `item_type`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + +insert into version (version) values(2023092001); + +commit; diff --git a/webapp/controller/AvatarController.class.php b/webapp/controller/AvatarController.class.php new file mode 100644 index 00000000..f2b65d36 --- /dev/null +++ b/webapp/controller/AvatarController.class.php @@ -0,0 +1,68 @@ +_rspData(array( + 'list' => $avatarList + )); + } + + public function useAvatar(){ + $heroUniid = trim(getReqVal('hero_uniid', 0)); + $avatarUniid = trim(getReqVal('avatar_uniid', 0)); + + $heroDb = Hero::find($heroUniid); + if (!$heroDb){ + $this->_rspErr(1, 'hero_uniid error'); + return; + } + $avatarDb = Avatar::find($avatarUniid); + if (!$avatarDb){ + $this->_rspErr(1, 'avatar_uniid error'); + return; + } + if ($heroDb['idx'] == $avatarDb['hero_idx']){ + $this->_rspErr(1, 'avatar_uniid error'); + return; + } + $randAttr = emptyReplace(json_decode($heroDb['rand_attr'], true), array()); + + + } + + public function remove(){ + + } + + public function clearAvatar(){ + + } + + + public function buyAvatar(){ + $itemId = trim(getReqVal('item_id', 0)); + $itemMeta = \mt\Item::get($itemId); + if (!$itemMeta || $itemMeta['type'] != \mt\Item::AVATAR_TYPE){ + $this->_rspErr(1, 'item id error'); + return; + } + //检验钻石是否足够 并消耗钻石 + { + + } + Avatar::addAvatar($itemMeta); + $this->_rspOk(); + } +} + diff --git a/webapp/models/Avatar.php b/webapp/models/Avatar.php new file mode 100644 index 00000000..028a4282 --- /dev/null +++ b/webapp/models/Avatar.php @@ -0,0 +1,78 @@ +_getAccountId(), myself()->_getAddress(), $avatarUniId); + } + + private static function internalFind($accountId, $address, $avatarUniId) + { + $row = SqlHelper::ormSelectOne( + myself()->_getMysql($accountId), + 't_avatar', + array( + 'idx' => $avatarUniId, + ) + ); + if ($row) { + $row['avatar_uniid'] = $row['idx']; + if ($row['account_id'] != $accountId) { + $openId = $address; + if (!NftService::isAvatarOwner($openId, $row['token_id'])) { + $row = null; + } + } + } + return $row; + } + + public static function getAvatarList($cb){ + SqlHelper::ormSelect( + myself()->_getSelfMysql(), + 't_avatar', + array( + 'account_id' => myself()->_getAccountId() + ), + function ($row) use($cb) { + $row['tags'] = ''; + $cb($row); + } + ); + foreach (NftService::getAvatar(myself()->_getAddress()) as $nftDb) { + if (! $nftDb['deleted']){ + $row = SqlHelper::ormSelectOne( + myself()->_getSelfMysql(), + 't_avatar', + array( + 'token_id' => $nftDb['token_id'], + ) + ); + $row['tags'] = $nftDb['tags']; + $cb($row); + } + } + } + + public static function addAvatar($avatarMeta){ + SqlHelper::insert( + myself()->_getSelfMysql(), + 't_avatar', + array( + 'account_id' => myself()->_getAccountId(), + 'item_id' => $avatarMeta['id'], + 'item_type' => $avatarMeta['sub_type'], + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime(), + ) + ); + } + +} \ No newline at end of file diff --git a/webapp/models/Nft.php b/webapp/models/Nft.php index afd46c67..4b790f25 100644 --- a/webapp/models/Nft.php +++ b/webapp/models/Nft.php @@ -26,6 +26,7 @@ class Nft extends BaseModel const GENESIS_TYPE = 7; //创世徽章 const PLANET_TYPE = 8; //星球 const RING_TYPE = 19; //戒指 + const AVATAR_TYPE = 29; //装饰 const GENESIS_TAG = 1; diff --git a/webapp/mt/Item.php b/webapp/mt/Item.php index 009c53e0..dddc2f37 100644 --- a/webapp/mt/Item.php +++ b/webapp/mt/Item.php @@ -104,6 +104,7 @@ class Item { const CHEST_BOX_TYPE = 23; const PLANET_TYPE = 28; + const AVATAR_TYPE = 29; const FUNC_RENAME_CARD_SUBTYPE = 1; const MATERIAL_CHIP_SUBTYPE = 3; diff --git a/webapp/services/NftService.php b/webapp/services/NftService.php index e13aec34..457d9d3c 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, + 'avatar' => Nft::AVATAR_TYPE, ); public static function getChipBlance($account, $tokenId) @@ -28,6 +29,11 @@ class NftService extends BaseService { return Nft::getChipBlance($account, $tokenId); } + public static function isAvatarOwner($openId, $tokenId) + { + return self::internalIsOwner($openId, 'avatar', $tokenId); + } + public static function isHeroOwner($openId, $tokenId) { return self::internalIsOwner($openId, 'hero', $tokenId); @@ -62,6 +68,10 @@ class NftService extends BaseService { { return self::internalGetList($openId, 'ring'); } + public static function getAvatar($openId) + { + return self::internalGetList($openId, 'avatar'); + } private static function internalGetList($openId, $name) {