Merge branch 'star' of git.kingsome.cn:server/game2006api into star

This commit is contained in:
hujiabin 2023-06-29 18:01:25 +08:00
commit a7d64cdd48
3 changed files with 109 additions and 1 deletions

View File

@ -247,5 +247,32 @@ class Shop(object):
['!items', [0], '宝箱物品列表'],
]
},
{
'name': 'openBlindBox',
'desc': '打开盲盒',
'group': 'Shop',
'url': 'webapp/index.php?c=Shop&a=openBlindBox',
'params': [
_common.ReqHead(),
['item_id', 0, '宝箱物品id item_id'],
],
'response': [
_common.RspHead(),
['!items', [_common.BlindBoxResult()], '宝箱物品列表'],
]
},
{
'name': 'getMyBlindBoxs',
'desc': '获取我的盲盒列表',
'group': 'Shop',
'url': 'webapp/index.php?c=Shop&a=getMyBlindBoxs',
'params': [
_common.ReqHead(),
],
'response': [
_common.RspHead(),
['!items', [0], '盲盒列表'],
]
},
]

View File

@ -1147,7 +1147,7 @@ class ShopController extends BaseAuthedController
);
}
public function buyBlindBox()
private function buyBlindBox()
{
$account = $this->_getAccountId();
@ -1229,6 +1229,61 @@ class ShopController extends BaseAuthedController
);
}
public function openBlindBox()
{
$account = $this->_getAccountId();
$item_id = getReqVal('item_id', 0);
$meta = mt\Item::get($item_id);
$box = Bag::find($item_id);
if (!$box) {
$this->_rspErr(2, 'item_id is invalid');
return;
}
$num = $box['item_num'];
if ($num <= 1) {
$this->_rspErr(2, 'num is invalid');
return;
}
$itemStore = mt\ShopChest::getRandomItemListByChestType($meta['sub_type']);
$result = array();
Bag::decItem($item_id, $num);
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']);
$propertyChgService = new services\PropertyChgService();
if ($item['item_type'] == 2) {
$this->internalAddItem($propertyChgService, $itemMeta, $item['num'], 1);
} else {
for ($j = 0; $j < $item['num']; $j++) {
$this->internalAddItem($propertyChgService, $itemMeta, 1, 1);
}
}
$record[$key] = array("item_id" => $item['item_id'], "item_num" => $item['num']);
array_push($result, $record[$key]);
}
}
error_log("openBlindBox start " . json_encode(
array(
'account' => $account,
'item_id' => $item_id,
'num' => $num,
'items' => $result,
)
));
$this->_rspData(
array(
'items' => $result,
)
);
}
public function getChestItems()
{
$goods_id = getReqVal('goods_id', 0);
@ -1261,6 +1316,21 @@ class ShopController extends BaseAuthedController
);
}
public function getMyBlindBoxs() {
$itemDb = Bag::getAllByType(mt\Item::CHEST_BOX_TYPE);
$items = array();
foreach ($itemDb as $key => $value) {
array_push($items, $value['item_id']);
}
$this->_rspData(
array(
'items' => $items,
)
);
}
private function buyGoodsFree()
{
}

View File

@ -103,6 +103,17 @@ class Bag extends BaseModel {
);
}
public static function getAllByType($type) {
$itemList = array();
self::getItemList(function ($row) use(&$itemList, $type) {
$itemMeta = mt\Item::get($row['item_id']);
if ($itemMeta['type'] == $type && $row['item_num'] > 0) {
array_push($itemList, $row);
}
});
return $itemList;
}
public static function all()
{
$itemList = array();