<?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="cn.pluss.platform.mapper.MerchantStoreMapper">

    <resultMap id="StoreInfoVO" type="cn.pluss.platform.vo.StoreInfoVO" autoMapping="true">

    </resultMap>

    <select id="queryMerchantNoStoreList" parameterType="cn.pluss.platform.entity.MerchantStore"
            resultType="cn.pluss.platform.entity.MerchantStore">
        SELECT * from tb_pluss_merchant_store
        <where>
            <if test="id!= null">
                and id = #{id}
            </if>
            <if test="merchantCode!= null">
                and merchantCode in (SELECT merchantCode
                FROM tb_pluss_merchant_base_info
                WHERE bindingCode =(SELECT bindingCode
                FROM tb_pluss_merchant_base_info
                where merchantCode = #{merchantCode}))
            </if>
            <if test="storeId!= null">
                and storeId = #{storeId}
            </if>
            <if test="storeName!= null">
                and storeName = #{storeName}
            </if>
            <if test="linkName!= null">
                and linkName = #{linkName}
            </if>
            <if test="linkPhone!= null">
                and linkPhone = #{linkPhone}
            </if>
            <if test="address!= null">
                and address = #{address}
            </if>
            <if test="storeDesc!= null">
                and storeDesc = #{storeDesc}
            </if>
            <if test="logo!= null">
                and logo = #{logo}
            </if>
            <if test="creator!= null">
                and creator = #{creator}
            </if>
            <if test="createDt!= null">
                and createDt = #{createDt}
            </if>
            <if test="openingTime!= null">
                and openingTime = #{openingTime}
            </if>
            <if test="status!= null">
                and status = #{status}
            </if>
            <if test="merchantName!= null">
                and merchantName = #{merchantName}
            </if>
            <if test="parentCode!= null">
                and parentCode = #{parentCode}
            </if>
            <if test="email!= null">
                and email = #{email}
            </if>
            <if test="isAccount!= null">
                and isAccount = #{isAccount}
            </if>
            <if test="loginName!= null">
                and loginName = #{loginName}
            </if>
            <if test="storeHeadPic!= null">
                and storeHeadPic = #{storeHeadPic}
            </if>
            <if test="storeInsidePic!= null">
                and storeInsidePic = #{storeInsidePic}
            </if>
            <if test="cashPic!= null">
                and cashPic = #{cashPic}
            </if>
            <if test="productDesc!= null">
                and productDesc = #{productDesc}
            </if>
            <if test="paymentCodeUrl!= null">
                and paymentCodeUrl = #{paymentCodeUrl}
            </if>
            <if test="isMarket!= null">
                and isMarket = #{isMarket}
            </if>
        </where>
    </select>

    <select id="queryMerchantStorePage" parameterType="java.util.Map"
            resultType="cn.pluss.platform.entity.MerchantStore">
        SELECT * from tb_pluss_merchant_store
        <where>
            <if test="id!= null">
                and id = #{id}
            </if>
            <if test="merchantCode!= null">
                and merchantCode = #{merchantCode}
            </if>
            <if test="storeId!= null">
                and storeId = #{storeId}
            </if>
            <if test="storeName!= null">
                and storeName LIKE CONCAT("%",#{storeName},"%")
            </if>
            <if test="linkName!= null">
                and linkName = #{linkName}
            </if>
            <if test="linkPhone!= null">
                and linkPhone = #{linkPhone}
            </if>
            <if test="address!= null">
                and address = #{address}
            </if>
            <if test="storeDesc!= null">
                and storeDesc = #{storeDesc}
            </if>
            <if test="logo!= null">
                and logo = #{logo}
            </if>
            <if test="creator!= null">
                and creator = #{creator}
            </if>
            <if test="createDt!= null">
                and createDt = #{createDt}
            </if>
            <if test="openingTime!= null">
                and openingTime = #{openingTime}
            </if>
            <if test="status!= null">
                and status = #{status}
            </if>
            <if test="merchantName!= null">
                and merchantName = #{merchantName}
            </if>
            <if test="parentCode!= null">
                and parentCode = #{parentCode}
            </if>
            <if test="email!= null">
                and email = #{email}
            </if>
            <if test="isAccount!= null">
                and isAccount = #{isAccount}
            </if>
            <if test="loginName!= null">
                and loginName = #{loginName}
            </if>
            <if test="storeHeadPic!= null">
                and storeHeadPic = #{storeHeadPic}
            </if>
            <if test="storeInsidePic!= null">
                and storeInsidePic = #{storeInsidePic}
            </if>
            <if test="cashPic!= null">
                and cashPic = #{cashPic}
            </if>
            <if test="productDesc!= null">
                and productDesc = #{productDesc}
            </if>
            <if test="paymentCodeUrl!= null">
                and paymentCodeUrl = #{paymentCodeUrl}
            </if>
        </where>
        order by id desc limit #{pageSize} offset #{offset}
    </select>

    <select id="queryMerchantStorePageCount" parameterType="java.util.Map" resultType="java.lang.Integer">
        SELECT count(*) from tb_pluss_merchant_store ms
        JOIN tb_pluss_merchant_base_info mbi on ms.merchantCode = mbi.merchantCode
        LEFT JOIN tb_pluss_user_app ua ON ms.merchantCode = ua.merchantCode
        LEFT JOIN tb_pluss_merchant_channel_status mcs ON ms.merchantCode = mcs.merchantCode
        <where>
            <if test="merchantCode!=null and merchantCode!=''">
                and ms.merchantCode =#{merchantCode}
            </if>
            <if test="merchantType!=null and merchantType!=''">
                and mbi.merchantType =#{merchantType}
            </if>
            <if test="merchantName!=null and merchantName!=''">
                and ms.merchantName LIKE CONCAT('%',#{merchantName},'%')
            </if>
            <if test="storeName!=null and storeName!=''">
                and ms.storeName LIKE CONCAT('%',#{storeName},'%')
            </if>
            <if test="status == '1'.toString() ">
                and (ms.status in ('1','0') OR ms.status IS NULL)
            </if>
            <if test="status == '2'.toString() ">
                and ms.status = '2'
            </if>
            <if test="productDesc!=null and productDesc!=''">
                and mbi.productDesc=#{productDesc}
            </if>
            <if test="payEcdemicSwitch == '2'.toString() ">
                and (ms.payEcdemicSwitch = '0' OR ms.payEcdemicSwitch IS NULL)
            </if>
            <if test="payEcdemicSwitch == '1'.toString() ">
                and ms.payEcdemicSwitch='1'
            </if>
            <if test="address!=null and address!=''">
                and ms.address LIKE CONCAT('%',#{address},'%')
            </if>
            <if test="userId!=null">
                and ua.userId = #{userId}
            </if>
            <if test="merchantType!=null and merchantType!=''">
                and mbi.merchantType=#{merchantType}
            </if>
            <if test="alias!=null and alias!=''">
                and mbi.alias like concat("%",#{alias},"%")
            </if>
            <if test="stTime!= null and stTime!=''">
                and ms.createDt  <![CDATA[>=]]> #{stTime}
            </if>
            <if test="endTime!= null and endTime!=''">
                and ms.createDt <![CDATA[<=]]> #{endTime}
            </if>
            <if test="isMarket!=null and isMarket!=''">
                and ms.isMarket=#{isMarket}
            </if>
            <if test="mcsStatus != null and mcsStatus != ''">
                and mcs.`status` = #{mcsStatus}
            </if>

            <if test="startTime != null and startTime != ''">
                and mcs.createTime <![CDATA[ >= ]]> #{startTime}
            </if>
            <if test="endTime != null and endTime != ''">
                and mcs.createTime  <![CDATA[ <= ]]> #{endTime}
            </if>

            and ua.userType = 'promoter'
        </where>
    </select>

    <select id="queryMerchantStoreNoPageCount" parameterType="java.util.Map" resultType="java.lang.Integer">
        SELECT count(*) from tb_pluss_merchant_store ms
        JOIN tb_pluss_merchant_base_info mbi on ms.merchantCode = mbi.merchantCode
        LEFT JOIN tb_pluss_user_app ua ON ms.merchantCode = ua.merchantCode
        <where>
            <if test="merchantCode!=null and merchantCode!=''">
                and ms.merchantCode in (SELECT merchantCode
                FROM tb_pluss_merchant_base_info
                WHERE bindingCode =(SELECT bindingCode
                FROM tb_pluss_merchant_base_info
                where merchantCode = #{merchantCode}))
            </if>
            <if test="merchantType!=null and merchantType!=''">
                and mbi.merchantType =#{merchantType}
            </if>
            <if test="merchantName!=null and merchantName!=''">
                and ms.merchantName LIKE CONCAT('%',#{merchantName},'%')
            </if>
            <if test="storeName!=null and storeName!=''">
                and ms.storeName LIKE CONCAT('%',#{storeName},'%')
            </if>
            <if test="status == '1'.toString() ">
                and (ms.status in ('1','0') OR ms.status IS NULL)
            </if>
            <if test="status == '2'.toString() ">
                and ms.status = '2'
            </if>
            <if test="productDesc!=null and productDesc!=''">
                and mbi.productDesc=#{productDesc}
            </if>
            <if test="payEcdemicSwitch == '2'.toString() ">
                and (ms.payEcdemicSwitch = '0' OR ms.payEcdemicSwitch IS NULL)
            </if>
            <if test="payEcdemicSwitch == '1'.toString() ">
                and ms.payEcdemicSwitch='1'
            </if>
            <if test="address!=null and address!=''">
                and ms.address LIKE CONCAT('%',#{address},'%')
            </if>
            <if test="userId!=null">
                and ua.userId = #{userId}
            </if>
            <if test="merchantType!=null and merchantType!=''">
                and mbi.merchantType=#{merchantType}
            </if>
            <if test="alias!=null and alias!=''">
                and mbi.alias like concat("%",#{alias},"%")
            </if>
            <if test="stTime!= null">
                and ms.createDt  <![CDATA[>=]]> #{stTime}
            </if>
            <if test="endTime!= null">
                and ms.createDt <![CDATA[<=]]> #{endTime}
            </if>
            <if test="isMarket!=null and isMarket!=''">
                and ms.isMarket=#{isMarket}
            </if>
            and ua.userType = 'promoter'
        </where>
    </select>

    <select id="queryMerchantStorePageApp" parameterType="java.util.Map"
            resultType="cn.pluss.platform.entity.MerchantStore">
        SELECT * from tb_pluss_merchant_store
        <where>
            <if test="id!= null">
                and id = #{id}
            </if>
            <if test="merchantCode!= null">
                and merchantCode = #{merchantCode}
            </if>
            <if test="storeId!= null">
                and storeId = #{storeId}
            </if>
            <if test="storeName!= null">
                and storeName LIKE CONCAT("%",#{storeName},"%")
            </if>
            <if test="linkName!= null">
                and linkName = #{linkName}
            </if>
            <if test="linkPhone!= null">
                and linkPhone = #{linkPhone}
            </if>
            <if test="address!= null">
                and address = #{address}
            </if>
            <if test="storeDesc!= null">
                and storeDesc = #{storeDesc}
            </if>
            <if test="logo!= null">
                and logo = #{logo}
            </if>
            <if test="creator!= null">
                and creator = #{creator}
            </if>

            <if test="startTime!= null and startTime!=''">
                <![CDATA[
                            and  DATE_FORMAT(createDt, '%Y-%m-%d %H:%i:%S')>=DATE_FORMAT(#{startTime}, '%Y-%m-%d %H:%i:%S')
                         ]]>
            </if>
            <if test="endTime!= null and endTime!=''">
                <![CDATA[
                            and  DATE_FORMAT(createDt, '%Y-%m-%d %H:%i:%S')<=DATE_FORMAT(#{endTime}, '%Y-%m-%d %H:%i:%S')
                         ]]>
            </if>

            <if test="openingTime!= null">
                and openingTime = #{openingTime}
            </if>
            <if test="status!= null">
                and status = #{status}
            </if>
            <if test="merchantName!= null">
                and merchantName = #{merchantName}
            </if>
            <if test="parentCode!= null">
                and parentCode = #{parentCode}
            </if>
            <if test="email!= null">
                and email = #{email}
            </if>
            <if test="isAccount!= null">
                and isAccount = #{isAccount}
            </if>
            <if test="loginName!= null">
                and loginName = #{loginName}
            </if>
            <if test="paymentCodeUrl!= null">
                and paymentCodeUrl = #{paymentCodeUrl}
            </if>
        </where>
        order by id desc limit #{pageSize} offset #{offset}
    </select>

    <select id="queryMerchantStorePageCountApp" parameterType="java.util.Map" resultType="java.lang.Integer">
        SELECT count(*) from tb_pluss_merchant_store
        <where>
            <if test="id!= null">
                and id = #{id}
            </if>
            <if test="merchantCode!= null">
                and merchantCode = #{merchantCode}
            </if>
            <if test="storeId!= null">
                and storeId = #{storeId}
            </if>
            <if test="storeName!= null">
                and storeName LIKE CONCAT("%",#{storeName},"%")
            </if>
            <if test="linkName!= null">
                and linkName = #{linkName}
            </if>
            <if test="linkPhone!= null">
                and linkPhone = #{linkPhone}
            </if>
            <if test="address!= null">
                and address = #{address}
            </if>
            <if test="storeDesc!= null">
                and storeDesc = #{storeDesc}
            </if>
            <if test="logo!= null">
                and logo = #{logo}
            </if>
            <if test="creator!= null">
                and creator = #{creator}
            </if>
            <if test="startTime!= null and startTime!=''">
                <![CDATA[
                            and  DATE_FORMAT(createDt, '%Y-%m-%d %H:%i:%S')>=DATE_FORMAT(#{startTime}, '%Y-%m-%d %H:%i:%S')
                         ]]>
            </if>
            <if test="endTime!= null and endTime!=''">
                <![CDATA[
                            and  DATE_FORMAT(createDt, '%Y-%m-%d %H:%i:%S')<=DATE_FORMAT(#{endTime}, '%Y-%m-%d %H:%i:%S')
                         ]]>
            </if>
            <if test="openingTime!= null">
                and openingTime = #{openingTime}
            </if>
            <if test="status!= null">
                and status = #{status}
            </if>
            <if test="merchantName!= null">
                and merchantName = #{merchantName}
            </if>
            <if test="parentCode!= null">
                and parentCode = #{parentCode}
            </if>
            <if test="email!= null">
                and email = #{email}
            </if>
            <if test="isAccount!= null">
                and isAccount = #{isAccount}
            </if>
            <if test="loginName!= null">
                and loginName = #{loginName}
            </if>
        </where>
    </select>

    <select id="queryNewStoreListPage" parameterType="java.util.Map" resultMap="StoreInfoVO, cn.pluss.platform.mapper.CommonMapper.count">
        SELECT SQL_CALC_FOUND_ROWS
        ms.id AS id,
        mbi.id AS mercId,
        ms.isMarket AS isMarket,
        ua.userType AS userType,
        ms.storeId AS storeId,
        ms.storeName AS storeName,
        ms.logo AS logo,
        mbi.merchantName AS merchantName,
        mbi.merchantType AS merchantType,
        mbi.alias AS alias,
        mbi.isUnionPay AS isUnionPay,
        ms.`status` AS `status`,
        ms.payEcdemicSwitch AS payEcdemicSwitch,
        ms.merchantCode AS merchantCode,
        mbi.productDesc AS productDesc,
        mbi.address AS address,
        mbi.md5Key AS md5Key,
        mbi.subAppId AS subAppId,
        mbi.appid AS appid,
        IFNULL(mr.rate,38) AS rate,
        mr.updateTime AS updateTime,
        mr.previousRate AS previousRate,
        ms.isMarket,
        mbi.province,
        mcs.valid validStatus,
        mbi.city,
        mbi.district,
        t.location,
        ua.userId AS userId,
        (
        CASE
        (
        SELECT
        COUNT(*)
        FROM
        tb_pluss_merchant_base_info mi
        WHERE
        mi.merchantCode = ms.merchantCode
        AND mi.bussAuthNum IS NOT NULL
        AND mi.principalPerson IS NOT NULL
        AND mi.bussAuthStartTime IS NOT NULL
        AND mi.bussAuthEndTime IS NOT NULL
        )
        WHEN 1 THEN
        '营业执照'
        WHEN 0 THEN
        '小微'
        END
        ) AS storeType,
        mcs.`status` AS mcsStatus,
        mcs.remark AS remark,
        mcs.channel AS channel,
        mcs.merchantId AS merchantId,
        IF(mcs.channel = 4,mcs.settlementType,'D1') AS settleType,
        mcs.id as csId,
        op.operatRemark as operatRemark,
        mcs.createTime as incomTime
        FROM
        tb_pluss_merchant_store ms
        LEFT JOIN (SELECT CONCAT(province,city,district,address) as location,merchantCode FROM
        tb_pluss_merchant_base_info
        ) t ON t.merchantCode = ms.merchantCode
        LEFT JOIN tb_pluss_merchant_base_info mbi ON ms.merchantCode = mbi.merchantCode
        LEFT JOIN tb_pluss_merchant_rate mr ON mbi.userId = mr.userId
        LEFT JOIN tb_pluss_user_app ua ON ms.merchantCode = ua.merchantCode
        LEFT JOIN tb_pluss_merchant_channel_status mcs ON ms.merchantCode = mcs.merchantCode
        LEFT JOIN (SELECT IF(GROUP_CONCAT(remark, '\n') = " " ,"",GROUP_CONCAT(remark, '\n')) AS operatRemark,userId
        FROM
        tb_pluss_operation_record WHERE dictValue IN ('KTGRDZWL', 'GBGRDZWL', 'GBSHJYGN', 'KTSHJYGN') GROUP BY userId)
        op on op.userId = mbi.userId
        <where>
            <if test="userId != null and userId != ''">
                and ua.userId = #{userId}
            </if>
            <if test="merchantCode!=null and merchantCode!=''">
                and ms.merchantCode = #{merchantCode}
            </if>
            <if test="merchantType!=null and merchantType!=''">
                and mbi.merchantType = #{merchantType}
            </if>
            <if test="merchantName!=null and merchantName!=''">
                and mbi.merchantName LIKE CONCAT('%',#{merchantName},'%')
            </if>
            <if test="storeName!=null and storeName!=''">
                and ms.storeName LIKE CONCAT('%',#{storeName},'%')
            </if>
            <if test="status == '1'.toString() ">
                and (ms.status in ('1','0') OR ms.status IS NULL)
            </if>
            <if test="status == '2'.toString() ">
                and ms.status = '2'
            </if>
            <if test="address!=null and address!=''">
                and ms.address LIKE CONCAT('%',#{address},'%')
            </if>
            <if test="payEcdemicSwitch == '2'.toString() ">
                and (ms.payEcdemicSwitch = '0' OR ms.payEcdemicSwitch IS NULL)
            </if>
            <if test="payEcdemicSwitch == '1'.toString() ">
                and ms.payEcdemicSwitch='1'
            </if>
            <if test="isMarket!=null and isMarket!=''">
                and ms.isMarket=#{isMarket}
            </if>
            <if test="id!=null and id!=''">
                and ms.id LIKE CONCAT('%',#{id},'%')
            </if>
            <if test="merchantType!=null and merchantType!=''">
                and mbi.merchantType=#{merchantType}
            </if>
            <if test="alias!=null and alias!=''">
                and mbi.alias like concat("%",#{alias},"%")
            </if>
            <if test="location != null and location != ''">
                and t.location like concat("%",#{location},"%")
            </if>
            <if test="mcsStatus != null and mcsStatus != ''">
                and mcs.`status` = #{mcsStatus}
            </if>

            <if test="startTime != null and startTime != ''">
                and mcs.createTime <![CDATA[ >= ]]> #{startTime}
            </if>
            <if test="endTime != null and endTime != ''">
                and mcs.createTime  <![CDATA[ <= ]]> #{endTime}
            </if>

            and userType = 'promoter'
        </where>
        order by ms.id desc limit #{pageSize} offset #{offset};
        SELECT found_rows() as count
    </select>

    <update id="disableMerchantStore" parameterType="java.util.Map">
        update tb_pluss_merchant_store ms
            LEFT JOIN tb_pluss_merchant_base_info mbi
        ON ms.merchantCode = mbi.merchantCode
            set status=#{status}
        where mbi.userId = ${id}
    </update>

    <update id="pesUpdateMerchantStore" parameterType="java.util.Map">
        update tb_pluss_merchant_store ms
            LEFT JOIN tb_pluss_merchant_base_info mbi
        ON ms.merchantCode = mbi.merchantCode
            set payEcdemicSwitch=#{payEcdemicSwitch}
        where mbi.userId = ${id}
    </update>

    <update id="operatMarketMerchantStore" parameterType="java.util.Map">
        update tb_pluss_merchant_store
        set isMarket = #{isMarker}
        where id in
        <foreach collection="ids" open="(" separator="," close=")" item="item" index="index">
            #{item}
        </foreach>
    </update>

    <select id="showMerchantStoreReceipt" resultType="cn.pluss.platform.vo.StoreInfoVO">
        SELECT ms.merchantCode AS merchantCode,
               ms.storeId      AS storeId,
               ua.userId       as userId,
               ms.storeName    as storeName
        FROM tb_pluss_user_app ua
                 LEFT JOIN tb_pluss_merchant_store ms
                           on ms.merchantCode = ua.merchantCode
        WHERE ua.userId = #{userId}
    </select>

    <select id="queryStoreSignList" parameterType="java.util.Map" resultType="cn.pluss.platform.vo.StoreSignVO">
        SELECT ms.linkPhone as linkPhone,ms.merchantName as merchantName,ms.id,ms.storeId as storeId,ms.storeName as
        storeName,mbi.alias as alias,mbc.id as mbcId,ua.leshuaStatus as
        leshuaStatus,ua.wechatStatus as wechatStatus,mbi.aliRate as aliRate,mbi.wechatRate as wechatRate,mbi.leshuaRate
        as leshuaRate,ua.userId as userId FROM tb_pluss_merchant_store ms
        LEFT JOIN tb_pluss_merchant_base_info mbi ON ms.merchantCode=mbi.merchantCode
        LEFT JOIN tb_pluss_merchant_bank_card mbc ON mbc.merchantCode=ms.merchantCode
        LEFT JOIN tb_pluss_user_app ua ON ua.userId=mbi.userId
        <where>
            <if test="storeId!=null and storeId!=''">
                and ms.storeId LIKE CONCAT('%',#{storeId},'%')
            </if>
            <if test="alias!=null and alias!=''">
                and mbi.alias LIKE CONCAT('%',#{alias},'%')
            </if>
            <if test="storeName!=null and storeName!=''">
                and ms.storeName LIKE CONCAT('%',#{storeName},'%')
            </if>
            <if test="merchantCode!=null and merchantCode!=''">
                and ms.merchantCode = #{merchantCode}
            </if>
            <if test="userId!=null">
                and ua.userId = #{userId}
            </if>
            <if test="linkPhone!=null and linkPhone!=''">
                and ms.linkPhone =#{linkPhone}
            </if>
            and ua.userType = 'promoter'
        </where>
        order by ms.id desc limit #{pageSize} offset #{offset}
    </select>

    <select id="selectStatus" parameterType="java.util.Map" resultType="cn.pluss.platform.vo.StoreInfoVO">
        select *
        from tb_pluss_merchant_store
        where id = #{id}
    </select>

    <select id="selectPage2" resultType="cn.pluss.platform.vo.StoreInfoVO">
        SELECT DISTINCT ms.id                         AS id,
                        mbi.id                        AS mercId,
                        ms.isMarket                   AS isMarket,
                        ua.userType                   AS userType,
                        ms.storeId                    AS storeId,
                        ms.storeName                  AS storeName,
                        ms.logo                       AS logo,
                        mbi.merchantName              AS merchantName,
                        mbi.merchantType              AS merchantType,
                        mbi.alias                     AS alias,
                        ms.`status`                   AS `status`,
                        ms.payEcdemicSwitch           AS payEcdemicSwitch,
                        mbi.merchantCode              AS merchantCode,
                        mbi.productDesc               AS productDesc,
                        mbi.address                   AS address,
                        IFNULL(mr.rate, 38)           AS rate,
                        mr.updateTime                 AS updateTime,
                        mr.previousRate               AS previousRate,
                        ms.isMarket,
                        mbi.province,
                        mbi.city,
                        mbi.district,
                        t.location,
                        ua.userId                     AS userId,
                        (
                            CASE
                                (
                                    SELECT COUNT(*)
                                    FROM tb_pluss_merchant_base_info mi
                                    WHERE mi.merchantCode = ms.merchantCode
                                      AND mi.bussAuthNum IS NOT NULL
                                      AND mi.principalPerson IS NOT NULL
                                      AND mi.bussAuthStartTime IS NOT NULL
                                      AND mi.bussAuthEndTime IS NOT NULL
                                )
                                WHEN 1 THEN
                                    '营业执照'
                                WHEN 0 THEN
                                    '小微'
                                END
                            )                         AS storeType,
                        mcs.remark                    AS remark,
                        IF(mcs.channel = 4, '0', '1') AS settleType,
                        mcs.id                        as csId
        FROM tb_pluss_merchant_store ms
                 LEFT JOIN (SELECT CONCAT(province, city, district, address) as location, merchantCode
                            FROM tb_pluss_merchant_base_info
        ) t ON t.merchantCode = ms.merchantCode
                 LEFT JOIN tb_pluss_merchant_base_info mbi ON ms.merchantCode = mbi.merchantCode
                 LEFT JOIN tb_pluss_merchant_rate mr ON mbi.userId = mr.userId
                 LEFT JOIN tb_pluss_user_app ua ON ms.merchantCode = ua.merchantCode
                 LEFT JOIN tb_pluss_merchant_channel_status mcs ON ms.merchantCode = mcs.merchantCode
            ${ew.customSqlSegment}
    </select>

</mapper>
