PlayRuleController.php 2.0 KB
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/9
 * Time: 16:05
 */
namespace app\admin\controller;
use api\common\model\CommonModel;
use app\admin\model\PlayRuleModel;
use cmf\controller\AdminBaseController;
use Think\Model;




class PlayRuleController extends AdminBaseController{
    //index方法
    public function index()
    {
        $playruleModel=new PlayRuleModel();
        $lists=$playruleModel->getPlayRule();
        $this->assign('list',$lists);
        return $this->fetch();
    }
    //编辑规则
    public function edit()
    {
        $id = $this->request->param('id', 0, 'intval');
        $playruleModel=new PlayRuleModel();
        $post=$playruleModel->edit($id);
        $this->assign('post',$post);
        return $this->fetch();

    }
    //编辑规则提交
    public function editPost()
    {
        $data = $this->request->param();

        $playruleModel=new PlayRuleModel();
//        $result=$this->allowField(true)->isUpdate(true)->data($data, true)->save();
        $result=$playruleModel->editPost($data['post']['id'],$data['post']['name'],htmlspecialchars_decode($data['post']['content']));
        if ($result) {
            return $this->success('编辑成功');
        }
    }
    //规则添加
    public function add()
    {
        return $this->fetch();
    }
    //规则添加提交
    public function addPost()
    {
        $data=$this->request->param();
        $data['post']['create_time']=time();

        $playruleModel=new PlayRuleModel();
        $result=$playruleModel->addPost( $data['post']['name'],htmlspecialchars_decode($data['post']['content']),$data['post']['create_time']);
        if ($result){
            return $this->success('添加成功','index');
        }
    }
    //规则删除
    public function deletePlayRule()
    {
        $id = $this->request->param('id', 0, 'intval');
        $playruleModel=new PlayRuleModel();
        $result=$playruleModel->deletePlayRule($id);
        if ($result){
            return $this->success('删除成功');
        }
    }
}