package com.ruoyi.other.controller;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.exception.ServiceException;
|
import com.ruoyi.common.core.utils.StringUtils;
|
import com.ruoyi.common.core.utils.poi.ExcelUtil;
|
import com.ruoyi.common.core.web.page.PageInfo;
|
import com.ruoyi.common.security.service.TokenService;
|
import com.ruoyi.other.api.domain.Shop;
|
import com.ruoyi.other.api.domain.ShopBalanceStatement;
|
|
import com.ruoyi.other.dto.ShopBalanceDto;
|
|
import com.ruoyi.other.mapper.ShopBalanceStatementMapper;
|
import com.ruoyi.other.service.ShopBalanceStatementService;
|
import com.ruoyi.other.service.ShopService;
|
|
import com.ruoyi.other.vo.*;
|
|
import com.ruoyi.system.api.domain.SysUser;
|
import com.ruoyi.system.api.feignClient.SysUserClient;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiParam;
|
import org.apache.commons.lang3.tuple.Pair;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletResponse;
|
import java.math.BigDecimal;
|
import java.time.LocalDateTime;
|
import java.time.LocalTime;
|
import java.time.format.DateTimeFormatter;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
import java.util.stream.Stream;
|
|
/**
|
* <p>
|
* 前端控制器
|
* </p>
|
*
|
* @author luodangjia
|
* @since 2024-11-20
|
*/
|
@RestController
|
@RequestMapping("/shop-balance-statement")
|
@Api(tags = "管理后台-财务统计-门店分佣统计")
|
public class ShopBalanceStatementController {
|
@Resource
|
private ShopBalanceStatementService shopBalanceStatementService;
|
@Resource
|
private TokenService tokenService;
|
@Resource
|
private ShopBalanceStatementMapper shopBalanceStatementMapper;
|
@Resource
|
private ShopService shopService;
|
@Resource
|
private SysUserClient sysUserClient;
|
/*
|
@Resource
|
private ShopBalanceStatementCopyMapper shopBalanceStatementCopyMapper;
|
@Resource
|
private ShopWithdrawService shopWithdrawService;
|
*/
|
|
|
/**
|
* 门店分佣统计
|
*/
|
/*@GetMapping("/commissionStatistics")
|
@ApiOperation("门店分佣统计")
|
public R<ShopCommissionStatisticsVO> shopCommissionStatistics(@ApiParam("页码") @RequestParam Integer pageNum,
|
@ApiParam("每一页数据大小") Integer pageSize,
|
ShopBalanceStatement shopBalanceStatement) {
|
ShopCommissionStatisticsVO shopCommissionStatisticsVO = shopBalanceStatementService.shopCommissionStatistics(Page.of(pageNum, pageSize), shopBalanceStatement);
|
return R.ok(shopCommissionStatisticsVO);
|
}*/
|
|
/**
|
* 导出门店分佣统计
|
*/
|
/*@GetMapping("/export")
|
@ApiOperation("导出门店分佣统计")
|
public void export(HttpServletResponse response, ShopBalanceStatement shopBalanceStatement) {
|
ShopCommissionStatisticsVO shopCommissionStatisticsVO = shopBalanceStatementService.shopCommissionStatistics(Page.of(1, Integer.MAX_VALUE), shopBalanceStatement);
|
IPage<ShopBalanceStatement> statementIPage = shopCommissionStatisticsVO.getStatementIPage();
|
ExcelUtil<ShopBalanceStatement> util = new ExcelUtil<>(ShopBalanceStatement.class);
|
util.exportExcel(response, statementIPage.getRecords(), "用户积分统计");
|
}*/
|
|
/*@GetMapping("/commissionStatistics/list")
|
@ApiOperation(value = "门店余额明细", notes = "门店余额明细", tags = {"门店后台"})
|
public R<Page<ShopBalanceStatement>> shopCommissionStatisticslist(@ApiParam("页码") @RequestParam Integer pageNum,
|
@ApiParam("每一页数据大小") Integer pageSize,
|
ShopBalanceStatement shopBalanceStatement) {
|
Long userid = tokenService.getLoginUser().getUserid();
|
R<SysUser> sysUserR = sysUserClient.getSysUser(userid);
|
SysUser sysUser = sysUserR.getData();
|
Integer objectId = sysUser.getObjectId();
|
Page<ShopBalanceStatement> page = shopBalanceStatementService.lambdaQuery().eq(ShopBalanceStatement::getShopId, objectId).eq(shopBalanceStatement.getType() != null, ShopBalanceStatement::getType, shopBalanceStatement.getType())
|
.orderByDesc(ShopBalanceStatement::getCreateTime)
|
.page(Page.of(pageNum, pageSize));
|
|
return R.ok(page);
|
|
|
}*/
|
|
|
/*@GetMapping("/commissionStatistics/info")
|
@ApiOperation(value = "门店余额明细上方数据", notes = "门店余额明细", tags = {"门店后台"})
|
public R<ShopBalanceDto> shopCommissionStatisticsinfo(Integer type) {
|
Integer objectId = tokenService.getLoginUser().getSysUser().getObjectId();
|
ShopBalanceDto dto = new ShopBalanceDto();
|
Shop byId = shopService.getById(objectId);
|
|
if (type == null) {
|
List<ShopBalanceStatement> list = shopBalanceStatementService.lambdaQuery().eq(ShopBalanceStatement::getShopId, objectId).eq(ShopBalanceStatement::getType, 3).list();
|
List<ShopBalanceStatement> list1 = shopBalanceStatementService.lambdaQuery().eq(ShopBalanceStatement::getShopId, objectId).eq(ShopBalanceStatement::getType, 1).list();
|
BigDecimal bigDecimal1 = new BigDecimal(0);
|
for (ShopBalanceStatement shopBalanceStatement : list) {
|
bigDecimal1 = bigDecimal1.add(shopBalanceStatement.getVariableAmount());
|
}
|
for (ShopBalanceStatement shopBalanceStatement : list1) {
|
bigDecimal1 = bigDecimal1.add(shopBalanceStatement.getVariableAmount());
|
}
|
dto.setBigDecimal1(bigDecimal1);
|
|
BigDecimal bigDecimal2 = new BigDecimal(0);
|
for (ShopBalanceStatement shopBalanceStatement : list) {
|
bigDecimal2 = bigDecimal2.add(shopBalanceStatement.getVariableAmount());
|
}
|
dto.setBigDecimal2(bigDecimal2);
|
|
BigDecimal bigDecimal3 = new BigDecimal(0);
|
for (ShopBalanceStatement shopBalanceStatement : list1) {
|
bigDecimal3 = bigDecimal3.add(shopBalanceStatement.getVariableAmount());
|
}
|
dto.setBigDecimal3(bigDecimal3);
|
|
List<ShopBalanceStatement> list2 = shopBalanceStatementService.lambdaQuery().eq(ShopBalanceStatement::getShopId, objectId).eq(ShopBalanceStatement::getType, 2).list();
|
BigDecimal bigDecimal4 = new BigDecimal(0);
|
for (ShopBalanceStatement shopBalanceStatement : list2) {
|
bigDecimal4 = bigDecimal4.add(shopBalanceStatement.getVariableAmount());
|
}
|
dto.setBigDecimal4(bigDecimal4);
|
|
dto.setBigDecimal5(byId.getCanWithdrawMoney());
|
dto.setBigDecimal6(byId.getWithdrawMoney());
|
return R.ok(dto);
|
} else {
|
switch (type) {
|
case 1:
|
// 关联用户分拥
|
BigDecimal bigDecimal = new BigDecimal("0");
|
List<ShopBalanceStatement> list1 = shopBalanceStatementService.lambdaQuery().eq(ShopBalanceStatement::getShopId, objectId).eq(ShopBalanceStatement::getType, 1).list();
|
for (ShopBalanceStatement shopBalanceStatement : list1) {
|
bigDecimal = bigDecimal.add(shopBalanceStatement.getVariableAmount());
|
}
|
dto.setBigDecimal3(bigDecimal);
|
dto.setBigDecimal1(bigDecimal);
|
break;
|
case 2:
|
// 下级门店分佣
|
BigDecimal bigDecimal2 = new BigDecimal(0);
|
List<ShopBalanceStatement> list2 = shopBalanceStatementService.lambdaQuery().eq(ShopBalanceStatement::getShopId, objectId).eq(ShopBalanceStatement::getType, 2).list();
|
for (ShopBalanceStatement shopBalanceStatement : list2) {
|
bigDecimal2 = bigDecimal2.add(shopBalanceStatement.getVariableAmount());
|
}
|
dto.setBigDecimal4(bigDecimal2);
|
dto.setBigDecimal1(bigDecimal2);
|
break;
|
case 3:
|
// 服务费分佣
|
List<ShopBalanceStatement> list = shopBalanceStatementService.lambdaQuery().eq(ShopBalanceStatement::getShopId, objectId).eq(ShopBalanceStatement::getType, 3).list();
|
BigDecimal bigDecimal3 = new BigDecimal(0);
|
for (ShopBalanceStatement shopBalanceStatement : list) {
|
bigDecimal3 = bigDecimal3.add(shopBalanceStatement.getVariableAmount());
|
}
|
dto.setBigDecimal2(bigDecimal3);
|
dto.setBigDecimal1(bigDecimal3);
|
break;
|
case 4:
|
// 余额提现
|
dto.setBigDecimal6(byId.getWithdrawMoney());
|
break;
|
}
|
}
|
return R.ok(dto);
|
}
|
*/
|
|
/* @PostMapping("/getList")
|
public R<List<ShopBalanceStatement>> getList(@RequestBody ShopBalanceStatement shopBalanceStatement) {
|
return R.ok(shopBalanceStatementMapper.selectShopBalanceStatementList(shopBalanceStatement));
|
}*/
|
|
|
/**
|
* 保存门店余额流水
|
*
|
* @param shopBalanceStatement
|
*/
|
@PostMapping("/saveShopBalanceStatement")
|
public void saveShopBalanceStatement(@RequestBody ShopBalanceStatement shopBalanceStatement) {
|
shopBalanceStatementService.save(shopBalanceStatement);
|
}
|
|
/* @PostMapping("/saveShopBalanceStatementCopy")
|
public void saveShopBalanceStatementCopy(@RequestBody ShopBalanceStatementCopy shopBalanceStatementCopy) {
|
shopBalanceStatementCopyMapper.insert(shopBalanceStatementCopy);
|
}*/
|
|
/* @DeleteMapping("/deleteShopBalanceStatementCopy")
|
public R<Boolean> deleteShopBalanceStatementCopy(@RequestParam("orderId") Long orderId, @RequestParam("type") List<Integer> type) {
|
shopBalanceStatementCopyMapper.delete(new LambdaQueryWrapper<ShopBalanceStatementCopy>().in(ShopBalanceStatementCopy::getType, type)
|
.eq(ShopBalanceStatementCopy::getObjectId, orderId));
|
return R.ok();
|
}
|
|
*/
|
/* @PostMapping("/getShopBalanceStatementCopy")
|
public R<List<ShopBalanceStatementCopy>> getShopBalanceStatementCopy(@RequestParam("orderId") Long orderId, @RequestParam("type") List<Integer> type) {
|
List<ShopBalanceStatementCopy> shopBalanceStatementCopies = shopBalanceStatementCopyMapper.selectList(new LambdaQueryWrapper<ShopBalanceStatementCopy>().in(ShopBalanceStatementCopy::getType, type)
|
.eq(ShopBalanceStatementCopy::getObjectId, orderId));
|
return R.ok(shopBalanceStatementCopies);
|
}
|
*/
|
|
/**
|
* 获取门店流水数据
|
*
|
* @param types
|
* @param objectId
|
* @return
|
*/
|
@PostMapping("/getShopBalanceStatementList")
|
public R<List<ShopBalanceStatement>> getShopBalanceStatementList(@RequestParam("types") Collection<Integer> types, @RequestParam(value = "objectId", required = false) Long objectId) {
|
List<ShopBalanceStatement> list = shopBalanceStatementService.list(new LambdaQueryWrapper<ShopBalanceStatement>()
|
.eq(objectId != null, ShopBalanceStatement::getObjectId, objectId)
|
.in(types != null && !types.isEmpty(), ShopBalanceStatement::getType, types));
|
return R.ok(list);
|
}
|
|
@PostMapping("/getShopBalanceStatementList2")
|
public R<List<ShopBalanceStatement>> getShopBalanceStatementList2(@RequestParam("type") Integer type, @RequestParam(value = "shopId") Integer shopId,
|
@RequestParam(value = "date") LocalDateTime date) {
|
LambdaQueryWrapper<ShopBalanceStatement> queryWrapper = new LambdaQueryWrapper<ShopBalanceStatement>()
|
.eq(ShopBalanceStatement::getType, type)
|
.between(ShopBalanceStatement::getCreateTime, date.with(LocalTime.MIN), date.with(LocalTime.MAX));
|
if (null != shopId && 0 != shopId) {
|
queryWrapper.eq(ShopBalanceStatement::getShopId, shopId);
|
}else{
|
List<Integer> shipIds = shopService.list(new LambdaQueryWrapper<Shop>().eq(Shop::getDelFlag, 0)).stream().map(Shop::getId).collect(Collectors.toList());
|
if(shipIds.size() > 0){
|
queryWrapper.in(ShopBalanceStatement::getShopId, shipIds);
|
}else{
|
queryWrapper.eq(ShopBalanceStatement::getShopId, -1);
|
}
|
}
|
List<ShopBalanceStatement> list = shopBalanceStatementService.list(queryWrapper);
|
return R.ok(list);
|
}
|
|
|
/**
|
* 获取门店佣金
|
*
|
* @param shopId
|
* @return
|
*/
|
/* @GetMapping("getShopCommission")
|
@ApiOperation(value = "获取门店佣金", notes = "获取门店佣金", tags = {"小程序-个人中心-门店管理-门店钱包"})
|
@Transactional
|
public R<ShopCommission> getShopCommission(@RequestParam("shopId") Integer shopId) {
|
// 合并查询逻辑
|
List<ShopBalanceStatementCopy> copies = shopBalanceStatementCopyMapper.selectList(
|
new LambdaQueryWrapper<ShopBalanceStatementCopy>()
|
.eq(ShopBalanceStatementCopy::getShopId, shopId));
|
|
List<ShopBalanceStatement> statements = shopBalanceStatementService.list(
|
new LambdaQueryWrapper<ShopBalanceStatement>()
|
.eq(ShopBalanceStatement::getShopId, shopId));
|
|
// 合并计算
|
Map<Integer, BigDecimal> result = Stream.concat(
|
copies.stream().map(e -> Pair.of(e.getType(), e.getVariableAmount())),
|
statements.stream().map(e -> Pair.of(e.getType(), e.getVariableAmount()))
|
).collect(Collectors.groupingBy(
|
Pair::getKey,
|
Collectors.mapping(Pair::getValue, Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))
|
));
|
|
// 待审核佣金
|
BigDecimal waitingAudit = shopWithdrawService.list(new LambdaQueryWrapper<ShopWithdraw>()
|
.eq(ShopWithdraw::getShopId, shopId)
|
.eq(ShopWithdraw::getAuditStatus, 0))
|
.stream()
|
.map(ShopWithdraw::getMoney)
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
// 店铺信息校验
|
Shop shop = shopService.getById(shopId);
|
if (shop == null) {
|
throw new ServiceException("店铺不存在");
|
}
|
|
// 构建结果
|
|
List<ShopWithdraw> list = shopWithdrawService.lambdaQuery().eq(ShopWithdraw::getShopId, shopId)
|
.eq(ShopWithdraw::getAuditStatus, 0).list();
|
BigDecimal withdrawAuditMoney = list.stream().map(ShopWithdraw::getMoney).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
|
|
ShopCommission commission = new ShopCommission();
|
commission.setCanWithdrawCommission(shop.getCanWithdrawMoney());
|
commission.setWithdrawnCommission(shop.getWithdrawMoney().subtract(withdrawAuditMoney));
|
commission.setCommissionAmount(
|
result.getOrDefault(1, BigDecimal.ZERO)
|
.add(result.getOrDefault(2, BigDecimal.ZERO)
|
.add(result.getOrDefault(3, BigDecimal.ZERO))
|
));
|
commission.setWaitingAuditCommission(waitingAudit);
|
commission.setTotalAmount(commission.getCommissionAmount());
|
|
return R.ok(commission);
|
}
|
*/
|
/**
|
* 获取门店佣金明细
|
*/
|
/* @GetMapping("/getshopCommissionStatisticsDetail")
|
@ApiOperation(value = "门店返佣明细", notes = "门店返佣明细", tags = {"小程序-个人中心-门店管理-门店钱包"})
|
public R<ShopBalanceStatementDetailPage> shopCommissionStatisticsDetail(@ApiParam("店铺id") Integer shopId,
|
@ApiParam("类型") Integer type,
|
@ApiParam("开始时间") String createTime,
|
@ApiParam("页码") Integer pageNum,
|
@ApiParam("每一页数据大小") Integer pageSize) {
|
|
LocalDateTime startDate = null;
|
LocalDateTime endDate = null;
|
if (StringUtils.isNotEmpty(createTime)){
|
startDate = LocalDateTime.parse(createTime + " 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
endDate = LocalDateTime.parse(createTime + " 23:59:59", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
}
|
|
List<ShopBalanceStatementCopy> copies = shopBalanceStatementCopyMapper.selectList(
|
new LambdaQueryWrapper<ShopBalanceStatementCopy>()
|
.eq(ShopBalanceStatementCopy::getShopId, shopId)
|
.eq(type != null, ShopBalanceStatementCopy::getType, type)
|
.between(startDate != null && endDate != null, ShopBalanceStatementCopy::getCreateTime,
|
startDate, endDate));
|
|
List<ShopBalanceStatement> statements = shopBalanceStatementService.list(
|
new LambdaQueryWrapper<ShopBalanceStatement>()
|
.eq(ShopBalanceStatement::getShopId, shopId)
|
.eq(type != null, ShopBalanceStatement::getType, type)
|
.between(startDate != null && endDate != null, ShopBalanceStatement::getCreateTime,
|
startDate, endDate));
|
|
Map<Integer, String> itemMap = new HashMap<>();
|
itemMap.put(1, "服务商分佣");
|
itemMap.put(2, "高级服务商分佣");
|
itemMap.put(3, "核销门店服务费");
|
itemMap.put(4, "提现");
|
|
List<ShopCommissionDetail> list = new ArrayList<>();
|
for (ShopBalanceStatementCopy copy : copies) {
|
ShopCommissionDetail detail = new ShopCommissionDetail();
|
detail.setItem(itemMap.get(copy.getType()));
|
detail.setTime(copy.getCreateTime());
|
detail.setAmount(copy.getVariableAmount());
|
|
BigDecimal beforeAmount = copy.getHistoricalBalance();
|
BigDecimal afterAmount = copy.getBalance();
|
if (beforeAmount.compareTo(afterAmount) > 0) {
|
detail.setType(2);
|
} else {
|
detail.setType(1);
|
}
|
list.add(detail);
|
}
|
|
for (ShopBalanceStatement statement : statements) {
|
ShopCommissionDetail detail = new ShopCommissionDetail();
|
detail.setItem(itemMap.get(statement.getType()));
|
detail.setTime(statement.getCreateTime());
|
detail.setAmount(statement.getVariableAmount());
|
|
BigDecimal beforeAmount = statement.getHistoricalBalance();
|
BigDecimal afterAmount = statement.getBalance();
|
if (beforeAmount.compareTo(afterAmount) > 0) {
|
detail.setType(2);
|
} else {
|
detail.setType(1);
|
}
|
list.add(detail);
|
}
|
|
// 按时间排序加手动分页
|
Integer total = list.size();
|
list.sort(Comparator.comparing(ShopCommissionDetail::getTime).reversed());
|
if (pageNum != null && pageSize != null) {
|
int fromIndex = (pageNum - 1) * pageSize;
|
int toIndex = Math.min(fromIndex + pageSize, list.size());
|
list = list.subList(fromIndex, toIndex);
|
}
|
|
ShopBalanceStatementDetailPage page = new ShopBalanceStatementDetailPage();
|
page.setRecords(list);
|
page.setTotal(total);
|
page.setPageSize(pageSize);
|
page.setPageNum(pageNum);
|
return R.ok(page);
|
}*/
|
|
|
/**
|
* 获取门店流水数据
|
*
|
* @param types
|
* @param objectId
|
* @return
|
*/
|
@GetMapping("/getShopBalanceStatementPageList")
|
public R<PageInfo<ShopBalanceStatementVO>> getShopBalanceStatementPageList(@RequestParam(value = "types",required = false) Collection<Integer> types,
|
@RequestParam(value = "objectId", required = false) Long objectId,
|
@RequestParam(value = "id",required = false) Integer id,
|
@ApiParam("当前页")@RequestParam("pageCurr") Integer pageCurr,
|
@ApiParam("分页大小")@RequestParam("pageSize") Integer pageSize) {
|
PageInfo<ShopBalanceStatementVO> pageInfo=shopBalanceStatementService.getShopBalanceStatementPageList(types,objectId,id,pageCurr,pageSize);
|
|
return R.ok(pageInfo);
|
}
|
|
|
}
|