<?php

// 获取募捐列表
require_once ("../user_include.inc");

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

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

//参数验证
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"] = "用户不存在！";
	responseOK($result);
}

//每页显示条数
$rowCount = 10;

$result = array();

$offset = $page * $rowCount;

//检索数据库
$donationEventlist = array();
$param = array();
$param['status_NOT'] = array('NEW','NG');
$param['delete_flg'] = false;
$tmpList = DonationsEventDat::getList($param,'id','desc', $offset, $rowCount);
$allCount = DonationsEventDat::getListCount($param);
$pageCount = ceil($allCount/$rowCount);

if(!empty($tmpList)) {
	foreach($tmpList as $tmp) {
		$tmp->start_time = substr($tmp->start_time, 0, 10);
		$tmp->finish_time = substr($tmp->finish_time, 0, 10);
		$tmp->status_title = DonationEventStatus::getTitleByName($tmp->status);
		$donationEventlist[] = $tmp;
	}
}

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


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