|
|
@@ -0,0 +1,234 @@
|
|
|
+package com.etotem.cfc.controller.admin;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.etotem.cfc.common.Result;
|
|
|
+import com.etotem.cfc.entity.TeamAwardRecord;
|
|
|
+import com.etotem.cfc.entity.TeamShareRecord;
|
|
|
+import com.etotem.cfc.entity.WithdrawalRequest;
|
|
|
+import com.etotem.cfc.service.ServiceCostConfigService;
|
|
|
+import com.etotem.cfc.service.TeamProfitConfigService;
|
|
|
+import com.etotem.cfc.service.TeamProfitFlowService;
|
|
|
+import com.etotem.cfc.service.WithdrawalService;
|
|
|
+import com.etotem.cfc.util.ParamUtils;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestAttribute;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 团队分润管理端接口(能力键 {@code team.admin.manage},单元 admin;规格 §12-T5)。
|
|
|
+ *
|
|
|
+ * <p>契约溯源:{@code docs/superpowers/specs/2026-11-07-referral-team-profit-sharing.md} v0.7
|
|
|
+ * §12-T5 管理端(成本价/星级档位#12/团队门槛/团队奖分档配置 + 分润流水查询 + 提现审核,复用
|
|
|
+ * 现有管理端佣金模式)。统一 {@code /api/admin} 前缀 + 全部 {@code @PostMapping} +
|
|
|
+ * {@code JwtInterceptor} 拦截 + 管理员角色门禁(role=admin)。</p>
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/admin/team-profit")
|
|
|
+public class TeamProfitAdminController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TeamProfitConfigService teamProfitConfigService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TeamProfitFlowService teamProfitFlowService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ServiceCostConfigService serviceCostConfigService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private WithdrawalService withdrawalService;
|
|
|
+
|
|
|
+ // ==================== 配置:星级档位(§11-#12 后台可调) ====================
|
|
|
+
|
|
|
+ @PostMapping("/config/star-tiers")
|
|
|
+ public Result<int[]> getStarTiers(@RequestAttribute("role") String role) {
|
|
|
+ if (!isAdmin(role)) {
|
|
|
+ return Result.error("无权限");
|
|
|
+ }
|
|
|
+ return Result.success(teamProfitConfigService.getStarTiers());
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/config/default-star-tiers")
|
|
|
+ public Result<int[]> getDefaultStarTiers(@RequestAttribute("role") String role) {
|
|
|
+ if (!isAdmin(role)) {
|
|
|
+ return Result.error("无权限");
|
|
|
+ }
|
|
|
+ return Result.success(teamProfitConfigService.defaultStarTiers());
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/config/save-star-tiers")
|
|
|
+ public Result<String> saveStarTiers(@RequestBody Map<String, Object> params,
|
|
|
+ @RequestAttribute("role") String role) {
|
|
|
+ if (!isAdmin(role)) {
|
|
|
+ return Result.error("无权限");
|
|
|
+ }
|
|
|
+ Object raw = params == null ? null : params.get("tiers");
|
|
|
+ if (!(raw instanceof java.util.List)) {
|
|
|
+ return Result.error("tiers 必须为 6 档整数数组");
|
|
|
+ }
|
|
|
+ java.util.List<?> list = (java.util.List<?>) raw;
|
|
|
+ if (list.size() != 6) {
|
|
|
+ return Result.error("星级档位必须为 6 档(1-6 星一一对应)");
|
|
|
+ }
|
|
|
+ int[] tiers = new int[6];
|
|
|
+ for (int i = 0; i < 6; i++) {
|
|
|
+ Object item = list.get(i);
|
|
|
+ if (item == null) {
|
|
|
+ return Result.error("星级档位不能为空");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ tiers[i] = Integer.parseInt(String.valueOf(item).trim());
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ return Result.error("星级档位必须为整数");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ teamProfitConfigService.saveStarTiers(tiers);
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
+ return Result.error(e.getMessage());
|
|
|
+ }
|
|
|
+ return Result.success("保存成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== 配置:比率 / 份额 / 归属 / 权重(§7.8) ====================
|
|
|
+
|
|
|
+ @PostMapping("/config/ratios")
|
|
|
+ public Result<Map<String, Object>> getRatios(@RequestAttribute("role") String role) {
|
|
|
+ if (!isAdmin(role)) {
|
|
|
+ return Result.error("无权限");
|
|
|
+ }
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
+ data.put("eightShareRatio", teamProfitConfigService.getEightShareRatio());
|
|
|
+ data.put("teamAwardRatio", teamProfitConfigService.getTeamAwardRatio());
|
|
|
+ data.put("shareTotal", teamProfitConfigService.getShareTotal());
|
|
|
+ data.put("awardDistribute", teamProfitConfigService.getAwardDistribute());
|
|
|
+ data.put("starWeight", teamProfitConfigService.getStarWeight());
|
|
|
+ return Result.success(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/config/save")
|
|
|
+ public Result<String> saveConfig(@RequestBody Map<String, Object> params,
|
|
|
+ @RequestAttribute("role") String role) {
|
|
|
+ if (!isAdmin(role)) {
|
|
|
+ return Result.error("无权限");
|
|
|
+ }
|
|
|
+ String key = params == null ? null : (String) params.get("key");
|
|
|
+ Object rawValue = params == null ? null : params.get("value");
|
|
|
+ if (key == null || key.trim().isEmpty() || rawValue == null) {
|
|
|
+ return Result.error("key 与 value 不能为空");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ teamProfitConfigService.saveConfig(key, String.valueOf(rawValue));
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
+ return Result.error(e.getMessage());
|
|
|
+ }
|
|
|
+ return Result.success("保存成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== 配置:服务成本价(§7.5 + §11-#8) ====================
|
|
|
+
|
|
|
+ @PostMapping("/cost/get")
|
|
|
+ public Result<Integer> getCost(@RequestBody Map<String, Object> params,
|
|
|
+ @RequestAttribute("role") String role) {
|
|
|
+ if (!isAdmin(role)) {
|
|
|
+ return Result.error("无权限");
|
|
|
+ }
|
|
|
+ String serviceType = params == null ? null : (String) params.get("serviceType");
|
|
|
+ if (serviceType == null || serviceType.trim().isEmpty()) {
|
|
|
+ return Result.error("serviceType 不能为空");
|
|
|
+ }
|
|
|
+ return Result.success(serviceCostConfigService.getCostCent(serviceType));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/cost/save")
|
|
|
+ public Result<Integer> saveCost(@RequestBody Map<String, Object> params,
|
|
|
+ @RequestAttribute("role") String role) {
|
|
|
+ if (!isAdmin(role)) {
|
|
|
+ return Result.error("无权限");
|
|
|
+ }
|
|
|
+ String serviceType = params == null ? null : (String) params.get("serviceType");
|
|
|
+ String serviceName = params == null ? null : (String) params.get("serviceName");
|
|
|
+ Integer costCent = null;
|
|
|
+ Object costRaw = params == null ? null : params.get("costCent");
|
|
|
+ if (costRaw != null) {
|
|
|
+ try {
|
|
|
+ costCent = Integer.parseInt(String.valueOf(costRaw).trim());
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ costCent = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (serviceType == null || serviceType.trim().isEmpty()) {
|
|
|
+ return Result.error("serviceType 不能为空");
|
|
|
+ }
|
|
|
+ if (costCent == null || costCent < 0) {
|
|
|
+ return Result.error("costCent 必须为非负整数(分)");
|
|
|
+ }
|
|
|
+ return Result.success(serviceCostConfigService.saveCostCent(serviceType, serviceName, costCent));
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== 分润流水查询(§7.3 / §7.4) ====================
|
|
|
+
|
|
|
+ @PostMapping("/flow/share-records")
|
|
|
+ public Result<Page<TeamShareRecord>> shareRecords(@RequestBody Map<String, Object> params,
|
|
|
+ @RequestAttribute("role") String role) {
|
|
|
+ if (!isAdmin(role)) {
|
|
|
+ return Result.error("无权限");
|
|
|
+ }
|
|
|
+ Long recipientUserId = ParamUtils.getLong(params == null ? null : params.get("recipientUserId"));
|
|
|
+ String status = params == null ? null : (String) params.get("status");
|
|
|
+ int page = getInt(params, "page", 1);
|
|
|
+ int size = getInt(params, "size", 20);
|
|
|
+ return Result.success(teamProfitFlowService.queryTeamShareRecords(recipientUserId, status, page, size));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/flow/award-records")
|
|
|
+ public Result<Page<TeamAwardRecord>> awardRecords(@RequestBody Map<String, Object> params,
|
|
|
+ @RequestAttribute("role") String role) {
|
|
|
+ if (!isAdmin(role)) {
|
|
|
+ return Result.error("无权限");
|
|
|
+ }
|
|
|
+ Long ownerUserId = ParamUtils.getLong(params == null ? null : params.get("ownerUserId"));
|
|
|
+ String status = params == null ? null : (String) params.get("status");
|
|
|
+ int page = getInt(params, "page", 1);
|
|
|
+ int size = getInt(params, "size", 20);
|
|
|
+ return Result.success(teamProfitFlowService.queryTeamAwardRecords(ownerUserId, status, page, size));
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== 提现审核(复用 withdrawal_requests,§11-#7) ====================
|
|
|
+
|
|
|
+ @PostMapping("/withdrawals")
|
|
|
+ public Result<Page<WithdrawalRequest>> withdrawals(@RequestBody Map<String, Object> params,
|
|
|
+ @RequestAttribute("role") String role) {
|
|
|
+ if (!isAdmin(role)) {
|
|
|
+ return Result.error("无权限");
|
|
|
+ }
|
|
|
+ String status = params == null ? null : (String) params.get("status");
|
|
|
+ String type = params == null ? null : (String) params.get("type");
|
|
|
+ int page = getInt(params, "page", 1);
|
|
|
+ int size = getInt(params, "size", 20);
|
|
|
+ return Result.success(withdrawalService.getAdminList(status, type, page, size));
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== helpers ====================
|
|
|
+
|
|
|
+ private static boolean isAdmin(String role) {
|
|
|
+ return "admin".equals(role);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static int getInt(Map<String, Object> params, String key, int defaultValue) {
|
|
|
+ if (params == null || params.get(key) == null) {
|
|
|
+ return defaultValue;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return ((Number) params.get(key)).intValue();
|
|
|
+ } catch (ClassCastException e) {
|
|
|
+ return defaultValue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|