/* * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ package org.springblade.modules.pay.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.google.gson.Gson; import org.springblade.modules.pay.entity.OrderInfoEntity; import org.springblade.modules.pay.entity.RefundInfoEntity; import org.springblade.modules.pay.mapper.RefundInfoMapper; import org.springblade.modules.pay.service.IOrderInfoService; import org.springblade.modules.pay.service.IRefundInfoService; import org.springblade.modules.pay.vo.RefundInfoVO; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.Random; /** * 退款信息 服务实现类 * * @author BladeX * @since 2024-04-07 */ @Service public class RefundInfoServiceImpl extends ServiceImpl implements IRefundInfoService { @Resource private IOrderInfoService orderInfoService; @Override public IPage selectRefundInfoPage(IPage page, RefundInfoVO refundInfo) { return page.setRecords(baseMapper.selectRefundInfoPage(page, refundInfo)); } @Override public RefundInfoEntity createRefundByOrderNo(String orderNo, String reason) { //根据订单号获取订单信息 OrderInfoEntity orderInfo = orderInfoService.getOne(Wrappers.lambdaQuery() .eq(OrderInfoEntity::getOrderNo, orderNo)); //根据订单号生成退款订单 RefundInfoEntity refundInfo = new RefundInfoEntity(); refundInfo.setOrderNo(orderNo);//订单编号 refundInfo.setRefundNo(getOrderNoStr());//退款单编号 refundInfo.setTotalFee(orderInfo.getTotalFee());//原订单金额(分) refundInfo.setRefund(orderInfo.getTotalFee());//退款金额(分) refundInfo.setReason(reason);//退款原因 //保存退款订单 baseMapper.insert(refundInfo); return refundInfo; } @Override public void updateRefund(String content) { //将json字符串转换成Map Gson gson = new Gson(); Map resultMap = gson.fromJson(content, HashMap.class); //根据退款单编号修改退款单 QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("refund_no", resultMap.get("out_refund_no")); //设置要修改的字段 RefundInfoEntity refundInfo = new RefundInfoEntity(); refundInfo.setRefundId(resultMap.get("refund_id"));//微信支付退款单号 //查询退款和申请退款中的返回参数 if(resultMap.get("status") != null){ refundInfo.setRefundStatus(resultMap.get("status"));//退款状态 refundInfo.setContentReturn(content);//将全部响应结果存入数据库的content字段 } //退款回调中的回调参数 if(resultMap.get("refund_status") != null){ refundInfo.setRefundStatus(resultMap.get("refund_status"));//退款状态 refundInfo.setContentNotify(content);//将全部响应结果存入数据库的content字段 } //更新退款单 baseMapper.update(refundInfo, queryWrapper); } //生成订单号 public static String getOrderNoStr() { String order = "refund" + new SimpleDateFormat("yyyyMMdd").format(new Date()); Random r = new Random(); for (int i = 0; i < 10; i++) { order += r.nextInt(9); } return order; } }