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

This commit is contained in:
hujiabin 2023-06-28 20:01:14 +08:00
commit 6b0187869b
4 changed files with 207 additions and 64 deletions

View File

@ -217,5 +217,20 @@ class Shop(object):
_common.RspHead(), _common.RspHead(),
['block_chain', _common.ShopTrans(), '链上购买订单信息'] ['block_chain', _common.ShopTrans(), '链上购买订单信息']
] ]
},
{
'name': 'buyBlindBox',
'desc': '购买盲盒(宝箱)',
'group': 'Shop',
'url': 'webapp/index.php?c=Shop&a=buyBlindBox',
'params': [
_common.ReqHead(),
['id', 0, '商品唯一id参见shopGoods表'],
['num', 0, '购买数量 1:单个 10:十连抽'],
],
'response': [
_common.RspHead(),
['!result', [_common.BlindBoxResult()], '盲盒结果列表'],
]
} }
] ]

View File

@ -1219,3 +1219,11 @@ class ShopTrans(object):
['item_id', 0, 'item_id'], ['item_id', 0, 'item_id'],
['item_num', 0, 'item_num'], ['item_num', 0, 'item_num'],
] ]
class BlindBoxResult(object):
def __init__(self):
self.fields = [
['item_id', 0, 'item_id'],
['item_num', 0, 'item_num'],
]

View File

