<?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.com.xingxi.store.data.mapper.WxaStorePaymentInfoMapper">

    <select id="selectOrderedPaymeninfoByWxOpenId" resultType="PaymentInfo">
        SELECT t_payment_info.* FROM t_payment_info
        WHERE t_payment_info.delFlag = '0'
          AND t_payment_info.orderStatus = 'ORDERED'
          AND UNIX_TIMESTAMP(t_payment_info.timeExpire) > UNIX_TIMESTAMP(NOW())
          AND t_payment_info.orderId = #{orderId}
          AND t_payment_info.wxOpenId = #{wxopenid}
        ORDER BY t_payment_info.timeStart DESC
        LIMIT 1
    </select>


    <select id="selectLockPaymentInfoByOutTradeNo" parameterType="String" resultType="PaymentInfo">
        SELECT t_payment_info.* FROM t_payment_info
        WHERE t_payment_info.delFlag = '0'
          AND t_payment_info.orderStatus = 'ORDERED'
          AND t_payment_info.outTradeNo = #{outTradeNo}
        FOR UPDATE
    </select>

    <select id="selectPaymentInfoByOrderId" resultType="PaymentInfo">
        select t_payment_info.* from t_payment_info
        where t_payment_info.delFlag = '0'
          and t_payment_info.orderId = #{orderId}
    </select>


    <update id="updatePaymentInfoByOutTradeNo" parameterType="PaymentInfo">
        update t_payment_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderId != null">orderId = #{orderId},</if>
            <if test="orderNo != null and orderNo != ''">orderNo = #{orderNo},</if>
            <if test="orderStatus != null and orderStatus != ''">orderStatus = #{orderStatus},</if>
            <if test="payTime != null">payTime = #{payTime},</if>
            <if test="payKind != null and payKind != ''">payKind = #{payKind},</if>
            <if test="sellerId != null">sellerId = #{sellerId},</if>
            <if test="combineAppid != null and combineAppid != ''">combineAppid = #{combineAppid},</if>
            <if test="combineMchid != null and combineMchid != ''">combineMchid = #{combineMchid},</if>
            <if test="deviceId != null and deviceId != ''">deviceId = #{deviceId},</if>
            <if test="payerClientIp != null and payerClientIp != ''">payerClientIp = #{payerClientIp},</if>
            <if test="mchid != null and mchid != ''">mchid = #{mchid},</if>
            <if test="outTradeNo != null and outTradeNo != ''">outTradeNo = #{outTradeNo},</if>
            <if test="subMchid != null and subMchid != ''">subMchid = #{subMchid},</if>
            <if test="subAttach != null and subAttach != ''">subAttach = #{subAttach},</if>
            <if test="subDescription != null and subDescription != ''">subDescription = #{subDescription},</if>
            <if test="payAmount != null">payAmount = #{payAmount},</if>
            <if test="subCurrency != null and subCurrency != ''">subCurrency = #{subCurrency},</if>
            <if test="profitSharing != null and profitSharing != ''">profitSharing = #{profitSharing},</if>
            <if test="wxOpenId != null and wxOpenId != ''">wxOpenId = #{wxOpenId},</if>
            <if test="notifyUrl != null and notifyUrl != ''">notifyUrl = #{notifyUrl},</if>
            <if test="stateCode != null and stateCode != ''">stateCode = #{stateCode},</if>
            <if test="prepayId != null and prepayId != ''">prepayId = #{prepayId},</if>
            <if test="tradeType != null and tradeType != ''">tradeType = #{tradeType},</if>
            <if test="tradeState != null and tradeState != ''">tradeState = #{tradeState},</if>
            <if test="bankType != null and bankType != ''">bankType = #{bankType},</if>
            <if test="successTime != null">successTime = #{successTime},</if>
            <if test="transactionId != null and transactionId != ''">transactionId = #{transactionId},</if>
            <if test="wxOrderId != null and wxOrderId != ''">wxOrderId = #{wxOrderId},</if>
            <if test="wxOrderStatus != null and wxOrderStatus != ''">wxOrderStatus = #{wxOrderStatus},</if>
            <if test="delFlag != null and delFlag != ''">delFlag = #{delFlag},</if>
            <if test="createUser != null and createUser != ''">createUser = #{createUser},</if>
            <if test="createTime != null">createTime = #{createTime},</if>
            <if test="updateUser != null and updateUser != ''">updateUser = #{updateUser},</if>
            <if test="updateTime != null">updateTime = #{updateTime},</if>
        </trim>
        where outTradeNo = #{outTradeNo}
    </update>

    <update id="updatePaymentInfoByOrderId" parameterType="PaymentInfo">
        update t_payment_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderId != null">orderId = #{orderId},</if>
            <if test="orderNo != null and orderNo != ''">orderNo = #{orderNo},</if>
            <if test="orderStatus != null and orderStatus != ''">orderStatus = #{orderStatus},</if>
            <if test="payTime != null">payTime = #{payTime},</if>
            <if test="payKind != null and payKind != ''">payKind = #{payKind},</if>
            <if test="sellerId != null">sellerId = #{sellerId},</if>
            <if test="combineAppid != null and combineAppid != ''">combineAppid = #{combineAppid},</if>
            <if test="combineMchid != null and combineMchid != ''">combineMchid = #{combineMchid},</if>
            <if test="deviceId != null and deviceId != ''">deviceId = #{deviceId},</if>
            <if test="payerClientIp != null and payerClientIp != ''">payerClientIp = #{payerClientIp},</if>
            <if test="mchid != null and mchid != ''">mchid = #{mchid},</if>
            <if test="outTradeNo != null and outTradeNo != ''">outTradeNo = #{outTradeNo},</if>
            <if test="subMchid != null and subMchid != ''">subMchid = #{subMchid},</if>
            <if test="subAttach != null and subAttach != ''">subAttach = #{subAttach},</if>
            <if test="subDescription != null and subDescription != ''">subDescription = #{subDescription},</if>
            <if test="payAmount != null">payAmount = #{payAmount},</if>
            <if test="subCurrency != null and subCurrency != ''">subCurrency = #{subCurrency},</if>
            <if test="profitSharing != null and profitSharing != ''">profitSharing = #{profitSharing},</if>
            <if test="wxOpenId != null and wxOpenId != ''">wxOpenId = #{wxOpenId},</if>
            <if test="notifyUrl != null and notifyUrl != ''">notifyUrl = #{notifyUrl},</if>
            <if test="stateCode != null and stateCode != ''">stateCode = #{stateCode},</if>
            <if test="prepayId != null and prepayId != ''">prepayId = #{prepayId},</if>
            <if test="tradeType != null and tradeType != ''">tradeType = #{tradeType},</if>
            <if test="tradeState != null and tradeState != ''">tradeState = #{tradeState},</if>
            <if test="bankType != null and bankType != ''">bankType = #{bankType},</if>
            <if test="successTime != null">successTime = #{successTime},</if>
            <if test="transactionId != null and transactionId != ''">transactionId = #{transactionId},</if>
            <if test="wxOrderId != null and wxOrderId != ''">wxOrderId = #{wxOrderId},</if>
            <if test="wxOrderStatus != null and wxOrderStatus != ''">wxOrderStatus = #{wxOrderStatus},</if>
            <if test="delFlag != null and delFlag != ''">delFlag = #{delFlag},</if>
            <if test="createUser != null and createUser != ''">createUser = #{createUser},</if>
            <if test="createTime != null">createTime = #{createTime},</if>
            <if test="updateUser != null and updateUser != ''">updateUser = #{updateUser},</if>
            <if test="updateTime != null">updateTime = #{updateTime},</if>
        </trim>
        where orderId = #{orderId}
    </update>


</mapper>
