<?php
/**
 * 点评评分分组
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author zhaoh <1070309178@qq.com>
 */
namespace Admin\Controller;
class PointGroupController extends BaseController{
    public function _initialize(){
        parent::_initialize();
		$map['pid']=0;$map['status']=1;
    }
    /**
     * 评分分组列表
     */
    public function index(){
        $name = CONTROLLER_NAME;
        $postdata = I('param.');
		if(!empty($postdata['keyword'])){
			$map_or['name']=array('like','%'.$postdata['keyword'].'%');
			$map_or['id']=$postdata['keyword'];
			$map_or['_logic']='or';
			$map['_complex']=$map_or;
		}
        $list = $this->lists($name, $map);
        $this->assign('list', $list);
        $this->assign($postdata);
        $this->display();
    }
	public function _before_edit(){
		$id=I('id');if(!$id)$this->error('参数不正确！');
		$info=M('PointGroup')->where('id='.$id)->field(true)->find();
        $this->assign('info',$info);
	}
    /**
     * 编辑分组
     */
    public function edit_group(){
        $postdata = I('param.');
		$id=$postdata['id'];
		
		$data['name']=$postdata['name'];
		$data['sort']=$postdata['sort'];
		if($id){
			$map['id']=$id;
			$res=M('PointGroup')->where($map)->save($data);
			if($res===false)$this->error('编辑失败');
		}else{
			$id=M('PointGroup')->add($data);
			if(!$id)$this->error('添加失败');
		}
		$this->success('操作成功',U('PointGroup/index'));
    }
}