添加增加减少会员余额接口

This commit is contained in:
牛叉闪闪 2024-08-19 11:20:58 +08:00
parent 53fd7e24c0
commit 635625842a
3 changed files with 80 additions and 0 deletions

View File

@ -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<Object> midfiyAccount(Map<String,Object> map){
return null;
}
}

View File

@ -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<String, Object> queryShopUser(TbShopUserQueryCriteria criteria) {
IPage<ShopUserInfoVo> iPage = shopUserMapper.queryUser(criteria, criteria.getIsVip(),
@ -183,4 +191,66 @@ public class TbShopUserServiceImpl implements TbShopUserService {
}
FileUtil.downloadExcel(list, response);
}
@Override
public void modfiyAccount(Map<String, Object> 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);
}
}

View File

@ -89,4 +89,6 @@ public interface TbShopUserService {
void rechargeListDownload(HttpServletResponse response, TbShopRechargeListDto criteria) throws IOException;
void modfiyAccount(Map<String,Object> map);
}