From cc51bdb5d3f9901b7f5e44c75036bd72e8882a44 Mon Sep 17 00:00:00 2001 From: songliang Date: Wed, 5 Jul 2023 17:41:44 +0800 Subject: [PATCH] ... --- .../controller/BaseAuthedController.class.php | 4 +- webapp/controller/ShopController.class.php | 237 ++++++++++++++---- 2 files changed, 186 insertions(+), 55 deletions(-) diff --git a/webapp/controller/BaseAuthedController.class.php b/webapp/controller/BaseAuthedController.class.php index 8ccd92f0..6bcb6013 100644 --- a/webapp/controller/BaseAuthedController.class.php +++ b/webapp/controller/BaseAuthedController.class.php @@ -606,9 +606,9 @@ class BaseAuthedController extends BaseController { return 'Not enough item'; } 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 { - return "${itemMeta['name']}Not enough"; + return "${itemMeta['name']} Not enough"; } } diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index e73465cb..2e6742d3 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -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(); @@ -430,7 +424,7 @@ class ShopController extends BaseAuthedController $max_count = count($arrCosts); $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( array( @@ -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); - $goods_id = $row['goods_id']; - $pending = $this->checkPendingBuyGoodsNormal($address, $goods_id, $row['shop_id'], $id); - if ($pending) { - $this->_rspErr(1, 'pending'); + 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++) { @@ -664,6 +694,102 @@ class ShopController extends BaseAuthedController } } + public function buyGoodsDSDiamond() + { + $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, + ) + ); + } + public function buyGoodsDS() { $account = $this->_getAccountId(); @@ -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,