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.

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