<?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.cyksj.mapper.OrderDonRenewRecordMapper">


    <select id="getOtherRenewSku" resultType="com.cyksj.model.entity.OrderDon">
        select o.* from (select order_id from order_don_renew_record where order_id != #{orderId}
        and is_valid = 0
        and user_id in
        <foreach collection="userIds" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>) orr inner join order_don o on o.id = orr.order_id
        and o.status not in ('close','noPayment','refund')
        and o.order_type = 2 and o.relation_id = #{relationId}
        inner join goods_don_sku sku on sku.id = o.sku_id
        order by sku.months desc,sku.gpt_limit_num desc
        limit 1
    </select>

    <select id="getOtherRenewSkus" resultType="com.cyksj.model.entity.OrderDon">
        select o.* from (select order_id from order_don_renew_record where order_id != #{orderId}
        and is_valid = 0
        and user_id in
        <foreach collection="userIds" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>) orr inner join order_don o on o.id = orr.order_id
        and o.status not in ('close','noPayment','refund')
        and o.order_type = 2 and o.relation_id = #{relationId}
        inner join goods_don_sku sku on sku.id = o.sku_id
        order by sku.months desc,sku.gpt_limit_num desc
    </select>
</mapper>