<?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="shop.alien.mapper.StoreUserMapper">

    <!-- 查询已删除的用户 -->
    <select id="getRemoveUser" resultType="shop.alien.entity.store.vo.StoreUserVo">
        select concat(name, "(账号已注销)") as name, phone
        FROM store_user
        where id = #{id}
    </select>

    <select id="getUserIncludeDeleted" resultType="shop.alien.entity.store.StoreUser">
        select id, phone, name, nick_name
        FROM store_user
        where id = #{id}
    </select>

    <!-- 通过 store_user 与 store_platform_user_role 联表查主账号下的子账号 id（store_user.id），用于删除/禁用时用子账号 id 判断 -->
    <select id="selectSubAccountUserIdsByMainAccountIdWithRole" resultType="java.lang.Integer">
        SELECT DISTINCT u.id
        FROM store_user u
        INNER JOIN store_platform_user_role r ON u.id = r.user_id AND r.delete_flag = 0
        WHERE u.sub_account_id = #{mainAccountId}
          AND u.account_type = 2
          AND u.delete_flag = 0
    </select>

</mapper>