diff --git a/hai-order/src/main/java/com/web/rocketmq/consumer/OrderCancelConsumer.java b/hai-order/src/main/java/com/web/rocketmq/consumer/OrderCancelConsumer.java index a0acf6f0..a9b8a32b 100644 --- a/hai-order/src/main/java/com/web/rocketmq/consumer/OrderCancelConsumer.java +++ b/hai-order/src/main/java/com/web/rocketmq/consumer/OrderCancelConsumer.java @@ -20,10 +20,16 @@ public class OrderCancelConsumer implements RocketMQListener { @Override public void onMessage(HighOrder order) { - HighOrder highOrder = orderService.getOrderDetailByNo(order.getOrderNo()); - if (highOrder != null && highOrder.getOrderStatus().equals(OrderStatus.STATUS1.getNumber())) { - // 取消订单 - orderService.cancelOrder(highOrder, null); + try { + Thread.sleep(1000*10); // 休眠 10 秒钟 + HighOrder highOrder = orderService.getOrderDetailByNo(order.getOrderNo()); + if (highOrder != null && highOrder.getOrderStatus().equals(OrderStatus.STATUS1.getNumber())) { + // 取消订单 + orderService.cancelOrder(highOrder, null); + } + } catch (InterruptedException e) { + System.out.println(e); + throw new RuntimeException(e); } } } 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 a746f720..db6900fa 100644 --- a/hai-service/src/main/java/com/hai/service/HighDiscountUserRelService.java +++ b/hai-service/src/main/java/com/hai/service/HighDiscountUserRelService.java @@ -84,4 +84,18 @@ public interface HighDiscountUserRelService { */ Integer receiveDiscountCount(Long userId,Long discountId); + /** + * 【惠支付】用户优惠券使用 + * @param userDiscountId + * @param phone + */ + void hzfUserDiscountUse(Long userDiscountId,String phone); + + /** + * 【惠支付】用户优惠券退回 + * @param userDiscountId + * @param phone + */ + void hzfUserDiscountReturn(Long userDiscountId,String phone); + } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageServiceImpl.java index d7c8c78b..e6cc4fe9 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageServiceImpl.java @@ -356,7 +356,6 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic } @Override - @Transactional(propagation= Propagation.REQUIRES_NEW) public String giveAway(Long packageId, List phoneList) throws Exception { UserInfoModel userInfoModel = userCenter.getSessionModel(UserInfoModel.class); @@ -385,22 +384,17 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic discountPackageDeliver.setOpUserName(userInfoModel.getSecUser().getUserName()); discountPackageDeliverService.insertDeliver(discountPackageDeliver); - // 查询出来系统中的用户 - Map userMap = new HashMap<>(); - userMap.put("status", "1"); - List listUser = highUserService.getListUser(userMap); - new Thread(() -> { int alreadyProcessedNum = 0; for (String phone : phoneList) { try { // 根据手机号查询用户 - List userList = listUser.stream().filter(p -> p.getPhone().equals(phone)).collect(Collectors.toList()); - if (userList.size() > 0) { + HighUser highUser = highUserService.findByPhone(phone); + if (highUser != null) { Map freeMap = new HashMap<>(); freeMap.put("discountPackageId", packageId); - freeMap.put("userId", userList.get(0).getId()); - freeMap.put("userPhone", userList.get(0).getPhone()); + freeMap.put("userId", highUser.getId()); + freeMap.put("userPhone", highUser.getPhone()); HighDiscountPackageActual packageActual = freeUserDiscountPackage(freeMap); HighDiscountPackageDeliverUser deliverUser = new HighDiscountPackageDeliverUser(); @@ -409,8 +403,8 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic deliverUser.setPackageId(packageId); deliverUser.setPackageName(discountPackage.getTitle()); deliverUser.setPackageActualId(packageActual.getId().longValue()); - deliverUser.setUserId(userList.get(0).getId()); - deliverUser.setUserPhone(userList.get(0).getPhone()); + deliverUser.setUserId(highUser.getId()); + deliverUser.setUserPhone(highUser.getPhone()); deliverUser.setStatus(2); deliverUser.setOpUserId(userInfoModel.getSecUser().getId()); deliverUser.setOpUserName(userInfoModel.getSecUser().getUserName()); @@ -439,8 +433,8 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic deliverUser.setPackageId(packageId); deliverUser.setPackageName(discountPackage.getTitle()); deliverUser.setPackageActualId(packageActual.getId().longValue()); - deliverUser.setUserId(userList.get(0).getId()); - deliverUser.setUserPhone(userList.get(0).getPhone()); + deliverUser.setUserId(highUser.getId()); + deliverUser.setUserPhone(highUser.getPhone()); deliverUser.setStatus(2); discountPackageDeliverService.insertDeliverUser(deliverUser); } @@ -455,6 +449,7 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic discountPackageDeliverService.updateDeliver(discountPackageDeliver); redisUtil.del(serialNum); }).start(); + return serialNum; } } 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 1522f2ed..ddf407fa 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 @@ -38,6 +38,9 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic @Resource private HighAgentService highAgentService; + @Resource + private HighUserService userService; + @Resource private HighDiscountService highDiscountService; @@ -293,4 +296,54 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic public Integer receiveDiscountCount(Long userId, Long discountId) { return highDiscountUserRelMapper.receiveDiscountCount(userId, discountId); } + + @Override + @Transactional(rollbackFor=Exception.class,propagation= Propagation.REQUIRES_NEW) + public void hzfUserDiscountUse(Long userDiscountId, String phone) { + HighDiscountUserRel discountUserRel = getRelById(userDiscountId); + if (discountUserRel == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的优惠券"); + } + + HighUser user = userService.findByUserId(discountUserRel.getUserId()); + if (user == null){ + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的用户"); + } + if (!user.getPhone().equals(phone)) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "拥有人和使用人不一致"); + } + + discountUserRel.setUseTime(new Date()); // 使用时间 + discountUserRel.setStatus(2); //状态 0:已过期 1:未使用 2:已使用 + updateDiscountUserRel(discountUserRel); + + HighDiscountAgentCode code = highDiscountAgentCodeService.getCodeById(discountUserRel.getDiscountAgentCodeId()); + code.setStatus(3); + highDiscountAgentCodeService.updateCode(code); + + } + + @Override + @Transactional(rollbackFor=Exception.class,propagation= Propagation.REQUIRES_NEW) + public void hzfUserDiscountReturn(Long userDiscountId, String phone) { + HighDiscountUserRel discountUserRel = getRelById(userDiscountId); + if (discountUserRel == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的优惠券"); + } + HighUser user = userService.findByUserId(discountUserRel.getUserId()); + if (user == null){ + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的用户"); + } + if (!user.getPhone().equals(phone)) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "拥有人和使用人不一致"); + } + + discountUserRel.setUseTime(null); // 使用时间 + discountUserRel.setStatus(1); //状态 0:已过期 1:未使用 2:已使用 + updateDiscountUserRel(discountUserRel); + + HighDiscountAgentCode code = highDiscountAgentCodeService.getCodeById(discountUserRel.getDiscountAgentCodeId()); + code.setStatus(1); + highDiscountAgentCodeService.updateCode(code); + } } diff --git a/hai-user/src/main/java/com/web/controller/DiscountController.java b/hai-user/src/main/java/com/web/controller/DiscountController.java index 497f81a2..2a24ba2f 100644 --- a/hai-user/src/main/java/com/web/controller/DiscountController.java +++ b/hai-user/src/main/java/com/web/controller/DiscountController.java @@ -10,6 +10,7 @@ import com.hai.common.security.UserCenter; import com.hai.common.utils.HttpsUtils; import com.hai.common.utils.ResponseMsgUtil; import com.hai.config.CommonSysConst; +import com.hai.entity.HighDiscountAgentCode; import com.hai.entity.HighDiscountUserRel; import com.hai.model.HighUserModel; import com.hai.model.ResponseData; @@ -25,6 +26,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; +import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -41,6 +43,7 @@ public class DiscountController { @Resource private HighDiscountUserRelService discountUserRelService; + @RequestMapping(value="/getUserDiscountList",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询用户优惠券列表") @@ -104,60 +107,6 @@ public class DiscountController { } } - @RequestMapping(value="/useUserDiscount",method = RequestMethod.GET) - @ResponseBody - @ApiOperation(value = "使用优惠券") - public ResponseData useUserDiscount(@RequestParam(name = "userDiscountId", required = true) Long userDiscountId) { - try { - - HighUserModel userInfoModel = userCenter.getSessionModel(HighUserModel.class); - if (userInfoModel == null) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.SEC_USER_EXPIRED, ""); - } - HighDiscountUserRel rel = discountUserRelService.getRelById(userDiscountId); - if (rel == null) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的优惠券"); - } - return ResponseMsgUtil.success(rel); - - } catch (Exception e) { - log.error("HighDiscountController -> getUserDiscountDetail() error!",e); - return ResponseMsgUtil.exception(e); - } - } - - @RequestMapping(value="/cancelUserDiscount",method = RequestMethod.GET) - @ResponseBody - @ApiOperation(value = "取消使用优惠券") - public ResponseData cancelUserDiscount(@RequestParam(name = "userDiscountId", required = true) Long userDiscountId) { - try { - - HighUserModel userInfoModel = userCenter.getSessionModel(HighUserModel.class); - if (userInfoModel == null) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.SEC_USER_EXPIRED, ""); - } - HighDiscountUserRel rel = discountUserRelService.getRelById(userDiscountId); - if (rel == null) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的优惠券"); - } - JSONObject param = new JSONObject(); - param.put("id", rel.getId()); - param.put("userId", rel.getUserId()); - param.put("discountId", rel.getDiscountId()); - param.put("discountName", rel.getDiscountName()); - param.put("discountType", rel.getDiscountType()); - param.put("discountCondition", rel.getDiscountCondition()); - param.put("discountPrice", rel.getDiscountPrice()); - param.put("receiveTime", rel.getCreateTime()); - param.put("status", rel.getStatus()); - return ResponseMsgUtil.success(param); - - } catch (Exception e) { - log.error("HighDiscountController -> getUserDiscountDetail() error!",e); - return ResponseMsgUtil.exception(e); - } - } - @RequestMapping(value="/queryUserDiscountList",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询用户优惠券列表") @@ -192,6 +141,40 @@ public class DiscountController { } } + + @RequestMapping(value="/hzfUserDiscountUse",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "【惠支付】优惠券使用") + public ResponseData hzfUserDiscountUse(@RequestParam(name = "userDiscountId", required = true) Long userDiscountId, + @RequestParam(name = "userPhone", required = true) String userPhone) { + try { + + discountUserRelService.hzfUserDiscountUse(userDiscountId, userPhone); + return ResponseMsgUtil.success("操作成功"); + + } catch (Exception e) { + log.error("HighDiscountController -> getUserDiscountDetail() error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/hzfUserDiscountReturn",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "【惠支付】优惠券退款") + public ResponseData hzfUserDiscountReturn(@RequestParam(name = "userDiscountId", required = true) Long userDiscountId, + @RequestParam(name = "userPhone", required = true) String userPhone) { + try { + + discountUserRelService.hzfUserDiscountReturn(userDiscountId, userPhone); + return ResponseMsgUtil.success("操作成功"); + + } catch (Exception e) { + log.error("HighDiscountController -> getUserDiscountDetail() error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/queryHzfDiscountList",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询【惠支付】优惠列表")