puzhibing
2025-01-04 36f2f14ace300855a436f1ed9faf07049587a08f
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopController.java
@@ -11,11 +11,14 @@
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.vo.VerifiableShopVo;
import com.ruoyi.other.api.domain.Shop;
import com.ruoyi.other.api.domain.ShopScore;
import com.ruoyi.other.mapper.ShopMapper;
import com.ruoyi.other.service.ShopScoreService;
import com.ruoyi.other.service.ShopService;
import com.ruoyi.other.util.GeodesyUtil;
import com.ruoyi.other.util.tencentMap.TencentMapUtil;
import com.ruoyi.other.vo.NearbyShopVO;
import com.ruoyi.other.vo.ShopDetailVO;
import com.ruoyi.other.vo.ShopStatistics;
@@ -34,10 +37,7 @@
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
/**
@@ -95,6 +95,10 @@
        shop.setServerOrderNumber(0);
        shop.setCustomOrderNumber(0);
        shop.setAppUserId(appUser.getId());
        String city = TencentMapUtil.inverseGeographicalAnalysis(shop.getLongitude(), shop.getLatitude(), false);
        shop.setProvinceCode(city.substring(0, 2) + "0000");
        shop.setCityCode(city.substring(0, 4) + "00");
        shop.setDistrictCode(city);
        shopService.save(shop);
        AppUserShop appUserShop = new AppUserShop();
@@ -195,10 +199,13 @@
        if (!shopService.cheUserByPhone(phone)) {
            return R.fail("该手机号未注册");
        }
        String city = TencentMapUtil.inverseGeographicalAnalysis(shop.getLongitude(), shop.getLatitude(), false);
        shop.setProvinceCode(city.substring(0, 2) + "0000");
        shop.setCityCode(city.substring(0, 4) + "00");
        shop.setDistrictCode(city);
        Shop old_shop = shopService.getById(shop.getId());
        shopService.updateById(shop);
        //修改管理员
        if(!phone.equals(old_shop.getPhone())){
            AppUser appUser = appUserClient.getAppUserById(old_shop.getAppUserId());
            //需要先判断用户是否没有关联任何门店
            List<AppUserShop> userShops = appUserShopClient.getAppUserShop(appUser.getId()).getData();
@@ -259,7 +266,6 @@
                userShop.setShopId(shop.getId());
                userShop.setRoleType(1);
                userShopClient.saveUserShop(userShop);
            }
        }
        return R.ok();
    }
@@ -448,5 +454,55 @@
    public void updateShop(@RequestBody Shop shop){
        shopService.updateById(shop);
    }
    @ResponseBody
    @GetMapping("/getVerifiableShop")
    @ApiOperation(value = "获取可核销门店列表", tags = {"购物车-小程序"})
    public R<List<VerifiableShopVo>> getVerifiableShop(String longitude, String latitude){
        String city = TencentMapUtil.inverseGeographicalAnalysis(longitude, latitude, false);
        city = city.substring(0, 4) + "00";
        List<Shop> list = shopService.list(new LambdaQueryWrapper<Shop>().eq(Shop::getDelFlag, 0).eq(Shop::getCityCode, city));
        List<VerifiableShopVo> verifiableShopVoList = new ArrayList<>();
        for (Shop shop : list) {
            VerifiableShopVo vo = new VerifiableShopVo();
            vo.setId(shop.getId());
            vo.setName(shop.getName());
            Double wgs84 = GeodesyUtil.getDistance(longitude + "," + latitude, shop.getLongitude() + "," + shop.getLatitude()).get("WGS84");
            vo.setDistance(wgs84.longValue());
            verifiableShopVoList.add(vo);
        }
        verifiableShopVoList.sort(new Comparator<VerifiableShopVo>() {
            @Override
            public int compare(VerifiableShopVo o1, VerifiableShopVo o2) {
                return o1.getDistance().compareTo(o2.getDistance());
            }
        });
        return R.ok(verifiableShopVoList);
    }
    @ResponseBody
    @GetMapping("/getSysUserShop")
    @ApiOperation(value = "获取可切换的门店列表", tags = {"门店后台-首页"})
    public R<List<VerifiableShopVo>> getSysUserShop(){
        Long userid = tokenService.getLoginUser().getUserid();
        UserShop userShop = new UserShop();
        userShop.setUserId(userid);
        List<UserShop> data = userShopClient.getUserShop(userShop).getData();
        List<Integer> collect = data.stream().map(UserShop::getShopId).collect(Collectors.toList());
        List<Shop> shops = shopService.listByIds(collect);
        List<VerifiableShopVo> list = new ArrayList<>();
        for (Shop shop : shops) {
            VerifiableShopVo vo = new VerifiableShopVo();
            vo.setId(shop.getId());
            vo.setName(shop.getName());
            list.add(vo);
        }
        return R.ok(list);
    }
}