From a49918b8803a1460a8756552fdc932dc70dfbde8 Mon Sep 17 00:00:00 2001 From: hujiabin <519660157@qq.com> Date: Mon, 3 Jul 2023 11:30:40 +0800 Subject: [PATCH] 1 --- webapp/controller/HeroController.class.php | 2 +- webapp/services/callback/BuyPassCbService.php | 35 ++------- .../services/callback/ShopAddItemService.php | 74 ++++++++++++++----- 3 files changed, 64 insertions(+), 47 deletions(-) diff --git a/webapp/controller/HeroController.class.php b/webapp/controller/HeroController.class.php index e19ca3a7..8259215c 100644 --- a/webapp/controller/HeroController.class.php +++ b/webapp/controller/HeroController.class.php @@ -420,7 +420,7 @@ class HeroController extends BaseAuthedController { } $response = services\BlockChainService::gameItemMallBuy( Transaction::RESET_HERO_LEVEL_TYPE, services\BlockChainService::formatCurrency($price), V_ITEM_RESET_CARD, 1); - $this->_setV(TN_DAILY_RESET_HERO_LEVEL_STATE, $hero_unnid, 1); + $this->_setV(TN_DAILY_RESET_HERO_LEVEL_STATE, intval($hero_unnid), 1); BcOrder::upsert($response['trans_id'], array( 'item_id' => V_ITEM_RESET_CARD, 'item_num' => 1, diff --git a/webapp/services/callback/BuyPassCbService.php b/webapp/services/callback/BuyPassCbService.php index d706a23c..f62a86f7 100644 --- a/webapp/services/callback/BuyPassCbService.php +++ b/webapp/services/callback/BuyPassCbService.php @@ -69,7 +69,7 @@ class BuyPassCbService 'hero_unnid' => json_decode($order['ext_data']), )), )); - $this->_resetHeroLevel($order); + $this->_resetHeroLevel($order,$itemService); error_log("callback resetHeroLevel address: {$order['address']}, order_id: {$order['order_id']}, item_id: {$order['item_id']}, item_num: {$order['item_num']}"); $itemService->addGameLog($order['address'],"resetHero","end",array( 'param1' => $order['order_id'], @@ -86,7 +86,7 @@ class BuyPassCbService } } - private function _resetHeroLevel($order){ + private function _resetHeroLevel($order,$addItemService){ $heroDb = SqlHelper::ormSelectOne( myself()->_getMysql($order['address']), 't_hero', @@ -122,35 +122,12 @@ class BuyPassCbService 'rand_attr' => $heroDb['base_attr'], ) ); - $conn = myself()->_getMysql($order['address']); - $this->_addBagItem($conn,$order['account_id'],$piece_item_id,$piece); - $this->_addBagItem($conn,$order['account_id'],V_ITEM_HERO_META,$serum); - $this->_addBagItem($conn,$order['account_id'],V_ITEM_GOLD,$gold); + $addItemService->addItem($order['address'],$piece_item_id,$piece); + $addItemService->addItem($order['address'],V_ITEM_HERO_META,$serum); + $addItemService->addItem($order['address'],V_ITEM_GOLD,$gold); $this->_updateDynData($order,TN_DAILY_RESET_HERO_LEVEL_STATE,json_decode($order['ext_data'])); } - private function _addBagItem($conn,$accountId,$itemId,$itemNum){ - SqlHelper::upsert - ($conn, - 't_bag', - array( - 'account_id' => $accountId, - 'item_id' => $itemId - ), - array( - 'item_num' => function () use($itemNum) { return "item_num + {$itemNum}";}, - 'modifytime' => myself()->_getNowTime(), - ), - array( - 'account_id' => $accountId, - 'item_id' => $itemId, - 'item_num' => $itemNum, - 'createtime' => myself()->_getNowTime(), - 'modifytime' => myself()->_getNowTime() - ) - ); - } - private function _activateUser($address){ SqlHelper::update (myself()->_getMysql($address), @@ -209,6 +186,8 @@ class BuyPassCbService } private function _updateDynData($user,$x,$y){ + $x = intval($x) ; + $y = intval($y) ; SqlHelper::update ( myself()->_getMysql($user['address']), 't_dyndata', diff --git a/webapp/services/callback/ShopAddItemService.php b/webapp/services/callback/ShopAddItemService.php index 614ac92d..5be0bc81 100644 --- a/webapp/services/callback/ShopAddItemService.php +++ b/webapp/services/callback/ShopAddItemService.php @@ -40,31 +40,36 @@ class ShopAddItemService } $accountId = $this->getAccountId($address); $conn = myself()->_getMysql($address); - if (\mt\Item::isBagItem($itemMeta['type'], $itemMeta['sub_type'])) { - $this->internalAddBag($conn,$itemId,$itemNum,$accountId); + if ($this->_isVirtualItem($itemId)) { + $this->_addVirtualItem($conn,$accountId,$itemId, $itemNum); }else{ - for ($i = 0; $i < $itemNum; $i++) { - switch ($itemMeta['type']){ - case \mt\Item::HERO_TYPE : { - $this->internalAddHero($conn,$itemMeta,$accountId); - } - break; - case \mt\Item::GUN_TYPE : { - $this->internalAddGun($conn,$itemMeta,$accountId); - } - break; - case \mt\Item::CHIP_TYPE : { - $this->internalAddChip($conn,$itemMeta,$accountId); - } - break; - case \mt\Item::HERO_SKIN_TYPE : { - $this->internalAddHeroSkin($conn,$itemMeta,$accountId); + if (\mt\Item::isBagItem($itemMeta['type'], $itemMeta['sub_type'])) { + $this->internalAddBag($conn,$itemId,$itemNum,$accountId); + }else{ + for ($i = 0; $i < $itemNum; $i++) { + switch ($itemMeta['type']){ + case \mt\Item::HERO_TYPE : { + $this->internalAddHero($conn,$itemMeta,$accountId); + } + break; + case \mt\Item::GUN_TYPE : { + $this->internalAddGun($conn,$itemMeta,$accountId); + } + break; + case \mt\Item::CHIP_TYPE : { + $this->internalAddChip($conn,$itemMeta,$accountId); + } + break; + case \mt\Item::HERO_SKIN_TYPE : { + $this->internalAddHeroSkin($conn,$itemMeta,$accountId); + } } } } } + } private function getAccountId($address){ @@ -220,4 +225,37 @@ class ShopAddItemService return in_array($itemId, array(V_ITEM_GOLD, V_ITEM_DIAMOND, V_ITEM_EXP, V_ITEM_ACTIVE,V_ITEM_BCEG,V_ITEM_STAR)); } + private function _addVirtualItem($conn,$accountId,$itemId,$itemNum){ + if ($itemNum <= 0){ + return; + } + switch ($itemId) { + case V_ITEM_GOLD: + { + $this->_updateUserInfo($conn,$accountId,array( + 'gold' => function () use($itemNum) { + return "gold + ${itemNum}"; + } + )); + } + break; + default: + { + } + break; + } + } + + private function _updateUserInfo($conn,$accountId,$fieldsKv) + { + SqlHelper::update + ($conn, + 't_user', + array( + 'account_id' => $accountId + ), + $fieldsKv + ); + } + } \ No newline at end of file