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.

searchInvoice.php 2.4 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Steven
  5. * Date: 2017/11/23
  6. * Time: 13:40
  7. */
  8. namespace backend\modules\hotel\models\search;
  9. use yii\data\ActiveDataProvider;
  10. use backend\modules\hotel\models\OrderInvoiceInfo;
  11. class searchInvoice extends OrderInvoiceInfo
  12. {
  13. public $date_from;
  14. public $date_to;
  15. public $search_key;
  16. /**
  17. * @inheritdoc
  18. */
  19. public function rules()
  20. {
  21. return [
  22. [['InvoiceType', 'PostType', 'OrderID', 'Status', 'CreateTime', 'date_from', 'date_to', 'search_key','ChannelId'], 'safe'],
  23. ];
  24. }
  25. public function attributeLabels()
  26. {
  27. return array_merge(
  28. parent::attributeLabels(), [
  29. 'date_from' => '起始日期',
  30. 'date_to' => '结束日期',
  31. ]);
  32. }
  33. public function search($queryParams)
  34. {
  35. $query = self::find()->select(['a.*', 'b.supplier_name'])->joinWith('baseSupplier b')->from('order_invoice_info a');
  36. $query->andFilterWhere(['<>', 'a.Status', '1']);
  37. $dataProvider = new ActiveDataProvider([
  38. 'query' => $query,
  39. 'sort' => false,
  40. 'pagination' => [
  41. 'pageSize' => 20,
  42. ]
  43. ]);
  44. $this->load($queryParams);
  45. if (!empty($this->InvoiceType)) {
  46. $query->andFilterWhere(['InvoiceType' => $this->InvoiceType]);
  47. }
  48. if (!empty($this->date_from) && !empty($this->date_to)) {
  49. $query->andFilterWhere(['between', 'a.CreateTime', $this->date_from, $this->date_to]);
  50. }
  51. if (!empty($this->PostType)) {
  52. $query->andFilterWhere(['PostType' => $this->PostType]);
  53. }
  54. if (!empty($this->Status)) {
  55. $query->andFilterWhere(['a.Status' => $this->Status]);
  56. }
  57. if (!empty($this->ChannelId)) {
  58. $query->andFilterWhere(['a.ChannelId' => $this->ChannelId]);
  59. }
  60. if (!empty(trim($this->search_key))) {
  61. $query->andFilterWhere(['or',
  62. ['like', 'a.OrderID', trim($this->search_key)],
  63. ['like', 'a.ReceiverName', trim($this->search_key)],
  64. ['like', 'a.ReceiverMobile', trim($this->search_key)],
  65. ['like', 'a.InvoiceTitle', trim($this->search_key)]]);
  66. }
  67. $query -> orderBy(['a.Status' => SORT_ASC,'a.UpdateTime' => SORT_DESC]);
  68. return $dataProvider;
  69. }
  70. }