diff --git a/docs/api/reports.md b/docs/api/reports.md index 32feef2..1d71804 100644 --- a/docs/api/reports.md +++ b/docs/api/reports.md @@ -119,7 +119,7 @@
Возвращаемые параметры: id - идентификатор отчёта, date - дата отчёта, diff --git a/frontend/modules/api/controllers/ReportsController.php b/frontend/modules/api/controllers/ReportsController.php index 0e683df..37411e4 100755 --- a/frontend/modules/api/controllers/ReportsController.php +++ b/frontend/modules/api/controllers/ReportsController.php @@ -72,7 +72,7 @@ class ReportsController extends ApiController /** * @throws NotFoundHttpException */ - public function actionFindByDate(): array + public function actionFindByDate()//: array { $reportsModel = new ReportSearchForm(); @@ -82,11 +82,19 @@ class ReportsController extends ApiController } $reportsModel->attributes = $params; - $reportsModel->byDate = true; + $reportsModel->date = $params['date']; + + if (!$this->checkDate($reportsModel->date)) { + throw new BadRequestHttpException('Wrong date format'); + } + +// return $reportsModel->date; +// return $reportsModel->user_card_id; if(!$reportsModel->validate()){ return $reportsModel->errors; } + return $reportsModel->findByDate(); } @@ -170,14 +178,14 @@ class ReportsController extends ApiController /** * @throws NotFoundHttpException */ - public function actionReportsByDate($fromDate, $toDate, $user_id = null) + public function actionReportsByDate($fromDate, $toDate, $user_card_id = null) { if (!$this->checkDate($fromDate) || !$this->checkDate($toDate)) { throw new BadRequestHttpException('Wrong date format'); } $params = Yii::$app->request->get(); - $userId = $user_id ?? Yii::$app->user->id; + $userId = $user_card_id ?? Yii::$app->user->id; /** @var UserCard $userCard */ $userCard = UserCard::find()->where(['id_user' => $userId])->one(); @@ -187,7 +195,7 @@ class ReportsController extends ApiController $reportsModel = new ReportSearchForm(); $reportsModel->attributes = $params; - $reportsModel->user_id = $userCard->id; + $reportsModel->user_card_id = $userCard->id; $reports = $reportsModel->findByDate(); return ArrayHelper::toArray($reports , [ diff --git a/frontend/modules/api/models/ReportSearchForm.php b/frontend/modules/api/models/ReportSearchForm.php index 5359698..cb83a4a 100755 --- a/frontend/modules/api/models/ReportSearchForm.php +++ b/frontend/modules/api/models/ReportSearchForm.php @@ -13,7 +13,7 @@ class ReportSearchForm extends Model public $offset; public $fromDate; public $toDate; - public $user_id; + public $user_card_id; /** * @var false */ @@ -24,10 +24,10 @@ class ReportSearchForm extends Model { $this->limit = 10; $this->offset = 0; - $this->user_id = null; + $this->user_card_id = null; $this->toDate = date('Y-m-d', time()); - $this->fromDate = date('Y-m-01', time()); + $this->fromDate = date('Y-m-d', time()); $this->date = date('Y-m-d'); $this->byDate = false; @@ -38,8 +38,8 @@ class ReportSearchForm extends Model { return [ [['byDate'], 'safe'], - [['fromDate', 'toDate', 'date'], 'date', 'format' => 'php:Y-m-d'], - [['limit', 'offset', 'user_id'], 'integer', 'min' => 0], +// [['fromDate', 'toDate', 'date'], 'date', 'format' => 'Y-m-d'], + [['limit', 'offset', 'user_card_id'], 'integer', 'min' => 0], ]; } @@ -57,8 +57,8 @@ class ReportSearchForm extends Model $queryBuilder->limit($this->limit) ->offset($this->offset); - if (isset($this->user_id)) { - $queryBuilder->andWhere(['user_card_id' => $this->user_id]); + if (isset($this->user_card_id)) { + $queryBuilder->andWhere(['user_card_id' => $this->user_card_id]); } $data = $queryBuilder->asArray()->all(); @@ -69,8 +69,8 @@ class ReportSearchForm extends Model public function findByDate(): array { return Reports::find() - ->where(['between', 'reports.created_at', $this->fromDate, $this->toDate]) - ->andWhere(['user_card_id' => $this->user_id]) + ->where(['user_card_id' => $this->user_card_id]) + ->andWhere(['created_at' => $this->date]) ->all(); } } \ No newline at end of file