<?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.hzs.member.bonus.mapper.CuMemberBonusMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="CuMemberBonus" type="com.hzs.common.domain.member.ext.CuMemberBonusExt">
        <id column="PK_ID" property="pkId"/>
        <result column="DEL_FLAG" property="delFlag"/>
        <result column="PK_COUNTRY" property="pkCountry"/>
        <result column="PK_CREATOR" property="pkCreator"/>
        <result column="CREATION_TIME" property="creationTime"/>
        <result column="PK_MODIFIED" property="pkModified"/>
        <result column="MODIFIED_TIME" property="modifiedTime"/>
        <result column="PK_MEMBER" property="pkMember"/>
        <result column="PERIOD" property="period"/>
        <result column="PK_RATE" property="pkRate"/>
        <result column="out_exchange_rate" property="outExchangeRate"/>
        <result column="DIRECT_INCOME" property="directIncome"/>
        <result column="EXPAND_INCOME" property="expandIncome"/>
        <result column="EXPAND_NO_CAPPING" property="expandNoCapping"/>
        <result column="EXPAND_CAPPING" property="expandCapping"/>
        <result column="COACH_INCOME" property="coachIncome"/>
        <result column="SHARE_INCOME" property="shareIncome"/>
        <result column="SERVICE_INCOME" property="serviceIncome"/>
        <result column="BACK_POINTS" property="backPoints"/>
        <result column="SERVICE_SPEND" property="serviceSpend"/>
        <result column="PUR_REAL_SUBTOTAL" property="purRealSubtotal"/>
        <result column="REPUR_PUSH_INCOME" property="repurPushIncome"/>
        <result column="REPUR_RANGE_INCOME" property="repurRangeIncome"/>
        <result column="REPUR_EXPAND_INCOME" property="repurExpandIncome"/>
        <result column="REPUR_COACH_INCOME" property="repurCoachIncome"/>
        <result column="REPUR_REAL_SUBTOTAL" property="repurRealSubtotal"/>
        <result column="CLOUD_DIRECT_INCOME" property="cloudDirectIncome"/>
        <result column="CLOUD_PUR_INCOME" property="cloudPurIncome"/>
        <result column="CLOUD_REPUR_INCOME" property="cloudRepurIncome"/>
        <result column="CLOUD_REAL_SUBTOTAL" property="cloudRealSubtotal"/>
        <result column="REPUR_COUPON" property="repurCoupon"/>
        <result column="REPUR_COUPON_SHARE" property="repurCouponShare"/>
        <result column="REPUR_COUPON_SUBTOTAL" property="repurCouponSubtotal"/>
        <result column="GLOBAL_POINTS" property="globalPoints"/>
        <result column="CAR_AWARD_POINTS" property="carAwardPoints"/>
        <result column="HI_FUN_INCOME" property="hiFunIncome"/>
        <result column="MAKER_DIRECT_INCOME" property="makerDirectIncome"/>
        <result column="MAKER_SHARE_INCOME" property="makerShareIncome"/>
        <result column="MAKER_REAL_SUBTOTAL" property="makerRealSubtotal"/>
        <result column="REAL_INCOME_TOTAL" property="realIncomeTotal"/>
        <result column="INCOME_STATUS" property="incomeStatus"/>
        <result column="GRANT_STATUS" property="grantStatus"/>
        <result column="SETTLE_DATE" property="settleDate"/>
        <result column="MEMBER_CODE" property="memberCode"/>
        <result column="MEMBER_NAME" property="memberName"/>
        <result column="PK_SETTLE_GRADE" property="pkSettleGrade"/>
        <result column="PK_AWARDS" property="pkAwards"/>
        <result column="VERTEX_NAME" property="vertexName"/>
        <result column="TEAM_NAME" property="teamName"/>
        <result column="STORE_INCOME" property="storeIncome"/>
        <result column="HAI_FUN_INCOME" property="haiFunIncome"/>
        <result column="PUR_REAL_SUBTOTAL" property="purRealSubtotal"/>
        <result column="pk_vertex" property="pkVertex"/>
        <result column="pk_team_code" property="pkTeamCode"/>
        <result column="REPUR_REAL_SUBTOTAL" property="repurRealSubtotal"/>
        <result column="CLOUD_REAL_SUBTOTAL" property="cloudRealSubtotal"/>
        <result column="MAKER_REAL_SUBTOTAL" property="makerRealSubtotal"/>
    </resultMap>

    <!--查询当天小区新增数据-->
    <select id="queryMemberBonusByTime" resultType="java.lang.Long">
        select cb.PK_MEMBER
        from cu_member_bonus cb
        where cb.del_flag = 0
          and cb.PERIOD = #{period}
    </select>

    <select id="queryWeekMemberBonus" resultMap="CuMemberBonus">
        select cb.pk_member, sum(expand_income) expand_income, sum(repur_expand_income) repur_expand_income
        from cu_member_bonus cb
                 inner join BD_SYSTEM_CONFIG sy
                            on cb.pk_country = sy.pk_country
        where sy.key = 'EXPAND_CAP_METHOD1'
          and sy.value = '2'
          and cb.period >= #{startPeriod}
          and cb.period &lt; #{endPeriod}
        group by cb.pk_member
    </select>

</mapper>
