package com.hfkj.dao;

import com.hfkj.openapi.v1.model.TradeBillsModel;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @className: OpenApiTradeOrderMapper
 * @author: HuRui
 * @date: 2023/5/25
 **/
@Repository
public interface OpenApiTradeOrderMapper {

    @Select({
            "<script>" +
                    " SELECT " +
                    " a.pay_time payTime," +
                    " a.mer_no merchantNo," +
                    " a.platform_trade_no platformTradeNo," +
                    " a.out_trade_no outTradeNo, " +
                    " a.pay_user_id payUserId, " +
                    " \"JSAPI\" as tradeType," +
                    " case a.pay_mode" +
                    " when \"WECHAT\" then '微信'" +
                    " when \"ALIPAY\" then '支付宝'" +
                    " when \"UQRCODEPAY\" then '云闪付'" +
                    " end payMode," +
                    " \"交易成功\" as tradeStatus," +
                    " a.trade_amount tradeAmount," +
                    " a.trade_actual_amount tradeActualAmount," +
                    " case a.refund_type" +
                    " when 1 then '全额退款' " +
                    " when 2 then '部分退款'" +
                    " end refundType," +
                    " a.refund_price refundPrice," +
                    " subject subject," +
                    " case a.create_type" +
                    " when 1 then '扫一扫'" +
                    " when 2 then '被扫'" +
                    " when 3 then 'API'" +
                    " end createType" +
                    " FROM `bs_trade_order` a" +
                    " where a.mer_no = #{merNo} " +
                    " <![CDATA[ and pay_time >= #{billDateS} ]]>" +
                    " <![CDATA[ and pay_time <= #{billDateE} ]]>" +
                    " and a.`status` in (3,6)" +
                    " GROUP BY a.id" +
            " </script>"
    })
    List<TradeBillsModel> queryTradeBills(@Param("merNo") String merNo,@Param("billDateS") String billDateS, @Param("billDateE") String billDateE);

}
