From cbe3888bb6b1012273f16409f988114abd4542c5 Mon Sep 17 00:00:00 2001 From: lidongdong <1459917685@qq.com> Date: 星期三, 30 八月 2023 14:10:00 +0800 Subject: [PATCH] 新增小程序商家购买下单接口 小程序积分兑换记录列表修改 --- springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/VolunteerCreditsExchangeServiceImpl.java | 99 +++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 91 insertions(+), 8 deletions(-) diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/VolunteerCreditsExchangeServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/VolunteerCreditsExchangeServiceImpl.java index 2bd3c70..1348577 100644 --- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/VolunteerCreditsExchangeServiceImpl.java +++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/VolunteerCreditsExchangeServiceImpl.java @@ -6,19 +6,14 @@ import com.panzhihua.common.model.vos.R; import com.panzhihua.common.model.vos.community.VolunteerCreditsExchangeVO; import com.panzhihua.common.model.vos.community.VolunteerIntegralMerchantVO; -import com.panzhihua.common.model.vos.community.VolunteerTypeVO; import com.panzhihua.common.service.user.UserService; import com.panzhihua.common.utlis.Snowflake; import com.panzhihua.common.utlis.StringUtils; import com.panzhihua.service_community.dao.VolunteerCreditsExchangeDao; -import com.panzhihua.service_community.dao.VolunteerTypeDao; -import com.panzhihua.service_community.entity.VolunteerActivity; import com.panzhihua.service_community.entity.VolunteerCreditsExchange; import com.panzhihua.service_community.entity.VolunteerIntegralMerchant; -import com.panzhihua.service_community.entity.VolunteerType; import com.panzhihua.service_community.service.VolunteerCreditsExchangeService; import com.panzhihua.service_community.service.VolunteerIntegralMerchantService; -import com.panzhihua.service_community.service.VolunteerTypeService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -65,9 +60,30 @@ } VolunteerIntegralMerchant goods=goodsService.queryById(item.getGoodsId()); + + LoginUserInfoVO loginUserInfoVOR=userService.getUserInfoByUserId(item.getUserId()).getData(); + if(goods==null) { return R.fail("商品不存在"); + } + + int integral=0; + if(!StringUtils.isEmpty(loginUserInfoVOR.getLoveIntegral())) + { + integral=Integer.valueOf(loginUserInfoVOR.getLoveIntegral()); + } + + if(integral<Integer.valueOf(goods.getIntegral())) + { + return R.fail("剩余积分不足!无法下单兑换"); + } + + item.setNeedScore(goods.getIntegral()); + + if(StringUtils.isEmpty(item.getUserId())) + { + return R.fail("兑换用户id不能为空"); } if(StringUtils.isEmpty(goods.getGoodNum())) @@ -91,7 +107,52 @@ } + int num1=integral-Integer.valueOf(goods.getIntegral()); + loginUserInfoVOR.setLoveIntegral(num1+""); + userService.putUser(loginUserInfoVOR); + + item.setPalyIntegral(goods.getIntegral()); + //设置订单号 + item.setOrderNumber(Snowflake.getId()+""); + int num= baseMapper.insertData(item); + if(num>0) + { + return R.ok(); + } + return R.fail("操作失败"); + } + + @Override + public R insertMerchantData(VolunteerCreditsExchangeVO item) + { + if (item==null) + { + return R.fail("参数不能为空"); + } + + if(StringUtils.isEmpty(item.getGoodsId())) + { + return R.fail("商品id不能为空"); + } + + if(StringUtils.isEmpty(item.getMerchantId())) + { + return R.fail("商家id不能为空"); + } + + VolunteerIntegralMerchant goods=goodsService.queryById(item.getGoodsId()); + LoginUserInfoVO loginUserInfoVOR=userService.getUserInfoByUserId(item.getUserId()).getData(); + + if(goods==null) + { + return R.fail("商品不存在"); + } + + if(StringUtils.isEmpty(item.getPalyIntegral())) + { + return R.fail("支付积分不能为空"); + } int integral=0; if(!StringUtils.isEmpty(loginUserInfoVOR.getLoveIntegral())) @@ -99,9 +160,9 @@ integral=Integer.valueOf(loginUserInfoVOR.getLoveIntegral()); } - if(integral<Integer.valueOf(goods.getIntegral())) + if(integral<Integer.valueOf(item.getPalyIntegral())) { - return R.fail("剩余积分不足!无法下单兑换"); + return R.fail("剩余积分不足!无法支付"); } item.setNeedScore(goods.getIntegral()); @@ -111,10 +172,32 @@ return R.fail("兑换用户id不能为空"); } - int num1=integral-Integer.valueOf(goods.getIntegral()); + if(StringUtils.isEmpty(goods.getGoodNum())) + { + return R.fail("商品库存不足"); + } + else + { + int goodNum=Integer.valueOf(goods.getGoodNum()); + if(goodNum<=0) + { + return R.fail("商品库存不足"); + } + + goodNum--; + + VolunteerIntegralMerchantVO vo=new VolunteerIntegralMerchantVO(); + vo.setId(goods.getId()); + vo.setGoodNum(goodNum+""); + goodsService.updateById(vo); + } + + + int num1=integral-Integer.valueOf(item.getPalyIntegral()); loginUserInfoVOR.setLoveIntegral(num1+""); userService.putUser(loginUserInfoVOR); + item.setCondition("3"); //设置订单号 item.setOrderNumber(Snowflake.getId()+""); int num= baseMapper.insertData(item); -- Gitblit v1.7.1