<?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.ysk.cashier.mybatis.mapper.TbMShopUserMapper">

    <resultMap id="BaseResultMap" type="cn.ysk.cashier.mybatis.entity.TbShopUser">
            <id property="id" column="id" jdbcType="INTEGER"/>
            <result property="amount" column="amount" jdbcType="DECIMAL"/>
            <result property="credit_amount" column="credit_amount" jdbcType="DECIMAL"/>
            <result property="consume_amount" column="consume_amount" jdbcType="DECIMAL"/>
            <result property="consume_number" column="consume_number" jdbcType="INTEGER"/>
            <result property="level_consume" column="level_consume" jdbcType="DECIMAL"/>
            <result property="status" column="status" jdbcType="TINYINT"/>
            <result property="merchant_id" column="merchant_id" jdbcType="VARCHAR"/>
            <result property="shop_id" column="shop_id" jdbcType="VARCHAR"/>
            <result property="user_id" column="user_id" jdbcType="VARCHAR"/>
            <result property="parent_id" column="parent_id" jdbcType="VARCHAR"/>
            <result property="parent_level" column="parent_level" jdbcType="VARCHAR"/>
            <result property="name" column="name" jdbcType="VARCHAR"/>
            <result property="head_img" column="head_img" jdbcType="VARCHAR"/>
            <result property="sex" column="sex" jdbcType="TINYINT"/>
            <result property="birth_day" column="birth_day" jdbcType="VARCHAR"/>
            <result property="telephone" column="telephone" jdbcType="VARCHAR"/>
            <result property="is_vip" column="is_vip" jdbcType="TINYINT"/>
            <result property="code" column="code" jdbcType="VARCHAR"/>
            <result property="is_attention" column="is_attention" jdbcType="TINYINT"/>
            <result property="attention_at" column="attention_at" jdbcType="INTEGER"/>
            <result property="is_shareholder" column="is_shareholder" jdbcType="TINYINT"/>
            <result property="level" column="level" jdbcType="TINYINT"/>
            <result property="distribute_type" column="distribute_type" jdbcType="VARCHAR"/>
            <result property="sort" column="sort" jdbcType="INTEGER"/>
            <result property="created_at" column="created_at" jdbcType="BIGINT"/>
            <result property="updated_at" column="updated_at" jdbcType="BIGINT"/>
            <result property="mini_open_id" column="mini_open_id" jdbcType="VARCHAR"/>
            <result property="dynamic_code" column="dynamic_code" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,amount,credit_amount,
        consume_amount,consume_number,level_consume,
        status,merchant_id,shop_id,
        user_id,parent_id,parent_level,
        name,head_img,sex,
        birth_day,telephone,is_vip,
        code,is_attention,attention_at,
        is_shareholder,level,distribute_type,
        sort,created_at,updated_at,
        mini_open_id,dynamic_code
    </sql>
    <select id="selectUserSummary">
        SELECT
            COUNT(*) total,
            SUM(
                    IFNULL( b.charge_amount, 0 )) chage_total
        FROM
            tb_shop_user AS a
                LEFT JOIN tb_user_info AS b ON a.user_id = b.id
        WHERE
            a.shop_id = #{shopId}
        <if test="isVip !=null">
            and a.is_vip=#{isVip}
        </if>
    </select>
</mapper>
