<if condition="empty($coupon_detail)">
<div class="empty-coupon">
<i class="empty-coupon-icon iconfont icon-qiaquan "></i>
<p class="empty-order-mark">暂无未使用优惠券!</p>
</div>
<else />
<!-- 无优惠券时提示 end-->
<!-- 优惠券 start -->
<div class="sale_paper">
<!-- <i class="iconfont icon-wodeyouhuiquan"></i>暂时无未使用优惠券 -->
<div class="container">
<foreach name="coupon_detail" item="v">
<div class="paperbox">
<div class="triangle"></div>
<p>{$v['coupon_name']}优惠劵</p>
<em>{$v['coupon_denomination']}<span>元</span><sup>优惠券</sup></em>
<h4>满{$v['coupon_condition']}可用</h4>
<span class="coupon_shop">最终解释权{$shopData['shop_name']}</span>
<strong>( 使用时间:{$v['start_time']|date="m/d",###}-{$v['end_time']|date="m/d",###} )</strong>
<div class="free-collecte" coupon_id="{$v['id']}">未使用</div>
<div class="transform-triangle"></div>
<!-- <h4>满{$v['coupon_condition']}可用</h4> -->
</div>
</foreach>
</div>
</div>
<!-- 优惠券 end -->
</if>
//js代码
// 点击li的未使用...
$('.coupon-status').click(function(){
$(this).addClass('color');
$(this).siblings().removeClass('color');
// 获取到状态码
var status = $(this).attr('status');
// 发起ajax在后台查询数据
$.post("{:U('addon/WeiuidDeit/Mobile/couponStatus')}",{status:status},function(data){
if(data.return_code == 200){
var str = '';
for(var i = 0; i<data.data.length;i++){
str += '<div class="paperbox">';
str += '<div class="triangle"></div>';
str += '<p>'+data['data'][i]['coupon_name']+'优惠劵</p>';
str += '<em>'+data['data'][i]['coupon_denomination']+'<span>元</span><sup>优惠券</sup></em>';
str += '<h4>满'+data['data'][i]['coupon_condition']+'可用</h4>';
str += '<span class="coupon_shop">最终解释权'+data['shopdata']+'</span>';
str += '<strong>( 使用时间:'+data['data'][i]['start_time']+'-'+data['data'][i]['end_time']+' )</strong>';
str += '<div class="free-collecte" coupon_id="'+data['data'][i]['id']+'">未使用</div>';
str += '<div class="transform-triangle"></div>';
str += '</div>';
}
// 商品的数据
$('.container').html(str);
$('.empty-coupon').remove();
$('.sale_paper').show();
}else{
$('.empty-coupon').html('');
var str = '';
str += '<div class="empty-coupon"><i class="empty-coupon-icon iconfont icon-qiaquan "></i><p class="empty-order-mark">暂无未使用优惠券!</p></div>'
$('.paper_nav').after(str);
$('.sale_paper').hide();
}
});
});
//控制器代码
/*
查询领取优惠表
循环出个人用户的所有领取的优惠卷
*/
// 个人中心优惠卷页面
public function coupon()
{
// 显示的是未使用的优惠卷
$coupon_detail = M()->table('antweb_foodcouponreceive as a')
->join('antweb_foodcoupon as b on b.id=a.foodcoupon_id')
->where([
'foodmumber_id'=>session('userinfo')['id'],
'receive_status'=>1,
])
->order('a.id desc')
->select();
// 查询是否有过期的优惠卷
foreach($coupon_detail as $k=>$v){
if($v['receive_status'] != 3){
// 当前时间跟优惠卷结束时间做判断
if(time()>$v['end_time']){
$coupondata = D('foodcouponreceive')->where([
'foodmumber_id'=>session('userinfo')['id']
])->setInc('receive_status',2);
}
}
}
$this->assign([
'coupon_detail'=>$coupon_detail
]);
$this->display();
}
/*
未使用,已使用,已过期
author:咔咔
time:2018.6.23
*/
// 优惠卷状态 receive_status == 3
public function couponStatus()
{
// 获取优惠卷状态码
$status = I('status');
$couponData = M()->table('antweb_foodcouponreceive as a')
->join('antweb_foodcoupon as b on b.id=a.foodcoupon_id')
->where([
'foodmumber_id'=>session('userinfo')['id'],
'shop_id'=>session('business_id'),
'receive_status'=>$status,
])
->select();
foreach($couponData as $k=>$v){
$couponData[$k]['start_time'] = date('m-d',$v['start_time']);
$couponData[$k]['end_time'] = date('m-d',$v['end_time']);
}
// 查询店铺信息
$shopData = D('foodmanagement')->where([
'id'=>session('business_id')
])->find();
// 验证是否查询成功
if($couponData){
$return['return_code'] = 200;
$return['return_msg'] = '查询成功';
$return['data'] = $couponData;
$return['shopdata'] = $shopData['shop_name'];
}else{
$return['return_code'] = 400;
$return['return_msg'] = '查询失败';
}
$this->ajaxReturn($return);
}