add avatar
This commit is contained in:
parent
c0cb1f538f
commit
0be29c4e35
@ -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 */;
|
19
sql/gamedb2006_migrate_230920_01.sql
Normal file
19
sql/gamedb2006_migrate_230920_01.sql
Normal file
@ -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;
|
68
webapp/controller/AvatarController.class.php
Normal file
68
webapp/controller/AvatarController.class.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
require_once('mt/Item.php');
|
||||
require_once('models/Hero.php');
|
||||
require_once('models/Avatar.php');
|
||||
|
||||
use models\Hero;
|
||||
use models\Avatar;
|
||||
class AvatarController extends BaseAuthedController {
|
||||
|
||||
public function avatarList(){
|
||||
$avatarList = array();
|
||||
Avatar::getAvatarList(function ($row) use (&$avatarList){
|
||||
array_push($avatarList,$row);
|
||||
});
|
||||
$this->_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();
|
||||
}
|
||||
}
|
||||
|
78
webapp/models/Avatar.php
Normal file
78
webapp/models/Avatar.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace models;
|
||||
|
||||
use mt;
|
||||
use phpcommon\SqlHelper;
|
||||
use services\NftService;
|
||||
|
||||
class Avatar extends BaseModel
|
||||
{
|
||||
public static function find($avatarUniId){
|
||||
return self::internalFind(myself()->_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(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user