|
|
|
@ -1,20 +1,16 @@ |
|
|
|
|
package com.hai.service.impl; |
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.alicp.jetcache.anno.CacheType; |
|
|
|
|
import com.alicp.jetcache.anno.Cached; |
|
|
|
|
|
|
|
|
|
import com.hai.common.exception.ErrorCode; |
|
|
|
|
import com.hai.common.exception.ErrorHelp; |
|
|
|
|
import com.hai.common.exception.SysCode; |
|
|
|
|
import com.hai.common.pay.util.XmlUtil; |
|
|
|
|
import com.hai.common.pay.util.sdk.WXPayConstants; |
|
|
|
|
|
|
|
|
|
import com.hai.common.security.AESEncodeUtil; |
|
|
|
|
import com.hai.common.utils.*; |
|
|
|
|
import com.hai.config.*; |
|
|
|
|
import com.hai.dao.HighGasOrderPushMapper; |
|
|
|
|
import com.hai.dao.HighOrderMapper; |
|
|
|
|
import com.hai.dao.OutRechargeOrderMapper; |
|
|
|
|
import com.hai.dao.OutRechargeOrderMapperExt; |
|
|
|
|
import com.hai.entity.*; |
|
|
|
@ -22,33 +18,26 @@ import com.hai.enum_type.*; |
|
|
|
|
import com.hai.model.*; |
|
|
|
|
import com.hai.order.service.OrderService; |
|
|
|
|
import com.hai.order.type.OrderChildStatus; |
|
|
|
|
import com.hai.order.type.OrderPayType; |
|
|
|
|
import com.hai.order.type.OrderRefundOpUserType; |
|
|
|
|
import com.hai.service.*; |
|
|
|
|
import com.hai.service.pay.impl.GoodsOrderServiceImpl; |
|
|
|
|
import io.swagger.models.auth.In; |
|
|
|
|
import org.apache.commons.collections4.MapUtils; |
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
import org.apache.http.HttpEntity; |
|
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse; |
|
|
|
|
import org.apache.http.client.methods.HttpPost; |
|
|
|
|
import org.apache.http.entity.StringEntity; |
|
|
|
|
import org.apache.http.impl.client.CloseableHttpClient; |
|
|
|
|
import org.apache.http.util.EntityUtils; |
|
|
|
|
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.transaction.annotation.Isolation; |
|
|
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.math.RoundingMode; |
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Service("outRechargeOrderService") |
|
|
|
|
public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { |
|
|
|
@ -213,6 +202,7 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { |
|
|
|
|
return outRechargeOrder; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// todo 接口已经废弃
|
|
|
|
|
@Override |
|
|
|
|
@Transactional( |
|
|
|
|
isolation = Isolation.SERIALIZABLE, |
|
|
|
@ -592,16 +582,19 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法退款,订单已充值成功无法退款z"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 订单处理
|
|
|
|
|
HighOrder highOrder = highOrderService.getOrderByOrderNo(outRechargeOrder.getOrderNo()); |
|
|
|
|
orderService.refundOrder(highOrder, "话费自动退款",OrderRefundOpUserType.TYPE1, |
|
|
|
|
null, |
|
|
|
|
"系统自动退款"); |
|
|
|
|
|
|
|
|
|
// 话费充值业务订单处理
|
|
|
|
|
outRechargeOrder.setPayStatus(105); |
|
|
|
|
outRechargeOrder.setRechargeStatus(203); |
|
|
|
|
outRechargeOrder.setRefundTime(new Date()); |
|
|
|
|
outRechargeOrderService.updateOrder(outRechargeOrder); |
|
|
|
|
|
|
|
|
|
// 子订单修改状态
|
|
|
|
|
// 充值订单记录修改状态
|
|
|
|
|
childOrder.setStatus(103); |
|
|
|
|
outRechargeChildOrderService.updateOrder(childOrder); |
|
|
|
|
} |
|
|
|
@ -625,7 +618,7 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { |
|
|
|
|
// 定义新的子订单对象
|
|
|
|
|
OutRechargeChildOrder childOrder = new OutRechargeChildOrder(); |
|
|
|
|
|
|
|
|
|
// 初始化充值平台 1:尖椒 2:龙阅 3:畅停 4.嗨购
|
|
|
|
|
// 初始化充值平台 1:尖椒 2:龙阅 3:城宇 4.畅停
|
|
|
|
|
int platformType = 0; |
|
|
|
|
|
|
|
|
|
// 判断子订单是否存在充值中订单
|
|
|
|
@ -638,19 +631,22 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { |
|
|
|
|
if (status == 0 || status == 3 || status == 99) { |
|
|
|
|
return; |
|
|
|
|
} else if (status == 1) { |
|
|
|
|
completeOrder(outRechargeOrder , childOrder); |
|
|
|
|
completeOrder(outRechargeOrder.getOrderNo()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 修改充值记录状态
|
|
|
|
|
childOrder.setStatus(103); |
|
|
|
|
childOrder.setUpdateTime(new Date()); |
|
|
|
|
outRechargeChildOrderService.updateOrder(childOrder); |
|
|
|
|
platformType = childOrder.getRechargePlatform(); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 获取充值平台
|
|
|
|
|
platformType = getRechargePlatformType(); |
|
|
|
|
|
|
|
|
|
// 定义下单请求数据对象
|
|
|
|
|
JSONObject object = new JSONObject(); |
|
|
|
|
|
|
|
|
|
// 定义充值订单号
|
|
|
|
|
// 定义新充值订单号
|
|
|
|
|
String orderNo = "CZ" + DateUtil.date2String(new Date(), "yyyyMMddHHmmss") + IDGenerator.nextId(5); |
|
|
|
|
|
|
|
|
|
// 查询平台
|
|
|
|
@ -661,9 +657,11 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { |
|
|
|
|
if (string.length() == 1) { |
|
|
|
|
platformType = Integer.parseInt(string); |
|
|
|
|
} else { |
|
|
|
|
// 如果平台充值记录暂无 则充值第一个
|
|
|
|
|
if (platformType == 0) { |
|
|
|
|
platformType = Integer.parseInt(rechargePlatform[0]); |
|
|
|
|
} else { |
|
|
|
|
// 获取上一条充值平台的下一个平台内容
|
|
|
|
|
platformType = Integer.parseInt(rechargePlatform[ArrayUtils.arrayIndex(rechargePlatform , String.valueOf(platformType))]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -729,7 +727,7 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { |
|
|
|
|
childOrder.setRechargePlatform(3); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
// 嗨购充值
|
|
|
|
|
// 畅停充值
|
|
|
|
|
if (s.equals("4") && platformType == 4) { |
|
|
|
|
|
|
|
|
|
map.put("sourceId" , outRechargePrice.getId()); |
|
|
|
@ -771,12 +769,20 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void completeOrder(OutRechargeOrder order, OutRechargeChildOrder childOrder) { |
|
|
|
|
public void completeOrder(String orderNo) { |
|
|
|
|
|
|
|
|
|
OutRechargeOrder order = outRechargeOrderService.findByOrderNo(orderNo); |
|
|
|
|
OutRechargeChildOrder childOrder = order.getOutRechargeChildOrders().get(0); |
|
|
|
|
|
|
|
|
|
// 修改话费充值业务订单状态
|
|
|
|
|
childOrder.setStatus(101); |
|
|
|
|
order.setRechargeStatus(202); |
|
|
|
|
order.setPayStatus(100); |
|
|
|
|
order.setFinishTime(new Date()); |
|
|
|
|
outRechargeOrderService.updateOrder(order); |
|
|
|
|
outRechargeChildOrderService.updateOrder(childOrder); |
|
|
|
|
|
|
|
|
|
// 修改订单状态
|
|
|
|
|
HighOrder highOrder = highOrderService.getOrderByOrderNo(order.getOrderNo()); |
|
|
|
|
if (highOrder != null) { |
|
|
|
|
highOrder.setOrderStatus(OrderStatusEnum.type3.getType()); |
|
|
|
@ -788,8 +794,19 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { |
|
|
|
|
orderService.updateOrderData(highOrder); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
outRechargeOrderService.updateOrder(order); |
|
|
|
|
outRechargeChildOrderService.updateOrder(childOrder); |
|
|
|
|
|
|
|
|
|
// 推送小程序消息
|
|
|
|
|
new Thread(() -> { |
|
|
|
|
HighUser highUser = highUserService.findByUserId(highOrder.getMemId()); |
|
|
|
|
WxMsgConfig.rechargedSuccess( |
|
|
|
|
order.getRechargeContent() + "充值成功", |
|
|
|
|
String.valueOf(order.getPayRealPrice()), |
|
|
|
|
order.getOrderNo(), |
|
|
|
|
order.getFinishTime(), |
|
|
|
|
OrderPayType.getDataByType(order.getPayType()).getName(), |
|
|
|
|
highUser.getOpenId()); |
|
|
|
|
}).start(); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -818,18 +835,26 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void rechargeOrderHandle(OutRechargeOrder outRechargeOrder, OutRechargeChildOrder childOrder) throws Exception { |
|
|
|
|
public void rechargeOrderHandle(String orderNo) throws Exception { |
|
|
|
|
|
|
|
|
|
// 定义话费充值业务订单模型 or 充值记录订单模型
|
|
|
|
|
OutRechargeOrder outRechargeOrder = findByOrderNo(orderNo); |
|
|
|
|
OutRechargeChildOrder childOrder = outRechargeOrder.getOutRechargeChildOrders().get(0); |
|
|
|
|
|
|
|
|
|
// 状态需要支付状态为已充值 并且 充值状态不为 充值成功
|
|
|
|
|
if (outRechargeOrder.getPayStatus() == 102 && outRechargeOrder.getRechargeStatus() != 202) { |
|
|
|
|
|
|
|
|
|
// 判断充值记录是否存在
|
|
|
|
|
if (outRechargeOrder.getOutRechargeChildOrders().size() == 0) { |
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
OutRechargeChildOrder outRechargeChildOrder = new OutRechargeChildOrder(); |
|
|
|
|
|
|
|
|
|
outRechargeChildOrder.setOrderNo("CZ" + DateUtil.date2String(new Date(), "yyyyMMddHHmmss") + IDGenerator.nextId(5)); |
|
|
|
|
outRechargeChildOrder.setParentOrderId(outRechargeOrder.getId()); |
|
|
|
|
outRechargeChildOrder.setUpdateTime(new Date()); |
|
|
|
|
outRechargeChildOrder.setCreateTime(new Date()); |
|
|
|
|
|
|
|
|
|
outRechargeChildOrderService.insertOrder(outRechargeChildOrder); |
|
|
|
|
// 话费退款
|
|
|
|
|
refundOrder(outRechargeOrder.getId() , outRechargeChildOrder); |
|
|
|
|
} else { |
|
|
|
|
// -1 取消,0充值中 ,1充值成功,2充值失败,3部分成功
|
|
|
|
@ -837,7 +862,7 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { |
|
|
|
|
if (status == 2 || status == -1) { |
|
|
|
|
refundOrder(outRechargeOrder.getId() , childOrder); |
|
|
|
|
} else if (status == 1) { |
|
|
|
|
completeOrder(outRechargeOrder , childOrder); |
|
|
|
|
completeOrder(outRechargeOrder.getOrderNo()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -868,7 +893,7 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
// 嗨购
|
|
|
|
|
// 畅停
|
|
|
|
|
if (childOrder.getRechargePlatform() == 4) { |
|
|
|
|
object.put("orderid" , childOrder.getOrderNo()); |
|
|
|
|
|
|
|
|
@ -898,4 +923,13 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { |
|
|
|
|
} |
|
|
|
|
return 99; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Integer getRechargePlatformType() { |
|
|
|
|
OutRechargeChildOrder outRechargeChildOrder = outRechargeChildOrderService.findOutRechargeChildOrderByDesc(); |
|
|
|
|
|
|
|
|
|
if (outRechargeChildOrder != null) { |
|
|
|
|
return outRechargeChildOrder.getRechargePlatform(); |
|
|
|
|
} |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|