Merge branch '2.0-dev' of http://139.159.177.244:3000/hurui/hai-server into 2.0-dev
commit
9dfac24d77
File diff suppressed because one or more lines are too long
@ -0,0 +1,333 @@ |
||||
package com.web.controller.notify; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hai.config.WxMsgConfig; |
||||
import com.hai.entity.*; |
||||
import com.hai.enum_type.OrderStatusEnum; |
||||
import com.hai.enum_type.RechargePayType; |
||||
import com.hai.order.service.OrderService; |
||||
import com.hai.order.type.OrderChildStatus; |
||||
import com.hai.service.*; |
||||
import com.hai.service.impl.OutRechargeOrderServiceImpl; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.PrintWriter; |
||||
import java.util.Date; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.Objects; |
||||
|
||||
@Controller |
||||
@RequestMapping(value = "/mobileRechargeNotify") |
||||
@Api(value = "通知") |
||||
public class MobileRechargeNotifyController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(OutRechargeOrderServiceImpl.class); |
||||
|
||||
@Resource |
||||
private OutRechargeOrderService outRechargeOrderService; |
||||
|
||||
@Resource |
||||
private OutRechargeChildOrderService outRechargeChildOrderService; |
||||
|
||||
@Resource |
||||
private HighUserService highUserService; |
||||
|
||||
@Resource |
||||
private ApiOrderRecordService apiOrderRecordService; |
||||
|
||||
@Resource |
||||
private HighOrderService highOrderService; |
||||
|
||||
@Resource |
||||
private OrderService orderService; |
||||
|
||||
@RequestMapping(value = "/rechargeCallbackByJj", method = RequestMethod.POST) |
||||
@ApiOperation(value = "尖椒充值回调") |
||||
@ResponseBody |
||||
public void rechargeCallbackByJj(@RequestBody String reqBodyStr, HttpServletRequest request, HttpServletResponse response) { |
||||
try { |
||||
|
||||
JSONObject dataObject = JSONObject.parseObject(reqBodyStr, JSONObject.class); |
||||
|
||||
log.info("============回调任务Start============="); |
||||
log.info("尖椒订单充值-回调参数: " + dataObject); |
||||
log.info("============回调任务End============="); |
||||
|
||||
// 1 尖椒 2 龙阅
|
||||
dataObject.put("orderNo" , dataObject.getString("out_order_id")); |
||||
|
||||
// 查询充值记录订单
|
||||
OutRechargeChildOrder childOrder = outRechargeChildOrderService.findByOrderNo(dataObject.getString("out_order_id")); |
||||
|
||||
// 查询充值订单
|
||||
OutRechargeOrder rechargeOrder = outRechargeOrderService.findByOrderId(childOrder.getParentOrderId()); |
||||
|
||||
// 判断是否充值成功 并发送微信小程序服务通知
|
||||
if (dataObject.getInteger("status") == 3) { |
||||
if (rechargeOrder.getRechargeStatus() ==201) { |
||||
new Thread(() -> { |
||||
HighUser highUser = highUserService.findByUserId(rechargeOrder.getUserId()); |
||||
WxMsgConfig.rechargedSuccess( |
||||
rechargeOrder.getRechargeContent() + "充值成功", |
||||
String.valueOf(rechargeOrder.getPayRealPrice()), |
||||
rechargeOrder.getOrderNo(), |
||||
rechargeOrder.getFinishTime(), |
||||
RechargePayType.getNameByType(rechargeOrder.getPayType()), |
||||
highUser.getOpenId()); |
||||
}).start(); |
||||
} |
||||
|
||||
childOrder.setStatus(101); |
||||
rechargeOrder.setRechargeStatus(202); |
||||
rechargeOrder.setPayStatus(100); |
||||
|
||||
outRechargeOrderService.updateOrder(rechargeOrder); |
||||
outRechargeChildOrderService.updateOrder(childOrder); |
||||
orderFinish(rechargeOrder); |
||||
|
||||
// api商户订单
|
||||
if (rechargeOrder.getPayType() == 6) { |
||||
apiOrderRecord(rechargeOrder); |
||||
} |
||||
|
||||
} else { |
||||
// 充值失败操作
|
||||
callbackResult(childOrder , rechargeOrder); |
||||
} |
||||
|
||||
response.setCharacterEncoding("UTF-8"); |
||||
response.setContentType("text/html;charset=utf-8"); |
||||
PrintWriter writer= response.getWriter(); |
||||
writer.write("SUCCESS"); |
||||
|
||||
|
||||
} catch (Exception e) { |
||||
log.error("WechatPayController --> wechatNotify() error!", e); |
||||
} |
||||
} |
||||
|
||||
|
||||
@RequestMapping(value = "/rechargeCallbackByLy", method = RequestMethod.POST) |
||||
@ApiOperation(value = "龙阅充值回调") |
||||
@ResponseBody |
||||
public void rechargeCallbackByLy( |
||||
@RequestParam(name = "out_trade_num", required = true) String out_trade_num, |
||||
@RequestParam(name = "userid", required = true) Long userid, |
||||
@RequestParam(name = "state", required = true) Long state, |
||||
@RequestBody String reqBodyStr , |
||||
HttpServletRequest request, HttpServletResponse response) { |
||||
try { |
||||
|
||||
log.info("============回调任务Start============="); |
||||
log.info("龙阅订单充值-回调参数: " + reqBodyStr); |
||||
log.info("============回调任务End============="); |
||||
|
||||
OutRechargeChildOrder childOrder = outRechargeChildOrderService.findByOrderNo(out_trade_num); |
||||
|
||||
OutRechargeOrder rechargeOrder = outRechargeOrderService.findByOrderId(childOrder.getParentOrderId()); |
||||
|
||||
// 判断是否充值成功 并发送微信小程序服务通知
|
||||
if (state == 1) { |
||||
if (rechargeOrder.getRechargeStatus() ==201) { |
||||
new Thread(() -> { |
||||
HighUser highUser = highUserService.findByUserId(rechargeOrder.getUserId()); |
||||
WxMsgConfig.rechargedSuccess( |
||||
rechargeOrder.getRechargeContent() + "充值成功", |
||||
String.valueOf(rechargeOrder.getPayRealPrice()), |
||||
rechargeOrder.getOrderNo(), |
||||
rechargeOrder.getFinishTime(), |
||||
RechargePayType.getNameByType(rechargeOrder.getPayType()), |
||||
highUser.getOpenId()); |
||||
}).start(); |
||||
} |
||||
childOrder.setStatus(101); |
||||
rechargeOrder.setRechargeStatus(202); |
||||
rechargeOrder.setPayStatus(100); |
||||
rechargeOrder.setFinishTime(new Date()); |
||||
|
||||
outRechargeOrderService.updateOrder(rechargeOrder); |
||||
outRechargeChildOrderService.updateOrder(childOrder); |
||||
orderFinish(rechargeOrder); |
||||
if (rechargeOrder.getPayType() == 6) { |
||||
apiOrderRecord(rechargeOrder); |
||||
} |
||||
} else { |
||||
callbackResult(childOrder , rechargeOrder); |
||||
} |
||||
|
||||
response.setCharacterEncoding("UTF-8"); |
||||
response.setContentType("text/html;charset=utf-8"); |
||||
PrintWriter writer= response.getWriter(); |
||||
writer.write("SUCCESS"); |
||||
|
||||
|
||||
} catch (Exception e) { |
||||
log.error("WechatPayController --> wechatNotify() error!", e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/rechargeCallbackByHg", method = RequestMethod.POST) |
||||
@ApiOperation(value = "嗨购充值回调") |
||||
@ResponseBody |
||||
public void rechargeCallbackByHg( |
||||
@RequestParam(name = "mchid", required = false) String mchid, |
||||
@RequestParam(name = "out_order_id", required = false) String out_order_id, |
||||
@RequestParam(name = "orderid", required = true) String orderid, |
||||
@RequestParam(name = "return_time", required = false) String return_time, |
||||
@RequestParam(name = "return_price", required = false) String return_price, |
||||
@RequestParam(name = "recharge_price", required = false) String recharge_price, |
||||
@RequestParam(name = "price", required = false) String price, |
||||
@RequestParam(name = "status", required = true) String status, |
||||
@RequestParam(name = "phone", required = false) String phone, |
||||
@RequestParam(name = "secret_key", required = false) String secret_key, |
||||
HttpServletResponse response) { |
||||
try { |
||||
|
||||
|
||||
|
||||
JSONObject dataObject = new JSONObject(); |
||||
|
||||
dataObject.put("mchid" , mchid); |
||||
dataObject.put("out_order_id" , out_order_id); |
||||
dataObject.put("orderid" , orderid); |
||||
dataObject.put("return_time" , return_time); |
||||
dataObject.put("return_price" , return_price); |
||||
dataObject.put("recharge_price" , recharge_price); |
||||
dataObject.put("price" , price); |
||||
dataObject.put("status" , status); |
||||
dataObject.put("phone" , phone); |
||||
dataObject.put("secret_key" , secret_key); |
||||
|
||||
log.info("============回调任务Start============="); |
||||
log.info("嗨购订单充值-回调参数: " + dataObject); |
||||
log.info("============回调任务End============="); |
||||
|
||||
// 1 尖椒 2 龙阅
|
||||
|
||||
// 查询充值记录订单
|
||||
OutRechargeChildOrder childOrder = outRechargeChildOrderService.findByOrderNo(orderid); |
||||
|
||||
// 查询充值订单
|
||||
OutRechargeOrder rechargeOrder = outRechargeOrderService.findByOrderId(childOrder.getParentOrderId()); |
||||
|
||||
// 判断是否充值成功 并发送微信小程序服务通知
|
||||
if (Objects.equals(status, "1")) { |
||||
if (rechargeOrder.getRechargeStatus() ==201) { |
||||
new Thread(() -> { |
||||
HighUser highUser = highUserService.findByUserId(rechargeOrder.getUserId()); |
||||
WxMsgConfig.rechargedSuccess( |
||||
rechargeOrder.getRechargeContent() + "充值成功", |
||||
String.valueOf(rechargeOrder.getPayRealPrice()), |
||||
rechargeOrder.getOrderNo(), |
||||
rechargeOrder.getFinishTime(), |
||||
RechargePayType.getNameByType(rechargeOrder.getPayType()), |
||||
highUser.getOpenId()); |
||||
}).start(); |
||||
} |
||||
|
||||
childOrder.setStatus(101); |
||||
rechargeOrder.setRechargeStatus(202); |
||||
rechargeOrder.setPayStatus(100); |
||||
|
||||
outRechargeOrderService.updateOrder(rechargeOrder); |
||||
outRechargeChildOrderService.updateOrder(childOrder); |
||||
orderFinish(rechargeOrder); |
||||
|
||||
// api商户订单
|
||||
if (rechargeOrder.getPayType() == 6) { |
||||
apiOrderRecord(rechargeOrder); |
||||
} |
||||
|
||||
} else { |
||||
// 充值失败操作
|
||||
callbackResult(childOrder , rechargeOrder); |
||||
} |
||||
|
||||
response.setCharacterEncoding("UTF-8"); |
||||
response.setContentType("text/html;charset=utf-8"); |
||||
PrintWriter writer= response.getWriter(); |
||||
writer.write("success"); |
||||
|
||||
|
||||
} catch (Exception e) { |
||||
log.error("WechatPayController --> wechatNotify() error!", e); |
||||
} |
||||
} |
||||
|
||||
|
||||
// 充值回调结果处理
|
||||
private void callbackResult(OutRechargeChildOrder childOrder , OutRechargeOrder rechargeOrder) throws Exception { |
||||
|
||||
// 101:充值成功 102: 充值中 103:充值失败 104 未充值
|
||||
// 订单支付状态 : 101.待支付 102.已支付 100.已完成 104.已取消 105.已退款
|
||||
if (childOrder.getStatus() == 102 && rechargeOrder.getPayStatus() == 102) { |
||||
|
||||
Date rechargeTime = rechargeOrder.getCreateTimed(); |
||||
Date currentTime = new Date(); |
||||
// 当前时间减去充值时间
|
||||
int hours = (int) ((currentTime.getTime() - rechargeTime.getTime()) / (1000 * 60 * 60)); |
||||
|
||||
// // 判断快充 并且 充值时间小于6
|
||||
// if (rechargeOrder.getRechargeType() == 1 && hours < 6) {
|
||||
// outRechargeOrderService.pollRequest(rechargeOrder);
|
||||
// return;
|
||||
// }
|
||||
// 判断慢充 并且 充值时间小于72
|
||||
if (hours < 72) { |
||||
outRechargeOrderService.pollRequest(rechargeOrder); |
||||
return; |
||||
} |
||||
|
||||
outRechargeOrderService.refundOrder(rechargeOrder.getId() , childOrder); |
||||
|
||||
// 发送充值失败 微信小程序服务通知
|
||||
new Thread(() -> { |
||||
HighUser highUser = highUserService.findByUserId(rechargeOrder.getUserId()); |
||||
WxMsgConfig.rechargedFail( |
||||
rechargeOrder.getRechargeContent() + "充值失败", |
||||
String.valueOf(rechargeOrder.getPayRealPrice()), |
||||
highUser.getOpenId()); |
||||
}).start(); |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
// 订单完成操作
|
||||
private void orderFinish(OutRechargeOrder rechargeOrder) { |
||||
HighOrder highOrder = highOrderService.getOrderByOrderNo(rechargeOrder.getOrderNo()); |
||||
if (highOrder != null) { |
||||
highOrder.setOrderStatus(OrderStatusEnum.type3.getType()); |
||||
highOrder.setFinishTime(new Date()); |
||||
for (HighChildOrder highChildOrder : highOrder.getHighChildOrderList()) { |
||||
highChildOrder.setChildOrderStatus(OrderChildStatus.STATUS3.getNumber()); |
||||
highChildOrder.setFinishTime(new Date()); |
||||
} |
||||
orderService.updateOrderData(highOrder); |
||||
} |
||||
|
||||
} |
||||
|
||||
private void apiOrderRecord(OutRechargeOrder rechargeOrder) { |
||||
Map<String, Object> orderMap = new HashMap<>(); |
||||
orderMap.put("orderId" , rechargeOrder.getId()); |
||||
|
||||
// 查询是否用重复订单
|
||||
ApiOrderRecord apiOrderRecord = apiOrderRecordService.queryOrderResult(orderMap); |
||||
|
||||
apiOrderRecord.setStatus(100); |
||||
apiOrderRecord.setRequestTime(new Date()); |
||||
apiOrderRecordService.updateOrderRecord(apiOrderRecord); |
||||
|
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue