退单
This commit is contained in:
@@ -27,7 +27,7 @@ public class Constants {
|
||||
*/
|
||||
public static final String ORDER_STATUS_FAIL = "4";
|
||||
/**
|
||||
* 订单状态 - 交易失败
|
||||
* 订单状态 - 退款
|
||||
*/
|
||||
public static final String ORDER_STATUS_REFUND = "6";
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.peanut.common.utils.DateUtils;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.common.utils.R;
|
||||
@@ -33,6 +34,7 @@ import com.peanut.modules.common.dao.UserCourseBuyDao;
|
||||
import com.peanut.modules.common.entity.*;
|
||||
import com.peanut.modules.common.service.*;
|
||||
import com.peanut.modules.master.service.CourseCatalogueService;
|
||||
import com.peanut.modules.pay.alipay.service.AliPayService;
|
||||
import com.peanut.modules.pay.weChatPay.dto.WechatPaymentInfo;
|
||||
import com.peanut.modules.pay.weChatPay.service.WxpayService;
|
||||
import com.peanut.modules.sys.entity.SysConfigEntity;
|
||||
@@ -122,6 +124,8 @@ public class BuyOrderController {
|
||||
private BuyOrderRefundService buyOrderRefundService;
|
||||
@Autowired
|
||||
private BuyOrderRefundLogService buyOrderRefundLogService;
|
||||
@Autowired
|
||||
private AliPayService aliPayService;
|
||||
|
||||
@RequestMapping(value = "/decomposeShipment", method = RequestMethod.POST)
|
||||
public R decomposeShipment(@RequestBody BuyOrderListRequestVo requestVo) {
|
||||
@@ -661,12 +665,7 @@ public class BuyOrderController {
|
||||
|| Constants.ORDER_STATUS_OUT_OF_TIME.equals(buyOrder.getOrderStatus())) {
|
||||
return R.error("当前订单状态不支持退单");
|
||||
}
|
||||
// QueryWrapper<BuyOrderRefund> refundQueryWrapper = new QueryWrapper<>();
|
||||
// refundQueryWrapper.eq("order_id",buyOrder.getOrderId());
|
||||
// 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);
|
||||
|
||||
@@ -697,17 +696,45 @@ public class BuyOrderController {
|
||||
int refundId = buyOrderRefund.getId();
|
||||
|
||||
if (Constants.PAYMENT_METHOD_VIRTUAL.equals(buyOrder.getPaymentMethod())) {
|
||||
//BigDecimal refundPeanutCoin = buyOrder.getRealMoney() == null?BigDecimal.ZERO : buyOrder.getRealMoney();
|
||||
if(refundFee.compareTo(BigDecimal.ZERO)>0){
|
||||
transactionDetailsService.refundRecord(buyOrder,user,refundFee);
|
||||
user.setPeanutCoin(user.getPeanutCoin().add(refundFee));
|
||||
myUserService.updateById(user);
|
||||
buyOrderRefundLogService.insertRefundLog(refundId,1,1);
|
||||
buyOrderService.refundOrder(buyOrder,user,refundId);
|
||||
}
|
||||
} else if (Constants.PAYMENT_METHOD_WECHAT_PAY.equals(buyOrder.getPaymentMethod())) {
|
||||
if (refundFee.compareTo(BigDecimal.ZERO) > 0) {
|
||||
Map<String, Object> refundParams = new HashMap<>();
|
||||
refundParams.put("orderSn", buyOrder.getOrderSn());
|
||||
refundParams.put("refundFee", refundFee);
|
||||
refundParams.put("reason", StringUtils.isBlank(remark) ? "后台申请退款" : remark);
|
||||
String refundResult = wxpayService.refund(refundParams);
|
||||
JSONObject resultJson = JSONObject.parseObject(refundResult);
|
||||
if (!"SUCCESS".equals(resultJson.getString("status"))) {
|
||||
return R.error("微信退款申请失败");
|
||||
}
|
||||
buyOrderRefundLogService.insertRefundLog(refundId,4,0);
|
||||
}
|
||||
} else if (Constants.PAYMENT_METHOD_ALI_PAY.equals(buyOrder.getPaymentMethod())) {
|
||||
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("支付宝退款申请失败");
|
||||
}
|
||||
buyOrderRefundLogService.insertRefundLog(refundId,3,1);
|
||||
}
|
||||
}
|
||||
|
||||
buyOrderService.refundOrder(buyOrder,user,refundId);
|
||||
return R.ok("ok");
|
||||
|
||||
}
|
||||
@RequestMapping("/llll")
|
||||
public R ls(){
|
||||
|
||||
@@ -74,4 +74,6 @@ public interface BuyOrderService extends IService<BuyOrder> {
|
||||
BigDecimal getRefundFee(Map<String, Object> params, BuyOrder buyOrder);
|
||||
|
||||
void refundOrder(BuyOrder buyOrder, MyUserEntity user, int refundId);
|
||||
|
||||
void refundOrder(BuyOrder buyOrder);
|
||||
}
|
||||
@@ -17,7 +17,6 @@ import com.peanut.modules.book.service.CountyService;
|
||||
import com.peanut.modules.book.service.ExpressOrderService;
|
||||
import com.peanut.modules.book.service.MyUserService;
|
||||
import com.peanut.modules.book.service.ProvinceService;
|
||||
import com.peanut.modules.book.vo.UserVipYearVo;
|
||||
import com.peanut.modules.common.dao.*;
|
||||
import com.peanut.modules.book.service.*;
|
||||
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.vo.CourseCatalogueVo;
|
||||
import com.peanut.modules.oss.service.OssService;
|
||||
import com.qiniu.util.Json;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.time.DateUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -1094,5 +1091,38 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void refundOrder(BuyOrder buyOrder){
|
||||
if(buyOrder.getCouponId()!=null && buyOrder.getCouponId()!=0){
|
||||
couponService.rollbackCoupon(buyOrder.getCouponId());
|
||||
}
|
||||
QueryWrapper<BuyOrderProduct> productQueryWrapper = new QueryWrapper<>();
|
||||
productQueryWrapper.eq("order_id",buyOrder.getOrderId());
|
||||
List<BuyOrderProduct> orderProducts = buyOrderProductService.list(productQueryWrapper);
|
||||
|
||||
//积分恢复
|
||||
BigDecimal jf = buyOrder.getJfDeduction()==null?BigDecimal.ZERO : buyOrder.getJfDeduction();
|
||||
MyUserEntity user = myUserService.getById(buyOrder.getUserId());
|
||||
if(jf.compareTo(BigDecimal.ZERO)>0){
|
||||
jfTransactionDetailsService.refundJfTransaction(buyOrder,user);
|
||||
user.setJf(jf.add(user.getJf()));
|
||||
myUserService.updateById(user);
|
||||
buyOrderRefundLogService.insertRefundLog(refundId,2,1);
|
||||
}
|
||||
if(buyOrder.getOrderType().equals("vip")){
|
||||
userVipService.refundVip(buyOrder);
|
||||
}else{
|
||||
//撤回本订单购买赠送的优惠券
|
||||
couponService.refundZSCouponHistoryByOrder(buyOrder);
|
||||
/*//恢复用户权益(点穴/时辰取穴/五运六气/肿瘤古方)
|
||||
myUserService.rollbackUserPowers(buyOrder, orderProducts);*/
|
||||
//撤回电子书权限
|
||||
userEbookBuyService.rollbackUserEbooks(buyOrder, orderProducts);
|
||||
//撤回课程权限
|
||||
removeCourseToUser(buyOrder);
|
||||
//回滚库存
|
||||
shopProductService.rollbackStock(buyOrder);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ public class BuyOrderRefund implements Serializable {
|
||||
private int deductShipping;
|
||||
//商品名称
|
||||
private String title;
|
||||
private int status;
|
||||
private String remark;
|
||||
private Date createTime;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
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.BuyOrderService;
|
||||
import com.peanut.modules.book.service.MyUserService;
|
||||
@@ -81,6 +82,10 @@ public class AliPayServiceImpl implements AliPayService {
|
||||
private TrainingClassService trainingClassService;
|
||||
@Autowired
|
||||
private AiVipLogService aiVipLogService;
|
||||
@Autowired
|
||||
private BuyOrderRefundService buyOrderRefundService;
|
||||
@Autowired
|
||||
private BuyOrderRefundLogService buyOrderRefundLogService;
|
||||
|
||||
@Override
|
||||
public String pay(AlipayDTO payDto) {
|
||||
@@ -367,7 +372,17 @@ public class AliPayServiceImpl implements AliPayService {
|
||||
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());
|
||||
refundOrderService.save(refund);
|
||||
refundOrderService.businessOpt(order);
|
||||
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);
|
||||
}
|
||||
}
|
||||
return resJson;
|
||||
}
|
||||
|
||||
@@ -137,6 +137,7 @@ public class WeChatPayController {
|
||||
public void refundNotify(HttpServletRequest request){
|
||||
wxpayService.refundNotify(request);
|
||||
}
|
||||
|
||||
@PostMapping("/lsRefundNotify")
|
||||
public void lsRefundNotify(HttpServletRequest request){
|
||||
wxpayService.lsRefundNotify(request);
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.peanut.common.utils.ShiroUtils;
|
||||
import com.peanut.config.Constants;
|
||||
import com.peanut.modules.book.service.BookBuyConfigService;
|
||||
import com.peanut.modules.book.service.BuyOrderService;
|
||||
import com.peanut.modules.book.service.MyUserService;
|
||||
@@ -78,6 +79,10 @@ public class WxpayServiceImpl extends ServiceImpl<PayWechatOrderDao, PayWechatOr
|
||||
@Autowired
|
||||
private JfTransactionDetailsDao jfTransactionDetailsDao;
|
||||
@Autowired
|
||||
private BuyOrderRefundService buyOrderRefundService;
|
||||
@Autowired
|
||||
private BuyOrderRefundLogService buyOrderRefundLogService;
|
||||
@Autowired
|
||||
private UserVipService userVipService;
|
||||
@Autowired
|
||||
private CouponService couponService;
|
||||
@@ -380,15 +385,15 @@ public class WxpayServiceImpl extends ServiceImpl<PayWechatOrderDao, PayWechatOr
|
||||
w.selectAll(BuyOrder.class);
|
||||
w.leftJoin(PayWechatOrderEntity.class,PayWechatOrderEntity::getOrderSn, BuyOrder::getOrderSn);
|
||||
w.eq("t1.order_id",resourceMap.get("transaction_id").toString());
|
||||
|
||||
BuyOrder order = buyOrderService.getOne(w);
|
||||
PayRefundOrder refund = new PayRefundOrder();
|
||||
refund.setPayType("1");
|
||||
refund.setOrderId(order.getOrderId());
|
||||
refund.setTradeNo(resourceMap.get("transaction_id").toString());
|
||||
refund.setOutTradeNo(resourceMap.get("out_trade_no").toString());
|
||||
refund.setRefundFee(((Map)resourceMap.get("amount")).get("refund").toString());
|
||||
refundOrderService.save(refund);
|
||||
refundOrderService.businessOpt(order);
|
||||
BuyOrderRefund buyOrderRefund = buyOrderRefundService.getOne(new QueryWrapper<BuyOrderRefund>().eq("order_id",order.getOrderId()));
|
||||
buyOrderRefund.setStatus(1);
|
||||
buyOrderRefundService.updateById(buyOrderRefund);
|
||||
|
||||
buyOrderRefundLogService.insertRefundLog(buyOrderRefund.getId(),4,1);
|
||||
|
||||
buyOrderService.refundOrder();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
@@ -415,7 +420,17 @@ public class WxpayServiceImpl extends ServiceImpl<PayWechatOrderDao, PayWechatOr
|
||||
refund.setOutTradeNo(resourceMap.get("out_trade_no").toString());
|
||||
refund.setRefundFee(((Map)resourceMap.get("amount")).get("refund").toString());
|
||||
refundOrderService.save(refund);
|
||||
refundOrderService.businessOpt(order);
|
||||
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(),4,1);
|
||||
}
|
||||
} else {
|
||||
refundOrderService.businessOpt(order);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user