diff --git a/doc/Avatar.py b/doc/Avatar.py new file mode 100644 index 00000000..349a9101 --- /dev/null +++ b/doc/Avatar.py @@ -0,0 +1,73 @@ +# -*- coding: utf-8 -*- + +import _common + +class Avatar(object): + + def __init__(self): + self.apis = [ + { + 'name': 'avatarMetaList', + 'desc': 'item配置表中装饰列表', + 'group': 'Avatar', + 'url': 'webapp/index.php?c=Avatar&a=avatarMetaList', + 'params': [ + _common.ReqHead(), + ], + 'response': [ + _common.RspHead(), + ['!list', [], '装饰列表(参数见item.xlsx字段)'] + ] + },{ + 'name': 'avatarList', + 'desc': '获取装饰物品列表', + 'group': 'Avatar', + 'url': 'webapp/index.php?c=Avatar&a=avatarList', + 'params': [ + _common.ReqHead(), + ], + 'response': [ + _common.RspHead(), + ['!list', [AvatarInfo()], '装饰列表'] + ] + },{ + 'name': 'equip', + 'desc': '穿戴装饰物品', + 'group': 'Avatar', + 'url': 'webapp/index.php?c=Avatar&a=equip', + 'params': [ + _common.ReqHead(), + ['hero_uniid', '', '英雄唯一id'], + ['avatar_uniid', '', '装饰唯一id'], + ], + 'response': [ + _common.RspHead(), + ] + },{ + 'name': 'buyAvatar', + 'desc': '购买装饰物品', + 'group': 'Avatar', + 'url': 'webapp/index.php?c=Avatar&a=buyAvatar', + 'params': [ + _common.ReqHead(), + ['item_id', '', '装饰物品itemId'], + ], + 'response': [ + _common.RspHead(), + ] + }, + ] + + + +class AvatarInfo(object): + + def __init__(self): + self.fields = [ + ['account_id', '', 'account_id'], + ['token_id', '', 'token_id'], + ['item_id', 0, 'item_id'], + ['item_type', 0, '1:翅膀'], + ['status', 0, '0:为穿戴 1:已穿戴'], + ['hero_idx', 0, '穿戴的英雄唯一id'], + ] \ No newline at end of file diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 2464c962..59d04cdc 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -1684,7 +1684,6 @@ 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 '装备状态', diff --git a/webapp/controller/AvatarController.class.php b/webapp/controller/AvatarController.class.php index f2b65d36..f46ab279 100644 --- a/webapp/controller/AvatarController.class.php +++ b/webapp/controller/AvatarController.class.php @@ -3,11 +3,19 @@ require_once('mt/Item.php'); require_once('models/Hero.php'); require_once('models/Avatar.php'); - +require_once('services/LogService.php'); use models\Hero; use models\Avatar; +use services\LogService; class AvatarController extends BaseAuthedController { + public function avatarMetaList(){ + $metaList = \mt\Item::getMetaListByType(\mt\Item::AVATAR_TYPE); + $this->_rspData(array( + 'list' => $metaList + )); + } + public function avatarList(){ $avatarList = array(); Avatar::getAvatarList(function ($row) use (&$avatarList){ @@ -18,7 +26,7 @@ class AvatarController extends BaseAuthedController { )); } - public function useAvatar(){ + public function equip(){ $heroUniid = trim(getReqVal('hero_uniid', 0)); $avatarUniid = trim(getReqVal('avatar_uniid', 0)); @@ -37,16 +45,69 @@ class AvatarController extends BaseAuthedController { return; } $randAttr = emptyReplace(json_decode($heroDb['rand_attr'], true), array()); + $itemMeta = \mt\Item::get($avatarDb['item_id']); + $quality = 1; + foreach ($randAttr as $value){ + $quality = max($quality,$value['quality']); + } + switch ($itemMeta['quality']){ + case 2 : { + if ($quality < 3){ + $this->_rspErr(1, 'Can not meet the wearing condition'); + return; + } + } + break; + case 3 :{ + if ($quality < 4){ + $this->_rspErr(1, 'Can not meet the wearing condition'); + return; + } + } + break; + case 4 :{ + if ($quality < 5){ + $this->_rspErr(1, 'Can not meet the wearing condition'); + return; + } + } + } - + Avatar::equipUpdate($avatarDb,$heroUniid); + $this->_rspOk(); } public function remove(){ - + $avatarUniid = trim(getReqVal('avatar_uniid', 0)); + $avatarDb = Avatar::find($avatarUniid); + if (!$avatarDb){ + $this->_rspErr(1, 'avatar_uniid error'); + return; + } + Avatar::update($avatarUniid,array( + 'hero_idx' => null, + 'status' => 0, + 'modifytime' => myself()->_getNowTime(), + )); + $this->_rspOk(); } public function clearAvatar(){ - + $heroUniid = trim(getReqVal('hero_uniid', 0)); + $heroDb = Hero::find($heroUniid); + if (!$heroDb){ + $this->_rspErr(1, 'hero_uniid error'); + return; + } + $avatarDbs = Avatar::getAvatarByHeroIdx($heroUniid); + foreach ($avatarDbs as $avatarDb){ + Avatar::update($avatarDb['idx'],array( + 'hero_idx' => null, + 'status' => 0, + 'modifytime' => myself()->_getNowTime(), + )); + } + $this->_rspOk(); } @@ -58,8 +119,25 @@ class AvatarController extends BaseAuthedController { return; } //检验钻石是否足够 并消耗钻石 + $costItems = array( + array( + 'item_id' => V_ITEM_DIAMOND, + 'item_num' => $itemMeta['diamond'] + ), + ); + $lackItem = null; + if (!$this->_hasEnoughItems($costItems, $lackItem)) { + $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); + return; + } + $this->_decItems($costItems); { - + //埋点 + $event = [ + 'name' => LogService::BUY_HERO_AVATAR, + 'val' => $itemMeta['diamond'] + ]; + LogService::consumeDiamond($event); } Avatar::addAvatar($itemMeta); $this->_rspOk(); diff --git a/webapp/models/Avatar.php b/webapp/models/Avatar.php index 028a4282..83be5d00 100644 --- a/webapp/models/Avatar.php +++ b/webapp/models/Avatar.php @@ -34,6 +34,30 @@ class Avatar extends BaseModel return $row; } + public static function getAvatarByHeroIdx($heroUniid){ + $rows = SqlHelper::ormSelect( + myself()->_getSelfMysql(), + 't_avatar', + array( + 'hero_idx' => $heroUniid, + ) + ); + return $rows; + } + + public static function getOneByType($heroUniid,$itemType){ + $row = SqlHelper::ormSelectOne( + myself()->_getSelfMysql(), + 't_avatar', + array( + 'hero_idx' => $heroUniid, + 'item_type' => $itemType, + ) + ); + return $row; + } + + public static function getAvatarList($cb){ SqlHelper::ormSelect( myself()->_getSelfMysql(), @@ -42,7 +66,6 @@ class Avatar extends BaseModel 'account_id' => myself()->_getAccountId() ), function ($row) use($cb) { - $row['tags'] = ''; $cb($row); } ); @@ -55,7 +78,6 @@ class Avatar extends BaseModel 'token_id' => $nftDb['token_id'], ) ); - $row['tags'] = $nftDb['tags']; $cb($row); } } @@ -75,4 +97,45 @@ class Avatar extends BaseModel ); } + public static function equipUpdate($avatarDb,$heroUniid){ + $row = self::getOneByType($heroUniid,$avatarDb['item_type']); + if ($row){ + SqlHelper::update( + myself()->_getSelfMysql(), + 't_avatar', + array( + 'idx' => $row['idx'], + ), + array( + 'status' => 0, + 'hero_idx' => null, + 'modifytime' => myself()->_getNowTime(), + ) + ); + } + SqlHelper::update( + myself()->_getSelfMysql(), + 't_avatar', + array( + 'idx' => $avatarDb['idx'], + ), + array( + 'status' => 1, + 'hero_idx' => $heroUniid, + 'modifytime' => myself()->_getNowTime(), + ) + ); + } + + public static function update($avatarUniid,$feildKv){ + SqlHelper::update( + myself()->_getSelfMysql(), + 't_avatar', + array( + 'idx' => $avatarUniid, + ), + $feildKv + ); + } + } \ No newline at end of file diff --git a/webapp/models/Nft.php b/webapp/models/Nft.php index 4b790f25..f9aae1a5 100644 --- a/webapp/models/Nft.php +++ b/webapp/models/Nft.php @@ -26,7 +26,7 @@ class Nft extends BaseModel const GENESIS_TYPE = 7; //创世徽章 const PLANET_TYPE = 8; //星球 const RING_TYPE = 19; //戒指 - const AVATAR_TYPE = 29; //装饰 + const AVATAR_TYPE = 30; //装饰 const GENESIS_TAG = 1; diff --git a/webapp/services/LogService.php b/webapp/services/LogService.php index 75d4fdcb..867358a0 100644 --- a/webapp/services/LogService.php +++ b/webapp/services/LogService.php @@ -17,6 +17,7 @@ class LogService extends BaseService const CHIP_LEVEL_UP = "chip_level_Up"; //芯片升级 const BUY_BATTLE_PASS = "buy_battle_pass"; //通行证购买 const BUY_PASS_EXP = "buy_pass_exp"; //购买通行证经验 + const BUY_HERO_AVATAR = "buy_hero_avatar"; //购买英雄装饰 const SHOP_BUY_ITEM = "shop_buy_item_normal"; //商城购买物品 const SHOP_BUY_ITEM_DAILY = "shop_buy_item_daily"; //商城每日精选购买物品