package cn.iocoder.yudao.module.pay.dal.mysql.wxprofitsharing;

import java.math.BigDecimal;
import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.pay.dal.dataobject.refundlog.PayRefundLogDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wxprofitsharing.WxProfitsharingDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.pay.controller.admin.wxprofitsharing.vo.*;
import org.apache.ibatis.annotations.Select;

/**
 * 微信分账记录 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface WxProfitsharingMapper extends BaseMapperX<WxProfitsharingDO> {

    default PageResult<WxProfitsharingDO> selectPage(WxProfitsharingPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<WxProfitsharingDO>()
                .eqIfPresent(WxProfitsharingDO::getPayWxOrderId, reqVO.getPayWxOrderId())
                .eqIfPresent(WxProfitsharingDO::getTotalPrice, reqVO.getTotalPrice())
                .eqIfPresent(WxProfitsharingDO::getReturnPrice, reqVO.getReturnPrice())
                .eqIfPresent(WxProfitsharingDO::getOutOrderNo, reqVO.getOutOrderNo())
                .eqIfPresent(WxProfitsharingDO::getOrderId, reqVO.getOrderId())
                .eqIfPresent(WxProfitsharingDO::getState, reqVO.getState())
                .betweenIfPresent(WxProfitsharingDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(WxProfitsharingDO::getId));
    }

    @Select("select sum(wx_amount) from member_dish_order where DATE(create_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)")
    BigDecimal getToday();

    @Select("select * from member_refund_log where left_money > 0 ")
    List<PayRefundLogDO> getRefund();

    @Select("select money from member_recharge_log where DATE(create_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY) ")
    BigDecimal getRechargeLog();

    @Select("select wx_amount from member_card where user_id = #{userId} order by create_time desc limit 1")
    BigDecimal getWxAmount(Long userId);

    @Select("select count(1) from member_dish_order where user_id = #{userId} and order_status = '0'")
    int orderCount(Long userId);

}