From 45f7566a07c8c1062687ea183b3a072a1a779638 Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Mon, 27 Nov 2023 14:34:49 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/cweb/config/AuthConfig.java | 1 + .../controller/HighUserCardController.java | 49 +++++++++++++++++-- .../impl/OrderCreateHandleServiceImpl.java | 15 +++++- 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java b/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java index 2279fb54..7ab3938c 100644 --- a/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java +++ b/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java @@ -126,6 +126,7 @@ public class AuthConfig implements WebMvcConfigurer { .excludePathPatterns("/wechat/*") .excludePathPatterns("/tuanyou/*") .excludePathPatterns("/notify/*") + .excludePathPatterns("/highUserCard/calculateRecharge") .excludePathPatterns("/highOrder/getOrderByOrderNo") .excludePathPatterns("/coupon/getUserCouponByOrderNo") .excludePathPatterns("/activity/getActivityByCoupon") diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighUserCardController.java b/hai-cweb/src/main/java/com/cweb/controller/HighUserCardController.java index 55f80eae..38838d5a 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighUserCardController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighUserCardController.java @@ -10,10 +10,7 @@ import com.hai.common.security.UserCenter; import com.hai.common.utils.RedisUtil; import com.hai.common.utils.ResponseMsgUtil; import com.hai.config.HuiLianTongUnionCardConfig; -import com.hai.entity.HighFleetOilCard; -import com.hai.entity.HighOilCard; -import com.hai.entity.HighUser; -import com.hai.entity.HighUserCard; +import com.hai.entity.*; import com.hai.enum_type.UserCardType; import com.hai.model.HighUserModel; import com.hai.model.ResponseData; @@ -30,6 +27,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.*; @Controller @@ -60,6 +58,49 @@ public class HighUserCardController { @Resource private HighOilCardService oilCardService; + @Resource + private SecConfigService secConfigService; + + @RequestMapping(value = "/calculateRecharge", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "计算充值金额") + public ResponseData calculateRecharge(@RequestBody JSONObject body, HttpServletRequest request) { + try { + + if (body == null || body.getBigDecimal("rechargeAmount") == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + // 充值赠送比例 + SecConfig rechargeRatio = secConfigService.findByCodeType("OIL_CARD_RECHARGE_RATIO"); + + // 充值金额 + BigDecimal rechargeAmount = body.getBigDecimal("rechargeAmount"); + + // 赠送比例 + BigDecimal ratio = new BigDecimal("0"); + + // 赠送金额 + BigDecimal givePrice = new BigDecimal("0"); + + if (rechargeRatio != null) { + ratio = new BigDecimal(rechargeRatio.getCodeValue()).divide(new BigDecimal("100")); + givePrice = body.getBigDecimal("rechargeAmount").multiply(ratio).setScale(2, RoundingMode.DOWN); + } + + Map param = new HashMap<>(); + param.put("rechargeAmount", rechargeAmount); + param.put("rechargeRatio", ratio.multiply(new BigDecimal("100"))); + param.put("givePrice", givePrice); + param.put("rechargeAmountTotal", rechargeAmount.add(givePrice)); + return ResponseMsgUtil.success(param); + + } catch (Exception e) { + log.error("HighUserCardController --> calculateRecharge() error!", e); + return ResponseMsgUtil.exception(e); + } + } + @RequestMapping(value = "/bindCard", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "绑卡") diff --git a/hai-service/src/main/java/com/hai/order/service/impl/OrderCreateHandleServiceImpl.java b/hai-service/src/main/java/com/hai/order/service/impl/OrderCreateHandleServiceImpl.java index 9ae858a3..b98987aa 100644 --- a/hai-service/src/main/java/com/hai/order/service/impl/OrderCreateHandleServiceImpl.java +++ b/hai-service/src/main/java/com/hai/order/service/impl/OrderCreateHandleServiceImpl.java @@ -1214,6 +1214,17 @@ public class OrderCreateHandleServiceImpl implements OrderCreateHandleService { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的油卡"); } + // 充值金额 + BigDecimal rechargeAmount = createOrderChildModel.getGoodsPrice(); + // 赠送金额 + BigDecimal givePrice = new BigDecimal("0"); + + SecConfig rechargeRatio = secConfigService.findByCodeType("OIL_CARD_RECHARGE_RATIO"); + if (rechargeRatio != null && StringUtils.isNotBlank(rechargeRatio.getCodeValue())) { + BigDecimal ratio = new BigDecimal(rechargeRatio.getCodeValue()).divide(new BigDecimal("100")); + givePrice = rechargeAmount.multiply(ratio).setScale(2, RoundingMode.DOWN); + } + HighChildOrder childOrder = new HighChildOrder(); childOrder.setOrderNo(order.getOrderNo()); childOrder.setMemId(order.getMemId()); @@ -1224,7 +1235,7 @@ public class OrderCreateHandleServiceImpl implements OrderCreateHandleService { childOrder.setGoodsId(card.getId()); childOrder.setGoodsName("油卡充值"); childOrder.setGoodsSpecName(card.getCardNo()); - childOrder.setGoodsPrice(createOrderChildModel.getGoodsPrice()); + childOrder.setGoodsPrice(rechargeAmount.add(givePrice)); childOrder.setGoodsActualPrice(childOrder.getGoodsPrice()); childOrder.setSaleCount(createOrderChildModel.getSaleCount()); childOrder.setGiveawayType(false); @@ -1234,7 +1245,7 @@ public class OrderCreateHandleServiceImpl implements OrderCreateHandleService { childOrder.setTotalDeductionPrice(childOrder.getTotalPrice().subtract(childOrder.getTotalActualPrice())); childOrder.setPraiseStatus(0); childOrder.setCreateTime(new Date()); - + childOrder.setExt1(givePrice.toString()); return childOrder; } } From 771878c342864e1b8ea693d9a0af985b6a59054b Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Mon, 27 Nov 2023 14:35:04 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hai-cweb/src/main/java/com/cweb/config/AuthConfig.java | 1 - 1 file changed, 1 deletion(-) diff --git a/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java b/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java index 7ab3938c..2279fb54 100644 --- a/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java +++ b/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java @@ -126,7 +126,6 @@ public class AuthConfig implements WebMvcConfigurer { .excludePathPatterns("/wechat/*") .excludePathPatterns("/tuanyou/*") .excludePathPatterns("/notify/*") - .excludePathPatterns("/highUserCard/calculateRecharge") .excludePathPatterns("/highOrder/getOrderByOrderNo") .excludePathPatterns("/coupon/getUserCouponByOrderNo") .excludePathPatterns("/activity/getActivityByCoupon") From de89593c48752ba8bde723165c01b1d20ca1e76a Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Mon, 27 Nov 2023 18:18:51 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/service/impl/OrderCreateHandleServiceImpl.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hai-service/src/main/java/com/hai/order/service/impl/OrderCreateHandleServiceImpl.java b/hai-service/src/main/java/com/hai/order/service/impl/OrderCreateHandleServiceImpl.java index b98987aa..a2dc3294 100644 --- a/hai-service/src/main/java/com/hai/order/service/impl/OrderCreateHandleServiceImpl.java +++ b/hai-service/src/main/java/com/hai/order/service/impl/OrderCreateHandleServiceImpl.java @@ -1236,13 +1236,13 @@ public class OrderCreateHandleServiceImpl implements OrderCreateHandleService { childOrder.setGoodsName("油卡充值"); childOrder.setGoodsSpecName(card.getCardNo()); childOrder.setGoodsPrice(rechargeAmount.add(givePrice)); - childOrder.setGoodsActualPrice(childOrder.getGoodsPrice()); + childOrder.setGoodsActualPrice(createOrderChildModel.getGoodsPrice()); childOrder.setSaleCount(createOrderChildModel.getSaleCount()); childOrder.setGiveawayType(false); childOrder.setChildOrderStatus(OrderChildStatus.STATUS1.getNumber()); childOrder.setTotalPrice(childOrder.getGoodsPrice()); - childOrder.setTotalActualPrice(childOrder.getGoodsPrice()); - childOrder.setTotalDeductionPrice(childOrder.getTotalPrice().subtract(childOrder.getTotalActualPrice())); + childOrder.setTotalActualPrice(createOrderChildModel.getGoodsPrice()); + childOrder.setTotalDeductionPrice(createOrderChildModel.getGoodsPrice().subtract(childOrder.getTotalActualPrice())); childOrder.setPraiseStatus(0); childOrder.setCreateTime(new Date()); childOrder.setExt1(givePrice.toString());