mirror of
https://gitee.com/likeadmin/likeadmin_java.git
synced 2026-06-01 14:40:10 +08:00
增加退款接口
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
package com.mdd.common.enums;
|
||||
|
||||
public enum RefundEnum {
|
||||
|
||||
// 退款类型
|
||||
TYPE_ADMIN(1, "后台退款"),
|
||||
|
||||
// 退款状态
|
||||
REFUND_ING(0, "退款中"),
|
||||
REFUND_SUCCESS(1, "退款成功"),
|
||||
REFUND_ERROR(2, "退款失败"),
|
||||
|
||||
// 退款订单类型
|
||||
ORDER_TYPE_ORDER(1, "普通订单"),
|
||||
ORDER_TYPE_RECHARGE(2, "充值订单");
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
*/
|
||||
private final int code;
|
||||
private final String msg;
|
||||
RefundEnum(int code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取状态码
|
||||
*
|
||||
* @author fzr
|
||||
* @return Long
|
||||
*/
|
||||
public int getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取提示
|
||||
*
|
||||
* @author fzr
|
||||
* @return String
|
||||
*/
|
||||
public String getMsg() {
|
||||
return this.msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据编码获取Msg
|
||||
*
|
||||
* @author fzr
|
||||
* @param code 类型
|
||||
* @return String
|
||||
*/
|
||||
public static String getOrderType(Integer code){
|
||||
switch (code) {
|
||||
case 1:
|
||||
return "order";
|
||||
case 2:
|
||||
return "recharge";
|
||||
}
|
||||
return "未知";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
package com.mdd.common.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.mdd.common.core.basics.IBaseMapper;
|
||||
import com.mdd.common.entity.RefundLog;
|
||||
import com.mdd.common.entity.RefundRecord;
|
||||
import com.mdd.common.util.TimeUtils;
|
||||
import com.mdd.common.util.ToolUtils;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
@@ -9,4 +13,29 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
*/
|
||||
@Mapper
|
||||
public interface RefundLogMapper extends IBaseMapper<RefundLog> {
|
||||
|
||||
/**
|
||||
* 生成唯一单号
|
||||
*
|
||||
* @author fzr
|
||||
* @param field 字段名
|
||||
* @return String
|
||||
*/
|
||||
default String randMakeOrderSn(String field) {
|
||||
String date = TimeUtils.timestampToDate(System.currentTimeMillis()/1000, "yyyyMMddHHmmss");
|
||||
String sn;
|
||||
while (true) {
|
||||
sn = date + ToolUtils.randomInt(12);
|
||||
RefundLog snModel = this.selectOne(
|
||||
new QueryWrapper<RefundLog>()
|
||||
.select("id")
|
||||
.eq(field, sn)
|
||||
.last("limit 1"));
|
||||
if (snModel == null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return sn;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package com.mdd.common.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.mdd.common.core.basics.IBaseMapper;
|
||||
import com.mdd.common.entity.RechargeOrder;
|
||||
import com.mdd.common.entity.RefundRecord;
|
||||
import com.mdd.common.util.TimeUtils;
|
||||
import com.mdd.common.util.ToolUtils;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
@@ -9,4 +13,29 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
*/
|
||||
@Mapper
|
||||
public interface RefundRecordMapper extends IBaseMapper<RefundRecord> {
|
||||
|
||||
/**
|
||||
* 生成唯一单号
|
||||
*
|
||||
* @author fzr
|
||||
* @param field 字段名
|
||||
* @return String
|
||||
*/
|
||||
default String randMakeOrderSn(String field) {
|
||||
String date = TimeUtils.timestampToDate(System.currentTimeMillis()/1000, "yyyyMMddHHmmss");
|
||||
String sn;
|
||||
while (true) {
|
||||
sn = date + ToolUtils.randomInt(12);
|
||||
RefundRecord snModel = this.selectOne(
|
||||
new QueryWrapper<RefundRecord>()
|
||||
.select("id")
|
||||
.eq(field, sn)
|
||||
.last("limit 1"));
|
||||
if (snModel == null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return sn;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -115,18 +115,19 @@ public class WxPayDriver {
|
||||
*/
|
||||
public static WxPayRefundV3Result refund(RefundRequestV3 request) throws WxPayException {
|
||||
WxPayRefundV3Request requestObj = new WxPayRefundV3Request();
|
||||
request.setTransactionId(request.getTransactionId());
|
||||
request.setOutTradeNo(request.getOutRefundNo());
|
||||
request.setOutRefundNo(request.getOutRefundNo());
|
||||
request.setReason(request.getReason());
|
||||
request.setNotifyUrl(request.getNotifyUrl());
|
||||
request.setSubMchid(request.getSubMchid());
|
||||
request.setGoodsDetails(request.getGoodsDetails());
|
||||
requestObj.setTransactionId(request.getTransactionId());
|
||||
requestObj.setOutTradeNo(request.getOutTradeNo());
|
||||
requestObj.setOutRefundNo(request.getOutRefundNo());
|
||||
requestObj.setReason(request.getReason());
|
||||
requestObj.setNotifyUrl(request.getNotifyUrl());
|
||||
requestObj.setSubMchid(request.getSubMchid());
|
||||
requestObj.setGoodsDetails(request.getGoodsDetails());
|
||||
|
||||
WxPayRefundV3Request.Amount amount = new WxPayRefundV3Request.Amount();
|
||||
amount.setRefund(request.getRefundAmount());
|
||||
amount.setTotal(request.getTotalAmount());
|
||||
amount.setCurrency(StringUtils.isEmpty(request.getCurrency()) ? "CNY" : request.getCurrency());
|
||||
requestObj.setAmount(amount);
|
||||
|
||||
return wxPayService.refundV3(requestObj);
|
||||
}
|
||||
|
||||
@@ -12,35 +12,35 @@ public class RefundRequestV3 implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -1L;
|
||||
|
||||
/** 订单流水号 */
|
||||
/** 订单流水号: (必须) */
|
||||
private String transactionId;
|
||||
|
||||
/** 订单单号 */
|
||||
/** 订单单号: (必须) */
|
||||
private String outTradeNo;
|
||||
|
||||
/** 退款单号 */
|
||||
/** 退款单号: (必须) */
|
||||
@SerializedName("out_refund_no")
|
||||
private String outRefundNo;
|
||||
|
||||
/** 退款原因 */
|
||||
private String reason;
|
||||
|
||||
/** 通知接口 */
|
||||
private String notifyUrl;
|
||||
|
||||
/** 退款金额 */
|
||||
/** 退款金额 : (必须)*/
|
||||
private Integer refundAmount;
|
||||
|
||||
/** 订单总额 */
|
||||
/** 订单总额: (必须) */
|
||||
private Integer totalAmount;
|
||||
|
||||
/** 退款币种 */
|
||||
/** 退款原因: 非必须 */
|
||||
private String reason;
|
||||
|
||||
/** 通知接口: 非必须 */
|
||||
private String notifyUrl;
|
||||
|
||||
/** 退款币种: 非必须 */
|
||||
private String currency;
|
||||
|
||||
/** 商品信息 */
|
||||
/** 商品信息: 非必须 */
|
||||
private List<WxPayRefundV3Request.GoodsDetail> goodsDetails;
|
||||
|
||||
/** 子商户号 */
|
||||
/** 子商户号: 非必须 */
|
||||
private String subMchid;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user