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.

169 lines
5.0 KiB

  1. <?php
  2. namespace backend\modules\shop\models\searchs;
  3. use yii\base\Model;
  4. use yii\data\ActiveDataProvider;
  5. use yii\helpers\ArrayHelper;
  6. use backend\modules\shop\models\ars\AfterSale;
  7. /**
  8. * AfterSaleSearch represents the model behind the search form of `backend\modules\shop\models\ars\AfterSale`.
  9. */
  10. class AfterSaleSearch extends AfterSale
  11. {
  12. /**
  13. * @return array
  14. * 增加创建时间查询字段
  15. */
  16. public function attributes()
  17. {
  18. return ArrayHelper::merge(['created_at_range'], parent::attributes());
  19. }
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function rules()
  24. {
  25. return [
  26. [['id', 'user_id', 'order_goods_id', 'amount', 'count', 'apply_at', 'dealt_at', 'finish_at', 'operator_id', 'refund_type', 'status', 'reason', 'refund_mode'], 'integer'],
  27. [['wx_refund_id', 'after_sale_sn', 'description', 'image', 'remarks', 'take_shipping_sn'], 'safe'],
  28. ['created_at_range','safe'],
  29. ];
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function scenarios()
  35. {
  36. // bypass scenarios() implementation in the parent class
  37. return Model::scenarios();
  38. }
  39. /**
  40. * @return array
  41. * 列格式
  42. */
  43. public function columns()
  44. {
  45. return [
  46. [
  47. 'class' => 'blobt\grid\CheckboxColumn',
  48. 'width' => '2%',
  49. 'align' => 'center'
  50. ],
  51. 'id',
  52. 'wx_refund_id',
  53. 'after_sale_sn',
  54. 'user_id',
  55. 'order_goods_id',
  56. //'amount',
  57. //'count',
  58. //'apply_at',
  59. //'dealt_at',
  60. //'finish_at',
  61. //'operator_id',
  62. //'refund_type',
  63. //'description',
  64. //'image',
  65. //'status',
  66. //'reason',
  67. //'remarks',
  68. //'take_shipping_sn',
  69. //'refund_mode',
  70. [
  71. 'class' => 'iron\grid\ActionColumn',
  72. 'align' => 'center',
  73. ],
  74. ];
  75. }
  76. /**
  77. * @param $params
  78. * @return ActiveDataProvider
  79. * 不分页的所有数据
  80. */
  81. public function allData($params)
  82. {
  83. $query = AfterSale::find();
  84. $dataProvider = new ActiveDataProvider([
  85. 'query' => $query,
  86. 'pagination' => false,
  87. 'sort' => false
  88. ]);
  89. $this->load($params);
  90. return $this->filter($query, $dataProvider);
  91. }
  92. /**
  93. * Creates data provider instance with search query applied
  94. *
  95. * @param array $params
  96. *
  97. * @return ActiveDataProvider
  98. */
  99. public function search($params)
  100. {
  101. $query = AfterSale::find();
  102. // add conditions that should always apply here
  103. $dataProvider = new ActiveDataProvider([
  104. 'query' => $query,
  105. 'pagination' => [
  106. 'pageSizeLimit' => [1, 200]
  107. ],
  108. 'sort' => [
  109. 'defaultOrder' => [
  110. 'id' => SORT_DESC,
  111. ]
  112. ],
  113. ]);
  114. $this->load($params);
  115. return $this->filter($query, $dataProvider);
  116. }
  117. /**
  118. * @param $query
  119. * @param $dataProvider
  120. * @return ActiveDataProvider
  121. * 条件筛选
  122. */
  123. private function filter($query, $dataProvider){
  124. if (!$this->validate()) {
  125. // uncomment the following line if you do not want to return any records when validation fails
  126. // $query->where('0=1');
  127. return $dataProvider;
  128. }
  129. // grid filtering conditions
  130. $query->andFilterWhere([
  131. 'id' => $this->id,
  132. 'user_id' => $this->user_id,
  133. 'order_goods_id' => $this->order_goods_id,
  134. 'amount' => $this->amount,
  135. 'count' => $this->count,
  136. 'apply_at' => $this->apply_at,
  137. 'dealt_at' => $this->dealt_at,
  138. 'finish_at' => $this->finish_at,
  139. 'operator_id' => $this->operator_id,
  140. 'refund_type' => $this->refund_type,
  141. 'status' => $this->status,
  142. 'reason' => $this->reason,
  143. 'refund_mode' => $this->refund_mode,
  144. ]);
  145. $query->andFilterWhere(['like', 'wx_refund_id', $this->wx_refund_id])
  146. ->andFilterWhere(['like', 'after_sale_sn', $this->after_sale_sn])
  147. ->andFilterWhere(['like', 'description', $this->description])
  148. ->andFilterWhere(['like', 'image', $this->image])
  149. ->andFilterWhere(['like', 'remarks', $this->remarks])
  150. ->andFilterWhere(['like', 'take_shipping_sn', $this->take_shipping_sn]);
  151. if ($this->created_at_range) {
  152. $arr = explode(' ~ ', $this->created_at_range);
  153. $start = strtotime($arr[0]);
  154. $end = strtotime($arr[1]) + 3600 * 24;
  155. $query->andFilterWhere(['between', 'created_at', $start, $end]);
  156. }
  157. return $dataProvider;
  158. }
  159. }