admin
2020-01-18 26f41e1a5c34a3e36c9e73c237e3643e707924ce
商城订单失效退还红包
5个文件已修改
124 ■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderMoneySettleServiceImpl.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopOrderPayServiceImpl.java 57 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopOrderServiceImpl.java 20 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/shop/BanLiShopOrderPayService.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/util/rocketmq/consumer/order/BanLiShopOrderMessageListener.java 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderMoneySettleServiceImpl.java
@@ -114,6 +114,15 @@
    @Resource
    private HongBaoV2SettleTempService hongBaoV2SettleTempService;
    //下级被封禁,红包失效
    private void invalidHongBaoForbidden(Long id) {
        HongBaoV2 updateHongBaoV2 = new HongBaoV2(id);
        updateHongBaoV2.setState(HongBaoV2.STATE_SHIXIAO);
        updateHongBaoV2.setBeizhu("封禁失效");
        updateHongBaoV2.setUpdateTime(new Date());
        hongBaoV2Mapper.updateByPrimaryKeySelective(updateHongBaoV2);
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void inviteSettleTB(Long uid) throws OrderMoneySettleException {
@@ -145,6 +154,7 @@
                        // 上级用户不是正常用户,订单均不能到账
                        UserInfo userInfo = userInfoMapper.selectAvailableByPrimaryKey(co.getUserInfo().getId());
                        if (userInfo == null || userInfo.getState() != UserInfo.STATE_NORMAL) {
                            invalidHongBaoForbidden(item.getId());
                            hongBaoList.remove(i);
                            i--;
                        }
@@ -210,6 +220,7 @@
                        // 上级用户不是正常用户,订单均不能到账
                        UserInfo userInfo = userInfoMapper.selectAvailableByPrimaryKey(co.getUserInfo().getId());
                        if (userInfo == null || userInfo.getState() != UserInfo.STATE_NORMAL) {
                            invalidHongBaoForbidden(item.getId());
                            hongBaoList.remove(i);
                            i--;
                        }
@@ -269,6 +280,7 @@
                        // 上级用户不是正常用户,订单均不能到账
                        UserInfo userInfo = userInfoMapper.selectAvailableByPrimaryKey(co.getUserInfo().getId());
                        if (userInfo == null || userInfo.getState() != UserInfo.STATE_NORMAL) {
                            invalidHongBaoForbidden(item.getId());
                            hongBaoList.remove(i);
                            i--;
                        }
@@ -479,7 +491,7 @@
                        Long uid = its.next();
                        if (userSubMoneyMap.get(uid) != null) {
                            // 减去维权资金
                            userMoney.put(uid, userMoney.get(uid).subtract(userSubMoneyMap.get(uid)));
                            userMoney.put(uid, userMoney.get(uid).subtract(userSubMoneyMap.get(uid)));
                        }
                    }
                }
fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopOrderPayServiceImpl.java
@@ -73,10 +73,10 @@
    @Resource
    private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
    @Resource
    private ConfigService configService;
    @Resource
    private AdminUserService adminUserService;
@@ -132,7 +132,7 @@
        }
    }
    @Transactional(rollbackFor=Exception.class)
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void payOrderByMoney(Long orderId, BigDecimal money) throws BanLiShopOrderException {
        BanLiShopOrder order = banLiShopOrderService.selectByPrimaryKeyForUpdate(orderId);
@@ -176,7 +176,7 @@
     */
    private void paySuccess(BanLiShopOrder order) {
        ThreadUtil.run(new Runnable() {
            @Override
            public void run() {
                long[] targetUids = new long[] { 3L, 4L };
@@ -191,11 +191,10 @@
                }
            }
        });
    }
    @Transactional(rollbackFor=Exception.class)
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void refund(Long orderId) throws BanLiShopOrderException {
        // 订单退款
@@ -392,4 +391,48 @@
        }
    }
    @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);
        }
    }
}
fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopOrderServiceImpl.java
@@ -91,12 +91,11 @@
    @Resource
    private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
    @Resource
    private RedPackForbidService redPackForbidService;
    @Transactional(rollbackFor=Exception.class)
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void addOrder(BanLiShopOrder order) throws BanLiShopOrderException {
        // 查询必要的参数是否添加
@@ -224,7 +223,7 @@
        banLiShopOrderMapper.updateByPrimaryKeySelective(order);
    }
    @Transactional(rollbackFor=Exception.class)
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void payOrderByHongBao(Long orderId) throws BanLiShopOrderException, RedPackBalanceException {
        BanLiShopOrder order = banLiShopOrderMapper.selectByPrimaryKeyForUpdate(orderId);
@@ -329,6 +328,7 @@
        return banLiShopOrderMapper.selectByPrimaryKeyForUpdate(id);
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void invalidOrderByOrderId(Long id, String desc) {
        // 判断订单是否存在
@@ -347,8 +347,8 @@
                    if (isS)// 支付成功,重新发送支付成功消息
                    {
                        BanLiShopOrderMQMsg msg = new BanLiShopOrderMQMsg(order.getId(), order.getUid());
                        Message message =MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER,
                                OrderTopicTagEnum.banLiShopOrderPaid,msg);
                        Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER,
                                OrderTopicTagEnum.banLiShopOrderPaid, msg);
                        producer.send(message);
                        return;
                    }
