diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 3fa1048c..a4641300 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -84,7 +84,7 @@ CREATE TABLE `t_hero` ( `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', PRIMARY KEY (`idx`), - UNIQUE KEY `account_id_hero_id` (`account_id`, `hero_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/HeroController.class.php b/webapp/controller/HeroController.class.php index d794f4eb..c7482cf6 100644 --- a/webapp/controller/HeroController.class.php +++ b/webapp/controller/HeroController.class.php @@ -51,10 +51,10 @@ class HeroController extends BaseAuthedController { public function takeonSkin() { - $heroId = getReqVal('hero_id', 0); + $heroUniId = getReqVal('hero_uniid', 0); $skinId = getReqVal('skin_id', 0); - $heroDb = Hero::find($heroId); - $heroSkinDb = Hero::find($skinId); + $heroDb = Hero::find($heroUniId); + $heroSkinDb = HeroSkin::find($skinId); if (!$heroDb) { $this->_rspErr(1, '你还没这个英雄'); return; @@ -63,15 +63,15 @@ class HeroController extends BaseAuthedController { $this->_rspErr(2, '你还没这个皮肤'); return; } - Hero::takeonSkin($heroId, $skinId); + Hero::takeonSkin($heroUniId, $skinId); $this->_rspOk(); } public function upgradeSkill() { - $heroId = getReqVal('hero_id', 0); + $heroUniId = getReqVal('hero_uniid', 0); $skillIdx = getReqVal('skill_idx', 0); - $heroDb = Hero::find($heroId); + $heroDb = Hero::find($heroUniId); if (!$heroDb) { $this->_rspErr(1, '你还没这个英雄'); return; @@ -80,15 +80,7 @@ class HeroController extends BaseAuthedController { $this->_rspErr(1, 'skill_idx参数必须为0-1'); return; } - Hero::upgradeSkill($heroId, $skillIdx); - $this->_rspOk(); - } - - public function useYokeItem() - { - $heroId = getReqVal('hero_id', 0); - $itemId = getReqVal('item_id', 0); - $itemNum = getReqVal('item_num', 0); + Hero::upgradeSkill($heroUniId, $skillIdx); $this->_rspOk(); } diff --git a/webapp/models/Hero.php b/webapp/models/Hero.php index 78886d83..18f8d8eb 100644 --- a/webapp/models/Hero.php +++ b/webapp/models/Hero.php @@ -10,31 +10,55 @@ use phpcommon\SqlHelper; class Hero extends BaseModel { - public static function find($heroId) + const GETED_STATE = 0; + const TRY_STATE = 1; + + const NO_LOCK = 1; + const LEVEL_LOCK = 1; + const QUALITY_LOCK = 2; + + public static function find($heroUniId) { $row = SqlHelper::ormSelectOne( myself()->_getSelfMysql(), 't_hero', array( 'account_id' => myself()->_getAccountId(), - 'hero_id' => $heroId, + 'idx' => $heroUniId, ) ); + if ($row) { + $row['hero_uniid'] = $row['idx']; + } return $row; } public static function toDto($row) { - return array( + $attr = emptyReplace(json_decode($row['attr'], true), array()); + $lockType = 0; + $lockTime = 0; + if ($row['lock_type'] != 0 && $row['unlock_time'] - myself()->_getNowTime() > 0) { + $lockType = $row['lock_type']; + $lockTime = $row['unlock_time'] - myself()->_getNowTime(); + } + $tradeLocktime = max(0, $row['unlock_trade_time'] - myself()->_getNowTime()); + $dto = array( 'hero_id' => $row['hero_id'], 'hero_lv' => $row['hero_lv'], 'hero_tili' => $row['hero_tili'], + 'state' => $row['state'], 'skin_id' => $row['skin_id'], + 'quality' => $row['quality'], 'skill_lv1' => $row['skill_lv1'], 'skill_lv2' => $row['skill_lv2'], - 'yoke_lv' => $row['yoke_lv'], - 'yoke_exp' => $row['yoke_exp'], + 'attr' => $attr, + 'try_count' => $row['try_count'], + 'lock_type' => $lockType, + 'lock_time' => $lockTime, + 'trade_locktime' => $tradeLocktime, ); + return $dto; } public static function addHero($heroMeta) @@ -54,63 +78,50 @@ class Hero extends BaseModel { 'hero_id' => $heroMeta['id'], 'hero_lv' => 1, 'hero_tili' => $realHeroMeta ? $realHeroMeta['tili'] : 0, + 'state' => self::GETED_STATE, #'skin_id' => $defSkin, 'skill_lv1' => 1, 'skill_lv2' => 1, - 'yoke_lv' => 0, - 'yoke_exp' => 0, + 'attr' => '[]', + 'lock_type' => self::NO_LOCK, + 'unlock_time' => 0, + 'unlock_trade_time' => 0, 'createtime' => myself()->_getNowTime(), 'modifytime' => myself()->_getNowTime() ) ); } - public static function takeonSkin($heroId, $skinId) + public static function takeonSkin($heroUniId, $skinId) { - SqlHelper::update( - myself()->_getSelfMysql(), - 't_hero', - array( - 'account_id' => myself()->_getAccountId(), - 'hero_id' => $heroMeta['id'] - ), - array( - 'skin_id' => $skinId, - 'modifytime' => myself()->_getNowTime() - ) - ); + self::update($heroUniId, array( + 'skin_id' => $skinId, + 'modifytime' => myself()->_getNowTime() + )); } - public static function upgradeSkill($heroId, $skillIdx) + public static function upgradeSkill($heroUniId, $skillIdx) { if (!in_array($skillIdx, array(0, 1))) { return; } $fieldName = 'skill_lv' . ($skillIdx + 1); - SqlHelper::update( - myself()->_getSelfMysql(), - 't_hero', - array( - 'account_id' => myself()->_getAccountId(), - 'hero_id' => $heroId - ), - array( + self::update($heroUniId, array( $fieldName => function () use($fieldName) { return "${fieldName} + 1"; }, 'modifytime' => myself()->_getNowTime() - ) - ); + )); } - public static function update($heroId, $fieldsKv) + public static function update($heroUniId, $fieldsKv) { SqlHelper::update (myself()->_getSelfMysql(), 't_hero', array( 'account_id' => myself()->_getAccountId(), - 'hero_id' => $heroId, + 'idx' => $heroUniId, ), $fieldsKv ); diff --git a/webapp/services/BattleDataService.php b/webapp/services/BattleDataService.php index 8d73a9b4..9f2b4d68 100644 --- a/webapp/services/BattleDataService.php +++ b/webapp/services/BattleDataService.php @@ -301,7 +301,7 @@ class BattleDataService extends BaseService { private function decCost() { - $heroDb = Hero::find(getReqVal('hero_id', 0)); + $heroDb = Hero::find(getReqVal('hero_uniid', 0)); if (!$heroDb) { return false; } @@ -309,7 +309,7 @@ class BattleDataService extends BaseService { if ($heroDb['hero_tili'] < $costTili) { return false; } - Hero::update($heroDb['hero_id'], array( + Hero::update($heroDb['hero_uniid'], array( 'hero_tili' => function () use($costTili) { return "GREATEST(0, hero_tili - ${costTili})"; }