审查视图

app/admin/controller/LabelController.php 3.3 KB
anyv authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
<?php
namespace app\admin\controller;

use app\admin\model\RouteModel;
use cmf\controller\AdminBaseController;
use think\Db;

class LabelController extends AdminBaseController{

    /**
     * 分类列表管理
     */
    public function classify_list(){

        $data = Db::name('classification') -> select();
        $this -> assign('data',$data);
        return $this -> fetch();

    }

    /**
anyv authored
22
     *分类添加
anyv authored
23 24 25
     */
    public function classify_add(){
anyv authored
26
        if($this -> request -> isPost()){
anyv authored
27
            $_POST['create_time'] = time();
anyv authored
28 29 30 31 32 33
            $data = Db::name('classification') -> insert($_POST);
            if($data){
                $this -> success('添加成功',url('Label/classify_list'));
            }else{
                $this -> error('添加失败!');
            }
anyv authored
34 35 36
        }else{
            return $this -> fetch();
        }
anyv authored
37 38 39

    }
anyv authored
40 41 42 43 44
    /**
     * 分类编辑
     */
    public function classify_edit(){
anyv authored
45 46 47 48 49 50 51 52 53 54 55 56 57
        if($this -> request -> isPost()){
            $data = Db::name('classification') -> update($_POST);
            if($data){
                $this -> success('保存成功',url('Label/classify_edit',array('id'=>$_POST['id'])));
            }else{
                $this -> error('保存失败!');
            }
        }else{
            $id = $this -> request -> param();
            $data = Db::name('classification') -> where('id',$id['id']) -> find();
            $this -> assign('data',$data);
            return $this -> fetch();
        }
anyv authored
58 59

    }
anyv authored
60 61 62 63 64 65 66 67 68


    /**
     * 删除分类
     */
    public function classify_del(){

        $id = $_POST['id'];
        $del = Db::name('classification') -> delete($id);
anyv authored
69
        Db::name('goods') -> where("type = 1 and classify_id = ".$id) -> delete();
anyv authored
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
        if($del){
            return true;
        }else{
            return false;
        }

    }


    /**
     * 标签列表管理
     */
    public function lab_list(){

        $data = Db::name('label') -> select();
        $this -> assign('data',$data);
        return $this -> fetch();

    }

    /**
     * 标签添加
     */
    public function lab_add(){

        $data['name'] = $_POST['name'];
        $data['create_time'] = time();
        $res = Db::name('label') -> insertGetId($data);
        if($res){
            $data['create_time'] = date('Y-m-d H:i:s',$data['create_time']);
            $data['id'] = $res;
            return json_encode($data);
        }else{
            return true;
        }

    }

    /**
     * 标签编辑
     */
    public function lab_edit(){

        $id = $_POST['id'];
        $data = Db::name('label') -> where('id',$id) -> find();
        return json_encode($data);

    }

    /**
     * 标签编辑修改数据
     */
    public function lab_edit_post(){

        $data['id'] = $_POST['id'];
        $data['name'] = $_POST['name'];
        $res = Db::name('label') -> update($data);
        if($res){
            return true;
        }else{
            return false;
        }

    }

    /**
     * 删除标签
     */
    public function lab_del(){

        $id = $_POST['id'];
        $del = Db::name('label') -> delete($id);
anyv authored
142
        Db::name('goods_label') -> where('label_id',$id) -> delete();
anyv authored
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
        if($del){
            return true;
        }else{
            return false;
        }

    }










}