123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/3/4
- * Time: 上午9:42
- */
- namespace common\models;
- class NewsWeirdo extends Common
- {
- public function rules()
- {
- return [
- ['thumb','required','message'=>'不能为空','on'=>'add'],
- [['subject','abstract','source','content'],'required','message'=>'{attribute}不能为空'],
- [['sort','click','click_true'],'number'],
- ['thumb','string','max'=>50],
- ['author','string','max'=>30],
- // ['open_time','date', 'format'=>'yyyy-mm-dd','message'=>'时间格式为:1990-01-01'],
- ['short_subject','string','max'=>50],
- ];
- }
- public function attributeLabels()
- {
- return [
- 'thumb'=>'缩略图',
- 'subject'=>'资讯标题',
- 'abstract'=>'简单描述',
- 'author'=>'作者',
- 'clicks'=>'点击数',
- 'content'=>'资讯内容',
- 'source'=>'来源',
- 'short_subject'=>'短标题'
- ];
- }
- public function FindById($id)
- {
- return self::findOne($id);
- }
- public function Authenticator($input)
- {
- $this->load($input,'');
- if($this->validate()) return $this;
- return $this->errors;
- }
- public function getList($page)
- {
- $query = self::find();
- $query->andWhere(['del'=>$this->setDel]);
- $query->andFilterWhere(['like','subject',$this->subject]);
- if(!empty($page['page']))
- {
- $query->offset = ($page['page'] - 1) * $page['limit'];
- $query->limit = $page['limit'];
- }
- return $query->orderBy(['create_at'=>SORT_DESC])->asArray()->all();
- }
- public function getListTotal()
- {
- $query = self::find();
- $query->andWhere(['del'=>$this->setDel]);
- $query->andFilterWhere(['like','subject',$this->subject]);
- return $query->count();
- }
- //前台数据展示
- public function HomeList($pages)
- {
- $query = self::find();
- $query->andWhere(['is_show'=>1]);
- $query->andWhere(['del'=>$this->setDel]);
- $query->select(['subject','click','abstract','thumb','short_subject','id']);
- if(is_object($pages))
- {
- $query->offset($pages->offset);
- $query->limit($pages->limit);
- }
- $query->orderBy(['click'=>SORT_DESC,'create_at'=>SORT_DESC]);
- return $query->asArray()->all();
- }
- public function HomeListTotal()
- {
- $query = self::find();
- $query->andWhere(['is_show'=>1]);
- $query->andWhere(['del'=>$this->setDel]);
- return $query->count();
- }
- //移动端
- public function Mhomelist($page)
- {
- $query = self::find();
- $query->andWhere(['is_show'=>1]);
- $query->andWhere(['del'=>$this->setDel]);
- $query->select(['subject','click','abstract','thumb','short_subject','id']);
- if(!empty($page['page']))
- {
- $query->offset = ($page['page'] - 1) * $page['limit'];
- $query->limit = $page['limit'];
- }
- $query->orderBy(['click'=>SORT_DESC,'create_at'=>SORT_DESC]);
- return $query->asArray()->all();
- }
- // public function RandList($limit,$select = null)
- // {
- // $query = self::find();
- // $query->andWhere(['is_show'=>1]);
- // $query->andWhere(['del'=>$this->setDel]);
- //// ['subject','thumb','short_subject','id']
- // $query->select($select);
- // $query->limit = $limit;
- // $query->orderBy('RAND()');
- // return $query->asArray()->all();
- // }
- public function Clickadd($id)
- {
- $query = self::findOne($id);
- $query->click = ++$query->click;
- $query->click_true = ++$query->click_true;
- return $query->save();
- }
- }
|