From de97c91d2a58b5de2ce7c71d2b2bf72c97906487 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 30 Nov 2021 16:39:18 +0800 Subject: [PATCH] 1 --- sql/gamedb.sql | 15 +- .../controller/BaseAuthedController.class.php | 17 ++ webapp/controller/ShopController.class.php | 151 +++++++++++++++++- webapp/models/GunSkin.php | 24 +++ webapp/mt/Item.php | 11 +- webapp/services/AwardService.php | 35 +--- 6 files changed, 213 insertions(+), 40 deletions(-) diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 35ae5e3..f98fbb5 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -126,6 +126,7 @@ CREATE TABLE `t_gun_skin` ( `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', `account_id` varchar(60) CHARACTER SET utf8 NOT NULL COMMENT 'account_id', `skin_id` int(11) NOT NULL DEFAULT '0' COMMENT '皮肤ID', + `skin_state` int(11) NOT NULL DEFAULT '0' COMMENT '状态(0=已经购,1 = 试用状态)', `try_expire_at` int(11) NOT NULL DEFAULT '0' COMMENT '试用截止时间', `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', @@ -155,13 +156,13 @@ CREATE TABLE `t_gun_talent` ( /*!40101 SET character_set_client = @saved_cs_client */; -- --- Table structure for table `dyndata` +-- Table structure for table `t_dyndata` -- -DROP TABLE IF EXISTS `dyndata`; +DROP TABLE IF EXISTS `t_dyndata`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `dyndata` ( +CREATE TABLE `t_dyndata` ( `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)', `x` int(11) NOT NULL DEFAULT '0' COMMENT 'x', @@ -175,10 +176,14 @@ CREATE TABLE `dyndata` ( ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*!40101 SET character_set_client = @saved_cs_client */; -DROP TABLE IF EXISTS `shop_data`; +-- +-- Table structure for table `t_shop_data` +-- + +DROP TABLE IF EXISTS `t_shop_data`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `shop_data` ( +CREATE TABLE `t_shop_data` ( `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id', `shop_id` int(11) NOT NULL DEFAULT '0' COMMENT '商店id', diff --git a/webapp/controller/BaseAuthedController.class.php b/webapp/controller/BaseAuthedController.class.php index 266c9ba..7772bb3 100644 --- a/webapp/controller/BaseAuthedController.class.php +++ b/webapp/controller/BaseAuthedController.class.php @@ -1,6 +1,7 @@ _decItems($costItems); - Hero::addHero($heroMeta); + $this->internalAddItem($heroMeta); $awardService = new services\AwardService(); $heroDb = Hero::find($heroId); if ($heroDb) { $awardService->addHero(Hero::toDto($heroDb)); } $this->rspData(array( - 'award' => $awardService->toData() + 'award' => $awardService->toDto() )); } @@ -77,6 +77,90 @@ class ShopController extends BaseAuthedController { $itemId = getReqVal('item_id', 0); $itemNum = getReqVal('item_num', 0); $costItemId = getReqVal('cost_item_id', 0); + + $itemMeta = mt\Item::get($itemId); + if (!$itemMeta) { + $this->_rspErr(1, 'item_id参数错误'); + return; + } + if ($itemNum != 1) { + $this->_rspErr(1, 'item_num参数必须等于1'); + return; + } + $costItemMeta = mt\Item::get($costItemId); + if (!$costItemMeta) { + $this->_rspErr(1, 'cost_item_id参数错误'); + return; + } + $types = array(mt\Item::HERO_TYPE, + mt\Item::HERO_SKIN_TYPE, + mt\Item::GUN_SKIN_TYPE); + if (!mt\Item::inTypes($itemMeta, $types)) { + $this->_rspErr(1, 'cost_item_id参数错误'); + return; + } + { + switch ($itemMeta['type']) { + case mt\Item::HERO_TYPE: + { + $heroDb = Hero::find($itemMeta['id']); + if (!$heroDb) { + $this->_rspErr(4, '你已经拥有该英雄'); + return; + } + } + break; + case mt\Item::HERO_SKIN_TYPE: + { + $heroSkinDb = HeroSkin::find($itemMeta['id']); + if (!$heroSkinDb) { + $this->_rspErr(4, '你已经拥有该皮肤'); + return; + } + } + break; + case mt\Item::GUN_SKIN_TYPE: + { + $gunSkinDb = GunSkin::find($itemMeta['id']); + if (!$gunSkinDb) { + $this->_rspErr(4, '你已经拥有该皮肤'); + return; + } + } + break; + default: + { + $this->_rspErr(1, 'cost_item_id参数错误'); + return; + } + break; + } + } + $priceInfo = mt\Item::getPriceInfo($itemMeta); + if (empty($priceInfo)) { + $this->_rspErr(2, '配置表错误'); + return; + } + $costItems = $this->getCostTimes($priceInfo, $costItemId); + if (empty($costItems)) { + $this->_rspErr(2, '配置表错误2'); + return; + } + $lackItem = null; + if (!$this->_hasEnoughItems($costItems, $lackItem)) { + $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); + return; + } + $this->_decItems($costItems); + $this->internalAddItem($itemMeta); + $awardService = new services\AwardService(); + $awardService->addItem($itemId, $itemNum); + $this->rspData(array( + 'award' => $awardService->toDto(), + 'property_chg' => array( + 'user_info' => User::info($this->_getOrmUserInfo()) + ) + )); } public function getOutsidePriceInfo() @@ -87,7 +171,7 @@ class ShopController extends BaseAuthedController { mt\Item::HERO_SKIN_TYPE, mt\Item::GUN_SKIN_TYPE); mt\Item::filter(function ($meta) use(&$items, &$types) { - if (in_array($meta['type'], $types)) { + if (mt\Item::inTypes($meta, $types)) { array_push($items, $meta); } return true; @@ -102,4 +186,65 @@ class ShopController extends BaseAuthedController { )); } + private function getCostItems($priceInfo, $costItemId) + { + $costGroup = null; + array_walk($priceInfo['cost_list'], function ($val) use(&$costGroup, $costItemId) { + if ($costGroup) { + return; + } + if (count($val) > 0 && $val[0]['cost_item_id'] == $costItemId) { + $costGroup = $val; + return; + } + }); + if (!$costGroup) { + return null; + } + $costItems = array(); + array_walk($costGroup, function ($val) use (&$costItems, $priceInfo) { + if ($val['cost_item_is_discount'] && + $priceInfo['discount'] > 0 && + $this->_getNowTime() >= $priceInfo['discount_begin_time'] && + $this->_getNowTime() <= $priceInfo['discount_end_time'] + ) { + array_push($costItems, array( + 'item_id' => $val['cost_item_id'], + 'item_num' => (int)($val['cost_item_num'] * ($priceInfo['discount'] / 100)), + )); + } else { + array_push($costItems, array( + 'item_id' => $val['cost_item_id'], + 'item_num' => $val['cost_item_num'], + )); + } + }); + return $costItems; + } + + private function internalAddItem($itemMeta) + { + switch ($itemMeta['type']) { + case mt\Item::HERO_TYPE: + { + Hero::addHero($itemMeta); + } + break; + case mt\Item::HERO_SKIN_TYPE: + { + HeroSkin::addSkin($itemMeta); + } + break; + case mt\Item::GUN_SKIN_TYPE: + { + GunSkin::addSkin($itemMeta); + } + break; + default: + { + } + break; + } + } + } diff --git a/webapp/models/GunSkin.php b/webapp/models/GunSkin.php index 2fa08de..41015c6 100644 --- a/webapp/models/GunSkin.php +++ b/webapp/models/GunSkin.php @@ -32,4 +32,28 @@ class GunSkin extends BaseModel { ); } + public static function addSkin($skinId) + { + SqlHelper::upsert( + myself()->_getSelfMysql(), + 't_gun_skin', + array( + 'account_id' => myself()->_getAccountId(), + 'skin_id' => $skinId + ), + array( + 'skin_state' => self::GETED_STATE, + 'modifytime' => myself()->_getNowTime() + ), + array( + 'account_id' => myself()->_getAccountId(), + 'skin_id' => $skinId, + 'skin_state' => self::GETED_STATE, + 'try_expire_at' => 0, + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime() + ) + ); + } + } diff --git a/webapp/mt/Item.php b/webapp/mt/Item.php index d6415de..7e1e28f 100644 --- a/webapp/mt/Item.php +++ b/webapp/mt/Item.php @@ -63,6 +63,11 @@ class Item { return $meta['type'] == $type; } + public static function inTypes($meta, $types) + { + return in_array($meta['type'], $types); + } + public static function filter($cb) { foreach (self::getMetaList() as $meta) { @@ -87,14 +92,16 @@ class Item { array_push($info['price_info']['cost_list'], array( 'cost_item_id' => V_ITEM_GOLD, - 'cost_item_num' => $meta['gold'] + 'cost_item_num' => $meta['gold'], + 'cost_item_is_discount' => 1 )); } if ($meta['diamond_price'] > 0) { array_push($info['price_info']['cost_list'], array( 'cost_item_id' => V_ITEM_DIAMOND, - 'cost_item_num' => $meta['diamond_price'] + 'cost_item_num' => $meta['diamond_price'], + 'cost_item_is_discount' => 1 )); } return $info; diff --git a/webapp/services/AwardService.php b/webapp/services/AwardService.php index e3ccad1..3a7dee6 100644 --- a/webapp/services/AwardService.php +++ b/webapp/services/AwardService.php @@ -4,31 +4,14 @@ namespace services; class AwardService extends BaseService { - const ITEM_TYPE = 1; - const HERO_TYPE = 2; - const HEROSKIN_TYPE = 3; - const GUNSKIN_TYPE = 4; - private $items = array(); - public function addItem($itemDto) + public function addItem($itemId, $itemNum) { - $this->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); + array_push($items, array( + 'item_id' => $itemId, + 'item_num' => $itemNum + )); } public function toDto() @@ -38,12 +21,4 @@ class AwardService extends BaseService { ); } - private function internalAdd($type, $dto) - { - array_push($items, array( - 'type' => $type, - "union_${type}" => $dto - )); - } - }