<?php
// 获取用户当前代金券
require_once ("../user_include.inc");

ErrorLogger::doOutput("Koala...ajax_get_my_coupons.php....Start.", 0);

$ta = new TemplateAction();
if(!$ta->isLogin()) {
	print json_encode(array("status"=>"NG", "html"=>""));
	exit;
}

//检索用户收录的单词
$param = array();
$param["user_id"] = $ta->user->id;
$param["coupon_count_MIN"] = 1;
$param["delete_flg"] = false;
$user_coupon_list = UserCouponDat::getList($param, "coupon_id", "ASC");

ErrorLogger::doOutput("Koala...ajax_get_my_coupons.php....End.", 0);

$index = 0;
ob_start();
foreach($user_coupon_list as $tmp) {
	$index++;
	$coupon = Coupon::getById($tmp->coupon_id);
?>
		<div class="coupon">
			<img src="images/<?=$coupon->image?>" class="coupon_img">
			<div class="item_exchange_row">
				<div>有效期: <?=substr($tmp->dead_time,0,10)?></div>
				<div>可转让: <?=(1 - $tmp->transfer_count)?>次</div>
				<div onclick="useCoupon('<?=$tmp->id?>', '<?=$tmp->coupon_id?>');" class="coupon_button">使用</div>
				<div onclick="sendCoupon('<?=$tmp->id?>', '<?=$tmp->coupon_id?>');" class="coupon_button">赠送</div>
			</div>
		</div>
<?
}
$html = ob_get_contents();
ob_end_clean();
print json_encode(array("status"=>"OK", "html"=>$html));
?>