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

import com.fzm.mall.server.front.goods.model.Count;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fzm.mall.server.front.goods.model.vo.SaleHotVo;
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 fzm
 * @since 2021-03-05
 */
public interface CountMapper extends BaseMapper<Count> {
    @Select("select * from goods_count a left join goods_spu b on  a.goods_id = b.goods_id where b.status = 1 order by a.praise desc,sales desc,b.create_time asc limit ${start},${end};")
    List<SaleHotVo> getList(int start, int end);
    @Select("select count(*) from goods_count a left join goods_spu b on  a.goods_id = b.goods_id where b.status = 1")
    int getCount();
    @Update("update goods_count set sales = sales + #{number} where goods_id = #{goodsId}")
    void addSale(@Param("goodsId") String goodsId, @Param("number") Integer number);

    @Select("select b.*,t.uid merchantId from goods_count a inner join tran t on t.goods_id = a.goods_id left join goods_spu b on  a.goods_id = b.goods_id where b.status = 1 order by a.sales desc limit ${start},${end};")
    List<SaleHotVo> listTopTenSaleHotVo(int start, int end);
}
