<?php

// 更新用户孩子年龄段
require_once ("../user_include.inc");

$unionId = ParamUtil::getRequestString("unionId", 0);
$age = ParamUtil::getRequestNumber("age", 1);
ErrorLogger::doOutput("Compass...ajax_update_user_age.php....Start.", 0);

ErrorLogger::doOutput("Compass...ajax_update_user_age.php....unionId=" . $unionId, 0);
ErrorLogger::doOutput("Compass...ajax_update_user_age.php....age=" . $age, 0);

//参数验证
if(empty($unionId)) {
	responseNG("参数错误！");
}

//年龄段参数
$tmpObj = ChildAgeRange::getById($age);
if(empty($tmpObj)) {
	responseNG("参数错误！");
}

//检索用户是否存在
$param['unionid'] = $unionId;
$param['delete_flg'] = false;
$tmpUserMstList = UserMst::getList($param,'id','desc', 0, 1);
if(empty($tmpUserMstList)) {
	responseNG("参数错误！");
}

$user = $tmpUserMstList[0];
$user->child_age = $age;
$user->save();

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

responseOK("更新成功！");

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