<?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.ichangzuo.system.mapper.IntegralMapper">
    <!-- 提现分页列表 -->
    <select id="listPagedAdmin" resultType="com.ichangzuo.system.model.vo.IntegralAdminPageVO">
        SELECT
            details_id,
            d.user_id,
            u.user_name,
            u.nickname,
            title,
            score,
            d.balance,
            ruleid,
            ruletype,
            addtime,
            comment
        FROM mc_user_integral_details d
        LEFT JOIN mc_user u ON u.user_id = d.user_id
        <where>
            <if test='queryParams.userId!=null'>
                AND d.user_id = #{queryParams.userId}
            </if>
            <if test='queryParams.ruletype!=null'>
                <choose>
                    <when test="queryParams.ruletype==1">
                        AND ( ruletype=1 OR ruletype=3 OR ruletype=5 )
                    </when>
                    <otherwise>
                        AND ( ruletype!=1 AND ruletype!=3 AND ruletype!=5 )
                    </otherwise>
                </choose>
            </if>
            <if test="queryParams.addtime != null and queryParams.addtime.size > 0">
                <if test="queryParams.addtime[0] != null and queryParams.addtime[0] != ''">
                    <bind name="startDate" value="queryParams.addtime[0]"/>
                    AND addtime &gt;= #{startDate}
                </if>
                <if test="queryParams.addtime[1] != null and queryParams.addtime[1] != ''">
                    <bind name="endDate" value="queryParams.addtime[1]"/>
                    AND addtime &lt;= #{endDate}
                </if>
            </if>
        </where>
        ORDER BY details_id DESC
    </select>

    <select id="listPagedUser" resultType="com.ichangzuo.system.model.vo.IntegralUserPageVO">
        SELECT
            details_id,
            title,
            score,
            balance,
            ruleid,
            ruletype,
            addtime,
            comment
        FROM mc_user_integral_details
        <where>
            <if test='queryParams.userId!=null'>
                AND user_id = #{queryParams.userId}
            </if>
            <if test='queryParams.ruletype!=null'>
                <choose>
                    <when test="queryParams.ruletype==1">
                        AND ( ruletype=1 OR ruletype=3 OR ruletype=5 )
                    </when>
                    <otherwise>
                        AND ( ruletype!=1 AND ruletype!=3 AND ruletype!=5 )
                    </otherwise>
                </choose>
            </if>
            <if test="queryParams.addtime != null and queryParams.addtime.size > 0">
                <if test="queryParams.addtime[0] != null and queryParams.addtime[0] != ''">
                    <bind name="startDate" value="queryParams.addtime[0]"/>
                    AND addime &gt;= #{startDate}
                </if>
                <if test="queryParams.addtime[1] != null and queryParams.addtime[1] != ''">
                    <bind name="endDate" value="queryParams.addtime[1]"/>
                    AND addtime &lt;= #{endDate}
                </if>
            </if>
        </where>
        ORDER BY details_id DESC
    </select>
</mapper>
