<?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.yami.shop.dao.SkuMapper">
    <resultMap id="BaseResultMap" type="com.yami.shop.bean.model.Sku">
        <!--
          WARNING - @mbg.generated
        -->
        <id column="sku_id" jdbcType="BIGINT" property="skuId"/>
        <result column="prod_id" jdbcType="BIGINT" property="prodId"/>
        <result column="properties" jdbcType="VARCHAR" property="properties"/>
        <result column="ori_price" jdbcType="DECIMAL" property="oriPrice"/>
        <result column="price" jdbcType="DECIMAL" property="price"/>
        <result column="stocks" jdbcType="INTEGER" property="stocks"/>
        <result column="actual_stocks" jdbcType="INTEGER" property="actualStocks"/>
        <result column="status" jdbcType="TINYINT" property="status"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="rec_time" jdbcType="TIMESTAMP" property="recTime"/>
        <result column="party_code" jdbcType="VARCHAR" property="partyCode"/>
        <result column="model_id" jdbcType="VARCHAR" property="modelId"/>
        <result column="pic" jdbcType="VARCHAR" property="pic"/>
        <result column="sku_name" jdbcType="VARCHAR" property="skuName"/>
        <result column="is_delete" jdbcType="INTEGER" property="isDelete"/>
    </resultMap>

    <insert id="insertBatch">
        INSERT INTO `tz_sku` (
        `prod_id`,`properties`,`ori_price`,`price`,`stocks`,`actual_stocks`,
        `update_time`,`rec_time`,`party_code`,`model_id`, `pic`,
        `sku_name`,`prod_name`,`version`,`weight`,`volume`, `status`, `is_delete`, `sku_score`
        )
        VALUES
        <foreach collection="skuList" item="sku" separator=",">
            (
            #{prodId},#{sku.properties},#{sku.oriPrice},#{sku.price},#{sku.stocks},
            #{sku.actualStocks}, NOW(),NOW(),#{sku.partyCode},#{sku.modelId}, #{sku.pic},
            #{sku.skuName},#{sku.prodName},0,#{sku.weight},#{sku.volume}, #{sku.status},0, #{sku.skuScore}
            )
        </foreach>
    </insert>

    <select id="listByProdId" resultType="com.yami.shop.bean.model.Sku">
        select *
        from tz_sku
        where prod_id = #{prodId}
          and is_delete = 0
    </select>

    <select id="listByProdIdAndPlatform" resultType="com.yami.shop.bean.model.Sku">
        SELECT ts.sku_id,
               ts.prod_id,
               ts.sku_name,
               ts.prod_name,
               ts.ori_price,
               tcp.channel_prod_price AS price,
               ts.sku_score,
               ts.properties,
               ts.stocks,
               tss.shop_sku_stocks    AS actual_stocks,
               ts.update_time,
               ts.rec_time,
               ts.party_code,
               ts.model_id,
               ts.pic,
               ts.version,
               ts.weight,
               ts.volume,
               ts.`status`,
               ts.is_delete,
               ts.weight_unit,
               ts.sku_code,
               ts.hb_spu_id,
               ts.hb_sku_id
        FROM tz_shop_sku AS tss
                 LEFT JOIN tz_sku AS ts ON ts.sku_id = tss.sku_id
                 LEFT JOIN tz_channel_prod AS tcp ON ts.sku_id = tcp.sku_id
        WHERE tss.spu_id = #{prodId}
          AND ts.is_delete = 0
          AND tcp.is_delete = 0
          AND ts.`status` = 1
          AND tss.shop_id = #{shopId}
          AND tcp.channel_id = #{channelId}
    </select>

    <select id="listBySukIdAndPlatformShop" resultType="com.yami.shop.bean.model.Sku">
        SELECT ts.sku_id,
               ts.prod_id,
               ts.sku_name,
               ts.prod_name,
               ts.ori_price,
               tcp.channel_prod_price AS price,
               ts.sku_score,
               ts.properties,
               ts.stocks,
               tss.shop_sku_stocks    AS actual_stocks,
               ts.update_time,
               ts.rec_time,
               ts.party_code,
               ts.model_id,
               ts.pic,
               ts.version,
               ts.weight,
               ts.volume,
               ts.`status`,
               ts.is_delete,
               ts.weight_unit,
               ts.sku_code,
               ts.hb_spu_id,
               ts.hb_sku_id
        FROM tz_sku AS ts
                 LEFT JOIN tz_shop_sku AS tss ON ts.sku_id = tss.sku_id
                 LEFT JOIN tz_channel_prod AS tcp ON ts.sku_id = tcp.sku_id
        WHERE ts.sku_id = #{skuId}
          AND ts.is_delete = 0
          AND tcp.is_delete = 0
          AND ts.`status` = 1
          AND tss.shop_id = #{shopId}
          AND tcp.channel_id = #{channelId}
        LIMIT 1
    </select>
    <select id="listBySukIdAndPlatform" resultType="com.yami.shop.bean.model.Sku">
        SELECT ts.sku_id,
               ts.prod_id,
               ts.sku_name,
               ts.prod_name,
               ts.ori_price,
               tcp.channel_prod_price AS price,
               ts.sku_score,
               ts.properties,
               ts.stocks,
               tss.shop_sku_stocks    AS actual_stocks,
               ts.update_time,
               ts.rec_time,
               ts.party_code,
               ts.model_id,
               ts.pic,
               ts.version,
               ts.weight,
               ts.volume,
               ts.`status`,
               ts.is_delete,
               ts.weight_unit,
               ts.sku_code,
               ts.hb_spu_id,
               ts.hb_sku_id
        FROM tz_sku AS ts
                 LEFT JOIN tz_shop_sku AS tss ON ts.sku_id = tss.sku_id
                 LEFT JOIN tz_channel_prod AS tcp ON ts.sku_id = tcp.sku_id
        WHERE ts.sku_id = #{skuId}
          AND ts.is_delete = 0
          AND tcp.is_delete = 0
          AND ts.`status` = 1
          AND tcp.channel_id = #{channelId} LIMIT 1
    </select>
    <select id="selectByHbSkuId" resultType="com.yami.shop.bean.model.Sku">
        select *
        from tz_sku
        where hb_sku_id = #{hbSkuId}
          and is_delete = 0
    </select>

    <update id="updateStocks" parameterType="com.yami.shop.bean.model.Sku">
        update tz_sku
        set stocks      = stocks - #{sku.stocks},
            version     = version + 1,
            update_time = NOW()
        where sku_id = #{sku.skuId}
          and #{sku.stocks} &lt;= stocks
    </update>

    <update id="deleteByProdId">
        update tz_sku
        set is_delete = 1
        where prod_id = #{prodId}
    </update>


    <update id="returnStock">
        <foreach collection="skuCollect" item="changeStocks" index="skuId" separator=";">
            update tz_sku set stocks = stocks + #{changeStocks} where sku_id = #{skuId}
        </foreach>
    </update>

    <select id="buyTogetherOften" resultType="com.yami.shop.bean.vo.SkuBuyTogetherOftenVo">
        SELECT a.shop_id,b.sku_id, b.prod_id, b.prod_name, b.pic, c.channel_prod_price, d.shop_sku_stocks,IFNULL(e.basket_count,0) prodCount
        FROM tz_order_item a
                 LEFT JOIN tz_sku b on a.sku_id = b.sku_id
                 LEFT JOIN tz_channel_prod c on a.sku_id = c.sku_id and c.is_delete = 0
                 LEFT JOIN tz_shop_sku d on a.sku_id = d.sku_id and d.is_delete = 0
                 LEFT JOIN tz_basket e on a.prod_id=e.prod_id and a.sku_id=e.sku_id and a.shop_id=e.shop_id and e.user_id=#{userId}
        WHERE a.order_number in (SELECT a.order_number FROM tz_order_item a
                                 LEFT JOIN tz_order b on a.order_number=b.order_number
                                 WHERE a.prod_id = #{prodId} and a.shop_id = #{shopId} and b.channel_id=#{channelId})
          and a.prod_id!=#{prodId}
          and a.shop_id=#{shopId}
          and b.`status`=1
          and b.is_delete=0
          and d.sale_status=1
          and c.channel_id=#{channelId}
          and c.shop_id=#{shopId}
        GROUP BY a.sku_id
        ORDER BY a.rec_time desc, a.order_item_id desc
    </select>

    <select id="goodsTotalPrice" resultType="Double">
        SELECT (SELECT SUM(IFNULL(total,0)) goods_total_price FROM tz_order
        WHERE is_payed=1
        <if test="po.startTime != null and po.startTime != ''">
            and create_time&gt;= #{po.startTime}
        </if>

        <if test="po.endTime != null and po.endTime != ''">
            and create_time&lt;= #{po.endTime}
        </if>
        <if test="po.skuId != null or (po.skuName != null and po.skuName != '') or (po.spec != null and po.spec != '')">
        and order_number in(SELECT a.order_number FROM tz_order_item a LEFT JOIN tz_sku b on a.sku_id=b.sku_id
                                                <where>
                                                    <if test="po.skuId != null">
                                                        AND a.sku_id like concat('%',#{po.skuId} ,'%')
                                                    </if>

                                                    <if test="po.skuName != null and po.skuName != ''">
                                                        AND a.sku_name like concat('%',#{po.skuName} ,'%')
                                                    </if>

                                                    <if test="po.spec != null and po.spec != ''">
                                                        AND b.spec like concat('%',#{po.spec} ,'%')
                                                    </if>
                                                </where>
            )
        </if>

          and channel_id in
        <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
        )
        -
        (SELECT IFNULL(SUM(a.sku_price * product_count),0)
        FROM `tz_order_refund_sku` a
        LEFT JOIN tz_order_refund b on a.order_refund_id=b.refund_id
        LEFT JOIN tz_order c on b.order_number=c.order_number
        LEFT JOIN tz_sku d on a.sku_id=d.sku_id
        WHERE b.return_money_sts=70
        <if test="po.startTime != null and po.startTime != ''">
            and b.apply_time&gt;= #{po.startTime}
        </if>

        <if test="po.endTime != null and po.endTime != ''">
            and b.apply_time&lt;= #{po.endTime}
        </if>
        and c.channel_id in
        <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>

        <if test="po.skuId != null">
            AND a.sku_id like concat('%',#{po.skuId} ,'%')
        </if>

        <if test="po.skuName != null and po.skuName != ''">
            AND d.sku_name like concat('%',#{po.skuName} ,'%')
        </if>

        <if test="po.spec != null and po.spec != ''">
            AND d.spec like concat('%',#{po.spec} ,'%')
        </if>

        ) goods_total_price
    </select>

    <select id="totalPoints" resultType="Double">
        SELECT TRUNCATE(((SELECT SUM(IFNULL(offset_points,0)) FROM tz_order
        WHERE is_payed=1
        <if test="po.startTime != null and po.startTime != ''">
            and create_time&gt;= #{po.startTime}
        </if>

        <if test="po.endTime != null and po.endTime != ''">
            and create_time&lt;= #{po.endTime}
        </if>
        and channel_id in
        <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
        <if test="po.skuId != null or (po.skuName != null and po.skuName != '') or (po.spec != null and po.spec != '')">
            and order_number in(SELECT a.order_number FROM tz_order_item a LEFT JOIN tz_sku b on a.sku_id=b.sku_id
            <where>
                <if test="po.skuId != null">
                    AND a.sku_id like concat('%',#{po.skuId} ,'%')
                </if>

                <if test="po.skuName != null and po.skuName != ''">
                    AND a.sku_name like concat('%',#{po.skuName} ,'%')
                </if>

                <if test="po.spec != null and po.spec != ''">
                    AND b.spec like concat('%',#{po.spec} ,'%')
                </if>
            </where>
            )
        </if>
        )
        -
        (SELECT  IFNULL(SUM( total_offset_points ),0)  FROM (SELECT
        CASE
        WHEN refund_type=1 THEN total_offset_points
        ELSE total_offset_points+ (freight_amount * 100)
        END AS total_offset_points
        FROM tz_order_refund a
        LEFT JOIN (SELECT SUM(tor.offset_points) total_offset_points ,tor.order_number
        FROM tz_order_refund tor
        WHERE tor.return_money_sts=70
        <if test="po.startTime != null and po.startTime != ''">
            and tor.apply_time&gt;= #{po.startTime}
        </if>

        <if test="po.endTime != null and po.endTime != ''">
            and tor.apply_time&lt;= #{po.endTime}
        </if>
            and tor.order_number in(SELECT ao.order_number FROM tz_order_item ao
                LEFT JOIN tz_sku b on ao.sku_id=b.sku_id
                LEFT JOIN tz_order c on ao.order_number=c.order_number
            <where>
                 c.channel_id in
                <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
                <if test="po.skuId != null or (po.skuName != null and po.skuName != '') or (po.spec != null and po.spec != '')">
                <if test="po.skuId != null">
                    AND ao.sku_id like concat('%',#{po.skuId} ,'%')
                </if>
                <if test="po.skuName != null and po.skuName != ''">
                    AND ao.sku_name like concat('%',#{po.skuName} ,'%')
                </if>
                <if test="po.spec != null and po.spec != ''">
                    AND b.spec like concat('%',#{po.spec} ,'%')
                </if>
                </if>
            </where>
            )
        GROUP BY tor.order_number) b on a.order_number=b.order_number
        WHERE return_money_sts=70
        <if test="po.startTime != null and po.startTime != ''">
            and apply_time &gt;= #{po.startTime}
        </if>

        <if test="po.endTime != null and po.endTime != ''">
            and apply_time &lt;= #{po.endTime}
        </if>
            and a.order_number in(SELECT ao2.order_number FROM tz_order_item ao2
        LEFT JOIN tz_sku b on ao2.sku_id=b.sku_id
        LEFT JOIN tz_order c on ao2.order_number=c.order_number
        <where>
            c.channel_id in
            <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
            <if test="po.skuId != null or (po.skuName != null and po.skuName != '') or (po.spec != null and po.spec != '')">
                <if test="po.skuId != null">
                    AND ao2.sku_id like concat('%',#{po.skuId} ,'%')
                </if>
                <if test="po.skuName != null and po.skuName != ''">
                    AND ao2.sku_name like concat('%',#{po.skuName} ,'%')
                </if>
                <if test="po.spec != null and po.spec != ''">
                    AND b.spec like concat('%',#{po.spec} ,'%')
                </if>
            </if>
        </where>
        )
        GROUP BY a.order_number) a)) /100,2) total_offset_points
    </select>

    <select id="totalCash" resultType="Double">
        SELECT (SELECT SUM(IFNULL(actual_total,0)) FROM tz_order WHERE is_payed=1
        <if test="po.startTime != null and po.startTime != ''">
            and create_time&gt;= #{po.startTime}
        </if>

        <if test="po.endTime != null and po.endTime != ''">
            and create_time&lt;= #{po.endTime}
        </if>
        and channel_id in
        <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
        <if test="po.skuId != null or (po.skuName != null and po.skuName != '') or (po.spec != null and po.spec != '')">
            and order_number in(SELECT a.order_number FROM tz_order_item a LEFT JOIN tz_sku b on a.sku_id=b.sku_id
            <where>
                <if test="po.skuId != null">
                    AND a.sku_id like concat('%',#{po.skuId} ,'%')
                </if>
                <if test="po.skuName != null and po.skuName != ''">
                    AND a.sku_name like concat('%',#{po.skuName} ,'%')
                </if>
                <if test="po.spec != null and po.spec != ''">
                    AND b.spec like concat('%',#{po.spec} ,'%')
                </if>
            </where>
            )
        </if>
                                                                 )
        -
        (SELECT IFNULL(SUM( refund_amount ),0) FROM tz_order_refund WHERE return_money_sts=70
        <if test="po.startTime != null and po.startTime != ''">
            and apply_time&gt;= #{po.startTime}
        </if>

        <if test="po.endTime != null and po.endTime != ''">
            and apply_time&lt;= #{po.endTime}
        </if>
        and order_number in(SELECT a.order_number FROM tz_order_item a
        LEFT JOIN tz_sku b on a.sku_id=b.sku_id
        LEFT JOIN tz_order c on a.order_number=c.order_number
        <where>
            c.channel_id in
            <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
            <if test="po.skuId != null or (po.skuName != null and po.skuName != '') or (po.spec != null and po.spec != '')">
                <if test="po.skuId != null">
                    AND a.sku_id like concat('%',#{po.skuId} ,'%')
                </if>
                <if test="po.skuName != null and po.skuName != ''">
                    AND a.sku_name like concat('%',#{po.skuName} ,'%')
                </if>
                <if test="po.spec != null and po.spec != ''">
                    AND b.spec like concat('%',#{po.spec} ,'%')
                </if>
            </if>
        </where>
        )) cash
    </select>

    <select id="totalFreight" resultType="Double">
        SELECT (SELECT IFNULL(SUM(freight_amount),0) total_freight FROM tz_order
        WHERE is_payed=1
        <if test="po.startTime != null and po.startTime != ''">
            and create_time&gt;= #{po.startTime}
        </if>

        <if test="po.endTime != null and po.endTime != ''">
            and create_time&lt;= #{po.endTime}
        </if>
        and channel_id in
        <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
        <if test="po.skuId != null or (po.skuName != null and po.skuName != '') or (po.spec != null and po.spec != '')">
            and order_number in(SELECT a.order_number FROM tz_order_item a LEFT JOIN tz_sku b on a.sku_id=b.sku_id
            <where>
                <if test="po.skuId != null">
                    AND a.sku_id like concat('%',#{po.skuId} ,'%')
                </if>

                <if test="po.skuName != null and po.skuName != ''">
                    AND a.sku_name like concat('%',#{po.skuName} ,'%')
                </if>

                <if test="po.spec != null and po.spec != ''">
                    AND b.spec like concat('%',#{po.spec} ,'%')
                </if>
            </where>
            )
        </if>
        )
        -
        (SELECT IFNULL(SUM(freight_amount),0)
        FROM `tz_order_refund`
        WHERE return_money_sts=70
        <if test="po.startTime != null and po.startTime != ''">
            and apply_time&gt;= #{po.startTime}
        </if>

        <if test="po.endTime != null and po.endTime != ''">
            and apply_time&lt;= #{po.endTime}
        </if>
          and refund_type=1
        and order_number in(SELECT a.order_number FROM tz_order_item a
        LEFT JOIN tz_sku b on a.sku_id=b.sku_id
        LEFT JOIN tz_order c on a.order_number=c.order_number
        <where>
            c.channel_id in
            <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
            <if test="po.skuId != null or (po.skuName != null and po.skuName != '') or (po.spec != null and po.spec != '')">
                <if test="po.skuId != null">
                    AND a.sku_id like concat('%',#{po.skuId} ,'%')
                </if>
                <if test="po.skuName != null and po.skuName != ''">
                    AND a.sku_name like concat('%',#{po.skuName} ,'%')
                </if>
                <if test="po.spec != null and po.spec != ''">
                    AND b.spec like concat('%',#{po.spec} ,'%')
                </if>
            </if>
        </where>
        ))
    </select>

    <select id="skuStatisticsList" resultType="com.yami.shop.bean.vo.SkuStatisticsVo">
        SELECT a.prod_id,a.sku_id,a.sku_name,c.spec,TRUNCATE(IFNULL(SUM(a.price*a.prod_count)/SUM(a.prod_count),0),2) price,IFNULL(SUM(a.prod_count),0)-IFNULL(d.product_count,0) as prod_count,
        TRUNCATE(IFNULL(SUM(a.price*a.prod_count)/SUM(a.prod_count),0),2) * (IFNULL(SUM(a.prod_count),0)-IFNULL(d.product_count,0)) total
        FROM tz_order_item a
        LEFT JOIN tz_order b on a.order_number=b.order_number
        LEFT JOIN tz_sku c on a.sku_id=c.sku_id
        LEFT JOIN (SELECT a.sku_id,SUM(a.product_count) product_count
        FROM `tz_order_refund_sku` a
        LEFT JOIN tz_order_refund b on a.order_refund_id=b.refund_id
        WHERE return_money_sts=70

        <if test="po.startTime != null and po.startTime != ''">
            and b.apply_time&gt;= #{po.startTime}
        </if>

        <if test="po.endTime != null and po.endTime != ''">
            and b.apply_time&lt;= #{po.endTime}
        </if>
        GROUP BY a.sku_id) d on a.sku_id = d.sku_id

        WHERE b.is_payed=1
        <if test="po.startTime != null and po.startTime != ''">
            and a.rec_time&gt;= #{po.startTime}
        </if>

        <if test="po.endTime != null and po.endTime != ''">
            and a.rec_time&lt;= #{po.endTime}
        </if>
        and b.channel_id in
        <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
        <if test="po.skuId != null">
            AND a.sku_id like concat('%',#{po.skuId} ,'%')
        </if>

        <if test="po.skuName != null and po.skuName != ''">
            AND a.sku_name like concat('%',#{po.skuName} ,'%')
        </if>

        <if test="po.spec != null and po.spec != ''">
            AND c.spec like concat('%',#{po.spec} ,'%')
        </if>
        GROUP BY a.sku_id HAVING prod_count>0
    </select>

    <select id="skuStatisticsList2" resultType="com.yami.shop.bean.vo.SkuStatisticsVo">
        SELECT a.prod_id,a.sku_id,a.sku_name,c.spec,TRUNCATE(IFNULL(SUM(a.price*a.prod_count)/SUM(a.prod_count),0),2) price,IFNULL(SUM(a.prod_count),0)-IFNULL(d.product_count,0) as prod_count,
        TRUNCATE(IFNULL(SUM(a.price*a.prod_count)/SUM(a.prod_count),0),2) * (IFNULL(SUM(a.prod_count),0)-IFNULL(d.product_count,0)) total
        FROM tz_order_item a
        LEFT JOIN tz_order b on a.order_number=b.order_number
        LEFT JOIN tz_sku c on a.sku_id=c.sku_id
        LEFT JOIN (SELECT a.sku_id,SUM(a.product_count) product_count
        FROM `tz_order_refund_sku` a
        LEFT JOIN tz_order_refund b on a.order_refund_id=b.refund_id
        WHERE return_money_sts=70

        <if test="po.startTime != null and po.startTime != ''">
            and b.apply_time&gt;= #{po.startTime}
        </if>

        <if test="po.endTime != null and po.endTime != ''">
            and b.apply_time&lt;= #{po.endTime}
        </if>
        GROUP BY a.sku_id) d on a.sku_id = d.sku_id

        WHERE b.is_payed=1
        <if test="po.startTime != null and po.startTime != ''">
            and a.rec_time&gt;= #{po.startTime}
        </if>

        <if test="po.endTime != null and po.endTime != ''">
            and a.rec_time&lt;= #{po.endTime}
        </if>
        and b.channel_id in
        <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
        <if test="po.skuId != null">
            AND a.sku_id like concat('%',#{po.skuId} ,'%')
        </if>

        <if test="po.skuName != null and po.skuName != ''">
            AND a.sku_name like concat('%',#{po.skuName} ,'%')
        </if>

        <if test="po.spec != null and po.spec != ''">
            AND c.spec like concat('%',#{po.spec} ,'%')
        </if>
        GROUP BY a.sku_id HAVING prod_count>0
    </select>

    <select id="freightStatisticsList" resultType="com.yami.shop.bean.vo.FreightStatisticsVo">
        SELECT @row_number := @row_number + 1 AS sort,a.pay_time,CONCAT(b.receiver,'  ',b.mobile) receiver,a.dvy_flow_id delivery_no,b.address to_address,a.freight_amount money,a.order_number order_no,
        CASE WHEN a.dvy_type=1 THEN '邮政'
        WHEN a.dvy_type=3 THEN '麦芽田-闪送'
        ELSE
        '其他'
        END delivery
        FROM (SELECT @row_number := 0) sort,
        tz_order a
        LEFT JOIN tz_user_addr_order b on a.addr_order_id =b.addr_order_id
        WHERE a.is_payed=1 and a.hb_order_status not in(0,60)
        and a.channel_id in
        <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>

        <if test="po.delivery != null">
            and a.dvy_type=#{po.delivery}
        </if>

        <if test="po.receiver != null and po.receiver != ''">
            AND b.receiver like concat('%',#{po.receiver} ,'%')
        </if>
        <if test="po.mobile != null and po.mobile != ''">
            AND b.mobile like concat('%',#{po.mobile} ,'%')
        </if>
        <if test="po.deliveryNo != null and po.deliveryNo != ''">
            AND a.dvy_flow_id like concat('%',#{po.deliveryNo} ,'%')
        </if>
        <if test="po.toAddress != null and po.toAddress != ''">
            AND b.address like concat('%',#{po.toAddress} ,'%')
        </if>
        <if test="po.orderNo != null and po.orderNo != ''">
            AND a.order_number like concat('%',#{po.orderNo} ,'%')
        </if>
        <if test="po.startTime != null and po.startTime != ''">
            and a.pay_time&gt;= #{po.startTime}
        </if>
        <if test="po.endTime != null and po.endTime != ''">
            and a.pay_time&lt;= #{po.endTime}
        </if>
    </select>

    <select id="freightStatisticsList2" resultType="com.yami.shop.bean.vo.FreightStatisticsVo">
        SELECT @row_number := @row_number + 1 AS sort,a.pay_time,CONCAT(b.receiver,'  ',b.mobile) receiver,a.dvy_flow_id delivery_no,b.address to_address,a.freight_amount money,a.order_number order_no,
        CASE WHEN a.dvy_type=1 THEN '邮政'
        WHEN a.dvy_type=3 THEN '麦芽田-闪送'
        ELSE
        '其他'
        END delivery
        FROM (SELECT @row_number := 0) sort,
        tz_order a
        LEFT JOIN tz_user_addr_order b on a.addr_order_id =b.addr_order_id
        WHERE a.is_payed=1 and a.hb_order_status not in(0,60)
        and a.channel_id in
        <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>

        <if test="po.delivery != null">
            and a.dvy_type=#{po.delivery}
        </if>

        <if test="po.receiver != null and po.receiver != ''">
            AND b.receiver like concat('%',#{po.receiver} ,'%')
        </if>
        <if test="po.mobile != null and po.mobile != ''">
            AND b.mobile like concat('%',#{po.mobile} ,'%')
        </if>
        <if test="po.deliveryNo != null and po.deliveryNo != ''">
            AND a.dvy_flow_id like concat('%',#{po.deliveryNo} ,'%')
        </if>
        <if test="po.toAddress != null and po.toAddress != ''">
            AND b.address like concat('%',#{po.toAddress} ,'%')
        </if>
        <if test="po.orderNo != null and po.orderNo != ''">
            AND a.order_number like concat('%',#{po.orderNo} ,'%')
        </if>
        <if test="po.startTime != null and po.startTime != ''">
            and a.pay_time&gt;= #{po.startTime}
        </if>
        <if test="po.endTime != null and po.endTime != ''">
            and a.pay_time&lt;= #{po.endTime}
        </if>
    </select>


</mapper>
