package shop.alien.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import shop.alien.entity.store.LifeCoupon;
import shop.alien.entity.store.vo.LifeCouponVo;

import java.util.List;

public interface PlatformStoreCouponMapper extends BaseMapper<LifeCoupon> {

    @Select("select coupon.id, store.store_name,coupon.stock_qty, coupon.name, user.phone, coupon.created_time,coupon.single_qty, coupon.name, coupon.start_date, coupon.end_date, coupon.status " +
            "from life_coupon coupon " +
            "join store_info store on store.id = coupon.store_id " +
            "join store_user user on store.id = user.store_id " +
            "${ew.customSqlSegment}")
    IPage<LifeCouponVo> getCouponList(IPage<LifeCouponVo> iPage, @Param(Constants.WRAPPER) QueryWrapper<LifeCouponVo> wrapper);


    @Select("select coupon.id, store.store_name,coupon.stock_qty, coupon.name, user.phone, coupon.created_time, coupon.name, coupon.start_date, coupon.end_date, coupon.status " +
            "from life_coupon coupon " +
            "join store_info store on store.id = coupon.store_id " +
            "join store_user user on store.id = user.store_id " +
            "${ew.customSqlSegment}")
    List<LifeCouponVo> getCouponListWithoutPage(@Param(Constants.WRAPPER) QueryWrapper<LifeCouponVo> wrapper);

    @Select("select lc.*,si.store_name,si.store_tel phone\n" +
            "from life_coupon lc \n" +
            "left join store_info si on si.id = lc.store_id \n" +
            "where lc.id = ${id}")
    LifeCouponVo getCouponById(Integer id);
}
