diff --git a/doc/_common.py b/doc/_common.py index 914f1f4f..f00c82f8 100644 --- a/doc/_common.py +++ b/doc/_common.py @@ -96,5 +96,5 @@ class Award(object): def __init__(self): self.fields = [ - ['!item_list', [AwardItem()], '奖励物品列表'] + ['!items', [AwardItem()], '奖励物品列表'] ] diff --git a/webapp/bootstrap/init.php b/webapp/bootstrap/init.php index 02e65860..6af4e249 100644 --- a/webapp/bootstrap/init.php +++ b/webapp/bootstrap/init.php @@ -4,6 +4,7 @@ ini_set('date.timezone','Asia/Shanghai'); require 'phpcommon/common.php'; require_once('phpcommon/sqlhelper.php'); require_once('models/BaseModel.php'); +require_once('services/BaseService.php'); define('TEAMID_KEY', 'team_uuid:'); diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 8202cdcb..049bd9f9 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -6,6 +6,8 @@ require_once('mt/Item.php'); require_once('mt/Parameter.php'); require_once('mt/Drop.php'); +require_once('services/AwardService.php'); + use phpcommon\SqlHelper; class ShopController extends BaseAuthedController { @@ -37,6 +39,10 @@ class ShopController extends BaseAuthedController { $this->_rspErr(2, '配置表错误'); return; } + if (Hero::find($heroId)) { + $this->_rspErr(3, '你已经有该英雄'); + return; + } $costItems = array( 'item_id' => $goodsInfo['costItemId'], 'item_num' => $goodsInfo['costItemNum'], @@ -48,6 +54,14 @@ class ShopController extends BaseAuthedController { } $this->_decItems($costItems); Hero::addHero($heroMeta); + $awardService = new services\AwardService(); + $heroDb = Hero::find($heroId); + if ($heroDb) { + $awardService->addHero(Hero::toDto($heroDb)); + } + $this->rspData(array( + 'award' => $awardService->toData() + )); } public function buyHeroSkin() diff --git a/webapp/services/AwardService.php b/webapp/services/AwardService.php new file mode 100644 index 00000000..e3ccad17 --- /dev/null +++ b/webapp/services/AwardService.php @@ -0,0 +1,49 @@ +internalAdd(self::ITEM_TYPE, $itemDto); + } + + public function addHero($heroDto) + { + $this->internalAdd(self::HERO_TYPE, $heroDto); + } + + public function addHeroSkin($heroSkinDto) + { + $this->internalAdd(self::HEROSKIN_TYPE, $heroSkinDto); + } + + public function addGunSkin($gunSkinDto) + { + $this->internalAdd(self::GUNSKIN_TYPE, $gunSkinDto); + } + + public function toDto() + { + return array( + 'items' => $this->items + ); + } + + private function internalAdd($type, $dto) + { + array_push($items, array( + 'type' => $type, + "union_${type}" => $dto + )); + } + +} diff --git a/webapp/services/BaseService.php b/webapp/services/BaseService.php index e69de29b..190cebfc 100644 --- a/webapp/services/BaseService.php +++ b/webapp/services/BaseService.php @@ -0,0 +1,7 @@ +