public function run() { $img = Img::find(); //选择栏目 if (!empty($this->short_code)) { $img = $img->select(Img::tableName() . '.*')->joinWith(['column' => function ($query) { $query->where([Column::tableName() . '.short_code' => $this->short_code]); }]); } //选择类型 if (!empty($this->type)) { if ($this->type == static::TYPE_N) { //自动取新 $img = $img->orderBy(Img::tableName() . '.created_at DESC'); } elseif ($this->type == static::TYPE_V) { //自动取查看最多 $img = $img->orderBy(Img::tableName() . '.hits DESC'); } else { //后台指定 $img = $img->andFilterWhere(['like', Img::tableName() . '.flag', $this->type]); } } //限制数量 $models = $img->active()->limit($this->num)->all(); // fb($models); if ($models) { return $this->render('side-img-top', ['title' => $this->title, 'length' => $this->length, 'models' => $models]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Img::find()->alive(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => [], 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'column_id' => $this->column_id, 'hits' => $this->hits, 'status' => $this->status, 'deleted' => $this->deleted, 'updated_at' => $this->updated_at, 'created_at' => $this->created_at]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'flag', $this->flag])->andFilterWhere(['like', 'colorval', $this->colorval])->andFilterWhere(['like', 'boldval', $this->boldval])->andFilterWhere(['like', 'source', $this->source])->andFilterWhere(['like', 'author', $this->author])->andFilterWhere(['like', 'link_url', $this->link_url])->andFilterWhere(['like', 'keywords', $this->keywords])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'pic_url', $this->pic_url])->andFilterWhere(['like', 'picarr', $this->picarr]); return $dataProvider; }
/** * 首页 * @return string */ public function actionIndex() { $columns = Column::find()->where(['type' => Column::CMS_TYPE_LIST])->active()->orderBy('order ASC')->all(); //关于我们单页 $about = Column::find()->where(['short_code' => 'about-brief'])->active()->one(); //首页主广告 $mainAdType = AdType::find()->where(['short_code' => 'home_main'])->active()->one(); //in查询 $mainAds = $mainAdType->getAd()->active()->orderBy('order ASC')->all(); //底部广告 $adBottom = Ad::find()->where(['short_code' => 'home_bottom'])->active()->one(); //搬家现场,推荐 $scenes = Img::find()->select(Img::tableName() . '.*')->where(['like', Img::tableName() . '.flag', 'c'])->joinWith(['column' => function ($query) { $query->where([Column::tableName() . '.short_code' => 'xianchang']); }])->active()->all(); //搬家现场推荐 return $this->render('index', ['columns' => $columns, 'about' => $about, 'mainAdType' => $mainAdType, 'mainAds' => $mainAds, 'adBottom' => $adBottom, 'scenes' => $scenes]); }