<?php
// +----------------------------------------------------------------------
// | 文海代码生成器
// +----------------------------------------------------------------------
// | Copyright (c) 2021 https://www.kaifashu.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 开发树
// +----------------------------------------------------------------------

namespace app\admin\controller;
use app\common\model\MessageForm as MessageFormModel;
/**
 *学校
 */
class MessageForm extends Auth
{
    /**
     * 列表
     */
    public function index(){
        $param=[
            'nickname'=>''
        ];
        $param=$this->initParam($param);
        $map[] = ['status','>',-1];
        if($param['nickname']!=''){
            $map[]=['name','like','%'.$param['nickname'].'%'];
        }
        $model=new MessageFormModel();
        $lists=$model
        ->where($map)-> order('create_time desc')
            ->paginate($this->config['LIST_ROWS'],false,['query' => $this->getRouteQuery()]);
        $this->assign('lists',$lists);
        $this->assign('param',$param);
        return $this -> fetch();
    }
    /**
     * 留言详情
     */
    public function details($id = 0) {
        $model=new MessageFormModel();
        $linkInfo = $model -> get($id);
        $this -> assign('info', $linkInfo);
        $this -> assign('id', $id);
        $this -> meta_title = '留言详情';
        return $this -> fetch();
    }

    /**
     * 删除
     */
    public function del(){
        $id=$this->request->param('ids/a');
        $thisModel=new MessageFormModel();
        //伪删除
        $where[] =['id','in',$id];
        $re=$thisModel->save([
            'status'  => -1
        ],$where);
        if($re){
            //添加行为记录
            action_log("messageform_del", "message_form", $id, session('UID'));
            $this->success('删除成功！');
        }
        else{
            $this->error($thisModel->getError());
        }
    }
}