package com.jeequan.jeepay.service.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jeequan.jeepay.db.entity.RedPacketInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 红包记录 Mapper 接口
 * </p>
 *
 * @author [mybatis plus generator]
 * @since 2024-01-18
 */
public interface RedPacketInfoMapper extends BaseMapper<RedPacketInfo> {

    @Select("SELECT * FROM t_red_packet_info WHERE mch_no = #{mchNo} and store_id = #{storeId} and pay_user_id = #{payUserId} and state in (1,2) and expire_time > now()")
    RedPacketInfo getRedPaketData(@Param("mchNo") String mchNo, @Param("storeId") String storeId, @Param("payUserId") String payUserId);

    @Select("SELECT * FROM t_red_packet_info WHERE expire_time <= now() and state in (1,2)")
    List<RedPacketInfo> listRedPacketByExpire();

    @Update("UPDATE t_red_packet_info SET `state` = #{state},remark = #{remark} WHERE flow_no = #{flowNo}")
    int updateRedExpire(@Param("flowNo") String flowNo, @Param("state") byte expire,@Param("remark") String remark);
}
