<?php

// 获取圈子首页数据
require_once ("../user_include.inc");

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

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

$result = array();

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

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

$userMst = $userList[0];

//获取用户的所在圈子
$userCircleList = array();

$param = array();
$param['user_id'] = $userMst->id;
$param['delete_flg'] = false;
$tmpUserCircleList = CircleMemberDat::getList($param,'id','desc');
if(!empty($tmpUserCircleList)) {
	foreach($tmpUserCircleList as $tmp) {
		$tmp2 = array();
		//获取圈子名称
		$tmpCircle = CircleDat::getById($tmp->circle_id);
		if(!empty($tmpCircle)) {
			$userCircleList[] = array("circle_id"=>$tmpCircle->id, "circle_title"=>$tmpCircle->title, "front_image"=>$tmpCircle->front_image);
		}
	}
}


//组装返回数据
$result["userCircleList"] = $userCircleList;

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