<?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.shop.mapper.RechargeOrderMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*,b.phone,b.nickname,b.user_id,b.avatar,c.organization_id,c.organization_name
        FROM shop_recharge_order a
        LEFT JOIN sys_user b ON a.user_id = b.user_id
        LEFT JOIN sys_organization c ON a.organization_id = c.organization_id
        <where>
            <if test="param.orderId != null">
                AND a.order_id = #{param.orderId}
            </if>
            <if test="param.orderNo != null">
                AND a.order_no LIKE CONCAT('%', #{param.orderNo}, '%')
            </if>
            <if test="param.userId != null">
                AND a.user_id = #{param.userId}
            </if>
            <if test="param.rechargeType != null">
                AND a.recharge_type = #{param.rechargeType}
            </if>
            <if test="param.planId != null">
                AND a.plan_id = #{param.planId}
            </if>
            <if test="param.payPrice != null">
                AND a.pay_price = #{param.payPrice}
            </if>
            <if test="param.giftMoney != null">
                AND a.gift_money = #{param.giftMoney}
            </if>
            <if test="param.actualMoney != null">
                AND a.actual_money = #{param.actualMoney}
            </if>
            <if test="param.payMethod != null">
                AND a.pay_method LIKE CONCAT('%', #{param.payMethod}, '%')
            </if>
            <if test="param.payStatus != null">
                AND a.pay_status = #{param.payStatus}
            </if>
            <if test="param.payTime != null">
                AND a.pay_time = #{param.payTime}
            </if>
            <if test="param.tradeId != null">
                AND a.trade_id = #{param.tradeId}
            </if>
            <if test="param.platform != null">
                AND a.platform LIKE CONCAT('%', #{param.platform}, '%')
            </if>
            <if test="param.shopId != null">
                AND a.shop_id = #{param.shopId}
            </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.merchantCode != null">
                AND a.merchant_code LIKE CONCAT('%', #{param.merchantCode}, '%')
            </if>
            <if test="param.organizationId != null">
              AND c.organization_id = #{param.organizationId}
            </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>
            <if test="param.keywords != null">
              AND (
              b.nickname LIKE CONCAT('%', #{param.keywords}, '%')
              OR b.alias LIKE CONCAT('%', #{param.keywords}, '%')
              OR b.phone LIKE CONCAT('%', #{param.keywords}, '%')
              )
            </if>
        </where>
    </sql>

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

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

</mapper>
