123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace common\models;
- class PushRecommend extends Common
- {
- public function rules()
- {
- return [
- ['title','required','message'=>'不能为空','on'=>'add'],
- ['title', 'unique', 'targetClass' => 'common\models\PushRecommend','on'=>'add','message'=>'栏目名称已经存在'],
- [['title'],'trim'],
- ['title','string','max'=>15],
- [['city','sort'],'number'],
- ['city','default','value'=>0],
- ];
- }
- public function attributeLabels()
- {
- return [
- 'title'=>'栏目名称',
- ];
- }
- 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()
- {
- $query = self::find();
- $query->select(['pfg_push_recommend.del as isdel','pfg_push_recommend.id as cat_id','pfg_category_city.city_name','pfg_category_city.id','pfg_push_recommend.title','pfg_push_recommend.city','pfg_push_recommend.create_at','pfg_push_recommend.is_show','pfg_push_recommend.sort']);
- $query->leftJoin('pfg_category_city','pfg_push_recommend.city=pfg_category_city.id');
- $query->andWhere(['pfg_push_recommend.del'=>1]);
- $query->andWhere(['pfg_push_recommend.is_show'=>1]);
- $query->andWhere(['pfg_category_city.state'=>1]);
- if(!empty($input['page']))
- {
- $query->limit = $input['limit'];
- $query->offset = ($input['page']-1 )* $input['limit'];
- }
- return $query->orderBy(['pfg_push_recommend.sort'=>SORT_ASC])->asArray()->all();
- }
- public function adminList()
- {
- $query = self::find();
- $query->select(['pfg_push_recommend.del as isdel','pfg_push_recommend.id as cat_id','pfg_category_city.city_name','pfg_category_city.id','pfg_push_recommend.title','pfg_push_recommend.city','pfg_push_recommend.create_at','pfg_push_recommend.is_show','pfg_push_recommend.sort']);
- $query->leftJoin('pfg_category_city','pfg_push_recommend.city=pfg_category_city.id');
- $query->andWhere(['pfg_push_recommend.del'=>1]);
- $query->andWhere(['pfg_category_city.state'=>1]);
- if(!empty($input['page']))
- {
- $query->limit = $input['limit'];
- $query->offset = ($input['page']-1 )* $input['limit'];
- }
- return $query->orderBy(['pfg_push_recommend.sort'=>SORT_ASC])->asArray()->all();
- }
- /**前台栏目显示*/
- public function getCatList($input)
- {
- $query = self::find();
- $query->select(['id','title','city','create_at','is_show','sort']);
- $query->andWhere(['del'=>$this->setDel]);
- $query->andWhere(['is_show'=>1]);
- $query->andFilterWhere(['city'=>0]);
- if(!empty($input['page']))
- {
- $query->limit = $input['limit'];
- $query->offset = ($input['page']-1 )* $input['limit'];
- }
- return $query->orderBy(['sort'=>SORT_ASC])->asArray()->all();
- }
- public function getCatOne($input)
- {
- $query = self::find();
- $query->select(['id','title','city','create_at','is_show','sort']);
- $query->andWhere(['del'=>$this->setDel]);
- $query->andWhere(['is_show'=>1]);
- $query->andFilterWhere(['city'=>$input]);
- $query->limit =1;
- return $query->orderBy(['sort'=>SORT_DESC])->asArray()->all();
- }
- public function Total()
- {
- $query = self::find();
- $query->andWhere(['del'=>$this->setDel]);
- // $query->leftJoin('pfg_push_recommend','pfg_push_news.nid=pfg_news.id');
- return $query->count();
- }
- }
|