Compare commits

..

13 Commits

Author SHA1 Message Date
wyn
bc52704f0f 退单 2026-05-08 18:16:00 +08:00
wyn
f58918b179 退单 2026-05-08 13:54:45 +08:00
wyn
d3b25e8078 退单 2026-05-08 09:14:07 +08:00
wyn
e1eecb5cdc 退款 2026-05-07 08:00:15 +08:00
wyn
f47bca3a8b 退单 2026-05-06 18:08:27 +08:00
wyn
7cb2d42662 退款 2026-05-02 20:24:26 +08:00
wyn
5422fe0140 退款 2026-05-02 18:38:51 +08:00
wyn
4e672f7e1d 退款 2026-04-30 23:08:14 +08:00
wyn
594c99b4dc 退单 2026-04-30 19:00:15 +08:00
wyn
a4edccc7de 退单 2026-04-30 09:54:18 +08:00
wyn
6bc3f33d3d 退款 2026-04-28 23:21:29 +08:00
wyn
f50e17aa87 退单 2026-04-28 18:15:23 +08:00
wyn
43d0340593 退单 2026-04-28 17:34:00 +08:00
29 changed files with 487 additions and 86 deletions

View File

@@ -27,9 +27,17 @@ public class Constants {
*/ */
public static final String ORDER_STATUS_FAIL = "4"; public static final String ORDER_STATUS_FAIL = "4";
/** /**
* 订单状态 - 交易失败 * 订单状态 - 交易超时
*/
public static final String ORDER_STATUS_TIMEOUT = "5";
/**
* 订单状态 - 退款
*/ */
public static final String ORDER_STATUS_REFUND = "6"; public static final String ORDER_STATUS_REFUND = "6";
/**
* 订单状态 - 退款中
*/
public static final String ORDER_STATUS_REFUNDING = "7";
/** /**
* 订单状态 - 全部 * 订单状态 - 全部

View File

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.alibaba.fastjson.JSONObject;
import com.peanut.common.utils.DateUtils; import com.peanut.common.utils.DateUtils;
import com.peanut.common.utils.PageUtils; import com.peanut.common.utils.PageUtils;
import com.peanut.common.utils.R; import com.peanut.common.utils.R;
@@ -33,11 +34,15 @@ import com.peanut.modules.common.dao.UserCourseBuyDao;
import com.peanut.modules.common.entity.*; import com.peanut.modules.common.entity.*;
import com.peanut.modules.common.service.*; import com.peanut.modules.common.service.*;
import com.peanut.modules.master.service.CourseCatalogueService; import com.peanut.modules.master.service.CourseCatalogueService;
import com.peanut.modules.pay.alipay.dto.ReFundDTO;
import com.peanut.modules.pay.alipay.service.AliPayService;
import com.peanut.modules.pay.weChatPay.dto.WeChatRefundInfo;
import com.peanut.modules.pay.weChatPay.dto.WechatPaymentInfo; import com.peanut.modules.pay.weChatPay.dto.WechatPaymentInfo;
import com.peanut.modules.pay.weChatPay.service.WxpayService; import com.peanut.modules.pay.weChatPay.service.WxpayService;
import com.peanut.modules.sys.entity.SysConfigEntity; import com.peanut.modules.sys.entity.SysConfigEntity;
import com.peanut.modules.sys.service.SysConfigService; import com.peanut.modules.sys.service.SysConfigService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpException;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@@ -122,6 +127,8 @@ public class BuyOrderController {
private BuyOrderRefundService buyOrderRefundService; private BuyOrderRefundService buyOrderRefundService;
@Autowired @Autowired
private BuyOrderRefundLogService buyOrderRefundLogService; private BuyOrderRefundLogService buyOrderRefundLogService;
@Autowired
private AliPayService aliPayService;
@RequestMapping(value = "/decomposeShipment", method = RequestMethod.POST) @RequestMapping(value = "/decomposeShipment", method = RequestMethod.POST)
public R decomposeShipment(@RequestBody BuyOrderListRequestVo requestVo) { public R decomposeShipment(@RequestBody BuyOrderListRequestVo requestVo) {
@@ -599,24 +606,28 @@ public class BuyOrderController {
return R.error("退款信息不存在"); return R.error("退款信息不存在");
} }
QueryWrapper<BuyOrderRefundLog> wapper2 = new QueryWrapper<>(); QueryWrapper<BuyOrderRefundLog> wapper2 = new QueryWrapper<>();
wapper2.eq("refund_id",refundInfo.getId()).orderByDesc("create_time"); wapper2.eq("refund_id",refundInfo.getId()).orderByDesc("id");
List<BuyOrderRefundLog> list = buyOrderRefundLogService.list(wapper2); List<BuyOrderRefundLog> list = buyOrderRefundLogService.list(wapper2);
for (BuyOrderRefundLog log : list){ for (BuyOrderRefundLog log : list){
if(log.getType()==1){ if(log.getType()==4){
log.setTitle("天医币已退还"); log.setTitle("天医币已退还");
log.setContent("天医币已退还到账户,可在我的->天医币中查看明细"); log.setContent("天医币已退还到账户,可在我的->天医币中查看明细");
}else if(log.getType()==2){ }else if(log.getType()==5){
log.setTitle("积分已退还"); log.setTitle("积分已退还");
log.setContent("积分已退还到账户,可在我的->积分中查看明细"); log.setContent("积分已退还到账户,可在我的->积分中查看明细");
}else if(log.getType()==3){ }else if(log.getType()==2){
log.setTitle(log.getStatus()==1?"到账成功":"已退款,支付宝处理中"); log.setTitle(log.getStatus()==1?"到账成功":(log.getStatus()==2?"支付宝处理中":"提交支付宝处理"));
log.setContent(log.getStatus()==1?"已退到您的支付宝,到账时间以支付宝处理时间为准,可前往「支付宝-账单」查看":"已将退款资金提交给支付宝处理通常情况下退款会原路退回您的支付账户预计会在1-7天内到账"); log.setContent(log.getStatus()==1?"已退到您的支付宝,到账时间以支付宝处理时间为准,可前往「支付宝-账单」查看":(log.getStatus()==2?"已将退款提交给支付宝处理":"支付宝处理中通常情况下退款会原路退回您的支付账户预计会在1-7天内到账"));
}else if(log.getType()==4){ }else if(log.getType()==1){
log.setTitle(log.getStatus()==1?"到账成功":"已退款,微信处理中"); log.setTitle(log.getStatus()==1?"到账成功":(log.getStatus()==2?"微信处理中":"提交微信处理"));
log.setContent(log.getStatus()==1?"已退到您的微信,到账时间以微信处理时间为准,可前往「微信-账单」查看":"已将退款资金提交给微信处理通常情况下退款会原路退回您的支付账户预计会在1-7天内到账"); log.setContent(log.getStatus()==1?"已退到您的微信,到账时间以微信处理时间为准,可前往「微信-账单」查看":(log.getStatus()==2?"已将退款提交给微信处理":"微信处理中通常情况下退款会原路退回您的支付账户预计会在1-7天内到账"));
}else if(log.getType()==0){
log.setTitle("发起退款");
log.setContent("系统会在1-2天内提交处理");
} }
} }
BuyOrderRefundLog log = new BuyOrderRefundLog(); /* BuyOrderRefundLog log = new BuyOrderRefundLog();
log.setId(0); log.setId(0);
log.setRefundId(refundInfo.getId()); log.setRefundId(refundInfo.getId());
log.setType(0); log.setType(0);
@@ -624,7 +635,7 @@ public class BuyOrderController {
log.setCreateTime(refundInfo.getCreateTime()); log.setCreateTime(refundInfo.getCreateTime());
log.setTitle("发起退款"); log.setTitle("发起退款");
log.setContent("系统会在1-2天内提交处理"); log.setContent("系统会在1-2天内提交处理");
list.add(log); list.add(log);*/
Map<String,Object> result = new HashMap<>(); Map<String,Object> result = new HashMap<>();
BigDecimal shippingMoney = refundInfo.getDeductShipping()==1?refundInfo.getShippingMoney():BigDecimal.ZERO; BigDecimal shippingMoney = refundInfo.getDeductShipping()==1?refundInfo.getShippingMoney():BigDecimal.ZERO;
@@ -654,20 +665,16 @@ public class BuyOrderController {
if (user == null) { if (user == null) {
return R.error("订单对应用户不存在"); return R.error("订单对应用户不存在");
} }
if(Constants.ORDER_STATUS_REFUND.equals(buyOrder.getOrderStatus())
if (Constants.ORDER_STATUS_TO_BE_PAID.equals(buyOrder.getOrderStatus()) || Constants.ORDER_STATUS_REFUNDING.equals(buyOrder.getOrderStatus())){
return R.error("请勿重复提交退款");
}else if (Constants.ORDER_STATUS_TO_BE_PAID.equals(buyOrder.getOrderStatus())
|| Constants.ORDER_STATUS_FAIL.equals(buyOrder.getOrderStatus()) || Constants.ORDER_STATUS_FAIL.equals(buyOrder.getOrderStatus())
|| Constants.ORDER_STATUS_REFUND.equals(buyOrder.getOrderStatus())
|| Constants.ORDER_STATUS_OUT_OF_TIME.equals(buyOrder.getOrderStatus())) { || Constants.ORDER_STATUS_OUT_OF_TIME.equals(buyOrder.getOrderStatus())) {
return R.error("当前订单状态不支持退单"); return R.error("当前订单状态不支持退单");
} }
// QueryWrapper<BuyOrderRefund> refundQueryWrapper = new QueryWrapper<>(); //设置状态为退款中
// refundQueryWrapper.eq("order_id",buyOrder.getOrderId()); buyOrder.setOrderStatus(Constants.ORDER_STATUS_REFUNDING);
// long refundOrderNums = buyOrderRefundService.count(refundQueryWrapper);
if(buyOrder.getOrderStatus().equals(Constants.ORDER_STATUS_REFUND)){
return R.error("请勿重复申请退款");
}
buyOrder.setOrderStatus(Constants.ORDER_STATUS_REFUND);
buyOrderService.updateById(buyOrder); buyOrderService.updateById(buyOrder);
BigDecimal refundFee = buyOrder.getRealMoney(); BigDecimal refundFee = buyOrder.getRealMoney();
@@ -679,13 +686,13 @@ public class BuyOrderController {
} }
String remark = params.containsKey("remark") && params.get("remark").toString()!=null?params.get("remark").toString():""; String remark = params.containsKey("remark") && params.get("remark").toString()!=null?params.get("remark").toString():"";
String refundNo = buyOrderRefundService.genRefundNo();
BuyOrderRefund buyOrderRefund = new BuyOrderRefund(); BuyOrderRefund buyOrderRefund = new BuyOrderRefund();
String refundNo = buyOrderRefundService.genRefundNo();
buyOrderRefund.setRefundNo(refundNo); buyOrderRefund.setRefundNo(refundNo);
buyOrderRefund.setOrderId(buyOrder.getOrderId()); buyOrderRefund.setOrderId(buyOrder.getOrderId());
buyOrderRefund.setOrderSn(buyOrder.getOrderSn()); buyOrderRefund.setOrderSn(buyOrder.getOrderSn());
buyOrderRefund.setUserId(buyOrder.getUserId()); buyOrderRefund.setUserId(buyOrder.getUserId());
buyOrderRefund.setType("线上"); //id buyOrderRefund.setType(params.containsKey("deductShipping")?"后台":"线上"); //id
buyOrderRefund.setPayType(buyOrder.getPaymentMethod()); buyOrderRefund.setPayType(buyOrder.getPaymentMethod());
buyOrderRefund.setFee(refundFee); buyOrderRefund.setFee(refundFee);
buyOrderRefund.setJfDeduction(buyOrder.getJfDeduction()); buyOrderRefund.setJfDeduction(buyOrder.getJfDeduction());
@@ -694,20 +701,79 @@ public class BuyOrderController {
buyOrderRefund.setRemark(remark); buyOrderRefund.setRemark(remark);
buyOrderRefundService.save(buyOrderRefund); buyOrderRefundService.save(buyOrderRefund);
int refundId = buyOrderRefund.getId(); buyOrderRefundLogService.insertRefundLog(buyOrderRefund.getId(),0,1);
int refundId = buyOrderRefund.getId();
if (Constants.PAYMENT_METHOD_VIRTUAL.equals(buyOrder.getPaymentMethod())) { if (Constants.PAYMENT_METHOD_VIRTUAL.equals(buyOrder.getPaymentMethod())) {
//BigDecimal refundPeanutCoin = buyOrder.getRealMoney() == null?BigDecimal.ZERO : buyOrder.getRealMoney(); //if(refundFee.compareTo(BigDecimal.ZERO)>0){
if(refundFee.compareTo(BigDecimal.ZERO)>0){ //退还虚拟币
transactionDetailsService.refundRecord(buyOrder,user,refundFee); transactionDetailsService.refundRecord(buyOrder,user,refundFee);
user.setPeanutCoin(user.getPeanutCoin().add(refundFee)); user.setPeanutCoin(user.getPeanutCoin().add(refundFee));
myUserService.updateById(user); myUserService.updateById(user);
buyOrderRefundLogService.insertRefundLog(refundId,1,1); //记录退款进度
} buyOrderRefundLogService.insertRefundLog(refundId,4,1);
} //积分、其他权益退回
buyOrderService.refundOrder(buyOrder,user,refundId); buyOrderService.refundOrder(buyOrder,user,refundId);
//更改订单状态为已退款
buyOrder.setOrderStatus(Constants.ORDER_STATUS_REFUND);
buyOrderService.updateById(buyOrder);
return R.ok("ok"); return R.ok("ok");
//}
} else if (Constants.PAYMENT_METHOD_WECHAT_PAY.equals(buyOrder.getPaymentMethod())) {
buyOrderRefundLogService.insertRefundLog(refundId,1,0);
if (refundFee.compareTo(BigDecimal.ZERO) > 0) {
WeChatRefundInfo weChatRefundInfo = new WeChatRefundInfo();
weChatRefundInfo.setOrderSn(buyOrder.getOrderSn());
weChatRefundInfo.setOrderId(buyOrder.getOrderId());
weChatRefundInfo.setOrderType(buyOrder.getOrderType());
weChatRefundInfo.setRefundNo(buyOrderRefund.getRefundNo());
weChatRefundInfo.setTotalAmount(buyOrder.getRealMoney());
weChatRefundInfo.setRefundAmount(buyOrderRefund.getFee());
weChatRefundInfo.setRemark("用户申请退款");
weChatRefundInfo.setRefundId(buyOrderRefund.getId());
if(buyOrder.getCome()==null||buyOrder.getCome()==0){
weChatRefundInfo.setAppName(buyOrder.getAppName());
} else if (buyOrder.getCome()==2){
weChatRefundInfo.setAppName("wumen");
} else if (buyOrder.getCome()==1) {
weChatRefundInfo.setAppName("zmzm");
} else if (buyOrder.getCome()==3) {
weChatRefundInfo.setAppName("xlkj");
} else if (buyOrder.getCome()==4) {
weChatRefundInfo.setAppName("thyy");
}
try {
wxpayService.refund(weChatRefundInfo);
} catch (Exception e) {
System.out.println("msg=" + e.getMessage());
}
}
}else if (Constants.PAYMENT_METHOD_ALI_PAY.equals(buyOrder.getPaymentMethod())) {
buyOrderRefundLogService.insertRefundLog(refundId,2,0);
if (refundFee.compareTo(BigDecimal.ZERO) > 0) {
aliPayService.refund(buyOrder,user,buyOrderRefund);
}
}
// else if (Constants.PAYMENT_METHOD_ALI_PAY.equals(buyOrder.getPaymentMethod())) {
// buyOrderRefundLogService.insertRefundLog(refundId,2,0);
// if (refundFee.compareTo(BigDecimal.ZERO) > 0) {
// Map<String, Object> refundParams = new HashMap<>();
// refundParams.put("orderSn", buyOrder.getOrderSn());
// refundParams.put("refundFee", refundFee);
// String refundResult = aliPayService.refund(refundParams);
// JSONObject resultJson = JSONObject.parseObject(refundResult);
// JSONObject responseJson = resultJson.getJSONObject("alipay_trade_refund_response");
// if (responseJson == null
// || !"10000".equals(responseJson.getString("code"))
// || !"Y".equals(responseJson.getString("fund_change"))) {
// return R.error("支付宝退款申请失败");
// }else{
// buyOrderRefundLogService.insertRefundLog(refundId,3,2);
// }
// }
// }
return R.ok("ok");
} }
@RequestMapping("/llll") @RequestMapping("/llll")
public R ls(){ public R ls(){

View File

@@ -35,7 +35,8 @@ public interface MyUserService extends IService<MyUserEntity> {
boolean checkUserTelOrEmail(MyUserEntity user); boolean checkUserTelOrEmail(MyUserEntity user);
void rollbackUserPowers(BuyOrder order, List<BuyOrderProduct> orderProducts); //void rollbackUserPowers(BuyOrder order, List<BuyOrderProduct> orderProducts);
void rollbackUserPowers(BuyOrder order, MyUserEntity user, List<BuyOrderProduct> orderProducts);
} }

View File

@@ -17,7 +17,6 @@ import com.peanut.modules.book.service.CountyService;
import com.peanut.modules.book.service.ExpressOrderService; import com.peanut.modules.book.service.ExpressOrderService;
import com.peanut.modules.book.service.MyUserService; import com.peanut.modules.book.service.MyUserService;
import com.peanut.modules.book.service.ProvinceService; import com.peanut.modules.book.service.ProvinceService;
import com.peanut.modules.book.vo.UserVipYearVo;
import com.peanut.modules.common.dao.*; import com.peanut.modules.common.dao.*;
import com.peanut.modules.book.service.*; import com.peanut.modules.book.service.*;
import com.peanut.modules.book.to.UserOrderDto; import com.peanut.modules.book.to.UserOrderDto;
@@ -29,9 +28,7 @@ import com.peanut.modules.common.entity.*;
import com.peanut.modules.common.service.*; import com.peanut.modules.common.service.*;
import com.peanut.modules.common.vo.CourseCatalogueVo; import com.peanut.modules.common.vo.CourseCatalogueVo;
import com.peanut.modules.oss.service.OssService; import com.peanut.modules.oss.service.OssService;
import com.qiniu.util.Json;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.time.DateUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -223,6 +220,8 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
} else if (type.equals("2")) { } else if (type.equals("2")) {
orderEntity.setPaymentDate(new Date()); orderEntity.setPaymentDate(new Date());
orderEntity.setOrderStatus("3"); orderEntity.setOrderStatus("3");
}else if (type.equals("6")) {
orderEntity.setOrderStatus("6");
} }
updateById(orderEntity); updateById(orderEntity);
} }
@@ -461,9 +460,9 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
b1.setProduct(byId); b1.setProduct(byId);
b1.setExpressOrder(expressOrderDao.selectById(b1.getExpressOrderId())); b1.setExpressOrder(expressOrderDao.selectById(b1.getExpressOrderId()));
boolean refundableStatusProduct = false; boolean refundableStatusProduct = false;
if(b1.getProduct().getGoodsType().equals("05") && (paymentDateTime > timestamp-7*24*60*60*1000)){ if(b1.getProduct()!=null && b1.getProduct().getGoodsType().equals("05") && (paymentDateTime > timestamp-7*24*60*60*1000)){
refundableStatusProduct = true; refundableStatusProduct = true;
}else if(!b1.getProduct().getGoodsType().equals("05") && b.getOrderStatus().equals("1")){ }else if(b1.getProduct()!=null && !b1.getProduct().getGoodsType().equals("05") && b.getOrderStatus().equals("1")){
refundableStatusProduct = true; refundableStatusProduct = true;
} }
refundableStatusArr[i] = refundableStatusProduct; refundableStatusArr[i] = refundableStatusProduct;
@@ -478,12 +477,10 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
} }
} }
if(b.getOrderStatus().equals(Constants.ORDER_STATUS_REFUND)){ if(b.getOrderStatus().equals(Constants.ORDER_STATUS_REFUND)){
QueryWrapper<BuyOrderRefund> wrapperRefund = new QueryWrapper<>(); BuyOrderRefund refundInfo = buyOrderRefundService.getRefundInfoByOrderId(b.getOrderId());
wrapperRefund.eq("order_id",b.getOrderId());
BuyOrderRefund refundInfo = buyOrderRefundService.getOne(wrapperRefund);
b.setRefundRemark(refundInfo.getRemark()); b.setRefundRemark(refundInfo.getRemark());
} }
b.setRefundableStatus(b.getOrderStatus().equals("6")?false:refundableStatus); b.setRefundableStatus(b.getOrderStatus().equals("6")|| b.getOrderStatus().equals("7")?false:refundableStatus);
b.setProductList(buyOrderProducts); b.setProductList(buyOrderProducts);
//设置快递信息传递给前端 //设置快递信息传递给前端
ConsigneeVo consigneeVo = new ConsigneeVo(); ConsigneeVo consigneeVo = new ConsigneeVo();
@@ -539,7 +536,7 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
wrapper.eq(BuyOrder::getUserId,userOrderDto.getUserId()); wrapper.eq(BuyOrder::getUserId,userOrderDto.getUserId());
// wrapper.eq(BuyOrder::getOrderType,"order");//这里有点问题 // wrapper.eq(BuyOrder::getOrderType,"order");//这里有点问题
if(userOrderDto.getOrderStatus()==null){ if(userOrderDto.getOrderStatus()==null){
Integer[] sts = {0,1,2,3,6}; Integer[] sts = {0,1,2,3,6,7};
wrapper.in(BuyOrder::getOrderStatus,sts); wrapper.in(BuyOrder::getOrderStatus,sts);
}else{ }else{
wrapper.eq(BuyOrder::getOrderStatus,userOrderDto.getOrderStatus()); wrapper.eq(BuyOrder::getOrderStatus,userOrderDto.getOrderStatus());
@@ -572,9 +569,9 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
bb.setRecordId(userRecord.getId()); bb.setRecordId(userRecord.getId());
} }
boolean refundableStatusProduct = false; boolean refundableStatusProduct = false;
if (bb.getProduct().getGoodsType().equals("05") && paymentDateTime > timestamp - 7 * 24 * 60 * 60 * 1000) { if (bb.getProduct()!=null && bb.getProduct().getGoodsType().equals("05") && paymentDateTime > timestamp - 7 * 24 * 60 * 60 * 1000) {
refundableStatusProduct = true; refundableStatusProduct = true;
} else if (!bb.getProduct().getGoodsType().equals("05") && b.getOrderStatus().equals(Constants.ORDER_STATUS_TO_BE_SHIPPED)){ } else if (bb.getProduct()!=null && !bb.getProduct().getGoodsType().equals("05") && b.getOrderStatus().equals(Constants.ORDER_STATUS_TO_BE_SHIPPED)){
refundableStatusProduct = true; refundableStatusProduct = true;
} }
refundableStatusArr[i] = refundableStatusProduct; refundableStatusArr[i] = refundableStatusProduct;
@@ -588,7 +585,7 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
} }
} }
} }
b.setRefundableStatus(b.getOrderStatus().equals("6")?false:refundableStatus); b.setRefundableStatus(b.getOrderStatus().equals("6") || b.getOrderStatus().equals("7")?false:refundableStatus);
b.setProductList(buyOrderProducts); b.setProductList(buyOrderProducts);
b.setTimestamp(b.getCreateTime().getTime()/1000); b.setTimestamp(b.getCreateTime().getTime()/1000);
//充值订单填充充值商品信息 //充值订单填充充值商品信息
@@ -737,10 +734,14 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
public void removeCourseToUser(BuyOrder orderEntity){ public void removeCourseToUser(BuyOrder orderEntity){
QueryWrapper<UserCourseBuyLog> buyLogQueryWrapper = new QueryWrapper<>(); QueryWrapper<UserCourseBuyLog> buyLogQueryWrapper = new QueryWrapper<>();
buyLogQueryWrapper.eq("order_sn",orderEntity.getOrderSn()); buyLogQueryWrapper.eq("order_sn",orderEntity.getOrderSn());
log.info("order+sn===="+orderEntity.getOrderSn());
List<UserCourseBuyLog> userCourseBuyLogList = userCourseBuyLogDao.selectList(buyLogQueryWrapper); List<UserCourseBuyLog> userCourseBuyLogList = userCourseBuyLogDao.selectList(buyLogQueryWrapper);
log.info("size===="+userCourseBuyLogList.size());
for (UserCourseBuyLog userCourseBuyLog:userCourseBuyLogList){ for (UserCourseBuyLog userCourseBuyLog:userCourseBuyLogList){
userCourseBuyDao.deleteById(userCourseBuyLog.getUserCourseBuyId()); log.info("===delete====="+userCourseBuyLog.getUserCourseBuyId());
userCourseBuyLogDao.deleteById(userCourseBuyLog.getId()); log.info("===delete2====="+userCourseBuyLog.getId());
userCourseBuyDao.realDeleteById(userCourseBuyLog.getUserCourseBuyId());
userCourseBuyLogDao.realDeleteById(userCourseBuyLog.getId());
} }
} }
@Override @Override
@@ -1076,23 +1077,22 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
jfTransactionDetailsService.refundJfTransaction(buyOrder,user); jfTransactionDetailsService.refundJfTransaction(buyOrder,user);
user.setJf(jf.add(user.getJf())); user.setJf(jf.add(user.getJf()));
myUserService.updateById(user); myUserService.updateById(user);
buyOrderRefundLogService.insertRefundLog(refundId,2,1); buyOrderRefundLogService.insertRefundLog(refundId,5,1);
} }
if(buyOrder.getOrderType().equals("vip")){ if(buyOrder.getOrderType().equals("vip")){
userVipService.refundVip(buyOrder); userVipService.refundVip(buyOrder);
}else{ }else{
//撤回本订单购买赠送的优惠券 //撤回本订单购买赠送的优惠券
couponService.refundZSCouponHistoryByOrder(buyOrder); couponService.refundZSCouponHistoryByOrder(buyOrder);
/*//恢复用户权益(点穴/时辰取穴/五运六气/肿瘤古方) //恢复用户权益(点穴/时辰取穴/五运六气/肿瘤古方)
myUserService.rollbackUserPowers(buyOrder, orderProducts);*/ myUserService.rollbackUserPowers(buyOrder,user, orderProducts);
//撤回电子书权限 //撤回电子书权限
userEbookBuyService.rollbackUserEbooks(buyOrder, orderProducts); userEbookBuyService.rollbackUserEbooks(buyOrder, orderProducts);
//撤回课程权限 //撤回课程权限
log.info("====remove========="+buyOrder.getOrderSn());
removeCourseToUser(buyOrder); removeCourseToUser(buyOrder);
//回滚库存 //回滚库存
shopProductService.rollbackStock(buyOrder); shopProductService.rollbackStock(buyOrder);
} }
} }
} }

