mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-19 18:45:03 +08:00
单元测试
This commit is contained in:
@@ -9,7 +9,12 @@ import com.jsowell.common.core.domain.ykc.TransactionRecordsData;
|
||||
import com.jsowell.common.core.redis.RedisCache;
|
||||
import com.jsowell.common.enums.ykc.OrderStatusEnum;
|
||||
import com.jsowell.common.exception.BusinessException;
|
||||
import com.jsowell.common.util.*;
|
||||
import com.jsowell.common.util.BytesUtil;
|
||||
import com.jsowell.common.util.DateUtils;
|
||||
import com.jsowell.common.util.DictUtils;
|
||||
import com.jsowell.common.util.JWTUtils;
|
||||
import com.jsowell.common.util.StringUtils;
|
||||
import com.jsowell.common.util.YKCUtils;
|
||||
import com.jsowell.common.util.id.SnUtils;
|
||||
import com.jsowell.common.util.id.SnowflakeIdWorker;
|
||||
import com.jsowell.common.util.ip.AddressUtils;
|
||||
@@ -29,6 +34,7 @@ import com.jsowell.pile.dto.ImportBillingTemplateDTO;
|
||||
import com.jsowell.pile.dto.QueryOrderDTO;
|
||||
import com.jsowell.pile.dto.QueryPileDTO;
|
||||
import com.jsowell.pile.dto.QueryStationDTO;
|
||||
import com.jsowell.pile.dto.RefundableWxPayOrderData;
|
||||
import com.jsowell.pile.dto.WeixinPayDTO;
|
||||
import com.jsowell.pile.mapper.MemberBasicInfoMapper;
|
||||
import com.jsowell.pile.mapper.PileBillingTemplateMapper;
|
||||
@@ -40,7 +46,9 @@ import com.jsowell.pile.service.IPileStationInfoService;
|
||||
import com.jsowell.pile.service.SimCardService;
|
||||
import com.jsowell.pile.service.WechatPayService;
|
||||
import com.jsowell.pile.service.WxpayCallbackRecordService;
|
||||
import com.jsowell.pile.vo.web.*;
|
||||
import com.jsowell.pile.vo.web.BillingTemplateVO;
|
||||
import com.jsowell.pile.vo.web.OrderListVO;
|
||||
import com.jsowell.pile.vo.web.PileDetailVO;
|
||||
import com.jsowell.service.MemberService;
|
||||
import com.jsowell.service.OrderService;
|
||||
import com.jsowell.service.PileRemoteService;
|
||||
@@ -141,6 +149,57 @@ public class SpringBootTestController {
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
@Test
|
||||
public void testRefundForBalance() {
|
||||
BigDecimal refundAmount = new BigDecimal("2");
|
||||
// 退款金额 元转分 123
|
||||
int refundTotalCents = refundAmount.multiply(new BigDecimal(100)).intValue();
|
||||
|
||||
// 查询用户充值余额订单 过滤掉已经退款的充值订单 refundableOrder
|
||||
List<RefundableWxPayOrderData> recordList = Lists.newArrayList();
|
||||
// recordList.add(RefundableWxPayOrderData.builder().outTradeNo("1").transactionId("1").payerAmount(new BigDecimal("1000")).refundableAmount(new BigDecimal("0")).build());
|
||||
// recordList.add(RefundableWxPayOrderData.builder().outTradeNo("2").transactionId("2").payerAmount(new BigDecimal("1000")).refundableAmount(new BigDecimal("0")).build());
|
||||
recordList.add(RefundableWxPayOrderData.builder().outTradeNo("3").transactionId("3").payerAmount(new BigDecimal("500")).refundableAmount(new BigDecimal("300")).build());
|
||||
|
||||
// 也许需要多笔支付订单才够退款
|
||||
List<WechatPayRefundRequest> requestList = com.google.common.collect.Lists.newArrayList();
|
||||
WechatPayRefundRequest request;
|
||||
for (RefundableWxPayOrderData record : recordList) {
|
||||
int refundableTotal = record.getRefundableAmount().intValue(); // 该笔支付订单的可退金额,单位分
|
||||
int payerTotal = record.getPayerAmount().intValue(); // 该笔支付订单的支付金额,单位分
|
||||
// 用户申请退款金额-可退金额
|
||||
refundTotalCents = refundTotalCents - refundableTotal; // 123 - 100
|
||||
request = new WechatPayRefundRequest();
|
||||
request.setTransaction_id(record.getTransactionId()); // 微信支付单号
|
||||
request.setOut_trade_no(record.getOutTradeNo()); // 商户订单号
|
||||
request.setOut_refund_no(SnowflakeIdWorker.getSnowflakeId()); // 商户退款单号
|
||||
request.setNotify_url(WeChatPayParameter.refundNotifyUrl); // 回调接口
|
||||
request.setReason("用户余额退款");
|
||||
request.setFunds_account("AVAILABLE");
|
||||
if (refundTotalCents > 0) {
|
||||
// 如果大于0说明,这笔单退完也不够
|
||||
WechatPayRefundRequest.Amount amount = new WechatPayRefundRequest.Amount();
|
||||
amount.setRefund(refundableTotal); // 退款金额
|
||||
amount.setTotal(payerTotal); // 原订单金额
|
||||
request.setAmount(amount);
|
||||
requestList.add(request);
|
||||
} else {
|
||||
// 如果小于0,这笔单退一部分
|
||||
// 生成退款单号
|
||||
WechatPayRefundRequest.Amount amount = new WechatPayRefundRequest.Amount();
|
||||
// 部分退
|
||||
int i = refundableTotal + refundTotalCents;
|
||||
amount.setRefund(i); // 退款金额
|
||||
amount.setTotal(payerTotal); // 原订单金额
|
||||
request.setAmount(amount);
|
||||
requestList.add(request);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(requestList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloseStartFailedOrder() {
|
||||
String startTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.addDays(new Date(), -2));
|
||||
|
||||
Reference in New Issue
Block a user