diff --git a/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/response/member/MemberHeadResponse.java b/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/response/member/MemberHeadResponse.java new file mode 100644 index 000000000..076bac5ba --- /dev/null +++ b/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/response/member/MemberHeadResponse.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.shop.response.member; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; + +/** + * @Title:MemberGradeResponse + * @Description: TODO + * @author: tangqian + * @date: 2023/5/17 13:45 + * @version: V1.0.0 + */ +@Data +public class MemberHeadResponse implements Serializable { + private static final long serialVersionUID = 5155396515478444684L; + @Schema(description = "会员等级") + private String grade; + @Schema(description = "会员积分") + private String integral; +} diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/admin/notify/WxPayNotifyController.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/admin/notify/WxPayNotifyController.java index 77b2445a5..ac69a1215 100644 --- a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/admin/notify/WxPayNotifyController.java +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/admin/notify/WxPayNotifyController.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.shop.controller.admin.notify; import cn.hutool.json.JSONUtil; +import cn.iocoder.yudao.module.shop.service.order.StoreOrderService; import com.github.binarywang.wxpay.bean.notify.OriginNotifyResponse; import com.github.binarywang.wxpay.bean.notify.SignatureHeader; import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyV3Result; @@ -31,113 +32,106 @@ import javax.servlet.http.HttpServletResponse; public class WxPayNotifyController { + @Autowired + private WxPayService wxPayService; - @Autowired - private WxPayService wxPayService; + @Autowired + private StoreOrderService storeOrderService; - - - - - - - /** - * Description: 微信支付回调接口 - * - * @author: perry - * @date: 2019/8/15 20:05 - * @param: - * @return: - */ - @PostMapping("/pay_notify") - public String wxPayNotify(@RequestBody String jsonData, HttpServletRequest request, HttpServletResponse response) { - // 支付结果通用通知文档: https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7 - // 支付成功结果通知 - log.info("支付原始通知=" + jsonData); - OriginNotifyResponse notifyResponse = JSONUtil.toBean(jsonData, OriginNotifyResponse.class); - log.info("支付原始通知=" + JSONUtil.toJsonPrettyStr(notifyResponse)); - WxPayOrderNotifyV3Result v3Result = null; - try { - //解密后的数据 - v3Result = wxPayService.parseOrderNotifyV3Result(jsonData, this.getRequestHeader(request)); - WxPayOrderNotifyV3Result.DecryptNotifyResult result = v3Result.getResult(); - log.info("支付通知=" + JSONUtil.toJsonPrettyStr(result)); - if (StringUtils.equals("SUCCESS",result.getTradeType())) { - log.info("微信支付回调成功"); - // 验证相关参数-金额 - // 修改订单状态 - // 写入 - response.setStatus(HttpServletResponse.SC_OK); - return "success"; - } - } catch (Exception e) { - log.error(e.getMessage(), e); + /** + * Description: 微信支付回调接口 + * + * @author: perry + * @date: 2019/8/15 20:05 + * @param: + * @return: + */ + @PostMapping("/pay_notify") + public String wxPayNotify(@RequestBody String jsonData, HttpServletRequest request, HttpServletResponse response) { + // 支付结果通用通知文档: https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7 + // 支付成功结果通知 + log.info("支付原始通知=" + jsonData); + OriginNotifyResponse notifyResponse = JSONUtil.toBean(jsonData, OriginNotifyResponse.class); + log.info("支付原始通知=" + JSONUtil.toJsonPrettyStr(notifyResponse)); + WxPayOrderNotifyV3Result v3Result = null; + try { + //解密后的数据 + v3Result = wxPayService.parseOrderNotifyV3Result(jsonData, this.getRequestHeader(request)); + WxPayOrderNotifyV3Result.DecryptNotifyResult result = v3Result.getResult(); + // 验签 + Boolean b = storeOrderService.wxPayNotify(result); + if (b) { + response.setStatus(HttpServletResponse.SC_OK); + return "success"; + } + } catch (Exception e) { + log.error(e.getMessage(), e); + } + // 通知应答码:HTTP应答状态码需返回5XX或4XX,同时需返回应答报文 + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + return "failure"; } - // 通知应答码:HTTP应答状态码需返回5XX或4XX,同时需返回应答报文 - response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - return "failure"; - } - /** - * 获取回调请求头:签名相关 - * - * @param request HttpServletRequest - * @return SignatureHeader - */ - public SignatureHeader getRequestHeader(HttpServletRequest request) { - // 获取通知签名 - String signature = request.getHeader("wechatpay-signature"); - String nonce = request.getHeader("wechatpay-nonce"); - String serial = request.getHeader("wechatpay-serial"); - String timestamp = request.getHeader("wechatpay-timestamp"); + /** + * 获取回调请求头:签名相关 + * + * @param request HttpServletRequest + * @return SignatureHeader + */ + public SignatureHeader getRequestHeader(HttpServletRequest request) { + // 获取通知签名 + String signature = request.getHeader("wechatpay-signature"); + String nonce = request.getHeader("wechatpay-nonce"); + String serial = request.getHeader("wechatpay-serial"); + String timestamp = request.getHeader("wechatpay-timestamp"); - SignatureHeader signatureHeader = new SignatureHeader(); - signatureHeader.setSignature(signature); - signatureHeader.setNonce(nonce); - signatureHeader.setSerial(serial); - signatureHeader.setTimeStamp(timestamp); - return signatureHeader; - } - - - /** - * Description: 微信支付退款回调接口 - * - * @author: perry - * @date: 2019/8/15 20:05 - * @param: - * @return: - */ - @PostMapping("/refund_notify") - public String wxPayRefundNotify(@RequestBody String jsonData, HttpServletRequest request, HttpServletResponse response) throws Exception { - // 支付结果通用通知文档: https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7 - // 支付成功结果通知 - OriginNotifyResponse notifyResponse = JSONUtil.toBean(jsonData, OriginNotifyResponse.class); - WxPayRefundNotifyV3Result v3Result = null; - log.info("退款原始通知=" + JSONUtil.toJsonPrettyStr(jsonData)); - try { - //解密后的数据 - v3Result = wxPayService.parseRefundNotifyV3Result(JSONUtil.toJsonPrettyStr(notifyResponse), this.getRequestHeader(request)); - WxPayRefundNotifyV3Result.DecryptNotifyResult result = v3Result.getResult(); - log.info("退款通知=" + JSONUtil.toJsonPrettyStr(result)); - //退款状态 - if (StringUtils.equals("SUCCESS",result.getRefundId())) { - log.info("微信退款回调成功"); - // 验证相关参数-金额 - // 修改订单状态 - // 写入 - response.setStatus(HttpServletResponse.SC_OK); - return "success"; - } - } catch (Exception e) { - log.error(e.getMessage(), e); + SignatureHeader signatureHeader = new SignatureHeader(); + signatureHeader.setSignature(signature); + signatureHeader.setNonce(nonce); + signatureHeader.setSerial(serial); + signatureHeader.setTimeStamp(timestamp); + return signatureHeader; } - // 通知应答码:HTTP应答状态码需返回5XX或4XX,同时需返回应答报文 - response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - return "failure"; - } + /** + * Description: 微信支付退款回调接口 + * + * @author: perry + * @date: 2019/8/15 20:05 + * @param: + * @return: + */ + @PostMapping("/refund_notify") + public String wxPayRefundNotify(@RequestBody String jsonData, HttpServletRequest request, HttpServletResponse response) throws Exception { + // 支付结果通用通知文档: https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7 + // 支付成功结果通知 + OriginNotifyResponse notifyResponse = JSONUtil.toBean(jsonData, OriginNotifyResponse.class); + WxPayRefundNotifyV3Result v3Result = null; + log.info("退款原始通知=" + JSONUtil.toJsonPrettyStr(jsonData)); + try { + //解密后的数据 + v3Result = wxPayService.parseRefundNotifyV3Result(JSONUtil.toJsonPrettyStr(notifyResponse), this.getRequestHeader(request)); + WxPayRefundNotifyV3Result.DecryptNotifyResult result = v3Result.getResult(); + log.info("退款通知=" + JSONUtil.toJsonPrettyStr(result)); + //退款状态 + if (StringUtils.equals("SUCCESS", result.getRefundId())) { + log.info("微信退款回调成功"); + // 验证相关参数-金额 + // 修改订单状态 + // 写入 + response.setStatus(HttpServletResponse.SC_OK); + return "success"; + } + } catch (Exception e) { + log.error(e.getMessage(), e); + } + // 通知应答码:HTTP应答状态码需返回5XX或4XX,同时需返回应答报文 + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + + return "failure"; + + } } diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/admin/recharge/vo/RechargeGearRespVO.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/admin/recharge/vo/RechargeGearRespVO.java index 9e4006b8a..0c1ac5524 100644 --- a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/admin/recharge/vo/RechargeGearRespVO.java +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/admin/recharge/vo/RechargeGearRespVO.java @@ -16,4 +16,7 @@ public class RechargeGearRespVO extends RechargeGearBaseVO { @Schema(description = "创建时间", required = true) private LocalDateTime createTime; + @Schema(description = "该挡位是否已充值1是0否", required = true) + private String isExist; + } diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/app/buy/TopUpOrderController.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/app/buy/TopUpOrderController.java index 10ae23ee9..8db055756 100644 --- a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/app/buy/TopUpOrderController.java +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/app/buy/TopUpOrderController.java @@ -48,5 +48,11 @@ public class TopUpOrderController { } + @Operation(summary = "申请退款") + @RequestMapping(value = "/memberApplyRefund", method = RequestMethod.POST) + public CommonResult memberApplyRefund(@Valid @RequestBody RefundRequest request){ + log.info("memberApplyRefund申请退款===>{}", request); + return CommonResult.success(storeOrderService.memberApplyRefund(request)); + } } diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/app/member/MemberController.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/app/member/MemberController.java index ed739bab2..3399878ba 100644 --- a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/app/member/MemberController.java +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/app/member/MemberController.java @@ -1,12 +1,12 @@ package cn.iocoder.yudao.module.shop.controller.app.member; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; import cn.iocoder.yudao.module.shop.controller.admin.recharge.vo.RechargeGearRespVO; import cn.iocoder.yudao.module.shop.controller.admin.recharge.vo.RechargeOrderRespVO; -import cn.iocoder.yudao.module.shop.convert.recharge.RechargeGearConvert; import cn.iocoder.yudao.module.shop.convert.recharge.RechargeOrderConvert; -import cn.iocoder.yudao.module.shop.dal.dataobject.recharge.RechargeGearDO; import cn.iocoder.yudao.module.shop.dal.dataobject.recharge.RechargeOrderDO; +import cn.iocoder.yudao.module.shop.response.member.MemberHeadResponse; import cn.iocoder.yudao.module.shop.service.recharge.RechargeGearService; import cn.iocoder.yudao.module.shop.service.recharge.RechargeOrderService; import io.swagger.v3.oas.annotations.Operation; @@ -40,17 +40,26 @@ public class MemberController { // 会员档次信息列表 @Operation(summary = "会员档次信息") @RequestMapping(value = "/memberGradeInfo", method = RequestMethod.GET) + @PreAuthenticated public CommonResult> memberGradeInfo() { - List gradeInfo = rechargeGearService.getGradeInfo(); - return CommonResult.success(RechargeGearConvert.INSTANCE.convertList(gradeInfo)); + return CommonResult.success(rechargeGearService.getGradeInfo()); } // 充值列表记录 @Operation(summary = "获取当前登录账号的充值记录") @RequestMapping(value = "/memberOrderInfo", method = RequestMethod.GET) + @PreAuthenticated public CommonResult> memberOrderInfo() { List orderDOS = rechargeOrderService.memberOrderInfo(); return CommonResult.success(RechargeOrderConvert.INSTANCE.convertList(orderDOS)); } + @Operation(summary = "会员头部信息") + @RequestMapping(value = "/memberHeadInfo", method = RequestMethod.GET) + @PreAuthenticated + public CommonResult memberHeadInfo() { + return CommonResult.success(rechargeOrderService.memberHeadInfo()); + } + + } diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/dal/dataobject/recharge/PhoneRecordDO.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/dal/dataobject/recharge/PhoneRecordDO.java index be91c71f8..4fff21412 100644 --- a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/dal/dataobject/recharge/PhoneRecordDO.java +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/dal/dataobject/recharge/PhoneRecordDO.java @@ -49,7 +49,7 @@ public class PhoneRecordDO extends BaseDO { /** * 充值档位 */ - private BigDecimal rechargeGearId; + private Long rechargeGearId; /** * 返费结束日期 */ diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/order/StoreOrderService.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/order/StoreOrderService.java index 980267c3f..295f253ad 100644 --- a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/order/StoreOrderService.java +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/order/StoreOrderService.java @@ -14,6 +14,7 @@ import cn.iocoder.yudao.module.shop.response.member.InitOrderResponse; import cn.iocoder.yudao.module.shop.response.order.*; import cn.iocoder.yudao.module.shop.vo.order.LogisticsResultVo; import com.baomidou.mybatisplus.extension.service.IService; +import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyV3Result; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.pagehelper.PageInfo; @@ -398,4 +399,8 @@ public interface StoreOrderService extends IService { Object memberRefund(RefundRequest request, HttpServletRequest servletRequest); Object refundNotify(HttpServletRequest request, Map params); + + Boolean wxPayNotify(WxPayOrderNotifyV3Result.DecryptNotifyResult result); + + Boolean memberApplyRefund(RefundRequest request); } diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/order/impl/StoreOrderRefundServiceImpl.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/order/impl/StoreOrderRefundServiceImpl.java index 992846071..14b8c44b0 100644 --- a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/order/impl/StoreOrderRefundServiceImpl.java +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/order/impl/StoreOrderRefundServiceImpl.java @@ -70,6 +70,7 @@ public class StoreOrderRefundServiceImpl extends ServiceImpl{}", params); String orderId = params.get("out_trade_no"); String amount = params.get("refund_amount"); String total_amount = params.get("total_amount"); - log.info("orderId:{}",orderId); - log.info("amount:{}",amount); - log.info("amount:{}",total_amount); + log.info("orderId:{}", orderId); + log.info("amount:{}", amount); + log.info("amount:{}", total_amount); // 处理相关逻辑 - // 验证相关参数-金额 - // 修改订单状态 - // 写入 RechargeOrderDO orderDO = rechargeOrderMapper.selectOne(Wrappers.lambdaQuery().eq(RechargeOrderDO::getOrderId, orderId)); + if (Objects.isNull(orderDO)) { + log.error("订单号错误,未查询到相关信息!入参订单号:{}", orderId); + return "failure"; + } + // 验证相关参数-金额 + if (new BigDecimal(amount).compareTo(orderDO.getPayPrice()) != 0) { + log.error("支付金额不匹配,订单实际支付金额:{},支付宝入参验证金额:{}", orderDO.getPayPrice(), amount); + return "failure"; + } + // 修改订单状态 orderDO.setPaid((byte) 1); rechargeOrderMapper.updateById(orderDO); + // 写入 充值档位记录表 + addPhoneRecord(orderDO, orderId); + log.debug(">>>>>>>>>>>>>>支付宝订单交易成功!订单号:{}<<<<<<<<<<<<<<<<<<<<", orderId); return "success"; } else { return "failure"; } } + public void addPhoneRecord(RechargeOrderDO orderDO, String orderId) { + List infoDOS = rechargeOrderInfoMapper.selectList(Wrappers.lambdaQuery().eq(RechargeOrderInfoDO::getOrderNo, orderId)); + List recordDOS = new ArrayList<>(); + infoDOS.forEach(info -> { + PhoneRecordDO phoneRecordDO = new PhoneRecordDO(); + phoneRecordDO.setUserId(Long.valueOf(orderDO.getUid())); + phoneRecordDO.setRechargeOrderId(Long.valueOf(orderDO.getId())); + phoneRecordDO.setPhone(orderDO.getUserPhone()); + phoneRecordDO.setRefundFeeAmount(replace(info.getPrice())); + phoneRecordDO.setRechargeGearId(Long.valueOf(info.getRechargeGearId())); + LocalDateTime localDateTime = LocalDateTime.now(); + LocalDateTime newLocalDateTime = localDateTime.plusMonths(12); + phoneRecordDO.setRefundFeeEndDate(newLocalDateTime); + phoneRecordDO.setRefundFeeNumber("12"); + recordDOS.add(phoneRecordDO); + }); + phoneRecordMapper.insertBatch(recordDOS); + } + + public BigDecimal replace(BigDecimal amount) { + if (new BigDecimal("240").compareTo(amount) == 0) { + return new BigDecimal("360"); + } else if (new BigDecimal("400").compareTo(amount) == 0) { + return new BigDecimal("600"); + } else if (new BigDecimal("640").compareTo(amount) == 0) { + return new BigDecimal("960"); + } + return null; + } + + @Override public Object memberRefund(RefundRequest request, HttpServletRequest servletRequest) { RechargeOrderDO orderDO = rechargeOrderMapper.selectById(request.getOrderId()); @@ -1187,10 +1236,10 @@ public class StoreOrderServiceImpl extends ServiceImpl paramMap = new HashMap<>(params); paramMap.remove("sign_type"); // 移除sign_type参数 @@ -1201,17 +1250,13 @@ public class StoreOrderServiceImpl extends ServiceImpl"); + // 验证相关参数-金额 + String outTradeNo = result.getOutTradeNo(); + // 用户支付金额 + Integer payerTotal = result.getAmount().getPayerTotal() / 100; + // 处理相关逻辑 + RechargeOrderDO orderDO = rechargeOrderMapper.selectOne(Wrappers.lambdaQuery().eq(RechargeOrderDO::getOrderId, outTradeNo)); + if (new BigDecimal(payerTotal).compareTo(orderDO.getPayPrice()) != 0) { + log.error("支付金额不匹配,订单实际支付金额:{},微信入参验证金额:{}", orderDO.getPayPrice(), payerTotal); + return Boolean.FALSE; + } + // 修改订单状态 + orderDO.setPaid((byte) 1); + rechargeOrderMapper.updateById(orderDO); + // 写入 充值档位记录表 + addPhoneRecord(orderDO, outTradeNo); + log.debug(">>>>>>>>>>>>>>微信订单交易成功!订单号:{}<<<<<<<<<<<<<<<<<<<<", outTradeNo); + } + return Boolean.TRUE; + } + + @Override + public Boolean memberApplyRefund(RefundRequest request) { + RechargeOrderDO orderDO = rechargeOrderMapper.selectById(request.getOrderId()); + orderDO.setRefundStatus((byte) 1); + return rechargeOrderMapper.updateById(orderDO) > 0; + } + private RechargeOrderDO initializeOrder(OrderContentRequest request, String code, MemberUserRespDTO user) { RechargeOrderDO orderDO = new RechargeOrderDO(); diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/recharge/RechargeGearService.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/recharge/RechargeGearService.java index d526d6c3e..7df68dd83 100644 --- a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/recharge/RechargeGearService.java +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/recharge/RechargeGearService.java @@ -67,5 +67,5 @@ public interface RechargeGearService { */ List getRechargeGearList(RechargeGearExportReqVO exportReqVO); - List getGradeInfo(); + List getGradeInfo(); } diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/recharge/RechargeGearServiceImpl.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/recharge/RechargeGearServiceImpl.java index 22822d1ca..42beda78e 100644 --- a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/recharge/RechargeGearServiceImpl.java +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/recharge/RechargeGearServiceImpl.java @@ -1,11 +1,23 @@ package cn.iocoder.yudao.module.shop.service.recharge; +import cn.iocoder.yudao.framework.security.core.LoginUser; +import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; +import cn.iocoder.yudao.module.shop.dal.dataobject.recharge.RechargeOrderDO; +import cn.iocoder.yudao.module.shop.dal.dataobject.recharge.RechargeOrderInfoDO; +import cn.iocoder.yudao.module.shop.dal.mysql.recharge.RechargeOrderInfoMapper; +import cn.iocoder.yudao.module.shop.dal.mysql.recharge.RechargeOrderMapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import org.springframework.stereotype.Service; + import javax.annotation.Resource; + +import org.springframework.util.Assert; +import org.springframework.util.CollectionUtils; import org.springframework.validation.annotation.Validated; import java.util.*; +import java.util.stream.Collectors; + import cn.iocoder.yudao.module.shop.controller.admin.recharge.vo.*; import cn.iocoder.yudao.module.shop.dal.dataobject.recharge.RechargeGearDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -27,6 +39,10 @@ public class RechargeGearServiceImpl implements RechargeGearService { @Resource private RechargeGearMapper rechargeGearMapper; + @Resource + private RechargeOrderInfoMapper orderInfoMapper; + @Resource + private RechargeOrderMapper orderMapper; @Override public String createRechargeGear(RechargeGearCreateReqVO createReqVO) { @@ -81,9 +97,26 @@ public class RechargeGearServiceImpl implements RechargeGearService { } @Override - public List getGradeInfo() { - return rechargeGearMapper.selectList(Wrappers.lambdaQuery() + public List getGradeInfo() { + LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); + Assert.notNull(loginUser, "登录失效,请重新登录!"); + List rechargeGearDOS = rechargeGearMapper.selectList(Wrappers.lambdaQuery() .eq(RechargeGearDO::getDeleted, 0)); + List rechargeGearRespVOS = RechargeGearConvert.INSTANCE.convertList(rechargeGearDOS); + RechargeOrderDO orderDO = orderMapper.selectOne(Wrappers.lambdaQuery().eq(RechargeOrderDO::getUid, loginUser.getId()).last("LIMIT 1")); + if (Objects.nonNull(orderDO)) { + List infoDOS = orderInfoMapper.selectList(Wrappers.lambdaQuery().eq(RechargeOrderInfoDO::getOrderNo, orderDO.getOrderId())); + Map> collect = infoDOS.stream().collect(Collectors.groupingBy(RechargeOrderInfoDO::getRechargeGearId)); + rechargeGearRespVOS.forEach(vo -> { + List infoDOS1 = collect.get(vo.getId()); + if (!CollectionUtils.isEmpty(infoDOS1)) { + vo.setIsExist("1"); + } else { + vo.setIsExist("0"); + } + }); + } + return rechargeGearRespVOS; } } diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/recharge/RechargeOrderService.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/recharge/RechargeOrderService.java index 31308cad0..a5b7a24a5 100644 --- a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/recharge/RechargeOrderService.java +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/recharge/RechargeOrderService.java @@ -5,6 +5,7 @@ import javax.validation.*; import cn.iocoder.yudao.module.shop.controller.admin.recharge.vo.*; import cn.iocoder.yudao.module.shop.dal.dataobject.recharge.RechargeOrderDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.shop.response.member.MemberHeadResponse; /** * 订单 Service 接口 @@ -69,4 +70,5 @@ public interface RechargeOrderService { List memberOrderInfo(); + MemberHeadResponse memberHeadInfo(); } diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/recharge/RechargeOrderServiceImpl.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/recharge/RechargeOrderServiceImpl.java index c1227ce02..830b76302 100644 --- a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/recharge/RechargeOrderServiceImpl.java +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/recharge/RechargeOrderServiceImpl.java @@ -2,14 +2,19 @@ package cn.iocoder.yudao.module.shop.service.recharge; import cn.iocoder.yudao.framework.security.core.LoginUser; import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; +import cn.iocoder.yudao.module.shop.response.member.MemberHeadResponse; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import org.springframework.stereotype.Service; + import javax.annotation.Resource; import org.springframework.util.Assert; +import org.springframework.util.CollectionUtils; import org.springframework.validation.annotation.Validated; +import java.math.BigDecimal; import java.util.*; + import cn.iocoder.yudao.module.shop.controller.admin.recharge.vo.*; import cn.iocoder.yudao.module.shop.dal.dataobject.recharge.RechargeOrderDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -88,7 +93,32 @@ public class RechargeOrderServiceImpl implements RechargeOrderService { public List memberOrderInfo() { LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); Assert.notNull(loginUser, "登录失效,请重新登录!"); - return rechargeOrderMapper.selectList(Wrappers.lambdaQuery().eq(RechargeOrderDO::getUid,loginUser.getId())); + return rechargeOrderMapper.selectList(Wrappers.lambdaQuery().eq(RechargeOrderDO::getUid, loginUser.getId())); + } + + @Override + public MemberHeadResponse memberHeadInfo() { + MemberHeadResponse response = new MemberHeadResponse(); + LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); + Assert.notNull(loginUser, "登录失效,请重新登录!"); + List orderDOS = rechargeOrderMapper.selectList(Wrappers.lambdaQuery().eq(RechargeOrderDO::getUid, loginUser.getId())); + if (!CollectionUtils.isEmpty(orderDOS)) { + BigDecimal amount = new BigDecimal("0"); + for (RechargeOrderDO orderDO : orderDOS) { + amount = amount.add(orderDO.getPayPrice()); + } + if (amount.compareTo(new BigDecimal("640")) < 0) { + response.setGrade("普通会员"); + response.setIntegral(amount.stripTrailingZeros().toPlainString() + "/" + "640"); + } else if (amount.compareTo(new BigDecimal("640")) >= 0) { + response.setGrade("高级会员"); + response.setIntegral(amount.stripTrailingZeros().toPlainString() + "/" + "1040"); + } else { + response.setGrade("中级会员"); + response.setIntegral(amount.stripTrailingZeros().toPlainString() + "/" + "1040"); + } + } + return response; } }