From 34f741f39e22bf48df33321230380b40c23110c3 Mon Sep 17 00:00:00 2001 From: huliguo <2023611923@qq.com> Date: 星期五, 18 四月 2025 21:34:13 +0800 Subject: [PATCH] 店铺、积分、订单 --- ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/GoodsController.java | 68 +++++++++++++++++++++++++++------ 1 files changed, 55 insertions(+), 13 deletions(-) diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/GoodsController.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/GoodsController.java index 7c85c9e..6232702 100644 --- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/GoodsController.java +++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/GoodsController.java @@ -6,17 +6,23 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.web.controller.BaseController; import com.ruoyi.common.core.web.page.PageInfo; import com.ruoyi.common.redis.annotation.DistributedLock; import com.ruoyi.other.api.domain.Goods; import com.ruoyi.other.dto.AddGoodsDTO; +import com.ruoyi.other.enums.GoodsStatus; import com.ruoyi.other.service.GoodsService; import com.ruoyi.other.vo.GoodsVO; +import com.ruoyi.system.api.domain.SysConfig; +import com.ruoyi.system.api.feignClient.SysConfigClient; import io.swagger.annotations.*; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.math.BigDecimal; +import java.time.LocalDateTime; import java.util.List; /** @@ -33,6 +39,8 @@ public class GoodsController extends BaseController { @Resource private GoodsService goodsService; + @Resource + private SysConfigClient sysConfigClient; @@ -44,11 +52,50 @@ @PostMapping("/addGoods") @ApiOperation(value = "发布商品", tags = {"管理后台-商品管理"}) public R<Void> addGoods(@RequestBody Goods goods) { - /* if(goods.getPurchaseLimit()==null){ + + if(goods.getPurchaseLimit()==null){ goods.setPurchaseLimit(-1); } - goodsService.addGoods(goods);*/ + goods.setSaleNum(0); + goods.setStatus(GoodsStatus.DOWN.getCode()); + goods.setIntegral(getPoint(goods.getSellingPrice())); + goods.setDelFlag(0); + goods.setCreateTime(LocalDateTime.now()); + goodsService.addGoods(goods); return R.ok(); + } + /** + * 获取现金对应积分 + */ + public Integer getPoint(BigDecimal cash){ + if (cash == null || cash.compareTo(BigDecimal.ZERO) < 0) { + throw new IllegalArgumentException("金额不能为null或负数"); + } + // 获取积分兑换比例配置 + R<SysConfig> info = sysConfigClient.getInfo(6L); + if (info == null || info.getData() == null) { + throw new RuntimeException("获取积分兑换比例配置失败"); + } + String configValue = info.getData().getConfigValue(); + if (StringUtils.isBlank(configValue)) { + throw new RuntimeException("积分兑换比例配置值为空"); + } + try { + // 使用BigDecimal处理比例,避免精度问题 + BigDecimal ratio = new BigDecimal(configValue.trim()); + if (ratio.compareTo(BigDecimal.ZERO) <= 0) { + throw new RuntimeException("积分兑换比例必须大于0"); + } + + // 计算积分并四舍五入取整 + return cash.multiply(ratio).intValue(); + + } catch (NumberFormatException e) { + throw new RuntimeException("积分兑换比例配置值格式错误", e); + } catch (ArithmeticException e) { + throw new RuntimeException("积分计算结果溢出", e); + } + } /** @@ -90,20 +137,15 @@ @PutMapping("/manageGoodsUpdate") @ApiOperation(value = "商品修改", tags = {"管理后台-商品管理"}) public R<Void> manageGoodsUpdate(@RequestBody Goods goods){ - /* if(goods.getPurchaseLimit()==null){ + if(goods.getPurchaseLimit()==null){ goods.setPurchaseLimit(-1); } + goods.setSaleNum(0); + goods.setStatus(GoodsStatus.DOWN.getCode()); + goods.setIntegral(getPoint(goods.getSellingPrice())); + goods.setDelFlag(0); + goods.setCreateTime(LocalDateTime.now()); goodsService.updateManageGoods(goods); - if (goods.getType()==2){ - goods.setAppointStore(2); - goodsService.updateById(goods); - } - if (goods.getType()==1){ - LambdaUpdateWrapper<Goods> goodsLambdaUpdateWrapper = new LambdaUpdateWrapper<>(); - goodsLambdaUpdateWrapper.set(Goods::getDistributionMode,null); - goodsLambdaUpdateWrapper.eq(Goods::getId, goods.getId()); - goodsService.update(goodsLambdaUpdateWrapper); - }*/ return R.ok(); } -- Gitblit v1.7.1