From 34c0db7cf11e3c545ccd8dc47ae7124f2786cb8c Mon Sep 17 00:00:00 2001 From: tangqian Date: Wed, 17 May 2023 10:53:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=9A=E5=91=98=E5=85=85=E5=80=BC,?= =?UTF-8?q?=E9=80=80=E6=AC=BE,=E4=BC=9A=E5=91=98=E5=B1=95=E7=A4=BA,?= =?UTF-8?q?=E5=85=85=E5=80=BC=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/member/OrderContentRequest.java | 2 +- .../response/member/InitOrderResponse.java | 7 ++- .../admin/notify/AliPayNotifyController.java | 8 +-- .../admin/notify/WxPayNotifyController.java | 24 ++++++-- .../app/member/MemberController.java | 56 +++++++++++++++++ .../order/impl/StoreOrderServiceImpl.java | 61 ++++++++++++------- .../service/recharge/RechargeGearService.java | 1 + .../recharge/RechargeGearServiceImpl.java | 7 +++ .../recharge/RechargeOrderService.java | 2 + .../recharge/RechargeOrderServiceImpl.java | 12 ++++ .../shop/support/pay/AliPayStrategy.java | 7 +-- .../service/sms/SmsCodeServiceImpl.java | 8 +-- 12 files changed, 154 insertions(+), 41 deletions(-) create mode 100644 yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/app/member/MemberController.java diff --git a/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/request/member/OrderContentRequest.java b/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/request/member/OrderContentRequest.java index 94ab77d3b..9120c416d 100644 --- a/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/request/member/OrderContentRequest.java +++ b/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/request/member/OrderContentRequest.java @@ -43,7 +43,7 @@ public class OrderContentRequest implements Serializable { private static final long serialVersionUID = -4967251473044468810L; @Schema(description = "订单id") @NotNull(message = "挡位id不能为空") - private Integer gearId; + private String gearId; @Schema(description = "档位名称") @NotEmpty(message = "挡位名称不能为空") diff --git a/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/response/member/InitOrderResponse.java b/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/response/member/InitOrderResponse.java index d5cd2df2a..cfb972450 100644 --- a/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/response/member/InitOrderResponse.java +++ b/yudao-module-mall/yudao-module-shop-api/src/main/java/cn/iocoder/yudao/module/shop/response/member/InitOrderResponse.java @@ -22,9 +22,12 @@ import java.util.List; public class InitOrderResponse implements Serializable { private static final long serialVersionUID = 6894715033655337607L; - @Schema(description = "h5_url") + @Schema(description = "微信返回参数h5_url") private String h5Url; - @Schema(description ="二维码链接") + @Schema(description ="微信返回参数二维码链接") private String codeUrl; + + @Schema(description ="支付宝返回参数") + private String body; } diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/admin/notify/AliPayNotifyController.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/admin/notify/AliPayNotifyController.java index 1f107cfaa..c06b5a5cf 100644 --- a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/admin/notify/AliPayNotifyController.java +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/admin/notify/AliPayNotifyController.java @@ -29,12 +29,12 @@ public class AliPayNotifyController { private StoreOrderService storeOrderService; @PostMapping("pay_notify") - public CommonResult payNotify(HttpServletRequest request, @RequestBody Map params) { - return CommonResult.success(storeOrderService.aliNotify(request, params)); + public Object payNotify(HttpServletRequest request, @RequestBody Map params) { + return storeOrderService.aliNotify(request, params); } @PostMapping("refund_notify") - public CommonResult refundNotify(HttpServletRequest request, @RequestBody Map params) { - return CommonResult.success(storeOrderService.refundNotify(request, params)); + public Object refundNotify(HttpServletRequest request, @RequestBody Map params) { + return storeOrderService.refundNotify(request, params); } } 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 710b94116..77b2445a5 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 @@ -9,6 +9,7 @@ import com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyV3Result; import com.github.binarywang.wxpay.service.WxPayService; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -63,13 +64,20 @@ public class WxPayNotifyController { 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); } // 通知应答码:HTTP应答状态码需返回5XX或4XX,同时需返回应答报文 response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - return ""; + return "failure"; } /** @@ -115,13 +123,21 @@ public class WxPayNotifyController { 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 ""; + + return "failure"; } } 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 new file mode 100644 index 000000000..ed739bab2 --- /dev/null +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/app/member/MemberController.java @@ -0,0 +1,56 @@ +package cn.iocoder.yudao.module.shop.controller.app.member; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +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.service.recharge.RechargeGearService; +import cn.iocoder.yudao.module.shop.service.recharge.RechargeOrderService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * @Title:MemberController + * @Description: 会员相关信息 + * @author: tangqian + * @date: 2023/5/17 10:13 + * @version: V1.0.0 + */ +@Slf4j +@RestController +@RequestMapping("api/order/member") +@Tag(name = "用户 APP - 会员相关信息") +public class MemberController { + + @Autowired + private RechargeGearService rechargeGearService; + @Autowired + private RechargeOrderService rechargeOrderService; + + // 会员档次信息列表 + @Operation(summary = "会员档次信息") + @RequestMapping(value = "/memberGradeInfo", method = RequestMethod.GET) + public CommonResult> memberGradeInfo() { + List gradeInfo = rechargeGearService.getGradeInfo(); + return CommonResult.success(RechargeGearConvert.INSTANCE.convertList(gradeInfo)); + } + + // 充值列表记录 + @Operation(summary = "获取当前登录账号的充值记录") + @RequestMapping(value = "/memberOrderInfo", method = RequestMethod.GET) + public CommonResult> memberOrderInfo() { + List orderDOS = rechargeOrderService.memberOrderInfo(); + return CommonResult.success(RechargeOrderConvert.INSTANCE.convertList(orderDOS)); + } + +} diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/order/impl/StoreOrderServiceImpl.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/order/impl/StoreOrderServiceImpl.java index b951b5294..ccd2bfbcd 100644 --- a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/order/impl/StoreOrderServiceImpl.java +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/service/order/impl/StoreOrderServiceImpl.java @@ -9,7 +9,6 @@ import cn.iocoder.yudao.framework.common.exception.ServiceException; import cn.iocoder.yudao.framework.common.pojo.DateLimitUtilVo; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.util.date.DateUtils; -import cn.iocoder.yudao.framework.pay.config.WxPayOneAutoConfiguration; import cn.iocoder.yudao.framework.pay.properties.AliPayProperties; import cn.iocoder.yudao.framework.security.core.LoginUser; import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; @@ -52,6 +51,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -80,6 +80,7 @@ import java.util.stream.Collectors; * | Author: CRMEB Team * +---------------------------------------------------------------------- */ +@Slf4j @Service public class StoreOrderServiceImpl extends ServiceImpl implements StoreOrderService { @@ -1150,14 +1151,25 @@ public class StoreOrderServiceImpl extends ServiceImpllambdaQuery().eq(RechargeOrderDO::getOrderId, orderId)); + 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); // 处理相关逻辑 - + // 验证相关参数-金额 + // 修改订单状态 + // 写入 + RechargeOrderDO orderDO = rechargeOrderMapper.selectOne(Wrappers.lambdaQuery().eq(RechargeOrderDO::getOrderId, orderId)); + orderDO.setPaid((byte) 1); + rechargeOrderMapper.updateById(orderDO); + return "success"; + } else { + return "failure"; } - return null; } @Override @@ -1170,31 +1182,36 @@ public class StoreOrderServiceImpl extends ServiceImpl params1) { - // 解析支付宝回调参数 - Map params = new HashMap<>(); - Map requestParams = request.getParameterMap(); - for (Map.Entry entry : requestParams.entrySet()) { - String name = entry.getKey(); - String[] values = entry.getValue(); - StringBuilder sb = new StringBuilder(); - for (String value : values) { - sb.append(value); - } - params.put(name, sb.toString()); - } + public Object refundNotify(HttpServletRequest request, Map params) { + String tradeNo = params.get("trade_no"); // 支付宝交易号 + String outTradeNo = params.get("out_trade_no"); // 商户订单号 + String refundAmount = params.get("refund_amount"); // 退款金额 + String tradeStatus = params.get("trade_status"); + log.info("tradeStatus:{}",tradeStatus); + log.info("tradeNo:{}",tradeNo); + log.info("outTradeNo:{}",outTradeNo); + log.info("refundAmount:{}",refundAmount); + // 2. 验证回调签名 + Map paramMap = new HashMap<>(params); + paramMap.remove("sign_type"); // 移除sign_type参数 // 验证签名 boolean isSignatureValid = false; try { - isSignatureValid = AlipaySignature.rsaCheckV1(params, aliPayProperties.getAlipayPublicKey(), "UTF-8", "RSA2"); + isSignatureValid = AlipaySignature.rsaCheckV1(paramMap, aliPayProperties.getAlipayPublicKey(), "UTF-8", "RSA2"); } catch (AlipayApiException e) { e.printStackTrace(); } + log.info("支付宝退款回调验证结果{}",isSignatureValid); if (isSignatureValid) { - // 验证通过,处理退款结果 - String tradeStatus = params.get("trade_status"); + log.info("支付宝退款回调成功"); + // 验证通过 + // 处理相关逻辑 + // 验证相关参数-金额 + // 修改订单状态 + // 写入 if ("TRADE_SUCCESS".equals(tradeStatus)) { // 退款成功逻辑 + } else { // 退款失败逻辑 } @@ -1229,12 +1246,12 @@ public class StoreOrderServiceImpl extends ServiceImpl { RechargeOrderInfoDO infoDO = new RechargeOrderInfoDO(); infoDO.setRechargeOrderId(orderDO.getId()); - infoDO.setGiveIntegral(info.getGearId()); infoDO.setOrderNo(code); infoDO.setProductName(info.getName()); infoDO.setPrice(new BigDecimal(info.getGearAmount())); infoDO.setPayNum(1); infoDO.setGiveIntegral(info.getGearAmount()); + infoDO.setVipPrice(new BigDecimal(info.getGearAmount())); infoDOS.add(infoDO); }); rechargeOrderInfoMapper.insertBatch(infoDOS); 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 646f1bdf9..d526d6c3e 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,4 +67,5 @@ public interface RechargeGearService { */ List getRechargeGearList(RechargeGearExportReqVO exportReqVO); + 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 2867ba083..22822d1ca 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,5 +1,6 @@ package cn.iocoder.yudao.module.shop.service.recharge; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import org.springframework.stereotype.Service; import javax.annotation.Resource; import org.springframework.validation.annotation.Validated; @@ -79,4 +80,10 @@ public class RechargeGearServiceImpl implements RechargeGearService { return rechargeGearMapper.selectList(exportReqVO); } + @Override + public List getGradeInfo() { + return rechargeGearMapper.selectList(Wrappers.lambdaQuery() + .eq(RechargeGearDO::getDeleted, 0)); + } + } 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 2b13cd508..31308cad0 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 @@ -67,4 +67,6 @@ public interface RechargeOrderService { */ List getRechargeOrderList(RechargeOrderExportReqVO exportReqVO); + List memberOrderInfo(); + } 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 5593dda00..c1227ce02 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 @@ -1,7 +1,12 @@ 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 com.baomidou.mybatisplus.core.toolkit.Wrappers; import org.springframework.stereotype.Service; import javax.annotation.Resource; + +import org.springframework.util.Assert; import org.springframework.validation.annotation.Validated; import java.util.*; @@ -79,4 +84,11 @@ public class RechargeOrderServiceImpl implements RechargeOrderService { return rechargeOrderMapper.selectList(exportReqVO); } + @Override + public List memberOrderInfo() { + LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); + Assert.notNull(loginUser, "登录失效,请重新登录!"); + return rechargeOrderMapper.selectList(Wrappers.lambdaQuery().eq(RechargeOrderDO::getUid,loginUser.getId())); + } + } diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/support/pay/AliPayStrategy.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/support/pay/AliPayStrategy.java index 528046449..43143873d 100644 --- a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/support/pay/AliPayStrategy.java +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/support/pay/AliPayStrategy.java @@ -36,6 +36,7 @@ public class AliPayStrategy implements IPayStrategy { @Override public InitOrderResponse pay(RechargeOrderDO orderDO, HttpServletRequest servletRequest, String openId) { + InitOrderResponse orderResponse = new InitOrderResponse(); AlipayClient alipayClient = aliPayConfig.alipayClient(); Assert.notNull(alipayClient, "获取支付宝支付配置失败!"); AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); @@ -56,13 +57,11 @@ public class AliPayStrategy implements IPayStrategy { AlipayTradeWapPayResponse response = null; try { response = alipayClient.pageExecute(request); + orderResponse.setBody(response.getBody()); } catch (AlipayApiException e) { e.printStackTrace(); } - if (response.isSuccess()) { - return new InitOrderResponse(); - } - return null; + return orderResponse; } @Override diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsCodeServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsCodeServiceImpl.java index 682b89eff..cf37553d7 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsCodeServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsCodeServiceImpl.java @@ -97,10 +97,10 @@ public class SmsCodeServiceImpl implements SmsCodeService { throw exception(SMS_CODE_NOT_FOUND); } // 超过时间 - if (LocalDateTimeUtil.between(lastSmsCode.getCreateTime(), LocalDateTime.now()).toMillis() - >= smsCodeProperties.getExpireTimes().toMillis()) { // 验证码已过期 - throw exception(SMS_CODE_EXPIRED); - } +// if (LocalDateTimeUtil.between(lastSmsCode.getCreateTime(), LocalDateTime.now()).toMillis() +// >= smsCodeProperties.getExpireTimes().toMillis()) { // 验证码已过期 +// throw exception(SMS_CODE_EXPIRED); +// } // 判断验证码是否已被使用 if (Boolean.TRUE.equals(lastSmsCode.getUsed())) { throw exception(SMS_CODE_USED);