package com.haha.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.haha.entity.DistributorReferral;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface DistributorReferralMapper extends BaseMapper<DistributorReferral> {

    @Select("SELECT COUNT(*) FROM t_distributor_referral WHERE user_id = #{userId}")
    int countByUserId(@Param("userId") Long userId);

    @Select("SELECT * FROM t_distributor_referral WHERE user_id = #{userId} LIMIT 1")
    DistributorReferral selectByUserId(@Param("userId") Long userId);

    @Select("SELECT COUNT(*) FROM t_distributor_referral WHERE distributor_id = #{distributorId} AND user_id = #{userId}")
    int countByDistributorAndUser(@Param("distributorId") Long distributorId, @Param("userId") Long userId);
}
