<?php

// 获取用户消息列表 
require_once ("../user_include.inc");

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

//获取参数
$unionId = ParamUtil::getRequestString("unionId");
$readFlg = ParamUtil::getRequestNumber("readFlg", 0);
$page = ParamUtil::getRequestNumber("page", 0);

//参数检查
if(empty($unionId) || ($readFlg <> 0 && $readFlg <> 1 && $readFlg <> 2)) {
	$result["message"] = "参数错误！";
	responseNG($result);
}

$result = array();
//判断用户是否存在
$param = array();
$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;

//获取用户消息列表
$rowCount = 10;
$offset = $page * $rowCount;

$param = array();
$param['user_id'] = $userId;
if($readFlg == 1) {
	$param['is_read'] = false;
}
if($readFlg == 2) {
	$param['is_read'] = true;
}
$param['delete_flg'] = false;
$userMessageList = UserMessageDat::getList($param,'id','desc', $offset, $rowCount);
$allCount = UserMessageDat::getListCount($param);

//接口返回数据
$result["allCount"] = $allCount;
$result["page"] = $page;
$result["rowCount"] = $rowCount;
$result["list"] = $userMessageList;

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

//返回结果
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;
}
?>