From 5f25c762e2853e87fc4b86b157ba87cf1322df2f Mon Sep 17 00:00:00 2001 From: zhibing.pu <393733352@qq.com> Date: 星期六, 31 八月 2024 14:53:13 +0800 Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/mx_charging_pile --- ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TGoodsController.java | 95 ++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 85 insertions(+), 10 deletions(-) diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TGoodsController.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TGoodsController.java index 3e7d414..afb862e 100644 --- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TGoodsController.java +++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TGoodsController.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.ruoyi.account.api.dto.GrantCouponDto; import com.ruoyi.account.api.feignClient.AppCouponClient; import com.ruoyi.account.api.feignClient.AppUserClient; @@ -35,7 +36,9 @@ import javax.annotation.Resource; import javax.swing.*; import java.util.Arrays; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * <p> @@ -67,8 +70,17 @@ private WxPaymentClient wxPaymentClient; - - + /** + * 远程调用 根据商品名称查询商品ids + * @param name + * @return + */ + @PostMapping("/getGoodsIdsByName/{name}") + public R<List<Integer>> getGoodsIdsByName(@PathVariable("name")String name) { + List<Integer> collect = goodsService.list(new QueryWrapper<TGoods>() + .like("name", name)).stream().map(TGoods::getId).collect(Collectors.toList()); + return R.ok(collect); + } @PostMapping("/saveGoods") @ApiOperation(tags = {"管理后台-商品管理"},value = "商品添加") @@ -98,10 +110,25 @@ @GetMapping("/getInfo") - @ApiOperation(tags = {"管理后台-商品管理","小程序-兑换商城"},value = "商品查看详情") + @ApiOperation(tags = {"管理后台-商品管理"},value = "商品查看详情") public AjaxResult<TGoods> getInfo(Integer id) { - return AjaxResult.ok(goodsService.getById(id)); + TGoods byId = goodsService.getById(id); + return AjaxResult.ok(byId); } + + + @GetMapping("/getInfoByType") + @ApiOperation(tags = {"小程序-兑换商城"},value = "商品查看详情") + public AjaxResult getInfoByType(Integer goodType,Integer id) { + if (goodType==1){ + TGoods byId = goodsService.getById(id); + return AjaxResult.ok(byId);} + else { + TCoupon byId = couponService.getById(id); + return AjaxResult.ok(byId); + } + } + @@ -118,6 +145,40 @@ return AjaxResult.ok(goodsService.pageList1(appGoodQuery)); } + + + @ApiOperation(tags = {"小程序-兑换商城"},value = "积分兑换商品检查数量") + @PostMapping(value = "/app/shop/check") + public R check(@RequestBody ExchangeDto exchangeDto) { + //检查当前用户积分是否够 + Long userId = tokenService.getLoginUserApplet().getUserId(); + Integer point = 0; + + if (exchangeDto.getGoodType()==1) { + //查询当前商品信息 + TGoods good = goodsService.getById(exchangeDto.getGoodId()); + point = good.getRedeemPoints(); + //检查当前用户是否到达兑换上限 + Long count = orderClient.getExchangeById(exchangeDto.getGoodId(), userId,exchangeDto.getGoodType()).getData(); + if (good.getLimitExchangeTimes() != -1 && count >= good.getLimitExchangeTimes()) { + return R.fail("当前用户已兑换"+count+"张"); + } + TAppUser user = appUserClient.getUserById(userId).getData(); + if (user.getPoints()<good.getRedeemPoints()){ + return R.fail("当前用户积分不足"); + } + }else { + TCoupon coupon = couponService.getById(exchangeDto.getGoodId()); + point = coupon.getRedeemPoints(); + + Long count = orderClient.getExchangeById(exchangeDto.getGoodId(), userId,exchangeDto.getGoodType()).getData(); + if (coupon.getInventoryQuantity() != -1 && count >= coupon.getInventoryQuantity()) { + return R.fail("当前用户已到达兑换"+coupon+"次"); + } + } + return R.ok(); + + } @ApiOperation(tags = {"小程序-兑换商城"},value = "积分兑换商品") @PostMapping(value = "/app/shop") public AjaxResult<PageInfo<TGoods>> shop(@RequestBody ExchangeDto exchangeDto) { @@ -132,7 +193,7 @@ //检查当前用户是否到达兑换上限 Long count = orderClient.getExchangeById(exchangeDto.getGoodId(), userId,exchangeDto.getGoodType()).getData(); if (good.getLimitExchangeTimes() != -1 && count >= good.getLimitExchangeTimes()) { - return AjaxResult.error("当前用户已到达兑换上限"); + return AjaxResult.error("当前用户已兑换"+count+"张"); } TAppUser user = appUserClient.getUserById(userId).getData(); if (user.getPoints()<good.getRedeemPoints()){ @@ -144,10 +205,11 @@ Long count = orderClient.getExchangeById(exchangeDto.getGoodId(), userId,exchangeDto.getGoodType()).getData(); if (coupon.getInventoryQuantity() != -1 && count >= coupon.getInventoryQuantity()) { - return AjaxResult.error("当前用户已到达兑换上限"); + return AjaxResult.error("当前用户已到达兑换"+coupon+"次"); } } exchangeDto.setPoint(point); + exchangeDto.setUserId(userId); //生成积分兑换成功的订单 R<Long> longR = orderClient.exchangeCreate(exchangeDto); if (exchangeDto.getGoodType()==2) { @@ -165,7 +227,7 @@ pointChangeDto.setPoints(point); pointChangeDto.setRemark(longR.getData().toString()); pointChangeDto.setType(6); - appUserClient.change(pointChangeDto); + appUserClient.changeDown(pointChangeDto); return AjaxResult.success(); @@ -177,7 +239,7 @@ Long userId = tokenService.getLoginUserApplet().getUserId(); TAppUser user = appUserClient.getUserById(userId).getData(); boolean isVip = false; - if (user.getVipEndTime().isAfter(LocalDateTime.now())){ + if (user.getVipEndTime()!=null&&user.getVipEndTime().isAfter(LocalDateTime.now())){ isVip = true; } //计算价格 @@ -194,7 +256,7 @@ originalPrice = good.getVipPrice(); } } - orderPrice.add(originalPrice.multiply(BigDecimal.valueOf(exchangeDto.getNum()))); + orderPrice = orderPrice.add(originalPrice.multiply(BigDecimal.valueOf(exchangeDto.getNum()))); }else { TCoupon coupon = couponService.getById(exchangeDto.getGoodId()); BigDecimal originalPrice = coupon.getPaymentAmount(); @@ -204,7 +266,7 @@ originalPrice = coupon.getVipPaymentAmount(); } } - orderPrice.add(originalPrice); + orderPrice = orderPrice.add(originalPrice); } exchangeDto.setOrderPrice(orderPrice); @@ -224,6 +286,7 @@ exchangeDto.setPayPrice(payPrice); exchangeDto.setDiscountPrice(discountPrice); exchangeDto.setVipDiscount(vipDiscount); + exchangeDto.setUserId(userId); //创建订单 TShoppingOrder shopOrder = orderClient.shopCreate(exchangeDto).getData(); if (exchangeDto.getPayMethod()==1) { @@ -255,5 +318,17 @@ TGoods goods = goodsService.getById(id); return R.ok(goods); } + + + /** + * 修改商品 + * @param goods + * @return + */ + @PostMapping("/updateGoods") + public R updateGoods(@RequestBody TGoods goods){ + goodsService.updateById(goods); + return R.ok(); + } } -- Gitblit v1.7.1