示例#1
0
 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]);
     }
 }
示例#2
0
 /**
  * 首页
  * @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]);
 }