SysController.php 7.9 KB
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;

use cmf\controller\AdminBaseController;
use think\Db;
use think\Validate;

/**
 * Class UserController
 * @package app\admin\controller
 * @adminMenuRoot(
 *     'name'   => '管理组',
 *     'action' => 'default',
 *     'parent' => 'user/AdminIndex/default',
 *     'display'=> true,
 *     'order'  => 10000,
 *     'icon'   => '',
 *     'remark' => '管理组'
 * )
 */
class SysController extends AdminBaseController
{
    public  $table_name_tag = 'goods';
    /***标签管理***/
    //评论标签管理
    public function train_type(){

        $param = $this->request->param();

        $keyword = empty($param['keyword']) ? '' : $param['keyword'];
        if (!empty($keyword)) {
            $where['name'] = ['like', "%$keyword%"];
        }
        $type = empty($param['type']) ? '' : $param['type'];
        if (!empty($type)) {
            $where['type'] = ['eq', $type];
        }

        $where['delete_time']=0;
        $list = DB::name($this->table_name_tag)->where($where)->select()->toArray();
        $this->assign('list', $list);

        return $this->fetch();
    }

    //添加评论标签管理
    public function tag_add(){
        return $this->fetch();
    }
    public function tag_add_do(){
        $data = $this->request->param();
        $validate = new Validate([
            'name'  => 'require',
        ]);
        if (!$validate->check($data)) {
            $this->error('名字不能为空!');
        }else{
            $datain['name'] = $data['name'];
            $datain['price'] = $data['price'];
            $datain['des'] = $data['des'];
            $datain['hetong'] = $data['hetong'];
            $datain['create_time'] = time();

            $result = DB::name($this->table_name_tag)->insert($datain);

            if ($result) {
                $this->success('添加成功!', url('train_type'));
            }else{
                $this->error('添加失败!');
            }
        }
    }

    //修改评论标签管理
    public function tag_edit(){
        $id = $this->request->param('id', 0, 'intval');
        if ($id > 0) {
            $info = DB::name($this->table_name_tag)->where(['id'=>$id])->find();
            $this->assign('info', $info);
            return $this->fetch();
        } else {
            $this->error('操作错误!');
        }
        return $this->fetch();
    }
    public function tag_edit_do(){
        $data = $this->request->param();
        $validate = new Validate([
            'name'  => 'require',
        ]);
        if (!$validate->check($data)) {
            $this->error('名字不能为空!');
        }else{
            $datain['id'] = $data['id'];
            $datain['name'] = $data['name'];
            $datain['price'] = $data['price'];
            $datain['des'] = $data['des'];
            $datain['hetong'] = $data['hetong'];
            $datain['create_time'] = time();

            $result = DB::name($this->table_name_tag)->update($datain);

            if ($result) {
                $this->success('修改成功!', url('train_type'));
            }else{
                $this->error('修改失败!');
            }
        }
    }

    //删
    public function tag_delete()
    {
        $id                     = $this->request->param('id');
        $datain['id']           = $id;
        $datain['delete_time']  = time();

        $result = DB::name($this->table_name_tag)->update($datain);
        if ($result) {
            $this->success('删除成功!');
        } else {
            $this->error('删除失败');
        }
    }
    /***标签管理结束***/


    /**
     * 停用管理员
     */
    public function ban()
    {
        $id = $this->request->param('id', 0, 'intval');
        if (!empty($id)) {
            $result = Db::name('goods')->where(["id" => $id])->setField('status', '0');
            if ($result !== false) {
                $this->success("停用成功!");
            } else {
                $this->error('停用失败!');
            }
        } else {
            $this->error('数据传入失败!');
        }
    }

    /**
     * 启用管理员
     */
    public function cancelBan()
    {
        $id = $this->request->param('id', 0, 'intval');
        if (!empty($id)) {
            $result = Db::name('goods')->where(["id" => $id])->setField('status', '1');
            if ($result !== false) {
                $this->success("启用成功!");
            } else {
                $this->error('启用失败!');
            }
        } else {
            $this->error('数据传入失败!');
        }
    }

    //列表页
    public function data_list(){
        //获取筛选参数
        $param = $this->request->param();
        //1
        $keyword = empty($param['keyword']) ? '' : $param['keyword'];
        if (!empty($keyword)) {
            $where['name'] = ['like', "%$keyword%"];
        }
        //2
        $type = empty($param['type']) ? '' : $param['type'];
        if (!empty($type)) {
            $where['type'] = ['eq', $type];
        }

        $where['delete_time']=0;
        $list = DB::name($this->table_name_tag)->where($where)->select()->toArray();
        $this->assign('list', $list);

        return $this->fetch();
    }

    //列表编辑
    public function data_edit(){
        $param = $this->request->param();
        //提交数据
        if($this->request->isPost()){
            //添加提交
            $datain['name'] = $param['name'];
            $datain['price'] = $param['price'];
            $datain['des'] = $param['des'];
            $datain['hetong'] = $param['hetong'];
            $datain['create_time'] = time();
            $result = DB::name($this->table_name_tag)->insert($datain);
            if ($result) {
                $this->success('添加成功!', url('data_list'));
            }else{
                $this->error('添加失败!');
            }
            //提交修改
            if($param['id']){
                $datain['id'] = $param['id'];
                $result = DB::name($this->table_name_tag)->update($datain);
                if ($result) {
                    $this->success('修改成功!', url('data_list'));
                }else{
                    $this->error('添加失败!');
                }
            }
        }else{
            //展示表单
            if($param['id']){
                $info = DB::name($this->table_name_tag)->where(['id'=>$param['id']])->find();
                $this->assign('info', $info);
            }
            return $this->fetch();
        }

    }

    //列表状态修改
    public function data_satus(){
        $param = $this->request->param();
        $id = $param['id'];
        $type = $param['type'];
        if($type == 'ban'){
            $field = 'status';
            $field_value = '0';
            $field_msg = '停用';
        }elseif($type == 'cancelban'){
            $field = 'status';
            $field_value = '1';
            $field_msg = '启用';
        }elseif($type == 'sel'){
            $field = 'delete_time';
            $field_value = time();
            $field_msg = '删除';
        }

        $result = Db::name('goods')->where(["id" => $id])->setField($field, $field_value);
        if ($result != false) {
            $this->success("{$field_msg}成功!");
        } else {
            $this->error("{$field_msg}失败!");
        }
    }









}