<?php

// 获取用户持有证书列表 
require_once ("../user_include.inc");

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

$userId = $userList[0]->id;

//获取用户证书列表
$sql = "select c.title, c.front_image, u.status from user_certificate_dat u, certificate_mst c where u.delete_flg=false and c.delete_flg=false and u.user_id='{$userId}' and u.certificate_id=c.id";
$db = &CompassDBManager::getInstance();
$tmpList = $db->executeQuery($sql);
$allCount = count($tmpList);

$certificateList = array();
//改写状态值
if(!empty($tmpList)) {
	$statusArray = array("WAITING"=>"制作中","SENDING"=>"配送中", "FINISH"=>"已签收"); // WAITING:制作中；SENDING:配送中；FINISH:已签收
	foreach($tmpList as $tmp) {
		//替换为标题
		$tmp["status"] = $statusArray[$tmp["status"]];
		$certificateList[] = $tmp;
	}
}

//接口返回数据
$result["allCount"] = $allCount;
$result["certificateList"] = $certificateList;

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