withdrawRecordMapper.xml 11.3 KB
<?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.sibu.orderHelper.integral.web.dao.WithdrawRecordDao">

    <resultMap type="com.sibu.orderHelper.integral.vo.WithdrawRecordVo" id="withdrawRecordResponse">
        <id column="id" property="id" />
        <result column="member_id" property="memberId" />
        <result column="partner_trade_no" property="partnerTradeNo" />
        <result column="open_id" property="openId" />
        <result column="amount" property="amount" />
        <result column="user_name" property="userName" />
        <result column="pay_desc" property="payDesc" />
        <result column="pay_dt" property="payDt" />
        <result column="create_dt" property="createDt" />
        <result column="status" property="status" />
        <result column="fail_code" property="failCode" />
        <result column="operator" property="operator" />
        <result column="nick_name" property="nickName"></result>
        <result column="phone" property="phone"></result>
        <result column="payment_no" property="paymentNo"></result>
    </resultMap>

    <!--分页查询提现记录-->
    <select id="selectHasWithdrawForPage" parameterType="java.util.Map" resultMap="withdrawRecordResponse">
        SELECT r.*,m.nick_name,m.phone FROM `t_withdraw_record` r INNER JOIN `t_member_info` m
        ON r.`member_id` =m.`member_id`
        where 1=1
        <if test="phone!=null and phone !=''">
            and m.phone=#{phone}
        </if>
        <if test="partnerTradeNo!=null and partnerTradeNo!=''">
            and r.partner_trade_no=#{partnerTradeNo}
        </if>
        <if test="paymentNo!=null and paymentNo!=''">
            and r.payment_no=#{paymentNo}
        </if>
        <if test="startDt !=null">
            and r.create_dt >=#{startDt}
        </if>
        <if test="endDt !=null">
            and r.create_dt &lt;= #{endDt}
        </if>
        <if test="payStartDt !=null">
            and r.pay_dt >=#{payStartDt}
        </if>
        <if test="payEndDt !=null">
            and r.pay_dt &lt;= #{payEndDt}
        </if>
        <if test="status!=null">
            and r.status=#{status}
        </if>
        limit #{pageNow},#{pageSize}
    </select>

    <!--查询总记录条数-->
    <select id="selectCountWithdraw"  parameterType="java.util.Map" resultType="java.lang.Integer">
        SELECT count(1) FROM `t_withdraw_record` r INNER JOIN `t_member_info` m
        ON r.`member_id` =m.`member_id`
        where 1=1
        <if test="phone!=null and phone!=''">
            and m.phone=#{phone}
        </if>
        <if test="partnerTradeNo!=null and partnerTradeNo!=''">
            and r.partner_trade_no=#{partnerTradeNo}
        </if>
        <if test="paymentNo!=null and paymentNo!=''">
            and r.payment_no=#{paymentNo}
        </if>
        <if test="startDt !=null">
            and r.create_dt >=#{startDt}
        </if>
        <if test="endDt !=null">
            and r.create_dt &lt;= #{endDt}
        </if>
        <if test="payStartDt !=null">
            and r.pay_dt >=#{payStartDt}
        </if>
        <if test="payEndDt !=null">
            and r.pay_dt &lt;= #{payEndDt}
        </if>
        <if test="status!=null">
            and r.status=#{status}
        </if>
    </select>

    <!--更新提现记录-->
    <update id="updateWithdrawRecord" parameterType="com.sibu.orderHelper.integral.vo.UpdateWithdrawRecordVo" >
        update t_withdraw_record
        <set>
            <if test="payDesc!=null and payDesc!='' " >
                pay_desc=#{payDesc},
            </if>
            <if test="paymentNo!=null and paymentNo!=''" >
                payment_no=#{paymentNo},
            </if>
            <if test="status!=null" >
                status=#{status},
            </if>
            <if test="payDt!=null" >
                pay_dt=#{payDt},
            </if>
            <if test="failCode!=null and failCode!=''" >
                fail_code=#{failCode},
            </if>
            <if test="operator!=null and operator!=''">
                operator=#{operator},
            </if>
        </set>
        where id=#{id} and status=#{previousStatus}
    </update>

    <!--新增提现记录详情-->
    <insert id="updateWithdrawRecordDetail" parameterType="com.sibu.orderHelper.integral.vo.UpdateWithdrawRecordVo" >
        insert into t_withdraw_record_status(withdraw_recode_id,status,create_dt)
        VALUE(
        #{id},
        #{status},
        NOW()
        )
    </insert>

    <!--通过ID查询记录-->
    <select id="selectWithdrawRecordById" resultMap="withdrawRecordResponse" parameterType="java.lang.Long">
        SELECT r.*,m.nick_name,m.phone FROM `t_withdraw_record` r INNER JOIN `t_member_info` m
        ON r.`member_id` =m.`member_id`
        where r.id=#{id}
    </select>

    <!--查询收益总额-->
    <select id="selectTotalProfitAmount" parameterType="java.util.Map" resultType="java.math.BigDecimal">
        select sum(profit_money-refund_money) from `t_share_profit_record` WHERE share_user_id =#{memberId} and profit_status =1 AND create_dt &lt; #{createDt}
    </select>

    <!--查询已提现记录-->
    <select id="selectHasWithdrawSum" parameterType="java.util.Map" resultType="java.math.BigDecimal">
        select sum(amount) from t_withdraw_record where status in(1,2) and member_id=#{memberId} and create_dt &lt;#{createDt}
    </select>

    <resultMap type="com.sibu.orderHelper.integral.reponse.WebWithdrawRecord" id="withdrawRecordResultMap">
        <id column="id" property="id" />
        <result column="member_id" property="memberId" />
        <result column="partner_trade_no" property="partnerTradeNo" />
        <result column="open_id" property="openId" />
        <result column="amount" property="amount" />
        <result column="user_name" property="userName" />
        <result column="pay_desc" property="payDesc" />
        <result column="pay_dt" property="payDt" />
        <result column="create_dt" property="createDt" />
        <result column="status" property="status" />
        <result column="fail_code" property="failCode" />
        <result column="operator" property="operator" />
        <result column="nick_name" property="nickName"/>
        <result column="true_name" property="trueName"/>
        <result column="phone" property="phone"/>
        <result column="wechat" property="wechat"/>
        <result column="id_card" property="idCard"/>
    </resultMap>

    <!--分页查询提现记录-->
    <select id="listWithdrawRecord" parameterType="java.util.Map" resultMap="withdrawRecordResultMap">
        SELECT r.*,m.nick_name,m.phone,m.wechat,m.id_card,m.true_name FROM `t_withdraw_record` r INNER JOIN `t_member_info` m
        ON r.`member_id` =m.`member_id`
        where 1=1
        <if test="phone!=null and phone !=''">
            and m.phone=#{phone}
        </if>
        <if test="nickName!=null and nickName!=''">
            and m.nick_name=#{nickName}
        </if>
        <if test="idCard!=null and idCard!=''">
            and m.id_card=#{idCard}
        </if>
        <if test="startDt !=null">
            and r.create_dt >=#{startDt}
        </if>
        <if test="endDt !=null">
            and r.create_dt &lt;= #{endDt}
        </if>
        limit #{pageNow},#{pageSize}
    </select>

    <!--查询总记录条数-->
    <select id="totalWithdrawRecord"  parameterType="java.util.Map" resultType="java.lang.Integer">
        SELECT count(1) FROM `t_withdraw_record` r INNER JOIN `t_member_info` m
        ON r.`member_id` =m.`member_id`
        where 1=1
        <if test="phone!=null and phone !=''">
            and m.phone=#{phone}
        </if>
        <if test="nickName!=null and nickName!=''">
            and m.nick_name=#{nickName}
        </if>
        <if test="idCard!=null and idCard!=''">
            and m.id_card=#{idCard}
        </if>
        <if test="startDt !=null">
            and r.create_dt >=#{startDt}
        </if>
        <if test="endDt !=null">
            and r.create_dt &lt;= #{endDt}
        </if>
    </select>
    <!--查询提现记录的佣金详情记录条数-->
    <select id="totalWithdrawDetail" parameterType="java.util.Map" resultType="java.lang.Integer">
        select count(1) FROM  t_share_profit_record  WHERE   share_user_id=#{shareUserId}

    </select>
    <!--查询提现记录的佣金详情-->
    <select id="selectHasWithdrawDetailForPage" parameterType="java.util.Map" resultMap="selectHasWithdrawDetailMap" >
      select r.*,t.nick_name AS  nickName,p.name AS  productName from  t_share_profit_record  r
      LEFT JOIN t_member_info t ON r.buyer_user_id=t.member_id
      LEFT  JOIN  im_product p ON  r.product_id=p.im_product_id
      WHERE r.share_user_id=#{shareUserId}
      ORDER  BY  r.id ASC
       limit #{pageNow},#{pageSize}
    </select>


    <resultMap type="com.sibu.orderHelper.vo.WithdrawRecordDetailVo" id="selectHasWithdrawDetailMap">
        <id column="id" property="id" />
        <result column="share_user_id" property="shareUserId" />
        <result column="buyer_user_id" property="buyerUserId" />
        <result column="order_id" property="orderId" />
        <result column="nick_name" property="nickName" />
        <result column="name" property="productName" />
        <result column="order_code" property="orderCode" />
        <result column="profit_money" property="profitMoney" />
        <result column="refund_money" property="refundMoney" />
        <result column="profit_status" property="profitStatus" />
        <result column="product_id" property="productId" />
        <result column="product_price" property="productPrice" />
        <result column="product_share_percentage" property="productSharePercentage" />
        <result column="product_amount" property="productAmount" />
        <result column="profit_dt" property="profitDt"/>
        <result column="order_dt" property="orderDt"/>
        <result column="refund_dt" property="refundDt"/>
        <result column="create_dt" property="createDt"/>
        <result column="update_dt" property="updateDt"/>
        <result column="settlement_dt" property="settlementDt"/>
    </resultMap>
    <!--根据不同状态查询提现记录总金额-->
    <select id="totalWithdraw"  parameterType="java.util.Map" resultType="java.math.BigDecimal">
        SELECT SUM(amount) AS sumMoney FROM t_withdraw_record  WHERE  member_id=#{memberId} AND status=#{status}
    </select>
    <!-- 总利润 -->
    <select id="sumProfit" parameterType="java.util.Map" resultType="java.math.BigDecimal">
        SELECT SUM(profit_money) AS sumProfitMoney FROM t_share_profit_record  WHERE share_user_id=#{memberId}
    </select>
    <!-- 佣金不用状态的总金额-->
    <select id="shareProfitRecordList" parameterType="java.util.Map" resultMap="getRecord">
        select SUM(profit_money) AS money,profit_status AS  status FROM  t_share_profit_record
        WHERE   share_user_id=#{memberId}
        GROUP BY profit_status
    </select>

    <resultMap type="java.util.Map" id="getRecord">
        <id column="money" property="money" />
        <result column="status" property="status"  />
    </resultMap>
    <!-- 不同状态的提现记录总金额-->
    <select id="withdrawRecordList" parameterType="java.util.Map">
        SELECT SUM(amount) AS money,status FROM t_withdraw_record  WHERE member_id=#{memberId} GROUP BY status
    </select>
</mapper>