/**
  * What to do when this action will be called.
  *
  * Just render the `index` view file from current controller.
  */
 public function run()
 {
     if (Yii::app()->user->isGuest) {
         $this->controller->layout = '//layouts/landing';
         $this->controller->render('landing');
     } else {
         $this->controller->layout = '//layouts/main';
         $user = Yii::app()->user->data();
         $balance = Balance::model()->findAllByAttributes(array('id_user' => $user->id));
         $transactions = Transaction::model()->findAllByAttributes(array('id_user' => $user->id), new CDbCriteria(array('order' => 'create_time DESC', 'limit' => 10)));
         $this->controller->render('home', array('transactions' => $transactions, 'balance' => $balance));
     }
 }
示例#2
0
 public function actionTest()
 {
     $start = time();
     Yii::app()->cache->flush();
     Yii::app()->db->createCommand()->truncateTable(Buy::model()->tableName());
     Yii::app()->db->createCommand()->truncateTable(Sell::model()->tableName());
     Yii::app()->db->createCommand()->truncateTable(Order::model()->tableName());
     Yii::app()->db->createCommand()->truncateTable(Balance::model()->tableName());
     // Тест на 10 000 руб.
     Status::setParam('balance', 10000);
     Status::setParam('balance_btc', 0);
     $exs = Exchange::getAllByDt('btc_rur', '2013-12-16', '2014-01-06');
     $cnt = 0;
     foreach ($exs as $exchange) {
         $obj = new stdClass();
         $obj->dtm = $exchange['dt'];
         $obj->buy = $exchange['buy'];
         $obj->sell = $exchange['sell'];
         $cnt++;
         $bot = new Bot($obj);
         $bot->run();
     }
     $end = time();
     echo '<b>Elapsed time: ' . ($end - $start) / 60 . ' min.<br/>';
     echo '<b>Steps count: ' . $cnt . '<br/>';
 }
