From 635625842ac5b3c67d422e0106c2adeaaf5697ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E5=8F=89=E9=97=AA=E9=97=AA?= <18322780655@163.com> Date: Mon, 19 Aug 2024 11:20:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=A2=9E=E5=8A=A0=E5=87=8F?= =?UTF-8?q?=E5=B0=91=E4=BC=9A=E5=91=98=E4=BD=99=E9=A2=9D=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/shop/TbShopUserController.java | 8 +++ .../impl/shopimpl/TbShopUserServiceImpl.java | 70 +++++++++++++++++++ .../service/shop/TbShopUserService.java | 2 + 3 files changed, 80 insertions(+) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopUserController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopUserController.java index 0dbe5f8b..e5df29ca 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopUserController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopUserController.java @@ -21,6 +21,7 @@ import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.util.Map; /** * @author lyf @@ -96,4 +97,11 @@ public class TbShopUserController { public void rechargeListDownload(HttpServletResponse response, @RequestBody TbShopRechargeListDto criteria) throws IOException { tbShopUserService.rechargeListDownload(response, criteria); } + + + @PostMapping("midfiyAccount") + @ApiOperation("增加扣减会员余额") + public ResponseEntity midfiyAccount(Map map){ + return null; + } } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopUserServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopUserServiceImpl.java index c1c1d916..f0dfc99a 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopUserServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopUserServiceImpl.java @@ -1,12 +1,15 @@ package cn.ysk.cashier.service.impl.shopimpl; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.ysk.cashier.dto.shop.TbShopRechargeListDto; import cn.ysk.cashier.dto.shop.TbShopRechargeRespDto; import cn.ysk.cashier.dto.shop.TbShopUserDto; import cn.ysk.cashier.dto.shop.TbShopUserQueryCriteria; +import cn.ysk.cashier.exception.BadRequestException; import cn.ysk.cashier.mapper.shop.TbShopUserMapper; +import cn.ysk.cashier.mybatis.entity.TbShopUserFlow; import cn.ysk.cashier.mybatis.mapper.ShopUserMapper; import cn.ysk.cashier.mybatis.mapper.TbShopUserFlowMapper; import cn.ysk.cashier.pojo.shop.TbShopUser; @@ -31,6 +34,7 @@ import java.io.IOException; import java.math.BigDecimal; import java.time.Instant; import java.util.*; +import java.util.regex.Pattern; /** * @author lyf @@ -50,6 +54,10 @@ public class TbShopUserServiceImpl implements TbShopUserService { @Autowired private ShopUserMapper shopUserMapper; + @Autowired + private TbShopUserFlowMapper tbShopUserFlowMapper; + + @Override public Map queryShopUser(TbShopUserQueryCriteria criteria) { IPage iPage = shopUserMapper.queryUser(criteria, criteria.getIsVip(), @@ -183,4 +191,66 @@ public class TbShopUserServiceImpl implements TbShopUserService { } FileUtil.downloadExcel(list, response); } + + @Override + public void modfiyAccount(Map map) { + if(ObjectUtil.isNull(map)||ObjectUtil.isEmpty(map)||!map.containsKey("id")||!map.containsKey("type")||!map.containsKey("amount") + ||ObjectUtil.isEmpty(map.get("id"))||ObjectUtil.isNull(map.get("id"))||ObjectUtil.isNull(map.get("type"))||ObjectUtil.isEmpty(map.get("type")) + ||ObjectUtil.isEmpty(map.get("amount"))||ObjectUtil.isNull(map.get("amount")) + + ){ + throw new BadRequestException("参数错误"); + + } + + String regex = "^(([1-9][0-9]*)|(([0]\\.\\d{1,2}|[1-9][0-9]*\\.\\d{1,2})))$"; + if(!map.get("amount").toString().matches(regex)){ + throw new BadRequestException("请输入正确的数字"); + } + + + + TbShopUser tbShopUser= tbShopUserRepository.getById(Integer.valueOf(map.get("id")+"")); + if(ObjectUtil.isNull(tbShopUser)){ + throw new BadRequestException("不存在的会员信息"); + } + + BigDecimal amount=new BigDecimal(map.get("amount").toString()); + if(amount.compareTo(tbShopUser.getAmount())>0){ + throw new BadRequestException("账户余额不足,请输入正确的金额"); + } + + String type=map.get("type").toString(); + TbShopUserFlow flow=new TbShopUserFlow(); + + if("in".equals(type)){ + flow.setType("+"); + flow.setBizName("充值退款"); + flow.setBizCode("manualIn"); + tbShopUser.setAmount(tbShopUser.getAmount().add(amount)); + }else if("out".equals(type)){ + flow.setBizCode("manualOut"); + flow.setBizName("消费"); + flow.setType("-"); + tbShopUser.setAmount(tbShopUser.getAmount().subtract(amount)); + }else { + throw new BadRequestException("错误的请求类型"); + } + + tbShopUser.setUpdatedAt(System.currentTimeMillis()); + tbShopUserRepository.save(tbShopUser); + + + flow.setShopUserId(tbShopUser.getId()); + flow.setAmount(amount); + flow.setBalance(tbShopUser.getAmount()); + flow.setCreateTime(new Date()); + + tbShopUserFlowMapper.insert(flow); + + + + + } + } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/TbShopUserService.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/TbShopUserService.java index ad4c884b..608242c3 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/TbShopUserService.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/TbShopUserService.java @@ -89,4 +89,6 @@ public interface TbShopUserService { void rechargeListDownload(HttpServletResponse response, TbShopRechargeListDto criteria) throws IOException; + void modfiyAccount(Map map); + }