<?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="cn.newfeifan.mall.module.trade.dal.mysql.order.TradeOrderMapper">

    <resultMap id="BaseResultMap" type="cn.newfeifan.mall.module.distri.mq.message.order.DistriOrderMessage">
        <id column="totalPrice" property="totalPrice"/>
        <result column="price" property="price"/>
        <result column="productCount" property="productCount"/>
        <result column="costPrice" property="costPrice"/>
        <result column="no" property="no"/>
        <result column="userId" property="userId"/>
        <result column="shopId" property="shopId"/>
        <result column="merchantId" property="merchantId"/>
        <result column="orderId" property="orderId"/>
        <result column="name" property="name"/>
        <result column="nickName" property="nickName"/>
        <result column="count" property="count"/>


    </resultMap>

<!--    参与 冻结转可用的订单计算-->
    <select id="queryAllOrder" resultMap="BaseResultMap">
        select tor.total_price as totalPrice,
               toi.cost_price as costPrice,
               toi.price as price,
               tor.product_count as productCount,
               tor.`no` as `no`,
               tor.id as orderId,
               tor.user_id as userId,
               ps.merchant_id as merchantId,
               ps.shop_id as shopId,
               mu.`name` as name,
               mu.nickname as nickname,
               toi.count as `count`,
               toi.id as orderItemId,
               toi.increase_integral AS increaseIntegral,
               toi.ancestor_increase_integral AS ancestorIncreaseIntegral,
               toi.freeze_high_quota AS freezeHighQuota
        from trade_order tor
                 LEFT JOIN member_user mu
                           ON tor.user_id = mu.id
                 LEFT JOIN trade_order_item toi
                           on tor.id = toi.order_id
                 LEFT JOIN product_sku ps
                           on toi.sku_id = ps.id
        where tor.pay_status = 1
        and tor.deleted = 0 and toi.deleted = 0
        and toi.distribute_benefit = 0
        and toi.after_sale_status = 0
        and date(tor.create_time) <![CDATA[ <= ]]> DATE_SUB(CURDATE(), INTERVAL 7 DAY)
--         and date(tor.pay_time) <![CDATA[ <= ]]> DATE_SUB('2024-06-21', INTERVAL 7 DAY)
--         and date(tor.pay_time) = '2024-06-20'
--           and tor.receiving_time &lt; DATE_SUB(NOW(), INTERVAL 7 DAY)
    </select>

<!--    参与合赢奖的订单-->
    <select id="queryDailyOrder" resultMap="BaseResultMap">
        select tor.total_price as totalPrice,
               toi.cost_price as costPrice,
               toi.price as price,
               tor.product_count as productCount,
               tor.`no` as `no`,
               tor.id as orderId,
               tor.user_id as userId,
               ps.merchant_id as merchantId,
               ps.shop_id as shopId,
               mu.`name` as name,
               mu.nickname as nickname,
               toi.count as `count`,
               toi.id as orderItemId,
               toi.increase_integral AS increaseIntegral,
               toi.ancestor_increase_integral AS ancestorIncreaseIntegral
        from trade_order tor
                 LEFT JOIN member_user mu
                           ON tor.user_id = mu.id
                 LEFT JOIN trade_order_item toi
                           on tor.id = toi.order_id
                 LEFT JOIN product_sku ps
                           on toi.sku_id = ps.id
        where tor.pay_status = 1
          and tor.deleted = 0 and toi.deleted = 0
          and toi.after_sale_status = 0
          and toi.transition_time is null
          and DATE(tor.create_time) &lt; CURDATE()
--           and DATE(tor.create_time) = '2024-06-20'
    </select>
</mapper>
