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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sqx.common.utils.PageUtils;
import com.sqx.common.utils.Result;
import com.sqx.modules.app.dao.UserMoneyDetailsDao;
import com.sqx.modules.app.entity.UserMoneyDetails;
import com.sqx.modules.app.service.UserMoneyDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestAttribute;

import java.util.Collection;
import java.util.HashMap;

@Service
public class UserMoneyDetailsServiceImpl extends ServiceImpl<UserMoneyDetailsDao, UserMoneyDetails> implements UserMoneyDetailsService {

    @Autowired
    UserMoneyDetailsDao userMoneyDetailsDao;

    @Override
    public Result queryUserMoneyDetails(Integer page, Integer limit,UserMoneyDetails userMoneyDetails) {
        IPage<UserMoneyDetails> pages;
        if (page != null && limit != null) {
            pages = new Page<>(page, limit);
        } else {
            pages = new Page<>();
        }
        return Result.success().put("data", baseMapper.selectPage(pages, new QueryWrapper<>(userMoneyDetails).orderByDesc("create_time")));
    }

    @Override
    public Result selectUserMoneyDetails(Integer page, Integer limit,Long userId, Integer classify,Integer type) {
        //原类别 1保证金 2抽佣金额 3师傅订单收益 4余额充值（后续再加） 5用户提现 6师傅提现 7用户支付订单  8会员分销 9退款
        //1保证金（1） 2分销收益（2）3用户钱包（4，5，7，8） 4师傅钱包（3,6,8）
        return Result.success().put("data", baseMapper.selectPage(new Page<>(page,limit),
                new QueryWrapper<UserMoneyDetails>().eq("user_id",userId).eq(type != null && type != 0, "type", type)
                        .eq(classify==1,"classify",1)
                        .eq(classify==2,"classify",2)
                        .in(classify==3,"classify",4,5,7,8,9)
                        .in(classify==4,"classify",3,6,8)
                        .orderByDesc("create_time")));
    }

    @Override
    public Result selectCashDeposit(String phone, Integer type, Integer page, Integer limit, Long userId) {
        Page<UserMoneyDetails> pages = new Page<>(page, limit);
        PageUtils pageUtils = new PageUtils(baseMapper.selectCashDeposit(pages, phone, type, userId));
        return Result.success().put("data", pageUtils);
    }


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

    @Override
    public IPage<HashMap<String, Object>> getProfitList(Long userId,Integer type, Integer page, Integer limit) {
        Page<HashMap<String, Object>> pages;
        if (page != null && limit != null) {
            pages = new Page<>(page, limit);
        } else {
             pages = new Page<>();
             pages.setSize(-1);
        }
        return userMoneyDetailsDao.getProfitList(pages, userId,type);
    }



    @Override
    public boolean saveBatch(Collection<UserMoneyDetails> entityList) {
        return false;
    }
}
