/** * Creates data provider instance with search query applied * @param array $params * @return ActiveDataProvider */ public function search($params) { $query = InvoiceModel::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); $this->load($params); if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'amount' => $this->amount]); if (isset($params['user'])) { $query->andFilterWhere(['user_name' => $params['user']]); } if (isset($params['scenario'])) { $query->andWhere('withdraw' == $params['scenario'] ? 'amount < 0' : 'amount > 0'); } $query->andFilterWhere(['like', 'user_name', $this->user_name])->andFilterWhere(['like', 'status', $this->status]); return $dataProvider; }
/** * Finds the Invoice model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Invoice the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Invoice::findOne($id)) !== null) { $model->scenario = $model->amount < 0 ? 'withdraw' : 'payment'; return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public static function statistics() { $started = strtotime(SQL::queryCell('SELECT "time" FROM "journal" WHERE id = 1')); $invested = (int) SQL::queryCell('SELECT count(*) FROM "node"'); return ['Started' => date('d-m-Y', $started), 'Running days' => floor((time() - $started) / (3600 * 24)), 'Users' => User::find()->count(), 'Total deposited' => Invoice::find()->where(['or', ['status' => 'success'], ['status' => 'delete']])->andWhere('amount > 0')->sum('amount'), 'Total withdraw' => -Invoice::find()->where(['or', ['status' => 'success'], ['status' => 'delete']])->andWhere('amount < 0')->sum('amount'), 'Number of investments' => $invested]; }