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.
 
 
 

188 lines
5.6 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\AfterSale;
use backend\modules\shop\models\ars\OrderGoods;
/**
* AfterSaleSearch represents the model behind the search form of `backend\modules\shop\models\ars\AfterSale`.
*/
class AfterSaleSearch extends AfterSale
{
/**
* @return array
* 增加创建时间查询字段
*/
public function attributes()
{
return ArrayHelper::merge(['created_at_range'], parent::attributes());
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id', 'user_id', 'order_goods_id', 'amount', 'count', 'apply_at', 'dealt_at', 'finish_at', 'operator_id', 'refund_type', 'status', 'reason', 'refund_mode'], 'integer'],
[['wx_refund_id', 'after_sale_sn', 'description', 'image', 'remarks', 'take_shipping_sn'], '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',
'after_sale_sn',
[
'attribute' => 'order_goods_id',
'value' => function ($model) {
return $model->goods->goods_name;
}
],
[
'attribute' => 'order_pay_amount',
'value' => function ($model) {
return sprintf("%1\$.2f", $model->goods->order->payment_amount);
},
'label' => '订单支付金额'
],
[
'attribute' => 'amount',
'value' => function ($model) {
return sprintf("%1\$.2f", $model->amount);
}
],
[
'attribute' => 'status',
'value' => function ($model) {
return AfterSale::$status[$model->status];
}
],
'apply_at:datetime',
'dealt_at:datetime',
'finish_at:datetime',
[
'class' => 'iron\grid\ActionColumn',
'align' => 'center',
'config' => [
[
'name' => 'view',
'icon' => 'list',
'title' => '详情',
]
]
],
];
}
/**
* @param $params
* @return ActiveDataProvider
* 不分页的所有数据
*/
public function allData($params)
{
$query = AfterSale::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 = AfterSale::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,
'user_id' => $this->user_id,
'order_goods_id' => $this->order_goods_id,
'amount' => $this->amount,
'count' => $this->count,
'apply_at' => $this->apply_at,
'dealt_at' => $this->dealt_at,
'finish_at' => $this->finish_at,
'operator_id' => $this->operator_id,
'refund_type' => $this->refund_type,
'status' => $this->status,
'reason' => $this->reason,
'refund_mode' => $this->refund_mode,
]);
$query->andFilterWhere(['like', 'wx_refund_id', $this->wx_refund_id])
->andFilterWhere(['like', 'after_sale_sn', $this->after_sale_sn])
->andFilterWhere(['like', 'description', $this->description])
->andFilterWhere(['like', 'image', $this->image])
->andFilterWhere(['like', 'remarks', $this->remarks])
->andFilterWhere(['like', 'take_shipping_sn', $this->take_shipping_sn]);
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;
}
}