huliguo
2025-04-09 91e9c006a2ce431a5916b137974bd004622eb9fa
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopController.java
@@ -16,14 +16,13 @@
import com.ruoyi.order.vo.OrderSaleNum;
import com.ruoyi.order.vo.VerifiableShopVo;
import com.ruoyi.other.api.domain.*;
import com.ruoyi.other.enums.PhoneType;
import com.ruoyi.other.mapper.ShopMapper;
import com.ruoyi.other.mapper.ShopScoreMapper;
import com.ruoyi.other.service.*;
import com.ruoyi.other.util.GeodesyUtil;
import com.ruoyi.other.util.tencentMap.TencentMapUtil;
import com.ruoyi.other.vo.NearbyShopVO;
import com.ruoyi.other.vo.SaveWithdrawalAccount;
import com.ruoyi.other.vo.ShopDetailVO;
import com.ruoyi.other.vo.ShopStatistics;
import com.ruoyi.other.vo.*;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.feignClient.SysUserClient;
import com.ruoyi.system.api.feignClient.UserShopClient;
@@ -70,6 +69,8 @@
    @Resource
    private ShopMapper shopMapper;
    @Resource
    private ShopScoreMapper shopScoreMapper;
    @Resource
    private UserShopClient userShopClient;
    @Resource
    private GoodsService goodsService;
@@ -79,9 +80,65 @@
    private OrderClient orderClient;
    @Resource
    private ReceiverBankChannelService receiverBankChannelService;
    @Resource
    private ShopScoreService shopScoreService;
    /**
     * 门店打分
     * @return
     */
    @PostMapping("/shopScore")
    @ApiOperation(value = "门店打分", tags = {"小程序-个人中心"})
    public R<Void> shopScore(@RequestBody ShopScore shopScore) {
        if (null==shopScore.getShopId()){
            return R.fail("门店不能为空");
        }
        if (null==shopScore.getScore()){
            return R.fail("评分不能为空");
        }
        //验证门店是否存在
        Shop one = shopService.getOne(new LambdaQueryWrapper<Shop>().eq(Shop::getId, shopScore.getShopId()).eq(Shop::getStatus, 1).eq(Shop::getDelFlag, 0));
        if (null == one){
            return R.fail("门店不存在");
        }
        LoginUser loginUserApplet = tokenService.getLoginUserApplet();
        shopScore.setAppUserId(loginUserApplet.getUserid());
        ShopScore one1 = shopScoreService.getOne(new LambdaQueryWrapper<ShopScore>().eq(ShopScore::getAppUserId, loginUserApplet.getUserid()));
        if (null!=one1){
            return  R.fail("不能重复评分");
        }
        shopScore.setCreateTime(LocalDateTime.now());
        shopScoreService.save(shopScore);
        //计算,更新到门店中
        //总评分
        List<BigDecimal> scores = shopScoreMapper.selectList(new LambdaQueryWrapper<ShopScore>().eq(ShopScore::getShopId, shopScore.getShopId())).stream().map(ShopScore::getScore).collect(Collectors.toList());
        BigDecimal score = getScore(scores);
        one.setId(shopScore.getShopId().intValue());
        one.setScore(score.doubleValue());
        shopMapper.updateById(one);
        return R.ok();
    }
    /**
     * 计算评分
     */
    private BigDecimal getScore(List<BigDecimal> scores) {
        if (scores == null || scores.isEmpty()) {
            return BigDecimal.ZERO.setScale(1, RoundingMode.HALF_UP); // 默认返回 0.0
        }
        // 计算总分
        BigDecimal totalScore = scores.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
        // 计算平均值,并保留 1 位小数(四舍五入)
        BigDecimal averageScore = totalScore.divide(
                new BigDecimal(scores.size()),
                1,  // 保留 1 位小数
                RoundingMode.HALF_UP  // 四舍五入
        );
        return averageScore;
    }
    @PostMapping
    @ApiOperation(value = "新增门店", tags = {"管理后台-门店管理"})
