Skip to content

Commit 491c6e5

Browse files
committed
add
1 parent 4c7016a commit 491c6e5

11 files changed

+403
-20
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
2-
class AdminController extends Controller{
2+
class AdminController extends BackPlatformController{
33

44
/**
55
* 展示登陆页面
66
* @return [type] [description]
77
*/
88
public function indexAction(){
9-
require './app/view/back/login.html';
9+
require CURR_VIEW_DIR.'login.html';
1010
}
1111

1212
public function signinAction(){
@@ -15,7 +15,7 @@ public function signinAction(){
1515
$model_admin = new AdminModel;
1616
if ($model_admin->checkByLogin($_POST['username'],$_POST['password'])) {
1717
//setcookie('is_login','yes');
18-
session_start();
18+
//session_start();
1919
$_SESSION['is_login'] = 'yes';
2020
//echo '合法用户';
2121
$this->jump('index.php?p=back&c=Index&a=index');
@@ -25,4 +25,5 @@ public function signinAction(){
2525
$this->jump('index.php?p=back&c=Admin&a=index','非法用户',2);
2626
}
2727
}
28+
2829
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
class BackPlatformController extends Controller{
4+
5+
public function __construct(){
6+
//开启session
7+
$this->initSeesion();
8+
//验证是否登陆
9+
$this->checkLogin();
10+
}
11+
12+
/**
13+
*  初始化入库的代码
14+
*
15+
*/
16+
protected function initSeesion(){
17+
new SessionDBTool;
18+
}
19+
20+
/**
21+
* 检验当前是否登陆
22+
*/
23+
protected function checkLogin(){
24+
// 判断用户是否登陆
25+
@session_start();
26+
if (CONTROLLER == 'Admin' && (ACTION == 'index' || ACTION=='signin')) {
27+
//不需要验证
28+
}else{
29+
//需要
30+
if(isset($_SESSION['is_login']) && $_SESSION['is_login'] == 'yes'){
31+
//继续执行
32+
}else{
33+
$this->jump('index.php?p=back&c=Admin&a=index','请登录',2);
34+
}
35+
}
36+
}
37+
38+
}

shop/app/controller/back/CategoryController.class.php

+71-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
class CategoryController extends Controller{
2+
class CategoryController extends BackPlatformController{
33
/**
44
*分类列表展示
55
* @return [type] [description]
@@ -9,4 +9,74 @@ public function listAction(){
99
$list = $model_name->getList();
1010
require CURR_VIEW_DIR.'category.html';
1111
}
12+
13+
/**
14+
* 删除分类
15+
*/
16+
public function delAction(){
17+
$model_category = new CategoryModel;
18+
if ($model_category->delById($_GET['id'])) {
19+
//删除成功
20+
$this->jump('index.php?p=back&c=Category&a=list');
21+
}else{
22+
//删除失败
23+
$this->jump('index.php?p=back&c=Category&a=list','失败:'.$model_category->error_info);
24+
}
25+
}
26+
27+
/**
28+
* 增加分类
29+
*/
30+
public function addAction(){
31+
$model_name = new CategoryModel;
32+
$list = $model_name->getList(0);
33+
//echo '<pre>';
34+
//var_dump($list);
35+
//echo '</pre>';
36+
require CURR_VIEW_DIR.'categoryAdd.html';
37+
}
38+
39+
public function insertAction(){
40+
$data['cat_name'] = $_POST['cat_name'];
41+
$data['parent_id'] =$_POST['parent_id'];
42+
$data['sort_order'] = $_POST['sort_order'];
43+
44+
$model_name = new CategoryModel;
45+
if ($model_name->addCate($data)) {
46+
$this->jump('index.php?p=back&c=Category&a=list');
47+
}else{
48+
$this->jump('index.php?p=back&c=Category&a=list','失败:'.$model_category->error_info);
49+
}
50+
51+
52+
}
53+
54+
/**
55+
* 修改商品信息
56+
* @param [type] $cat_id 商品ID
57+
* @return [type] [description]
58+
*/
59+
public function editAction(){
60+
$cat_id = $_GET['id'];
61+
$modle_name = new CategoryModel;
62+
$curr_cat = $modle_name -> getById($cat_id);
63+
$cat_list = $modle_name->getList(0);
64+
require CURR_VIEW_DIR.'categoryEdit.html';
65+
}
66+
67+
68+
public function updateAction(){
69+
$data['cat_id'] = $_POST['cat_id'];
70+
$data['parent_id'] = $_POST['parent_id'];
71+
$data['sort_order'] = $_POST['sort_order'];
72+
$data['cat_name'] = $_POST['cat_name'];
73+
74+
$model_name = new CategoryModel;
75+
if ($model_name -> updateCat($data)) {
76+
$this->jump('index.php?p=back&c=Category&a=list');
77+
}else{
78+
$this->jump('index.php?p=back&c=Category&a=list','修改失败'.$model_name->error_info);
79+
}
80+
}
81+
1282
}

shop/app/controller/back/IndexController.class.php

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
<?php
22

3-
class IndexController extends Controller{
4-
3+
class IndexController extends BackPlatformController{
4+
/**
5+
* 载入后台首页动作
6+
* @return [type] [description]
7+
*/
58
public function indexAction(){
69
//判断用户是否已经登陆
710
//if (isset($_COOKIE['is_login']) && $_COOKIE['is_login'] == 'yes') {
8-
session_start();
9-
if(isset($_SESSION['is_login']) && $_SESSION['is_login'] == 'yes'){
10-
# code...
11-
}else{
12-
//die('没有登录');
13-
$this->jump('index.php?p=back&c=Admin&a=index','没有用户',5);
14-
die();
15-
}
11+
// session_start();
12+
// if(isset($_SESSION['is_login']) && $_SESSION['is_login'] == 'yes'){
13+
// # code...
14+
// }else{
15+
// //die('没有登录');
16+
// $this->jump('index.php?p=back&c=Admin&a=index','没有用户',5);
17+
// die();
18+
// }
1619
require CURR_VIEW_DIR.'index.html';
1720
}
1821

shop/app/model/CategoryModel.class.php

+62-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ class CategoryModel extends Model{
44
* 获取所有分类信息
55
* @return 所有分类
66
*/
7-
public function getList(){
7+
public function getList($p_id=0){
88
$sql = "select * from `demo_category` order by sort_order";
99
$list = $this->db->fetchAll($sql);
1010
//return $list;
11-
$list = $this->getTree($list,0,0);
11+
$list = $this->getTree($list,$p_id,0);
1212
return $list;
1313
}
1414

@@ -19,7 +19,7 @@ public function getList(){
1919
* @param [type] $deep 当前的分类深度
2020
* @return [type] [description]
2121
*/
22-
public function getTree($arr,$pid=0,$deep){
22+
public function getTree($arr,$pid=0,$deep=0){
2323
static $tree = array();
2424
foreach ($arr as $row ) {
2525
if ($row['parent_id'] == $pid) {
@@ -30,4 +30,63 @@ public function getTree($arr,$pid=0,$deep){
3030
}
3131
return $tree;
3232
}
33+
/**
34+
* 利用ID删除分类
35+
* @param [type] $id [description]
36+
* @return bool
37+
*/
38+
public function delById($id){
39+
if ($this->isLeaf($id) ){
40+
$this->error_info = '分类不是末级分类';
41+
return false;
42+
}
43+
$sql = "delete from demo_category where `cat_id`=$id";
44+
return $this->db->query($sql);
45+
}
46+
47+
/**
48+
* 判断当前分类下是否有子节点
49+
* @return boolean [description]
50+
*/
51+
public function isLeaf($cat_id){
52+
$sql = "select count(*) from demo_category where parent_id=$cat_id";
53+
$child_count = $this->db->fetchColoum($sql);
54+
return $child_count == 0;
55+
}
56+
57+
/**
58+
* 插入新分类
59+
* @param $data 当前插入分类的信息
60+
*/
61+
public function addCate($data){
62+
if($data['cat_name'] ==''){
63+
$this->error_info = '分类名不能为空';
64+
// return false;
65+
}
66+
67+
$sql = "SELECT count(*) from demo_category where parent_id={$data['parent_id']} and cat_name='{$data['cat_name']}' ";
68+
69+
$cat_count = $this->db->fetchColoum($sql);
70+
if ($cat_count > 0) {
71+
$this->error_info = '分类已经存在';
72+
}
73+
74+
$sql = "INSERT INTO `demo_category`(`cat_name`, `sort_order`, `parent_id`) VALUES ('{$data['cat_name']}','{$data['sort_order']}','{$data['parent_id']}')";
75+
return $this->db->query($sql);
76+
}
77+
78+
public function getById($cat_id){
79+
$sql = "select * from demo_category where cat_id='{$cat_id}'";
80+
return $this->db->fetchRow($sql);
81+
}
82+
83+
public function pdateCat($data){
84+
$child_list = $this->getList($data['cat_id']);
85+
$ids = array($data['cat_id']);
86+
foreach ($child_list as $row) {
87+
88+
}
89+
90+
$sql = "update demo_category "
91+
}
3392
}

shop/app/view/back/category.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<body>
3131

3232
<h1>
33-
<span class="action-span"><a href="#">添加分类</a></span>
33+
<span class="action-span"><a href="/index.php?p=back&c=Category&a=add">添加分类</a></span>
3434
<span class="action-span1"><a href="index.php?act=main">ECSHOP 管理中心</a> </span><span id="search_id" class="action-span1"> - 商品分类 </span>
3535
<div style="clear:both"></div>
3636
</h1>
@@ -68,8 +68,8 @@ <h1>
6868
<!--
6969
<a href="category.php?act=move&cat_id=12">转移商品</a> |
7070
-->
71-
<a href="category.php?act=edit&amp;cat_id=12">编辑</a> |
72-
<a href="javascript:;" onclick="listTable.remove(12, '您确认要删除这条记录吗?')" title="移除">移除</a>
71+
<a href="index.php?p=back&c=Category&a=edit&id=<?php echo $row['cat_id']?>" onclick="confrim('是否要编辑')">编辑</a> |
72+
<a href="index.php?p=back&c=Category&a=del&id=<?php echo $row['cat_id']?>" onclick="return confrim('是否要删除:<?php echo $row["cat_name"]?>');" title="移除">移除</a>
7373
</td>
7474
<?php endforeach;?>
7575
</tr>

shop/app/view/back/categoryAdd.html

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml">
3+
<head>
4+
<title>ECSHOP 管理中心 - 添加分类 </title>
5+
<meta name="robots" content="noindex, nofollow">
6+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7+
<link href="/app/view/back/stylesgeneral.css" rel="stylesheet" type="text/css" />
8+
<link href="/app/view/back/styles/main.css" rel="stylesheet" type="text/css" />
9+
</head>
10+
<body>
11+
12+
<h1>
13+
<span class="action-span"><a href="index.php?p=back&c=Category&a=list">商品分类</a></span>
14+
<span class="action-span1"><a href="index.php?act=main">ECSHOP 管理中心</a> </span><span id="search_id" class="action-span1"> - 添加分类 </span>
15+
<div style="clear:both"></div>
16+
</h1>
17+
<!-- start add new category form -->
18+
<div class="main-div">
19+
<form action="index.php?p=back&c=Category&a=insert" method="post">
20+
<table width="100%" id="general-table">
21+
<tr>
22+
<td class="label">分类名称:</td>
23+
<td>
24+
<input type='text' name='cat_name' maxlength="20" value='' size='27' /> <font color="red">*</font>
25+
</td>
26+
</tr>
27+
<tr>
28+
<td class="label">上级分类:</td>
29+
<td>
30+
<select name="parent_id">
31+
<option value="0">顶级分类</option>
32+
<?php foreach($list as $row) :?>
33+
<option value="<?php echo $row['cat_id'];?>">
34+
<?php echo str_repeat('&nbsp;&nbsp;', $row['deep']), $row['cat_name'];?>
35+
</option>
36+
<?php endForeach;?>
37+
</select>
38+
</td>
39+
</tr>
40+
<tr>
41+
<td class="label">排序:</td>
42+
<td>
43+
<input type="text" name='sort_order' value="50" size="15" />
44+
</td>
45+
</tr>
46+
</table>
47+
<div class="button-div">
48+
<input type="submit" value=" 确定 " />
49+
<input type="reset" value=" 重置 " />
50+
</div>
51+
</form>
52+
</div>
53+
54+
<div id="footer">
55+
&copy;<a href="http://banzhuande.me">banzhuande.me</a>
56+
</div>
57+
58+
</body>
59+
</html>
60+
l

0 commit comments

Comments
 (0)