<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.canteen.core.account.v3.mapper.AccWalletInfoMapper">

    <!--    根据客户id 获取钱包信息-->
    <select id="queryAccWalletInfoVOListByCustId" resultType="com.bonus.canteen.core.account.v3.web.vo.AccWalletInfoVO">
        SELECT
        cust_id,
        acc_id,
        wallet_id,
        wallet_bal,
        limit_balance,
        frozen_balance,
        last_subsidy_amount,
        last_subsidy_time
        FROM acc_wallet_info
        WHERE cust_id = #{custId}
    </select>

    <update id="updateAccWalletInfoForUse">
        UPDATE acc_wallet_info
           SET wallet_bal = wallet_bal - #{amount},
               update_id  = #{updateId}
         WHERE cust_id = #{custId}
           AND wallet_id = #{walletId}
    </update>

    <!--    充值修改钱包信息-->
    <update id="updateAccWalletInfoForRecharge">
        UPDATE acc_wallet_info
        SET wallet_bal = wallet_bal + #{amount}
        , update_id  = #{updateId}
        <if test="lastSubsidyAmount != null">
            , last_subsidy_amount = #{lastSubsidyAmount}
            , last_subsidy_time   = #{lastSubsidyTime}
        </if>
        WHERE cust_id = #{custId}
        AND wallet_id = #{walletId}
    </update>
    <!--    钱包冻结修改钱包信息-->
    <update id="updateAccWalletInfoForFrozen">
        UPDATE acc_wallet_info
           SET wallet_bal     = wallet_bal - #{amount},
               frozen_balance = frozen_balance + #{amount}
                   ,
               update_id      = #{updateId}
         WHERE cust_id = #{custId}
           AND wallet_id = #{walletId}
    </update>

    <!--    钱包解冻修改钱包信息-->
    <update id="updateAccWalletInfoForUnFrozen">
        UPDATE acc_wallet_info
           SET wallet_bal     = wallet_bal + #{amount},
               frozen_balance = frozen_balance - #{amount},
               update_id      = #{updateId}
         WHERE cust_id = #{custId}
           AND wallet_id = #{walletId}
    </update>

</mapper>
