| | |
| | | package com.ruoyi.other.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.common.core.utils.GeodesyUtil; |
| | | import com.ruoyi.common.core.utils.ServletUtils; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.other.api.domain.Phone; |
| | | import com.ruoyi.other.api.domain.Shop; |
| | | import com.ruoyi.other.api.domain.ShopScore; |
| | | import com.ruoyi.other.mapper.PhoneMapper; |
| | | import com.ruoyi.other.mapper.ShopMapper; |
| | | import com.ruoyi.other.mapper.ShopScoreMapper; |
| | | import com.ruoyi.other.service.ShopScoreService; |
| | | import com.ruoyi.other.service.ShopService; |
| | | import com.ruoyi.other.vo.NearbyShopVO; |
| | | import com.ruoyi.other.vo.SaveWithdrawalAccount; |
| | |
| | | @Resource |
| | | private ShopMapper shopMapper; |
| | | @Resource |
| | | private PhoneMapper phoneMapper; |
| | | @Resource |
| | | private ShopScoreService shopScoreService; |
| | | @Resource |
| | | private AppUserClient appUserClient; |
| | | @Resource |
| | | private TokenService tokenService; |
| | | @Resource |
| | | private SysUserClient sysUserClient; |
| | | @Resource |
| | | private ShopScoreMapper scoreMapper; |
| | | |
| | | |
| | | /** |
| | | * 获取门店列表 |
| | | * @param PageNum |
| | | * @param pageSize |
| | | * @param shop |
| | | * @return |
| | | */ |
| | | @Override |
| | | public IPage<Shop> getShopList(Integer PageNum, Integer pageSize, Shop shop) { |
| | | Page<Shop> page = new Page<>(); |
| | |
| | | return shopMapper.selectShopList(page, shop); |
| | | } |
| | | |
| | | @Override |
| | | public List<NearbyShopVO> nearbyShopList(BigDecimal longitude, BigDecimal latitude) { |
| | | String token = SecurityUtils.getToken(ServletUtils.getRequest()); |
| | | AppUser appUser = null; |
| | | if(StringUtils.isNotEmpty(token)){ |
| | | Long userid = tokenService.getLoginUserApplet().getUserid(); |
| | | appUser = appUserClient.getAppUserById(userid); |
| | | } |
| | | |
| | | List<NearbyShopVO> nearbyShopVOS = shopMapper.selectNearbyShopList(); |
| | | /** |
| | | * 获取最近的门店 |
| | | * @param longitude |
| | | * @param latitude |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<NearbyShopVO> nearbyShopList(BigDecimal longitude, BigDecimal latitude,Shop shop) { |
| | | //获取所有店 |
| | | List<NearbyShopVO> nearbyShopVOS = shopMapper.selectNearbyShopList(shop); |
| | | if (nearbyShopVOS == null || nearbyShopVOS.isEmpty()) { |
| | | return Collections.emptyList(); |
| | | } |
| | | //计算距离 |
| | | for (NearbyShopVO nearbyShopVO : nearbyShopVOS) { |
| | | Double wgs84 = GeodesyUtil.getDistance(nearbyShopVO.getLongitude() + "," + nearbyShopVO.getLatitude(), longitude + "," + latitude).get("WGS84"); |
| | | nearbyShopVO.setDistance(new BigDecimal(wgs84).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); |
| | | } |
| | | /*//排序 |
| | | nearbyShopVOS.sort(new Comparator<NearbyShopVO>() { |
| | | @Override |
| | | public int compare(NearbyShopVO o1, NearbyShopVO o2) { |
| | | return o1.getDistance().compareTo(o2.getDistance()); |
| | | } |
| | | }); |
| | | });*/ |
| | | |
| | | if(null != appUser && null != appUser.getShopId()){ |
| | | AppUser finalAppUser = appUser; |
| | | Optional<NearbyShopVO> first = nearbyShopVOS.stream().filter(s -> s.getId().equals(finalAppUser.getShopId().longValue())).findFirst(); |
| | | if(first.isPresent()){ |
| | | NearbyShopVO nearbyShopVO = first.get(); |
| | | if(null != nearbyShopVO){ |
| | | nearbyShopVOS.remove(nearbyShopVO); |
| | | } |
| | | } |
| | | |
| | | Shop shop = shopMapper.selectById(appUser.getShopId()); |
| | | if(null != shop && shop.getDelFlag() == 0 && shop.getStatus() == 1){ |
| | | NearbyShopVO vo = new NearbyShopVO(); |
| | | vo.setId(appUser.getShopId().longValue()); |
| | | vo.setName(shop.getName()); |
| | | vo.setAddress(shop.getAddress()); |
| | | vo.setHomePicture(shop.getHomePicture()); |
| | | Double wgs84 = GeodesyUtil.getDistance(longitude.toString() + "," + latitude.toString(), shop.getLongitude() + "," + shop.getLatitude()).get("WGS84"); |
| | | vo.setDistance(new BigDecimal(wgs84).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); |
| | | nearbyShopVOS.add(0, vo); |
| | | } |
| | | } |
| | | if (nearbyShopVOS == null || nearbyShopVOS.isEmpty()) { |
| | | return Collections.emptyList(); |
| | | } |
| | | return sortByDistance(nearbyShopVOS); |
| | | } |
| | | |
| | |
| | | if (shopDetailVO == null) { |
| | | throw new ServiceException("查询店铺不存在"); |
| | | } |
| | | //查询客服电话 |
| | | Phone phone = phoneMapper.selectOne(new LambdaQueryWrapper<Phone>().eq(Phone::getShopId, shopDetailVO.getId())); |
| | | ArrayList<String> phones = new ArrayList<>(); |
| | | if (phone != null) { |
| | | if (phone.getPhoneOne() != null) { |
| | | phones.add(phone.getPhoneOne()); |
| | | } |
| | | if (phone.getPhoneTwo() != null) { |
| | | phones.add(phone.getPhoneTwo()); |
| | | } |
| | | } |
| | | shopDetailVO.setPhones(phones); |
| | | |
| | | //我的评分 |
| | | if (userid != null){ |
| | | ShopScore one = shopScoreService.getOne(new LambdaQueryWrapper<ShopScore>().eq(ShopScore::getAppUserId, userid).eq(ShopScore::getShopId, shopId).last(" order by create_time desc limit 0, 1")); |
| | | shopDetailVO.setMyScore(null == one ? BigDecimal.ZERO : one.getScore()); |
| | | } |
| | | |
| | | // 计算距离 |
| | | if (shopDetailVO.getLongitude() != null && shopDetailVO.getLatitude() != null){ |
| | |
| | | } |
| | | return shopDetailVO; |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | public Boolean cheUserByPhone(String phone) { |
| | |
| | | this.updateById(shop); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |