Esempio n. 1
0
 public function RemoveOrder($OrderID, $ID, $back)
 {
     $Orders = Orders::find('first', array('conditions' => array('_id' => new MongoID($ID))));
     $data = array('page.refresh' => true);
     Details::find('all')->save($data);
     if ($Orders['Completed'] == 'N') {
         $details = Details::find('first', array('conditions' => array('user_id' => (string) $Orders['user_id'])));
         if ($Orders['Action'] == 'Buy') {
             $balanceFirst = 'balance.' . $Orders['FirstCurrency'];
             $balanceSecond = 'balance.' . $Orders['SecondCurrency'];
             $data = array($balanceSecond => (double) ($details[$balanceSecond] + $Orders['PerPrice'] * $Orders['Amount']));
             $details = Details::find('all', array('conditions' => array('user_id' => $Orders['user_id'], 'username' => $Orders['username'])))->save($data);
         }
         if ($Orders['Action'] == 'Sell') {
             $balanceFirst = 'balance.' . $Orders['FirstCurrency'];
             $balanceSecond = 'balance.' . $Orders['SecondCurrency'];
             $data = array($balanceFirst => (double) ($details[$balanceFirst] + (double) $Orders['Amount']));
             $details = Details::find('all', array('conditions' => array('user_id' => $Orders['user_id'], 'username' => $Orders['username'])))->save($data);
         }
         if (String::hash($Orders['_id']) == $OrderID) {
             $Remove = Orders::remove(array('_id' => $ID));
         }
         $data = array('page.refresh' => true);
         Details::find('all')->save($data);
     }
     $this->redirect(array('controller' => 'ex', 'action' => "x/" . $back));
 }
 public function cancelorder($key = null)
 {
     if (!$this->request->data) {
         return $this->render(array('json' => array('success' => 0, 'now' => time(), 'error' => "Not submitted through POST.")));
     }
     if ($key == null) {
         return $this->render(array('json' => array('success' => 0, 'now' => time(), 'error' => "Key not specified. Please get your key from your settings page under security.")));
     } else {
         $details = Details::find('first', array('conditions' => array('key' => $key)));
         if (count($details) == 0) {
             return $this->render(array('json' => array('success' => 0, 'now' => time(), 'error' => "Incorrect Key! Please get your key from your settings page under security.")));
         } else {
             if (!$this->requestAPI("cancelorder", $details['username'])) {
                 return $this->render(array('json' => array('success' => 0, 'now' => time(), 'error' => "Too many requests from your IP. Try after some time.")));
             }
             $ID = $this->request->data['order_id'];
             if ($ID == "") {
                 return $this->render(array('json' => array('success' => 0, 'now' => time(), 'error' => "Order ID cannot be null.")));
             }
             $Orders = Orders::find('first', array('conditions' => array('_id' => new MongoID($ID))));
             if ($Orders['Completed'] == 'N') {
                 $details = Details::find('first', array('conditions' => array('user_id' => (string) $Orders['user_id'])));
                 if ($Orders['Action'] == 'Buy') {
                     $balanceFirst = 'balance.' . $Orders['FirstCurrency'];
                     $balanceSecond = 'balance.' . $Orders['SecondCurrency'];
                     $data = array($balanceSecond => (double) ($details[$balanceSecond] + $Orders['PerPrice'] * $Orders['Amount']));
                     $details = Details::find('all', array('conditions' => array('user_id' => $Orders['user_id'], 'username' => $Orders['username'])))->save($data);
                 }
                 if ($Orders['Action'] == 'Sell') {
                     $balanceFirst = 'balance.' . $Orders['FirstCurrency'];
                     $balanceSecond = 'balance.' . $Orders['SecondCurrency'];
                     $data = array($balanceFirst => (double) ($details[$balanceFirst] + (double) $Orders['Amount']));
                     $details = Details::find('all', array('conditions' => array('user_id' => $Orders['user_id'], 'username' => $Orders['username'])))->save($data);
                 }
                 $Remove = Orders::remove(array('_id' => $ID));
                 $result = $Remove;
                 $data = array('page.refresh' => true);
                 Details::find('all')->save($data);
                 return $this->render(array('json' => array('success' => 1, 'now' => time(), 'result' => $result)));
             }
         }
     }
 }
Esempio n. 3
0
 public function RemoveCompletedOrder($ID)
 {
     if ($this->__init() == false) {
         $this->redirect('ex::dashboard');
     }
     $Orders = Orders::find('first', array('conditions' => array('_id' => new MongoID($ID))));
     /*	print_r($Orders['_id']);
     	print_r("<br>");
     	print_r($Orders['Transact']['id']);
     	print_r("<br>");
     */
     if ($Orders['Completed'] == 'Y') {
         $details = Details::find('first', array('conditions' => array('user_id' => (string) $Orders['user_id'])));
         if ($Orders['Action'] == 'Buy') {
             $balanceFirst = 'balance.' . $Orders['FirstCurrency'];
             $balanceSecond = 'balance.' . $Orders['SecondCurrency'];
             $data = array($balanceSecond => (double) ($details[$balanceSecond] + $Orders['PerPrice'] * $Orders['Amount']));
             /*				print_r($Orders['username']);
             				print_r($details[$balanceSecond]);
             				print_r($data);
             				*/
             $details = Details::find('all', array('conditions' => array('user_id' => $Orders['user_id'], 'username' => $Orders['username'])))->save($data);
             $fromUser = Details::find('first', array('conditions' => array('user_id' => (string) $Orders['Transact']['user_id'])));
             $data = array($balanceFirst => (double) ($fromUser[$balanceFirst] + (double) $Orders['Amount']));
             /*				print_r($Orders['Transact']['username']);
             				print_r($fromUser[$balanceFirst]);
             				print_r($data);
             		*/
             $details = Details::find('all', array('conditions' => array('user_id' => $Orders['Transact']['user_id'], 'username' => $Orders['Transact']['username'])))->save($data);
         }
         if ($Orders['Action'] == 'Sell') {
             $balanceFirst = 'balance.' . $Orders['FirstCurrency'];
             $balanceSecond = 'balance.' . $Orders['SecondCurrency'];
             $data = array($balanceFirst => (double) ($details[$balanceFirst] + (double) $Orders['Amount']));
             /*				print_r($Orders['username']);
             				print_r($details[$balanceFirst]);
             				print_r($data);
             		*/
             $details = Details::find('all', array('conditions' => array('user_id' => $Orders['user_id'], 'username' => $Orders['username'])))->save($data);
             $fromUser = Details::find('first', array('conditions' => array('user_id' => (string) $Orders['Transact']['user_id'])));
             $data = array($balanceSecond => (double) ($fromUser[$balanceSecond] + $Orders['PerPrice'] * $Orders['Amount']));
             /*				print_r($Orders['Transact']['username']);
             				print_r($fromUser[$balanceSecond]);
             				print_r($data);
             		*/
             $details = Details::find('all', array('conditions' => array('user_id' => $Orders['Transact']['user_id'], 'username' => $Orders['Transact']['username'])))->save($data);
         }
         $Remove = Orders::remove(array('_id' => $Orders['_id']));
         $Remove = Orders::remove(array('_id' => $Orders['Transact']['id']));
         $data = array('page.refresh' => true);
         Details::find('all')->save($data);
     }
     $this->redirect(array('controller' => 'Admin', 'action' => "orders"));
 }