|
@@ -2,6 +2,7 @@ package com.yonge.cooleshow.biz.dal.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.yonge.cooleshow.biz.dal.config.HuifuConfiguration;
|
|
|
import com.yonge.cooleshow.biz.dal.enums.*;
|
|
@@ -20,7 +21,7 @@ import com.yonge.cooleshow.biz.dal.vo.res.OrderCreateRes;
|
|
|
import com.yonge.cooleshow.biz.dal.vo.UserOrderVo;
|
|
|
import com.yonge.cooleshow.biz.dal.vo.res.OrderPayRes;
|
|
|
import com.yonge.cooleshow.common.entity.HttpResponseResult;
|
|
|
-import com.yonge.cooleshow.common.exception.BizException;
|
|
|
+import com.yonge.toolset.base.exception.BizException;
|
|
|
import com.yonge.cooleshow.common.service.IdGeneratorService;
|
|
|
import com.yonge.toolset.utils.string.StringUtil;
|
|
|
import org.apache.commons.beanutils.BeanUtils;
|
|
@@ -35,6 +36,7 @@ import com.yonge.cooleshow.biz.dal.dao.UserOrderDao;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
+import java.lang.reflect.InvocationTargetException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.time.LocalDateTime;
|
|
@@ -176,8 +178,9 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
}
|
|
|
if (!OrderStatusEnum.WAIT_PAY.equals(detail.getStatus())
|
|
|
&& !OrderStatusEnum.PAYING.equals(detail.getStatus())) {
|
|
|
- return HttpResponseResult.failed("订单已完成");
|
|
|
+ return HttpResponseResult.failed("订单已关闭");
|
|
|
}
|
|
|
+
|
|
|
if (!StringUtil.isEmpty(detail.getTransNo())) {
|
|
|
try {
|
|
|
Map<String, Object> resMap = paymentSdk.queryPayment(detail.getTransNo());
|
|
@@ -194,6 +197,8 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
}
|
|
|
//关闭订单
|
|
|
doOrderCancel(detail, OrderStatusEnum.CLOSE, StringUtil.isEmpty(payReq.getReason()) ? "用户取消订单" : payReq.getReason());
|
|
|
+ //关闭订单付款单
|
|
|
+ orderPaymentService.closePayment(payReq.getOrderNo(), StringUtil.isEmpty(payReq.getReason()) ? "用户取消订单" : payReq.getReason());
|
|
|
return HttpResponseResult.succeed(true);
|
|
|
|
|
|
}
|
|
@@ -214,6 +219,11 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public Integer updateStatusByOrderNo(String orderNo, String orderStatus) {
|
|
|
+ return baseMapper.updateStatusByOrderNo(orderNo,orderStatus);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public void setOrderStatus(String orderNo, OrderStatusEnum orderStatus) {
|
|
|
UserOrderVo detail = detail(orderNo, null);
|
|
|
if (OrderStatusEnum.WAIT_PAY.equals(detail.getStatus())
|
|
@@ -243,7 +253,7 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public HttpResponseResult<UserOrder> executeOrder(OrderReq orderReq) throws Exception{
|
|
|
+ public HttpResponseResult<UserOrder> executeOrder(OrderReq orderReq) throws Exception {
|
|
|
log.info("订单[创建订单] Req:{}", JSONObject.toJSONString(orderReq));
|
|
|
//订单号生成
|
|
|
Long orderNo = idGeneratorService.generatorId("userOrder");
|
|
@@ -288,20 +298,18 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public HttpResponseResult<OrderPayRes> orderPay(OrderPayReq payReq) throws Exception{
|
|
|
+ public HttpResponseResult<OrderPayRes> orderPay(OrderPayReq payReq) throws Exception {
|
|
|
//查询订单
|
|
|
UserOrderVo detail = detail(payReq.getOrderNo(), payReq.getUserId());
|
|
|
if (null == detail || !payReq.getUserId().equals(detail.getUserId())) {
|
|
|
return HttpResponseResult.failed("订单不存在");
|
|
|
}
|
|
|
- if (OrderStatusEnum.WAIT_PAY.equals(detail.getStatus())) {
|
|
|
- //处于待支付状态,需要调用汇付发起付款请求接口
|
|
|
- return orderPayWaitPay(payReq, detail);
|
|
|
- } else if (OrderStatusEnum.PAYING.equals(detail.getStatus())) {
|
|
|
- //处于付款中状态,需要拉起付款接口返回信息,并且去到汇付
|
|
|
- return orderPayPaying(payReq, detail);
|
|
|
+ //查询付款单
|
|
|
+ if (!OrderStatusEnum.WAIT_PAY.equals(detail.getStatus())
|
|
|
+ && !OrderStatusEnum.PAYING.equals(detail.getStatus())) {
|
|
|
+ return HttpResponseResult.failed("订单状态异常");
|
|
|
}
|
|
|
- return HttpResponseResult.failed("订单状态异常");
|
|
|
+ return doOrderPayWaitPay(payReq, detail);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -314,16 +322,6 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public HttpResponseResult<OrderPayRes> orderPaytoPaying(OrderPayReq payReq) {
|
|
|
- //查询订单
|
|
|
- UserOrderVo detail = detail(payReq.getOrderNo(), payReq.getUserId());
|
|
|
- if (OrderStatusEnum.PAYING.equals(detail.getStatus())) {
|
|
|
- return orderPayPaying(payReq, detail);
|
|
|
- }
|
|
|
- return HttpResponseResult.failed("订单状态异常");
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void orderCallback(String data, String type) {
|
|
|
JSONObject hfRes = JSONObject.parseObject(data);
|
|
@@ -436,89 +434,17 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
doOrderCancel(detail, OrderStatusEnum.CLOSE, "订单超时");
|
|
|
}
|
|
|
|
|
|
- /***
|
|
|
- * 处理待支付订单
|
|
|
- * @author liweifan
|
|
|
- * @param: payReq
|
|
|
- * @param: detail
|
|
|
- * @updateTime 2022/4/13 16:59
|
|
|
- * @return: com.yonge.cooleshow.common.entity.HttpResponseResult<com.yonge.cooleshow.biz.dal.vo.res.OrderPayRes>
|
|
|
- */
|
|
|
- private HttpResponseResult<OrderPayRes> orderPayWaitPay(OrderPayReq payReq, UserOrderVo detail) {
|
|
|
- OrderPayRes orderPayRes = new OrderPayRes();
|
|
|
-
|
|
|
- UserOrderPayment orderPayment = orderPaymentService.detailByOrderNo(payReq.getOrderNo());
|
|
|
- if (null != orderPayment && TradeStatusEnum.pending.equals(orderPayment.getStatus())
|
|
|
- && !StringUtil.isEmpty(orderPayment.getPayInfo())) {
|
|
|
- orderPayRes.setPay_amt(orderPayment.getPayAmt().toString());
|
|
|
- orderPayRes.setPay_info(orderPayment.getPayInfo());
|
|
|
- orderPayRes.setPayChannel(orderPayment.getPayChannel());
|
|
|
- return HttpResponseResult.succeed(orderPayRes);
|
|
|
- }
|
|
|
-
|
|
|
- PaymentReq paymentReq = new PaymentReq();
|
|
|
- paymentReq.setOrder_no(payReq.getOrderNo());
|
|
|
- paymentReq.setPay_channel(payReq.getPayChannel().getCode());
|
|
|
- paymentReq.setPay_amt(detail.getActualPrice().setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
- paymentReq.setGoods_title(detail.getOrderName());
|
|
|
- paymentReq.setGoods_desc(detail.getOrderDesc());
|
|
|
-
|
|
|
- DeviceInfo deviceInfo = new DeviceInfo();
|
|
|
- deviceInfo.setDevice_ip(payReq.getIpAddress());
|
|
|
-
|
|
|
- paymentReq.setDevice_info(deviceInfo);
|
|
|
- //异步通知地址
|
|
|
- paymentReq.setNotify_url(HuifuConfiguration.getHuifuProperties().getNotifyUrl());
|
|
|
-
|
|
|
- if (PayChannelEnum.alipay_lite.equals(payReq.getPayChannel())) {
|
|
|
- Map<String, Object> expend = new HashMap<>();
|
|
|
- expend.put("buyer_id", payReq.getBuyerId());
|
|
|
- paymentReq.setExpend(expend);
|
|
|
- }
|
|
|
- if (PayChannelEnum.wx_lite.equals(payReq.getPayChannel())) {
|
|
|
- Map<String, Object> expend = new HashMap<>();
|
|
|
- expend.put("open_id", payReq.getOpenId());
|
|
|
- paymentReq.setExpend(expend);
|
|
|
- }
|
|
|
- //付款请求
|
|
|
- HttpResponseResult<Map<String, Object>> responseResult = paymentSdk.executePayment(paymentReq);
|
|
|
- if (responseResult.getStatus()) {
|
|
|
- orderPayRes.setPay_amt(detail.getActualPrice().setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
- String pay_info = ((JSONObject) responseResult.getData().get("expend")).getString("pay_info");
|
|
|
- orderPayRes.setPay_info(pay_info);
|
|
|
- orderPayRes.setPayChannel(payReq.getPayChannel());
|
|
|
-
|
|
|
- //入订单付款表,同时修改订单状态
|
|
|
- orderPaymentService.insertOrderPayment(responseResult, payReq);
|
|
|
-
|
|
|
- baseMapper.updateStatusByOrderNo(payReq.getOrderNo(), OrderStatusEnum.PAYING.getCode());
|
|
|
- return HttpResponseResult.succeed(orderPayRes);
|
|
|
- } else {
|
|
|
- //入订单付款表,同时修改订单状态
|
|
|
- doOrderCancel(detail, OrderStatusEnum.FAIL, responseResult.getMsg());
|
|
|
- return HttpResponseResult.failed(responseResult.getMsg());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /***
|
|
|
- * 处理待支付中订单
|
|
|
- * @author liweifan
|
|
|
- * @param: payReq
|
|
|
- * @param: detail
|
|
|
- * @updateTime 2022/4/1 10:32
|
|
|
- * @return: com.yonge.cooleshow.common.entity.HttpResponseResult<java.lang.Boolean>
|
|
|
- */
|
|
|
- private HttpResponseResult<OrderPayRes> orderPayPaying(OrderPayReq payReq, UserOrderVo detail) {
|
|
|
- UserOrderPayment orderPayment = orderPaymentService.detailByOrderNo(payReq.getOrderNo());
|
|
|
- if (TradeStatusEnum.pending.equals(orderPayment.getStatus())) {
|
|
|
+ private HttpResponseResult<OrderPayRes> doOrderPayWaitPay(OrderPayReq payReq, UserOrderVo detail) {
|
|
|
+ UserOrderPayment orderPayment = orderPaymentService.detailByOrderNo(payReq.getOrderNo(), payReq.getPayChannel(), TradeStatusEnum.pending);
|
|
|
+ //当前渠道已经有创建支付请求
|
|
|
+ if (null != orderPayment && !StringUtil.isEmpty(orderPayment.getPayInfo())) {
|
|
|
OrderPayRes orderPayRes = new OrderPayRes();
|
|
|
- orderPayRes.setPay_info(orderPayment.getPayInfo());
|
|
|
orderPayRes.setPay_amt(orderPayment.getPayAmt().toString());
|
|
|
+ orderPayRes.setPay_info(orderPayment.getPayInfo());
|
|
|
orderPayRes.setPayChannel(orderPayment.getPayChannel());
|
|
|
return HttpResponseResult.succeed(orderPayRes);
|
|
|
- } else {
|
|
|
- return HttpResponseResult.failed("未找到订单信息");
|
|
|
}
|
|
|
+ return orderPaymentService.createOrderPayment(payReq, detail);
|
|
|
}
|
|
|
|
|
|
/***
|
|
@@ -672,7 +598,7 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
* @updateTime 2022/4/13 17:23
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- void doOrderCancel(UserOrderVo userOrder, OrderStatusEnum orderStatus, String reason) {
|
|
|
+ public void doOrderCancel(UserOrderVo userOrder, OrderStatusEnum orderStatus, String reason) {
|
|
|
//已经完成过的订单,不能再取消
|
|
|
if (!OrderStatusEnum.WAIT_PAY.equals(userOrder.getStatus())
|
|
|
&& !OrderStatusEnum.PAYING.equals(userOrder.getStatus())) {
|
|
@@ -698,8 +624,6 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
userOrder.setStatus(orderStatus);
|
|
|
userOrder.setUpdateTime(new Date());
|
|
|
baseMapper.updateById(userOrder);
|
|
|
-
|
|
|
- orderPaymentService.closePayment(userOrder.getOrderNo(), reason);
|
|
|
}
|
|
|
|
|
|
void orderSuccess(UserOrderVo detail) {
|
|
@@ -720,28 +644,31 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
&& !OrderStatusEnum.PAYING.equals(detail.getStatus())) {
|
|
|
return;
|
|
|
}
|
|
|
+ //修改订单状态
|
|
|
Date now = new Date();
|
|
|
detail.setStatus(OrderStatusEnum.PAID);
|
|
|
detail.setPayTime(now);
|
|
|
detail.setUpdateTime(now);
|
|
|
updateById(detail);
|
|
|
- //更新付款单
|
|
|
- UserOrderPayment orderPayment = orderPaymentService.detailByOrderNo(detail.getOrderNo());
|
|
|
- if (null != orderPayment) {
|
|
|
- orderPayment.setStatus(TradeStatusEnum.succeeded);
|
|
|
- orderPayment.setArrivalTime(now);
|
|
|
- orderPayment.setUpdateTime(now);
|
|
|
- if (null != hfRes) {
|
|
|
- try {
|
|
|
+
|
|
|
+ try {
|
|
|
+ //更新付款单
|
|
|
+ UserOrderPayment orderPayment = orderPaymentService.detailByTransNo(hfRes.getString("id"));
|
|
|
+ if (null != orderPayment) {
|
|
|
+ orderPayment.setStatus(TradeStatusEnum.succeeded);
|
|
|
+ orderPayment.setArrivalTime(now);
|
|
|
+ orderPayment.setUpdateTime(now);
|
|
|
+ if (null != hfRes) {
|
|
|
orderPayment.setBackPayAmt(new BigDecimal(hfRes.getString("pay_amt")));
|
|
|
orderPayment.setFeeAmt(new BigDecimal(hfRes.getString("fee_amt")));
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- log.error("完成订单,付款单金额格式化失败,参数{}", hfRes.toJSONString());
|
|
|
}
|
|
|
+ orderPaymentService.updateById(orderPayment);
|
|
|
}
|
|
|
- orderPaymentService.updateById(orderPayment);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error("完成订单失败,参数{}", hfRes.toJSONString());
|
|
|
}
|
|
|
+ //调用业务
|
|
|
List<UserOrderDetailVo> orderDetailList = orderDetailService.getOrderDetilListByOrderNo(detail.getOrderNo());
|
|
|
for (UserOrderDetailVo orderDetailVo : orderDetailList) {
|
|
|
orderDetailVo.setUserId(detail.getUserId());
|