package cn.pluss.platform.mapper;

import cn.pluss.platform.entity.MercOrderDetail;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 订单详情表 Mapper 接口
 * </p>
 *
 * @author Djh
 * @since 2022-03-17
 */
public interface MercOrderDetailMapper extends BaseMapper<MercOrderDetail> {

    /**
     * 获取已经退款的订单额度
     * @param orderNo
     * @return
     */
    @Select("SELECT IFNULL(SUM(refundAmt),0) FROM tb_pluss_merc_order_detail WHERE orderNo = #{orderNo} AND status = '03'  ")
    BigDecimal getUseRefundAmtByOrderNo(String orderNo);

    /**
     * 分页查询
     * @param page
     * @param condition
     * @return
     */
    Page<MercOrderDetail> pageInfo(Page<MercOrderDetail> page, @Param("condition") MercOrderDetail condition);

    /**
     * 根据订单号和code查询订单信息
     * @param orderNo
     * @param code
     * @return
     */
    @Select("SELECT * FROM tb_pluss_merc_order_detail WHERE  orderNo = #{orderNo} and `code` = #{code}")
    List<MercOrderDetail> listByOrderNoAndCode(@Param("orderNo") String orderNo, @Param("code")String code);
}
