package com.sqx.modules.pay.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sqx.common.utils.PageUtils;
import com.sqx.modules.pay.dao.PayDetailsDao;
import com.sqx.modules.pay.entity.PayDetails;
import com.sqx.modules.pay.service.PayDetailsService;
import com.sqx.modules.utils.TimeCompleteUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 充值记录
 */
@Service
public class PayDetailsServiceImpl extends ServiceImpl<PayDetailsDao, PayDetails> implements PayDetailsService {

    /**
     * 充值记录
     */
    @Autowired
    private PayDetailsDao payDetailsDao;


    @Override
    public PageUtils selectPayDetails(int page, int limit, String startTime, String endTime, Long userId, Integer state, String userName, String orderId) {
        PageHelper.startPage(page, limit);
        if (state != null && state == -1) {
            state = null;
        }
        List<Map<String, Object>> payDetails = payDetailsDao.selectPayDetails(TimeCompleteUtils.completeStartTime(startTime), TimeCompleteUtils.completeEndTime(endTime), userId, state, userName, orderId);
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(payDetails);
        return PageUtils.page(pageInfo);
    }

    @Override
    public Double selectSumPay(String createTime, String endTime, Long userId) {
        if (userId == null || userId == -1) {
            return payDetailsDao.selectSumPay(TimeCompleteUtils.completeStartTime(createTime), TimeCompleteUtils.completeEndTime(endTime), null);
        }
        return payDetailsDao.selectSumPay(TimeCompleteUtils.completeStartTime(createTime), TimeCompleteUtils.completeEndTime(endTime), userId);
    }

    @Override
    public PageUtils payMemberAnalysis(int page, int limit, String time, Integer flag) {
        PageHelper.startPage(page, limit);
        List<Map<String, Object>> list = payDetailsDao.payMemberAnalysis(time, flag);
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
        return PageUtils.page(pageInfo);
    }

    @Override
    public PageUtils selectUserMemberList(int page, int limit, String phone) {
        PageHelper.startPage(page, limit);
        List<Map<String, Object>> list = payDetailsDao.selectUserMemberList(phone);
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
        return PageUtils.page(pageInfo);
    }

    @Override
    public Double selectSumMember(String time, Integer flag) {
        return payDetailsDao.selectSumMember(time, flag);
    }

    @Override
    public Double selectSumPayByState(String time, Integer flag, Integer state) {
        return payDetailsDao.selectSumPayByState(time, flag, state);
    }

    @Override
    public Double selectSumPayByClassify(String time, Integer flag, Integer classify, Integer payClassify) {
        return payDetailsDao.selectSumPayByClassify(time, flag, classify, payClassify);
    }

    @Override
    public Double instantselectSumPay(String date, Long userId) {
        return payDetailsDao.instantselectSumPay(date, userId);
    }


}
