ZjCommentController.php 2.2 KB
<?php
/**
 * Created by PhpStorm.
 * User: wz
 * Date: 2018/7/4
 * Time: 16:42
 */

namespace app\admin\controller;


use ClassesWithParents\D;
use cmf\controller\AdminBaseController;
use think\Db;

class ZjCommentController extends AdminBaseController
{
    /**
     * 评论管理首页
     */
    public function index()
    {
        $where=[];
        if ($this->request->isPost()){
            $in=input('post.');
            if (strlen($in['ser_type'])>'0'){
                $where['s.ser_type']=$in['ser_type'];
            }
            if (strlen($in['name'])>'0'){
                $where['s.id']=$in['name'];
            }
            if (strlen($in['level'])>'0'){
                $where['c.level']=$in['level'];
            }
        }
        $com=Db::name('zj_comment')->alias('c')->join('user u','c.user_id=u.id')->join('zj_service s','c.service_id=s.id')->field('c.*,u.user_nickname as uname')->where($where)->paginate('10');
        $service=Db::name('zj_service')->field('id,name,ser_type')->select();//查询服务名称 联动筛选

        $this->assign('allservice',$service);
        $this->assign('allcom',$com);
        return $this->fetch();
    }

    /**
     * 评论显示与隐藏
     */
    public function comstate()
    {
        $param=$this->request->param();
        if ($param){
            $id=$this->request->param('ids/a');
            if ($param['yes']=='1'){
                $com=Db::name('zj_comment')->where(['id'=>['in',$id]])->update(['is_sta'=>'1']);
            }else{
                $com=Db::name('zj_comment')->where(['id'=>['in',$id]])->update(['is_sta'=>'0']);
            }
            if ($com){
                $this->success('评论可见度修改成功','');
            }else{
                $this->error('评论可见度修改失败');
            }
        }
    }

    /**
     * 删除评论
     */
    public function delete()
    {
        if ($this->request->param()){
            $id=$this->request->param('ids/a');
            $del=Db::name('zj_comment')->where(['id'=>['in',$id]])->delete();
            if($del){
                $this->success('评论删除成功','');
            }else{
                $this->error('评论删除失败');
            }
        }
    }

}