From 14e4996136edbe3a4c9d9db7dddef37dfeef971c Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Tue, 19 Nov 2019 19:25:29 +0800 Subject: [PATCH] =?UTF-8?q?antgoods=E5=A2=9E=E5=8A=A0=E5=95=86=E5=93=81?= =?UTF-8?q?=E5=88=86=E7=B1=BB=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/controllers/CategoryController.php | 149 +++++++++++++++++ .../src/models/searchs/CategorySearch.php | 153 ++++++++++++++++++ .../goods/src/views/category/_form.php | 38 +++++ .../goods/src/views/category/_search.php | 49 ++++++ .../goods/src/views/category/create.php | 18 +++ .../goods/src/views/category/index.php | 28 ++++ .../goods/src/views/category/update.php | 19 +++ .../goods/src/views/category/view.php | 37 +++++ 8 files changed, 491 insertions(+) create mode 100644 vendor/antgoods/goods/src/controllers/CategoryController.php create mode 100644 vendor/antgoods/goods/src/models/searchs/CategorySearch.php create mode 100644 vendor/antgoods/goods/src/views/category/_form.php create mode 100644 vendor/antgoods/goods/src/views/category/_search.php create mode 100644 vendor/antgoods/goods/src/views/category/create.php create mode 100644 vendor/antgoods/goods/src/views/category/index.php create mode 100644 vendor/antgoods/goods/src/views/category/update.php create mode 100644 vendor/antgoods/goods/src/views/category/view.php diff --git a/vendor/antgoods/goods/src/controllers/CategoryController.php b/vendor/antgoods/goods/src/controllers/CategoryController.php new file mode 100644 index 0000000..64017dc --- /dev/null +++ b/vendor/antgoods/goods/src/controllers/CategoryController.php @@ -0,0 +1,149 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all Category models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new CategorySearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + 'columns' => $searchModel->columns() + ]); + } + + /** + * Displays a single Category 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 Category model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Category(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect('index'); + } + + return $this->render('create', [ + 'model' => $model, + ]); + } + + /** + * Updates an existing Category 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 Category 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 Category model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Category the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Category::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } + /** + * @author iron + * 文件导出 + */ + public function actionExport() + { + $searchModel = new CategorySearch(); + $params = Yii::$app->request->queryParams; + if ($params['page-type'] == 'all') { + $dataProvider = $searchModel->allData($params); + } else { + $dataProvider = $searchModel->search($params); + } + \iron\widget\Excel::export([ + 'models' => $dataProvider->getModels(), + 'format' => 'Xlsx', + 'asAttachment' => true, + 'fileName' =>'Categories'. "-" .date('Y-m-d H/i/s', time()), + 'columns' => $searchModel->columns() + ]); + } +} diff --git a/vendor/antgoods/goods/src/models/searchs/CategorySearch.php b/vendor/antgoods/goods/src/models/searchs/CategorySearch.php new file mode 100644 index 0000000..63ad3f0 --- /dev/null +++ b/vendor/antgoods/goods/src/models/searchs/CategorySearch.php @@ -0,0 +1,153 @@ + 'blobt\grid\CheckboxColumn', + 'width' => '2%', + 'align' => 'center' + ], + 'id', + 'name', + 'pid', + 'goods_count', + 'sort_order', + //'icon_type', + //'icon', + //'is_show', + //'is_delete', + //'created_at', + //'updated_at', + [ + 'class' => 'iron\grid\ActionColumn', + 'align' => 'center', + ], + ]; + } + /** + * @param $params + * @return ActiveDataProvider + * 不分页的所有数据 + */ + public function allData($params) + { + $query = Category::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 = Category::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, + 'pid' => $this->pid, + 'goods_count' => $this->goods_count, + 'sort_order' => $this->sort_order, + 'icon_type' => $this->icon_type, + 'is_show' => $this->is_show, + 'is_delete' => $this->is_delete, + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]); + + $query->andFilterWhere(['like', 'name', $this->name]) + ->andFilterWhere(['like', 'icon', $this->icon]); + 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/vendor/antgoods/goods/src/views/category/_form.php b/vendor/antgoods/goods/src/views/category/_form.php new file mode 100644 index 0000000..c2fe65f --- /dev/null +++ b/vendor/antgoods/goods/src/views/category/_form.php @@ -0,0 +1,38 @@ + + +
+ + + + field($model, 'name')->textInput(['maxlength' => true]) ?> + + field($model, 'pid')->textInput() ?> + + field($model, 'goods_count')->textInput() ?> + + field($model, 'sort_order')->textInput() ?> + + field($model, 'icon_type')->textInput() ?> + + field($model, 'icon')->textInput(['maxlength' => true]) ?> + + field($model, 'is_show')->textInput() ?> + + field($model, 'is_delete')->textInput() ?> + +
+ 'btn btn-success']) ?> + 'btn btn-info']) ?> +
+ + + +
diff --git a/vendor/antgoods/goods/src/views/category/_search.php b/vendor/antgoods/goods/src/views/category/_search.php new file mode 100644 index 0000000..d43cb1d --- /dev/null +++ b/vendor/antgoods/goods/src/views/category/_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/vendor/antgoods/goods/src/views/category/create.php b/vendor/antgoods/goods/src/views/category/create.php new file mode 100644 index 0000000..1ecb4fa --- /dev/null +++ b/vendor/antgoods/goods/src/views/category/create.php @@ -0,0 +1,18 @@ +title = '创建 Category'; +$this->params['breadcrumbs'][] = ['label' => 'Categories', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/vendor/antgoods/goods/src/views/category/index.php b/vendor/antgoods/goods/src/views/category/index.php new file mode 100644 index 0000000..b63d020 --- /dev/null +++ b/vendor/antgoods/goods/src/views/category/index.php @@ -0,0 +1,28 @@ +title = '商品分类'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+
+ $dataProvider, + 'filter' => $this->render("_search", ['model' => $searchModel]), + 'batch' => [ + [ + "label" => "删除", + "url" => "category/deletes" + ], + ], + 'columns' => $columns + ]); + ?> +
+
\ No newline at end of file diff --git a/vendor/antgoods/goods/src/views/category/update.php b/vendor/antgoods/goods/src/views/category/update.php new file mode 100644 index 0000000..a4a8106 --- /dev/null +++ b/vendor/antgoods/goods/src/views/category/update.php @@ -0,0 +1,19 @@ +title = '编辑 Category: ' . $model->name; +$this->params['breadcrumbs'][] = ['label' => 'Categories', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = 'Update '; +?> +
+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/vendor/antgoods/goods/src/views/category/view.php b/vendor/antgoods/goods/src/views/category/view.php new file mode 100644 index 0000000..2a087d5 --- /dev/null +++ b/vendor/antgoods/goods/src/views/category/view.php @@ -0,0 +1,37 @@ +title = $model->name; +$this->params['breadcrumbs'][] = ['label' => 'Categories', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +\yii\web\YiiAsset::register($this); +?> +
+ +

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

+ + $model, + 'attributes' => [ + 'id', + 'name', + 'pid', + 'goods_count', + 'sort_order', + 'icon_type', + 'icon', + 'is_show', + 'is_delete', + 'created_at', + 'updated_at', + ], + ]) ?> + +