<?php
/**
 * 点评标签分组
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author zhaoh <1070309178@qq.com>
 */
namespace Admin\Controller;
class DpGroupController 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);
        if(empty($list)){
	  $data=array();
	  $data['name']='商品标签';
	  $data['memo']='用于购买仓库商品后评价使用';
	  $data['preset']='味道不错 实惠 赞 哈哈哈';
	  $data['allow_dp']=0;
	  $data['allow_search']=0;
	  $data['allow_vote']=0;
	  $data['sort']=100;
	  M('DpGroup')->add($data);
	  $data['name']='服务标签';
	  $data['memo']='用于购买仓库服务后评价使用';
	  $data['preset']='服务周到 全心全意 棒棒哒';
	  $data['allow_dp']=0;
	  $data['allow_search']=0;
	  $data['allow_vote']=0;
	  $data['sort']=100;
	  M($name)->add($data);
	  $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('DpGroup')->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['memo']=$postdata['memo'];
		$data['preset']=$postdata['preset'];
		if($id){
			$map['id']=$id;
			$res=M('DpGroup')->where($map)->save($data);
			if($res===false){
				$this->error('编辑失败');
			}else{
				$msg = '编辑成功';
			}
		}else{
			$id=M('DpGroup')->add($data);
			if(!$id){
				$this->error('添加失败');
			}else{
				$msg = '添加成功';
			}
		}
		$this->success($msg,U('DpGroup/index'));
    }
}