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

  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. [
  55. 'attribute' => 'order_goods_id',
  56. 'value' => function ($model) {
  57. return $model->goods->goods_name;
  58. }
  59. ],
  60. [
  61. 'attribute' => 'order_pay_amount',
  62. 'value' => function ($model) {
  63. return sprintf("%1\$.2f", $model->goods->order->payment_amount);
  64. },
  65. 'label' => '订单支付金额'
  66. ],
  67. [
  68. 'attribute' => 'amount',
  69. 'value' => function ($model) {
  70. return sprintf("%1\$.2f", $model->amount);
  71. }
  72. ],
  73. [
  74. 'attribute' => 'status',
  75. 'value' => function ($model) {
  76. return AfterSale::$status[$model->status];
  77. }
  78. ],
  79. 'apply_at:datetime',
  80. 'dealt_at:datetime',
  81. 'finish_at:datetime',
  82. [
  83. 'class' => 'iron\grid\ActionColumn',
  84. 'align' => 'center',
  85. 'config' => [
  86. [
  87. 'name' => 'view',
  88. 'icon' => 'list',
  89. 'title' => '详情',
  90. ]
  91. ]
  92. ],
  93. ];
  94. }
  95. /**
  96. * @param $params
  97. * @return ActiveDataProvider
  98. * 不分页的所有数据
  99. */
  100. public function allData($params)
  101. {
  102. $query = AfterSale::find();
  103. $dataProvider = new ActiveDataProvider([
  104. 'query' => $query,
  105. 'pagination' => false,
  106. 'sort' => false
  107. ]);
  108. $this->load($params);
  109. return $this->filter($query, $dataProvider);
  110. }
  111. /**
  112. * Creates data provider instance with search query applied
  113. *
  114. * @param array $params
  115. *
  116. * @return ActiveDataProvider
  117. */
  118. public function search($params)
  119. {
  120. $query = AfterSale::find();
  121. // add conditions that should always apply here
  122. $dataProvider = new ActiveDataProvider([
  123. 'query' => $query,
  124. 'pagination' => [
  125. 'pageSizeLimit' => [1, 200]
  126. ],
  127. 'sort' => [
  128. 'defaultOrder' => [
  129. 'id' => SORT_DESC,
  130. ]
  131. ],
  132. ]);
  133. $this->load($params);
  134. return $this->filter($query, $dataProvider);
  135. }
  136. /**
  137. * @param $query
  138. * @param $dataProvider
  139. * @return ActiveDataProvider
  140. * 条件筛选
  141. */
  142. private function filter($query, $dataProvider){
  143. if (!$this->validate()) {
  144. // uncomment the following line if you do not want to return any records when validation fails
  145. // $query->where('0=1');
  146. return $dataProvider;
  147. }
  148. // grid filtering conditions
  149. $query->andFilterWhere([
  150. 'id' => $this->id,
  151. 'user_id' => $this->user_id,
  152. 'order_goods_id' => $this->order_goods_id,
  153. 'amount' => $this->amount,
  154. 'count' => $this->count,
  155. 'apply_at' => $this->apply_at,
  156. 'dealt_at' => $this->dealt_at,
  157. 'finish_at' => $this->finish_at,
  158. 'operator_id' => $this->operator_id,
  159. 'refund_type' => $this->refund_type,
  160. 'status' => $this->status,
  161. 'reason' => $this->reason,
  162. 'refund_mode' => $this->refund_mode,
  163. ]);
  164. $query->andFilterWhere(['like', 'wx_refund_id', $this->wx_refund_id])
  165. ->andFilterWhere(['like', 'after_sale_sn', $this->after_sale_sn])
  166. ->andFilterWhere(['like', 'description', $this->description])
  167. ->andFilterWhere(['like', 'image', $this->image])
  168. ->andFilterWhere(['like', 'remarks', $this->remarks])
  169. ->andFilterWhere(['like', 'take_shipping_sn', $this->take_shipping_sn]);
  170. if ($this->created_at_range) {
  171. $arr = explode(' ~ ', $this->created_at_range);
  172. $start = strtotime($arr[0]);
  173. $end = strtotime($arr[1]) + 3600 * 24;
  174. $query->andFilterWhere(['between', 'created_at', $start, $end]);
  175. }
  176. return $dataProvider;
  177. }
  178. }