Helius
2022-05-27 54cc7a8fb98d345fc2b97c895598b24d8b47d705
充值卡订单欠款检测
3 files modified
30 ■■■■■ changed files
zq-erp/src/main/java/com/matrix/system/hive/dao/MoneyCardUseFlowDao.java 2 ●●●●● patch | view | raw | blame | history
zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysOrderServiceImpl.java 22 ●●●●● patch | view | raw | blame | history
zq-erp/src/main/resources/mybatis/mapper/hive/MoneyCardUseFlowDao.xml 6 ●●●●● patch | view | raw | blame | history
zq-erp/src/main/java/com/matrix/system/hive/dao/MoneyCardUseFlowDao.java
@@ -35,5 +35,7 @@
    public MoneyCardUseFlow  selectById(Long id);
    int updateVipCardId(@Param("vipId") Long vipId, @Param("cardId") Long cardId);
    double selectCardUseAmount(Long cardId);
    
}
zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysOrderServiceImpl.java
@@ -925,6 +925,28 @@
            }
        });
        // 充值卡订单欠款检测
        if (Dictionary.FLAG_NO_N.equals(moneyCardUse.getIsVipCar())) {
            SysOrder sysOrder = sysOrderDao.selectById(orderItemDao.selectById(moneyCardUse.getOrderItemId()).getOrderId());
            if (Dictionary.ORDER_STATU_QK.equals(sysOrder.getStatu())) {
                if (SysOrderFlow.IS_GIFT_Y.equals(flow.getIsGift())) {
                    throw new GlobleException("充值卡订单存在欠款,无法使用赠送余额支付");
                }
                // 若该笔订单中,有多项明细,则充值卡直接无法支付; 若订单中,仅充值卡一项,则已付款和充值卡使用情况判断是否可使用
                List<SysOrderItem> items = orderItemDao.selectByOrderId(sysOrder.getId());
                if (items.size() > 1) {
                    throw new GlobleException("充值卡订单存在欠款,无法支付");
                } else {
                    double totalUse = moneyCardUseFlowDao.selectCardUseAmount(moneyCardUse.getId());
                    Double hasPay = sysOrder.getZkTotal() - sysOrder.getArrears();
                    if (hasPay < (totalUse + flow.getAmount().doubleValue())) {
                        throw new GlobleException("充值卡订单存在欠款,已支付金额不足");
                    }
                }
            }
         }
        SysUsers user = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY);
        MoneyCardUseFlow moneyCardUseFlow = new MoneyCardUseFlow();
zq-erp/src/main/resources/mybatis/mapper/hive/MoneyCardUseFlowDao.xml
@@ -366,6 +366,12 @@
            set car_use_id=#{cardId}
        where vip_id=#{vipId} and type='会员充值'
    </update>
    <select id="selectCardUseAmount" resultType="java.lang.Double">
        select IFNULL(ABS(sum(IFNULL(total, 0))), 0)
        from money_card_use_flow
        where car_use_id=#{cardId} and type='消费扣款'
    </select>
</mapper>