提交 5891faab 编写于 作者: T Terry

添加分类是否在菜单中显示选项

上级 a6e149fd
...@@ -252,6 +252,20 @@ class Index extends AppadminbaseBlockEdit implements AppadminbaseBlockEditInterf ...@@ -252,6 +252,20 @@ class Index extends AppadminbaseBlockEdit implements AppadminbaseBlockEditInterf
'require' => 1, 'require' => 1,
'default' => 1, 'default' => 1,
], ],
[
'label'=>'Menu是否显示',
'name'=>'menu_show',
'display'=>[
'type' => 'select',
'data' => [
1 => '菜单中显示',
2 => '菜单中不显示',
],
],
'require' => 1,
'default' => 1,
],
[ [
'label'=>'Url Key', 'label'=>'Url Key',
......
...@@ -53,8 +53,11 @@ class Index ...@@ -53,8 +53,11 @@ class Index
// 这样是为了防止恶意攻击,也就是发送很多不同的页面个数的链接,绕开缓存。 // 这样是为了防止恶意攻击,也就是发送很多不同的页面个数的链接,绕开缓存。
$this->getNumPerPage(); $this->getNumPerPage();
//echo Yii::$service->page->translate->__('fecshop,{username}', ['username' => 'terry']); //echo Yii::$service->page->translate->__('fecshop,{username}', ['username' => 'terry']);
$this->initCategory(); if(!$this->initCategory()){
Yii::$service->url->redirect404();
return;
}
// change current layout File. // change current layout File.
//Yii::$service->page->theme->layoutFile = 'home.php'; //Yii::$service->page->theme->layoutFile = 'home.php';
...@@ -471,6 +474,16 @@ class Index ...@@ -471,6 +474,16 @@ class Index
$primaryVal = Yii::$app->request->get($primaryKey); $primaryVal = Yii::$app->request->get($primaryKey);
$this->_primaryVal = $primaryVal; $this->_primaryVal = $primaryVal;
$category = Yii::$service->category->getByPrimaryKey($primaryVal); $category = Yii::$service->category->getByPrimaryKey($primaryVal);
if ($category) {
$enableStatus = Yii::$service->category->getCategoryEnableStatus();
if ($category['status'] != $enableStatus){
return false;
}
} else {
return false;
}
$this->_category = $category; $this->_category = $category;
Yii::$app->view->registerMetaTag([ Yii::$app->view->registerMetaTag([
'name' => 'keywords', 'name' => 'keywords',
...@@ -486,6 +499,7 @@ class Index ...@@ -486,6 +499,7 @@ class Index
$this->_title = $this->_title ? $this->_title : $name; $this->_title = $this->_title ? $this->_title : $name;
Yii::$app->view->title = $this->_title; Yii::$app->view->title = $this->_title;
$this->_where = $this->initWhere(); $this->_where = $this->initWhere();
return true;
} }
// 面包屑导航 // 面包屑导航
......
...@@ -24,12 +24,13 @@ class CategoryController extends AppfrontController ...@@ -24,12 +24,13 @@ class CategoryController extends AppfrontController
Yii::$service->page->theme->layoutFile = 'category_view.php'; Yii::$service->page->theme->layoutFile = 'category_view.php';
} }
// 网站信息管理 // 分类页面。
public function actionIndex() public function actionIndex()
{ {
$data = $this->getBlock()->getLastData(); $data = $this->getBlock()->getLastData();
if(is_array($data)){
return $this->render($this->action->id, $data); return $this->render($this->action->id, $data);
}
} }
/** /**
* Yii2 behaviors 可以参看地址:http://www.yiichina.com/doc/guide/2.0/concept-behaviors * Yii2 behaviors 可以参看地址:http://www.yiichina.com/doc/guide/2.0/concept-behaviors
......
...@@ -54,7 +54,10 @@ class Index ...@@ -54,7 +54,10 @@ class Index
// 这样是为了防止恶意攻击,也就是发送很多不同的页面个数的链接,绕开缓存。 // 这样是为了防止恶意攻击,也就是发送很多不同的页面个数的链接,绕开缓存。
$this->getNumPerPage(); $this->getNumPerPage();
//echo Yii::$service->page->translate->__('fecshop,{username}', ['username' => 'terry']); //echo Yii::$service->page->translate->__('fecshop,{username}', ['username' => 'terry']);
$this->initCategory(); if(!$this->initCategory()){
Yii::$service->url->redirect404();
return;
}
// change current layout File. // change current layout File.
//Yii::$service->page->theme->layoutFile = 'home.php'; //Yii::$service->page->theme->layoutFile = 'home.php';
...@@ -483,6 +486,16 @@ class Index ...@@ -483,6 +486,16 @@ class Index
$primaryVal = Yii::$app->request->get($primaryKey); $primaryVal = Yii::$app->request->get($primaryKey);
$this->_primaryVal = $primaryVal; $this->_primaryVal = $primaryVal;
$category = Yii::$service->category->getByPrimaryKey($primaryVal); $category = Yii::$service->category->getByPrimaryKey($primaryVal);
if ($category) {
$enableStatus = Yii::$service->category->getCategoryEnableStatus();
if ($category['status'] != $enableStatus){
return false;
}
} else {
return false;
}
$this->_category = $category; $this->_category = $category;
Yii::$app->view->registerMetaTag([ Yii::$app->view->registerMetaTag([
'name' => 'keywords', 'name' => 'keywords',
...@@ -498,6 +511,7 @@ class Index ...@@ -498,6 +511,7 @@ class Index
$this->_title = $this->_title ? $this->_title : $name; $this->_title = $this->_title ? $this->_title : $name;
Yii::$app->view->title = $this->_title; Yii::$app->view->title = $this->_title;
$this->_where = $this->initWhere(); $this->_where = $this->initWhere();
return true;
} }
// 面包屑导航 // 面包屑导航
......
...@@ -24,12 +24,13 @@ class CategoryController extends AppfrontController ...@@ -24,12 +24,13 @@ class CategoryController extends AppfrontController
Yii::$service->page->theme->layoutFile = 'category_view.php'; Yii::$service->page->theme->layoutFile = 'category_view.php';
} }
// 网站信息管理 // 分类页面。
public function actionIndex() public function actionIndex()
{ {
$data = $this->getBlock()->getLastData(); $data = $this->getBlock()->getLastData();
if(is_array($data)){
return $this->render($this->action->id, $data); return $this->render($this->action->id, $data);
}
} }
public function behaviors() public function behaviors()
......
...@@ -17,6 +17,14 @@ use yii\mongodb\ActiveRecord; ...@@ -17,6 +17,14 @@ use yii\mongodb\ActiveRecord;
*/ */
class Category extends ActiveRecord class Category extends ActiveRecord
{ {
const MENU_SHOW = 1;
const MENU_NOT_SHOW = 2;
const STATUS_ENABLE = 1;
const STATUS_DISABLE = 2;
/** /**
* mongodb collection 的名字,相当于mysql的table name * mongodb collection 的名字,相当于mysql的table name
*/ */
...@@ -35,6 +43,7 @@ class Category extends ActiveRecord ...@@ -35,6 +43,7 @@ class Category extends ActiveRecord
'parent_id', 'parent_id',
'name', 'name',
'status', 'status',
'menu_show',
'url_key', 'url_key',
'level', 'level',
'thumbnail_image', 'thumbnail_image',
......
...@@ -35,6 +35,18 @@ class Category extends Service ...@@ -35,6 +35,18 @@ class Category extends Service
//$this->_category = new CategoryMysqldb; //$this->_category = new CategoryMysqldb;
} }
} }
protected function actionGetCategoryEnableStatus()
{
return $this->_category->getCategoryEnableStatus();
}
protected function actionGetCategoryMenuShowStatus()
{
return $this->_category->getCategoryMenuShowStatus();
}
/** /**
* 得到当前的category service 对应的主键名称,譬如如果是mongo,返回的是 _id. * 得到当前的category service 对应的主键名称,譬如如果是mongo,返回的是 _id.
......
...@@ -423,4 +423,13 @@ class Url extends Service ...@@ -423,4 +423,13 @@ class Url extends Service
//header("Location: $homeUrl"); //header("Location: $homeUrl");
} }
} }
protected function actionRedirect404()
{
$error404UrlKey = Yii::$app->errorHandler->errorAction;
$error404Url = $this->getUrl($error404UrlKey);
if ($error404Url) {
Yii::$app->getResponse()->redirect($error404Url)->send();
}
}
} }
...@@ -27,7 +27,18 @@ class CategoryMongodb implements CategoryInterface ...@@ -27,7 +27,18 @@ class CategoryMongodb implements CategoryInterface
{ {
return '_id'; return '_id';
} }
/**
* 得到分类激活状态的值
*/
public function getCategoryEnableStatus(){
return Category::STATUS_ENABLE;
}
/**
* 得到分类在menu中显示的状态值
*/
public function getCategoryMenuShowStatus(){
return Category::MENU_SHOW;
}
/** /**
* 通过主键,得到Category对象。 * 通过主键,得到Category对象。
*/ */
...@@ -112,7 +123,8 @@ class CategoryMongodb implements CategoryInterface ...@@ -112,7 +123,8 @@ class CategoryMongodb implements CategoryInterface
} }
$model->updated_at = time(); $model->updated_at = time();
unset($one['_id']); unset($one['_id']);
$one['status'] = (int)$one['status'];
$one['menu_show'] = (int)$one['menu_show'];
$saveStatus = Yii::$service->helper->ar->save($model, $one); $saveStatus = Yii::$service->helper->ar->save($model, $one);
$originUrl = $originUrlKey.'?'.$this->getPrimaryKey() .'='. $primaryVal; $originUrl = $originUrlKey.'?'.$this->getPrimaryKey() .'='. $primaryVal;
$originUrlKey = isset($one['url_key']) ? $one['url_key'] : ''; $originUrlKey = isset($one['url_key']) ? $one['url_key'] : '';
......
...@@ -26,6 +26,7 @@ class Menu extends Service ...@@ -26,6 +26,7 @@ class Menu extends Service
*/ */
protected function actionGetCategoryMenuArr($parentId = '') protected function actionGetCategoryMenuArr($parentId = '')
{ {
$arr = []; $arr = [];
if (!$parentId) { if (!$parentId) {
$parentId = $this->rootCategoryId; $parentId = $this->rootCategoryId;
...@@ -34,6 +35,8 @@ class Menu extends Service ...@@ -34,6 +35,8 @@ class Menu extends Service
'_id', 'parent_id', 'name', 'url_key', 'menu_custom', '_id', 'parent_id', 'name', 'url_key', 'menu_custom',
])->where([ ])->where([
'parent_id' => $parentId, 'parent_id' => $parentId,
'status' => Category::STATUS_ENABLE,
'menu_show' => Category::MENU_SHOW,
])->all(); ])->all();
if (is_array($data) && !empty($data)) { if (is_array($data) && !empty($data)) {
foreach ($data as $category) { foreach ($data as $category) {
......
...@@ -55,7 +55,7 @@ use fecshop\app\appfront\helper\Format; ...@@ -55,7 +55,7 @@ use fecshop\app\appfront\helper\Format;
<td>&nbsp;</td> <td>&nbsp;</td>
<td valign="top" style="padding:7px 9px 9px;font-size:12px;border-right-color:rgb(234,234,234);border-bottom-color:rgb(234,234,234);border-left-color:rgb(234,234,234);border-right-width:1px;border-bottom-width:1px;border-left-width:1px;border-right-style:solid;border-bottom-style:solid;border-left-style:solid"> <td valign="top" style="padding:7px 9px 9px;font-size:12px;border-right-color:rgb(234,234,234);border-bottom-color:rgb(234,234,234);border-left-color:rgb(234,234,234);border-right-width:1px;border-bottom-width:1px;border-left-width:1px;border-right-style:solid;border-bottom-style:solid;border-left-style:solid">
<p><b>PayPal - <?= $order['payment_method']; ?></b></p> <p><b><?= ucfirst(str_replace('_',' ',$order['payment_method'])); ?></b></p>
</td> </td>
</tr> </tr>
......
...@@ -55,7 +55,7 @@ use fecshop\app\appfront\helper\Format; ...@@ -55,7 +55,7 @@ use fecshop\app\appfront\helper\Format;
<td>&nbsp;</td> <td>&nbsp;</td>
<td valign="top" style="padding:7px 9px 9px;font-size:12px;border-right-color:rgb(234,234,234);border-bottom-color:rgb(234,234,234);border-left-color:rgb(234,234,234);border-right-width:1px;border-bottom-width:1px;border-left-width:1px;border-right-style:solid;border-bottom-style:solid;border-left-style:solid"> <td valign="top" style="padding:7px 9px 9px;font-size:12px;border-right-color:rgb(234,234,234);border-bottom-color:rgb(234,234,234);border-left-color:rgb(234,234,234);border-right-width:1px;border-bottom-width:1px;border-left-width:1px;border-right-style:solid;border-bottom-style:solid;border-left-style:solid">
<p><b>PayPal - <?= $order['payment_method']; ?></b></p> <p><b><?= ucfirst(str_replace('_',' ',$order['payment_method'])); ?></b></p>
</td> </td>
</tr> </tr>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册