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.

299 lines
10 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' => 'update',
  134. 'icon' => 'pencil',
  135. 'title' => '修改'
  136. ],
  137. [
  138. 'name' => 'delivery',
  139. 'icon' => 'box',
  140. 'title' => '发货',
  141. 'hide' => [
  142. 'attributes' => [
  143. 'status',
  144. 'status',
  145. 'status',
  146. 'status',
  147. 'status',
  148. 'status',
  149. 'status',
  150. ],
  151. 'values' => [
  152. Order::STATUS_UNCONFIRMED,
  153. Order::STATUS_NONPAYMENT,
  154. Order::STATUS_CANCEL,
  155. Order::STATUS_PAYMENT_TO_BE_CONFIRMED,
  156. Order::STATUS_APPLY_REFUND,
  157. Order::STATUS_REFUND,
  158. Order::STATUS_SHIPMENT_ALL,
  159. Order::STATUS_FINISH
  160. ],
  161. 'rule' => 'or'
  162. ]
  163. ],
  164. [
  165. 'name' => 'refund',
  166. 'icon' => 'dollar',
  167. 'title' => '退款',
  168. 'hide' => [
  169. 'attributes' => [
  170. 'status',
  171. 'status',
  172. 'status',
  173. 'status',
  174. 'status',
  175. 'status',
  176. 'status',
  177. ],
  178. 'values' => [
  179. Order::STATUS_UNCONFIRMED,
  180. Order::STATUS_NONPAYMENT,
  181. Order::STATUS_CANCEL,
  182. Order::STATUS_PAYMENT_TO_BE_CONFIRMED,
  183. Order::STATUS_REFUND,
  184. Order::STATUS_SHIPMENT_ALL,
  185. Order::STATUS_FINISH
  186. ],
  187. 'rule' => 'or'
  188. ]
  189. ],
  190. ],
  191. ],
  192. ];
  193. }
  194. /**
  195. * @param $params
  196. * @return ActiveDataProvider
  197. * 不分页的所有数据
  198. */
  199. public function allData($params)
  200. {
  201. $query = Order::find();
  202. $dataProvider = new ActiveDataProvider([
  203. 'query' => $query,
  204. 'pagination' => false,
  205. 'sort' => false
  206. ]);
  207. $this->load($params);
  208. return $this->filter($query, $dataProvider);
  209. }
  210. /**
  211. * Creates data provider instance with search query applied
  212. *
  213. * @param array $params
  214. *
  215. * @return ActiveDataProvider
  216. */
  217. public function search($params)
  218. {
  219. $query = Order::find();
  220. // add conditions that should always apply here
  221. $dataProvider = new ActiveDataProvider([
  222. 'query' => $query,
  223. 'pagination' => [
  224. 'pageSizeLimit' => [1, 200]
  225. ],
  226. 'sort' => [
  227. 'defaultOrder' => [
  228. 'id' => SORT_DESC,
  229. ]
  230. ],
  231. ]);
  232. $this->load($params);
  233. return $this->filter($query, $dataProvider);
  234. }
  235. /**
  236. * @param $query
  237. * @param $dataProvider
  238. * @return ActiveDataProvider
  239. * 条件筛选
  240. */
  241. private function filter($query, $dataProvider)
  242. {
  243. if (!$this->validate()) {
  244. // uncomment the following line if you do not want to return any records when validation fails
  245. // $query->where('0=1');
  246. return $dataProvider;
  247. }
  248. // grid filtering conditions
  249. $query->andFilterWhere([
  250. 'id' => $this->id,
  251. 'user_id' => $this->user_id,
  252. 'status' => $this->status,
  253. 'type' => $this->type,
  254. 'goods_count' => $this->goods_count,
  255. 'goods_amount' => $this->goods_amount,
  256. 'shipping_amount' => $this->shipping_amount,
  257. 'shipping_type' => $this->shipping_type,
  258. 'taking_site' => $this->taking_site,
  259. 'pay_type' => $this->pay_type,
  260. 'pay_at' => $this->pay_at,
  261. 'payment_amount' => $this->payment_amount,
  262. 'receivables' => $this->receivables,
  263. 'discount_amount' => $this->discount_amount,
  264. 'updated_at' => $this->updated_at,
  265. 'created_at' => $this->created_at,
  266. ]);
  267. $query->andFilterWhere(['like', 'order_sn', $this->order_sn])
  268. ->andFilterWhere(['like', 'invoice_id', $this->invoice_id])
  269. ->andFilterWhere(['like', 'consignee', $this->consignee])
  270. ->andFilterWhere(['like', 'phone', $this->phone])
  271. ->andFilterWhere(['like', 'province', $this->province])
  272. ->andFilterWhere(['like', 'city', $this->city])
  273. ->andFilterWhere(['like', 'area', $this->area])
  274. ->andFilterWhere(['like', 'payment_sn', $this->payment_sn])
  275. ->andFilterWhere(['like', 'remarks', $this->remarks])
  276. ->andFilterWhere(['like', 'discount_description', $this->discount_description]);
  277. if ($this->created_at_range) {
  278. $arr = explode(' ~ ', $this->created_at_range);
  279. $start = strtotime($arr[0]);
  280. $end = strtotime($arr[1]) + 3600 * 24;
  281. $query->andFilterWhere(['between', 'created_at', $start, $end]);
  282. }
  283. return $dataProvider;
  284. }
  285. }