|
@@ -0,0 +1,276 @@
|
|
|
|
|
+package com.etotem.cfc.controller.admin;
|
|
|
|
|
+
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
+import com.etotem.cfc.common.AdminRoles;
|
|
|
|
|
+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 io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestAttribute;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
+
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
|
+import java.util.LinkedHashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+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)/团队门槛/团队奖分档配置 + 分润流水查询与提现审核
|
|
|
|
|
+ * (复用现有管理端佣金模式)。</p>
|
|
|
|
|
+ *
|
|
|
|
|
+ * <p><b>接口约定(项目规范)</b>:{@code /api/admin} 前缀统一 {@code @PostMapping},
|
|
|
|
|
+ * JwtInterceptor 拦截 + 控制器内管理员角色门禁(admin/operator/finance 平台角色)。</p>
|
|
|
|
|
+ *
|
|
|
|
|
+ * <p><b>规格:docs/superpowers/specs/2026-11-07-referral-team-profit-sharing.md v0.7
|
|
|
|
|
+ * §7.5 + §7.8 + §11-#12 + §12-T5。</b></p>
|
|
|
|
|
+ */
|
|
|
|
|
+@Tag(name = "管理端-团队分润")
|
|
|
|
|
+@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;
|
|
|
|
|
+
|
|
|
|
|
+ // ==================== 配置(§7.8 + §11-#12) ====================
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "团队分润配置总览(星级档位/比率/份额/归属/权重)")
|
|
|
|
|
+ @PostMapping("/config")
|
|
|
|
|
+ public Result<Map<String, Object>> config(@RequestAttribute("role") String role,
|
|
|
|
|
+ @RequestAttribute(value = "roles", required = false) List<String> roles) {
|
|
|
|
|
+ Result<Map<String, Object>> gate = requirePlatformRole(role, roles);
|
|
|
|
|
+ if (gate != null) {
|
|
|
|
|
+ return gate;
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<String, Object> data = new LinkedHashMap<>();
|
|
|
|
|
+ data.put("starTiers", teamProfitConfigService.getStarTiers());
|
|
|
|
|
+ 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);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "保存星级档位(后台配置 #12,非 6 档拒收)")
|
|
|
|
|
+ @PostMapping("/config/star-tiers")
|
|
|
|
|
+ public Result<String> saveStarTiers(@RequestBody(required = false) Map<String, Object> body,
|
|
|
|
|
+ @RequestAttribute("role") String role,
|
|
|
|
|
+ @RequestAttribute(value = "roles", required = false) List<String> roles) {
|
|
|
|
|
+ Result<Map<String, Object>> gate = requirePlatformRole(role, roles);
|
|
|
|
|
+ if (gate != null) {
|
|
|
|
|
+ return Result.error(gate.getCode(), gate.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (body == null) {
|
|
|
|
|
+ return Result.badRequest("请求体不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ int[] tiers = toIntArray(body.get("starTiers"));
|
|
|
|
|
+ if (tiers == null) {
|
|
|
|
|
+ return Result.badRequest("starTiers 不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ teamProfitConfigService.saveStarTiers(tiers);
|
|
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
|
|
+ return Result.badRequest(e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ return Result.success("星级档位已保存");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "保存团队分润配置项(写入 service_config group_key='team_profit')")
|
|
|
|
|
+ @PostMapping("/config/save")
|
|
|
|
|
+ public Result<String> saveConfig(@RequestBody(required = false) Map<String, Object> body,
|
|
|
|
|
+ @RequestAttribute("role") String role,
|
|
|
|
|
+ @RequestAttribute(value = "roles", required = false) List<String> roles) {
|
|
|
|
|
+ Result<Map<String, Object>> gate = requirePlatformRole(role, roles);
|
|
|
|
|
+ if (gate != null) {
|
|
|
|
|
+ return Result.error(gate.getCode(), gate.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (body == null) {
|
|
|
|
|
+ return Result.badRequest("请求体不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ String key = (String) body.get("key");
|
|
|
|
|
+ String value = body.get("value") != null ? String.valueOf(body.get("value")) : null;
|
|
|
|
|
+ if (key == null || key.trim().isEmpty()) {
|
|
|
|
|
+ return Result.badRequest("配置键不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ teamProfitConfigService.saveConfig(key, value);
|
|
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
|
|
+ return Result.badRequest(e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ return Result.success("配置已保存");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ==================== 分润流水查询(§7.3/§7.4) ====================
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "8 份分佣流水分页查询(§7.3 team_share_record)")
|
|
|
|
|
+ @PostMapping("/flow/share-records")
|
|
|
|
|
+ public Result<Page<TeamShareRecord>> shareRecords(@RequestBody(required = false) Map<String, Object> body,
|
|
|
|
|
+ @RequestAttribute("role") String role,
|
|
|
|
|
+ @RequestAttribute(value = "roles", required = false) List<String> roles) {
|
|
|
|
|
+ Result<Map<String, Object>> gate = requirePlatformRole(role, roles);
|
|
|
|
|
+ if (gate != null) {
|
|
|
|
|
+ return Result.error(gate.getCode(), gate.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ Long recipientUserId = ParamUtils.getLong(body != null ? body.get("recipientUserId") : null);
|
|
|
|
|
+ String status = body != null ? (String) body.get("status") : null;
|
|
|
|
|
+ int page = (int) ParamUtils.getLong(body != null ? body.get("page") : null, 1L);
|
|
|
|
|
+ int size = (int) ParamUtils.getLong(body != null ? body.get("size") : null, 10L);
|
|
|
|
|
+ return Result.success(teamProfitFlowService.queryTeamShareRecords(recipientUserId, status, page, size));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "团队奖流水分页查询(§7.4 team_award_record)")
|
|
|
|
|
+ @PostMapping("/flow/award-records")
|
|
|
|
|
+ public Result<Page<TeamAwardRecord>> awardRecords(@RequestBody(required = false) Map<String, Object> body,
|
|
|
|
|
+ @RequestAttribute("role") String role,
|
|
|
|
|
+ @RequestAttribute(value = "roles", required = false) List<String> roles) {
|
|
|
|
|
+ Result<Map<String, Object>> gate = requirePlatformRole(role, roles);
|
|
|
|
|
+ if (gate != null) {
|
|
|
|
|
+ return Result.error(gate.getCode(), gate.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ Long teamId = ParamUtils.getLong(body != null ? body.get("teamId") : null);
|
|
|
|
|
+ String status = body != null ? (String) body.get("status") : null;
|
|
|
|
|
+ int page = (int) ParamUtils.getLong(body != null ? body.get("page") : null, 1L);
|
|
|
|
|
+ int size = (int) ParamUtils.getLong(body != null ? body.get("size") : null, 10L);
|
|
|
|
|
+ return Result.success(teamProfitFlowService.queryTeamAwardRecords(teamId, status, page, size));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ==================== 成本价配置(§7.5) ====================
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "读取服务成本价 C(分)")
|
|
|
|
|
+ @PostMapping("/cost/get")
|
|
|
|
|
+ public Result<Integer> getCost(@RequestBody(required = false) Map<String, Object> body,
|
|
|
|
|
+ @RequestAttribute("role") String role,
|
|
|
|
|
+ @RequestAttribute(value = "roles", required = false) List<String> roles) {
|
|
|
|
|
+ Result<Map<String, Object>> gate = requirePlatformRole(role, roles);
|
|
|
|
|
+ if (gate != null) {
|
|
|
|
|
+ return Result.error(gate.getCode(), gate.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ String serviceType = body != null ? (String) body.get("serviceType") : null;
|
|
|
|
|
+ return Result.success(serviceCostConfigService.getCostCent(serviceType));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "保存服务成本价 C(分,管理端维护)")
|
|
|
|
|
+ @PostMapping("/cost/save")
|
|
|
|
|
+ public Result<Integer> saveCost(@RequestBody(required = false) Map<String, Object> body,
|
|
|
|
|
+ @RequestAttribute("role") String role,
|
|
|
|
|
+ @RequestAttribute(value = "roles", required = false) List<String> roles) {
|
|
|
|
|
+ Result<Map<String, Object>> gate = requirePlatformRole(role, roles);
|
|
|
|
|
+ if (gate != null) {
|
|
|
|
|
+ return Result.error(gate.getCode(), gate.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (body == null) {
|
|
|
|
|
+ return Result.badRequest("请求体不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ String serviceType = (String) body.get("serviceType");
|
|
|
|
|
+ String serviceName = (String) body.get("serviceName");
|
|
|
|
|
+ int costCent = (int) ParamUtils.getLong(body.get("costCent"), -1L);
|
|
|
|
|
+ if (serviceType == null || serviceType.trim().isEmpty()) {
|
|
|
|
|
+ return Result.badRequest("serviceType 不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (costCent < 0) {
|
|
|
|
|
+ return Result.badRequest("costCent 不能为负数");
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ return Result.success(serviceCostConfigService.saveCostCent(serviceType, serviceName, costCent));
|
|
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
|
|
+ return Result.badRequest(e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ==================== 提现审核(复用 withdrawal_requests,type=team_share/team_award,§11-#7) ====================
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "提现审核列表(按来源 type=team_share/team_award 过滤,§11-#7)")
|
|
|
|
|
+ @PostMapping("/withdrawal/list")
|
|
|
|
|
+ public Result<Page<WithdrawalRequest>> withdrawalList(@RequestBody(required = false) Map<String, Object> body,
|
|
|
|
|
+ @RequestAttribute("role") String role,
|
|
|
|
|
+ @RequestAttribute(value = "roles", required = false) List<String> roles) {
|
|
|
|
|
+ Result<Map<String, Object>> gate = requirePlatformRole(role, roles);
|
|
|
|
|
+ if (gate != null) {
|
|
|
|
|
+ return Result.error(gate.getCode(), gate.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ String status = body != null ? (String) body.get("status") : null;
|
|
|
|
|
+ String type = body != null ? (String) body.get("type") : null;
|
|
|
|
|
+ int page = (int) ParamUtils.getLong(body != null ? body.get("page") : null, 1L);
|
|
|
|
|
+ int size = (int) ParamUtils.getLong(body != null ? body.get("size") : null, 10L);
|
|
|
|
|
+ return Result.success(withdrawalService.getAdminList(status, type, page, size));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ==================== 内部辅助 ====================
|
|
|
|
|
+
|
|
|
|
|
+ /** 管理员角色门禁:平台角色(admin/operator/finance)直通;否则 403。 */
|
|
|
|
|
+ private Result<Map<String, Object>> requirePlatformRole(String role, List<String> roles) {
|
|
|
|
|
+ if ("admin".equals(role) || AdminRoles.hasAnyPlatformRole(roles)) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ return Result.forbidden("无权限:需要管理员角色");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /** 解析请求体中的 int[](接受 List<Number>/List<String>/int[]),失败返回 null。 */
|
|
|
|
|
+ private int[] toIntArray(Object value) {
|
|
|
|
|
+ if (value == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (value instanceof int[]) {
|
|
|
|
|
+ return ((int[]) value).clone();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (value instanceof List) {
|
|
|
|
|
+ List<?> list = (List<?>) value;
|
|
|
|
|
+ int[] result = new int[list.size()];
|
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
+ Object item = list.get(i);
|
|
|
|
|
+ if (item instanceof Number) {
|
|
|
|
|
+ result[i] = ((Number) item).intValue();
|
|
|
|
|
+ } else if (item instanceof String) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ result[i] = Integer.parseInt(((String) item).trim());
|
|
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (value instanceof String) {
|
|
|
|
|
+ String raw = ((String) value).replace('[', ' ').replace(']', ' ').trim();
|
|
|
|
|
+ if (raw.isEmpty()) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ String[] parts = raw.split("[,/]");
|
|
|
|
|
+ int[] result = new int[parts.length];
|
|
|
|
|
+ for (int i = 0; i < parts.length; i++) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ result[i] = Integer.parseInt(parts[i].trim());
|
|
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|