<?php
class ServeAction extends Action {
	public function checkUser($level){
		if(empty($_SESSION['aid'])) $this->redirect('/Admin/Index/login');
		if(!empty($level) && !in_array($level,$_SESSION['levels'])) $this->error('您没有此权限!.');
	}
	public function index(){
		$this->checkUser('1_4_1');
		$data = M('Serve');
		$list = $data->order('taxis')->select();
		$this->assign('list',$list);
		$this->display();
	}
	public function add(){
		$this->checkUser('1_4_2');
		$this->display();
	}
	public function check(){
		if(empty($_POST['name']) || !isset($_POST['kind']) || empty($_POST['number']) || empty($_POST['taxis'])) $this->error('所有选项都不能为空喔，亲!');	
		$this->checkUser('1_4_2');
		unset($_POST['__hash__']);
		$data = M('Serve');
		if(!$data->add($_POST)) $this->error('添加客服失败!');
		$this->assign('jumpUrl','__URL__/index/');
		$this->success('添加客服成功! ^_^');
	}
	public function edit(){
		$this->checkUser('1_4_2');
		$id = (int)$_GET['id'];
		$data = M('Serve');
		$list = $data->where("id = $id")->find();
		$this->assign('list',$list);
		$this->display();
	}
	public function amend(){
		if(empty($_POST['name']) || !isset($_POST['kind']) || empty($_POST['number']) || empty($_POST['taxis'])) $this->error('每一样都得留下！');	
		$this->checkUser('1_4_2');
		unset($_POST['__hash__']);
		$data = M('Serve');
		if(!$data->save($_POST)) $this->error('修改客服信息失败!');
		$this->assign('jumpUrl','__URL__/index/');
		$this->success('修改客服信息成功! ^_^');
	}
	public function del(){
		$this->checkUser('1_4_2');
		$id = (int)$_GET['id'];
		$data = M('Serve');
		if(!$data->where("id = $id")->delete()) $this->error('删除失败!请联系网络管理员!');
		$this->success('删除成功!');
	}
	public function stop(){
		$this->checkUser('1_4_2');
		$list['id'] = (int)$_GET['id'];
		$list['state'] = (int)$_GET['state'];
		$data = M('Serve');
		if(!$data->save($list)) $this->error('操作失败!请重试');
		$this->success('操作成功!');
	}
}
?>	