123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/5/21
- * Time: 下午5:18
- */
- namespace common\models;
- class PushNews extends Common
- {
- public function rules()
- {
- return [
- ['nid', 'unique', 'targetClass' => 'common\models\PushNews','on'=>['add'],'message'=>'该资讯已存在','filter'=>function($query){
- $query->andWhere(['del'=>$this->setDel]);
- return $query->andWhere(['type'=>$this->type]);
- }],
- // ['']
- ['nid','required','message'=>'请选择资讯'],
- ['type','number'],
- ['cid','number'],
- ['sort','number','message'=>'排序只能是数字'],
- ['sort','number','max'=>10000],
- ];
- }
- public function attributeLabels()
- {
- return [
- 'nid'=>'资讯名称',
- '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_push_news.cid','pfg_push_news.id','pfg_news.subject','pfg_push_news.create_at','pfg_push_news.is_show','pfg_push_news.sort','pfg_push_news.img']);
- $query->andWhere(['pfg_push_news.del'=>$this->setDel]);
- $query->andWhere(['pfg_push_news.type'=>$this->type]);
- $query->andFilterWhere(['pfg_push_news.cid'=>$this->cid]);
- $query->leftJoin('pfg_news','pfg_push_news.nid=pfg_news.id');
- if(!empty($input['page']))
- {
- $query->limit = $input['limit'];
- $query->offset = ($input['page']-1 )* $input['limit'];
- }
- return $query->orderBy(['pfg_push_news.sort'=>SORT_DESC,'pfg_push_news.id'=>SORT_DESC])->asArray()->all();
- }
- public function Total()
- {
- $query = self::find();
- $query->andWhere(['pfg_push_news.del'=>$this->setDel]);
- $query->andWhere(['pfg_push_news.type'=>$this->type]);
- $query->andFilterWhere(['pfg_push_news.cid'=>$this->cid]);
- $query->leftJoin('pfg_news','pfg_push_news.nid=pfg_news.id');
- return $query->count();
- }
- public function Homegetlist($limit)
- {
- $query = self::find();
- $query->select(['pfg_news.id','pfg_news.subject','pfg_push_news.img','pfg_news.abstract','pfg_news.short_subject','pfg_news.thumb']);
- $query->andWhere(['pfg_push_news.del'=>$this->setDel]);
- $query->andWhere(['pfg_push_news.is_show'=>1]);
- $query->andWhere(['pfg_push_news.type'=>$this->type]);
- $query->leftJoin('pfg_news','pfg_push_news.nid=pfg_news.id');
- $query->limit = $limit;
- return $query->orderBy(['pfg_push_news.sort'=>SORT_DESC,'pfg_push_news.id'=>SORT_DESC])->asArray()->all();
- }
- public function getPushNewscolumn()
- {
- return $this->hasMany(PushNewscolumn::className(),['cid'=>'id']);
- }
- }
|