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.

268 lines
8.9 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\Order;
  7. use Yii;
  8. use yii\helpers\Html;
  9. /**
  10. * OrderSearch represents the model behind the search form of ` backend\modules\shop\models\ars\Order`.
  11. */
  12. class OrderSearch extends Order
  13. {
  14. /**
  15. * @return array
  16. * 增加创建时间查询字段
  17. */
  18. public function attributes()
  19. {
  20. return ArrayHelper::merge(['created_at_range'], parent::attributes());
  21. }
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public function rules()
  26. {
  27. return [
  28. [['id', 'user_id', 'status', 'type', 'goods_count', 'goods_amount', 'shipping_amount', 'shipping_type', 'taking_site', 'pay_type', 'pay_at', 'payment_amount', 'receivables', 'discount_amount', 'updated_at', 'created_at'], 'integer'],
  29. [['order_sn', 'invoice_id', 'consignee', 'phone', 'province', 'city', 'area', 'payment_sn', 'remarks', 'discount_description'], 'safe'],
  30. ['created_at_range','safe'],
  31. ];
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function scenarios()
  37. {
  38. // bypass scenarios() implementation in the parent class
  39. return Model::scenarios();
  40. }
  41. /**
  42. * @return array
  43. * 列格式
  44. */
  45. public function columns()
  46. {
  47. return [
  48. [
  49. 'class' => 'blobt\grid\CheckboxColumn',
  50. 'width' => '2%',
  51. 'align' => 'center'
  52. ],
  53. [
  54. 'attribute' => 'id',
  55. 'width' => '5%',
  56. ],
  57. [
  58. 'attribute' => 'user_id',
  59. 'width' => '5%',
  60. // 'value' => function ($model) {
  61. // return base64_decode($model->user->nickname);
  62. // }
  63. ],
  64. [
  65. 'attribute' => 'order_sn',
  66. 'width' => '8%',
  67. ],
  68. // [
  69. // 'attribute' => 'invoice_id',
  70. // 'width' => '8%',
  71. // ],
  72. [
  73. 'attribute' => 'type',
  74. 'width' => '5%',
  75. 'value' => function ($model) {
  76. return !empty($model->type) ? Order::dropDown('type', $model->type) : '';
  77. }
  78. ],
  79. [
  80. 'label' => '订单信息',
  81. 'format' => 'raw',
  82. 'width' => '7%',
  83. 'value' => function ($model) {
  84. return Yii::$app->controller->renderPartial('order_info', ['model' => $model]);
  85. },
  86. ],
  87. [
  88. 'label' => '物流信息',
  89. 'format' => 'raw',
  90. 'width' => '20%',
  91. 'value' => function ($model) {
  92. return Yii::$app->controller->renderPartial('shipping_info', ['model' => $model]);
  93. },
  94. ],
  95. [
  96. 'label' => '收货信息',
  97. 'format' => 'raw',
  98. 'width' => '17%',
  99. 'value' => function ($model) {
  100. return Yii::$app->controller->renderPartial('table_consignee_info', ['model' => $model]);
  101. },
  102. ],
  103. [
  104. 'attribute' => 'status',
  105. 'width' => '5%',
  106. 'value' => function ($model) {
  107. return Order::dropDown('status', $model->status);
  108. }
  109. ],
  110. // [
  111. // 'attribute' => 'updated_at',
  112. // 'width' => '8%',
  113. // 'value' => function ($model) {
  114. // return date('Y-m-d H:i:s', $model->updated_at);
  115. // }
  116. // ],
  117. // [
  118. // 'attribute' => 'created_at',
  119. // 'value' => function ($model) {
  120. // return date('Y-m-d H:i:s', $model->created_at);
  121. // }
  122. // ],
  123. [
  124. 'class' => 'iron\grid\ActionColumn',
  125. 'align' => 'center',
  126. 'config' => [
  127. [
  128. 'name' => 'view',
  129. 'icon' => 'list',
  130. 'title' => '详情',
  131. ],
  132. [
  133. 'name' => 'delivery',
  134. 'icon' => 'box',
  135. 'title' => '发货',
  136. 'hide' => [
  137. 'attributes' => [
  138. 'status',
  139. 'status',
  140. 'status',
  141. 'status',
  142. 'status',
  143. 'status',
  144. 'status',
  145. ],
  146. 'values' => [
  147. Order::STATUS_UNCONFIRMED,
  148. Order::STATUS_NONPAYMENT,
  149. Order::STATUS_CANCEL,
  150. Order::STATUS_PAYMENT_TO_BE_CONFIRMED,
  151. Order::STATUS_APPLY_REFUND,
  152. Order::STATUS_REFUND,
  153. Order::STATUS_SHIPMENT_ALL,
  154. Order::STATUS_FINISH
  155. ],
  156. 'rule' => 'or'
  157. ]
  158. ],
  159. [
  160. 'name' => 'update',
  161. 'icon' => 'pencil',
  162. 'title' => '修改'
  163. ]
  164. ],
  165. ],
  166. ];
  167. }
  168. /**
  169. * @param $params
  170. * @return ActiveDataProvider
  171. * 不分页的所有数据
  172. */
  173. public function allData($params)
  174. {
  175. $query = Order::find();
  176. $dataProvider = new ActiveDataProvider([
  177. 'query' => $query,
  178. 'pagination' => false,
  179. 'sort' => false
  180. ]);
  181. $this->load($params);
  182. return $this->filter($query, $dataProvider);
  183. }
  184. /**
  185. * Creates data provider instance with search query applied
  186. *
  187. * @param array $params
  188. *
  189. * @return ActiveDataProvider
  190. */
  191. public function search($params)
  192. {
  193. $query = Order::find();
  194. // add conditions that should always apply here
  195. $dataProvider = new ActiveDataProvider([
  196. 'query' => $query,
  197. 'pagination' => [
  198. 'pageSizeLimit' => [1, 200]
  199. ],
  200. 'sort' => [
  201. 'defaultOrder' => [
  202. 'id' => SORT_DESC,
  203. ]
  204. ],
  205. ]);
  206. $this->load($params);
  207. return $this->filter($query, $dataProvider);
  208. }
  209. /**
  210. * @param $query
  211. * @param $dataProvider
  212. * @return ActiveDataProvider
  213. * 条件筛选
  214. */
  215. private function filter($query, $dataProvider){
  216. if (!$this->validate()) {
  217. // uncomment the following line if you do not want to return any records when validation fails
  218. // $query->where('0=1');
  219. return $dataProvider;
  220. }
  221. // grid filtering conditions
  222. $query->andFilterWhere([
  223. 'id' => $this->id,
  224. 'user_id' => $this->user_id,
  225. 'status' => $this->status,
  226. 'type' => $this->type,
  227. 'goods_count' => $this->goods_count,
  228. 'goods_amount' => $this->goods_amount,
  229. 'shipping_amount' => $this->shipping_amount,
  230. 'shipping_type' => $this->shipping_type,
  231. 'taking_site' => $this->taking_site,
  232. 'pay_type' => $this->pay_type,
  233. 'pay_at' => $this->pay_at,
  234. 'payment_amount' => $this->payment_amount,
  235. 'receivables' => $this->receivables,
  236. 'discount_amount' => $this->discount_amount,
  237. 'updated_at' => $this->updated_at,
  238. 'created_at' => $this->created_at,
  239. ]);
  240. $query->andFilterWhere(['like', 'order_sn', $this->order_sn])
  241. ->andFilterWhere(['like', 'invoice_id', $this->invoice_id])
  242. ->andFilterWhere(['like', 'consignee', $this->consignee])
  243. ->andFilterWhere(['like', 'phone', $this->phone])
  244. ->andFilterWhere(['like', 'province', $this->province])
  245. ->andFilterWhere(['like', 'city', $this->city])
  246. ->andFilterWhere(['like', 'area', $this->area])
  247. ->andFilterWhere(['like', 'payment_sn', $this->payment_sn])
  248. ->andFilterWhere(['like', 'remarks', $this->remarks])
  249. ->andFilterWhere(['like', 'discount_description', $this->discount_description]);
  250. if ($this->created_at_range) {
  251. $arr = explode(' ~ ', $this->created_at_range);
  252. $start = strtotime($arr[0]);
  253. $end = strtotime($arr[1]) + 3600 * 24;
  254. $query->andFilterWhere(['between', 'created_at', $start, $end]);
  255. }
  256. return $dataProvider;
  257. }
  258. }