<?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.ruoyi.frequency.store.mapper.StoreMapper">

    <resultMap type="com.ruoyi.frequency.store.entity.Store" id="StoreResult">
        <result property="id"    column="id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="customerId"    column="customer_id"    />
        <result property="sysUserId"    column="sys_user_id"    />
        <result property="afterSaleDays"    column="after_sale_days"    />
        <result property="nickname"    column="nickname"    />
        <result property="avatar"    column="avatar"    />
        <result property="account"    column="account"    />
        <result property="mobile"    column="mobile"    />
        <result property="signature"    column="signature"    />
        <result property="loginPwd"    column="login_pwd"    />
        <result property="payPwd"    column="pay_pwd"    />
        <result property="cancellationTime"    column="cancellation_time"    />
        <result property="fansNum"    column="fansNum"    />
        <result property="followNum"    column="followNum"    />
        <result property="balance"    column="balance"    />
        <result property="likeNum"    column="like_num"    />
        <result property="isBond"    column="is_bond"    />
        <result property="bondAmount"    column="bond_amount"    />
        <result property="invitationCode"    column="invitation_code"    />
        <result property="bindEnterpriseId"    column="bind_enterprise_id"    />
        <result property="wecomQrcode"    column="wecom_qrcode"    />
        <result property="enterDate"    column="enter_date"    />
        <result property="area"    column="area"    />
        <result property="onlineStatus"    column="online_status"    />
        <result property="onlineDuration"    column="online_duration"    />
        <result property="wechatOpenid"    column="wechat_openid"    />
        <result property="income"    column="income"    />
        <result property="violationDeduction"    column="violation_deduction"    />
        <result property="levelId"    column="level_id"    />
        <result property="star"    column="star"    />
        <result property="commissionRatio"    column="commission_ratio"    />
        <result property="levelName"    column="levelName"    />
        <result property="isAuth"    column="isAuth"    />
        <result property="isHighendAuth"    column="isHighendAuth"    />
        <result property="closeMessage"    column="close_message"    />
        <result property="specialityArea"    column="speciality_area"    />
        <result property="withdrawableAmount"    column="withdrawableAmount"    />
        <result property="ifHighend"    column="ifHighend"    />
        <result property="isPlatform"    column="is_platform"    />
        <result property="integral"    column="integral"    />
        <result property="onceWorkCompanys"    column="once_work_companys"    />
        <result property="accumulateIntegral"    column="accumulate_integral"    />
    </resultMap>

    <sql id="selectStoreVo">
        SELECT t.id,
               t.create_by,
               t.create_time,
               t.update_by,
               t.update_time,
               t.del_flag,
               t.customer_id,
               t.sys_user_id,
               t.after_sale_days,
               t.nickname,
               t.name,
               t.avatar,
               t.account,
               t.mobile,
               t.signature,
               t.login_pwd,
               t.pay_pwd,
               t.cancellation_time,
               (SELECT count(1) FROM t_follow f WHERE f.del_flag = 1 AND f.user_type = 2 AND f.user_id = t.id) fansNum,
               (SELECT count(1)
                FROM t_follow f
                WHERE f.del_flag = 1
                  AND f.follower_user_type = 2
                  AND f.follower_user_id = t.id)                                                               followNum,
               t.balance,
               t.like_num,
               t.is_bond,
               t.bond_amount,
               t.invitation_code,
               t.bind_enterprise_id,
               t.wecom_qrcode,
               t.enter_date,
               t.area,
               t.online_status,
               t.online_duration,
               t.wechat_openid,
               t.income,
               t.violation_deduction,
               t.level_id,
               t.remark,
               t.star,
               l.`name`                                                                                        levelName,
               t.close_message,
               t.is_platform,
               t.is_dd_auth,
               t.commission_ratio,
               case
                   when t3.id is not null and t3.type = 1 then t3.result
                   else 0
                   end as                                                                                      isAuth,
               case when t4.id is not null then t4.status else 0 end                                           isHighendAuth,
               case when t4.id is not null AND t4.`status` >= 3 then 2 else 1 end                              ifHighend,
               t.speciality_area,
               (SELECT
                        sum(IFNULL(wt.price,0))
                        FROM
                        t_wallet_record wt
                        WHERE
                        wt.del_flag = 1
                        AND (
                        (
                        wt.record_type IN (6, 8)
                        AND wt.create_time  &lt; #{beginOfMonth}
                        )
                        OR wt.record_type IN (2, 3, 7, 10, 11, 12, 17, 20)
                        )
                        AND wt.user_type = 2
                        AND wt.user_id = t.id)                       withdrawableAmount,
               t.integral,
               t.once_work_companys,
               t.accumulate_integral,
               t3.sex,
               (SELECT count(1)
                FROM t_order o
                WHERE o.first_status = 2 AND o.store_id = t.id ) orderCount,
                    (
                SELECT
                    IFNULL(ROUND(AVG(o.amount), 2) , 0)
                FROM
                    t_order o
                WHERE
                    o.first_status = 2
                  AND o.store_id = t.id
                    ) unitPrice
                    , (
                SELECT
                    create_time
                FROM
                    t_order o
                WHERE
                    o.first_status = 2
                  AND o.store_id = t.id
                ORDER BY
                    o.create_time DESC
                    LIMIT 1
                    ) lastTransactionTime,
                    (
                SELECT
                    IFNULL(sum (o.amount), 0)
                FROM
                    t_order o
                WHERE
                    o.first_status = 2
                  AND o.store_id = t.id
                  AND DATE_FORMAT(o.create_time
                    , '%Y-%m-01') >= DATE_FORMAT(CURDATE()
                    , '%Y-%m-01')
                    ) monthAmount
        FROM
            t_store AS t
            LEFT JOIN t_level l
        ON l.type = 2 and l.id = (
            SELECT
            l2.id
            FROM
            t_level l2
            WHERE
            l2.del_flag = 1
            and l2.type = 2
            and l2.compliance &lt;= t.income
            ORDER BY
            l2.compliance DESC
            LIMIT 1
            )
            LEFT JOIN t_auth AS t3 ON t3.store_id = t.id
            AND t3.del_flag = 1
            AND t3.result = 2
            AND t3.pay_status = 2
            LEFT JOIN t_highend_auth AS t4 ON t4.store_id = t.id
            AND t4.del_flag = 1
    </sql>

    <select id="selectStoreList" parameterType="com.ruoyi.frequency.store.entity.Store" resultMap="StoreResult">
        <include refid="selectStoreVo"/>
        <where> and t.del_flag != 2 and t.bind_enterprise_id is null
            <if test="isPlatform != null "> and t.is_platform = #{isPlatform}</if>
            <if test="delFlag != null "> and t.del_flag = #{delFlag}</if>
            <if test="customerId != null "> and t.customer_id = #{customerId}</if>
            <if test="sysUserId != null "> and t.sys_user_id = #{sysUserId}</if>
            <if test="afterSaleDays != null "> and t.after_sale_days = #{afterSaleDays}</if>
            <if test="nickname != null  and nickname != ''"> and t.nickname like concat('%', #{nickname}, '%')</if>
            <if test="avatar != null  and avatar != ''"> and t.avatar = #{avatar}</if>
            <if test="account != null  and account != ''"> and t.account like concat('%', #{account}, '%')</if>
            <if test="mobile != null  and mobile != ''"> and t.mobile like concat('%', #{mobile}, '%')</if>
            <if test="signature != null  and signature != ''"> and t.signature = #{signature}</if>
            <if test="loginPwd != null  and loginPwd != ''"> and t.login_pwd = #{loginPwd}</if>
            <if test="payPwd != null  and payPwd != ''"> and t.pay_pwd = #{payPwd}</if>
            <if test="cancellationTime != null "> and t.cancellation_time = #{cancellationTime}</if>
            <if test="fansNum != null "> and t.fans_num = #{fansNum}</if>
            <if test="followNum != null "> and t.follow_num = #{followNum}</if>
            <if test="balance != null "> and t.balance = #{balance}</if>
            <if test="likeNum != null "> and t.like_num = #{likeNum}</if>
            <if test="isBond != null "> and t.is_bond = #{isBond}</if>
            <if test="bondAmount != null "> and t.bond_amount = #{bondAmount}</if>
            <if test="invitationCode != null  and invitationCode != ''"> and t.invitation_code = #{invitationCode}</if>
            <if test="bindEnterpriseId != null "> and t.bind_enterprise_id = #{bindEnterpriseId}</if>
            <if test="wecomQrcode != null  and wecomQrcode != ''"> and t.wecom_qrcode = #{wecomQrcode}</if>
            <if test="enterDate != null "> and t.enter_date = #{enterDate}</if>
            <if test="area != null  and area != ''"> and t.area = #{area}</if>
            <if test="onlineDuration != null "> and t.online_duration = #{onlineDuration}</if>
            <if test="wechatOpenid != null  and wechatOpenid != ''"> and t.wechat_openid = #{wechatOpenid}</if>
            <if test="income != null "> and t.income = #{income}</if>
            <if test="violationDeduction != null "> and t.violation_deduction = #{violationDeduction}</if>
            <if test="levelId != null "> and l.id = #{levelId}</if>
            <if test="star != null "> and t.star = #{star}</if>
            <if test="authStatus != null ">
                <if test="authStatus == 1 "> and t3.id is null and t4.id is null</if>
                <if test="authStatus == 2 "> and t3.id is not null</if>
                <if test="authStatus == 3 "> and t4.id is not null</if>
            </if>
            <if test="beginTime != null ">
                and  t.create_time >= #{beginTime}

            </if>
            <if test="endTime != null ">
                and  t.create_time &lt; #{endTime}
            </if>
            <if test="onlineStatus != null ">
                <if test="onlineStatus == 1 ">
                AND t.id in
                    <foreach item="id" collection="userIds" open="(" separator="," close=")">
                        #{id}
                    </foreach>
                </if>
                <if test="onlineStatus == 2 ">
                    AND t.id not in
                    <foreach item="id" collection="userIds" open="(" separator="," close=")">
                        #{id}
                    </foreach>
                </if>
             </if>

            <choose>
                <when test="minYear == null and maxYear != null">
                    AND ifnull(YEAR(NOW())-YEAR(t.enter_date),0) >= #{maxYear}
                </when>
                <otherwise>
                    <if test="minYear != null  and minYear != ''">
                        AND ifnull(YEAR(NOW())-YEAR(t.enter_date),0) >= #{minYear}
                    </if>
                    <if test="maxYear != null  and maxYear != ''">
                        AND ifnull(YEAR(NOW())-YEAR(t.enter_date),0) &lt; #{maxYear}
                    </if>
                </otherwise>
            </choose>
            <if test="screen != null  and screen != ''">
                <if test="screen == 1">
                    AND t.id not in (select ha.store_id from t_highend_auth ha where ha.del_flag = 1 )
                </if>
            </if>
        </where>
        <choose>
            <when test="sortType != null ">
                <if test="sortType == 1 ">
                    order by t.online_duration desc
                </if>
                <if test="sortType == 2 ">
                    order by t.online_duration
                </if>
            </when>
            <otherwise>
                order by t.create_time desc
            </otherwise>
        </choose>
    </select>

    <select id="statistics" parameterType="com.ruoyi.frequency.store.entity.Store" resultType="com.ruoyi.frequency.store.model.result.StoreCount">
        SELECT
        count(1) number,
        ifnull(sum(t.online_duration),0) online_duration,
        ifnull(sum(t.balance),0) balance,

        IFNULL((SELECT sum(wt.price)
        FROM t_wallet_record wt
        where
         (
        (wt.record_type in (6, 8)  AND wt.create_time &lt; #{beginOfMonth})
        or wt.record_type in (2, 3,7,10,11,12)
        )
        AND wt.user_type = 2
        AND wt.user_id = t.id),
        0) withdrawableAmount,
        ifnull(sum(t.income),0) income,
        ifnull(sum(t.bond_amount),0) bond_amount
        FROM
        t_store AS t
        where
        t.id in
        <foreach item="id" collection="list" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>

    <select id="onlineNumber" parameterType="com.ruoyi.frequency.store.entity.Store" resultType="java.lang.Integer">
        SELECT
        count(1) number
        FROM
        t_store AS t
        LEFT JOIN t_level l ON l.type = 2 and l.id = (
        SELECT
        l2.id
        FROM
        t_level l2
        WHERE
        l2.del_flag = 1
        and l2.type = 2
        and l2.compliance &lt;= t.income
        ORDER BY
        l2.compliance DESC
        LIMIT 1
        )
        LEFT JOIN t_auth AS t3 ON t3.store_id = t.id
        AND t3.del_flag = 1
        AND t3.result = 2
        LEFT JOIN t_highend_auth AS t4 ON t4.store_id = t.id
        AND t4.del_flag = 1
        <where> and t.del_flag != 2 and t.bind_enterprise_id is null
            <if test="isPlatform != null "> and t.is_platform = #{isPlatform}</if>
            <if test="delFlag != null "> and t.del_flag = #{delFlag}</if>
            <if test="customerId != null "> and t.customer_id = #{customerId}</if>
            <if test="sysUserId != null "> and t.sys_user_id = #{sysUserId}</if>
            <if test="afterSaleDays != null "> and t.after_sale_days = #{afterSaleDays}</if>
            <if test="nickname != null  and nickname != ''"> and t.nickname like concat('%', #{nickname}, '%')</if>
            <if test="avatar != null  and avatar != ''"> and t.avatar = #{avatar}</if>
            <if test="account != null  and account != ''"> and t.account like concat('%', #{account}, '%')</if>
            <if test="mobile != null  and mobile != ''"> and t.mobile like concat('%', #{mobile}, '%')</if>
            <if test="signature != null  and signature != ''"> and t.signature = #{signature}</if>
            <if test="loginPwd != null  and loginPwd != ''"> and t.login_pwd = #{loginPwd}</if>
            <if test="payPwd != null  and payPwd != ''"> and t.pay_pwd = #{payPwd}</if>
            <if test="cancellationTime != null "> and t.cancellation_time = #{cancellationTime}</if>
            <if test="fansNum != null "> and t.fans_num = #{fansNum}</if>
            <if test="followNum != null "> and t.follow_num = #{followNum}</if>
            <if test="balance != null "> and t.balance = #{balance}</if>
            <if test="likeNum != null "> and t.like_num = #{likeNum}</if>
            <if test="isBond != null "> and t.is_bond = #{isBond}</if>
            <if test="bondAmount != null "> and t.bond_amount = #{bondAmount}</if>
            <if test="invitationCode != null  and invitationCode != ''"> and t.invitation_code = #{invitationCode}</if>
            <if test="bindEnterpriseId != null "> and t.bind_enterprise_id = #{bindEnterpriseId}</if>
            <if test="wecomQrcode != null  and wecomQrcode != ''"> and t.wecom_qrcode = #{wecomQrcode}</if>
            <if test="enterDate != null "> and t.enter_date = #{enterDate}</if>
            <if test="area != null  and area != ''"> and t.area = #{area}</if>
            <if test="onlineDuration != null "> and t.online_duration = #{onlineDuration}</if>
            <if test="wechatOpenid != null  and wechatOpenid != ''"> and t.wechat_openid = #{wechatOpenid}</if>
            <if test="income != null "> and t.income = #{income}</if>
            <if test="violationDeduction != null "> and t.violation_deduction = #{violationDeduction}</if>
            <if test="levelId != null "> and l.id = #{levelId}</if>
            <if test="star != null "> and t.star = #{star}</if>
            <if test="authStatus != null ">
                <if test="authStatus == 1 "> and t3.id is null and t4.id is null</if>
                <if test="authStatus == 2 "> and t3.id is not null</if>
                <if test="authStatus == 3 "> and t4.id is not null</if>
            </if>
            <if test="beginTime != null ">
                and  t.create_time >= #{beginTime}

            </if>
            <if test="endTime != null ">
                and  t.create_time &lt; #{endTime}
            </if>
            <if test="onlineStatus != null ">
                <if test="onlineStatus == 1 ">
                    AND t.id in
                    <foreach item="id" collection="userIds" open="(" separator="," close=")">
                        #{id}
                    </foreach>
                </if>
                <if test="onlineStatus == 2 ">
                    AND t.id not in
                    <foreach item="id" collection="userIds" open="(" separator="," close=")">
                        #{id}
                    </foreach>
                </if>
            </if>

            <choose>
                <when test="minYear == null and maxYear != null">
                    AND ifnull(YEAR(NOW())-YEAR(t.enter_date),0) >= #{maxYear}
                </when>
                <otherwise>
                    <if test="minYear != null  and minYear != ''">
                        AND ifnull(YEAR(NOW())-YEAR(t.enter_date),0) >= #{minYear}
                    </if>
                    <if test="maxYear != null  and maxYear != ''">
                        AND ifnull(YEAR(NOW())-YEAR(t.enter_date),0) &lt; #{maxYear}
                    </if>
                </otherwise>
            </choose>
            <if test="screen != null  and screen != ''">
                <if test="screen == 1">
                    AND t.id not in (select ha.store_id from t_highend_auth ha where ha.del_flag = 1 )
                </if>
            </if>
        </where>
        <choose>
            <when test="sortType != null ">
                <if test="sortType == 1 ">
                    order by t.online_duration desc
                </if>
                <if test="sortType == 2 ">
                    order by t.online_duration
                </if>
            </when>
            <otherwise>
                order by t.create_time desc
            </otherwise>
        </choose>
    </select>

    <select id="selectStoreById" parameterType="Long" resultMap="StoreResult">
        <include refid="selectStoreVo"/>
        where t.id = #{id}
    </select>

    <insert id="insertStore" parameterType="com.ruoyi.frequency.store.entity.Store">
        insert into t_store
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="createUser != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateUser != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="customerId != null">customer_id,</if>
            <if test="sysUserId != null">sys_user_id,</if>
            <if test="afterSaleDays != null">after_sale_days,</if>
            <if test="nickname != null">nickname,</if>
            <if test="avatar != null">avatar,</if>
            <if test="account != null">account,</if>
            <if test="mobile != null">mobile,</if>
            <if test="signature != null">signature,</if>
            <if test="loginPwd != null">login_pwd,</if>
            <if test="payPwd != null">pay_pwd,</if>
            <if test="cancellationTime != null">cancellation_time,</if>
            <if test="fansNum != null">fans_num,</if>
            <if test="followNum != null">follow_num,</if>
            <if test="balance != null">balance,</if>
            <if test="likeNum != null">like_num,</if>
            <if test="isBond != null">is_bond,</if>
            <if test="bondAmount != null">bond_amount,</if>
            <if test="invitationCode != null and invitationCode != ''">invitation_code,</if>
            <if test="bindEnterpriseId != null">bind_enterprise_id,</if>
            <if test="wecomQrcode != null">wecom_qrcode,</if>
            <if test="enterDate != null">enter_date,</if>
            <if test="area != null">area,</if>
            <if test="onlineStatus != null">online_status,</if>
            <if test="onlineDuration != null">online_duration,</if>
            <if test="wechatOpenid != null">wechat_openid,</if>
            <if test="income != null">income,</if>
            <if test="violationDeduction != null">violation_deduction,</if>
            <if test="levelId != null">level_id,</if>
            <if test="star != null">star,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="createUser != null">#{createUser},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateUser != null">#{updateUser},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="customerId != null">#{customerId},</if>
            <if test="sysUserId != null">#{sysUserId},</if>
            <if test="afterSaleDays != null">#{afterSaleDays},</if>
            <if test="nickname != null">#{nickname},</if>
            <if test="avatar != null">#{avatar},</if>
            <if test="account != null">#{account},</if>
            <if test="mobile != null">#{mobile},</if>
            <if test="signature != null">#{signature},</if>
            <if test="loginPwd != null">#{loginPwd},</if>
            <if test="payPwd != null">#{payPwd},</if>
            <if test="cancellationTime != null">#{cancellationTime},</if>
            <if test="fansNum != null">#{fansNum},</if>
            <if test="followNum != null">#{followNum},</if>
            <if test="balance != null">#{balance},</if>
            <if test="likeNum != null">#{likeNum},</if>
            <if test="isBond != null">#{isBond},</if>
            <if test="bondAmount != null">#{bondAmount},</if>
            <if test="invitationCode != null and invitationCode != ''">#{invitationCode},</if>
            <if test="bindEnterpriseId != null">#{bindEnterpriseId},</if>
            <if test="wecomQrcode != null">#{wecomQrcode},</if>
            <if test="enterDate != null">#{enterDate},</if>
            <if test="area != null">#{area},</if>
            <if test="onlineStatus != null">#{onlineStatus},</if>
            <if test="onlineDuration != null">#{onlineDuration},</if>
            <if test="wechatOpenid != null">#{wechatOpenid},</if>
            <if test="income != null">#{income},</if>
            <if test="violationDeduction != null">#{violationDeduction},</if>
            <if test="levelId != null">#{levelId},</if>
            <if test="star != null">#{star},</if>
        </trim>
    </insert>

    <update id="updateStore" parameterType="com.ruoyi.frequency.store.entity.Store">
        update t_store
        <trim prefix="SET" suffixOverrides=",">
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="customerId != null">customer_id = #{customerId},</if>
            <if test="sysUserId != null">sys_user_id = #{sysUserId},</if>
            <if test="afterSaleDays != null">after_sale_days = #{afterSaleDays},</if>
            <if test="nickname != null">nickname = #{nickname},</if>
            <if test="avatar != null">avatar = #{avatar},</if>
            <if test="account != null">account = #{account},</if>
            <if test="mobile != null">mobile = #{mobile},</if>
            <if test="signature != null">signature = #{signature},</if>
            <if test="loginPwd != null">login_pwd = #{loginPwd},</if>
            <if test="payPwd != null">pay_pwd = #{payPwd},</if>
            <if test="cancellationTime != null">cancellation_time = #{cancellationTime},</if>
            <if test="fansNum != null">fans_num = #{fansNum},</if>
            <if test="followNum != null">follow_num = #{followNum},</if>
            <if test="balance != null">balance = #{balance},</if>
            <if test="likeNum != null">like_num = #{likeNum},</if>
            <if test="isBond != null">is_bond = #{isBond},</if>
            <if test="bondAmount != null">bond_amount = #{bondAmount},</if>
            <if test="invitationCode != null and invitationCode != ''">invitation_code = #{invitationCode},</if>
            <if test="bindEnterpriseId != null">bind_enterprise_id = #{bindEnterpriseId},</if>
            <if test="wecomQrcode != null">wecom_qrcode = #{wecomQrcode},</if>
            <if test="enterDate != null">enter_date = #{enterDate},</if>
            <if test="area != null">area = #{area},</if>
            <if test="onlineStatus != null">online_status = #{onlineStatus},</if>
            <if test="onlineDuration != null">online_duration = #{onlineDuration},</if>
            <if test="wechatOpenid != null">wechat_openid = #{wechatOpenid},</if>
            <if test="income != null">income = #{income},</if>
            <if test="violationDeduction != null">violation_deduction = #{violationDeduction},</if>
            <if test="levelId != null">level_id = #{levelId},</if>
            <if test="star != null">star = #{star},</if>
        </trim>
        where id = #{id}
    </update>
    <update id="saveIdNo">
        UPDATE t_store
        SET nickname = (
            SELECT
                tt.num
            FROM
                (
                    SELECT
                        count(*) AS num
                    FROM
                        t_store
                    WHERE
                            create_time &lt;= (
                            SELECT
                                create_time
                            FROM
                                t_store
                            WHERE
                                id = #{id}
                        )
                ) tt
        )
        WHERE
            id = #{id}
    </update>

    <delete id="deleteStoreById" parameterType="Long">
        delete from t_store where id = #{id}
    </delete>

    <delete id="deleteStoreByIds" parameterType="String">
        delete from t_store where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>


    <select id="getAuthStore" resultType="java.lang.Integer">
       SELECT
        count(t.id)
        FROM
        t_store AS t
        LEFT JOIN t_auth a ON t.id = a.store_id and a.del_flag = 1
        LEFT JOIN t_enterprise e ON t.bind_enterprise_id = e.id
        LEFT JOIN t_highend_auth h ON t.id = h.store_id and h.status >= 3 and h.del_flag = 1
        WHERE
        t.del_flag = 1
        AND (a.result = 2  or h.status >= 3)
        AND t.bind_enterprise_id is null
        AND t.id in
        <foreach collection="list" item="id" open="(" close=")" separator=",">
           #{id}
        </foreach>
    </select>

    <select id="getCommonAuthStore" resultType="java.lang.Integer">
        SELECT
        count(t.id)
        FROM
        t_store AS t
        LEFT JOIN t_auth a ON t.id = a.store_id and a.del_flag = 1
        WHERE
        t.del_flag = 1
        AND a.result = 2
        AND a.type = 1
        AND t.id in
        <foreach collection="list" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </select>


    <select id="getHighAuthStore" resultType="java.lang.Integer">
        SELECT
        count(t.id)
        FROM
        t_store AS t
        LEFT JOIN t_highend_auth h ON t.id = h.store_id and h.status >= 3 and h.del_flag = 1
        WHERE
        t.del_flag = 1
        AND  h.status >= 3
        AND t.id in
        <foreach collection="list" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </select>


    <select id="getKujialeAuthStore" resultType="java.lang.Integer">
        SELECT
        count(t.id)
        FROM
        t_store AS t
        LEFT JOIN t_auth a ON t.id = a.store_id and a.del_flag = 1
        WHERE
        t.del_flag = 1
        AND a.result = 2
        AND a.type = 3
        AND t.id in
        <foreach collection="list" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </select>
    <select id="getOrderInfo" resultType="com.ruoyi.frequency.store.model.result.OrderResult">
        select * from t_order where id=#{orderId}
    </select>
    <select id="canCancellation" resultType="java.lang.Integer">
        select count(*) from t_order t where t.store_id = #{userId} and t.status in (1,2,3)
    </select>


</mapper>
