package com.cyksj.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cyksj.model.entity.RegisterAccountData;
import com.cyksj.model.entity.RegisterOrderDon;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;

/**
 * @author chan
 * @date 2022/11/7 2:38 PM
 */
public interface RegisterOrderDonMapper extends BaseMapper<RegisterOrderDon> {

	@Select("select platform,count(distinct user_id) as numOfUser," +
			"count(user_id) as numOfOrder,sum(money) as money" +
			" from register_order_don" +
			" where created_time between #{yesZeroDate} and #{thisZeroDate} and status not in ('noPayment','close') and platform = #{platform}")
	RegisterAccountData registerAccountDataEveryDay(@Param("yesZeroDate") Date yesZeroDate, @Param("thisZeroDate") Date thisZeroDate, @Param("platform") String platform);

	@Select("select count(user_id) as 'numOfRefundOrder',"+
			"sum(money) as 'refundMoney'" +
			" from register_order_don" +
			" where created_time between #{yesZeroDate} and #{thisZeroDate} and status = 'refund' and platform = #{platform}")
	RegisterAccountData selectRefundOrderDetail(@Param("yesZeroDate") Date yesZeroDate, @Param("thisZeroDate") Date thisZeroDate, @Param("platform") String platform);

	@Select("select id from `order_don` where sku_id = 14 and user_id = #{userId} and status not in ('close','noPayment') limit 1")
	Integer isPaySpotifyYearTicket(Long userId);
}
