<?php


namespace app\admin\controller;


use think\facade\Request;
use think\facade\Db;

class Message extends  Base
{

    //公众号提交的留言列表
    public function messageList(){
        $page = Request::param('page',1);
        $limit = Request::param('limit',config('app.limit'));
        $list =Db::name('message')->alias('m')->page($page,$limit)->order('create_time','desc')->select()->toArray();
        foreach ($list as $k =>$v) {
            $list[$k]['content'] =  mb_substr($v['content'],0,50,'utf-8');
            switch ($v['from']){

                case 1:
                    $list[$k]['from'] = "客满了官网";
                    break;
                case 2:
                    $list[$k]['from'] = "睿者智能官网";
                    break;
                case 3:
                    $list[$k]['from'] = "客满了公众号";
                    break;
                case 4:
                    $list[$k]['from'] = "睿者智能公众号";
                    break;
            }
        }
        $count =Db::name('message')->count();
        $res['total'] = $count;
        $res['data'] = changeField($list);
        return $this->returnJson($res,'success');
    }


    //意见反馈详情
    public function messageDetail(){
        $id = Request::param('message_id');
        $where['message_id'] = $id;
        $info = Db::name('message')->where($where)->find();
        if($info) {
            return $this->returnJson(changeField($info),'success');
        } else {
            return $this->returnJson([],'未找到该数据!',400);
        }
    }

    public function messageDel(){
        $id = Request::param('message_id');
        $where['message_id'] = $id;
        $info = Db::name('message')->where($where)->delete();
        if($info) {
            return $this->returnJson([],'删除成功!');
        } else {
            return $this->returnJson([],'未找到该数据!',400);
        }
    }


    public function changeMessage()
    {
        $id = Request::param('message_id');
        $where['message_id'] = $id;
        $data['is_operation'] = 1;
        $info = Db::name('message')->where($where)->update($data);
        if($info) {
            return $this->returnJson([],'标注成功!');
        } else {
            return $this->returnJson([],'未找到该数据!',400);
        }

    }

}