@@ -92,7 +149,7 @@
        if (appUser == null){
            return R.fail("该手机号未注册");
        }
        shop.setShopAllPoint(0);
     /*   shop.setShopAllPoint(0);
        shop.setLowerLevelSharePoint(0);
        shop.setSharePoint(0);
        shop.setServerPoint(0);
@@ -100,12 +157,12 @@
        shop.setGiveawayAllMoney(BigDecimal.ZERO);
        shop.setGiveawayMoney(BigDecimal.ZERO);
        shop.setLowerLevelGiveawayMoney(BigDecimal.ZERO);
        shop.setServerGiveawayMoney(BigDecimal.ZERO);
        shop.setServerGiveawayMoney(BigDecimal.ZERO);*/
        shop.setCanWithdrawMoney(BigDecimal.ZERO);
        shop.setWithdrawMoney(BigDecimal.ZERO);
        shop.setOrderNumber(0);
        shop.setServerOrderNumber(0);
        shop.setCustomOrderNumber(0);
      /*  shop.setServerOrderNumber(0);
        shop.setCustomOrderNumber(0);*/
        shop.setAppUserId(appUser.getId());
        String city = TencentMapUtil.inverseGeographicalAnalysis(shop.getLongitude(), shop.getLatitude(), false);
        if(!StringUtils.hasLength(city)){
@@ -201,7 +258,7 @@
    @DeleteMapping("/deleteShop")
    @ApiOperation(value = "删除门店", tags = {"管理后台-门店管理"})
    public R<Void> deleteShop(@ApiParam("门店id") @RequestParam("id") Integer id){
        List<Goods> list1 = goodsService.list(new LambdaQueryWrapper<Goods>().eq(Goods::getDelFlag, 0).eq(Goods::getAppointStore, 1).eq(Goods::getStatus, 2));
        /*List<Goods> list1 = goodsService.list(new LambdaQueryWrapper<Goods>().eq(Goods::getDelFlag, 0).eq(Goods::getAppointStore, 1).eq(Goods::getStatus, 2));
        if(list1.size() > 0){
            Set<Integer> collect1 = list1.stream().map(Goods::getId).collect(Collectors.toSet());
            long count = goodsShopService.count(new LambdaQueryWrapper<GoodsShop>().eq(GoodsShop::getShopId, id).in(GoodsShop::getGoodsId, collect1));
@@ -228,7 +285,7 @@
        if(data.size() > 0){
            //删除门店后台账号和关系数据
            sysUserClient.delShopUser(shop.getId(), 2);
        }
        }*/
        return R.ok();
    }
@@ -404,11 +461,11 @@
    @GetMapping("/list")
    @ApiOperation(value = "门店列表", tags = {"管理后台-门店管理"})
    public R<IPage<Shop>> list(@ApiParam("页码") @RequestParam Integer pageNum,@ApiParam("每一页数据大小") Integer pageSize,Shop shop){
    public R<IPage<Shop>> list(@ApiParam("页码") @RequestParam("pageNum") Integer pageNum,@ApiParam("每一页数据大小") @RequestParam("pageSize") Integer pageSize,Shop shop){
        IPage<Shop> shopIPage = shopService.getShopList(pageNum, pageSize, shop);
        for (Shop record : shopIPage.getRecords()) {
        /*for (Shop record : shopIPage.getRecords()) {
            record.setLaveUsePoint(record.getLavePoint());
        }
        }*/
        return R.ok(shopIPage);
    }
@@ -459,16 +516,19 @@
    /**
     * 附近门店列表
     * 附近门店列表/更多门店
     */
    @GetMapping("/nearbyShopList")
    @ApiOperation(value = "附近门店列表", tags = {"小程序-首页"})
    @ApiOperation(value = "附近门店列表/更多门店", tags = {"小程序-首页"})
    public R<List<NearbyShopVO>> nearbyShopList(@ApiParam("经度") @RequestParam BigDecimal longitude,
                                                @ApiParam("纬度") @RequestParam BigDecimal latitude) {
        return R.ok(shopService.nearbyShopList(longitude, latitude));
                                                @ApiParam("纬度") @RequestParam BigDecimal latitude,
                                                Shop shop) {
        return R.ok(shopService.nearbyShopList(longitude, latitude,shop));
    }
    /**
     * 门店详情
     */
    @GetMapping("/shopDetail")
    @ApiOperation(value = "门店详情", tags = {"小程序-首页"})
    public R<ShopDetailVO> shopDetail(@ApiParam("门店id") @RequestParam Integer shopId,
@@ -476,6 +536,9 @@
                                      @ApiParam("纬度") @RequestParam BigDecimal latitude) {
        return R.ok(shopService.getShopDetail(shopId, longitude, latitude));
    }
    /**
@@ -599,7 +662,7 @@
    @GetMapping("/getVerifiableShop")
    @ApiOperation(value = "获取可核销门店列表", tags = {"购物车-小程序"})
    public R<List<VerifiableShopVo>> getVerifiableShop(String longitude, String latitude, Integer goodsId){
        String city = TencentMapUtil.inverseGeographicalAnalysis(longitude, latitude, false);
       /* String city = TencentMapUtil.inverseGeographicalAnalysis(longitude, latitude, false);
        if(null == city){
            city = "510100";
        }
@@ -633,7 +696,8 @@
                return o1.getDistance().compareTo(o2.getDistance());
            }
        });
        return R.ok(verifiableShopVoList);
        return R.ok(verifiableShopVoList);*/
        return null;
    }
@@ -744,76 +808,17 @@
        List<Shop> shopList = shopService.list(queryWrapper);
        BigDecimal serverGiveawayMoney = BigDecimal.ZERO;
        BigDecimal giveawayMoney = BigDecimal.ZERO;
        for (Shop shop : shopList) {
       /* for (Shop shop : shopList) {
            serverGiveawayMoney = serverGiveawayMoney.add(shop.getServerGiveawayMoney());
            giveawayMoney = giveawayMoney.add(shop.getGiveawayMoney().add(shop.getLowerLevelGiveawayMoney()));
        }
        }*/
        Map<String, BigDecimal> map = new HashMap<>();
        map.put("serverGiveawayMoney", serverGiveawayMoney);
        map.put("giveawayMoney", giveawayMoney);
        return R.ok(map);
    }
    /**
     * 获取指定用户的服务商
     * @return
     */
    @GetMapping("/getServiceProvider")
    public R<Shop> getServiceProvider(@RequestParam("appUserId") Long appUserId){
        //向上找获取第一个开店的门店
        List<Shop> list = shopService.list(new LambdaQueryWrapper<Shop>().eq(Shop::getDelFlag, 0).eq(Shop::getStatus, 1));
        AppUser appUser = appUserClient.getAppUserById(appUserId);
        //上级集合,防止循环关联
        Set<Long> pid = new HashSet<>();
        Shop shop = getSuperiorStore(appUser, list, 1, 1, pid);
        return R.ok(shop);
    }
    public Shop getSuperiorStore(AppUser appUser, List<Shop> list, Integer hierarchy, Integer num, Set<Long> pid){
        if(null == appUser.getInviteUserId()){
            return null;
        }
        if(pid.contains(appUser.getInviteUserId())){
            return null;
        }
        AppUser appUser1 = appUserClient.getAppUserById(appUser.getInviteUserId());
        if(null != appUser1){
            Optional<Shop> first = list.stream().filter(shop -> shop.getAppUserId().equals(appUser1.getId())).findFirst();
            if(first.isPresent()){
                if(hierarchy.equals(num)){
                    return first.get();
                }
                num++;
            }
        }
        return getSuperiorStore(appUser1, list, hierarchy, num, pid);
    }
    /**
     * 获取指定用户的高级服务商
     * @return
     */
    @GetMapping("/getSuperiorServiceProvider")
    public R<Shop> getSuperiorServiceProvider(@RequestParam("appUserId") Long appUserId){
        //向上找获取第一个开店的门店
        List<Shop> list = shopService.list(new LambdaQueryWrapper<Shop>().eq(Shop::getDelFlag, 0).eq(Shop::getStatus, 1));
        AppUser appUser = appUserClient.getAppUserById(appUserId);
        //上级集合,防止循环关联
        Set<Long> pid = new HashSet<>();
        Shop shop = getSuperiorStore(appUser, list, 2, 1, pid);
        return R.ok(shop);
    }
}