From 639d10d6575aca8e0c57e48b75e8fc2935c7266d Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 1 Dec 2021 11:17:44 +0800 Subject: [PATCH] 1 --- doc/_common.py | 8 ++-- webapp/controller/ShopController.class.php | 49 ++++++++++++++++++++++ webapp/mt/Item.php | 6 +-- 3 files changed, 56 insertions(+), 7 deletions(-) diff --git a/doc/_common.py b/doc/_common.py index f61027e..9a2ca92 100644 --- a/doc/_common.py +++ b/doc/_common.py @@ -110,7 +110,7 @@ class CostInfoItem(object): self.fields = [ ['item_id', 0, '购买需要消耗的道具id'], ['item_num', 0, '购买需要消耗的道具数量'], - ['is_discount', 0, '是否参与折扣'], + ['discount', 0, '折扣百分比(0-100)'], ] class CostInfo(object): @@ -125,7 +125,6 @@ class PriceInfo(object): def __init__(self): self.fields = [ ['!cost_list', [CostInfo()], '扣费方式列表'], - ['discount', 0, '折扣百分比(0-100)'], ['discount_begin_time', 0, '折扣开始时间(utc时间)'], ['discount_end_time', 0, '折扣结束时间(utc时间)'], ] @@ -134,8 +133,9 @@ class DiscountInfo(object): def __init__(self): self.fields = [ - ['item_id', 0, '购买需要消耗的道具id'], - ['discount', 0, '折扣百分比(0-100)'], + ['item_id', 0, '道具id'], + ['gold_discount', 0, '金币折扣百分比(0-100)'], + ['diamond_discount', 0, '钻石折扣百分比(0-100)'], ] class ItemPriceInfo(object): diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index b31ef6c..f0f6730 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -196,6 +196,55 @@ class ShopController extends BaseAuthedController { )); } + public function getDiscountList() + { + $items = array(); + { + $types = array(mt\Item::HERO_TYPE, + mt\Item::HERO_SKIN_TYPE, + mt\Item::GUN_SKIN_TYPE); + mt\Item::filter(function ($meta) use(&$items, &$types) { + if (mt\Item::inTypes($meta, $types)) { + array_push($items, $meta); + } + return true; + }); + } + $goodsDtoList = array(); + array_walk($items, function ($val) use(&$priceList, &$goodsDtoList) { + $goodsDto = array( + 'item_id' => $val['id'], + 'gold_discount' => 0, + 'diamond_discount' => 0, + ); + $priceInfo = mt\Item::getPriceInfo($val); + if (!empty($priceInfo)) { + foreach ($priceInfo['price_info']['cost_list'] as $cost) { + if ($cost['discount'] > 0) { + switch ($cost['item_id']) { + case V_ITEM_GOLD: + { + $goodsDto['gold_discount'] = $cost['discount']; + } + break; + case V_ITEM_DIAMOND: + { + $goodsDto['diamond_discount'] = $cost['discount']; + } + break; + } + } + } + if ($goodsDto['gold_discount'] > 0 || $goodsDto['diamond_discount'] > 0) { + array_push($goodsDtoList, $goodsDto); + } + } + }); + $this->_rspData(array( + 'goods_list' => $goodsDtoList, + )); + } + private function outsideBuy($shopId, $itemId, $itemNum, $costItemId) { $itemMeta = mt\Item::get($itemId); diff --git a/webapp/mt/Item.php b/webapp/mt/Item.php index 2a55f96..392ec9d 100644 --- a/webapp/mt/Item.php +++ b/webapp/mt/Item.php @@ -87,17 +87,17 @@ class Item { 'item_id' => $meta['id'], 'price_info' => array( 'cost_list' => array(), - 'discount' => (int)$meta['discount'], 'discount_begin_time' => phpcommon\datetimeToTimestamp($meta['discount_begin']), 'discount_end_time' => phpcommon\datetimeToTimestamp($meta['discount_end']) ) ); + $discount = splitStr1($meta['discount']); if ($meta['gold'] > 0) { array_push($info['price_info']['cost_list'], array( 'item_id' => V_ITEM_GOLD, 'item_num' => $meta['gold'], - 'is_discount' => 1 + 'discount' => count($discount) > 0 ? (int)$discount[0] : 0 )); } if ($meta['diamond_price'] > 0) { @@ -105,7 +105,7 @@ class Item { array( 'item_id' => V_ITEM_DIAMOND, 'item_num' => $meta['diamond_price'], - 'is_discount' => 1 + 'discount' => count($discount) > 1 ? (int)$discount[1] : 0 )); } return $info;