<?php
if (!defined('puyuetian')) {
	exit('403');
}

if (!$_G['USER']['ID']) {
	ExitGourl('index.php?c=login&from=sms_reg');
}

if ($_G['GET']['SUBMIT'] == 'yes') {
	$phone = Cstr($_POST['phone'], false, $_G['STRING']['NUMERICAL'], 11, 11);
	if (substr($phone, 0, 1) != 1 || !$phone) {
		ExitJson('手机号不正确');
	}
	if ($_G['TABLE']['USER'] -> getId('phone', $phone)) {
		ExitJson('手机号已存在');
	}
	if ($_SESSION['APP_PUYUETIAN_SMS_PHONE'] != $phone) {
		ExitJson('接收短信手机号与提交的手机号不一致');
	}
	if ($_SESSION['APP_PUYUETIAN_SMS_CODE'] != $_POST['code'] || !$_POST['code']) {
		ExitJson('短信验证码错误');
	}
	if ($_G['TABLE']['USER'] -> newData(array('id' => $_G['USER']['ID'], 'phone' => $phone))) {
		//$_SESSION['APP_PUYUETIAN_SMS_PHONE'] = $_SESSION['APP_PUYUETIAN_SMS_CODE'] = '';
		ExitJson('修改成功', true);
	} else {
		ExitJson('修改失败');
	}
}
$_G['SET']['WEBTITLE'] = '换绑手机号';
$_G['TEMPLATE']['BODY'] = 'hadskycloudserver:sms_changephone';
