From 0d945f7a49a6c2443d8e80cec6764e130f8ae70b Mon Sep 17 00:00:00 2001 From: azw Date: Sat, 29 Jul 2023 21:46:35 +0800 Subject: [PATCH] 1 --- webapp/controller/ShopController.class.php | 245 ++++++++------------- 1 file changed, 96 insertions(+), 149 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index ea922fd6..aa633f79 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -135,163 +135,110 @@ class ShopController extends BaseAuthedController { $costItemId = $this->getCostItemIdByTokenType($tokenType); switch ($tokenType) { - case ShopController::TOKEN_TYPE_GOLD: - $costItems = $this->makeCostItems($costItemId, $goodsNum * $need_price); - $lackItem = null; - if (!$this->_hasEnoughItems($costItems, $lackItem)) { - $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); - return; - } + case ShopController::TOKEN_TYPE_GOLD: + $costItems = $this->makeCostItems($costItemId, $goodsNum * $need_price); + $lackItem = null; + if (!$this->_hasEnoughItems($costItems, $lackItem)) { + $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); + return; + } - $itemMeta = mt\Item::get($goodsMeta['goods_id']); - $propertyChgService = new services\PropertyChgService(); - for ($i = 0; $i < $goodsNum; $i++) { - $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0); - } - $awardService = new services\AwardService(); - $awardService->addItem($goodsMeta['goods_id'], $goodsNum); - ShopBuyRecord::add($id, $goodsNum); - $this->_decItems($costItems); - $goodsDto = array( - 'goods_id' => $id, + $itemMeta = mt\Item::get($goodsMeta['goods_id']); + $propertyChgService = new services\PropertyChgService(); + for ($i = 0; $i < $goodsNum; $i++) { + $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0); + } + $awardService = new services\AwardService(); + $awardService->addItem($goodsMeta['goods_id'], $goodsNum); + ShopBuyRecord::add($id, $goodsNum); + $this->_decItems($costItems); + $goodsDto = array( + 'goods_id' => $id, + 'item_id' => $goodsMeta['goods_id'], + 'price_info' => array( 'item_id' => $goodsMeta['goods_id'], - 'price_info' => array( - 'item_id' => $goodsMeta['goods_id'], - 'cost_list' => array(), - 'discount_begin_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_begin']), - 'discount_end_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_end']) - ), - 'flag_icon' => $goodsMeta['tag'], - 'limit_type' => $goodsMeta['limit_type'], - 'bought_times' => $boughtTimes, - 'total_buy_times' => $goodsMeta['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: - if ($isFreeBuy) { - $need_price = 0; - } - $costItems = $this->makeCostItems($costItemId, $goodsNum * $need_price); - $lackItem = null; - if (!$this->_hasEnoughItems($costItems, $lackItem)) { - $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); - return; + 'cost_list' => array(), + 'discount_begin_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_begin']), + 'discount_end_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_end']) + ), + 'flag_icon' => $goodsMeta['tag'], + 'limit_type' => $goodsMeta['limit_type'], + 'bought_times' => $boughtTimes, + 'total_buy_times' => $goodsMeta['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: + if ($isFreeBuy) { + $need_price = 0; + } + $costItems = $this->makeCostItems($costItemId, $goodsNum * $need_price); + $lackItem = null; + if (!$this->_hasEnoughItems($costItems, $lackItem)) { + $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); + return; + } - $itemMeta = mt\Item::get($goodsMeta['goods_id']); - $propertyChgService = new services\PropertyChgService(); - for ($i = 0; $i < $goodsNum; $i++) { - $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0); - } - $awardService = new services\AwardService(); - $awardService->addItem($goodsMeta['goods_id'], $goodsNum); - ShopBuyRecord::add($id, $goodsNum); - if ($isFreeBuy) { - $this->addFreeBuyRecord($goodsMeta); - } - $this->_decItems($costItems); - $event = [ - 'name' => LogService::SHOP_BUY_ITEM, - 'val' => $costItems[0]['item_num'] - ]; - LogService::consumeDiamond($event); + $itemMeta = mt\Item::get($goodsMeta['goods_id']); + $propertyChgService = new services\PropertyChgService(); + for ($i = 0; $i < $goodsNum; $i++) { + $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 0); + } + $awardService = new services\AwardService(); + $awardService->addItem($goodsMeta['goods_id'], $goodsNum); + ShopBuyRecord::add($id, $goodsNum); + if ($isFreeBuy) { + $this->addFreeBuyRecord($goodsMeta); + } + $this->_decItems($costItems); + $event = [ + 'name' => LogService::SHOP_BUY_ITEM, + 'val' => $costItems[0]['item_num'] + ]; + LogService::consumeDiamond($event); - $goodsDto = array( - 'goods_id' => $id, + $goodsDto = array( + 'goods_id' => $id, + 'item_id' => $goodsMeta['goods_id'], + 'price_info' => array( 'item_id' => $goodsMeta['goods_id'], - 'price_info' => array( - 'item_id' => $goodsMeta['goods_id'], - 'cost_list' => array(), - 'discount_begin_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_begin']), - 'discount_end_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_end']) - ), - 'flag_icon' => $goodsMeta['tag'], - 'limit_type' => $goodsMeta['limit_type'], - 'bought_times' => $boughtTimes, - 'total_buy_times' => $goodsMeta['limit_num'], - ); { - $priceInfo = mt\Item::getPriceInfo($itemMeta); - if (!empty($priceInfo)) { - $goodsDto['price_info'] = $priceInfo['price_info']; - } + 'cost_list' => array(), + 'discount_begin_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_begin']), + 'discount_end_time' => phpcommon\datetimeToTimestamp($goodsMeta['discount_end']) + ), + 'flag_icon' => $goodsMeta['tag'], + 'limit_type' => $goodsMeta['limit_type'], + 'bought_times' => $boughtTimes, + 'total_buy_times' => $goodsMeta['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_CEG: - case ShopController::TOKEN_TYPE_CEC: - if ($isFreeBuy) { - $propertyChgService = new services\PropertyChgService(); - $this->addFreeBuyRecord($goodsMeta); - $itemMeta = mt\Item::get($goodsMeta['goods_id']); - $this->internalAddItem($propertyChgService, $itemMeta, $goods_count, 1); - $this->_rspOk(); - } else { - $price = $this->normalizeWeb3Price($goodsNum * $need_price); - $item_id = $goodsMeta['goods_id']; - $item_count = $goodsNum; - - $response = services\BlockChainService::gameItemMallBuy( - Transaction::BUY_GOODS_ACTION_TYPE, - $price, - $item_id, - $item_count - ); - - BcOrder::upsert($response['trans_id'], array( - 'item_id' => $item_id, - 'item_num' => $item_count, - 'order_type' => 1, - 'price' => $goodsNum * $need_price, - 'ext_data' => json_encode(array( - 'mode' => SHOP_BUY_MODE_NORMAL, - 'shop_id' => $goodsMeta['shop_id'], - 'id' => $id, - )), - )); - - $response['item_id'] = $item_id; - $response['item_num'] = $item_count; - - error_log("buy normal, item_id = " . $item_id . " item_count = " . $item_count . " need_price = " . $need_price . " price = " . $price . " response = " . json_encode($response)); - - $this->_rspData( - array( - "block_chain" => $response - ) - ); - } - break; - - case ShopController::TOKEN_TYPE_BCEG: - break; - - case ShopController::TOKEN_TYPE_USDT: - case ShopController::TOKEN_TYPE_USDC: - case ShopController::TOKEN_TYPE_BUSD: - case ShopController::TOKEN_TYPE_MATIC: - case ShopController::TOKEN_TYPE_BNB: + } + $propertyChgService->addUserChg(); + $this->_rspData( + array( + 'award' => $awardService->toDto(), + 'property_chg' => $propertyChgService->toDto(), + 'goods_chg' => $goodsDto + ) + ); + break; default: { - $this->_rspErr(1, "token_type is unsupport, {$tokenType}"); + $this->_rspErr(1, "token_type is unsupport, {$tokenType}"); } } }