You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
162 lines
4.5 KiB
162 lines
4.5 KiB
<?php
|
|
|
|
namespace goods\models\searchs;
|
|
|
|
use yii\base\Model;
|
|
use yii\bootstrap4\Html;
|
|
use yii\data\ActiveDataProvider;
|
|
use yii\helpers\ArrayHelper;
|
|
use goods\models\ars\ShopCategory;
|
|
|
|
/**
|
|
* ShopCategorySearch represents the model behind the search form of `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', 'is_show', 'is_delete', 'created_at', 'updated_at', 'icon'], 'integer'],
|
|
[['name', 'keywords', 'desc', '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',
|
|
['attribute' => 'icon',
|
|
'contentOptions' => [
|
|
'align' => 'center',
|
|
],
|
|
'width'=>'10%',
|
|
'format' => 'raw',
|
|
'value' => function ($model) {
|
|
return $model->iconFile ?
|
|
Html::img(['/'.$model->iconFile->path], ['style' => 'width:80px'])
|
|
: '<div class="table_not_setting">未设置</div>';
|
|
|
|
}
|
|
],
|
|
'sort_order',
|
|
[
|
|
'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()
|
|
->where(['is_delete' => ShopCategory::IS_DELETE_NO]);
|
|
|
|
// 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' => $this->icon,
|
|
'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', '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;
|
|
}
|
|
}
|