public static function EGOP_transaction_o() { $usr = usr::getCurrentUser(1); if ($usr == null) { header('Location: /'); exit; } $client_account = Core::validate($_POST['email']); $amount = Core::validate($_POST['amount']); $currency_name = Core::validate($_POST['currency']); if ($amount == 0 || !Core::isDouble($amount, 2)) { print json_encode(array('location' => URL_WRONG_MONEY_VALUE)); exit; } if (!Core::isEmailAddress($client_account)) { print json_encode(array('location' => URL_WRONG_DATA_INPUT)); exit; } $currency = new Currency(); if (!$currency->findBy(array('Name' => $currency_name))) { print json_encode(array('location' => URL_SERVER_ERROR)); exit; } $purseList = Purse::findBy(array('UID' => $usr->getId(), 'CurId' => $currency->getId())); if (empty($purseList)) { exit; } $limits = self::transactionLimits($currency->getId(), 'EGOP', 1); $feeVolume = $amount * $limits['fee']; $feeVolume = Core::round_up($feeVolume, 2); $purse = new Purse(); $purse->findById($purseList[0]['id']); if ($purse->getValue() < $amount + $feeVolume) { print json_encode(array('location' => URL_WRONG_MONEY_VALUE)); exit; } if ($amount < $limits['min']) { print json_encode(array('location' => URL_ERROR . self::LIMITS)); return; } if ($limits['max'] != null) { $transaction_history = new AtEgop(); $transactions = $transaction_history->findAllByForLastPeriod(array('UID' => $usr->getid(), 'type' => 1, 'status' => 1)); $totalAmount = 0.0; if (isset($transactions)) { foreach ($transactions as $transaction) { $totalAmount += $transaction['amount']; } } if ($totalAmount + $amount > $limits['max']) { print json_encode(array('location' => URL_ERROR . self::LIMITS)); return; } } $at = new AtEgop(); $at->setUID($usr->getId()); $at->setClientAccount($client_account); $at->setAmount($amount); $at->setCurrencyId($currency->getId()); $at->setType(1); $at->setStatus(0); $at->setTimestamp(Core::timestamp_gmp()); $at->insert(); $success = self::send_output_link('EGOP', $at->getId(), $usr); if (!$success) { print json_encode(array('location' => URL_SERVER_ERROR)); return; } print json_encode(array('location' => URL_NOTIFICATION_SEND)); }
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; }