package com.fzm.mall.server.front.goods.mapper;

import com.fzm.mall.server.front.goods.model.MarketingCoupon;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fzm.mall.server.front.goods.model.vo.UserCouponVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * <p>
 * 商品优惠券 Mapper 接口
 * </p>
 *
 * @author fzm
 * @since 2021-03-09
 */
public interface MarketingCouponMapper extends BaseMapper<MarketingCoupon> {
    @Select("select b.* from marketing_coupon_sku a left join marketing_coupon b on a.coupon_id = b.coupon_id where a.goods_id = #{goodsId} and b.circulation = 0 or (b.circulation !=0 and b.amt >0) and b.scope in (1,${type})")
    List<MarketingCoupon> getByGoodsId(@Param("goodsId") String goodsId,@Param("type") Integer type);
    @Select("select * from marketing_coupon where coupon_id = #{couponId} and scope in (1,${type})")
    MarketingCoupon getByCouponId(@Param("couponId") String couponId,@Param("type") Integer type);
    @Select("select goods_id from marketing_coupon_sku where coupon_id = #{couponId}")
    String getGoodsId(@Param("couponId") String couponId);

    @Select("select * from marketing_coupon where merchant_id = #{merchantId} and status = 1 and scope in (1,#{type}) and start_time <= #{time} and end_time>=#{time} order by create_time desc ")
    List<UserCouponVo> getByMerchantId(@Param("merchantId") String merchantId, @Param("time") long currentTimeMillis,@Param("type")Integer type);

    @Select("select count(*) from marketing_coupon where merchant_id = #{merchantId} and status = 1 and scope in (1,#{type}) and start_time <= #{time} and end_time>=#{time}")
    Integer getCount(@Param("merchantId") String merchantId, @Param("time") long currentTimeMillis,@Param("type")Integer type);
}
