IMRefundOrderMapper.xml 17.7 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.dao.IMRefundOrderDao">
    <select id="sumAlreadyRefundQuantityByOrderIdAndOrderItemId" resultType="java.lang.Integer">
        select ifnull(sum(quantity),0) from im_refund_order_item where order_id = #{orderId} and order1_id = #{order1Id} and
        refund_id in (
            select refund_id from im_order_refund where order_id = #{orderId} and refund_status = 7
        )
    </select>
    <select id="countRefundingOrderByOrderId" resultType="java.lang.Integer">
        select count(*) from im_order_refund where
        order_id = #{orderId} and refund_status != 7 and refund_status != 100 and refund_status != 101
    </select>
    <resultMap id="BaseResultMap" type="com.sibu.orderHelper.integral.model.IMOrderRefundBean">
        <id column="refund_id" jdbcType="VARCHAR" property="refundId"/>
        <result column="refund_code" jdbcType="VARCHAR" property="refundCode"/>
        <result column="order_id" jdbcType="VARCHAR" property="orderId"/>
        <result column="order_code" jdbcType="VARCHAR" property="orderCode"/>
        <result column="order_from" jdbcType="TINYINT" property="orderFrom"/>
        <result column="member_id" jdbcType="VARCHAR" property="memberId"/>
        <result column="refund_type" jdbcType="INTEGER" property="refundType"/>
        <result column="refund_goods_status" jdbcType="INTEGER" property="refundGoodsStatus"/>
        <result column="refund_reason_id" jdbcType="INTEGER" property="refundReasonId"/>
        <result column="refund_reason" jdbcType="VARCHAR" property="refundReason"/>
        <result column="refund_money" jdbcType="DECIMAL" property="refundMoney"/>
        <result column="order_money" jdbcType="DECIMAL" property="orderMoney"/>
        <result column="refund_remark" jdbcType="VARCHAR" property="refundRemark"/>
        <result column="refund_status" jdbcType="INTEGER" property="refundStatus"/>
        <result column="refund_status_last_update_dt" jdbcType="TIMESTAMP" property="refundStatusLastUpdateDt"/>
        <result column="apply_date" jdbcType="TIMESTAMP" property="applyDate"/>
        <result column="refund_money_success_flag" jdbcType="BIT" property="refundMoneySuccessFlag"/>
        <result column="refund_date" jdbcType="TIMESTAMP" property="refundDate"/>
        <result column="buyer_username" jdbcType="VARCHAR" property="buyerUsername"/>
        <result column="buyer_phone" jdbcType="VARCHAR" property="buyerPhone"/>
        <result column="refund_seller_phone" jdbcType="VARCHAR" property="refundSellerPhone"/>
        <result column="refund_seller_address" jdbcType="VARCHAR" property="refundSellerAddress"/>
        <result column="refund_seller_name" jdbcType="VARCHAR" property="refundSellerName"/>
        <result column="finish_date" jdbcType="TIMESTAMP" property="finishDate"/>
        <result column="refund_integral" jdbcType="BIGINT" property="refundIntegral"/>
        <result column="refund_goods_deliver_id" jdbcType="TINYINT" property="refundGoodsDeliverId"/>
        <result column="refund_goods_deliver_name" jdbcType="VARCHAR" property="refundGoodsDeliverName"/>
        <result column="refund_goods_waybill" jdbcType="VARCHAR" property="refundGoodsWaybill"/>
        <result column="refund_goods_remark" jdbcType="VARCHAR" property="refundGoodsRemark"/>
        <result column="refund_tips" jdbcType="VARCHAR" property="refundTips"/>
        <result column="receive_goods_flag" jdbcType="BIT" property="receiveGoodsFlag"/>
        <result column="receive_goods_dt" jdbcType="TIMESTAMP" property="receiveGoodsDt"/>
        <result column="refund_freight" property="refundFreight"/>
        <result column="refund_to_account_type" property="refundToAccountType"/>
        <result column="refund_alipay_account" property="refundAlipayAccount"/>
        <result column="refund_alipay_account_real_name" property="refundAlipayAccountRealName"/>
        <result column="refund_bank_account" property="refundBankAccount"/>
        <result column="refund_bank_account_real_name" property="refundBankAccountRealName"/>
        <result column="refund_bank_branch_full_name" property="refundBankBranchFullName"/>
        <result column="change_goods_waybill" property="changeGoodsWaybill"/>
        <result column="change_goods_deliver_name" property="changeGoodsDeliverName"/>
        <result column="change_goods_finish_flag" property="changeGoodsFinishFlag"/>

    </resultMap>
    <sql id="Base_Column_List">
