51,410
社区成员
发帖
与我相关
我的任务
分享

// 用户优惠券
public int userCouponRelation(int userId, boolean newUser, String exchange) {
int i = 0;
List<ComicCoupon> couponList = new ArrayList();
if (newUser) {
couponList = comicCouponMapper.getCouponByNewUserAndExchange("T", null);
} else {
couponList = comicCouponMapper.getCouponByNewUserAndExchange("F", exchange);
}
if (couponList == null || couponList.isEmpty())
return i;
ComicUserCoupon userCoupon = null;
Date date = new Date();
List<ComicUserCoupon> userCouponList = new ArrayList();
for (ComicCoupon comicCoupon : couponList) {
Integer couponId = comicCoupon.getId();
Integer validate = comicCoupon.getCouponValidate();//手动输入的优惠券天数,例如:1(1天) 2(2天),不是时间控件选择的
userCoupon = new ComicUserCoupon();
userCoupon.setCouponsId(couponId);
userCoupon.setUserId(userId);
userCoupon.setCreateTime(date);//点击提交时优惠券生成时间(就是用户领取优惠券的时间)
userCoupon.setValidateTime(getEndTime(date, validate));//最终生成优惠券有效期(优惠券生成时间+优惠天数)
userCouponList.add(userCoupon);
}
comicCouponMapper.addUserCoupon(userCouponList);
i = 1;
return i;
}
private Date getEndTime(Date date, Integer day) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH, day);
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
date = calendar.getTime();
return date;
}private Date getEndTime(Date date, Integer day) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
calendar.add(Calendar.DAY_OF_MONTH, day + 1);
calendar.add(Calendar.SECOND, -1);
return calendar.getTime();
}