<?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.yc.ship.module.ota.dal.mysql.tradelog.TradeLogMapper">

    <!--
        一般情况下，尽可能使用 Mapper 进行 CRUD 增删改查即可。
        无法满足的场景，例如说多表关联查询，才使用 XML 编写 SQL。
        代码生成器暂时只生成 Mapper XML 文件本身，更多推荐 MybatisX 快速开发插件来生成查询。
        文档可见：https://www.iocoder.cn/MyBatis/x-plugins/
     -->

    <select id="getTradeLogPage" resultType="com.yc.ship.module.ota.dal.dataobject.tradelog.TradeLogDO">
        SELECT
            t1.*,t2.order_no orderNo, s.store_name storeName
        FROM
            ota_trade_log t1
                LEFT JOIN trade_order t2 ON t1.order_id = t2.id
                LEFT JOIN otc_agency_store s ON s.id = t1.store_id
        WHERE
            1 = 1
          <if test="pageReqVO.tradeType != null">
              AND t1.trade_type = #{pageReqVO.tradeType}
          </if>
          <if test="pageReqVO.operatorName != null">
              AND t1.operator_name LIKE concat('%',#{pageReqVO.operatorName},'%')
          </if>
          <if test="pageReqVO.tradeMode != null">
              AND t1.trade_mode = #{pageReqVO.tradeMode}
          </if>
          <if test="pageReqVO.distributorId != null">
              AND t1.distributor_id = #{pageReqVO.distributorId}
          </if>
          <if test="pageReqVO.tradeTime != null">
              AND t1.trade_time BETWEEN #{pageReqVO.tradeStartTime} AND #{pageReqVO.tradeEndTime}
          </if>
          <if test="pageReqVO.orderNo != null and pageReqVO.orderNo != ''">
              AND t2.order_no = #{pageReqVO.orderNo}
          </if>
          <if test="pageReqVO.storeId != null">
              AND t1.store_id = #{pageReqVO.storeId}
          </if>
        ORDER BY
            t1.create_time DESC
    </select>
</mapper>
