|
|
@ -12,6 +12,7 @@ import com.hfkj.entity.*; |
|
|
|
import com.hfkj.mer.BsMerPayConfigService; |
|
|
|
import com.hfkj.mer.BsMerPayConfigService; |
|
|
|
import com.hfkj.model.order.OrderChildModel; |
|
|
|
import com.hfkj.model.order.OrderChildModel; |
|
|
|
import com.hfkj.model.order.OrderModel; |
|
|
|
import com.hfkj.model.order.OrderModel; |
|
|
|
|
|
|
|
import com.hfkj.service.goods.BsOrderMeiTuanService; |
|
|
|
import com.hfkj.service.hlt.HltCardRefundService; |
|
|
|
import com.hfkj.service.hlt.HltCardRefundService; |
|
|
|
import com.hfkj.service.hlt.HuiLianTongUnionCardService; |
|
|
|
import com.hfkj.service.hlt.HuiLianTongUnionCardService; |
|
|
|
import com.hfkj.service.order.BsOrderChildService; |
|
|
|
import com.hfkj.service.order.BsOrderChildService; |
|
|
@ -35,6 +36,7 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.math.BigDecimal; |
|
|
|
|
|
|
|
import java.math.RoundingMode; |
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
@ -60,6 +62,8 @@ public class BsOrderRefundServiceImpl implements BsOrderRefundService { |
|
|
|
private HltCardRefundService hltCardRefundService; |
|
|
|
private HltCardRefundService hltCardRefundService; |
|
|
|
@Resource |
|
|
|
@Resource |
|
|
|
private OrderRefundSuccessService orderRefundSuccessService; |
|
|
|
private OrderRefundSuccessService orderRefundSuccessService; |
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
|
|
private BsOrderMeiTuanService orderMeiTuanService; |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void editData(BsOrderRefund data) { |
|
|
|
public void editData(BsOrderRefund data) { |
|
|
|
data.setUpdateTime(new Date()); |
|
|
|
data.setUpdateTime(new Date()); |
|
|
@ -215,6 +219,7 @@ public class BsOrderRefundServiceImpl implements BsOrderRefundService { |
|
|
|
|
|
|
|
|
|
|
|
// 资金退款
|
|
|
|
// 资金退款
|
|
|
|
orderRefund.setRefundStatus(refundMoney(orderRefund)?OrderRefundStatusEnum.status2.getCode():OrderRefundStatusEnum.status3.getCode()); |
|
|
|
orderRefund.setRefundStatus(refundMoney(orderRefund)?OrderRefundStatusEnum.status2.getCode():OrderRefundStatusEnum.status3.getCode()); |
|
|
|
|
|
|
|
orderRefund.setFinishTime(orderRefund.getRefundStatus().equals(OrderRefundStatusEnum.status2.getCode())?new Date():null); |
|
|
|
editData(orderRefund); |
|
|
|
editData(orderRefund); |
|
|
|
|
|
|
|
|
|
|
|
// 退款成功
|
|
|
|
// 退款成功
|
|
|
@ -248,16 +253,31 @@ public class BsOrderRefundServiceImpl implements BsOrderRefundService { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@Transactional(propagation= Propagation.REQUIRES_NEW,rollbackFor= {RuntimeException.class}) |
|
|
|
@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) { |
|
|
|
if (orderChild == null) { |
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的子订单"); |
|
|
|
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()); |
|
|
|
BsOrder order = orderService.getOrder(orderChild.getOrderNo()); |
|
|
|
if (order == null) { |
|
|
|
if (order == null) { |
|
|
@ -268,6 +288,7 @@ public class BsOrderRefundServiceImpl implements BsOrderRefundService { |
|
|
|
BsOrderRefund orderRefund = new BsOrderRefund(); |
|
|
|
BsOrderRefund orderRefund = new BsOrderRefund(); |
|
|
|
orderRefund.setMerId(orderChild.getMerId()); |
|
|
|
orderRefund.setMerId(orderChild.getMerId()); |
|
|
|
orderRefund.setOrderNo(orderChild.getOrderNo()); |
|
|
|
orderRefund.setOrderNo(orderChild.getOrderNo()); |
|
|
|
|
|
|
|
orderRefund.setTradeRefundNo(tradeRefundNo); |
|
|
|
orderRefund.setOrderChildNo(orderChild.getChildOrderNo()); |
|
|
|
orderRefund.setOrderChildNo(orderChild.getChildOrderNo()); |
|
|
|
orderRefund.setUserId(order.getUserId()); |
|
|
|
orderRefund.setUserId(order.getUserId()); |
|
|
|
orderRefund.setUserPhone(order.getUserPhone()); |
|
|
|
orderRefund.setUserPhone(order.getUserPhone()); |
|
|
@ -276,20 +297,39 @@ public class BsOrderRefundServiceImpl implements BsOrderRefundService { |
|
|
|
orderRefund.setRefundPayChannel(order.getPayChannel()); |
|
|
|
orderRefund.setRefundPayChannel(order.getPayChannel()); |
|
|
|
orderRefund.setReufndPayType(order.getPayType()); |
|
|
|
orderRefund.setReufndPayType(order.getPayType()); |
|
|
|
|
|
|
|
|
|
|
|
// if (orderChild.getSurplusRefundCount().equals(productCount)) {
|
|
|
|
// 是否全额退款
|
|
|
|
// // 全部退款
|
|
|
|
if (orderMeiTuan.getTradeAmount().equals(refundPrice)) { |
|
|
|
// orderRefund.setRefundPrice(orderChild.getSurplusRefundPrice());
|
|
|
|
// 全部退款
|
|
|
|
// orderRefund.setRefundIntegral(orderChild.getSurplusRefundIntegral());
|
|
|
|
orderRefund.setRefundPrice(orderChild.getSurplusRefundPrice()); |
|
|
|
// } else {
|
|
|
|
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"))
|
|
|
|
BigDecimal proportion = refundPrice.divide(orderChild.getProductTotalPrice() , 2 , RoundingMode.HALF_UP); |
|
|
|
// .divide(new BigDecimal(orderChild.getProductCount().toString()), 2, BigDecimal.ROUND_DOWN).setScale(2);
|
|
|
|
// 退积分
|
|
|
|
//
|
|
|
|
Long unitPriceIntegral = new BigDecimal(orderChild.getIntegralDiscountPrice()).multiply(proportion).longValue(); |
|
|
|
// orderRefund.setRefundPrice(unitPrice.multiply(new BigDecimal(productCount.toString())));
|
|
|
|
// 退金额
|
|
|
|
// orderRefund.setRefundIntegral(unitPriceIntegral.multiply(new BigDecimal("100")).longValue());
|
|
|
|
BigDecimal price = orderChild.getProductActualPrice().multiply(proportion); |
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
if (price.compareTo(new BigDecimal("0.01")) < 0) { |
|
|
|
|
|
|
|
price = new BigDecimal(0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 插入退款积分
|
|
|
|
|
|
|
|
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) { |
|
|
|
if (orderRefund.getRefundIntegral() > 0L) { |
|
|
@ -314,8 +354,15 @@ public class BsOrderRefundServiceImpl implements BsOrderRefundService { |
|
|
|
orderRefund.setAccountMerchantKey(orderChild.getSettleAccountKey()); |
|
|
|
orderRefund.setAccountMerchantKey(orderChild.getSettleAccountKey()); |
|
|
|
editData(orderRefund); |
|
|
|
editData(orderRefund); |
|
|
|
|
|
|
|
|
|
|
|
// 资金退款
|
|
|
|
|
|
|
|
orderRefund.setRefundStatus(refundMoney(orderRefund)?OrderRefundStatusEnum.status2.getCode():OrderRefundStatusEnum.status3.getCode()); |
|
|
|
|
|
|
|
|
|
|
|
if (orderRefund.getRefundPrice().compareTo(new BigDecimal(0)) > 0) { |
|
|
|
|
|
|
|
// 资金退款
|
|
|
|
|
|
|
|
orderRefund.setRefundStatus(refundMoney(orderRefund)?OrderRefundStatusEnum.status2.getCode():OrderRefundStatusEnum.status3.getCode()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
orderRefund.setRefundStatus(OrderRefundStatusEnum.status2.getCode()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
editData(orderRefund); |
|
|
|
editData(orderRefund); |
|
|
|
|
|
|
|
|
|
|
|
// 退款成功
|
|
|
|
// 退款成功
|
|
|
@ -358,6 +405,17 @@ public class BsOrderRefundServiceImpl implements BsOrderRefundService { |
|
|
|
return null; |
|
|
|
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 |
|
|
|
@Override |
|
|
|
public List<BsOrderRefund> getRefundList(Map<String, Object> param) { |
|
|
|
public List<BsOrderRefund> getRefundList(Map<String, Object> param) { |
|
|
|
BsOrderRefundExample example = new BsOrderRefundExample(); |
|
|
|
BsOrderRefundExample example = new BsOrderRefundExample(); |
|
|
|