package com.supersavedriving.driver.modular.system.service.impl;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
import com.supersavedriving.driver.core.util.ToolUtil;
|
import com.supersavedriving.driver.modular.system.dao.RevenueMapper;
|
import com.supersavedriving.driver.modular.system.model.AppUser;
|
import com.supersavedriving.driver.modular.system.model.Driver;
|
import com.supersavedriving.driver.modular.system.model.Order;
|
import com.supersavedriving.driver.modular.system.model.Revenue;
|
import com.supersavedriving.driver.modular.system.service.IAppUserService;
|
import com.supersavedriving.driver.modular.system.service.IDriverService;
|
import com.supersavedriving.driver.modular.system.service.IOrderService;
|
import com.supersavedriving.driver.modular.system.service.IRevenueService;
|
import com.supersavedriving.driver.modular.system.warpper.CommissionListWarpper;
|
import com.supersavedriving.driver.modular.system.warpper.PerformanceRankingWarpper;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* 收入记录
|
* @author pzb
|
* @Date 2023/2/25 16:12
|
*/
|
@Service
|
public class RevenueServiceImpl extends ServiceImpl<RevenueMapper, Revenue> implements IRevenueService {
|
|
@Autowired
|
private IOrderService orderService;
|
|
@Autowired
|
private IAppUserService appUserService;
|
|
@Autowired
|
private IDriverService driverService;
|
|
|
|
|
|
|
/**
|
* 获取司机佣金记录
|
* @param driverId
|
* @param time
|
* @param pageNum
|
* @param pageSize
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<CommissionListWarpper> queryCommissionList(Integer driverId, String time, Integer pageNum, Integer pageSize) throws Exception {
|
pageNum = (pageNum - 1) * pageSize;
|
Wrapper<Revenue> wrapper = new EntityWrapper<Revenue>().eq("type", 2).eq("userType", 2)
|
.eq("userId", driverId);
|
if(ToolUtil.isNotEmpty(time)){
|
wrapper.eq("DATE_FORMAT(createTime, '%Y年%m月')", time);
|
}
|
List<Revenue> revenues = this.selectList(wrapper.last(" order by createTime desc limit " + pageNum + ", " + pageSize));
|
List<CommissionListWarpper> list = new ArrayList<>();
|
for (Revenue revenue : revenues) {
|
CommissionListWarpper commissionListWarpper = new CommissionListWarpper();
|
commissionListWarpper.setCreateTime(revenue.getCreateTime().getTime());
|
commissionListWarpper.setAmount(revenue.getAmount());
|
commissionListWarpper.setUserType(2);
|
Order order = orderService.selectById(revenue.getOrderId());
|
if(null != order.getUserId()){
|
AppUser appUser = appUserService.selectById(order.getUserId());
|
if(null != appUser.getInviterType() && appUser.getInviterType() == 2 && appUser.getInviterId().compareTo(driverId) == 0){
|
commissionListWarpper.setUserType(1);
|
}
|
}
|
if(null == commissionListWarpper.getUserType()){
|
Driver driver = driverService.selectById(order.getDriverId());
|
if(null != driver.getInviterType() && driver.getInviterType() == 2 && driver.getInviterId().compareTo(driverId) == 0){
|
commissionListWarpper.setUserType(2);
|
}
|
}
|
list.add(commissionListWarpper);
|
}
|
return list;
|
}
|
|
/**
|
* 获取司机总收入
|
* @param driverId
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public Double queryTotalAmount(Integer driverId) throws Exception {
|
return this.baseMapper.queryTotalAmount(driverId);
|
}
|
|
|
/**
|
* 获取司机佣金收入排行
|
* @param time
|
* @param dayType
|
* @return
|
*/
|
@Override
|
public List<PerformanceRankingWarpper> queryDriverRank(Integer type, String time, Integer dayType) {
|
return this.baseMapper.queryDriverRank(type, time, dayType);
|
}
|
}
|