huliguo
5 天以前 6acf6357094588946b5528f1ef1ed84a0f1037fd
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopController.java
@@ -15,6 +15,7 @@
import com.ruoyi.account.api.model.AppUserShop;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.bean.BeanUtils;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.common.security.service.TokenService;
@@ -50,6 +51,7 @@
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
@@ -221,41 +223,58 @@
    @PutMapping("/editShop")
    @ApiOperation(value = "门店管理-编辑门店", tags = {"管理后台-门店管理"})
    public R<Void> editShop(@RequestBody Shop shop){
        //修改店长
        //判断是否修改店长
        Shop byId = shopService.getById(shop.getId());
        String phone = shop.getPhone();
        AppUser appUser = appUserClient.getAppUserByPhone1(phone).getData();
        if (appUser == null){
            return R.fail("该手机号未注册");
        if (!phone.equals(byId.getPhone())){
            //修改店长
            AppUser appUser = appUserClient.getAppUserByPhone1(phone).getData();
            if (appUser == null){
                return R.fail("该手机号未注册");
            }
            Long originalUserId = byId.getAppUserId();
            //添加用户id到shop信息中
            shop.setAppUserId(appUser.getId());
            //删除店铺关系
            R deleteR = appUserShopClient.delete(shop.getId(), originalUserId);
            if (deleteR.getCode()!=200){
                throw new RuntimeException("删除用户门店关系失败");
            }
            //添加shopuser
            AppUserShop appUserShop = new AppUserShop();
            appUserShop.setAppUserId(appUser.getId());
            appUserShop.setShopId(shop.getId());
            R appUserShopR = appUserShopClient.insert(appUserShop);
            if (appUserShopR.getCode()!=200){
                throw new RuntimeException("添加用户门店关系失败");
            }
        }
        Long originalUserId = shop.getAppUserId();
        //添加用户id到shop信息中
        shop.setAppUserId(appUser.getId());
        //删除店铺关系
        R deleteR = appUserShopClient.delete(shop.getId(), originalUserId);
        if (deleteR.getCode()!=200){
            throw new RuntimeException("删除用户门店关系失败");
        }
        //删除客服电话
        QueryWrapper<Phone> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("shop_id", shop.getId());
        phoneService.remove(queryWrapper);
        queryWrapper.eq("type",2);
        Phone one = phoneService.getOne(queryWrapper);
        if (!one.getPhoneOne().equals(shop.getServiceTel())){
            phoneService.removeById(one.getId());
            //添加客服phone
            Phone phone1 = new Phone();
            phone1.setType(2);//门店
            phone1.setPhoneOne(shop.getServiceTel());
            phone1.setShopId(shop.getId());
            phoneService.save(phone1);
        }
        //修改店铺
        shopService.updateById(shop);
        //添加shopuser
        AppUserShop appUserShop = new AppUserShop();
        appUserShop.setAppUserId(appUser.getId());
        appUserShop.setShopId(shop.getId());
        R appUserShopR = appUserShopClient.insert(appUserShop);
        if (appUserShopR.getCode()!=200){
            throw new RuntimeException("添加用户门店关系失败");
        }
        //添加客服phone
        Phone phone1 = new Phone();
        phone1.setType(2);//门店
        phone1.setPhoneOne(shop.getServiceTel());
        phone1.setShopId(shop.getId());
        phoneService.save(phone1);
        return R.ok();
    }
@@ -635,9 +654,9 @@
    /**
     * 获取所有门店
     */
    @PostMapping("/getAllShop")
    @GetMapping("/getAllShop")
    public R<List<Shop>> getAllShop(){
        List<Shop> list = shopService.list(new LambdaQueryWrapper<Shop>().eq(Shop::getDelFlag, 0));
        List<Shop> list = shopService.list(new LambdaQueryWrapper<Shop>().select(Shop::getName,Shop::getId).eq(Shop::getDelFlag, 0));
        return R.ok(list);
    }
@@ -680,6 +699,16 @@
        return R.ok(list);
    }
    @GetMapping("/getServiceProvider")
    R<List<String>> getServiceProvider(@RequestParam("appUserId") Long appUserId){
        LambdaQueryWrapper<Shop> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(Shop::getAppUserId, appUserId);
        queryWrapper.eq(Shop::getDelFlag,0);
        List<Shop> shops = shopMapper.selectList(queryWrapper);
        List<String> collect = shops.stream().map(Shop::getName).distinct().collect(Collectors.toList());
        return R.ok(collect);
    }
/*
    @GetMapping("/getShopStatistics")
@@ -705,7 +734,7 @@
*/
    /**
     * 获取店铺收益 后天-工作台-收益分析
     * 获取店铺收益 后台-工作台-收益分析
     */
    @PostMapping("/getIncomeAnalysis")
    R<Map<String, Object>> getIncomeAnalysis(@RequestBody ShopAnalysisDTO shopAnalysisDTO){
@@ -726,6 +755,30 @@
        return R.ok(shop.getId());
    }
    /**
     * 店铺余额列表
     */
    @GetMapping("/getBalanceList")
    @ApiOperation(value = "门店余额列表", tags = {"后台-财务统计-余额列表"})
    R<PageInfo<ShopBalanceListVO>> getBalanceList(@ApiParam("门店名称")@RequestParam(value = "name",required = false) String name,
                     @ApiParam("当前页")@RequestParam("pageCurr") Integer pageCurr,
                     @ApiParam("分页大小")@RequestParam("pageSize") Integer pageSize){
        PageInfo<ShopBalanceListVO> pageInfo=shopService.getBalanceList(name,pageCurr,pageSize);
        return R.ok(pageInfo);
    }
    /**
     * 导出店铺余额列表
     */
    @GetMapping("/shopBalanceExcel")
    @ApiOperation(value = "导出", tags = {"后台-财务统计-余额列表"})
    void shopBalanceExcel(HttpServletResponse response,@ApiParam("门店名称")@RequestParam(value = "name" ,required = false) String name){
        List<ShopBalanceExcel> exportList =shopMapper.shopBalanceExcel(name);
        ExcelUtil<ShopBalanceExcel> util = new ExcelUtil<ShopBalanceExcel>(ShopBalanceExcel.class);
        util.exportExcel(response, exportList, "店铺余额列表数据");
    }
}