<?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.gxwebsoft.love.mapper.UserPlanLogMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*,b.role_id,
              b.name as planName,b.icon as planIcon,
              c.nickname,c.avatar as userAvatar,
              d.dealer_id as dealerId,
              e.dealer_id as dealerId2,
              f.real_name as realName2,f.certificate_code as idCard
        FROM love_user_plan_log a
        LEFT JOIN love_user_plan b ON a.plan_id = b.plan_id
        LEFT JOIN sys_user c ON a.user_id = c.user_id
        LEFT JOIN shop_user_referee d ON a.user_id = d.user_id and d.deleted = 0
        LEFT JOIN shop_user_referee e ON d.dealer_id = e.user_id and e.deleted = 0
        LEFT JOIN love_certificate f ON a.user_id = f.user_id and f.certificate_type = 'idCard'
        <where>
            <if test="param.logId != null">
                AND a.log_id = #{param.logId}
            </if>
            <if test="param.logNo != null">
                AND a.log_no LIKE CONCAT('%', #{param.logNo}, '%')
            </if>
            <if test="param.money != null">
                AND a.money = #{param.money}
            </if>
            <if test="param.planId != null">
                AND a.plan_id = #{param.planId}
            </if>
            <if test="param.userId != null">
                AND a.user_id = #{param.userId}
            </if>
            <if test="param.sortNumber != null">
                AND a.sort_number = #{param.sortNumber}
            </if>
            <if test="param.comments != null">
                AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
            </if>
            <if test="param.status != null">
                AND a.status = #{param.status}
            </if>
            <if test="param.deleted != null">
                AND a.deleted = #{param.deleted}
            </if>
            <if test="param.deleted == null">
                AND a.deleted = 0
            </if>
            <if test="param.createTimeStart != null">
                AND a.create_time &gt;= #{param.createTimeStart}
            </if>
            <if test="param.createTimeEnd != null">
                AND a.create_time &lt;= #{param.createTimeEnd}
            </if>
        </where>
    </sql>

    <!-- 分页查询 -->
    <select id="selectPageRel" resultType="com.gxwebsoft.love.entity.UserPlanLog">
        <include refid="selectSql"></include>
    </select>

    <!-- 查询全部 -->
    <select id="selectListRel" resultType="com.gxwebsoft.love.entity.UserPlanLog">
        <include refid="selectSql"></include>
    </select>

  <!-- 按OutTradeNo查询 -->
  <select id="getByOutTradeNo" resultType="com.gxwebsoft.love.entity.UserPlanLog">
    <include refid="selectSql"></include>
  </select>

  <!-- 更新订单状态 -->
  <select id="updateByOutTradeNo" resultType="com.gxwebsoft.love.entity.UserPlanLog">
    UPDATE love_user_plan_log SET pay_status = #{param.payStatus},pay_time = #{param.payTime},pay_price = #{param.payPrice} WHERE log_no = #{param.logNo}
  </select>

</mapper>
