public static function changeOrderVolume(Order $order, $newVolume) { if ($order->getStatus() != OrderStatus::ACTIVE || $newVolume == $order->getVolume()) { return false; } $deal = new Deal(); $deal->findActiveDealByOrderId($order->getId()); $volumeDifference = $order->getVolume() - $newVolume; if ($deal->getVolume() < $volumeDifference) { return false; } $rate = new Rate(); $rate->findById($order->getRateId()); $purse = new Purse(); if ($order->getType() == OrderType::BUY) { $purseSelect = Purse::findBy(array('UID' => $order->getUserId(), 'CurId' => $rate->getSecondCurrencyId())); $purse->findById($purseSelect[0]['id']); $difference = $order->getPrice() * $volumeDifference * (1.0 + $rate->getFee()); $purse->addValue($difference); } else { $purseSelect = Purse::findBy(array('UID' => $order->getUserId(), 'CurId' => $rate->getFirstCurrencyId())); $purse->findById($purseSelect[0]['id']); $purse->addValue($volumeDifference); } if ($purse->getValue() < 0) { return false; } $purse->save(); $deal->setDate(date("Y-m-d H:i:s")); $deal->setVolume($newVolume); $deal->save(); $order->setVolume($newVolume); $order->updatePart(); $order->save(); return true; }