<?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="cn.reghao.tnb.content.app.chat.db.mapper.HongbaoMapper">
    <insert id="save" useGeneratedKeys="true" keyProperty="id">
        insert into chat_hongbao
        (`hongbao_id`,`receiver_type`,`receiver_id`,`amount`,`num`,`remain`,`remark`,`create_by`,`create_at`)
        values
        (#{hongbaoId},#{receiverType},#{receiverId},#{amount},#{num},#{remain},#{remark},#{createBy},#{createAt})
    </insert>

    <update id="updateHongbaoRemainDecr">
        update chat_hongbao
        set remain=if(remain &lt; 1, 0, remain-1)
        where hongbao_id=#{hongbaoId}
    </update>
    
    <select id="findHongbaoById" resultType="cn.reghao.tnb.content.app.chat.model.po.Hongbao">
        select *
        from chat_hongbao
        where hongbao_id=#{hongbaoId}
    </select>
</mapper>
