admin
2020-07-14 eec7e789a87863c25d92c10ad5dfc22ad80c448d
fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopOrderPayServiceImpl.java
@@ -5,17 +5,37 @@
import javax.annotation.Resource;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.yeshi.utils.NumberUtil;
import org.yeshi.utils.exception.WXOrderException;
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.Producer;
import com.aliyun.openservices.ons.api.SendResult;
import com.google.gson.Gson;
import com.yeshi.fanli.dto.mq.order.OrderTopicTagEnum;
import com.yeshi.fanli.dto.mq.order.body.BanLiShopOrderMQMsg;
import com.yeshi.fanli.dto.msg.MsgRedPackUseContentDTO;
import com.yeshi.fanli.entity.bus.msg.MsgMoneyDetail.MsgTypeMoneyTypeEnum;
import com.yeshi.fanli.entity.common.AdminUser;
import com.yeshi.fanli.entity.common.Config;
import com.yeshi.fanli.entity.redpack.RedPackDetail;
import com.yeshi.fanli.entity.shop.BanLiShopGoods;
import com.yeshi.fanli.entity.shop.BanLiShopGoodsClass;
import com.yeshi.fanli.entity.shop.BanLiShopGoodsSets;
import com.yeshi.fanli.entity.shop.BanLiShopOrder;
import com.yeshi.fanli.entity.shop.ChargeTypeEnum;
import com.yeshi.fanli.entity.system.ConfigKeyEnum;
import com.yeshi.fanli.exception.redpack.RedPackBalanceException;
import com.yeshi.fanli.exception.redpack.RedPackDetailException;
import com.yeshi.fanli.exception.shop.BanLiShopOrderException;
import com.yeshi.fanli.exception.shop.FuLuChargeException;
import com.yeshi.fanli.service.AdminUserService;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.money.msg.UserMoneyMsgNotificationService;
import com.yeshi.fanli.service.inter.redpack.RedPackBalanceService;
import com.yeshi.fanli.service.inter.redpack.RedPackDetailService;
import com.yeshi.fanli.service.inter.shop.BanLiShopGoodsClassService;
@@ -23,133 +43,402 @@
import com.yeshi.fanli.service.inter.shop.BanLiShopGoodsSetService;
import com.yeshi.fanli.service.inter.shop.BanLiShopOrderPayService;
import com.yeshi.fanli.service.inter.shop.BanLiShopOrderService;
import com.yeshi.fanli.service.manger.msg.RocketMQManager;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.ThreadUtil;
import com.yeshi.fanli.util.charge.FuLuChargeApiUtil;
import com.yeshi.fanli.util.email.MailSenderUtil;
import com.yeshi.fanli.util.factory.RedPackDetailFactory;
import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory;
import com.yeshi.fanli.util.rocketmq.MQTopicName;
import com.yeshi.fanli.util.wx.BanLiShopWXPayUtil;
@Service
public class BanLiShopOrderPayServiceImpl implements BanLiShopOrderPayService {
   @Resource
   private BanLiShopGoodsSetService banLiShopGoodsSetService;
    @Resource
    private BanLiShopGoodsSetService banLiShopGoodsSetService;
   @Resource
   private BanLiShopGoodsService banLiShopGoodsService;
    @Resource
    private BanLiShopGoodsService banLiShopGoodsService;
   @Resource
   private BanLiShopGoodsClassService banLiShopGoodsClassService;
    @Resource
    private BanLiShopGoodsClassService banLiShopGoodsClassService;
   @Resource
   private RedPackBalanceService redPackBalanceService;
    @Resource
    private RedPackBalanceService redPackBalanceService;
   @Resource
   private BanLiShopOrderService banLiShopOrderService;
    @Resource
    private BanLiShopOrderService banLiShopOrderService;
   @Resource
   private RedPackDetailService redPackDetailService;
    @Resource
    private RedPackDetailService redPackDetailService;
   @Transactional
   @Override
   public void payOrderByHongBao(Long orderId) throws BanLiShopOrderException, RedPackBalanceException {
      BanLiShopOrder order = banLiShopOrderService.selectByPrimaryKeyForUpdate(orderId);
      if (order == null) {
         throw new BanLiShopOrderException(1, "订单不存在");
      }
      if (order.getHongBaoPayment() == null)
         throw new BanLiShopOrderException(2, "不需要采用红包支付");
    @Resource
    private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
      if (order.getHongBaoPaymentState() != null && order.getHongBaoPaymentState() == BanLiShopOrder.PAY_STATE_PAID) {
         throw new BanLiShopOrderException(3, "重复支付");
      }
    @Resource
    private ConfigService configService;
      BanLiShopGoods goods = banLiShopGoodsService.selectByPrimaryKey(order.getGoods().getId());
      BanLiShopGoodsClass goodsClass = banLiShopGoodsClassService.selectByPrimaryKey(goods.getGoodsClass().getId());
      BanLiShopGoodsSets set = banLiShopGoodsSetService.selectByPrimaryKey(order.getGoodsSet().getId());
      RedPackDetail detail = null;
      try {
         detail = RedPackDetailFactory.createUseByShopOrder(orderId, order.getUid(), goodsClass.getName(),
               set.getName(), order.getHongBaoPayment());
      } catch (RedPackDetailException e) {
         e.printStackTrace();
      }
    @Resource
    private AdminUserService adminUserService;
      if (detail == null)
         throw new RedPackBalanceException(4, "红包详情失败");
      redPackBalanceService.subRedPack(order.getUid(), order.getHongBaoPayment(), detail);
    @Resource
    private RocketMQManager rocketMQManager;
      BanLiShopOrder update = new BanLiShopOrder();
      update.setId(order.getId());
      update.setHongBaoPaymentState(BanLiShopOrder.PAY_STATE_PAID);
      // 判断其他待支付项是否已经支付
      update.setUpdateTime(new Date());
      if (order.getState() == BanLiShopOrder.STATE_NO_PAY)
         if ((order.getBalancePaymentState() == null
               || order.getBalancePaymentState() == BanLiShopOrder.PAY_STATE_PAID)
               && (order.getMoneyPaymentState() == null
                     || order.getMoneyPaymentState() == BanLiShopOrder.PAY_STATE_PAID))// 其他待支付项已经支付
            update.setState(BanLiShopOrder.STATE_PAID);
      banLiShopOrderService.udpateSelectiveByPrimaryKey(update);
      if (update.getState() != null && update.getState() == BanLiShopOrder.STATE_PAID) {
         paySuccess(order);
      }
   }
    @Resource
    private UserInfoService userInfoService;
   @Transactional
   @Override
   public void payOrderByMoney(Long orderId, BigDecimal money) throws BanLiShopOrderException {
      BanLiShopOrder order = banLiShopOrderService.selectByPrimaryKeyForUpdate(orderId);
      if (order == null) {
         throw new BanLiShopOrderException(1, "订单不存在");
      }
      if (order.getMoneyPayment() == null)
         throw new BanLiShopOrderException(2, "不需要采用现金支付");
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void payOrderByHongBao(Long orderId) throws BanLiShopOrderException, RedPackBalanceException {
        BanLiShopOrder order = banLiShopOrderService.selectByPrimaryKeyForUpdate(orderId);
        if (order == null) {
            throw new BanLiShopOrderException(1, "订单不存在");
        }
        if (order.getHongBaoPayment() == null)
            return;
      if (order.getMoneyPaymentState() != null && order.getMoneyPaymentState() == BanLiShopOrder.PAY_STATE_PAID) {
         throw new BanLiShopOrderException(3, "重复支付");
      }
        if (order.getHongBaoPaymentState() != null && order.getHongBaoPaymentState() == BanLiShopOrder.PAY_STATE_PAID) {
            throw new BanLiShopOrderException(3, "重复支付");
        }
      if (order.getMoneyPayment().compareTo(money) > 0) {
         throw new BanLiShopOrderException(4, "支付金额不够");
      }
        BanLiShopGoods goods = banLiShopGoodsService.selectByPrimaryKey(order.getGoods().getId());
        BanLiShopGoodsClass goodsClass = banLiShopGoodsClassService.selectByPrimaryKey(goods.getGoodsClass().getId());
        BanLiShopGoodsSets set = banLiShopGoodsSetService.selectByPrimaryKey(order.getGoodsSet().getId());
        RedPackDetail detail = null;
        try {
            detail = RedPackDetailFactory.createUseByShopOrder(orderId, order.getUid(), goodsClass.getName(),
                    set.getName(), order.getHongBaoPayment());
        } catch (RedPackDetailException e) {
            e.printStackTrace();
        }
      // 支付成功
      BanLiShopOrder update = new BanLiShopOrder();
      update.setId(order.getId());
      update.setMoneyPaymentState(BanLiShopOrder.PAY_STATE_PAID);
      // 判断其他待支付项是否已经支付
      update.setUpdateTime(new Date());
      if (order.getState() == BanLiShopOrder.STATE_NO_PAY)
         if ((order.getBalancePaymentState() == null
               || order.getBalancePaymentState() == BanLiShopOrder.PAY_STATE_PAID)
               && (order.getHongBaoPaymentState() == null
                     || order.getHongBaoPaymentState() == BanLiShopOrder.PAY_STATE_PAID))// 其他待支付项已经支付
            update.setState(BanLiShopOrder.STATE_PAID);
      banLiShopOrderService.udpateSelectiveByPrimaryKey(update);
      if (update.getState() != null && update.getState() == BanLiShopOrder.STATE_PAID) {
         paySuccess(order);
      }
   }
        if (detail == null)
            throw new RedPackBalanceException(4, "红包详情失败");
        redPackBalanceService.subRedPack(order.getUid(), order.getHongBaoPayment(), detail);
   /**
    * 支付成功
    */
   private void paySuccess(BanLiShopOrder order) {
      // 将红包明细外显
      RedPackDetail detail = null;
      try {
         detail = RedPackDetailFactory.createUseByShopOrder(order.getId(), order.getUid(), "", "",
               order.getHongBaoPayment());
      } catch (RedPackDetailException e) {
         e.printStackTrace();
      }
        BanLiShopOrder update = new BanLiShopOrder();
        update.setId(order.getId());
        update.setHongBaoPaymentState(BanLiShopOrder.PAY_STATE_PAID);
        // 判断其他待支付项是否已经支付
        update.setUpdateTime(new Date());
        if (order.getState() == BanLiShopOrder.STATE_NO_PAY)
            if ((order.getBalancePaymentState() == null
                    || order.getBalancePaymentState() == BanLiShopOrder.PAY_STATE_PAID)
                    && (order.getMoneyPaymentState() == null
                    || order.getMoneyPaymentState() == BanLiShopOrder.PAY_STATE_PAID))// 其他待支付项已经支付
            {
                update.setState(BanLiShopOrder.STATE_PAID);
                update.setStateDesc("支付成功");
            }
        banLiShopOrderService.udpateSelectiveByPrimaryKey(update);
        if (update.getState() != null && update.getState() == BanLiShopOrder.STATE_PAID) {
            paySuccess(order);
        }
    }
      if (detail != null) {
         RedPackDetail oldDetail = redPackDetailService.getByIdentifyCode(detail.getIdentifyCode());
         if (oldDetail != null) {// 外显红包详情
            RedPackDetail update = new RedPackDetail();
            update.setId(oldDetail.getId());
            update.setDisplay(true);
            redPackDetailService.updateByPrimaryKeySelective(update);
         }
      }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void payOrderByMoney(Long orderId, BigDecimal money) throws BanLiShopOrderException {
        BanLiShopOrder order = banLiShopOrderService.selectByPrimaryKeyForUpdate(orderId);
        if (order == null) {
            throw new BanLiShopOrderException(1, "订单不存在");
        }
        if (order.getMoneyPayment() == null)
            throw new BanLiShopOrderException(2, "不需要采用现金支付");
   }
        if (order.getMoneyPaymentState() != null && order.getMoneyPaymentState() != BanLiShopOrder.PAY_STATE_NOPAY) {
            throw new BanLiShopOrderException(3, "重复支付");
        }
        if (order.getMoneyPayment().compareTo(money) > 0) {
            throw new BanLiShopOrderException(4, "支付金额不够");
        }
        // 支付成功
        BanLiShopOrder update = new BanLiShopOrder();
        update.setId(order.getId());
        update.setMoneyPaymentState(BanLiShopOrder.PAY_STATE_PAID);
        // 判断其他待支付项是否已经支付
        update.setUpdateTime(new Date());
        if (order.getState() == BanLiShopOrder.STATE_NO_PAY)
            if ((order.getBalancePaymentState() == null
                    || order.getBalancePaymentState() == BanLiShopOrder.PAY_STATE_PAID)
                    && (order.getHongBaoPaymentState() == null
                    || order.getHongBaoPaymentState() == BanLiShopOrder.PAY_STATE_PAID))// 其他待支付项已经支付
            {
                update.setState(BanLiShopOrder.STATE_PAID);
                update.setStateDesc("支付成功");
            }
        banLiShopOrderService.udpateSelectiveByPrimaryKey(update);
        if (update.getState() != null && update.getState() == BanLiShopOrder.STATE_PAID) {
            paySuccess(order);
        }
    }
    /**
     * 支付成功
     */
    private void paySuccess(BanLiShopOrder order) {
        ThreadUtil.run(new Runnable() {
            @Override
            public void run() {
                SystemEnum system = userInfoService.getUserSystem(order.getUid());
                long[] targetUids = new long[]{3L, 4L};
                Config config = configService.getConfig(ConfigKeyEnum.extractCodeEmailFrom.getKey(),system);
                String[] sts = config.getValue().split(",");
                String account = sts[0];
                String pwd = sts[1];
                for (long adminId : targetUids) {
                    AdminUser adminUser = adminUserService.selectByPrimaryKey(adminId);
                    String msg = "有新的红包商城订单";
                    boolean isS = MailSenderUtil.sendEmail(adminUser.getEmail(), account, pwd, "有新的红包商城订单", msg);
                }
            }
        });
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void refund(Long orderId) throws BanLiShopOrderException {
        // 订单退款
        // 查询订单是否已经被拒绝
        BanLiShopOrder order = banLiShopOrderService.selectByPrimaryKeyForUpdate(orderId);
        if (order == null)
            throw new BanLiShopOrderException(1, "订单不存在");
        if (order.getState() == BanLiShopOrder.STATE_REJECT_REFUND_FAIL
                || order.getState() == BanLiShopOrder.STATE_REJECT_REFUND_SUCCESS)
            throw new BanLiShopOrderException(2, "订单未被拒绝/订单已退款");
        BanLiShopOrder update = new BanLiShopOrder();
        update.setId(order.getId());
        if (order.getHongBaoPaymentState() != null && order.getHongBaoPaymentState() == BanLiShopOrder.PAY_STATE_PAID) {
            BanLiShopGoods goods = banLiShopGoodsService.selectByPrimaryKey(order.getGoods().getId());
            BanLiShopGoodsClass goodsClass = banLiShopGoodsClassService
                    .selectByPrimaryKey(goods.getGoodsClass().getId());
            BanLiShopGoodsSets set = banLiShopGoodsSetService.selectByPrimaryKey(order.getGoodsSet().getId());
            // 红包退款
            RedPackDetail detail = null;
            try {
                detail = RedPackDetailFactory.createShopOrderDrawBack(orderId, order.getUid(), goodsClass.getName(),
                        set.getName(), order.getHongBaoPayment());
            } catch (RedPackDetailException e) {
                e.printStackTrace();
            }
            if (detail == null)
                throw new BanLiShopOrderException(4, "红包详情失败");
            try {
                redPackBalanceService.addRedPack(order.getUid(), order.getHongBaoPayment(), detail);
            } catch (RedPackBalanceException e) {
                throw new BanLiShopOrderException(5, "红包退款失败");
            }
            update.setHongBaoPaymentState(BanLiShopOrder.PAY_STATE_REFUND);
            order.setHongBaoPaymentState(BanLiShopOrder.PAY_STATE_REFUND);
        }
        if (order.getMoneyPaymentState() != null && order.getMoneyPaymentState() == BanLiShopOrder.PAY_STATE_PAID) {
            try {
                boolean success = BanLiShopWXPayUtil.refund(order.getOrderNo(), order.getMoneyPayment());
                if (success) {
                    update.setMoneyPaymentState(BanLiShopOrder.PAY_STATE_REFUNDING);
                    order.setMoneyPaymentState(BanLiShopOrder.PAY_STATE_REFUNDING);
                    // 发送退款消息
                    BanLiShopOrderMQMsg msg = new BanLiShopOrderMQMsg(order.getId(), order.getUid());
                    Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER,
                            OrderTopicTagEnum.banLiShopOrderRefund, msg);
                    SendResult result = rocketMQManager.sendNormalMsg(message, 1000 * 60 * 5L, null);
                    if (result == null) {
                        throw new BanLiShopOrderException(8, "消息发送失败");
                    }
                } else
                    throw new BanLiShopOrderException(6, "微信支付退款失败");
            } catch (WXOrderException e) {
                throw new BanLiShopOrderException(6, "微信支付退款失败");
            }
        }
        // 检查 是否退款成功
        if (order.getMoneyPaymentState() != null
                && order.getMoneyPaymentState() == BanLiShopOrder.PAY_STATE_REFUNDING) {
            try {
                boolean isS = BanLiShopWXPayUtil.isRefundSuccess(order.getOrderNo());
                if (isS) {
                    update.setMoneyPaymentState(BanLiShopOrder.PAY_STATE_REFUND);
                    order.setMoneyPaymentState(BanLiShopOrder.PAY_STATE_REFUND);
                }
            } catch (WXOrderException e) {
                throw new BanLiShopOrderException(7, "微信支付退款查询失败");
            }
        }
        if (update.getHongBaoPaymentState() != null || update.getMoneyPaymentState() != null) {
            // 获取整个订单的退款状态
            int state = getRefundState(order);
            update.setState(state);
            update.setUpdateTime(new Date());
            banLiShopOrderService.udpateSelectiveByPrimaryKey(update);
        }
    }
    /**
     * 获取整个退款状态
     *
     * @param order
     * @return
     */
    private int getRefundState(BanLiShopOrder order) {
        int refundCount = 0;
        int refundSuccessCount = 0;
        if (order.getHongBaoPayment() != null) {
            refundCount++;
            if (order.getHongBaoPaymentState() != null
                    && order.getHongBaoPaymentState() == BanLiShopOrder.PAY_STATE_REFUND)
                refundSuccessCount++;
        }
        if (order.getBalancePayment() != null) {
            refundCount++;
            if (order.getBalancePaymentState() != null
                    && order.getBalancePaymentState() == BanLiShopOrder.PAY_STATE_REFUND)
                refundSuccessCount++;
        }
        if (order.getMoneyPayment() != null) {
            refundCount++;
            if (order.getMoneyPaymentState() != null && order.getMoneyPaymentState() == BanLiShopOrder.PAY_STATE_REFUND)
                refundSuccessCount++;
        }
        if (refundCount == refundSuccessCount)
            return BanLiShopOrder.STATE_REJECT_REFUND_SUCCESS;// 退款成功
        else {
            if (refundSuccessCount == 0)
                return BanLiShopOrder.STATE_REJECT;// 退款中
            else
                return BanLiShopOrder.STATE_REJECT_REFUND_PART_SUCCESS;// 部分退款成功
        }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void charge(Long orderId) throws BanLiShopOrderException {
        BanLiShopOrder order = banLiShopOrderService.selectByPrimaryKey(orderId);
        if (order == null)
            throw new BanLiShopOrderException(1, "订单不存在");
        if (order.getState() != BanLiShopOrder.STATE_PAID) {
            throw new BanLiShopOrderException(100, "订单不是处于付款状态");
        }
        if (order.getChargeAccountType() == ChargeTypeEnum.phone) {
            if (!StringUtil.isMobile(order.getChargeAccount())) {
                throw new BanLiShopOrderException(101, "电话号码格式不正确");
            }
        } else if (order.getChargeAccountType() == ChargeTypeEnum.qq) {
            if (!NumberUtil.isNumeric(order.getChargeAccount())) {
                throw new BanLiShopOrderException(101, "QQ号格式错误");
            }
        } else {
            throw new BanLiShopOrderException(102, "非充值商品");
        }
        // 获取福禄的套餐
        BanLiShopGoodsSets set = banLiShopGoodsSetService.selectByPrimaryKey(order.getGoodsSet().getId());
        if (set == null) {
            throw new BanLiShopOrderException(104, "商品套餐已下线");
        }
        if (StringUtil.isNullOrEmpty(set.getChargeFuLuNum())) {
            throw new BanLiShopOrderException(105, "福禄充值ID为空");
        }
        // 改变状态为成功
        BanLiShopOrder update = new BanLiShopOrder(order.getId());
        update.setState(BanLiShopOrder.STATE_SUCCESS);
        update.setStateDesc("充值成功");
        update.setUpdateTime(new Date());
        update.setSuccessTime(new Date());
        banLiShopOrderService.udpateSelectiveByPrimaryKey(update);
        if (order.getHongBaoPayment() != null && order.getHongBaoPayment().compareTo(new BigDecimal(0)) > 0) {
            // 将红包明细外显
            RedPackDetail detail = null;
            try {
                detail = RedPackDetailFactory.createUseByShopOrder(order.getId(), order.getUid(), "", "",
                        order.getHongBaoPayment());
            } catch (RedPackDetailException e) {
                e.printStackTrace();
            }
            if (detail != null) {
                redPackDetailService.changeDisplayByIdentifyCode(detail.getIdentifyCode(), true);
            }
        }
        // 消息发送
        MsgRedPackUseContentDTO dto = new MsgRedPackUseContentDTO();
        dto.setGoodsSetName(order.getOrderGoods().getSetName());
        dto.setHongBao(order.getHongBaoPayment());
        dto.setMoney(order.getMoneyPayment());
        dto.setTime(new Date());
        userMoneyMsgNotificationService.redPackMsg(order.getUid(), MsgTypeMoneyTypeEnum.redPackUseSuccess,
                new Gson().toJson(dto), null);
        try {
            if (Constant.IS_TEST) {
                FuLuChargeApiUtil.shaXiangCharge(set.getChargeFuLuNum(), "banlishop" + order.getOrderNo(),
                        order.getChargeAccount());
            } else
                FuLuChargeApiUtil.charge(set.getChargeFuLuNum(), "banlishop" + order.getOrderNo(),
                        order.getChargeAccount());
        } catch (FuLuChargeException e) {
            throw new BanLiShopOrderException(e.getCode(), e.getMsg());
        }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void invalidOrderByOrderId(Long orderId, String stateDesc) throws BanLiShopOrderException {
        BanLiShopOrder order = banLiShopOrderService.selectByPrimaryKeyForUpdate(orderId);
        if (order == null)
            return;
        // 退款
        if (order.getState() == BanLiShopOrder.STATE_NO_PAY) {// 状态还是未支付
            // 退款红包
            if (order.getHongBaoPaymentState() != null
                    && order.getHongBaoPaymentState() == BanLiShopOrder.PAY_STATE_PAID) {
                BanLiShopGoods goods = banLiShopGoodsService.selectByPrimaryKey(order.getGoods().getId());
                BanLiShopGoodsClass goodsClass = banLiShopGoodsClassService
                        .selectByPrimaryKey(goods.getGoodsClass().getId());
                BanLiShopGoodsSets set = banLiShopGoodsSetService.selectByPrimaryKey(order.getGoodsSet().getId());
                // 红包退款
                RedPackDetail detail = null;
                try {
                    detail = RedPackDetailFactory.createShopOrderDrawBack(orderId, order.getUid(), goodsClass.getName(),
                            set.getName(), order.getHongBaoPayment());
                } catch (RedPackDetailException e) {
                    e.printStackTrace();
                }
                if (detail == null)
                    throw new BanLiShopOrderException(4, "红包详情失败");
                try {
                    redPackBalanceService.addRedPack(order.getUid(), order.getHongBaoPayment(), detail);
                } catch (RedPackBalanceException e) {
                    throw new BanLiShopOrderException(5, "红包退款失败");
                }
                BanLiShopOrder update = new BanLiShopOrder(order.getId());
                update.setHongBaoPaymentState(BanLiShopOrder.PAY_STATE_REFUND);
                update.setUpdateTime(new Date());
                banLiShopOrderService.udpateSelectiveByPrimaryKey(update);
            }
            banLiShopOrderService.invalidOrderByOrderId(orderId, stateDesc);
        }
    }
}