<?php
class SystemAction extends GlobalAction{
    /**
	 * 列表
	 *
	 */
    public function index(){
		
		$memberConfig = D('memberConfig');
		$config = $memberConfig->where('id = 1')->find();
		$this->assign('config',$config);

		if($_POST){
			if($memberConfig->create()){
				if(false !== $memberConfig->save()){
					$this->success('更新成功');				
				}else{
					$this->error('没有任何更新');
				}
			}
		}

		$this->display();
    }

    //修改密码
    public function options(){

    	if($_POST){


    		if(empty($_POST['pwd1'])){
    			$this->error('请输入原密码');
    		}

    		if(empty($_POST['pwd2'])){
    			$this->error('请输入新密码');
    		}

    		if(empty($_POST['pwd3'])){
    			$this->error('请输入确认新密码');
    		}

    		if($_POST['pwd3'] !== $_POST['pwd2']){
    			$this->error('请输入的密码不一致！');
    		}

    		$username =  $this->username;
    		$Admin = D('Admin');
    		$checkPwd = $Admin->where("username = '{$username}'")->find();
    		if($checkPwd['password'] !== adminmymd5($_POST['pwd1'])){
    			$this->error('请输入旧密码不正确！');
    		}
    		
    		$condition['username'] = $username;
    		$data['password'] = adminmymd5(trim($_POST['pwd2']));
   			$result = $Admin->where($condition)->save($data);
			if($result){
				$this->assign('jumpUrl',$_POST['returnurl']);
				$this->success('更新成功');					
			}else{
				$this->error('没有任何更新');
			}
    	}
    	$this->display();
    }


    public function shoudong(){

    	

    	if($_POST){
    		$nper = (int)$_POST['number'];
    		//记录指向开奖
			$MemberRaceManal = D('MemberRaceManal'); 
			$resultF = $MemberRaceManal->where("nper = '{$nper}'")->find();
			if($resultF){
				//更新
				$data['manalvalue'] = (int)$_POST['results'];
				$result = $MemberRaceManal->where("nper = '{$nper}'")->save($data);
				if($result){
					$this->success('更新成功');					
				}else{
					$this->error('没有任何更新');
				}
			}else{
				//插入
				$data['nper'] = (int)$_POST['number'];
				$data['manalvalue'] = (int)$_POST['results'];
				$result = $MemberRaceManal->add($data);
	    		if($result){
					$this->success('添加成功');					
				}else{
					$this->error('没有任何添加');
				}
			}
    	}

    	$this->display();	
    }

  

    /**
	 * 更新缓存
	 *
	 */
    public function clear(){
		clearCore();
		$this->assign('jumpUrl',U('Index/main'));
		$this->success('缓存更新成功');

	}	
}
?>