From e46499752bfd20dea7cf7f0e486e0a3af0fb71c0 Mon Sep 17 00:00:00 2001 From: 199901012 Date: Sat, 27 Mar 2021 13:42:17 +0800 Subject: [PATCH] =?UTF-8?q?'=E9=94=80=E5=94=AE=E7=A0=81=E4=BD=BF=E7=94=A8'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/HighCouponCodeController.java | 40 +++++++++++++-- .../com/hai/common/exception/ErrorCode.java | 3 ++ .../hai/service/HighCouponCodeService.java | 15 ++++++ .../com/hai/service/HighOrderService.java | 14 +++++ .../impl/HighCouponCodeServiceImpl.java | 51 +++++++++++++++++++ .../service/impl/HighOrderServiceImpl.java | 32 ++++++++++++ .../pay/impl/GoodsOrderServiceImpl.java | 4 +- 7 files changed, 153 insertions(+), 6 deletions(-) diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighCouponCodeController.java b/hai-bweb/src/main/java/com/bweb/controller/HighCouponCodeController.java index 9c77dc6d..306b8159 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighCouponCodeController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighCouponCodeController.java @@ -1,11 +1,13 @@ package com.bweb.controller; +import com.alibaba.fastjson.JSONObject; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.hai.common.exception.ErrorCode; 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.ResponseMsgUtil; import com.hai.entity.HighCouponCode; import com.hai.model.ResponseData; @@ -13,16 +15,15 @@ import com.hai.model.UserInfoModel; import com.hai.service.HighCouponCodeService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -41,6 +42,9 @@ public class HighCouponCodeController { @Resource private HighCouponCodeService highCouponCodeService; + @Resource + private UserCenter userCenter; + @RequestMapping(value="/getCouponCodeList",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "销售码列表") @@ -62,4 +66,32 @@ public class HighCouponCodeController { return ResponseMsgUtil.exception(e); } } + + + @RequestMapping(value="/useCouponCode",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "使用卡卷码") + public ResponseData useCouponCode(@RequestBody String reqBody, HttpServletRequest request) { + try { + SessionObject sessionObject = userCenter.getSessionObject(request); + UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); + if (userInfoModel.getMerchantStore() == null) { + log.error("HighMerchantController -> useCouponCode() error!","该主角色没有权限"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.MENU_TREE_HAS_NOT_ERROR, ""); + } + JSONObject jsonObject = JSONObject.parseObject(reqBody); + String code = jsonObject.getString("code"); + if (StringUtils.isBlank(code)) { + log.error("HighMerchantStoreController -> useCouponCode() error!","参数错误"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + highCouponCodeService.useCouponCode(code, userInfoModel); + + return ResponseMsgUtil.success("操作成功"); + } catch (Exception e) { + log.error("HighCouponController -> useCouponCode() error!",e); + return ResponseMsgUtil.exception(e); + } + } } diff --git a/hai-service/src/main/java/com/hai/common/exception/ErrorCode.java b/hai-service/src/main/java/com/hai/common/exception/ErrorCode.java index 87410b11..4565bad4 100644 --- a/hai-service/src/main/java/com/hai/common/exception/ErrorCode.java +++ b/hai-service/src/main/java/com/hai/common/exception/ErrorCode.java @@ -100,6 +100,9 @@ public enum ErrorCode { COUPON_STOCK_INSUFFICIENT("2118","卡卷库存数量不足"), NOT_FOUND_ORDER("2119","未找到订单信息"), ORDER_NO_STAY_PAY("2120","订单不处于待支付状态"), + NOT_FOUND_COUPON_CODE("2121","销售码不存在"), + COUPON_CODE_STATUS("2122","卡券码状态错误"), + COUPON_CODE_OVERDUE("2122","卡券码已过期"), STATUS_ERROR("3000","状态错误"), ADD_DATA_ERROR("3001","增加数据失败"), diff --git a/hai-service/src/main/java/com/hai/service/HighCouponCodeService.java b/hai-service/src/main/java/com/hai/service/HighCouponCodeService.java index 26ba1180..54084960 100644 --- a/hai-service/src/main/java/com/hai/service/HighCouponCodeService.java +++ b/hai-service/src/main/java/com/hai/service/HighCouponCodeService.java @@ -2,6 +2,7 @@ package com.hai.service; import com.hai.entity.HighCouponCode; import com.hai.model.HighCouponCodeModel; +import com.hai.model.UserInfoModel; import java.util.Date; import java.util.List; @@ -35,6 +36,13 @@ public interface HighCouponCodeService { **/ void updateCouponCode(HighCouponCode highCouponCode); + /** + * @Author 胡锐 + * @Description 使用卡卷 + * @Date 2021/3/27 13:21 + **/ + void useCouponCode(String code, UserInfoModel userInfoModel); + /** * @Author 胡锐 * @Description 根据订单id查询 @@ -42,6 +50,13 @@ public interface HighCouponCodeService { **/ HighCouponCode getCouponCodeByOrderId(Long childOrderId); + /** + * @Author 胡锐 + * @Description 根据销售码查询 + * @Date 2021/3/27 12:39 + **/ + HighCouponCode getCouponCodeBySalesCode(String code); + /** * * @Title: getStockCountByCoupon diff --git a/hai-service/src/main/java/com/hai/service/HighOrderService.java b/hai-service/src/main/java/com/hai/service/HighOrderService.java index ca33705f..533102eb 100644 --- a/hai-service/src/main/java/com/hai/service/HighOrderService.java +++ b/hai-service/src/main/java/com/hai/service/HighOrderService.java @@ -33,6 +33,13 @@ public interface HighOrderService { **/ void updateOrder(HighOrder highOrder); + /** + * @Author 胡锐 + * @Description 获取未完成的子订单数量 + * @Date 2021/3/27 13:35 + **/ + Integer getUndoneChildOrder(Long orderId); + /** * @Author 胡锐 * @Description 根据id查询 @@ -54,4 +61,11 @@ public interface HighOrderService { **/ List getOrderList(Map map); + /** + * @Author 胡锐 + * @Description 子订单完成 + * @Date 2021/3/27 13:28 + **/ + void childOrderComplete(Long childOrderId); + } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighCouponCodeServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighCouponCodeServiceImpl.java index 27fa90f6..9002bb4b 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighCouponCodeServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighCouponCodeServiceImpl.java @@ -1,13 +1,22 @@ package com.hai.service.impl; +import com.hai.common.exception.ErrorCode; +import com.hai.common.exception.ErrorHelp; +import com.hai.common.exception.SysCode; import com.hai.dao.HighCouponCodeMapper; import com.hai.dao.HighCouponCodeMapperExt; +import com.hai.entity.HighChildOrder; import com.hai.entity.HighCouponCode; import com.hai.entity.HighCouponCodeExample; +import com.hai.entity.HighOrder; +import com.hai.model.UserInfoModel; import com.hai.service.HighCouponCodeService; +import com.hai.service.HighOrderService; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.Date; @@ -29,6 +38,9 @@ public class HighCouponCodeServiceImpl implements HighCouponCodeService { @Resource private HighCouponCodeMapperExt highCouponCodeMapperExt; + @Resource + private HighOrderService highOrderService; + @Override public void insertCouponCode(HighCouponCode highCouponCode) { highCouponCodeMapper.insert(highCouponCode); @@ -44,6 +56,34 @@ public class HighCouponCodeServiceImpl implements HighCouponCodeService { highCouponCodeMapper.updateByPrimaryKey(highCouponCode); } + @Override + @Transactional(propagation= Propagation.REQUIRES_NEW) + public void useCouponCode(String code, UserInfoModel userInfoModel) { + + // 查询销售码 + HighCouponCode salesCode = getCouponCodeBySalesCode(code); + if (salesCode == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON_CODE, ""); + } + + // 状态:1.待销售 2.未使用 3.已使用 99.预支付 + if (salesCode.getStatus() != 2) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COUPON_CODE_STATUS, ""); + } + + // 使用时间已到期 + if (salesCode.getUseEndTime().compareTo(new Date()) == -1) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COUPON_CODE_OVERDUE, ""); + } + + salesCode.setStoreId(userInfoModel.getMerchantStore().getId()); + salesCode.setConsumeTime(new Date()); + salesCode.setStatus(3); + updateCouponCode(salesCode); + + highOrderService.childOrderComplete(salesCode.getChildOrderId()); + } + @Override public HighCouponCode getCouponCodeByOrderId(Long childOrderId) { HighCouponCodeExample example = new HighCouponCodeExample(); @@ -56,6 +96,17 @@ public class HighCouponCodeServiceImpl implements HighCouponCodeService { return null; } + @Override + public HighCouponCode getCouponCodeBySalesCode(String code) { + HighCouponCodeExample example = new HighCouponCodeExample(); + example.createCriteria().andSalesCodeEqualTo(code); + List codes = highCouponCodeMapper.selectByExample(example); + if (codes != null && codes.size() > 0) { + return codes.get(0); + } + return null; + } + @Override public Integer getStockCountByCoupon(Long couponId) { HighCouponCodeExample example = new HighCouponCodeExample(); 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 0a918a18..eaebe53a 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,6 +167,18 @@ public class HighOrderServiceImpl implements HighOrderService { } } + @Override + public Integer getUndoneChildOrder(Long orderId) { + HighOrder order = getOrderById(orderId); + Integer count = 0; + for (HighChildOrder childOrder : order.getHighChildOrderList()) { + if (childOrder.getChildOrdeStatus() != 3) { + count++; + } + } + return count; + } + @Override public HighOrder getOrderById(Long id) { HighOrder order = highOrderMapper.selectByPrimaryKey(id); @@ -213,4 +225,24 @@ public class HighOrderServiceImpl implements HighOrderService { example.setOrderByClause("create_time desc"); return highOrderMapper.selectByExample(example); } + + @Override + @Transactional(propagation= Propagation.REQUIRES_NEW) + public void childOrderComplete(Long childOrderId) { + HighChildOrder childOrder = highChildOrderMapper.selectByPrimaryKey(childOrderId); + if (childOrder == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + childOrder.setChildOrdeStatus(3); + highChildOrderMapper.updateByPrimaryKey(childOrder); + + // 查询未完成的子订单数量 + Integer count = getUndoneChildOrder(childOrder.getOrderId()); + if (count == 0) { + HighOrder order = getOrderById(childOrder.getOrderId()); + order.setOrderStatus(3); + order.setFinishTime(new Date()); + highOrderMapper.updateByPrimaryKey(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 f7de2069..1bc58098 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 @@ -62,10 +62,9 @@ public class GoodsOrderServiceImpl implements PayService { order.setOrderStatus(2); // 订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 for (HighChildOrder highChildOrder : order.getHighChildOrderList()) { - highChildOrder.setChildOrdeStatus(2); // 子订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 - // 商品类型 商品类型 1:卡卷 2:金币充值 if (highChildOrder.getGoodsType() == 1) { + highChildOrder.setChildOrdeStatus(2); // 子订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 HighCouponCode code = highCouponCodeService.getCouponCodeByOrderId(highChildOrder.getId()); code.setStatus(2); // 状态:1.待销售 2.未使用 3.已使用 99.预支付 highCouponCodeService.updateCouponCode(code); @@ -82,6 +81,7 @@ public class GoodsOrderServiceImpl implements PayService { } if (highChildOrder.getGoodsType() == 2) { + highChildOrder.setChildOrdeStatus(3); // 子订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 // 金币 1:100 Integer goldNum = new BigDecimal(highChildOrder.getTotalPrice().toString()).multiply(new BigDecimal("100")).intValue(); highUserService.goldHandle(highChildOrder.getGoodsId(), goldNum, 1, 1, highChildOrder.getId());