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

This commit is contained in:
hujiabin 2023-07-06 11:42:29 +08:00
commit 508ba7aff0
2 changed files with 196 additions and 65 deletions

View File

@ -63,6 +63,8 @@ class ShopController extends BaseAuthedController
const TOKEN_TYPE_CEG = '1';
const TOKEN_TYPE_CEC = '2';
const TOKEN_TYPE_BCEG = '3';
const TOKEN_TYPE_DIAMOND = '4';
const TOKEN_TYPE_USDT = '11';
const TOKEN_TYPE_USDC = '12';
@ -358,11 +360,7 @@ class ShopController extends BaseAuthedController
public function refreshDailySelection()
{
$address = $this->_getAddress();
if (empty($address)) {
$this->_rspErr(2, 'address is empty');
return;
}
$address = $this->_getAccountId();
$maxCount = mt\Parameter::getByName('daily_selection_refresh_time')['param_value'];
$count = $this->countTodayRefreshTimes($address);
@ -400,11 +398,7 @@ class ShopController extends BaseAuthedController
public function getDailySelectionList()
{
$address = $this->_getAddress();
if (empty($address)) {
$this->_rspErr(3, 'address is empty');
return;
}
$address = $this->_getAccountId();
// 不清除过期的每日精选可以避免跨日操作错误
// $chk = $this->clearBeforeTodayDailySelections();
@ -445,10 +439,10 @@ class ShopController extends BaseAuthedController
public function buyGoodsNormal()
{
$address = $this->_getAddress();
if (empty($address)) {
$this->_rspErr(4, 'address is empty');
return;
}
// if (empty($address)) {
// $this->_rspErr(4, 'address is empty');
// return;
// }
$id = getReqVal('id', 0);
$token_type = getReqVal('token_type', '');
$goods_num = getReqVal('goods_num', 0);
@ -460,12 +454,20 @@ class ShopController extends BaseAuthedController
$row = mt\ShopGoods::get($id);
if (!$row) {
$this->_rspErr(1, 'goods not found');
return;
}
$goods_id = $row['goods_id'];
if (!empty($address)) {
$pending = $this->checkPendingBuyGoodsNormal($address, $goods_id, $row['shop_id'], $id);
if ($pending) {
$this->_rspErr(1, 'pending');
return;
}
}
$desired_token_type = $row['token_type'];
$check_token_type = splitStr1($desired_token_type);
$token_pos = array_search($token_type, $check_token_type, true);
@ -498,11 +500,7 @@ class ShopController extends BaseAuthedController
$buyRecord = getXVal($buyRecordHash, $id);
$boughtTimes = $buyRecord ? $buyRecord['this_day_buy_times'] + 1 : 1;
if ($buyRecord && getXVal($buyRecord, 'this_day_buy_times', 0) >= $row['limit_num']) {
$this->_rspErr(2, 'Has reached the maximum number of purchase restrictions today');
return;
}
if ($row['limit_num'] <= 0) {
$this->_rspErr(2, 'The maximum number of purchase restrictions has been reached');
$this->_rspErr(2, 'Daily purchase limit');
return;
}
}
@ -511,32 +509,19 @@ class ShopController extends BaseAuthedController
$buyRecord = getXVal($buyRecordHash, $id);
$boughtTimes = $buyRecord ? $buyRecord['this_week_buy_times'] + 1 : 1;
if ($buyRecord && getXVal($buyRecord, 'this_week_buy_times', 0) >= $row['limit_num']) {
$this->_rspErr(2, 'The maximum number of purchase restrictions this week has been reached');
return;
}
if ($row['limit_num'] <= 0) {
$this->_rspErr(2, 'The maximum number of purchase restrictions has been reached');
$this->_rspErr(2, 'Weekly purchase limit reached');
return;
}
}
break;
case ShopController::TOTAL_BUY_LIMIT: {
error_log("total buy limit " . $address . " " . $id . " " . $row['limit_num']);
// error_log("total buy limit " . $address . " " . $id . " " . $row['limit_num']);
$buyRecord = getXVal($buyRecordHash, $id);
$boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + 1 : 1;
if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $row['limit_num']) {
$this->_rspErr(2, 'The maximum number of purchase restrictions has been reached 1');
$this->_rspErr(2, 'Purchase limit reached');
return;
}
if ($row['limit_num'] <= 0) {
$this->_rspErr(2, 'he maximum number of purchase restrictions has been reached 2');
return;
}
// $sendingTimes = $this->countBuyGoodsRequestTimesByGoodsId($address, $row['goods_id']);
// if ($sendingTimes >= $row['limit_num']) {
// $this->_rspErr(2, 'The maximum number of purchase restrictions has been reached 3');
// return;
// }
}
break;
default: {
@ -550,8 +535,8 @@ class ShopController extends BaseAuthedController
$need_price = $price_array[$token_pos];
$discount = $discount_array[$token_pos];
$discount_begin = strtotime($row['discount_begin'] . ' UTC');
$discount_end = strtotime($row['discount_end'] . ' UTC');
$discount_begin = strtotime($row['discount_begin']);
$discount_end = strtotime($row['discount_end']);
$nowTime = $this->_getNowTime();
if ($nowTime >= $discount_begin && $nowTime < $discount_end) {
@ -570,6 +555,51 @@ class ShopController extends BaseAuthedController
return;
}
$itemMeta = mt\Item::get($row['goods_id']);
$propertyChgService = new services\PropertyChgService();
for ($i = 0; $i < $goods_num; $i++) {
$this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0);
}
$awardService = new services\AwardService();
$awardService->addItem($row['goods_id'], $goods_num);
ShopBuyRecord::add($id, $goods_num);
$this->_decItems($costItems);
$goodsDto = array(
'goods_id' => $id,
'item_id' => $row['goods_id'],
'price_info' => array(
'item_id' => $row['goods_id'],
'cost_list' => array(),
'discount_begin_time' => phpcommon\datetimeToTimestamp($row['discount_begin']),
'discount_end_time' => phpcommon\datetimeToTimestamp($row['discount_end'])
),
'flag_icon' => $row['tag'],
'limit_type' => $row['limit_type'],
'bought_times' => $boughtTimes,
'total_buy_times' => $row['limit_num'],
); {
$priceInfo = mt\Item::getPriceInfo($itemMeta);
if (!empty($priceInfo)) {
$goodsDto['price_info'] = $priceInfo['price_info'];
}
}
$propertyChgService->addUserChg();
$this->_rspData(
array(
'award' => $awardService->toDto(),
'property_chg' => $propertyChgService->toDto(),
'goods_chg' => $goodsDto
)
);
break;
case ShopController::TOKEN_TYPE_DIAMOND:
$costItems = $this->makeCostItems($costItemId, $goods_num * $need_price);
$lackItem = null;
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
$this->_rspErr(2, $this->_getLackItemErrMsg($lackItem));
return;
}
$itemMeta = mt\Item::get($row['goods_id']);
$propertyChgService = new services\PropertyChgService();
for ($i = 0; $i < $goods_num; $i++) {
@ -665,6 +695,102 @@ class ShopController extends BaseAuthedController
}
public function buyGoodsDS()
{
$idx = getReqVal('idx', 0);
$grid = getReqVal('grid', 0);
$count = getReqVal('count', 0);
if ($grid < 1 || $grid > 6) {
$this->_rspErr(2, 'grid is invalid');
return;
}
$conn = $this->_getMysql('');
$row = SqlHelper::selectOne(
$conn,
't_shop_dailyselection',
array(
'idx',
'address',
'grid_' . $grid,
'count_' . $grid,
),
array('idx' => $idx)
);
if (!$row) {
$this->_rspErr(2, 'idx is invalid');
return;
}
if ($row['grid_' . $grid] == 0) {
$this->_rspErr(2, 'grid is invalid');
return;
}
if ($row['count_' . $grid] < $count) {
$this->_rspErr(2, 'count is invalid');
return;
}
$sel_id = $row['grid_' . $grid];
$goods = mt\Dailyselection::get($sel_id);
$token_type = $goods['token_type'];
$costItemId = $this->getCostItemIdByTokenType($token_type);
$costItems = $this->makeCostItems($costItemId, $goods['goods_num'] * $count * $goods['price']);
$lackItem = null;
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
$this->_rspErr(2, $this->_getLackItemErrMsg($lackItem));
return;
}
$item_id = $goods['goods_id'];
$item_num = $goods['goods_num'] * $count;
$sql = "UPDATE t_shop_dailyselection SET count_$grid = count_$grid - $count WHERE idx = $idx";
$chk = $conn->execScript($sql);
$itemMeta = mt\Item::get($item_id);
$propertyChgService = new services\PropertyChgService();
for ($i = 0; $i < $count; $i++) {
$this->internalAddItem($propertyChgService, $itemMeta, $item_num, 0);
}
$awardService = new services\AwardService();
$awardService->addItem($goods['goods_id'], $count);
$this->_decItems($costItems);
$goodsDto = array(
'goods_id' => $sel_id,
'item_id' => $goods['goods_id'],
'price_info' => array(
'item_id' => $goods['goods_id'],
'cost_list' => array(),
),
'bought_times' => 0,
'total_buy_times' => 0,
); {
$priceInfo = mt\Item::getPriceInfo($itemMeta);
if (!empty($priceInfo)) {
$goodsDto['price_info'] = $priceInfo['price_info'];
}
}
$propertyChgService->addUserChg();
$this->_rspData(
array(
'idx' => $idx,
'grid' => $grid,
'count' => $count,
)
);
}
private function buyGoodsDSOld()
{
$account = $this->_getAccountId();
$address = $this->_getAddress();
@ -768,7 +894,7 @@ class ShopController extends BaseAuthedController
);
}
public function openBlindBox()
private function openBlindBox()
{
$account = $this->_getAccountId();
@ -826,11 +952,11 @@ class ShopController extends BaseAuthedController
public function getChestItems()
{
$address = $this->_getAddress();
if (!$address) {
$this->_rspErr(2, 'address is invalid');
return;
}
// $address = $this->_getAddress();
// if (!$address) {
// $this->_rspErr(2, 'address is invalid');
// return;
// }
$id = getReqVal('id', 0);
$goods = mt\ShopGoods::get($id);
@ -873,13 +999,13 @@ class ShopController extends BaseAuthedController
}
$free_num = $goods['free_num'];
$pending = $this->checkPendingBuyGoodsNormal($address, $goods_id, $shop_id, $id);
// $pending = $this->checkPendingBuyGoodsNormal($address, $goods_id, $shop_id, $id);
error_log("getChestItems start " . json_encode(
array(
'goods_id' => $goods_id,
'items' => array_keys($record),
'free_num' => $free_num,
'pending' => $pending,
'pending' => 0,
)
));
@ -887,12 +1013,12 @@ class ShopController extends BaseAuthedController
array(
'items' => array_keys($record),
'free_num' => $free_num,
'pending' => $pending,
'pending' => 0,
)
);
}
public function getMyBlindBoxs()
private function getMyBlindBoxs()
{
$itemDb = Bag::getAllByType(mt\Item::CHEST_BOX_TYPE);
@ -914,14 +1040,12 @@ class ShopController extends BaseAuthedController
case ShopController::TOKEN_TYPE_GOLD:
return V_ITEM_GOLD;
break;
case ShopController::TOKEN_TYPE_CEG:
return V_ITEM_GOLD;
break;
case ShopController::TOKEN_TYPE_CEC:
case ShopController::TOKEN_TYPE_DIAMOND:
return V_ITEM_DIAMOND;
break;
case ShopController::TOKEN_TYPE_CEG:
case ShopController::TOKEN_TYPE_BCEG:
case ShopController::TOKEN_TYPE_USDT:
case ShopController::TOKEN_TYPE_USDC:
@ -1646,7 +1770,7 @@ class ShopController extends BaseAuthedController
}
}
private function buyBlindBox()
public function buyBlindBox()
{
$account = $this->_getAccountId();
@ -1678,22 +1802,25 @@ class ShopController extends BaseAuthedController
return;
}
} else {
$gold = 1500;
if ($gold < $cost) {
$this->_rspErr(2, 'gold is not enough');
$costItems = $this->makeCostItems(V_ITEM_DIAMOND, $num * $shop['price']);
$lackItem = null;
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
$this->_rspErr(2, $this->_getLackItemErrMsg($lackItem));
return;
}
$gold -= $cost;
}
$recommend = $shop['recommend'];
$itemStore = mt\ShopChest::getRandomItemListByChestType($recommend);
$itemStore = mt\ShopChest::getRandomItemListByChestType($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'], 1);
@ -1721,6 +1848,10 @@ class ShopController extends BaseAuthedController
)
));
if (!$isFreeBuy) {
$this->_decItems($costItems);
}
$this->_rspData(
array(
'reuslt' => $result,