<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.web.modules.home.mapper.CategoryAppMapper">

    <select id="selectPlatformLevel2Tabs" resultType="com.ruoyi.web.modules.category.vo.CategoryVisibleChildVO">
        select category_id as categoryId,
               category_name as categoryName,
               category_pic as categoryPic,
               hot_flag as hotFlag,
               sort_no as sortNo
        from biz_goods_category
        where shop_id is null
          and category_level = '2'
          and parent_id = #{level1Id}
          and show_flag = '1'
          and del_flag = '0'
        order by sort_no asc, create_time asc
    </select>

    <select id="selectGoodsByCategory" resultType="com.ruoyi.web.modules.home.vo.HomeHotGoodsVO">
        select g.goods_id as goodsId,
               g.goods_sn as goodsSn,
               g.goods_name as goodsName,
               g.main_pic as mainPic,
               g.sale_price as salePrice,
               s.shop_id as shopId,
               s.shop_name as shopName
        from biz_goods g
        inner join biz_shop s on g.shop_id = s.shop_id and s.del_flag = '0'
        where g.goods_status = '2'
          and g.del_flag = '0'
          and g.category_id = #{categoryId}
        order by
        <choose>
            <when test="sortBy == 'sales_asc'">
                g.sales_count asc, g.goods_sn asc
            </when>
            <when test="sortBy == 'price_desc'">
                g.sale_price desc, g.goods_sn asc
            </when>
            <when test="sortBy == 'price_asc'">
                g.sale_price asc, g.goods_sn asc
            </when>
            <otherwise>
                g.sales_count desc, g.goods_sn asc
            </otherwise>
        </choose>
    </select>

</mapper>
