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
240 lines
8.9 KiB
package com.example.demo.controller.cash;
|
|
|
|
|
|
import com.example.demo.Util.JWTUtil;
|
|
import com.example.demo.domain.entity.Admin;
|
|
import com.example.demo.domain.vo.cash.CashRecordDTO;
|
|
import com.example.demo.domain.vo.cash.CashRecordDone;
|
|
import com.example.demo.domain.vo.cash.CashRecordRefund;
|
|
import com.example.demo.domain.vo.coin.Page;
|
|
import com.example.demo.domain.vo.coin.RechargeUser;
|
|
import com.example.demo.domain.vo.coin.Result;
|
|
import com.example.demo.service.cash.RefundService;
|
|
import com.example.demo.service.coin.MarketService;
|
|
|
|
import jakarta.annotation.Resource;
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.util.ObjectUtils;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* @program: GOLD
|
|
* @ClassName RefundController
|
|
* @description:
|
|
* @author: huangqizhen
|
|
* @create: 2025−09-26 14:15
|
|
* @Version 1.0
|
|
**/
|
|
@RestController
|
|
@RequestMapping("/Money")
|
|
@RequiredArgsConstructor
|
|
@Slf4j
|
|
@CrossOrigin
|
|
public class CashRefundController {
|
|
@Autowired
|
|
private RefundService refundService;
|
|
@Autowired
|
|
MarketService marketService;
|
|
|
|
|
|
/**
|
|
* 当地财务负责人退款记录
|
|
*/
|
|
@PostMapping("/select")
|
|
public Result select(@RequestBody Page page) throws Exception {
|
|
// 获取当前请求对象
|
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
String token = request.getHeader("token");
|
|
|
|
// 解析 token 获取用户信息
|
|
Admin admin = (Admin) JWTUtil.getUserDetailsList(String.valueOf(token), Admin.class);
|
|
List<String> userMarkets = Arrays.asList(StringUtils.split(admin.getMarkets(), ","));
|
|
List<String> markets = marketService.getMarketIds(userMarkets);
|
|
|
|
// 校验分页参数
|
|
if (ObjectUtils.isEmpty(page.getPageNum())) {
|
|
return Result.error("页码数为空!");
|
|
}
|
|
if (ObjectUtils.isEmpty(page.getPageSize())) {
|
|
return Result.error("页大小为空!");
|
|
}
|
|
|
|
// 获取传入的市场列表
|
|
List<String> requestedMarkets = page.getCashRecordDTO() != null ? page.getCashRecordDTO().getMarkets() : null;
|
|
|
|
// 权限校验逻辑
|
|
if (markets.contains("9") || markets.contains("9999")) {
|
|
// 特权市场:9 或 9999,跳过权限校验,直接放行传入的 markets
|
|
// 如果业务需要,也可以在这里做空值处理
|
|
if (page.getCashRecordDTO() != null) {
|
|
// 保持 requestedMarkets 不变,原样接受
|
|
// 可选:如果 requestedMarkets 为 null,可设为默认值或保持 null
|
|
}
|
|
} else {
|
|
// 普通用户:必须校验权限
|
|
if (requestedMarkets == null || requestedMarkets.isEmpty()) {
|
|
page.getCashRecordDTO().setMarkets(markets);
|
|
}
|
|
if (!markets.containsAll(requestedMarkets)) {
|
|
return Result.error("无权限!请求的市场不在授权范围内。");
|
|
}
|
|
// 校验通过,保持 requestedMarkets 不变
|
|
}
|
|
return Result.success(refundService.financeSelect(page.getPageNum(), page.getPageSize(), page.getCashRecordDTO()));
|
|
}
|
|
|
|
/**
|
|
* 添加退款现金记录
|
|
*/
|
|
@PostMapping("/add")
|
|
public Result add(@RequestBody CashRecordRefund cashRecordRefund) throws Exception {
|
|
try {
|
|
return Result.success(refundService.add(cashRecordRefund));
|
|
} catch (Exception e) {
|
|
return Result.error(e.getMessage());
|
|
}
|
|
}
|
|
/**
|
|
* 执行人查看退款现金记录
|
|
*/
|
|
@PostMapping("/exSelect")
|
|
public Result executor(@RequestBody Page page) throws Exception {
|
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
String token = request.getHeader("token");
|
|
|
|
// 解析 token 获取用户信息
|
|
Admin admin = (Admin) JWTUtil.getUserDetailsList(String.valueOf(token), Admin.class);
|
|
List<String> userMarkets = Arrays.asList(StringUtils.split(admin.getMarkets(), ","));
|
|
List<String> markets = marketService.getMarketIds(userMarkets);
|
|
|
|
// 校验分页参数
|
|
if (ObjectUtils.isEmpty(page.getPageNum())) {
|
|
return Result.error("页码数为空!");
|
|
}
|
|
if (ObjectUtils.isEmpty(page.getPageSize())) {
|
|
return Result.error("页大小为空!");
|
|
}
|
|
|
|
// 获取传入的市场列表
|
|
List<String> requestedMarkets = page.getCashRecordDTO() != null ? page.getCashRecordDTO().getMarkets() : null;
|
|
|
|
// 权限校验逻辑
|
|
if (markets.contains("9") || markets.contains("9999")) {
|
|
// 特权市场:9 或 9999,跳过权限校验,直接放行传入的 markets
|
|
// 如果业务需要,也可以在这里做空值处理
|
|
if (page.getCashRecordDTO() != null) {
|
|
// 保持 requestedMarkets 不变,原样接受
|
|
// 可选:如果 requestedMarkets 为 null,可设为默认值或保持 null
|
|
}
|
|
} else {
|
|
// 普通用户:必须校验权限
|
|
if (requestedMarkets == null || requestedMarkets.isEmpty()) {
|
|
page.getCashRecordDTO().setMarkets(markets);
|
|
}
|
|
if (!markets.containsAll(requestedMarkets)) {
|
|
return Result.error("无权限!请求的市场不在授权范围内。");
|
|
}
|
|
// 校验通过,保持 requestedMarkets 不变
|
|
}
|
|
return Result.success(refundService.exSelect(page.getPageNum(), page.getPageSize(), page.getCashRecordDTO()));
|
|
}
|
|
/**
|
|
* 查询客服提交现金记录
|
|
*/
|
|
@PostMapping("/selecta")
|
|
public Result selecta(@RequestBody Page page) {
|
|
|
|
|
|
// 校验分页参数
|
|
if (ObjectUtils.isEmpty(page.getPageNum())) {
|
|
return Result.error("页码数为空!");
|
|
}
|
|
if (ObjectUtils.isEmpty(page.getPageSize())) {
|
|
return Result.error("页大小为空!");
|
|
}
|
|
// 获取传入的市场列表
|
|
List<String> requestedMarkets = page.getCashRecordDTO() != null ? page.getCashRecordDTO().getMarkets() : null;
|
|
|
|
return Result.success(refundService.select(page.getPageNum(), page.getPageSize(), page.getCashRecordDTO()));
|
|
}
|
|
@PostMapping("/update")
|
|
public Result update(@RequestBody CashRecordDone cashRecordDone)throws Exception {
|
|
if (cashRecordDone.getStatus() == null) {
|
|
return Result.error("状态为空");
|
|
}
|
|
if (cashRecordDone.getStatus() == 10) {
|
|
return Result.success(refundService.withdraw(cashRecordDone));
|
|
}
|
|
else if (cashRecordDone.getStatus() == 11) {
|
|
|
|
try {
|
|
return Result.success(refundService.update(cashRecordDone));
|
|
} catch (Exception e) {
|
|
return Result.error(e.getMessage());
|
|
}
|
|
}
|
|
|
|
else return Result.error("该订单状态无法支持此操作");
|
|
}
|
|
@PostMapping("/review")
|
|
public Result review(@RequestBody CashRecordDone cashRecordDone){
|
|
try {
|
|
return Result.success(refundService.review(cashRecordDone));
|
|
} catch (Exception e) {
|
|
return Result.error(e.getMessage());
|
|
}
|
|
}
|
|
@PostMapping("/finalReview")
|
|
public Result finalReview(@RequestBody CashRecordDone cashRecordDone) {
|
|
return Result.success(refundService.finalreview(cashRecordDone));
|
|
}
|
|
@PostMapping("/executor")
|
|
public Result executor(@RequestBody CashRecordDone cashRecordDone) throws Exception {
|
|
try {
|
|
return Result.success(refundService.executor(cashRecordDone));
|
|
}
|
|
catch (Exception e) {
|
|
return Result.error(e.getMessage());
|
|
}
|
|
|
|
}
|
|
/**
|
|
* 新增线上退款订单
|
|
*/
|
|
@PostMapping("/addOnline")
|
|
public Result addOnline(@RequestBody CashRecordRefund cashRecordRefund){
|
|
try {
|
|
return Result.success(refundService.add(cashRecordRefund));
|
|
} catch (Exception e) {
|
|
return Result.error(e.getMessage());
|
|
}
|
|
}
|
|
|
|
@PostMapping("/export")
|
|
public Result export(@RequestBody Page page) throws Exception {
|
|
|
|
// 校验分页参数
|
|
if (ObjectUtils.isEmpty(page.getPageNum())) {
|
|
return Result.error("页码数为空!");
|
|
}
|
|
if (ObjectUtils.isEmpty(page.getPageSize())) {
|
|
return Result.error("页大小为空!");
|
|
}
|
|
|
|
return Result.success(refundService.financeSelect(page.getPageNum(), page.getPageSize(), page.getCashRecordDTO()));
|
|
}
|
|
@PostMapping("/ceshi")
|
|
public Result ceshi() {
|
|
return Result.success("测试消息");
|
|
}
|
|
}
|