ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/factory/AppCouponFallbackFactory.java
@@ -48,6 +48,11 @@ public R grantCoupon(GrantCouponDto dto) { return R.fail("给用户发放优惠券:"+throwable.getMessage()); } @Override public R refund(String id) { return R.fail("后台退款 退回优惠券失败:"+throwable.getMessage()); } }; } } ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/factory/AppUserFallbackFactory.java
@@ -59,6 +59,11 @@ } @Override public R refundPoints(String param) { return R.fail("后台兑换订单退款回退用户积分失败:"+throwable.getMessage()); } @Override public R<List<TAppUser>> getUserByIds(List<Long> appUserIds) { return R.fail("根据用户id查询用户信息失败:"+throwable.getMessage()); } ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/feignClient/AppCouponClient.java
@@ -47,4 +47,6 @@ */ @PostMapping("/t-app-coupon/grantCoupon") R grantCoupon(@RequestBody GrantCouponDto dto); @PostMapping(value = "/t-app-coupon/refund/{id}") R refund(@PathVariable("id") String id); } ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/feignClient/AppUserClient.java
@@ -66,4 +66,10 @@ */ @GetMapping("/t-app-user/user/selectByPhone") R<TAppUser> selectByPhone(@RequestParam("phone") String phone); /** * 远程调用 积分兑换订单 退款回退积分 * @return */ @PostMapping(value = "/t-app-user/refundPoints/{param}") public R refundPoints(@PathVariable("param")String param); } ruoyi-api/ruoyi-api-payment/src/main/java/com/ruoyi/payment/api/factory/AliPaymentFallbackFactory.java
@@ -2,6 +2,8 @@ import com.ruoyi.common.core.domain.R; import com.ruoyi.payment.api.feignClient.AliPaymentClient; import com.ruoyi.payment.api.model.RefundReq; import com.ruoyi.payment.api.model.RefundResp; import com.ruoyi.payment.api.vo.AliPaymentReq; import com.ruoyi.payment.api.vo.AliPaymentResp; import com.ruoyi.payment.api.vo.AliQueryOrder; @@ -40,6 +42,11 @@ public void close(String outTradeNo) { throw new RuntimeException("关闭支付订单失败:" + throwable.getMessage()); } @Override public R<RefundResp> refund(RefundReq dto) { throw new RuntimeException("支付宝退款失败:" + throwable.getMessage()); } }; } } ruoyi-api/ruoyi-api-payment/src/main/java/com/ruoyi/payment/api/factory/WxPaymentFallbackFactory.java
@@ -2,6 +2,7 @@ import com.ruoyi.common.core.domain.R; import com.ruoyi.payment.api.feignClient.WxPaymentClient; import com.ruoyi.payment.api.model.WxPaymentRefundModel; import com.ruoyi.payment.api.vo.NotifyV3PayDecodeRespBody; import com.ruoyi.payment.api.vo.PaymentOrder; import org.slf4j.Logger; @@ -51,6 +52,12 @@ public void close(String outTradeNo) { throw new RuntimeException("关闭支付订单失败:" + throwable.getMessage()); } @Override public R<String> refundOrderR(WxPaymentRefundModel model) { return R.fail("微信退款失败:" + throwable.getMessage()); } }; } } ruoyi-api/ruoyi-api-payment/src/main/java/com/ruoyi/payment/api/feignClient/AliPaymentClient.java
@@ -3,11 +3,14 @@ import com.ruoyi.common.core.constant.ServiceNameConstants; import com.ruoyi.common.core.domain.R; import com.ruoyi.payment.api.factory.WxPaymentFallbackFactory; import com.ruoyi.payment.api.model.RefundReq; import com.ruoyi.payment.api.model.RefundResp; import com.ruoyi.payment.api.vo.AliPaymentReq; import com.ruoyi.payment.api.vo.AliPaymentResp; import com.ruoyi.payment.api.vo.AliQueryOrder; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; /** * @author zhibing.pu @@ -40,4 +43,9 @@ */ @PostMapping("/ali/close") void close(String outTradeNo); /** * 后台退款 远程调用 */ @PostMapping("/ali/refund") public R<RefundResp> refund(@RequestBody RefundReq dto); } ruoyi-api/ruoyi-api-payment/src/main/java/com/ruoyi/payment/api/feignClient/WxPaymentClient.java
@@ -3,8 +3,10 @@ import com.ruoyi.common.core.constant.ServiceNameConstants; import com.ruoyi.common.core.domain.R; import com.ruoyi.payment.api.factory.WxPaymentFallbackFactory; import com.ruoyi.payment.api.model.WxPaymentRefundModel; import com.ruoyi.payment.api.vo.NotifyV3PayDecodeRespBody; import com.ruoyi.payment.api.vo.PaymentOrder; import io.swagger.annotations.ApiOperation; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -59,4 +61,8 @@ */ @PostMapping("/wx/pay/close") void close(String outTradeNo); @ApiOperation("订单退款") @PostMapping(value = "/wx/refundOrderR") public R<String> refundOrderR(@RequestBody WxPaymentRefundModel model); } ruoyi-api/ruoyi-api-payment/src/main/java/com/ruoyi/payment/api/model/PaymentReq.java
File was renamed from ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/ali/v2/model/PaymentReq.java @@ -1,4 +1,4 @@ package com.ruoyi.payment.ali.v2.model; package com.ruoyi.payment.api.model; import lombok.Data; ruoyi-api/ruoyi-api-payment/src/main/java/com/ruoyi/payment/api/model/PaymentResp.java
File was renamed from ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/ali/v2/model/PaymentResp.java @@ -1,4 +1,4 @@ package com.ruoyi.payment.ali.v2.model; package com.ruoyi.payment.api.model; import lombok.Data; ruoyi-api/ruoyi-api-payment/src/main/java/com/ruoyi/payment/api/model/QueryRefundReq.java
File was renamed from ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/ali/v2/model/QueryRefundReq.java @@ -1,4 +1,4 @@ package com.ruoyi.payment.ali.v2.model; package com.ruoyi.payment.api.model; import lombok.Data; ruoyi-api/ruoyi-api-payment/src/main/java/com/ruoyi/payment/api/model/QueryRefundResp.java
File was renamed from ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/ali/v2/model/QueryRefundResp.java @@ -1,4 +1,4 @@ package com.ruoyi.payment.ali.v2.model; package com.ruoyi.payment.api.model; import com.fasterxml.jackson.annotation.JsonSetter; import lombok.Data; ruoyi-api/ruoyi-api-payment/src/main/java/com/ruoyi/payment/api/model/QueryResp.java
File was renamed from ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/ali/v2/model/QueryResp.java @@ -1,4 +1,4 @@ package com.ruoyi.payment.ali.v2.model; package com.ruoyi.payment.api.model; import com.fasterxml.jackson.annotation.JsonSetter; import lombok.Data; ruoyi-api/ruoyi-api-payment/src/main/java/com/ruoyi/payment/api/model/RefundReq.java
File was renamed from ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/ali/v2/model/RefundReq.java @@ -1,4 +1,4 @@ package com.ruoyi.payment.ali.v2.model; package com.ruoyi.payment.api.model; import lombok.Data; ruoyi-api/ruoyi-api-payment/src/main/java/com/ruoyi/payment/api/model/RefundResp.java
File was renamed from ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/ali/v2/model/RefundResp.java @@ -1,4 +1,4 @@ package com.ruoyi.payment.ali.v2.model; package com.ruoyi.payment.api.model; import com.fasterxml.jackson.annotation.JsonSetter; import lombok.Data; ruoyi-api/ruoyi-api-payment/src/main/java/com/ruoyi/payment/api/model/WxPaymentRefundModel.java
File was renamed from ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/wx/model/WxPaymentRefundModel.java @@ -1,4 +1,4 @@ package com.ruoyi.payment.wx.model; package com.ruoyi.payment.api.model; import lombok.*; ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppCouponController.java
@@ -38,6 +38,7 @@ import javax.annotation.Resource; import java.math.BigDecimal; import javax.annotation.Resource; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; @@ -72,7 +73,17 @@ @Resource private ChargingGunClient chargingGunClient; /** * 后台退款 回退优惠券使用状态 * @return */ @PostMapping(value = "/refund/{id}") public R refund(@PathVariable("id") String id) { TAppCoupon byId = tAppCouponService.getById(id); byId.setStatus(1); tAppCouponService.updateById(byId); return R.ok(); } /** * 小程序扫一扫 添加车辆 * @param dto @@ -190,6 +201,13 @@ return R.ok(tAppCouponService.pagelist(couponId)); } @ApiOperation(value = "优惠卷可用数量", tags = {"小程序-站点管理-站点详情"}) @GetMapping(value = "/couponCount") public R<Long> couponCount() { LocalDateTime now = LocalDateTime.now(); return R.ok(tAppCouponService.lambdaQuery().le(TAppCoupon::getStartTime, now).ge(TAppCoupon::getEndTime, now).eq(TAppCoupon::getStatus, 1).count()); } @Autowired private TAppUserTagService appUserTagService; @Autowired ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppUserController.java
@@ -116,7 +116,20 @@ private TInviteUserService inviteUserService; /** * 远程调用 积分兑换订单 退款回退积分 * @return */ @PostMapping(value = "/refundPoints/{param}") public R refundPoints(@PathVariable("param")String param) { String[] split = param.split("-"); String userId = split[0]; String points = split[1]; TAppUser byId = appUserService.getById(userId); byId.setPoints(byId.getPoints()+Integer.parseInt(points)); appUserService.updateById(byId); return R.ok(); } @ApiOperation(value = "查询当前用户是否为会员 0否1是", tags = {"小程序--查询当前用户是否为会员"}) @PostMapping(value = "/getUserInfo") @@ -537,7 +550,8 @@ } @ApiOperation(value = "优惠卷列表不分页(1可使用2不可用)", tags = {"小程序-个人中心"}) @ApiOperation(value = "优惠卷详情(1可使用2不可用)", tags = {"小程序-个人中心"}) @PostMapping(value = "/user/coupon/getById") public R<TAppCoupon> couponGetById(@RequestParam("id")Long id) { TAppCoupon appCoupon = appCouponService.getById(id); ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/SiteController.java
@@ -153,7 +153,7 @@ @ApiOperation(value = "获取站点下充电桩及充电枪列表", tags = {"小程序-站点管理-站点详情"}) @GetMapping("/getChargingGunList") public AjaxResult<List<TChargingPileVO>> getChargingGunList(@RequestParam(value = "siteId")@ApiParam(value = "站点id", required = true)Integer siteId, @RequestParam(value = "siteId",required = false)@ApiParam(value = "类型 1=超充,2=快充,3=慢充")Integer type){ @RequestParam(value = "type",required = false)@ApiParam(value = "类型 1=超充,2=快充,3=慢充")Integer type){ return AjaxResult.success(chargingPileService.getChargingGunList(siteId,type)); } ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/TAccountingStrategyDetailController.java
@@ -2,9 +2,11 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.ruoyi.chargingPile.api.model.Site; import com.ruoyi.chargingPile.api.model.TAccountingStrategy; import com.ruoyi.chargingPile.api.vo.StrategyPriceVO; import com.ruoyi.chargingPile.api.vo.TAccountingStrategyDetailVO; import com.ruoyi.chargingPile.service.ISiteService; import com.ruoyi.chargingPile.service.TAccountingStrategyDetailService; import com.ruoyi.chargingPile.service.TAccountingStrategyService; import com.ruoyi.common.core.exception.ServiceException; @@ -17,8 +19,6 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.time.LocalTime; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -35,11 +35,13 @@ @RequestMapping("/t-accounting-strategy-detail") public class TAccountingStrategyDetailController { private final ISiteService siteService; private final TAccountingStrategyService accountingStrategyService; private final TAccountingStrategyDetailService accountingStrategyDetailService; @Autowired public TAccountingStrategyDetailController(TAccountingStrategyService accountingStrategyService, TAccountingStrategyDetailService accountingStrategyDetailService) { public TAccountingStrategyDetailController(ISiteService siteService, TAccountingStrategyService accountingStrategyService, TAccountingStrategyDetailService accountingStrategyDetailService) { this.siteService = siteService; this.accountingStrategyService = accountingStrategyService; this.accountingStrategyDetailService = accountingStrategyDetailService; } @@ -50,9 +52,8 @@ @ApiOperation(tags = {"小程序-站点管理-站点详情"},value = "通过站点id查询计费策略明细列表") @GetMapping(value = "/queryAccountingStrategyDetailBySiteId") public AjaxResult<List<TAccountingStrategyDetailVO>> queryAccountingStrategyDetailBySiteId(@RequestParam("siteId") Integer siteId) { TAccountingStrategy accountingStrategy = accountingStrategyService.getOne(Wrappers.lambdaQuery(TAccountingStrategy.class) .eq(TAccountingStrategy::getSiteId, siteId) .last("limit 1")); Site site = siteService.getById(siteId); TAccountingStrategy accountingStrategy = accountingStrategyService.getById(site.getAccountingStrategyId()); if(Objects.isNull(accountingStrategy)){ throw new ServiceException("未查询到计费策略"); } ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TAccountingStrategyDetailServiceImpl.java
@@ -4,12 +4,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.account.api.feignClient.AppUserClient; import com.ruoyi.account.api.model.TAppUser; import com.ruoyi.chargingPile.api.model.Site; import com.ruoyi.chargingPile.api.model.TAccountingStrategy; import com.ruoyi.chargingPile.api.model.TAccountingStrategyDetail; import com.ruoyi.chargingPile.api.vo.StrategyPriceVO; import com.ruoyi.chargingPile.api.vo.TAccountingStrategyDetailVO; import com.ruoyi.chargingPile.mapper.TAccountingStrategyDetailMapper; import com.ruoyi.chargingPile.mapper.TAccountingStrategyMapper; import com.ruoyi.chargingPile.service.ISiteService; import com.ruoyi.chargingPile.service.TAccountingStrategyDetailService; import com.ruoyi.common.core.exception.ServiceException; import com.ruoyi.common.core.utils.DateUtils; @@ -46,6 +48,8 @@ @Autowired private TokenService tokenService; @Autowired private ISiteService siteService; @Autowired private AppUserClient appUserClient; @Override public List<TAccountingStrategyDetailVO> queryAccountingStrategyDetailByStrategyId(Integer strategyId) { @@ -54,27 +58,28 @@ @Override public List<TAccountingStrategyDetailVO> queryStrategyBySiteIdAndTime(Integer siteId) { TAccountingStrategy accountingStrategy = accountingStrategyMapper.selectOne(Wrappers.lambdaQuery(TAccountingStrategy.class) .eq(TAccountingStrategy::getSiteId, siteId) .last("limit 1")); Site site = siteService.getById(siteId); TAccountingStrategy accountingStrategy = accountingStrategyMapper.selectById(site.getAccountingStrategyId()); if(Objects.isNull(accountingStrategy)){ throw new ServiceException("未查询到计费策略"); } List<TAccountingStrategyDetailVO> list = this.queryAccountingStrategyDetailByStrategyId(accountingStrategy.getId()); list.stream().filter(item -> "24:00".equals(item.getEndTime())).forEach(item -> item.setEndTime("23:59:59")); // 获取当前登录用户id Long userId = tokenService.getLoginUserApplet().getUserId(); // 根据id查询用户信息 TAppUser appUser = appUserClient.getUserById(userId).getData(); if(Objects.nonNull(appUser) && Objects.nonNull(appUser.getVipId())){ if(Objects.nonNull(appUser)){ // 查询会员信息 TVip vip = vipClient.getInfo1(appUser.getVipId()).getData(); TAccountingStrategyDetailVO accountingStrategyDetailVO; TAccountingStrategyDetailVO accountingStrategyDetailNext; // 获取当前时间段的计费策略明细 accountingStrategyDetailVO = list.stream().filter(detail -> DateUtils.string2LocalTime(detail.getStartTime() + " :00").compareTo(LocalTime.now()) <= 0 && DateUtils.string2LocalTime(detail.getEndTime() + " :00").compareTo(LocalTime.now()) > 0) accountingStrategyDetailVO = list.stream().filter(detail -> DateUtils.string2LocalTime(detail.getStartTime() + ":00").compareTo(LocalTime.now()) <= 0 && DateUtils.string2LocalTime(detail.getEndTime() + ("23:59:59".equals(detail.getEndTime())?"":":00")).compareTo(LocalTime.now()) > 0) .findFirst().orElseThrow(() -> new ServiceException("当前时间段未查询到计费策略明细")); // 获取后一次的计费策略明细 accountingStrategyDetailVO.setEndTime("23:59:59".equals(accountingStrategyDetailVO.getEndTime())? "00:00":accountingStrategyDetailVO.getEndTime()); accountingStrategyDetailNext = list.stream().filter(detail -> detail.getStartTime().compareTo(accountingStrategyDetailVO.getEndTime()) == 0) .findFirst().orElseThrow(() -> new ServiceException("未查询到下一时间段的计费策略明细")); if(Objects.nonNull(vip) && vip.getType() == 2){ @@ -94,9 +99,8 @@ @Override public StrategyPriceVO queryPrice(Integer siteId) { TAccountingStrategy accountingStrategy = accountingStrategyMapper.selectOne(Wrappers.lambdaQuery(TAccountingStrategy.class) .eq(TAccountingStrategy::getSiteId, siteId) .last("limit 1")); Site site = siteService.getById(siteId); TAccountingStrategy accountingStrategy = accountingStrategyMapper.selectById(site.getAccountingStrategyId()); if(Objects.isNull(accountingStrategy)){ throw new ServiceException("未查询到计费策略"); } @@ -104,8 +108,10 @@ StrategyPriceVO strategyPriceVO = new StrategyPriceVO(); List<TAccountingStrategyDetailVO> list = this.queryAccountingStrategyDetailByStrategyId(accountingStrategy.getId()); list.stream().filter(item -> "24:00".equals(item.getEndTime())).forEach(item -> item.setEndTime("23:59:59")); // 获取当前时间段的计费策略明细 TAccountingStrategyDetailVO accountingStrategyDetailVO = list.stream().filter(detail -> detail.getStartTime().compareTo(LocalTime.now().toString()) <= 0 && detail.getEndTime().compareTo(LocalTime.now().toString()) >= 0) TAccountingStrategyDetailVO accountingStrategyDetailVO = list.stream().filter(detail -> DateUtils.string2LocalTime(detail.getStartTime() + ":00").compareTo(LocalTime.now()) <= 0 && DateUtils.string2LocalTime(detail.getEndTime() + ("23:59:59".equals(detail.getEndTime())?"":":00")).compareTo(LocalTime.now()) > 0) .findFirst().orElseThrow(() -> new ServiceException("当前时间段未查询到计费策略明细")); strategyPriceVO.setDiscountAmount(accountingStrategyDetailVO.getElectrovalence().add(accountingStrategyDetailVO.getServiceCharge()) .subtract(accountingStrategyDetailVO.getServiceCharge().multiply(accountingStrategy.getDiscount())).setScale(2, BigDecimal.ROUND_HALF_UP)); ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingPileServiceImpl.java
@@ -244,9 +244,12 @@ @Override public List<TChargingPileVO> getChargingGunList(Integer siteId,Integer type) { List<TChargingPileVO> chargingPileVOS = this.baseMapper.getChargingGunList(siteId); List<TChargingGun> chargingGuns = chargingGunService.list(Wrappers.lambdaQuery(TChargingGun.class) .eq(TChargingGun::getSiteId, siteId) .eq(TChargingGun::getChargeMode, type)); LambdaQueryWrapper<TChargingGun> wrapper = new LambdaQueryWrapper<>(); if(Objects.nonNull(type)){ wrapper.eq(TChargingGun::getChargeMode, type); } wrapper.eq(TChargingGun::getSiteId, siteId); List<TChargingGun> chargingGuns = chargingGunService.list(wrapper); // 查询充电枪信息 chargingPileVOS.forEach(item -> { item.setChargingGunList(chargingGuns.stream().filter(gun -> gun.getChargingPileId().equals(item.getId())).collect(Collectors.toList())); ruoyi-service/ruoyi-chargingPile/src/main/resources/mapper/chargingPile/SiteMapper.xml
@@ -109,7 +109,7 @@ ts.id, ts.partner_id, ts.code, ts.`name`, ts.site_type, ts.business_category, ts.status, ts.construction_site, ts.img_url, ts.lon, ts.lat, ts.address, ts.country_code, ts.phone,ts.guide, ts.service_description, ts.vehicle_description, ts.parking_space, ts.rate_description, ts.space_charge_explain, ts.accounting_strategy_id,ts.del_flag,tcg.fastCount, tcg.slowCount,tcg.superCount,tasd.electrovalence,tasd.vipElectrovalence, tcg.slowCount,tcg.superCount,tasd.electrovalence,tasd.vipElectrovalence,tcg.superFreeCount,tcg.fastFreeCount,tcg.slowFreeCount, ROUND( 6378.138 * 2 * ASIN( SQRT( @@ -136,7 +136,10 @@ select site_id, SUM(CASE WHEN charge_mode = 1 THEN 1 ELSE 0 END) AS superCount, SUM(CASE WHEN charge_mode = 2 THEN 1 ELSE 0 END) AS fastCount, SUM(CASE WHEN charge_mode = 3 THEN 1 ELSE 0 END) AS slowCount SUM(CASE WHEN charge_mode = 3 THEN 1 ELSE 0 END) AS slowCount, SUM(CASE WHEN charge_mode = 1 and `status` = 2 THEN 1 ELSE 0 END) AS superFreeCount, SUM(CASE WHEN charge_mode = 2 and `status` = 2 THEN 1 ELSE 0 END) AS fastFreeCount, SUM(CASE WHEN charge_mode = 3 and `status` = 2 THEN 1 ELSE 0 END) AS slowFreeCount from t_charging_gun where ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TExchangeOrderController.java
@@ -27,6 +27,8 @@ import com.ruoyi.common.core.utils.OrderCodeUtil; import com.ruoyi.other.api.feignClient.CouponClient; import com.ruoyi.other.api.feignClient.GoodsClient; import com.ruoyi.payment.api.feignClient.AliPaymentClient; import com.ruoyi.payment.api.feignClient.WxPaymentClient; import com.ruoyi.system.api.domain.SysUser; import com.ruoyi.system.api.feignClient.SysUserClient; import io.swagger.annotations.Api; @@ -67,6 +69,7 @@ private GoodsClient goodsClient; @Resource private CouponClient couponClient; @PostMapping("/getExchangeOrderList") @ApiOperation(value = "列表查询", tags = {"管理后台-兑换订单"}) @@ -131,11 +134,13 @@ public AjaxResult cancelShoppingOrder(String id) { TExchangeOrder byId = exchangeOrderService.getById(id); Long userid = tokenService.getLoginUser().getUserid(); // todo 根据支付方式 取消订单 byId.setCancellationId(userid); byId.setCancellationTime(LocalDateTime.now()); byId.setStatus(4); exchangeOrderService.updateById(byId); // 回退积分 Integer points = byId.getPoints(); appUserClient.refundPoints(byId.getAppUserId()+"-"+points); return AjaxResult.success(); } @GetMapping("/consignerShoppingOrder") ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TShoppingOrderController.java
@@ -3,6 +3,7 @@ import java.time.LocalDateTime; import com.ruoyi.account.api.feignClient.AppCouponClient; import com.ruoyi.account.api.feignClient.AppUserClient; import com.ruoyi.account.api.model.TAppUserAddress; import com.ruoyi.common.core.domain.R; @@ -18,6 +19,11 @@ import com.ruoyi.order.service.TShoppingOrderService; import com.ruoyi.other.api.feignClient.CouponClient; import com.ruoyi.other.api.feignClient.GoodsClient; import com.ruoyi.payment.api.feignClient.AliPaymentClient; import com.ruoyi.payment.api.feignClient.WxPaymentClient; import com.ruoyi.payment.api.model.RefundReq; import com.ruoyi.payment.api.model.RefundResp; import com.ruoyi.payment.api.model.WxPaymentRefundModel; import com.ruoyi.system.api.domain.SysUser; import com.ruoyi.system.api.feignClient.SysUserClient; import io.swagger.annotations.Api; @@ -111,6 +117,12 @@ } @Resource private TokenService tokenService; @Resource private AliPaymentClient aliPaymentClient; @Resource private WxPaymentClient wxPaymentClient; @Resource private AppCouponClient appCouponClient; @GetMapping("/cancelShoppingOrder") @ApiOperation(value = "取消订单", tags = {"管理后台-购物订单"}) public AjaxResult cancelShoppingOrder(String id) { @@ -123,9 +135,40 @@ switch (byId.getPaymentType()){ case 1: // 微信 WxPaymentRefundModel wxPaymentRefundModel = new WxPaymentRefundModel(); wxPaymentRefundModel.setTransaction_id(byId.getSerialNumber()); wxPaymentRefundModel.setOut_trade_no(byId.getCode()); wxPaymentRefundModel.setOut_refund_no(OrderCodeUtil.getOrderCode("GW")); // todo 部署到线上之后写回调地址 // wxPaymentRefundModel.setNotify_url(""); String string = byId.getPaymentAmount().multiply(new BigDecimal("100")).toString(); int i = Integer.parseInt(string); WxPaymentRefundModel.RefundAmount refundAmount = new WxPaymentRefundModel.RefundAmount(); refundAmount.setTotal(i); refundAmount.setRefund(i); wxPaymentRefundModel.setAmount(refundAmount); wxPaymentClient.refundOrderR(wxPaymentRefundModel); break; case 2: // 支付宝 RefundReq refundReq = new RefundReq(); refundReq.setOutTradeNo(byId.getSerialNumber()); String gw = OrderCodeUtil.getOrderCode("GW"); refundReq.setOutRequestNo(gw); refundReq.setRefundAmount(byId.getPaymentAmount().toString()); refundReq.setRefundReason("后台退款"); RefundResp data = aliPaymentClient.refund(refundReq).getData(); if (data!=null){ // 退款成功 回退优惠券 // byId.setStatus(4); if (byId.getAppCouponId()!=null){ appCouponClient.refund(byId.getAppCouponId().toString()); byId.setRefundCode(gw); byId.setRefundAmount(byId.getPaymentAmount()); byId.setRefundStatus(2); byId.setRefundSerialNumber(data.getTradeNo()); } } break; } shoppingOrderService.updateById(byId); ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/ali/v2/AppletPayUtil.java
@@ -9,7 +9,7 @@ import com.alipay.api.response.*; import com.ruoyi.payment.ali.config.AliProperties; import com.ruoyi.payment.ali.config.SignType; import com.ruoyi.payment.ali.v2.model.*; import com.ruoyi.payment.api.model.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/controller/AliPayController.java
@@ -3,9 +3,7 @@ import com.ruoyi.common.core.domain.R; import com.ruoyi.payment.ali.config.AliProperties; import com.ruoyi.payment.ali.v2.AppletPayUtil; import com.ruoyi.payment.ali.v2.model.PaymentReq; import com.ruoyi.payment.ali.v2.model.PaymentResp; import com.ruoyi.payment.ali.v2.model.QueryResp; import com.ruoyi.payment.api.model.*; import com.ruoyi.payment.api.vo.AliPaymentReq; import com.ruoyi.payment.api.vo.AliPaymentResp; import com.ruoyi.payment.api.vo.AliQueryOrder; @@ -78,6 +76,13 @@ throw new RuntimeException("关闭支付宝订单失败"); } } /** * 后台退款 远程调用 */ @PostMapping("/refund") public R<RefundResp> refund(@RequestBody RefundReq dto){ return R.ok(appletPayUtil.refund(dto)); } ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/controller/WxPayController.java
@@ -5,7 +5,7 @@ import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.payment.api.vo.PaymentOrder; import com.ruoyi.payment.wx.enums.RefundEnum; import com.ruoyi.payment.wx.model.WxPaymentRefundModel; import com.ruoyi.payment.api.model.WxPaymentRefundModel; import com.ruoyi.payment.wx.resp.NotifyV3PayDecodeRespBody; import com.ruoyi.payment.wx.utils.WxV3Pay; import io.swagger.annotations.Api; @@ -79,7 +79,30 @@ // TODO 退款业务处理 return AjaxResult.success(); } /** * 微信v3支付-订单退款 远程调用 * * @return */ @ApiOperation("订单退款") @PostMapping(value = "refundOrderR") public R<String> refundOrderR(@RequestBody WxPaymentRefundModel model) { Map<String, Object> result = wxV3Pay.refund(model); log.info("退款结果:{}", result); // 微信支付退款单号 String refund_id = result.get("refund_id").toString(); // 商户退款单号 String out_refund_no = result.get("out_refund_no").toString(); // 微信支付订单号 String transaction_id = result.get("transaction_id").toString(); // 商户订单号 tradeNo String out_trade_no = result.get("out_trade_no").toString(); // 退款成功时间 String success_time = Objects.nonNull(result.get("success_time")) ? result.get("success_time").toString() : null; // 退款状态 RefundEnum String status = result.get("status").toString(); return R.ok(status); } /** * 支付回调 */ @@ -144,6 +167,12 @@ // 时间不对的话,可以调用 WxTimeUtils.toRfc3339Date(success_time)转换一下 String success_time = params.get("success_time").toString(); if (tradeState.equals(RefundEnum.SUCCESS.name())) { String substring = out_refund_no.substring(0, 2); switch (substring){ case "GW": break; } // TODO 退款成功处理 wxV3Pay.ack(); } else { ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/wx/utils/WxAbstractPay.java
@@ -4,7 +4,7 @@ import com.ruoyi.common.core.utils.WebUtils; import com.ruoyi.payment.wx.model.WxCloseOrderModel; import com.ruoyi.payment.wx.model.WxPaymentInfoModel; import com.ruoyi.payment.wx.model.WxPaymentRefundModel; import com.ruoyi.payment.api.model.WxPaymentRefundModel; import com.ruoyi.payment.wx.resp.NotifyV3PayDecodeRespBody; import com.wechat.pay.contrib.apache.httpclient.auth.PrivateKeySigner; import com.wechat.pay.contrib.apache.httpclient.auth.Verifier; ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/wx/utils/WxV3Pay.java
@@ -7,7 +7,7 @@ import com.ruoyi.payment.wx.model.WeixinProperties; import com.ruoyi.payment.wx.model.WxCloseOrderModel; import com.ruoyi.payment.wx.model.WxPaymentInfoModel; import com.ruoyi.payment.wx.model.WxPaymentRefundModel; import com.ruoyi.payment.api.model.WxPaymentRefundModel; import com.ruoyi.payment.wx.resp.NotifyV3PayDecodeRespBody; import com.wechat.pay.contrib.apache.httpclient.WechatPayHttpClientBuilder; import com.wechat.pay.contrib.apache.httpclient.auth.PrivateKeySigner;