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.

240 lines
8.9 KiB

1 month ago
1 month ago
1 month ago
1 month ago
  1. package com.example.demo.controller.cash;
  2. import com.example.demo.Util.JWTUtil;
  3. import com.example.demo.domain.entity.Admin;
  4. import com.example.demo.domain.vo.cash.CashRecordDTO;
  5. import com.example.demo.domain.vo.cash.CashRecordDone;
  6. import com.example.demo.domain.vo.cash.CashRecordRefund;
  7. import com.example.demo.domain.vo.coin.Page;
  8. import com.example.demo.domain.vo.coin.RechargeUser;
  9. import com.example.demo.domain.vo.coin.Result;
  10. import com.example.demo.service.cash.RefundService;
  11. import com.example.demo.service.coin.MarketService;
  12. import jakarta.annotation.Resource;
  13. import jakarta.servlet.http.HttpServletRequest;
  14. import lombok.RequiredArgsConstructor;
  15. import lombok.extern.slf4j.Slf4j;
  16. import org.apache.commons.lang3.StringUtils;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.util.ObjectUtils;
  19. import org.springframework.web.bind.annotation.*;
  20. import org.springframework.web.context.request.RequestContextHolder;
  21. import org.springframework.web.context.request.ServletRequestAttributes;
  22. import java.util.Arrays;
  23. import java.util.List;
  24. /**
  25. * @program: GOLD
  26. * @ClassName RefundController
  27. * @description:
  28. * @author: huangqizhen
  29. * @create: 202509-26 14:15
  30. * @Version 1.0
  31. **/
  32. @RestController
  33. @RequestMapping("/Money")
  34. @RequiredArgsConstructor
  35. @Slf4j
  36. @CrossOrigin
  37. public class CashRefundController {
  38. @Autowired
  39. private RefundService refundService;
  40. @Autowired
  41. MarketService marketService;
  42. /**
  43. * 当地财务负责人退款记录
  44. */
  45. @PostMapping("/select")
  46. public Result select(@RequestBody Page page) throws Exception {
  47. // 获取当前请求对象
  48. HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
  49. String token = request.getHeader("token");
  50. // 解析 token 获取用户信息
  51. Admin admin = (Admin) JWTUtil.getUserDetailsList(String.valueOf(token), Admin.class);
  52. List<String> userMarkets = Arrays.asList(StringUtils.split(admin.getMarkets(), ","));
  53. List<String> markets = marketService.getMarketIds(userMarkets);
  54. // 校验分页参数
  55. if (ObjectUtils.isEmpty(page.getPageNum())) {
  56. return Result.error("页码数为空!");
  57. }
  58. if (ObjectUtils.isEmpty(page.getPageSize())) {
  59. return Result.error("页大小为空!");
  60. }
  61. // 获取传入的市场列表
  62. List<String> requestedMarkets = page.getCashRecordDTO() != null ? page.getCashRecordDTO().getMarkets() : null;
  63. // 权限校验逻辑
  64. if (markets.contains("9") || markets.contains("9999")) {
  65. // 特权市场:9 或 9999,跳过权限校验,直接放行传入的 markets
  66. // 如果业务需要,也可以在这里做空值处理
  67. if (page.getCashRecordDTO() != null) {
  68. // 保持 requestedMarkets 不变,原样接受
  69. // 可选:如果 requestedMarkets 为 null,可设为默认值或保持 null
  70. }
  71. } else {
  72. // 普通用户:必须校验权限
  73. if (requestedMarkets == null || requestedMarkets.isEmpty()) {
  74. page.getCashRecordDTO().setMarkets(markets);
  75. }
  76. if (!markets.containsAll(requestedMarkets)) {
  77. return Result.error("无权限!请求的市场不在授权范围内。");
  78. }
  79. // 校验通过,保持 requestedMarkets 不变
  80. }
  81. return Result.success(refundService.financeSelect(page.getPageNum(), page.getPageSize(), page.getCashRecordDTO()));
  82. }
  83. /**
  84. * 添加退款现金记录
  85. */
  86. @PostMapping("/add")
  87. public Result add(@RequestBody CashRecordRefund cashRecordRefund) throws Exception {
  88. try {
  89. return Result.success(refundService.add(cashRecordRefund));
  90. } catch (Exception e) {
  91. return Result.error(e.getMessage());
  92. }
  93. }
  94. /**
  95. * 执行人查看退款现金记录
  96. */
  97. @PostMapping("/exSelect")
  98. public Result executor(@RequestBody Page page) throws Exception {
  99. HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
  100. String token = request.getHeader("token");
  101. // 解析 token 获取用户信息
  102. Admin admin = (Admin) JWTUtil.getUserDetailsList(String.valueOf(token), Admin.class);
  103. List<String> userMarkets = Arrays.asList(StringUtils.split(admin.getMarkets(), ","));
  104. List<String> markets = marketService.getMarketIds(userMarkets);
  105. // 校验分页参数
  106. if (ObjectUtils.isEmpty(page.getPageNum())) {
  107. return Result.error("页码数为空!");
  108. }
  109. if (ObjectUtils.isEmpty(page.getPageSize())) {
  110. return Result.error("页大小为空!");
  111. }
  112. // 获取传入的市场列表
  113. List<String> requestedMarkets = page.getCashRecordDTO() != null ? page.getCashRecordDTO().getMarkets() : null;
  114. // 权限校验逻辑
  115. if (markets.contains("9") || markets.contains("9999")) {
  116. // 特权市场:9 或 9999,跳过权限校验,直接放行传入的 markets
  117. // 如果业务需要,也可以在这里做空值处理
  118. if (page.getCashRecordDTO() != null) {
  119. // 保持 requestedMarkets 不变,原样接受
  120. // 可选:如果 requestedMarkets 为 null,可设为默认值或保持 null
  121. }
  122. } else {
  123. // 普通用户:必须校验权限
  124. if (requestedMarkets == null || requestedMarkets.isEmpty()) {
  125. page.getCashRecordDTO().setMarkets(markets);
  126. }
  127. if (!markets.containsAll(requestedMarkets)) {
  128. return Result.error("无权限!请求的市场不在授权范围内。");
  129. }
  130. // 校验通过,保持 requestedMarkets 不变
  131. }
  132. return Result.success(refundService.exSelect(page.getPageNum(), page.getPageSize(), page.getCashRecordDTO()));
  133. }
  134. /**
  135. * 查询客服提交现金记录
  136. */
  137. @PostMapping("/selecta")
  138. public Result selecta(@RequestBody Page page) {
  139. // 校验分页参数
  140. if (ObjectUtils.isEmpty(page.getPageNum())) {
  141. return Result.error("页码数为空!");
  142. }
  143. if (ObjectUtils.isEmpty(page.getPageSize())) {
  144. return Result.error("页大小为空!");
  145. }
  146. // 获取传入的市场列表
  147. List<String> requestedMarkets = page.getCashRecordDTO() != null ? page.getCashRecordDTO().getMarkets() : null;
  148. return Result.success(refundService.select(page.getPageNum(), page.getPageSize(), page.getCashRecordDTO()));
  149. }
  150. @PostMapping("/update")
  151. public Result update(@RequestBody CashRecordDone cashRecordDone)throws Exception {
  152. if (cashRecordDone.getStatus() == null) {
  153. return Result.error("状态为空");
  154. }
  155. if (cashRecordDone.getStatus() == 10) {
  156. return Result.success(refundService.withdraw(cashRecordDone));
  157. }
  158. else if (cashRecordDone.getStatus() == 11) {
  159. try {
  160. return Result.success(refundService.update(cashRecordDone));
  161. } catch (Exception e) {
  162. return Result.error(e.getMessage());
  163. }
  164. }
  165. else return Result.error("该订单状态无法支持此操作");
  166. }
  167. @PostMapping("/review")
  168. public Result review(@RequestBody CashRecordDone cashRecordDone){
  169. try {
  170. return Result.success(refundService.review(cashRecordDone));
  171. } catch (Exception e) {
  172. return Result.error(e.getMessage());
  173. }
  174. }
  175. @PostMapping("/finalReview")
  176. public Result finalReview(@RequestBody CashRecordDone cashRecordDone) {
  177. return Result.success(refundService.finalreview(cashRecordDone));
  178. }
  179. @PostMapping("/executor")
  180. public Result executor(@RequestBody CashRecordDone cashRecordDone) throws Exception {
  181. try {
  182. return Result.success(refundService.executor(cashRecordDone));
  183. }
  184. catch (Exception e) {
  185. return Result.error(e.getMessage());
  186. }
  187. }
  188. /**
  189. * 新增线上退款订单
  190. */
  191. @PostMapping("/addOnline")
  192. public Result addOnline(@RequestBody CashRecordRefund cashRecordRefund){
  193. try {
  194. return Result.success(refundService.add(cashRecordRefund));
  195. } catch (Exception e) {
  196. return Result.error(e.getMessage());
  197. }
  198. }
  199. @PostMapping("/export")
  200. public Result export(@RequestBody Page page) throws Exception {
  201. // 校验分页参数
  202. if (ObjectUtils.isEmpty(page.getPageNum())) {
  203. return Result.error("页码数为空!");
  204. }
  205. if (ObjectUtils.isEmpty(page.getPageSize())) {
  206. return Result.error("页大小为空!");
  207. }
  208. return Result.success(refundService.financeSelect(page.getPageNum(), page.getPageSize(), page.getCashRecordDTO()));
  209. }
  210. @PostMapping("/ceshi")
  211. public Result ceshi() {
  212. return Result.success("测试消息");
  213. }
  214. }