You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
180 lines
7.0 KiB
180 lines
7.0 KiB
package com.example.demo.controller;
|
|
|
|
|
|
import com.example.demo.domain.entity.Audit;
|
|
import com.example.demo.domain.entity.Detail;
|
|
import com.example.demo.domain.entity.DetailY;
|
|
import com.example.demo.domain.entity.User;
|
|
import com.example.demo.domain.vo.Page;
|
|
import com.example.demo.domain.vo.Result;
|
|
import com.example.demo.mapper.DetailMapper;
|
|
import com.example.demo.mapper.RefundMapper;
|
|
import com.example.demo.mapper.UserMapper;
|
|
import com.example.demo.sevice.AuditService;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.util.ObjectUtils;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.time.LocalDate;
|
|
import java.time.Month;
|
|
import java.util.Arrays;
|
|
|
|
import static com.example.demo.Util.JWTUtil.getUserDetails;
|
|
|
|
@RestController
|
|
@RequestMapping("/audit/audit")
|
|
@RequiredArgsConstructor
|
|
@Slf4j
|
|
@Transactional
|
|
@CrossOrigin
|
|
public class AuditController {
|
|
@Autowired
|
|
private RefundMapper refundMapper;
|
|
@Autowired
|
|
private UserMapper userMapper;
|
|
@Autowired
|
|
private DetailMapper detailMapper;
|
|
private final AuditService auditService;
|
|
@PostMapping("/add")
|
|
public Result add(@RequestBody Audit audit){
|
|
try {
|
|
auditService.add(audit);
|
|
return Result.success();
|
|
}catch (Exception e){
|
|
log.warn(Arrays.toString(e.getStackTrace()));
|
|
return Result.error(e.getMessage());
|
|
}
|
|
}
|
|
|
|
@PostMapping("/goldedit")
|
|
public Result goldedit(@RequestBody Audit audit) throws Exception {
|
|
auditService.goldedit(audit);
|
|
return Result.success();
|
|
}
|
|
|
|
@PostMapping("/edit")
|
|
public Result edit(@RequestBody Audit audit){
|
|
|
|
//先执行auditService.edit(audit);
|
|
//然后创建一个类,去接收这个audit,如果status=1
|
|
//根据退款ID找到detail表中的记录获取到他的三种金币
|
|
//把金币加到user表中对应的金币中
|
|
|
|
auditService.edit(audit);
|
|
|
|
//退款通过
|
|
if(audit.getStatus() == 1 && audit.getRefundId()!=null){
|
|
Detail detail = detailMapper.selectByDetailId(audit.getRefundId());
|
|
BigDecimal rechargeCoin = detail.getRechargeCoin();
|
|
BigDecimal taskCoin = detail.getTaskCoin();
|
|
BigDecimal freeCoin = detail.getFreeCoin();
|
|
|
|
User user = userMapper.selectByJwcode(detail.getJwcode());
|
|
user.setBuyJb(user.getBuyJb().add(rechargeCoin));
|
|
user.setCoreJb(user.getCoreJb().add(taskCoin));
|
|
User user1 = userMapper.selectByJwcode1(detail.getJwcode());
|
|
LocalDate now = LocalDate.now();
|
|
Month currentMonth = now.getMonth();
|
|
|
|
// 判断月份范围并返回对应值
|
|
if (currentMonth.getValue() <= 6) {
|
|
user.setFree6(user.getFree6().add(freeCoin)); // 在1月到6月时返回的值
|
|
} else {
|
|
user.setFree12(user.getFree12().add(freeCoin)); // 在7月到12月时返回的值
|
|
}
|
|
detail.setUsername(user1.getName()); // 获取 user 的 name 设置到 detail 的 username
|
|
detail.setArea(user1.getArea()); // 获取 user 的 area 设置到 detail 的 area
|
|
detail.setAdminName(detail.getAdminName());
|
|
refundMapper.inserty(detail);
|
|
userMapper.update(user);
|
|
}
|
|
// 充值驳回
|
|
// if (audit.getStatus() == 2 && audit.getRechargeId() != null) {
|
|
// // 获取 detail1 对象
|
|
// DetailY detail1 = detailMapper.selectByDetailId(audit.getDetailId());
|
|
// if (detail1 == null) {
|
|
// throw new RuntimeException("驳回失败!未找到对应的 DetailY 信息,audit.getDetailId() = " + audit.getDetailId());
|
|
// }
|
|
//
|
|
// // 获取金币数据
|
|
// BigDecimal rechargeCoin1 = detail1.getRechargeCoin();
|
|
// BigDecimal taskCoin1 = detail1.getTaskCoin();
|
|
// BigDecimal freeCoin1 = detail1.getFreeCoin();
|
|
//
|
|
// // 获取 user1 对象
|
|
// User user1 = userMapper.selectByJwcode(detail1.getJwcode());
|
|
// if (user1 == null) {
|
|
// throw new RuntimeException("驳回失败!未找到对应的用户信息,detail1.getJwcode() = " + detail1.getJwcode());
|
|
// }
|
|
//
|
|
// // 检查并更新用户金币
|
|
// if (rechargeCoin1 != null) {
|
|
// if (user1.getBuyJb().compareTo(rechargeCoin1) < 0) {
|
|
// throw new RuntimeException("驳回失败!该用户剩余 BuyJb 金币不足扣除数量!");
|
|
// } else {
|
|
// user1.setBuyJb(user1.getBuyJb().subtract(rechargeCoin1));
|
|
// }
|
|
// }
|
|
//
|
|
// if (taskCoin1 != null) {
|
|
// if (user1.getCoreJb().compareTo(taskCoin1) < 0) {
|
|
// throw new RuntimeException("驳回失败!该用户剩余 CoreJb 金币不足扣除数量!");
|
|
// } else {
|
|
// user1.setCoreJb(user1.getCoreJb().subtract(taskCoin1));
|
|
// }
|
|
// }
|
|
//
|
|
//
|
|
// // 判断当前月份
|
|
// LocalDate now1 = LocalDate.now();
|
|
// Month currentMonth1 = now1.getMonth();
|
|
//
|
|
// // 检查 free6 或 free12 的金币是否足够
|
|
// if (freeCoin1 != null) {
|
|
// if (currentMonth1.getValue() <= 6) {
|
|
// if (user1.getFree6().compareTo(freeCoin1) < 0) {
|
|
// throw new RuntimeException("驳回失败!该用户剩余 free6 金币不足扣除数量!");
|
|
// } else {
|
|
// user1.setFree6(user1.getFree6().subtract(freeCoin1));
|
|
// }
|
|
// } else {
|
|
// if (user1.getFree12().compareTo(freeCoin1) < 0) {
|
|
// throw new RuntimeException("驳回失败!该用户剩余 free12 金币不足扣除数量!");
|
|
// } else {
|
|
// user1.setFree12(user1.getFree12().subtract(freeCoin1));
|
|
// }
|
|
// }
|
|
// }
|
|
//
|
|
// // 更新用户信息到数据库
|
|
// userMapper.update(user1);
|
|
// }
|
|
|
|
return Result.success();
|
|
|
|
}
|
|
@PostMapping
|
|
public Result search(@RequestBody Page page){
|
|
if(ObjectUtils.isEmpty(page.getPageNum())){
|
|
return Result.success(auditService.search(page.getAudit()));
|
|
}
|
|
else {
|
|
return Result.success(auditService.searchForPage(page.getPageNum(),page.getPageSize(),page.getAudit()));
|
|
}
|
|
}
|
|
@PostMapping("/refund")
|
|
public Result searchForPage(@RequestBody Page page){
|
|
if(ObjectUtils.isEmpty(page.getPageNum())){
|
|
return Result.success(auditService.searchForDetail(page.getDetail()));
|
|
}
|
|
else {
|
|
return Result.success(auditService.searchForConsumeDetail(page.getPageNum(), page.getPageSize(), page.getDetail()));
|
|
}
|
|
|
|
}
|
|
}
|
|
|