public function stat($params) { $query = SentSms::find(); $this->load($params); $query->select(['COUNT(`STATUS`) as `all`', 'SUM(`Status`) as `succeed`', "DATE_FORMAT(SmsTime,'%Y-%m-%d') as `date`"]); $query->addGroupBy("TO_DAYS(SmsTime)"); if (!empty($this->SmsTime) && strpos($this->SmsTime, " 至 ")) { list($startTime, $endTime) = explode(" 至 ", $this->SmsTime); $startTime = $startTime . " 00:00:00"; $endTime = $endTime . " 23:59:59"; $query->andFilterWhere(["between", "SmsTime", $startTime, $endTime]); } $dataProvider = new ArrayDataProvider(['allModels' => $query->asArray()->all()]); return $dataProvider; }
/** * Finds the SentSms model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return SentSms the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = SentSms::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }