Pu Zhibing
2025-04-03 1f09f6daaf73bc83cceb4ae22b862b7b365635cf
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopBalanceStatementController.java
@@ -31,6 +31,8 @@
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.BeanUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@@ -105,10 +107,8 @@
        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));
        Page<ShopBalanceStatement> page = shopBalanceStatementService.shopCommissionStatisticslist(objectId, shopBalanceStatement.getType(), pageNum, pageSize);
        page.getRecords().forEach(s->s.setVariableAmount(s.getVariableAmount().multiply(new BigDecimal(s.getChangeDirection()))));
        return R.ok(page);
@@ -125,11 +125,20 @@
        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();
            List<ShopBalanceStatementCopy> list3 = shopBalanceStatementCopyMapper.selectList(new LambdaQueryWrapper<ShopBalanceStatementCopy>().eq(ShopBalanceStatementCopy::getShopId, objectId).eq(ShopBalanceStatementCopy::getType, 3));
            List<ShopBalanceStatementCopy> list4 = shopBalanceStatementCopyMapper.selectList(new LambdaQueryWrapper<ShopBalanceStatementCopy>().eq(ShopBalanceStatementCopy::getShopId, objectId).eq(ShopBalanceStatementCopy::getType, 1));
            BigDecimal bigDecimal1 = new BigDecimal(0);
            for (ShopBalanceStatement shopBalanceStatement : list) {
                bigDecimal1 = bigDecimal1.add(shopBalanceStatement.getVariableAmount());
            }
            for (ShopBalanceStatementCopy shopBalanceStatement : list3) {
                bigDecimal1 = bigDecimal1.add(shopBalanceStatement.getVariableAmount());
            }
            for (ShopBalanceStatement shopBalanceStatement : list1) {
                bigDecimal1 = bigDecimal1.add(shopBalanceStatement.getVariableAmount());
            }
            for (ShopBalanceStatementCopy shopBalanceStatement : list4) {
                bigDecimal1 = bigDecimal1.add(shopBalanceStatement.getVariableAmount());
            }
            dto.setBigDecimal1(bigDecimal1);
@@ -138,17 +147,27 @@
            for (ShopBalanceStatement shopBalanceStatement : list) {
                bigDecimal2 = bigDecimal2.add(shopBalanceStatement.getVariableAmount());
            }
            for (ShopBalanceStatementCopy shopBalanceStatement : list3) {
                bigDecimal2 = bigDecimal2.add(shopBalanceStatement.getVariableAmount());
            }
            dto.setBigDecimal2(bigDecimal2);
            BigDecimal bigDecimal3 = new BigDecimal(0);
            for (ShopBalanceStatement shopBalanceStatement : list1) {
                bigDecimal3 = bigDecimal3.add(shopBalanceStatement.getVariableAmount());
            }
            for (ShopBalanceStatementCopy shopBalanceStatement : list4) {
                bigDecimal3 = bigDecimal3.add(shopBalanceStatement.getVariableAmount());
            }
            dto.setBigDecimal3(bigDecimal3);
            List<ShopBalanceStatement> list2 = shopBalanceStatementService.lambdaQuery().eq(ShopBalanceStatement::getShopId, objectId).eq(ShopBalanceStatement::getType, 2).list();
            List<ShopBalanceStatementCopy> list5 = shopBalanceStatementCopyMapper.selectList(new LambdaQueryWrapper<ShopBalanceStatementCopy>().eq(ShopBalanceStatementCopy::getShopId, objectId).eq(ShopBalanceStatementCopy::getType, 2));
            BigDecimal bigDecimal4 = new BigDecimal(0);
            for (ShopBalanceStatement shopBalanceStatement : list2) {
                bigDecimal4 = bigDecimal4.add(shopBalanceStatement.getVariableAmount());
            }
            for (ShopBalanceStatementCopy shopBalanceStatement : list5) {
                bigDecimal4 = bigDecimal4.add(shopBalanceStatement.getVariableAmount());
            }
            dto.setBigDecimal4(bigDecimal4);
