Example #1
0
 /**
  * Lists all Goods models.
  * @return mixed
  */
 public function actionIndex()
 {
     if (!$this->is_access('goods/index')) {
         Yii::$app->session->setFlash('error', $this->errorInfo);
         return $this->redirect($this->redirectUrl);
     }
     $query = Goods::find()->where(['is_delete' => 0]);
     $request = Yii::$app->request;
     /* 搜索 begin */
     if (($cat_id = $request->get('cat_id')) > 0) {
         $query = $query->andWhere(['cat_id' => $cat_id]);
     }
     if (($brand_id = $request->get('brand_id')) > 0) {
         $query = $query->andWhere(['brand_id' => $brand_id]);
     }
     if (($intro_type = $request->get('intro_type')) && $intro_type != 'is_all') {
         $query = $query->andWhere([$intro_type => 1]);
     }
     if (is_numeric($is_on_sale = $request->get('is_on_sale'))) {
         $query = $query->andWhere(['is_on_sale' => $is_on_sale]);
     }
     if (!empty($goods_name = $request->get('goods_name'))) {
         $query = $query->andWhere("goods_name like '%{$goods_name}%'");
     }
     /* 搜索 end */
     $dataProvider = new ActiveDataProvider(['query' => $query, 'Sort' => ['defaultOrder' => ['goods_id' => SORT_DESC]]]);
     Yii::$app->view->params['meta_title'] = '商品列表';
     // 商品分类
     $Category = new Category();
     $categoryList = $Category->dropListHtml();
     // 品牌
     $Brand = new Brand();
     $brandList = $Brand->dropListHtml();
     return $this->render('index', ['dataProvider' => $dataProvider, 'categoryList' => $categoryList, 'brandList' => $brandList]);
 }