From 9e8c542caf11c0b72639a8e323fa81fd3b4f594e Mon Sep 17 00:00:00 2001 From: huliguo <2023611923@qq.com> Date: 星期二, 01 四月 2025 19:00:09 +0800 Subject: [PATCH] 首页 --- ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopController.java | 76 +++++++++++++++++++++++++++++++++----- 1 files changed, 66 insertions(+), 10 deletions(-) diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopController.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopController.java index 02e4ffc..5b7826c 100644 --- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopController.java +++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopController.java @@ -17,13 +17,11 @@ import com.ruoyi.order.vo.VerifiableShopVo; import com.ruoyi.other.api.domain.*; 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 +68,8 @@ @Resource private ShopMapper shopMapper; @Resource + private ShopScoreMapper shopScoreMapper; + @Resource private UserShopClient userShopClient; @Resource private GoodsService goodsService; @@ -79,9 +79,61 @@ 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.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 = {"管理后台-门店管理"}) @@ -404,7 +456,7 @@ @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()) { record.setLaveUsePoint(record.getLavePoint()); @@ -459,16 +511,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, @@ -478,6 +533,7 @@ } + /** * 绑定门店 */ -- Gitblit v1.7.1