$instance
$instance : object
Reference to the CI singleton
Application Controller Class
This class object is the super class that every library in CodeIgniter will be assigned to.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Reg extends CI_Controller 
{
    private static $data = array();
    public function __construct()
    {
        parent::__construct();
       
        $this->load->model('Webcommon_model','common');
        $this->load->model('User_model','user');
        $this->load->model('Userinfo_model','userinfo');
        $this->load->model('Usercount_model','usercount');
$this->load->model('Userpoints_model','userpoints');
    }
    
    /**
     * 注册
     * */
    public function reg()
    {
        $phone = trim($this->input->get_post('phone'));
        $password   = trim($this->input->get_post('password'));//用户密码
       $confirmPassword = trim($this->input->get_post('confirmPassword'));
        $token = $this->input->get_post('token');
        $regphone = "/^(13|15|17|18|14)[0-9]{9}$/";
        $fverifycode = trim($this->input->get_post('fverifycode'));
        if(empty($phone))
        {
            echo $this->common->returnArray ( array ('userId'=>''), '手机号不能为空', 100010 );exit;
        }
        else if(!preg_match($regphone, $phone))
        {
            echo $this->common->returnArray ( array ( 'list' => '' ), '手机格式不正确', 100011 );exit;
        }
        else
        {
            $data = $this->user->checkUnique(trim($phone));
            if(!empty($data))
            {
                echo $this->common->returnArray ( array ( 'list' => '' ), '手机号已存在', 100012 );exit;
            }
        }
        if(empty($fverifycode))
        {
            echo $this->common->returnArray ( array ('userId'=>''), '请输入验证码', 400012 );exit;
        }
        $regpass ='/^[a-zA-Z0-9 &!#$%()*+,-=.\/:;?@\[\]^_`<>{|}~]{6,8}$/';
        
        
        if(empty($password))
        {
            echo $this->common->returnArray ( array ( 'list' => '' ), '请输入密码', 200018 );exit;
        }
	    else if(!preg_match($regpass, $password))
	    {
	        echo $this->common->returnArray ( array ( 'list' => '' ), '密码格式不正确', 200013);exit;
	    }else if($confirmPassword != $password)
         {
             echo $this->common->returnArray ( array ( 'list' => '' ), '两次密码输入不一致', 200019);exit;
        }
	   
        $stime = $this->input->get_post('stime');
        $etime = $this->input->get_post('etime');
        $verifycode = $this->input->get_post('verifycode');
        $yanphone = $this->input->get_post('yanphone');
        
        $fphone = $this->input->get_post('fphone');
        $time = $etime-$stime;
        if($fverifycode != $verifycode && $yanphone !=$fphone )
        {
            echo $this->common->returnArray ( array ( 'list' => '' ), '验证码不正确', 400010 );exit;
        }
        if( $time>120 )
        {
            echo $this->common->returnArray ( array ( 'list' => '' ), '验证码已过期',400012);exit;
        }
        
        $userData = array(
                'phone' => $phone,
                'typeFlag'=>2,
                'createTime' => time(),
                'password' => md5($password),
                'token' => $token
                );
      
        $userId = $this->user->insertData($userData);
        $userInfoData = array(
                'userId' =>$userId,
                'typeFlag' =>2
        );
        $this->userinfo->insertData($userInfoData);
        $countData = array(
                'userId' => $userId,
                'firstTime' => time(),
                'firstIP' => $_SERVER['REMOTE_ADDR'],
                'jifenNum' => 30,
                'loginNum'=>1
                );
        $this->usercount->insertData($countData);
        $msg ='注册获得30积分';
        $countuserdata = array(
                'userId' => $userId,
                'operandType' =>$msg,
                'listId' => 0,
                'operandNum' => 30,
                'typeFlag' => 6,
                'changeTime' => time(),
                'flag'=> 2
        );
        $this->userpoints->insertData( $countuserdata );
        echo $this->common->returnArray ( array ('userId'=>$userId), '注册成功', 200 );exit;
    }
         
    /**
     * 退出登录
     *
     * @author lxn
     * @param userId Internet 必选  用户ID
     * @param token  String   必选  用户token值
     *
     * @return json
     */
    public function logout()
    {
        $userId = (int)trim($this->input->get_post('userId'));
        $token  = (string)trim($this->input->get_post('token'));
    
        if(empty($userId ) || empty($token) )
        {
            echo $this->common->returnArray ( array ( 'list' => '' ), '请登录', 3);exit;
        }
        $data   = array('token' => "");//统计表更新数据
        $updateStatus = $this->user->setUserById($data, $userId );
        echo $this->common->returnArray(array('list' => ''),'退出成功',200);
    }
    /**
     * 找回密码并设置新密码
     *
     * @author lxn
     * @时间              2015-5-22 16:04:37
     * @访问地址    ROOT/app/user/findPassWord
     *
     * @param phone        String  必选 用户手机号
     * @param userPassWord String  必选 新密码
     * @param randomCode   Integer 必选 发送的随机码
     *
     * @return json
     */
    public function findpassword()
    {
        $phone  = (string)trim($this->input->get_post('phone'));
        $password = trim($this->input->get_post('password'));
//         $confirmPassword = trim($this->input->get_post('confirmPassword'));
        $verifycode = trim($this->input->get_post('verifycode'));
        $fverifycode = $this->input->get_post('fverifycode');
        if (empty($verifycode) || empty($password) || empty($phone))
        {
            echo $this->common->returnArray(array('list' => ''), '参数错误', 1);
            exit;
        }
        $data = $this->user->checkUnique( $phone );
        $regphone = "/^(13|15|17|18|14)[0-9]{9}$/";
        if(empty($phone))
        {
            echo $this->common->returnArray ( array ('userId'=>''), '手机号不能为空', 100010 );exit;
        }
        else if(!preg_match($regphone, $phone))
        {
            echo $this->common->returnArray ( array ( 'list' => '' ), '手机格式不正确',100011 );exit;
        }
        else
        {
           
            if(empty($data))
            {
                echo $this->common->returnArray ( array ( 'list' => '' ), '手机号没有注册', 100013 );exit;
            }
        }
        if(empty($fverifycode))
        {
            echo $this->common->returnArray ( array ('userId'=>''), '请输入验证码',400012 );exit;
        }
        $regpass ='/^[a-zA-Z0-9 &!#$%()*+,-=.\/:;?@\[\]^_`<>{|}~]{6,8}$/';
        if(empty($password))
        {
            echo $this->common->returnArray ( array ( 'list' => '' ), '请输入密码', 200018 );exit;
        }
        else if(!preg_match($regpass, $password))
        {
            echo $this->common->returnArray ( array ( 'list' => '' ), '密码格式不正确',200013 );exit;
        }
//         if($confirmPassword != $password)
//         {
//             echo $this->common->returnArray ( array ( 'list' => '' ), '两次密码输入不一致', 200019);exit;
//         }
       
        $stime = $this->input->get_post('stime');
        $etime = $this->input->get_post('etime');
        $fphone = $this->input->get_post('fphone');
        $time = $etime-$stime;
        if($fverifycode != $verifycode && $phone !=$fphone )
        {
            echo $this->common->returnArray ( array ( 'list' => '' ), '验证码不正确', 400010 );exit;
        }
        if( $time>120 )
        {
            echo $this->common->returnArray ( array ( 'list' => '' ), '验证码已过期', 400011 );exit;
        }        
        $uodateData = array('password' => md5($password));
        $this->user->setUserById( $uodateData,$data['userId']);
        echo $this->common->returnArray(array('list' => ''), '修改成功',200);
    }
    
    /**
     *获取验证码
     * */
    public function checksms()
    {
       
        $mobilephone = $this->input->get_post('phone');
        if(empty($mobilephone))
        {
            echo $this->common->returnArray ( array ( 'list' => '' ), '手机格式不正确', 100011 );exit;
        }
        $code = rand(10000,99999);
        $smsres = $this->common->sendSms($mobilephone,$code);
    
        echo $this->common->returnArray(array('stime' => time(),'verifycode'=>$code,'phone'=>$mobilephone), '验证码已发送', 200);
    }
    
    
    
    /**
     * 修改密码
     *
     * @author lxn
    
     * @param phone String 必选 用户手机号
     * @param oldPW String 必选 原密码
     * @param newPW String 必选 新密码
     *
     * @return json
     */
    public function setpassword()
    {
        $userId   	  = trim($this->input->get_post('userId'));
        $token   	  = trim($this->input->get_post('token'));
        
       if(empty($token)&&empty($userId))
       {
           echo $this->common->returnArray(array('list' => ''), '参数错误', 1);
           exit;
       }
        
        $userPassword = trim($this->input->get_post('oldpw'));
        $newPassword  = trim($this->input->get_post('newpw'));
    
        if (empty($userPassword) || empty($userPassword) || empty($newPassword))
        {
            echo $this->common->returnArray(array('list' => ''), '参数错误', 1);
            exit;
        }
        $this->common->getLoginStuate($userId, $token);//登录账户验证,互踢
        $userInfo = $this->user->getUserRow( $userId );
    
        if (md5($userPassword) != $userInfo['password'])
        {
            echo $this->common->returnArray(array('list' => ''), '原密码错误', 200020);
            exit;
        }
        $regpass ='/^[a-zA-Z0-9 &!#$%()*+,-=.\/:;?@\[\]^_`<>{|}~]{6,8}$/';
        if(empty($newPassword))
        {
            echo $this->common->returnArray ( array ( 'list' => '' ), '请输入新密码', 200012 );exit;
        }
        else if(!preg_match($regpass, $newPassword))
        {
            echo $this->common->returnArray ( array ( 'list' => '' ), '新密码格式不正确', 200021);exit;
        }
        $userId = $userInfo['userId'];
        $uodateData = array('password' => md5($newPassword));
      
        $this->user->setUserById( $uodateData,$userId);
        echo $this->common->returnArray(array('list' => ''),'修改成功',200);
    }
/**
     * 找回支付密码并设置新密码
     *
     * @author lxn
     * @时间              2015-5-22 16:04:37
     * @访问地址    ROOT/app/user/findPassWord
     *
     * @param phone        String  必选 用户手机号
     * @param userPassWord String  必选 新密码
     * @param randomCode   Integer 必选 发送的随机码
     *
     * @return json
     */
    public function findpaypassword()
    {
 	$userId = trim($this->input->get_post('userId'));
        $token  = trim($this->input->get_post('token'));
        
       if(empty($token)||empty($userId))
       {
           echo $this->common->returnArray(array('list' => ''), '参数错误', 1);
           exit;
       }
        $phone  = (string)trim($this->input->get_post('phone'));
        $password = trim($this->input->get_post('payPassword'));
        $confirmPassword = trim($this->input->get_post('confirmPayPassword'));
        $verifycode = trim($this->input->get_post('verifycode'));
        $fverifycode = $this->input->get_post('fverifycode');
        if (empty($verifycode) || empty($password) || empty($phone))
        {
            echo $this->common->returnArray(array('list' => ''), '参数错误', 1);
            exit;
        }
        $user = $this->user->getUserRow( $userId );
    	if(empty($user['phone']))
    	{
    		$userPhone = $user['userName'];
    	}
    	else if(empty($user['userName'])&&$user['userName']!=0)
    	{
    		$userPhone = $user['email'];
    	}
    	else
    	{
    		$userPhone = $user['phone'];
    	 }
        //$data = $this->user->checkUnique( $phone );
        $regphone = "/^(13|15|17|18|14)[0-9]{9}$/";
        if(empty($phone))
        {
            echo $this->common->returnArray ( array ('userId'=>''), '手机号不能为空', 100010 );exit;
        }
        else if(!preg_match($regphone, $phone))
        {
            echo $this->common->returnArray ( array ( 'list' => '' ), '手机格式不正确',100011 );exit;
        }
        else if($userPhone != $phone)
        {
              echo $this->common->returnArray ( array ( 'list' => '' ), '手机号没有注册', 100013 );exit; 
        }
        if(empty($fverifycode))
        {
            echo $this->common->returnArray ( array ('userId'=>''), '请输入验证码',400012 );exit;
        }
        $regpass ='/^[a-zA-Z0-9 &!#$%()*+,-=.\/:;?@\[\]^_`<>{|}~]{6,8}$/';
        if(empty($password))
        {
            echo $this->common->returnArray ( array ( 'list' => '' ), '请输入密码', 200018 );exit;
        }
        else if(!preg_match($regpass, $password))
        {
            echo $this->common->returnArray ( array ( 'list' => '' ), '密码格式不正确',200013 );exit;
        }
        if($confirmPassword != $password)
        {
            echo $this->common->returnArray ( array ( 'list' => '' ), '两次密码输入不一致', 200019);exit;
        }
       
        $stime = $this->input->get_post('stime');
        $etime = $this->input->get_post('etime');
        $fphone = $this->input->get_post('fphone');
        $time = $etime-$stime;
        if(($fverifycode != $verifycode) || ($phone !=$fphone) )
        {
            echo $this->common->returnArray ( array ( 'list' => '' ), '验证码不正确', 400010 );exit;
        }
        if( $time>120 )
        {
            echo $this->common->returnArray ( array ( 'list' => '' ), '验证码已过期', 400011 );exit;
        }        
        $uodateData = array('payPassword' => md5($password));
        $this->user->setUserById( $uodateData,$userId);
        echo $this->common->returnArray(array('list' => ''), '修改成功',200);
    }
  
}