<?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.gree.mall.manager.commonmapper.TaxMapper">

    <select id="queryTaxById" resultType="com.gree.mall.manager.plus.entity.GoodsCategory">
        select gc.* from order_detail od LEFT JOIN goods gs on  gs.goods_id = od.goods_id
                                         left join goods_category gc on gc.category_id = gs.category_id
        where od.order_detail_id = #{orderDetailId}
    </select>

    <select id="queryGoodsCategoryByOrderId" resultType="com.gree.mall.manager.plus.entity.GoodsCategory">
        select c.* from order_detail a
            join goods b on a.goods_id = b.goods_id
            join goods_category c on c.category_id = b.category_id
            where a.order_id=#{orderId}
    </select>

    <select id="queryOrderTaxExcelMsg" resultType="com.gree.mall.manager.bean.tax.OrderTaxExcelBean">
        SELECT
            ot.* ,
            GROUP_CONCAT(gc.name) as categoryNames,
            a.pay_time
        from order_tax ot
        left join order_info a on a.order_id = ot.order_id
        LEFT JOIN order_detail od on od.order_id=ot.order_id
        LEFT JOIN goods g on g.goods_id=od.goods_id
        LEFT JOIN goods_category gc on gc.category_id=g.category_id
        <where>
            gc.category_id is not null
            <if test="status != null">
                and ot.status = #{status}
            </if>
            <if test="orderId != null">
                and ot.order_id like concat('%',#{orderId},'%')
            </if>
            <if test="companyWechatIds != null and companyWechatIds.size > 0">
                and ot.company_wechat_id in
                <foreach item="item" index="index" collection="companyWechatIds" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="adminWebsitIds != null and adminWebsitIds.size > 0">
                and ot.websit_id in
                <foreach item="item" index="index" collection="adminWebsitIds" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        GROUP BY ot.order_tax_id
        ORDER BY ot.create_time DESC

    </select>
</mapper>