UserSearch.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace common\modules\user\backend\models;
  3. use common\modules\user\models\User;
  4. use Yii;
  5. use yii\base\Model;
  6. use yii\data\ActiveDataProvider;
  7. use common\models\Goods;
  8. /**
  9. * GoodsSearch represents the model behind the search form about `common\models\Goods`.
  10. */
  11. class UserSearch extends User
  12. {
  13. /**
  14. * @inheritdoc
  15. */
  16. public function rules()
  17. {
  18. return [
  19. [['id', 'level_id'], 'integer'],
  20. [['nickname', 'tel', 'openid', 'access_token'], 'safe'],
  21. ];
  22. }
  23. /**
  24. * @inheritdoc
  25. */
  26. public function scenarios()
  27. {
  28. // bypass scenarios() implementation in the parent class
  29. return Model::scenarios();
  30. }
  31. /**
  32. * Creates data provider instance with search query applied
  33. *
  34. * @param array $params
  35. *
  36. * @return ActiveDataProvider
  37. */
  38. public function search($params)
  39. {
  40. $query = User::find();
  41. $dataProvider = new ActiveDataProvider([
  42. 'query' => $query,
  43. 'sort' => [
  44. 'defaultOrder' => [
  45. 'id' => SORT_DESC
  46. ]
  47. ]
  48. ]);
  49. $this->load($params);
  50. if (!$this->validate()) {
  51. // uncomment the following line if you do not want to return any records when validation fails
  52. // $query->where('0=1');
  53. return $dataProvider;
  54. }
  55. $query->andFilterWhere([
  56. 'id' => $this->id,
  57. 'level_id' => $this->level_id,
  58. ]);
  59. $query->andFilterWhere(['like', 'nickname', $this->nickname])
  60. ->andFilterWhere(['like', 'tel', $this->tel])
  61. ->andFilterWhere(['like', 'access_token', $this->access_token])
  62. ->andFilterWhere(['like', 'openid', $this->openid]);
  63. return $dataProvider;
  64. }
  65. }