@@ -379,8 +379,8 @@
        if (order.getState() != BanLiShopOrder.STATE_PAID)
            throw new BanLiShopOrderException(1, "订单未处于待审核状态");
        Message message =MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.banLiShopOrderRefund,
            new BanLiShopOrderMQMsg(order.getId(), order.getUid()));
        Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.banLiShopOrderRefund,
                new BanLiShopOrderMQMsg(order.getId(), order.getUid()));
        try {
            orderTransactionProducer.send(message, new LocalTransactionExecuter() {
                @Override
@@ -440,9 +440,9 @@
            throw new BanLiShopOrderException(22, "商品已下线");
        }
        if(redPackForbidService.verifyForbid(uid))
        if (redPackForbidService.verifyForbid(uid))
            throw new BanLiShopOrderException(25, "红包功能已被封禁");
        if (pay.getHongBaoPrice() != null && pay.getHongBaoPrice().compareTo(new BigDecimal(0)) > 0) {
            BigDecimal money = redPackBalanceService.getBalance(uid);
            if (money.compareTo(pay.getHongBaoPrice()) < 0) {
fanli/src/main/java/com/yeshi/fanli/service/inter/shop/BanLiShopOrderPayService.java
@@ -45,4 +45,16 @@
     * @throws BanLiShopOrderException
     */
    public void charge(Long orderId) throws BanLiShopOrderException;
    /**
     * 验证订单失效状态
     * @Title: invalidOrderByOrderId
     * @Description:
     * @param orderId
     * @param stateDesc
     * void 返回类型
     * @throws
     */
    public void invalidOrderByOrderId(Long orderId, String stateDesc) throws BanLiShopOrderException;
}
fanli/src/main/java/com/yeshi/fanli/util/rocketmq/consumer/order/BanLiShopOrderMessageListener.java
@@ -39,9 +39,9 @@
    @Override
    public Action consume(Message message, ConsumeContext context) {
        LogHelper.mqInfo("consumer:BanLiShopOrderMessageListener",message.getMsgID(), message.getTopic(), message.getTag(),
                new String(message.getBody()));
        LogHelper.mqInfo("consumer:BanLiShopOrderMessageListener", message.getMsgID(), message.getTopic(),
                message.getTag(), new String(message.getBody()));
        String tag = message.getTag();
        if (MQTopicName.TOPIC_ORDER.name().equalsIgnoreCase(message.getTopic())) {
@@ -49,9 +49,16 @@
                BanLiShopOrderMQMsg banLiShopOrderMQMsg = new Gson().fromJson(new String(message.getBody()),
                        BanLiShopOrderMQMsg.class);
                if (banLiShopOrderMQMsg != null)
                    // 使订单失效
                    banLiShopOrderService.invalidOrderByOrderId(banLiShopOrderMQMsg.getOrderId(), "订单失效-长期未付款");
                return Action.CommitMessage;
                    try {
                        banLiShopOrderPayService.invalidOrderByOrderId(banLiShopOrderMQMsg.getOrderId(), "订单失效-长期未付款");
                        return Action.CommitMessage;
                    } catch (BanLiShopOrderException e) {
                        e.printStackTrace();
                        return Action.CommitMessage;
                    } catch (Exception e) {
                        return Action.ReconsumeLater;
                    }
            } else if (tag.equalsIgnoreCase(OrderTopicTagEnum.banLiShopOrderPaid.name()))// 商城订单付款成功
            {
                BanLiShopOrderMQMsg msg = new Gson().fromJson(new String(message.getBody()), BanLiShopOrderMQMsg.class);
@@ -71,7 +78,7 @@
                }
                return Action.CommitMessage;
            }
        }
        return Action.CommitMessage;
    }