|
|
@ -156,6 +156,85 @@ public class BeanConsumeServiceImpl implements BeanConsumeService { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public Result reduceBeanDC(BeanConsume consume) { |
|
|
|
|
|
|
|
|
|
|
|
// 验证精网号是否有效 |
|
|
|
|
|
if (consume.getJwcode() == null || consume.getJwcode().isEmpty()) { |
|
|
|
|
|
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("用户永久金豆余额不足"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String jwcode = consume.getJwcode(); |
|
|
|
|
|
//String jwcode = "1bf7194c2dc63c45cd834d35e38faa71"; |
|
|
|
|
|
try { |
|
|
|
|
|
BaseDES2 d = new BaseDES2(); |
|
|
|
|
|
jwcode = d.encrypt(jwcode); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
return Result.error("加密失败"); |
|
|
|
|
|
} |
|
|
|
|
|
String content = consume.getRemark(); // 备注作为content参数 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 2. 创建请求参数对象(使用Map或自定义实体类) |
|
|
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
|
|
params.put("jwcode", jwcode); |
|
|
|
|
|
int total = consume.getPermanentBean() + consume.getFreeBean(); |
|
|
|
|
|
params.put("total", String.valueOf(total)); |
|
|
|
|
|
params.put("buy", consume.getPermanentBean().toString()); |
|
|
|
|
|
params.put("free", consume.getFreeBean().toString()); |
|
|
|
|
|
params.put("content", content); |
|
|
|
|
|
|
|
|
|
|
|
// 3. 构建请求头,指定Content-Type为JSON |
|
|
|
|
|
HttpHeaders headers = new HttpHeaders(); |
|
|
|
|
|
headers.setContentType(MediaType.APPLICATION_JSON); // 关键:设置为JSON格式 |
|
|
|
|
|
|
|
|
|
|
|
// 4. 构建请求实体(参数+头信息) |
|
|
|
|
|
HttpEntity<Map<String, String>> requestEntity = new HttpEntity<>(params, headers); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
// 5. 发送POST请求 |
|
|
|
|
|
ResponseEntity<String> response = restTemplate.postForEntity( |
|
|
|
|
|
apiUrl, |
|
|
|
|
|
requestEntity, |
|
|
|
|
|
String.class |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
System.out.println("请求参数:" + params); |
|
|
|
|
|
System.out.println("响应状态码:" + response.getStatusCodeValue()); |
|
|
|
|
|
System.out.println("响应内容:" + response.getBody()); |
|
|
|
|
|
|
|
|
|
|
|
if (!response.getStatusCode().is2xxSuccessful()) { |
|
|
|
|
|
return Result.error("远程接口接口调用失败,状态码:" + response.getStatusCodeValue() + ",响应:" + response.getBody()); |
|
|
|
|
|
} |
|
|
|
|
|
return Result.success(response.getBody()); |
|
|
|
|
|
} catch (RestClientException e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
return Result.error("请求发送失败:" + e.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
//筛选查询直播消费 |
|
|
//筛选查询直播消费 |
|
|
@Override |
|
|
@Override |
|
|
public Object selectLiveBy(Integer pageNum, Integer pageSize, BeanConsumeLive beanConsumeLive) { |
|
|
public Object selectLiveBy(Integer pageNum, Integer pageSize, BeanConsumeLive beanConsumeLive) { |
|
|
|