CommentController.php 6.0 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 CommentController extends AdminBaseController
{
    public  $table_name = 'commente';
    public  $table_name1 = 'commente1';
    public  $table_name_tag = 'commente_tag';

/***标签管理***/
    //评论标签管理
    public function tag(){

        $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['type'] = $data['type'];
            $datain['create_time'] = time();

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

            if ($result) {
                $this->success('添加成功!', url('tag'));
            }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['type'] = $data['type'];
            $datain['name'] = $data['name'];
            $datain['create_time'] = time();

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

            if ($result) {
                $this->success('保存成功!', url('tag'));
            }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 trainer(){
        $param = $this->request->param();

        $name = empty($param['name']) ? '' : $param['name'];
        if (!empty($name)) {
            $where['u.user_nickname'] = $name;
        }
        $mobile = empty($param['mobile']) ? '' : $param['mobile'];
        if (!empty($mobile)) {
            $where['mobile'] = $mobile;
        }
        $where['c.delete_time'] = 0;
        $list = DB::name($this->table_name)
            ->alias('c')
            ->join('qnb_user u','u.id=c.teach_id')
            ->order('create_time desc')
            ->field('c.*')
            ->where($where)
            ->paginate(15);

        $this->assign("list", $list->items());
        $this->assign('page', $list->render());
        return $this->fetch();
    }

    public function del_trainer(){
        $id                     = $this->request->param('id');
        if(!$id){
            $this->error('删除失败');
        }
        $result = DB::name($this->table_name)->where(['id'=>$id])->delete();
        if ($result) {
            $this->success('删除成功!');
        } else {
            $this->error('删除失败');
        }
    }

    //学生评价
    public function student(){
        $param = $this->request->param();

        $name = empty($param['name']) ? '' : $param['name'];
        if (!empty($keyword)) {
            $where['u.nick_nickname'] = $name;
        }
        $mobile = empty($param['mobile']) ? '' : $param['mobile'];
        if (!empty($mobile)) {
            $where['mobile'] = $mobile;
        }
        $list = DB::name($this->table_name1)
            ->alias('c')
            ->join('qnb_user u','u.id=c.uid')
            ->field('c.*')
            ->order('create_time desc')
            ->where(['c.delete_time'=>0])
            ->paginate(15);

        $this->assign("list", $list->items());
        $this->assign('page', $list->render());
        return $this->fetch();
    }

    public function del_student(){
        $id                     = $this->request->param('id');
        if(!$id){
            $this->error('删除失败');
        }
        $result = DB::name($this->table_name1)->where(['id'=>$id])->delete();
        if ($result) {
            $this->success('删除成功!');
        } else {
            $this->error('删除失败');
        }
    }












}