@ -8,6 +8,7 @@ require_once('mt/Parameter.php');
require_once('mt/Drop.php'); require_once('mt/Drop.php');
require_once('mt/PayMethod.php'); require_once('mt/PayMethod.php');
require_once('mt/Dailyselection.php'); require_once('mt/Dailyselection.php');
require_once('mt/ShopChest.php');
require_once('models/User.php'); require_once('models/User.php');
require_once('models/Hero.php'); require_once('models/Hero.php');
@ -40,6 +41,7 @@ use models\Chip;
use mt\Shop; use mt\Shop;
use mt\PayMethod; use mt\PayMethod;
use mt\Dailyselection; use mt\Dailyselection;
use mt\ShopChest;
use models\Transaction; use models\Transaction;
use models\BcOrder; use models\BcOrder;
@ -265,7 +267,7 @@ class ShopController extends BaseAuthedController
$itemMeta = mt\Item::get($row['goods_id']); $itemMeta = mt\Item::get($row['goods_id']);
$propertyChgService = new services\PropertyChgService(); $propertyChgService = new services\PropertyChgService();
for ($i = 0; $i < $goods_num; $i++) { for ($i = 0; $i < $goods_num; $i++) {
$this->internalAddItem($propertyChgService, $itemMeta, $goods_count); $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0);
} }
$awardService = new services\AwardService(); $awardService = new services\AwardService();
$awardService->addItem($row['goods_id'], $goods_num); $awardService->addItem($row['goods_id'], $goods_num);
@ -406,7 +408,7 @@ class ShopController extends BaseAuthedController
$itemMeta = mt\Item::get($row['goods_id']); $itemMeta = mt\Item::get($row['goods_id']);
$propertyChgService = new services\PropertyChgService(); $propertyChgService = new services\PropertyChgService();
for ($i = 0; $i < $goods_num; $i++) { for ($i = 0; $i < $goods_num; $i++) {
$this->internalAddItem($propertyChgService, $itemMeta, $goods_count); $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0);
} }
$awardService = new services\AwardService(); $awardService = new services\AwardService();
// $awardService->addItem($row['goods_id'], $goods_num); // $awardService->addItem($row['goods_id'], $goods_num);
@ -671,7 +673,7 @@ class ShopController extends BaseAuthedController
return; return;
} }
$this->_decItems($costItems); $this->_decItems($costItems);
$this->internalAddItem($propertyChgService, $itemMeta, 1); $this->internalAddItem($propertyChgService, $itemMeta, 1, 0);
$awardService = new services\AwardService(); $awardService = new services\AwardService();
$awardService->addItem($itemId, $itemNum); $awardService->addItem($itemId, $itemNum);
ShopBuyRecord::add($itemId, $itemNum); ShopBuyRecord::add($itemId, $itemNum);
@ -952,7 +954,7 @@ class ShopController extends BaseAuthedController
$itemMeta = mt\Item::get($row['goods_id']); $itemMeta = mt\Item::get($row['goods_id']);
$propertyChgService = new services\PropertyChgService(); $propertyChgService = new services\PropertyChgService();
for ($i = 0; $i < $goods_num; $i++) { for ($i = 0; $i < $goods_num; $i++) {
$this->internalAddItem($propertyChgService, $itemMeta, $goods_count); $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0);
} }
$awardService = new services\AwardService(); $awardService = new services\AwardService();
$awardService->addItem($row['goods_id'], $goods_num); $awardService->addItem($row['goods_id'], $goods_num);
@ -992,10 +994,10 @@ class ShopController extends BaseAuthedController
$propertyChgService = new services\PropertyChgService(); $propertyChgService = new services\PropertyChgService();
$this->addFreeBuyRecord($row); $this->addFreeBuyRecord($row);
$itemMeta = mt\Item::get($row['goods_id']); $itemMeta = mt\Item::get($row['goods_id']);
$this->internalAddItem($propertyChgService, $itemMeta, $goods_count); $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 1);
$this->_rspOk(); $this->_rspOk();
} else { } else {
error_log("buy normal 1, need_price = ". $need_price . " goods_num = " . $goods_num); error_log("buy normal 1, need_price = " . $need_price . " goods_num = " . $goods_num);
$price = $this->normalizeWeb3Price($goods_num * $need_price); $price = $this->normalizeWeb3Price($goods_num * $need_price);
error_log("buy normal 2, price = " . $price); error_log("buy normal 2, price = " . $price);
$item_id = $row['goods_id']; $item_id = $row['goods_id'];
@ -1096,15 +1098,16 @@ class ShopController extends BaseAuthedController
$price = $this->normalizeWeb3Price($goods['price'] * $count); $price = $this->normalizeWeb3Price($goods['price'] * $count);
$item_id = $goods['goods_id']; $item_id = $goods['goods_id'];
$item_count = $goods['goods_num'] * $count; $item_count = $goods['goods_num'] * $count;
error_log("buyGoodsDS start " . json_encode(array( error_log("buyGoodsDS start " . json_encode(
'idx' => $idx, array(
'grid' => $grid, 'idx' => $idx,
'count' => $count, 'grid' => $grid,
'goodPrice' => $goods['price'], 'count' => $count,
'price' => $price, 'goodPrice' => $goods['price'],
'item_id' => $item_id, 'price' => $price,
'item_count' => $item_count, 'item_id' => $item_id,
) 'item_count' => $item_count,
)
)); ));
$response = services\BlockChainService::gameItemMallBuy( $response = services\BlockChainService::gameItemMallBuy(
Transaction::BUY_GOODS_ACTION_TYPE, Transaction::BUY_GOODS_ACTION_TYPE,
@ -1125,12 +1128,13 @@ class ShopController extends BaseAuthedController
)), )),
)); ));
error_log("buyGoodsDS start " . json_encode(array( error_log("buyGoodsDS start " . json_encode(
'idx' => $idx, array(
'grid' => $grid, 'idx' => $idx,
'count' => $count, 'grid' => $grid,
'block_chain' => $response, 'count' => $count,
) 'block_chain' => $response,
)
)); ));
$this->_rspData( $this->_rspData(
@ -1143,6 +1147,80 @@ 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;
}
$isFreeBuy = false;
if (!empty($shop['free_type'])) {
$count = $this->countFreeBuyTimes($shop);
if ($count < $shop['free_num']) {
$isFreeBuy = true;
}
}
$cost = $shop['price'] * $num;
if ($isFreeBuy) {
$cost = 0;
}
$recommend = $shop['recommend'];
$itemStore = mt\ShopChest::getRandomItemListByChestType($recommend);
if ($isFreeBuy) {
if ($num != 1) {
$this->_rspErr(2, 'num is invalid');
return;
}
}
$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']);
$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]);
}
if ($isFreeBuy && $num == 1) {
$this->addFreeBuyRecord($shop);
}
}
error_log("buyBlindBox start " . json_encode(
array(
'account' => $account,
'itemListStore' => $result,
)
));
$this->_rspData(
array(
'reuslt' => $result,
)
);
}
private function buyGoodsFree() private function buyGoodsFree()
{ {
@ -1335,7 +1413,7 @@ class ShopController extends BaseAuthedController
return; return;
} }
$this->_decItems($costItems); $this->_decItems($costItems);
$this->internalAddItem($propertyChgService, $itemMeta, 1); $this->internalAddItem($propertyChgService, $itemMeta, 1, 0);
$awardService = new services\AwardService(); $awardService = new services\AwardService();
$awardService->addItem($itemId, $itemNum); $awardService->addItem($itemId, $itemNum);
ShopBuyRecord::add($itemId, $itemNum); ShopBuyRecord::add($itemId, $itemNum);
@ -1454,7 +1532,7 @@ class ShopController extends BaseAuthedController
return $costItems; return $costItems;
} }
private function internalAddItem($propertyChgService, $itemMeta, $count) private function internalAddItem($propertyChgService, $itemMeta, $count, $sysAdd)
{ {
switch ($itemMeta['type']) { switch ($itemMeta['type']) {
case mt\Item::HERO_TYPE: { case mt\Item::HERO_TYPE: {
@ -1488,8 +1566,10 @@ class ShopController extends BaseAuthedController
$this->_addVirtualItem($itemMeta['id'], $count, null, $propertyChgService); $this->_addVirtualItem($itemMeta['id'], $count, null, $propertyChgService);
$propertyChgService->addUserChg(); $propertyChgService->addUserChg();
// 充值就尝试开启首充活动 // 充值就尝试开启首充活动
if ($itemMeta['id'] == 10001) { if ($sysAdd != 1) {
$this->beginFirstTupop(); if ($itemMeta['id'] == 10001) {
$this->beginFirstTupop();
}
} }
} else { } else {
Bag::addItem($itemMeta['id'], $count); Bag::addItem($itemMeta['id'], $count);
@ -1587,50 +1667,48 @@ class ShopController extends BaseAuthedController
return phpcommon\bnToStr($ret_price); return phpcommon\bnToStr($ret_price);
} }
private function countFreeBuyTimes($goods) { private function countFreeBuyTimes($goods)
{
$conn = myself()->_getMysql(''); $conn = myself()->_getMysql('');
$account = myself()->_getAccountId(); $account = myself()->_getAccountId();
switch($goods['free_type']) switch ($goods['free_type']) {
{ case 1: {
case 1: $dayTime = myself()->_getNowDaySeconds();
{ $sql = 'SELECT COUNT(*) as cnt FROM t_shop_free_record WHERE account_id = ? AND `id` = ? AND goods_id = ? AND createtime >= ?';
$dayTime = myself()->_getNowDaySeconds(); $row = $conn->execQueryOne($sql, array($account, $goods['id'], $goods['goods_id'], $dayTime));
$sql = 'SELECT COUNT(*) as cnt FROM t_shop_free_record WHERE account_id = ? AND `id` = ? AND goods_id = ? AND createtime >= ?'; return $row['cnt'];
$row = $conn->execQueryOne($sql, array($account, $goods['id'], $goods['goods_id'], $dayTime)); }
return $row['cnt']; break;
}
break;
} }
return 0; return 0;
} }
private function addFreeBuyRecord($goods) { private function addFreeBuyRecord($goods)
{
$conn = myself()->_getMysql(''); $conn = myself()->_getMysql('');
$account = myself()->_getAccountId(); $account = myself()->_getAccountId();
switch($goods['free_type']) switch ($goods['free_type']) {
{ case 1: {
case 1: $dayTime = myself()->_getNowTime();
{ SqlHelper::insert(
$dayTime = myself()->_getNowTime(); $conn,
SqlHelper::insert( 't_shop_free_record',
$conn, array(
't_shop_free_record', 'account_id' => $account,
array( 'shop_id' => $goods['shop_id'],
'account_id' => $account, 'id' => $goods['id'],
'shop_id' => $goods['shop_id'], 'goods_id' => $goods['goods_id'],
'id' => $goods['id'], 'goods_num' => $goods['goods_num'],
'goods_id' => $goods['goods_id'], 'free_type' => $goods['free_type'],
'goods_num' => $goods['goods_num'], 'free_num' => $goods['free_num'],
'free_type' => $goods['free_type'], 'createtime' => $dayTime,
'free_num' => $goods['free_num'], )
'createtime' => $dayTime, );
) }
); break;
}
break;
} }
} }
} }

42
webapp/mt/ShopChest.php Normal file
View File

@ -0,0 +1,42 @@
<?php
namespace mt;
use phpcommon;
class ShopChest
{
public static function getRandomItemListByChestType($chestType) {
self::cacheRandomItemListByChestTypes();
return getXVal(self::$itemListWithChestType, $chestType, null);
}
protected static function cacheRandomItemListByChestTypes() {
if (!self::$itemListWithChestType) {
self::$itemListWithChestType = array();
foreach (self::getMetaList() as $meta) {
if (!getXVal(self::$itemListWithChestType, $meta['chest_type'], null)) {
self::$itemListWithChestType[$meta['chest_type']] = array();
}
if(!getXVal(self::$itemListWithChestType[$meta['chest_type']], $meta['item_type'], null)) {
self::$itemListWithChestType[$meta['chest_type']][$meta['item_type']] = array();
}
array_push(self::$itemListWithChestType[$meta['chest_type']][$meta['item_type']], $meta);
}
}
}
protected static function getMetaList()
{
if (!self::$metaList) {
self::$metaList = getMetaTable('Shopchest@Shopchest.php');
}
return self::$metaList;
}
protected static $itemListWithChestType;
protected static $metaList;
}