diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighCouponController.java b/hai-bweb/src/main/java/com/bweb/controller/HighCouponController.java index 4983aeae..78fa78b3 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighCouponController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighCouponController.java @@ -134,6 +134,14 @@ public class HighCouponController { throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOF_FOUND, ""); } + // 计算销售截止时间 + Calendar salesEndTime = Calendar.getInstance(); + salesEndTime.setTime(highCoupon.getSalesEndTime()); + salesEndTime.set(Calendar.HOUR_OF_DAY, 23); + salesEndTime.set(Calendar.MINUTE, 59); + salesEndTime.set(Calendar.SECOND, 59); + highCoupon.setSalesEndTime(salesEndTime.getTime()); + String setCouponKey = DateUtil.date2String(new Date(), "yyyyMMddHHmmss"); //订单号生成 年月日小时分秒 + 5位随机数 highCoupon.setCouponKey(setCouponKey); highCoupon.setCompanyId(merchant.getCompanyId()); diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighDiscountController.java b/hai-bweb/src/main/java/com/bweb/controller/HighDiscountController.java index bb6cb574..e8e02312 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighDiscountController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighDiscountController.java @@ -1,5 +1,6 @@ package com.bweb.controller; +import com.alibaba.fastjson.JSON; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.hai.common.exception.ErrorCode; @@ -7,6 +8,7 @@ import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.security.SessionObject; import com.hai.common.security.UserCenter; +import com.hai.common.utils.DateUtil; import com.hai.common.utils.ResponseMsgUtil; import com.hai.entity.HighDiscount; import com.hai.model.ResponseData; @@ -23,6 +25,8 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import java.util.Calendar; +import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -73,11 +77,19 @@ public class HighDiscountController { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } + // 计算销售截止时间 + Calendar salesEndTime = Calendar.getInstance(); + salesEndTime.setTime(highDiscount.getSalesEndTime()); + salesEndTime.set(Calendar.HOUR_OF_DAY, 23); + salesEndTime.set(Calendar.MINUTE, 59); + salesEndTime.set(Calendar.SECOND, 59); + highDiscount.setSalesEndTime(salesEndTime.getTime()); + + highDiscount.setDiscountKey(DateUtil.date2String(new Date(), "yyyyMMddHHmmss")); highDiscount.setCompanyId(userInfoModel.getBsCompany().getId()); highDiscount.setOperatorId(userInfoModel.getSecUser().getId()); highDiscount.setOperatorName(userInfoModel.getSecUser().getUserName()); highDiscount.setStatus(1); - highDiscountService.insertDiscount(highDiscount); return ResponseMsgUtil.success("操作成功"); @@ -114,11 +126,18 @@ public class HighDiscountController { log.error("HighDiscountController -> updateDiscount() error!","未找到优惠券信息"); throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_DISCOUNT, ""); } + // 计算销售截止时间 + Calendar salesEndTime = Calendar.getInstance(); + salesEndTime.setTime(highDiscount.getSalesEndTime()); + salesEndTime.set(Calendar.HOUR_OF_DAY, 23); + salesEndTime.set(Calendar.MINUTE, 59); + salesEndTime.set(Calendar.SECOND, 59); + + discount.setSalesEndTime(salesEndTime.getTime()); discount.setDiscountName(highDiscount.getDiscountName()); discount.setDiscountImg(highDiscount.getDiscountImg()); discount.setDiscountCarouselImg(highDiscount.getDiscountCarouselImg()); discount.setEffectiveDay(highDiscount.getEffectiveDay()); - discount.setSalesEndTime(highDiscount.getSalesEndTime()); highDiscountService.updateDiscount(highDiscount); @@ -130,6 +149,29 @@ public class HighDiscountController { } + @RequestMapping(value="/updateDiscountStatus",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "修改优惠券状态") + public ResponseData updateDiscountStatus(@RequestParam(name = "discountId", required = true) Long discountId, + @RequestParam(name = "status", required = true) Integer status) { + try { + // 查询优惠券 + HighDiscount discount = highDiscountService.getDiscountById(discountId); + if (discount == null) { + log.error("HighDiscountController -> updateDiscountStatus() error!","未找到优惠券信息"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_DISCOUNT, ""); + } + discount.setStatus(status); + discount.setUpdateTime(new Date()); + highDiscountService.updateDiscount(discount); + + return ResponseMsgUtil.success("操作成功"); + } catch (Exception e) { + log.error("HighDiscountController -> updateDiscountStatus() error!",e); + return ResponseMsgUtil.exception(e); + } + } + @RequestMapping(value="/getDiscountById",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "根据id查询") @@ -168,5 +210,4 @@ public class HighDiscountController { } } - } diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java b/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java index 769f094e..ffea0fa8 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java @@ -26,9 +26,8 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; +import java.util.*; +import java.util.stream.Collectors; /** * @Auther: 胡锐 @@ -57,6 +56,9 @@ public class HighOrderController { @Resource private HighDiscountUserRelService highDiscountUserRelService; + @Resource + private HighDiscountCouponRelService highDiscountCouponRelService; + @Resource private HighUserService highUserService; @@ -96,6 +98,20 @@ public class HighOrderController { log.error("HighOrderController --> addOrder() error!", "未找到卡卷信息"); throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, ""); } + + // 校验优惠券是否可用 + if (highOrder.getMemDiscountId() != null) { + List discountCouponRelList = highDiscountCouponRelService.getRelByCoupon(coupon.getId()); + if (discountCouponRelList.size() > 0) { + List collect = discountCouponRelList.stream().filter(o -> o.getDiscountId().equals(highOrder.getMemDiscountId())).collect(Collectors.toList()); + if (collect == null || collect.size() == 0) { + log.error("HighOrderController --> addOrder() error!", "无法使用优惠券"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法使用优惠券"); + } + } + } + + // 是否到底限购数量 if (highCouponService.userBuyLimitNumber(userInfoModel.getHighUser().getId(), coupon.getId()) == true) { log.error("HighOrderController --> addOrder() error!", "已达到限购数量"); diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java b/hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java index e8e05613..e6fbcd4b 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java @@ -9,8 +9,12 @@ import com.hai.common.exception.SysCode; import com.hai.common.security.SessionObject; import com.hai.common.security.UserCenter; import com.hai.common.utils.ResponseMsgUtil; +import com.hai.entity.HighDiscount; +import com.hai.entity.HighDiscountCouponRel; +import com.hai.entity.HighDiscountUserRel; import com.hai.model.HighUserModel; import com.hai.model.ResponseData; +import com.hai.service.HighDiscountCouponRelService; import com.hai.service.HighDiscountUserRelService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -22,8 +26,11 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * @Auther: 胡锐 @@ -43,6 +50,9 @@ public class HighUserDiscountController { @Resource private HighDiscountUserRelService highDiscountUserRelService; + @Resource + private HighDiscountCouponRelService highDiscountCouponRelService; + @RequestMapping(value="/receiveDiscount",method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "用户领取优惠券") @@ -59,7 +69,7 @@ public class HighUserDiscountController { log.error("HighDiscountController -> receiveDiscount() error!", "参数错误"); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } - // 领取成功 + // 领取 highDiscountUserRelService.receiveDiscount(userInfoModel.getHighUser().getId(), discountAgentId); return ResponseMsgUtil.success("操作成功"); @@ -97,8 +107,8 @@ public class HighUserDiscountController { @RequestMapping(value="/getUserNormalDiscountList",method = RequestMethod.GET) @ResponseBody - @ApiOperation(value = "获取用户的【可以使用】的优惠券列表") - public ResponseData getUserNormalDiscountList(HttpServletRequest request) { + @ApiOperation(value = "根据卡券,查询【可以使用】优惠券列表") + public ResponseData getDiscountListByCoupon(@RequestParam(name = "couponId", required = true) Long couponId,HttpServletRequest request) { try { // 用户 @@ -108,10 +118,27 @@ public class HighUserDiscountController { Map map = new HashMap<>(); map.put("userId", userInfoModel.getHighUser().getId()); map.put("status", 1); - return ResponseMsgUtil.success(highDiscountUserRelService.getDiscountList(map)); + + + List list = new ArrayList<>(); + // 查询用户的优惠券 + List userRels = highDiscountUserRelService.getDiscountList(map); + if (userRels.size() > 0) { + // 查询当前卡券有哪些优惠券 + List discountCouponRelList = highDiscountCouponRelService.getRelByCoupon(couponId); + if (discountCouponRelList.size() > 0) { + for (HighDiscountCouponRel highDiscountCouponRel : discountCouponRelList) { + List collect = userRels.stream().filter(o -> o.getDiscountId().equals(highDiscountCouponRel.getDiscountId())).collect(Collectors.toList()); + if (collect != null && collect.size() > 0) { + list.add(collect.get(0)); + } + } + } + } + return ResponseMsgUtil.success(list); } catch (Exception e) { - log.error("HighDiscountController -> getUserNormalDiscountList() error!",e); + log.error("HighDiscountController -> getDiscountListByCoupon() error!",e); return ResponseMsgUtil.exception(e); } } diff --git a/hai-service/src/main/java/com/hai/dao/SecUserMapperExt.java b/hai-service/src/main/java/com/hai/dao/SecUserMapperExt.java index f97ffcd8..65896104 100644 --- a/hai-service/src/main/java/com/hai/dao/SecUserMapperExt.java +++ b/hai-service/src/main/java/com/hai/dao/SecUserMapperExt.java @@ -62,9 +62,9 @@ public interface SecUserMapperExt { " sec_user su " + " WHERE" + " STATUS = 1 " + + " AND su.`password` = #{password}" + " AND su.login_name = #{loginName} " + " OR su.telephone = #{loginName} " + - " AND su.`password` = #{password}" + "" }) @Results({ diff --git a/hai-service/src/main/java/com/hai/service/HighDiscountCouponRelService.java b/hai-service/src/main/java/com/hai/service/HighDiscountCouponRelService.java index 4087e8ff..ca170011 100644 --- a/hai-service/src/main/java/com/hai/service/HighDiscountCouponRelService.java +++ b/hai-service/src/main/java/com/hai/service/HighDiscountCouponRelService.java @@ -47,6 +47,13 @@ public interface HighDiscountCouponRelService { **/ HighDiscountCouponRel getRelByDiscountCoupon(Long discountId,Long couponId); + /** + * @Author 胡锐 + * @Description 根据卡券查询 + * @Date 2021/4/4 20:23 + **/ + List getRelByCoupon(Long couponId); + /** * @Author 胡锐 * @Description 根据优惠券查询 diff --git a/hai-service/src/main/java/com/hai/service/HighDiscountUserRelService.java b/hai-service/src/main/java/com/hai/service/HighDiscountUserRelService.java index 81e316a7..db043025 100644 --- a/hai-service/src/main/java/com/hai/service/HighDiscountUserRelService.java +++ b/hai-service/src/main/java/com/hai/service/HighDiscountUserRelService.java @@ -15,7 +15,7 @@ public interface HighDiscountUserRelService { /** * @Author 胡锐 - * @Description 领取卡券 + * @Description 领取优惠券 * @Date 2021/4/4 15:12 **/ void receiveDiscount(Long userId,Long discountAgentId); diff --git a/hai-service/src/main/java/com/hai/service/impl/HighDiscountCouponRelServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighDiscountCouponRelServiceImpl.java index fad9c4ab..a65958d3 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighDiscountCouponRelServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighDiscountCouponRelServiceImpl.java @@ -53,8 +53,7 @@ public class HighDiscountCouponRelServiceImpl implements HighDiscountCouponRelSe @Override public HighDiscountCouponRel getRelByDiscountCoupon(Long discountId, Long couponId) { HighDiscountCouponRelExample example = new HighDiscountCouponRelExample(); - example.createCriteria().andDiscountIdEqualTo(discountId).andCouponIdEqualTo(couponId); - + example.createCriteria().andDiscountIdEqualTo(discountId).andCouponIdEqualTo(couponId).andStatusEqualTo(1); List list = highDiscountCouponRelMapper.selectByExample(example); if (list != null && list.size() > 0) { return list.get(0); @@ -62,10 +61,21 @@ public class HighDiscountCouponRelServiceImpl implements HighDiscountCouponRelSe return null; } + @Override + public List getRelByCoupon(Long couponId) { + HighDiscountCouponRelExample example = new HighDiscountCouponRelExample(); + example.createCriteria().andCouponIdEqualTo(couponId).andStatusEqualTo(1); + List list = highDiscountCouponRelMapper.selectByExample(example); + for (HighDiscountCouponRel rel : list) { + rel.setHighCoupon(highCouponService.getCouponDetail(rel.getCouponId())); + } + return list; + } + @Override public List getRelByDiscount(Long discountId) { HighDiscountCouponRelExample example = new HighDiscountCouponRelExample(); - example.createCriteria().andDiscountIdEqualTo(discountId); + example.createCriteria().andDiscountIdEqualTo(discountId).andStatusEqualTo(1);; List list = highDiscountCouponRelMapper.selectByExample(example); for (HighDiscountCouponRel rel : list) { rel.setHighCoupon(highCouponService.getCouponDetail(rel.getCouponId())); diff --git a/hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java index 01cd9ac0..eddc1555 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java @@ -75,7 +75,12 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic userRel.setCreateTime(new Date()); // 计算使用有效期 Calendar userEndTime = Calendar.getInstance(); + userEndTime.setTime(new Date()); + userEndTime.set(Calendar.HOUR_OF_DAY, 23); + userEndTime.set(Calendar.MINUTE, 59); + userEndTime.set(Calendar.SECOND, 59); userEndTime.add(Calendar.DATE, rel.getHighDiscount().getEffectiveDay()); + if (userEndTime.getTime().compareTo(rel.getHighDiscount().getSalesEndTime()) == 1) { userRel.setUseEndTime(rel.getHighDiscount().getSalesEndTime()); } else { diff --git a/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java index 0efe0c0b..75dd0856 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java @@ -167,7 +167,12 @@ public class HighOrderServiceImpl implements HighOrderService { // 计算使用有效期 Calendar userEndTime = Calendar.getInstance(); + userEndTime.setTime(new Date()); + userEndTime.set(Calendar.HOUR_OF_DAY, 23); + userEndTime.set(Calendar.MINUTE, 59); + userEndTime.set(Calendar.SECOND, 59); userEndTime.add(Calendar.DATE, coupon.getRecycleDay()); + if (userEndTime.getTime().compareTo(code.getUseEndTime()) == 1) { highUserCoupon.setUseEndTime(code.getUseEndTime()); } else { @@ -351,6 +356,13 @@ public class HighOrderServiceImpl implements HighOrderService { } highChildOrder.setChildOrdeStatus(5); // 子订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 } + + if (order.getMemDiscountId() != null) { + HighDiscountUserRel rel = highDiscountUserRelService.getRelById(order.getMemDiscountId()); + rel.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用 + rel.setUseTime(new Date()); + highDiscountUserRelService.updateDiscountUserRel(rel); + } updateOrder(order); } } diff --git a/hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java b/hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java index cd86ba5d..a93e0e31 100644 --- a/hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java @@ -81,6 +81,10 @@ public class GoodsOrderServiceImpl implements PayService { // 计算使用有效期 Calendar userEndTime = Calendar.getInstance(); + userEndTime.setTime(new Date()); + userEndTime.set(Calendar.HOUR_OF_DAY, 23); + userEndTime.set(Calendar.MINUTE, 59); + userEndTime.set(Calendar.SECOND, 59); userEndTime.add(Calendar.DATE, coupon.getRecycleDay()); if (userEndTime.getTime().compareTo(code.getUseEndTime()) == 1) { highUserCoupon.setUseEndTime(code.getUseEndTime());