<?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);

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

//年龄段参数
$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);

$result["recommend"] = false;
//已经是会员不用购买
if($userMst.is_member==false && ($userMst.role==1 || $userMst.role==2 || $userMst.role==3|| $userMst.role==5|| $userMst.role==6)) {
	$result["recommend"] = true;
}
$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;
}
?>