1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/5/21
- * Time: 下午5:18
- */
- namespace common\models;
- class PushmNewscolumn extends Common
- {
- public function rules()
- {
- return [
- ['cid', 'unique', 'targetClass' => 'common\models\PushmNewscolumn','on'=>['add'],'message'=>'该栏目已存在','filter'=>function($query){
- return $query->andWhere(['del'=>$this->setDel]);
- }],
- ['cid','required','message'=>'请选择栏目'],
- ['sort','number','message'=>'排序只能是数字'],
- ['sort','number','max'=>10000],
- ['short','string','max'=>40],
- ];
- }
- public function attributeLabels()
- {
- return [
- 'cid'=>'栏目名称',
- 'sort'=>'排序',
- ];
- }
- public function Authenticator($input)
- {
- $this->load($input,'');
- if(!$this->validate()) return $this->errors;
- return $this;
- }
- public function FindById($id)
- {
- return self::findOne($id);
- }
- public function getList($input)
- {
- $query = self::find();
- $query->select(['pfg_category_news.news_name','pfg_pushm_newscolumn.id','pfg_pushm_newscolumn.create_at','pfg_pushm_newscolumn.is_show','pfg_pushm_newscolumn.sort']);
- $query->andWhere(['pfg_pushm_newscolumn.del'=>$this->setDel]);
- $query->leftJoin('pfg_category_news','pfg_pushm_newscolumn.cid=pfg_category_news.id');
- if(!empty($input['page']))
- {
- $query->limit = $input['limit'];
- $query->offset = ($input['page']-1 )* $input['limit'];
- }
- return $query->orderBy(['pfg_pushm_newscolumn.create_at'=>SORT_DESC])->asArray()->all();
- }
- public function WhereColumn($query)
- {
- }
- public function Total()
- {
- $query = self::find();
- $query->andWhere(['pfg_pushm_newscolumn.del'=>$this->setDel]);
- $query->leftJoin('pfg_category_news','pfg_pushm_newscolumn.cid=pfg_category_news.id');
- return $query->count();
- }
- public function getPushNews()
- {
- return $this->hasMany(PushNews::className(),['id'=>'cid']);
- }
- public function Homegetlist($limit)
- {
- $query = self::find();
- $query->select(['pfg_category_news.news_name','pfg_category_news.id']);
- $query->andWhere(['pfg_pushm_newscolumn.del'=>$this->setDel]);
- $query->andWhere(['pfg_pushm_newscolumn.is_show'=>1]);
- $query->leftJoin('pfg_category_news','pfg_pushm_newscolumn.cid=pfg_category_news.id');
- $query->limit = $limit;
- return $query->orderBy(['pfg_pushm_newscolumn.sort'=>SORT_DESC])->asArray()->all();
- }
- }
|