<?php

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

ErrorLogger::doOutput("Compass...ajax_get_user_message_detail.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['id'] = $messageId;
$param['delete_flg'] = false;
$userMessageList = UserMessageDat::getList($param,'id','desc', 0, 1);

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

//获取消息详情
$attachDat = array();
$userMessageDat = $userMessageList[0];

if($userMessageDat->attach_dat_type == "VOLUNTEER") {
	$attachDat = VolunteerEventDat::getById($userMessageDat->attach_dat_id);
}
if($userMessageDat->attach_dat_type == "CIRCLE") {
	$attachDat = CircleDat::getById($userMessageDat->attach_dat_id);
}

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


//返回结果
$result["userMessageDat"] = $userMessageDat;
$result["attachDat"] = $attachDat;
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;
}
?>