|
|
|
@ -12,6 +12,7 @@ import com.hfkj.entity.*; |
|
|
|
|
import com.hfkj.mer.BsMerPayConfigService; |
|
|
|
|
import com.hfkj.model.order.OrderChildModel; |
|
|
|
|
import com.hfkj.model.order.OrderModel; |
|
|
|
|
import com.hfkj.service.goods.BsOrderMeiTuanService; |
|
|
|
|
import com.hfkj.service.hlt.HltCardRefundService; |
|
|
|
|
import com.hfkj.service.hlt.HuiLianTongUnionCardService; |
|
|
|
|
import com.hfkj.service.order.BsOrderChildService; |
|
|
|
@ -35,6 +36,7 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.math.RoundingMode; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
@ -60,6 +62,8 @@ public class BsOrderRefundServiceImpl implements BsOrderRefundService { |
|
|
|
|
private HltCardRefundService hltCardRefundService; |
|
|
|
|
@Resource |
|
|
|
|
private OrderRefundSuccessService orderRefundSuccessService; |
|
|
|
|
@Resource |
|
|
|
|
private BsOrderMeiTuanService orderMeiTuanService; |
|
|
|
|
@Override |
|
|
|
|
public void editData(BsOrderRefund data) { |
|
|
|
|
data.setUpdateTime(new Date()); |
|
|
|
@ -248,16 +252,31 @@ public class BsOrderRefundServiceImpl implements BsOrderRefundService { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@Transactional(propagation= Propagation.REQUIRES_NEW,rollbackFor= {RuntimeException.class}) |
|
|
|
|
public BsOrderRefund meiTuanRefund(String childOrderNo, String tradeNo , BigDecimal refundPrice, String remark) { |
|
|
|
|
public BsOrderRefund meiTuanRefund(String tradeRefundNo, String tradeNo , BigDecimal refundPrice, String remark) { |
|
|
|
|
|
|
|
|
|
// 查询退款订
|
|
|
|
|
BsOrderRefund bsOrderRefund = getRefundByTradeRefundNo(tradeRefundNo); |
|
|
|
|
|
|
|
|
|
if (bsOrderRefund != null) { |
|
|
|
|
return bsOrderRefund; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 查询业务订单
|
|
|
|
|
BsOrderMeituan orderMeiTuan = orderMeiTuanService.findOrderMeiTuanByTradeNo(tradeNo); |
|
|
|
|
if (orderMeiTuan == null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的业务订单"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 查询子订单
|
|
|
|
|
OrderChildModel orderChild = orderChildService.getDetail(childOrderNo); |
|
|
|
|
OrderChildModel orderChild = orderChildService.getDetail(orderMeiTuan.getChildOrderNo()); |
|
|
|
|
if (orderChild == null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的子订单"); |
|
|
|
|
} |
|
|
|
|
// if (productCount > orderChild.getSurplusRefundCount()) {
|
|
|
|
|
// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "退款失败!退货数量超过子订单可退数量");
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
if (orderChild.getStatus() != OrderChildStatusEnum.status2.getCode()) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "当前状态不支持退款!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 查询交易订单
|
|
|
|
|
BsOrder order = orderService.getOrder(orderChild.getOrderNo()); |
|
|
|
|
if (order == null) { |
|
|
|
@ -276,20 +295,35 @@ public class BsOrderRefundServiceImpl implements BsOrderRefundService { |
|
|
|
|
orderRefund.setRefundPayChannel(order.getPayChannel()); |
|
|
|
|
orderRefund.setReufndPayType(order.getPayType()); |
|
|
|
|
|
|
|
|
|
// if (orderChild.getSurplusRefundCount().equals(productCount)) {
|
|
|
|
|
// // 全部退款
|
|
|
|
|
// orderRefund.setRefundPrice(orderChild.getSurplusRefundPrice());
|
|
|
|
|
// orderRefund.setRefundIntegral(orderChild.getSurplusRefundIntegral());
|
|
|
|
|
// } else {
|
|
|
|
|
// // 部分退款
|
|
|
|
|
// // 计算单价
|
|
|
|
|
// BigDecimal unitPrice = orderChild.getSurplusRefundPrice().divide(new BigDecimal(orderChild.getProductCount().toString()), 2, BigDecimal.ROUND_DOWN).setScale(2);
|
|
|
|
|
// BigDecimal unitPriceIntegral = new BigDecimal(orderChild.getSurplusRefundIntegral().toString()).divide(new BigDecimal("100"))
|
|
|
|
|
// .divide(new BigDecimal(orderChild.getProductCount().toString()), 2, BigDecimal.ROUND_DOWN).setScale(2);
|
|
|
|
|
//
|
|
|
|
|
// orderRefund.setRefundPrice(unitPrice.multiply(new BigDecimal(productCount.toString())));
|
|
|
|
|
// orderRefund.setRefundIntegral(unitPriceIntegral.multiply(new BigDecimal("100")).longValue());
|
|
|
|
|
// }
|
|
|
|
|
// 是否全额退款
|
|
|
|
|
if (orderMeiTuan.getTradeAmount().equals(refundPrice)) { |
|
|
|
|
// 全部退款
|
|
|
|
|
orderRefund.setRefundPrice(orderChild.getSurplusRefundPrice()); |
|
|
|
|
orderRefund.setRefundIntegral(orderChild.getSurplusRefundIntegral()); |
|
|
|
|
} else { |
|
|
|
|
// 部分退款
|
|
|
|
|
// 计算部分退款比例
|
|
|
|
|
BigDecimal proportion = orderChild.getProductTotalPrice().divide(refundPrice, 2, RoundingMode.DOWN); |
|
|
|
|
// 退积分
|
|
|
|
|
Long unitPriceIntegral = new BigDecimal(orderChild.getIntegralDiscountPrice()).multiply(proportion).longValue(); |
|
|
|
|
// 退金额
|
|
|
|
|
BigDecimal price = orderChild.getProductActualPrice().multiply(proportion); |
|
|
|
|
|
|
|
|
|
// 插入退款积分
|
|
|
|
|
if (unitPriceIntegral > orderChild.getSurplusRefundIntegral()) { |
|
|
|
|
orderRefund.setRefundIntegral(orderChild.getSurplusRefundIntegral()); |
|
|
|
|
} else { |
|
|
|
|
orderRefund.setRefundIntegral(unitPriceIntegral); |
|
|
|
|
} |
|
|
|
|
// 插入退款金额
|
|
|
|
|
if (price.compareTo(orderChild.getSurplusRefundPrice()) > 0) { |
|
|
|
|
orderRefund.setRefundPrice(orderChild.getSurplusRefundPrice()); |
|
|
|
|
} else { |
|
|
|
|
orderRefund.setRefundPrice(price); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (orderRefund.getRefundIntegral() > 0L) { |
|
|
|
@ -358,6 +392,17 @@ public class BsOrderRefundServiceImpl implements BsOrderRefundService { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public BsOrderRefund getRefundByTradeRefundNo(String tradeRefundNo) { |
|
|
|
|
BsOrderRefundExample example = new BsOrderRefundExample(); |
|
|
|
|
example.createCriteria().andTradeRefundNoEqualTo(tradeRefundNo); |
|
|
|
|
List<BsOrderRefund> list = orderRefundMapper.selectByExample(example); |
|
|
|
|
if (!list.isEmpty()){ |
|
|
|
|
return list.get(0); |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<BsOrderRefund> getRefundList(Map<String, Object> param) { |
|
|
|
|
BsOrderRefundExample example = new BsOrderRefundExample(); |
|
|
|
|