package com.hfkj.dao;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

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

/**
 * mapper扩展类
 */
public interface BsTradeOrderMapperExt {

    @Select("<script>" +
            " select " +
            " case WHEN sum(trade_actual_amount) is not null then sum(trade_actual_amount) else 0 end tradePrice," +
            " count(1) count" +
            " from bs_trade_order " +
            " where 1 = 1" +
            " <if test='param.agentId != null'> and agent_id = #{param.agentId}</if>" +
            " <if test='param.salesmanId != null'> and salesman_id = #{param.salesmanId} </if>" +
            " <if test='param.merId != null'> and mer_id = #{param.merId} </if>" +
            " <if test='param.storeId != null'> and store_id = #{param.storeId} </if>" +
            " <if test='param.storeName != null'> and store_name CONCAT('%', #{param.storeName} , '%') </if>" +
            " <if test='param.payMode != null'> and pay_mode = #{param.payMode}</if>" +
            " <if test='param.outTradeNo != null'> and out_trade_no like CONCAT('%', #{param.outTradeNo} , '%')</if>" +
            " <if test='param.accTradeNo != null'> and acc_trade_no = #{param.accTradeNo}</if>" +
            " <if test='param.payTimeS != null'> <![CDATA[  and pay_time >= #{param.payTimeS} ]]>  </if>" +
            " <if test='param.payTimeE != null'> <![CDATA[  and pay_time <= #{param.payTimeE} ]]>  </if>" +
            " <if test='param.status != null'> and status = #{param.status}</if>" +
            "</script>")
    Map<String,Object> countTradeOrderPrice(@Param("param") Map<String, Object> param);


    @Select("SELECT count(1) FROM `bs_trade_order` where user_phone = #{userPhone} and `status` = 3 and rebate_activity_part = 1 and pay_time BETWEEN #{timeS} and #{timeE} ")
    Integer countUserTrade(@Param("userPhone") String userPhone, @Param("timeS") String timeS, @Param("timeE") String timeE);
    
    @Select("<script>" +
            " select " +
            " mer_no merNo," +
            " sum(user_discount_actual_price) totalPrice" +
            " from bs_trade_order " +
            " where `status` = 3 and user_discount_actual_price is not null " +
            " <![CDATA[ and pay_time >= #{startTime} ]]>" +
            " <![CDATA[ and pay_time <= #{endTime} ]]>" +
            " GROUP BY mer_no " +
            " </script>")
    List<Map<String,Object>> countMerUserDiscountPrice(@Param("startTime") String startTime, @Param("endTime") String endTime);
}
