Example #1
0
 public function run()
 {
     $post = Post::find();
     //选择栏目
     if (!empty($this->short_code)) {
         $post = $post->select(Post::tableName() . '.*')->joinWith(['column' => function ($query) {
             $query->where([Column::tableName() . '.short_code' => $this->short_code]);
         }]);
     }
     //选择类型
     if (!empty($this->type)) {
         if ($this->type == static::TYPE_N) {
             //自动取新
             $post = $post->orderBy(Post::tableName() . '.created_at DESC');
         } elseif ($this->type == static::TYPE_V) {
             //自动取查看最多
             $post = $post->orderBy(Post::tableName() . '.hits DESC');
         } else {
             //后台指定
             $post = $post->andFilterWhere(['like', Post::tableName() . '.flag', $this->type]);
         }
     }
     //限制数量
     $models = $post->active()->limit($this->num)->all();
     //     	fb($models);
     return $this->render('side-post-top', ['title' => $this->title, 'length' => $this->length, 'models' => $models]);
 }
Example #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]);
 }
Example #3
0
 public function run()
 {
     if (!empty($this->id)) {
         //自动寻找类型
         $class = 'common\\models\\cms\\' . ucfirst($this->controllerId);
         $all = $class::find();
         //选择栏目
         if (!empty($this->short_code)) {
             $all = $all->select($class::tableName() . '.*')->joinWith(['column' => function ($query) {
                 $query->where([Column::tableName() . '.short_code' => $this->short_code]);
             }]);
         }
         //自动判断
         if ($this->actionId == 'view') {
             //详情
             $model = $class::findOne($this->id);
             //在详情中,直接获取栏目
             $all = $all->andWhere(['column_id' => $model->column_id]);
         } elseif ($this->actionId == 'list') {
             //列表
             $column = Column::findOne($this->id);
             //在列表中,直接获取栏目
             $all = $all->andWhere(['column_id' => $column->id]);
         }
         //选择类型
         if (!empty($this->type)) {
             if ($this->type == static::TYPE_N) {
                 //自动取新
                 $all = $all->orderBy($class::tableName() . '.created_at DESC');
             } elseif ($this->type == static::TYPE_V) {
                 //自动取查看最多
                 $all = $all->orderBy($class::tableName() . '.hits DESC');
             } else {
                 //后台指定
                 $all = $all->andFilterWhere(['like', $class::tableName() . '.flag', $this->type]);
             }
         }
         //限制数量
         $models = $all->active()->limit($this->num)->all();
         return $this->render('side-current-top', ['title' => $this->title, 'length' => $this->length, 'models' => $models, 'type' => $this->controllerId]);
     }
 }