/**
  * Finds the Plan model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Plan the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Plan::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#2
0
 public function getMonthStat($user_id)
 {
     $account_query = Account::find()->where(['user_id' => $user_id, 'io_type' => Account::IO_TYPE_EXPENDITURE])->andWhere(['>=', 'date', date("Y-m-01")]);
     $sum = round($account_query->sum('value'), 2);
     $month_days = intval((strtotime(date("Y-m-d")) - strtotime(date("Y-m-01")) + 3600 * 24) / (3600 * 24));
     $average = round($sum / $month_days, 2);
     $plan = Plan::findOne(['user_id' => $user_id]);
     return ['sum' => $sum, 'average' => $average, 'plan' => isset($plan->value) ? intval($plan->value) : 5000];
 }