金币系统后端
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

5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
  1. package com.example.demo.controller;
  2. import com.example.demo.domain.entity.Audit;
  3. import com.example.demo.domain.entity.Detail;
  4. import com.example.demo.domain.entity.DetailY;
  5. import com.example.demo.domain.entity.User;
  6. import com.example.demo.domain.vo.Page;
  7. import com.example.demo.domain.vo.Result;
  8. import com.example.demo.mapper.DetailMapper;
  9. import com.example.demo.mapper.RefundMapper;
  10. import com.example.demo.mapper.UserMapper;
  11. import com.example.demo.sevice.AuditService;
  12. import lombok.RequiredArgsConstructor;
  13. import lombok.extern.slf4j.Slf4j;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.transaction.annotation.Transactional;
  16. import org.springframework.util.ObjectUtils;
  17. import org.springframework.web.bind.annotation.*;
  18. import java.math.BigDecimal;
  19. import java.time.LocalDate;
  20. import java.time.Month;
  21. import java.util.Arrays;
  22. import static com.example.demo.Util.JWTUtil.getUserDetails;
  23. @RestController
  24. @RequestMapping("/audit/audit")
  25. @RequiredArgsConstructor
  26. @Slf4j
  27. @Transactional
  28. @CrossOrigin
  29. public class AuditController {
  30. @Autowired
  31. private RefundMapper refundMapper;
  32. @Autowired
  33. private UserMapper userMapper;
  34. @Autowired
  35. private DetailMapper detailMapper;
  36. private final AuditService auditService;
  37. @PostMapping("/add")
  38. public Result add(@RequestBody Audit audit){
  39. try {
  40. auditService.add(audit);
  41. return Result.success();
  42. }catch (Exception e){
  43. log.warn(Arrays.toString(e.getStackTrace()));
  44. return Result.error(e.getMessage());
  45. }
  46. }
  47. @PostMapping("/goldedit")
  48. public Result goldedit(@RequestBody Audit audit) throws Exception {
  49. auditService.goldedit(audit);
  50. return Result.success();
  51. }
  52. @PostMapping("/edit")
  53. public Result edit(@RequestBody Audit audit){
  54. //先执行auditService.edit(audit);
  55. //然后创建一个类,去接收这个audit,如果status=1
  56. //根据退款ID找到detail表中的记录获取到他的三种金币
  57. //把金币加到user表中对应的金币中
  58. auditService.edit(audit);
  59. //退款通过
  60. if(audit.getStatus() == 1 && audit.getRefundId()!=null){
  61. Detail detail = detailMapper.selectByDetailId(audit.getRefundId());
  62. BigDecimal rechargeCoin = detail.getRechargeCoin();
  63. BigDecimal taskCoin = detail.getTaskCoin();
  64. BigDecimal freeCoin = detail.getFreeCoin();
  65. User user = userMapper.selectByJwcode(detail.getJwcode());
  66. user.setBuyJb(user.getBuyJb().add(rechargeCoin));
  67. user.setCoreJb(user.getCoreJb().add(taskCoin));
  68. User user1 = userMapper.selectByJwcode1(detail.getJwcode());
  69. LocalDate now = LocalDate.now();
  70. Month currentMonth = now.getMonth();
  71. // 判断月份范围并返回对应值
  72. if (currentMonth.getValue() <= 6) {
  73. user.setFree6(user.getFree6().add(freeCoin)); // 在1月到6月时返回的值
  74. } else {
  75. user.setFree12(user.getFree12().add(freeCoin)); // 在7月到12月时返回的值
  76. }
  77. detail.setUsername(user1.getName()); // 获取 user 的 name 设置到 detail 的 username
  78. detail.setArea(user1.getArea()); // 获取 user 的 area 设置到 detail 的 area
  79. detail.setAdminName(detail.getAdminName());
  80. refundMapper.inserty(detail);
  81. userMapper.update(user);
  82. }
  83. // 充值驳回
  84. // if (audit.getStatus() == 2 && audit.getRechargeId() != null) {
  85. // // 获取 detail1 对象
  86. // DetailY detail1 = detailMapper.selectByDetailId(audit.getDetailId());
  87. // if (detail1 == null) {
  88. // throw new RuntimeException("驳回失败!未找到对应的 DetailY 信息,audit.getDetailId() = " + audit.getDetailId());
  89. // }
  90. //
  91. // // 获取金币数据
  92. // BigDecimal rechargeCoin1 = detail1.getRechargeCoin();
  93. // BigDecimal taskCoin1 = detail1.getTaskCoin();
  94. // BigDecimal freeCoin1 = detail1.getFreeCoin();
  95. //
  96. // // 获取 user1 对象
  97. // User user1 = userMapper.selectByJwcode(detail1.getJwcode());
  98. // if (user1 == null) {
  99. // throw new RuntimeException("驳回失败!未找到对应的用户信息,detail1.getJwcode() = " + detail1.getJwcode());
  100. // }
  101. //
  102. // // 检查并更新用户金币
  103. // if (rechargeCoin1 != null) {
  104. // if (user1.getBuyJb().compareTo(rechargeCoin1) < 0) {
  105. // throw new RuntimeException("驳回失败!该用户剩余 BuyJb 金币不足扣除数量!");
  106. // } else {
  107. // user1.setBuyJb(user1.getBuyJb().subtract(rechargeCoin1));
  108. // }
  109. // }
  110. //
  111. // if (taskCoin1 != null) {
  112. // if (user1.getCoreJb().compareTo(taskCoin1) < 0) {
  113. // throw new RuntimeException("驳回失败!该用户剩余 CoreJb 金币不足扣除数量!");
  114. // } else {
  115. // user1.setCoreJb(user1.getCoreJb().subtract(taskCoin1));
  116. // }
  117. // }
  118. //
  119. //
  120. // // 判断当前月份
  121. // LocalDate now1 = LocalDate.now();
  122. // Month currentMonth1 = now1.getMonth();
  123. //
  124. // // 检查 free6 或 free12 的金币是否足够
  125. // if (freeCoin1 != null) {
  126. // if (currentMonth1.getValue() <= 6) {
  127. // if (user1.getFree6().compareTo(freeCoin1) < 0) {
  128. // throw new RuntimeException("驳回失败!该用户剩余 free6 金币不足扣除数量!");
  129. // } else {
  130. // user1.setFree6(user1.getFree6().subtract(freeCoin1));
  131. // }
  132. // } else {
  133. // if (user1.getFree12().compareTo(freeCoin1) < 0) {
  134. // throw new RuntimeException("驳回失败!该用户剩余 free12 金币不足扣除数量!");
  135. // } else {
  136. // user1.setFree12(user1.getFree12().subtract(freeCoin1));
  137. // }
  138. // }
  139. // }
  140. //
  141. // // 更新用户信息到数据库
  142. // userMapper.update(user1);
  143. // }
  144. return Result.success();
  145. }
  146. @PostMapping
  147. public Result search(@RequestBody Page page){
  148. if(ObjectUtils.isEmpty(page.getPageNum())){
  149. return Result.success(auditService.search(page.getAudit()));
  150. }
  151. else {
  152. return Result.success(auditService.searchForPage(page.getPageNum(),page.getPageSize(),page.getAudit()));
  153. }
  154. }
  155. @PostMapping("/refund")
  156. public Result searchForPage(@RequestBody Page page){
  157. if(ObjectUtils.isEmpty(page.getPageNum())){
  158. return Result.success(auditService.searchForDetail(page.getDetail()));
  159. }
  160. else {
  161. return Result.success(auditService.searchForConsumeDetail(page.getPageNum(), page.getPageSize(), page.getDetail()));
  162. }
  163. }
  164. }