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

import com.fzm.mall.server.front.goods.model.Sku;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fzm.mall.server.front.goods.model.vo.SkuVo;
import com.fzm.mall.server.front.order.model.vo.ShopInfoVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 商品规格表 Mapper 接口
 * </p>
 *
 * @author fzm
 * @since 2021-03-09
 */
public interface SkuMapper extends BaseMapper<Sku> {
    @Select("select * from goods_sku where goods_id = #{goodsId} and status = 1")
    List<SkuVo> getByGoodsIs(@Param("goodsId") String goodsId);

    @Select("select goods_id from goods_sku where sku_id = #{skuId}")
    String getGoodsIdByskuId(@Param("skuId") String skuId);

    @Select("select a.*,b.type,b.name as name, b.merchant_id as merchantId,c.enterprise_name as merchantName  from goods_sku a left join goods_spu b on a.goods_id = b.goods_id left join  merchant c on b.merchant_id = c.merchant_id where a.sku_id = #{skuId}")
    SkuVo getBySkuId(@Param("skuId") String skuId);

    @Select("select address_name as addr,contact_name as name,contact_phone as phone from distribution_address where address_id = #{addressId} ")
    ShopInfoVo getShopInfoVo(@Param("addressId") String addressId);

    @Select("select exp_name from distribution_express where simple_name = #{returnExpressName}")
    String getExpressName(@Param("returnExpressName") String returnExpressName);

    @Select("select  b.merchant_id as merchantId  from goods_sku a left join goods_spu b on a.goods_id = b.goods_id left join  merchant c on b.merchant_id = c.merchant_id where a.sku_id = #{skuId}")
    String getSidBySkuId(@Param("skuId") String skuId);

    @Select("select token_id from external_token where label_name = #{coin} limit 1")
    Long getTrueCoin(@Param("coin") String coin);
}
