diff --git a/webapp/controller/MarketController.class.php b/webapp/controller/MarketController.class.php index 41edf1c8..0a683c14 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -917,7 +917,7 @@ class MarketController extends BaseController } else { $job_filter_array = explode('|', $job_filters); } - + $search_filters = getReqVal('search_filters', ''); if ($search_filters != '') { $search_filter_array = explode('|', $search_filters); @@ -1513,9 +1513,92 @@ class MarketController extends BaseController private function decItems($address, $item_id, $amount) { + $self = myself(); + if (!$self) { + return false; + } + + $userInfo = $this->getUserInfo($address, array('gold')); + $count = $this->getItemCount($item_id, $userInfo); + if ($count < $amount) { + return false; + } + + $r = $this->decItem($address, $item_id, $amount); + if (!$r) { + return false; + } + return true; } + private function decItem($address, $item_id, $amount) + { + $self = myself(); + if (!$self) { + return false; + } + switch ($item_id) { + case V_ITEM_GOLD: { + $r = $this->decGold($address, $amount); + if (!$r) { + return false; + } + } + break; + } + return true; + } + + private function decGold($address, $amount) + { + $self = myself(); + if (!$self) { + return false; + } + + $userInfo = $this->getUserInfo($address, array('gold')); + $count = $this->getItemCount(V_ITEM_GOLD, $userInfo); + if ($count < $amount) { + return false; + } + + $r = $this->updateUserInfo($address, array( + 'gold' => function () use ($amount) { + return "GREATEST(0, gold - ${amount})"; + }, + 'consume_gold' => function () use ($amount) { + return "consume_gold + ${amount}"; + } + )); + if (!$r) { + return false; + } + + return true; + } + + private function updateUserInfo($address, $fieldKv) + { + $self = myself(); + if (!$self) { + return false; + } + + $r = SqlHelper::update( + $self->_getMysql(''), + 't_user', + array( + 'address' => $address, + ), + $fieldKv + ); + if (!$r) { + return false; + } + + return true; + } private function getCostItem($address, $item_id) { $self = myself();