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.
187 lines
5.1 KiB
187 lines
5.1 KiB
<?php
|
|
|
|
namespace backend\modules\shop\models\searchs;
|
|
|
|
use yii\base\Model;
|
|
use yii\data\ActiveDataProvider;
|
|
use yii\helpers\ArrayHelper;
|
|
use backend\modules\shop\models\ars\Delivery;
|
|
|
|
/**
|
|
* DeliverySearch represents the model behind the search form of `backend\modules\shop\models\ars\Delivery`.
|
|
*/
|
|
class DeliverySearch extends Delivery
|
|
{
|
|
/**
|
|
* @return array
|
|
* 增加创建时间查询字段
|
|
*/
|
|
public function attributes()
|
|
{
|
|
return ArrayHelper::merge(['created_at_range'], parent::attributes());
|
|
}
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['id', 'order_id', 'type', 'status', 'updated_at', 'created_at'], 'integer'],
|
|
[['shipping_name', 'shipping_id', 'goods', 'decription'], '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'
|
|
],
|
|
[
|
|
'attribute' => 'id',
|
|
'width' => '7%',
|
|
],
|
|
[
|
|
'attribute' => 'order_id',
|
|
'width' => '7%',
|
|
],
|
|
[
|
|
'attribute' => 'shipping_name',
|
|
'width' => '10%',
|
|
],
|
|
[
|
|
'attribute' => 'invoice_sn',
|
|
'width' => '10%',
|
|
],
|
|
[
|
|
'attribute' => 'type',
|
|
'width' => '8%',
|
|
'value' => function ($model) {
|
|
return Delivery::dropDown('type', $model->type);
|
|
}
|
|
],
|
|
[
|
|
'attribute' => 'status',
|
|
'width' => '7%',
|
|
],
|
|
[
|
|
'attribute' => 'decription',
|
|
'width' => '15%',
|
|
],
|
|
[
|
|
'attribute' => 'created_at',
|
|
'width' => '10%',
|
|
'value' => function ($model) {
|
|
return date('Y-m-d H:i:s', $model->created_at);
|
|
}
|
|
],
|
|
[
|
|
'class' => 'iron\grid\ActionColumn',
|
|
'align' => 'center',
|
|
'config' => [
|
|
[
|
|
'name' => 'view',
|
|
'icon' => 'list',
|
|
'title' => '详情',
|
|
],
|
|
],
|
|
],
|
|
|
|
];
|
|
}
|
|
/**
|
|
* @param $params
|
|
* @return ActiveDataProvider
|
|
* 不分页的所有数据
|
|
*/
|
|
public function allData($params)
|
|
{
|
|
$query = Delivery::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 = Delivery::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,
|
|
'order_id' => $this->order_id,
|
|
'type' => $this->type,
|
|
'status' => $this->status,
|
|
'updated_at' => $this->updated_at,
|
|
'created_at' => $this->created_at,
|
|
]);
|
|
|
|
$query->andFilterWhere(['like', 'shipping_name', $this->shipping_name])
|
|
->andFilterWhere(['like', 'shipping_id', $this->shipping_id])
|
|
->andFilterWhere(['like', 'goods', $this->goods])
|
|
->andFilterWhere(['like', 'decription', $this->decription]);
|
|
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;
|
|
}
|
|
}
|