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.

242 lines
9.0 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. cashRecordRefund.setStatus(10);
  89. try {
  90. return Result.success(refundService.add(cashRecordRefund));
  91. } catch (Exception e) {
  92. return Result.error(e.getMessage());
  93. }
  94. }
  95. /**
  96. * 执行人查看退款现金记录
  97. */
  98. @PostMapping("/exSelect")
  99. public Result executor(@RequestBody Page page) throws Exception {
  100. HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
  101. String token = request.getHeader("token");
  102. // 解析 token 获取用户信息
  103. Admin admin = (Admin) JWTUtil.getUserDetailsList(String.valueOf(token), Admin.class);
  104. List<String> userMarkets = Arrays.asList(StringUtils.split(admin.getMarkets(), ","));
  105. List<String> markets = marketService.getMarketIds(userMarkets);
  106. // 校验分页参数
  107. if (ObjectUtils.isEmpty(page.getPageNum())) {
  108. return Result.error("页码数为空!");
  109. }
  110. if (ObjectUtils.isEmpty(page.getPageSize())) {
  111. return Result.error("页大小为空!");
  112. }
  113. //// 获取传入的市场列表
  114. // List<String> requestedMarkets = page.getCashRecordDTO() != null ? page.getCashRecordDTO().getMarkets() : null;
  115. //
  116. //// 权限校验逻辑
  117. // if (markets.contains("9") || markets.contains("9999")) {
  118. // // 特权市场:9 或 9999,跳过权限校验,直接放行传入的 markets
  119. // // 如果业务需要,也可以在这里做空值处理
  120. // if (page.getCashRecordDTO() != null) {
  121. // // 保持 requestedMarkets 不变,原样接受
  122. // // 可选:如果 requestedMarkets 为 null,可设为默认值或保持 null
  123. // }
  124. // } else {
  125. // // 普通用户:必须校验权限
  126. // if (requestedMarkets == null || requestedMarkets.isEmpty()) {
  127. // page.getCashRecordDTO().setMarkets(markets);
  128. // }
  129. // if (!markets.containsAll(requestedMarkets)) {
  130. // return Result.error("无权限!请求的市场不在授权范围内。");
  131. // }
  132. // // 校验通过,保持 requestedMarkets 不变
  133. // }
  134. return Result.success(refundService.exSelect(page.getPageNum(), page.getPageSize(), page.getCashRecordDTO()));
  135. }
  136. /**
  137. * 查询客服提交现金记录
  138. */
  139. @PostMapping("/selecta")
  140. public Result selecta(@RequestBody Page page) {
  141. // 校验分页参数
  142. if (ObjectUtils.isEmpty(page.getPageNum())) {
  143. return Result.error("页码数为空!");
  144. }
  145. if (ObjectUtils.isEmpty(page.getPageSize())) {
  146. return Result.error("页大小为空!");
  147. }
  148. // 获取传入的市场列表
  149. List<String> requestedMarkets = page.getCashRecordDTO() != null ? page.getCashRecordDTO().getMarkets() : null;
  150. return Result.success(refundService.select(page.getPageNum(), page.getPageSize(), page.getCashRecordDTO()));
  151. }
  152. @PostMapping("/update")
  153. public Result update(@RequestBody CashRecordDone cashRecordDone)throws Exception {
  154. if (cashRecordDone.getStatus() == null) {
  155. return Result.error("状态为空");
  156. }
  157. if (cashRecordDone.getStatus() == 10) {
  158. return Result.success(refundService.withdraw(cashRecordDone));
  159. }
  160. else if (cashRecordDone.getStatus() == 11) {
  161. try {
  162. return Result.success(refundService.update(cashRecordDone));
  163. } catch (Exception e) {
  164. return Result.error(e.getMessage());
  165. }
  166. }
  167. else return Result.error("该订单状态无法支持此操作");
  168. }
  169. @PostMapping("/review")
  170. public Result review(@RequestBody CashRecordDone cashRecordDone){
  171. try {
  172. return Result.success(refundService.review(cashRecordDone));
  173. } catch (Exception e) {
  174. return Result.error(e.getMessage());
  175. }
  176. }
  177. @PostMapping("/finalReview")
  178. public Result finalReview(@RequestBody CashRecordDone cashRecordDone) {
  179. return Result.success(refundService.finalreview(cashRecordDone));
  180. }
  181. @PostMapping("/executor")
  182. public Result executor(@RequestBody CashRecordDone cashRecordDone) throws Exception {
  183. try {
  184. return Result.success(refundService.executor(cashRecordDone));
  185. }
  186. catch (Exception e) {
  187. return Result.error(e.getMessage());
  188. }
  189. }
  190. /**
  191. * 新增线上退款订单
  192. */
  193. @PostMapping("/addOnline")
  194. public Result addOnline(@RequestBody CashRecordRefund cashRecordRefund){
  195. cashRecordRefund.setStatus(20);
  196. try {
  197. return Result.success(refundService.add(cashRecordRefund));
  198. } catch (Exception e) {
  199. return Result.error(e.getMessage());
  200. }
  201. }
  202. @PostMapping("/export")
  203. public Result export(@RequestBody Page page) throws Exception {
  204. // 校验分页参数
  205. if (ObjectUtils.isEmpty(page.getPageNum())) {
  206. return Result.error("页码数为空!");
  207. }
  208. if (ObjectUtils.isEmpty(page.getPageSize())) {
  209. return Result.error("页大小为空!");
  210. }
  211. return Result.success(refundService.financeSelect(page.getPageNum(), page.getPageSize(), page.getCashRecordDTO()));
  212. }
  213. @PostMapping("/ceshi")
  214. public Result ceshi() {
  215. return Result.success("测试消息");
  216. }
  217. }