<?
// 社会用户注册1【非机构】
require_once ("../user_include.inc");

ErrorLogger::doOutput("Compass...ajax_social_user_register1.php....Start.", 0);

//获取参数
$name = ParamUtil::getRequestString("name");//用户填写的用户名称
$mobile = ParamUtil::getRequestNumber("mobile");
$legalPerson = ParamUtil::getRequestString("legalPerson");
$organizationContact = ParamUtil::getRequestNumber("organizationContact");
$openId = ParamUtil::getRequestString("openId");
$unionId = ParamUtil::getRequestString("unionId");

ErrorLogger::doOutput("Compass...ajax_social_user_register1.php....name=" . $name, 0);
ErrorLogger::doOutput("Compass...ajax_social_user_register1.php....mobile=" . $mobile, 0);
ErrorLogger::doOutput("Compass...ajax_social_user_register1.php....openId=" . $openId, 0);
ErrorLogger::doOutput("Compass...ajax_social_user_register1.php....unionId=" . $unionId, 0);


//参数验证
if(empty($name) || empty($openId) || empty($unionId) || empty($mobile)) {
	$result["message"] = "参数错误！";
	responseNG($result);
}

//判断用户是否已经存在
$param = array();
$param['openid'] = $openId;
$param['unionid'] = $unionId;
$param['delete_flg'] = false;
$userList = UserMst::getList($param,'id','desc', 0, 1);
if(!empty($userList)) {
	$result["message"] = "用户已注册！";
	responseOK($result);
}

//用户数据插入
$userMst = new UserMst();
$userMst->school_no = $schoolNo;
$userMst->class_no = $classNo;
if(empty($legalPerson)) {
	$userMst->role = 5; //社会用户[非机构]
} else {
	$userMst->role = 6; //社会用户[机构]
}

$userMst->openid = $openId;
$userMst->unionid = $unionId;
$userMst->name = $name;
$userMst->mobile = $mobile;
$userMst->legal_person = $legalPerson;
$userMst->organization_contact = $organizationContact;
$userMst->save();

ErrorLogger::doOutput("Compass...ajax_social_user_register1.php....End.", 0);

$result["message"] = "注册成功！";
responseOK($result);

function responseNG($result) {
	$result = array("status"=>"NG", "result"=>$result);
	print json_encode($result);
	exit;
}
function responseOK($result) {
	$result = array("status"=>"OK", "result"=>$result);
	print json_encode($result);
	exit;
}

?>