feat:退款
fix:修复bug
This commit is contained in:
1 parent
bb1def88d9
commit
075a9cc876
26 files changed
+467
-97
No files matched your search
+6
@@ -3,6 +3,7 @@ package com.bsd.pjcloud.hard.api.dto.order;
|
||||
import com.bsd.pjcloud.admin.api.vo.base.BaseIsIncludeTreeInterface;
|
||||
import com.bsd.pjcloud.common.core.constant.enums.DateRangeTypeEnum;
|
||||
import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
@@ -84,4 +85,9 @@ public class HardOrderDto extends HardOrderEntity implements BaseIsIncludeTreeIn
|
||||
*/
|
||||
private Boolean productDescIsNotEmpty = false;
|
||||
|
||||
/**
|
||||
* 是否为优惠商品
|
||||
*/
|
||||
private String isDiscountsProduct;
|
||||
|
||||
}
|
||||
+7
-7
@@ -1,5 +1,7 @@
|
||||
package com.bsd.pjcloud.thirdparty.dto.oathmini.pay.wechat;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
@@ -14,14 +16,12 @@ import lombok.NoArgsConstructor;
|
||||
@NoArgsConstructor
|
||||
public class ThirdMiniWechatRefundDto {
|
||||
|
||||
private Long orderId;
|
||||
|
||||
private String wechantOrderId;
|
||||
|
||||
private Long refundId;
|
||||
|
||||
private Integer orderPrice;
|
||||
@NotEmpty
|
||||
private String payNo;
|
||||
|
||||
/**
|
||||
* 为null就全额退款
|
||||
*/
|
||||
private Integer refundPrice;
|
||||
|
||||
}
|
||||
+12
@@ -87,6 +87,12 @@ public class ThirdPayOrderEntity extends Model<ThirdPayOrderEntity> {
|
||||
@Schema(description = "支付参数")
|
||||
private String payRep;
|
||||
|
||||
/**
|
||||
* 支付回调返回
|
||||
*/
|
||||
@Schema(description = "支付回调返回")
|
||||
private String payCallbackRes;
|
||||
|
||||
/**
|
||||
* 支付返回
|
||||
*/
|
||||
@@ -99,6 +105,12 @@ public class ThirdPayOrderEntity extends Model<ThirdPayOrderEntity> {
|
||||
@Schema(description = "退款订单号")
|
||||
private String refundNo;
|
||||
|
||||
/**
|
||||
* 退款回调返回
|
||||
*/
|
||||
@Schema(description = "退款回调返回")
|
||||
private String refundCallbackRes;
|
||||
|
||||
/**
|
||||
* 退款时间
|
||||
*/
|
||||
|
||||
+13
-1
@@ -5,12 +5,13 @@ import com.bsd.pjcloud.common.security.annotation.Inner;
|
||||
import com.bsd.pjcloud.common.security.service.PjcloudUser;
|
||||
import com.bsd.pjcloud.common.security.util.SecurityUtils;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.ThirdMiniAppPayDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.pay.wechat.ThirdMiniWechatRefundDto;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdMiniAppService;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.ThirdMinAppOAth2LoginVo;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.pay.ThirdMiniAppPayVo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -28,6 +29,15 @@ public class ThirdMinAppPayCotroller {
|
||||
|
||||
private final ThirdMiniAppService thirdMiniAppService;
|
||||
|
||||
|
||||
@Operation(summary = "小程序支付退款")
|
||||
@PostMapping("/refund")
|
||||
public R<ThirdMiniAppPayVo> miniRefund(@Valid @RequestBody ThirdMiniWechatRefundDto dto) {
|
||||
return R.ok(thirdMiniAppService.miniRefund(dto));
|
||||
}
|
||||
|
||||
/* ************************************* start app start ************************************* */
|
||||
|
||||
@Operation(summary = "小程序支付")
|
||||
@PostMapping("/app/pay")
|
||||
public R<ThirdMiniAppPayVo> miniPay(@Validated @RequestBody ThirdMiniAppPayDto dto) {
|
||||
@@ -51,4 +61,6 @@ public class ThirdMinAppPayCotroller {
|
||||
return R.ok(thirdMiniAppService.miniRefundCallback(body, headers));
|
||||
}
|
||||
|
||||
/* ************************************* end app end ************************************* */
|
||||
|
||||
}
|
||||
+6
@@ -3,6 +3,7 @@ package com.bsd.pjcloud.thirdparty.service;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.ThirdMiniAppGetUniqueDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.ThirdMiniAppOAth2LoginDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.ThirdMiniAppPayDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.pay.wechat.ThirdMiniWechatRefundDto;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.ThirdMinAppOAth2LoginVo;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.pay.ThirdMiniAppPayVo;
|
||||
|
||||
@@ -25,6 +26,11 @@ public interface ThirdMiniAppService {
|
||||
*/
|
||||
ThirdMiniAppPayVo miniPay(Long userId, ThirdMiniAppPayDto dto);
|
||||
|
||||
/**
|
||||
* 小程序退款
|
||||
*/
|
||||
ThirdMiniAppPayVo miniRefund(ThirdMiniWechatRefundDto dto);
|
||||
|
||||
/**
|
||||
* 小程序支付回调
|
||||
*/
|
||||
|
||||
+2
-2
@@ -40,7 +40,7 @@ public interface ThirdMiniAppWechatService {
|
||||
/**
|
||||
* 申请退款
|
||||
*/
|
||||
ThirdMiniWechatRefundVo refund(ThirdMiniWechatRefundDto dto);
|
||||
ThirdMiniWechatRefundVo refund(ThirdPayOrderEntity thirdPayOrder, ThirdMiniWechatRefundDto dto);
|
||||
|
||||
/**
|
||||
* 查询退款
|
||||
@@ -55,6 +55,6 @@ public interface ThirdMiniAppWechatService {
|
||||
/**
|
||||
* 退款回调
|
||||
*/
|
||||
String refundCallback(HttpEntity<String> httpEntity, @RequestHeader Map<String, String> headers);
|
||||
ThirdPayOrderEntity refundCallback(String body, @RequestHeader Map<String, String> headers);
|
||||
|
||||
}
|
||||
+83
-13
@@ -21,17 +21,14 @@ import com.bsd.pjcloud.thirdparty.dto.oathmini.ThirdMiniAppGetUniqueDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.ThirdMiniAppOAth2LoginDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.ThirdMiniAppPayDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.pay.wechat.ThirdMiniJsapiPayDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.pay.wechat.ThirdMiniWechatRefundDto;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdMiniAppAliPayService;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdMiniAppService;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdMiniAppWechatService;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdPayLogService;
|
||||
import com.bsd.pjcloud.thirdparty.service.*;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.ThirdMinAppOAth2LoginVo;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.pay.ThirdMiniAppPayVo;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.pay.wechat.ThirdMiniJsapiPayVo;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.pay.wechat.ThirdMiniWechatQueryVo;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.pay.wechat.ThirdMiniWechatRefundQueryVo;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.pay.wechat.*;
|
||||
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargePaySuccess;
|
||||
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeRefundSuccess;
|
||||
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargePackageEntity;
|
||||
import com.bsd.pjcloud.wallet.api.feign.RemoteWalletRechargePackageService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -53,9 +50,12 @@ import java.util.Map;
|
||||
@RequiredArgsConstructor
|
||||
public class ThirdMiniAppServiceImpl implements ThirdMiniAppService {
|
||||
|
||||
static private final String TAG = "小程序服务类";
|
||||
|
||||
private final ThirdMiniAppWechatService thirdMiniAppWechatService;
|
||||
private final ThirdMiniAppAliPayService thirdMiniAppAliPayService;
|
||||
private final ThirdPayLogService thirdPayLogService;
|
||||
private final ThirdPayOrderService thirdPayOrderService;
|
||||
|
||||
private final RemoteUserService remoteUserService;
|
||||
private final RemoteTokenService remoteTokenService;
|
||||
@@ -193,6 +193,31 @@ public class ThirdMiniAppServiceImpl implements ThirdMiniAppService {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序退款
|
||||
*/
|
||||
@Override
|
||||
public ThirdMiniAppPayVo miniRefund(ThirdMiniWechatRefundDto dto) {
|
||||
// 查询详情
|
||||
ThirdPayOrderEntity thirdPayOrder = thirdPayOrderService.getByPayNo(dto.getPayNo());
|
||||
if (ObjectUtil.isEmpty(thirdPayOrder)) {
|
||||
log.error("|{}|小程序退款错误,订单不存在dto:|{}|", TAG, JSONUtil.toJsonStr(dto));
|
||||
throw new RuntimeException("订单不存在");
|
||||
}
|
||||
// 微信小程序
|
||||
if (ObjectUtil.equals(thirdPayOrder.getPayPlatformType(), MiniPlatformTypeEnum.WECHAT.getType())) {
|
||||
thirdMiniAppWechatService.refund(thirdPayOrder, dto);
|
||||
}
|
||||
// 支付宝
|
||||
else if (ObjectUtil.equals(thirdPayOrder.getPayPlatformType(), MiniPlatformTypeEnum.ALI_PAY.getType())) {
|
||||
|
||||
}
|
||||
// 不支持的支付类型
|
||||
else {
|
||||
throw new RuntimeException("不支持的支付类型");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序支付回调
|
||||
@@ -220,6 +245,32 @@ public class ThirdMiniAppServiceImpl implements ThirdMiniAppService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序退款回调
|
||||
*/
|
||||
@Override
|
||||
public String miniRefundCallback(String body, Map<String, String> headers) {
|
||||
MiniPlatformTypeEnum platformType = checkRefundMiniPlatformType(body);
|
||||
// 微信小程序
|
||||
if (ObjectUtil.equals(platformType, MiniPlatformTypeEnum.WECHAT)) {
|
||||
ThirdPayOrderEntity thirdPayOrder = thirdMiniAppWechatService.refundCallback(body, headers);
|
||||
if (ObjectUtil.isEmpty(thirdPayOrder)) {
|
||||
return ThirdMiniWechantRefunCallbackVo.wechantError();
|
||||
}
|
||||
// 根据订单bizType来处理
|
||||
boolean isSuccess = disposeRefundSuccessAfter(thirdPayOrder);
|
||||
return isSuccess ? ThirdMiniWechatQueryVo.wechantSuccess() : ThirdMiniWechatQueryVo.wechantError();
|
||||
}
|
||||
// 支付宝
|
||||
else if (ObjectUtil.equals(platformType, MiniPlatformTypeEnum.ALI_PAY)) {
|
||||
return null;
|
||||
}
|
||||
// 不支持的支付类型
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private MiniPlatformTypeEnum checkMiniPlatformType(String body) {
|
||||
ThirdMiniWechatRefundQueryVo vo = JSONUtil.toBean(JSONUtil.toJsonStr(XmlUtil.xmlToMap(body)), ThirdMiniWechatRefundQueryVo.class);
|
||||
// 查询订单
|
||||
@@ -229,6 +280,15 @@ public class ThirdMiniAppServiceImpl implements ThirdMiniAppService {
|
||||
return null;
|
||||
}
|
||||
|
||||
private MiniPlatformTypeEnum checkRefundMiniPlatformType(String body) {
|
||||
ThirdMiniWechantRefunCallbackSoureVo vo = JSONUtil.toBean(JSONUtil.toJsonStr(XmlUtil.xmlToMap(body)), ThirdMiniWechantRefunCallbackSoureVo.class);
|
||||
// 查询订单
|
||||
if (ObjectUtil.isNotEmpty(vo) && ObjectUtil.isNotEmpty(vo.getAppid()) && ObjectUtil.isNotEmpty(vo.getMch_id()) && ObjectUtil.isNotEmpty(vo.getNonce_str()) && ObjectUtil.isNotEmpty(vo.getReq_info())) {
|
||||
return MiniPlatformTypeEnum.WECHAT;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean disposePaySuccessAfter(ThirdPayOrderEntity thirdPayOrder) {
|
||||
if (ObjectUtil.notEqual(thirdPayOrder.getStatus(), ThirdPayOrderStatusEnum.PAY_SUCCESS.getType())) {
|
||||
return true;
|
||||
@@ -247,12 +307,22 @@ public class ThirdMiniAppServiceImpl implements ThirdMiniAppService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序退款回调
|
||||
*/
|
||||
@Override
|
||||
public String miniRefundCallback(String body, Map<String, String> headers) {
|
||||
return "";
|
||||
private boolean disposeRefundSuccessAfter(ThirdPayOrderEntity thirdPayOrder) {
|
||||
if (ObjectUtil.notEqual(thirdPayOrder.getStatus(), ThirdPayOrderStatusEnum.REFUND_SUCCESS.getType())) {
|
||||
return true;
|
||||
}
|
||||
// 已退款
|
||||
try {
|
||||
WalletRechargeRefundSuccess dto = new WalletRechargeRefundSuccess();
|
||||
dto.setRefundNo(thirdPayOrder.getRefundNo());
|
||||
dto.setUserId(thirdPayOrder.getUserId());
|
||||
dto.setBizId(thirdPayOrder.getBizId());
|
||||
dto.setBizType(thirdPayOrder.getBizType());
|
||||
return remoteWalletRechargePackageService.remoteRefundSuccess(dto).getData();
|
||||
} catch (Exception e) {
|
||||
log.error("处理小程序退款成功回调异常", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+60
-17
@@ -100,7 +100,7 @@ public class ThirdMiniAppWechatServiceImpl implements ThirdMiniAppWechatService
|
||||
ThirdMiniWechantPayConstant.Api api = initApi(ThirdMiniWechantPayConstant.WECHAT_PAY);
|
||||
|
||||
String xmlStr = XmlUtil.mapToXmlStr(params);
|
||||
payOrder.setPayRep(xmlStr);
|
||||
payOrder.setPayRep(JSONUtil.toJsonStr(params));
|
||||
|
||||
String res = api.getHttpRequest().body(xmlStr).execute().body();
|
||||
log.debug("JSAPI/小程序下单,json,xml|{}", res);
|
||||
@@ -108,13 +108,14 @@ public class ThirdMiniAppWechatServiceImpl implements ThirdMiniAppWechatService
|
||||
log.error("JSAPI/小程序下单,res为空");
|
||||
return null;
|
||||
}
|
||||
ThirdMiniJsapiPayVo vo = JSONUtil.toBean(JSONUtil.toJsonStr(XmlUtil.xmlToMap(res)), ThirdMiniJsapiPayVo.class);
|
||||
String jsonVo = JSONUtil.toJsonStr(XmlUtil.xmlToMap(res));
|
||||
ThirdMiniJsapiPayVo vo = JSONUtil.toBean(jsonVo, ThirdMiniJsapiPayVo.class);
|
||||
log.debug("|{}|JSAPI/小程序下单,json,res|{}", TAG, JSONUtil.toJsonStr(vo));
|
||||
if (!vo.isHttpSucess()) {
|
||||
return null;
|
||||
}
|
||||
payOrder.setPayTime(LocalDateTime.now());
|
||||
payOrder.setPayRes(res);
|
||||
payOrder.setPayRes(jsonVo);
|
||||
// 生成小程序 paySign
|
||||
String nonceStr = RandomUtil.randomString(32);
|
||||
long timeStamp = System.currentTimeMillis() / 1000;
|
||||
@@ -268,12 +269,30 @@ public class ThirdMiniAppWechatServiceImpl implements ThirdMiniAppWechatService
|
||||
}
|
||||
}
|
||||
|
||||
private String getTransactionIdByThirdPayOrder(ThirdPayOrderEntity thirdPayOrder) {
|
||||
if (ObjectUtil.isEmpty(thirdPayOrder) || ObjectUtil.isEmpty(thirdPayOrder.getPayRes())) {
|
||||
return null;
|
||||
}
|
||||
String payRes = thirdPayOrder.getPayCallbackRes();
|
||||
ThirdMiniWechantRefunCallbackVo thirdMiniJsapiPay = JSONUtil.toBean(payRes, ThirdMiniWechantRefunCallbackVo.class);
|
||||
return thirdMiniJsapiPay.getTransaction_id();
|
||||
}
|
||||
|
||||
/**
|
||||
* 申请退款
|
||||
*/
|
||||
@Override
|
||||
public ThirdMiniWechatRefundVo refund(ThirdMiniWechatRefundDto dto) {
|
||||
public ThirdMiniWechatRefundVo refund(ThirdPayOrderEntity thirdPayOrder, ThirdMiniWechatRefundDto dto) {
|
||||
MiniAppConfig.WechatConfig wechatConfig = miniAppConfig.getWechatConfig();
|
||||
|
||||
ThirdPayOrderEntity updateObj = new ThirdPayOrderEntity();
|
||||
updateObj.setId(thirdPayOrder.getId());
|
||||
|
||||
Integer refundFee = dto.getRefundPrice();
|
||||
if (ObjectUtil.isEmpty(refundFee)) {
|
||||
refundFee = thirdPayOrder.getPrice();
|
||||
}
|
||||
String refundNo = "refund_" + thirdPayOrder.getPayNo();
|
||||
try {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
// 公众账号ID
|
||||
@@ -287,15 +306,15 @@ public class ThirdMiniAppWechatServiceImpl implements ThirdMiniAppWechatService
|
||||
// 签名类型
|
||||
params.put("sign_type", "MD5");
|
||||
// 微信支付订单号
|
||||
params.put("transaction_id", dto.getWechantOrderId());
|
||||
params.put("transaction_id", getTransactionIdByThirdPayOrder(thirdPayOrder));
|
||||
// 商户订单号
|
||||
params.put("out_trade_no", dto.getOrderId());
|
||||
params.put("out_trade_no", thirdPayOrder.getPayNo());
|
||||
// 商户退款单号
|
||||
params.put("out_refund_no", dto.getRefundId());
|
||||
params.put("out_refund_no", refundNo);
|
||||
// 订单金额
|
||||
params.put("total_fee", dto.getOrderPrice());
|
||||
params.put("total_fee", thirdPayOrder.getPrice());
|
||||
// 退款金额
|
||||
params.put("refund_fee", dto.getRefundPrice());
|
||||
params.put("refund_fee", refundFee);
|
||||
// 退款结果通知url
|
||||
params.put("notify_url", wechatConfig.getRefundCallbackUrl());
|
||||
// 生成签名
|
||||
@@ -303,6 +322,7 @@ public class ThirdMiniAppWechatServiceImpl implements ThirdMiniAppWechatService
|
||||
ThirdMiniWechantPayConstant.Api api = initApi(ThirdMiniWechantPayConstant.REFUND);
|
||||
api.setSslSocketFactory(createSSLSocketFactory());
|
||||
|
||||
updateObj.setRefundRep(JSONUtil.toJsonStr(params));
|
||||
String xmlStr = XmlUtil.mapToXmlStr(params);
|
||||
|
||||
String res = api.getHttpRequest().body(xmlStr).execute().body();
|
||||
@@ -311,15 +331,22 @@ public class ThirdMiniAppWechatServiceImpl implements ThirdMiniAppWechatService
|
||||
log.error("|{}|申请退款,res为空", TAG);
|
||||
return null;
|
||||
}
|
||||
String jsonVo = JSONUtil.toJsonStr(XmlUtil.xmlToMap(res));
|
||||
updateObj.setRefundRes(jsonVo);
|
||||
ThirdMiniWechatRefundVo vo = JSONUtil.toBean(JSONUtil.toJsonStr(XmlUtil.xmlToMap(res)), ThirdMiniWechatRefundVo.class);
|
||||
log.debug("|{}|申请退款,json,res|{}", TAG, JSONUtil.toJsonStr(vo));
|
||||
if (!vo.isHttpSucess()) {
|
||||
return null;
|
||||
}
|
||||
updateObj.setRefundNo(refundNo);
|
||||
updateObj.setRefundTime(LocalDateTime.now());
|
||||
updateObj.setStatus(ThirdPayOrderStatusEnum.REFUNDING.getType());
|
||||
return vo;
|
||||
} catch (Exception e) {
|
||||
log.error("|{}|申请退款,异常", TAG, e);
|
||||
return null;
|
||||
} finally {
|
||||
thirdPayOrderService.updateById(updateObj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,6 +416,7 @@ public class ThirdMiniAppWechatServiceImpl implements ThirdMiniAppWechatService
|
||||
// 更新订单状态
|
||||
ThirdPayOrderEntity updateObj = new ThirdPayOrderEntity();
|
||||
updateObj.setId(payOrderEntity.getId());
|
||||
updateObj.setPayCallbackRes(bodyJson);
|
||||
updateObj.setStatus(paySucess ? ThirdPayOrderStatusEnum.PAY_SUCCESS.getType() : ThirdPayOrderStatusEnum.PAY_FAILED.getType());
|
||||
thirdPayOrderService.updateById(updateObj);
|
||||
return thirdPayOrderService.getById(payOrderEntity.getId());
|
||||
@@ -398,15 +426,30 @@ public class ThirdMiniAppWechatServiceImpl implements ThirdMiniAppWechatService
|
||||
* 退款回调
|
||||
*/
|
||||
@Override
|
||||
public String refundCallback(HttpEntity<String> httpEntity, Map<String, String> headers) {
|
||||
String body = httpEntity.getBody();
|
||||
ThirdMiniWechantRefunCallbackVo decrypt = decrypt(body);
|
||||
if (ObjectUtil.isEmpty(decrypt)) {
|
||||
// 告诉微信错误
|
||||
return ThirdMiniWechantRefunCallbackVo.wechantError();
|
||||
public ThirdPayOrderEntity refundCallback(String body, Map<String, String> headers) {
|
||||
ThirdMiniWechantRefunCallbackVo vo = decrypt(body);
|
||||
if (ObjectUtil.isEmpty(vo)) {
|
||||
return null;
|
||||
}
|
||||
boolean isSuccess = true;
|
||||
return isSuccess ? ThirdMiniWechantRefunCallbackVo.wechantSuccess() : ThirdMiniWechantRefunCallbackVo.wechantError();
|
||||
// 查询订单
|
||||
ThirdPayOrderEntity payOrderEntity = thirdPayOrderService.getByPayNo(vo.getOut_trade_no());
|
||||
if (ObjectUtil.isEmpty(payOrderEntity)) {
|
||||
log.error("|{}|refundCallback,意外的错误,订单不存在,微信返回json|{}|", TAG, JSONUtil.toJsonStr(vo));
|
||||
return null;
|
||||
}
|
||||
// 重复的回调
|
||||
if (ObjectUtil.notEqual(payOrderEntity.getStatus(), ThirdPayOrderStatusEnum.REFUNDING.getType())) {
|
||||
log.error("|{}|refundCallback,意外的错误,重复的回调,微信返回json|{}|", TAG, JSONUtil.toJsonStr(vo));
|
||||
return null;
|
||||
}
|
||||
// 更新订单状态
|
||||
boolean refundSuccess = vo.isAllSuccess();
|
||||
ThirdPayOrderEntity updateObj = new ThirdPayOrderEntity();
|
||||
updateObj.setId(payOrderEntity.getId());
|
||||
updateObj.setRefundCallbackRes(JSONUtil.toJsonStr(vo));
|
||||
updateObj.setStatus(refundSuccess ? ThirdPayOrderStatusEnum.REFUND_SUCCESS.getType() : ThirdPayOrderStatusEnum.REFUND_FAILED.getType());
|
||||
thirdPayOrderService.updateById(updateObj);
|
||||
return thirdPayOrderService.getById(payOrderEntity.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Vendored
+3
-1
@@ -15,10 +15,12 @@
|
||||
a.pay_time,
|
||||
a.pay_rep,
|
||||
a.pay_res,
|
||||
a.pay_callback_res,
|
||||
a.refund_no,
|
||||
a.refund_time,
|
||||
a.refund_rep,
|
||||
a.refund_res,
|
||||
a.refund_callback_res,
|
||||
a.expire_time,
|
||||
a.create_time,
|
||||
a.update_time,
|
||||
@@ -30,7 +32,7 @@
|
||||
|
||||
<sql id="whereA">
|
||||
a.del_flag = '0'
|
||||
<if test="dto.payNo null and dto.payNo != '' ">
|
||||
<if test="dto.payNo != null and dto.payNo != '' ">
|
||||
and a.pay_no LIKE concat('%',#{dto.payNo},'%')
|
||||
</if>
|
||||
<if test="dto.id != null">
|
||||
|
||||
@@ -12,7 +12,11 @@
|
||||
|
||||
<artifactId>pjcloud-wallet-api</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<properties>
|
||||
<kotlin.version>2.2.20</kotlin.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- 连表查询注解 -->
|
||||
<dependency>
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
@@ -52,5 +56,81 @@
|
||||
<groupId>com.bsd</groupId>
|
||||
<artifactId>pjcloud-upms-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jdk8</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-test</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sourceDirs>
|
||||
<sourceDir>src/main/java</sourceDir>
|
||||
<sourceDir>target/generated-sources/annotations</sourceDir>
|
||||
</sourceDirs>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>test-compile</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<jvmTarget>1.8</jvmTarget>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>default-compile</id>
|
||||
<phase>none</phase>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>default-testCompile</id>
|
||||
<phase>none</phase>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>testCompile</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>testCompile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.bsd.pjcloud.wallet.api.dto.recharge;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class WalletRechargeRefundSuccess {
|
||||
|
||||
/**
|
||||
* 订单号
|
||||
*/
|
||||
private String refundNo;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 业务类型
|
||||
*/
|
||||
private String bizType;
|
||||
|
||||
/**
|
||||
* 业务id
|
||||
*/
|
||||
private String bizId;
|
||||
|
||||
}
|
||||
+8
@@ -95,11 +95,19 @@ public class WalletManageEntity extends Model<WalletManageEntity> {
|
||||
|
||||
/**
|
||||
* 饭卡绑定状态
|
||||
*
|
||||
* @see WalleCardStatusEnum
|
||||
*/
|
||||
@Schema(description = "饭卡绑定状态")
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 版本号
|
||||
*/
|
||||
@Version
|
||||
@Schema(description = "版本号")
|
||||
private Integer version = 0;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
|
||||
+7
@@ -78,6 +78,13 @@ public class WalletTransactionEntity extends Model<WalletTransactionEntity> {
|
||||
@Schema(description = "余额, 单位分")
|
||||
private Integer balance;
|
||||
|
||||
/**
|
||||
* 乐观锁
|
||||
*/
|
||||
@Version
|
||||
@Schema(description = "乐观锁")
|
||||
private Integer version = 0;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
|
||||
+4
@@ -4,6 +4,7 @@ import com.bsd.pjcloud.common.core.constant.ServiceNameConstants;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.feign.annotation.NoToken;
|
||||
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargePaySuccess;
|
||||
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeRefundSuccess;
|
||||
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargePackageEntity;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -21,4 +22,7 @@ public interface RemoteWalletRechargePackageService {
|
||||
@PostMapping("/wallet-recharge-package/remote/pay-success")
|
||||
R<Boolean> remotePaySuccess(@RequestBody WalletRechargePaySuccess dto);
|
||||
|
||||
@NoToken
|
||||
@PostMapping("/wallet-recharge-package/remote/refund-success")
|
||||
R<Boolean> remoteRefundSuccess(@RequestBody WalletRechargeRefundSuccess dto);
|
||||
}
|
||||
@@ -13,6 +13,12 @@
|
||||
<artifactId>pjcloud-wallet-biz</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- 分布式锁 -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>lock4j-redis-template-spring-boot-starter</artifactId>
|
||||
<version>2.2.7</version>
|
||||
</dependency>
|
||||
<!--引入分布式事务-->
|
||||
<dependency>
|
||||
<groupId>com.bsd</groupId>
|
||||
|
||||
-3
@@ -37,9 +37,6 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 会员钱包流水表
|
||||
*
|
||||
* @author pjcloud
|
||||
* @date 2024-12-30 09:17:49
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
|
||||
+8
@@ -10,6 +10,7 @@ import com.bsd.pjcloud.common.log.annotation.SysLog;
|
||||
import com.bsd.pjcloud.common.security.annotation.Inner;
|
||||
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargePackageDto;
|
||||
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargePaySuccess;
|
||||
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeRefundSuccess;
|
||||
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargePackageEntity;
|
||||
import com.bsd.pjcloud.wallet.service.WalletRechargePackageService;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@@ -52,6 +53,13 @@ public class WalletRechargePackageController {
|
||||
public R<Boolean> remotePaySuccess(@RequestBody WalletRechargePaySuccess dto) {
|
||||
return R.ok(walletRechargePackageService.remotePaySuccess(dto));
|
||||
}
|
||||
|
||||
@Inner
|
||||
@Operation(summary = "退款成功", description = "退款成功")
|
||||
@PostMapping("/remote/refund-success")
|
||||
public R<Boolean> remoteRefundSuccess(@RequestBody WalletRechargeRefundSuccess dto) {
|
||||
return R.ok(walletRechargePackageService.remoteRefundSuccess(dto));
|
||||
}
|
||||
/* ************************************* end remote end ************************************* */
|
||||
|
||||
/* ************************************* start app start ************************************* */
|
||||
|
||||
+6
-5
@@ -64,7 +64,7 @@ public interface WalletManageMapper extends PjcloudBaseMapper<WalletManageEntity
|
||||
*/
|
||||
default int updateWhenConsumption(Long id, Integer price, Boolean force) {
|
||||
LambdaUpdateWrapper<WalletManageEntity> lambdaUpdateWrapper = new LambdaUpdateWrapper<WalletManageEntity>()
|
||||
.setSql(" balance = balance - " + price + ", total_expense = total_expense + " + price)
|
||||
.setSql(" balance = balance - " + price + ", total_expense = total_expense + " + price + ", version = version + 1")
|
||||
.eq(WalletManageEntity::getId, id);
|
||||
if (ObjectUtil.isEmpty(force) || !force) {
|
||||
lambdaUpdateWrapper.ge(WalletManageEntity::getBalance, price);
|
||||
@@ -80,7 +80,7 @@ public interface WalletManageMapper extends PjcloudBaseMapper<WalletManageEntity
|
||||
*/
|
||||
default int updateWhenConsumptionRefund(Long id, Integer price) {
|
||||
LambdaUpdateWrapper<WalletManageEntity> lambdaUpdateWrapper = new LambdaUpdateWrapper<WalletManageEntity>()
|
||||
.setSql(" balance = balance + " + price + ", total_expense = total_expense - " + price)
|
||||
.setSql(" balance = balance + " + price + ", total_expense = total_expense - " + price + ", version = version + 1")
|
||||
.eq(WalletManageEntity::getId, id);
|
||||
return update(null, lambdaUpdateWrapper);
|
||||
}
|
||||
@@ -91,10 +91,11 @@ public interface WalletManageMapper extends PjcloudBaseMapper<WalletManageEntity
|
||||
* @param id 钱包 id
|
||||
* @param price 钱包金额
|
||||
*/
|
||||
default int updateWhenRecharge(Long id, Integer price) {
|
||||
default int updateWhenRecharge(Long id, Integer price, Integer version) {
|
||||
LambdaUpdateWrapper<WalletManageEntity> lambdaUpdateWrapper = new LambdaUpdateWrapper<WalletManageEntity>()
|
||||
.setSql(" balance = balance + " + price + ", total_recharge = total_recharge + " + price)
|
||||
.eq(WalletManageEntity::getId, id);
|
||||
.setSql(" balance = balance + " + price + ", total_recharge = total_recharge + " + price + ", version = version + 1")
|
||||
.eq(WalletManageEntity::getId, id)
|
||||
.eq(WalletManageEntity::getVersion, version);
|
||||
return update(null, lambdaUpdateWrapper);
|
||||
}
|
||||
|
||||
|
||||
+5
-19
@@ -4,21 +4,16 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.bsd.pjcloud.common.core.util.BeanUtils;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.common.data.datascope.PjcloudBaseMapper;
|
||||
import com.bsd.pjcloud.wallet.api.dto.WalletTransactionDto;
|
||||
import com.bsd.pjcloud.wallet.api.dto.WalletTransactionSumAndCountDto;
|
||||
import com.bsd.pjcloud.wallet.api.entity.WalletManageEntity;
|
||||
import com.bsd.pjcloud.wallet.api.entity.WalletTransactionEntity;
|
||||
import com.bsd.pjcloud.wallet.api.entity.WalletTypeEntity;
|
||||
import com.bsd.pjcloud.wallet.api.vo.WalletExportCzTotalPerson;
|
||||
import com.bsd.pjcloud.wallet.api.vo.WalletTransactionSumAndCountVo;
|
||||
import com.bsd.pjcloud.wallet.api.vo.WalletTypeCountVo;
|
||||
import com.bsd.pjcloud.wallet.api.vo.WalletTypeTotalVo;
|
||||
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeApplySelectCompareVo;
|
||||
import com.bsd.pjcloud.wallet.api.vo.transaction.WalletTransactionVo;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@@ -65,25 +60,16 @@ public interface WalletTransactionMapper extends PjcloudBaseMapper<WalletTransac
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
default Page<WalletTransactionVo> scopePageList(Page page, WalletTransactionDto dto, DataScope dataScope) {
|
||||
Page list = selectPageByScope(page, commonWrapperQuery(dto), dataScope);
|
||||
list.setRecords(BeanUtils.toBean(list.getRecords(), WalletTransactionVo.class));
|
||||
return list;
|
||||
}
|
||||
Page<WalletTransactionVo> scopePageList(Page page, @Param("dto") WalletTransactionDto dto, DataScope dataScope);
|
||||
|
||||
List<WalletTransactionVo> scopeList(@Param("dto") WalletTransactionDto dto, DataScope dataScope);
|
||||
|
||||
Long count(@Param("dto") WalletTransactionDto dto, DataScope dataScope);
|
||||
|
||||
WalletTypeCountVo walletTypetotal(@Param("dto") WalletTransactionDto dto, @Param("dataScope") DataScope dataScope);
|
||||
|
||||
List<WalletTypeCountVo> walletTypetotalByDept(@Param("dto") WalletTransactionDto dto, @Param("dataScope") DataScope dataScope);
|
||||
|
||||
default List<WalletTransactionVo> scopeList(WalletTransactionDto dto, DataScope dataScope) {
|
||||
List<WalletTransactionEntity> list = selectListByScope(commonWrapperQuery(dto), dataScope);
|
||||
return BeanUtils.toBean(list, WalletTransactionVo.class);
|
||||
}
|
||||
|
||||
default Long count(WalletTransactionDto dto, DataScope dataScope) {
|
||||
return selectCountByScope(commonWrapperQuery(dto), dataScope);
|
||||
}
|
||||
|
||||
Page<WalletTransactionVo> scopeJzPageList(Page page, @Param("dto") WalletTransactionDto dto, DataScope dataScope);
|
||||
|
||||
Integer getTransactionPriceCount(@Param("month") String importTimeStr, @Param("walletId") Long walletId,
|
||||
|
||||
+6
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargePackageDto;
|
||||
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargePaySuccess;
|
||||
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeRefundSuccess;
|
||||
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargePackageEntity;
|
||||
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargePackageVo;
|
||||
|
||||
@@ -14,6 +15,11 @@ public interface WalletRechargePackageService extends IService<WalletRechargePac
|
||||
*/
|
||||
Boolean remotePaySuccess(WalletRechargePaySuccess dto);
|
||||
|
||||
/**
|
||||
* 退款成功
|
||||
*/
|
||||
Boolean remoteRefundSuccess(WalletRechargeRefundSuccess dto);
|
||||
|
||||
Page<WalletRechargePackageVo> pageJoin(Page page, WalletRechargePackageDto dto);
|
||||
|
||||
/**
|
||||
|
||||
-6
@@ -29,7 +29,6 @@ import com.bsd.pjcloud.common.core.util.CollectionUtils;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.common.data.resolver.ParamResolver;
|
||||
import com.bsd.pjcloud.common.data.tenant.TenantContextHolder;
|
||||
import com.bsd.pjcloud.wallet.api.constant.WalletTypeEnum;
|
||||
import com.bsd.pjcloud.wallet.api.dto.WalletManageBalanceDto;
|
||||
import com.bsd.pjcloud.wallet.api.dto.WalletManageDto;
|
||||
@@ -59,14 +58,9 @@ import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
/**
|
||||
* 钱包管理
|
||||
*
|
||||
* @author dzc
|
||||
* @date 2024-12-30 09:06:35
|
||||
*/
|
||||
@Validated
|
||||
@Slf4j
|
||||
|
||||
+6
-1
@@ -10,6 +10,8 @@ import com.alibaba.excel.ExcelWriter;
|
||||
import com.alibaba.excel.write.metadata.WriteSheet;
|
||||
import com.alibaba.excel.write.metadata.fill.FillConfig;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.lock.annotation.Lock4j;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.bsd.pjcloud.admin.api.entity.SysDept;
|
||||
@@ -127,6 +129,7 @@ public class WalletTransactionServiceImpl extends ServiceImpl<WalletTransactionM
|
||||
insetObj.setBizId(String.valueOf(bizId));
|
||||
insetObj.setBizType(bizType.getCode());
|
||||
insetObj.setTitle(bizType.getDesc());
|
||||
insetObj.setVersion(wallet.getVersion());
|
||||
save(insetObj);
|
||||
return insetObj;
|
||||
}
|
||||
@@ -134,6 +137,7 @@ public class WalletTransactionServiceImpl extends ServiceImpl<WalletTransactionM
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
// @CacheEvict(value = CacheConstants.WALLET_DETAIL, key = "#walletId")
|
||||
@Lock4j(keys = {"'add_wallet_balance'", "#walletId", "#bizId"}, acquireTimeout = 5000, expire = 60000)
|
||||
public WalletTransactionEntity addWalletBalance(Long walletId, Integer price, String bizId, WalletBizEnum bizType) {
|
||||
WalletManageEntity wallet = walletManageService.getById(walletId);
|
||||
if (ObjectUtil.isEmpty(wallet)) {
|
||||
@@ -143,7 +147,7 @@ public class WalletTransactionServiceImpl extends ServiceImpl<WalletTransactionM
|
||||
switch (bizType) {
|
||||
case UPDATE:
|
||||
case RECHARGE, BATCH, TRANSFER_ACCOUNTS: {
|
||||
walletManageMapper.updateWhenRecharge(wallet.getId(), price);
|
||||
walletManageMapper.updateWhenRecharge(wallet.getId(), price, wallet.getVersion());
|
||||
break;
|
||||
}
|
||||
case REFUND, TRANSFER_ACCOUNTS_REFUND, RETURN_CANTEEN: {
|
||||
@@ -164,6 +168,7 @@ public class WalletTransactionServiceImpl extends ServiceImpl<WalletTransactionM
|
||||
insetObj.setBizId(String.valueOf(bizId));
|
||||
insetObj.setBizType(bizType.getCode());
|
||||
insetObj.setTitle(bizType.getDesc());
|
||||
insetObj.setVersion(wallet.getVersion());
|
||||
save(insetObj);
|
||||
return insetObj;
|
||||
}
|
||||
|
||||
+37
@@ -10,6 +10,7 @@ import com.bsd.pjcloud.wallet.api.constant.WalletBizEnum;
|
||||
import com.bsd.pjcloud.wallet.api.constant.WalletTypeEnum;
|
||||
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargePackageDto;
|
||||
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargePaySuccess;
|
||||
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeRefundSuccess;
|
||||
import com.bsd.pjcloud.wallet.api.entity.WalletManageEntity;
|
||||
import com.bsd.pjcloud.wallet.api.entity.WalletTransactionEntity;
|
||||
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargePackageEntity;
|
||||
@@ -71,6 +72,42 @@ public class WalletRechargePackageServiceImpl extends ServiceImpl<WalletRecharge
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款成功的回调
|
||||
*/
|
||||
@Override
|
||||
public Boolean remoteRefundSuccess(WalletRechargeRefundSuccess dto) {
|
||||
// 小程序用户钱包充值
|
||||
if (ObjectUtil.equals(dto.getBizType(), ThirdPayOrderBizTypeEnum.MINI_APP_WALLET_RECHARGE.getType())) {
|
||||
// 查询充值套餐
|
||||
WalletRechargePackageEntity rechargePackage = baseMapper.selectById(dto.getBizId());
|
||||
if (ObjectUtil.isEmpty(rechargePackage)) {
|
||||
log.error("{}退款成功的回调,充值套餐不存在,dto:{}", TAG, JSONUtil.toJsonStr(dto));
|
||||
return false;
|
||||
}
|
||||
// 需要退款的金额
|
||||
Integer totalPrice = rechargePackage.getPayPrice() + rechargePackage.getBonusPrice();
|
||||
if (totalPrice <= 0) {
|
||||
log.error("{}退款成功的回调,充值套餐金额<=0,dto:{}", TAG, JSONUtil.toJsonStr(dto));
|
||||
return false;
|
||||
}
|
||||
// 查询这个用户的充值钱包
|
||||
WalletManageEntity topupWallet = walletManageService.getWallet(dto.getUserId(), WalletTypeEnum.TOPUP);
|
||||
if (ObjectUtil.isEmpty(topupWallet)) {
|
||||
log.error("{}退款成功的回调,查询这个用户的充值钱包,dto:{}", TAG, JSONUtil.toJsonStr(dto));
|
||||
return false;
|
||||
}
|
||||
// 进行扣款预约扣款为负数
|
||||
WalletTransactionEntity walletTransaction = walletTransactionService.reduceWalletBalance(topupWallet.getId(), totalPrice, dto.getRefundNo(), WalletBizEnum.REFUND, true);
|
||||
return ObjectUtil.isNotEmpty(walletTransaction);
|
||||
}
|
||||
// 不支持的类型
|
||||
else {
|
||||
log.error("{}退款成功的回调,不支持的类型,dto:{}", TAG, JSONUtil.toJsonStr(dto));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<WalletRechargePackageVo> pageJoin(Page page, WalletRechargePackageDto dto) {
|
||||
return baseMapper.pageJoin(page, dto);
|
||||
|
||||
@@ -2,25 +2,6 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.bsd.pjcloud.wallet.mapper.WalletManageMapper">
|
||||
<resultMap id="walletManageMap" type="com.bsd.pjcloud.wallet.api.entity.WalletManageEntity">
|
||||
<id property="id" column="id"/>
|
||||
<result property="userId" column="user_id"/>
|
||||
<result property="walletTypeId" column="wallet_type_id"/>
|
||||
<result property="cardNumber" column="card_number"/>
|
||||
<result property="balance" column="balance"/>
|
||||
<result property="totalExpense" column="total_expense"/>
|
||||
<result property="totalRecharge" column="total_recharge"/>
|
||||
<result property="freezePrice" column="freeze_price"/>
|
||||
<result property="isFreeze" column="is_freeze"/>
|
||||
<result property="activeBindTime" column="active_bind_time"/>
|
||||
<result property="status" column="active_bind_status"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="updateBy" column="update_by"/>
|
||||
<result property="updateTime" column="update_time"/>
|
||||
<result property="delFlag" column="del_flag"/>
|
||||
<result property="tenantId" column="tenant_id"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectA">
|
||||
select a.id,
|
||||
@@ -35,6 +16,7 @@
|
||||
a.is_freeze,
|
||||
a.active_bind_time,
|
||||
a.status,
|
||||
a.version,
|
||||
a.create_by,
|
||||
a.create_time,
|
||||
a.update_by,
|
||||
|
||||
+43
-2
@@ -22,12 +22,13 @@
|
||||
a.title,
|
||||
a.price,
|
||||
a.balance,
|
||||
a.version,
|
||||
a.create_by,
|
||||
a.create_time,
|
||||
a.update_by,
|
||||
a.update_time,
|
||||
a.del_flag,
|
||||
a.tenant_id,
|
||||
a.tenant_id
|
||||
</sql>
|
||||
|
||||
<sql id="whereA">
|
||||
@@ -102,7 +103,7 @@
|
||||
</sql>
|
||||
|
||||
<select id="scopeJzPageList" resultType="com.bsd.pjcloud.wallet.api.vo.transaction.WalletTransactionVo">
|
||||
<include refid="selectA"/>
|
||||
<include refid="selectA"/>,
|
||||
y.process_id as processId
|
||||
from wallet_transaction a
|
||||
inner join wallet_recharge_import i on i.id = a.biz_id and i.del_flag = '0'
|
||||
@@ -282,4 +283,44 @@
|
||||
and t.dept_id not in (1875013738914156546, 1910218102049226753, 1910218128624336898, 1942046316044144642)
|
||||
order by v.mchId, v.deptId
|
||||
</select>
|
||||
|
||||
<select id="scopePageList" resultType="com.bsd.pjcloud.wallet.api.vo.transaction.WalletTransactionVo">
|
||||
<include refid="selectA"/>
|
||||
from wallet_transaction a
|
||||
left join wallet_manage m on m.id = a.wallet_id and m.del_flag = '0'
|
||||
<where>
|
||||
<include refid="whereA"/>
|
||||
<if test="dto.walletTypeId != null">
|
||||
and m.wallet_type_id = #{dto.walletTypeId}
|
||||
</if>
|
||||
</where>
|
||||
order by a.create_time desc, a.user_id desc
|
||||
</select>
|
||||
|
||||
<select id="scopeList" resultType="com.bsd.pjcloud.wallet.api.vo.transaction.WalletTransactionVo">
|
||||
<include refid="selectA"/>
|
||||
from wallet_transaction a
|
||||
left join wallet_manage m on m.id = a.wallet_id and m.del_flag = '0'
|
||||
<where>
|
||||
<include refid="whereA"/>
|
||||
<if test="dto.walletTypeId != null">
|
||||
and m.wallet_type_id = #{dto.walletTypeId}
|
||||
</if>
|
||||
</where>
|
||||
order by a.create_time desc, a.user_id desc
|
||||
</select>
|
||||
|
||||
<select id="count" resultType="java.lang.Long">
|
||||
select count(*)
|
||||
from wallet_transaction a
|
||||
left join wallet_manage m on m.id = a.wallet_id and m.del_flag = '0'
|
||||
<where>
|
||||
<include refid="whereA"/>
|
||||
<if test="dto.walletTypeId != null">
|
||||
and m.wallet_type_id = #{dto.walletTypeId}
|
||||
</if>
|
||||
</where>
|
||||
order by a.create_time desc, a.user_id desc
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.bsd.pjcloud;
|
||||
|
||||
import com.bsd.pjcloud.wallet.WalletApp;
|
||||
import com.bsd.pjcloud.wallet.api.constant.WalletBizEnum;
|
||||
import com.bsd.pjcloud.wallet.service.WalletTransactionService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@SpringBootTest(classes = WalletApp.class)
|
||||
public class WalletTransactionTest {
|
||||
|
||||
@Resource
|
||||
private WalletTransactionService walletTransactionService;
|
||||
|
||||
@Test
|
||||
public void eruptAdd() {
|
||||
// 4.24
|
||||
Long walletId = 1877309001545244673L;
|
||||
int price = 1;
|
||||
String bizId = "-1";
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
walletTransactionService.addWalletBalance(walletId, price, bizId, WalletBizEnum.RECHARGE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user