Frontend.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace common\models;
  3. class Frontend extends Common
  4. {
  5. public $title;
  6. public function rules()
  7. {
  8. return [
  9. ['name','required','message'=>'不能为空'],
  10. //['name', 'unique', 'targetClass' => 'common\models\Frontend','on'=>['add']],
  11. [['pid','sort'],'number'],
  12. ['sort','default','value'=>0],
  13. ['url','string','min'=>1],
  14. ['url','default','value'=>'javascript:;'],
  15. ['icon','string','max'=>50],
  16. ['width','string','max'=>50],
  17. ['function','string','max'=>100],
  18. ['status','in', 'range' => [1, 2, 3]],
  19. ['del','default','value'=>1],
  20. ['function','default','value'=>''],
  21. ['pid','default','value'=>0],
  22. ];
  23. }
  24. public function Authenticator($input)
  25. {
  26. $this->load($input,'');
  27. if(!$this->validate()) return $this->errors;
  28. return $this;
  29. }
  30. public function FindById($id)
  31. {
  32. return self::findOne($id);
  33. }
  34. /*更改排序*/
  35. public function GetFindById($id)
  36. {
  37. return self::findOne($id);
  38. }
  39. public function OneFind()
  40. {
  41. $query = self::find();
  42. $query = $this->ManyWhere($query);
  43. return $query->one();
  44. }
  45. public function MultipleConditionQuery($select = null)
  46. {
  47. $query = self::find()->select($select);
  48. $query = $this->ManyWhere($query);
  49. return $query->orderBy(['sort'=>SORT_DESC])->asArray()->all();
  50. }
  51. private function ManyWhere($query)
  52. {
  53. $query->andFilterWhere(['pid'=>$this->pid]);
  54. $query->andFilterWhere(['id'=>$this->id]);
  55. $query->andFilterWhere(['status'=>$this->status]);
  56. // $query->andFilterWhere(['del'=>$this->setDel]);
  57. return $query;
  58. }
  59. public function getList($data,$select = [])
  60. {
  61. $query = self::find();
  62. $query->andFilterWhere(['del'=>$this->setDel]);
  63. $query->select($select);
  64. $query->orderBy(['sort'=>SORT_DESC]);
  65. if(!empty($data['page']))
  66. {
  67. $query->offset = ($data['page'] - 1) * $data['limit'];
  68. $query->limit = $data['limit'];
  69. }
  70. return $query->asArray()->all();
  71. }
  72. public function getListTotal()
  73. {
  74. $query = self::find();
  75. $query->andFilterWhere(['del'=>$this->setDel]);
  76. return $query->count();
  77. }
  78. public function PidList($id = 0)
  79. {
  80. $query = self::find();
  81. $query->select(['name as title','id as value','pid','id']);
  82. $query->andWhere(['status'=>$this->setDel]);
  83. $query->andFilterWhere(['pid'=>$id]);
  84. return $query->orderBy(['create_at'=>SORT_DESC])->asArray()->all();
  85. }
  86. /*20181108 eit*/
  87. public function getNavList($select=null,$type)
  88. {
  89. $query = self::find();
  90. $query->select($select);
  91. $query->andWhere(['status'=>$this->setDel]);
  92. $query->andWhere(['del'=>$this->setDel]);
  93. $query->andWhere(['type'=>$type]);
  94. // $query->andWhere(['position'=>$position]);
  95. $query->andWhere(['<>','pid',0]);
  96. return $query->orderBy(['sort'=>SORT_DESC])->asArray()->all();
  97. }
  98. public function SonList($limit,$select = [])
  99. {
  100. $query = self::find();
  101. $query->andWhere(['del'=>1]);
  102. $query->andWhere(['status'=>1]);
  103. $query->andWhere(['pid'=>$this->pid]);
  104. $query->select($select);
  105. if(empty($limit))
  106. {
  107. $query->limit = 10;
  108. }else{
  109. $query->limit = $limit;
  110. }
  111. return $query->orderBy(['sort'=>SORT_DESC])->asArray()->all();
  112. }
  113. }