From 8edf14e24001ca12c1980d641e09c5b230ca130f Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 28 Jul 2023 11:25:24 +0800 Subject: [PATCH] 1 --- doc/Shop.py | 23 +----- webapp/controller/ShopController.class.php | 90 +--------------------- 2 files changed, 7 insertions(+), 106 deletions(-) diff --git a/doc/Shop.py b/doc/Shop.py index fdade734..97ae3b3c 100644 --- a/doc/Shop.py +++ b/doc/Shop.py @@ -163,28 +163,13 @@ class Shop(object): ] }, { - 'name': 'buyBlindBox', - 'desc': '购买盲盒(宝箱)', + 'name': 'boxPreview', + 'desc': '宝箱道具预览', 'group': 'Shop', - 'url': 'webapp/index.php?c=Shop&a=buyBlindBox', + 'url': 'webapp/index.php?c=Shop&a=boxPreview', 'params': [ _common.ReqHead(), - ['id', 0, '商品唯一id,参见shopGoods表'], - ['num', 0, '购买数量 1:单个 10:十连抽'], - ], - 'response': [ - _common.RspHead(), - ['!result', [_common.BlindBoxResult()], '盲盒结果列表'], - ] - }, - { - 'name': 'getChestItems', - 'desc': '获取宝箱可能出现的物品列表', - 'group': 'Shop', - 'url': 'webapp/index.php?c=Shop&a=getChestItems', - 'params': [ - _common.ReqHead(), - ['id', 0, '商品唯一id,参见shopGoods表'], + ['goods_uuid', 0, '商品唯一id'], ], 'response': [ _common.RspHead(), diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index b0aa2b75..9a81f2d7 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -632,9 +632,10 @@ class ShopController extends BaseAuthedController case ShopController::TOKEN_TYPE_BUSD: case ShopController::TOKEN_TYPE_MATIC: case ShopController::TOKEN_TYPE_BNB: - default: + default: { $this->_rspErr(1, "token_type is unsupport, {$token_type}"); } + } } public function buyDiamond() @@ -684,7 +685,7 @@ class ShopController extends BaseAuthedController ); } - public function getChestItems() + public function boxPreview() { $id = getReqVal('id', 0); $goods = mt\ShopGoods::get($id); @@ -960,89 +961,4 @@ class ShopController extends BaseAuthedController } } - public function buyBlindBox() - { - $account = $this->_getAccountId(); - - $id = getReqVal('id', 0); - $num = getReqVal('num', 0); - - if (!($num == 1 || $num == 10)) { - $this->_rspErr(2, 'num is invalid'); - return; - } - - $shop = mt\ShopGoods::get($id); - if (!$shop) { - $this->_rspErr(2, 'id is invalid'); - return; - } - $meta = mt\Item::get($shop['goods_id']); - $cost = $shop['price'] * $num; - $isFreeBuy = false; - if (!empty($shop['free_type'])) { - $count = $this->countFreeBuyTimes($shop['free_type'], $shop['id'], $shop['goods_id']); - if ($count < $shop['free_num']) { - $isFreeBuy = true; - } - } - if ($isFreeBuy) { - if ($num != 1) { - $this->_rspErr(2, 'num is invalid'); - return; - } - } else { - $costItems = $this->makeCostItems(V_ITEM_DIAMOND, $num * $shop['price']); - $lackItem = null; - if (!$this->_hasEnoughItems($costItems, $lackItem)) { - $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); - return; - } - } - - $itemStore = mt\ShopChest::getRandomItemListByChestType($meta['sub_type']); - $grade = $meta['sub_type']; - $result = array(); - for ($i = 0; $i < $num; $i++) { - $record = array(); - foreach ($itemStore as $key => $value) { - $item = $this->weighted_random($value); - $itemMeta = mt\Item::get($item['item_id']); - if (!$itemMeta) { - $this->_rspErr(2, 'item_id is invalid ' . $item['item_id'] . ' in blind box ' . $shop['goods_id']); - return; - } - $propertyChgService = new services\PropertyChgService(); - if ($item['item_type'] == 2) { - $this->internalAddItem($propertyChgService, $itemMeta, $item['num'], 0, $grade); - } else { - for ($j = 0; $j < $item['num']; $j++) { - $this->internalAddItem($propertyChgService, $itemMeta, 1, 0, $grade); - } - } - $record[$key] = array("item_id" => $item['item_id'], "item_num" => $item['num']); - array_push($result, $record[$key]); - } - if ($isFreeBuy) { - $this->addFreeBuyRecord($shop); - } - } - - if (!$isFreeBuy) { - $this->_decItems($costItems); - $event = [ - 'name' => LogService::SHOP_BUY_ITEM_BLIND_BOX, - 'val' => $costItems[0]['item_num'] - ]; - LogService::consumeDiamond($event); - } - $propertyChgService->addUserChg(); - $this->_rspData( - array( - 'reuslt' => $result, - 'property_chg' => $propertyChgService->toDto(), - ) - ); - } - }