puzhibing
2025-01-08 ddf3f19408fb311734218aaaa5edb49c5134b1eb
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopController.java
@@ -11,6 +11,7 @@
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.order.feignClient.OrderClient;
import com.ruoyi.order.vo.VerifiableShopVo;
import com.ruoyi.other.api.domain.Goods;
import com.ruoyi.other.api.domain.GoodsShop;
@@ -77,6 +78,8 @@
    private GoodsService goodsService;
    @Resource
    private GoodsShopService goodsShopService;
    @Resource
    private OrderClient orderClient;
@@ -179,7 +182,6 @@
        Shop shop = shopService.getById(id);
        shop.setDelFlag(1);
        shopService.updateById(shop);
        //获取门店的员工数据
        UserShop userShop = new UserShop();
        userShop.setShopId(shop.getId());
        List<UserShop> data = userShopClient.getUserShop(userShop).getData();
@@ -189,16 +191,19 @@
        sysUserClient.delShopUser(shop.getId(), 2);
        //修改小程序用户类型和门店数据
        for (SysUser sysUser : sysUserList) {
            String userName = sysUser.getUserName();
            //通过电话号码查询小程序用户和门店关系数据
            AppUser appUser = appUserClient.getAppUserByPhone1(userName).getData();
            AppUser appUser = appUserClient.getAppUserByPhone1(sysUser.getUserName()).getData();
            //需要先判断用户是否没有关联任何门店
            List<AppUserShop> userShops = appUserShopClient.getAppUserShop(appUser.getId()).getData();
            if(userShops.size() == 1 && userShops.get(0).getShopId().equals(shop.getId())){
                appUser.setUserType(1);
                appUserClient.editAppUserById(appUser);
            }
            //删除用户门店关系表数据
            AppUserShop appUserShop = new AppUserShop();
            appUserShop.setAppUserId(appUser.getId());
            appUserShop.setShopId(shop.getId());
            appUserShopClient.delAppUserShop(appUserShop);
        }
        return R.ok();
    }
@@ -282,6 +287,22 @@
        }
        return R.ok();
    }
    @PutMapping("/freezingOrThawing")
    @ApiOperation(value = "门店管理-冻结/解冻门店", tags = {"管理后台-门店管理"})
    public R freezingOrThawing(@RequestParam("id") Integer id, @RequestParam("status") Integer status){
        Shop shop = shopService.getById(id);
        if(shop.getStatus().equals(status)){
            return R.fail("不能重复操作");
        }
        shop.setStatus(status);
        shopService.updateById(shop);
        return R.ok();
    }
    @GetMapping("/list")
    @ApiOperation(value = "门店列表", tags = {"管理后台-门店管理"})
@@ -383,6 +404,9 @@
    @ApiOperation(value = "绑定门店", tags = {"小程序-个人中心"})
    public R<Void> bindShop(@ApiParam("门店id") @RequestParam Integer shopId) {
        AppUser appUser = appUserClient.getAppUserById(SecurityUtils.getUserId());
        if(null != appUser.getShopId()){
            return R.fail("不能重复绑定门店");
        }
        appUser.setShopId(shopId);
        return appUserClient.editAppUserById(appUser);
    }
@@ -418,7 +442,7 @@
    @ResponseBody
    @PostMapping("/getShopByUserId")
    public R<List<Shop>> getShopByUserId(@RequestParam("id") Long id){
        List<Shop> list = shopService.lambdaQuery().eq(Shop::getAppUserId, id).list();
        List<Shop> list = shopService.lambdaQuery().eq(Shop::getAppUserId, id).eq(Shop::getDelFlag,0).list();
        return R.ok(list);
    }
    
@@ -455,6 +479,14 @@
    @ApiOperation(value = "门店统计", tags = {"管理后台-首页统计"})
    public R<ShopStatistics> shopStatistics(@ApiParam("门店id") Integer shopId) {
        ShopStatistics shopStatistics = shopMapper.getShopStatistics(shopId);
        if(null == shopId){
            shopId = 0;
        }
        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);
    }
    
@@ -476,12 +508,16 @@
    @ApiOperation(value = "获取可核销门店列表", tags = {"购物车-小程序"})
    public R<List<VerifiableShopVo>> getVerifiableShop(String longitude, String latitude, Integer goodsId){
        String city = TencentMapUtil.inverseGeographicalAnalysis(longitude, latitude, false);
        if(null == city){
            city = "510100";
        }
        city = city.substring(0, 4) + "00";
        LambdaQueryWrapper<Shop> wrapper = new LambdaQueryWrapper<Shop>().eq(Shop::getDelFlag, 0).eq(Shop::getCityCode, city);
        if(null != goodsId){
            Goods goods = goodsService.getById(goodsId);
            if(1 == goods.getType() && 1 == goods.getAppointStore()){
                List<Integer> collect = goodsShopService.list(new LambdaQueryWrapper<GoodsShop>().eq(GoodsShop::getGoodsId, goods)).stream().map(GoodsShop::getShopId).collect(Collectors.toList());
                List<Integer> collect = goodsShopService.list(new LambdaQueryWrapper<GoodsShop>().eq(GoodsShop::getGoodsId, goods.getId()))
                        .stream().map(GoodsShop::getShopId).collect(Collectors.toList());
                if(collect.size() > 0){
                    wrapper.in(Shop::getId, collect);
                }
@@ -538,5 +574,16 @@
        shopService.saveWithdrawalAccount(saveWithdrawalAccount);
        return R.ok();
    }
    /**
     * 获取所有门店
     * @return
     */
    @PostMapping("/getAllShop")
    public R<List<Shop>> getAllShop(){
        List<Shop> list = shopService.list(new LambdaQueryWrapper<Shop>().eq(Shop::getDelFlag, 0).eq(Shop::getStatus, 1));
        return R.ok(list);
    }
}