@@ -162,7 +181,11 @@
                    // 关联用户分拥
                    BigDecimal bigDecimal = new BigDecimal("0");
                    List<ShopBalanceStatement> list1 = shopBalanceStatementService.lambdaQuery().eq(ShopBalanceStatement::getShopId, objectId).eq(ShopBalanceStatement::getType, 1).list();
                    List<ShopBalanceStatementCopy> list4 = shopBalanceStatementCopyMapper.selectList(new LambdaQueryWrapper<ShopBalanceStatementCopy>().eq(ShopBalanceStatementCopy::getShopId, objectId).eq(ShopBalanceStatementCopy::getType, 1));
                    for (ShopBalanceStatement shopBalanceStatement : list1) {
                        bigDecimal = bigDecimal.add(shopBalanceStatement.getVariableAmount());
                    }
                    for (ShopBalanceStatementCopy shopBalanceStatement : list4) {
                        bigDecimal = bigDecimal.add(shopBalanceStatement.getVariableAmount());
                    }
                    dto.setBigDecimal3(bigDecimal);
@@ -172,7 +195,11 @@
                    // 下级门店分佣
                    BigDecimal bigDecimal2 = new BigDecimal(0);
                    List<ShopBalanceStatement> list2 = shopBalanceStatementService.lambdaQuery().eq(ShopBalanceStatement::getShopId, objectId).eq(ShopBalanceStatement::getType, 2).list();
                    List<ShopBalanceStatementCopy> list5 = shopBalanceStatementCopyMapper.selectList(new LambdaQueryWrapper<ShopBalanceStatementCopy>().eq(ShopBalanceStatementCopy::getShopId, objectId).eq(ShopBalanceStatementCopy::getType, 2));
                    for (ShopBalanceStatement shopBalanceStatement : list2) {
                        bigDecimal2 = bigDecimal2.add(shopBalanceStatement.getVariableAmount());
                    }
                    for (ShopBalanceStatementCopy shopBalanceStatement : list5) {
                        bigDecimal2 = bigDecimal2.add(shopBalanceStatement.getVariableAmount());
                    }
                    dto.setBigDecimal4(bigDecimal2);
@@ -181,8 +208,12 @@
                case 3:
                    // 服务费分佣
                    List<ShopBalanceStatement> list = shopBalanceStatementService.lambdaQuery().eq(ShopBalanceStatement::getShopId, objectId).eq(ShopBalanceStatement::getType, 3).list();
                    List<ShopBalanceStatementCopy> list6 = shopBalanceStatementCopyMapper.selectList(new LambdaQueryWrapper<ShopBalanceStatementCopy>().eq(ShopBalanceStatementCopy::getShopId, objectId).eq(ShopBalanceStatementCopy::getType, 3));
                    BigDecimal bigDecimal3 = new BigDecimal(0);
                    for (ShopBalanceStatement shopBalanceStatement : list) {
                        bigDecimal3 = bigDecimal3.add(shopBalanceStatement.getVariableAmount());
                    }
                    for (ShopBalanceStatementCopy shopBalanceStatement : list6) {
                        bigDecimal3 = bigDecimal3.add(shopBalanceStatement.getVariableAmount());
                    }
                    dto.setBigDecimal2(bigDecimal3);
