| | |
| | | package com.yeshi.fanli.service.impl.user;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.text.ParseException;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | |
| | | userSystemCouponRecordService.updateByPrimaryKeySelective(couponRecord);
|
| | |
|
| | | UserSystemCoupon userSystemCoupon = couponRecord.getUserSystemCoupon();
|
| | |
|
| | | int expiryDay = 15;
|
| | |
|
| | | SystemCoupon systemCoupon = userSystemCoupon.getSystemCoupon();
|
| | | SystemCoupon coupon = systemCouponService.selectByPrimaryKey(systemCoupon.getId());
|
| | | if (coupon != null) {
|
| | | expiryDay = coupon.getExpiryDay();
|
| | | }
|
| | |
|
| | | // 结束日期
|
| | | Date endTime = null;
|
| | | try {
|
| | | // 今天在内 减去一天
|
| | | String endDay = DateUtil.plusDay(expiryDay - 1, new Date());
|
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
| | | endTime = format.parse(endDay);
|
| | | } catch (ParseException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | // 状态初始化
|
| | | userSystemCoupon.setState(UserSystemCoupon.STATE_CAN_USE);
|
| | | userSystemCoupon.setUseTime(null);
|
| | |
|
| | | // 有效期时间重新定义
|
| | | userSystemCoupon.setStartTime(new Date());
|
| | | userSystemCoupon.setEndTime(endTime);
|
| | | userSystemCoupon.setUpdateTime(new Date());
|
| | | userSystemCouponMapper.updateByPrimaryKey(userSystemCoupon);
|
| | | }
|
| | |
| | | Date now = new Date();
|
| | | Date endTime = userCoupon.getEndTime();
|
| | | if (endTime != null && endTime.getTime() < now.getTime()) {
|
| | | |
| | | // TODO 过期
|
| | | // 过期
|
| | | List<UserSystemCoupon> list = new ArrayList<UserSystemCoupon>();
|
| | | list.add(userCoupon);
|
| | | updateCounponInvalid(list);
|
| | | return;
|
| | | }
|
| | |
|
| | |
| | | userCouponVO.setCouponPicture(systemCoupon.getPicture());
|
| | | }
|
| | |
|
| | | if (UserSystemCoupon.STATE_CAN_USE == state) {
|
| | | if (UserSystemCoupon.STATE_CAN_USE == state || UserSystemCoupon.STATE_IN_USE == state) {
|
| | | int differentDays = 0;
|
| | | if (endTime != null && startTime != null) {
|
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
| | |
| | | }
|
| | | tips = tips.replace("{口令}", tokenRecord.getToken()).replace("{下载链接}", configService.get("app_down_link"));
|
| | | }
|
| | | |
| | | Date endTimeGive = record.getEndTime();
|
| | | if (endTimeGive != null) {
|
| | | Map<String, Object> remainDays = new HashMap<String, Object>();
|
| | | remainDays.put("content", "剩余" + DateUtil.dateDiff2(new Date(), endTimeGive) + "过期");
|
| | | remainDays.put("fontColor", "#F14242");
|
| | | userCouponVO.setRemainDays(remainDays);
|
| | | }
|
| | | }
|
| | | } else {
|
| | | tips = "";
|
| | | }
|
| | | userCouponVO.setGiveTips(tips);
|
| | | |
| | | } else if (UserSystemCoupon.STATE_END_USE == state) {
|
| | | if (give && CouponTypeEnum.freeCouponGive == type) {
|
| | | userCouponVO.setState(UserSystemCoupon.STATE_GIVE_END);
|
| | |
| | | Date now = new Date();
|
| | | Date endTime = userCoupon.getEndTime();
|
| | | if (endTime != null && endTime.getTime() < now.getTime()) {
|
| | | |
| | | // TODO 过期
|
| | | List<UserSystemCoupon> list = new ArrayList<UserSystemCoupon>();
|
| | | list.add(userCoupon);
|
| | | updateCounponInvalid(list);
|
| | | continue;
|
| | | }
|
| | |
|