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

use cmf\controller\AdminBaseController;
use app\portal\model\CommentModel;
use think\Db;

class CommentController extends AdminBaseController
{
    protected $targets = ["_blank" => "新标签页打开", "_self" => "本窗口打开"];

    //首页
    public function index(){
        $comment = Db::name('comment')
            ->alias('c')
            ->join('user u','c.user_id = u.id','LEFT')
            ->field('c.*,u.user_nickname nickname,u.avatar')
            ->select();
        $this->assign('comment', $comment);
        return $this->fetch();
    }

    //删除
    public function delete(){
        $id = $this->request->param('id', 0, 'intval');
        CommentModel::destroy($id);
        $this->success("删除成功!", url("comment/index"));
    }

    //审核通过与驳回
    public function toggle()
    {
        $data      = $this->request->param();
        $CommentModel = new CommentModel();

        if (isset($data['ids']) && !empty($data["display"])) {
            $ids = $this->request->param('ids/a');
            $CommentModel->where('id', 'in', $ids)->update(['status' => 1]);
            $this->success("更新成功!");
        }

        if (isset($data['ids']) && !empty($data["hide"])) {
            $ids = $this->request->param('ids/a');
            $CommentModel->where('id', 'in', $ids)->update(['status' => 2]);
            $this->success("更新成功!");
        }

    }

}