示例#3
0
 public static function add($currency, $desc, $summ)
 {
     $last = Balance::model()->find(array('condition' => 'currency = "' . $currency . '"', 'order' => 'id desc'));
     $last_balance = 0;
     if ($last) {
         $last_balance = $last->balance;
     }
     $bot = Bot::get_Instance();
     $b = new Balance();
     $b->dtm = $bot->current_exchange->dtm;
     $b->description = $desc;
     $b->summ = $summ;
     $b->balance = $last_balance + $summ;
     $b->currency = $currency;
     $b->save() || die(print_r($b->errors, true));
     return $last;
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionTodayStorage()
 {
     $dates = date('Y:m:d');
     $depId = $_POST['depId'];
     $Products = array();
     /*$model = DepBalance::model()->with('products')->findAll('t.department_id = :depId AND t.type = :type',array(':depId'=>$depId,'type'=>1));
       foreach ($model as $val) {
           $products[$val->prod_id] = $val->getRelated('products')->name;
       }*/
     //$model = new Products();
     //$products = $model->getProdName($depId);
     $storageModel = Storage::model()->findAll();
     $balanceModel = Balance::model()->with('products')->findAll('b_date = :b_date', array(':b_date' => $dates));
     if (!empty($balanceModel)) {
         foreach ($balanceModel as $val) {
             $products[$val->prod_id] = $val->getRelated('products')->name;
             $Products[$val->prod_id] = $Products[$val->prod_id] + $val->startCount;
         }
     } else {
         foreach ($storageModel as $val) {
             $Products[$val->prod_id] = $Products[$val->prod_id] + $val->curCount;
         }
     }
     $realizedProd = Faktura::model()->with('realize.products')->findAll('date(realize_date) = :realize_date', array('realize_date' => $dates));
     foreach ($realizedProd as $value) {
         foreach ($value->getRelated('realize') as $val) {
             $Products[$val->prod_id] = $Products[$val->prod_id] + $val->count;
         }
     }
     $realizeStorageProd = DepFaktura::model()->with('realizedProd')->findAll('date(real_date) = :real_date AND fromDepId = :fromDepId', array(':real_date' => $dates, ':fromDepId' => 0));
     foreach ($realizeStorageProd as $value) {
         foreach ($value->getRelated('realizedProd') as $val) {
             $Products[$val->prod_id] = $Products[$val->prod_id] - $val->count;
         }
     }
     $expBalance = Yii::app()->db->createCommand()->select('ord.just_id,ord.count')->from('expense ex')->join('orders ord', 'ord.expense_id = ex.expense_id')->where('date(ex.order_date) = :dates AND ex.kind = :kind ', array(':dates' => $dates, ':kind' => 1))->queryAll();
     foreach ($expBalance as $val) {
         $Products[$val['just_id']] = $Products[$val['just_id']] - $val['count'];
     }
     $this->renderPartial('todayStorage', array('Products' => $Products, 'products' => $products, 'depId' => $depId));
 }
 public function actionToday()
 {
     $dates = date('Y-m-d');
     $startProducts = array();
     $inProducts = array();
     $outProducts = array();
     $inOutProducts = array();
     $endProducts = array();
     $prodModel = Products::model()->findAll();
     //Приход
     $fakturaProd = Faktura::model()->with('realize.products')->findAll('date(realize_date) = :realize_date', array('realize_date' => $dates));
     foreach ($fakturaProd as $value) {
         foreach ($value->getRelated('realize') as $key => $val) {
             $inProducts[$val->getRelated('products')->product_id] = $inProducts[$val->getRelated('products')->product_id] + $val->count;
         }
     }
     //Расход
     $Depfaktura = DepFaktura::model()->with('realizedProd')->findAll('date(real_date) = :real_date', array(':real_date' => $dates));
     foreach ($Depfaktura as $value) {
         foreach ($value->getRelated('realizedProd') as $val) {
             $outProducts[$val->prod_id] = $outProducts[$val->prod_id] + $val->count;
         }
     }
     $expense = Expense::model()->with('order.products')->findAll('date(order_date) = :dates AND t.kind = :kind', array(':kind' => 1, ':dates' => $dates));
     foreach ($expense as $value) {
         foreach ($value->getRelated('order') as $val) {
             $inOutProducts[$val->just_id] = $inOutProducts[$val->just_id] + $val->count;
         }
     }
     $curProd = Balance::model()->with('products')->findAll('b_date = :dates', array(':dates' => $dates), array('order' => 'products.name'));
     foreach ($curProd as $value) {
         $endProducts[$value->prod_id] = $endProducts[$value->prod_id] + $value->startCount + $inProducts[$value->prod_id] - $outProducts[$value->prod_id] - $inOutProducts[$value->prod_id];
     }
     $this->render('today', array('prodModel' => $prodModel, 'model' => $curProd, 'inProducts' => $inProducts, 'outProducts' => $outProducts, 'inOutProducts' => $inOutProducts, 'endProducts' => $endProducts));
 }
 public function addProd($id)
 {
     if ($this->checkProd($id) != true) {
         $max_date = Balance::model()->find(array('select' => 'MAX(b_date) as b_date'));
         $model = new Balance();
         $model->b_date = $max_date->b_date;
         $model->prod_id = $id;
         $model->startCount = 0;
         $model->endCount = 0;
         $model->save();
     }
 }
示例#7
0
 public function actionTest()
 {
     if ($_SERVER['HTTP_HOST'] !== 'btcbot.loc') {
         return;
     }
     $start = time();
     Yii::app()->cache->flush();
     Yii::app()->db->createCommand()->truncateTable(Buy::model()->tableName());
     Yii::app()->db->createCommand()->truncateTable(Sell::model()->tableName());
     Yii::app()->db->createCommand()->truncateTable(Order::model()->tableName());
     Yii::app()->db->createCommand()->truncateTable(Balance::model()->tableName());
     Status::setParam('balance', 5000);
     Status::setParam('balance_btc', 0);
     $exs = Exchange::getAll();
     $cnt = 0;
     foreach ($exs as $exchange) {
         $obj = new stdClass();
         $obj->dtm = $exchange['dt'];
         $obj->buy = $exchange['buy'];
         $obj->sell = $exchange['sell'];
         $cnt++;
         $bot = new Bot($obj);
         $bot->run();
     }
     $end = time();
     echo '<b>Время выполнения: ' . ($end - $start) / 60 . ' мин.<br/>';
     echo '<b>Сделано шагов: ' . $cnt . '<br/>';
     //$this->render('index');
 }