首頁 > php教程 > PHP源码 > 主體

前一任的神级代码,速来膜拜

PHP中文网
發布: 2016-05-25 16:58:32
原創
1203 人瀏覽過

[PHP]代码 

<?php
/**
 * App用户注册接口
 * return: json
 */
public function signup_old(){
	$yyUser = M(&#39;table.user&#39;,&#39;youyax_&#39;);
	$data[&#39;user&#39;] = $_POST[&#39;userName&#39;];
	$data[&#39;telephone&#39;] = $_POST[&#39;telephone&#39;];
	$password = $_POST[&#39;password&#39;];
	$repassword = $_POST[&#39;repassword&#39;];
	$data[&#39;beAgent&#39;] = $_POST[&#39;beAgent&#39;];
	$data[&#39;realName&#39;] = $_POST[&#39;realName&#39;];
	$data[&#39;email&#39;] = $_POST[&#39;email&#39;];
	$data[&#39;credit&#39;] = I(&#39;identityCard&#39;);
	if(empty($data[&#39;user&#39;]) || empty($password) || empty($repassword) || empty($data[&#39;email&#39;]) ){
		$arr[&#39;code&#39;] = 0;
		$arr[&#39;message&#39;] = &#39;必填项不能为空!&#39;;
		echo json_encode($arr);
		return false;
	}
	$lenP = strlen($password);
	if($lenP < 6 || $lenP >20){
		$arr[&#39;code&#39;] = 0;
		$arr[&#39;message&#39;] = &#39;密码必须为6-20位!&#39;;
		echo json_encode($arr);
		return false;
	}
	if( empty($data[&#39;beAgent&#39;]) ){
		$data[&#39;beAgent&#39;] = 0;
	}
	if($data[&#39;beAgent&#39;] == 1){
		if(empty($data[&#39;realName&#39;]) || empty($data[&#39;telephone&#39;]) || empty($data[&#39;credit&#39;])){
			$arr[&#39;code&#39;] = 0;
			$arr[&#39;message&#39;] = &#39;经纪人必须填写手机号、真实姓名、身份证号!&#39;;
			echo json_encode($arr);
			return false;
		}
		$creditLength = strlen($data[&#39;credit&#39;]);
		if (!in_array($creditLength, array(15, 18)))
			$this->response(0, &#39;身份证号码不合法&#39;);
	}
	$verifyE = $this->checkEmail($data[&#39;email&#39;]);
	if($verifyE){
		$email = $data[&#39;email&#39;];
		$mapE[&#39;email&#39;] = array(&#39;in&#39;,$email);
		$count = $yyUser->where($mapE)->count();
		if($count==0){
			if($repassword == $password){
				$data[&#39;pass&#39;] = md5($password);
				$userName = $data[&#39;user&#39;];
				$mapU[&#39;user&#39;] = array(&#39;in&#39;,$userName);
				$count = $yyUser->where($mapU)->count();
				if($count==0){
					$tel = $data[&#39;telephone&#39;];
					$verifyT = $this->checkTel($tel);
					if( !empty($data[&#39;telephone&#39;])){
						if(!$verifyT){
							$arr[&#39;code&#39;] = 0;
							$arr[&#39;message&#39;] = &#39;不是正确的手机号码!&#39;;
							echo json_encode($arr);
							return false;
						}
						$mapT[&#39;telephone&#39;] = array(&#39;in&#39;,$tel);
						$count = $yyUser->where($mapT)->count();
						if($count!=0){
							$arr[&#39;code&#39;] = 0;
							$arr[&#39;message&#39;] = &#39;手机号码已被使用!&#39;;
							echo json_encode($arr);
							return false;
						}
					}
					$data[&#39;status&#39;] = 1;
					$bools = $yyUser->add($data);
					if($bools){
						$id = $yyUser->field(&#39;id&#39;)->where(&#39;user = &#39;.&#39;"&#39;.$data[&#39;user&#39;].&#39;"&#39;)->select();
						$userId = $id[0][&#39;id&#39;];
						$arr[&#39;code&#39;] = 1;
						$arr[&#39;message&#39;] = &#39;注册成功!&#39;;
						$arrData[&#39;userId&#39;] = $userId;
						$arrData[&#39;userName&#39;] = $data[&#39;user&#39;];
						$arrData[&#39;beAgent&#39;] = $data[&#39;beAgent&#39;];
						$arrData[&#39;realName&#39;] = $data[&#39;realName&#39;];
						$arrData[&#39;password&#39;] = $data[&#39;pass&#39;];
						$arrData[&#39;email&#39;] = $data[&#39;email&#39;];
						$arr[&#39;data&#39;] = $arrData;
						echo json_encode($arr);
					}else {
						$arr[&#39;code&#39;] = 0;
						$arr[&#39;message&#39;] = &#39;注册失败,系统异常,请重新注册!&#39;;
						echo json_encode($arr);
					}
				}else {
					$arr[&#39;code&#39;] = 0;
					$arr[&#39;message&#39;] = &#39;用户名已被使用!&#39;;
					echo json_encode($arr);
				}
			}else {
				$arr[&#39;code&#39;] = 0;
				$arr[&#39;message&#39;] = &#39;密码不一致!&#39;;
				echo json_encode($arr);
			}
		}else {
			$arr[&#39;code&#39;] = 0;
			$arr[&#39;message&#39;] = &#39;手机号码已被使用!&#39;;
			echo json_encode($arr);
		}
	}else {
		$arr[&#39;code&#39;] = 0;
		$arr[&#39;message&#39;] = &#39;手机号码不合法&#39;;
		echo json_encode($arr);
	}
}
登入後複製

                   

                   

相關標籤:
php
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門推薦
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!