<?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.MerchantMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*,
               b.username, b.nickname, b.phone,
               c.grade_id,c.name as gradeName
        FROM shop_merchant a
        LEFT JOIN sys_user b ON a.merchant_owner = b.user_id
        LEFT JOIN shop_user_grade c ON b.grade_id = c.grade_id
        <where>
            <if test="param.merchantId != null">
                AND a.merchant_id = #{param.merchantId}
            </if>
            <if test="param.merchantName != null">
                AND a.merchant_name LIKE CONCAT('%', #{param.merchantName}, '%')
            </if>
            <if test="param.merchantCode != null">
                AND a.merchant_code LIKE CONCAT('%', #{param.merchantCode}, '%')
            </if>
            <if test="param.money != null">
                AND a.money = #{param.money}
            </if>
            <if test="param.freezeMoney != null">
                AND a.freeze_money = #{param.freezeMoney}
            </if>
            <if test="param.totalMoney != null">
                AND a.total_money = #{param.totalMoney}
            </if>
            <if test="param.logo != null">
                AND a.logo LIKE CONCAT('%', #{param.logo}, '%')
            </if>
            <if test="param.background != null">
                AND a.background LIKE CONCAT('%', #{param.background}, '%')
            </if>
            <if test="param.merchantHours != null">
                AND a.merchant_hours LIKE CONCAT('%', #{param.merchantHours}, '%')
            </if>
            <if test="param.province != null">
                AND a.province LIKE CONCAT('%', #{param.province}, '%')
            </if>
            <if test="param.city != null">
                AND a.city LIKE CONCAT('%', #{param.city}, '%')
            </if>
            <if test="param.region != null">
                AND a.region LIKE CONCAT('%', #{param.region}, '%')
            </if>
            <if test="param.address != null">
                AND a.address LIKE CONCAT('%', #{param.address}, '%')
            </if>
            <if test="param.content != null">
                AND a.content LIKE CONCAT('%', #{param.content}, '%')
            </if>
            <if test="param.lngAndLat != null">
                AND a.lng_and_lat LIKE CONCAT('%', #{param.lngAndLat}, '%')
            </if>
            <if test="param.geohash != null">
                AND a.geohash LIKE CONCAT('%', #{param.geohash}, '%')
            </if>
            <if test="param.summary != null">
                AND a.summary LIKE CONCAT('%', #{param.summary}, '%')
            </if>
            <if test="param.payType != null">
                AND a.pay_type = #{param.payType}
            </if>
            <if test="param.alipayName != null">
                AND a.alipay_name LIKE CONCAT('%', #{param.alipayName}, '%')
            </if>
            <if test="param.alipayAccount != null">
                AND a.alipay_account LIKE CONCAT('%', #{param.alipayAccount}, '%')
            </if>
            <if test="param.bankName != null">
                AND a.bank_name LIKE CONCAT('%', #{param.bankName}, '%')
            </if>
            <if test="param.bankAccount != null">
                AND a.bank_account LIKE CONCAT('%', #{param.bankAccount}, '%')
            </if>
            <if test="param.bankCard != null">
                AND a.bank_card LIKE CONCAT('%', #{param.bankCard}, '%')
            </if>
            <if test="param.isEdit != null">
                AND a.is_edit = #{param.isEdit}
            </if>
            <if test="param.isCheck != null">
                AND a.is_check = #{param.isCheck}
            </if>
            <if test="param.merchantOwner != null">
              AND a.merchant_owner = #{param.merchantOwner}
            </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.customerId != null">
                AND a.customer_id = #{param.customerId}
            </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.username != null">
            AND b.username = #{param.username}
          </if>
          <if test="param.nickname != null">
            AND b.nickname LIKE CONCAT('%', #{param.nickname}, '%')
          </if>
          <if test="param.phone != null">
            AND b.phone = #{param.phone}
          </if>
          <if test="param.tenantId != null">
            AND a.tenant_id = #{param.tenantId}
          </if>
          <if test="param.gradeId != null">
            AND c.grade_id = #{param.gradeId}
          </if>
          <if test="param.sceneType == 'SHOP_USER'">
            AND c.grade_id >= 7
          </if>
        </where>
    </sql>

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

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

</mapper>
