...
This commit is contained in:
parent
d60e7dd3cd
commit
297d0ecf90
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user