diff --git a/webapp/controller/MarketController.class.php b/webapp/controller/MarketController.class.php index 63859067..472cb570 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -513,11 +513,6 @@ class MarketController extends BaseAuthedController return; } - $payment_token_address = getReqVal('payment_token_address', ''); - $nonce = getReqVal('nonce', ''); - $signature = getReqVal('signature', ''); - $net_id = getReqVal('net_id', ''); - $conn = myself()->_getSelfMysql(); $nftDb = null; @@ -530,34 +525,23 @@ class MarketController extends BaseAuthedController $c_type = null; $c_id = null; - if ($nft_token) { - $nftDb = Nft::findNftByOwner($account, $nft_token); - $nftDetail = Nft::toDto($nftDb); - $detail = $this->getNftGameData($nftDb); - $c_name = $nftDetail['info']['name']; - $c_job = isset($nftDetail['info']['job']) ? $nftDetail['info']['job'] - : (isset($detail['chip_type']) ? $detail['chip_type'] - : (isset($detail['type']) ? $detail['type'] - : 0)); - $c_lv = @$detail['gun_lv'] | @$detail['hero_lv'] | @$detail['chip_grade']; - $c_quality = isset($nftDetail['info']['quality']) ? $nftDetail['info']['quality'] : 0; - $c_durability = isset($nftDetail['info']['durability']) ? $nftDetail['info']['durability'] : (isset($detail['hero_tili']) ? $detail['hero_tili'] : 0); - $c_type = isset($detail['type']) ? $detail['type'] : 0; - $c_id = $nftDetail['item_id']; - } else { - if (!$this->decItems($account, $item_id, $amount)) { - $this->_rspErr(1, 'item not enough, item_id:' . $item_id); - return; - } - $itemMeta = mt\Item::get($item_id); - $c_name = $itemMeta['name']; - $c_job = 0; - $c_lv = 0; - $c_quality = $itemMeta['quality']; - $c_durability = 0; - $c_type = 0; - $c_id = $item_id; + // 检查是否有足够的物品 + $costItems = $this->makeCostItems($item_id, $amount); + $lackItem = null; + if (!$this->_hasEnoughItems($costItems, $lackItem)) { + $this->_rspErr(2, $this->_getLackItemErrMsg($lackItem)); + return; } + $this->_decItems($costItems); + + $itemMeta = mt\Item::get($item_id); + $c_name = $itemMeta['name']; + $c_job = 0; + $c_lv = 0; + $c_quality = $itemMeta['quality']; + $c_durability = 0; + $c_type = 0; + $c_id = $item_id; $r = SqlHelper::insert( $conn, @@ -583,6 +567,17 @@ class MarketController extends BaseAuthedController $this->_rspOk(); } + private function makeCostItems($item_id, $num) + { + $costItems = array( + array( + 'item_id' => $item_id, + 'item_num' => $num + ) + ); + return $costItems; + } + public function sellCancel() { $account = strtolower(getReqVal('account', ''));