From d1a583a58f11b0d0d8568024cabc451687836465 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Wed, 20 Nov 2019 11:39:24 +0800 Subject: [PATCH] =?UTF-8?q?antgoods=E6=A8=A1=E5=9D=97=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E5=95=86=E5=93=81=E5=88=86=E7=B1=BB=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/views/layouts/sidebar.php | 3 +- .../controllers/ShopcategoryController.php | 149 ++++++++++++++++ .../goods/src/models/ars/ShopCategory.php | 16 +- .../src/models/searchs/ShopCategorySearch.php | 159 ++++++++++++++++++ .../goods/src/views/shopcategory/_form.php | 41 +++++ .../goods/src/views/shopcategory/_search.php | 49 ++++++ .../goods/src/views/shopcategory/create.php | 18 ++ .../goods/src/views/shopcategory/index.php | 28 +++ .../goods/src/views/shopcategory/update.php | 19 +++ .../goods/src/views/shopcategory/view.php | 40 +++++ 10 files changed, 519 insertions(+), 3 deletions(-) create mode 100644 vendor/antgoods/goods/src/controllers/ShopcategoryController.php create mode 100644 vendor/antgoods/goods/src/models/searchs/ShopCategorySearch.php create mode 100644 vendor/antgoods/goods/src/views/shopcategory/_form.php create mode 100644 vendor/antgoods/goods/src/views/shopcategory/_search.php create mode 100644 vendor/antgoods/goods/src/views/shopcategory/create.php create mode 100644 vendor/antgoods/goods/src/views/shopcategory/index.php create mode 100644 vendor/antgoods/goods/src/views/shopcategory/update.php create mode 100644 vendor/antgoods/goods/src/views/shopcategory/view.php diff --git a/backend/views/layouts/sidebar.php b/backend/views/layouts/sidebar.php index 54868f1..c8f8ada 100755 --- a/backend/views/layouts/sidebar.php +++ b/backend/views/layouts/sidebar.php @@ -22,7 +22,8 @@ use iron\widgets\Menu; ], ['label' => '商品管理', 'url' => '#', 'icon' => 'far fa-archive', 'items' => [ ['label' => '商品列表', 'url' => ['/antgoods/goods/index']], - ['label' => '商品分类', 'url' => ['/antgoods/category/index']], + ['label' => '后台商品分类', 'url' => ['/antgoods/category/index']], + ['label' => '前端商品分类', 'url' => ['/antgoods/shopcategory/index']], ['label' => '品牌管理', 'url' => ['/antgoods/brand/index']], ] ], diff --git a/vendor/antgoods/goods/src/controllers/ShopcategoryController.php b/vendor/antgoods/goods/src/controllers/ShopcategoryController.php new file mode 100644 index 0000000..ef1feec --- /dev/null +++ b/vendor/antgoods/goods/src/controllers/ShopcategoryController.php @@ -0,0 +1,149 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all ShopCategory models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new ShopCategorySearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + 'columns' => $searchModel->columns() + ]); + } + + /** + * Displays a single ShopCategory 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 ShopCategory model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new ShopCategory(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect('index'); + } + + return $this->render('create', [ + 'model' => $model, + ]); + } + + /** + * Updates an existing ShopCategory 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 ShopCategory 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 ShopCategory model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return ShopCategory the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = ShopCategory::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } + /** + * @author iron + * 文件导出 + */ + public function actionExport() + { + $searchModel = new ShopCategorySearch(); + $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' =>'Shop Categories'. "-" .date('Y-m-d H/i/s', time()), + 'columns' => $searchModel->columns() + ]); + } +} diff --git a/vendor/antgoods/goods/src/models/ars/ShopCategory.php b/vendor/antgoods/goods/src/models/ars/ShopCategory.php index 2ffb20c..a848f51 100644 --- a/vendor/antgoods/goods/src/models/ars/ShopCategory.php +++ b/vendor/antgoods/goods/src/models/ars/ShopCategory.php @@ -25,6 +25,18 @@ use yii\behaviors\TimestampBehavior; */ class ShopCategory extends \yii\db\ActiveRecord { + //是否显示is_show + const IS_SHOW_DISPLAY = 0;//显示 + const IS_SHOW_HIDE = 1;//隐藏 + //是否删除is_delete + const IS_DELETE_NO = 0;//未删除 + const IS_DELETE_YES = 1;//已删除 + + public static $isShow = [ + self::IS_SHOW_DISPLAY => '显示', + self::IS_SHOW_HIDE => '隐藏' + ]; + /** * {@inheritdoc} */ @@ -65,8 +77,8 @@ class ShopCategory extends \yii\db\ActiveRecord 'icon_type' => '图标类型', 'icon' => '图标', 'filter_attr' => '筛选属性', - 'is_show' => '是否显示,1为不显示', - 'is_delete' => '是否删除,1为已删除', + 'is_show' => '是否显示', + 'is_delete' => '是否删除', 'created_at' => '创建时间', 'updated_at' => '更新时间', ]; diff --git a/vendor/antgoods/goods/src/models/searchs/ShopCategorySearch.php b/vendor/antgoods/goods/src/models/searchs/ShopCategorySearch.php new file mode 100644 index 0000000..524eb11 --- /dev/null +++ b/vendor/antgoods/goods/src/models/searchs/ShopCategorySearch.php @@ -0,0 +1,159 @@ + 'blobt\grid\CheckboxColumn', + 'width' => '2%', + 'align' => 'center' + ], + 'id', + 'name', + 'pid', + 'goods_count', + 'keywords', + //'desc', + //'sort_order', + //'icon_type', + //'icon', + //'filter_attr', + //'is_show', + //'is_delete', + //'created_at', + //'updated_at', + [ + 'class' => 'iron\grid\ActionColumn', + 'align' => 'center', + ], + ]; + } + /** + * @param $params + * @return ActiveDataProvider + * 不分页的所有数据 + */ + public function allData($params) + { + $query = ShopCategory::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 = ShopCategory::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', 'keywords', $this->keywords]) + ->andFilterWhere(['like', 'desc', $this->desc]) + ->andFilterWhere(['like', 'icon', $this->icon]) + ->andFilterWhere(['like', 'filter_attr', $this->filter_attr]); + 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/shopcategory/_form.php b/vendor/antgoods/goods/src/views/shopcategory/_form.php new file mode 100644 index 0000000..1c3efe6 --- /dev/null +++ b/vendor/antgoods/goods/src/views/shopcategory/_form.php @@ -0,0 +1,41 @@ + + +
+ + + + field($model, 'name')->textInput(['maxlength' => true]) ?> + + field($model, 'goods_count')->textInput() ?> + + field($model, 'keywords')->textInput(['maxlength' => true]) ?> + + field($model, 'desc')->textInput(['maxlength' => true]) ?> + + field($model, 'sort_order')->textInput() ?> + + field($model, 'icon_type')->textInput() ?> + + field($model, 'icon')->textInput(['maxlength' => true]) ?> + + field($model, 'filter_attr')->textarea(['rows' => 6]) ?> + + field($model, 'is_show')->widget(Icheck::className(), ["items" => $model::$isShow, 'type' => "radio"]) ?> + +
+ 'btn btn-success']) ?> + 'btn btn-info']) ?> +
+ + + +
diff --git a/vendor/antgoods/goods/src/views/shopcategory/_search.php b/vendor/antgoods/goods/src/views/shopcategory/_search.php new file mode 100644 index 0000000..1e839e6 --- /dev/null +++ b/vendor/antgoods/goods/src/views/shopcategory/_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/shopcategory/create.php b/vendor/antgoods/goods/src/views/shopcategory/create.php new file mode 100644 index 0000000..ff6a2cd --- /dev/null +++ b/vendor/antgoods/goods/src/views/shopcategory/create.php @@ -0,0 +1,18 @@ +title = '创建前端商品分类'; +$this->params['breadcrumbs'][] = ['label' => '前端商品分类', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/vendor/antgoods/goods/src/views/shopcategory/index.php b/vendor/antgoods/goods/src/views/shopcategory/index.php new file mode 100644 index 0000000..af3692d --- /dev/null +++ b/vendor/antgoods/goods/src/views/shopcategory/index.php @@ -0,0 +1,28 @@ +title = '前端商品分类'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+
+ $dataProvider, + 'filter' => $this->render("_search", ['model' => $searchModel]), + 'batch' => [ + [ + "label" => "删除", + "url" => "shopcategory/deletes" + ], + ], + 'columns' => $columns + ]); + ?> +
+
\ No newline at end of file diff --git a/vendor/antgoods/goods/src/views/shopcategory/update.php b/vendor/antgoods/goods/src/views/shopcategory/update.php new file mode 100644 index 0000000..d59515f --- /dev/null +++ b/vendor/antgoods/goods/src/views/shopcategory/update.php @@ -0,0 +1,19 @@ +title = '编辑前端商品分类: ' . $model->name; +$this->params['breadcrumbs'][] = ['label' => '前端商品分类', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = '编辑 '; +?> +
+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/vendor/antgoods/goods/src/views/shopcategory/view.php b/vendor/antgoods/goods/src/views/shopcategory/view.php new file mode 100644 index 0000000..23f9c29 --- /dev/null +++ b/vendor/antgoods/goods/src/views/shopcategory/view.php @@ -0,0 +1,40 @@ +title = $model->name; +$this->params['breadcrumbs'][] = ['label' => '前端商品分类', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +\yii\web\YiiAsset::register($this); +?> +
+ +

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

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