diff --git a/backend/modules/shop/controllers/CommentController.php b/backend/modules/shop/controllers/CommentController.php new file mode 100644 index 0000000..c167fa0 --- /dev/null +++ b/backend/modules/shop/controllers/CommentController.php @@ -0,0 +1,150 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all Comment models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new CommentSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + 'columns' => $searchModel->columns() + ]); + } + + /** + * Displays a single Comment model. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Comment model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Comment(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect('index'); + } + + return $this->render('create', [ + 'model' => $model, + ]); + } + + /** + * Updates an existing Comment model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect('index'); + } + + return $this->render('update', [ + 'model' => $model, + ]); + } + + /** + * Deletes an existing Comment model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the Comment model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Comment the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Comment::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } + /** + * @author iron + * 文件导出 + */ + public function actionExport() + { + $searchModel = new CommentSearch(); + $params = Yii::$app->request->queryParams; + if ($params['page-type'] == 'all') { + $dataProvider = $searchModel->allData($params); + } else { + $dataProvider = $searchModel->search($params); + } + Excel::export([ + 'models' => $dataProvider->getModels(), + 'format' => 'Xlsx', + 'asAttachment' => true, + 'fileName' =>'Comments'. "-" .date('Y-m-d H/i/s', time()), + 'columns' => $searchModel->columns() + ]); + } +} diff --git a/backend/modules/shop/models/searchs/CommentSearch.php b/backend/modules/shop/models/searchs/CommentSearch.php new file mode 100644 index 0000000..d39c4b5 --- /dev/null +++ b/backend/modules/shop/models/searchs/CommentSearch.php @@ -0,0 +1,147 @@ + 'blobt\grid\CheckboxColumn', + 'width' => '2%', + 'align' => 'center' + ], + 'id', + 'user_id', + 'order_goods_id', + 'star', + 'content', + //'status', + //'updated_at', + //'created_at', + [ + 'class' => 'iron\grid\ActionColumn', + 'align' => 'center', + ], + ]; + } + /** + * @param $params + * @return ActiveDataProvider + * 不分页的所有数据 + */ + public function allData($params) + { + $query = Comment::find(); + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + 'pagination' => false, + 'sort' => false + ]); + $this->load($params); + return $this->filter($query, $dataProvider); + } + + /** + * Creates data provider instance with search query applied + * + * @param array $params + * + * @return ActiveDataProvider + */ + public function search($params) + { + $query = Comment::find(); + + // add conditions that should always apply here + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + 'pagination' => [ + 'pageSizeLimit' => [1, 200] + ], + 'sort' => [ + 'defaultOrder' => [ + 'id' => SORT_DESC, + ] + ], + ]); + + $this->load($params); + return $this->filter($query, $dataProvider); + } + /** + * @param $query + * @param $dataProvider + * @return ActiveDataProvider + * 条件筛选 + */ + private function filter($query, $dataProvider){ + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'id' => $this->id, + 'user_id' => $this->user_id, + 'order_goods_id' => $this->order_goods_id, + 'star' => $this->star, + 'status' => $this->status, + 'updated_at' => $this->updated_at, + 'created_at' => $this->created_at, + ]); + + $query->andFilterWhere(['like', 'content', $this->content]); + if ($this->created_at_range) { + $arr = explode(' ~ ', $this->created_at_range); + $start = strtotime($arr[0]); + $end = strtotime($arr[1]) + 3600 * 24; + $query->andFilterWhere(['between', 'created_at', $start, $end]); + } + return $dataProvider; + } +} diff --git a/backend/modules/shop/views/comment/_form.php b/backend/modules/shop/views/comment/_form.php new file mode 100644 index 0000000..78898f8 --- /dev/null +++ b/backend/modules/shop/views/comment/_form.php @@ -0,0 +1,32 @@ + + +
+ + + + field($model, 'user_id')->textInput() ?> + + field($model, 'order_goods_id')->textInput() ?> + + field($model, 'star')->textInput() ?> + + field($model, 'content')->textarea(['rows' => 6]) ?> + + field($model, 'status')->textInput() ?> + +
+ 'btn btn-success']) ?> + 'btn btn-info']) ?> +
+ + + +
diff --git a/backend/modules/shop/views/comment/_search.php b/backend/modules/shop/views/comment/_search.php new file mode 100644 index 0000000..54cde7b --- /dev/null +++ b/backend/modules/shop/views/comment/_search.php @@ -0,0 +1,49 @@ + + + ['index'], + 'method' => 'get', + 'validateOnType' => true, + ]); +?> +
+
+ field($model, 'id', [ + "template" => "{input}{error}", + "inputOptions" => [ + "placeholder" => "检索ID", + "class" => "form-control", + ], + "errorOptions" => [ + "class" => "error-tips" + ] + ]) + ?> +
+
+ field($model, "created_at_range", [ + "template" => "{input}{error}", + "inputOptions" => [ + "placeholder" => "创建时间", + ], + "errorOptions" => [ + "class" => "error-tips" + ] + ])->widget(DateRangePicker::className()); + ?> +
+
+ ', ['class' => 'btn btn-default']) ?> + ', ['class' => 'btn btn-default']) ?> +
+
+ \ No newline at end of file diff --git a/backend/modules/shop/views/comment/create.php b/backend/modules/shop/views/comment/create.php new file mode 100644 index 0000000..2c4decc --- /dev/null +++ b/backend/modules/shop/views/comment/create.php @@ -0,0 +1,18 @@ +title = '创建 Comment'; +$this->params['breadcrumbs'][] = ['label' => 'Comments', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/modules/shop/views/comment/index.php b/backend/modules/shop/views/comment/index.php new file mode 100644 index 0000000..a0cea8b --- /dev/null +++ b/backend/modules/shop/views/comment/index.php @@ -0,0 +1,28 @@ +title = 'Comments'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+
+ $dataProvider, + 'filter' => $this->render("_search", ['model' => $searchModel]), + 'batch' => [ + [ + "label" => "删除", + "url" => "comment/deletes" + ], + ], + 'columns' => $columns + ]); + ?> +
+
\ No newline at end of file diff --git a/backend/modules/shop/views/comment/update.php b/backend/modules/shop/views/comment/update.php new file mode 100644 index 0000000..da61136 --- /dev/null +++ b/backend/modules/shop/views/comment/update.php @@ -0,0 +1,19 @@ +title = '编辑 Comment: ' . $model->id; +$this->params['breadcrumbs'][] = ['label' => 'Comments', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = 'Update '; +?> +
+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/modules/shop/views/comment/view.php b/backend/modules/shop/views/comment/view.php new file mode 100644 index 0000000..beefa45 --- /dev/null +++ b/backend/modules/shop/views/comment/view.php @@ -0,0 +1,34 @@ +title = $model->id; +$this->params['breadcrumbs'][] = ['label' => 'Comments', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +\yii\web\YiiAsset::register($this); +?> +
+ +

+ 'btn btn-success']) ?> +

+ + $model, + 'attributes' => [ + 'id', + 'user_id', + 'order_goods_id', + 'star', + 'content:ntext', + 'status', + 'updated_at', + 'created_at', + ], + ]) ?> + +