refund_id,
    refund_code,
    order_id,
    order_code,
    order_from,
    member_id,
    refund_type,
    refund_goods_status,
    refund_reason_id,
    refund_reason,
    refund_money,
    order_money,
    refund_remark,
    refund_status,
    refund_status_last_update_dt,
    apply_date,
    refund_money_success_flag,
    refund_date,
    buyer_username,
    buyer_phone,
    refund_seller_phone,
    refund_seller_address,
    refund_seller_name,
    finish_date,
    refund_integral,
    refund_goods_deliver_id,
    refund_goods_deliver_name,
    refund_goods_waybill,
    refund_goods_remark,
    refund_tips,
    receive_goods_flag,
    receive_goods_dt,
    deduction_product_vb,
    deduction_product_vb_refund_status,
    deduction_product_vb_refund_dt,
    profit_refund_status,
    profit_refund_dt,
    refund_freight,
    refund_to_account_type,
    refund_alipay_account,
    refund_alipay_account_real_name,
    refund_bank_account,
    refund_bank_account_real_name,
    refund_bank_branch_full_name,
    change_goods_waybill,
    change_goods_deliver_name,
    change_goods_finish_flag
  </sql>
    <select id="list" resultMap="BaseResultMap"
            parameterType="com.sibu.orderHelper.integral.request.RefundListPagerRequest">
        select
        <include refid="Base_Column_List"/>
        from im_order_refund
        where member_id = #{memberId}
        order by apply_date desc
        limit ${(pageNow - 1) * pageSize}, ${pageSize}

    </select>
    <select id="findOneRefundingByOrderIdAndOrder1Id" resultMap="BaseResultMap"
            parameterType="com.sibu.orderHelper.integral.request.RefundListPagerRequest">
        select
        of.*
        from im_order_refund of inner join im_refund_order_item oi on of.refund_id = oi.refund_id
        and of.order_id = #{orderId} and oi.order1_id = #{order1Id} and of.refund_status != 7 and of.refund_status != 100 and of.refund_status != 101
        limit 0,1
    </select>

    <select id="countList" resultType="java.lang.Integer"
            parameterType="com.sibu.orderHelper.integral.request.RefundListPagerRequest">
        select count(*) from im_order_refund where member_id = #{memberId}
    </select>

    <sql id="refund_order_column">
    	refund_id,refund_code,order_id,order_code,member_id,refund_type,refund_reason,
    	refund_money,order_money,refund_remark,apply_date,buyer_username,buyer_phone
    </sql>
    <select id="findOneByRefundIdAndMemberId" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from im_order_refund where refund_id = #{refundId} and member_id = #{memberId}
    </select>

    <insert id="addRefundOrder" parameterType="IMOrderRefundBean">
        insert into im_order_refund(<include refid="refund_order_column"/>)
        value(
        #{refundId},
        #{refundCode},
        #{orderId},
        #{orderCode},
        #{memberId},
        #{refundType},
        #{refundReason},
        #{refundMoney},
        #{orderMoney},
        #{refundRemark},
        NOW(),
        #{buyerUsername},
        ${buyerPhone}
        )
    </insert>
    <insert id="insert" parameterType="com.sibu.orderHelper.integral.model.IMOrderRefundBean">
        insert into im_order_refund (refund_id, refund_code, order_id,
      order_code, order_from, member_id,
      refund_type, refund_goods_status, refund_reason_id,
      refund_reason, refund_money, order_money,
      refund_remark, refund_status, refund_status_last_update_dt,
      apply_date, refund_money_success_flag, refund_date,
      buyer_username, buyer_phone, refund_seller_phone,
      refund_seller_address, refund_seller_name,
      finish_date, refund_integral, refund_goods_deliver_id,
      refund_goods_deliver_name, refund_goods_waybill,
      refund_goods_remark, refund_tips, receive_goods_flag,
      receive_goods_dt,deduction_product_vb,supplier_id,supplier_name,platform_type)
    values (#{refundId,jdbcType=VARCHAR}, #{refundCode,jdbcType=VARCHAR}, #{orderId,jdbcType=VARCHAR},
      #{orderCode,jdbcType=VARCHAR}, #{orderFrom,jdbcType=TINYINT}, #{memberId,jdbcType=VARCHAR},
      #{refundType,jdbcType=INTEGER}, #{refundGoodsStatus,jdbcType=INTEGER}, #{refundReasonId,jdbcType=INTEGER},
      #{refundReason,jdbcType=VARCHAR}, #{refundMoney,jdbcType=DECIMAL}, #{orderMoney,jdbcType=DECIMAL},
      #{refundRemark,jdbcType=VARCHAR}, #{refundStatus,jdbcType=INTEGER}, #{refundStatusLastUpdateDt,jdbcType=TIMESTAMP},
      #{applyDate,jdbcType=TIMESTAMP}, #{refundMoneySuccessFlag,jdbcType=BIT}, #{refundDate,jdbcType=TIMESTAMP},
      #{buyerUsername,jdbcType=VARCHAR}, #{buyerPhone,jdbcType=VARCHAR}, #{refundSellerPhone,jdbcType=VARCHAR},
      #{refundSellerAddress,jdbcType=VARCHAR}, #{refundSellerName,jdbcType=VARCHAR},
      #{finishDate,jdbcType=TIMESTAMP}, #{refundIntegral,jdbcType=BIGINT}, #{refundGoodsDeliverId,jdbcType=TINYINT},
      #{refundGoodsDeliverName,jdbcType=VARCHAR}, #{refundGoodsWaybill,jdbcType=VARCHAR},
      #{refundGoodsRemark,jdbcType=VARCHAR}, #{refundTips,jdbcType=VARCHAR}, #{receiveGoodsFlag,jdbcType=BIT},
      #{receiveGoodsDt,jdbcType=TIMESTAMP},#{deductionProductVb},#{supplierId},#{supplierName},#{platformType})

    </insert>
    <update id="updateDeliveryInfoByRefundIdAndMemberId"
            parameterType="com.sibu.orderHelper.integral.request.UpdateDeliveryInfoRequest">
        update im_order_refund set   
        refund_goods_deliver_id=#{deliverId},
        refund_goods_deliver_name=#{deliverName},
        refund_goods_waybill=#{waybill},
        refund_goods_remark=#{remark},
        refund_freight=#{refundFreight},
        refund_to_account_type=#{refundToAccountType},
        refund_alipay_account=#{refundAlipayAccount},
        refund_alipay_account_real_name=#{refundAlipayAccountRealName},
        refund_bank_account=#{refundBankAccount},
        refund_bank_account_real_name=#{refundBankAccountRealName},
        refund_bank_branch_full_name=#{refundBankBranchFullName}
        where refund_id = #{refundId} and member_id = #{memberId}
    </update>
    <update id="updateRefundStatusByRefundIdAndMemberId">
        update im_order_refund set
        refund_status=#{refundStatus}
        where refund_id = #{refundId} and member_id = #{memberId}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.sibu.orderHelper.integral.model.IMOrderRefundBean">
        update im_order_refund
        <set>
            <if test="refundCode != null">
                refund_code = #{refundCode,jdbcType=VARCHAR},
            </if>
            <if test="orderId != null">
                order_id = #{orderId,jdbcType=VARCHAR},
            </if>
            <if test="orderCode != null">
                order_code = #{orderCode,jdbcType=VARCHAR},
            </if>
            <if test="orderFrom != null">
                order_from = #{orderFrom,jdbcType=TINYINT},
            </if>
            <if test="memberId != null">
                member_id = #{memberId,jdbcType=VARCHAR},
            </if>
            <if test="refundType != null">
                refund_type = #{refundType,jdbcType=INTEGER},
            </if>
            <if test="refundGoodsStatus != null">
                refund_goods_status = #{refundGoodsStatus,jdbcType=INTEGER},
            </if>
            <if test="refundReasonId != null">
                refund_reason_id = #{refundReasonId,jdbcType=INTEGER},
            </if>
            <if test="refundReason != null">
                refund_reason = #{refundReason,jdbcType=VARCHAR},
            </if>
            <if test="refundMoney != null">
                refund_money = #{refundMoney,jdbcType=DECIMAL},
            </if>
            <if test="orderMoney != null">
                order_money = #{orderMoney,jdbcType=DECIMAL},
            </if>
            <if test="refundRemark != null">
                refund_remark = #{refundRemark,jdbcType=VARCHAR},
            </if>
            <if test="refundStatus != null">
                refund_status = #{refundStatus,jdbcType=INTEGER},
            </if>
            <if test="refundStatusLastUpdateDt != null">
                refund_status_last_update_dt = #{refundStatusLastUpdateDt,jdbcType=TIMESTAMP},
            </if>
            <if test="applyDate != null">
                apply_date = #{applyDate,jdbcType=TIMESTAMP},
            </if>
            <if test="refundMoneySuccessFlag != null">
                refund_money_success_flag = #{refundMoneySuccessFlag,jdbcType=BIT},
            </if>
            <if test="refundDate != null">
                refund_date = #{refundDate,jdbcType=TIMESTAMP},
            </if>
            <if test="buyerUsername != null">
                buyer_username = #{buyerUsername,jdbcType=VARCHAR},
            </if>
            <if test="buyerPhone != null">
                buyer_phone = #{buyerPhone,jdbcType=VARCHAR},
            </if>
            <if test="refundSellerPhone != null">
                refund_seller_phone = #{refundSellerPhone,jdbcType=VARCHAR},
            </if>
            <if test="refundSellerAddress != null">
                refund_seller_address = #{refundSellerAddress,jdbcType=VARCHAR},
            </if>
            <if test="refundSellerName != null">
                refund_seller_name = #{refundSellerName,jdbcType=VARCHAR},
            </if>
            <if test="finishDate != null">
                finish_date = #{finishDate,jdbcType=TIMESTAMP},
            </if>
            <if test="refundIntegral != null">
                refund_integral = #{refundIntegral,jdbcType=BIGINT},
            </if>
            <if test="refundGoodsDeliverId != null">
                refund_goods_deliver_id = #{refundGoodsDeliverId,jdbcType=TINYINT},
            </if>
            <if test="refundGoodsDeliverName != null">
                refund_goods_deliver_name = #{refundGoodsDeliverName,jdbcType=VARCHAR},
            </if>
            <if test="refundGoodsWaybill != null">
                refund_goods_waybill = #{refundGoodsWaybill,jdbcType=VARCHAR},
            </if>
            <if test="refundGoodsRemark != null">
                refund_goods_remark = #{refundGoodsRemark,jdbcType=VARCHAR},
            </if>
            <if test="refundTips != null">
                refund_tips = #{refundTips,jdbcType=VARCHAR},
            </if>
            <if test="receiveGoodsFlag != null">
                receive_goods_flag = #{receiveGoodsFlag,jdbcType=BIT},
            </if>
            <if test="receiveGoodsDt != null">
                receive_goods_dt = #{receiveGoodsDt,jdbcType=TIMESTAMP},
            </if>
        </set>
        where refund_id = #{refundId,jdbcType=VARCHAR}
    </update>
    <select id="getRefundRecodeResult" parameterType="java.util.Map" resultType="String">
    	select operator_remark from im_refund_procedure_record where refund_id = #{refundId} 
    </select>
    <select id="getRefundDetail" resultMap="refundResponseResultMap" parameterType="java.util.Map">
    	select refund_id,refund_code,order_code,refund_type,refund_procedure_status,refund_reason,
    		   refund_money,order_money,refund_remark,refund_status,apply_date,refund_date,refund_seller_phone,refund_seller_address,refund_seller_name 
    	from im_order_refund 
    	where member_id = #{memberId} and order_id = #{orderId}
    </select>

    <resultMap type="RefundOrderResponse" id="refundResponseResultMap">
        <id column="refund_id" property="refundId"/>
        <result column="refund_code" property="refundCode"/>
        <result column="order_code" property="orderCode"/>
        <result column="refund_type" property="refundType"/>
        <result column="refund_procedure_status" property="refundProcedureStatus"/>
        <result column="refund_reason" property="refundReason"/>
        <result column="refund_money" property="refundMoney"/>
        <result column="order_money" property="orderMoney"/>
        <result column="refund_remark" property="refundRemark"/>
        <result column="refund_status" property="refundStatus"/>
        <result column="apply_date" property="applyDate"/>
        <result column="refund_date" property="refundDate"/>
        <result column="refund_seller_address" property="refundSellerAddress"/>
        <result column="refund_seller_phone" property="refundSellerPhone"/>
        <result column="refund_seller_name" property="refundSellerName"/>
    </resultMap>

    <select id="statisticsRefundingNum" resultType="java.lang.Integer">
        select count(*) from im_order_refund where member_id = #{memberId} and refund_status != 7 and refund_status != 100 and refund_status != 101
    </select>
    <select id="countOrderItemNotFinishHistory" resultType="java.lang.Integer">
        select count(*) from im_order_refund of
        inner join im_refund_order_item ofitem
        on of.order_id=#{orderId}
        and of.refund_status != 7 and of.refund_status != 100 and of.refund_status != 101
        and ofitem.order1_id=#{order1Id}
        and of.refund_id = ofitem.refund_id
    </select>

    <select id="searchSuccessRefundOrderList"  resultMap="BaseResultMap">
        SELECT  * FROM  im_order_refund  WHERE  refund_status = 7 GROUP  BY  order_code
    </select>

    <select id="countRefundOrderListByOrderCode" parameterType="java.lang.String" resultType="java.lang.Integer">
        SELECT sum(r1.quantity) FROM im_refund_order_item r1,im_order_refund r WHERE r1.refund_id = r.refund_id
      AND r.refund_status = 7 AND r.order_code = #{orderCode}
    </select>
</mapper>