123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- namespace common\models;
- class CategoryNews extends Common
- {
- public function FindById($id)
- {
- return self::findOne($id);
- }
- public function rules()
- {
- return [
- ['news_name','required','message'=>'不能为空'],
- ['sort','number'],
- ['state','default','value'=>1],
- ['recommend','in','range'=>[1,2]],
- ];
- }
- public function getList($input,$select = null,$state = null)
- {
- $query = $this->FindQuery();
- $query->select($select);
- $query = $this->WhereFocus($query);
- if (!empty($state) && $state == 1) {
- $query->andWhere(['state'=>1]);
- }
- if (!empty($input['page']))
- {
- $query->limit = $input['limit'];
- $query->offset = ($input['page'] - 1) * $input['limit'];
- }
- return $query->orderBy(['state'=>SORT_ASC,'sort'=>SORT_DESC,'create_at'=>SORT_DESC])->asArray()->all();
- }
- public function WhereFocus($query)
- {
- $query->andFilterWhere(['like','news_name',$this->news_name]);
- $query->andWhere(['del'=>$this->setDel]);
- return $query;
- }
- public function Total()
- {
- $query = $this->FindQuery();
- $query = $this->WhereFocus($query);
- return $query->count();
- }
- private function FindQuery()
- {
- return self::find();
- }
- }
|