<?php

// 修改用户的未读消息为已读状态
require_once ("../user_include.inc");

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

//获取参数
$unionId = ParamUtil::getRequestString("unionId");
$messageId = ParamUtil::getRequestNumber("messageId");


//参数检查
if(empty($unionId) || empty($messageId)) {
	$result["message"] = "参数错误！";
	responseNG($result);
}

//检索用户是否存在
$param['unionid'] = $unionId;
$param['delete_flg'] = false;
$userList = UserMst::getList($param,'id','desc', 0, 1);
if(empty($userList)) {
	$result["message"] = "用户不存在！";
	responseNG($result);
}
$userId = $userList[0]->id;

//查询消息数据
$param = array();
$param['user_id'] = $userId;
$param['is_read'] = false;
$param['id'] = $messageId;
$param['delete_flg'] = false;
$userMessageList = UserMessageDat::getList($param,'id','desc', 0, 1);

//更新
if(!empty($userMessageList)) {
	$userMessageList[0]->is_read = true;
	$userMessageList[0]->save();
}

ErrorLogger::doOutput("Compass...ajax_set_user_message_read.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;
}
?>