diff --git a/app/appfront/modules/Catalog/block/product/Index.php b/app/appfront/modules/Catalog/block/product/Index.php index 9ec437e2dcf6e8e54819ae2d8db10d4ab152ac4d..de5bee4d67cb34ce894cf3a15750344b5b3a2c97 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 d7b5cef427c2a8b83d72c63ba00c85174f69ff33..afbcd26fb110235bc833d99376dc7fc0b37175a8 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 75f92e1a8df79c61ac9519a26ad5af5274d7e1a0..cdeb62e7cb0704def5b0f1e7878e9a3f233b178f 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 3255c096775e7755e6c2b0d18ac7b9f4a3606d53..7ce48acb720e758d9185ed6e718c770d8b370dda 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 5abf07a1997ec77c1ed5338b6ff0a197b08814f3..d7105d8cb48b960cb058441df004ec578a54002d 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 1dead86c365e77eb8270d8299e309389753bebd6..f1923594d3aedd0e0b58456460acea1b62cea8e9 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 3892ebbb73ff358994cdf6a216737dc450be9881..1472319318815a5d5a1586f5d7d7e442bfe56049 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); }