123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/3/4
- * Time: 上午9:29
- */
- namespace common\models;
- //
- //use yii\db\ActiveRecord;
- //use yii\behaviors\TimestampBehavior;
- class CategoryNews extends Common
- {
- // public $dels = 1; //废弃
- // public $item = [1=>'不推荐',2=>'推荐'];
- // public function behaviors()
- // {
- // return [
- // [
- // 'class' => TimestampBehavior::className(),
- // 'attributes' => [
- // # 创建之前
- // ActiveRecord::EVENT_BEFORE_INSERT => ['create_at', 'update_at'],
- // # 修改之前
- // ActiveRecord::EVENT_BEFORE_UPDATE => ['update_at']
- // ],
- // #设置默认值
- // 'value' => $_SERVER['REQUEST_TIME']
- // ]
- // ];
- // }
- 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();
- }
- }
|