|
|
@ -12,6 +12,7 @@ import com.example.demo.mapper.coin.RoleMapper; |
|
|
import com.example.demo.mapper.coin.UserMapper; |
|
|
import com.example.demo.mapper.coin.UserMapper; |
|
|
import com.example.demo.mapper.live.LiveMapper; |
|
|
import com.example.demo.mapper.live.LiveMapper; |
|
|
import com.example.demo.service.bean.BeanConsumeService; |
|
|
import com.example.demo.service.bean.BeanConsumeService; |
|
|
|
|
|
import com.example.demo.service.bean.BeanUserService; |
|
|
import com.github.pagehelper.PageHelper; |
|
|
import com.github.pagehelper.PageHelper; |
|
|
import com.github.pagehelper.PageInfo; |
|
|
import com.github.pagehelper.PageInfo; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
@ -157,37 +158,33 @@ public class BeanConsumeServiceImpl implements BeanConsumeService { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public Result reduceBeanDC(BeanConsume consume) { |
|
|
public Result reduceBeanDC(BeanConsume consume) { |
|
|
|
|
|
|
|
|
// 验证精网号是否有效 |
|
|
// 验证精网号是否有效 |
|
|
if (consume.getJwcode() == null || consume.getJwcode().isEmpty()) { |
|
|
if (consume.getJwcode() == null || consume.getJwcode().isEmpty()) { |
|
|
return Result.error("精网号不能为空"); |
|
|
return Result.error("精网号不能为空"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 验证免费豆和永久豆是否为非负数 |
|
|
|
|
|
if (consume.getFreeBean() < 0 || consume.getPermanentBean() < 0) { |
|
|
|
|
|
return Result.error("免费豆和永久豆不能为负数"); |
|
|
|
|
|
} |
|
|
|
|
|
// 验证免费豆和永久豆是否为非负数 |
|
|
|
|
|
if (consume.getFreeBean() > 999999 || consume.getPermanentBean() > 999999) { |
|
|
|
|
|
return Result.error("免费豆和永久豆不能超过999999"); |
|
|
|
|
|
} |
|
|
|
|
|
// 验证免费豆和永久豆是否均为0 |
|
|
|
|
|
if (consume.getFreeBean() == 0 && consume.getPermanentBean() == 0) { |
|
|
|
|
|
return Result.error("免费豆和永久豆不能同时为0"); |
|
|
|
|
|
} |
|
|
|
|
|
//获取用户当前余额 |
|
|
//获取用户当前余额 |
|
|
BeanUserCard user= beanUserMapper.userCard(consume.getJwcode()); |
|
|
|
|
|
if (user.getFreeBean() < consume.getFreeBean()) { |
|
|
|
|
|
return Result.error("用户免费金豆余额不足"); |
|
|
|
|
|
} |
|
|
|
|
|
if (user.getPermanentBean() < consume.getPermanentBean()) { |
|
|
|
|
|
return Result.error("用户永久金豆余额不足"); |
|
|
|
|
|
|
|
|
BeanUserCard user = beanUserMapper.userCard(consume.getJwcode()); |
|
|
|
|
|
|
|
|
|
|
|
// 计算需要扣除的总金豆数量 |
|
|
|
|
|
int totalConsume = consume.getPermanentBean(); |
|
|
|
|
|
|
|
|
|
|
|
// 检查用户金豆余额是否足够 |
|
|
|
|
|
if (user.getFreeBean() + user.getPermanentBean() < totalConsume) { |
|
|
|
|
|
return Result.error("用户金豆余额不足"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 先扣免费金豆,再扣永久金豆 |
|
|
|
|
|
int freeBeanConsume = Math.min(totalConsume, user.getFreeBean()); |
|
|
|
|
|
int permanentBeanConsume = totalConsume - freeBeanConsume; |
|
|
|
|
|
|
|
|
|
|
|
// 将计算后的值赋给consume对象 |
|
|
|
|
|
consume.setFreeBean(freeBeanConsume); |
|
|
|
|
|
consume.setPermanentBean(permanentBeanConsume); |
|
|
|
|
|
|
|
|
String jwcode = consume.getJwcode(); |
|
|
String jwcode = consume.getJwcode(); |
|
|
//String jwcode = "1bf7194c2dc63c45cd834d35e38faa71"; |
|
|
|
|
|
try { |
|
|
try { |
|
|
BaseDES2 d = new BaseDES2(); |
|
|
BaseDES2 d = new BaseDES2(); |
|
|
jwcode = d.encrypt(jwcode); |
|
|
jwcode = d.encrypt(jwcode); |
|
|
|