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

@ -606,9 +606,9 @@ class BaseAuthedController extends BaseController {
return 'Not enough item'; return 'Not enough item';
} }
if (SERVER_ENV != _ONLINE) { if (SERVER_ENV != _ONLINE) {
return "${itemMeta['name']}Not enough stock:${lackItem['inventory']} need:${lackItem['item_num']}"; return "${itemMeta['name']} Not enough stock:${lackItem['inventory']} need:${lackItem['item_num']}";
} else { } else {
return "${itemMeta['name']}Not enough"; return "${itemMeta['name']} Not enough";
} }
} }

View File

@ -63,6 +63,8 @@ class ShopController extends BaseAuthedController
const TOKEN_TYPE_CEG = '1'; const TOKEN_TYPE_CEG = '1';
const TOKEN_TYPE_CEC = '2'; const TOKEN_TYPE_CEC = '2';
const TOKEN_TYPE_BCEG = '3'; const TOKEN_TYPE_BCEG = '3';
const TOKEN_TYPE_DIAMOND = '4';
const TOKEN_TYPE_USDT = '11'; const TOKEN_TYPE_USDT = '11';
const TOKEN_TYPE_USDC = '12'; const TOKEN_TYPE_USDC = '12';
@ -358,11 +360,7 @@ class ShopController extends BaseAuthedController
public function refreshDailySelection() public function refreshDailySelection()
{ {
$address = $this->_getAddress(); $address = $this->_getAccountId();
if (empty($address)) {
$this->_rspErr(2, 'address is empty');
return;
}
$maxCount = mt\Parameter::getByName('daily_selection_refresh_time')['param_value']; $maxCount = mt\Parameter::getByName('daily_selection_refresh_time')['param_value'];
$count = $this->countTodayRefreshTimes($address); $count = $this->countTodayRefreshTimes($address);
@ -400,11 +398,7 @@ class ShopController extends BaseAuthedController
public function getDailySelectionList() public function getDailySelectionList()
{ {
$address = $this->_getAddress(); $address = $this->_getAccountId();
if (empty($address)) {
$this->_rspErr(3, 'address is empty');
return;
}
// 不清除过期的每日精选可以避免跨日操作错误 // 不清除过期的每日精选可以避免跨日操作错误
// $chk = $this->clearBeforeTodayDailySelections(); // $chk = $this->clearBeforeTodayDailySelections();
@ -430,7 +424,7 @@ class ShopController extends BaseAuthedController
$max_count = count($arrCosts); $max_count = count($arrCosts);
$cost = $count < $max_count ? $arrCosts[$count] : -1; $cost = $count < $max_count ? $arrCosts[$count] : -1;
error_log('getDailySelectionList address: ' . $address . ' idx:'. $selection['idx'] . ' refresh_info:' . "{$count}/{$max_count}" . ' cost:' . $cost); error_log('getDailySelectionList address: ' . $address . ' idx:' . $selection['idx'] . ' refresh_info:' . "{$count}/{$max_count}" . ' cost:' . $cost);
$this->_rspData( $this->_rspData(
array( array(
@ -445,10 +439,10 @@ class ShopController extends BaseAuthedController
public function buyGoodsNormal() public function buyGoodsNormal()
{ {
$address = $this->_getAddress(); $address = $this->_getAddress();
if (empty($address)) { // if (empty($address)) {
$this->_rspErr(4, 'address is empty'); // $this->_rspErr(4, 'address is empty');
return; // return;
} // }
$id = getReqVal('id', 0); $id = getReqVal('id', 0);
$token_type = getReqVal('token_type', ''); $token_type = getReqVal('token_type', '');
$goods_num = getReqVal('goods_num', 0); $goods_num = getReqVal('goods_num', 0);
@ -460,12 +454,20 @@ class ShopController extends BaseAuthedController
$row = mt\ShopGoods::get($id); $row = mt\ShopGoods::get($id);
$goods_id = $row['goods_id']; if (!$row) {
$pending = $this->checkPendingBuyGoodsNormal($address, $goods_id, $row['shop_id'], $id); $this->_rspErr(1, 'goods not found');
if ($pending) {
$this->_rspErr(1, 'pending');
return; 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']; $desired_token_type = $row['token_type'];
$check_token_type = splitStr1($desired_token_type); $check_token_type = splitStr1($desired_token_type);
$token_pos = array_search($token_type, $check_token_type, true); $token_pos = array_search($token_type, $check_token_type, true);
@ -498,11 +500,7 @@ class ShopController extends BaseAuthedController
$buyRecord = getXVal($buyRecordHash, $id); $buyRecord = getXVal($buyRecordHash, $id);
$boughtTimes = $buyRecord ? $buyRecord['this_day_buy_times'] + 1 : 1; $boughtTimes = $buyRecord ? $buyRecord['this_day_buy_times'] + 1 : 1;
if ($buyRecord && getXVal($buyRecord, 'this_day_buy_times', 0) >= $row['limit_num']) { if ($buyRecord && getXVal($buyRecord, 'this_day_buy_times', 0) >= $row['limit_num']) {
$this->_rspErr(2, 'Has reached the maximum number of purchase restrictions today'); $this->_rspErr(2, 'Daily purchase limit');
return;
}
if ($row['limit_num'] <= 0) {
$this->_rspErr(2, 'The maximum number of purchase restrictions has been reached');
return; return;
} }
} }
@ -511,32 +509,19 @@ class ShopController extends BaseAuthedController
$buyRecord = getXVal($buyRecordHash, $id); $buyRecord = getXVal($buyRecordHash, $id);
$boughtTimes = $buyRecord ? $buyRecord['this_week_buy_times'] + 1 : 1; $boughtTimes = $buyRecord ? $buyRecord['this_week_buy_times'] + 1 : 1;
if ($buyRecord && getXVal($buyRecord, 'this_week_buy_times', 0) >= $row['limit_num']) { 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'); $this->_rspErr(2, 'Weekly purchase limit reached');
return;
}
if ($row['limit_num'] <= 0) {
$this->_rspErr(2, 'The maximum number of purchase restrictions has been reached');
return; return;
} }
} }
break; break;
case ShopController::TOTAL_BUY_LIMIT: { 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); $buyRecord = getXVal($buyRecordHash, $id);
$boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + 1 : 1; $boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + 1 : 1;
if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $row['limit_num']) { 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; 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; break;
default: { default: {
@ -550,8 +535,8 @@ class ShopController extends BaseAuthedController
$need_price = $price_array[$token_pos]; $need_price = $price_array[$token_pos];
$discount = $discount_array[$token_pos]; $discount = $discount_array[$token_pos];
$discount_begin = strtotime($row['discount_begin'] . ' UTC'); $discount_begin = strtotime($row['discount_begin']);
$discount_end = strtotime($row['discount_end'] . ' UTC'); $discount_end = strtotime($row['discount_end']);
$nowTime = $this->_getNowTime(); $nowTime = $this->_getNowTime();
if ($nowTime >= $discount_begin && $nowTime < $discount_end) { if ($nowTime >= $discount_begin && $nowTime < $discount_end) {
@ -570,6 +555,51 @@ class ShopController extends BaseAuthedController
return; 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']); $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++) {
@ -665,6 +695,102 @@ class ShopController extends BaseAuthedController
} }
public function buyGoodsDS() 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(); $account = $this->_getAccountId();
$address = $this->_getAddress(); $address = $this->_getAddress();
@ -768,7 +894,7 @@ class ShopController extends BaseAuthedController
); );
} }
public function openBlindBox() private function openBlindBox()
{ {
$account = $this->_getAccountId(); $account = $this->_getAccountId();
@ -826,11 +952,11 @@ class ShopController extends BaseAuthedController
public function getChestItems() public function getChestItems()
{ {
$address = $this->_getAddress(); // $address = $this->_getAddress();
if (!$address) { // if (!$address) {
$this->_rspErr(2, 'address is invalid'); // $this->_rspErr(2, 'address is invalid');
return; // return;
} // }
$id = getReqVal('id', 0); $id = getReqVal('id', 0);
$goods = mt\ShopGoods::get($id); $goods = mt\ShopGoods::get($id);
@ -873,13 +999,13 @@ class ShopController extends BaseAuthedController
} }
$free_num = $goods['free_num']; $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( error_log("getChestItems start " . json_encode(
array( array(
'goods_id' => $goods_id, 'goods_id' => $goods_id,
'items' => array_keys($record), 'items' => array_keys($record),
'free_num' => $free_num, 'free_num' => $free_num,
'pending' => $pending, 'pending' => 0,
) )
)); ));
@ -887,12 +1013,12 @@ class ShopController extends BaseAuthedController
array( array(
'items' => array_keys($record), 'items' => array_keys($record),
'free_num' => $free_num, 'free_num' => $free_num,
'pending' => $pending, 'pending' => 0,
) )
); );
} }
public function getMyBlindBoxs() private function getMyBlindBoxs()
{ {
$itemDb = Bag::getAllByType(mt\Item::CHEST_BOX_TYPE); $itemDb = Bag::getAllByType(mt\Item::CHEST_BOX_TYPE);
@ -914,14 +1040,12 @@ class ShopController extends BaseAuthedController
case ShopController::TOKEN_TYPE_GOLD: case ShopController::TOKEN_TYPE_GOLD:
return V_ITEM_GOLD; return V_ITEM_GOLD;
break; 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; return V_ITEM_DIAMOND;
break; break;
case ShopController::TOKEN_TYPE_CEG:
case ShopController::TOKEN_TYPE_BCEG: case ShopController::TOKEN_TYPE_BCEG:
case ShopController::TOKEN_TYPE_USDT: case ShopController::TOKEN_TYPE_USDT:
case ShopController::TOKEN_TYPE_USDC: case ShopController::TOKEN_TYPE_USDC:
@ -1646,7 +1770,7 @@ class ShopController extends BaseAuthedController
} }
} }
private function buyBlindBox() public function buyBlindBox()
{ {
$account = $this->_getAccountId(); $account = $this->_getAccountId();
@ -1678,22 +1802,25 @@ class ShopController extends BaseAuthedController
return; return;
} }
} else { } else {
$gold = 1500; $costItems = $this->makeCostItems(V_ITEM_DIAMOND, $num * $shop['price']);
if ($gold < $cost) { $lackItem = null;
$this->_rspErr(2, 'gold is not enough'); if (!$this->_hasEnoughItems($costItems, $lackItem)) {
$this->_rspErr(2, $this->_getLackItemErrMsg($lackItem));
return; return;
} }
$gold -= $cost;
} }
$recommend = $shop['recommend']; $itemStore = mt\ShopChest::getRandomItemListByChestType($meta['sub_type']);
$itemStore = mt\ShopChest::getRandomItemListByChestType($recommend);
$result = array(); $result = array();
for ($i = 0; $i < $num; $i++) { for ($i = 0; $i < $num; $i++) {
$record = array(); $record = array();
foreach ($itemStore as $key => $value) { foreach ($itemStore as $key => $value) {
$item = $this->weighted_random($value); $item = $this->weighted_random($value);
$itemMeta = mt\Item::get($item['item_id']); $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(); $propertyChgService = new services\PropertyChgService();
if ($item['item_type'] == 2) { if ($item['item_type'] == 2) {
$this->internalAddItem($propertyChgService, $itemMeta, $item['num'], 1); $this->internalAddItem($propertyChgService, $itemMeta, $item['num'], 1);
@ -1721,6 +1848,10 @@ class ShopController extends BaseAuthedController
) )
)); ));
if (!$isFreeBuy) {
$this->_decItems($costItems);
}
$this->_rspData( $this->_rspData(
array( array(
'reuslt' => $result, 'reuslt' => $result,