@@ -225,7 +256,15 @@
                .eq(ShopBalanceStatementCopy::getObjectId, orderId));
        return R.ok();
    }
    @DeleteMapping("/deleteShopBalanceStatementCopyByIds")
    public R<Boolean> deleteShopBalanceStatementCopyByIds(@RequestParam("ids") List<Long> ids){
        shopBalanceStatementCopyMapper.deleteBatchIds(ids);
        return R.ok();
    }
    @PostMapping("/getShopBalanceStatementCopy")
    public R<List<ShopBalanceStatementCopy>> getShopBalanceStatementCopy(@RequestParam("orderId") Long orderId, @RequestParam("type") List<Integer> type) {
@@ -258,8 +297,39 @@
                .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);
        for (ShopBalanceStatement shopBalanceStatement : list) {
            shopBalanceStatement.setVariableAmount(shopBalanceStatement.getVariableAmount().multiply(new BigDecimal(shopBalanceStatement.getChangeDirection())));
        }
        LambdaQueryWrapper<ShopBalanceStatementCopy> queryWrapper1 = new LambdaQueryWrapper<ShopBalanceStatementCopy>()
                .eq(ShopBalanceStatementCopy::getType, type)
                .between(ShopBalanceStatementCopy::getCreateTime, date.with(LocalTime.MIN), date.with(LocalTime.MAX));
        if (null != shopId && 0 != shopId) {
            queryWrapper1.eq(ShopBalanceStatementCopy::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){
                queryWrapper1.in(ShopBalanceStatementCopy::getShopId, shipIds);
            }else{
                queryWrapper1.eq(ShopBalanceStatementCopy::getShopId, -1);
            }
        }
        List<ShopBalanceStatementCopy> list1 = shopBalanceStatementCopyMapper.selectList(queryWrapper1);
        for (ShopBalanceStatementCopy shopBalanceStatementCopy  : list1) {
            ShopBalanceStatement shopBalanceStatement = new ShopBalanceStatement();
            BeanUtils.copyProperties(shopBalanceStatementCopy, shopBalanceStatement);
            shopBalanceStatement.setVariableAmount(shopBalanceStatement.getVariableAmount().multiply(new BigDecimal(shopBalanceStatement.getChangeDirection())));
            list.add(shopBalanceStatement);
        }
        return R.ok(list);
    }
@@ -272,6 +342,7 @@
     */
    @GetMapping("getShopCommission")
    @ApiOperation(value = "获取门店佣金", notes = "获取门店佣金", tags = {"小程序-个人中心-门店管理-门店钱包"})
    @Transactional
    public R<ShopCommission> getShopCommission(@RequestParam("shopId") Integer shopId) {
        // 合并查询逻辑
        List<ShopBalanceStatementCopy> copies = shopBalanceStatementCopyMapper.selectList(
@@ -284,8 +355,8 @@
        // 合并计算
        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()))
                copies.stream().map(e -> Pair.of(e.getType(), e.getVariableAmount().multiply(new BigDecimal(e.getChangeDirection())))),
                statements.stream().map(e -> Pair.of(e.getType(), e.getVariableAmount().multiply(new BigDecimal(e.getChangeDirection()))))
        ).collect(Collectors.groupingBy(
                Pair::getKey,
                Collectors.mapping(Pair::getValue, Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))
@@ -306,7 +377,6 @@
        }
        // 构建结果
        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);
@@ -321,7 +391,6 @@
                        ));
        commission.setWaitingAuditCommission(waitingAudit);
        commission.setTotalAmount(commission.getCommissionAmount());
        return R.ok(commission);
    }
@@ -370,9 +439,7 @@
            detail.setTime(copy.getCreateTime());
            detail.setAmount(copy.getVariableAmount());
            BigDecimal beforeAmount = copy.getHistoricalBalance();
            BigDecimal afterAmount = copy.getBalance();
            if (beforeAmount.compareTo(afterAmount) > 0) {
            if (copy.getChangeDirection() == -1) {
                detail.setType(2);
            } else {
                detail.setType(1);
@@ -386,9 +453,7 @@
            detail.setTime(statement.getCreateTime());
            detail.setAmount(statement.getVariableAmount());
            BigDecimal beforeAmount = statement.getHistoricalBalance();
            BigDecimal afterAmount = statement.getBalance();
            if (beforeAmount.compareTo(afterAmount) > 0) {
            if (statement.getChangeDirection() == -1) {
                detail.setType(2);
            } else {
                detail.setType(1);