|
|
|
@ -1,13 +1,20 @@ |
|
|
|
|
package com.hai.order.service.impl; |
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.hai.common.exception.ErrorCode; |
|
|
|
|
import com.hai.common.exception.ErrorHelp; |
|
|
|
|
import com.hai.common.exception.SysCode; |
|
|
|
|
import com.hai.common.utils.DateUtil; |
|
|
|
|
import com.hai.config.HuiLianTongUnionCardConfig; |
|
|
|
|
import com.hai.config.UnionPayConfig; |
|
|
|
|
import com.hai.config.WxOrderConfig; |
|
|
|
|
import com.hai.dao.HighOrderRefundMapper; |
|
|
|
|
import com.hai.entity.HighChildOrder; |
|
|
|
|
import com.hai.entity.HighOrder; |
|
|
|
|
import com.hai.entity.HighOrderRefund; |
|
|
|
|
import com.hai.entity.HighOrderRefundExample; |
|
|
|
|
import com.hai.model.OrderRefundModel; |
|
|
|
|
import com.hai.order.model.RefundPriceModel; |
|
|
|
|
import com.hai.order.service.OrderRefundService; |
|
|
|
|
import com.hai.order.service.OrderService; |
|
|
|
|
import com.hai.order.type.OrderChildStatus; |
|
|
|
@ -15,6 +22,7 @@ import com.hai.order.type.OrderPayType; |
|
|
|
|
import com.hai.order.type.OrderRefundStatus; |
|
|
|
|
import com.hai.order.type.OrderStatus; |
|
|
|
|
import com.hai.order.utils.OrderUtil; |
|
|
|
|
import com.hai.service.HighOilCardService; |
|
|
|
|
import com.hai.service.HighUserService; |
|
|
|
|
import org.apache.commons.collections4.MapUtils; |
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
@ -22,6 +30,7 @@ import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.util.Calendar; |
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
@ -44,11 +53,19 @@ public class OrderRefundServiceImpl implements OrderRefundService { |
|
|
|
|
@Resource |
|
|
|
|
private OrderService orderService; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private HighUserService highUserService; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private HighOilCardService oilCardService; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public HighOrder createOrderRefund(HighOrder order, String remarks) throws Exception { |
|
|
|
|
// 退款订单号
|
|
|
|
|
String refundOrderNo = OrderUtil.generateRefundOrderNo(); |
|
|
|
|
public void update(HighOrderRefund orderRefund) { |
|
|
|
|
orderRefundMapper.updateByPrimaryKey(orderRefund); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public HighOrder createOrderRefund(String refundOrderNo,HighOrder order, String remarks) throws Exception { |
|
|
|
|
for (HighChildOrder orderChild : order.getHighChildOrderList()) { |
|
|
|
|
// 创建退款记录
|
|
|
|
|
HighOrderRefund orderRefund = createOrderChildRefund(orderChild, refundOrderNo, orderChild.getSaleCount(), remarks); |
|
|
|
@ -63,7 +80,7 @@ public class OrderRefundServiceImpl implements OrderRefundService { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public HighOrderRefund createOrderChildRefund(HighChildOrder orderChild,String refundNo,Integer refundGoodsCount, String remarks) throws Exception { |
|
|
|
|
public HighOrderRefund createOrderChildRefund(HighChildOrder orderChild,String refundOrderNo,Integer refundGoodsCount, String remarks) throws Exception { |
|
|
|
|
if (!orderChild.getChildOrderStatus().equals(OrderChildStatus.STATUS2.getNumber()) |
|
|
|
|
&& !orderChild.getChildOrderStatus().equals(OrderChildStatus.STATUS3.getNumber())){ |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "子订单状态错误"); |
|
|
|
@ -92,7 +109,7 @@ public class OrderRefundServiceImpl implements OrderRefundService { |
|
|
|
|
orderRefund.setOrderChildId(orderChild.getId()); |
|
|
|
|
orderRefund.setOrderChildNo(orderChild.getChildOrderNo()); |
|
|
|
|
orderRefund.setMemId(orderChild.getMemId()); |
|
|
|
|
orderRefund.setMemName(orderChild.getMemPhone()); |
|
|
|
|
orderRefund.setMemName(orderChild.getMemName()); |
|
|
|
|
orderRefund.setMemPhone(orderChild.getMemPhone()); |
|
|
|
|
orderRefund.setGoodsType(orderChild.getGoodsType()); |
|
|
|
|
orderRefund.setGoodsId(orderChild.getGoodsId()); |
|
|
|
@ -101,7 +118,7 @@ public class OrderRefundServiceImpl implements OrderRefundService { |
|
|
|
|
orderRefund.setGoodsImg(orderChild.getGoodsImg()); |
|
|
|
|
orderRefund.setGoodsSpecName(orderChild.getGoodsSpecName()); |
|
|
|
|
orderRefund.setGoodsCount(orderChild.getSaleCount()); |
|
|
|
|
orderRefund.setRefundOrderNo(refundNo==null?OrderUtil.generateRefundOrderNo():refundNo); |
|
|
|
|
orderRefund.setRefundOrderNo(refundOrderNo==null?OrderUtil.generateRefundOrderNo():refundOrderNo); |
|
|
|
|
orderRefund.setRefundGoodsNum(refundGoodsCount); |
|
|
|
|
orderRefund.setReturnTotalPrice(refundPrice.add(new BigDecimal(refundIntegral).divide(new BigDecimal("100")))); |
|
|
|
|
orderRefund.setRefundPrice(refundPrice); |
|
|
|
@ -114,6 +131,85 @@ public class OrderRefundServiceImpl implements OrderRefundService { |
|
|
|
|
return orderRefund; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public RefundPriceModel refundPrice(String refundOrderNo, HighOrder order, OrderPayType orderPayType, BigDecimal refundPrice, Integer refundIntegral) { |
|
|
|
|
RefundPriceModel refundPriceModel = new RefundPriceModel(); |
|
|
|
|
refundPriceModel.setRefundSuccess(false); |
|
|
|
|
refundPriceModel.setRefundOrderNo(refundOrderNo); |
|
|
|
|
try { |
|
|
|
|
// 积分退款
|
|
|
|
|
if (refundIntegral != null && refundIntegral > 0) { |
|
|
|
|
String remark = "订单" + order.getOrderNo() + "退款,退还积分:" + refundIntegral; |
|
|
|
|
// 积分退款
|
|
|
|
|
highUserService.goldHandle(order.getMemId(), order.getPayGold(),1, 3, order.getId() , remark); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 第三方退款
|
|
|
|
|
if (orderPayType.getNumber().equals(OrderPayType.PAY_TYPE2.getNumber())) { |
|
|
|
|
// 微信退款
|
|
|
|
|
OrderRefundModel orderRefundModel = WxOrderConfig.orderToRefund(order.getPaySerialNo(),order.getPayRealPrice(), order.getAccountMerchantNum(), refundPrice); |
|
|
|
|
if(orderRefundModel.getResult_code().equals("SUCCESS")) { |
|
|
|
|
refundPriceModel.setRefundSuccess(true); |
|
|
|
|
refundPriceModel.setThirdPartyRefundOrderNo(orderRefundModel.getRefund_id()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} else if (orderPayType.getNumber().equals(OrderPayType.PAY_TYPE4.getNumber())) { |
|
|
|
|
|
|
|
|
|
JSONObject refund = HuiLianTongUnionCardConfig.refund(refundOrderNo, order.getPaySerialNo()); |
|
|
|
|
if (!refund.getString("respCode").equals("0000")) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR,refund.getString("respMessage")); |
|
|
|
|
} |
|
|
|
|
JSONObject consumptionResult = HuiLianTongUnionCardConfig.resolveResponse(refund.getString("data")); |
|
|
|
|
if (consumptionResult.getBoolean("success") != true) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "交易失败!"+consumptionResult.getString("message")); |
|
|
|
|
} |
|
|
|
|
refundPriceModel.setRefundSuccess(true); |
|
|
|
|
refundPriceModel.setThirdPartyRefundOrderNo(consumptionResult.getString("orderId")); |
|
|
|
|
|
|
|
|
|
} else if (orderPayType.getNumber().equals(OrderPayType.PAY_TYPE5.getNumber())) { |
|
|
|
|
Calendar startTime = Calendar.getInstance(); |
|
|
|
|
startTime.set(Calendar.HOUR_OF_DAY, 00); |
|
|
|
|
startTime.set(Calendar.MINUTE, 00); |
|
|
|
|
startTime.set(Calendar.SECOND, 00); |
|
|
|
|
|
|
|
|
|
Calendar endTime = Calendar.getInstance(); |
|
|
|
|
startTime.set(Calendar.HOUR_OF_DAY, 23); |
|
|
|
|
startTime.set(Calendar.MINUTE, 59); |
|
|
|
|
startTime.set(Calendar.SECOND, 59); |
|
|
|
|
|
|
|
|
|
// 订单是否处于当日的订单
|
|
|
|
|
if (DateUtil.isEffectiveDate(order.getPayTime(), startTime.getTime(), endTime.getTime())) { |
|
|
|
|
// 订单撤销
|
|
|
|
|
JSONObject refund = UnionPayConfig.cancel(UnionPayConfig.MER_ID3, UnionPayConfig.TERM_ID3, order.getOrderNo(), order.getPaySerialNo()); |
|
|
|
|
System.out.println(refund.toJSONString()); |
|
|
|
|
if (!refund.getString("resultcode").equals("00") || !refund.getString("resultcode").equals("W6")) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, refund.getString("returnmsg")); |
|
|
|
|
} |
|
|
|
|
refundPriceModel.setRefundSuccess(true); |
|
|
|
|
} else { |
|
|
|
|
// 订单退款
|
|
|
|
|
JSONObject refund = UnionPayConfig.zwrefund(UnionPayConfig.MER_ID3, UnionPayConfig.TERM_ID3, order.getOrderNo(), order.getPaySerialNo(), order.getPayRealPrice().multiply(new BigDecimal("100")).longValue()); |
|
|
|
|
System.out.println(refund.toJSONString()); |
|
|
|
|
if (!refund.getString("resultcode").equals("00") || !refund.getString("resultcode").equals("W6")) { |
|
|
|
|
JSONObject refund2 = UnionPayConfig.zwrefund(UnionPayConfig.MER_ID1, UnionPayConfig.TERM_ID1, order.getOrderNo(), order.getPaySerialNo(), order.getPayRealPrice().multiply(new BigDecimal("100")).longValue()); |
|
|
|
|
if (!refund2.getString("resultcode").equals("00") || !refund.getString("resultcode").equals("W6")) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, refund2.getString("returnmsg")); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
refundPriceModel.setRefundSuccess(true); |
|
|
|
|
} |
|
|
|
|
} else if (orderPayType.getNumber().equals(OrderPayType.PAY_TYPE7.getNumber())) { |
|
|
|
|
// 油卡退款
|
|
|
|
|
oilCardService.refund(order.getOrderNo()); |
|
|
|
|
refundPriceModel.setRefundSuccess(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
refundPriceModel.setRefundSuccess(false); |
|
|
|
|
} |
|
|
|
|
return refundPriceModel; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<HighOrderRefund> getRefundOrderList(Map<String, Object> param) { |
|
|
|
|
HighOrderRefundExample example = new HighOrderRefundExample(); |
|
|
|
@ -171,23 +267,10 @@ public class OrderRefundServiceImpl implements OrderRefundService { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public HighOrderRefund getRefundByRefundNo(String refundOrderNo) { |
|
|
|
|
public List<HighOrderRefund> getRefundByRefundNo(String refundOrderNo) { |
|
|
|
|
HighOrderRefundExample example = new HighOrderRefundExample(); |
|
|
|
|
example.createCriteria().andRefundOrderNoEqualTo(refundOrderNo); |
|
|
|
|
List<HighOrderRefund> list = orderRefundMapper.selectByExample(example); |
|
|
|
|
if (list.size() > 0) { |
|
|
|
|
return list.get(0); |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
return orderRefundMapper.selectByExample(example); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 金额退回用户 |
|
|
|
|
* @param orderNo 订单号 |
|
|
|
|
* @param refundPrice 退款金额 |
|
|
|
|
* @param refundIntegral 退款积分 |
|
|
|
|
*/ |
|
|
|
|
public void refundPrice(String orderNo,BigDecimal refundPrice,Integer refundIntegral) throws Exception { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|