View File

@@ -102,9 +102,8 @@ public class MyUserServiceImpl extends ServiceImpl<MyUserDao, MyUserEntity> impl
MyUserEntity one = getOne(wrapper); MyUserEntity one = getOne(wrapper);
return one == null; return one == null;
} }
@Override
public void rollbackUserPowers(BuyOrder order, List<BuyOrderProduct> orderProducts) { public void rollbackUserPowers(BuyOrder order, MyUserEntity user, List<BuyOrderProduct> orderProducts) {
MyUserEntity user = getById(order.getUserId());
if(user == null){ if(user == null){
return; return;
} }

View File

@@ -88,6 +88,7 @@ public class TransactionDetailsServiceImpl extends ServiceImpl<TransactionDetail
TransactionDetailsEntity transactionDetailsEntity = new TransactionDetailsEntity(); TransactionDetailsEntity transactionDetailsEntity = new TransactionDetailsEntity();
transactionDetailsEntity.setUserId(user.getId()); transactionDetailsEntity.setUserId(user.getId());
transactionDetailsEntity.setOrderType("订单退款"); transactionDetailsEntity.setOrderType("订单退款");
transactionDetailsEntity.setPayNo(buyOrder.getOrderSn());
transactionDetailsEntity.setChangeAmount(refundPrice); transactionDetailsEntity.setChangeAmount(refundPrice);
transactionDetailsEntity.setUserBalance(user.getPeanutCoin().add(refundPrice)); transactionDetailsEntity.setUserBalance(user.getPeanutCoin().add(refundPrice));
transactionDetailsEntity.setRelationId(buyOrder.getOrderId()); transactionDetailsEntity.setRelationId(buyOrder.getOrderId());

View File

@@ -1,7 +1,5 @@
package com.peanut.modules.book.vo; package com.peanut.modules.book.vo;
import com.spire.ms.System.DateTime;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;

View File

@@ -55,7 +55,7 @@ public class TransactionDetailsController {
BuyOrder buyOrder = buyOrderService.getOne(new LambdaQueryWrapper<BuyOrder>() BuyOrder buyOrder = buyOrderService.getOne(new LambdaQueryWrapper<BuyOrder>()
.eq(BuyOrder::getOrderSn,orderSn)); .eq(BuyOrder::getOrderSn,orderSn));
if (buyOrder!=null){ if (buyOrder!=null){
if ("购买商品".equals(detail.getOrderType())){ if ("购买商品".equals(detail.getOrderType())||"订单退款".equals(detail.getOrderType())){
List<BuyOrderProduct> products = buyOrderProductService.list(new LambdaQueryWrapper<BuyOrderProduct>() List<BuyOrderProduct> products = buyOrderProductService.list(new LambdaQueryWrapper<BuyOrderProduct>()
.eq(BuyOrderProduct::getOrderId,buyOrder.getOrderId())); .eq(BuyOrderProduct::getOrderId,buyOrder.getOrderId()));
for (BuyOrderProduct buyOrderProduct : products) { for (BuyOrderProduct buyOrderProduct : products) {

View File

@@ -2,6 +2,7 @@ package com.peanut.modules.common.dao;
import com.github.yulichang.base.MPJBaseMapper; import com.github.yulichang.base.MPJBaseMapper;
import com.peanut.modules.common.entity.UserCourseBuyEntity; import com.peanut.modules.common.entity.UserCourseBuyEntity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
@@ -18,4 +19,7 @@ public interface UserCourseBuyDao extends MPJBaseMapper<UserCourseBuyEntity> {
List<Map<String,Object>> getIncome(@Param("date") String date); List<Map<String,Object>> getIncome(@Param("date") String date);
List<Map<String,Object>> getCoursePurchaseDetails(int courseId,int catalogueId,Integer limit,Integer offset); List<Map<String,Object>> getCoursePurchaseDetails(int courseId,int catalogueId,Integer limit,Integer offset);
@Delete("DELETE FROM user_course_buy WHERE id = #{userCourseBuyId}")
int realDeleteById(int userCourseBuyId);
} }

View File

@@ -2,8 +2,11 @@ package com.peanut.modules.common.dao;
import com.github.yulichang.base.MPJBaseMapper; import com.github.yulichang.base.MPJBaseMapper;
import com.peanut.modules.common.entity.UserCourseBuyLog; import com.peanut.modules.common.entity.UserCourseBuyLog;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
@Mapper @Mapper
public interface UserCourseBuyLogDao extends MPJBaseMapper<UserCourseBuyLog> { public interface UserCourseBuyLogDao extends MPJBaseMapper<UserCourseBuyLog> {
@Delete("DELETE FROM user_course_buy_log WHERE id = #{userCourseBuyLogId}")
int realDeleteById(int userCourseBuyLogId);
} }

View File

@@ -1,6 +1,5 @@
package com.peanut.modules.common.dao; package com.peanut.modules.common.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.yulichang.base.MPJBaseMapper; import com.github.yulichang.base.MPJBaseMapper;
import com.peanut.modules.common.entity.UserVipLog; import com.peanut.modules.common.entity.UserVipLog;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;

View File

@@ -29,6 +29,8 @@ public class BuyOrderRefund implements Serializable {
private int deductShipping; private int deductShipping;
//商品名称 //商品名称
private String title; private String title;
private int status;
private String remark; private String remark;
private Date createTime; private Date createTime;
private String wxRefundNo;
} }

View File

@@ -27,7 +27,7 @@ public class BuyOrderRefundLog implements Serializable {
private Date createTime; private Date createTime;
private int type; private int type;
private int status; private int status;
private int reason;
@TableField(exist = false) @TableField(exist = false)
private String title; private String title;

View File

@@ -6,4 +6,5 @@ import com.peanut.modules.common.entity.BuyOrderRefundLog;
public interface BuyOrderRefundLogService extends IService<BuyOrderRefundLog> { public interface BuyOrderRefundLogService extends IService<BuyOrderRefundLog> {
void insertRefundLog(int buyOrderRefundId, int type, int status); void insertRefundLog(int buyOrderRefundId, int type, int status);
void insertRefundLog(int buyOrderRefundId, int type, int status, String reason);
} }

View File

@@ -9,4 +9,6 @@ import java.math.BigDecimal;
public interface BuyOrderRefundService extends IService<BuyOrderRefund> { public interface BuyOrderRefundService extends IService<BuyOrderRefund> {
int insertBuyOrderRefund(BuyOrder buyOrder, BigDecimal refundFee, int deductShipping,String remark); int insertBuyOrderRefund(BuyOrder buyOrder, BigDecimal refundFee, int deductShipping,String remark);
String genRefundNo(); String genRefundNo();
BuyOrderRefund getRefundInfoByOrderId(int orderId);
} }

View File

@@ -2,6 +2,7 @@ package com.peanut.modules.common.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.modules.common.dao.BuyOrderRefundLogDao; import com.peanut.modules.common.dao.BuyOrderRefundLogDao;
import com.peanut.modules.common.entity.BuyOrder;
import com.peanut.modules.common.entity.BuyOrderRefund; import com.peanut.modules.common.entity.BuyOrderRefund;
import com.peanut.modules.common.entity.BuyOrderRefundLog; import com.peanut.modules.common.entity.BuyOrderRefundLog;
import com.peanut.modules.common.service.BuyOrderRefundLogService; import com.peanut.modules.common.service.BuyOrderRefundLogService;
@@ -19,4 +20,12 @@ public class BuyOrderRefundLogServiceImpl extends ServiceImpl<BuyOrderRefundLogD
log.setStatus(status); log.setStatus(status);
this.save(log); this.save(log);
} }
@Override
public void insertRefundLog(int refundId, int type, int status, String reason){
BuyOrderRefundLog log = new BuyOrderRefundLog();
log.setRefundId(refundId);
log.setType(type);
log.setStatus(status);
this.save(log);
}
} }

View File

@@ -1,5 +1,6 @@
package com.peanut.modules.common.service.impl; package com.peanut.modules.common.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.modules.common.dao.BuyOrderRefundDao; import com.peanut.modules.common.dao.BuyOrderRefundDao;
import com.peanut.modules.common.entity.BuyOrder; import com.peanut.modules.common.entity.BuyOrder;
@@ -37,4 +38,11 @@ public class BuyOrderRefundServiceImpl extends ServiceImpl<BuyOrderRefundDao, Bu
int random = new Random().nextInt(900) + 100; // 100~999 int random = new Random().nextInt(900) + 100; // 100~999
return "RF" + time + random; return "RF" + time + random;
} }
@Override
public BuyOrderRefund getRefundInfoByOrderId(int orderId){
QueryWrapper<BuyOrderRefund> wrapperRefund = new QueryWrapper<>();
wrapperRefund.eq("order_id",orderId).last("LIMIT 1");
BuyOrderRefund refundInfo = this.getOne(wrapperRefund);
return refundInfo;
}
} }

