<?php

// 审核拒绝加入圈子的申请
require_once ("../user_include.inc");

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

//获取参数
$userId = ParamUtil::getRequestNumber("userId", 0);//申请者
$circleId = ParamUtil::getRequestNumber("circleId", 0);//圈子id
$msgId = ParamUtil::getRequestNumber("msgId", 0);//圈主收到的消息id

$result = array();

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

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

$userMst = $userList[0];

//判断圈子是否存在
$circleDat = CircleDat::getById($circleId);
if(empty($circleDat)) {
	$result["message"] = "圈子不存在！";
	responseNG($result);
}

//用户是否已经加入圈子
$param = array();
$param['circle_id'] = $circleDat->id;
$param['user_id'] = $userMst->id;
$param['delete_flg'] = false;
$tmpCount = CircleMemberDat::getListCount($param);
if($tmpCount >= 1) {
	$result["message"] = "不能重复加入圈子！";
	responseNG($result);
}

//拒绝加入圈子处理，删除本条消息
$userMsgDat = UserMessageDat::getById($msgId);
if(!empty($userMsgDat)) {
	$userMsgDat->is_read = true;
	$userMsgDat->is_operated = true;
	$userMsgDat->save();
}

$result["message"] = "操作成功！";
responseOK($result);

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