|  | @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.core.metadata.IPage;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.config.HuifuConfiguration;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.enums.*;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.vo.UserOrderDetailVo;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.common.constant.SysConfigConstant;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dto.req.OrderPayReq;
 | 
	
	
		
			
				|  | @@ -11,10 +12,6 @@ import com.yonge.cooleshow.biz.dal.dto.req.OrderReq;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.entity.UserOrderDetail;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.entity.UserOrder;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.entity.UserOrderPayment;
 | 
	
		
			
				|  |  | -import com.yonge.cooleshow.biz.dal.enums.OrderStatusEnum;
 | 
	
		
			
				|  |  | -import com.yonge.cooleshow.biz.dal.enums.OrderTypeEnum;
 | 
	
		
			
				|  |  | -import com.yonge.cooleshow.biz.dal.enums.PayChannelEnum;
 | 
	
		
			
				|  |  | -import com.yonge.cooleshow.biz.dal.enums.PayStatusEnum;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.sdk.PaymentSdk;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.sdk.req.DeviceInfo;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.sdk.req.PaymentReq;
 | 
	
	
		
			
				|  | @@ -59,26 +56,28 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
 | 
	
		
			
				|  |  |      private IdGeneratorService idGeneratorService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      //验证订单是否可以下单
 | 
	
		
			
				|  |  | -    private static final Map<OrderTypeEnum, Function<OrderReq, HttpResponseResult<OrderCreateRes>>> orderCreate = new HashMap<>();
 | 
	
		
			
				|  |  | +    private static final Map<GoodTypeEnum, Function<OrderReq.OrderReqInfo, HttpResponseResult<OrderCreateRes>>> orderCreate = new HashMap<>();
 | 
	
		
			
				|  |  |      //插入订单后执行
 | 
	
		
			
				|  |  | -    private static final Map<OrderTypeEnum, Consumer<UserOrderVo>> orderAfter = new HashMap<>();
 | 
	
		
			
				|  |  | +    private static final Map<GoodTypeEnum, Consumer<UserOrderDetailVo>> orderAfter = new HashMap<>();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      //订单完成后执行
 | 
	
		
			
				|  |  | -    private static final Map<OrderTypeEnum, Consumer<UserOrderVo>> orderSuccess = new HashMap<>();
 | 
	
		
			
				|  |  | +    private static final Map<GoodTypeEnum, Consumer<UserOrderDetailVo>> orderSuccess = new HashMap<>();
 | 
	
		
			
				|  |  |      //订单取消后执行
 | 
	
		
			
				|  |  | -    private static final Map<OrderTypeEnum, Consumer<UserOrderVo>> orderCancel = new HashMap<>();
 | 
	
		
			
				|  |  | +    private static final Map<GoodTypeEnum, Consumer<UserOrderDetailVo>> orderCancel = new HashMap<>();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @PostConstruct
 | 
	
		
			
				|  |  |      private void init() {
 | 
	
		
			
				|  |  |          /**********订单生成前******************/
 | 
	
		
			
				|  |  |          //vip开通缴费
 | 
	
		
			
				|  |  | -        orderCreate.put(OrderTypeEnum.VIP, vipCardService::orderCreate);
 | 
	
		
			
				|  |  | +        orderCreate.put(GoodTypeEnum.VIP, vipCardService::orderCreate);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          /**********订单生成后******************/
 | 
	
		
			
				|  |  |          //orderAfter.put(OrderTypeEnum.VIP, vipCardService::orderAfter);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          /**********订单完成后******************/
 | 
	
		
			
				|  |  |          //vip开通缴费
 | 
	
		
			
				|  |  | -        orderSuccess.put(OrderTypeEnum.VIP, vipCardService::orderSuccess);
 | 
	
		
			
				|  |  | +        orderSuccess.put(GoodTypeEnum.VIP, vipCardService::orderSuccess);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          /**********订单取消后******************/
 | 
	
	
		
			
				|  | @@ -89,7 +88,7 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
 | 
	
		
			
				|  |  |      public UserOrderVo detail(Long id) {
 | 
	
		
			
				|  |  |          UserOrderVo userOrderVo = baseMapper.detailById(id);
 | 
	
		
			
				|  |  |          if (null != userOrderVo) {
 | 
	
		
			
				|  |  | -            userOrderVo.setOrderDetail(orderDetailService.detail(userOrderVo.getOrderNo()));
 | 
	
		
			
				|  |  | +            userOrderVo.setOrderDetailList(orderDetailService.getOrderDetilListByOrderNo(userOrderVo.getOrderNo()));
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          return userOrderVo;
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -98,7 +97,7 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
 | 
	
		
			
				|  |  |      public UserOrderVo detail(String orderNo) {
 | 
	
		
			
				|  |  |          UserOrderVo userOrderVo = baseMapper.detailByOrderNo(orderNo);
 | 
	
		
			
				|  |  |          if (null != userOrderVo) {
 | 
	
		
			
				|  |  | -            userOrderVo.setOrderDetail(orderDetailService.detail(userOrderVo.getOrderNo()));
 | 
	
		
			
				|  |  | +            userOrderVo.setOrderDetailList(orderDetailService.getOrderDetilListByOrderNo(userOrderVo.getOrderNo()));
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          return userOrderVo;
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -118,27 +117,36 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
 | 
	
		
			
				|  |  |      public HttpResponseResult<UserOrder> executeOrder(OrderReq orderReq) {
 | 
	
		
			
				|  |  |          log.info("订单[创建订单] Req:{}", JSONObject.toJSONString(orderReq));
 | 
	
		
			
				|  |  |          //验证参数,必须验证参数
 | 
	
		
			
				|  |  | -        Function<OrderReq, HttpResponseResult<OrderCreateRes>> checkFunction = orderCreate.get(orderReq.getOrderType());
 | 
	
		
			
				|  |  | -        if (Objects.isNull(checkFunction)) {
 | 
	
		
			
				|  |  | -            return HttpResponseResult.failed("订单商品信息获取失败");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        HttpResponseResult<OrderCreateRes> checkResult = checkFunction.apply(orderReq);
 | 
	
		
			
				|  |  | -        OrderCreateRes createRes = checkResult.getData();
 | 
	
		
			
				|  |  | -        if (!checkResult.getStatus() || null == createRes || !createRes.getRes()) {
 | 
	
		
			
				|  |  | -            log.info("订单[创建订单] Res:{}", JSONObject.toJSONString(checkResult));
 | 
	
		
			
				|  |  | -            return HttpResponseResult.failed("订单商品信息获取失败");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        if (!checkPositiveOrZero(createRes.getOriginalPrice())
 | 
	
		
			
				|  |  | -                || !checkPositiveOrZero(createRes.getExpectPrice())
 | 
	
		
			
				|  |  | -        ) {
 | 
	
		
			
				|  |  | -            return HttpResponseResult.failed("金额校验失败");
 | 
	
		
			
				|  |  | +        List<OrderCreateRes> resList = new ArrayList<>();
 | 
	
		
			
				|  |  | +        for (OrderReq.OrderReqInfo info : orderReq.getOrderInfos()) {
 | 
	
		
			
				|  |  | +            Function<OrderReq.OrderReqInfo, HttpResponseResult<OrderCreateRes>> createFunction = orderCreate.get(info.getGoodType());
 | 
	
		
			
				|  |  | +            if (Objects.isNull(createFunction)) {
 | 
	
		
			
				|  |  | +                return HttpResponseResult.failed("订单商品信息获取失败");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            info.setUserId(orderReq.getUserId());
 | 
	
		
			
				|  |  | +            HttpResponseResult<OrderCreateRes> createResult = createFunction.apply(info);
 | 
	
		
			
				|  |  | +            OrderCreateRes createRes = createResult.getData();
 | 
	
		
			
				|  |  | +            createRes.setGoodType(info.getGoodType());
 | 
	
		
			
				|  |  | +            if (!createResult.getStatus() || null == createRes || !createRes.getRes()) {
 | 
	
		
			
				|  |  | +                log.info("订单[创建订单] Res:{}", JSONObject.toJSONString(createResult));
 | 
	
		
			
				|  |  | +                return HttpResponseResult.failed("订单商品信息获取失败");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            resList.add(createRes);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          //验证成功后,订单入库
 | 
	
		
			
				|  |  | -        UserOrderVo orderVo = insertOrder(orderReq, checkResult.getData());
 | 
	
		
			
				|  |  | +        UserOrderVo orderVo = insertOrder(orderReq, resList);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        List<UserOrderDetailVo> orderDetailList = orderVo.getOrderDetailList();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        for(UserOrderDetailVo orderDetailVo : orderDetailList){
 | 
	
		
			
				|  |  | +            orderDetailVo.setUserId(orderReq.getUserId());
 | 
	
		
			
				|  |  | +            orderDetailVo.setOrderId(orderVo.getId());
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        Consumer<UserOrderVo> afterFunction = orderAfter.get(orderReq.getOrderType());
 | 
	
		
			
				|  |  | -        if (!Objects.isNull(afterFunction)) {
 | 
	
		
			
				|  |  | -            afterFunction.accept(orderVo);
 | 
	
		
			
				|  |  | +            Consumer<UserOrderDetailVo> afterFunction = orderAfter.get(orderDetailVo.getGoodType());
 | 
	
		
			
				|  |  | +            if (!Objects.isNull(afterFunction)) {
 | 
	
		
			
				|  |  | +                afterFunction.accept(orderDetailVo);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          return HttpResponseResult.succeed(orderVo);
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -151,7 +159,7 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
 | 
	
		
			
				|  |  |          if (null == detail || !payReq.getUserId().equals(detail.getUserId())) {
 | 
	
		
			
				|  |  |              return HttpResponseResult.failed("订单不存在");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        if (OrderStatusEnum.WAIT_PAY.equals(detail.getStatus())) {
 | 
	
		
			
				|  |  | +        if (OrderStatusEnum.WAIT_PAY.equals(detail.getStatus()) || OrderStatusEnum.FAIL.equals(detail.getStatus())) {
 | 
	
		
			
				|  |  |              //处于待支付状态,需要调用汇付发起付款请求接口
 | 
	
		
			
				|  |  |              return orderPayWaitPay(payReq, detail);
 | 
	
		
			
				|  |  |          } else if (OrderStatusEnum.PAYING.equals(detail.getStatus())) {
 | 
	
	
		
			
				|  | @@ -171,7 +179,9 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
 | 
	
		
			
				|  |  |                  log.error("汇付支付回调,订单未找到。 req is {}", data);
 | 
	
		
			
				|  |  |                  return;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            if (detail.getStatus().equals(OrderStatusEnum.PAYING)) {
 | 
	
		
			
				|  |  | +            if (!detail.getStatus().equals(OrderStatusEnum.PAID)
 | 
	
		
			
				|  |  | +                    && !detail.getStatus().equals(OrderStatusEnum.WAIT_PAY)
 | 
	
		
			
				|  |  | +                    && !detail.getStatus().equals(OrderStatusEnum.CLOSE)) {
 | 
	
		
			
				|  |  |                  orderSuccess(detail, hfRes);
 | 
	
		
			
				|  |  |              } else {
 | 
	
		
			
				|  |  |                  log.error("汇付支付回调,订单状态异常。 req is {}", data);
 | 
	
	
		
			
				|  | @@ -186,6 +196,9 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
 | 
	
		
			
				|  |  |          List<UserOrderVo> orderList = baseMapper.selectPendingList();
 | 
	
		
			
				|  |  |          for (UserOrderVo userOrder : orderList) {
 | 
	
		
			
				|  |  |              //待支付订单直接取消
 | 
	
		
			
				|  |  | +            if (OrderStatusEnum.FAIL.equals(userOrder.getStatus())) {
 | 
	
		
			
				|  |  | +                failPayOrderHandle(userOrder);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |              if (OrderStatusEnum.WAIT_PAY.equals(userOrder.getStatus())) {
 | 
	
		
			
				|  |  |                  waitPayOrderHandle(userOrder);
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -196,6 +209,16 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /***
 | 
	
		
			
				|  |  | +     * 处理支付失败订单
 | 
	
		
			
				|  |  | +     * @author liweifan
 | 
	
		
			
				|  |  | +     * @param: userOrder
 | 
	
		
			
				|  |  | +     * @updateTime 2022/4/13 16:51
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    private void failPayOrderHandle(UserOrderVo userOrder) {
 | 
	
		
			
				|  |  | +        orderCancel(userOrder);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /***
 | 
	
		
			
				|  |  |       * 处理待支付订单
 | 
	
		
			
				|  |  |       * @author liweifan
 | 
	
		
			
				|  |  |       * @param: userOrder
 | 
	
	
		
			
				|  | @@ -263,15 +286,24 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
 | 
	
		
			
				|  |  |              paymentReq.setExpend(expend);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          //付款请求
 | 
	
		
			
				|  |  | -        Map<String, Object> res = paymentSdk.executePayment(paymentReq);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        OrderPayRes orderPayRes = new OrderPayRes();
 | 
	
		
			
				|  |  | -        orderPayRes.setPay_amt(detail.getActualPrice().setScale(2).toString());
 | 
	
		
			
				|  |  | -        String pay_info = ((JSONObject) res.get("expend")).getString("pay_info");
 | 
	
		
			
				|  |  | -        orderPayRes.setPay_info(pay_info);
 | 
	
		
			
				|  |  | -        //入订单付款表,同时修改订单状态
 | 
	
		
			
				|  |  | -        insertOrderPayment(res, payReq);
 | 
	
		
			
				|  |  | -        return HttpResponseResult.succeed(orderPayRes);
 | 
	
		
			
				|  |  | +        HttpResponseResult<Map<String, Object>> responseResult = paymentSdk.executePayment(paymentReq);
 | 
	
		
			
				|  |  | +        if (responseResult.getStatus()) {
 | 
	
		
			
				|  |  | +            OrderPayRes orderPayRes = new OrderPayRes();
 | 
	
		
			
				|  |  | +            orderPayRes.setPay_amt(detail.getActualPrice().setScale(2).toString());
 | 
	
		
			
				|  |  | +            String pay_info = ((JSONObject) responseResult.getData().get("expend")).getString("pay_info");
 | 
	
		
			
				|  |  | +            orderPayRes.setPay_info(pay_info);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            //入订单付款表,同时修改订单状态
 | 
	
		
			
				|  |  | +            insertOrderPayment(responseResult, payReq);
 | 
	
		
			
				|  |  | +            baseMapper.updateStatusByOrderNo(payReq.getOrderNo(), OrderStatusEnum.PAYING.getCode());
 | 
	
		
			
				|  |  | +            return HttpResponseResult.succeed(orderPayRes);
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            //入订单付款表,同时修改订单状态
 | 
	
		
			
				|  |  | +            insertOrderPayment(responseResult, payReq);
 | 
	
		
			
				|  |  | +            baseMapper.updateStatusByOrderNo(payReq.getOrderNo(), OrderStatusEnum.FAIL.getCode());
 | 
	
		
			
				|  |  | +            return HttpResponseResult.failed(responseResult.getMsg());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /***
 | 
	
	
		
			
				|  | @@ -282,19 +314,23 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
 | 
	
		
			
				|  |  |       * @updateTime 2022/4/13 17:56
 | 
	
		
			
				|  |  |       * @return: com.yonge.cooleshow.biz.dal.entity.UserOrderPayment
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  | -    private UserOrderPayment insertOrderPayment(Map<String, Object> res, OrderPayReq payReq) {
 | 
	
		
			
				|  |  | +    private UserOrderPayment insertOrderPayment(HttpResponseResult<Map<String, Object>> responseResult, OrderPayReq payReq) {
 | 
	
		
			
				|  |  |          UserOrderPayment orderPayment = new UserOrderPayment();
 | 
	
		
			
				|  |  |          orderPayment.setOrderNo(payReq.getOrderNo());
 | 
	
		
			
				|  |  |          orderPayment.setPayChannel(payReq.getPayChannel());
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        orderPayment.setTransNo(res.get("id").toString());
 | 
	
		
			
				|  |  | -        orderPayment.setPayAmt(
 | 
	
		
			
				|  |  | -                new BigDecimal(res.get("pay_amt").toString()).setScale(2)
 | 
	
		
			
				|  |  | -        );
 | 
	
		
			
				|  |  | -        String pay_info = ((JSONObject) res.get("expend")).getString("pay_info");
 | 
	
		
			
				|  |  | -        orderPayment.setPayInfo(pay_info);
 | 
	
		
			
				|  |  | -        orderPayment.setStatus(PayStatusEnum.pending);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +        if (responseResult.getStatus()) {
 | 
	
		
			
				|  |  | +            Map<String, Object> res = responseResult.getData();
 | 
	
		
			
				|  |  | +            orderPayment.setTransNo(res.get("id").toString());
 | 
	
		
			
				|  |  | +            orderPayment.setPayAmt(
 | 
	
		
			
				|  |  | +                    new BigDecimal(res.get("pay_amt").toString()).setScale(2)
 | 
	
		
			
				|  |  | +            );
 | 
	
		
			
				|  |  | +            String pay_info = ((JSONObject) res.get("expend")).getString("pay_info");
 | 
	
		
			
				|  |  | +            orderPayment.setPayInfo(pay_info);
 | 
	
		
			
				|  |  | +            orderPayment.setStatus(PayStatusEnum.pending);
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            orderPayment.setPayFailMsg(responseResult.getMsg());
 | 
	
		
			
				|  |  | +            orderPayment.setStatus(PayStatusEnum.failed);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |          orderPaymentService.save(orderPayment);
 | 
	
		
			
				|  |  |          return orderPayment;
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -326,52 +362,65 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
 | 
	
		
			
				|  |  |       * @updateTime 2022/3/31 16:15
 | 
	
		
			
				|  |  |       * @return: com.yonge.cooleshow.biz.dal.entity.Order
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  | -    private UserOrderVo insertOrder(OrderReq orderReq, OrderCreateRes data) {
 | 
	
		
			
				|  |  | +    private UserOrderVo insertOrder(OrderReq orderReq, List<OrderCreateRes> resList) {
 | 
	
		
			
				|  |  |          UserOrder userOrder = new UserOrder();
 | 
	
		
			
				|  |  |          //订单号生成
 | 
	
		
			
				|  |  |          Long orderNo = idGeneratorService.generatorId("userOrder");
 | 
	
		
			
				|  |  |          userOrder.setOrderNo(orderNo.toString());
 | 
	
		
			
				|  |  |          userOrder.setUserId(orderReq.getUserId());
 | 
	
		
			
				|  |  | -        userOrder.setMerchId(data.getMerchId());
 | 
	
		
			
				|  |  |          userOrder.setOrderName(orderReq.getOrderName());
 | 
	
		
			
				|  |  | +        userOrder.setOrderType(orderReq.getOrderType());
 | 
	
		
			
				|  |  |          userOrder.setOrderDesc(orderReq.getOrderDesc());
 | 
	
		
			
				|  |  |          userOrder.setStatus(OrderStatusEnum.WAIT_PAY);
 | 
	
		
			
				|  |  | -        userOrder.setOriginalPrice(data.getOriginalPrice());
 | 
	
		
			
				|  |  | -        userOrder.setExpectPrice(data.getExpectPrice());
 | 
	
		
			
				|  |  | +        userOrder.setUserNote(orderReq.getUserNote());
 | 
	
		
			
				|  |  | +        userOrder.setCreateTime(new Date());
 | 
	
		
			
				|  |  | +        userOrder.setOriginalPrice(new BigDecimal(0));
 | 
	
		
			
				|  |  | +        userOrder.setExpectPrice(new BigDecimal(0));
 | 
	
		
			
				|  |  | +        userOrder.setPlantformFee(new BigDecimal(0));
 | 
	
		
			
				|  |  | +        List<UserOrderDetailVo> orderDetailList = new ArrayList<>();
 | 
	
		
			
				|  |  | +        for (OrderCreateRes res : resList) {
 | 
	
		
			
				|  |  | +            UserOrderDetailVo orderDetail = new UserOrderDetailVo();
 | 
	
		
			
				|  |  | +            orderDetail.setOrderNo(userOrder.getOrderNo());
 | 
	
		
			
				|  |  | +            orderDetail.setMerchId(res.getMerchId());
 | 
	
		
			
				|  |  | +            orderDetail.setGoodType(res.getGoodType());
 | 
	
		
			
				|  |  | +            orderDetail.setBizId(res.getBizId());
 | 
	
		
			
				|  |  | +            orderDetail.setBizContent(res.getBizContent());
 | 
	
		
			
				|  |  | +            orderDetail.setOriginalPrice(null != res.getOriginalPrice() ? res.getOriginalPrice() : new BigDecimal(0));
 | 
	
		
			
				|  |  | +            orderDetail.setExpectPrice(null != res.getExpectPrice() ? res.getExpectPrice() : new BigDecimal(0));
 | 
	
		
			
				|  |  | +            orderDetail.setGoodNum(null != res.getGoodNum() ? res.getGoodNum() : 1);
 | 
	
		
			
				|  |  | +            //商品单价计算,使用商品原价计算,退费计算公式(退费金额=实际订单金额-(商品单价 * 已经使用商品数))
 | 
	
		
			
				|  |  | +            //其中,已经使用的商品单价按照原价算
 | 
	
		
			
				|  |  | +            orderDetail.setGoodPrice(
 | 
	
		
			
				|  |  | +                    orderDetail.getOriginalPrice().divide(new BigDecimal(orderDetail.getGoodNum())).setScale(2)
 | 
	
		
			
				|  |  | +            );
 | 
	
		
			
				|  |  | +            //平台服务费
 | 
	
		
			
				|  |  | +            BigDecimal serviceFeeRate = getServiceFeeRate(res.getGoodType());
 | 
	
		
			
				|  |  | +            orderDetail.setPlantformFee(userOrder.getActualPrice().multiply(serviceFeeRate));
 | 
	
		
			
				|  |  | +            orderDetail.setPlantformFeeRate(serviceFeeRate);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            orderDetail.setCreateTime(new Date());
 | 
	
		
			
				|  |  | +            orderDetailService.save(orderDetail);
 | 
	
		
			
				|  |  | +            orderDetailList.add(orderDetail);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            userOrder.setOriginalPrice(userOrder.getOriginalPrice().add(orderDetail.getOriginalPrice()));
 | 
	
		
			
				|  |  | +            userOrder.setExpectPrice(userOrder.getExpectPrice().add(orderDetail.getExpectPrice()));
 | 
	
		
			
				|  |  | +            userOrder.setPlantformFee(userOrder.getPlantformFee().add(orderDetail.getPlantformFee()));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          //todo 优惠券优惠金额,暂时为0
 | 
	
		
			
				|  |  |          BigDecimal couponAmount = new BigDecimal(0);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        userOrder.setActualPrice(data.getExpectPrice().subtract(couponAmount).setScale(2));
 | 
	
		
			
				|  |  | +        userOrder.setActualPrice(userOrder.getExpectPrice().subtract(couponAmount).setScale(2));
 | 
	
		
			
				|  |  |          userOrder.setCouponAmount(couponAmount);
 | 
	
		
			
				|  |  | -        //平台服务费
 | 
	
		
			
				|  |  | -        BigDecimal serviceFeeRate = getServiceFeeRate(orderReq.getOrderType());
 | 
	
		
			
				|  |  | -        userOrder.setPlantformFee(userOrder.getActualPrice().multiply(serviceFeeRate));
 | 
	
		
			
				|  |  | -        userOrder.setPlantformFeeRate(serviceFeeRate);
 | 
	
		
			
				|  |  | -        userOrder.setUserNote(orderReq.getUserNote());
 | 
	
		
			
				|  |  | -        userOrder.setOrderType(orderReq.getOrderType());
 | 
	
		
			
				|  |  | -        userOrder.setCreateTime(new Date());
 | 
	
		
			
				|  |  | +        if (userOrder.getActualPrice().subtract(orderReq.getActualPrice()).abs()
 | 
	
		
			
				|  |  | +                .compareTo(new BigDecimal(0.01)) > 0) {
 | 
	
		
			
				|  |  | +            throw new BizException("交易金额异常");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          int insert = baseMapper.insert(userOrder);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          if (insert == 0 || null == userOrder.getId()) {
 | 
	
		
			
				|  |  |              throw new BizException("插入失败");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        UserOrderDetail orderDetail = new UserOrderDetail();
 | 
	
		
			
				|  |  | -        orderDetail.setOrderNo(userOrder.getOrderNo());
 | 
	
		
			
				|  |  | -        orderDetail.setBizId(data.getBizId());
 | 
	
		
			
				|  |  | -        orderDetail.setBizContent(data.getBizContent());
 | 
	
		
			
				|  |  | -        if (null != data.getGoodNum()) {
 | 
	
		
			
				|  |  | -            orderDetail.setGoodNum(data.getGoodNum());
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        //商品单价计算,使用商品原价计算,退费计算公式(退费金额=实际订单金额-(商品单价 * 已经使用商品数))
 | 
	
		
			
				|  |  | -        //其中,已经使用的商品单价按照原价算
 | 
	
		
			
				|  |  | -        orderDetail.setGoodPrice(
 | 
	
		
			
				|  |  | -                data.getOriginalPrice().divide(new BigDecimal(data.getGoodNum())).setScale(2)
 | 
	
		
			
				|  |  | -        );
 | 
	
		
			
				|  |  | -        orderDetail.setCreateTime(new Date());
 | 
	
		
			
				|  |  | -        orderDetailService.save(orderDetail);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |          UserOrderVo vo = new UserOrderVo();
 | 
	
		
			
				|  |  |          try {
 | 
	
		
			
				|  |  |              BeanUtils.copyProperties(vo, userOrder);
 | 
	
	
		
			
				|  | @@ -379,7 +428,7 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
 | 
	
		
			
				|  |  |              e.printStackTrace();
 | 
	
		
			
				|  |  |              throw new BizException("对象转换失败");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        vo.setOrderDetail(orderDetail);
 | 
	
		
			
				|  |  | +        vo.setOrderDetailList(orderDetailList);
 | 
	
		
			
				|  |  |          return vo;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -390,15 +439,15 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
 | 
	
		
			
				|  |  |       * @updateTime 2022/3/31 16:49
 | 
	
		
			
				|  |  |       * @return: java.math.BigDecimal
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  | -    private BigDecimal getServiceFeeRate(OrderTypeEnum orderTypeEnum) {
 | 
	
		
			
				|  |  | +    private BigDecimal getServiceFeeRate(GoodTypeEnum goodTypeEnum) {
 | 
	
		
			
				|  |  |          String configValue = "0";
 | 
	
		
			
				|  |  | -        if (OrderTypeEnum.VIDEO.equals(orderTypeEnum)) {
 | 
	
		
			
				|  |  | +        if (GoodTypeEnum.VIDEO.equals(goodTypeEnum)) {
 | 
	
		
			
				|  |  |              configValue = sysConfigService.findConfigValue(SysConfigConstant.VIDEO_LESSON_SERVICE_FEE);
 | 
	
		
			
				|  |  | -        } else if (OrderTypeEnum.PRACTICE.equals(orderTypeEnum)) {
 | 
	
		
			
				|  |  | +        } else if (GoodTypeEnum.PRACTICE.equals(goodTypeEnum)) {
 | 
	
		
			
				|  |  |              configValue = sysConfigService.findConfigValue(SysConfigConstant.PRACTICE_SERVICE_FEE);
 | 
	
		
			
				|  |  | -        } else if (OrderTypeEnum.LIVE.equals(orderTypeEnum)) {
 | 
	
		
			
				|  |  | +        } else if (GoodTypeEnum.LIVE.equals(goodTypeEnum)) {
 | 
	
		
			
				|  |  |              configValue = sysConfigService.findConfigValue(SysConfigConstant.LIVE_SERVICE_RATE);
 | 
	
		
			
				|  |  | -        } else if (OrderTypeEnum.MUSIC.equals(orderTypeEnum)) {
 | 
	
		
			
				|  |  | +        } else if (GoodTypeEnum.MUSIC.equals(goodTypeEnum)) {
 | 
	
		
			
				|  |  |              configValue = sysConfigService.findConfigValue(SysConfigConstant.MUSIC_SHEET_SERVICE_FEE);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          return new BigDecimal(configValue).divide(new BigDecimal(100));
 | 
	
	
		
			
				|  | @@ -429,12 +478,18 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
 | 
	
		
			
				|  |  |          if (null != orderPayment) {
 | 
	
		
			
				|  |  |              //更新付款单
 | 
	
		
			
				|  |  |              orderPayment.setStatus(PayStatusEnum.failed);
 | 
	
		
			
				|  |  | +            orderPayment.setPayFailMsg("交易取消");
 | 
	
		
			
				|  |  |              orderPaymentService.updateById(orderPayment);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        //调用业务
 | 
	
		
			
				|  |  | -        Consumer<UserOrderVo> userOrderVoConsumer = orderCancel.get(userOrder.getOrderType());
 | 
	
		
			
				|  |  | -        if (!Objects.isNull(userOrderVoConsumer)) {
 | 
	
		
			
				|  |  | -            userOrderVoConsumer.accept(userOrder);
 | 
	
		
			
				|  |  | +        List<UserOrderDetailVo> orderDetailList = orderDetailService.getOrderDetilListByOrderNo(userOrder.getOrderNo());
 | 
	
		
			
				|  |  | +        for(UserOrderDetailVo orderDetailVo : orderDetailList){
 | 
	
		
			
				|  |  | +            orderDetailVo.setUserId(userOrder.getUserId());
 | 
	
		
			
				|  |  | +            orderDetailVo.setOrderId(userOrder.getId());
 | 
	
		
			
				|  |  | +            //调用业务
 | 
	
		
			
				|  |  | +            Consumer<UserOrderDetailVo> userOrderVoConsumer = orderCancel.get(orderDetailVo.getGoodType());
 | 
	
		
			
				|  |  | +            if (!Objects.isNull(userOrderVoConsumer)) {
 | 
	
		
			
				|  |  | +                userOrderVoConsumer.accept(orderDetailVo);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -468,10 +523,16 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          orderPaymentService.updateById(orderPayment);
 | 
	
		
			
				|  |  | -        //调用业务
 | 
	
		
			
				|  |  | -        Consumer<UserOrderVo> userOrderVoConsumer = orderSuccess.get(detail.getOrderType());
 | 
	
		
			
				|  |  | -        if (!Objects.isNull(userOrderVoConsumer)) {
 | 
	
		
			
				|  |  | -            userOrderVoConsumer.accept(detail);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        List<UserOrderDetailVo> orderDetailList = orderDetailService.getOrderDetilListByOrderNo(detail.getOrderNo());
 | 
	
		
			
				|  |  | +        for(UserOrderDetailVo orderDetailVo : orderDetailList){
 | 
	
		
			
				|  |  | +            orderDetailVo.setUserId(detail.getUserId());
 | 
	
		
			
				|  |  | +            orderDetailVo.setOrderId(detail.getId());
 | 
	
		
			
				|  |  | +            //调用业务
 | 
	
		
			
				|  |  | +            Consumer<UserOrderDetailVo> userOrderVoConsumer = orderSuccess.get(orderDetailVo.getGoodType());
 | 
	
		
			
				|  |  | +            if (!Objects.isNull(userOrderVoConsumer)) {
 | 
	
		
			
				|  |  | +                userOrderVoConsumer.accept(orderDetailVo);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  }
 |