luofl
2025-02-24 8acc98732aba58ad5c710f92d72e6fa5bf888d11
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopController.java
@@ -15,6 +15,7 @@
import com.ruoyi.common.security.utils.MD5Generator;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.order.feignClient.OrderClient;
import com.ruoyi.order.vo.OrderSaleNum;
import com.ruoyi.order.vo.VerifiableShopVo;
import com.ruoyi.other.api.domain.*;
import com.ruoyi.other.mapper.ShopMapper;
@@ -688,14 +689,35 @@
    @ApiOperation(value = "门店统计", tags = {"管理后台-首页统计"})
    public R<ShopStatistics> shopStatistics(@ApiParam("门店id") Integer shopId) {
        ShopStatistics shopStatistics = shopMapper.getShopStatistics(shopId);
        if(null == shopId){
            shopId = 0;
        List<Integer> shopIds;
        shopIds = shopService.list(new LambdaQueryWrapper<Shop>()
                        .eq(Shop::getDelFlag, 0)
                        .eq(shopId !=null,Shop::getId, shopId))
                .stream()
                .map(Shop::getId)
                .collect(Collectors.toList());
        if (CollectionUtils.isEmpty(shopIds)){
            shopStatistics.setTotalOrder(0);
            shopStatistics.setServiceOrder(0);
            shopStatistics.setGoodsOrder(0);
        }else {
            OrderSaleNum serviceOrderSaleNum = new OrderSaleNum();
            serviceOrderSaleNum.setShopIds(shopIds);
            serviceOrderSaleNum.setType(1);
            Integer serviceOrder = orderClient.getShopSaleNumByShopIds(serviceOrderSaleNum).getData();
            OrderSaleNum goodsOrderSaleNum = new OrderSaleNum();
            goodsOrderSaleNum.setShopIds(shopIds);
            goodsOrderSaleNum.setType(2);
            Integer goodsOrder = orderClient.getShopSaleNumByShopIds(goodsOrderSaleNum).getData();
            shopStatistics.setTotalOrder(serviceOrder + goodsOrder);
            shopStatistics.setServiceOrder(serviceOrder);
            shopStatistics.setGoodsOrder(goodsOrder);
        }
        Integer serviceOrder = orderClient.getShopSaleNum(shopId, 1).getData();
        Integer goodsOrder = orderClient.getShopSaleNum(shopId, 2).getData();
        shopStatistics.setTotalOrder(serviceOrder + goodsOrder);
        shopStatistics.setServiceOrder(serviceOrder);
        shopStatistics.setGoodsOrder(goodsOrder);
        return R.ok(shopStatistics);
    }
    
@@ -825,7 +847,7 @@
    @GetMapping("/getShopStatistics")
    public R<Map<String, BigDecimal> > getShopStatistics(@RequestParam("shopId") Integer shopId){
        LambdaQueryWrapper<Shop> queryWrapper = new LambdaQueryWrapper<Shop>().eq(Shop::getDelFlag, 0).eq(Shop::getStatus, 1);
        if(null != shopId){
        if(null != shopId && 0 != shopId){
            queryWrapper.eq(Shop::getId, shopId);
        }
        List<Shop> shopList = shopService.list(queryWrapper);
@@ -841,5 +863,70 @@
        return R.ok(map);
    }
    /**
     * 获取指定用户的服务商
     * @param userId
     * @return
     */
    @GetMapping("/getServiceProvider")
    public R<Shop> getServiceProvider(Long userId){
        List<AppUser> allSuperiors = getAllSuperiors(userId);
        //当前绑定门店的店铺信息(服务商)
        Shop serviceProvider = null;
        for (AppUser allSuperior : allSuperiors) {
            List<Shop> shopList = shopService.lambdaQuery().eq(Shop::getAppUserId, allSuperior.getId()).eq(Shop::getDelFlag,0).list();
            if (!CollectionUtils.isEmpty(shopList)){
                serviceProvider = shopList.get(0);
                break;
            }
        }
        return R.ok(serviceProvider);
    }
    /**
     * 获取指定用户的高级服务商
     * @return
     */
    @GetMapping("/getSuperiorServiceProvider")
    public R<Shop> getSuperiorServiceProvider(Long userId){
        List<AppUser> allSuperiors = getAllSuperiors(userId);
        Long techerId = null;
        for (AppUser allSuperior : allSuperiors) {
            List<Shop> shopList = shopService.lambdaQuery().eq(Shop::getAppUserId, allSuperior.getId()).eq(Shop::getDelFlag,0).list();
            if (!CollectionUtils.isEmpty(shopList)){
                techerId = allSuperior.getId();
                break;
            }
        }
        if (techerId == null){
            return R.fail("暂无高级服务商");
        }
        List<AppUser> allSuperiors1 = getAllSuperiors(techerId);
        for (AppUser allSuperior : allSuperiors1) {
            List<Shop> shopList = shopService.lambdaQuery().eq(Shop::getAppUserId, allSuperior.getId()).eq(Shop::getDelFlag,0).list();
            if (!CollectionUtils.isEmpty(shopList)){
                return R.ok(shopList.get(0));
            }
        }
        return R.fail("暂无高级服务商");
    }
    public List<AppUser> getAllSuperiors(Long userId) {
        List<AppUser> allSuperiors = new ArrayList<>();
        // 获取当前用户的直接上级
        AppUser currentUser = appUserClient.getAppUserById(userId);
        if (currentUser != null && currentUser.getInviteUserId() != null) {
            AppUser superior = appUserClient.getAppUserById(currentUser.getInviteUserId());
            if (superior != null) {
                allSuperiors.add(superior); // 添加直接上级
                allSuperiors.addAll(getAllSuperiors(superior.getId())); // 递归添加上级的上级
            }
        }
        return allSuperiors;
    }
}