'不能为空','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(); } }