From 1971354ae2eeb98f9b87263837accc575fd510b3 Mon Sep 17 00:00:00 2001 From: Terry <2358269014@qq.com> Date: Wed, 19 Jul 2017 18:08:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=A7=E5=93=81status=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E6=88=90=E5=85=B3=E9=97=AD=EF=BC=8C=E5=88=99=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=E8=AF=A5=E4=BA=A7=E5=93=81=E8=B7=B3=E8=BD=AC404=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/Catalog/block/product/Index.php | 16 +++++++++++++++- .../Catalog/controllers/ProductController.php | 8 +++----- .../modules/Catalog/block/product/Index.php | 16 +++++++++++++++- .../Catalog/controllers/ProductController.php | 8 +++----- models/mongodb/Product.php | 5 ++++- services/Product.php | 8 +++++++- services/product/ProductMongodb.php | 11 ++++++++++- 7 files changed, 57 insertions(+), 15 deletions(-) diff --git a/app/appfront/modules/Catalog/block/product/Index.php b/app/appfront/modules/Catalog/block/product/Index.php index 9ec437e2..de5bee4d 100644 --- a/app/appfront/modules/Catalog/block/product/Index.php +++ b/app/appfront/modules/Catalog/block/product/Index.php @@ -37,7 +37,10 @@ class Index { $productImgSize = Yii::$app->controller->module->params['productImgSize']; $productImgMagnifier = Yii::$app->controller->module->params['productImgMagnifier']; - $this->initProduct(); + if(!$this->initProduct()){ + Yii::$service->url->redirect404(); + return; + } ReviewHelper::initReviewConfig(); $ReviewAndStarCount = ReviewHelper::getReviewAndStarCount($this->_product); list($review_count, $reviw_rate_star_average) = $ReviewAndStarCount; @@ -391,6 +394,16 @@ class Index $primaryVal = Yii::$app->request->get($primaryKey); $this->_primaryVal = $primaryVal; $product = Yii::$service->product->getByPrimaryKey($primaryVal); + if ($product) { + $enableStatus = Yii::$service->product->getEnableStatus(); + if ($product['status'] != $enableStatus){ + + return false; + } + } else { + + return false; + } $this->_product = $product; Yii::$app->view->registerMetaTag([ 'name' => 'keywords', @@ -416,6 +429,7 @@ class Index // 重新查询产品信息。 $product = Yii::$service->product->getByPrimaryKey($primaryVal); $this->_product = $product; + return true; } // 面包屑导航 diff --git a/app/appfront/modules/Catalog/controllers/ProductController.php b/app/appfront/modules/Catalog/controllers/ProductController.php index d7b5cef4..afbcd26f 100644 --- a/app/appfront/modules/Catalog/controllers/ProductController.php +++ b/app/appfront/modules/Catalog/controllers/ProductController.php @@ -27,12 +27,10 @@ class ProductController extends AppfrontController // 产品详细页面 public function actionIndex() { - //$data = Yii::$service->product->apicoll(); - //var_dump($data); - //echo 1;exit; $data = $this->getBlock()->getLastData(); - - return $this->render($this->action->id, $data); + if(is_array($data)){ + return $this->render($this->action->id, $data); + } } /** * Yii2 behaviors 可以参看地址:http://www.yiichina.com/doc/guide/2.0/concept-behaviors diff --git a/app/apphtml5/modules/Catalog/block/product/Index.php b/app/apphtml5/modules/Catalog/block/product/Index.php index 75f92e1a..cdeb62e7 100644 --- a/app/apphtml5/modules/Catalog/block/product/Index.php +++ b/app/apphtml5/modules/Catalog/block/product/Index.php @@ -37,7 +37,10 @@ class Index { $productImgSize = Yii::$app->controller->module->params['productImgSize']; $productImgMagnifier = Yii::$app->controller->module->params['productImgMagnifier']; - $this->initProduct(); + if(!$this->initProduct()){ + Yii::$service->url->redirect404(); + return; + } ReviewHelper::initReviewConfig(); $ReviewAndStarCount = ReviewHelper::getReviewAndStarCount($this->_product); list($review_count, $reviw_rate_star_average) = $ReviewAndStarCount; @@ -391,6 +394,16 @@ class Index $primaryVal = Yii::$app->request->get($primaryKey); $this->_primaryVal = $primaryVal; $product = Yii::$service->product->getByPrimaryKey($primaryVal); + if ($product) { + $enableStatus = Yii::$service->product->getEnableStatus(); + if ($product['status'] != $enableStatus){ + + return false; + } + } else { + + return false; + } $this->_product = $product; Yii::$app->view->registerMetaTag([ 'name' => 'keywords', @@ -416,6 +429,7 @@ class Index // 重新查询产品信息。 $product = Yii::$service->product->getByPrimaryKey($primaryVal); $this->_product = $product; + return true; } // 面包屑导航 diff --git a/app/apphtml5/modules/Catalog/controllers/ProductController.php b/app/apphtml5/modules/Catalog/controllers/ProductController.php index 3255c096..7ce48acb 100644 --- a/app/apphtml5/modules/Catalog/controllers/ProductController.php +++ b/app/apphtml5/modules/Catalog/controllers/ProductController.php @@ -27,12 +27,10 @@ class ProductController extends AppfrontController // 网站信息管理 public function actionIndex() { - //$data = Yii::$service->product->apicoll(); - //var_dump($data); - //echo 1;exit; $data = $this->getBlock()->getLastData(); - - return $this->render($this->action->id, $data); + if(is_array($data)){ + return $this->render($this->action->id, $data); + } } public function behaviors() diff --git a/models/mongodb/Product.php b/models/mongodb/Product.php index 5abf07a1..d7105d8c 100644 --- a/models/mongodb/Product.php +++ b/models/mongodb/Product.php @@ -18,7 +18,10 @@ use yii\mongodb\ActiveRecord; class Product extends ActiveRecord { public static $_customProductAttrs; - + + const STATUS_ENABLE = 1; + const STATUS_DISABLE = 2; + /** * mongodb collection 的名字,相当于mysql的table name */ diff --git a/services/Product.php b/services/Product.php index 1dead86c..f1923594 100644 --- a/services/Product.php +++ b/services/Product.php @@ -33,7 +33,13 @@ class Product extends Service //$this->_category = new CategoryMysqldb; } } - + + protected function actionGetEnableStatus() + { + return $this->_product->getEnableStatus(); + } + + /** * 得到产品的所有的属性组。 */ diff --git a/services/product/ProductMongodb.php b/services/product/ProductMongodb.php index 3892ebbb..14723193 100644 --- a/services/product/ProductMongodb.php +++ b/services/product/ProductMongodb.php @@ -25,7 +25,13 @@ class ProductMongodb implements ProductInterface { return '_id'; } - + /** + * 得到分类激活状态的值 + */ + public function getEnableStatus(){ + return Product::STATUS_ENABLE; + } + public function getByPrimaryKey($primaryKey) { if ($primaryKey) { @@ -80,6 +86,8 @@ class ProductMongodb implements ProductInterface } } } + + /* * example filter: @@ -478,6 +486,7 @@ class ProductMongodb implements ProductInterface $select = $filter['select']; $query = Product::find()->asArray(); $query->where($where); + $query->andWhere(['status' => $this->getEnableStatus()]); if (is_array($select) && !empty($select)) { $query->select($select); } -- GitLab