| | |
| | | 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; |
| | | |
| | | /** |
| | |
| | | public class GoodsController extends BaseController { |
| | | @Resource |
| | | private GoodsService goodsService; |
| | | @Resource |
| | | private SysConfigClient sysConfigClient; |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 添加商品 |
| | |
| | | @PostMapping("/addGoods") |
| | | @ApiOperation(value = "发布商品", tags = {"管理后台-商品管理"}) |
| | | public R<Void> addGoods(@RequestBody Goods goods) { |
| | | |
| | | 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.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); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | @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(); |
| | | } |
| | | |