Browse Source

antgoods模块增加前端商品分类模块

wechat_public_accounts
linyaostalker 5 years ago
parent
commit
d1a583a58f
  1. 3
      backend/views/layouts/sidebar.php
  2. 149
      vendor/antgoods/goods/src/controllers/ShopcategoryController.php
  3. 16
      vendor/antgoods/goods/src/models/ars/ShopCategory.php
  4. 159
      vendor/antgoods/goods/src/models/searchs/ShopCategorySearch.php
  5. 41
      vendor/antgoods/goods/src/views/shopcategory/_form.php
  6. 49
      vendor/antgoods/goods/src/views/shopcategory/_search.php
  7. 18
      vendor/antgoods/goods/src/views/shopcategory/create.php
  8. 28
      vendor/antgoods/goods/src/views/shopcategory/index.php
  9. 19
      vendor/antgoods/goods/src/views/shopcategory/update.php
  10. 40
      vendor/antgoods/goods/src/views/shopcategory/view.php

3
backend/views/layouts/sidebar.php

@ -22,7 +22,8 @@ use iron\widgets\Menu;
], ],
['label' => '商品管理', 'url' => '#', 'icon' => 'far fa-archive', 'items' => [ ['label' => '商品管理', 'url' => '#', 'icon' => 'far fa-archive', 'items' => [
['label' => '商品列表', 'url' => ['/antgoods/goods/index']], ['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']], ['label' => '品牌管理', 'url' => ['/antgoods/brand/index']],
] ]
], ],

149
vendor/antgoods/goods/src/controllers/ShopcategoryController.php

@ -0,0 +1,149 @@
<?php
namespace antgoods\goods\controllers;
use Yii;
use antgoods\goods\models\ars\ShopCategory;
use antgoods\goods\models\searchs\ShopCategorySearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* ShopcategoryController implements the CRUD actions for ShopCategory model.
*/
class ShopcategoryController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'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()
]);
}
}

16
vendor/antgoods/goods/src/models/ars/ShopCategory.php

@ -25,6 +25,18 @@ use yii\behaviors\TimestampBehavior;
*/ */
class ShopCategory extends \yii\db\ActiveRecord 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} * {@inheritdoc}
*/ */
@ -65,8 +77,8 @@ class ShopCategory extends \yii\db\ActiveRecord
'icon_type' => '图标类型', 'icon_type' => '图标类型',
'icon' => '图标', 'icon' => '图标',
'filter_attr' => '筛选属性', 'filter_attr' => '筛选属性',
'is_show' => '是否显示,1为不显示',
'is_delete' => '是否删除,1为已删除',
'is_show' => '是否显示',
'is_delete' => '是否删除',
'created_at' => '创建时间', 'created_at' => '创建时间',
'updated_at' => '更新时间', 'updated_at' => '更新时间',
]; ];

159
vendor/antgoods/goods/src/models/searchs/ShopCategorySearch.php

@ -0,0 +1,159 @@
<?php
namespace antgoods\goods\models\searchs;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use yii\helpers\ArrayHelper;
use antgoods\goods\models\ars\ShopCategory;
/**
* ShopCategorySearch represents the model behind the search form of `antgoods\goods\models\ars\ShopCategory`.
*/
class ShopCategorySearch extends ShopCategory
{
/**
* @return array
* 增加创建时间查询字段
*/
public function attributes()
{
return ArrayHelper::merge(['created_at_range'], parent::attributes());
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id', 'pid', 'goods_count', 'sort_order', 'icon_type', 'is_show', 'is_delete', 'created_at', 'updated_at'], 'integer'],
[['name', 'keywords', 'desc', 'icon', 'filter_attr'], 'safe'],
['created_at_range','safe'],
];
}
/**
* {@inheritdoc}
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* @return array
* 列格式
*/
public function columns()
{
return [
[
'class' => '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;
}
}

41
vendor/antgoods/goods/src/views/shopcategory/_form.php

@ -0,0 +1,41 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use blobt\widgets\Icheck;
/* @var $this yii\web\View */
/* @var $model antgoods\goods\models\ars\ShopCategory */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="shop-category-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'goods_count')->textInput() ?>
<?= $form->field($model, 'keywords')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'desc')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'sort_order')->textInput() ?>
<?= $form->field($model, 'icon_type')->textInput() ?>
<?= $form->field($model, 'icon')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'filter_attr')->textarea(['rows' => 6]) ?>
<?= $form->field($model, 'is_show')->widget(Icheck::className(), ["items" => $model::$isShow, 'type' => "radio"]) ?>
<div class="form-group">
<?= Html::submitButton('保存', ['class' => 'btn btn-success']) ?>
<?= Html::a('返回', ['index'], ['class' => 'btn btn-info']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

49
vendor/antgoods/goods/src/views/shopcategory/_search.php

@ -0,0 +1,49 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use \blobt\widgets\DateRangePicker;
/* @var $this yii\web\View */
/* @var $model common\models\searchs\ShopCategorySearch */
/* @var $form yii\widgets\ActiveForm */
?>
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
'validateOnType' => true,
]);
?>
<div class="row">
<div class="col">
<?= $form->field($model, 'id', [
"template" => "{input}{error}",
"inputOptions" => [
"placeholder" => "检索ID",
"class" => "form-control",
],
"errorOptions" => [
"class" => "error-tips"
]
])
?>
</div>
<div class="col">
<?= $form->field($model, "created_at_range", [
"template" => "{input}{error}",
"inputOptions" => [
"placeholder" => "创建时间",
],
"errorOptions" => [
"class" => "error-tips"
]
])->widget(DateRangePicker::className());
?>
</div>
<div class="form-group">
<?= Html::submitButton('<i class="fa fa-filter"></i>', ['class' => 'btn btn-default']) ?>
<?= Html::resetButton('<i class="fa fa-eraser"></i>', ['class' => 'btn btn-default']) ?>
</div>
</div>
<?php ActiveForm::end(); ?>

18
vendor/antgoods/goods/src/views/shopcategory/create.php

@ -0,0 +1,18 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model antgoods\goods\models\ars\ShopCategory */
$this->title = '创建前端商品分类';
$this->params['breadcrumbs'][] = ['label' => '前端商品分类', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="shop-category-create">
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

28
vendor/antgoods/goods/src/views/shopcategory/index.php

@ -0,0 +1,28 @@
<?php
use yii\helpers\Html;
use iron\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel common\models\searchs\ShopCategorySearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = '前端商品分类';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="row">
<div class="col-12">
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filter' => $this->render("_search", ['model' => $searchModel]),
'batch' => [
[
"label" => "删除",
"url" => "shopcategory/deletes"
],
],
'columns' => $columns
]);
?>
</div>
</div>

19
vendor/antgoods/goods/src/views/shopcategory/update.php

@ -0,0 +1,19 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model antgoods\goods\models\ars\ShopCategory */
$this->title = '编辑前端商品分类: ' . $model->name;
$this->params['breadcrumbs'][] = ['label' => '前端商品分类', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = '编辑 ';
?>
<div class="shop-category-update">
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

40
vendor/antgoods/goods/src/views/shopcategory/view.php

@ -0,0 +1,40 @@
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model antgoods\goods\models\ars\ShopCategory */
$this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => '前端商品分类', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<div class="shop-category-view">
<p>
<?= Html::a('返回列表', ['index'], ['class' => 'btn btn-success']) ?>
</p>
<?= DetailView::widget([
'model' => $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',
],
]) ?>
</div>
Loading…
Cancel
Save