View File

@@ -7,8 +7,10 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.peanut.common.utils.ExpressOrderUtil; import com.peanut.common.utils.ExpressOrderUtil;
import com.peanut.common.utils.Query; import com.peanut.common.utils.Query;
import com.peanut.config.Constants;
import com.peanut.modules.common.dao.*; import com.peanut.modules.common.dao.*;
import com.peanut.modules.common.entity.*; import com.peanut.modules.common.entity.*;
import com.peanut.modules.common.service.BuyOrderRefundService;
import com.peanut.modules.common.service.BuyOrderService; import com.peanut.modules.common.service.BuyOrderService;
import com.peanut.modules.common.to.PrepareOrderDto; import com.peanut.modules.common.to.PrepareOrderDto;
import com.peanut.modules.common.vo.UserBaseVo; import com.peanut.modules.common.vo.UserBaseVo;
@@ -18,10 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.Instant; import java.time.Instant;
import java.util.Date; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Slf4j @Slf4j
@@ -44,6 +43,8 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
private AiBuyConfigDao aiBuyConfigDao; private AiBuyConfigDao aiBuyConfigDao;
@Autowired @Autowired
private ShopProductCourseDao shopProductCourseDao; private ShopProductCourseDao shopProductCourseDao;
@Autowired
private BuyOrderRefundService buyOrderRefundService;
@Override @Override
public Map<String, Object> initPrepareOrder(PrepareOrderDto prepareOrderDto) { public Map<String, Object> initPrepareOrder(PrepareOrderDto prepareOrderDto) {
@@ -75,7 +76,7 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
wrapper.eq(BuyOrder::getUserId,params.get("userId")); wrapper.eq(BuyOrder::getUserId,params.get("userId"));
wrapper.eq(BuyOrder::getCome,params.get("come")); wrapper.eq(BuyOrder::getCome,params.get("come"));
if(StringUtils.isEmpty(params.get("orderStatus").toString())){ if(StringUtils.isEmpty(params.get("orderStatus").toString())){
Integer[] sts = {0,1,2,3,6}; Integer[] sts = {0,1,2,3,6,7};
wrapper.in(BuyOrder::getOrderStatus,sts); wrapper.in(BuyOrder::getOrderStatus,sts);
}else{ }else{
wrapper.eq(BuyOrder::getOrderStatus,params.get("orderStatus").toString()); wrapper.eq(BuyOrder::getOrderStatus,params.get("orderStatus").toString());
@@ -122,9 +123,9 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
w.disableLogicDel().eq(ShopProduct::getProductId,bb.getProductId()); w.disableLogicDel().eq(ShopProduct::getProductId,bb.getProductId());
bb.setProduct(shopProductDao.selectOne(w)); bb.setProduct(shopProductDao.selectOne(w));
boolean refundableStatusProduct = false; boolean refundableStatusProduct = false;
if(bb.getProduct().getGoodsType().equals("05") && (paymentDateTime > timestamp-7*24*60*60*1000)){ if(bb.getProduct()!=null && bb.getProduct().getGoodsType().equals("05") && (paymentDateTime > timestamp-7*24*60*60*1000)){
refundableStatusProduct = true; refundableStatusProduct = true;
}else if(!bb.getProduct().getGoodsType().equals("05") && b.getOrderStatus().equals("1")){ }else if(bb.getProduct()!=null && !bb.getProduct().getGoodsType().equals("05") && b.getOrderStatus().equals("1")){
refundableStatusProduct = true; refundableStatusProduct = true;
} }
refundableStatusArr[i] = refundableStatusProduct; refundableStatusArr[i] = refundableStatusProduct;
@@ -147,7 +148,7 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
b.setExpressList(expressOrders); b.setExpressList(expressOrders);
} }
} }
b.setRefundableStatus(b.getOrderStatus().equals("6")?false:refundableStatus); b.setRefundableStatus(b.getOrderStatus().equals("6") || b.getOrderStatus().equals("7")?false:refundableStatus);
} }
} }
return page; return page;
@@ -256,7 +257,24 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
@Override @Override
public List<Map<String, Object>> exportPhysicalBuyOrderInfo(String date,String orderType) { public List<Map<String, Object>> exportPhysicalBuyOrderInfo(String date,String orderType) {
return this.baseMapper.exportPhysicalBuyOrderInfo(date, orderType); List<Map<String, Object>> list = this.baseMapper.exportPhysicalBuyOrderInfo(date, orderType);
List<Map<String, Object>> newList = new ArrayList<>();
for (Map<String, Object> map:list){
if(map.get("orderStatus").toString().equals("已退款")){
Map<String, Object> newMap = new HashMap<>(map);
map.put("orderStatus","已付款");
newList.add(map);
newMap.put("orderPrice","-"+map.get("orderPrice").toString());
newMap.put("price","-"+map.get("price").toString());
newList.add(newMap);
}else{
newList.add(map);
}
}
return newList;
} }
@Override @Override

