| <?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="cc.mrbird.febs.mall.mapper.MallMoneyFlowMapper"> | 
|   | 
|     <select id="selectMoneyFlowInPage" resultType="cc.mrbird.febs.mall.vo.AdminMallMoneyFlowVo"> | 
|         select | 
|                a.*, | 
|                b.name fromMemberName | 
|         from mall_money_flow a | 
|         left join mall_member b on a.rt_member_id = b.id | 
|         where a.member_id = #{record.id} | 
|         order by a.CREATED_TIME desc | 
|     </select> | 
|   | 
|     <select id="selectApiMoneyFlowInPage" resultType="cc.mrbird.febs.mall.vo.MoneyFlowVo"> | 
|         select | 
|             a.*, | 
|             case when a.rt_member_id is null then (select n.phone from mall_member n where n.id=a.member_id) | 
|                  when a.rt_member_id is not null then (select m.phone from mall_member m where m.id=a.rt_member_id) | 
|             end phone, | 
|             c.description memberLevel | 
|         from mall_money_flow a | 
|             left join mall_member b on a.rt_member_id=b.id | 
|             left join data_dictionary_custom c on b.level = c.code and c.type='AGENT_LEVEL' | 
|         <where> | 
|             <if test="record.inOrOut == 3"> | 
|                 and a.amount > 0 | 
|             </if> | 
|             <if test="record.inOrOut == 2"> | 
|                 and 0 > a.amount | 
|             </if> | 
|             <if test="record.memberId != null"> | 
|                 and a.member_id=#{record.memberId} | 
|             </if> | 
|             <if test="record.flowType != null and record.flowType != ''"> | 
|                 and a.flow_type=#{record.flowType} | 
|             </if> | 
|             <if test="record.type != null and record.type != ''"> | 
|                 and a.type=#{record.type} | 
|             </if> | 
|         </where> | 
|         order by a.created_time desc | 
|     </select> | 
|   | 
|     <select id="selectApiFcmMoneyFlowInPage" resultType="cc.mrbird.febs.mall.vo.MoneyFlowVo"> | 
|         select | 
|         a.* | 
|         from mall_money_flow a | 
|         <where> | 
|             <if test="record.inOrOut == 3"> | 
|                 and a.amount > 0 | 
|             </if> | 
|             <if test="record.inOrOut == 2"> | 
|                 and 0 > a.amount | 
|             </if> | 
|             <if test="record.memberId != null"> | 
|                 and a.member_id=#{record.memberId} | 
|             </if> | 
|             <if test="record.flowType != null and record.flowType != ''"> | 
|                 and a.flow_type=#{record.flowType} | 
|             </if> | 
|             <if test="record.type != null and record.type != ''"> | 
|                 and a.type=#{record.type} | 
|             </if> | 
|         </where> | 
|         order by a.created_time desc | 
|     </select> | 
|   | 
|     <select id="getMoneyFlowListInPage" resultType="cc.mrbird.febs.mall.vo.AdminMoneyFlowListVo"> | 
|         select | 
|         a.*, | 
|         b.account_login accountLogin | 
|         from mall_money_flow a | 
|         left join mall_member b on a.member_id=b.id | 
|         <where> | 
|             <if test="record != null" > | 
|                 <if test="record.accountLogin!=null and record.accountLogin!=''"> | 
|                     and b.account_login like concat('%',  #{record.accountLogin},'%') | 
|                 </if> | 
|                 <if test="record.name!=null and record.name!=''"> | 
|                     and b.name like concat('%',  #{record.name},'%') | 
|                 </if> | 
|                 <if test="record.phone!=null and record.phone!=''"> | 
|                     and b.phone like concat('%',  #{record.phone},'%') | 
|                 </if> | 
|                 <if test="record.type!=null and record.type!=''"> | 
|                     and a.type = #{record.type} | 
|                 </if> | 
|                 <if test="record.flowType!=null and record.flowType!=''"> | 
|                     and a.flow_type like concat('%',  #{record.flowType},'%') | 
|                 </if> | 
|             </if> | 
|         </where> | 
|         order by a.created_time desc | 
|     </select> | 
|   | 
|     <select id="getMoneyChargeListInPage" resultType="cc.mrbird.febs.mall.vo.AdminMoneyChargeListVo"> | 
|         select | 
|         a.id id, | 
|         a.created_time createdTime, | 
|         a.amount amount, | 
|         a.amount_fee amountFee, | 
|         a.withdraw_no withdrawNo, | 
|         a.remark remark, | 
|         a.status status, | 
|         b.name, | 
|         b.account_login accountLogin, | 
|         b.bind_phone bindPhone, | 
|         b.phone | 
|         from mall_member_withdraw a | 
|         inner join mall_member b on a.member_id=b.id | 
|         <where> | 
|             <if test="record != null" > | 
|                 <if test="record.accountLogin!=null and record.accountLogin!=''"> | 
|                     and b.account_login like concat('%',  #{record.accountLogin},'%') | 
|                 </if> | 
|                 <if test="record.name!=null and record.name!=''"> | 
|                     and b.name like concat('%',  #{record.name},'%') | 
|                 </if> | 
|                 <if test="record.phone!=null and record.phone!=''"> | 
|                     and b.phone like concat('%',  #{record.phone},'%') | 
|                 </if> | 
|                 <if test="record.status!=null and record.status!=''"> | 
|                     and a.status = #{record.status} | 
|                 </if> | 
|             </if> | 
|         </where> | 
|         order by a.created_time desc | 
|     </select> | 
|   | 
|     <select id="selectMoneyFlowProfitByDate" resultType="cc.mrbird.febs.mall.entity.MallMoneyFlow"> | 
|         select a.member_id, sum(a.amount) amount from mall_money_flow a | 
|         where a.type in (1, 2) and date_format(a.created_time, '%Y-%m-%d') = date_format(#{date}, '%Y-%m-%d') | 
|         and is_return is null | 
|         group by a.member_id; | 
|     </select> | 
|   | 
|     <update id="updateIsReturnByMemberId"> | 
|         update mall_money_flow | 
|         set is_return=#{isReturn} | 
|         where member_id=#{memberId} and type in (1, 2) | 
|     </update> | 
|   | 
|     <select id="selectProfitByDateAndMemberId" resultType="java.math.BigDecimal"> | 
|         select ifnull(sum(a.amount),0) from mall_money_flow a | 
|         where member_id=#{memberId} and flow_type=4 and date_format(a.CREATED_TIME, '%Y-%m-%d') = date_format(now(), '%Y-%m-%d') and amount > 0 | 
|     </select> | 
|   | 
|     <select id="selectCommissionIncome" resultType="java.math.BigDecimal"> | 
|         select ifnull(sum(amount),0) from mall_money_flow | 
|         where type in (2,19,20,21,22,23,24,27,28,29,30) and member_id=#{memberId} | 
|         <if test="type == 1"> | 
|             and date_format(created_time, '%Y-%m-%d') = date_format(#{date}, '%Y-%m-%d') | 
|         </if> | 
|         <if test="type == 2"> | 
|             and date_format(created_time, '%Y-%m') = date_format(#{date}, '%Y-%m') | 
|         </if> | 
|     </select> | 
|   | 
|     <select id="selectThankfulCommission" resultType="java.math.BigDecimal"> | 
|         select ifnull(sum(amount),0) from mall_money_flow | 
|         where flow_type=4 and amount > 0 | 
|           and member_id=#{memberId} | 
|           and date_format(created_time, '%Y-%m-%d') = date_format(#{date}, '%Y-%m-%d') | 
|           and type in (2,3,4) | 
|     </select> | 
|   | 
|     <insert id="insertMoneyFlow" parameterType="cc.mrbird.febs.mall.entity.MallMoneyFlow"> | 
|         insert into mall_money_flow( | 
|             REVISION, | 
|             CREATED_BY, | 
|             CREATED_TIME, | 
|             UPDATED_BY, | 
|             UPDATED_TIME, | 
|             member_id, | 
|             amount, | 
|             type, | 
|             order_no, | 
|             rt_member_id, | 
|             status, | 
|             remark, | 
|             flow_type) VALUES | 
|                 ( | 
|                     #{revision}, | 
|                     #{createdBy}, | 
|                     #{createdTime}, | 
|                     #{updatedBy}, | 
|                     #{updatedTime}, | 
|                     #{memberId}, | 
|                     #{amount}, | 
|                     #{type}, | 
|                     #{orderNo}, | 
|                     #{rtMemberId}, | 
|                     #{status}, | 
|                     #{remark}, | 
|                     #{flowType} | 
|                 ) | 
|     </insert> | 
|   | 
|     <select id="selectTeamEqualsMemberByDate" resultType="cc.mrbird.febs.mall.vo.AdminTeamEqualsPerkVo"> | 
|         select | 
|                a.member_id memberId, | 
|                sum(a.amount) sumAmount, | 
|                c.id rtMemberId | 
|         from mall_money_flow a | 
|         inner join mall_member b on b.id = a.member_id | 
|         inner join mall_member c on c.invite_id = b.referrer_id and c.level = b.level | 
|         where | 
|             a.type IN (19, 20, 21, 22, 23, 24, 27) | 
|           and date_format(a.created_time, '%Y-%m-%d') = date_format(#{date}, '%Y-%m-%d') | 
|         group by a.member_id; | 
|     </select> | 
|   | 
|     <select id="selectOrderMoneyFlowInPage" resultType="cc.mrbird.febs.mall.vo.AdminMallMoneyFlowVo"> | 
|         select | 
|             a.*, | 
|             b.name fromMemberName | 
|         from mall_money_flow a | 
|                  left join mall_member b on a.member_id = b.id | 
|         where a.order_no = #{record.orderNo} | 
|         order by a.CREATED_TIME desc | 
|     </select> | 
|   | 
|     <select id="selectMoneyFlowByMemberIdAndIsRetrun" resultType="cc.mrbird.febs.mall.entity.MallMoneyFlow"> | 
|         SELECT | 
|             * | 
|         FROM | 
|             mall_money_flow a | 
|         WHERE | 
|             a.type = 26 | 
|           AND a.flow_type = 6 | 
|           AND a.is_return = #{isReturn} | 
|           AND a.member_id = #{memberId} | 
|         ORDER BY | 
|             a.created_time ASC | 
|     </select> | 
|   | 
|     <update id="updateRemarkById"> | 
|         update mall_money_flow | 
|         <set> | 
|             remark = #{remark} | 
|         </set> | 
|         WHERE id =  #{id} | 
|     </update> | 
|   | 
|     <update id="updateRemarkAndIsReturnById"> | 
|         update mall_money_flow | 
|         <set> | 
|             remark = #{remark}, | 
|             is_return = 1 | 
|         </set> | 
|         WHERE id =  #{id} | 
|     </update> | 
|   | 
|     <select id="selectByOrderNoAndMemberId" resultType="cc.mrbird.febs.mall.entity.MallMoneyFlow"> | 
|         SELECT | 
|             * | 
|         FROM | 
|             mall_money_flow a | 
|         WHERE | 
|             a.type = 25 | 
|           AND a.flow_type = 5 | 
|           AND a.is_return = #{isReturn} | 
|           AND a.member_id = #{memberId} | 
|           AND a.order_no = #{orderNo} | 
|         ORDER BY | 
|             a.created_time ASC | 
|     </select> | 
|   | 
|     <select id="selectByOrderAndType" resultType="cc.mrbird.febs.mall.entity.MallMoneyFlow"> | 
|         SELECT | 
|             * | 
|         FROM | 
|             mall_money_flow a | 
|         WHERE | 
|             a.type = #{type} | 
|           AND a.flow_type = #{flowType} | 
|           AND a.member_id = #{memberId} | 
|           AND a.order_no = #{orderNo} | 
|     </select> | 
|   | 
|     <select id="selectApiFcmMoneyFlowInsideInPage" resultType="cc.mrbird.febs.mall.vo.MoneyFlowVo"> | 
|         select | 
|         a.* | 
|         from mall_money_flow a | 
|         <where> | 
|             a.type in (2,3,4,5) | 
|             <if test="record.inOrOut == 3"> | 
|                 and a.amount > 0 | 
|             </if> | 
|             <if test="record.inOrOut == 2"> | 
|                 and 0 > a.amount | 
|             </if> | 
|             <if test="record.memberId != null"> | 
|                 and a.member_id=#{record.memberId} | 
|             </if> | 
|             <if test="record.flowType != null and record.flowType != ''"> | 
|                 and a.flow_type=#{record.flowType} | 
|             </if> | 
|         </where> | 
|         order by a.created_time desc | 
|     </select> | 
| </mapper> |