View File

@@ -50,6 +50,7 @@ public class AliPayController {
*/ */
@RequestMapping("/refund") @RequestMapping("/refund")
public R refund(@RequestBody Map<String,Object> params) { public R refund(@RequestBody Map<String,Object> params) {
log.info("in=====refund=========");
String refund = aliPayService.refund(params); String refund = aliPayService.refund(params);
return R.ok().put("msg",refund); return R.ok().put("msg",refund);
} }

View File

@@ -2,8 +2,13 @@ package com.peanut.modules.pay.alipay.service;
import com.peanut.modules.common.entity.BuyOrder;
import com.peanut.modules.common.entity.BuyOrderRefund;
import com.peanut.modules.common.entity.MyUserEntity;
import com.peanut.modules.pay.alipay.dto.AlipayDTO; import com.peanut.modules.pay.alipay.dto.AlipayDTO;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import org.springframework.transaction.annotation.Transactional;
import java.util.Map; import java.util.Map;
@@ -30,4 +35,5 @@ public interface AliPayService {
String refund(Map<String,Object> params); String refund(Map<String,Object> params);
String refund(BuyOrder buyOrder, MyUserEntity user, BuyOrderRefund buyOrderRefund);
} }

View File

@@ -7,8 +7,9 @@ import com.alipay.api.internal.util.AlipaySignature;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.google.gson.JsonObject;
import com.peanut.common.utils.CopyUtils; import com.peanut.common.utils.CopyUtils;
import com.peanut.common.utils.OrderUtils; import com.peanut.config.Constants;
import com.peanut.modules.book.service.BookBuyConfigService; import com.peanut.modules.book.service.BookBuyConfigService;
import com.peanut.modules.book.service.BuyOrderService; import com.peanut.modules.book.service.BuyOrderService;
import com.peanut.modules.book.service.MyUserService; import com.peanut.modules.book.service.MyUserService;
@@ -25,6 +26,7 @@ import com.peanut.modules.pay.alipay.dto.ReFundDTO;
import com.peanut.modules.pay.alipay.service.AliPayService; import com.peanut.modules.pay.alipay.service.AliPayService;
import com.peanut.modules.pay.refund.entity.PayRefundOrder; import com.peanut.modules.pay.refund.entity.PayRefundOrder;
import com.peanut.modules.pay.refund.service.PayRefundOrderService; import com.peanut.modules.pay.refund.service.PayRefundOrderService;
import com.qiniu.util.Json;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -33,6 +35,7 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -81,6 +84,10 @@ public class AliPayServiceImpl implements AliPayService {
private TrainingClassService trainingClassService; private TrainingClassService trainingClassService;
@Autowired @Autowired
private AiVipLogService aiVipLogService; private AiVipLogService aiVipLogService;
@Autowired
private BuyOrderRefundService buyOrderRefundService;
@Autowired
private BuyOrderRefundLogService buyOrderRefundLogService;
@Override @Override
public String pay(AlipayDTO payDto) { public String pay(AlipayDTO payDto) {
@@ -143,6 +150,7 @@ public class AliPayServiceImpl implements AliPayService {
} }
log.info(">>>>>>>>>>支付宝回调 sign = {}, trade_status = {}, out_trade_no = {}, 参数 = {}", params.get("sign"), log.info(">>>>>>>>>>支付宝回调 sign = {}, trade_status = {}, out_trade_no = {}, 参数 = {}", params.get("sign"),
params.get("trade_status"), params.get("out_trade_no"), params.toString()); params.get("trade_status"), params.get("out_trade_no"), params.toString());
log.info(params.get("out_trade_no"), params.toString());
//调用SDK验证签名验证是阿里回调而不是其他恶意回调 //调用SDK验证签名验证是阿里回调而不是其他恶意回调
BuyOrder buyOrder = buyOrderService.getOne(new LambdaQueryWrapper<BuyOrder>() BuyOrder buyOrder = buyOrderService.getOne(new LambdaQueryWrapper<BuyOrder>()
.eq(BuyOrder::getOrderSn,params.get("out_trade_no"))); .eq(BuyOrder::getOrderSn,params.get("out_trade_no")));
@@ -156,6 +164,31 @@ public class AliPayServiceImpl implements AliPayService {
log.info(">>>>>>>>>>验签通过"); log.info(">>>>>>>>>>验签通过");
//验签通过 获取交易状态 //验签通过 获取交易状态
String tradeStatus = params.get("trade_status"); String tradeStatus = params.get("trade_status");
if(params.containsKey("out_biz_no") && params.containsKey("gmt_refund") && params.containsKey("refund_fee")){
PayRefundOrder refund = new PayRefundOrder();
refund.setPayType("2");
refund.setRefundId(params.get("out_biz_no").toString());
refund.setTradeNo(params.get("trade_no").toString());
refund.setOrderSn(params.get("out_trade_no").toString());
refund.setRefundFee(params.get("refund_fee").toString());
refundOrderService.save(refund);
String toJSON = JSONObject.toJSONString(params);
PayZfbOrderEntity aliNotifyDto = JSONObject.toJavaObject(JSON.parseObject(toJSON), PayZfbOrderEntity.class);
PayZfbOrderEntity payZfbOrderEntity = payZfbOrderService.getOne(new QueryWrapper<PayZfbOrderEntity>().eq("trade_no", aliNotifyDto.getTradeNo()));
payZfbOrderEntity.setOutBizNo(refund.getRefundId());
payZfbOrderEntity.setTradeStatus(tradeStatus);
payZfbOrderEntity.setRefundFee(refund.getRefundFee());
String PATTERN = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(PATTERN);
payZfbOrderEntity.setGmtCreate(sdf.parse(params.get("gmt_create").toString()));
payZfbOrderEntity.setGmtRefund(sdf.parse(params.get("gmt_refund").toString()));
payZfbOrderEntity.setGmtClose(sdf.parse(params.get("gmt_close").toString()));
payZfbOrderService.updateById(payZfbOrderEntity);
return "success";
}
//只处理支付成功的订单: 修改交易表状态,支付成功 //只处理支付成功的订单: 修改交易表状态,支付成功
//只有交易通知状态为TRADE_SUCCESS或TRADE_FINISHED时支付宝才会认定为买家付款成功。 //只有交易通知状态为TRADE_SUCCESS或TRADE_FINISHED时支付宝才会认定为买家付款成功。
if (tradeStatus.equals("TRADE_SUCCESS") || tradeStatus.equals("TRADE_FINISHED")) { if (tradeStatus.equals("TRADE_SUCCESS") || tradeStatus.equals("TRADE_FINISHED")) {
@@ -323,7 +356,6 @@ public class AliPayServiceImpl implements AliPayService {
return "fail"; return "fail";
} }
} }
@Override @Override
@Transactional @Transactional
public String refund(Map<String,Object> params) { public String refund(Map<String,Object> params) {
@@ -331,6 +363,7 @@ public class AliPayServiceImpl implements AliPayService {
LambdaQueryWrapper<PayZfbOrderEntity> wrapper = new LambdaQueryWrapper(); LambdaQueryWrapper<PayZfbOrderEntity> wrapper = new LambdaQueryWrapper();
wrapper.eq(PayZfbOrderEntity::getRelevanceoid,params.get("orderSn").toString()); wrapper.eq(PayZfbOrderEntity::getRelevanceoid,params.get("orderSn").toString());
PayZfbOrderEntity payZfbOrder = payZfbOrderService.getOne(wrapper); PayZfbOrderEntity payZfbOrder = payZfbOrderService.getOne(wrapper);
ReFundDTO reFundDTO = new ReFundDTO(); ReFundDTO reFundDTO = new ReFundDTO();
reFundDTO.setOutTrandeNo(payZfbOrder.getOutTradeNo()); reFundDTO.setOutTrandeNo(payZfbOrder.getOutTradeNo());
reFundDTO.setTradeNo(payZfbOrder.getTradeNo()); reFundDTO.setTradeNo(payZfbOrder.getTradeNo());
@@ -339,6 +372,7 @@ public class AliPayServiceImpl implements AliPayService {
reFundDTO.setRefundAmount(new BigDecimal(params.get("refundFee").toString())); reFundDTO.setRefundAmount(new BigDecimal(params.get("refundFee").toString()));
// reFundDTO.setOutRequestNo(params.get("outRequestNo").toString()); // reFundDTO.setOutRequestNo(params.get("outRequestNo").toString());
reFundDTO.setOutRequestNo(UUID.randomUUID().toString()); reFundDTO.setOutRequestNo(UUID.randomUUID().toString());
BuyOrder buyOrder = buyOrderService.getOne(new LambdaQueryWrapper<BuyOrder>() BuyOrder buyOrder = buyOrderService.getOne(new LambdaQueryWrapper<BuyOrder>()
.eq(BuyOrder::getOrderSn,params.get("orderSn"))); .eq(BuyOrder::getOrderSn,params.get("orderSn")));
String mchName = ""; String mchName = "";
@@ -359,6 +393,7 @@ public class AliPayServiceImpl implements AliPayService {
MPJLambdaWrapper<BuyOrder> w = new MPJLambdaWrapper(); MPJLambdaWrapper<BuyOrder> w = new MPJLambdaWrapper();
w.leftJoin(PayZfbOrderEntity.class,PayZfbOrderEntity::getRelevanceoid, BuyOrder::getOrderSn); w.leftJoin(PayZfbOrderEntity.class,PayZfbOrderEntity::getRelevanceoid, BuyOrder::getOrderSn);
w.eq("trade_no",((Map)res.get("alipay_trade_refund_response")).get("trade_no")); w.eq("trade_no",((Map)res.get("alipay_trade_refund_response")).get("trade_no"));
BuyOrder order = buyOrderService.getOne(w); BuyOrder order = buyOrderService.getOne(w);
PayRefundOrder refund = new PayRefundOrder(); PayRefundOrder refund = new PayRefundOrder();
refund.setPayType("2"); refund.setPayType("2");
@@ -367,11 +402,81 @@ public class AliPayServiceImpl implements AliPayService {
refund.setOutTradeNo(((Map)res.get("alipay_trade_refund_response")).get("out_trade_no").toString()); refund.setOutTradeNo(((Map)res.get("alipay_trade_refund_response")).get("out_trade_no").toString());
refund.setRefundFee(((Map)res.get("alipay_trade_refund_response")).get("refund_fee").toString()); refund.setRefundFee(((Map)res.get("alipay_trade_refund_response")).get("refund_fee").toString());
refundOrderService.save(refund); refundOrderService.save(refund);
if (Constants.ORDER_STATUS_REFUND.equals(order.getOrderStatus())) {
BuyOrderRefund buyOrderRefund = buyOrderRefundService.getOne(new LambdaQueryWrapper<BuyOrderRefund>()
.eq(BuyOrderRefund::getOrderId, order.getOrderId())
.orderByDesc(BuyOrderRefund::getId)
.last("limit 1"));
if (buyOrderRefund != null) {
buyOrderRefundLogService.insertRefundLog(buyOrderRefund.getId(),3,1);
}
} else {
refundOrderService.businessOpt(order); refundOrderService.businessOpt(order);
} }
}
return resJson; return resJson;
} }
@Override
@Transactional
public String refund(BuyOrder buyOrder, MyUserEntity user, BuyOrderRefund buyOrderRefund){
LambdaQueryWrapper<PayZfbOrderEntity> wrapper = new LambdaQueryWrapper();
wrapper.eq(PayZfbOrderEntity::getRelevanceoid,buyOrder.getOrderSn());
PayZfbOrderEntity payZfbOrder = payZfbOrderService.getOne(wrapper);
//组装退款参数
ReFundDTO reFundDTO = new ReFundDTO();
reFundDTO.setOutTrandeNo(buyOrder.getOrderSn());
reFundDTO.setTradeNo(payZfbOrder.getTradeNo());
reFundDTO.setCustomerId(user.getId().toString());
reFundDTO.setRefundReason("用户申请退款");
reFundDTO.setRefundAmount(buyOrderRefund.getFee());
reFundDTO.setOutRequestNo(buyOrderRefund.getRefundNo());
String mchName = "";
if (("trainingClass".equals(buyOrder.getOrderType())||"lsorder".equals(buyOrder.getOrderType()))) {
mchName = "LS";
}
reFundDTO.setMchName(mchName);
log.info("========refundDto", JSON.toJSONString(reFundDTO));
//请求支付宝退款
Map<String, Object> map = aliPayUtil.aliPayRefund(reFundDTO);
buyOrderRefundLogService.insertRefundLog(buyOrderRefund.getId(),2,2);
Object obj = map.get("msg");
String resJson = obj.toString();
log.info(">>>>>>>>>>>支付宝返回的信息是 resJson = {}", resJson);
Map<String,Object> res = JSONObject.parseObject(resJson);
//10000表示接口请求成功Y表示资金变动成功
if ("10000".equals(((Map)res.get("alipay_trade_refund_response")).get("code"))&&
"Y".equals(((Map)res.get("alipay_trade_refund_response")).get("fund_change"))) {
log.info(">>>>>>>>>>>支付宝退款成功!<<<<<<<<<<<<<");
/* PayRefundOrder refund = new PayRefundOrder();
refund.setPayType("2");
// refund.setRefundId(((Map)res.get("alipay_trade_refund_response")).get("out_request_no").toString());
refund.setTradeNo(((Map)res.get("alipay_trade_refund_response")).get("trade_no").toString());
refund.setOrderSn(((Map)res.get("alipay_trade_refund_response")).get("out_trade_no").toString());
refund.setRefundFee(((Map)res.get("alipay_trade_refund_response")).get("refund_fee").toString());
refundOrderService.save(refund);*/
BuyOrderRefund refundInfo = buyOrderRefundService.getOne(new QueryWrapper<BuyOrderRefund>().eq("order_id",buyOrder.getOrderId()));
refundInfo.setStatus(1);
refundInfo.setWxRefundNo(refundInfo.getRefundNo());
buyOrderRefundService.updateById(refundInfo);
buyOrderService.refundOrder(buyOrder,user,refundInfo.getId());
buyOrderRefundLogService.insertRefundLog(refundInfo.getId(),2,1);
buyOrderService.updateOrderStatus(buyOrder.getUserId(),buyOrder.getOrderSn(),"6");
}
return resJson;
}
private void userCoinJf(BuyOrder order){ private void userCoinJf(BuyOrder order){
MyUserEntity userEntity = userService.getById(order.getUserId()); MyUserEntity userEntity = userService.getById(order.getUserId());
userEntity.setJf(userEntity.getJf().subtract(order.getJfDeduction())); userEntity.setJf(userEntity.getJf().subtract(order.getJfDeduction()));

View File

@@ -19,7 +19,9 @@ public class PayRefundOrder implements Serializable {
@TableId @TableId
private Integer refundId; private Integer id;
private String refundId;
/** /**
* 支付方式 1微信2支付宝3虚拟币 * 支付方式 1微信2支付宝3虚拟币
@@ -29,8 +31,9 @@ public class PayRefundOrder implements Serializable {
/** /**
* BuyOrder * BuyOrder
*/ */
private Integer orderId; private String orderSn;
private Integer orderId;
/** /**
* 微信支付宝订单号 * 微信支付宝订单号
*/ */

View File

@@ -126,6 +126,7 @@ public class WeChatPayController {
*/ */
@RequestMapping("/refund" ) @RequestMapping("/refund" )
public R refund(@RequestBody Map<String,Object> map){ public R refund(@RequestBody Map<String,Object> map){
return R.ok(wxpayService.refund(map)); return R.ok(wxpayService.refund(map));
} }
@@ -135,10 +136,13 @@ public class WeChatPayController {
*/ */
@PostMapping("/refundNotify") @PostMapping("/refundNotify")
public void refundNotify(HttpServletRequest request){ public void refundNotify(HttpServletRequest request){
wxpayService.refundNotify(request); wxpayService.refundNotify(request);
} }
@PostMapping("/lsRefundNotify") @PostMapping("/lsRefundNotify")
public void lsRefundNotify(HttpServletRequest request){ public void lsRefundNotify(HttpServletRequest request){
wxpayService.lsRefundNotify(request); wxpayService.lsRefundNotify(request);
} }

View File

@@ -0,0 +1,21 @@
package com.peanut.modules.pay.weChatPay.dto;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
@Data
public class WeChatRefundInfo implements Serializable {
private String orderSn;
private Integer orderId;
private String orderType;
private String refundNo;
private BigDecimal totalAmount;
private BigDecimal refundAmount;
private String remark;
private String appName;
private String currency;
private String notify_url;
private int refundId;
}

View File

@@ -2,6 +2,7 @@ package com.peanut.modules.pay.weChatPay.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.modules.common.entity.PayWechatOrderEntity; import com.peanut.modules.common.entity.PayWechatOrderEntity;
import com.peanut.modules.pay.weChatPay.dto.WeChatRefundInfo;
import com.peanut.modules.pay.weChatPay.dto.WechatPaymentInfo; import com.peanut.modules.pay.weChatPay.dto.WechatPaymentInfo;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -19,6 +20,8 @@ public interface WxpayService extends IService<PayWechatOrderEntity> {
String refund(Map<String,Object> map); String refund(Map<String,Object> map);
void refund(WeChatRefundInfo refundInfo);
void refundNotify(HttpServletRequest request); void refundNotify(HttpServletRequest request);
void lsRefundNotify(HttpServletRequest request); void lsRefundNotify(HttpServletRequest request);

View File

@@ -20,11 +20,13 @@ import com.peanut.modules.master.service.UserCourseBuyService;
import com.peanut.modules.pay.refund.entity.PayRefundOrder; import com.peanut.modules.pay.refund.entity.PayRefundOrder;
import com.peanut.modules.pay.refund.service.PayRefundOrderService; import com.peanut.modules.pay.refund.service.PayRefundOrderService;
import com.peanut.modules.pay.weChatPay.config.WechatPayConfig; import com.peanut.modules.pay.weChatPay.config.WechatPayConfig;
import com.peanut.modules.pay.weChatPay.dto.WeChatRefundInfo;
import com.peanut.modules.pay.weChatPay.dto.WechatPaymentInfo; import com.peanut.modules.pay.weChatPay.dto.WechatPaymentInfo;
import com.peanut.modules.pay.weChatPay.service.WxpayService; import com.peanut.modules.pay.weChatPay.service.WxpayService;
import com.peanut.modules.pay.weChatPay.util.HttpUtils; import com.peanut.modules.pay.weChatPay.util.HttpUtils;
import com.peanut.modules.pay.weChatPay.util.WechatPayValidator; import com.peanut.modules.pay.weChatPay.util.WechatPayValidator;
import com.peanut.modules.pay.weChatPay.util.WxPayUtil; import com.peanut.modules.pay.weChatPay.util.WxPayUtil;
import com.qiniu.util.Json;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -89,6 +91,12 @@ public class WxpayServiceImpl extends ServiceImpl<PayWechatOrderDao, PayWechatOr
private AiVipLogService aiVipLogService; private AiVipLogService aiVipLogService;
@Autowired @Autowired
private UserCourseBuyLogDao userCourseBuyLogDao; private UserCourseBuyLogDao userCourseBuyLogDao;
@Autowired
private BuyOrderRefundLogService buyOrderRefundLogService;
@Autowired
private MyUserService myUserService;
@Autowired
private BuyOrderRefundService buyOrderRefundService;
@Override @Override
public void prepay(WechatPaymentInfo paymentInfo){ public void prepay(WechatPaymentInfo paymentInfo){
@@ -136,6 +144,7 @@ public class WxpayServiceImpl extends ServiceImpl<PayWechatOrderDao, PayWechatOr
}else { }else {
responseJson = wxPayUtil.doPostWexinV3(wechatPayConfig.getPayUrl(), json.toJSONString(),""); responseJson = wxPayUtil.doPostWexinV3(wechatPayConfig.getPayUrl(), json.toJSONString(),"");
} }
System.out.println(responseJson);
String prepayId = responseJson.getString("prepay_id"); String prepayId = responseJson.getString("prepay_id");
if (paymentInfo.getBuyOrderId() == null) { if (paymentInfo.getBuyOrderId() == null) {
payWechatOrderService.add(paymentInfo.getOrderSn(), prepayId); payWechatOrderService.add(paymentInfo.getOrderSn(), prepayId);
@@ -350,6 +359,68 @@ public class WxpayServiceImpl extends ServiceImpl<PayWechatOrderDao, PayWechatOr
return responseJson.toJSONString(); return responseJson.toJSONString();
} }
@Override
public void refund(WeChatRefundInfo refundInfo) {
Map<String, Object> paramMap = new HashMap<>();
BigDecimal refund = new BigDecimal(refundInfo.getRefundAmount().toString());
//原订单总金额
BigDecimal total = refundInfo.getTotalAmount();
// 这里 * 100微信支付单位为 ‘分’
BigDecimal hand = new BigDecimal("100");
Map<String, Object> amountMap = new HashMap<>();
amountMap.put("refund", refund.multiply(hand).intValue());
amountMap.put("total", total.multiply(hand).intValue());
amountMap.put("currency", "CNY");
paramMap.put("amount", amountMap);
paramMap.put("out_refund_no", refundInfo.getRefundNo());
//微信支付订单号
paramMap.put("out_trade_no", refundInfo.getOrderSn());
//退款原因
paramMap.put("reason", refundInfo.getRemark());
String appid = "";
if (refundInfo.getAppName()==null||"".equals(refundInfo.getAppName())){
appid = wechatPayConfig.getAppId();
}else if ("zmzm".equals(refundInfo.getAppName())){
appid = wechatPayConfig.getZmzmappId();
} else if ("wumen".equals(refundInfo.getAppName())) {
appid = wechatPayConfig.getWumenappId();
} else if ("xlkj".equals(refundInfo.getAppName())) {
appid = wechatPayConfig.getXlkjappId();
} else if ("thyy".equals(refundInfo.getAppName())) {
appid = wechatPayConfig.getThyyappId();
}
// app id
// paramMap.put("appid", appid);
String notify_url = wechatPayConfig.getRefundNotifyUrl();
String mchName = "";
String mchid = wechatPayConfig.getMchId();
if ("trainingClass".equals(refundInfo.getOrderType())||"lsorder".equals(refundInfo.getOrderType())) {
mchName = "LS";
mchid = wechatPayConfig.getLsMchId();
notify_url = wechatPayConfig.getLsRefundNotifyUrl();
}
// paramMap.put("mchid", mchid);
paramMap.put("notify_url", notify_url);
JSONObject json = JSONObject.parseObject(JSON.toJSONString(paramMap));
log.info("=======微信退款申请请求参数:{}", json.toJSONString());
log.info(">>>>>>>>>>App请求微信退款申请接口");
JSONObject responseJson = wxPayUtil.doPostWexinV3(wechatPayConfig.getRefundUrl(), json.toJSONString(),mchName);
System.out.println(responseJson);
log.info(">>>>>>>>>>>微信退款返回的信息是 resJson = {}", responseJson.toJSONString());
buyOrderRefundLogService.insertRefundLog(refundInfo.getRefundId(),1,2);
if ("PROCESSING".equals(responseJson.get("status"))){
BuyOrderRefund buyOrderRefund = buyOrderRefundService.getById(refundInfo.getRefundId());
buyOrderRefund.setWxRefundNo(responseJson.getString("refund_id"));
buyOrderRefundService.updateById(buyOrderRefund);
}
}
private void userCoinJf(BuyOrder order){ private void userCoinJf(BuyOrder order){
MyUserEntity userEntity = userService.getById(order.getUserId()); MyUserEntity userEntity = userService.getById(order.getUserId());
userEntity.setJf(userEntity.getJf().subtract(order.getJfDeduction())); userEntity.setJf(userEntity.getJf().subtract(order.getJfDeduction()));
@@ -373,6 +444,18 @@ public class WxpayServiceImpl extends ServiceImpl<PayWechatOrderDao, PayWechatOr
// 解密resource中的通知数据 // 解密resource中的通知数据
String resource = bodyMap.get("resource").toString(); String resource = bodyMap.get("resource").toString();
Map<String, Object> resourceMap = WechatPayValidator.decryptFromResource(resource, wechatPayConfig.getApiV3Key(), 2); Map<String, Object> resourceMap = WechatPayValidator.decryptFromResource(resource, wechatPayConfig.getApiV3Key(), 2);
/*BuyOrder orderFalse = buyOrderService.getOne(new QueryWrapper<BuyOrder>().eq("user_id",149299).orderByDesc("order_id"));
BuyOrderRefund refundFalse = buyOrderRefundService.getOne(new QueryWrapper<BuyOrderRefund>().eq("user_id",149299).orderByDesc("id"));
Map<String, Object> resourceMap = new HashMap<>();
resourceMap.put("refund_status","SUCCESS");
resourceMap.put("out_trade_no",orderFalse.getOrderSn());
resourceMap.put("refund_id",System.currentTimeMillis());
resourceMap.put("out_refund_no",refundFalse.getRefundNo());
Map<String,BigDecimal> amount = new HashMap<>();
amount.put("refund",orderFalse.getRealMoney());
resourceMap.put("amount",amount);*/
log.info("微信退款回调结果 msg={}",resourceMap); log.info("微信退款回调结果 msg={}",resourceMap);
if ("SUCCESS".equals(resourceMap.get("refund_status").toString())){ if ("SUCCESS".equals(resourceMap.get("refund_status").toString())){
log.info(">>>>>>>>>>>微信退款成功!<<<<<<<<<<<<<"); log.info(">>>>>>>>>>>微信退款成功!<<<<<<<<<<<<<");
@@ -381,14 +464,41 @@ public class WxpayServiceImpl extends ServiceImpl<PayWechatOrderDao, PayWechatOr
w.leftJoin(PayWechatOrderEntity.class,PayWechatOrderEntity::getOrderSn, BuyOrder::getOrderSn); w.leftJoin(PayWechatOrderEntity.class,PayWechatOrderEntity::getOrderSn, BuyOrder::getOrderSn);
w.eq("t1.order_id",resourceMap.get("transaction_id").toString()); w.eq("t1.order_id",resourceMap.get("transaction_id").toString());
BuyOrder order = buyOrderService.getOne(w); BuyOrder order = buyOrderService.getOne(w);
PayRefundOrder refund = new PayRefundOrder(); PayRefundOrder refund = new PayRefundOrder();
refund.setPayType("1"); refund.setPayType("1");
refund.setOrderId(order.getOrderId()); refund.setRefundId(resourceMap.get("refund_id").toString());
refund.setTradeNo(resourceMap.get("transaction_id").toString()); refund.setTradeNo(resourceMap.get("transaction_id").toString());
refund.setOutTradeNo(resourceMap.get("out_trade_no").toString()); refund.setOrderSn(resourceMap.get("out_trade_no").toString());
String refundFeeStr = ((Map)resourceMap.get("amount")).get("refund").toString();
BigDecimal refundFee = new BigDecimal(refundFeeStr).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP);
refund.setRefundFee(((Map)resourceMap.get("amount")).get("refund").toString()); refund.setRefundFee(((Map)resourceMap.get("amount")).get("refund").toString());
refundOrderService.save(refund); refundOrderService.save(refund);
refundOrderService.businessOpt(order);
MyUserEntity user = myUserService.getById(order.getUserId());
BuyOrderRefund refundInfo = buyOrderRefundService.getOne(new QueryWrapper<BuyOrderRefund>().eq("order_id",order.getOrderId()));
refundInfo.setStatus(1);
refundInfo.setWxRefundNo( resourceMap.get("refund_id").toString());
buyOrderRefundService.updateById(refundInfo);
buyOrderService.refundOrder(order,user,refundInfo.getId());
buyOrderRefundLogService.insertRefundLog(refundInfo.getId(),1,1);
buyOrderService.updateOrderStatus(order.getUserId(),order.getOrderSn(),"6");
// refundOrderService.businessOpt(order);
}else{
if(resourceMap.containsKey("out_refund_no")){
String refundNo = resourceMap.get("out_refund_no").toString();
BuyOrderRefund refundInfo = buyOrderRefundService.getOne(new QueryWrapper<BuyOrderRefund>().eq("refund_no",refundNo));
refundInfo.setStatus(2);
refundInfo.setWxRefundNo( resourceMap.get("refund_id").toString());
buyOrderRefundService.updateById(refundInfo);
// buyOrderRefundLogService.insertRefundLog(refundInfo.getId(),1,3,resourceMap.get("reason").toString());
}
} }
} }
@Override @Override
@@ -408,14 +518,40 @@ public class WxpayServiceImpl extends ServiceImpl<PayWechatOrderDao, PayWechatOr
w.leftJoin(PayWechatOrderEntity.class,PayWechatOrderEntity::getOrderSn, BuyOrder::getOrderSn); w.leftJoin(PayWechatOrderEntity.class,PayWechatOrderEntity::getOrderSn, BuyOrder::getOrderSn);
w.eq("t1.order_id",resourceMap.get("transaction_id").toString()); w.eq("t1.order_id",resourceMap.get("transaction_id").toString());
BuyOrder order = buyOrderService.getOne(w); BuyOrder order = buyOrderService.getOne(w);
PayRefundOrder refund = new PayRefundOrder(); PayRefundOrder refund = new PayRefundOrder();
refund.setPayType("1"); refund.setPayType("1");
refund.setOrderId(order.getOrderId()); refund.setRefundId(resourceMap.get("refund_id").toString());
refund.setTradeNo(resourceMap.get("transaction_id").toString()); refund.setTradeNo(resourceMap.get("transaction_id").toString());
refund.setOutTradeNo(resourceMap.get("out_trade_no").toString()); refund.setOrderSn(resourceMap.get("out_trade_no").toString());
refund.setRefundFee(((Map)resourceMap.get("amount")).get("refund").toString()); refund.setRefundFee(((Map)resourceMap.get("amount")).get("refund").toString());
refundOrderService.save(refund); refundOrderService.save(refund);
refundOrderService.businessOpt(order);
//refundOrderService.businessOpt(order);
MyUserEntity user = myUserService.getById(order.getUserId());
BuyOrderRefund refundInfo = buyOrderRefundService.getOne(new QueryWrapper<BuyOrderRefund>().eq("order_id",order.getOrderId()));
refundInfo.setStatus(1);
refundInfo.setWxRefundNo( resourceMap.get("refund_id").toString());
buyOrderRefundService.updateById(refundInfo);
buyOrderService.refundOrder(order,user,refundInfo.getId());
buyOrderRefundLogService.insertRefundLog(refundInfo.getId(),1,1);
buyOrderService.updateOrderStatus(order.getUserId(),order.getOrderSn(),"6");
}else{
if(resourceMap.containsKey("out_refund_no")){
String refundNo = resourceMap.get("out_refund_no").toString();
BuyOrderRefund refundInfo = buyOrderRefundService.getOne(new QueryWrapper<BuyOrderRefund>().eq("refund_no",refundNo));
refundInfo.setStatus(2);
refundInfo.setWxRefundNo( resourceMap.get("refund_id").toString());
buyOrderRefundService.updateById(refundInfo);
// buyOrderRefundLogService.insertRefundLog(refundInfo.getId(),1,3,resourceMap.get("reason").toString());
}
} }
} }

View File

@@ -11,7 +11,7 @@ connection-timeout: 6000000ms
spring: spring:
# 环境 /dev1|test|prod # 环境 /dev1|test|prod
profiles: profiles:
active: dev1 active: prod
# jackson时间格式化 # jackson时间格式化
jackson: jackson:
time-zone: GMT+8 time-zone: GMT+8

View File

@@ -210,8 +210,9 @@
<!-- &lt;!&ndash; 4.2 生产环境:输出到文档&ndash;&gt;--> <!-- &lt;!&ndash; 4.2 生产环境:输出到文档&ndash;&gt;-->
<springProfile name="test,prod"> <springProfile name="test,prod">
<logger name="com.peanut" level="ERROR" additivity="false"> <logger name="com.peanut" level="INFO" additivity="false">
<!-- <appender-ref ref="DEBUG_FILE"/>--> <!-- <appender-ref ref="DEBUG_FILE"/>-->
<appender-ref ref="INFO_FILE"/>
<appender-ref ref="ERROR_FILE"/> <appender-ref ref="ERROR_FILE"/>
</logger> </logger>
<root level="info"> <root level="info">

View File

@@ -65,7 +65,8 @@
left join user u on u.id = bo.user_id left join user u on u.id = bo.user_id
left join buy_order_product bop on bop.order_id = bo.order_id left join buy_order_product bop on bop.order_id = bo.order_id
left join shop_product sp on sp.product_id = bop.product_id left join shop_product sp on sp.product_id = bop.product_id
where u.id not in (select id from user where tester_flag = 1) where
( u.id not in (select id from user where tester_flag = 1) or (u.id in (select id from user where tester_flag = 1) and (bo.payment_method='1' or bo.payment_method='2') and bo.create_time>='2026-05-06 00:00:00') )
and bo.order_status in (1,2,3,4) and sp.goods_type != '05' and bo.real_money > 0 and bo.order_status in (1,2,3,4) and sp.goods_type != '05' and bo.real_money > 0
<if test="orderType != null and orderType!= ''"> <if test="orderType != null and orderType!= ''">
<if test="orderType == 'lsorder' "> <if test="orderType == 'lsorder' ">
@@ -99,13 +100,14 @@
from ( from (
select bo.order_id,DATE_FORMAT(bo.create_time,'%Y-%m-%d %H:%i:%s') createTime,u.name,if(u.tel is null,if(u.email is null,'',u.email),u.tel) tel,bo.order_sn orderSn, select bo.order_id,DATE_FORMAT(bo.create_time,'%Y-%m-%d %H:%i:%s') createTime,u.name,if(u.tel is null,if(u.email is null,'',u.email),u.tel) tel,bo.order_sn orderSn,
IF(bo.payment_method=1,'微信',IF(bo.payment_method=2,'支付宝',IF(bo.payment_method=4,'天医币','0'))) payType, IF(bo.payment_method=1,'微信',IF(bo.payment_method=2,'支付宝',IF(bo.payment_method=4,'天医币','0'))) payType,
IF(bo.order_status = 4,'已删除',IF(bo.order_status = 3,'已完成',IF(bo.order_status = 2,'已发货','已付款'))) orderStatus,bo.real_money orderPrice,if(bo.remark like '%退%',bo.remark,'') remark IF(bo.order_status = 4,'已删除',IF(bo.order_status = 3,'已完成',IF(bo.order_status = 2,'已发货',IF(bo.order_status = 6,'已退款','已付款')))) orderStatus,bo.real_money orderPrice,if(bo.remark like '%退%',bo.remark,'') remark
from buy_order bo from buy_order bo
left join user u on u.id = bo.user_id left join user u on u.id = bo.user_id
left join buy_order_product bop on bop.order_id = bo.order_id left join buy_order_product bop on bop.order_id = bo.order_id
left join shop_product sp on sp.product_id = bop.product_id left join shop_product sp on sp.product_id = bop.product_id
where u.id not in (select id from user where tester_flag = 1) where
and bo.order_status in (1,2,3,4) and sp.goods_type != '05' and bo.real_money > 0 ( u.id not in (select id from user where tester_flag = 1) or (u.id in (select id from user where tester_flag = 1) and (bo.payment_method='1' or bo.payment_method='2') and bo.create_time>='2026-05-06 00:00:00') )
and bo.order_status in (1,2,3,4,6) and sp.goods_type != '05' and bo.real_money > 0
<if test="orderType != null and orderType!= ''"> <if test="orderType != null and orderType!= ''">
<if test="orderType == 'lsorder' "> <if test="orderType == 'lsorder' ">
and (bo.payment_method = '1' or (bo.payment_method = '2' and bo.order_id >37867)) and (bo.payment_method = '1' or (bo.payment_method = '2' and bo.order_id >37867))